Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
pattern in `CompPoly/Fields/Binary/BF128Ghash/Prelude.lean`.
- If `decide` is too slow, restructure the proposition, for example by batching
checks into a single conjunction, rather than reaching for `native_decide`.
- Apply a Rabin criterion at exactly the carrier and instances its certificate lemmas
use (`ZMod p`, `ZMod.instField p`, `ZMod.fintype p`), as one term. `lake build` is not a

Check warning on line 139 in AGENTS.md

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 27 words. Consider a split if it improves clarity. 'lake build` is not a reliable check: inside a `module`, unexposed Mathlib bodies'
reliable check: inside a `module`, unexposed Mathlib bodies such as `Polynomial.instAdd`
are opaque, so a mismatch may only appear in a full-closure replay.
- Keep concrete certificate proofs free of rewrite transports. A criterion that
depends on a field size takes it as a numeral `q` with `hcard : Fintype.card F = q`,
and it substitutes `q` internally. A concrete caller then states its conditions at
Expand Down
14 changes: 8 additions & 6 deletions CompPoly/Data/Polynomial/Rabin.lean
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@
no numeral in hand passes `rfl` and gets the `Fintype.card F` statement back verbatim.

The alternative — stating the conditions at `Fintype.card F` and having concrete callers cast each
one with `rw [hcard]` — is what this shape exists to rule out. Such a cast leaves an `Eq.mpr`

Check warning on line 97 in CompPoly/Data/Polynomial/Rabin.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing W6

Consider a direct verb if it preserves this meaning. 'rule out'

Check warning on line 97 in CompPoly/Data/Polynomial/Rabin.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 44 words. Consider a split if it improves clarity. 'Such a cast leaves an `Eq.mpr` transport around a certificate argument whose typ'
transport around a certificate argument whose type carries a huge exponent (`X ^ (q ^ d)`), and a
kernel replay from an empty environment need not follow the same normalization path the elaborator
took: one such transport has been observed to send the kernel into
`Polynomial.pow → npowRec → Nat.rec`, unfolding the power one exponent step at a time until the
deep-recursion guard fired. Since there is only one form of each statement, that cast has no
occasion to appear. `docs/wiki/field-extensions.md` records the history, and
transport around a certificate argument whose type carries a huge exponent (`X ^ (q ^ d)`): one
such transport has been observed to send the kernel into `Polynomial.pow → npowRec → Nat.rec`,
unfolding the power one exponent step at a time until the deep-recursion guard fired. Compiling the

Check warning on line 100 in CompPoly/Data/Polynomial/Rabin.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 47 words. Consider a split if it improves clarity. 'Compiling the defining module is not evidence against this -- inside a `module`,'
defining module is not evidence against this -- inside a `module`, imported definitions that are
not `@[expose]`d have no body for the kernel, Mathlib's `Polynomial.instAdd` among them, so the
slow path does not exist there, while a full-closure replay sees every body and takes it. Since
there is only one form of each statement, that cast has no occasion to appear.
`docs/wiki/field-extensions.md` records the history, and
`CompPoly/Data/Polynomial/RabinCertificate.lean` packages these tests at concrete degrees.
-/

Expand Down
20 changes: 12 additions & 8 deletions CompPoly/Fields/KoalaBear/Ext5/QuinticIrreducible.lean
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ theorem quintic_bezout_check :
= true := by rfl

/-- **`X^5 + X^2 - 1` is irreducible over KoalaBear**, by Rabin's test at prime degree with
kernel-checked certificates for both conditions. -/
theorem quinticPoly_irreducible : Irreducible quinticPoly := by
have hcard : Fintype.card Field = fieldSize := ZMod.card _
refine irreducible_of_rabin_prime_degree hcard (by norm_num) quinticPoly_natDegree ?_ ?_
· exact dvd_X_pow_sub_X_of_runChain toPoly_quinticL quinticPoly_ne_zero
quintic_trace_chain quintic_trace_exp
· exact isCoprime_X_pow_sub_X_of_runChain toPoly_quinticL quinticPoly_ne_zero
quintic_frob_chain quintic_frob_exp quintic_w_check quintic_bezout_check
kernel-checked certificates for both conditions.

Applied as one term at `ZMod fieldSize` with `ZMod.instField fieldSize`; see
`sexticPoly_irreducible` for why both are required and why the explicit `@` form must stay. -/
theorem quinticPoly_irreducible : Irreducible quinticPoly :=
@irreducible_of_rabin_prime_degree (ZMod fieldSize) (ZMod.instField fieldSize)
(ZMod.fintype fieldSize) quinticPoly 5 fieldSize (ZMod.card _) (by norm_num)
quinticPoly_natDegree
(dvd_X_pow_sub_X_of_runChain toPoly_quinticL quinticPoly_ne_zero
quintic_trace_chain quintic_trace_exp)
(isCoprime_X_pow_sub_X_of_runChain toPoly_quinticL quinticPoly_ne_zero
quintic_frob_chain quintic_frob_exp quintic_w_check quintic_bezout_check)

instance : Fact (Irreducible quinticPoly) := ⟨quinticPoly_irreducible⟩

Expand Down
36 changes: 26 additions & 10 deletions CompPoly/Fields/KoalaBear/Ext6/SexticIrreducible.lean
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,32 @@
= true := by rfl

/-- **`X^6 + X^3 + 1` is irreducible over KoalaBear**, by Rabin's test at a degree with two prime
factors, with kernel-checked certificates for all three conditions. -/
theorem sexticPoly_irreducible : Irreducible sexticPoly := by
have hcard : Fintype.card Field = fieldSize := ZMod.card _
refine irreducible_of_rabin_degree_six hcard sexticPoly_natDegree ?_ ?_ ?_
· exact dvd_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_trace_chain sextic_trace_exp
· exact isCoprime_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_cop3_chain sextic_cop3_exp sextic_cop3_w_check sextic_cop3_bezout_check
· exact isCoprime_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_cop2_chain sextic_cop2_exp sextic_cop2_w_check sextic_cop2_bezout_check
factors, with kernel-checked certificates for all three conditions.

Applied as one term at exactly the carrier and instances the certificate lemmas use:
`ZMod fieldSize`, `ZMod.instField fieldSize` and `ZMod.fintype fieldSize`. The carrier and the
instance are both required. With `KoalaBear.Field` in place of `ZMod fieldSize`, or with

Check warning on line 142 in CompPoly/Fields/KoalaBear/Ext6/SexticIrreducible.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 27 words. Consider a split if it improves clarity. 'With `KoalaBear.Field` in place of `ZMod fieldSize`, or with `instFieldField` (o'
`instFieldField` (or any synthesized instance, as `(F := ZMod fieldSize)` gives) in place of
`ZMod.instField fieldSize`, the kernel unfolds `X ^ (fieldSize ^ 6) - X` into
`Polynomial.pow → npowRec`, and a full-closure replay hits deep recursion.

Whether `lake build` catches that depends on the recursion budget in scope, so it cannot be relied

Check warning on line 147 in CompPoly/Fields/KoalaBear/Ext6/SexticIrreducible.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 41 words. Consider a split if it improves clarity. 'Whether `lake build` catches that depends on the recursion budget in scope, so i'
on: at the default `maxRecDepth` the mismatched spellings fail to elaborate, but with a raised
limit they compile and only a full replay rejects them. The reason this module can accept what a

Check warning on line 149 in CompPoly/Fields/KoalaBear/Ext6/SexticIrreducible.lean

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 42 words. Consider a split if it improves clarity. 'The reason this module can accept what a replay refuses is exposure, not nondete'
replay refuses is exposure, not nondeterminism -- inside a `module`, imported definitions that are
not `@[expose]`d have no body for the kernel, Mathlib's `Polynomial.instAdd` among them, so the
slow path does not exist here. A full-closure replay sees every body.

Keep the explicit `@` application. -/
theorem sexticPoly_irreducible : Irreducible sexticPoly :=
@irreducible_of_rabin_degree_six (ZMod fieldSize) (ZMod.instField fieldSize)
(ZMod.fintype fieldSize) sexticPoly fieldSize (ZMod.card _) sexticPoly_natDegree
(dvd_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_trace_chain sextic_trace_exp)
(isCoprime_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_cop3_chain sextic_cop3_exp sextic_cop3_w_check sextic_cop3_bezout_check)
(isCoprime_X_pow_sub_X_of_runChain toPoly_sexticL sexticPoly_ne_zero
sextic_cop2_chain sextic_cop2_exp sextic_cop2_w_check sextic_cop2_bezout_check)

instance : Fact (Irreducible sexticPoly) := ⟨sexticPoly_irreducible⟩

Expand Down
19 changes: 12 additions & 7 deletions docs/wiki/field-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,14 @@
`q`-parameterized statement is the same theorem, universally quantified over the spelling of the
size, so nothing is lost; `Extension/Binomial.lean` calls the Rabin layer exactly this way.

**Why there is no `Fintype.card F`-only variant.** Such a variant forces a concrete caller to cast

Check warning on line 284 in docs/wiki/field-extensions.md

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 55 words. Consider a split if it improves clarity. 'Such a variant forces a concrete caller to cast each condition with `rw [hcard]`'
each condition with `rw [hcard]`, which leaves an `Eq.mpr` transport wrapped around a certificate
whose type carries a huge exponent (`X ^ (fieldSize ^ 6)`). A kernel replay from an empty
environment checks a serialized and reconstructed expression graph and need not follow the
normalization path that checking the elaborator's in-memory term took; one such transport has been
observed to send the kernel into `Polynomial.pow → npowRec → Nat.rec`, unfolding the power one
exponent step at a time until the deep-recursion guard fired. With a single
whose type carries a huge exponent (`X ^ (fieldSize ^ 6)`); one such transport has been observed
to send the kernel into `Polynomial.pow → npowRec → Nat.rec`, unfolding the power one exponent
step at a time until the deep-recursion guard fired. Such a defect can survive `lake build`:

Check warning on line 288 in docs/wiki/field-extensions.md

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 50 words. Consider a split if it improves clarity. 'Such a defect can survive `lake build`: inside a `module`, imported definitions '
inside a `module`, imported definitions that are not `@[expose]`d have no body for the kernel --
Mathlib's `Polynomial.instAdd` among them -- so the slow path does not exist while the defining
module is compiled, and only a full-closure replay, which sees every body, takes it. With a single

Check warning on line 291 in docs/wiki/field-extensions.md

View workflow job for this annotation

GitHub Actions / Check Writing (warnings only)

Writing S1

This sentence has about 31 words. Consider a split if it improves clarity. 'With a single numeral-parameterized form, that cast has no occasion to appear — '
numeral-parameterized form, that cast has no occasion to appear — for us, or for a downstream
author writing their own extension, who is covered by no linter of ours.

Expand Down Expand Up @@ -375,8 +376,12 @@
chain checks (`decide +kernel`), the Bézout checks (`rfl`), and the assembly through
`irreducible_of_rabin_prime_degree` (prime `d`, see
`KoalaBear/Ext5/QuinticIrreducible.lean`) or `irreducible_of_rabin_degree_six`
(composite `d`, see `KoalaBear/Ext6/SexticIrreducible.lean`), passing
`hcard : Fintype.card Field = fieldSize := ZMod.card _`. At another composite `d`, use
(composite `d`, see `KoalaBear/Ext6/SexticIrreducible.lean`). Assemble with one
term-mode application whose carrier and instances are exactly those of the certificate
lemmas, e.g.
`@irreducible_of_rabin_degree_six (ZMod fieldSize) (ZMod.instField fieldSize) (ZMod.fintype fieldSize) f fieldSize (ZMod.card _) …`.
Do not `refine` against a goal stated over the field's `abbrev` (`KoalaBear.Field`), and do
not respell it with named arguments: either builds, and a full-closure replay does not. At another composite `d`, use
`irreducible_of_rabin_prime_power` when `d = ℓ ^ k` — as `BF64.basePoly_irreducible`
does at `d = 64` — `irreducible_of_rabin_two_prime_factors` at two distinct prime
factors, or `Polynomial.irreducible_of_rabin` beyond that. Each condition then applies
Expand Down
Loading