Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculus -- bugs in solve #3745

Open
williamstein opened this issue Jul 30, 2008 · 16 comments
Open

calculus -- bugs in solve #3745

williamstein opened this issue Jul 30, 2008 · 16 comments

Comments

@williamstein
Copy link
Contributor

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

Upstream: Reported upstream. No feedback yet.

Component: calculus

Stopgaps: todo

Issue created by migration from https://trac.sagemath.org/ticket/3745

@rlmill
Copy link
Mannequin

rlmill mannequin commented Aug 13, 2008

comment:1

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) 
[]

@rlmill rlmill mannequin changed the title calculus -- bug in solve calculus -- bugs in solve Aug 13, 2008
@rlmill
Copy link
Mannequin

rlmill mannequin commented Aug 13, 2008

comment:3

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)

@kcrisman
Copy link
Member

comment:4

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.

@kcrisman
Copy link
Member

comment:5

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 :(

@williamstein
Copy link
Contributor Author

comment:6
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>

@kcrisman
Copy link
Member

comment:7

It could be worth trying these with #13364.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@kcrisman
Copy link
Member

@kcrisman
Copy link
Member

Upstream: Reported upstream. No feedback yet.

@kcrisman
Copy link
Member

comment:16

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.

@kcrisman
Copy link
Member

comment:17

https://sourceforge.net/p/maxima/bugs/2846/

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.

@sagetrac-jakobkroeker
Copy link
Mannequin

sagetrac-jakobkroeker mannequin commented Aug 19, 2015

Stopgaps: todo

@sagetrac-zonova
Copy link
Mannequin

sagetrac-zonova mannequin commented Nov 27, 2016

comment:19

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?

@kcrisman
Copy link
Member

comment:20

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.

@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants