Rational Numbers in Qn

Objective

A rational number is a quotient of two integers. For our purposes, we will restrict ourselves to positive integers and rational numbers in the interval (0, 1).

For any positive integer n, our goal is to obtain a list of all the unique rational numbers h/k in the interval (0,1) where h < kn. We call the set of such rational numbers Qn. We also want to know the number of elements in Qn, denoted |Qn|.

E.g. if n = 5, there are 9 qualifying rational numbers, namely 1/2, 1/3, 1/4, 1/5, 2/3, 2/5, 3/4, 3/5, and 4/5. There are a maximum of C(n,2) pairs of such integers. When n = 5, C(5,2) = 10, but 2/4 is a duplicate entry since ½ is already on the list.

As you can see, the number of such rational numbers is related to the number of pairs of coprime integers, namely

Qn = {h/k : 0 < h < kn and gcd(h, k) = 1}

In fact, if you don’t take the order of the two numbers into account, the number of such rational numbers is one less than the number of coprimes since 1 is coprime with itself but 1/1 is not in the interval (0,1).

Worksheet Functions

Real Statistics Functions: The Real Statistics Resource Pack provides the following worksheet functions.

FRACS(n): returns an array with three columns. Column 1 contains the values in Qn in decimal form, and the other two columns contain the corresponding h and k values for an h/k in Qn

NFRAC(n) = the number of unique elements in Qn

Example 1: What are the elements in Q7?

Using the formula =FRACS(7), we obtain the output shown in A2:C18 of Figure 1.

List of Q7 elements

Figure 1 – Q7

We see that the first element in Figure 1 is 1/7 = .142857.

We also see that |Q7| = 17. You can get the same result using the formula =NFRAC(7).

Note that there are C(7,2) = 21 distinct pairs of integers between 1 and 7, and so there are a maximum of 21 elements in Q7. The four fractions 2/4, 2/6, 4/6, and 3/6 are already in the list of elements in Q7, namely as 1/2, 1/3, 2/3, and 1/2, bringing the total down to 21-4 = 17 elements.

Size of Qn for large n

Define

A_n

Clearly

Size of Qn

As we observed in Property 2 of Coprime Numbers

P(An) for large n

where

P(An)

Thus, for large n we expect that

Size of An

This means that

Size of Qn

For example, when n = 1000

Q1000

The actual number is 304,191.

Fraction of h/k in Qn

The fraction of pairs of integers h < k <= n for which h/k is in Qn is

Fraction of pairs in Qn

As n → ∞, this has the same limit as An/n2, namely 6/πper Property 2 of Coprime Numbers.

Examples Workbook

Click here to download the Excel workbook with the examples described on this webpage.

References

Stack Exchange (2022) Probability that two random numbers are coprime is 6/π2
https://math.stackexchange.com/questions/64498/probability-that-two-random-numbers-are-coprime-is-frac6-pi2

Wikipedia (2023) Basel problem
https://en.wikipedia.org/wiki/Basel_problem

Lei, J., Kadane, J. B. (2019) On the probability that two random integers are coprime
https://arxiv.org/abs/1806.00053

Leave a Comment