## Mathematics for Game Developers 5: Real Numbers part 1

The site was down over the weekend, when this post was due. So I'm declaring today to be Saturday. In reality, it's much too late on Monday night for me to be writing anything. So this will be short, and likely make even less sense than normal.

Last time, we ended with a definition of the rational numbers, and I observed that they should be enough for any use: they are packed densely on the number line, with infinitely many filling the gap between any two. How could there be any more numbers? Where would they go?

I'm sure you are all familiar with Pythagoras' theorem: in a right triangle, the square of the side opposite the right angle (the hypotenuse) is equal to the sum of the squares of the other two sides. This gives us a way to calculate the length of the diagonal of a unit square: the diagonal is the hypotenuse, and the square of its length is the sum of the squares of two adjacent sides of the square. If we denote the length of the diagonal by $latex d$, we have $latex d^2 = 1^2 + 1^2$, or $latex d^2 = 2$.

So what rational number is $latex d$? Since it's a length, it is clearly positive. So there must be positive integers $latex a$ and $latex b$ such that $latex d = \frac{a}{b}$. There will be many possible pairs, and it's useful to chose the smallest. In that case, $latex a$ and $latex b$ will have no common divisor: if they did, we could divide both by that common divisor, and get a smaller pair.

Since $latex a$ and $latex b$ have no common divisor, it follows that at most one of them is even: they can't both be, or they'd both be divisible by 2. Remember that bit. It's important.

Now, let's plug $latex d = \frac{a}{b}$ into the equation from Pythagoras' theorem: $latex \left(\frac{a}{b}\right)^2 = 2$. After a little routine rearrangement, that gives us $latex a^2 = 2b^2$. And that means $latex a^2$ is even.

Since the square of an odd number is always an odd number, it follows that $latex a$ can't be odd. It must be even, which means there is some integer $latex c$ such that $latex a = 2c$. We can plug that back into the equation, giving $latex (2c)^2 = 4c^2 = 2b^2$. Divide it all by 2, and we have $latex 2c^2 = b^2$. So, by the same logic, $latex b$ must be even too.

But wait. Didn't we just say that $latex a$ and $latex b$ have no common divisor? They can't both be even. We've managed to prove a contradiction, and that means our original assumption cannot be true. That assumption was that $latex d$ is a rational number.

If you're an ancient Greek mathematician, this comes as a bit of a shock. Mathematics is geometry. Numbers are lengths and areas and volumes. But that means there are numbers that are not rational.

So how do we define these numbers? This is a difficult question. We could define them to be the solutions of equations like $latex d^2 = r$, where $latex r$ is a rational number, but it this clearly doesn't cover all possible lengths. We could define them to be the solutions of general polynomial equations (like $latex 5x^3 + 3x^2 -18x + 7 = 0$), but it's very hard to see how we'd define operations like addition on them (and it also turns out that numbers like $latex \pi$ wouldn't be included).

The solution isn't obvious. As yet, I'm not sure how to go about introducing it, and it's too late to think very clearly, so you'll have to be patient.

My next post is scheduled for the 25th, and for a Christmas treat I'd like to put these numbers aside and give you one of my favourite proofs. The result is familiar - that there are infinitely many primes - but the proof is not the one you might know.