Opened 8 years ago

Last modified 8 years ago

#17065 needs_work defect

use Maxima's trigrat() in symbolic simplify

Reported by: Ralf Stephan Owned by:
Priority: major Milestone: sage-6.4
Component: symbolics Keywords: maxima, simplification, trigonometric
Cc: Merged in:
Authors: Ralf Stephan Reviewers:
Report Upstream: Fixed upstream, but not in a stable release. Work issues:
Branch: u/rws/use_maxima_s_trigrat___in_symbolic_simplify (Commits, GitHub, GitLab) Commit: 3db6f899c380523dc6d6e940650eede5984a37fa
Dependencies: Stopgaps:

Status badges

Description

The ask page http://ask.sagemath.org/question/11365/simplify-trigonometric-expression/ showed that trigrat() is not used. What a waste.

Change History (12)

comment:1 Changed 8 years ago by Ralf Stephan

Branch: u/rws/use_maxima_s_trigrat___in_symbolic_simplify

comment:2 Changed 8 years ago by Ralf Stephan

Authors: Ralf Stephan
Commit: 3db6f899c380523dc6d6e940650eede5984a37fa
Status: newneeds_review

Please review.


New commits:

3db6f8917065: do trigrat after trigexpand; doctest

comment:3 Changed 8 years ago by Nils Bruin

Status: needs_reviewneeds_work

Quite some doctest failures on the buildbot. Some of them are probably not due this particular change, but others most probably are. A few are simply *better* answers now (that's just a matter of changing the expected output), but there are also some that are much *worse*. So the change is not uniformly an improvement.

ratsimp claims "canonical form", so that's definitely attractive. However, do we know if its rewrites always apply across the whole domain? We'd have to document if it deviates.

comment:4 Changed 8 years ago by Ralf Stephan

Since setting "needs_work" makes the buildbot link disappear, and I'm too stupid to find the results otherwise (I tried), I cannot sort this out without help, sorry.

comment:5 Changed 8 years ago by Karl-Dieter Crisman

This can even lead to disaster, I think:

sage: F = (4*cos(9*pi/180)^2 - 3)*(4*cos(27*pi/180)^2 - 3)
sage: F.maxima_methods().trigrat()
sqrt(5) + 2*cos(7/10*pi) - 2*cos(1/10*pi) - 2*I*sin(3/5*pi) +
2*I*sin(2/5*pi) + 1

I really am not interested in seeing I turn up in such a simplification, regardless of the "correct" answer.

comment:6 in reply to:  4 Changed 8 years ago by Nils Bruin

Status: needs_workneeds_review

Replying to rws:

Since setting "needs_work" makes the buildbot link disappear, and I'm too stupid to find the results otherwise (I tried), I cannot sort this out without help, sorry.

Oh, that's silly. I'm setting it back to "needs review" to make the report visible for now. Hopefully we can have this fixed.

comment:7 Changed 8 years ago by Ralf Stephan

Status: needs_reviewneeds_work

Thanks, the link is now here: http://build.sagedev.org/trac/builders/trac_builder/builds/1046 so the ticket can be set to the right status.

comment:8 in reply to:  5 ; Changed 8 years ago by Ralf Stephan

Replying to kcrisman:

This can even lead to disaster, I think:

sage: F = (4*cos(9*pi/180)^2 - 3)*(4*cos(27*pi/180)^2 - 3)
sage: F.maxima_methods().trigrat()
sqrt(5) + 2*cos(7/10*pi) - 2*cos(1/10*pi) - 2*I*sin(3/5*pi) +
2*I*sin(2/5*pi) + 1

I really am not interested in seeing I turn up in such a simplification, regardless of the "correct" answer.

While this one could be resolved by adding a trigreduce to the queue:

sage: F = (4*cos(9*pi/180)^2 - 3)*(4*cos(27*pi/180)^2 - 3)
sage: F.maxima_methods().trigrat()
sqrt(5) + 2*cos(7/10*pi) - 2*cos(1/10*pi) - 2*I*sin(3/5*pi) +
2*I*sin(2/5*pi) + 1
sage: _.maxima_methods().trigreduce()
sqrt(5) - 2*cos(3/10*pi) - 2*cos(1/10*pi) + 1

I cannot see how to fix the doctest failure:

File "src/doc/de/thematische_anleitungen/sage_gymnasium.rst", line 394, in doc.de.thematische_anleitungen.sage_gymnasium
Failed example:
    (sin(x + y)/(log(x) + log(y))).simplify_full()
Expected:
    (cos(y)*sin(x) + cos(x)*sin(y))/log(x*y)
Got:
    ((-I*arctan2(0, x) - I*arctan2(0, y))*sin(x + y) + log(abs(x)*abs(y))*sin(x + y))/(arctan2(0, x)^2 + 2*arctan2(0, x)*arctan2(0, y) + arctan2(0, y)^2 + log(abs(x))^2 + 2*log(abs(x))*log(abs(y)) + log(abs(y))^2)

the minimal case being

sage: log(x).maxima_methods().trigrat()
I*arctan2(0, x) + log(abs(x))

comment:9 Changed 8 years ago by Ralf Stephan

On the other hand, replacing trigrat with trigsimp/trigexpand/trigreduce will fail in this case:

sage: sin(1/8*pi)*sin(3/8*pi)*sin(5/8*pi)*sin(7/8*pi)
sin(7/8*pi)*sin(5/8*pi)*sin(3/8*pi)*sin(1/8*pi)
sage: _.maxima_methods().trigreduce()
TypeError                                 Traceback (most recent call last)
/home/ralf/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __init__(self, parent, value, is_name, name)
    624                 self._name = parent._create(value, name=name)
    625             except (TypeError, RuntimeError, ValueError) as x:
--> 626                 raise TypeError(x)
    627 
    628     def _latex_(self):

TypeError: ECL says: Unrecognised output from sp1sintcos.

comment:10 in reply to:  9 Changed 8 years ago by Nils Bruin

Replying to rws:

On the other hand, replacing trigrat with trigsimp/trigexpand/trigreduce will fail in this case: [...]

Yes, I noticed that one too. I have confirmed that the same problem arises in Maxima 5.34.1 on SBCL, so it's probably a maxima problem. This is now: https://sourceforge.net/p/maxima/bugs/2818/

comment:11 Changed 8 years ago by Ralf Stephan

Report Upstream: N/AFixed upstream, but not in a stable release.

comment:12 in reply to:  8 Changed 8 years ago by Ralf Stephan

While some of the mentioned problems have been fixed in recent Maxima, this no longer works:

sage: F = (4*cos(9*pi/180)^2 - 3)*(4*cos(27*pi/180)^2 - 3)
sage: F.maxima_methods().trigrat()
sqrt(5) + 2*cos(7/10*pi) - 2*cos(1/10*pi) - 2*I*sin(3/5*pi) +
2*I*sin(2/5*pi) + 1
sage: _.maxima_methods().trigreduce()
sqrt(5) - 2*cos(3/10*pi) - 2*cos(1/10*pi) + 1
Note: See TracTickets for help on using tickets.