Skip to content

Pocklington primality certificates - #1233

Open
bgregoir wants to merge 1 commit into
zmodp-substfrom
pocklington
Open

bgregoir wants to merge 1 commit into
zmodp-substfrom
pocklington

Conversation

@bgregoir

@bgregoir bgregoir commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Adds Pocklington's primality criterion with computable certificates. It is a port of coqprime's Pocklington.v; names follow mathcomp where an equivalent exists.

Stacked on #1238 (ZModP); followed by #1237 (ChaChaPoly: 2^130 - 5 is prime and the Poly1305 proofs).

theories/algebra/IntDiv.ec (generic modular arithmetic, moved here following review)

  • modzXm; the multiplicative order on integers mulorder a n with mulorder_spec, mulorder_gt0, expz_mulorder, mulorder_dvdz, mulorder_dvd_pred (named mulorder to avoid a clash with Group.order);
  • pdivP (an integer > 1 has a prime divisor) and primePns (characterisation of non-primes by a prime divisor p with p^2 <= n);
  • reduction rules for computing, kept out of the default database: modular exponentiation by squaring powmod (powmod0, powmodE) in the hint database powmod, and Euclid's algorithm gcdE : gcd a b = if b = 0 then |a| else gcd b (a %% b) in the hint database gcd. They are used as cbv delta hint +powmod +gcd; plain cbv is unchanged.

theories/algebra/Pocklington.ec (new)

  • pocklington: if N - 1 = F1 * R1 and, for every prime p | F1, some a satisfies a^(N-1) = 1 mod N and gcd(a^((N-1)/p) - 1, N) = 1, then every prime divisor of N is 1 mod F1; pocklington_prime concludes prime N when N < F1^2. Unlike coqprime, the combination of the prime factors of F1 goes through gcd/Gauss instead of prime powers, and there is no 1 < a hypothesis;
  • computable corollary pock_certif : pock_check N c => all (fun pa => prime pa.1) c => prime N, where the certificate c lists pairs (p, a) whose p multiply to F1; pock_check is decided by cbv delta hint +powmod +gcd.

No new axioms. All of stdlib and examples check.

@fdupress

Copy link
Copy Markdown
Member

This would probably be best as 3 separate PRs (stacked):

  1. the ZModP change;
  2. Pocklington's criterion and computable primality check;
  3. the finalization of the ChaCha+Poly proofs.

We can probably merge as a single PR but it would be good to have the commits rebased into the above so each is meaningful in isolation.

Comment thread theories/algebra/Pocklington.ec Outdated
by rewrite !exprS // -(modzMmr (m %% d)) ih modzMmr modzMml.
qed.

(* -------------------------------------------------------------------- *)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this entire section move to IntDiv or a related theory on modular arithmetic without the algebra?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am agree with you, I will do that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread theories/algebra/Pocklington.ec Outdated

hint simplify powmod0, powmodS.

(* -------------------------------------------------------------------- *)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, does this belong in IntDiv?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps all of the generic, but computable stuff should be in a ComputableIntDiv theory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I think the best solution is to add reduction lemma in database that can be used when needed.

…y certificates

IntDiv: a ^ k mod d (modzXm), the multiplicative order of a modulo n
(mulorder), existence of a prime divisor (pdivP) and the sqrt bound for
composites (primePns). Reduction rules for computing, kept out of the
default database: modular exponentiation by squaring (powmod0, powmodE)
in the hint database powmod, and Euclid's algorithm (gcdE) in the hint
database gcd; use them with cbv delta hint +powmod +gcd.

Pocklington: Pocklington's criterion (after coqprime) and a checker for
certificates (list of prime factors of N - 1 with witnesses), sound by
pock_certif and evaluated by cbv.
@bgregoir bgregoir changed the title Pocklington primality certificates; 2^130 - 5 is prime Pocklington primality certificates Nov 10, 2026
@bgregoir
bgregoir changed the base branch from main to zmodp-subst November 10, 2026 19:50
@bgregoir
bgregoir marked this pull request as ready for review November 11, 2026 05:20
@bgregoir bgregoir closed this Nov 11, 2026
@bgregoir bgregoir reopened this Nov 11, 2026
@fdupress
fdupress added this pull request to stack #1239 November 11, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants