# How to work with polynomial rings with real or complex coefficients

I'm trying to learn more basics in Sage, and I'm struggling with polynomial rings with real and complex coefficients. Many of the basic functions seem to return errors from the Singular or Pari implementation, and I wonder if there is a simple workaround I'm missing. Here is an example:

P.<x,y> = PolynomialRing(RealField(), 2)
I = P.ideal(x^2 - y + 1, -x^2 - y - 1)
I.is_prime()


Returns an error:

TypeError: cannot call Singular function 'primdecSY' with ring parameter of type '<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>'


Running the same code with QQ instead of RealField() works fine, so I assume the issue is that the Singular function can't work with Sage's implementation of Real numbers. Is there a way around this to do basic operations on polynomial rings with coefficients in numerically approximated fields like the reals and complexes?

edit retag close merge delete

3

For ideals to work, one needs exact field - like AA or QQbar.

( 2023-04-21 02:38:25 +0200 )edit

Sort by ยป oldest newest most voted

The problem with real or complex fields is that their elements are approximate, and operations there are subject to rounding errors, which may accumulate with the number of performed operations. This is unacceptable situation for the ideals machinery, where accumulating errors destroy basic properties and make it impossible to perform basis operations (e.g., membership testing).

In other words, for ideals to work they have to be defined over exact fields/rings, which do not allow rounding errors of any kind. Unfortunately, real and complex fields cannot be implemented exactly. Nevertheless, there are suitable substitutes for real and complex fields:

We can approximate real and complex numbers with elements of AA and QQbar using algdep() function, where we can choose accuracy in the form of polynomial degree.

Clearly, rational fields QQ and QQ[I] are subfields of AA and QQbar, respectively, and appear when we approximate with polynomials of degree 1.

For example, we can approximate $\pi$ with a polynomial root of degree 5 as follows:

eps = 1e-6
pi_aa = AA.polynomial_root(algdep(pi,5),RIF(pi-eps,pi+eps))
print(pi_aa)
print(pi_aa.parent())


which gives

3.141592653589794?
Algebraic Real Field

more