[Haskell-cafe] Implementing Mathematica

Jon Harrop jon at ffconsultancy.com
Fri Jun 1 01:10:04 EDT 2007

On Thursday 31 May 2007 20:56:47 Andrew Coppin wrote:
> Jon Harrop wrote:
> > If you write a simple, numerically-intensive program that runs in the
> > Mathematica rewriter then its performance is about 100-1,000x slower than
> > that of a native-code compiled language like Haskell. Mathematica is
> > often 30x slower than interpreted OCaml bytecode.
> Is this before or after compiling the Mathematica code?

The 100-1,000x slower is without compilation in Mathematica. I found the ray 
tracer to be 30x slower in compiled Mathematica compared to OCaml bytecode 
(OCaml native code is much faster still).

So GHC will easily beat Mathematica on such tasks.

Incidentally, once you've reimplemented the core Mathematica language in 4 
days, you might like to reimplement their compiler. I believe their spec is 
freely available but you could just redo the whole thing yourself. You could 
probably extend it and optimise it quite easily. For example, it doesn't 
support recursion and I don't think it does type inference.

> I don't know, I thought one of the big advantages of Mathematica was
> supposed to be that it can transform problems into the most efficiently
> solvable form, select between multiple algorithms, etc.

On certain very specific problems, yes. So it might check to see if a matrix 
is symmetric and use a faster routine when possible. As far as the languange 
itself is concerned, it is fairly mundane.

> And I mostly use it to do insane things like give me parametric
> solutions to giant polynomials and so forth... ;-)

I used it to take integrals, do lots of FFTs, some general data analysis and 
lots of graph plotting. There are plenty of other computer algebra packages 
that could handle the integrals (although I never found any were better than 
just doing it by hand) and general-purpose languages that are better suited 
to the analysis, so now I just use it as a graph plotter.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists

More information about the Haskell-Cafe mailing list