Math For Programmers

Math For Programmers

To put this in perspective, think about long division. Raise your hand if you can do long division on paper, right now. Hands? Anyone? I didn't think so.

I went back and looked at the long-division algorithm they teach in grade school, and damn if it isn't annoyingly complicated. It's deterministic, sure, but you never have to do it by hand, because it's easier to find a calculator, even if you're stuck on a desert island without electricity. You'll still have a calculator in your watch, or your dental filling, or something. Why do they even teach it to you? Why do we feel vaguely guilty if we can't remember how to do it?

Update: You know, I posted this link because I thought he had some interesting comments on math education and on how it relates to programming, and you all took it and turned it into some kind of dick-waving referendum on "well of course I do long division every day!" Good for you. Thank you for sharing. Thank you for like, not getting bogged down in the minutiae or anything.

I hate each and every one of you. STFU.

Tags: ,
Current Music: Decoder -- Hacked ♬

83 Responses:

  1. xenogram says:

    [Raises hand]

    Crikey, that's not hard, unless you've done so much abstract maths that you can't divide up your shopping bill. Can't remember matricies though.

    • pozorvlak says:

      [Raises hand]

      FWIW, the long division algorithm is a lot more memorable if you do it for polynomials and then set x equal to 10 (or whatever base you're working in).

  2. mayaknife says:

    Why do they even teach it to you?

    Perhaps because the same algorithm can be used for other things which most calculators still can't do, such as dividing one polynomial by another.

  3. fo0bar says:

    10 minutes ago, I thought that if you didn't know long division, you shouldn't be anywhere near a computer.

    Now, I still think that, but my faith in humanity has been knocked down a notch or two.

    • jwz says:

      I no longer remember how to do long division. Because I haven't done long division since elementary school. Because I haven't needed to do long division since elementary school.

      So I'll just go ahead and be your poster child for world euthanasia or whatever. I'm glad to serve as a warning to others.

      • fo0bar says:

        JWZ. Doesn't know long division. A sorry excuse for a human.


        I guess the reason I know long division is I've done enough modulo operations over the years to believe that long divison is the natural progression from division remainders. Throw in some subtraction and multiplication (and, occasionally, guesses), and you have long division.

      • Have you really forgotten it or is it just not in your L1 cache? Pick up a piece of paper and writing stick and try 1969 / 23 or something. I've, well, not *needed* to do long division in a while, but I've *wanted* to on occasion, and not had a booted computer or a calculator handy.

        • jwz says:

          No, I really don't remember. I might be able to re-invent it, but it would be faster to look it up, or even do iterative subtraction. But frankly I think I'm far more likely to need to start a fire with two sticks than I am to ever need to do division on paper, if we're tossing around ridiculous "but what if" scenarios, probably involving desert islands or apocalypses.

          And I don't know how to do that either.

          • Hm. OK.

            I have a small and completely unjustifiable sense of moral superiority here over the fact that I remember how to do long division. I agree that making a fire from scratch is a more likely need.

          • airstrip_one says:

            Being able to reinvent an algorithm quickly is as useful as actually remembering it.

            It's unlikely I'll ever do arithmetics on a piece of paper, either, despite the fact that I don't bother to carry a PDA or a watch. If I'm not near a computer, I simply never have a need to make an arithmetical calculation that takes more than few seconds of thinking.

            • hafnir says:

              In my Diff Eq's class, for a test I memorized the general formula for solving second order diff. eq's (basically this, but with all the math combined in fewer steps). The teacher gave me almost no credit even though the answer was completely right. I got mad and asked him and he's like "will you remember this equation in a year?" and I told him "I'll look up the equation in the book in a year". It's been 15+ years, and I don't remember either, but obviously I can look either up!

          • babbage says:

            I might be able to re-invent it, but it would be faster to look it up, or even do iterative subtraction.

            While repeated subtraction works, actually dividing is far faster. I once discovered an arbitrary-precision program for calculating π which spent 95% of its computation in repeated subtraction. Somewhat ironically, it was Numerical Recipes in C.

          • hafnir says:

            I have a bachelors in math and I forgot how to do long division! I rederived it a few weeks ago 'cause that's when I realized I'd forgotten, and on completion:

            a) It's roughly optimized iterative subtraction.
            b) I found myself saying "this is stupid" once I had the answer, and immediately lost all my regrets about forgetting in the first place.

        • nelc says:

          I'm surprised that you're talking about needing a piece of paper. Doesn't anyone do long division in their heads any more? I'm not great at it, but I can usually work out a couple or three sig fig before I get lost. I used to it in the studio where I worked while people would go off to hunt for a calculator. When I came out with the answer they'd stare at me as if I was some kind of freak, but I figured that was because they were all arts graduates.

          Gosh, maybe I am a freak.

      • wfaulk says:

        Weird. I often find it much quicker to do simply do long division than to bother finding a computer. Of course, I usually have pen and paper on me. And no one seems to have calculators any more.

        • sherm says:

          And no one seems to have calculators any more.

          Wouldn't it be great if there were some sort of electronic device with a numeric keypad that was virtually attached to the wrist of every human over the age of six that we could somehow build a calculator into?

          • jwz says:

            I wonder if you can implement one of these "calculators" in terms of something everyone has, like Tetris? I know I've seen it done with glider guns...

        • solarbird says:

          I often find it much quicker to do simply do long division than to bother finding a computer.
          Indeed. Particularly when walking about in shops doing the occasional price comparison. I'd say I do long division by hand at least weekly, if not more. If I have to do a whole series, I grab a calculator. (And if I need to balance a set of reactions, I grab a real calculator and do it in linear algebra...)

          • ahruman says:

            In Sweden we have these things called comparison prices, which tell you how much something costs per kg or per litre as appropriate. Perhaps they should be removed in order to promote the dying art of long division.

        • pir_anha says:

          yup, same here. i have a calculator (i just looked for it, and its batteries have run out), but i don't carry it around with me while shopping.

      • harryh says:

        I no longer remember how to do long division

        Somehow I doubt that is really true. Sure, it might take you a bit longer than it did when you were 10 and it prime divisioning condition, but somehow I suspect that if someone gave you a pen & paper and demanded that you devide 9774 by 27 you'd be able to come up with the answer in a minute or three.

        • jwz says:

          I'm sure I could come up with the answer, but I'm equally sure it wouldn't be by using the long-forgotten elementary-school algorithm. I suspect I'd end up just binary searching it.

      • lindseykuper says:

        Do you remember learning it solidly in the first place? I'm wondering if maybe Steve Yegge and most of his audience just weren't paying attention because they figured out early that school was bunk.

        When I was in fourth grade, they still had me scared into paying attention, and I still remember how to do long division.

    • gfish says:

      And you shouldn't be allowed near metal tools if you can't smelt iron!

  4. inoshiro says:

    A very insightful read. I took a third year maths class on number theory that was nothing but proofs (induction, contradiction, etc), and linear algebra. We developed and formalized the RSA cryptosystem from basic principles of prime factorization and congruence theory.

    It was the most relevenant math class (since my calculus classes just taught me to sit down and crunch numbers) I had taken to that point, and has made my algorithms classes that much easier :)

  5. xinit says:

    Can't remember how to do long division... I can't remember how to do long hand square roots, but that was only showed to us one afternoon in high school just because someone asked. Division though isn't any harder than long hand multiplication, and it does have its uses if you can't get calc, xcalc, or bc to run...

    Next chapter: What the heck is an analog clock good for, anyway?

  6. zare_k says:

    I can do short division with no problem, but I can't remember the long division method at all.

    As a programmer, the most useful math class I took in college was a semester-long course concentrating on inductive proofs, set theory, prime numbers, etc. I had to take a about a year's worth of calculus freshman year and then never used any of it again until an advanced statistics course years later (at which point I'd forgotten all of it).

    • lilamp says:

      what the heck is short division? i must be confused, because after saying the long division algorithm sucked, the author of this article went on to describe exactly what i thought _was_ long division. when i do math in my head, i always visual it as if i were writing it down. i guess my brain doesn't grok math on a basic enough level to get around the visual/linguistic.

      • zare_k says:

        It's just a minor difference in notation, no algorithmic difference or anything. Here is a page with an example of how long division is written out with your interim subtractions and remainders trailing down the page. With short division you write the interim remainders up with the dividend. It's more visually compact so I find it easier to keep track of when I do mental arithmetic.

  7. allartburns says:

    I do long division (and multiplication) by hand weekly, if not daily. I also do a lot of fractional math for laying out physical things in the real world. A calculator is just one more thing I'd have to carry around with me. I have a nice HP at my desk, but it'd probably survive about 10 minutes in the shop.

    My phone purports to have a calcuator but I can do long division faster than I can unlearn RPN.

  8. lohphat says:

    Any private pilot has had to use an E6B (a military TLA for a circular slide rule) to pass their check-ride to get their license.

    That rekindled my math from HS about ratios and logs -- then it passed quickly.

  9. rapier1 says:

    This article is, of course, complete bullshit. Not because anything he says in it is egregiously wrong (even though some of it is hideously misguided) but because he is taking his specific and singular experience and saying "if its true for me it must be true for everyone". Even if, by some fluke, his experience is applicable to all people, he still hasn't proven it or even taken the first step towards proving it. As such it actually exemplifies a mind that doesn't actually think mathematically. This seems like a person that thinks in efficiency and short cuts. Its not efficient to do long division by hand so why should we? Likewise, its not efficient to postulate that random chance and natural biological processes explain human development when we can just say that it is the will of the flying spaghetti monster (which is an absurd parallel to draw I know).

    Personally, and this is only true for me, I found that proofs, conics, and all the other piddly math stuff that I was forced to learn (even though it was my choice to take honors level math classes in high school) taught me to view the world in different ways. Proofs were especially useful because it taught me how to break down a problem, look at the assumptions behind, and develop the processes which lead form the assumptions to the conclusion using basic logical building blocks. Which, when I was getting my degree in history, gave me a significant competative advantage over the other people in my major because history is *really* about who can argue an interpretation more convincingly.

    Oh, in daily life all that screwing around with long division and multiplication and such makes it really easy for me to quickly figure out things like price per unit of things in the supermarket, how much saving 15% is really going to save me, and why l can do basic algebra without having to resort anything much more complicated than a pencil. It also really helps when I'm laying tile, doing woodworking, or trying to prove to people why most every implementation of SSH sucks for bulk file transfer.

    As with all things YMMV.

    • ahruman says:

      OK, colour me intrigued. How do you prove that scp sucks using long division? :-)

      • rapier1 says:

        Well, not necessarily long division but basic math.

        Here is the background you need:

        TCP relies on receive side buffers for flow control (called RWIN for receive window). Basically if the buffer is Y bytes then you can have Y bytes in transit between points A and B at any one time (this is also known as the outstanding unacknowledged bytes). Now, the path between A and B has a 'natural' carrying capacity of bytes equal to the bandwidth multipled by the round trip time which is known as the BDP (bandwidth delay product (BDP=Bw * RTT)).

        If the RWIN is less than the BDP then utilization of the path will be RWIN/BDP because the sender simply won't send more than RWIN bytes of data at any one time.

        Now, SSHv2 (which most everyone uses) is a multiplexed protocol and as such it must implement its own flow control. They use an RWIN like method to do this. They set the SSH RWIN of 64k (defined at compile time). So it ends up that the effective receive window of any SSH connection is the minimum of the TCP and SSH RWINs (RWINe = min(RWINs, RWINt). Which means for most SSH connections on most systems you'll be limited to a 64K receive buffer size.

        Okay, so bringing everything together. Assume that
        RWINs = 64K
        RWINt = 256K (or any other arbitrary value)
        Bw' is the theoretical maximum throughput
        Bw is the bandwidth of the path (at its narrowest point)

        (RWINe/BDP)*Bw = Bw'
        (RWINe*Bw)/BDP = Bw'
        (RWINe*Bw)/(Bw*RTT) = Bw'
        RWINe/RTT = Bw'
        min(RWINs,RWINt)/RTT = Bw'
        min(64K, 256K)/RTT = Bw'
        64K/RTT = Bw'

        So the maximum theoretical throughput of an SSH file transfer will always be 64K divided by the roundtrip time. In other words SCP is great transfering files from one local machine to another but is atrocious if you need to transfer something from New York to San Francisco.

        So now for the division part:
        64K/1ms = 500Mb/s
        64K/50ms = 10Mb/s
        64K/100ms = 5Mb/s

        Which really blows if you have paid for a 1Gb/s connection (or even a 10Mb/s connection).

        I go into a bit more detail with pretty pictures at

        There is also a patch there that fixes the problem (and some other stuff).

    • valacosa says:

      I'm with you on this one. Proofs help me remember things.

      I wish more emphasis were placed on calculus, not less. Then again, I'm a physics major so I can't even brush my teeth without seeing calculus. I'm just a wee bit biased.

      Everyone should learn probability, though. Last time Tim Hortons ran "roll up the rim to win", every coffee cup had a 1 in 9 chance of winning. One night a bunch of us went for a coffee run and ended up purchasing 9 cups of coffee. One girl demanded that the winner of the prize tell her what they got. When we explained to her that buying 9 cups of coffee did not gaurentee a winner, she just kind of glazed over. Worse, someone else took her side!

      "But the odds are 1 in 9! And we have 9 cups of coffee!"


  10. saltdawg says:

    my columbian shipmate and I needed to do some math. We needed to deter,mine the length of some chain we needed to replace. My shipmate ain't that smart, but he was figurinbg out the length of the chain backwards and forewards.

    He ain't that smart, but when questioned, he chalked it up to his "former profession"

    I used to be a Jr. Psychatrist.


    I had no use for math as a psychytrist.

    I think columbians use math for something...

    • hermeticseal says:

      indeed, the money gets divided, the women get excited.

      i was somewhat relieved (?) to find that i can still do long division, just like the fuckin' penguins taught me to do so long ago. goddamn penguins.

  11. ianbicking says:

    My Mom is an elementary school teacher, and she (and other teachers at her school) haven't taught long division for years. I think that's the norm for progressive math education now. No doubt there's great swaths of the educational landscape where that isn't the case, but I think it's acknowledged among those who don't talk about stupid things like the "Three R's" that long division isn't a useful skill. If it is taught, it should be for its value as an interesting algorithm that is potentially comprehensible by more advanced students. Simply learning the steps as a *skill* is questionable.

    It certainly is related to other useful algorithms which can't be easily done on a calculator. But to understand that you either have to be good at math, or you have to have a math education much deeper than anything covered in standard arithmetic.

    • pozorvlak says:

      But it isn't an interesting algorithm, or rather, it's interesting only because it's not very good. It has horrible complexity (IIRC), for one thing.

      • ianbicking says:

        What you are learning about algorithms at this level isn't quite so involved as complexity. More like how to follow a set of rules, how to check your work, etc. More learning the skills of a computer, less the skills of a computer scientist.

    • rapier1 says:

      Does the current level of mathematical acheivement of American school students bear out that this progressive math is effective?

      • ianbicking says:

        Well, realistically high-performing students are reaching higher levels earlier in their education than they have before. Calculus is fairly common in schools, for instance, and seems to become only more common over time. For low-performing students, I don't know.

        Focusing on the levels where long division would actually be taught, skipping it does give more time for things like fractions, which I think *are* important. Unlike long division, fractions form the basis for lots of later mathematics.

        As for the testing question, well, if you test for long division then clearly skipping long division is a problem. If you don't then you'll never notice it, because long division doesn't lead directly to any other math skills.

        • rapier1 says:

          Well testing for specific things is actually different that mathematical acheivement. I was more thinking about how many US students are goign into engineering programs and other math intensive careers. The true impact of how a kid is being taught in say, 3rd grade, usually doesn't become apparent until many years down the line anyway.

          Also, I'm not sure why long division is such an issue. Don't people divide things any more? I mean, really. The only difference between long and short division is where the calculation takes place and the amount of work shown. Since quite a lot of math still requires division then I'm not sure how you can say long division doesn't lead to other skills.

          I guess you can just teach kids to use a calculator but what happens when they don't have a calculator? I can't be the last person in the world that doesn't use a calculator or computer for basic math problems, can I?

  12. jonabbey says:

    For individual divisions of modest size, I do long division, just because it's less hassle than digging out my Palm T|X and going all EasyCalc over it.

    Now, Algebra, Geometry, Trigonometry, Calculus, DiffEQ, Vector Calc, Topology.. all that has done zero for me in the real world, to date. Maybe possibly Geometry and Trig once or twice in twenty years, but little more than that.

    Linear Algebra was quite useful when I was doing some graphics programming, though, so I guess I should add points to Trig for that.

    I've not used any of that for paid employment, though. Just lots of discrete math.. and long division, when I'm filling out timesheets manually, rather than using a spreadsheet.

    • jonabbey says:

      I should add, I do not include Probability and Statistics in the above list of use-less math. That's some good eating, there.

  13. lindseykuper says:

    Not really into brevity, is he?

    I'm no expert, but I have some ideas about why they teach it to you.

  14. dojothemouse says:

    The way it's taught might be bunk, but teaching kids how to execute a useful algorithm isn't the worst lesson in the world. I spent a half a semester on RSA, and I'll never have to calculate RSA by hand anymore either.

  15. jcfiala says:

    Include me in the group of geeks who do long-division. heck, I can often get answers faster than some of my non-numeric friends can pull out their calculator and put in the answer. Sometimes I've been known to do it in my head while I'm driving.

    that said, it's an interesting article.

  16. I often do long division by hand, when it's otherwise too much annoyance to pull out my PDA or start bc.

    It's easy and fast. My only real annoyance with learning it way back when was that there were too many damn drills of homework of it, probably because it was easy for the teacher to grade.

  17. Being the sort of high school student who would lose his calculator within the first week of every school year, I wound up doing an awful lot of math by hand. And since that was back when I was young and my brain still worked, it's pretty much stuck with me.

    The author does have a point, in that linear algebra and similar numerical techniques are tremendously useful in CS, but those courses don't get much play in many CS curricula.

    A place I'm interviewing at right now does their heavy lifting with Matlab, which prompted me to pick up a Matlab book before going in to talk to them. The effort of grinding through the math side of it makes me wish I'd taken some courses along that line back in school. Not that I'd remember much at this point, but it'd probably be faster and easier to relearn it if I'd been exposed to it before.

  18. flipzagging says:

    I can still do long division by hand. Personally I'd feel a bit powerless if I couldn't do quick, reasonably exact calculations in my head or with a scrap of paper. But I guess I could live without the skill.

  19. transgress says:

    i remember long division, which is odd because i remember in school hating division, and its the main reason i stopped doing my math in grade school, which is probably the main reason I ended up dropping out- however I can still remember how to do it 15 years later. I find it odd that you cannot remember how to do it, and question the honesty of the statement, but I guess odder things have happened.

    I don't see a problem teaching this in school, looking back I think the biggest problem I had in math wasn't that they taught long division, but rather as a general rule of thumb short cuts were taught instead of explanations, so I always found myself stuck trying to remember some short cut and not being able to, and then unable to do the math itself because I never understood it in the first place, I had just memorized some short cut for a test and long since forgotten it. Over time I've developed absurd methods for doing things that get me the right answer, but generally takes me longer. For instance if you ask me to find x% of y, i will take y and divide it 2 or 4 times over and over again until I get a small enough percentage that I can add back up to find x%.

  20. jkonrath says:

    I still remember how to do long division. My issue is that I remember so well how to do something I learned 30 years ago when I was essentially bored and didn't want to learn it, but if I had learned how to do something similar a week ago, I probably would have forgotten it by today.

    A secondary concern is that it doesn't seem that anyone makes a good, cheap calculator anymore. I know there are TI scientific ones, and I'm aware that every OS has a calculator program, but the typical $5 office calculator is a piece of shit these days. They look pretty, but they all have spongy keys that don't feel right, or crippled or stupid features, or unreadable displays. I'm still using a calculator I stole from my job about 15 years ago, because I can't find a suitable replacement.

    • capo_mojo says:

      A $100 HP calculator that lasts basically forever is a reasonable alternative to a new $5 calculator every 2 years. I'm still using the 28S I bought as an undergrad, um, 20 years ago. If pressed I could probably even find the 15C that it replaced.

      And now that I look at their web site, HP makes $20 calculators now. Maybe they have been ignoring their calculator business well enough that the new cheap ones don't suck.

  21. spo0nman says:

    Can do it and don't feel guilty about not remembering how to integrate.

  22. pozorvlak says:

    I'm currently a maths grad student, and in a past life I've held programming jobs, and I've always believed that programming and doing maths (by which I mean real maths, ie finding and proving theorems) are at root the same activity. They're both about thinking logically in an abstract domain. They're both about looking for generalisations and thinking clearly and precisely. The differences that I see are that 1) other mathematicians are usually a bit more liberal in what they'll accept than computers, 2) programming is typically closer to a real-world application, 3) maths papers are typically denser and hairier than programs, 4) programs are often much larger than maths papers.

  23. alisgray says:

    maybe this is why my GRE math skills score was so much higher than I expected it to be. It took me so long to learn this skill in school that I still remember.

    Here is a fairly tedious game to remind you of what it is, and how it works.

    I still have some vague intentions of learning how to use a slide rule or an abacus.

    • defenestr8r says:

      The GRE is precisely the last time I can think of doing long division, and my math score was pretty good as well. That being said, it was one of the more painful parts of my dormant math brain to kickstart.

      And, of course, long division is critical to me getting my PhD in history. So glad I took that math section...

      • rapier1 says:

        Having gotten a degree in history as well I can tell you that division was quite helpful to me. Along with stats, algebra, some calculus and the like. Of course, I was focused on US/Soviet strategic arms control theory and I had to take into account things like economic policies, diminishing returns calculations, minimum acceptable force level ratios and the like. So I guess it depends on the kind of history you are most involved in.

  24. blaisepascal says:

    Except I don't always use paper. I remember computing my biorhythms in my head on long walks when I was younger (Step one: compute how many days D you've lived to the nearest day. That's all multiplace multiplication and addition. Step two: compute D%33, D%28, and D%23. That's where the long division came in play). If I needed to, I could still do it.

  25. rickbooth says:

    I can do long division on paper, but then I'm a maths teacher, so no surprise there. I've seen this piece before, and the problems with it are fairly glaringly clear: he assumes all education is vocational, all engineers and scientists are coders, and all coders need the same chunks of maths he does. Three strikes, gone.

    As to why I teach long division: firstly, you certainly want to teach short multiplication and division, because otherwise these are unmotivated magic keypress sequences on calculators, as opposed to operation on a system you understand at some sort of gut level. Then kids invariably *want to know* how you would deal with numbers with more than one digit, and the answer is right there (and of course long division and multiplication are mirror images of each other). It also makes it obvious, if your teacher is doing their job, that division is just repeated subtraction.

    And if "write down the biggest smaller multiple, write how many it was, take it off, repeat one place down" is annoyingly complicated, I'm not sure how he gets any coding done.

    • rapier1 says:

      I also think he misses out on the idea that teaching math is not just a way of teaching kids a utilisable skill. Its more, in my view at least, about teach kids a different and more logical way of looking at the world. If all you know is how to punch buttons and get an answer you end up being divorced from the process and it all ends up being magic.

      '10 divided by 2 is 5'
      'because the calculator told me so'

  26. Long division isn't hard.

    • jwz says:

      WOW NO SHIT? Something they teach you in third grade ISN'T HARD?? How can this be? Thank you for your brilliant and yet utterly point-missing insight!

  27. jesus_x says:

    I 100% agree with it's comments on math education, andhave been saying this also for years. We teach math ass backwards, and even do THAT poorly.

    Also, for the record, I wave my dick for entirely different reasons that long division.

  28. xah_lee says:

    for JWZ readers:

    The Condition of Industrial Programers