# What math should a programmer know?

I am an application programmer focussing on Line Of Business (LOB) applications. I am from non-mathematics and non-CS background. What mathematics should I learn which help me improve my programming and problem solving abilities.

-
A basic knowledge of numerics and combinatorics would be quite useful. –  Ｊ. Ｍ. May 3 '12 at 12:35
Shouldn't you be asking a programmer? –  Gerry Myerson May 3 '12 at 12:36
Math isn't needed as long as you use jQuery. doxdesk.com/img/updates/20091116-so-large.gif –  Jeff Davis May 3 '12 at 19:13

It really depends on what you're programming! Some areas of mathematics that have been very useful to me as a programmer (but may or may not be useful to you) have been:

• Computational complexity (for designing and benchmarking algorithms)
• Combinatorics (ties in closely with the above - can be used to reason about the theoretical performance limits of an algorithm)
• Logic (for reasoning about program behaviour - can help tremendously with debugging)
• Dynamic programming (for solving many problems that can be broken up into easier-to-solve subproblems)
• Linear algebra (for writing any heavy numerical code, e.g. graphics, finance, physics simulations)
• Numerical analysis (for writing PDE solvers)
• Probability (for writing monte carlo routines)
• Statistics (for benchmarking algorithms, drawing inference from large datasets etc)
• Information theory (for writing code that can assimilate new information into its current world state consistently)
• Machine learning (related to previous two - used to write code that can learn optimal behaviours from data)

Many of these fall broadly into the category of discrete mathematics. The field is well summarised in the book Concrete Mathematics by Graham, Knuth and Patashnik.

In general, you would be hard-pushed to find an area of mathematics that isn't useful to some aspect of programming. However, exactly how useful will depend mainly on what it is that you're trying to do.

Edit: I would add (and this part is pure opinion) that any developer who says that you don't need to know much mathematics to be a developer is probably not very good. The same thing applies to any programmer who says that you only need to know one language, or one programming paradigm. Programming is a dynamic and very rapidly evolving field. If you're not constantly learning new things, then you will find it very difficult to advance in your career.

Many of the greatest programmers the world has seen were/are also excellent mathematicians (Thompson, Ritchie, McCarthy, Knuth, Dijkstra, etc). I think you would find it tough to point out a great programmer who doesn't know much mathematics.

Edit: Based on the last six months to a year, I would now add Category Theory to the list. Having a appreciation of what it means, mathematically, to be a functor, monoid, monad or comonad has been useful in allowing me to quickly grasp the common patterns and structures when learning the Haskell programming language.

-
I disagree with your analysis that only a "not very good" developer would say that you don't need to know much math to develop software. It is an empirical fact that a typical business application developer will not need to know much beyond basic algebra and possibly rudimentary statistics. If you work a lot with databases, of course, basic set theory is helpful (which in my view though is subsumed in the "basic algebra" requirement). Of course, some fields will require a great deal of math, but the typical applications that businesses require and web sites that you use every day require... –  ItsNotObvious May 3 '12 at 13:47
..very little explicit mathematical knowledge to build. –  ItsNotObvious May 3 '12 at 13:47
@Sasha I'm not sure how you make that leap, that is not what I said. Developing reliable enterprise applications requires deep knowledge in development tools, API's, programming languages, patterns of application architecture, dependency management and a host of other skills. There is nothing superficial about the skill needed to apply these tools to develop a reliable application that fulfills business requirements. It is a completely different skillset though from applying numerical analysis to solve equations or using stochastic programming to do Monte Carlo simulations. –  ItsNotObvious May 3 '12 at 14:39
@ItsNotObvious +1 I am not claiming that business applications require superficial programming skills, I am saying that I do not find your logic convincing. A good programmer needs to be aware of much of the math Chris outlined, although the actual working knowledge might not be needed, as per your experience. –  Sasha May 3 '12 at 15:02
@Sasha Well, we're going to have to agree to disagree. I have developed a wide variety of business applications over the course of my career and I have never encountered any problem in this context that required more than basic algebra/stats to solve. Now, I think a good argument can be made that learning more mathematics will cultivate one's logical reasoning skills fluency with abstraction - which is of course very relevant. However, if I worked in a DOD facility implementing machine learning algorithms for target recognition, indeed much of the maths on that list (and more) would apply. –  ItsNotObvious May 3 '12 at 15:12

In my programming career, I have used a lot of mathematics. Number theory, mostly, but also elliptic curves, Bayesian probability, latin squares,...

Ask another programmer, and they might say "Numerical analysis, mostly, but also algorithmic complexity, queueing theory, graph theory,...".

To some extent, you will end up learning the mathematics that you need to solve your programming problems. On the other hand, if you already know some mathematics, you will tend to gravitate towards areas of programming that require your particular expertise.

-

That's a pretty wide-open question. I'm not sure it admits a definite "answer", since it depends to a large extent on what kind of programming you're doing.

In all likelihood, learning at least something about binary arithmetic is probably going to be useful - if only so you know why your program is spitting out negative numbers when all the inputs are positive. If you're doing to do any database work, then a minimal grasp of set theory is probably useful. It may or may not be useful to understand algorithmic complexity.

Beyond that, it's really, really going to depend on what you're trying to program. If you're just writing a utility program to read a CSV file and spit out some SQL, you don't need to know much maths. If you're building a ray tracer... you're gonna need a heck of a lot of linear algebra!

-

I have been a professional developer for over 15 years and the highest level math I have used for any professional project is basic trig, algebra and statistics. As others have said though, what math you need highly depends on the field that you work in. I primarily develop applications for enterprises including data-centric applications, web applications and backend service infrastructures (what you would call LOB apps). My ability to think abstractly about complex problems however has been greatly enhanced by my mathematical experience. If you don't have a specific field in min that requires a particular flavor of mathematics, your best bet though would probably be to develop a solid foundation in algorithms and data structures. Regardless of what type of programming you will do, this sort of knowlege will always be beneficial. A good, practical introduction to this topic is provided in Algorithms in a Nutshell.

To be specific, here are a couple of concrete examples of problems I have encountered as a business application developer that actually required a little math to solve:

1. Display a report where cells in a particular column are shaded from light to dark based on the value in the cell. I solved this by creating two lists and linearly interpolating between them. One list contained the data points and the other list contained the range of colors. This required nothing but simple algebra.

2. Implement amortization formulas for different types of loans (balloon, adjustable rate, fixed rate, etc). This required using the exponential and logarithm functions which I suppose technically one could argue uses calculus, but the level of math required nothing that was beyond basic college algebra - which treats exponentials/logarithms.

On the other hand, there are many more instances where I have had to develop rather complicated sorting algorithms or tune a slow algorithm for efficiency. Basic knowledge of data structures and algorithms has been very helpful in this regard.

I can also say that not one single potential employer during an interview has ever asked me a mathematically-oriented question. Rather, they are concerned with what tools, languages, platforms I know, what architectural patterns am I familiar with, how do I manage software complexity (not "computational complexity"), etc. I would be thrilled if I were asked something about math but, alas, it has never happened.

-
Algorithms is a field of mathematics, keep in mind. I bet you use mathematical fields in your software development much more than you realize. –  user606723 May 3 '12 at 15:29
In case you're ever looking for a job change, my employer puts all our developers through a very demanding math interview :) –  Chris Taylor May 3 '12 at 16:18
@ChrisTaylor Judging from the business you're in, your employer's demand for mathematical skills is not surprising. A career in QF would probably be pretty interesting, and I have considered exploring it, but moving to NY (which, in the US, is probably the only place one can do such work) is not an appealing prospect. –  ItsNotObvious May 3 '12 at 20:08

I guess I'll throw my hat into this one as well. Computer Science is in large, a subsection of Discrete Mathematical Science.

Basically, you should learn Discrete Mathematics in order increase your software development ability.

In discrete math subjects, many of the subjects collapse into core concepts that can be applied across subjects. Each specific field simply requires taking these core concepts and applying them in a specific way. This means, that while I might not use graph theory in everyday in my day job, that fact that I've studied graph theory, artificial intelligence, computational complexity, etc etc has developed these core Discrete Mathematical concepts in such a way that I can apply them towards other problems.

In my experience, each field of discrete mathematics is basically applying concepts you've learned in the past in new ways in order to solve a certain type of problems. Because I've learned how to apply these concepts towards X and Y, when I encounter a Z type problem I at least know where to start.

This means that while you may not use many mathematical fields directly in day-to-day operations, these core concepts are useful and help you make correct problem solving and design decisions, as well as debug.

-

Enormous variance:

I've had days programming HTML/CSS where typically the most complicated math I have to do is on the lines of: if the "left" property is set to 4 pixels and I want it 4 more over, I add 4+4 and get 8.

On the flip side I've had times working in scripting languages like JS or AS3 where I've needed quaternion mathematics like theoretical physicists work with to efficiently calculate forward kinematic orientations in 3d space...like I said...enormous variance depending on what you're building.

But a good place to start is algebra. Programming in some ways can be looked at as literally writing algebra:

var x = {some user input};
var y = {some changing parameter in the program};
changeBoxPositionTo(x / y + 40);


Look at that, it's a couple lines that could easily be part of a program...but those lines wouldn't look at all out of place on an algebra exam in the form of "What's the range of numbers possible if x is any whole number from 1 through 10 and y is any whole number from 20 through 30?" Most language of programming themselves are pretty much forms algebra, so that's a great place to start when trying to build up your math competence to be a better programmer!

-

I am doing a Computer Science degree at a state University and I have to take the following math courses: Calculus 1 | Calculus 2 | Linear Algebra | Discrete Math 1 | Discrete Math 2 | To be a Programmer you NEED math however not all of it. It all depends what are you interested in. You cant just do 3D programming without knowing geometry or maybe Calculus 3 or you can do algorithms involving matrices if you do not know Linear Algebra. You would also would not learn efficiency(Big-Oh) without learning Discrete math.

But best way to answer your question is the more math you learn programming would be more helpful in the long term.

-

A real programmers uses a DIFFERENT MATH that most of the time is incompatible with regular Math, or more specifically, it is the same with a different focus.

First, regular math is based in formula, while computer math is tabular (think in Excel).

Take in consideration that mathematic is more focused in science arts while computer is pure engineer.

For example, a computer example:

y = 20
x = y + 30


neither x nor y are a incognito value, here x is a assigned value and y store a previous value. In math and computer, both have the same result (x=50,y=20) but a sightly change can vary the result

x = y + 30
y = 20


in math, y=20 and x=50, while in computer, x=30 (or error) and y=20 (or undefined if the first line trigger an exception).

And of course

x = x + 1


is valid in computer science but make nonsense in pure math.

Even more, let's say a Summation :

for i=1 to 100 step 1 ( 1,2,3,4...)
amount=amount+i
next


it could be expressed mathematically while

for i=1 to 100 step 2 ' (1,3,5,...)
amount=amount+i
next


turn more tricky to express it mathematically. Then

for i=100 to 1 step -1 ' (100,99,98)
amount=amount+i
next


is trickiest to draw it mathematically specially since

for i=100 to 1 step 1 ' (100,99,98)
amount=amount+i
next


is never evaluated.

What math should a program know?. The basic is more than enough. In my experience, a good mathematic trends to be a bad programmer. Most math functions already are defined so, in case of needing, it is so easy to apply the function even without understanding how it works.

-
I can't think of any mathematician who would want to compute that sum and use a loop. –  Joshua Shane Liberman May 3 '12 at 20:44
I've never been one to mercy downvote, but this has gotten way more downvotes than I think it deserves. –  Ataraxia Jul 23 '13 at 14:14
The downvote just proves my point. b*tthurts hurts. :-). Anyways, if we check the last example that i put, then it is not evaluated, it is a common mistake that can be pinpointed by a programmer but missed by a mathematic. Why?, because in mathematic are so few wrong formula but instead there are incorrect formulas. What is the difference?. A lot. –  magallanes Jul 23 '13 at 21:13
Sorry, I meant to say mercy upvote. –  Ataraxia Jul 24 '13 at 18:01