This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

All Prime Numbers Have Primitive Roots

Ruben Gamboa University of Wyoming
Laramie, Wyoming [email protected] Stanford University
Stanford, California
   Woodrow Gamboa Stanford University
Stanford, California [email protected]
Abstract

If pp is a prime, then the numbers 1,2,,p11,2,\dots,p-1 form a group under multiplication modulo pp. A number gg that generates this group is called a primitive root of pp; i.e., gg is such that every number between 11 and p1p-1 can be written as a power of gg modulo pp. Building on prior work in the ACL2 community, this paper describes a constructive proof that every prime number has a primitive root.

1 Introduction

This paper describes a proof in ACL2 of the fact that all prime numbers have primitive roots. A primitive root of a prime number pp is a number gg such that all the numbers 1,2,,p11,2,\dots,p-1 can be written as gnmodpg^{n}\bmod p for some value of nn. For example, if p=5p=5, then g=2g=2 is a primitive root of pp since 1=24mod51=2^{4}\bmod 5, 2=21mod52=2^{1}\bmod 5, 3=23mod53=2^{3}\bmod 5, and 4=22mod54=2^{2}\bmod 5. However, for p=7p=7, the number 22 is not a primitive root of 7, because 2nmod72^{n}\bmod 7 is always one of 22, 44, or 11. In particular, 22 does not generate 33 mod 77. So not all numbers in 1,2,,p11,2,\dots,p-1 are powers of 22. The reader can easily verify that 33 is a primitive root of 77, so the theorem holds in this case.

More formally, if pp is a prime it is well known that the set of numbers modulo pp, written /p\mathbb{Z}/p\mathbb{Z}, forms a field. This occurs because when pp is prime and for non-zero a/pa\in\mathbb{Z}/p\mathbb{Z}, aa always has a multiplicative inverse, i.e., a number b/pb\in\mathbb{Z}/p\mathbb{Z} such that ab1(modp)ab\equiv 1\pmod{p}. (Actually, inverses exist whenever aa and pp have no common factors, but this is guaranteed for all non-zero aa when pp is prime.)

The multiplicative group of this field, denoted by (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}, contains the elements 1,2,,p11,2,\dots,p-1 and gg is a primitive root of pp precisely when gg generates (in the sense of group theory) this group. So the fact that prime numbers have primitive roots actually tells us something very interesting about the structure of the group (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}; it is a cyclic group, so it has the simplest possible structure. Primitive roots also have applications to fast arithmetic modulo pp, similar to the way logarithms can be used to turn multiplication to addition over the reals [6].

The ACL2 formalization of this result follows the hand proof presented in [4]. The proof itself builds on two significant forays into number theory in ACL2. First is Russinoff’s proof of quadratic reciprocity, which also defined the foundational notions of divides, primep, and useful lemmas such as that prime fields are integral domains (if ab=0ab=0 then either a=0a=0 or b=0b=0), and an important lemma due to Euclid (if pp divides abab, then either pp divides aa or pp divides bb[5, 8]. We also built on top of Kestrel’s formalization of prime fields, which includes definitions for the various field operations and their various arithmetic properties [7]. As this brief list of prior results indicates, many basic facts from number theory have already been formalized in ACL2, but unfortunately the results are scattered in several places in the community books. This is unfortunate, because number theory is a very practical branch of mathematics, e.g., with applications to cryptography. One thing we learned from this project is that it is time to collect these various results under a common branch of the community books, so that future projects can more easily build on top of the foundations that have already been implemented.

The rest of this paper is organized as follows. In Sect. 2, we present some of the basic mathematical definitions in ACL2 of standard concepts from number (and group) theory, like the order of a group element. These are actually useful formalizations that could be used in other projects, not just as part of this effort. Then in Sect. 3 we discuss polynomial congruences, and in particular we prove that a special family of polynomials have the greatest possible number of distinct roots. This seemingly unrelated fact turns out to be a key technical lemma that is used in Sect. 4 to construct elements that have a desired order. The proof of the main theorem follows from these constructions, and it is shown in Sect. 5. We conclude the paper in Sect. 6 and give some ideas for future work.

2 Mathematical Background

In this section, we discuss some mathematical foundations that are needed to prove that all prime numbers have primitive roots. The definitions and proofs in this section are very general and not solely for the purpose of our desired theorem. In other words, these should be part of a global library of ACL2 books formalizing number theory.

The first important concept is that of the order of an element of a group. If a(/p)a\in\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}, the order of aa, denoted as ord(a)\operatorname{ord}(a), is the least positive integer kk such that ak1(modp)a^{k}\equiv 1\pmod{p}.

The notion of order does not appear to be well-defined, since it seems possible that ak1(modp)a^{k}\not\equiv 1\pmod{p} for all positive integers kk. But when pp is prime, an important theorem of Fermat’s says that this cannot be the case.

Theorem 1 (Fermat’s Little Theorem).

If pp is a prime number, and a(/p)a\in\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}, then ap11(modp)a^{p-1}\equiv 1\pmod{p}.

This theorem, formalized in ACL2 as part of [5, 8], immediately shows that ord(a)p1\operatorname{ord}(a)\leq p-1. We used this to define order in ACL2. First, the function (all-powers a p) generates the list [a1modp,a2modp,,akmodp][a^{1}\bmod p,a^{2}\bmod p,\dots,a^{k}\bmod p] such that kp1k\leq p-1 and if 1i<k1\leq i<k, then aimodp1a^{i}\bmod p\neq 1. Clearly, the length of (all-powers a p) is between 11 and p1p-1, inclusive, and when the length is less than p1p-1 the last element must be equal to 1. Using Fermat’s Little Theorem, it is easy to show that even when the length is exactly equal to p1p-1, the last element is equal to 1. Then (order a p) is defined as (len (all-powers a p)), and it follows that aord(a)1(modp)a^{\operatorname{ord}(a)}\equiv 1\pmod{p}.

Another important theorem about order is that if nn is a positive integer such that an(modp)=1a^{n}\pmod{p}=1 and there does not exist a smaller positive integer mm such that am(modp)=1a^{m}\pmod{p}=1, then in fact ord(a)=n\operatorname{ord}(a)=n. We capture this theorem in ACL2 as

(defthmd smallest-pow-eq-1-is-order
(implies (and (fep a p)
(not (equal 0 a))
(primep p)
(posp n)
(equal (pow a n p) 1)
(not (exists-smaller-power-eq-1 a p n)))
(equal (order a p) n))
:hints ...)

We include the ACL2 source of that theorem here, only to familiarize the reader with the functions fep which recognizes elements of the field /p\mathbb{Z}/p\mathbb{Z}, primep which recognizes primes, pow which performs exponentiation in the field, and its friends add, mul, inv, etc., which perform the other arithmetic operations in the field—all of these were previously defined in the ACL2 Community Books.

An important fact about order is that for any element aa, ord(a)\operatorname{ord}(a) divides p1p-1, which we will write in the usual notation as ord(a)p1\operatorname{ord}(a)\mid p-1. This follows because if ord(a)=n\operatorname{ord}(a)=n, then the list L_n=[a1modp,a2modp,,anmodp]L_{\_}n=[a^{1}\bmod p,a^{2}\bmod p,\dots,a^{n}\bmod p] ends in 11, and 11 does not appear anywhere inside the list. But then an+kanaka_k(modn)a^{n+k}\equiv a^{n}a^{k}\equiv a_{\_}k\pmod{n}, so L_2n=[a1modp,a2modp,,a2nmodp]L_{\_}{2n}=[a^{1}\bmod p,a^{2}\bmod p,\dots,a^{2n}\bmod p] is simply two copies of L_nL_{\_}n; i.e., L_2n=app(L_n,L_n)L_{\_}{2n}=app(L_{\_}n,L_{\_}n). That means that L_2nL_{\_}{2n} ends in 11, and the only ones are anmodpa^{n}\bmod p and a2nmodpa^{2n}\bmod p. This is easily extended to any multiple of nn, and since we know that ap1modp=1a^{p-1}\bmod p=1, it follows (almost) immediately that p1p-1 must be a multiple of ord(a)\operatorname{ord}(a), i.e., ord(a)p1\operatorname{ord}(a)\mid p-1. This is actually a special case of Lagrange’s theorem for groups, but specialized for (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}.

Another fact about order that is important to our proof is that the order of an inverse is the same as the order of the element. I.e., ord(a1)=ord(a)\operatorname{ord}(a^{-1})=\operatorname{ord}(a). We proved this equality by showing that both inequalities hold, and we used Lagrange’s theorem to establish the inequalities. The end result in ACL2 is as follows

(defthmd order-inv
(implies (and (fep a p)
(not (equal 0 a))
(primep p))
(equal (order (inv a p) p)
(order a p)))
:hints ...)

We end this section by mentioning that the proof uses many facts about divides and the greatest common divisor of two integers, formalized as divides and g-c-d in [5, 8]. And it also depends on many facts about the arithmetic functions in /p\mathbb{Z}/p\mathbb{Z}, which were formalized in [7]. While we needed to prove a handful of additional properties about many of these these functions, the existing formalizations had already established most of the foundational results, so this was mostly a matter of engineering the lemmas needed for our proof.

3 A Special Polynomial Congruence

In this section, we take an aside to consider polynomials modulo pp. That is, we explore the roots of polynomial congruences, such as

a_0+a_1x++a_n1xn1+a_nxn0(modp).a_{\_}0+a_{\_}1x+\cdots+a_{\_}{n-1}x^{n-1}+a_{\_}nx^{n}\equiv 0\pmod{p}.

The reason that polynomials pop up on a paper about prime numbers, is that polynomials can be used as an alternative language to describe properties of congruences. For example, Fermat’s Little Theorem can be restated by saying that the polynomial congruence

1+xp10(modp)-1+x^{p-1}\equiv 0\pmod{p}

has exactly p1p-1 distinct roots in (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}.

Polynomials in ACL2 were formalized in [3] (among possibly many others), but there are significant differences between polynomials and polynomial congruences. For example, the polynomial x2+2x^{2}+2 has no roots among the reals, but the similar polynomial congruence x2+2x^{2}+2 does have a root in /11\mathbb{Z}/11\mathbb{Z}, because when x=3x=3, x2+2=32+2=110(mod11)x^{2}+2=3^{2}+2=11\equiv 0\pmod{11}. So many of the properties of polynomials could not be trivially transferred to polynomial congruences, and they had to be reproved from first principles.

One important lemma is that if xx is a root of the product of polynomials poly1 and poly2, then xx must be a root of at least one of those polynomials. This result depends crucially on the fact that (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*} is an integral domain when pp is prime; i.e., if ab0(modp)ab\equiv 0\pmod{p} then either a0(modp)a\equiv 0\pmod{p} or b0(modp)b\equiv 0\pmod{p}. This lemma has a (mostly) immediate corollary, that the number of distinct roots of the product of poly1 and poly2 is at most the number of distinct roots of poly1 plus the number of distinct roots of poly2. Note that all the roots must be in (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}, so the number of distinct roots of any polynomial is at most p1p-1. This also means that it is possible to find a root methodically, by testing if 11 is a root, or 22 is a root, an so on. So if we know that a polynomial has a root, finding that root is guaranteed.

As a special case, consider a linear polynomial of the form a_0+a_1xa_{\_}0+a_{\_}1x, where a_10(modp)a_{\_}1\not\equiv 0\pmod{p}. Then aa is a root of this polynomial congruence if and only if a=a_0/a_1modpa=-a_{\_}0/a_{\_}1\bmod p, or in ACL2

(defthm root-of-linear-pfield-polynomial
(implies (and (primep p)
(non-trivial-pfield-polynomial-p poly p)
(equal (len poly) 2)
(fep a p))
(equal (pfield-polynomial-root-p poly a p)
(equal a (neg (div (first poly)
(second poly)
p)
p))))
:hints ...)

In particular, since the arithmetic operations return a single value, this also shows that a non-trivial linear polynomial has exactly one root, where by “non-trivial” we mean that a_10(modp)a_{\_}1\not\equiv 0\pmod{p}.

Now consider a general polynomial P(x)=a_0+a_1x++a_n1xn1+a_nxnP(x)=a_{\_}0+a_{\_}1x+\cdots+a_{\_}{n-1}x^{n-1}+a_{\_}nx^{n} with a_n0(modp)a_{\_}n\not\equiv 0\pmod{p}. Suppose that aa is a root of this polynomial. Then using the long-division algorithm for polynomials, we can factor P(x)P(x) into P(x)=(xa)Q(x)P(x)=(x-a)Q(x) where Q(x)=b_0+b_1x++b_n2xn2+b_n1xn1Q(x)=b_{\_}0+b_{\_}1x+\cdots+b_{\_}{n-2}x^{n-2}+b_{\_}{n-1}x^{n-1}, for some suitable choice of b_ib_{\_}i.

(defthm eval-poly-with-root
(implies (and (integer-polynomial-p poly)
(primep p)
(integerp a)
(fep x p)
(pfield-polynomial-root-p poly a p))
(equal (eval-pfield-polynomial poly x p)
(mul (eval-pfield-polynomial
‘(,(- a) 1)
x p)
(eval-pfield-polynomial
(cdr (divide-polynomial-with-remainder-by-x+a
poly
(- a)))
x p)
p)))
:hints ...)

This also shows that if bb is a root of P(x)P(x), then either b=ab=a or bb is a root of Q(x)Q(x). In other words, the number of distinct roots of P(x)P(x) is at most 1 more than the number of distinct roots of Q(x)Q(x). If n=1n=1, we’ve already seen that P(x)P(x) has exactly one root in (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}. So by induction, the number of roots of P(x)P(x) is at most nn.

(defthm num-roots-of-poly-upper-bound
(implies (and (primep p)
(non-trivial-pfield-polynomial-p poly p)
(<= 2 (len poly)))
(<= (pfield-polynomial-num-roots poly p)
(len (cdr poly))))
:hints ...)

This is, of course, a familiar and expected result for polynomials over the reals, but it is somewhat surprising over /p\mathbb{Z}/p\mathbb{Z}, since it is possible that P(a)0P(a)\neq 0 but that P(a)0(modp)P(a)\equiv 0\pmod{p}. I.e., it is possible that aa is a root of the congruence, but not of the polynomial over the reals. Nevertheless, the total number of roots for the congruence is still bounded by nn.

Now we introduce a special class of polynomials, which we call Fermat polynomials. The function (fermat-poly n) constructs the polynomial 1+xn-1+x^{n}. Now suppose that n=p1n=p-1. From Fermat’s Little Theorem, it follows that this polynomial has exactly n=p1n=p-1 roots.

(defthm num-roots-of-fermat-poly
(implies (primep p)
(equal (pfield-polynomial-num-roots (fermat-poly (1- p)) p)
(1- p)))
:hints ...)

Now, suppose that nn is a composite that can be written as n=cdn=cd, and again consider the polynomial 1+xn-1+x^{n}. We observe that this polynomial can always be factored as

1+xn=1+xcd=(1+xd)(1+xd+x2d++x(c1)d).-1+x^{n}=-1+x^{cd}=(-1+x^{d})(1+x^{d}+x^{2d}+\dots+x^{(c-1)d}). (1)

This result is easily proved on paper by expanding the right-hand side and matching up exponents. In ACL2, this is a more technical proof that is really more about list manipulation. In particular, notice that the second polynomial on the right-hand side consists of c1c-1 copies of the polynomial xdx^{d} and that multiplying is by xdx^{d} (and taking into account the leading 1) results in cc copies of xdx^{d} with a leading 0 consed in front. Summing the negated polynomial then cancels all but the last copy of xdx^{d}, so the result is 1+xcd-1+x^{cd}. We found it convenient that reasoning about exponents was reduced to reasoning about cons and append kk times, at which ACL2 excels.

Looking at Eqn. 1, we see that the left-hand side has exactly nn roots when n=p1n=p-1 since pp is prime. But the right-hand side has at most d+(c1)dd+(c-1)d distinct roots. Since d+(c1)d=d+cdd=cd=nd+(c-1)d=d+cd-d=cd=n, we conclude that both polynomials in the product of the right-hand side must have the maximum number of distinct roots. In particular, the polynomial 1+xd-1+x^{d} must have exactly dd distinct roots. Recall that the only thing special about dd is that is divides nn, so we have proved the following important technical lemma:

(defthm num-roots-fermat-poly-divisor-implicit
(implies (and (posp d)
(primep p)
(divides d (1- p)))
(equal (pfield-polynomial-num-roots (fermat-poly d) p) d))
:hints ...)

We will use this lemma in the next section.

4 Constructing Elements of Given Order in (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}

In this section, we show how we can construct an element that has a desired order in (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*}, possibly by using other elements with known smaller order.

For starters, suppose that aa has order mm and bb has order nn. What is the order of abab? In general, there’s not much we can say; e.g., if b=a1b=a^{-1} then ab=1ab=1 so its order is 11. But when mm and nn are relatively prime, that is gcd(m,n)=1\gcd(m,n)=1, it turns out that the order of abab is equal to mnmn.

To see this, observe that (ab)mn1(modp)(ab)^{mn}\equiv 1\pmod{p}. This follows because

(ab)mn\displaystyle(ab)^{mn} ((ab)m)n\displaystyle\equiv\left((ab)^{m}\right)^{n}
(ambm)n\displaystyle\equiv\left(a^{m}b^{m}\right)^{n}
(1bm)n\displaystyle\equiv\left(1b^{m}\right)^{n}
(bm)n\displaystyle\equiv\left(b^{m}\right)^{n}
bmn\displaystyle\equiv b^{mn}
(bn)m\displaystyle\equiv\left(b^{n}\right)^{m}
1m\displaystyle\equiv 1^{m}
1(modp).\displaystyle\equiv 1\pmod{p}.

As seen in Sect. 2, this implies that ord(ab)mn\operatorname{ord}(ab)\mid mn, which means ord(ab)mn\operatorname{ord}(ab)\leq mn. That is, ord(ab)ord(a)ord(b)\operatorname{ord}(ab)\leq\operatorname{ord}(a)\operatorname{ord}(b).

Now, suppose that kk is such that (ab)k1(modp)(ab)^{k}\equiv 1\pmod{p}. It follows that akbk(b1)k(modp)a^{k}\equiv b^{-k}\equiv(b^{-1})^{k}\pmod{p}. Raising both sides to the power nn, we have that ank(b1)nka^{nk}\equiv(b^{-1})^{nk}. Since ord(b1)=ord(b)=n\operatorname{ord}(b^{-1})=\operatorname{ord}(b)=n, (b1)nk1(modp)(b^{-1})^{nk}\equiv 1\pmod{p}, so ank1(modp)a^{nk}\equiv 1\pmod{p} as well. This means that ord(ak)m\operatorname{ord}(a^{k})\mid m and ord(ak)n\operatorname{ord}(a^{k})\mid n, and since gcd(m,n)=1\gcd(m,n)=1 this means that the only possible value of ord(ak)\operatorname{ord}(a^{k}) is 1.

All that is to show that akbk1(modp)a^{k}\equiv b^{k}\equiv 1\pmod{p}. but that means that mkm\mid k and nkn\mid k. Again, since gcd(m,n)=1\gcd(m,n)=1 this means that mnkmn\mid k. The only constraint on kk is that (ab)k1(modp)(ab)^{k}\equiv 1\pmod{p}, so ord(ab)\operatorname{ord}(ab) is such a kk. This means that ord(a)ord(b)ord(ab)\operatorname{ord}(a)\operatorname{ord}(b)\mid\operatorname{ord}(ab), so ord(a)ord(b)ord(ab)\operatorname{ord}(a)\operatorname{ord}(b)\leq\operatorname{ord}(ab). Combined with the earlier inequality this shows that ord(ab)=ord(a)ord(b)\operatorname{ord}(ab)=\operatorname{ord}(a)\operatorname{ord}(b). In particular, given aa and bb with orders mm and nn that are relatively prime, this shows that we can construct an element with order mnmn:

(defthm construct-product-order
(implies (and (primep p)
(fep a p)
(not (equal 0 a))
(fep b p)
(not (equal 0 b))
(relatively-primep (order a p) (order b p)))
(equal (order (mul a b p) p)
(* (order a p) (order b p))))
:hints ...)

We now show how to construct an element that has a different special order. In particular, we wish to show that if pp and qq are primes and qkn=p1q^{k}\mid n=p-1, then there is some element g_qkg_{\_}{q^{k}} of (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*} with order qkq^{k}.

We define the function (number-of-powers x q) which returns the largest power kk such that qkxq^{k}\mid x. For instance, (number-of-powers 40 2) is 3, since 40=23540=2^{3}\cdot 5. Now suppose that xx divides a prime power qnq^{n}. Then in fact, xx must be one of 11, qq, q2q^{2}, …, qnq^{n}. In particular, x=qkx=q^{k} where kk is the number of powers of qq in xx (and note that knk\leq n):

(defthm factors-of-prime-powers
(implies (and (primep q)
(posp x)
(natp n)
(divides x (expt q n)))
(equal x (expt q (number-of-powers x q))))
:hints ...)

So suppose that xx is such that xqn1(modp)x^{q^{n}}\equiv 1\pmod{p}, assuming for now that such an xx exists. Then clearly ord(x)qn\operatorname{ord}(x)\mid q^{n}, which means that ord(qn)\operatorname{ord}(q^{n}) must be one of 11, qq, q2q^{2}, …, qnq^{n}. Now suppose also that the order of xx is qiq^{i} where i<ni<n. Then xqi1(modp)x^{q^{i}}\equiv 1\pmod{p}, so xqj1(modp)x^{q^{j}}\equiv 1\pmod{p} for any j>ij>i. This follows because

xqj\displaystyle x^{q^{j}} xqi+ji\displaystyle\equiv x^{q^{i+j-i}}
xqiqji\displaystyle\equiv x^{q^{i}q^{j-i}}
(xqi)qji\displaystyle\equiv\left(x^{q^{i}}\right)^{q^{j-i}}
1qji\displaystyle\equiv 1^{q^{j-i}}
1(modp)\displaystyle\equiv 1\pmod{p}

In particular, if the order of xx is qiq^{i} where i<ni<n, it must be the case that xqn11(modp)x^{q^{n-1}}\equiv 1\pmod{p}.

(defthm order-is-prime-power-lemma
(implies (and (primep p)
(primep q)
(<= q p)
(fep a p)
(not (= 0 a))
(natp n)
(= (pow a (expt q n) p) 1)
(not (= (pow a (expt q (- n 1)) p) 1)))
(equal (order a p) (expt q n)))
:hints ...)

Now we address the question of whether such an xx exists. I.e., is there an xx such that both of these equations hold:

xqn\displaystyle x^{q^{n}} 1(modp)\displaystyle\equiv 1\pmod{p} (2)
xqn1\displaystyle x^{q^{n-1}} 1(modp)\displaystyle\not\equiv 1\pmod{p} (3)

Note that for such an xx, ord(x)\operatorname{ord}(x) is necessarily equal to qnq^{n}.

This is where the theorems about polynomials proved in Sect. 3 come into play. Eqn. 2 holds precisely when xx is a root of the polynomial congruence xqn10(modp)x^{q^{n}}-1\equiv 0\pmod{p}, and the theorem from Sect. 3 guarantees that there are precisely qnq^{n} distinct roots of this polynomial congruence, as long as qnp1q^{n}\mid p-1. So there are qnq^{n} values of xx that satisfy Eqn. 2. Similarly, there are qn1q^{n-1} values of xx that satisfy Eqn. 3, again under the assumption that qn1p1q^{n-1}\mid p-1, which is guaranteed when qnp1q^{n}\mid p-1. Since qn>qn1q^{n}>q^{n-1}, there must be at least one xx that satisfies Eqn. 2 but not Eqn. 3. It follows, then that ord(x)=qn\operatorname{ord}(x)=q^{n} for this particular xx. Moreover, as observed earlier, the roots of any non-trivial polynomial congruence must be one of 11, 22, …, p1p-1, so it is possible to find an appropriate value of xx by searching.

(defthm order-is-prime-power
(implies (and (primep p)
(primep q)
(natp n)
(divides (expt q n) (1- p)))
(and (fep (witness-with-order-q^n q n p) p)
(not (= 0 (witness-with-order-q^n q n p)))
(equal (order (witness-with-order-q^n q n p) p)
(expt q n))))
:hints ...)

Using the two theorems proved in this section, we will show in the next how to find an element with order p1p-1, i.e., a primitive root of pp.

5 A Primitive Root of pp

Using the results proved in Sect. 4, it is straightforward to prove that all prime numbers have primitive roots. The typical pen-and-paper proof goes like this. Suppose that pp is an odd prime. (If p=2p=2, it is obvious that 11 is a primitive root.) Factor the number p1p-1 as a product of prime powers, as in

p1=q_1k_1q_2k_2q_mk_m.p-1={q_{\_}1}^{k_{\_}1}\cdot{q_{\_}2}^{k_{\_}2}\cdot\dots\cdot{q_{\_}m}^{k_{\_}m}.

Now, for each term q_ik_i{q_{\_}i}^{k_{\_}i}, there is an element c_ic_{\_}i of order q_ik_i{q_{\_}i}^{k_{\_}i}. Note that all the q_iq_{\_}i are primes distinct from one another, so the gcd of any q_ik_i{q_{\_}i}^{k_{\_}i} and any product of other q_jk_j{q_{\_}j}^{k_{\_}j} must be 11. So the c_ic_{\_}i are numbers of order q_ik_i{q_{\_}i}^{k_{\_}i} which are relatively prime. So c=c_1c_2c_mc=c_{\_}1\cdot c_{\_}2\cdot\dots\cdot c_{\_}m must have order q_1k_1q_2k_2q_mk_m=p1{q_{\_}1}^{k_{\_}1}\cdot{q_{\_}2}^{k_{\_}2}\cdot\dots\cdot{q_{\_}m}^{k_{\_}m}=p-1. Thus cc is a primitive root of pp.

We could have followed this approach in ACL2, and in fact prime factorization has been formalized in ACL2 and NQTHM numerous times, e.g., in [2]. But this turned out not to be very helpful for two reasons. First, the formalization in [2] uses a different (albeit equivalent) definition of “prime.” This is a common situation in the ACL2 formalizations of number theory, and it is something that we would like to see addressed. Second, the result about primitive roots does not depend on the full Fundamental Theorem of Arithmetic; i.e., what we need is that the number p1p-1 can be decomposed into prime powers, but we do not need that the decomposition is unique. Naturally, the uniqueness property is the hardest part of the proof. So simply proving a weak version of prime factorization would be easy and effective for our purposes.

In fact, it’s possible to decompose p1p-1 into powers of primes and compute the primitive root cc at the same time. The first step is to define the function (primitive-root-aux k p) that finds an element of order k:

(defun primitive-root-aux (k p)
(if (or (zp k) (= 1 k))
1
(let* ((q (least-divisor 2 k))
(n (number-of-powers k q))
(k1 (/ k (expt q n))))
(mul (witness-with-order-q^n q n p)
(primitive-root-aux k1 p)
p))))

The difficult part is helping ACL2 admit this function by proving that it always terminates. The function least-divisor, defined in [5, 8], finds the smallest divisor (starting at 2) of k. For k2k\geq 2, it is shown in [5, 8] that this number is always a prime less than or equal to kk. Then the function number-of-powers finds the corresponding exponent in the prime decomposition of k. Using those facts, we proved that k/qnk/q^{n} is a natural number that is smaller than kk, thus proving the termination of the function.

By inspection, it is easy to see that this function does return the primitive root cc described in the hand proof. We proved that in ACL2 using an induction suggested by the function primitive-root-aux to prove the following key theorem:

(defthm primes-have-primitive-roots-aux
(implies (and (primep p)
(natp k)
(divides k (1- p)))
(equal (order (primitive-root-aux k p) p)
k))
:hints ...)

In order for this to work, we had to prove a number of technical lemmas. For starters, since we’re using induction as suggested by primitive-root-aux we have to show that k/qnk/q^{n} is a natural that divides p1p-1 whenever kk is a natural that divides p1p-1. And we also had to show that the two terms multiplied in primitive-root-aux satisfy the conditions of the theorems construct-product-order and order-is-prime-power that are used to create the element of order kk. The most interesting are

  • the functions return elements in the multiplicative group (/p)\left(\mathbb{Z}/p\mathbb{Z}\right)^{*},

  • in particular the result of those operations is never 0,

  • the number k/qnk/q^{n} divides p1p-1 if kk divides p1p-1,

  • and the gcd of qnq^{n} and k/qnk/q^{n} is 11.

Once that is done, the primitive root of pp can be defined and shown to be a primitive root as follows:

(defund primitive-root (p)
(primitive-root-aux (1- p) p))
(defthm primes-have-primitive-roots
(implies (primep p)
(equal (order (primitive-root p) p)
(1- p)))
:hints ...)

6 Conclusion

In this paper, we presented a proof that all prime numbers have at least one primitive root. In fact, the number of primitive roots of pp can be shown to be ϕ(p1)\phi(p-1) where ϕ\phi is Euler’s totient function (the number of positive integers up to nn that are relatively prime to nn). Proving that would be a nice extension to this work that could happen in the future.

The proof relied on prior work on number theory, but our experience suggests that the prior work is scattered across many directories in the community books. Moreover, many foundational results needed to be proved to complement the existing foundations. This reflects the fact that the development of number theory in ACL2 has been driven by specific results, so the foundations developed in each project are tailored to support the needs of those specific projects. Given the importance of number theory in areas such as cryptography, as well as the suitability of ACL2 to reason effectively about this branch of mathematics, we think is would be a great time to consolidate these formalizations in ACL2 under a common location in the community books. Recent discussions in the ACL2 mailing list suggest that there is enough momentum to carry out this project.

References