solve limitations

35 views
Skip to first unread message

Damiano Pasetto

unread,
Feb 21, 2026, 4:21:59 AM (3 days ago) Feb 21
to sage-support
Hi,
I am quite new to SageMath. I wanted to use Sage to solve some easy equations and inequalities, but frequently the solve command doesn't provide any answer, sometimes the answers should be simplified, and sometimes it even gives wrong answers.

Am I doing something wrong? 

If sage cannot solve those simple problems, how can it be a valuable alternative to mathematica?

I am copying here some examples:

1) NOT SOLVIG
in: solve(abs(x-4)==x,x)
out: [x == abs(x - 4)]    NOT SOLVIG
(correct: x=2)

2) WRONG ANSWER
in: solve(abs(x+1)>=x,x)
out: [[x == 0], [0 < x], [x < 0]]   WRONG
(correct: all values of R)

3) NOT SOLVING
in: solve(x^2+abs(x+1)==4,x)
out: [x == -sqrt(-abs(x + 1) + 4), x == sqrt(-abs(x + 1) + 4)]    NOT SOLVIG
(correct: [(-1+sqrt(13))/2, (1-sqrt(21))/2])

4) CORRECT ANSWER BUT COMPLICATEDSIMPLIFICATIONS
in: solve(abs(5*x-1)>=x,x)
out: [[x == (1/4)], [x == (1/6)], [x == 0], [0 < x, x < (1/6)], [(1/4) < x], [x < 0]]    TOO COMLICATED
(correct: [x<=(1/6)], [x>=1/4])

Aram Dermenjian

unread,
Feb 22, 2026, 9:13:27 AM (2 days ago) Feb 22
to sage-s...@googlegroups.com
Hi Damiano,

For number 1 and 3, you can get the correct answer by using "to_poly_solve=True". 
sage: solve(abs(x-4)==x,x,  to_poly_solve=True)
[x == 2]
sage:  solve(x^2+abs(x+1)==4,x, to_poly_solve=True)
[x == -1/2*sqrt(21) + 1/2, x == 1/2*sqrt(13) - 1/2]

For number 2, the answer is correct, all values of R are present (x = 0, x < 0 and x > 0 gives you all real numbers).

Alternatively, you can use the sympy algorithm, which in your case seems to give "nicer" solutions (note that you might need to force the domain to be real numbers as solve assumes the domain to be complex numbers usually):
sage: solve(abs(x-4)==x,x, algorithm='sympy', domain='real')
[x == 2]
sage: solve(abs(x+1)>=x,x, algorithm='sympy')
[x < +Infinity]
sage: solve(x^2+abs(x+1)==4,x, algorithm='sympy', domain='real')
[x == 1/2*sqrt(13) - 1/2, x == -1/2*sqrt(21) + 1/2]
sage: solve(abs(5*x-1)>=x,x, algorithm='sympy')
[[x <= (1/6)], [x >= (1/4)]]

Note that you can get more information on any function using a question mark  after the function: "solve?" which will show the documentation for that function allowing you to see optional parameters and examples on how to use the function.

-Aram

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-support/16dc4c1c-c8f0-4b4d-9dbb-55f896cf738an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages