Opened 13 years ago

# calculus -- bugs in solve

Reported by: Owned by: was gfurnish major sage-6.4 calculus Reported upstream. No feedback yet. todo

We get a "solution" from `solve()` that isn't actually a solution:

```sage: f(x) = (sin(x) - 8*cos(x)*sin(x))*(sin(x)^2 + cos(x)) - (2*cos(x)*sin(x) - sin(x))*(-2*sin(x)^2 + 2*cos(x)^2 - cos(x))
sage: solve(f(x), x)
[x == pi, x == 1/2*pi, x == 0]
sage: f(pi/2)
-1
```

The following is correct:

```sage: solve(f(x).simplify_trig(), x)
[x == 0, x == pi - arccos(1/3), x == pi]
```

Reduced example (after manually removing the factor `sin(x)`):

```sage: g(x) = (1 - 8*cos(x))*(sin(x)^2 + cos(x)) - (2*cos(x) - 1)*(-2*sin(x)^2 + 2*cos(x)^2 - cos(x))
sage: solve(g(x), x)
[x == pi, x == 1/2*pi]
sage: g(pi/2)
-1
```

### comment:1 Changed 13 years ago by rlm

Also:

```sage: var('a b c')
sage: eqn1 = a - exp((-pi*b)/sqrt(1-b)) == 0
sage: eqn2 = c - atan(2*b*sqrt(1/(sqrt(4*b^4+1) - 2*b^2)))==0
sage: solve([eqn1,eqn2,a==0.1975],b,c,a)
[]
```

### comment:2 Changed 13 years ago by rlm

• Summary changed from calculus -- bug in solve to calculus -- bugs in solve

### comment:3 Changed 13 years ago by rlm

And even:

```sage: var('a,b,c,d')
sage: m = matrix(2,[a,b,c,d])
sage: i2=identity_matrix(SR,2)
sage: eqlist=[(m*m).list()[i] - i2.list()[i] for i in range(4)]
sage: solve(eqlist,a,b,c,d)
Traceback (most recent call last):
...
ValueError: Unable to solve [b*c + a^2 - 1, b*d + a*b, c*d + a*c, d^2 + b*c - 1] for (a, b, c, d)
```

### comment:4 Changed 12 years ago by kcrisman

Note this particular bug is still in Maxima as of 5.19.1. More bugs (but also lots more correct answers) have been introduced in the last year, and other bugs have been fixed. Writing a solve from scratch still looks very hard.

### comment:5 Changed 12 years ago by kcrisman

• Report Upstream set to N/A

Update from Maxima 5.20.1 in Sage:

```sage: sage: var('a,b,c,d')
(a, b, c, d)
sage: sage: m = matrix(2,[a,b,c,d])
sage: sage: i2=identity_matrix(SR,2)
sage: sage: eqlist=[(m*m).list()[i] - i2.list()[i] for i in range(4)]
sage: sage: solve(eqlist,a,b,c,d)
[a^2 + b*c - 1, a*b + b*d, a*c + c*d, b*c + d^2 - 1]
```

so this one seems to be working now, at least in the sense that it doesn't throw an error.

The second one now causes a hang.

And the first one is still there :(

### comment:6 Changed 12 years ago by was

<irrelevant rant> We should write our own native solve from scratch. Depending on maxima for solve is silly, for several reasons:

• For algebraic systems we could do much better using Groebner basis and singular.
• Coefficients for symbolic expressions can be in many base rings that don't even make sense to Maxima.

</irrelevant rant>

### comment:7 Changed 9 years ago by kcrisman

It could be worth trying these with #13364.

### comment:8 Changed 8 years ago by jdemeyer

• Milestone changed from sage-5.11 to sage-5.12

### comment:9 Changed 8 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

### comment:10 Changed 8 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:11 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.3 to sage-6.4

### comment:12 Changed 7 years ago by jdemeyer

• Description modified (diff)

### comment:13 Changed 7 years ago by jdemeyer

• Description modified (diff)

### comment:14 Changed 7 years ago by jdemeyer

• Description modified (diff)

### comment:15 follow-up: ↓ 17 Changed 7 years ago by kcrisman

• Report Upstream changed from N/A to Reported upstream. No feedback yet.

### comment:16 Changed 7 years ago by kcrisman

The one in comment:1 hangs for me as before, but upon Ctrl-C it does give `[]`. For what it's worth. Though in Maxima I got

```(%i1) solve([a - exp((-pi*b)/sqrt(1-b)) = 0, c - atan(2*b*sqrt(1/(sqrt(4*b^4+1) - 2*b^2)))=0,a=0.1975],[b,c,a]);

rat: replaced -0.1975 by -79/400 = -0.1975
(%o1)                                 []
```

almost immediately. So I'm not sure why it hangs. Is there even a solution to that? It seems quite arbitrary.

### comment:17 in reply to: ↑ 15 Changed 7 years ago by kcrisman

By the way, in the original report which has been erased, a Maxima dev suggested he'd reported this, so perhaps this is redundant, but I don't know where it would be.

### comment:18 Changed 6 years ago by jakobkroeker

• Stopgaps set to todo

### comment:19 Changed 5 years ago by zonova

I would like to point out that this bug still exists, 7 years later. There were a couple other cases of maxima's solve giving an incorrect answer (for eg, giving 0 when the function is undefined at 0). I am interested in studying this problem, does anyone have any recommendations on what would make for a better equation solver? And, if possible, some information on why Maxima's isn't great?

### comment:20 Changed 5 years ago by kcrisman

Basically, the short answer is that solving in general cases isn't easy. The long answer is that Maxima's is reasonable but often has small changes that impact other things. You are likely to get some response on the Maxima email list if you mention this bug. But writing a new one from scratch isn't a good idea; on the other hand, perhaps sympy's solver is now ready to swap in for Maxima's in Sage, I don't know. We do have both available.

Note: See TracTickets for help on using tickets.