sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.45k stars 482 forks source link

Give an `algorithm` keyword to (some?) `simplify` methods/functions #32472

Closed 7822f248-ba56-45f1-ab3d-4de7482bdf9f closed 1 year ago

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 3 years ago

Case in point (many other examples exist...) :

sage: var("x", domain="positive")
x
sage: u = -1/2*I*x + 1/2*I*sqrt(x^2 - 1) + 1/2*I/(x - sqrt(x^2 - 1))
sage: u.simplify()
-1/2*I*x + 1/2*I*sqrt(x^2 - 1) + 1/2*I/(x - sqrt(x^2 - 1))
sage: u._giac_().simplify()._sage_()
I*sqrt(x^2 - 1)
sage: u._fricas_().simplify()._sage_()
-(I*x^2 - I*sqrt(x^2 - 1)*x - I)/(x - sqrt(x^2 - 1))
sage: u._sympy_().simplify()._sage_()
-I*(x^2 - sqrt(x^2 - 1)*x - 1)/(x - sqrt(x^2 - 1))
sage: mathematica.FullSimplify(u).sage()
I*sqrt(x^2 - 1)

Suggestion : give to the simplify method of symbolic expressions (and its wrapper function) an algorithm keyword selecting an alternative to our "default" (which is to send the expression to Maxima and accept whatever Maxima sends back to us...).

This might be also useful for the more specialized methods/functions (such as simplify_trig). Advice required...

Advice also required about adding it to simplify_full, which aims to be a useful helper in complicated cases, but often bites more than it can swallow...

CC: @slel

Component: symbolics

Author: Emmanuel Charpentier

Branch/Commit: u/charpent/give_analgorithmkeyword_tosome__simplify__methods_functions @ 6472588

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

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 3 years ago

Branch: u/charpent/give_analgorithmkeyword_tosome__simplify__methods_functions

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 3 years ago

Commit: 5637286

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 3 years ago
comment:2

Replying to @EmmanuelCharpentier:

This does the job excusively for the simplify method of symbolic expressions and the simplify() function.

Passes ptestlong without failure ==> needs_review.


New commits:

5637286Add an algorithm keyword to simplify.
slel commented 3 years ago

Author: Emmanuel Charpentier

mezzarobba commented 2 years ago
comment:4

Lgtm, except that the examples in sage.calculus.functional.simplify() should use simplify(foo), not foo.simplify().

(I am unable to help with deciding exactly what to do with other simplification methods, unfortunately, but I like the idea of having keywords to choose a backend there as well.)

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 2 years ago
comment:5

Replying to @mezzarobba:

Lgtm, except that the examples in sage.calculus.functional.simplify() should use simplify(foo), not foo.simplify().

Right. I cut n' pasted the method examplen and forgot to modify it for the functional syntax. Shame on me.

Done, passes its doctest after rebasing on 9.5.beta7. Running ptestlong to be damn sure. Stay tuned...

(I am unable to help with deciding exactly what to do with other simplification methods, unfortunately, but I like the idea of having keywords to choose a backend there as well.)

Too bad. The specialized methods may (Maxima) or may not (giac, fricas) exost in the other backends... Advice still needed.

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 2 years ago
comment:6

Replying to @EmmanuelCharpentier:

...

Done, passes its doctest after rebasing on 9.5.beta7. Running ptestlong to be damn sure. Stay tuned...

ptestlong gives exactly the same failures as thos observed in 9.5.beta7 ==> probably worth positive_review.

Temporarily setting needs work , I'll set needs_review after pushing my edits.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 5637286 to 6472588

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

419aaa9Add an algorithm keyword to simplify.
16c7733Trac#39472 : fix example for the simplify function (rebased on 9.5.beta7)
6472588Merge branch 'u/charpent/give_an__algorithm__keyword_to__some____simplify__methods_functions' of trac.sagemath.org:sage into t/32472/give_an__algorithm__keyword_to__some____simplify__methods_functions