Skip to content

Commit fd7b471

Browse files
authored
Merge pull request #435 from isuruf/atan2
Fix converting atan2 to sympy
2 parents 7b617f9 + eb78901 commit fd7b471

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,14 @@ class atan2(Function):
26352635
cdef Basic Y = sympify(y)
26362636
return c2py(symengine.atan2(X.thisptr, Y.thisptr))
26372637

2638+
def _sympy_(self):
2639+
import sympy
2640+
return sympy.atan2(*self.args_as_sympy())
2641+
2642+
def _sage_(self):
2643+
import sage.all as sage
2644+
return sage.atan2(*self.args_as_sage())
2645+
26382646
# For backwards compatibility
26392647

26402648
Sin = sin

symengine/tests/test_sympy_conv.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
function_symbol, I, E, pi, oo, zoo, nan, true, false,
33
exp, gamma, have_mpfr, have_mpc, DenseMatrix, sin, cos, tan, cot,
44
csc, sec, asin, acos, atan, acot, acsc, asec, sinh, cosh, tanh, coth,
5-
asinh, acosh, atanh, acoth, Add, Mul, Pow, diff, GoldenRatio,
5+
asinh, acosh, atanh, acoth, atan2, Add, Mul, Pow, diff, GoldenRatio,
66
Catalan, EulerGamma, UnevaluatedExpr, RealDouble)
77
from symengine.lib.symengine_wrapper import (Subs, Derivative, RealMPFR,
88
ComplexMPC, PyNumber, Function, LambertW, zeta, dirichlet_eta,
@@ -171,6 +171,7 @@ def test_conv7():
171171
assert acot(x/3) == acot(sympy.Symbol("x") / 3)
172172
assert acsc(x/3) == acsc(sympy.Symbol("x") / 3)
173173
assert asec(x/3) == asec(sympy.Symbol("x") / 3)
174+
assert atan2(x/3, y) == atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))
174175

175176
assert sin(x/3)._sympy_() == sympy.sin(sympy.Symbol("x") / 3)
176177
assert sin(x/3)._sympy_() != sympy.cos(sympy.Symbol("x") / 3)
@@ -185,6 +186,22 @@ def test_conv7():
185186
assert acot(x/3)._sympy_() == sympy.acot(sympy.Symbol("x") / 3)
186187
assert acsc(x/3)._sympy_() == sympy.acsc(sympy.Symbol("x") / 3)
187188
assert asec(x/3)._sympy_() == sympy.asec(sympy.Symbol("x") / 3)
189+
assert atan2(x/3, y)._sympy_() == sympy.atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))
190+
191+
assert sympy.sympify(sin(x/3)) == sympy.sin(sympy.Symbol("x") / 3)
192+
assert sympy.sympify(sin(x/3)) != sympy.cos(sympy.Symbol("x") / 3)
193+
assert sympy.sympify(cos(x/3)) == sympy.cos(sympy.Symbol("x") / 3)
194+
assert sympy.sympify(tan(x/3)) == sympy.tan(sympy.Symbol("x") / 3)
195+
assert sympy.sympify(cot(x/3)) == sympy.cot(sympy.Symbol("x") / 3)
196+
assert sympy.sympify(csc(x/3)) == sympy.csc(sympy.Symbol("x") / 3)
197+
assert sympy.sympify(sec(x/3)) == sympy.sec(sympy.Symbol("x") / 3)
198+
assert sympy.sympify(asin(x/3)) == sympy.asin(sympy.Symbol("x") / 3)
199+
assert sympy.sympify(acos(x/3)) == sympy.acos(sympy.Symbol("x") / 3)
200+
assert sympy.sympify(atan(x/3)) == sympy.atan(sympy.Symbol("x") / 3)
201+
assert sympy.sympify(acot(x/3)) == sympy.acot(sympy.Symbol("x") / 3)
202+
assert sympy.sympify(acsc(x/3)) == sympy.acsc(sympy.Symbol("x") / 3)
203+
assert sympy.sympify(asec(x/3)) == sympy.asec(sympy.Symbol("x") / 3)
204+
assert sympy.sympify(atan2(x/3, y)) == sympy.atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))
188205

189206

190207
@unittest.skipIf(not have_sympy, "SymPy not installed")
@@ -204,6 +221,7 @@ def test_conv7b():
204221
assert sympify(sympy.acot(x/3)) == acot(Symbol("x") / 3)
205222
assert sympify(sympy.acsc(x/3)) == acsc(Symbol("x") / 3)
206223
assert sympify(sympy.asec(x/3)) == asec(Symbol("x") / 3)
224+
assert sympify(sympy.atan2(x/3, y)) == atan2(Symbol("x") / 3, Symbol("y"))
207225

208226

209227
@unittest.skipIf(not have_sympy, "SymPy not installed")

0 commit comments

Comments
 (0)