Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The polynomial Fermat characterization of the primes (Lemma 2.1)

Proved
AKS.poly_fermat

by Lucas · Oct 21, 2026 · Mathlib 0df444a (Lean v4.33.1)

fermats-little-theorempolynomial-congruencesprimality-testing

Lemma 2.1 of Agrawal, Kayal, and Saxena's paper (Annals of Mathematics 160 (2004) 781-793): the generalization of Fermat's Little Theorem to polynomial rings. For n at least 2 and a coprime to n, n is prime if and only if (X + a)^n = X^n + a in the polynomial ring over Z_n. The forward direction is the freshman's dream in Z_p[X] - every binomial coefficient C(p, i) with 0 < i < p is divisible by p - together with Fermat's little theorem for the base a. The backward direction isolates the coefficient of X^q, for a prime q with q^k dividing n exactly: the coefficient is C(n, q) a^(n-q), whose q-adic valuation falls below k because q^k does not divide C(n, q) and q does not divide a, so the identity fails in Z_n[X].

Formalization Note The congruence is stated as the definition polyFermat n a, an equality in Polynomial (ZMod n); the coprimality of a and n is a hypothesis, as in the paper.

Preamble
import Mathlib
import Definitions.Def_AKS_poly
import Definitions.Def_AKS_alg
Formal statement
namespace AKS

/-!  Lemma 2.1 of the paper: the polynomial Fermat characterization of the
primes.  -/
theorem poly_fermat (n a : ℕ) (hn : 2 ≤ n) (ha : Nat.gcd a n = 1) :
    Nat.Prime n ↔ polyFermat n a := by sorry

end AKS
Source
M. Agrawal, N. Kayal, N. Saxena, PRIMES is in P, Ann. of Math. 160 (2004) 781-793, Section 2 (Lemma 2.1).
Read-back

What the Lean code literally says, in plain math · glm-5-latest-short

Restate: for n at least 2 and a with gcd(a, n) = 1, n is prime exactly when the polynomial (X + a)^n equals X^n + a in Z_n[X]. No other hypotheses appear. The forward direction rests on the divisibility of the intermediate binomial coefficients by the prime; the backward direction on the nonvanishing of the coefficient of X^q modulo n for a prime q dividing n with multiplicity k, driven by q^k not dividing C(n, q) and by the coprimality of a with n.

Human review
  • Endorsed by Shuze Chen · Oct 21, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Lucas · Oct 21, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me