The Order of a Unit#
Recall that Zn∗ is the set of units of Zn; the elements a∈Zn with gcd(a,n)=1, i.e. exactly the elements that have a multiplicative inverse. Recall also Euler's Theorem: for any a∈Zn∗,
aϕ(n)=1 in Zn.
So some power of every unit eventually equals 1; it is natural to ask for the first time this happens.
Definition
Given any a∈Zn∗ for n∈Z+, the order of a, written ordn(a), is the smallest positive integer k such that ak=1 in Zn.
Basically, the order of a measures how long the powers a,a2,a3,… take to first return to 1; after that point the powers just repeat the same cycle forever. Other notation for the order of a∈Zn∗ includes ordZn(a), on(a) and ∣a∣.
Note
Be careful: "order" can mean something different depending on context; the order of a finite field F sometimes refers to the number of elements in F.
It is important to note that the order is only defined for units; if gcd(a,n)=1, then no power of a ever reaches 1.
Example. Explain why ord15(6) does not exist.
Notice that gcd(6,15)=3=1, so 6∈/Z15∗. Watching the powers directly,
62=36=2×15+6=6 in Z15,
so every power of 6 collapses back to 6 itself and can never equal 1. More generally, 3∣6k for every k∈Z+, but 3∤(15m+1) for any m; so 6k=1 in Z15 is impossible. Therefore ord15(6) does not exist; always check that a is a unit before talking about its order.
Example. Find the orders of each of the elements in Z7∗.
We previously found the power table for Z7∗:
| k |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
… |
| 1k |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
… |
| 2k |
2 |
4 |
1 |
2 |
4 |
1 |
2 |
… |
| 3k |
3 |
2 |
6 |
4 |
5 |
1 |
3 |
… |
| 4k |
4 |
2 |
1 |
4 |
2 |
1 |
4 |
… |
| 5k |
5 |
4 |
6 |
2 |
3 |
1 |
5 |
… |
| 6k |
6 |
1 |
6 |
1 |
6 |
1 |
6 |
… |
Reading along each row until the first 1 appears,
ord7(1)ord7(2)ord7(3)ord7(4)ord7(5)ord7(6)=1,=3,=6,=3,=6,=2.
Notice how every order that shows up (1,2,3 and 6) is a divisor of 6=ϕ(7); this is not a coincidence, as we are about to see.
Order Divides the Totient#
Before the main theorem, we need a small lemma that describes exactly which powers of a unit equal 1.
Lemma
For any a∈Zn⋆ and k∈N, we have ak=1 in Zn if and only if ordn(a)∣k.
Proof. Let d=ordn(a).
(⇐) Suppose d∣k; then k=dq for some q∈N, so
ak=adq=(ad)q=1q=1 in Zn.
(⇒) Suppose ak=1. By the Division Theorem we can write k=qd+r with 0≤r<d, so
1=ak=(ad)qar=1qar=ar.
But d is the smallest positive exponent giving 1, and r<d; the only way out is r=0. Hence k=qd; that is, d∣k. ■
Basically, the powers of a hit 1 at d,2d,3d,… and nowhere else; the sequence of powers is periodic with period exactly ordn(a). Since a is invertible, ai=aj (for i≥j) is the same as ai−j=1, which gives a fact worth boxing:
ai=aj in Zn⟺i≡j(modordn(a)).
Theorem
For any a∈Zn⋆, we have that ordn(a)∣ϕ(n).
Proof. By Euler's Theorem, aϕ(n)=1 in Zn; so by the Lemma above, ordn(a)∣ϕ(n). ■
This theorem is what makes computing orders fast. Instead of grinding through a,a2,a3,… one power at a time, you only ever need to test the exponents k that divide ϕ(n); the order must be one of those divisors, and it is the smallest one that works.
Example. Find ord15(7).
First, ϕ(15)=ϕ(3)ϕ(5)=2×4=8, so ord15(7)∈{1,2,4,8}. Testing the divisors in increasing order,
717274=7=1,=49=3×15+4=4=1,=(72)2=42=16=1 in Z15.
Therefore, ord15(7)=4.
Example. Find ord18(5).
Here ϕ(18)=ϕ(2)ϕ(9)=1×6=6, so the order is one of 1,2,3,6. Testing,
515253=5=1,=25=7=1,=5×7=35=17=−1=1 in Z18.
Every proper divisor of 6 has failed, so the order is forced to be ϕ(18) itself; we do not even need to compute 56, since Euler's Theorem already guarantees 56=1. Therefore, ord18(5)=6.
Notice how landing on −1 was a bonus; once you see ak=−1, you immediately know a2k=1, and that no smaller multiple of k can give 1 along that chain. Keep an eye out for −1; it saves a lot of arithmetic.
Example. Find 72026 in Z15.
From earlier, ord15(7)=4, so the powers of 7 repeat with period 4; we only care about 2026 modulo the order:
202672026=4×506+2,=(74)506×72=1506×4=4 in Z15.
Therefore, 72026=4 in Z15. You could also have reduced the exponent modulo ϕ(15)=8 (Euler), but the order gives the tightest possible reduction. Reduce the exponent modulo the order, never modulo n; 2026≡1(mod15) tells you nothing about 72026.
Primitive Elements#
Since the order of a unit always divides ϕ(n), the largest an order can possibly be is ϕ(n) itself. The units that actually achieve this maximum get a special name.
Definition
For any n∈Z+, a primitive element of Zn∗ (or a primitive root modulo n) is any element a∈Zn∗ such that ordn(a)=ϕ(n).
Basically, a primitive element is a unit whose powers take the longest possible route before cycling back to 1; as we will see shortly, its powers visit every unit along the way.
Example. The primitive elements of Z7∗ are 3 and 5, since we saw in the order table that ord7(3)=ord7(5)=6=ϕ(7).
Example. What are the primitive elements of Z6∗?
Here Z6∗={1,5} and ϕ(6)=2. Clearly ord6(1)=1=2, and
52=25=4×6+1=1 in Z6,
so ord6(5)=2=ϕ(6). Therefore, the only primitive element of Z6∗ is 5.
Example. What are the primitive elements of Z8∗?
Here Z8∗={1,3,5,7} and ϕ(8)=4. Squaring each unit,
325272=9=1 in Z8,=25=1 in Z8,=49=1 in Z8,
so every unit other than 1 has order 2, and ord8(1)=1; no element has order ϕ(8)=4. Therefore, Z8∗ has no primitive elements. Not every Zn∗ has a primitive element; never assume one exists without checking.
Primitive Elements as Generators#
Notation
For any element a of a finite group, the (cyclic) group generated by a is written ⟨a⟩ and given by ⟨a⟩={a0,a1,a2,a3,…}.
Theorem
If a is a primitive element of Zn⋆, then
⟨a⟩={a0,a1,a2,…,aϕ(n)−1}=Zn∗.
Proof. Each power ak is a product of units and hence a unit, so ⟨a⟩⊆Zn∗. Now suppose two of the listed powers were equal; say ai=aj with 0≤i<j≤ϕ(n)−1. Since a is invertible, we can multiply both sides by (ai)−1 to get
aj−i=1,where 0<j−i<ϕ(n).
But a is primitive, so ordn(a)=ϕ(n); there is no positive exponent smaller than ϕ(n) giving 1, which is a contradiction. Hence the powers a0,a1,…,aϕ(n)−1 are ϕ(n) distinct elements of Zn∗; and since Zn∗ only has ϕ(n) elements in total, the two sets must be equal. ■
Basically, a primitive element generates the whole unit group; every single unit mod n is some power of a. This is exactly why primitive elements are so useful: one element single-handedly produces everything.
For example, the first six powers of either primitive element of Z7∗ sweep out all of Z7∗; all six units appear in the rows for 3 and 5:
| k |
1 |
2 |
3 |
4 |
5 |
6 |
… |
| 3k |
3 |
2 |
6 |
4 |
5 |
1 |
… |
| 5k |
5 |
4 |
6 |
2 |
3 |
1 |
… |
Contrast this with 2, which is not primitive; its powers 2,4,1,2,4,1,… only ever produce {1,2,4}, i.e. ⟨2⟩=Z7∗.
Multiplication with Primitive Elements#
In Zp for any prime p, we can use the fact that the powers of a primitive element generate Zp∗ to build a method for multiplication in Zp that is very time-efficient for very large p.
Suppose we know a is a primitive element of Zp∗ and have recorded the powers of a in a lookup table. Then we can multiply two numbers x,y∈Zp∗ as follows:
- Use the lookup table to find i and j such that x=ai and y=aj in Zp.
- Calculate (i+j)mod(p−1).
- Use the lookup table to find a(i+j)mod(p−1)=xy in Zp.
The reason we reduce the exponent mod p−1 is that ordp(a)=ϕ(p)=p−1, so by our boxed fact the exponents only matter modulo p−1. The efficiency of this method for large p (and x,y) comes from the fact that the only calculation required is addition, which is computationally much cheaper than multiplication; this is basically how logarithm tables worked before calculators, with i playing the role of loga(x).
Example. Given the powers of 2 in Z11, find 5×10 and 7×9 in Z11.
| k |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
| 2k |
2 |
4 |
8 |
5 |
10 |
9 |
7 |
3 |
6 |
1 |
For 5×10: from the table, 5=24 and 10=25, so
5×10=24×25=2(4+5)mod10=29=6 in Z11.
For 7×9: from the table, 7=27 and 9=26, so
7×9=27×26=213mod10=23=8 in Z11.
As a sanity check, 50=4×11+6 and 63=5×11+8; both answers agree with direct computation.
The lookup table also lets you run this machine in reverse, which is exactly a discrete logarithm.
Example. Find all x∈Z such that 2x=7 in Z11.
From the table, 27=7; and since the powers of 2 repeat with period ord11(2)=10, we have 2x=27 if and only if x≡7(mod10). Therefore, the solutions are exactly x≡7(mod10).
Example. Solve x4=5 in Z11.
Every non-zero element of Z11 is a power of the primitive element 2, so write x=2t; from the table 5=24. The equation becomes
24t4t2tt=24≡4(mod10)≡2(mod5)≡1(mod5),
where we divided the congruence (and the modulus) by gcd(4,10)=2, then multiplied by the inverse of 2 mod 5. So t∈{1,6} modulo 10, giving
xx=21=2,=26=9 in Z11.
Checking: 92=81=4 and 42=16=5 in Z11. Therefore, the solutions are x=2 and x=9. Notice how the primitive element converted a nasty power equation into a linear congruence in the exponent; this is the standard trick for equations of the form xk=b in Zp.
Which Unit Groups Have Primitive Elements#
We saw that Z8∗ has no primitive element, so existence is a genuine question. Fortunately there is a complete answer.
Theorem
The unit group Zn⋆ has a primitive element if and only if n is equal to 1, 2, 4, pk, or 2pk, where p is any odd prime and k∈Z+.
The proof of this one is apparently quite complicated so it's omitted for this course; these questions are just pattern matching against the list. In particular, every prime modulus has a primitive root, which is why the multiplication trick above always works in Zp.
Example. Do each of the following groups of units have primitive elements?
- Z10∗: here 10=2×5=2pk with p=5, k=1; so yes. (Indeed 3 works: its powers in Z10 are 3,9,7,1, so ord10(3)=4=ϕ(10).)
- Z35∗: here 35=5×7 is a product of two distinct odd primes, which is not on the list; so no.
- Z343∗: here 343=73=pk; so yes.
Example. Show directly that Z12∗ has no primitive element.
Since 12=22×3 is not of any of the allowed forms, the theorem says no; but it is worth seeing this happen by hand. We have Z12∗={1,5,7,11} and ϕ(12)=4, and
5272112=25=1 in Z12,=49=1 in Z12,=121=1 in Z12,
so every unit has order at most 2<4. This is the same behaviour as Z8∗; everything squares to 1, so no single element can generate all four units.
Finding a Primitive Element#
In general, there is no known efficient method to find a primitive element of Zn∗. The method we use (inefficient, but fine by hand) is:
- Choose a to be a small element of Zn∗, taking candidates from the list of numbers that are not pure powers: 2,3,5,6,7,10,11,… in order.
- For each prime divisor pi of ϕ(n), compute aϕ(n)/pi in Zn.
- If aϕ(n)/pi=1 in Zn for all prime divisors pi of ϕ(n), then (and only then) a is a primitive element of Zn∗.
The reason this works comes back to order dividing the totient. If ordn(a)=ϕ(n), then ordn(a) is a proper divisor of ϕ(n); its prime factorisation must be missing at least one copy of some prime divisor pi of ϕ(n), so ordn(a)∣ϕ(n)/pi, and hence aϕ(n)/pi=1 by the Lemma. Conversely, if a is primitive then no exponent smaller than ϕ(n) can give 1. So testing just those few exponents ϕ(n)/pi detects primitivity exactly; you never have to check every divisor of ϕ(n).
We skip pure powers like 4,8,9 in the candidate list because they can never succeed after their base has failed; if 4=22 were primitive, then ordn(2) would already have to be ϕ(n) (a power of 2 can't cycle for longer than 2 does), so 2 would have been primitive first.
Example. Find a primitive element of Z31∗.
Here ϕ(31)=30=2×3×5, so the exponents to test are
230=15,330=10,530=6.
Candidate a=2:
25215=32=1 in Z31,=(25)3=1 in Z31,
so 2 fails the test (in fact ord31(2)=5) and is not primitive.
Candidate a=3: first note 35=243=7×31+26=26=−5 in Z31, then
36310315=35×3=−15=16=1,=(35)2=(−5)2=25=1,=310×35=25×(−5)=−125=−1=1 in Z31,
since −125+4×31=−1. All three tests pass; therefore 3 is a primitive element of Z31∗. Notice how writing 26 as −5 made every one of these computations painless; working with small negative representatives is almost always faster than working with large positive ones.
Finding All Primitive Elements#
Once you have found one primitive element, you get all the others essentially for free.
Theorem
Given a is a primitive element of Zn⋆, we have that ak is a primitive element of Zn⋆ if and only if gcd(k,ϕ(n))=1.
Proof. Let g=gcd(k,ϕ(n)) and let m=ordn(ak). Since ordn(a)=ϕ(n), the Lemma from earlier gives
(ak)m=akm=1⟺ϕ(n)∣km.
Dividing both ϕ(n) and k by g, this is equivalent to gϕ(n)∣gkm; and since gcd(gϕ(n),gk)=1, this happens exactly when gϕ(n)∣m. The smallest positive such m is gϕ(n), so
ordn(ak)=gcd(k,ϕ(n))ϕ(n),
which equals ϕ(n) precisely when gcd(k,ϕ(n))=1. ■
The exact same argument works with ϕ(n) replaced by the order of any unit, giving a formula that is genuinely worth memorising:
ordn(ak)=gcd(k,ordn(a))ordn(a).
Basically, raising a to the power k shrinks its cycle by exactly the factor gcd(k,ordn(a)); if k shares no factors with the order, the cycle length is untouched.
Corollary
If a is a primitive element of Zn∗, then the complete set of all primitive elements in Zn∗ is given by {ak:k∈Zϕ(n)∗}.
Corollary
If Zn∗ has a primitive element, then altogether Zn∗ has exactly ∣Zϕ(n)∗∣=ϕ(ϕ(n)) primitive elements.
If Zn∗ has a primitive element, it has exactly ϕ(ϕ(n)) of them.
This matches everything we have seen so far: Z6∗ has 1 primitive element (5) and ϕ(ϕ(6))=ϕ(2)=1, while Z7∗ has 2 primitive elements (3 and 5) and ϕ(ϕ(7))=ϕ(6)=2.
Example. Given 2 is a primitive element of Z9∗, find all the primitive elements of Z9∗.
Here ϕ(9)=9−3=6, and Z6∗={1,5}; so by the corollary, the primitive elements are exactly 21 and 25:
2125=2,=32=3×9+5=5 in Z9.
Therefore, the primitive elements of Z9∗ are 2 and 5; as a check, ϕ(ϕ(9))=ϕ(6)=2 elements, as expected.
Example. Find all primitive elements of Z31∗.
From the previous section, 3 is a primitive element of Z31∗ and ϕ(31)=30. The units mod 30=2×3×5 are the numbers coprime to 2, 3 and 5:
Z30∗={1,7,11,13,17,19,23,29},
which has ϕ(30)=ϕ(2)ϕ(3)ϕ(5)=1×2×4=8 elements; so there are exactly 8 primitive elements, namely 3k for each k∈Z30∗. First tabulate the powers of 3 up to 315=−1:
| k |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
| 3k |
3 |
9 |
27 |
19 |
26 |
16 |
17 |
20 |
29 |
25 |
13 |
8 |
24 |
10 |
30 |
The exponents up to 15 can be read straight off the table, and since 315=−1, every later power is just the negative of an earlier one; 315+j=−3j:
3137311313317319323329=3,=17,=13,=24,=−32=−9=22,=−34=−19=12,=−38=−20=11,=−314=−10=21 in Z31.
Therefore, the primitive elements of Z31∗ are
{3,11,12,13,17,21,22,24},
and there are 8=ϕ(ϕ(31)) of them, as expected.
Example. Construct the full order table for Z13∗ and hence find all primitive elements of Z13∗.
The lazy way is to compute the whole 12×12 power table; the smart way is to find one primitive element and then use the boxed formula for ordn(ak).
First, ϕ(13)=12=22×3, so the prime divisors of ϕ(13) are 2 and 3 and we test the exponents 212=6 and 312=4. Trying a=2:
2426=16=3=1,=64=12=−1=1 in Z13,
so 2 is a primitive element of Z13∗. Its powers are:
| k |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
| 2k |
2 |
4 |
8 |
3 |
6 |
12 |
11 |
9 |
5 |
10 |
7 |
1 |
Every unit a∈Z13∗ is 2k for exactly one k∈{1,…,12}, and
ord13(2k)=gcd(k,12)12.
For instance 9=28, so ord13(9)=gcd(8,12)12=412=3; checking, 93=729=56×13+1=1 in Z13. Running through every k gives the complete order table:
| a |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
| ord13(a) |
1 |
12 |
3 |
6 |
4 |
12 |
12 |
4 |
3 |
6 |
12 |
2 |
The primitive elements are the units of order 12; therefore the primitive elements of Z13∗ are
{2,6,7,11},
and indeed ϕ(ϕ(13))=ϕ(12)=4 of them. Notice also how every order in the table is a divisor of 12, and for each divisor d of 12 the number of elements of order d is exactly ϕ(d):
d=1d=2d=3d=4d=6d=12:{1},:{12},:{3,9},:{5,8},:{4,10},:{2,6,7,11},ϕ(1)ϕ(2)ϕ(3)ϕ(4)ϕ(6)ϕ(12)=1,=1,=2,=2,=2,=4.
This pattern holds whenever a primitive element exists; it is a handy sanity check that your order computations are consistent, since the counts have to add up to ϕ(n).