feat: wire PowIdentity into grind ring solver#13088
Open
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) <noreply@anthropic.com>
This commit wires the `PowIdentity` typeclass into the `grind` ring solver's Groebner basis engine. Instance discovery is decoupled from `IsCharP` — the solver synthesizes `PowIdentity α ?p` with a fresh metavar for `p`, so it works for any type with a `PowIdentity` instance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Move grind_pow_identity test from removed tests/lean/run/ to tests/elab/ and add missing PowIdentity trace lines to grind_ring_1 guard_msgs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a comment explaining why getPowIdentityInst? uses a fresh metavar for CommSemiring rather than passing the ring solver's commSemiringInst (as getIsCharInst? does with semiringInst). PowIdentity instances are declared against the canonical CommSemiring, which may not be definitionally equal to CommRing.toCommSemiring. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 wires the
PowIdentitytypeclass (from #13086) into thegrindring solver's Groebner basis engine.When a ring has a
PowIdentity α pinstance, the solver pushesx ^ p = xas a new fact for each variablex, which becomesx^p - x = 0in the Groebner basis. Sincepis anoutParam, instance discovery is decoupled fromIsCharP— the solver synthesizesPowIdentity α ?pwith 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 providePowIdentity F_4 4and the solver would discoverp = 4, notp = 2.Note: the original motivating example
(x + y)^2 = x^128 + y^2from #12842 does not yet work because theToIntmodule liftsFin 2expressions to integers and expandsx^128via the binomial theorem before the ring solver can reduce it. Addressing that is a separate deeper change.🤖 Prepared with Claude Code