Skip to content

feat: detect and special case XORs when lowering AIG to CNF#13946

Open
georgerennie wants to merge 4 commits into
leanprover:masterfrom
georgerennie:george/xor_cnf
Open

feat: detect and special case XORs when lowering AIG to CNF#13946
georgerennie wants to merge 4 commits into
leanprover:masterfrom
georgerennie:george/xor_cnf

Conversation

@georgerennie
Copy link
Copy Markdown
Contributor

This PR adds detection and optimized lowering of XOR/XNOR gates to bv_decide's AIG to CNF lowering. It adds a function Std.Sat.AIG.detectXOR that detects XOR gates of the form ¬(a ∧ b) ∧ ¬(¬a ∧ ¬b) up to permutation of inputs and negation of inputs/output. When the CNF lowering lowers a gate, it first uses detectXor to see if it can be lowered as an XOR, and if so uses a 4 clause encoding instead of the 12 used by lowering as AND gates.

This PR adds detection and optimized lowering of XOR/XNOR gates to
`bv_decide`'s AIG to CNF lowering. This adds a function
`Std.Sat.AIG.detectXOR` that detects XOR gates of the form
`¬(a ∧ b) ∧ ¬(¬a ∧ ¬b)` up to permutation of inputs and negation of
inputs/output. When the CNF lowering lowers a gate, it first uses
`detectXor` to see if it can be lowered as an XOR, and if so uses a
4 clause description instead of the 12 used by lowering as AND gates.
@georgerennie georgerennie requested a review from hargoniX as a code owner June 3, 2026 19:00
@[expose] public section

/-!
This module contains functions to detect compound logic gates represented by sub-graphs of the `AIG`.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure whether this should really be its own file but it felt like something that might be useful for other optimizations. Subsequently we can add the same for ITE detection here.

@georgerennie
Copy link
Copy Markdown
Contributor Author

changelog-tactics

@github-actions github-actions Bot added the changelog-tactics User facing tactics label Jun 3, 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 Jun 3, 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 9820f61873fc94ae9fc94b8e23a02336a8741f09 --onto c47a0c7cf035381a2bcdd4cdf2442782eb4a5214. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-03 20:13: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 9820f61873fc94ae9fc94b8e23a02336a8741f09 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-03 20:13:49)

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