mathematica to sympy

1,145 views
Skip to first unread message

Comer Duncan

unread,
May 1, 2012, 10:49:54 AM5/1/12
to sy...@googlegroups.com
I have a set of Mathematica functions that I would like to translate
to sympy. I see the parsing.mathematica method and wonder what the
community thinks of the task of generalizing it to handle the
conversion of Mathematica modules to sympy? As the parser stands now
it seems to handle the translation of some Mma expressions. What I
need is more ambitious, I realize. Any ideas about resources i.e. ones
on people's back burners or some translators I am not aware of? This
does not strike me as an easy problem.

Thanks for your input.

Comer

krastano...@gmail.com

unread,
May 1, 2012, 11:00:38 AM5/1/12
to sy...@googlegroups.com
I doubt that any automated translation will produce quality code. The
style of Mathematica code is much more functional than the object
oriented python style. What you get from automatic translation will
not be human-readable (it will be python but very obfuscated).

So I am very pessimistic. However if you have any success with this it
will be great for sympy.

Aaron Meurer

unread,
May 1, 2012, 12:19:18 PM5/1/12
to sy...@googlegroups.com
This probably is doable, but we would need an actual parser in SymPy,
which is the difficult part. If we had that, adding rules for
Mathematica functions would ideally not be hard. See
https://github.com/sympy/sympy/wiki/parsing for some ideas on parsing.

More realistically, in
http://code.google.com/p/sympy/issues/detail?id=161, it is suggested
that for Maxima, Sage can be used. So I'm wondering if Sage, or maybe
some other project has a parser for Mathematica that can put it in a
form that SymPy can read, or at least on close.
http://code.google.com/p/sympy/issues/detail?id=2864 is also related
to this.

Can you give an example of a Mathematica expression that you want to parse?

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>

redsto...@163.com

unread,
Oct 8, 2014, 10:16:02 PM10/8/14
to sy...@googlegroups.com
you can try this expression for a test 
(-6x^2-x-7)(2x^3+3x^2-2x-5)

在 2012年5月2日星期三UTC+8上午12时19分18秒,Aaron Meurer写道:

Richard Fateman

unread,
Oct 9, 2014, 12:15:22 AM10/9/14
to sy...@googlegroups.com
There are at least 2 open source parsers for Mathematica code.

The trivial stuff  -- parsing x Sin[x]  into    x*sin(x) equivalent could be
done by following directions in any intro to compilers book.

The rest of the stuff, which requires pattern matching, simplification, and
a whole collection of specific commands all sitting inside the Mathematica
rule-based evaluation mechanism ...  well you won't get that by translating
naively into python.

It's like saying you can translate Lisp into C.  Sure.   But if you want to
execute it, you need a whole bunch of stuff, like a garbage collector,
arbitrary-precision integers,  etc etc etc   that you don't get by translating
(+ a b)     into a+b.

Francesco Bonazzi

unread,
Oct 9, 2014, 3:27:21 AM10/9/14
to sy...@googlegroups.com
Mathics somewhat translates Mathematica to SymPy.

https://github.com/poeschko/mathics

http://www.mathics.org/

I tried to play with Mathics' code a while ago, unfortunately there is very little documentation. In any case, Mathics has a parser for Mathematica's code, it builds its own AST object mapping, and calls SymPy to perform the algorithmic evaluation. You could try to use it and put a debugging breakpoint on the SymPy calls, but that's still hard to do.

Mathics has also a Mathematica compatible pattern matcher.

Technically, I think that if we add assumptions-awareness and specificity sorting to the patterns containing wild cards, and default/optional wildcards, SymPy's patterns would become much more similar to those of Mathematica (except for excessive matches like inverse functions and powers).

Garvin Li

unread,
Oct 9, 2014, 3:52:45 AM10/9/14
to sy...@googlegroups.com
Hi,I found that your email address is "163.com".So ,I guess maybe you are Chinese same to me ,shall we have a chart about sympy? My email:garv...@garvinli.com
Looking forward to your reply.

在 2014年10月9日星期四UTC+8上午10时16分02秒,redsto...@163.com写道:

Denis Akhiyarov

unread,
Oct 9, 2014, 10:00:08 AM10/9/14
to sy...@googlegroups.com
Probably the easiest is to transfer your Mathematica code to Fortran or C using built-in and third-party facilities within mathematica, and then call this C/Fortran from python.

Mathics is under GPL license, incompatible with Sympy?

here is a relevant SAGE discussion with some partial solutions:

and also scala parser:

Francesco Bonazzi

unread,
Oct 10, 2014, 4:43:57 AM10/10/14
to sy...@googlegroups.com


On Thursday, October 9, 2014 4:00:08 PM UTC+2, Denis Akhiyarov wrote:
Probably the easiest is to transfer your Mathematica code to Fortran or C using built-in and third-party facilities within mathematica, and then call this C/Fortran from python.

Mathics is under GPL license, incompatible with Sympy?


Inclusion into SymPy's code is not permitted by the GPL terms, but SymPy may be included and/or linked to Mathics (the converse is compatible).


How do you call Scala from Python?
Reply all
Reply to author
Forward
0 new messages