Humble Pi: When Math Goes Wrong in the Real World
Rate it:
Open Preview
Kindle Notes & Highlights
Read between October 16 - October 19, 2022
30%
Flag icon
You can count eleven distinct numbers with your fingers: zero to ten.
31%
Flag icon
The only downside is that you break the link between the numbers you are using to count with and the number of things you are counting. The first object corresponds to zero fingers, the second to one finger and all the way up to the eleventh object being represented with ten fingers.
31%
Flag icon
Counting from zero breaks the link between what you’ve counted to and what the total is. Counting from zero to fourteen is a total of fifteen.
31%
Flag icon
most off-by-one errors come from the complications of convincing code to run for a set number of times or count a certain number of things. I’m obsessed with one specific species of off-by-one error: the fence-post problem. Which is the second weapon in TheJosh’s arsenal.
31%
Flag icon
This mistake is called the fence-post problem because it is quintessentially described using the metaphor of a fence: if a fifty-meter stretch of fence has a post every ten meters, how many fence posts are there? The naive answer is five, but there would actually be six.
31%
Flag icon
If an escalator is refurbished twice, then it will be in use three times longer than it would be if it was never refurbished at all. The people who run the Tube forgot to mind the gap.
31%
Flag icon
Off-by-one errors also explain a struggle I always had with music theory. Moving along piano keys is measured in terms of the number of notes encompassed: hitting C on a piano, skipping D, and then hitting E is an interval called a third, because E is the third note on the scale. But what really matters is not how many notes are used but the difference between them.
31%
Flag icon
music intervals count the posts when they should count the fence!*
31%
Flag icon
So, when playing the piano, going up a “third” means going up two notes, and going up a “fifth” ...
This highlight has been truncated due to consecutive passage length restrictions.
31%
Flag icon
Counting the dividers and not the intervals means that the note between the transitions is double-counted. It is also why an “octave” of seven notes (and...
This highlight has been truncated due to consecutive passage length restrictions.
31%
Flag icon
When it comes to measuring time, we use a weird mix of counting posts and counting the sections of the fence. Or we can look at it in terms of rounding.
31%
Flag icon
Age is systematically rounded down: in many countries, a human is age zero for the first year of their life and increments to being one year old only after they have finished that whole period of their life. You are always older than your age.
31%
Flag icon
If you count the day of your birth as a birthday (which is hard to argue against), then when you turn thirty-nine, it is actually your fortieth birthday. True as that may be, in my experience, ...
This highlight has been truncated due to consecutive passage length restrictions.
32%
Flag icon
Vitruvius is warning those building a temple not to make a fence-post mistake and end up with one column too many. If anyone can find an older example of a fence-post mistake, or any off-by-one error, I’d love to hear about it.
32%
Flag icon
James proposes a day-zero rule that would mean that all contracts are required to acknowledge day zero—an initiative I fully support.
33%
Flag icon
Then one day mathematician Søren Eilers was walking around Legoland in Denmark and was unsatisfied with the 102,981,500 number he saw on display. Sometime later, in his office at the University of Copenhagen, he set about working out the number for combining six two-by-four Lego bricks but factoring in the fact that the bricks could be placed next to each other as well as on top of each other. This was not a calculation that could be done by hand. Even with only six Lego bricks, the number of ways they can be attached to each other is too great to be counted by a human.
33%
Flag icon
To make sure his number was right, Eilers gave the problem to a high-school student, Mikkel Abrahamsen, who was looking for a mathematics project. The code Eilers used was written in the Java programming language and run on an Apple computer. Abrahamsen came up with a new way to explore the combinations and programmed it in Pascal to run on an Intel machine. Both completely different methods gave the same answer of 915,103,765, so we can be fairly confident it is correct.
33%
Flag icon
Because calculating combinations can give such large numbers, they are often used in advertising. But very rarely do companies bother trying to get the answer correct.
33%
Flag icon
Being a combinatorist, he recognized that 1,001 is the total number of ways to pick 4 things out of a total of 14 options, so he figured they had 14 toppings and customers could choose 4. Actually, the restaurant had 26 toppings (he asked) and had picked “1,001” just because it sounded big.
33%
Flag icon
The number McDonald’s used was the result of a very different calculation. It’s the answer to the question of how many different ways you could arrange 8 menu items.
35%
Flag icon
UK postcodes have much finer resolution than those of Australia or the US. The building my office is in has one all to itself, a postcode that points at a single building. I can give my address as just my name and my postcode.
35%
Flag icon
If the UK wanted to really max out its postcode format by allowing all letters and digits in any positions of two groups of three or four symbols each, then there would be 2,980,015,017,984. Enough for one unique code for each patch of ground of about thirty square centimeters. I think that’s a great idea. When I do my online grocery shopping, I could give each thing I’m ordering the delivery address of the exact cupboard it needs to end up in.
35%
Flag icon
People online talk about how some companies would use only five-digit codes, despite having tens of thousands of customers. Five digits allows for a hundred thousand possible codes, and ten thousand customers would use 10 percent of those. In math, we’d say that the space of possible codes is saturated to the rather high proportion of 10 percent.
35%
Flag icon
At fewer than ten possible codes per customer, it would not take long to guess a valid one and make a “free” call. This kind of security through obscurity works only if the number of possible codes swamps the ones that are valid.
35%
Flag icon
Welterweight UFC fighter Rory MacDonald noticed that whenever he walked out before a fight they would not play the walkout song he requested. His opponents were picking aggressive songs to get them in the mood, and these were being played, but his choices seemed to be disregarded. I imagine that trying to get in the zone before a fight is not helped by the unexpected blasting of MC Hammer’s “U Can’t Touch This.” Other fighters were making fun of his music choices. This persisted until, one day before a fight, the producer came up to Rory and apologized for not being able to play the Nickelback ...more
36%
Flag icon
The game designers had deliberately given Gandhi the lowest non-zero aggression rating possible: a score of 1. Classic Gandhi. But later in the game, when all the civilizations were becoming more, well, civilized, every leader had their aggression rating dropped by two. For Gandhi, starting from 1, this calculation played out as 1 − 2 = 255, suddenly setting him to maximum aggression.
36%
Flag icon
The computer was getting an answer of 255 for the same reason computers have trouble keeping track of time: digital memory is finite. The aggression ratings were stored as an 8-digit binary number. Starting at 00000001 and counting down two gave 00000000 and then 11111111 (which is 255 in normal base-10 numbers). Instead of becoming negative, a number stored in a computer will wrap around to being the maximum possible value.
36%
Flag icon
Trains in Switzerland are not allowed to have 256 axles. This may be a great obscure fact, but it is not an example of European regulations gone mad. To keep track of where all the trains are on the Swiss rail network, there are detectors positioned around the rails. They are simple detectors, which are activated when a wheel goes over a rail, and they count how many wheels there are to provide some basic information about the train that has just passed. Unfortunately, they keep track of the number of wheels using an 8-digit binary number, and when that number reaches 11111111 it rolls over to ...more
36%
Flag icon
There have been plenty of times when a hardware issue has been covered by a software fix, but only in Switzerland have I seen a bug fixed with a bureaucracy patch.
36%
Flag icon
There are ways to mitigate rollover errors. If programmers see a 256 problem coming, they can put a hard limit in place to stop a value going over 255. This happens all the time, and it’s fun spotting people getting confused by the seemingly arbitrary threshold.
36%
Flag icon
If you’re in a WhatsApp group with 256 people (you and 255 friends) and you try to add a 257th person, you will simply be stopped from doing so. But given that you’re pretty much claiming to have 255 better friends, the newbie is probably too tenuous an associate to take it personally.
36%
Flag icon
The threat of a rollover error is also why the game of Minecraft has a maximum height limit of 256 blocks—an actual brick-wall solution.
37%
Flag icon
The programmers behind the original arcade version of Pac-Man had set the level number to be stored as an 8-digit binary number that would loop around when it rolled over. But they forgot to follow through all the consequences of that decision, and a convoluted chain of computer glitches are initiated on level 256, causing the game to fall apart.
37%
Flag icon
The game does not fail on level 256 because it cannot store the level number. As always, programmers start counting from zero, so level 1 is stored as index 0, level 2 is index 1, and so on (I’ll use “index” to refer to the number stored, as opposed to the actual level number). Level 256 is stored as index 255, which is 11111111 in binary. No problem. Even moving on to level 257 would just roll the index over to zero and drop Pac-Man back into the first maze. The game should be playable forever.
37%
Flag icon
The problem is the fruit. To add some variety to Pac-Man’s diet of dots and ghosts, there are eight different types of fruit dropped in twice per level (including a bell and a key, which Pac-Man seems to eat with the same ease as he does an apple or a strawberry). Each level is assigned a specific fruit, which is shown at the bottom of the screen, along with Pac-Man’s recent fruit consumption. It is this ornamental fruit parade that causes the complete meltdown of the game.
37%
Flag icon
Digital space was at such a premium in old computer systems that there are only three numbers stored in the game of Pac-Man as you play: what level you are on, how many lives remain, and what your sc...
This highlight has been truncated due to consecutive passage length restrictions.
37%
Flag icon
the game needs to be able to reconstruct from scratch what fruit Pac-Man must have consumed recently. There is room to depict only seven pieces of fruit, so the game needs to show the fruit from the current level and up to six levels before that (depending on how many levels have been played).
37%
Flag icon
The problem occurs when the code takes the level index and converts it into a level number by adding one. Level 256 is index 255, which gets increased by one to be . . . level 0. Zero is below seven, so it tries to draw as many pieces of fruit as the level number. Which would be fine if it drew zero pieces of fruit, but sadly, it draws first and counts second.
37%
Flag icon
The computer is now going to try to draw 256 pieces of fruit instead of the normal seven or fewer. Well, I say “fruit,” but the fruit menu runs out after only twenty rows. For the twenty-first piece of fruit the code looks at the next piece of the computer’s memory and tries to interpret it as a piece of fruit. It then keeps rolling through the memory as if it were some exotic table of alien fruit and draws it all as best it can. Some of this does match other symbols to be displayed in the game and so, as well as colorful noise, the screen is filled with letters and punctuation marks.
37%
Flag icon
Because of a quirk of the Pac-Man coordinate system, after the fruit fills the bottom of the screen right to left, it then moves to the top-right corner of the screen and starts filling the screen column by column. By the time 256 pieces of fruit have been drawn, half the screen is completely covered.
37%
Flag icon
the system does not complete a level until Pac-Man has eaten 244 dots. On this last, broken level, the mutant fruit has obliterated loads of the dots, so Pac-Man can never eat the required 244 dots and is doomed to wander what is left of his broken maz...
This highlight has been truncated due to consecutive passage length restrictions.
38%
Flag icon
The most dangerous 256 error I have found so far occurred in the Therac-25 medical radiation machine. This was designed to treat cancer patients with bursts of either an electron beam or intense X-rays. It was able to achieve both types of radiation from the one machine by either producing a low-current electron beam, which the patient was directly exposed to, or a high-current electron beam, which was aimed at a metal plate to produce X-rays.
38%
Flag icon
the Therac-25 looped through a piece of setup code, and only if all the systems were verified as being in the correct settings could the beam be turned on. The software had a number stored with the catchy name of Class3 (that’s just how creative programmers can be when naming their variables). Only after the Therac-25 machine had verified that everything was safe would it set Class3 = 0.
38%
Flag icon
To make sure that it was checked every time, the setup loop code would add one to Class3 at the beginning of each loop so it started at non-zero.
38%
Flag icon
Unfortunately, the Class3 number was stored as an 8-digit binary number that would roll over back to zero after it had maxed out. And the setup loop would be running over and over while waiting for everything to be ready, incrementing Class3 each time it ran. So every 256th time the setup loop ran, Class3 would be set to zero, not because the machine was safe but merely because the value had rolled over from 255 back to zero.
38%
Flag icon
On January 17, 1987, in Yakima Valley Memorial Hospital in Washington (now Virginia Mason Memorial), a patient was due to receive eighty-six rads from a Therac-25 machine (the rad is an antiquated unit of radiation absorption). Before the patient was to receive the dose of X-rays, however, the metal target and collimator had been moved out of the way so the machine could be aligned using normal visible light. They were not put back.
Dan Seitz
Gaaaaah
38%
Flag icon
The fix to the software was disturbingly simple: the setup loop was rewritten so it would set Class3 to a specific non-zero value each time instead of incrementing its previous value. It’s a sobering thought that neglecting the way computers keep track of numbers can result in preventable deaths.
38%
Flag icon
What is 5 − 4 − 1? It’s not a trick question: the answer is 0; and it’s not always as easy as it looks. Excel can get this wrong. The system of binary digits used by computers to store numbers in digital memory not only causes rollover errors, but also can break even the easiest-looking math.
38%
Flag icon
Binary has the same problem trying to store some fractions. Adding 0.4 to 0.1 does not give you 0.5 in binary, but rather:
39%
Flag icon
If you just enter = 0.5 − 0.4 − 0.1 into Excel, it will get it right. It knows that the total to subtract of 0.0111111 . . . should be exactly ½. However, if you enter = (0.5 − 0.4 − 0.1)*1, that freezes the error in place.