Menu

#3981 Trigreduce doesn't return principal value of atan(tan(...))

open
nobody
5
2022-10-04
2022-05-28
No

Trying to get the argument of the product of 2 complex numbers produces the wrong result:
image
image link

So I multiply

3(\cos(\frac{5π}{13}) + i*\sin(\frac{5π}{13})

with

4(\cos(\frac{7π}{13}) + i*\sin(\frac{7π}{13})

The right answer for the argument should be \frac{12π}{13}, not \frac{25π}{13}.

You can try yourself with this Maxima file that I've joined:
BUG.wxmx

Someone on Github of Wxmaxima suggested it's a problem with Maxima " switching to atan and atan getting the wrong result larger than pi/2."
Github issue

My version of WxMaxima: 22.04.0 Maxima version: 5.46.0 (x86_64-unknown-linux-gnu) Maxima compiled using: ECL 21.2.1

EDIT (Robert Dodier):
For reference, I'm appending here the content of the BUG.wxmx notebook.

Input:
             c:3*(cos(5*%pi/13)+%i*sin(5*%pi/13));

   Output:
               5 π        5 π
     3 (%i sin(---) + cos(---))
               13         13


Input:
             d:4*(cos(7*%pi/13)+%i*sin(7*%pi/13));

   Output:
               7 π        7 π
     4 (%i sin(---) + cos(---))
               13         13


Input:
             carg(c*d);

   Output:
                  7 π              5 π
              sin(---)         sin(---)
                  13               13
     π + atan(--------) + atan(--------)
                  7 π              5 π
              cos(---)         cos(---)
                  13               13


Input:
             trigreduce(%);

   Output:
     25 π
     ----
      13
1 Attachments

Discussion

  • Barton Willis

    Barton Willis - 2022-05-28

    Thanks for the bug report.

    The function trigreduce simplifies atan(tan(XXX)) to XXX. This simplification doesn’t respect the value of triginverses.

    The user documentation for trigreduce doesn’t say anything about simplifying all atan(tan(XXX)) expressions to XXX, so I say this is a bug.

    A possible fix to this bug is insert a check for the value of triginverses into sp1atrig (defined in trgred.lisp)

    (defun sp1atrig (fn exp)
      (cond ((atom exp)
         (sp1atrig2 fn exp))
        ((and (eq fn (zl-get (caar exp) '$inverse)) (eq '$triginverses '$all))
         (sp1 (cadr exp)))
        (t (sp1atrig2 fn exp))))
    
     
  • Barton Willis

    Barton Willis - 2022-05-28
    • Group: None --> Includes_proposed_fix
     
  • Barton Willis

    Barton Willis - 2022-05-28

    A quick test using the proposed change to sp1atrign gives a failure to rtest14, problem 376. The test istrigreduce(atan(tan(x+y+z))).

    I think that's the only failure caused by this proposed change,

     
  • Richard Gobeli

    Richard Gobeli - 2022-05-28

    I don't think there is any problem with the conversion of atan(tan(x)) to x, but the check still needs to be done that the resulting x needs to be in range of atan and that is -pi/2 to pi/2. This is necessary because the atan2 function added pi knowing that atan needed to be negative angle.

    It seems like the check of the resulting range of atan is not respected. The problem is that the atan(sin(7pi/13)/cos(7pi/13)) when reduced does not get atan(tan(x)). atan(tan(7pi/13)) does give -6pi/13.

     

    Last edit: Richard Gobeli 2022-05-29
  • Richard Gobeli

    Richard Gobeli - 2022-09-13

    Here is example of using rules and set limits function. the limit to the atan2rule can also be-pi/2 to pi/2.

     
  • Stavros Macrakis

    • summary: Trigreduce doesn't work --> Trigreduce doesn't return principal value of atan(tan(...))
     
  • Gustav Klopp

    Gustav Klopp - 2022-09-30

    I'd like to know more about this bug.
    can someone explain me why "carg" produce this "atan (sin x/cos x) + pi"?
    The manual only explains how to use it but not HOW it is done:
    https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html#index-carg

     
  • Raymond Toy

    Raymond Toy - 2022-10-04

    I wonder where the extra %pi comes from. c*d is

    12*(%i*sin((5*%pi)/13)+cos((5*%pi)/13))*(%i*sin((7*%pi)/13)+cos((7*%pi)/13))
    

    If then take the carg of each component I would expect 0 + atan(tan(5*%pi/13)) + atan(tan(7*%pi/13)) which trigreduce would simply to 12*%pi/13. But carg(c*d) has an extra %pi.

    Another weird result:

    expand(exponentialize(c*d));
    12*%e^((12*%i*%pi)/13)
    carg(%);
    atan(sin((12*%pi)/13)/cos((12*%pi)/13))+%pi;
    

    Where does that %pi come from? The arg of the exponential is just 12*%pi/13, which is the expected answer.

    Some more weird results:

    carg(exp(7*%i*%pi/13));
    atan(sin((7*%pi)/13)/cos((7*%pi)/13))+%pi
    

    But

    carg(exp(6*%i*%pi/13));
    atan(sin((6*%pi)/13)/cos((6*%pi)/13))
    

    It's almost as if the arg of the exponential is more than 6.5/13, then a %pi is added.

     

Log in to post a comment.