writing an interpeter for mathematica language

128 views
Skip to first unread message

Ondrej Certik

unread,
Dec 24, 2007, 5:15:49 PM12/24/07
to sage-...@googlegroups.com
Hi,

I am thinking for a long time already of writing an interpreter, in
Python of course, of the Mathematica
language:

http://code.google.com/p/sympy/issues/detail?id=161

that would call Sage (or SymPy) as a backend to do the actual
calculations. People would
just take their Mathematica code, and execute it directly in Sage. So
that they could
use Sage immediatelly. See the issue above for some details. I quite
like the idea of
telling my professor - you don't have to download 450MB download and you don't
have to steal it in order to use it from home, you can just download 200MB Sage
and use your program freely everywhere. And when people start using Sage,
even though with Mathematica programs, I think they will just switch to Python
with new programs.

What are your thoughts - especially from the social point of view - is
it a bad or good idea?

Ondrej

David

unread,
Dec 24, 2007, 6:04:49 PM12/24/07
to sage-devel
From a social point of view, I think this would be a great idea.
However, Mathematica contains many functions that have no equivalent
in Sage. You might find yourself re-implementing Mathematica from
scratch.

-David

root

unread,
Dec 24, 2007, 7:20:15 PM12/24/07
to sage-...@googlegroups.com, sage-...@googlegroups.com
Ondrej

>I am thinking for a long time already of writing an interpreter, in
>Python of course, of the Mathematica
>language:

Such a language interpreter exists already, called MockMMA, I believe.
Check with Richard Fateman.

Tim

David Joyner

unread,
Dec 24, 2007, 6:23:25 PM12/24/07
to sage-...@googlegroups.com
Also, the "Legal questions" section of http://omath.org/wiki/Main_Page
might be worth reading before you get started.

Ondrej Certik

unread,
Dec 25, 2007, 5:32:21 AM12/25/07
to sage-...@googlegroups.com
On Dec 25, 2007 12:04 AM, David <dmlaw...@gmail.com> wrote:
>
> From a social point of view, I think this would be a great idea.
> However, Mathematica contains many functions that have no equivalent
> in Sage. You might find yourself re-implementing Mathematica from
> scratch.

You mean like the language, or Mathematical functions, that should be in Sage,
but are not yet implemented?

If the latter, then that's exactly the reason why I think it's useful
to write it -
you would just take any user contributed opensource Mathematica program,
run it through it and it will tell you - hey, Sage still cannot do this. And
then you'd say - let's get this fixed in Sage.

If the former, well, it needs to be written be someone more familiar with
writing interpreters. There is going to be a summer of code soon,
let's write it as an idea for a project. SymPy will take part and Sage
hopefully too, so someone may pick this idea up.

On Dec 25, 2007 1:20 AM, root <da...@axiom-developer.org> wrote:
>
> Ondrej
>
> >I am thinking for a long time already of writing an interpreter, in
> >Python of course, of the Mathematica
> >language:
>
> Such a language interpreter exists already, called MockMMA, I believe.
> Check with Richard Fateman.

Thanks for the tip, yes, we checked that (see the link from my first email),
we were thinking of using this. I don't like that it's in LISP, because
it's difficult to call Python (=Sage functions) from LISP. But maybe
there is some way how to reuse the code easily (I fear it's more difficult
to reuse it, instead of just writing it from scratch).

On Dec 25, 2007 12:23 AM, David Joyner <wdjo...@gmail.com> wrote:
>
> Also, the "Legal questions" section of http://omath.org/wiki/Main_Page
> might be worth reading before you get started.

Thanks for the link, there are actually many interesting links in there.

I read the original email from Wolfram to Richard Fateman, they are mainly
objecting against using the name Mathematica (which is fair, even though
copyrighting the very name Mathematica in the first place is just ridiculous,
it's like copyrighting Physics, Chemistry, etc.) and against using
some Mathematica functions, but it was written in 1991, I don't think they
can be serious on that.

I really suggest everyone to read the links from the Legal questions
from the link above.
If this is true (which maybe it's not), Wolfram is a company I don't
want to pay a single cent to.

Ondrej

William Stein

unread,
Dec 26, 2007, 12:01:51 PM12/26/07
to sage-...@googlegroups.com
On Dec 25, 2007 3:32 AM, Ondrej Certik <ond...@certik.cz> wrote:
> What are your thoughts - especially from the social point of view - is
> it a bad or good idea?

Duh. Of course it would be a very valuable thing to have. This thread
shouldn't be about whether to do this but _how_.

At a bare minimum such a translator is a clear gap in Sage functionality,
i.e., Sage can't do the following in total generality yet (see below for more
discussion):

sage: z = mathematica('code')
sage: z.sage() # -- convert mathematica expression back to Sage


Writing a "mathematica language" --> "Python language" translator is
the key step in implementing the above command in general.

> On Dec 25, 2007 12:04 AM, David <dmlaw...@gmail.com> wrote:
> > From a social point of view, I think this would be a great idea.
> > However, Mathematica contains many functions that have no equivalent
> > in Sage. You might find yourself re-implementing Mathematica from
> > scratch.
>
> You mean like the language, or Mathematical functions, that should be in Sage,
> but are not yet implemented?
>
> If the latter, then that's exactly the reason why I think it's useful
> to write it -

+1

> you would just take any user contributed opensource Mathematica program,
> run it through it and it will tell you - hey, Sage still cannot do this. And
> then you'd say - let's get this fixed in Sage.

+1

> If the former, well, it needs to be written be someone more familiar with
> writing interpreters. There is going to be a summer of code soon,
> let's write it as an idea for a project. SymPy will take part and Sage
> hopefully too, so someone may pick this idea up.

I hope this will happen. I noticed here:

http://www.tangentspace.net/cz/archives/category/computer-algebra/

that somebody names Alex claims to have tried exactly this last summer.
What happened? Amusingly Alex's motivation for doing this is his dislike
of Sage :-): "Part of the
reason I'm taking this on is because I'd not like to see SymPy turn into a
melange like Sage– the idea of tying together disparate CASes and
mathematical libraries with a glue language is aesthetically
unappealing to me..."
Maybe Alex much prefers to reinvent the wheel instead of building the car :-).


> > Such a language interpreter exists already, called MockMMA, I believe.
> > Check with Richard Fateman.
>
> Thanks for the tip, yes, we checked that (see the link from my first email),
> we were thinking of using this. I don't like that it's in LISP, because
> it's difficult to call Python (=Sage functions) from LISP. But maybe
> there is some way how to reuse the code easily (I fear it's more difficult
> to reuse it, instead of just writing it from scratch).

I think one of the design constraints for such a parser is that it
should be written
in Python or Cython, for ease of maintanence by Sage/Sympy developers, etc.
Also, should we imagine it converting Mathematics expressions into Python
expressions, that are then evaluated using Python.

Could somebody hack up a quick demo that parses just a little of Mathematica
to Python?

By the way, we will need almost *EXACTLY* this in order to implement the
following in general:

sage: z = mathematica('code')
sage: SR(z) # or z.sage() -- convert mathematica expression
back to Sage

We have something fairly sophisticated for doing exactly the above for
arbitrary Maxima expressions (it is in calculus.py). For functions that
have no Sage equivalent, we basically construct a lazy Python object
that uses Maxima to do the actual work -- the same could be done for
Mathematica until everything is implemented in Sage.

-- William

Ondrej Certik

unread,
Dec 26, 2007, 12:22:06 PM12/26/07
to sage-...@googlegroups.com

Well, I understand him. :) I also don't like that Sage is so big and
difficult to package in Debian.
Let's improve Sage. Unfortunately, I didn't manage
to meet him at Caltech at Scipy2007, but I think he's quite busy in school now.


> > > Such a language interpreter exists already, called MockMMA, I believe.
> > > Check with Richard Fateman.
> >
> > Thanks for the tip, yes, we checked that (see the link from my first email),
> > we were thinking of using this. I don't like that it's in LISP, because
> > it's difficult to call Python (=Sage functions) from LISP. But maybe
> > there is some way how to reuse the code easily (I fear it's more difficult
> > to reuse it, instead of just writing it from scratch).
>
> I think one of the design constraints for such a parser is that it
> should be written
> in Python or Cython, for ease of maintanence by Sage/Sympy developers, etc.
> Also, should we imagine it converting Mathematics expressions into Python
> expressions, that are then evaluated using Python.
>
> Could somebody hack up a quick demo that parses just a little of Mathematica
> to Python?

There is a GHOP SymPy project with some code, but it's just arithmetics:

http://code.google.com/p/google-highly-open-participation-psf/issues/detail?id=307

>
> By the way, we will need almost *EXACTLY* this in order to implement the
> following in general:
>
> sage: z = mathematica('code')
> sage: SR(z) # or z.sage() -- convert mathematica expression
> back to Sage
>
> We have something fairly sophisticated for doing exactly the above for
> arbitrary Maxima expressions (it is in calculus.py). For functions that
> have no Sage equivalent, we basically construct a lazy Python object
> that uses Maxima to do the actual work -- the same could be done for
> Mathematica until everything is implemented in Sage.

Exactly.

Ondrej

mabshoff

unread,
Dec 26, 2007, 1:33:34 PM12/26/07
to sage-devel


On Dec 26, 6:22 pm, "Ondrej Certik" <ond...@certik.cz> wrote:
> On Dec 26, 2007 6:01 PM, William Stein <wst...@gmail.com> wrote:
>
>
>
>
>
> > On Dec 25, 2007 3:32 AM, Ondrej Certik <ond...@certik.cz> wrote:
> > > What are your thoughts - especially from the social point of view - is
> > > it a bad or good idea?
>
> > Duh. Of course it would be a very valuable thing to have. This thread
> > shouldn't be about whether to do this but _how_.
>
> > At a bare minimum such a translator is a clear gap in Sage functionality,
> > i.e., Sage can't do the following in total generality yet (see below for more
> > discussion):
>
> > sage: z = mathematica('code')
> > sage: z.sage() # -- convert mathematica expression back to Sage
>
> > Writing a "mathematica language" --> "Python language" translator is
> > the key step in implementing the above command in general.
>
> > > On Dec 25, 2007 12:04 AM, David <dmlawre...@gmail.com> wrote:
> > > > From a social point of view, I think this would be a great idea.
> > > > However, Mathematica contains many functions that have no equivalent
> > > > in Sage. You might find yourself re-implementing Mathematica from
> > > > scratch.
>
> > > You mean like the language, or Mathematical functions, that should be in Sage,
> > > but are not yet implemented?
>
> > > If the latter, then that's exactly the reason why I think it's useful
> > > to write it -
>
> > +1
>
> > > you would just take any user contributed opensource Mathematica program,
> > > run it through it and it will tell you - hey, Sage still cannot do this. And
> > > then you'd say - let's get this fixed in Sage.
>
> > +1
>
> > > If the former, well, it needs to be written be someone more familiar with
> > > writing interpreters. There is going to be a summer of code soon,
> > > let's write it as an idea for a project. SymPy will take part and Sage
> > > hopefully too, so someone may pick this idea up.
>
> > I hope this will happen. I noticed here:
>
> > http://www.tangentspace.net/cz/archives/category/computer-algebra/
>
> > that somebody names Alex claims to have tried exactly this last summer.
> > What happened? Amusingly Alex's motivation for doing this is his dislike
> > of Sage :-): "Part of the
> > reason I'm taking this on is because I'd not like to see SymPy turn into a
> > melange like Sage- the idea of tying together disparate CASes and
> > mathematical libraries with a glue language is aesthetically
> > unappealing to me..."
> > Maybe Alex much prefers to reinvent the wheel instead of building the car :-).

hehe, and since SymPy can now be used from Sage his next point

"what's the point of dividing development effort between two Python-
based metaCASes?"

isn't that valid any more.

> Well, I understand him. :) I also don't like that Sage is so big and
> difficult to package in Debian.
> Let's improve Sage. Unfortunately, I didn't manage
> to meet him at Caltech at Scipy2007, but I think he's quite busy in school now.
>
>
>
> > > > Such a language interpreter exists already, called MockMMA, I believe.
> > > > Check with Richard Fateman.

I just read Fateman's review paper on Mathematica 2.0 and it is a
hoot :) - it was recommended on some web page while I was looking for
something related to BasicCAS and it is well worth the read.

> > > Thanks for the tip, yes, we checked that (see the link from my first email),
> > > we were thinking of using this. I don't like that it's in LISP, because
> > > it's difficult to call Python (=Sage functions) from LISP. But maybe
> > > there is some way how to reuse the code easily (I fear it's more difficult
> > > to reuse it, instead of just writing it from scratch).
>
> > I think one of the design constraints for such a parser is that it
> > should be written
> > in Python or Cython, for ease of maintanence by Sage/Sympy developers, etc.
> > Also, should we imagine it converting Mathematics expressions into Python
> > expressions, that are then evaluated using Python.
>
> > Could somebody hack up a quick demo that parses just a little of Mathematica
> > to Python?
>
> There is a GHOP SymPy project with some code, but it's just arithmetics:
>
> http://code.google.com/p/google-highly-open-participation-psf/issues/...
>

There is also Pythonica - see http://www.tildesoft.com/Pythonica.html
- but it license status is unclear and the project seemed to have
died.

>
> > By the way, we will need almost *EXACTLY* this in order to implement the
> > following in general:
>
> > sage: z = mathematica('code')
> > sage: SR(z) # or z.sage() -- convert mathematica expression
> > back to Sage
>
> > We have something fairly sophisticated for doing exactly the above for
> > arbitrary Maxima expressions (it is in calculus.py). For functions that
> > have no Sage equivalent, we basically construct a lazy Python object
> > that uses Maxima to do the actual work -- the same could be done for
> > Mathematica until everything is implemented in Sage.
>
> Exactly.
>
> Ondrej

Cheers,

Michael

gv...@macmail.com

unread,
Dec 26, 2007, 6:42:56 PM12/26/07
to sage-...@googlegroups.com
>>> I am thinking for a long time already of writing an interpreter, in
>>> Python of course, of the Mathematica
>>> language:

>> Such a language interpreter exists already, called MockMMA, I believe.
>> Check with Richard Fateman.

> Thanks for the tip, yes, we checked that (see the link from my first
> email), we were thinking of using this. I don't like that it's in LISP,
> because it's difficult to call Python (=Sage functions) from LISP. But
> maybe there is some way how to reuse the code easily (I fear it's more
> difficult to reuse it, instead of just writing it from scratch).

I assume you know about http://common-lisp.net/project/python-on-lisp/

I've never used it, but it looks promising. Calling lisp from Python
seems to be more difficult, without going to something like CLPython which
probably isn't an option.

Not that I'm an expert, I just hate to avoid things simply becuase they
are written in lisp, since I happen to like lisp.

-Ivan

--
MacMail - the Webmail service especially for Mac users worldwide
http://www.macmail.com

Ondrej Certik

unread,
Dec 27, 2007, 4:44:19 AM12/27/07
to sage-...@googlegroups.com
On Dec 26, 2007 7:33 PM, mabshoff

The GHOP task result was committed to SymPy, you can see the code here:

http://hg.sympy.org/sympy/rev/54c7ceb12a75


On Dec 27, 2007 12:42 AM, <gv...@macmail.com> wrote:
>
> >>> I am thinking for a long time already of writing an interpreter, in
> >>> Python of course, of the Mathematica
> >>> language:
>

> >> Such a language interpreter exists already, called MockMMA, I believe.
> >> Check with Richard Fateman.
>

> > Thanks for the tip, yes, we checked that (see the link from my first
> > email), we were thinking of using this. I don't like that it's in LISP,
> > because it's difficult to call Python (=Sage functions) from LISP. But
> > maybe there is some way how to reuse the code easily (I fear it's more
> > difficult to reuse it, instead of just writing it from scratch).
>

> I assume you know about http://common-lisp.net/project/python-on-lisp/
>
> I've never used it, but it looks promising. Calling lisp from Python
> seems to be more difficult, without going to something like CLPython which
> probably isn't an option.
>
> Not that I'm an expert, I just hate to avoid things simply becuase they
> are written in lisp, since I happen to like lisp.
>

I have nothing against the language as is. :)

But from the social point of view, it's not an option for me. For example the
project you mention is basically dead, there is only one (!)
unanswered email in the
mailinglist. 8 revisions in the svn repository - well, for me it's not
a promising project.

Of course, you can say, that it's opensource, we can fix it, etc.
That's true, but
I prefer to use tools, that other people use too. Being the only one using it
and fixing it, is imho, a bad strategy. That's why I prefer to use mainstream
language for CAS, not a minor language or a new languge that I develop myself.

Ondrej

Reply all
Reply to author
Forward
0 new messages