units-mod-n-coprime-and-totient
A residue has a multiplicative inverse mod exactly when the greatest common divisor (gcd) of and is 1. The invertible residues form a group, the unit group , and it has elements.
Start with n = 6
Which of 1 to 5 have an inverse mod 6? Multiply and look for a 1. Since and , both 1 and 5 are units. The residue 1 is a unit for every and is its own inverse, since . The other three never reach 1: , , . Once a product hits 0 the row of products just cycles.
The rule is not " divides ": 6 does not divide 4, and 4 still fails. The rule is that and share a factor. 4 shares the factor 2 with 6, and a shared factor is enough to kill the inverse.
An inverse is a combination equal to 1
Write out what an inverse means. says for some integer , so
So "does have an inverse" is the same question as "can I build 1 out of and with integer coefficients". Bézout's identity is the name for the fact that the smallest positive number you can build this way is . The two directions below are that identity, proved on the pair we care about.
Shared factor means no inverse
Let and write , . Then every combination is
Every combination is a whole number of copies of . If the combination can never equal 1, so there is no inverse. That is the "only if" direction.
Coprime means an inverse exists: run Euclid backwards
Take and . Divide with remainder, then divide the divisor by the remainder, until the remainder is 0:
The last nonzero remainder is 1, and the goal is to write that 1 as a combination of 12 and 5. The first equation already does this for its own remainder: . The second equation contains that 2, so substitute, and its remainder 1 becomes a combination of 12 and 5 as well:
Reduce mod 12 and the term vanishes: , so 5 is its own inverse mod 12.
The general idea is a chain of substitutions. The first equation holds , and a remainder. The remainder has coefficient 1 in its own equation, so solving for it writes the remainder as a combination of and . Substitute that into the next equation, and its remainder is a combination of and too. Repeat down the chain. The last equation then reads , and for coprime and that is , with the inverse. This is the extended Euclidean algorithm. Tracking and step by step, rather than by substitution, is the follow-up in extended-euclidean-algorithm-study.
Two claims carry this proof and both need checking: each Euclid step keeps the gcd, and the chain stops exactly at the gcd.
Each Euclid step keeps the gcd
One step is with . The claim is .
First half. Let , so and . Picture a strip of length cut into segments of length and a leftover of length . The block tiles the whole strip and tiles each segment, so it must tile the leftover:
So is a common divisor of and , and that is all it is so far. The block is the greatest common divisor of . Nothing above says it is the greatest common divisor of , only that it is a factor of both. Being the gcd of the first pair does not make it the gcd of the second. What this half proves is .
Second half. Take any dividing both and , say and . Then
so divides as well. Every common divisor of is a common divisor of , which gives . The two inequalities together give equality. The trap in the one-sided version is its own note: euclid-step-keeps-gcd.
Why the chain stops at the gcd
The remainders are non-negative and strictly decreasing, since at every step, so the chain reaches 0 after finitely many steps. The last line reads , and , because every integer divides 0. Chain the lemma back up the lines and . The last nonzero remainder is the gcd. When and are coprime that remainder is 1, which is exactly what the back-substitution builds.
The answer to the opening question
For prime the only divisors are 1 and , so every residue from 1 to is coprime to and has an inverse. That is why is a field. For composite , exactly the residues that share a factor with drop out. Mod 6, that is 2, 3 and 4, and the survivors are 1 and 5.
The units form a group
Closure is the claim to check: if and are units, so is . Two different closures are in play, and keeping them apart is the whole proof.
The first is closure of the ring. Both and are elements of , and a ring is closed under multiplication, so the product is guaranteed to exist as an element of . The ring hands over the candidate inverse for free.
The second is closure of the unit group, which is the thing to prove. A unit is an element with some inverse in the ring, so check the candidate:
So has an inverse in the ring, which makes a unit. That is unit-group closure, proved from ring closure plus one computation. Nothing here needed to be a unit itself. Reaching for that fact is the circular step, because it is unit-group closure again.
The identity is 1, inverses exist by the definition of a unit, and associativity is inherited from the ring. So is a group.
How many units: φ(n)
Euler's totient counts the integers in to that are coprime to , so , and for a prime.
Count by removing the failures. Count over 1 to 15 rather than 1 to 14, so that every count is exact and 15 itself lands in the removed pile where it belongs. The multiples of 3 number , the multiples of 5 number , and 15 was removed twice, so add it back once:
The eight units mod 15 are 1, 2, 4, 7, 8, 11, 13, 14. The same count for any two distinct primes gives .
The general formula runs over the distinct primes dividing :
The way to remember it: for each prime there are exactly multiples to throw out. Start from , subtract each , add back each that was subtracted twice, and so on. Multiplying out the product produces exactly those signed terms, one per subset of the primes. Check: . For there is only one prime and nothing to double count, so .
Mantra The inverse question is a gcd question, and the gcd question is Euclid.
Open threads
- , with 27 as the test case: which residues fail, how many, and the closed form.
- The term-by-term match between expanding and inclusion-exclusion for three or more primes. Sketched in the session, not re-derived.
- Tracking the Bézout coefficients step by step instead of by substitution: extended-euclidean-algorithm-study.