# A Rational Number With a Finite Number of Digits

A rational number, by its definition, is a ratio of two integers. Yet, some of them are not expressible using a finite number of digits in decimals, or more formally known as base-ten positional notation. For example, the number one third can be written exactly as $$\frac{1}{3}$$ as a fraction, yet we cannot express the same number using a finite number of digits in base 10. The best we can do is to imply the indefinite repeating of the digit 3 using elipsis as in: $$\mathrm{0.33...}$$ or more formally with a vinculum such as an overline to indicate the sequence of digits to repeat as in: $$0.\overline{3}$$. In the case of one seventh, a sequence of digits $$142857$$ gets repeated as in $$\mathrm{0.142857142857...}$$ or $$0.\overline{142857}$$. When I was a kid and first learned of division, I was very fascinated by this phenomnea. Today, I present an answer to one of the questions I once had as a kid: when can a rational number be expressed using a finite number of digits?

## Theorem

*A rational number $$r$$ can be represented in the positional notation of an integral base $$b\ge 2$$
using a finite number of digits if and only if every factor of the denominator of $$r$$
in its irreducible fraction is also a factor of $$b$$*.

### Understanding the theorem

Let’s break down this statement. If $$r$$ is a rational number, it is a ratio of two integers by the definition. Thus, there exist two integers $$n\in \mathbb{Z}$$ and $$d\in \mathbb{Z}$$ such that $$r=\frac{n}{d}$$. Furthermore, without loss of generality, we can assume $$\frac{n}{d}$$ to be the irreducible fraction (also known as the lowest form) of $$r$$ meaning that $$n$$ and $$d$$ do not share a common factor. (If $$r$$ and $$d$$ did share common factors, we can keep dividing them by the common factors to arrive at the irreducible fraction.)

Now let $$b=\prod _{i=1}^{k}{p}_{bi}^{{q}_{bi}}={p}_{b1}^{{q}_{b1}}{p}_{b2}^{{q}_{b2}}...{p}_{bk}^{{q}_{bk}}$$ where $${p}_{bi}\in \mathbb{Z}$$ is a prime number and $${q}_{bi}\in \mathbb{Z}$$ for every $$i$$ be the prime factorization of $$b$$, and $$d=\prod _{j=1}^{l}{p}_{dj}^{{q}_{dj}}={p}_{d1}^{{q}_{d1}}{p}_{d2}^{{q}_{d2}}...{p}_{dl}^{{q}_{dl}}$$ where $${p}_{dj}\in \mathbb{Z}$$ is a prime number and $${q}_{dj}\in \mathbb{Z}$$ for every $$j$$ be the prime factorization of $$d$$. Then the theorem says that $$r$$ is expressible using a finite number of digits in the positional notation of base $$b$$ if and only if every prime number $${p}_{d1},{p}_{d2},...,{p}_{dl}$$ in the prime factorization of $$d$$ also appears in the prime factorization of $$b$$ (i.e. if $$t={p}_{di}$$ for some $$i$$, then $$t={p}_{bj}$$ for some $$j$$).

For example, one nineth is not expressible using a finite number of digits in base 10 because its irreducible fraction $$\frac{1}{9}$$ contains 3 (since $$9={3}^{2}$$) as a prime factor in its denominator, which is not a factor of $$10=2\cdot 5$$. However, $$\frac{1}{9}$$ is expressible using a finite number of digits in base 3 notation since the denominator only contains the prime factor of 3, which is also a factor of the base. Namely, $$\frac{1}{9}$$ is 0.01 in base 3. Similarly, $$\frac{1}{20}$$ is expressible using a finite number of digits in base 10 because its irreducible fraction $$\frac{1}{20}$$ only contains prime numbers which are also factors of 10 in its denominator: $$20={2}^{2}\cdot 5$$ Note that reducing the fraction to its irreducible form is important. As an example, $$\frac{3}{15}$$ is expressible using a finite number of digits in base 10 even though its denominator contains a prime factor of 3, which is not a factor of 10 since its irreducible form $$\frac{1}{5}$$ only contains the prime factor of 5, which is a factor of 10.

## Proof

### If a rational number can be represented using a finite number of digits in a base, then a prime factor of the denominator of its irreducible fraction is a factor of the base

Let $$r$$ be a rational number which can be expressed using a finite number of digits in the positional notation of an integral base $$b\ge 2$$. Then let $${d}_{k}...{d}_{2}{d}_{1}{d}_{0}.{d}_{-1}{d}_{-2}...{d}_{-l}$$ be such a sequence of digits presenting $$r$$ in base $$b$$ where $$k\in \mathbb{N}$$ is the place of the highest digit and $$l\in \mathbb{N}$$ is the place of the lowest digit after the radix point, and $${d}_{i}\in \{{d}_{i}\in \mathbb{Z}|0\le {d}_{i}<b\}$$ for all $$i$$ between $$-l$$ and $$k$$. Namely, $$r=\sum _{i=-l}^{k}{d}_{i}{b}^{i}={d}_{k}{b}^{k}+...+{d}_{1}{b}^{1}+{d}_{0}{b}^{0}+{d}_{-1}{b}^{-1}+...+{d}_{-l}{b}^{-l}$$ Let $$n=r\cdot {b}^{l}$$. Using the definition of $$r$$, $$n=r\cdot {b}^{l}=\left(\sum _{i=-l}^{k}{d}_{i}{b}^{i}\right)\cdot {b}^{l}=\sum _{i=-l}^{k}{d}_{i}{b}^{i+l}$$ Substituting $$i$$ with $$j=i+l$$ yields: $$n=\sum _{j=0}^{k+l}{d}_{j-l}{b}^{j}$$ Because $${d}_{j-l}$$ and $${b}^{j}$$ are both integers, $$n$$ is also an integer since the sum of products of integers is also an integer. Now consider the fraction $$\frac{n}{{b}^{l}}=\frac{r\cdot {b}^{l}}{{b}^{l}}=r$$. The denominator only contains the prime factors of b since it’s a power of b. Because reducing this fraction by canceling common factors in the numerator and the denominator does not introduce a new prime factor in the denominator, the irreducible fraction of $$r$$ must also not have a prime factor which is not a factor of b in its denominator. That is, every prime factor of the denominator of the irreducible fraction of $$r$$ is also a factor of b as desired.

### If every prime factor of the denominator of a rational number in its irreducible fraction is also a factor of a base, then the number can be represented using a finite number of digits in the base.

Let $$r$$ be a rational number and $$r=\frac{n}{d}$$ with $$n,d\in \mathbb{Z}$$ be its irreducible fraction such that every factor of $$d$$ is a factor of a base $$b\ge 2$$. Without loss of generality, assume $$d$$ is non-negative (since the negative sign can always be moved from the denominator of a fraction to its numerator).

**Case 1**: If $$n$$ is 0 or $$d$$ is 1, $$r$$ is an integer, and there is a representation of $$r$$ using a finite number of digit in base $$b$$.

**Case 2**: If $$n$$ is not 0 and $$d>1$$, let $$d=\prod _{i=1}^{k}{p}_{i}^{{q}_{i}}$$ where $$k\in \mathbb{N}$$,
$${p}_{i}\in \mathbb{N}$$ is a prime number and $${q}_{i}\in \mathbb{N}$$ for every $$i$$
be the prime factorization of $$d$$
using the fundamental theorem of arithmetic.
From the supposition, every prime factor ($${p}_{i}$$ for every $$i=\mathrm{1...}k$$) of $$d$$ is also a factor of the base $$b$$.
Let $${p}_{k+1},...{p}_{l}$$ be prime factors of b which is not a factor of $$d$$ if there are any,
and $$b=\prod _{j=1}^{l}{p}_{j}^{{r}_{j}}$$ where $$l\in \mathbb{N}$$ such that $$k\le l$$ and $${r}_{i}\in \mathbb{N}$$
be the prime factorization of $$b$$.

Now let $$m$$ be the maximum number amongst $${q}_{i}$$, and consider the quantity $$w=\frac{{b}^{m}}{d}$$. $$w=\frac{{b}^{m}}{d}=\frac{{\left(\prod _{j=1}^{l}{p}_{j}^{{r}_{j}}\right)}^{m}}{\prod _{i=1}^{k}{p}_{i}^{{q}_{i}}}=\frac{\prod _{j=1}^{l}{p}_{j}^{{r}_{j}m}}{\prod _{i=1}^{k}{p}_{i}^{{q}_{i}}}=\prod _{j=1}^{l}{p}_{j}^{{r}_{j}m}\prod _{i=1}^{k}{p}_{i}^{-{q}_{i}}$$ $$=\left\{\prod _{i=1}^{k}{p}_{i}^{{r}_{i}m}\prod _{j=k+1}^{l}{p}_{j}^{{r}_{j}m}\right\}\prod _{i=1}^{k}{p}_{i}^{-{q}_{i}}=\prod _{i=1}^{k}{p}_{i}^{{r}_{i}m-{q}_{i}}\prod _{j=k+1}^{l}{p}_{j}^{{r}_{j}m}$$ Because $$m\ge {q}_{i}$$ and $${r}_{i}\ge 1$$ by the definitions of $$m$$ and $${r}_{i}$$, $${r}_{i}m\ge {q}_{i}$$ and $${r}_{i}m-{q}_{i}\ge 0$$. Thus, $${p}_{i}^{{r}_{i}m-{q}_{i}}$$ is a non-negative integer for every $$i=1,...,k$$ since it’s a power of a prime number to a non-negative integer. Since $${p}_{j}^{{r}_{j}}$$ is also a non-negative integer for all $$j=k+1,...,l$$ and $$m$$ is a positive integer by their definitions, the whole product $$w$$ is also a non-negative integer. Then the quantity $$nw$$ is also an integer since the product of two integers is also an integer.

Let $${n}_{s}{n}_{s-1}...{n}_{0}$$ be the representation of $$nw$$ in the base $$b$$. Then consider the representation of $$\frac{nw}{{b}^{m}}=\frac{n{b}^{m}}{d{b}^{m}}=\frac{n}{d}$$ in base $$b$$: $${n}_{s}{n}_{s-1}...{n}_{m+1}.{n}_{m}...{n}_{0}$$ with the radix point between $${n}_{m}$$ and $${n}_{m+1}$$. This is the representation of $$\frac{n}{d}$$ in base $$b$$ using a finite number of digits as desired.

Q.E.D.

## Intuitive Reasoning

The second half of the proof gives us an intuition as to why this theorem holds.
The question of whether we can write down $$\frac{n}{d}$$ using a finite number of digits in base $$b$$
really comes down to whether we can write down $$\frac{1}{d}$$ using a finite number of digits in base $$b$$
because $$\frac{n}{d}$$ is just $$\frac{1}{d}$$ repeated $$n$$ times.
If $$\frac{1}{d}$$ is expressible using a finite number of digits in base $$b$$,
there ought to be some natural (positive) number $$c$$ such that c-th digit after the radix point is the last digit.
That is, since it’s finite, there must be *the last* digit.
The quantity $$\frac{1}{{b}^{c}}$$ represents 0 followed by $$c$$ 0s and then 1. (e.g. if $$c=3$$ then $$0.001$$.)
The question boils down to whether there is such a $$c$$.

Suppose there was such a $$c\in \mathbb{N}$$. Then $$\frac{1}{d}$$ ought to be some multiple of $$\frac{1}{{b}^{c}}$$. To give an example, consider a number $$0.345$$ with $$c=3$$ in base 10. We can think of this number as $$0.001$$ added $$345$$ times or simply $$0.001\cdot 345$$. Let $$t\in \mathbb{Z}$$ be such an integer multiple: $$\frac{1}{d}=t\cdot \frac{1}{{b}^{c}}$$. e.g. $$t=345$$ with $$\frac{1}{{b}^{c}}=\frac{1}{{10}^{3}}=\frac{1}{1000}$$ for expressing $$0.345$$ in base 10. Multiplying both sides of this equation by $$d\cdot {b}^{c}$$ yields: $${b}^{c}=dt$$.

This is a crucial equation. Intuitively, this equation says that $${b}^{c}$$ must be some integral multiple of the denominator $$d$$. e.g. in the case of $$0.345$$ in base 10, $${b}^{c}={10}^{3}=1000$$ must be some integral multiple of the denominator of its irreducible fraction. To see why, let’s turn $$0.345$$ into a proper fraction with integral numerators and denominators by multiplying the base number 10: $$0.345=\frac{3.45}{10}=\frac{34.5}{100}=\frac{345}{1000}$$ Now apply the prime factorization and cancel common factors to get the irreducible fraction: $$0.345=\frac{345}{1000}=\frac{3\cdot 5\cdot 23}{{2}^{3}\cdot {5}^{3}}=\frac{3\cdot 23}{{2}^{3}\cdot {5}^{2}}=\frac{69}{200}$$ Sure enough, $$1000=5\cdot 200$$. Notice that $$t=5$$ in this case is simply a common factor we originally had. In fact, $$t$$ can be thought of as common factors needed in numerators and denominators to make the denominator become a power of 10.

Now, going back to $${b}^{c}=dt$$, we see that $${b}^{c}$$ must have all prime factors of $$d$$ and $$t$$ because $${b}^{c}$$ and $$dt$$ are identical. But this would implies that every prime factor of $$d$$ must be a prime factor of $$b$$ since raising $$b$$ to the power of $$c$$ does not introduce a new prime factor, and multiplying $$d$$ with any integer, in particular by $$t$$, does not eliminate a prime factor in $$d$$.