Menu

#3896 Problem with trigreduce

None
open
nobody
trigreduce (10)
5
2025-10-12
2021-12-03
No

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 .

Discussion

  • Robert Dodier

    Robert Dodier - 2021-12-06

    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
    
     
  • Dominik Reitzle

    Dominik Reitzle - 2022-01-10

    I found a lot of examples by now, where the same problem appears.
    Here are two of them:

    (%i1) trigreduce(cos(acos(x)/2)^5*sin(acos(x)/2)^3);
    
    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) trigreduce(cos(acos(sqrt(x^2 + 1))/2)^5*sin(acos(sqrt(x^2 + 1))/2)^3);
    
    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.
    

    The second one of course must involve complex numbers. But if i switch to complex
    domain here, i get

    (%i3) domain:complex;
    (%o3)                               complex
    (%i4) trigreduce(cos(acos(sqrt(x^2 + 1))/2)^5*sin(acos(sqrt(x^2 + 1))/2)^3);
                                           2
                               (- %i sqrt(x  + 1)) - %i
    (%o4)                      ------------------------
                                          16
    

    and this is just wrong. A correct answer would be something like
    -1/16 x^2 sqrt(-x^2) (1+sqrt(1+x^2))
    or maybe
    -i/16 x^3 (1+sqrt(1+x^2))
    Is that the same problem? Or should this have its own ticket?

     
    • Robert Dodier

      Robert Dodier - 2025-10-12

      Dominik, thanks for the additional example. I've copied it to a separate ticket: https://sourceforge.net/p/maxima/bugs/4620/

       
  • Stavros Macrakis

    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.

     
    • Stavros Macrakis

      Another workaround is

      map('trigreduce,cos(1/2*acos(q))^2*sin(1/2*acos(q))^2)
          => (1-q)*(1+q)/4
      

      but of course that doesn't fix the bug.

       

Log in to post a comment.