Another last-minute one, so, you're getting something short and mostly inconsequential.
In our post about our plans for hand calculations of π, we mentioned casting out nines and elevens. If you're not familiar with these methods, you might theoretically be interested in what they are. If you are familiar, you might not have given any thought to a pretty fundamental question for our application: how do you do it on a fraction?
This math probably won't be terribly readable, but we still want to give it a go.
To start with: what even is casting out nines? Well, let's look at it from two angles: the goal, and the mechanics.
If you've done a lot of arithmetic, you're probably familiar with the kinds of mistakes you make while doing arithmetic. The kinds of mistakes we make most often are missing a carry or borrow, although we have also confused mixed up numbers and other errors of impatience. (We have a lot of impatience.) With the exception of swapping digits, most errors involve a number changing by one or a few...
...which probably means that the number will change modulo nine.
And that's the mechanics: you're calculating what a number equals modulo nine - what you would get if you divided that number by nine. And you're calculating modulo nine because:
- 10 is equal 9+1 and therefore equal to 1 mod 9, so xty y, 10x+y, is the same as x+y mod 9.
- 100 is equal to 99+1 and therefore equal to 1 mod 9, so x hundred and yty z is just x+y+z.
- 1000 is equal to 999+1, and 10000 is equal to 9999+1, and so on forever.
If you're calculating modulo nine, you can do it by just adding digits. And subtracting nine if you end up bigger than nine. (That's probably why it's called 'casting out nines' - you throw away nines.)
(And you can also do elevens by taking pairs of digits, because reasons. We're tired, you figure out why that works. Hint: 99 is a multiple of 11.)
So, that's casting out nines. But 3.14 mod 9 is still 3.14. How do you check your work with decimals?
...the answer is weirdly simple: just "keep adding each digit and casting out nines".
It works because, if 3.14 is the correct answer, then 314 should be 100 times the correct answer. You can just multiply things by ten until you turn your finite decimal into an integer, and if the integer is right, the decimal is right.
And because you can just multiply by ten, you don't have to actually do it.
22 is 4 mod 9. 7 is 7 mod 9. If we calculate 22/7 and get 3.14 with 0.02 left over ... well:
- 3.14 is 8,
- 8 times 7 is 56 is 2, and
- adding the 2 left over gives us 4.
You literally just declare that 0.02 is equal to 2 mod 9 and you're good to go.
Which is brain-bendy to us if we think about it too long, but which is definitely convenient.
(If you're doing 11s, you have to move over pairs of digits instead of single digits. We will not explain why.)