Skip to content

feat: make Bool.xor a standalone definition#13995

Draft
wrenna-robson wants to merge 6 commits into
leanprover:masterfrom
wrenna-robson:xor_semireducible
Draft

feat: make Bool.xor a standalone definition#13995
wrenna-robson wants to merge 6 commits into
leanprover:masterfrom
wrenna-robson:xor_semireducible

Conversation

@wrenna-robson

Copy link
Copy Markdown
Contributor

This PR makes Bool.xor a standalone definition instead of a reducible abbreviation for bne, so that simp and grind treat exclusive-or as an operation in its own right rather than unfolding it away. It adds dedicated xor simp lemmas and grind propagators, giving predictable xor-shaped normal forms and letting grind close goals involving ^^ that previously needed manual rewriting through bne.

Bool.xor is now defined by a branching match on its first argument, with the definition and ^^ notation living in Init.Prelude and Init.Notation. The xor lemmas in Init.Data.Bool are restated directly in terms of xor rather than as bne wrappers; new simp normal-form lemmas and Std.Commutative, Std.Associative, and Std.LawfulIdentity instances are added; and grind propagators for Bool.xor are registered, with supporting lemmas in Init.Grind.Lemmas. The BitVec bitblasting and Std.Sat AIG code is adapted to the new normal forms.

This implements RFC #13994.

AI disclosure: the grind propagators (propagateBoolXorUp/propagateBoolXorDown in Lean.Meta.Tactic.Grind.Propagate) and their supporting lemmas in Init.Grind.Lemmas were authored by Claude (Claude Code) and reviewed by me; the Bool.xor definition change and the simp lemma set are my own work.

wrenna-robson and others added 5 commits June 10, 2026 14:19
Previously `Bool.xor` was an `abbrev` for `bne`. Make it a semireducible def with its own simp lemma set (early lemmas in SimpLemmas, the rest in Bool). Move the `^^` notation and definition to Prelude, and fix the `or` recommended_spelling target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Use the `xor_*` lemmas (`xor_false`, `xor_left_inj`, `xor_assoc`, …) where proofs previously relied on `xor` being defeq to `bne`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
xor is now opaque; dedicated grind propagators will replace the unfold.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Make `Bool.xor` `@[inline]` and define it with a direct `match`, trim its docstring, and drop the now-redundant re-exports. Round out the xor/bne simp normal forms: `@[simp]` on `xor_eq_false_iff` and new `eq_not_self_*`/`eq_not_*_self` lemmas, with matching `bool_simp` coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add `propagateBoolXorUp`/`propagateBoolXorDown` so `grind` reasons about `Bool.xor` directly on the Bool equivalence graph, rather than relying on it being unfolded to `bne`. Propagates truth values from either argument, and the `a ≡ b ⟹ false` / `a ≠ b ⟹ true` equivalence facts in both directions, with supporting lemmas in `Init.Grind.Lemmas`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wrenna-robson

Copy link
Copy Markdown
Contributor Author

Opening this as a draft for visibility alongside RFC #13994. I'd like to hold it for review until the RFC has had feedback, since the design decision — in particular the change to the simp normal form for exclusive-or — is what I'm seeking comment on there.

@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 Jun 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 ab9722836dea9e2f5ca3157f14cc1460454b3a67 --onto 2e72131c7f007ab9d2538b676106c5141b24ba22. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-23 09:41:47)

@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 ab9722836dea9e2f5ca3157f14cc1460454b3a67 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-23 09:41:48)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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