This book contains a proof of Euler's Criterion for quadratic residues
This book contains a proof of Euler's Criterion for quadratic residues: Ifmod(m^((p-1)/2),p) = 1 if m is a quadratic residue mod p p-1 if not.Along the way, we also prove Wilson's Theorem: If
mod(j*j',p) = mod(m,p),called the associate of
Function:
(defun associate (j m p) (mod (* m (expt j (- p 2))) p))
Theorem:
(defthm associate-property (implies (and (primep p) (integerp m) (not (zp j)) (< j p) (not (divides p m))) (equal (mod (* (associate j m p) j) p) (mod m p))) :rule-classes nil)
Theorem:
(defthm associate-bnds (implies (and (primep p) (integerp m) (not (zp j)) (< j p) (not (divides p m))) (and (not (zp (associate j m p))) (< (associate j m p) p))) :rule-classes (:forward-chaining))
Theorem:
(defthm associate-is-unique (implies (and (primep p) (integerp m) (not (zp j)) (< j p) (not (divides p m)) (integerp x) (equal (mod m p) (mod (* j x) p))) (equal (associate j m p) (mod x p))) :rule-classes nil)
Theorem:
(defthm associate-of-associate (implies (and (primep p) (integerp m) (not (zp j)) (< j p) (not (divides p m))) (equal (associate (associate j m p) m p) (mod j p))))
Theorem:
(defthm associate-equal (implies (and (primep p) (integerp m) (integerp j) (not (divides p m)) (not (zp j)) (< j p) (not (zp i)) (< i p)) (equal (equal (associate j m p) (associate i m p)) (equal i j))))
Theorem:
(defthm associate-square (implies (and (primep p) (integerp m) (not (divides p m)) (not (zp j)) (< j p)) (iff (= (associate j m p) j) (= (mod (* j j) p) (mod m p)))) :rule-classes nil)If there exists
Function:
(defun root1 (m p) (find-root (1- p) m p))
Theorem:
(defthm res-root1 (implies (and (primep p) (residue m p)) (and (not (zp (root1 m p))) (< (root1 m p) p) (equal (mod (* (root1 m p) (root1 m p)) p) (mod m p)))) :rule-classes nil)
Function:
(defun root2 (m p) (- p (root1 m p)))
Theorem:
(defthm res-root2 (implies (and (primep p) (residue m p)) (and (not (zp (root2 m p))) (< (root2 m p) p) (equal (mod (* (root2 m p) (root2 m p)) p) (mod m p)))) :rule-classes nil)
Theorem:
(defthm associate-roots (implies (and (primep p) (integerp m) (not (divides p m)) (residue m p)) (and (equal (associate (root1 m p) m p) (root1 m p)) (equal (associate (root2 m p) m p) (root2 m p)))) :rule-classes nil)
Theorem:
(defthm only-2-roots (implies (and (primep p) (integerp m) (not (divides p m)) (residue m p) (not (zp j)) (< j p) (= (associate j m p) j)) (or (= j (root1 m p)) (= j (root2 m p)))) :rule-classes nil)
Theorem:
(defthm roots-distinct (implies (and (primep p) (not (= p 2)) (residue m p)) (not (= (root1 m p) (root2 m p)))) :rule-classes nil)For
Function:
(defun associates (n m p) (if (zp n) (if (residue m p) (cons (root2 m p) (cons (root1 m p) nil)) nil) (if (member n (associates (1- n) m p)) (associates (1- n) m p) (cons (associate n m p) (cons n (associates (1- n) m p))))))
Theorem:
(defthm member-associates (implies (and (primep p) (integerp m) (not (divides p m)) (integerp n) (< n p) (not (zp j)) (< j p)) (iff (member (associate j m p) (associates n m p)) (member j (associates n m p)))))We shall show that
Theorem:
(defthm subset-positives-associates (subsetp (positives n) (associates n m p)))
Theorem:
(defthm member-self-associate (implies (and (primep p) (integerp m) (not (divides p m)) (not (zp j)) (< j p) (equal (associate j m p) j)) (member j (associates n m p))))
Theorem:
(defthm distinct-positives-associates-lemma (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m)) (integerp n) (< n p)) (distinct-positives (associates n m p) (1- p))) :rule-classes nil)
Theorem:
(defthm distinct-positives-associates (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (distinct-positives (associates (1- p) m p) (1- p))) :rule-classes nil)We shall require a variation of the pigeonhole principle.
Theorem:
(defthm pigeonhole-principle-2 (implies (and (natp n) (distinct-positives l n) (subsetp (positives n) l)) (perm (positives n) l)) :rule-classes nil)
Theorem:
(defthm perm-associates-positives (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (perm (positives (1- p)) (associates (1- p) m p))) :rule-classes nil)It follows that the product of
Theorem:
(defthm times-list-associates-fact (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (equal (times-list (associates (1- p) m p)) (fact (1- p)))) :rule-classes nil)
Theorem:
(defthm perm-len (implies (perm l1 l2) (= (len l1) (len l2))) :rule-classes nil)
Theorem:
(defthm len-positives (equal (len (positives n)) (nfix n)))
Theorem:
(defthm len-associates (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (equal (len (associates (+ -1 p) m p)) (1- p))))
Theorem:
(defthm len-associates-even (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m)) (integerp n) (< n p)) (integerp (* 1/2 (len (associates n m p))))) :rule-classes (:type-prescription))On the other hand, we can compute the product of
Theorem:
(defthm times-list-associates (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m)) (< n p)) (equal (mod (times-list (associates n m p)) p) (if (residue m p) (mod (- (expt m (/ (len (associates n m p)) 2))) p) (mod (expt m (/ (len (associates n m p)) 2)) p)))) :rule-classes nil)Both Wilson's Theorem and Euler's Criterion now follow easily.
Theorem:
(defthm euler-lemma (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (equal (mod (fact (1- p)) p) (if (residue m p) (mod (- (expt m (/ (1- p) 2))) p) (mod (expt m (/ (1- p) 2)) p)))) :rule-classes nil)
Theorem:
(defthm wilson (implies (primep p) (equal (mod (fact (1- p)) p) (1- p))) :rule-classes nil)
Theorem:
(defthm euler-criterion (implies (and (primep p) (not (= p 2)) (integerp m) (not (divides p m))) (equal (mod (expt m (/ (1- p) 2)) p) (if (residue m p) 1 (1- p)))) :rule-classes nil)The First Supplement is the case
Theorem:
(defthm first-supplement (implies (and (primep p) (not (= p 2))) (iff (residue -1 p) (= (mod p 4) 1))) :rule-classes nil)