Key idea of this section
x ∈ ℚ ⟺ its base-b expansion is eventually periodic. For x = a/n in lowest terms, n = 2α·5β·m with gcd(m, 10) = 1: preperiod = max(α, β), period = ordm(10).
Expansions in an arbitrary base
Fix an integer base b ≥ 2. Every real x ∈ [0, 1) has a unique expansion x = ∑k ≥ 1 dk b−k with digits dk ∈ {0, 1, …, b − 1} that does not end in an infinite string of the digit b − 1. It is produced by the greedy rule dk = ⌊b·xk−1⌋, xk = b·xk−1 − dk, starting from x₀ = x. We call the expansion eventually periodic if there are s ≥ 0 and t ≥ 1 with dk+t = dk for all k > s; the least such s is the preperiod and the least such t the period.
Theorem 4.1. A real number x ∈ [0, 1) is rational if and only if its base-b expansion is eventually periodic.
Proof. Suppose x = a/n with 0 ≤ a < n. The greedy algorithm keeps every xk in the set {0, 1/n, …, (n − 1)/n}: indeed xk = rk/n where r₀ = a and rk is the remainder of b·rk−1 on division by n, and dk is the corresponding quotient. This is exactly long division. The sequence (rk) takes at most n values, so ri = rj for some i < j; since rk determines all later remainders and digits, the expansion is periodic from position i + 1 on with period dividing j − i.
Conversely, suppose the digits satisfy dk+t = dk for k > s. Let A be the integer with base-b digits d₁ … ds and B the integer with digits ds+1 … ds+t. Then
x = A/bs + (B/bs+t)·(1 + b−t + b−2t + ⋯) = A/bs + B/(bs (bt − 1)),
which is rational. ∎
Precise period and preperiod
We now determine the period and preperiod exactly. Work in base 10 (the argument is identical for any base, with the prime factors of b replacing 2 and 5).
Lemma 4.2. Let x ∈ (0, 1). Then x has an expansion with preperiod at most s and period dividing t if and only if 10s(10t − 1)·x ∈ ℤ.
Proof. The expansion of x is eventually periodic in the stated sense if and only if 10s+tx and 10s x have the same fractional part, i.e. if and only if 10s+tx − 10s x ∈ ℤ. (For the forward direction, the shift by s + t and by s produce identical digit strings after the point; for the converse, equal fractional parts have identical greedy expansions.) ∎
Theorem 4.3. Let x = a/n with gcd(a, n) = 1, 0 < a < n, and write n = 2α 5β m with gcd(m, 10) = 1. Then the preperiod of x is s₀ = max(α, β). If m = 1 the expansion terminates; if m > 1 the period is t₀ = ordm(10), the multiplicative order of 10 modulo m.
Proof. By the lemma, (s, t) is admissible exactly when n divides 10s(10t − 1)a, and since gcd(a, n) = 1 this means n | 10s(10t − 1). Because 10t − 1 is coprime to 10 and 2α 5β is coprime to m, this divisibility splits into two independent conditions:
2α 5β | 10s ⟺ s ≥ max(α, β), m | 10t − 1 ⟺ ordm(10) | t.
The set of admissible pairs is therefore {s ≥ s₀} × {t : t₀ | t}, which has a componentwise least element (s₀, t₀). When m = 1 every t is admissible, and t = 1 with repeating digit 0 shows that the expansion terminates after s₀ digits. ∎
The same reasoning shows that a reduced fraction a/n has a purely periodic expansion if and only if gcd(n, 10) = 1, and a terminating expansion if and only if n has no prime factors other than 2 and 5.
Consequences
Since ordm(10) divides every exponent e with 10e ≡ 1 (mod m), the period of 1/m divides φ(m) by Euler's theorem, and more sharply it divides the Carmichael exponent λ(m). For a prime p ≠ 2, 5 the period of 1/p divides p − 1, with equality precisely when 10 is a primitive root modulo p. Such primes are called full reptend primes; below 100 they are 7, 17, 19, 23, 29, 47, 59, 61 and 97. Artin's primitive root conjecture (1927) predicts that 10, like any integer other than −1 and the perfect squares, is a primitive root modulo infinitely many primes, with a positive density, approximately 0.3739558 (Artin's constant) for the base 10. Hooley proved this in 1967 assuming the generalised Riemann hypothesis; it remains open unconditionally for every individual base, although Heath-Brown (1986) showed that there are at most two prime bases for which the conjecture fails.
By the Chinese remainder theorem, ordmm′(10) = lcm(ordm(10), ordm′(10)) for coprime m and m′. Thus 1/91 = 1/(7·13) has period lcm(6, 6) = 6, and 1/21 has period lcm(1, 6) = 6. For prime powers, the standard lifting-the-exponent argument shows: if ordp²(10) ≠ ordp(10), then ord_(pk)(10) = pk−1 ordp(10) for all k ≥ 1. For example 1/7 has period 6 and 1/49 has period 42. The exceptional primes, those for which 10p−1 ≡ 1 (mod p²), are the base-10 Wieferich primes; the only ones known are 3, 487 and 56598313. For p = 487 the fractions 1/487 and 1/487² have the same period 486.
Midy's theorem
The expansion 1/7 = 0.(142857) has the curious property 142 + 857 = 999, and 1/13 = 0.(076923) satisfies 076 + 923 = 999.
Theorem 4.4 (Midy, 1836). Let p ≠ 2, 5 be prime and suppose the period of 1/p is even, t = 2k. Split the repeating block into halves A and B of k digits each. Then A + B = 10k − 1.
Proof. Since 102k ≡ 1 and 10k ≢ 1 (mod p), and the only square roots of 1 modulo a prime are ±1, we have 10k ≡ −1 (mod p). Multiplying 1/p = 0.(AB) by 10k shifts the expansion: 10k/p = A + 0.(BA). The fractional part of 10k/p is (p − 1)/p, because 10k ≡ p − 1 (mod p). Hence 0.(AB) + 0.(BA) = 1/p + (p − 1)/p = 1. Reading both purely periodic expansions as fractions with denominator 102k − 1,
(A·10k + B) + (B·10k + A) = 102k − 1, so (A + B)(10k + 1) = (10k − 1)(10k + 1),
and A + B = 10k − 1. ∎
The cyclic number 142857 has a further property: its multiples by 1, …, 6 are its cyclic rotations, because the fractions k/7 for k = 1, …, 6 are the six fractional parts of 10j/7. The same holds for the repeating block of 1/p for every full reptend prime p.
Mirror image in the p-adics
Theorem 4.1 has a twin. In Lesson 12 we shall meet p-adic expansions ∑k ≥ −N dk pk, which are infinite to the left rather than to the right. A p-adic number is rational if and only if its digit sequence is eventually periodic, and the proof is the same long-division argument read backwards.
Exercise
- (a)Find the period of 1/41 and write out its repeating block.
- (b)Find the preperiod and period of 1/84 and verify by computing the expansion.
Show solution
Answers: (a) 10⁵ − 1 = 99999 = 41·2439 so ord41(10) divides 5, and it is not 1 because 10 ≢ 1 (mod 41); hence the period is 5 and 1/41 = 0.(02439). (b) 84 = 2²·21 with α = 2, β = 0, m = 21, so the preperiod is 2 and the period is ord21(10) = lcm(ord3(10), ord7(10)) = lcm(1, 6) = 6. Indeed 1/84 = 0.01(190476).