Skip to content

feat: add permutation theorem support to Sym.simp#13046

Merged
leodemoura merged 2 commits intomasterfrom
lean-sym-interactive-10
Mar 23, 2026
Merged

feat: add permutation theorem support to Sym.simp#13046
leodemoura merged 2 commits intomasterfrom
lean-sym-interactive-10

Conversation

@leodemoura
Copy link
Copy Markdown
Member

This PR prevents Sym.simp from looping on permutation theorems like
∀ x y, x + y = y + x.

  • Add perm : Bool field to Theorem
  • Add isPerm that checks if LHS and RHS have the same structure with
    pattern variables (de Bruijn indices) rearranged via a consistent
    bijection. Uses ReaderT (offset for binder entry), StateT
    (forward/backward maps), ExceptT (failure).
  • Compute perm in mkTheoremFromDecl / mkTheoremFromExpr
  • In Theorem.rewrite, when perm is true, only apply the rewrite if
    the result is strictly less than the input (using acLt)
  • Tests include the classic AC normalization stress test with
    add_comm, add_assoc, add_left_comm

@leodemoura leodemoura added the changelog-tactics User facing tactics label Mar 22, 2026
@leodemoura leodemoura enabled auto-merge March 22, 2026 23:27
@leodemoura leodemoura disabled auto-merge March 22, 2026 23:30
This PR prevents `Sym.simp` from looping on permutation theorems like
`∀ x y, x + y = y + x`.

- Add `perm : Bool` field to `Theorem`
- Add `isPerm` that checks if LHS and RHS are the same structure with
  pattern variables (de Bruijn indices) rearranged via a consistent
  bijection. Uses `ReaderT` (offset), `StateT` (fwd/bwd maps),
  `ExceptT` (failure).
- Compute `perm` in `mkTheoremFromDecl` / `mkTheoremFromExpr`
- In `Theorem.rewrite`, when `perm` is true, only apply the rewrite if
  the result is strictly less than the input (using `acLt`)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leodemoura leodemoura force-pushed the lean-sym-interactive-10 branch from 79de8eb to be9d264 Compare March 22, 2026 23:34
@leodemoura leodemoura enabled auto-merge March 22, 2026 23:35
Replace `Nat.add_comm_of_pos` (a permutation theorem) with `f_idem`
(a non-perm conditional rewrite: `a > 0 → f (f a) = f a`).
Update all examples and expected trace output accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leodemoura leodemoura added this pull request to the merge queue Mar 23, 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 23, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase cffacf1b10db65a76be1f8e92bdc2e1f7d79def9 --onto 4bf7fa7447eea00cecba8327bb9c9e5f4485f0a7. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-23 00:26:17)

@leanprover-bot
Copy link
Copy Markdown
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 cffacf1b10db65a76be1f8e92bdc2e1f7d79def9 --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-23 00:26:19)

Merged via the queue into master with commit 9f4db47 Mar 23, 2026
15 checks passed
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