Skip to content

feat: make Bool.xor a standalone definition#13995

Draft
linesthatinterlace wants to merge 5 commits into
leanprover:masterfrom
linesthatinterlace:xor_semireducible
Draft

feat: make Bool.xor a standalone definition#13995
linesthatinterlace wants to merge 5 commits into
leanprover:masterfrom
linesthatinterlace:xor_semireducible

Conversation

@linesthatinterlace

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.

linesthatinterlace 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>
@linesthatinterlace

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant