Word up, know what I’m sayin’? Calculus rules everything around me, C.R.E.A.M.

– Wu-Tang Clan, “C.R.E.A.M” (but not actually).

When I was maybe about seven or eight years old, my Dad decided he would regularly sit down with me after school and try to teach me additional math. He would teach me concepts that were a little bit ahead of the curve in school. One day I just couldn’t focus, felt like it was too hard, and had enough.

“I hate math! Why do I need any of this?! I’ll get by with just adding and subtracting stuff, that will be enough!” – Young, stupid qword

I still remember exactly how sad he was to hear me say that, and he was rather silent for the rest of the day. He was an electrical engineer, and used math all the time for his job. Math was what helped him lift his immediate family out of poverty when growing up, and make a better life for them.

I didn’t understand this when growing up, and I think many others in grade school didn’t either. I remember it often being insisted that it would be “important for my future,” but I didn’t know what a “future” was, and “you’ll understand when you’re older” was so common a hand-wave that grown-ups would say that it didn’t have any meaning at all.

I once stayed up all night playing Metal Gear Solid on the PlayStation 2 all the way until 7am, when my dad woke up and lost his shit for me being up all night. I told him that I think I wanted to learn math again because they say you need it to make video games, and like games so that sounded cool. He forgave me and decided not to turn the PlayStation off (we couldn’t afford a memory card at the time, so it’d stay running all the time to not lose progress).

I returned to doing math lessons with my dad, but they tapered off pretty quickly as he got busier with his work. My grades in math took a back-seat all the way until high school, and around then my prefrontal cortex started clicking together and it dawned on me that getting rich is important because money lets you make a better and more comfortable life for yourself. A good school leads to good money and my math grades need to be good enough to get in - so at the very least it was a means to an end, and that’s probably what everyone meant by “it’s important for your future.” I’m maybe thankful that so many other kids in my school didn’t care about math, because it makes knowing it that much more valuable.

I was at least good enough to start a computer science career, and good enough to graduate with the degree. I thought that would probably have been the last use of math that would’ve happened in my life.

Except it absolutely wasn’t.

I honestly and truly use a lot of math, every day. And I don’t mean the “well I program computers and programming is math so I’m doing math ha ha“-argument (which is legitimate) - I use math both at work outside of programming, and in my daily life so often that I don’t even notice, and I think not knowing enough of it is a serious handicap. I’ll even give you a few examples:

  • Lottery tickets are dumb as fuck. Never buy them. You will not win. (But also have the sensibility to not insult people you know who do buy them).

  • How much and when should I drink coffee?

    I was recently watching an interview with Matthew Walker, neuroscientist and author of Why We Sleep. Matthew himself is completely decaffeinated, and does not drink any caffeine whatsoever as it affects sleep quality for the worse. He says that if you were to have a coffee though, then do it no later than 14 hours before you’re going to bed.

    If the half-life of caffeine in adults is 5 hours, how much caffeine is in your body 14 hours later?

    After 5 hours, half of a cup of coffee would be in your blood. After 10, it’d be a quarter. 15 would be an eighth, which is overshooting 14 just by a little bit. The exact answer is to throw 2^(-14/5) into Wolfram Alpha, which gives 0.14, so about 14 percent of that coffee is still in me. That’s not too far from an eighth, so I’m going to modify his advice and say at least 12 hours is likely fine - it’s the first 10 hours that dump most of the caffeine.

    What if I can power through the morning without coffee, but once I hit the afternoon I really just want a bit of a pick-me-up - but then I have to go to bed in nine hours. Could I make a cup of coffee but pour some of it out so that I’d not have too much caffeine in my blood later, trying to catch up to the 14-hour rule? How much do I need to pour out?

    Turns out that dumping exactly half will put me on track if I have about nine hours until bed. 2^((-9/5)) * 1/2 = 2^(-14/5).

    (Yes, I do actually do this. I’m trying to cut back first and then totally quit.)

  • Do not watch stock prices second-to-second.

    If you have some stock that will average a 15% annual return, but with 10% of volatility - what’s the chance that you’re in the green (greater than 0% return) by the year end?

    It’s 93%. Pretty good. I think you’re going to make some money.

    How about per month? With a normal distribution, mean for a month = 15 / 12, stdev for a month = 10 / sqrt(12), and you grab the z-score for the mean / stdev = ~0.43, it’s about 67%.

    What’s the chance that it’s in the green on any given day that you look (260 trading days a year)? 54%.

    Per trading hour? 51.3%.

    Per trading second? 50.02%. You’re almost flipping coins at this point, and red hurts a lot more than green pleases. So don’t look at it so often. You’re going to get a heart attack.

    This is from Fooled by Randomness. Great book.

  • A large pizza is always a better deal than the medium.

    (I’ve never seen this to be false, but run the numbers yourself with your local pizza place).

    A standard medium here is 12”, and a large is 14”. How much more area does a large have compared to a medium? 14^2 / 12^2 = ~1.36. A large pizza is almost a third bigger than a medium (but it sure doesn’t sound like it because two extra inches of diameter doesn’t seem like much)! If the large is more than 36% more expensive, then it’s a losing deal, but otherwise it’s better value. Of course, you may not actually want that much pizza or want to spent that much in total so there’s other things to consider.

  • Trying to get cheap gas.

    There’s a gas station around me that has the best pricing, but isn’t open all the time. I try to calculate exactly how much volume to purchase at a more expensive but 24/7-establishment so that I can cover all the driving I need to do until the cheaper place is open the next day. My car at the time didn’t do any fancy calculations on my behalf or estimate mileage, so I’d do it myself and always be pleased when I nail it. My current car now does do estimations which is tons easier, but not as fun :(

And those are just the most recent examples in real life that I can pull off the top of my head. At my day job, way more:

  • De Morgan’s laws:

    if not (a or b) is the same as if (not a) and (not b) and also if not (a and b) is the same as if (not a) or (not b).

    This occasionally can make if-s easier to read, and is known as De Morgan’s laws.

    You can also “force” a structure where this is applicable by not-ing twice. I use this trick every once in a while on more involved Boolean logic. I’ve seen a lot of juniors not know this!

  • The birthday paradox.

    This one is surprising. If you have 23 people in a room and every birthday of the year is equally likely, the likelihood any two people share a birthday is roughly 50%. This is probably higher in real life, because birthdays are not equally likely in practice.

    We need to calculate a unique, random id per user for some purpose. If these ID are numbers, how many digits do we need such that the likelihood of a collision and re-roll is low?

    With six digits, when generating 1178 ids there’ll be a 50% chance that one of them will collide with another. Seven digits will take 3724 ids, and ten digits will take 117742 ids.

  • Job processing rates.

    We have a queue of stuff to do, that can be done in parallel on multiple machines. With one machine processing the whole queue, it’ll take all day to finish. With 100 machines, it’ll be done in a half-hour but the compute cost would be pretty expensive. We have six hours to complete it all - whats the optimal number of machines to pay the least for compute?

    This one was the most fun to model, and involved a lot of calculus and optimization.

  • Oh yeah, I also write a lot of code so there’s that too. Sometimes I get to do some algorithmic stuff, like work with graphs.

Pretty much, you ought to take math seriously. It lets you solve a lot of actual problems, and I think not knowing (enough of) it causes problems. My friend’s wife struggles to be able to calculate sales tax for things, and things like interest rates and mortgages are firmly beyond her - I think life takes advantage of her for this.

This post is dedicated to my Dad, who aggressively tried to teach me a number of things I couldn’t appreciate until much later.