Opened 3 years ago
Last modified 19 months ago
#20436 new defect
Bug in solve with option to_poly_solve
Reported by: | bruno | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-7.2 |
Component: | symbolics | Keywords: | maxima, solve |
Cc: | kcrisman, rws | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
As reported in a question of ask.sagemath.org, there is a bug when one uses the option to_poly_solve
of solve
:
sage: p = x^10 - 10*x^8 + 35*x^6 + x^5 - 50*x^4 - 5*x^3 + 25*x^2 + 5*x - 1 sage: p.solve(x, to_poly_solve=True) Traceback (most recent call last): ... TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
Explanation for the bug
The method solve
with this option rely on Maxima's to_poly_solve
function, with option 'algexact:true'
, and expect the follwoing behavior from Maxima:
- Either return a list of explicit solutions;
- Or raise a
TypeError
(with message containing "Error executing code in Maxima" or equivalent).
It happens that this is not the case (anymore?):
sage: (p == 0)._maxima_().to_poly_solve(x, options='algexact:true') %solve([_SAGE_VAR_x^10-10*_SAGE_VAR_x^8+35*_SAGE_VAR_x^6+_SAGE_VAR_x^5-50*_SAGE_VAR_x^4-5*_SAGE_VAR_x^3+25*_SAGE_VAR_x^2+5*_SAGE_VAR_x-1=0],[_SAGE_VAR_x])
Since the value returned by Maxima is not in the expected format, conversion to Sage object fails, as exemplified above.
For completeness, an example where everything works fine follows:
sage: q = x^6 + x^5 + 3*x^4 + 6*x^3 + x - 1 sage: q.solve(x, to_poly_solve=True) [x == -1.635043562439497, x == 0.424403370866086, x == (0.2765006996266782 - 1.917801305541673*I), x == (-0.1711805215349513 - 0.595429812852917*I), x == (-0.1711805215349513 + 0.595429812852917*I), x == (0.2765006996266782 + 1.917801305541673*I)] sage: (q == 0)._maxima_().to_poly_solve(x, options='algexact:true') %union([_SAGE_VAR_x=-1.635043562439497],[_SAGE_VAR_x=0.424403370866086],[_SAGE_VAR_x=0.2765006996266782-1.917801305541673*%i],[_SAGE_VAR_x=-0.595429812852917*%i-0.1711805215349513],[_SAGE_VAR_x=0.595429812852917*%i-0.1711805215349513],[_SAGE_VAR_x=1.917801305541673*%i+0.2765006996266782])
Important note :-)
I do not know how to fix this bug!
Change History (4)
comment:1 Changed 3 years ago by
- Cc kcrisman rws added
comment:2 Changed 3 years ago by
comment:3 Changed 3 years ago by
(Also, the fix would be to somehow parse or otherwise deal with %solve
objects in Maxima.)
For what it's worth, this already happens in Sage 5.2 (nearly four years old). Likely we just never came across an example where it didn't just return a list of solutions when it couldn't give an exact answer.