The irrationality of rational numbers
Rational numbers are not as rational as we think, and here I talk about a few things that show how.

Either mathematics is too big for the human mind or the human mind is more than a machine.

I have been planning to write on this topic for a while now, ever since I read Tao's Analysis I. Everyone creates a mental model of what the numbers are based on their education, and so did I based on the basic school maths I had studied so far. This book challenged that model, and I found so many holes in my logic that I had to completely uppend that model and replace it with a new one. And though the full book is great, I want to list out a few things here that were essential in breaking my mental model for my own future reference and for anyone else who might find it useful. I have also added some things that weren't there in Tao's book, but I found from other great references (like this channel by Amitesh). Also, while I was still planning this write up, Chalk Talk on YouTube posted this great video that sums up almost all the logical holes I found in my previous mental model.

1   Warm up: Natural numbers are not dense

Natural numbers are one of the very first number system that any human is exposed to, and a property of the Natural numbers will help contextualize how the same property is different in the Rational numbers. It is known that natural numbers are not dense.

Definition (Dense sets). We need three things to make this definition. We need (1) a set \(X\) with (2) a distance function \(d\), and (3) a set \(S\subset X\). Then, \(S\) is dense in \(X\) if, for any number \(\epsilon>0\) and any \(x\in X\), there is some \(s\in S\) such that \(d(x, s) < \epsilon\).

Now, when we say that the natural numbers are not dense, then our set \(X\) is the set of real numbers, and the set \(S\) is the set of naturals, and the distance function \(d(x,y)=\lvert x-y\rvert\). One way to see it is that there is no natural number between \(1\) and \(2\).

2   The Rational numbers are dense

After studying the naturals and the integers, the next number system a young student learns about is the rational numbers which allows division. And this division operator bestows the wonderful property of the rational numbers being dense. We don't even need to think about the real numbers if we want to see (intuitionally at least) that the rational numbers are dense. Just observe that there is always a rational number between any two rational numbers. The proof of this statement is very simple, just find the rational number halfway between the two. If \(a\) and \(b\) are two rational numbers with \(a<b\), then \(c=\frac{a+b}{2}\) is between \(a\) and \(b\), that is \(a<c<b\). This is easily seen by computing \(c-a\) and \(b-c\) which are both \(\frac{b-a}{2}>0\).

The above proof doesn't consider the reals, however in fact, the rationals \(\mathbb{Q}\) are dense in the reals \(\mathbb{R}\), and this is because the reals are the closure of the rationals. I will not dwell too much on the meaning of closure. What is really interesting is that any real number can be approximated with a rational number with arbitrary accuracy. A way to see this is to realise that since the rationals are dense, there is at least one rational number (in fact there are infinitely many) in any given interval in the real number line. This is because you can increase the denominator (along with appropriate adjustments to the numerator) to get inside the interval (a proof of this fact can be seen in this video). Thus, we can approximate any real number, rational, or irrational, with a rational number with aribtrary accuracy by choosing a rational number inside the interval \((x-\epsilon,x+\epsilon)\) where \(x\) is the number we are approximating and \(\epsilon\) is used to decide the accuracy.

3   How many rational numbers are there?

You'd think that since there's a rational number near every real number, the count of the Rational numbers and the count of the Real numbers should be the same. Further, you'd think that the count of the Rational numbers is definitely larger than the count of the Natural numbers since \(\mathbb{N}\) is not dense and very far from many real numbers. That is a reasonable guess. However that is completely wrong.

Definition (Countable set). An infinite set \(X\) is said to be countable if there exists an invertible function \(f:X\to\mathbb{N}\), that is, we can assign a natural number to every element \(x\) of \(X\) and thus count \(X\).

Corollary. An infinite set \(X\) is said to be uncountable if no such bijection exists.

Now, here is the superstar statement of this section: The Rational numbers are countable, and the Real numbers are uncountable.

I will prove the first one by constructing the bijection \(f:\mathbb{Q}\to\mathbb{N}\). The construction is more like defining the function in programming, as a list of steps, rather than as a usual function in math. To construct the function, we have to first create a grid of rational numbers. The grid will be like the ones we see in excel, with a starting row and column, and then extend to infinity towards the right, and towards the bottom. The column and rows will be named by the natural numbers \({1,2,\dotsc}\) and the entries of the cell will be the rational number \(\text{row}/\text{column}\).

And, now, they can be counted diagonally. So that the first rational number is \(1/1\), the next two are \(1/2\) and \(2/1\), the next three are from the next diagonal \(1/3,2/2,3/1\), and so on. But, this is not a bijection yet, we must skip the duplicates to make the function invertible. And thus we have constructed the function \(f\) as \(f(1)=1,\) \(f(1/2)=2,\) \(f(2/1)=3,\) \(f(3/1)=4,\) \(f(1/3)=5,\dotsc\)

This function is still not complete, because we are missing \(0\), and the negative rationals. But that is remedied easily by assigning \(g(0)=1\), and \(g(x)=f(x)+1\) to first include \(0\). And then creating another grid with negative numbers as the row titles, and the usual naturals as column titles. This creates another function \(h\). And we can finally construct the full function we need by combining \(h\) and \(g\) to create \(f^{*}\). For example, $$f^{*}(x)=\begin{cases}2g(x),&x\ge 0\\ 2h(x)-1,&x\lt 0\end{cases}$$

The fact that the Real numbers are uncountable can be proved using Cantor's diagonalization argument. And in fact we don't even need to show that there isn't a bijection between all of \(\mathbb{R}\) and \(\mathbb{N}\). We can just show that we can not count all the numbers between \(0\) and \(1\) that only consist of \(0\)'s and \(1\)'s in their decimal expansion (see this video by Amitesh).

Remark. We now know that the count of rationals is not larger than the count of naturals. And it is not the same as the count of reals. But, I never mentioned the true statement that the count of reals is larger than the count of rationals (and therefore the count of naturals).

4   Some exotic functions

There are a couple of very exotic functions that showcase the weirdness of our number systems. The first of which is the simple looking function \(f_1:\mathbb{R}\to\mathbb{R}\) defined below. $$f_1(x)=\begin{cases}1,&x\in\mathbb{Q}\\0,&x\notin\mathbb{Q}\end{cases}$$ The interesting thing about this function is that it is discontinuous everywhere in its domain.

Definition (Continuity). A function \(f:X\to\mathbb{R}\) with \(X\subseteq\mathbb{R}\) is called continuous at a point \(x_0\) in its domain if for every number \(\epsilon>0\), there exists a number \(\delta>0\), such that \(|f(x)-f(x_0)|\lt\epsilon\) whenever \(|x-x_0|\lt\delta\).

Remark. To be more precise, we need the last condition to be \(x\in(x_0-\delta,x_0+\delta)\cap X\) since \(x\) should be in the domain.

Corollary 1. A function is said to be discontinuous at a point \(x_0\) if it is not continuous at that point.

Corollary 2. An alternate definition of continuity is that a function \(f:X\to\mathbb{R}\) is continuous at \(x_0\) if $$\lim_{x\to x_0;x\in X}f(x)=f(x_0).$$

This can be seen very easily from the definition of continuity and the definition of limits. The definition of continuity from Corollary 2 is what will be more useful for us to prove our statement about the exotic function \(f_1\).

Proof (part 1). Let \(x_0\in\mathbb{Q}\) be a rational number, thus \(f(x_0)=1\). We can find a sequence of irrational numbers that converges to this number. Let this sequence be \((a_0,a_1,a_2,\dotsc)\), then this sequence can be defined as $$a_n=x_0+\frac{\pi}{10^n}.$$ This sequence is just \(x_0+\pi, x_0+\frac{\pi}{10}, x_0+\frac{\pi}{100},\dotsc\), or in other words, we add the digits of \(\pi\) shifted right by \(n\) places to get \(a_n\). All the numbers in this sequence are irrational numbers, therefore the sequence \((f_1(a_0),f_1(a_1),f_1(a_2),\dotsc)\) is \((0,0,0,\dotsc)\) which clearly converges to \(0\neq f_1(x_0)\). Thus, we have shown that \(\lim_{a_n\to x_0}f_1(a_n)\neq f_1(x_0)\), and thus the function \(f_1\) is discontinuous at every rational number.

\(\square\)

For \(x_0\notin\mathbb{Q}\), we will need the following lemma.

Lemma. Given any interval \((a,b), a\lt b\), there exists a rational number inside it. That is there exists an \(x\in\mathbb{Q}\) such that \(a\lt x\lt b\).

Proof of lemma. Let's look at rational numbers \(q\) of the form \(\frac{1}{10^n}\) for \(n\ge 1\). The Archimedean property states that there exists an integer \(N\) such that \(Nq>a\). Now, \(Nq\) is a rational number, and it is greater than \(a\). Therefore it is a great candidate for the number \(x\) we are looking for. But we need to ensure that \(Nq\lt b\). More precisely, we want \(Nq\gt a\) or \(N\gt 10^n a\); and \(Nq\lt b\) or in other words \(N\lt 10^nb\). Combined together, this looks like \(10^na\lt N\lt 10^nb\). We just need \(n\) to be sufficiently large so that there is at least one integer between \(10^na\) and \(10^nb\). This is the same as saying \(10^nb-10^na>1\) (why?). Or, \(10^n>\frac{1}{b-a}\). Which means we can choose \(n>-\log_{10}(b-a)\).

\(\square\)

Remark. Notice that the above also gives the following bound \(b-a>\frac{1}{10^n}=q\). So, just choose \(q\) to be the decimal number with some zeros followed by one such that \(q\) is less than difference (you do this by adding more zeros between the decimal and the \(1\)). For example, if \(a=2.5\) and \(b=2.6\), then just choose \(q=0.01\) since \(0.01 \lt 0.1 = b-a\).

Remark. The proof has a few holes. It only works when both \(a\) and \(b\) are positive. But it can be easily adapted for other cases. For example if \(a\) is negative, and \(b\) is positive, then \(0\) is such a rational number. If both \(a\) and \(b\) are negative, then find the positive rational \(x\) that lies in \((-b,-a)\), and negate that to get \(a\lt -x\lt b\).

Proof (part 2). Now, we can prove that \(f_1\) is discontinuous at every irrational point too. Fix \(x_0\notin \mathbb{Q}\) as our irrational of interest. Then, we can construct a sequence of intervals enclosing \(x_0\) as \((I_0, I_1, I_2, \dotsc)\) defined by \(I_n=(x_0-\delta_n, x_0+\delta_n)\) where \(\delta_n=\frac{1}{10^n}\). Let \(a_0\) be a rational number in \(I_0\), let \(a_1\) be a rational number in \(I_1\), and so on. Then, we see that the sequence \((a_0, a_1, a_2, \dotsc)\) converges to \(x_0\) (why?). But, we know that the sequence \((f_1(a_0), f_1(a_1), f_1(a_2),\dotsc)\) is \((1, 1, 1, \dotsc)\) which converges to \(1\neq f_1(x_0)\). Thus, we have shown that \(\lim_{a_n\to x_0}f_1(a_n)\neq f_1(x_0)\), and thus the function \(f_1\) is discontinuous at every irrational number.

\(\square\)

Now, this is how the above fact challenged my mental model of how the numbers are placed and how continuity in functions behave. At a younger age, we learned about all kinds of discontinuities a function might have. One of those that really stuck with me because it came with an easy to visualize picture was removable discontinuity. The standard picture of this discontinuity is a simple graph of a polynomial like function, that has a hole at one point, denoted as an empty circle. At this point the function takes some other value that is disconnected from the rest of the graph. The function might look like \(f(x)=x^2\) for \(x\neq 3\) and \(f(3)=12\).

The point of discontinuity arises because the value of the function at the point of discontinuity is different from the value of the function at the points immediately to the left and right of the point of discontinuity. The problem arises when I assume all discontinuities can be visualized, and visualized exactly like this.

Wrong argument. Consider a single point \(x_0\in\mathbb{Q}\). The function \(f_1\) at this point would be continuous if the points immediately to the left of \(x_0\) and immediately to the right of \(x_0\) were rationals, because then the function values will all be coherent in some sense; they will all be \(1\)s for a continuous stretch of three numbers. But the function is discontinuous at this point. Therefore, they have to be irrational! A rational number is saddled by irrationals on both sides! Likewise, I can argue that an irrational number is saddled on both sides by rationals. Therefore, the real numbers have been formed by interleaving the rationals and irrationals. Thus, I can count irrationals, by counting the rationals next to it and assigning the count of the rational to its left to the irrational. Since the reals are made up of rationals and irrationals, I can argue that the real numbers are countable.

Where did I go wrong? The picture is not worth a thousand words here, it is just a convenient representation of a (representable) bit of math. There are aspects of math that cannot be represented as such, and can only be accessed by following the rules of inference. There is no real number (rational or irrational) to the immediate left or immediate right of any real number (unless you subscribe to the hyperreal numbers).


There is yet another very interesting and exotic function that I want to briefly talk about. It is Thomae's function, or the popcorn function. It is the function \(f_2:\mathbb{R}\to\mathbb{R}\), defined as follows. $$f_2(x)=\begin{cases} \frac{1}{q},&\text{if }x=\frac{p}{q},p\in\mathbb{Z},q\in\mathbb{N},\text{gcd}(p,q)=1\\ 0,&x\notin\mathbb{Q} \end{cases}$$

This function looks very much like the previous function \(f_1\). However, this function breaks the symmetry between the rational numbers and the irrational numbers displayed by \(f_1.\) This is because \(f_2\) is discontinuous at every rational number, but continuous at every irrational number. Amitesh did a great proof of this fact here in this video. Very briefly, the proof of discontinuity at every rational is the same as that for \(f_1\). We construct a sequence of irrationals that converge to the rational number and show that when the function is applied to the points of that sequence, it generates a sequence that doesn't converge to the function value at the rational.

It is the proof of continuity at irrationals which is much more interesting. It boils down to proving a simple lemma that states that if a sequence of rational numbers converges to an irrational number, then the denominator of the rational numbers has to grow without bounds. We have seen a flavor of it while proving the lemma required to prove the Proof (part 2) above. As rationals get closer to an irrational number, the denominator grows without bounds, the value of \(f_2\) decreases as the denominator grows and gets closer and closer to \(0\), which is the value of \(f_2\) at irrational points.

Remark. This still doesn't violate the wrong argument I provided earlier. It still seems like we have carefully crafted this function so that the value of the function at the rationals right next to any irrational is very close to the value of the function at the rational (=\(0\)). And this was required because the rationals saddle the irrationals. However, the argument is still wrong. I haven't found a convincing refutation of it yet, but I'm sure one day I will.

5   The length of numbers

This will be a small section. What I want to talk about here is the concept of computing lengths of sets and intervals of real numbers. This length is formally called the Lebesgue measure. I will just state a list of counter-intuitive facts without proof. Also, I will use the term measure to mean the Lebesgue measure or the length.

So, the rational numbers are everywhere (dense), they are countable (just as many as the set of Natural numbers that aren't everywhere), and take up \(0\) space as compared to the Real numbers. They are very tiny, and yet that are all we deal with in our day to day lives. Sure there are some imaginary units, and \(\pi\)'s, and Euler numbers, and logarithms, and square roots; but that's it. Even with these irrational numbers, we mostly deal with their rational approximations. In fact, we cannot even measure irrational numbers, for example, once we construct a very large right triangle with two sides of length equal to unity and the hypotenuse of length \(\sqrt{2}\), we can only measure \(\sqrt{2}\) upto a certain level of accuracy. We are limited by the Planck length. The idealisations of these exotic numbers do not exist in the real world. And yet, if you throw a dart on the real number line, the probability of hitting a rational number is zero.

6   Some interesting statements without proof
Conclusion

Over the past few months, I had collected a bunch of weird math facts that challenge the model of math that most people build after high school education. I have tried to faithfully replicate a few of them. The key takeaway, I think, is that simple visualizations are powerful, but they shouldn't be taken too far when it comes to math. You should always be skeptical of what you think you know for sure, and always be on the quest of finding more. Our knowledge is countable, while what we know is uncountable.