SymPy –> Sage conversion#
The file consists of _sage_()
methods that are added lazily to
the respective SymPy objects. Any call of the _sympy_()
method
of a symbolic expression will trigger the addition. See
sage.symbolic.expression_conversion.SymPyConverter
for the
conversion to SymPy.
Only Function
objects where the names differ need their own _sage()_
method. There are several functions with differing name that have an alias
in Sage that is the same as the name in SymPy, so no explicit translation
is needed for them:
sage: from sympy import Symbol, Si, Ci, Shi, Chi, sign
sage: sx = Symbol('x')
sage: assert sin_integral(x)._sympy_() == Si(sx)
sage: assert sin_integral(x) == Si(sx)._sage_()
sage: assert sinh_integral(x)._sympy_() == Shi(sx)
sage: assert sinh_integral(x) == Shi(sx)._sage_()
sage: assert cos_integral(x)._sympy_() == Ci(sx)
sage: assert cos_integral(x) == Ci(sx)._sage_()
sage: assert cosh_integral(x)._sympy_() == Chi(sx)
sage: assert cosh_integral(x) == Chi(sx)._sage_()
sage: assert sgn(x)._sympy_() == sign(sx)
sage: assert sgn(x) == sign(sx)._sage_()
AUTHORS:
Ralf Stephan (2017-10)
- class sage.interfaces.sympy.UndefSageHelper#
Bases:
object
Helper class to convert sympy function objects to sage functions
EXAMPLES:
sage: from sympy import Function sage: f = function('f') sage: F = Function('f') sage: assert f._sympy_() == F sage: assert f == F._sage_()
- sage.interfaces.sympy.check_expression(expr, var_symbols, only_from_sympy=False)#
Does
eval(expr)
both in Sage and SymPy and does other checks.EXAMPLES:
sage: from sage.interfaces.sympy import check_expression sage: check_expression("1.123*x", "x")
- sage.interfaces.sympy.sympy_init(*args, **kwargs)#
Add
_sage_()
methods to SymPy objects where needed.This gets called with every call to
Expression._sympy_()
so there is only need to call it if you bypass_sympy_()
to create SymPy objects. Note that SymPy objects have_sage_()
methods hard installed but having them inside Sage as one file makes them easier to maintain for Sage developers.EXAMPLES:
sage: from sage.interfaces.sympy import sympy_init sage: from sympy import Symbol, Abs sage: sympy_init() sage: assert abs(x) == Abs(Symbol('x'))._sage_()
- sage.interfaces.sympy.sympy_set_to_list(set, vars)#
Convert all set objects that can be returned by SymPy’s solvers.
- sage.interfaces.sympy.test_all()#
Call some tests that were originally in SymPy.
EXAMPLES:
sage: from sage.interfaces.sympy import test_all sage: test_all()