rtoy / maxima

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

Problem with trigreduce #1513

Open rtoy opened 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-04 18:03:18 Created by dreitzle on 2021-12-03 17:49:05 Original: https://sourceforge.net/p/maxima/bugs/3896


I stumbled upon the following problem in trigreduce():

Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp SBCL 1.4.9
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) trigreduce(cos(1/2*acos(q))^2*sin(1/2*acos(q))^2);

Maxima encountered a Lisp error:

 The value
   1
 is not of type
   LIST

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i2) build_info();
(%o2) 
Maxima version: "5.45.1"
Maxima build date: "2021-11-01 10:49:25"
Host type: "x86_64-pc-linux-gnu"
Lisp implementation type: "SBCL"
Lisp implementation version: "1.4.9"
User dir: "/home/rifleman/.maxima"
Temp dir: "/tmp"
Object dir: "/home/rifleman/.maxima/binary/5_45_1/sbcl/1_4_9"
Frontend: false

The correct answer should be something like (1-q^2)/4 .

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-04 18:03:19 Created by robert_dodier on 2021-12-06 05:35:55 Original: https://sourceforge.net/p/maxima/bugs/3896/#ca69


Confirmed in Maxima post-5.45. I was digging around in src/trgred.lisp a little bit, and I tried a few changes to SP1TLIN to avoid the error, but I wasn't able to get a correct result.

The code in src/trgred.lisp is pretty convoluted; from reading the comments, it looks like a fairly narrow range of expressions is handled. If so, then just starting over and rewriting in Maxima, making use of the pattern matching machinery (matchdeclare / defrule, etc.) could be a win.

For the record, I find I can get to the expected result by working in steps.

(%i1) cos(e/2)^2*sin(e/2)^2;
                                   2 e     2 e
(%o1)                           cos (-) sin (-)
                                     2       2
(%i2) trigreduce(%);
                                 1 - cos(2 e)
(%o2)                            ------------
                                      8
(%i3) %, e=acos(a);
                              1 - cos(2 acos(a))
(%o3)                         ------------------
                                      8
(%i4) trigexpand(%);
                                          2
                                   2 - 2 a
(%o4)                              --------
                                      8
(%i5) ratsimp(%);
                                      2
                                     a  - 1
(%o5)                              - ------
                                       4
rtoy commented 4 months ago

Imported from SourceForge on 2024-07-04 18:03:22 Created by macrakis on 2022-01-10 14:32:23 Original: https://sourceforge.net/p/maxima/bugs/3896/#179e


trigreduce(cos(k*acos(q))^2*sin(k*acos(q))^2) also works fine. Substituting k=1/2, applying trigexpand, then ratsimp, gets a nice simple (and correct) answer, -(q^2-1)/4.