Ask Your Question
0

solving polynomial equations with to_poly_solve

asked 2012-03-30 17:51:55 +0100

niles gravatar image

updated 2012-03-30 17:54:46 +0100

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
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-04-01 09:43:47 +0100

Volker Braun gravatar image

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.

edit flag offensive delete link more

Comments

Good, I figured!

kcrisman gravatar imagekcrisman ( 2012-04-02 12:10:58 +0100 )edit
1

answered 2012-03-31 00:51:21 +0100

kcrisman gravatar image

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[0].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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-03-30 17:51:55 +0100

Seen: 3,360 times

Last updated: Apr 01 '12