How often do coprime numbers appear?
Coprime numbers, also known as relatively prime numbers, are integers that do not share any prime factors, or equivalently having a greatest common divisor (GCD) of 1. Although the definition of coprime integers are originally for a pair of integers, it can be extended to any number of integers due to its associativity.
When I first learnt about coprime integers in a number theory course, there was a question that was not covered during the course, nor did it occur to me until recently: what is the probability of choosing a pair of coprime integers at random1?
Hi Again, Pi
There turns out to be a definitive answer to this question with several well-established proofs, and it is quite an elegant one:
Surprisingly, seems to appear out of nowhere in the answer, which makes this a topic that could make into 3Blue1Brown's "Why pi?" video series. However, this should look familiar to those who are familiar with the Basel problem, or the sum of reciprocals of perfect squares. In fact, they are very closely related.
A Straightforward Proof
There are several proofs of this result, including one by Dirichlet that has existed since all the way back to 1849, and one that involves a more advanced concept called lattice points (see Apostol's Introduction to Analytic Number Theory, Theorem 3.9), but there is actually a simpler, yet more insightful argument, presented by Simon Tiger, a budding prodigy mathematician.
He does not go for the usual brute-force, 'bottom-up' method of running through massive numbers of integer pair samples while checking for the coprimality of each pair and keeping track of the odds in order to see if the probability converges to a certain constant. Instead, he takes a 'top-down' approach by looking at the probability of a pair of integers having a greatest common divisor (GCD) of or above.
What does this mean? Suppose that we call the first number and the second number . Let's start with as the target factor. For and to have an GCD of , they must at least both be divisible by . Since modular arithmetic tells us that we can group integers evenly based on their respective remainders after being divided by a certain factor, the probability of (resp. ) being divisible by (i.e. having remainder zero) is .
Note that must be the highest common factor of and , so if we divide both of them by , they cannot share any other factor (except for of course). Note that this is exactly the definition of coprimality! In other words, we have obtained a pair of coprime integers (namely and ) through this procedure. What is the probability of finding such a pair? That's exactly what we're looking for; let's call that value .
The key of the procedure just now is that it gives us an important characterisation of a pair of integers having a certain number as their GCD: they must both be divisible by said number, and after dividing them by that number, the new resulting pair must be coprime.
Why?
If and had other common factors greater than (say, ) after being divided by their GCD (denoted here as ), then , which is greater than , should have been the GCD instead, leading to a contradiction.
What is the probability of finding an integer pair like this? The argument above tells us that it is the product of the probabilities, which represent the criteria that must be fulfilled simultaneously, that we obtained through the procedure, i.e. .
At this stage, you may have figured out that this procedure can be repeated for every other integer factors. For , we obtain ; for , we obtain , and so on. We can even deduce the general pattern: for a factor , the probability of an integer pair having as their GCD is . This general pattern even works for the case when , because an integer pair having as their GCD essentially means that they are coprime, so the corresponding probability is indeed .
Now, we see how everything comes together which helps us to obtain the value of that we want. Note that any integer pair has the GCD of any number. This means that the probability of obtaining any integer pair among the sea of all integer pairs, which is clearly , is equal to the sum of all probabilities of an integer pair having the GCD of any number, ranged over all integers! Rewriting this description into an algebraic equation, we obtain
Rearranging the variables a bit yields
In other words, the probability of a randomly chosen integer pair being coprime is the reciprocal of the sum of reciprocal of squares! That's where the Basel problem, i.e. the reason why shows up in the solution, plays a role!
Extension to integers
Another cool part of this argument is that it can be easily extended to an arbitrary number of randomly chosen integers, say, of them.
By investigating possible integers, say, instead of just two like before, calculating the probability of these integers having a certain number as their GCD now involves multiplying for times in total, followed by multiplying at the end as before.
In a similar vein, we then obtain that
Does the denominator ring a bell? It is in fact the definition of the Riemann zeta function!
Rather, for the special case of positive integers, it is more commonly known as the -series.
It may be tempting to ask what the probability will become as the number of integers chosen 'tends to infinity'. It may even be more tempting to deduce from the general formula we just obtained to conclude that the answer should be . However, this question is meaningless because there can be contradicting outcomes depending on what kind of infinite collections of integers we are considering. For instance, the probability is for all even numbers, but is for all positive integers; notice that both cases involve an infinite number of integers.
What if we consider a finite range of numbers and a finite number of choices instead? According to this paper, this probability seems to decrease as the number of choices increases, which is frankly an interesting result.
Other sources, further reading
- Zeta functions, statistical mechanics and Haar measure, by Qiaochu Yuan
- On the Probability That Two Random Integers Are Coprime, by Jing Lei and Joseph B. Kadane
- The Probability that Two Random Integers are Coprime, by Julien Bureaux and Nathanael Enriquez
- Probability of Coprimality section in the Wikipedia article on coprime integers
- What is the probability that integers chosen at random are coprime? on Mathematics StackExchange
- Probability that two random numbers are coprime is on Mathematics StackExchange
- The Probability that Positive Integers are Pairwise Relatively Prime, by László Tóth