This method can be overwritten if needed.
'''
variables = polynomial.variables();
- multi = (len(variables) > _sage_const_1 );
- res = self.base().zero();
- for (k,v) in polynomial.dict().items():
- term = self.base().one();
- ## We distinguish between several variables and just one
- ## because the return of poly.dict() is different
- if(multi):
- for i in range(len(variables)):
- term *= (self.map_of_vars()[str(variables[i])]**k[i]);
- else:
- term *= self.map_of_vars()[str(variables[_sage_const_0 ])]**k;
-
- res += term*self.base()(v);
-
- return res;
+
+ if(len(variables) == 0):
+ return self.base()(polynomial);
+
+ return polynomial(**{str(v) : self.map_of_vars()[str(v)] for v in variables});
+# multi = (len(variables) > _sage_const_1 );
+# res = self.base().zero();
+# for (k,v) in polynomial.dict().items():
+# term = self.base().one();
+# ## We distinguish between several variables and just one
+# ## because the return of poly.dict() is different
+# if(multi):
+# for i in range(len(variables)):
+# term *= (self.map_of_vars()[str(variables[i])]**k[i]);
+# else:
+# term *= self.map_of_vars()[str(variables[_sage_const_0 ])]**k;
+#
+# res += term*self.base()(v);
+#
+# return res;
def _mix_conversion(self, conversion):
'''
# This file was *autogenerated* from the file ./lazyRing.sage
from sage.all_cmdline import * # import sage library
-_sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_20 = Integer(20)
from sage.rings.ring import IntegralDomain;
from sage.structure.element import IntegralDomainElement;
from sage.categories.integral_domains import IntegralDomains;
'''
Method that a common divisor of 'self' and the input
'''
- if(len(input) > _sage_const_1 ):
+ if(len(input) > 1 ):
return self.gcd(input);
return _LazyElement(self.parent(), gcd([self.poly()]+[self.parent()(el).poly() for el in input]));
'''
Method that a common multiple of 'self' and the input
'''
- if(len(input) > _sage_const_1 ):
+ if(len(input) > 1 ):
return self.gcd(input);
return _LazyElement(self.parent(), lcm([self.poly()]+[self.parent()(el).poly() for el in input]));
# return result;
def is_zero(self):
- result = (self.poly() == _sage_const_0 );
- if((not result) and (self(**{repr(self.parent().base().variables()[_sage_const_0 ]):_sage_const_0 }) == _sage_const_0 )):
+ result = (self.poly() == 0 );
+ if((not result) and (self(**{repr(self.parent().base().variables()[0]):0}) == 0)):
if(not (self.__raw is None)):
- result = self.raw() == _sage_const_0 ;
+ result = self.raw() == 0 ;
else:
pol = None;
if(self.poly() in self.parent().poly_ring()):
except NotImplementedError:
factors = pol.factor(proof=False);
except:
- factors = [(pol,_sage_const_1 )];
+ factors = [(pol,1 )];
for factor in factors:
- result = (self.parent().to_real(factor[_sage_const_0 ]) == _sage_const_0 );
+ result = (self.parent().to_real(factor[0 ]) == 0 );
if(result):
- self.parent().add_relations(factor[_sage_const_0 ]);
+ self.parent().add_relations(factor[0 ]);
break;
return result;
def is_one(self):
try:
- result = (self.poly() == _sage_const_1 ) or (self.raw() == self.parent().one());
+ result = (self.poly() == 1 ) or (self.raw() == self.parent().one());
if(result):
- self.parent().add_relations(self.poly()-_sage_const_1 );
+ self.parent().add_relations(self.poly()-1 );
return result;
except TypeError:
return False;
## Auxiliary data
self.__var_name = "x";
- self.__version = _sage_const_1 ;
+ self.__version = 1 ;
################################################################################################
try:
built = element.built();
if(not (built is None)):
- if(built[_sage_const_0 ] == "derivative"):
- if(not(element in built[_sage_const_1 ])):
- integral = self(built[_sage_const_1 ][_sage_const_0 ]);
- if(not (integral.poly().is_monomial() and integral.poly().degree() == _sage_const_1 )):
- return self(built[_sage_const_1 ][_sage_const_0 ]).derivative().poly();
- elif(built[_sage_const_0 ] == "polynomial"):
+ if(built[0 ] == "derivative"):
+ if(not(element in built[1 ])):
+ integral = self(built[1 ][0 ]);
+ if(not (integral.poly().is_monomial() and integral.poly().degree() == 1 )):
+ return self(built[1 ][0 ]).derivative().poly();
+ elif(built[0 ] == "polynomial"):
## We check we do not have infinite recursion
- if(not element in built[_sage_const_1 ][_sage_const_1 ].values()):
+ if(not element in built[1 ][1 ].values()):
## We have some building information
- polys = {key : self.to_poly(built[_sage_const_1 ][_sage_const_1 ][key]) for key in built[_sage_const_1 ][_sage_const_1 ]};
- return built[_sage_const_1 ][_sage_const_0 ](**polys);
+ polys = {key : self.to_poly(built[1 ][1 ][key]) for key in built[1 ][1 ]};
+ return built[1 ][0 ](**polys);
except AttributeError:
pass;
## We try to keep the real representations small
try:
- new_elem = (element-rel[_sage_const_1 ])/rel[_sage_const_0 ];
+ new_elem = (element-rel[1 ])/rel[0 ];
if(new_elem.size() < self.map_of_vars()[var_found].size()):
self.__map_of_vars[var_found] = new_elem;
except:
pass;
## Otherwise, we return the polynomial computed
- return self.poly_ring()(rel[_sage_const_0 ]*self.poly_ring()(var_found) + rel[_sage_const_1 ]);
+ return self.poly_ring()(rel[0 ]*self.poly_ring()(var_found) + rel[1 ]);
################################################################################################
### Other Methods for LazyRing
## Deleting the map of derivatives
self.__map_of_derivatives = {};
- self.__version += _sage_const_1 ;
+ self.__version += 1 ;
def change_variable_name(self, new_name):
self.__var_name = str(new_name);
return self.__map_of_derivatives[el];
if(el in self.__constants):
- return _sage_const_0 ;
+ return 0 ;
else:
try:
el = self.poly_ring()(el);
return (not(coer is False) and not(coer is None));
def _element_constructor_(self, *args, **kwds):
- if(len(args) < _sage_const_1 ):
+ if(len(args) < 1 ):
print args
raise ValueError("Impossible to build an element without arguments");
- i = _sage_const_0 ;
- if(len(args) >= _sage_const_2 ):
- if(not (args[_sage_const_0 ] is self)):
+ i = 0 ;
+ if(len(args) >= 2 ):
+ if(not (args[0 ] is self)):
raise ValueError("RIOKO: What the .... are you sending to this method?");
- i = _sage_const_1 ;
+ i = 1 ;
X = args[i];
try:
def __find_relation(self, a, b):
## TODO We assume a and b are not constants
- i = _sage_const_1 ;
- while(self.sequence(a,i) == _sage_const_0 and self.sequence(b,i) == _sage_const_0 ):
- i = i + _sage_const_1 ;
+ i = 1 ;
+ while(self.sequence(a,i) == 0 and self.sequence(b,i) == 0 ):
+ i = i + 1 ;
ai = self.sequence(a,i);
bi = self.sequence(b,i);
- if(bi == _sage_const_0 or ai == _sage_const_0 ):
+ if(bi == 0 or ai == 0 ):
return None;
c = ai/bi;
- d = self.sequence(a,_sage_const_0 )-c*self.sequence(b,_sage_const_0 );
+ d = self.sequence(a,0 )-c*self.sequence(b,0 );
if(a == c*b + d):
return (c,d);
class LazyRingFunctor (ConstructionFunctor):
def __init__(self):
ID = IntegralDomains();
- self.rank = _sage_const_20 ;
+ self.rank = 20 ;
super(LazyRingFunctor, self).__init__(ID,ID);
### Methods to implement