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]


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments