A Mathematica interpreter in Typescript
spakhm.com
spakhm.com
I just wrote another post about perf benchmarking it against Mathematica proper-- https://www.spakhm.com/ts-wolfram-bench. Really surprised by the result, on the workload I tested Mathematica is only 2x faster than my barely optimized interpreter. A testament to the V8 engine, I didn't quite realize how ridiculously good V8 is until running this benchmark.
The amazing thing is how Mathematica starts working with just a few simple ideas, evaluator, backtracking pattern matcher, and a REPL.
were you able to implement Condition? how advanced is the pattern matcher? I got stuck after doing Blank BlankSequence and BlankNullSequence
https://github.com/anandijain/cas3.rs https://github.com/anandijain/cas8.rs
I'm new to Mathematica, so didn't know about `Condition` (thanks for mentioning it)
It was a little hard to get going, the parsing stage usually stops me because I never learned a good parser generator well enough to just start writing code. But once I got ts-parsec working, the rest was fairly easy. I think I got `D` to work within like two days. Was also very surprised how much you can do with so little!
Shoot me an email at coffeemug@gmail.com, let's chat more!
I suspect this benchmarks begint libraries more than term rewriting. A way to test that may be:
bif[1] := 0
bif[2] := 0
bif[n_] := bif[n-2] + bif[n-1]
Timing[Do[bif[15], 1000]]
You can check that neither tool is smart enough to solve that to bif[n_] := 0
by comparing running times for different large limits.As a quick double-check, fib(n)< 2^(n-1) and 2^14 is 16384.
So using bif is unnecessary and potentially harmful if it's optimized to zero.
Mathematica unfortunately has a lot of warts and rough edges clustered in specific fields (low level cryptography and binary manipulation heavy algorithms) which makes working with it a pain in the ass if you touch those fields regularly but outside of those specific fields it's fantastic.
And I can claim praise doubly so if you get the System Modeler/Modelica license as well. With those two together you can model a project using analog circuits, digital circuits, software running on hardware/RTOS, pneumatics, hydraulics, CFD, multibody physics, etc all running in a unified environment. And then of course from a high level you can tune parameters that drive all the parts of your model and test out swapping in different parts or running under different conditions.
You can do all the stuff that Mathematica and System Modeler are good for with other software packages cobbled together but that takes a lot more time to do and the integrations tend to not be nearly as clean. The only other product package on the market that compares would be MathWork's MATLAB + Simulink. The main difference being that Mathwork's products are more comprehensive in what all they cover but they tend to be less pleasant to work with.
IMHO the main sell is that you can do "all of the above" regardless of what domains you are working with without having to switch tools or negotiate different formats, etc.
So a systems engineer can model, simulate, and build a test framework for a project for all the bits (including the inside of the hardware and the physical world around it) without changing tools.
D[_?NumberQ, x_Symbol] = 0;
D[x_, x_Symbol] = 1;
D[Times[expr1_, expr2_], x_Symbol] = D[expr1, x] expr2 + D[expr2, x] expr1;
D[Plus[expr1_, expr2_], x_Symbol] = D[expr1, x] + D[expr2, x];
D[Sin[x_], x_Symbol] = Cos[x];
D[Cos[x_], x_Symbol] = -Sin[x];
D[f_Symbol[expr_], x_Symbol] := (D[f[x], x] /. x -> expr) * D[expr, x];
D[Power[expr_, p_Integer], x_Symbol] := p expr^(p - 1) * D[expr, x]; "
Absolutely brilliant! And simple! And terse! And brilliant!
See also: https://mathics.org/
It's a more mature and complete reimplementation of Mathematica, though still miles behind the original.
https://github.com/Mathics3/mathics-core/graphs/contributors
The project seems to have had a decent level of contributions for the last couple of years.