#2620 atan2(y,x)+atan2(-y,x) doesn't always return 0

None
closed
nobody
5
2015-08-26
2013-08-05
David Ronis
No

I'm running the git master (currently at 5.28.0_137_ge1a2891 using CLISP 2.49). I have a project that generates various atan2's. In trying to simplify an expression I noticed that something like:

atan2(y,x)-atan2(-y,x);

doesn't always return zero (which is should no matter what the signs or x or y are).

Here's a test case:

ans1:atan2(y,x)+atan2(-y,x);
(%o1) 0
(%i2) assume(y>0);
(%o2) [y > 0]
(%i3) ans2:atan2(y,x)+atan2(-y,x);
(%o3) atan2(y, x) + atan2(- y, x)
(%i4)

I also tried this on an older maxima on another box (unfortunately I left the version # at home) and things worked as expected.

Discussion

  • David Ronis

    David Ronis - 2013-08-06

    I just noticed a typo in my initial report; it is atan2(y,x)+atan2(-y,x) which should return zero, not atan2(y,x)-atan2(-y,x); (the example is correct).

     
  • David Ronis

    David Ronis - 2014-01-22

    I just updated maxima to the git/master (not having done so for several months). I notice that this bug is still present, even though a fix was posted to the newsgroup.

    The culprit was found by Stavros Macrakis macrakis@alum.mit.edu last August::

    The original simplification problem here has nothing to do with anything so sophisticated as square roots, branch cuts, etc.

    Here is the simplest case of the problem:

      assume(n<0,p>0)
    
      atan2( -x, r ) => - atan2(  x, r )   << moves negation out
      atan2( -n, r ) =>   atan2( -n, r )
      atan2( -p, r ) =>   atan2( -p, r )
    

    Maxima moves the negation out of atan2 if the first argument is syntactically negative but not known to be positive or negative. The culprit is the cond clause calling mminusp* in simpatan2.

    This looks intentional, but I don't know the motivation. It certainly breaks the simplification atan2(-p,r)+atan2(p,r). Replacing mminusp* with mminusp fixes this particular problem.

    Manually making the change indeed fixes the problem. Any good reason why it wasn't fixed in master?

    A patch:is attached.

     
  • Robert Dodier

    Robert Dodier - 2015-08-26

    Applied the patch as commit 67e616f. Closing this report as fixed.

     
  • Robert Dodier

    Robert Dodier - 2015-08-26
    • labels: --> atan2, simplification
    • status: open --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks