I read a comment on Hacker News sometime December 2019 about
the general long division algorithm being unintuitive.
This guy stated his credentials and the comment after his
said surely he could come up with a proof in around 15-30 minutes,
so I like Math and I like to think I’m at least somewhat good at it
for not being a mathematician, so I challenged myself to write up a proof just for fun.
Although I wrote out the first sketch of the proof that night it took me until now to do a writeup of it.
Justification for a proof
You might ask well why a proof, and I just have to say
I feel a proof is the best way to see something intuitively.
Here is my attempt at proving the long division algorithm.
If you notice any mistakes please let me know on twitter
or on a github issue on my blog or by any other means you
can contact me with.
First I’ll show an example of the long-division algorithm
the way I learned it in school. This is honestly what I first
wrote down to get the correct mental model of the algorithm.
Example
So, first we will divide 128 by 5 just as an example.
We set up the equation:
5;15)128
We first notice five doesn’t go into 1 so we do our first division of five on 12 instead
five goes into 12 two times so we write two on top and subtract 2×5 or 10:
5;125)128−10
that subtraction produces two:
5;125)128−10−12
Then we bring down the 8:
5;125)128−10↓−128
and repeat until we get:
5;125535)1283−10↓−1281−25−123
Clearing up Some Hand-wavyness
So, there are some parts there that may seem a little mysterious and hand-wavy, so lets start by clearing those up.
First of all at this step where we subtract 10:
5;125)128−10
We are really or atleast can really divide 5 from 12, if you want to think of it that way 5 from 12*10 which is 120.
and subtracting 100 which five goes into 100 twenty times.
5;1205)128−100
This mental model will come in handy for our proof. There are some other mental models that will help us
for example notice that the right side of this equation is our result rewritten:
2553=20+5+53
Or we could rewrite our division as
5128=51⋅(100+20+8)
First Proof Attempt
WARNING: this is gonna get a bit more math-intensive than the rest of the post after this point…
This was my first attempt to the proof which I did that night upon reading the HN comment, though it appears correct to me, I’m not sure I like it as much as the second Proof Attempt I have below.
Thus we see the general form is like
the following where all numbers, n,x1,x2,…,xy, are of the set {0,1,2,3,…} and m is of the set {1,2,3,…}.
So, we know n−mx1−mx2−…−mxy is the remainder, and x1+x2+…+xy+mn−mx1−mx2−…−mxy is the result.
Thus we need to prove equality of:
mn=x1+x2+…+xy+mn−mx1−mx2−…−mxy
Let’s multiply each side of the equation by m and then prove equality by simplifying the right hand side.
m⋅mn=m⋅(x1+x2+…+xy+mn−mx1−mx2−…−mxy)
n=m⋅(x1+x2+…+xy)+m⋅(mn−mx1−mx2−…−mxy)
n=mx1+mx2+…+mxy+n−mx1−mx2−…−mxy
n=n
Proof Attempt 2
This was my second and in my opinion more elegant approach that I wrote up sometime well I was reviewing my other proof to be posted.
It’s very similar, but better in my opinion as I did not have to manipulate both sides of the equation (because generally manipulating both sides can get you into false proof territory.)
We could do this one other way where we start at:
mn=x1+x2+…+xy+mn−mx1−mx2−…−mxy
We could just simplify the right hand side of the equation to make it equal the left hand side.
(Distributive property of division and subtraction)