Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks for the more explicit update, that clarifies something for me - I should have checked atan2(0,0) first!

In sage.symbolic.pynac.pyx, we have the following for the py_atan2(0,0) case.

else:
    if sgn_x > 0:
        return 0
    elif x == 0:
        raise ValueError, "arctan2(0,0) undefined"

Pynac is how we handle symbolics. So the problem is that you have a symbolic arctan2, which has (0,0) plugged in, and then is evaluated. Compare:

sage: atan2(0,0)
0
sage: atan2(0,0,hold=True)
arctan2(0, 0)
sage: atan2(0,0,hold=True).n()
ValueError: arctan2(0,0) undefined

Since Maxima also doesn't like this

sage: atan2(0,0,hold=True).simplify()
-----------------------------------------------------
TypeError: Error executing code in Maxima
CODE:
    sage1 : atan2(0,0)$
Maxima ERROR:

atan2: atan2(0,0) is undefined.
 -- an error. To debug this try: debugmode(true);

Mathematica also returns various things, depending on where you look, that are not zero. I say you are right about atan2(0,0). At the very least we need consistency. Maybe Ginac/Pynac says it's zero? Anyway, this is now ticket 11423.

I don't know that this will help your computation. You may need to try something more sophisticated - like other branch cuts for the arctangent :( What would you like to get from this computation - perhaps in a simpler case that still has atan2(0,0), in principle.

Thanks for the more explicit update, that clarifies something for me - I should have checked atan2(0,0) first!

In sage.symbolic.pynac.pyx, we have the following for the py_atan2(0,0) case.

else:
    if sgn_x > 0:
        return 0
    elif x == 0:
        raise ValueError, "arctan2(0,0) undefined"

Pynac is how we handle symbolics. So the problem is that you have a symbolic arctan2, which has (0,0) plugged in, and then is evaluated. Compare:

sage: atan2(0,0)
0
sage: atan2(0,0,hold=True)
arctan2(0, 0)
sage: atan2(0,0,hold=True).n()
ValueError: arctan2(0,0) undefined

Since Maxima also doesn't like this

sage: atan2(0,0,hold=True).simplify()
-----------------------------------------------------
TypeError: Error executing code in Maxima
CODE:
    sage1 : atan2(0,0)$
Maxima ERROR:

atan2: atan2(0,0) is undefined.
 -- an error. To debug this try: debugmode(true);

the zero behavior seems most wrong. Mathematica also returns various things, depending on where you look, that are not zero. I say you are right about atan2(0,0). At the very least we need consistency. Maybe Ginac/Pynac says it's zero? Anyway, this is now ticket 11423.

I don't know that this will help your computation. You may need to try something more sophisticated - like other branch cuts for the arctangent :( What would you like to get from this computation - perhaps in a simpler case that still has atan2(0,0), in principle.