# solving polynomial equations with to_poly_solve

I have a system of (quadratic) polynomial equations which I'd like to solve with Sage. Here and elsewhere I've seen references to the fact that to_poly_solve is faster than just calling solve in Sage.

Can I somehow tell to_poly_solve that I'd like to work over RR or RDF instead of whatever symbolic ring it's using by default? The coefficients of the equations I'm using are floats, but my solutions are coming out as huge fractions. I imagine it would be faster if the solver were working over RR.

EDIT: Upon further reflection, I suspect this is really a Maxima question, since the entire solving process is carried out there. Nevertheless, I would like to know if such functionality exists in Maxima and whether I can use it from Sage.

If you'd like to know, here are some test equations:

vars = var('a0, a1, a2, R')
eqs = []
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 2*a0 - 1.56835186587759*a1 - 1.79444137578129*a2 + 1]
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.56835186587759*a0 - 2*a1 - 1.12952287573422*a2 + 1]
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.79444137578129*a0 - 1.12952287573422*a1 - 2*a2 + 1]
eqs += [a0 + a1 + a2 == 1]

meqs = maxima(eqs)
solns = meqs.solve(vars)


For example, here is the value of a0 and R in this case:

sage: solns
a0=-127216901572440833725/188266808300071978748
sage: solns
R=9*sqrt(149350213112030161)/sqrt(47066702075017994687)

sage: solns.rhs().parent()
Maxima

edit retag close merge delete

Sort by » oldest newest most voted

You can use the Groebner basis method that I mentioned previously:

sage: ring = PolynomialRing(RDF, 'a0,a1,a2,a3,R', order='lex')
sage: ideal = ring.ideal([
....:  -R^2 + a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 2*a0 - 1.56835186587759*a1 - 1.79444137578129*a2 + 1,
....:  -R^2 + a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.56835186587759*a0 - 2*a1 - 1.12952287573422*a2 + 1,
....:   -R^2 + a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.79444137578129*a0 - 1.12952287573422*a1 - 2*a2 + 1,
....:   a0 + a1 + a2 - 1])
sage: ideal.groebner_basis()
[a0 + 0.675726767968, a1 - 0.750109938467, a2 - 0.9256168295, R^2 - 0.257026038676]


It seems we don't have Singular's support for floating point numbers wrapped, so its not as fast or nice as it could be. But the system of equations is so simple that it doesn't really matter here.

more

Use polynomial rings, I suspect. If there is in fact such functionality with Groebner bases etc. - you are closer to that environment than I am nowadays.

I tried using eqs.roots(ring=RR) and the like, but this gave a nasty error.

As for the Maxima, the point is exact solutions, so this is what to expect. There is something called [algsys](http://maxima.sourceforge.net/docs/manual/en/maxima_20.html#algsys) in Maxima that should be refinable to your needs, though Maxima does this rational substitution thing a lot, even when we ask it not to.

more