# Trying to translate a symbolic differentiation performance benchmark to Julia

**URL:** <https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735>\
**Category:** Performance\
**Created:** [October 1, 2018, 1:56pm UTC](https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735 "2018-10-01T13:56:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olof\_Salberger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olof_salberger/32/4850_2.png) [@Olof\_Salberger](https://discourse.julialang.org/u/Olof_Salberger)\
**Post date:** [October 1, 2018, 1:56pm UTC](https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735/1 "2018-10-01T13:56:04Z")

</div>

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: [Swift code to compute the nth derivative of x^x · GitHub](https://gist.github.com/jdh30/e3c9cfe31dc311be20cc2984b3398545)  
OCaml: [https://gist.github.com/jdh30/f3d90a65a7abc7c9faf5c0299b002db3](https://gist.github.com/jdh30/f3d90a65a7abc7c9faf5c0299b002db3)  
F#: [https://gist.github.com/jdh30/ae98e3fb548b120eb7a16777fbce449f](https://gist.github.com/jdh30/ae98e3fb548b120eb7a16777fbce449f)  
Mathematica: [https://gist.github.com/jdh30/1b7eba8819dc8295b7a46b6e206efeb5](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](http://flyingfrogblog.blogspot.com/2017/12/does-reference-counting-really-use-less_26.html)

---

<div class="post-metadata">

**Author:** ![JonHarrop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonharrop/32/10167_2.png) [@JonHarrop](https://discourse.julialang.org/u/JonHarrop)\
**Post date:** [September 8, 2019, 12:23am UTC](https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735/2 "2019-09-08T00:23:43Z")

</div>

Any luck?

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [September 8, 2019, 1:46am UTC](https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735/3 "2019-09-08T01:46:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olof\_Salberger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olof_salberger/32/4850_2.png) [@Olof\_Salberger](https://discourse.julialang.org/u/Olof_Salberger)\
**Post date:** [September 9, 2019, 1:23am UTC](https://discourse.julialang.org/t/trying-to-translate-a-symbolic-differentiation-performance-benchmark-to-julia/15735/4 "2019-09-09T01:23:58Z")

</div>

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](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.
