Opened 5 years ago
Closed 15 months ago
#20755 closed defect (fixed)
Bug in solve due to a bug in symbolic_expression_from_maxima_string
Reported by: | bruno | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.9 |
Component: | symbolics | Keywords: | maxima, solve |
Cc: | Merged in: | ||
Authors: | Bruno Grenet | Reviewers: | Vincent Delecroix |
Report Upstream: | N/A | Work issues: | |
Branch: | eb0ad68 (Commits) | Commit: | eb0ad68ae007807828945e13e58e9865c67adf77 |
Dependencies: | Stopgaps: |
Description
A bug in sage.calculus.calculus.symbolic_expression_from_maxima_string
implies bugs in solve
and roots
for symbolic expressions.
Symptoms
The method solve
for symbolic expressions is buggy (the list of multiplicities has size 2 instead of 4), as well as roots
as a (serious!) consequence:
sage: w = x^4 - (1+3*i)*x^3 - (2-4*i)*x^2 + (6-2*i)*x - 4 - 4*i sage: w.solve(x,multiplicities=True) ([x == -1/2*sqrt(2*I) + 3/2*I - 1/2, x == 1/2*sqrt(2*I) + 3/2*I - 1/2, x == (-I + 1), x == (I + 1)], [1, 1]) sage: w.roots() # should be 4 roots [(-1/2*sqrt(2*I) + 3/2*I - 1/2, 1), (1/2*sqrt(2*I) + 3/2*I - 1/2, 1)]
Diagnosis
- The behavior of
roots
is easily explained by the behavior ofsolve
, sinceroots
assume that the length of the list of solutions is the same as the length of the list of multiplicities. This should clearly be the case so the bug is not inroots
.
- Given the parameter in the example,
solve
calls Maxima and parses the result. The multiplicities are obtained by invokingP.get('multiplicities')
. This is the right invocation to Maxima, no bug there.
- To parse the solutions returned by Maxima,
solve
callssage.symbolic.relation.string_to_list_of_solutions
, which itself callssage.calculus.symbolic_expression_from_maxima_string
. The bug occurs in this last function: Indeed, while there is no apparent reason for this, invoking this function changes the variablemultiplicities
of Maxima. Here is an example:
sage: w = x^4 - (1+3*i)*x^3 - (2-4*i)*x^2 + (6-2*i)*x - 4 - 4*i sage: m = (w == 0)._maxima_() sage: P = m.parent() sage: s = m.solve(x).str() sage: s # the list of solutions returned by Maxima '[_SAGE_VAR_x=-(sqrt(2*%i)-3*%i+1)/2,_SAGE_VAR_x=(sqrt(2*%i)+3*%i-1)/2,_SAGE_VAR_x=1-%i,_SAGE_VAR_x=%i+1]' sage: P.get('multiplicities') # correct! '[1,1,1,1]' sage: l = sage.calculus.calculus.symbolic_expression_from_maxima_string(s) sage: l [x == -1/2*sqrt(2*I) + 3/2*I - 1/2, x == 1/2*sqrt(2*I) + 3/2*I - 1/2, x == (-I + 1), x == (I + 1)] sage: P.get('multiplicities') # WTF??? '[1,1]'
Change History (6)
comment:1 Changed 5 years ago by
- Type changed from PLEASE CHANGE to defect
comment:2 Changed 5 years ago by
comment:3 Changed 17 months ago by
- Milestone changed from sage-7.3 to sage-8.9
seems to work in 8.9.b1
one needs to check and add a doctest
comment:4 Changed 16 months ago by
- Branch set to u/bruno/20755_bug_in_solve
- Commit set to eb0ad68ae007807828945e13e58e9865c67adf77
- Status changed from new to needs_review
comment:5 Changed 16 months ago by
- Reviewers set to Vincent Delecroix
- Status changed from needs_review to positive_review
comment:6 Changed 15 months ago by
- Branch changed from u/bruno/20755_bug_in_solve to eb0ad68ae007807828945e13e58e9865c67adf77
- Resolution set to fixed
- Status changed from positive_review to closed
Note: See
TracTickets for help on using
tickets.
Well,
multiplicities
is a system variable. See http://maxima.sourceforge.net/docs/manual/maxima_20.html. Who knows when it gets updated? In particular, the reconstruction of symbolic expressions from strings might be calling into maxima again.The quick fix is to get the correct value of
multiplicities
out as soon as we can, before conversion back.In the longer run, it would be preferable to do the conversion while avoiding strings altogether. See
sr_sum
andsr_limit
etc. for examples how one can usesr_to_max
andmax_to_sr
to convert.