Skip to content

Commit 07c94c7

Browse files
committed
Add SympyForm[]
1 parent 86ac2d9 commit 07c94c7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

mathics/builtin/inout.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,35 @@ def apply(self, expr, evaluation) -> Expression:
19741974
return self.apply_python(expr, evaluation)
19751975

19761976

1977+
class SympyForm(Builtin):
1978+
"""
1979+
<dl>
1980+
<dt>'SympyForm[$expr$]'
1981+
<dd>returns an Sympy $expr$ in Python. Sympy is used internally
1982+
to implement a number of Mathics functions, like Simplify.
1983+
</dl>
1984+
1985+
>> SympyForm[Pi^2]
1986+
= pi**2
1987+
>> E^2 + 3E // SympyForm
1988+
= exp(2) + 3*E
1989+
"""
1990+
1991+
def apply_sympy(self, expr, evaluation) -> Expression:
1992+
'MakeBoxes[expr_, SympyForm]'
1993+
1994+
try:
1995+
# from trepan.api import debug; debug()
1996+
sympy_equivalent = expr.to_sympy()
1997+
except:
1998+
return
1999+
return StringFromPython(sympy_equivalent)
2000+
2001+
def apply(self, expr, evaluation) -> Expression:
2002+
"SympyForm[expr_]"
2003+
return self.apply_sympy(expr, evaluation)
2004+
2005+
19772006
class TeXForm(Builtin):
19782007
r"""
19792008
<dl>

0 commit comments

Comments
 (0)