Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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]

maxima.load('topoly_solver')
meqs = maxima(eqs)
solns = meqs.solve(vars)

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

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

sage: solns[0][0].rhs().parent()
Maxima

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]

maxima.load('topoly_solver')
meqs = maxima(eqs)
solns = meqs.solve(vars)

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

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

sage: solns[0][0].rhs().parent()
Maxima