[Haskell-cafe] Mathematica

Andrew Coppin andrewcoppin at btinternet.com
Fri May 11 14:48:34 EDT 2007


> How difficult would it be to implement Mathematica in Haskell?

OK, you'll be glad to know I wasn't entirely serious when I wrote that. ;-)

There are 4 conceptually seperate aspects to Mathematica.

- First, there is the absurdly efficient arbitrary precision number 
crunching engine. It can run parallel, it handles sparse matricies the 
size of a small planet, and so forth.

- Second, there is the user interface, with nice maths typesetting, 
graph plotting, and (new in v6) animation features.

- Third, there is the Mathematica programming language. It's similar to 
Haskell in many ways - and different to it in any other ways.

- Finally, but not least, there is a code library the size of a small 
star system implementing just about every function, identity, algorithm, 
optimisation and statistic known to human kind.

Obviously that last part cannot ever be duplicated - hell I don't even 
know what a hypergeometric function *is*, much less why you'd care about 
it. I certainly couldn't implement it, never mind implement it 
efficiently. I think part of the reason Mathematica costs so damn much 
is the decades of R&D that Wolfram Research has poured into the system 
(and indeed continues to pour into it). That's one Very Big Library!

So, I can't copy the giant code library. But then, given that I don't 
know what a hypergeometric function is, will it matter if I can't use 
one? Not really, no.

The absurdly efficient number crunching is obviously not implementable 
in Haskell - or indeed virtually any language except assembly. Haskell 
(or at least GHC) already has bignums from the GMP, so arbitrary 
integers are quite efficient already. That'll have to do.

The pretty user interface is obviously not implementable in Haskell. 
(Probably the closest you could get is to write something in XUL, run it 
in Mozilla and get it to talk to the Haskell computation engine.)

And that leaves the Mathematica programming language. Well, it has some 
baroque syntax in places. But beyond that, it's basically a graph 
reduction system, like Haskell. Unlike Haskell, it's not statically 
typed. And the pattern matching is far more general. It seems it would 
be a fairly difficult task to implement the pattern matching engine 
properly. Alternatively, you could just "cheat" and write a program that 
recognises a hard-coded range of patterns and transforms them. 
Personally, I'd prefer to do things the way Mathematica does...

Aaaanyway, maybe next time I'll wait until April 1st before posting a 
message like this. ;-) [Hmm... we should add the quote above to the 
humour pages or something!]



More information about the Haskell-Cafe mailing list