Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix converting atan2 to sympy #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,14 @@ class atan2(Function):
cdef Basic Y = sympify(y)
return c2py(symengine.atan2(X.thisptr, Y.thisptr))

def _sympy_(self):
import sympy
return sympy.atan2(*self.args_as_sympy())

def _sage_(self):
import sage.all as sage
return sage.atan2(*self.args_as_sage())

# For backwards compatibility

Sin = sin
Expand Down
20 changes: 19 additions & 1 deletion symengine/tests/test_sympy_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function_symbol, I, E, pi, oo, zoo, nan, true, false,
exp, gamma, have_mpfr, have_mpc, DenseMatrix, sin, cos, tan, cot,
csc, sec, asin, acos, atan, acot, acsc, asec, sinh, cosh, tanh, coth,
asinh, acosh, atanh, acoth, Add, Mul, Pow, diff, GoldenRatio,
asinh, acosh, atanh, acoth, atan2, Add, Mul, Pow, diff, GoldenRatio,
Catalan, EulerGamma, UnevaluatedExpr, RealDouble)
from symengine.lib.symengine_wrapper import (Subs, Derivative, RealMPFR,
ComplexMPC, PyNumber, Function, LambertW, zeta, dirichlet_eta,
Expand Down Expand Up @@ -171,6 +171,7 @@ def test_conv7():
assert acot(x/3) == acot(sympy.Symbol("x") / 3)
assert acsc(x/3) == acsc(sympy.Symbol("x") / 3)
assert asec(x/3) == asec(sympy.Symbol("x") / 3)
assert atan2(x/3, y) == atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))

assert sin(x/3)._sympy_() == sympy.sin(sympy.Symbol("x") / 3)
assert sin(x/3)._sympy_() != sympy.cos(sympy.Symbol("x") / 3)
Expand All @@ -185,6 +186,22 @@ def test_conv7():
assert acot(x/3)._sympy_() == sympy.acot(sympy.Symbol("x") / 3)
assert acsc(x/3)._sympy_() == sympy.acsc(sympy.Symbol("x") / 3)
assert asec(x/3)._sympy_() == sympy.asec(sympy.Symbol("x") / 3)
assert atan2(x/3, y)._sympy_() == sympy.atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))

assert sympy.sympify(sin(x/3)) == sympy.sin(sympy.Symbol("x") / 3)
assert sympy.sympify(sin(x/3)) != sympy.cos(sympy.Symbol("x") / 3)
assert sympy.sympify(cos(x/3)) == sympy.cos(sympy.Symbol("x") / 3)
assert sympy.sympify(tan(x/3)) == sympy.tan(sympy.Symbol("x") / 3)
assert sympy.sympify(cot(x/3)) == sympy.cot(sympy.Symbol("x") / 3)
assert sympy.sympify(csc(x/3)) == sympy.csc(sympy.Symbol("x") / 3)
assert sympy.sympify(sec(x/3)) == sympy.sec(sympy.Symbol("x") / 3)
assert sympy.sympify(asin(x/3)) == sympy.asin(sympy.Symbol("x") / 3)
assert sympy.sympify(acos(x/3)) == sympy.acos(sympy.Symbol("x") / 3)
assert sympy.sympify(atan(x/3)) == sympy.atan(sympy.Symbol("x") / 3)
assert sympy.sympify(acot(x/3)) == sympy.acot(sympy.Symbol("x") / 3)
assert sympy.sympify(acsc(x/3)) == sympy.acsc(sympy.Symbol("x") / 3)
assert sympy.sympify(asec(x/3)) == sympy.asec(sympy.Symbol("x") / 3)
assert sympy.sympify(atan2(x/3, y)) == sympy.atan2(sympy.Symbol("x") / 3, sympy.Symbol("y"))


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


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