I'm trying to represent the ring;
where theta is the root of a monic irreducible polynomial f with integer coefficients of degree d.
This ring is a subring of the algebraic integers, which itself is a subring of the field;
I can represent this field with sympy's AlgebraicField
class
Q_theta = sympy.polys.domains.AlgebraicField(QQ,theta)
Is there a way to represent the above integer subring in a similar way?
I suspect that may not be a feature in sympy
for these reasons:
First, if theta is not algebraic over the integers, then adjoining theta to a polynomial ring over the integers, is isomorphic.
For example, pi is not algebraic over the integers, because there are no integer coefficients that, combined with pi and powers of pi, will equal zero.
To prove that these, are in fact, isomorphic, just take the evaluation ring homomorphism that evaluates each polynomial at pi.
This may not be a ready feature, because computing whether a number is not-algebraic over any ring is non-trivial. For example, determining whether or not e + pi
is algebraic is still an open question.
This can be achieved in sympy
by
from sympy.polys.domains import ZZ, QQ, RR, FF, EX
x, y, z, t = symbols('x y z t')
ZZ['theta']
or
ZZ[t]
One can easily test that this, does in fact, give you the ring of polynomials over the integers.
Second, numbers that are algebraic, (numbers like the imaginary number i
, which are the roots of integer valued polynomials) can be obtained by taking the polynomial ring modulo and the idea generated by it's unique monic polynomial.
So if theta is the imaginary number i
, which has the unique monic polynomial x^2+1
>>> QQ.old_poly_ring(x).ideal(x**2+1)
<x**2 + 1>
>>> ZZ.old_poly_ring(x).ideal(x**2+1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/domains/ring.py", line 91, in ideal
return ModuleImplementedIdeal(self, self.free_module(1).submodule(
File "/usr/local/lib/python2.7/dist- packages/sympy/polys/domains/old_polynomialring.py", line 192, in free_module
return FreeModulePolyRing(self, rank)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/agca/modules.py", line 455, in __init__
+ 'got %s' % ring.dom)
NotImplementedError: Ground domain must be a field, got ZZ
Additionally, trying this:
>>> QQ.old_poly_ring(x).quotient_ring([x**2])
QQ[x]/<x**2>
>>> ZZ.old_poly_ring(x).quotient_ring([x**2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/domains/ring.py", line 115, in quotient_ring
e = self.ideal(*e)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/domains/ring.py", line 91, in ideal
return ModuleImplementedIdeal(self, self.free_module(1).submodule(
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/domains/old_polynomialring.py", line 192, in free_module
return FreeModulePolyRing(self, rank)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/agca/modules.py", line 455, in __init__
+ 'got %s' % ring.dom)
NotImplementedError: Ground domain must be a field, got ZZ
Looking at the docs:
However, useful functionality is only implemented for polynomial rings over fields, and various localizations and quotients thereof.
In short, unless theta is non-algebraic over the integers, this might be impossible within sympy's framework.
However, representing rings in this manner can be achieved by making classes and using Python's magic methods to override the regular behavior of +
and *
, which is essentially what we need to study rings.
Here is an example of the Gaussian Integers mentioned above. This code could easily be re-purposed to give you, say, the square root of 2, or any other algebraic number over the integers.
Physicist here: I understood some of those words, but maybe I can help anyway :-D
Have you tried SymPyIntegerRing?
class sympy.polys.domains.SymPyIntegerRing
Integer ring based on SymPy’s Integer type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With