Skip to content

feat: wire PowIdentity into grind ring solver#13088

Open
kim-em wants to merge 4 commits intomasterfrom
kim/pow-identity
Open

feat: wire PowIdentity into grind ring solver#13088
kim-em wants to merge 4 commits intomasterfrom
kim/pow-identity

Conversation

@kim-em
Copy link
Collaborator

@kim-em kim-em commented Mar 24, 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

kim-em and others added 2 commits March 24, 2026 05:37
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>
@kim-em kim-em requested a review from leodemoura as a code owner March 24, 2026 06:02
@kim-em kim-em added the changelog-tactics User facing tactics label Mar 24, 2026
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Mar 24, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c381c62060ec407ec850dac9d6542156b0c24b7d --onto e6df474dd9c3ad0e21771eaa808c53f66222216d. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-24 06:52:14)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c381c62060ec407ec850dac9d6542156b0c24b7d --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-24 06:52:16)

kim-em and others added 2 commits March 24, 2026 09:17
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-tactics User facing tactics toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants