feat: add permutation theorem support to Sym.simp#13046
Merged
leodemoura merged 2 commits intomasterfrom Mar 23, 2026
Merged
Conversation
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>
79de8eb to
be9d264
Compare
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>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
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 prevents
Sym.simpfrom looping on permutation theorems like∀ x y, x + y = y + x.perm : Boolfield toTheoremisPermthat checks if LHS and RHS have the same structure withpattern variables (de Bruijn indices) rearranged via a consistent
bijection. Uses
ReaderT(offset for binder entry),StateT(forward/backward maps),
ExceptT(failure).perminmkTheoremFromDecl/mkTheoremFromExprTheorem.rewrite, whenpermis true, only apply the rewrite ifthe result is strictly less than the input (using
acLt)add_comm,add_assoc,add_left_comm