Repository navigation
feat: add PowIdentity typeclass for grind ring solver - #13086
Merged
Merged
Conversation
This PR adds a `PowIdentity` typeclass stating `x ^ p = x` for all elements. The primary source of instances is Fermat's little theorem for finite fields. The `grind` ring solver will use this to add `x ^ p - x = 0` to the Groebner basis, reducing high-degree polynomials. The exponent `p` is an `outParam`, allowing instance synthesis to discover it automatically. Includes an instance for `Fin 2` proving `x ^ 2 = x`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This was referenced Mar 24, 2026
Collaborator
|
Reference manual CI status:
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Mar 24, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Mar 24, 2026
Collaborator
Author
|
The Mathlib instance for general finite fields has been added on leanprover-community/mathlib4-nightly-testing@lean-pr-testing-13086 In open Lean in
instance instGrindPowIdentity : Grind.PowIdentity K (Fintype.card K) where
pow_eq := pow_cardNo conversion needed — Grind's |
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Apr 8, 2026
This PR wires the `PowIdentity` typeclass (from #13086) into the `grind` ring solver's Groebner basis engine. When a ring has a `PowIdentity α p` instance, the solver pushes `x ^ p = x` as a new fact for each variable `x`, which becomes `x^p - x = 0` in the Groebner basis. Since `p` is an `outParam`, instance discovery is decoupled from `IsCharP` — the solver synthesizes `PowIdentity α ?p` with a fresh metavar and lets instance search find both the instance and the exponent. This correctly handles non-prime finite fields: for `F_4` (char 2, 4 elements), Mathlib would provide `PowIdentity F_4 4` and the solver would discover `p = 4`, not `p = 2`. Note: the original motivating example `(x + y)^2 = x^128 + y^2` from #12842 does not yet work because the `ToInt` module lifts `Fin 2` expressions to integers and expands `x^128` via the binomial theorem before the ring solver can reduce it. Addressing that is a separate deeper change. 🤖 Prepared with Claude Code --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 10, 2026
…#13086) This PR adds a `Lean.Grind.PowIdentity` typeclass stating that `x ^ p = x` for all elements of a commutative semiring, with `p` as an `outParam`. The primary source of instances is Fermat's little theorem: for a finite field with `q` elements, `x ^ q = x`. Since `p` is an `outParam`, instance synthesis discovers the correct exponent automatically — the solver does not need to know the characteristic or cardinality in advance. A concrete instance for `Fin 2` is provided. Mathlib can provide instances for general finite fields via `FiniteField.pow_card`. 🤖 Prepared with Claude Code Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 10, 2026
This PR wires the `PowIdentity` typeclass (from leanprover#13086) into the `grind` ring solver's Groebner basis engine. When a ring has a `PowIdentity α p` instance, the solver pushes `x ^ p = x` as a new fact for each variable `x`, which becomes `x^p - x = 0` in the Groebner basis. Since `p` is an `outParam`, instance discovery is decoupled from `IsCharP` — the solver synthesizes `PowIdentity α ?p` with a fresh metavar and lets instance search find both the instance and the exponent. This correctly handles non-prime finite fields: for `F_4` (char 2, 4 elements), Mathlib would provide `PowIdentity F_4 4` and the solver would discover `p = 4`, not `p = 2`. Note: the original motivating example `(x + y)^2 = x^128 + y^2` from leanprover#12842 does not yet work because the `ToInt` module lifts `Fin 2` expressions to integers and expands `x^128` via the binomial theorem before the ring solver can reduce it. Addressing that is a separate deeper change. 🤖 Prepared with Claude Code --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 12, 2026
…#13086) This PR adds a `Lean.Grind.PowIdentity` typeclass stating that `x ^ p = x` for all elements of a commutative semiring, with `p` as an `outParam`. The primary source of instances is Fermat's little theorem: for a finite field with `q` elements, `x ^ q = x`. Since `p` is an `outParam`, instance synthesis discovers the correct exponent automatically — the solver does not need to know the characteristic or cardinality in advance. A concrete instance for `Fin 2` is provided. Mathlib can provide instances for general finite fields via `FiniteField.pow_card`. 🤖 Prepared with Claude Code Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 12, 2026
This PR wires the `PowIdentity` typeclass (from leanprover#13086) into the `grind` ring solver's Groebner basis engine. When a ring has a `PowIdentity α p` instance, the solver pushes `x ^ p = x` as a new fact for each variable `x`, which becomes `x^p - x = 0` in the Groebner basis. Since `p` is an `outParam`, instance discovery is decoupled from `IsCharP` — the solver synthesizes `PowIdentity α ?p` with a fresh metavar and lets instance search find both the instance and the exponent. This correctly handles non-prime finite fields: for `F_4` (char 2, 4 elements), Mathlib would provide `PowIdentity F_4 4` and the solver would discover `p = 4`, not `p = 2`. Note: the original motivating example `(x + y)^2 = x^128 + y^2` from leanprover#12842 does not yet work because the `ToInt` module lifts `Fin 2` expressions to integers and expands `x^128` via the binomial theorem before the ring solver can reduce it. Addressing that is a separate deeper change. 🤖 Prepared with Claude Code --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
This PR adds a `Lean.Grind.PowIdentity` typeclass stating that `x ^ p = x` for all elements of a commutative semiring, with `p` as an `outParam`. The primary source of instances is Fermat's little theorem: for a finite field with `q` elements, `x ^ q = x`. Since `p` is an `outParam`, instance synthesis discovers the correct exponent automatically — the solver does not need to know the characteristic or cardinality in advance. A concrete instance for `Fin 2` is provided. Mathlib can provide instances for general finite fields via `FiniteField.pow_card`. 🤖 Prepared with Claude Code Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
This PR wires the `PowIdentity` typeclass (from #13086) into the `grind` ring solver's Groebner basis engine. When a ring has a `PowIdentity α p` instance, the solver pushes `x ^ p = x` as a new fact for each variable `x`, which becomes `x^p - x = 0` in the Groebner basis. Since `p` is an `outParam`, instance discovery is decoupled from `IsCharP` — the solver synthesizes `PowIdentity α ?p` with a fresh metavar and lets instance search find both the instance and the exponent. This correctly handles non-prime finite fields: for `F_4` (char 2, 4 elements), Mathlib would provide `PowIdentity F_4 4` and the solver would discover `p = 4`, not `p = 2`. Note: the original motivating example `(x + y)^2 = x^128 + y^2` from #12842 does not yet work because the `ToInt` module lifts `Fin 2` expressions to integers and expands `x^128` via the binomial theorem before the ring solver can reduce it. Addressing that is a separate deeper change. 🤖 Prepared with Claude Code --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
kim-em
added a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 4, 2026
* Update lean-toolchain for testing leanprover/lean4#13086 * feat: add `Lean.Grind.PowIdentity` instance for finite fields This provides a `PowIdentity K (Fintype.card K)` instance for any finite field, based on `FiniteField.pow_card` (Fermat's little theorem). This allows the `grind` ring solver to reduce high-degree polynomials over finite fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * Update lean-toolchain for testing leanprover/lean4#13132 * Update lean-toolchain for leanprover/lean4#13132 * Update lean-toolchain for leanprover/lean4#13132 * Update lean-toolchain for testing leanprover/lean4#13223 * Update lean-toolchain for testing leanprover/lean4#13229 * chore: indent tactic blocks after `by` and `decreasing_by` Adapt to leanprover/lean4#13217 which requires indented tactic sequences after `by` and `decreasing_by`. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent tactic block in EmptyLine test Adapt to leanprover/lean4#13217. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent expression continuations at column 0 Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent expression continuations at column 0 Co-Authored-By: Claude Opus 4.6 <[email protected]> * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13223 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13223 * chore: fix linter tests * lake update * fix hash command linter * fix bad merge * fixes * fixes * unpleasant fix. * touch for CI * cleanup of adaptation notes * chore: adaptations for nightly-2026-04-06 * chore: bump to nightly-2026-04-07 * chore: adaptations for nightly-2026-04-07 * chore: bump to nightly-2026-04-08 * Update lean-toolchain for testing leanprover/lean4#13262 * Update lean-toolchain for leanprover/lean4#13262 * universe fixes * chore: bump to nightly-2026-04-09 * Update lean-toolchain for testing leanprover/lean4#13346 * Update lean-toolchain for leanprover/lean4#13346 * lake update * fixes * fix tests * ci: skip inputRev validation on nightly-testing branch Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * chore: bump to nightly-2026-04-10 * fix * chore(nolints): add docBlame exceptions for auto-generated `instInhabited.default` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(lint-style): filter out duplicate `Init` from `Mathlib.lean` imports `Lean.parseImports'` now emits `Init` more than once for module-system files such as `Mathlib.lean`, but `findImportsFromSource` (in importGraph) only `.erase`s the first occurrence. The remaining `Init` was treated as a module to lint, producing `uncaught exception: no such file or directory ... file: Init.lean` and breaking the `lint-style` CI job on `nightly-testing`. Defensively filter out any remaining `Init` after `findImportsFromSource`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix * fix plausible * Update lean-toolchain for leanprover/lean4#13346 * chore: update importGraph, remove duplicate Init workaround Updates importGraph to pick up leanprover-community/import-graph#115, which fixes `findImportsFromSource` to filter (not just erase) `Init`. This removes the need for the defensive `.filter (· != `Init)` we added to `lint-style.lean`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * chore: bump to nightly-2026-04-11 * silence linter * broken test: still broken, but doesn't stop the build. * fix: exempt files registering initializers from the `privateModule` linter * Revert "silence linter" This reverts commit 8da25c3. * chore: remove unused sections in front of lone `declare_aesop_rule_sets` * chore: restore `initialize` test for `privateModule` linter with correct wording * chore: restore `privateModule` `initialize` test with linter turned on * fixes * fix from nightly-testing * importGraph has been fixed * chore: bump to nightly-2026-04-13 * Update lean-toolchain for testing leanprover/lean4#13325 * Update lean-toolchain for leanprover/lean4#13325 * chore: silence simp `varHead` and `varOther` warnings * chore: silence `varHead` warning * chore: fix `globalAtrtributeIn` test * chore: fix `Archive` build * Update lean-toolchain for leanprover/lean4#13325 * Update lean-toolchain for leanprover/lean4#13325 * fix from nightly-testing * chore: bump to nightly-2026-04-14 * chore: bump to nightly-2026-04-15 * adapt to lean4#13363: canUnfoldAtMatcher allowlist changes Adapt proofs to lean4#13363 which replaces the transparency bump from `.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist in `canUnfoldAtMatcher`. Class projections that were previously unfolded automatically in match discriminants now need explicit unfolding. * fix lint errors from lean4#13363 adaptation - Add doc string to `WithZero.withZeroSup` - Add `nolint simpNF` to auto-generated equation lemmas for `RegularExpression.matches'` and `RegularExpression.map` - Add `nolint simpNF` to `orderLHom_leSymb` * fixes * fix * fixes * chore: bump to nightly-2026-04-16 * fix tests * fix upstreamed import * chore: bump to nightly-2026-04-17 * set_option * Update lean-toolchain for testing leanprover/lean4#13441 * chore: adaptations for leanprover/lean4#13389 * fixes * fixes * fixes * fix Init filter in MinImports * fix test * add set_options * chore: bump to nightly-2026-04-19 * chore: bump to nightly-2026-04-20 * fix bad merge * fix #guard_msgs output * chore: bump to nightly-2026-04-22 * chore: bump to nightly-2026-04-23 * cleanup * revert an unnecessary change * revert unnecessary changes * add adaptation notes * minor fixes, whitespace and PR links * two improvements * improvements * slightly improve the proof in Limits/Shapes/Equalizers.lean * More * chore: bump to nightly-2026-04-24 * adapt to lean4#13363: canUnfoldAtMatcher allowlist changes Adapt proofs to lean4#13363 which replaces the transparency bump from `.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist in `canUnfoldAtMatcher`. Class projections like `CategoryStruct.comp`, `CategoryStruct.id`, `Stream.next?`, `Min.min` etc. are no longer auto-unfolded in match discriminants and need explicit unfolding in proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: remove unused helper lemmas from Ordinal/Notation adaptation Remove `zero_zero_eq`, `one_one_eq`, `repr_zero'`, and `ofNat_unfold` which were added during the lean4#13363 adaptation but are not used in any proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Update lean-toolchain for leanprover/lean4#13363 * adapt Limits/Shapes/ConcreteCategory to lean4#13363 Use `WalkingMulticospan.Hom.id_eq_id` and `Functor.map_id` to reduce stuck matches on `𝟙` in WalkingMulticospan naturality proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Bump batteries * Update lean-toolchain for leanprover/lean4#13363 * chore: bump to nightly-2026-04-25 * satisfy linter * chore: bump to nightly-2026-04-27 * Apply suggestion from @kim-em * Apply suggestion from @kim-em --------- Co-authored-by: leanprover-community-mathlib4-bot <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: Joachim Breitner <[email protected]> Co-authored-by: Wojciech Rozowski <[email protected]> Co-authored-by: mathlib-nightly-testing[bot] <mathlib-nightly-testing[bot]@users.noreply.github.com> Co-authored-by: mathlib4-bot <[email protected]> Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Sebastian Ullrich <[email protected]> Co-authored-by: thorimur <[email protected]> Co-authored-by: Julia Markus Himmel <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a
Lean.Grind.PowIdentitytypeclass stating thatx ^ p = xfor all elements of a commutative semiring, withpas anoutParam.The primary source of instances is Fermat's little theorem: for a finite field with
qelements,x ^ q = x. Sincepis anoutParam, instance synthesis discovers the correct exponent automatically — the solver does not need to know the characteristic or cardinality in advance.A concrete instance for
Fin 2is provided. Mathlib can provide instances for general finite fields viaFiniteField.pow_card.🤖 Prepared with Claude Code