Converting common math notation to code

If you try to look up an algorithm for a problem you are trying to solve, you might stumble upon scientific papers or articles that explain how to calculate that solution.

Often times though, you might not encounter (pseudo-) code, but just math notations, where the writer assumed (or didn't have time or space in the publication...) that you can just go from there, regardless of your chosen programming language.

Now, from social media, I have seen many people coming from a non-math/computer science background being frustrated and intimidated by the mathematical notation used.

So, inspired by this post by Freya HolmΓ©r I saw a while ago https://bsky.app/profile/freya.bsky.social/post/3lb62ilqhcs26 I thought about just compiling a list of symbols and things you may encounter together with a very quick explanation and some words/readings that you can maybe better search for.

The code is in JavaScript, as it can run in your browser, but will look mostly the same in most major languages. For many of the examples, you can execute the code with example values and change that code directly in the text fields and run it again.

This is in no way a guarantee that you will be able to implement every paper you see immediately. Frankly, a lot of papers are not written clearly enough for that to work and sometimes use their own notation (hopefully they defined what they use!). Additionally, math notation, while generally pretty standard, does have some quirks that real languages have, like "dialects" and "creative usage". But hopefully, if you encounter a symbol or a bunch of symbols and indices that seem very complex, you can decipher them bit by bit using this basic guide 😊

Currently, this document contains the following symbols, which I have roughly grouped as follows:

Iteration: βˆ‘,∏,⋃,β‹‚\sum, \prod, \bigcup, \bigcap

General symbols: {∈,βˆ‹,∉,βˆ‹ΜΈ,Ξ΄ij,∘\{ \in, \ni, \not\in, \not\ni, \delta_i^j, \circ

Operations: n!,(nk)n!, \binom{n}{k}

Differentiation: f⁑′(x),df⁑dx,βˆ‚fβ‘βˆ‚x,βˆ‡f⁑\operatorname{f}'(x), \frac{d \operatorname{f}}{d x}, \frac{\partial \operatorname{f}}{\partial x}, \nabla \operatorname{f}

You can skip through or look at any specific sections that you are interested in!

Happy coding!