Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
1 | initial version |
Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
Here is sample code (only an example, not my real use case):
class Rationals:
def __init__(self,nom,denom):
if (denom==0):
print("Error")
print(quit)
quit()
else:
divisor=ggT(nom,denom)
if (divisor!=0):
self.nom=nom/divisor
self.denom=denom/divisor
else:
self.nom=nom
self.denom=denom
def __add__(self,element2):
result=Rationals()
result.denom=self.denom*element2.denom
result.nom=self.denom*element.nom+self.nom*element.denom
divisor=ggT(result.nom,result.denom)
result.nom=result.nom/divisor
result.denom=result.denom/divisor
return result
def __mul__(self,element2):
result=Rationals()
result.nom=self.nom*element2.nom
result.denom=self.denom*element2.denom
divisor=ggT(result.nom,result.denom)
result.nom=result.nom/divisor
result.denom=result.denom/divisor
return result
Now if I type in RR = PolynomialRing(Rationals,'y') I get an error:
TypeError Traceback (most recent call last) <ipython-input-112-6f1923f0a0bd> in <module> ----> 1 RR = PolynomialRing(Rationals,'y')
/usr/lib/python3/dist-packages/sage/rings/polynomial/polynomial_ring_constructor.py in PolynomialRing(base_ring, args, *kwds) 553 """ 554 if not ring.is_Ring(base_ring): --> 555 raise TypeError("base_ring {!r} must be a ring".format(base_ring)) 556 557 n = -1 # Unknown number of variables
TypeError: base_ring <class '__main__.rationals'=""> must be a ring
Note that this is only an example, not my real use case. Of course, I could use QQ in sagemath, but I consider a more complex ring which does not exist in sagemath.
How do I tell sage that I am confident that my domain is actually a ring?
Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
Here is sample code (only an example, not my real use case):
class Rationals:
def __init__(self,nom,denom):
if (denom==0):
print("Error")
print(quit)
quit()
else:
divisor=ggT(nom,denom)
if (divisor!=0):
self.nom=nom/divisor
self.denom=denom/divisor
else:
self.nom=nom
self.denom=denom
def __add__(self,element2):
result=Rationals()
result.denom=self.denom*element2.denom
result.nom=self.denom*element.nom+self.nom*element.denom
divisor=ggT(result.nom,result.denom)
result.nom=result.nom/divisor
result.denom=result.denom/divisor
return result
def __mul__(self,element2):
result=Rationals()
result.nom=self.nom*element2.nom
result.denom=self.denom*element2.denom
divisor=ggT(result.nom,result.denom)
result.nom=result.nom/divisor
result.denom=result.denom/divisor
return result
Now if I type in RR = PolynomialRing(Rationals,'y') I get an error:
TypeError Traceback (most recent call last) <ipython-input-112-6f1923f0a0bd> in <module> ----> 1 RR = PolynomialRing(Rationals,'y')
/usr/lib/python3/dist-packages/sage/rings/polynomial/polynomial_ring_constructor.py in PolynomialRing(base_ring, args, *kwds) 553 """ 554 if not ring.is_Ring(base_ring): --> 555 raise TypeError("base_ring {!r} must be a ring".format(base_ring)) 556 557 n = -1 # Unknown number of variables
TypeError: base_ring <class '__main__.rationals'=""> must be a ring
Note that this is only an example, not my real use case. Of course, I could use QQ in sagemath, but I consider a more complex ring which does not exist in sagemath.
How do I tell sage that I am confident that my domain is actually a ring?
Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
Here is sample code (only an example, not my real use case):
class Rationals:
def __init__(self,nom,denom):
if (denom==0):
print("Error")
print(quit)
quit()
else:
divisor=gcd(nom,denom)
if (divisor!=0):
self.nom=nom/divisor
self.denom=denom/divisor
else:
self.nom=nom
self.denom=denom
def __add__(self,element2):
denom=self.denom*element2.denom
nom=self.denom*element2.nom+self.nom*element2.denom
divisor=gcd(nom,denom)
nom=nom/divisor
denom=denom/divisor
return Rationals(nom,denom)
def __mul__(self,element2):
nom=self.nom*element2.nom
denom=self.denom*element2.denom
divisor=gcd(nom,denom)
nom=nom/divisor
denom=denom/divisor
return Rationals(nom,denom)
Now if I type in RR = PolynomialRing(Rationals,'y') I get an error:
TypeError Traceback (most recent call last) <ipython-input-112-6f1923f0a0bd> in <module> ----> 1 RR = PolynomialRing(Rationals,'y')
/usr/lib/python3/dist-packages/sage/rings/polynomial/polynomial_ring_constructor.py in PolynomialRing(base_ring, args, *kwds) 553 """ 554 if not ring.is_Ring(base_ring): --> 555 raise TypeError("base_ring {!r} must be a ring".format(base_ring)) 556 557 n = -1 # Unknown number of variables
TypeError: base_ring <class '__main__.rationals'=""> must be a ring
Note that this is only an example, not my real use case. Of course, I could use QQ in sagemath, but I consider a more complex ring which does not exist in sagemath.
How do I tell sage that I am confident that my domain is actually a ring?