“How much math do I need to know to program?” Not That Much, Actually.

Here are some posts I’ve seen on the r/learnprogramming subreddit forum:

Math and programming have a somewhat misunderstood relationship. Many people think that you have to be good at math or made good grades in math class before you can even begin to learn programming. But how much math does a person need to know in order to program?

Not that much actually. This article will go into detail about the kinds of math you should know for programming. You probably know it already.

For general programming, you should know the following:

  • Addition, subtraction, division, and multiplication – And really, the computer will be doing the adding, subtracting, dividing, and multiplying for you anyway. You just have to know when you need to do these operations.
  • Mod – The mod operation is the “remainder” and its sign is usually the % percent sign. So 23 divided by 7 is 3 with a remainder of 2. But 23 mod 7 is 2.
  • The even/odd mod test trick – If you want to know if a number is odd or even, mod it by 2. If the result is 0, the number is even. If the result is 1, the number is odd. 23 mod 2 is 1, so you know 23 is odd. 24 mod 2 is 0, so you know 24 is even. If x mod 2 is 0, you know that whatever number is stored in the variable x is even.
  • To get a percentage of a number, multiply that number by the percent number with the decimal point in front of it. So to get 54% of 279, multiple 0.54 * 279. This is why 1.0 often means 100% and 0.0 means 0%.
  • Know what negative numbers are. A negative number times a negative number is a positive. A negative times a positive is negative. That’s about it.
  • Know what a Cartesian coordinate system is. In programming, the (0, 0) origin is the top left corner of the screen or window, and the Y axis increases going down.
  • Know the Pythagorean theorem, and that it can be used to find the distance between two points on a Cartesian coordinate system. The Pythagorean theorem is a^2 + b^2 = c^2. What this usually means in programming is the distance between coordinate (x1, y1) and (x2, y2) will just be sqrt( (x1 – x2)^2 + (y1 – y2)^2 ).
  • Know what decimal, binary, and hexadecimal numbering systems are. Decimal numbers are the numbers we’re used to that have ten digits: 0 to 9. It’s commonly thought that humans develop this system because we have ten fingers and counted on our fingers.

Computers work with binary data, which is a number system with only two digits: 0 and 1. This is because we build computers out of electronics components where it’s cheaper to make them only recognize two different states (one state to represent 0 and the other to represent 1).

The numbers are still the exact same, but they are written out differently because there are a different number of digits in each system. Because hex has 6 more digits than the 0-9 numerals can provide, we use the letters A through F for the digits above 9. The easiest way to show these number systems is with an odometer. The following three odometers always show the same number, but they are written out differently in different number systems:


See the Odometer Number Systems page in a new window.

You don’t even have to know the math of converting a number from one number system to another. Every programming language has functions that can do this for you.

(On a side note, hexadecimal is used because one hexadecimal digit can represent exactly four binary digits. So since 3 in hex represents 0011 in binary and A in hex represents 1010. This has the nice effect that the hex number 3A (which is 58 in decimal) is written in binary as 00111010. Hex is used in programming because it is a shorthand for binary. Nobody likes writing out all those ones and zeros.)

And that’s about it. Other than the number system stuff, you probably already knew all the math you needed to know to do programming. Despite the popular conception, math isn’t really used that much in programming. You would need to know math in order to write programs that do, say, earthquake simulators. But that’s more about needing to know math for earthquakes rather than needing to know math for programming an earthquake simulator.

Advanced Mathematics in Some Areas of Programming

There’s a few areas of programming where some additional math knowledge might be needed (but for 95% of the software you’ll write, you don’t need to know it.)

3D games and 3D graphics – 3D stuff will usually involve knowing trigonometry and linear algebra (that is, math dealing with matrices). Of course, there are many 3D graphics libraries that implement all this math programming for you, so you don’t need to know the math.

2D physics (like Angry Birds) and 3D physics (like many popular 3D games use) – To do programming that involves physics, you’ll need to learn some physics equations and formulas (specifically mechanics, which is the type of physics with springs, gravity, and balls rolling down inclined planes.) However, there are several physics engines and software libraries that implement this stuff for you, so you really don’t need to know the physics equations to make a game like Angry Birds.

Cryptography – And really, by cryptography, I just mean RSA. In which case, you’d have to learn some math about how prime numbers work and doing the Greatest Common Divisor (which is a dead simple algorithm, although plenty of programming languages have gcd() function that does this for you.) Other encryption ciphers are mostly moving data around in specific steps. For example, this Flash animation shows the steps in the AES “Rijndael” cipher. All the steps are basically substituting numbers for other numbers, shifting rows of numbers over, mixing up columns of numbers, and doing basic addition with numbers.

And that’s just if you want to write your own encryption ciphers (which you shouldn’t do, because there are already plenty of good ones and without expertise your cipher will probably suck and be easily cracked.) If you just want to write a program that encrypts data, there are software libraries that implement encryption and decryption functions already.

So even for the above situations, you don’t need to know the math to make programs with 3D graphics, physics, or encryption. Just learn to use the libraries.

What You Do Need to Learn to Do Programming

What you do need to learn is how to model data and devise algorithms. This basically means, how to take some real-world calculation or some data processing, and write out code that makes the computer do it. For example, in the game Dungeons and Dragons the characters and monsters have several different statistics for combat:

  • HP, or hit points, is the amount of damage a person can take before dying. More HP means you can take more damage before dying.
  • AC, or armor class, is a measure of the chance your armor has of blocking an attack. The lower the AC, the more protective the armor is.
  • THAC0 (pronounced “thay-co”), or “To Hit Armor Class 0”, is a measure of how skillful the person is at making a successful hit on an opponent. The lower the THAC0, the more accurate the person’s attack is.
  • The damage of the weapon is written out as something like 1d6+2. This means the damage is the amount from rolling 1 six-sided dice, and then adding 2 to it. A damage stat of 2d4 would be rolling 2 four-sided dice and adding them together. (Dungeons and Dragons uses 4, 6, 8, 10, 12, and 20-sided dice.)

To see if an attacker hits a defender, the attacker rolls a twenty-sided die. If this number is equal to or greater than the attacker’s THAC0 minus the defender’s AC, then the hit is successful and the defender takes damage. Otherwise, the defender has either dodged or blocked the attack and takes no damage.

Let’s take two Dungeon and Dragons characters, Alice and Bob, with the following stats:

  • Alice: HP 14, AC 5, THAC0 18, DAMAGE 1d6
  • Bob: HP 12, AC 7, THAC0 16, DAMAGE 2d4

So Alice has two more hit points than Bob and better armor (remember, lower AC is better). But Bob is more likely to make a successful hit (remember, lower THAC0 is better) and does more damage. We can tell Bob’s damage is better because 2d4 will result in 2 to 8 points of damage, while Alice’s 1d6 will result in 1 to 6 points of damage. (If you knew statistics math, you could calculate that Bob’s expected value of damage is 5, which is larger than Alice’s expected value of damage is 3.5.)

So would you bet on Alice or Bob to win in a fight? It’s hard to tell, they seem pretty evenly matched. Even if you knew a lot of statistics, doing all these calculations would be a pain. But you don’t need to know statistics in order to write a program that simulates Dungeons and Dragons combat (that is, models this process) and then run several hundred or thousand simulated fights and see who wins on average.

Here’s such a program written in Python: (Download source)

import random, copy

NUM_FIGHTS = 1
VERBOSE = True

# Lower thac0 and lower ac values are better. Higher damage & hp values are better.
aliceTemplate = {'name': 'Alice', 'hp': 14, 'ac': 5, 'thac0': 18, 'dmgnum': 1, 'dmgsize':6, 'dmgmod': 0}
bobTemplate   = {'name': 'Bob',   'hp': 12, 'ac': 7, 'thac0': 16, 'dmgnum': 2, 'dmgsize':4, 'dmgmod': 0}

def display(s):
    if VERBOSE:
        print(s)

def attack(attacker, defender):
    if random.randint(1, 20) >= attacker['thac0'] - defender['ac']:
        damage = 0
        for i in range(attacker['dmgnum']):
            damage += random.randint(1, attacker['dmgsize'])
        damage += attacker['dmgmod']
        display('%s (%s hp) hits %s (%s hp) for %s points of damage. %s is reduced to %s hp.' % (attacker['name'], attacker['hp'], defender['name'], defender['hp'], damage, defender['name'], defender['hp'] - damage))
        defender['hp'] -= damage
    else:
        display('%s misses %s.' % (attacker['name'], defender['name']))

aliceWins = 0
bobWins = 0
for i in range(NUM_FIGHTS):
    display('======================')
    display('Start of combat #%s' % (i+1))
    alice = copy.deepcopy(aliceTemplate)
    bob = copy.deepcopy(bobTemplate)
    while True:
        attack(alice, bob)
        if bob['hp'] <= 0:
            break

        attack(bob, alice)
        if alice['hp'] <= 0:
            break
    if alice['hp'] <= 0:
        display('Alice has died.')
        bobWins += 1
    if bob['hp'] <= 0:
        display('Bob has died.')
        aliceWins += 1

print()
print('Alice won %s (%s%%) fights. Bob won %s (%s%%) fights.' % (aliceWins, round(aliceWins / NUM_FIGHTS * 100, 2), bobWins, round(bobWins / NUM_FIGHTS * 100, 2)))

When you run this program, it produces output like this:

======================
Start of combat #1
Alice misses Bob.
Bob (12 hp) hits Alice (14 hp) for 6 points of damage. Alice is reduced to 8 hp.
Alice misses Bob.
Bob misses Alice.
Alice misses Bob.
Bob misses Alice.
Alice misses Bob.
Bob misses Alice.
Alice (8 hp) hits Bob (12 hp) for 5 points of damage. Bob is reduced to 7 hp.
Bob misses Alice.
Alice misses Bob.
Bob misses Alice.
Alice misses Bob.
Bob (7 hp) hits Alice (8 hp) for 2 points of damage. Alice is reduced to 6 hp.
Alice (6 hp) hits Bob (7 hp) for 6 points of damage. Bob is reduced to 1 hp.
Bob misses Alice.
Alice (6 hp) hits Bob (1 hp) for 1 points of damage. Bob is reduced to 0 hp.
Bob has died.

Alice won 1 (100.0%) fights. Bob won 0 (0.0%) fights.

But maybe Alice just got lucky in this one fight. Let’s reprogram this program to turn off the verbose output (displaying text on the screen takes a lot more time than running the simulation) and up the number of fights to 30,000 (this is just changing the NUM_FIGHTS variable to 30000 and the VERBOSE variable to False):

Alice won 12909 (43.03%) fights. Bob won 17091 (56.97%) fights.

So we can see that with the given stats, Bob is at a slight advantage. The computer just ran 30,000 simulated fights. If we were to play 30,000 fights of Dungeons and Dragons with pencil, paper, and physical dice, it would take months to calculate this. But my laptop had the results in less than 8 seconds.

But what if we increased Alice’s hit points from 14 to 20. Who would win then?

Alice won 19438 (64.79%) fights. Bob won 10562 (35.21%) fights.

We see that those 6 extra hit points turns the tables and gives Alice the advantage. How about if her hit points were only increased to 16 instead of 20?

Alice won 15176 (50.59%) fights. Bob won 14824 (49.41%) fights.

We see that just tweaking the stats by 2 hit points is just enough to even out the advantages that Bob gets from his higher level of damage.

And when you look at this program, the only math it uses is addition, subtraction, and multiplication and division to find a percentage. Even if we made the simulation more sophisticated to account for the effects of magic spells, healing potions, multiple attackers, and switching to different weapons in mid-combat, we wouldn’t need to know more math or have made good math grades to do the programming for it.

Sure, go ahead and learn more math. It can only help you become a better programmer. But how much math do you need to know to program? Very little, actually.

UPDATE: I guess I’d add basic algebra to the required knowledge, but only insofar as that if X * 3 = 12 knowing why X is 4.

(Here’s a list of other discussions on Reddit about this topic.)

54 comments.

  1. While this is true, it could be argued that rather than the math itself, it’s the ability to think intuitively using math that is the key.

    Then I suppose it follows that people who are able to do this will often have learned more math.

  2. I think Sam pretty much just nailed it. It isn’t the amount of math that you know, it is being able to use simple math in ways that you may not naturally think to use it in.

    Good post.

  3. Certainly learning more math will help you think in terms of programming. I don’t think in a school setting, however, a heavily math based curriculum (commonplace in US CS departments) is as helpful as tackling problems with code. Specifically, I don’t think calculus is as helpful as spending the same time learning to solve problems using code.

  4. My point is similar to Sam’s point. You need to know math in order to program, there’s no way around it. However, the article mistakes mathematics with calculation. Mathematics, generally speaking, as abstraction, logic, and deduction.

    If you can’t abstract, you can’t program. Take the Pythagorean theorem, that’s an abstraction of the instance 3^2 + 4^2 = 5^2, which is a class of triangle, specifically a right triangle.

    For example: “And when you look at this program, the only math it uses is addition, subtraction, and multiplication and division to find a percentage.”

    The D&D simulation might have simple calculation but it uses much more math than that because it’s model of combat. When constructing our model we didn’t include hair length or eye color as properties, which are present in actual battle. But in modeling battles those traits don’t seem to matter much in battle. Abstracting out what matters and quantifying it is the heart of mathematics.

    This article really makes the case.
    http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html

    Professors gave students simple tests, like the one below, and many failed. The concluded that either you can program or you can’t.

    int a = 10;
    int b = 20;
    a = b;

    What are the new values of a and b?

  5. Yes, you don’t need to know (much) math to start learning programming, but to be a good programmer I think you need it.
    And is not for the actual math you’re going to use, the most important programming skill is the ability to abstract.
    The best way to learn that? Yep, Math…

  6. I must say I was a bit surprised when I started learning programming how little maths was needed – I came from a hard science background with a head full of matrix transforms and calculus, and the most complex thing I’ve ever needed is 3D geometry.

    I think what you really need much more than maths is the problem solving instinct. Here maths helps you ONLY if you were taught maths “correctly”. Some schools emphasize memorization to teach maths – rote learning of forumla and solutions – this doesn’t help you at all. Others are good at giving you the core elements and teaching you how to use them to solve novel problems, I was taught this way and it definitely helped me a lot.

  7. I agree with Sam. It is all about having an intuitive grasp of logical outcomes. You need to be able to reason about what effect a series of steps will have. The skills that let a mathematician recognize a valid proof or derivation are the same skills that let a programmer know that a piece of code is correct after reading it.

    I would also add that the more math you know, the more comfortable you can be that you aren’t writing something in a silly way. If something you write takes forever to run or breaks on large inputs, then if you have a poor grasp of mathematics you won’t know if there is a faster way or if your problem is really intractable.

  8. 100% means 100/100 (or 100÷100, if you prefer), which is equal to 1.0 . *Always*, not *often*.

  9. From experience, I firmly believe in the general gist of what the author mentioned.

    I am what you call an “average” programmer. I don’t come from a hard mathematics background. When I shifted to the programming field, I was mainly involved in doing small modules for business applications, and then later on involved in full-bore business systems. Most of what I have done are still in operation, and I am still doing maintenance programming on many of them e.g. addition of features, adopting to new work procedures, etc.. This is in contrast to some of my colleagues coming from the so-called mathematics field whose outputs, many of them, are not being used because they did not “fit” what the user wanted.

    In most of the applications I have done, there is not much mathematics required. I have not even utilized Calculus. It may have been “abstracted” in APIs or libraries but it would not be fair for me to say that I “used” mathematics just because of this (just like saying that I used the science of electronics, optics, and the attendant “deep math” of it just because I’m using a karaoke microphone).

    Yes indeed heavy mathematics is important in many areas like in designing new and better compilers, or software that best renders light in the monitor, or software that would enable electrons to travel faster etc.. But how many are really doing these types of work. Can we say that, extensive math is needed in all programming, as some would say, just because of this so-called heavy stuff?.

    As for abstraction, I don’t believe that Math has the sole superiority on abstraction. The best abstractionists in the world are not mathematicians. Just look at the paintings…, or just look at the authors of the best computer programs… whatever those are?

    By the way, I am going to enroll in a masteral degree in applied mathematics.

  10. Probably, a loose knowledge about functions and recursiveness can also help.

  11. One confuion is that math (US) / maths (rest of the world) is not just arithmetic but also mathematics. The latter has a much wider scope. Even sticking to arithmetic, a solid grounding is important for any non-trivial programming. Whilst a lot can be done with library functions, understanding which one to use and how to use it properly requires background knowledge of the domain. Programmers must be aware of the peculiarities of computing mathematics, e.g. how to reduce rounding errors on long calculations, how to determine which algorithm will complete in a resonable time, etc.

    This does not mean that you have to be good at arithmetic. E.g. just because you cannot do square roots in your head or even quote the Newton-Raphson formula and use it to derive a technique for calcualting square roots does not obviate you from the obligation to understand the principle of how square roots are derived on a computer. Just a cursorary understanding will lead you to conclude that (x == sqrt(y)) is a much slower test than the equivalent (x*x == y).

    Another aspect is to have the right level for what you are programming. You correctly assert that not a lot of knowledge is needed to program an ‘Angry Birds’ app as the libraries encapsulate all of the maths required. However, I would not want to live near a nuclear power plant programmed by someone who did not understand the physics and the maths for nuclear reactions.

  12. Regarding basic operations (+, -, *, /), preference should also be mentioned, as well as the proper use of brackets to influence preference.

    Even/odd may also be determined by the bitwise & operator available in many languages.

    I’d also like to point out that knowing the cartesian coordinate system might in fact not help that much. I know it did confuse me quite a lot when I first encountered graphics programming and realized the y axis was going down, not up! I’m not at all sure if knowledge of cartesioan coordinates actually helped me that much: I pretty much had to relearn it as I went along programming stuff that I saw right on the screen. It wasn’t too hard either.

    Furthermore, you forgot at least two things:

    1. Boolean logic: you have to know how to combine conditional statements, e. g. in if statements

    2. Manipulating expressions: you gave the example of the pythagorean equation and then without losing a step went on to explain the use of it in calculating the distance. What you did, implicitely, is manipulate the equation to get a formula for what you needed. Without the knowledge how to manipulate equations, all the theorems in the world won’t do you any good in programming!

  13. You need no math at all. Programming is a human science.

  14. Very well written post… :)

  15. Quite simply, programming is about problem solving, and maths is about problem solvng. If you’re good at maths, it’s likely you’ll make a good programmer.

  16. Please, please, please; you say mathematics, why say math. Insert mathematic for each case of math and see how silly it sounds. Please use maths when you shorten mathematics. Do the maths!

  17. You’re going need to understand how sets work if you have anything to do with databases, and you may need a bit of logic (“not a and not b” is the same as “not (a or b)”).

  18. In the old days (back before the big bang), it was stressed in advanced programming and computer science classes that: “If you don’t know math, you have to invent it.” Math-savvy programmers didn’t have to “reinvent the wheel.”

    Many programmers with little math, wrote extensive, obscure, unstable code because they didn’t know (or even care about) the most simple, elegant way to create the best algorithm to perform a function. They just wanted to put in X and get Y.

    You could always tell when someone knew their math well, because they wouldn’t take as long as other programmers. Their number of lines of code would be less. Their lines would be shorter, more clear, more readable, and obviously be more stable. They had much more shortcuts, like ANDs, ORs, XORs, MODs, NULLs, etc.

    Algol actually required the use of these functions. You could often write a full page of fortran in just a few algol characters.

  19. Yes, you can test for odd or even using modulus, but it is a rather silly thing to do since doing a bitwise “and” with 1 is at least an order of magnitude more efficient. e.g.

    In C:
    if (x & 1) …

    in x86 assembly:

    test eax, 1
    jz even

  20. @Josh Gachnang

    “If you can’t abstract you can’t program.”

    Oh that’s not true. You just can’t program well. See turing.

  21. “Not that much, actually…” lmao

    (You also forgot the importance of the order of operations.)

    Put a programmer that is good at math beside a programmer that isn’t. Tell both of them to build a program that pulls numbers from a database that involves several table joins and compare results. The programmer that is good at math will realize that there are duplicate records (due to the joins) that are causing inflated counts. The programmer that hates math will assume the computer is doing the math correctly.

    Both can program. Which one would you choose to be on your team?

  22. I agree with mangecoeur. Problem solving comes natural to some, like math, but most it does not, it has to be learned. In this world where high tech touches every aspect of ones life, problem solving skills are in short supply. There needs to be an overhaul of secondary education where most students begin to learn advance math. Let’s face it most students will never use the math they learn and don’t see any relevance in learning it in teh first place. But the problem solving skills that they are supposed to learn in math class are not taught but are acquired through osmosis while being in math class. This has to stop. We need more classes in abstraction, logic, deduction and problem solving to get to the next level of software development. It is time to take programming from the math majors and put it in the hands of the left-brainers. Creativity is what yo need to program not advance math skills.

  23. I would add the Set Theory basics you need to properly understand and work with Relational Databases, a must in the vast majority of business apps.

  24. The statement “To get a percentage of a number, multiply that number by the percent number with the decimal point in front of it,” is misleading. Using this method would give a result of the value 0.6 for 6% instead of 0.06 and, perhaps 0.04 for 0.04%. A better choice would be “Move the decimal point two places to the left”

  25. All those differential equations and complex number systems and series aren’t that much needed, it means!

  26. What I see happening, even as of 2012, is poorly-trained programmers screwing up the most fundamental task of knowing WHEN to round … and when not to. In the financial arena, such a common mistake can quickly amount to a BIG discrepancy depending on how long it goes unnoticed. I’ve personally witnessed such a mistake whose discrepancy grew to hundreds-of-thousands overnight.

  27. Well if you consider that Boole’s Algebra is not a basic requirement,…

    Seriously not cool to forget that…

  28. The link to flash animation for AES (Rijndael) is missing. The name is also misspelt.

  29. I basically agree with the article in regards to the amount of math one actually needs to do their programming tasks and the points raised by Sam regarding the ability to think mathematically. They nailed it.

    My sorrow is that I’ve seen a lot of places where people think that math is only calculation and algorithms and ignore the fact that, for a programmer, a very important part of mathematical arsenal should be the ability to do basic logical operations. There are so many cases in which a programmer could not simplify a logical condition because he was unsure how the logical operations work. But why am I talking about complex operations; I bet everyone here has once encountered the infamous “if (isSomething == true)” in some other people’s code. (I can give tons of examples of such horrors.) I’d say that questions about basic boolean operations should be part of any job interview, but unfortunately they’re not.

  30. I think you are missing the fact that to do good SQL programming, you need to be able to think in therms on sets. So, set theory is a must.

  31. I’ve found in almost 40 years of programming that only the basic math concepts listed in the article were required of me. I have yet to need the Pythagorean theorem though. I actually hate math and have never understood why for so long it has been deemed fundamental to programming in general. Granted, there are some things that are beyond me, like graphics programming, cryptography, queueing theory, etc. But in my work on real-time, client/server, data communcations, and web applications, those skills haven’t been required. And if they were, then obviously I’m not the person for the job.

    Whatever I needed to learn to prepare me for a career as a programmer I picked up somewhere along the way. Not from mathmatics though I can assure you.

  32. When I think to Toto.equals() and Toto.hashCode(), that remebered me some pieces of fundamental algebra about equivalences and equivalences classes.

    I may need to override both together because a.equals(b) shall imply a.hashCode()==b.hashCode() … ouch… logic is not that far.

    Also I love when Map I use are “relatively” perfomants so maybe that the morphism “hashCode” I implements shall be relatively well balanced…. probabilities seems not that far.

    My experience tell me strongly injective functions are difficult to inverse and this is difficult to make hypothesis about their inverse images. So I don’t see how to insure that “p(Toto.hashCode()=X)” is relatively uniform.

    Finaly marketing, as always, are unclear about features and Toto is still unstable so it is difficult to build good hash function.

    Luckily, I’m confident Toto will only contains totaly orderable fields to be taken into account.

    I can build a total order on each fields it contains, so forget Map, I will use lexicographic order which is fortunately still a total order. So let’s use a SortedMap wich is still a good compromise in term of complexity (log2 of the number of entries).

    Hey guys don’t tell me that all this stuff are math !!!!
    I’m just speaking about implementing “Toto.equals()” and what the impact into my container ^^

  33. Here is a thought. Instead of going through all that why not do collision detection modified by armor rating and or damage rating of the weapon. Seems to me you would need even less math. I realize this is a little beside the point it just seems to me knowing what the programing language can do is just as,if not more, important as trying to impress someone with a complicated mathmatical formula.

  34. Good article… but one comment. You don’t mod a number with 2 to check if it’s odd; you AND it with 1 — much faster.

  35. I struggled with math early on. But after getting into programming, I found math got a lot easier. It’s really the same thought process that you learn. I think a key difference is the feedback you get by solving compilation errors and then application errors.

  36. Two areas of Mathematics that you have not mentioned that would be useful to a programmer are boolean logic (plus possibly predicate logic) and decimal fractions. Decimal fractions would be useful for understanding floating point numbers and why they are not 100% accurate.

  37. I would hate to find out the programmer that programmed my calculator didn’t know Basic Algebra… :>)

  38. You don’t need a lot of math to be able to program. You do need a lot of mathematical knowledge and training to be able to program well.

  39. Operator precedence is vital to reading and understanding code. People write all sorts of complicated expressions and it would be nearly impossible to understand their function without understanding the order the operations occur in. It also helps to be able to write code without a million parenthesis.

  40. You can more or less do everyday programming without deep mathematical knowledge, but it seems misleading to say that you can learn the 3D libraries, physics engines etc and understand how a game works. Writing a game starts from the fundamentals, and the basis for this is a working knowledge on some mathematical topics. Other than that, a really good article on the subject :)

  41. Programming is a bottomless ocean. But usually ops with bits are a must. Therefore, one must know what means AND, OR, XOR and NOT ops. As for me, I’m working in area, where one cannot do without advanced math. Image matching for aerial photogrammetry. There is a powerful and very unpleasant idea in programming- to replace pros by idiots. This is where such tips like “you may not know math, use libraries” go from. I met some wise boys, trying to solve problems, that they was not prepared for. A nice example- fingerprints, obtained from 3D scanner. One such boy wanted to extract papillary lines from it without knowing geometry of curved surfaces nor regularization. Another similar situation- FFT- Fast Fourier Transform, often used to compute convolutions. One MUST know underlying math in-depth, otherwise naive usage of corresponding libraries gives him some strange-looking mess.

  42. I have invested some time and effort recently improving my math due to a project that involved interpolation of unknown points along cubic and quadratic bezier curves. The result is a program that works correctly and I understand what is going on under the hood. I could have used a library or modified a code example but I feel that improving my math enabled me to solve problems more effectively and produce better code.

    Whilst the original post is true, you don’t need to know much math to program, improving your knowledge little and often will make you a better programmer.

  43. Those who say “maths” is a proper word, clearly don’t know the Etymology of Math. The word “math” in and of itself is plural. Maths isn’t, and never has been an English word. (I have to admit I don’t use “Etymology” much, when I first spelled it out, I found out it was the study of insects. Also, unfortunately, my spell-checker does say maths is a word.)
    Math encompasses Mathematical equations, Mathematical concepts, Mathematical theories, simple, irrational, geometry, trigonometry etc. However the colloquial expression “Do the Math” usually limits math to addition and subtraction. Implying whatever “it” to be done is, is a simple mathematical operation.

    “Know what a Cartesian coordinate system is.” Well, if you do, you’d also know that programming in terms of graphical displays, use a modified form of that system. (In the standard 2 dimensional x/y model, an increasing y value goes vertically up.) Positive y going down is a nod to the English top down form of writing and makes the layout of graphical images mixed in with text much easier to think about. Though, come to think of it, combining text and image in HTML aligns them both in the classical Cartesian manner. (The text is pushed down so the bottom of the text aligns with the bottom of the image.)

  44. Just enough math to check your payslip :)

  45. I am just amazed that he thought it necessary to actually explain the D&D combat system to his target audience.

    Of course some of us may have played before THACO was introduced.

  46. Math and as noted more importantly how to use mathematics (really important) is important, but it also depends on what programming discipline (industry) you are in. If your programming skills are in accounting type programs than basic math is all your going to need (these days) unless your reinventing charts, then you better know some basic on screen drawing math. On a factory floor if your involved in PLC’s you better know your number system conversions or have a tool to do so. If your doing gaming the sky really is the limit, depending on the game itself.

  47. A programmer should know nothing but to solve any given problem regarding any area of expertise, someone who can learn any subject with out much trouble

  48. I agree with some of the others above that math provides the style of thinking that helps with programming. If you didn’t do well in math classes, there’s a probability that programming isn’t for you. Also, set logic is a good math discipline to look into. This is just programming though. Once you get into design, there’s a possibility of more. Whether it is with crunching the numbers for system architecture feasibilities, solving a complicated problem (i.e. video forensics using tools like Fourier transforms, Taylor series, etc.), etc. My point is that overall the article is correct that you don’t need a great understanding of math to do most programming tasks. There are some projects that can require much more though especially if you have design responsibilities.

  49. You do not need that much mathematics to program but the way mathematicians think is definitely a requirement for effective programming and helps really a lot. It is not necessary to be a maths genius to do good programming but it helps :-)

  50. That may be enough to write a program, but not enough to be a programmer.

    I am more in the camp of this guy: http://www.eetimes.com/design/embedded/4238223/The-education-of-embedded-systems-software-engineers–failures-and-fixes?Ecosystem=embedded&cid=NL_UBM+Electronics

    - Paddy.

  51. In school, my understanding of mathematics sucked to the point that anything other than basic arithmetic was beyond me. 20-odd years later, my understanding of mathematics still sucks; I still look at formulae in mathematical notation and stare blankly much of the time. What has improved most whilst coding was my knowledge of available mathematic/arithmetic tools and the understanding of how to apply them to the task at hand, rather than my actual grasp of mathematics. In short, it’s not necessarily what you know, but how well you know it that is the key.

    For example, I write a lot of 3D-oriented code, which requires copious use of the dot and cross products. I still don’t understand the theory behind how they actually work, but because I understand what they do within the context of matrix manipulation, I am able to code effectively with minimal fuss. Try creating a camera looking at a 3D scene without knowing how to construct and manipulate the required matrices, in the correct order, to produce the desired output; sorry, but it’s just not possible without taking trial-and-error to an order of magnitude. Knowledge is power, but context is everything.

    Apart from Boolean and bitwise operations, operator precedence, data typing and some minimal set theory, the single biggest mathematical oversight by the OP is Algebra. Look closely at every level of programming language (be it C++, Python or even assembler) and you will notice that the language of code is Algebra. Without understanding how ‘c=a+b*2′ works in terms of assigning values to tokens and operating on the tokens [a,b] to produce a result in [c] – rather than the actual values within [a,b] – you cannot write effective working code, period. Algebra should have been the very first thing on the ‘must know’ list.

    Finally, I offer this as food for thought: a good coder knows enough to perform the task at hand; a great coder recognises what they don’t know and is prepared to do the hard yards to learn it, so the task at hand is performed faster and smarter.

  52. Mathematics is the art and science of discerning patterns; it is not the art of calculation. Calculating is only an expression of the application of mathematics to specific problems.

    The reader comment noting that percent calculating requires moving the decimal point 2 places rather than in the manner the author describes only begins to indicate the author’s errors in the calculation hints and other even more important messages in the article.

    Saying all the odometer readings in his example represent the same value only works because there are no fractional miles shown. I dare the author to post the binary equivalent of .3 decimal miles as a non-infinite sequence of binary 1 and 0. Any one who works with dollars and cents, or any sort of fractional values, knows this fact all too well or suffers the consequences. Why does he think IBM invented Packed/Unpacked Decimal numbers and decimal arithmetic, which most computer systems have implemented in hardware or a software library?

    One needs to know the art of abstraction from specific to general problem. Does the author write a separate subroutine (method) for every individual case of a functional requirement or does he generalize and write a subroutine that works for all specific instances of that requirement? One needs to have a “tool box” for going the opposite direction as well. Most programming problems are too big to be dealt with as a whole. They need to be broken down in to sub-problems that are tractable.

    Mathematics also teaches how to look at a problem and figure out that it is the same as one already solved or how to characterize the new specific problem in a way that describes an entire class of problems.

    Personal note: Programmer and software engineer for > 40 years; CS/IT professor as well for ca 20 years.

  53. I believe “maths” is common British usage, and “math” is American usage.

    I’m American, and I am not a mathematician, but I’m interested in programming. I’m learning Python for fun.

    I took some computer programming courses years ago, to be able to communicate better my department’s needs to the IT department where I worked. I had to learn enough about programming to re-phrase my requests in language they would understand so that they would be able to mentally picture a framework of the project in their own minds.

    I majored in English and Spanish as an undergrad. From what I can tell (so far) programming languages are just that – languages. Anyone from a linguistics background can learn the rules and do programming. Not that much math is truly required. I took college algebra as a liberal arts undergraduate. I haven’t had any trouble learning programming concepts so far. My impression is that once you know the “grammar” rules you can write the code.

  54. After a while I really needs to comeback to this post.
    I finally and definitely agree to both point of view.
    Math is needed to understand the world (I’m french, and french guys don’t understand world without maths) and and specifically algebra (including logic, magma, abelian groups, quotient and so on …) math is the fundament of computer science.
    I had life before to become germano/french guy blinded by first order logic and truth complexity, I was just a simple kid amazed by what a machine ca do when I was asked to do it, whatever my math background was.
    So finally I deffinitely agree with the post, just take a machine, write and amaze yourself of what it can do, math will follow.

Post a comment.