Translating Mathematical Notations Into Code You Can Use

Not all programmers come from a maths background. In fact, if you’re self-taught, chances are you’ve stumbled on a useful mathematical formula (say, on Wikipedia), except its in formal notation and might as well be Sanskrit. Sometimes you can get lucky and find code snippets, but if you’re reading straight from research papers, this isn’t always an option. Fortunately, you can translate it, if you have the time.

Image: Behdad Esfahbod / Flickr, licensed under Creative Commons 2.0

Developer Matt DesLauriers has put together a guide on GitHub, called “Maths-as-code”, that explains common mathematical notation in code terms. He uses JavaScript for the examples, which should be familiar enough to those who use syntactically similar languages such as C#.

If you’re curious, here’s the start of the explanation of sigma (Σ):

Sadly, there isn’t an automated way to convert notation to code, but at the very least you can use this to make the process easier.

Math as code [GitHub, via Reddit]

Have you subscribed to Lifehacker Australia's email newsletter? You can also follow us on LinkedIn, Facebook, Twitter and YouTube.

Trending Stories Right Now