Opened 4 years ago

Closed 4 years ago

#22877 closed defect (fixed)

Wrong atan2 of complex arguments

Reported by: rws Owned by:
Priority: major Milestone: sage-8.0
Component: calculus Keywords:
Cc: Merged in:
Authors: Ralf Stephan Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: f5c35ff (Commits, GitHub, GitLab) Commit: f5c35ff65d77df6f3193dd1fe709f0f7c2451bbc
Dependencies: Stopgaps:

Status badges

Description (last modified by rws)

sage: atan2(CC(I), CC(I+1))
0.615479708670387
sage: atan2(I, I+1)
arctan2(I, I + 1)
sage: atan2(CBF(I), CBF(I+1))
...
/home/ralf/sage/src/sage/libs/pynac/pynac.pyx in sage.libs.pynac.pynac.py_atan2 (build/cythonized/sage/libs/pynac/pynac.cpp:21132)()
   1798         P = RR
   1799     if y != 0:
-> 1800         if x > 0:
   1801             res = py_atan(abs(y/x))
   1802         elif x < 0:
...
TypeError: No order is defined for ComplexBalls.

But both SymPy and Wolfram Alpha use the form atan2(y,x) = -I*log((x + I*y)/sqrt(x^2 + y^2)) for complex x,y:

In [18]: atan2(I,I+1)
Out[18]: 
      ⎛        ⅈ         ⎞
-ⅈ⋅log⎜──────────────────⎟
      ⎜   _______________⎟
      ⎜  ╱             2 ⎟
      ⎝╲╱  -1 + (1 + ⅈ)  ⎠

In [19]: _.n()
Out[19]: 0.553574358897045 + 0.402359478108525⋅ⅈ

which is arctan(1/2*I + 1/2). (Wolfram reverses the argument and so one must input arctan(I+1,I) there)

Change History (12)

comment:1 Changed 4 years ago by rws

  • Description modified (diff)

comment:2 Changed 4 years ago by rws

  • Description modified (diff)
  • Summary changed from atan2 of complex arguments inconsistencies to Wrong atan2 of complex arguments

comment:3 Changed 4 years ago by rws

  • Branch set to u/rws/atan2_of_complex_arguments_inconsistencies

comment:4 Changed 4 years ago by rws

  • Authors set to Ralf Stephan
  • Commit set to 88e55d16a99c9f6767bd57472d185b6dff3c9631
  • Status changed from new to needs_review

New commits:

88e55d122877: Wrong atan2 of complex arguments

comment:5 Changed 4 years ago by rws

  • Component changed from symbolics to calculus

comment:6 Changed 4 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM.

comment:7 Changed 4 years ago by rws

Thanks.

comment:8 Changed 4 years ago by vbraun

  • Status changed from positive_review to needs_work
[sagelib-8.0.beta5]     if P in (float, RR, RBF):
[sagelib-8.0.beta5]                           ^
[sagelib-8.0.beta5] ------------------------------------------------------------
[sagelib-8.0.beta5] 
[sagelib-8.0.beta5] sage/libs/pynac/pynac.pyx:1807:27: undeclared name not builtin: RBF

comment:9 Changed 4 years ago by git

  • Commit changed from 88e55d16a99c9f6767bd57472d185b6dff3c9631 to f5c35ff65d77df6f3193dd1fe709f0f7c2451bbc

Branch pushed to git repo; I updated commit sha1. New commits:

401237eMerge branch 'develop' into t/22877/atan2_of_complex_arguments_inconsistencies
f5c35ff22877: fix reality check

comment:10 Changed 4 years ago by rws

  • Status changed from needs_work to needs_review

comment:11 Changed 4 years ago by tscrim

  • Status changed from needs_review to positive_review

comment:12 Changed 4 years ago by vbraun

  • Branch changed from u/rws/atan2_of_complex_arguments_inconsistencies to f5c35ff65d77df6f3193dd1fe709f0f7c2451bbc
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.