Ask HN: What are some important math topics every programmer should know?

59 points by sph ↗ HN
I'm a self taught full stack developer who's flunk out of high school and did not have the chance to study "advanced" maths such as calculus, statistics and probability.

In 10 years of experience I never felt the need for any of it, and a recent contract requires, for a simple feature, the basic knowledge of derivatives (given a polynomial curve, graph it in a dotted line when it falls off from the local maxima).

I've started catching up on courses on Khan Academy and having a great time. My question is, which math (or physics) knowledge have you actually used in your programming career, and think it's mandatory for software engineers to know?

PS: If anyone from Khan Academy is reading this, thank you for your project, you're doing a great service for humanity.

64 comments

[ 3.6 ms ] story [ 65.8 ms ] thread
I've used a lot of math in my work. But the point is, I have a lot of math to use. So many people say "I've never used math" or "Oh look, another day without using algebra," but really what's happening is that they don't realise that there are times when they can use mathematical thinking and techniques.

It's blub all over again.

So to be specific, I've used calculus in a bunch of places, Linear Algebra, Markov Chains, Quaternions, Topology, and Graph Theory is just everywhere. It's impossible to make recommendations - there's far too much, and what you need to do is get started on something, and keep track of things that look like they'll be interesting, useful, or the basis of something needed.

In part this is why I've started the "Topics In Maths" project I'm working on.

So good luck - keep pursuing stuff, and I hope you get more and more intrigued by what you find.

This is really important. I've seen so many people just thrash at problems because they did not have the math to solve it. It's not so much that they didn't take the course or whatever, but that they didn't even understand that there was a systematic way to find the answer.

You almost can't be a programmer these days without knowing about data filtering and validation. And I can't tell you how many ad-hoc ways I've seen people try to filter data that was worse than useless - it harmed the quality of the data.

So, linear algebra, robust statistics, optimal and non-optimal estimation, and some classification theory will take you a very long way in many jobs.

If this isn't clear - PageRank (the original google search algorithm) is just applied linear algebra. Netflix recommendations? Linear algebra. Spam filtering? Bayesian filtering. Medical imaging? linear algebra, Bayesian filtering. It goes on and on.

Math is not mandatory to be in the field, but there are a vast number of really interesting jobs which you have no hope of doing without a fair amount of math.

This is why I feel so sad when yet another "college is for suckers" thread starts on HN. It takes a lot of concentrated work and practice to develop the math skills and to learn to apply them, and college is the last chance you have to do that in a concentrated way. You just might learn about eigenvectors and invent the next PageRank!

graycat always has interesting posts about how he has used in his career - do a search.

Linear algebra also allows for things like

Facial recognition, error correction/detection, linear programming optimization, signal analysis, graphics, machine learning, quantum computing...

The list just goes on and on.

Can you give some examples of problems you've solved?
Briefly, tracking small radar targets in sea and rain clutter, compressing radar and audio streams, classification of radar signatures, classification of vessel behaviour, and more. I can't go into too much detail because it's all commercial in confidence, but those are the sorts of things I've worked on most recently.
If you don't have a hammer, nothing looks like a nail.
Graphs.
Good call.. I had to learn them when I was building a Bitcoin arbitrage bot, and how to implement the Bellman-Ford algorithm.

Also, any game programmer worth his name needs to understand them for pathfinding algorithms (A*, Dijkstra, etc.)

What is a program but a directed graph?
(comment deleted)
Yes - brings to mind computational/systems biology, where you have plenty of networks to analyse (gene expression, protein interaction, etc.)
Depends on the industry I suppose. I work in the financial industry and I have used linear algebra quite a bit and graph theory as well. I would say linear algebra in pretty important as it is also used heavily in graphics/games.
Every programmer should know? None.

Middle school maths is "good enough" for the majority of programming jobs (85%+). There are of course niche programming jobs in: finance, statistics, AI, CS, gamedev, and so on but if you look at the programming industry as a whole those jobs are a tiny proportion overall (the majority are "boring" enterprise-style developers and web-developers: Java/Tomcat, ASP.net/MVC, PHP, RoR, and so on).

The thing is that the "boring"/average programming jobs are the silent majority. You'll likely read in this thread tons of obscure topics and how they apply to obscure jobs, but the reality is that few programmers work in those industries, but nobody [else] is going to post just to admit that for their job they don't need any maths day to day because it is boring and redundant.

This is JUST my opinion, but if you want to learn obscure topics, you're better off spending time learning CS topics (e.g. floating point number representation/bugs/limitations, encryption/hashing/etc, binary representations, assembly, kernel inner workings, CPU inner workings, and even borderline electronics). While advanced maths has a place in some jobs, advanced CS topics seem to be useful even on the web-stack/enterprise-stack to understand where bottlenecks might be materialising.

Maths is not useless. But most programmers won't use a lot of it day to day, if for no other reason that they have a library which does it for them (and they'd be foolish to reinvent the wheel).

I'd say its really high school math. There are a number of concepts I use from 9th-12th grade math on a regular basis [e.g. DeMorgan's laws was in 12th grade iirc, most of the Algebra I use was also from 9th-10th grade] and I'm not in any of the niches you mentioned or any of the niches I'd consider "math heavy".

I'd agree that college math is really only relevant to specific niches in the industry but I think the niches are larger than you mentioned. [e.g. Distributed systems, flight guidance]

I think you might be using more math than you realize. You might not have LEARNED about it in a math class, but it is math. Set theory, statistics, etc.... I know a lot of what I do involves those things.
I like this answer. But I also think that if you want to be a great programmer, knowing some math will help you tackle great problems.

For example reddit upvoting/downvoting system can't sort posts by (number of upvotes)/(number of downvotes) because new posts with just a few upvotes would get sorted on top. It can't sort posts by (number of upvotes) - (number of downvotes) because then only old posts would get in the frontpage.

You can try to hack your way through a better solution (and I believe that's what HN did with a dumb "gravity" system where time makes posts lose points). But the clever solution here is to use Confidence Intervals[1]. You choose a margin of error and you enter the values in the formula and tadaaa! You don't even have to comprehend every part of the concept here, but knowing that it exists already helps you creating better code.

[1]: http://en.wikipedia.org/wiki/Confidence_interval

> you're better off spending time learning CS topics (e.g. floating point number representation/bugs/limitations, encryption/hashing/etc, binary representations, assembly, kernel inner workings, CPU inner workings, and even borderline electronics)

This. These are things that will directly affect the quality of your code.

Blub.

To expand on that, read Paul Graham's essay "Beating the Averages."

http://www.paulgraham.com/avg.html

You're stating, unequivocally, that math doesn't directly affect the quality of your code. In fact, in seems to me[0] that the vast majority of people who repeatedly declare that math is useless or of minimal use in coding are themselves not qualified in math. To them it's just all abstract nonsense that they don't need.

Contrast that with people who have got deep qualifications in math who say, repeatedly, that it does affect the quality of their code, and it does help.

What do you make of that?

If you don't have any background in math then you won't have the knowledge and experience to see when it will be useful.

[0] I'd love to see a proper survey/study of this.

> The thing is that the "boring"/average programming jobs are the silent majority.

Let's not forget about all the engineers (making planes, trains, automobiles, and all sorts of other things) who use "advanced math" daily and write software. It's not relevant to OP's question, but we sure like to ignore them. [1]

[1] Is there any data to back up that "boring" programming jobs are actually the majority?

Every good programmer should know? At least abstract Algebra.

The thing about advanced maths is that it forces you to think about abstractions in ways that not even programming forces you to think. You can get pretty far programming without much abstraction, but you can't understand the mathematical fact that any group of order four is either cyclic or isomorphic to the Klein-four group[1] without thinking in a really abstract way. The more you study these abstractions in advanced maths, the better you get at thinking in an abstraction-first way.

A great book that just came out this year explains this really well by taking you from a basic algorithm to an abstract implementation, explaining the maths along the way (from multiplication to abstract algebra and number theory). It's titled From Mathematics to Generic Programming and I recommend it to anyone who wants to understand more of what I mean[2].

--

[1]: http://math.stackexchange.com/questions/165341/any-group-of-...

[2]: http://www.amazon.com/Mathematics-Generic-Programming-Alexan...

There are many ways to learn about abstraction, and abstract algebra is not the only one. I.e., assorted facts about groups are mostly irrelevant, and if you can learn how to think abstractly by studying, say, graph theory, why would you need abstract algebra?
I completely agree. Logic or philosophy can help one to practice complex abstraction. Even the study of law (as in legal code) or religion involves abstract thinking.
This notion that you do not need any kind of mathematical knowledge is widespread.

Ever tried to delete 1 000 000 files in Windows Explorer ? Select All, Shift delete ?

Takes ages. Why ? because Explorer creates a list of files to be deleted by adding one after the other to the list while updating the screen.

del bak\[asterisk.asterisk] /S /Q /Y >NUL takes some time, but is way faster.

rmdir bak drops the entire directory and returns instantly.

The difference ? O(n^2) versus O(n) versus O(1)

Useful knowledge ? ... possibly.

Even then 'just' programming a website, winging full stack or doing anything worthwile you can get by without knowledge, but it sure helps...

P.S. how do you escape an asterisk ? Even google didn't know / i didn't find it...

I work in digital advertising (sorry, world), and use linear algebra often. ... I suck at it, so I usually get somebody with a math degree to help me out.
Like other commenters have said, it depends a lot on what programs you're writing. You might want to know some harmonic analysis if you're writing audio software. On the other hand, if you're making user interfaces, knowing a little bit of geometric math (vector algebra, trigonometry, calculus) can go a long way.
DeMorgan's laws. (You'll probably end up negating a boolean expression at some point. Don't screw it up!)
All the comments in this thread are really useful (thanks, everybody), but you finally gave me a name for something I badly need when refactoring overcomplicated "if" expressions.

I usually get a pen and paper and write the truth table by hand to understand how to simplify the logic.

Thanks!

Bottom line: You're constructing and executing math and likely do not realize how much math you are constructing and executing on a daily basis. This includes formal and experimental advanced theoretical mathematics, probability, statistics and number theory in some cases. Some academics do not like to hear this, however, you deal(industry term) in functions, variables, minimums, maximums, rates of change, statistics, probability and overall, symbols. If you're duplicating the next facebook (as facebook did with myspace and myspace, friendster, etc etc), snapchat or yo app your likely not directly engaged in much math or innovation compared to inventing something on the algorithmic level like Google. If you are creating or inventing something new on the software engineering level including the algorithmic level, then you are certainly creating a lot of theoretical math and perhaps without even knowing it. This is key.

Here's a good book to understand how you've leap-frogged certain aspects of mathematics via true and real innovative Computer Science: (the Einstein of India. Every country and family has their very own Einstein, you might be one of them.)

The Man Who Knew Infinity: A Life of the Genius Ramanujan http://www.amazon.com/The-Man-Who-Knew-Infinity/dp/067175061...

Binary numbers (1010 it's off to work we go!)

Boolean logic.

How numbers are encoded in binary. How ints, doubles, floats, etc. work under the hood on a computer. Can be learned on the job.

set theory, equivalence relations, partial and total orders, algebra (monoids, lattices, ...), graphs
I find understanding of symbolic logic to be very important.

For UI programming of any sort, an understanding of basic geometry is very important, including graphing. There have been times in my short career where I have had to implement pixel perfect renderings due to the types of problems that were being solved.

Sometimes I feel like I should have paid more attention in class, like when looking at an expression and wondering if it could be simplified or if all the parens are really necessary
Starting with the easiest:

boolean logic, boolean algebra

What does O(n) mean?

The compound interest formula

matrix/linear algebra, numerical analysis

The statistics behind A/B testing

numerical approximation of a derivative, integral, differential equation

Read "numerical recipes in C"

High school and even undergraduate college gives you a rather late-19th, early-20th century view of what "math" is. A lot of math doesn't involve "numbers", per se. So, as a programmer in your self-described situation, my advice is to work through the math in Structure and Interpretation of Computer Programs [1], commonly referred to as SICP, and to do so seriously.

Does it not feel like math? That is, alas, a deficiency in your education, but don't feel bad, it's a deficiency in most people's education. It's math, and directly applicable to what you are doing in life.

Now, these other suggestions are fine too. But I find it to be very, very practically useful to be able to take apart the very concepts of computation, and thereby learn how to reassemble them to suit my whims, and not be swept away by the fads of the day.

The SICP is a concentrated load of exactly what you missed out on by not getting a formal computer science education. I honestly would likely prefer someone with 3 or 4 years of industry experience and the ability to prove they really worked through the SICP (not just read over it once, but worked it through) over someone with a 4.0, a bachelor's degree, and nothing else.

[1]: https://mitpress.mit.edu/sicp/full-text/book/book.html

My first two jobs out of college were in FinTech -- lots of math there (partial derivatives, linear algebra, numerical analysis methods, stats and more)

Then later, I was in image processing -- a lot of linear algebra. Anything with recognition has mathematical concepts.

I'm tutoring a teen in game programming and keep having to take breaks to teach more and more trig.

Having a good grasp of probability and statistics will serve you in almost anything you do.

You need much more math to survive in the field beyond the appcrap/webcrap level. Here's the description of a 3D SLAM library for robotics. This is what looks at an image from a moving camera and builds a map of where the camera is and of its surroundings.

"RobotVision is a library for techniques used on the intersection of robotics and vision. The current version (1.1) comprises bundle adjustment, feature initialisation pose-graph optimisation, and 2D/3D visualisation among other things.

The bundle adjustment class follows the classical approach - the first order sparseness structure is exploited using the Schur complement. However, compared to other straight-forward implementations, it has the following features: The second-order sparseness structure -- not all landmarks are visible in all frames - is exploited using sparse Cholesky factorisation (using the CSparse library). Optionally, the implementation supports the use of robust kernels in order to guard against spurious matches. Also, the implementation generalises over different transformations, landmarks and observations using template meta programming. Among others, SE3 pose transformation with 3D Euclidean points and 2D image observations are provided as a default implementation for monocular SLAM. Furthermore, the bundle adjustment class also contains an information filter for inverse depth feature points which can be used efficiently for feature initialisation within a keyframe-based monocular SLAM framework.

The pose-graph optimisation framework is using Levenberg-Marquardt, whereas the sparse Hessian is dealt with using sparse Cholesky factorisation (CSparse). Again, it generalises over different transformations. Apart from the standard rigid transformation SE3, it also supports 3D similarity transformations Sim3. In other words, it can also deal with scale drift which occurs in monocular SLAM.

Both, the bundle adjustment class as well as the pose-graph optimisation class uses Lie theory. Poses transformations (SE3, Sim3) are represented on a manifold/ as a Lie group while incremental updates are done in the tangent space around the identity/Lie algebra. In this way, we achieve a minimal representation during optimisation while ensuring that we are always far from singularities."[1]

That's only some of what it takes today to do robotics.

The world is about to change. Tomorrow, everyone will discover that powerful humanoid robots are here.[2]

[1] https://openslam.org/robotvision.html [2] http://www.theroboticschallenge.org/

I work in quantitative finance and find that basic probability and statistics help a lot in this field. In fact, they are almost like prerequisites for hiring.

That said, I think everyone would benefit by reading a bit about these subjects, whether or not they’re developers. We seem to have a built-in tendency to underestimate the effect of randomness in life (see Fooled by Randomness and How to Lie with Statistics). To counteract that, I find statistical methods (e.g., hypothesis testing, confidence intervals, etc.) to be very useful tools to keep in mind. Having basic familiarity with such tools may not necessarily make us better programmers but it'll probably make us more rational decision makers in the general sense.

Every programmer should be able to convert between decimal, binary, and hexadecimal notation, and be able to understand the bit-shift and bitwise operations. That's it. Programming is too diverse a field for any one branch of mathematics to be required for all of them.

Many fields require linear algebra, geometry, trigonometry, graph theory, and discrete math.

Graphics and 3D-modeling programmers will need to know matrices (possibly also quaternions) and vector math. You may also need screw theory and geometric algebra.

Engineering support will need to know calculus.

AI will need probability.

Scientific support will need statistics.

Cryptography will require all the maths that exist, plus some that haven't been invented yet.

Business support will need to know sexagesimal math--for the clock-watching. You will really need to know when 5:00 rolls around, so you can stop working on your stupid CRUD app.

In short, the more math you know, the more likely it is that you will able to apply it to any given program. And the more you know, the easier it will be to pick up something you need and don't have already. Practically speaking, you are better off seeking a shallow knowledge of a broad array of disciplines, and deepen your knowledge of specific topics as needed.

If you know imaginary numbers, that makes it easier to learn about duals, quaternions, null vectors, spacetime manifolds, and such.

Ai/data sciences uses a lot of partial derivatives, linear algebra, etc
The jobs I've held have not been particularly 'mathy' but knowing linear algebra, numerical analysis and statistics have come in very handy over the years.

Knowing how to 'read' math has been helpful digesting Computer Science papers too.

Best math class I took in college was discrete math, it is extremely applicable to computer programming.

http://en.wikipedia.org/wiki/Discrete_mathematics

Highlights include Combinatorics, Set Theory, Graph Theory, etc. Great stuff, I liked it so much I kept the book even though the book store offered me $80 for it.

In the first year of my CS degree we studied some rudimentary CS-related mathematics.

Some of it I barely used beyond the exam, but there are two topics which rise high above the rest in terms usefulness when working on real-world web apps.

Set Theory: http://en.wikipedia.org/wiki/Set_theory

and

Combinatorics: http://en.wikipedia.org/wiki/Combinatorics

I can't tell you how useful these branches are in terms of the indirect and direct positive influence they have your thinking about how you organise and process data. Which at the end of the day is the core work of most web apps.

Even the very basics will help you greatly, remember I'm talking about first year CS courses here!

The tough part here is "every programmer should know" as there are very few universal "Must Knows". Much of CS theory is math so there is a lot to be said for "You're learning Math whether you think so or not."

Some general comments on math topics:

Partial Differential Equations - Useful for financial technology and engineering applications.

Statistics - Extremely useful in financial technology and marketing applications. (A/B testing, etc) Also good for having an informed worldview.

Regression Analysis - Same as Statistics, though less important for having an informed worldview.

Logic - Whether you call it Philosophy or Math, it's useful in hardware, formal verification, and general thinking.

Linear Algebra - Good for financial technology and machine learning.

Set Theory - Good for understanding databases.

Number Theory - Useful for cryptography.

Graph Theory - Great for networking, and algorithm thinking in general.

Theory of Functions - Good for understanding recursion (LISP, Scheme, etc) and functional programming.

Does anyone need to know all of this? No, but learning the math behind whatever niche you choose will make your intuition and thinking stronger. I think Stats is the only general purpose math that everyone should understand as part of being a critical thinker.

Logic and set theory are intertwined.
Set theory and everything are intertwined.
Categorically.
A lot of these are. One beauty of math is ideas from one part percolate into others.
I'm not disagreeing :-( I just found it useful when I was studying discrete mathematics that set theory is a branch of logic. Knowing logic before you study set theory means you have a solid conceptual foundation to aid your understanding.
... most of these are intertwined. Is there more significance to your comment, or is it just a nitpick?
Maybe I was unclear. Technically set theory is a branch of logic - I found that very useful to understand when I was studying discrete mathematics, and later when I was trying to understand the relational database model.

Yes, most of math is intertwined, however in the examples given above its just useful (at least in my mind) to know the how set theory fits into the larger branch of logic.

It appears that folks are seeing an attack/criticism in my post, probably because it was fairly succinct. Nothing could be further from the truth actually, the list I responded to is quite insightful - and I upvoted it!

Set theory & basic boolean algebra (De Morgan's laws, etc).