rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

trigrat(sin(%pi/5)) makes mess #2203

Open rtoy opened 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-05 21:35:09 Created by antonvoropaev on 2011-08-25 15:53:26 Original: https://sourceforge.net/p/maxima/bugs/2263


See also bug reports ID: 742909 and ID: 2999635

INPUT

build_info(); display2d : false; trigrat(sin(%pi/5));

INPUT AND OUTPUT

(%i1) build_info(); Maxima version: 5.25.0 Maxima build date: 12:0 8/2/2011 Host type: i686-pc-mingw32 Lisp implementation type: Clozure Common Lisp Lisp implementation version: Version 1.7-r14925M (WindowsX8632) (%o1) (%i2) display2d : false; (%o2) false (%i3) trigrat(sin(%pi/5)); (%o3) -(-sin(3*%pi/5)+%i*(cos(3*%pi/5)-cos(2*%pi/5)+2*cos(%pi/5)-1) +sin(2*%pi/5)-2*sin(%pi/5)) /2

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-05 21:35:10 Created by macrakis on 2020-05-10 19:58:39 Original: https://sourceforge.net/p/maxima/bugs/2263/#74e7


Verified that this is still a problem in 5.43 on SBCL.

Note that the result is doubly bad: not only does it make something simple into something complicated, but the imaginary part can actually be simplified by trigrat to zero:

e1: trigrat(sin(%pi/5))$
e2: imagpart(e1) => -(cos((3*%pi)/5)-cos((2*%pi)/5)+2*cos(%pi/5)-1)/2
trigrat(e2) => 0
float(e2) => -5e-17     << sanity check

I ran into a similar problem with sin(%pi/7). In fact, it gives stuff like this for all

sin(%pi*m/n)

with n>4.

A side-effect of this non-simplification is that trying scanmap(trigrat,e1) gets into an infinite loop, since a subexpression gets expanded....

Interestingly, if you load(spangl) (range reduction for trig), some of these problems go away:

(fresh Maxima)
load(spangl)$
trigrat(sin(%pi/5)) => sin(%pi/5)

but sometimes trigrat loops:

(fresh Maxima)
load(spangl)$
e1: trigrat(sin(%pi/7)) => (%i*(2*sin((3*%pi)/14)-2*cos(%pi/7)-2*sin(%pi/14)+1)+2*sin(%pi/7))/2
trigrat(e1) => sin(%pi/7)

That is, it's not idempotent.