Trying to translate a symbolic differentiation performance benchmark to Julia

Hi, I was interested in translating Jon Harrop’s symbolic derivatives benchmark to Julia, but since the original code is really heavy on ADT’s and pattern matching I don’t really have a good intuition for what style would work best when translating it, especially if I want to take advantage of the small union optimization. AFAIK, Julia doesn’t allow union types to be recursive as in const Uniontype = Union{Int,Node1{Uniontype},Node2{Uniontype}…} .

The benchmark source code for various languages is in the following links:
Swift: https://gist.github.com/jdh30/e3c9cfe31dc311be20cc2984b3398545
OCaml: https://gist.github.com/jdh30/f3d90a65a7abc7c9faf5c0299b002db3
F#: https://gist.github.com/jdh30/ae98e3fb548b120eb7a16777fbce449f
Mathematica: https://gist.github.com/jdh30/1b7eba8819dc8295b7a46b6e206efeb5

The blog post with the actual performance comparisons is here: http://flyingfrogblog.blogspot.com/2017/12/does-reference-counting-really-use-less_26.html

1 Like

Any luck?

1 Like

You might want MLStyle to get syntax support on ADTs and pattern matching.

1 Like

I did end up using MLStyle for the port, since porting the code is simply too tedious without using a dedicated @match macro that supports a wide range of patterns.

Made a quick port of the benchmark at https://gist.github.com/saolof/5743c28b22b5308045dafe926b3e126d
I haven’t spent any time optimizing it and it is more or less a straight copy of the OCaml version, except for leaning a bit more on the Julia standard library when appropriate.