7 ms·
A toy Mathematica interpreter in Haskell
- spitfire 10y agoI've written a Mathematica clone twice before. This guy got there much faster ( I was writing in C++). However both times I got the basic language going then realized it was the standard library that made Mathematica gold and abandoned it. Kudos to him and it's good work!
- tnecniv 10y agoThe library is really impressive. I wanted to do some feedback linearization of a system and started encoding the dynamics into Mathematica. I got about halfway done doing it on my own when I discovered there was a built in to do it for me.
- dekhn 10y agoMathematica's value is in the library, not the language. Wolfram etc put a ton of effort into making it do a good job on arbitrary problems. See the Mathematica book for me detail- for example, the root finding stuff is really neat.
- wfunction 10y agoAre the solver algorithms part of the standard library or part of the execution engine? i.e., are Solve/DSolve/etc. written in plain Mathematica code, or are they special somehow?
- tnecniv 10y agoYou can call external code from Mathematica, so they can be part of the standard lib and be special.
- wfunction 10y agoOK, but that doesn't answer my question...
- dekhn 10y agoThis is a great question. I suspect they use hard-coded stuff deep in the math kernel for efficiency. I remember the Mathematica book goes into detail on this, but I don't recall the specifics.
- Mathnerd314 10y agoIt would be interesting to benchmark it against the real thing.
- denfromufa 10y agoMathics is implementation of Mathematica (actually it is now called Wolfram language) using sympy, ply, and django. It also provides jupyter kernel. The original author was hired by Wolfram, but the project still lives on! http://mathics.github.io http://mathics.github.io Maxima is older than Mathematica and written in LISP. One of its contributors has written MockMMA to implement Mathematica in LISP: https://people.eecs.berkeley.edu/~fateman/lisp/ https://people.eecs.berkeley.edu/~fateman/lisp/
- wiz21c 10y agoI've looked at the github project for Mathics and didn't see any use of ply... Looks like they have written their own parser/lexer.
- denfromufa 10y agoYes, indeed - it is very weird! Because mathics still mentions ply in change.rst, but not used in code anymore: https://github.com/mathics/Mathics/blob/master/CHANGES.rst https://github.com/mathics/Mathics/blob/master/CHANGES.rst
- sn6uv 10y agoHidden in there (under 1.0) is "new recursive descent parser #416". We've only just finished 1.0 and haven't had a chance to announce it properly yet.
- denfromufa 10y agois this limitation in ply?
- sn6uv 10y agoWe previously used ply but ran into a few issues: The main issue was that generating the tables was extremely slow (~15mins). We solved this by packaging the tables, but when the version of ply changed a table regeneration was forced on our users. The recursive descent parser was also simpler and significantly more performant. There's a short write-up on the PR: https://github.com/mathics/Mathics/pull/416 https://github.com/mathics/Mathics/pull/416
- mrcactu5 10y agodoesn't this turn Mathematica into a scripting language for Haskell?
- gizmo686 10y agoNot any more than CPython is a scripting language for C. The Mathematica program is entirely interpenetrated. It does not have access to the underlying Haskell system.
- yunruse 10y agoThat's a bit of a shame, in some way. In the same way Hy [0] wraps Lisp's notation style around Python, it would be quite powerful if there was a way to 'wrap' Mathematica around Haskell; being able to combine the two would be interesting (and probably quite powerful). [0] http://docs.hylang.org http://docs.hylang.org
- dekhn 10y agoyou can use the Mathematica Kernel C API to make any language interface with mathematica (I did this with Python a long time ago). This typically involves the scripting langauge (or compiled language) invoking Mathematica functions, I;'m not 100% if Mathematica can then call back into Haskell or other language functions via a callback.
- bertiewhykovich 10y agoThis proves, once again, what a world-class, unbeatable tool Haskell is for writing toy interpreters.
- pjmlp 10y agoAny ML language is. When I was at the university[0], we were forbidden to use Caml Light, Lisp or Prolog in our compiler classes, because they would make the exercises too easy and so we wouldn't learn properly. [0] Haskell was still to be born and we had Miranda instead.
- paulsutter 10y agoYou might want to read his comment a little more carefully
- pjmlp 10y ago> unbeatable tool Haskell is for writing toy interpreters. unbeatable As if no other language has the same feature set.
- tome 10y agobertiewhykovich wasn't actually praising Haskell.
- pjmlp 10y agoThat isn't what I understand, maybe it lies on my lack of English skills.
- Wildgoose 10y agoI am English (and so a natural English speaker) and I read it in the exact same fashion that you did. I think the original poster may have been trying to be sarcastic, (it still isn't clear), but was so subtle about it that they failed for both of us.
- kccqzy 10y agoI've written a toy TeX interpreter/macro-expander as my first "large" Haskell program. It really made me think hard about both Haskell and TeX. I think this is a great way to learn two languages at the same time if you already have experience.