Opened 6 years ago

# Bug in solve with option to_poly_solve

Reported by: Owned by: Bruno Grenet major sage-7.2 symbolics maxima, solve Karl-Dieter Crisman, Ralf Stephan N/A

### 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!

### comment:1 Changed 6 years ago by Karl-Dieter Crisman

Cc: Karl-Dieter Crisman Ralf Stephan added

### comment:2 Changed 6 years ago by Karl-Dieter Crisman

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.

### comment:3 Changed 6 years ago by Karl-Dieter Crisman

(Also, the fix would be to somehow parse or otherwise deal with `%solve` objects in Maxima.)

### comment:4 Changed 5 years ago by Karl-Dieter Crisman

I think #22709 is a dup.

Also, a simpler example is just

```solve([cos(x)==x],x,to_poly_solve=True)
```
Note: See TracTickets for help on using tickets.