Skip to content

Xor decomp simpl#908

Open
tias wants to merge 2 commits intomasterfrom
xor_decomp_simpl
Open

Xor decomp simpl#908
tias wants to merge 2 commits intomasterfrom
xor_decomp_simpl

Conversation

@tias
Copy link
Copy Markdown
Collaborator

@tias tias commented Apr 4, 2026

reactived by #906

closes #747

not sure what should now remain of #778

also leaves open that a user 'could' write BoolVal + BoolVal == 1, and that linearize would choke on this, somewhere...

it looks like we already had all the right tests, just not run for all solvers yet

@tias tias requested a review from IgnaceBleukx April 4, 2026 08:42
Copy link
Copy Markdown
Collaborator

@IgnaceBleukx IgnaceBleukx left a comment

Choose a reason for hiding this comment

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

Yes, this decomposition is much cleaner and clearer than before.
One comment about negation, otherwise good to go

assert cp.Xor(bv).value()

def test_xor_with_constants(self):
def test_xor_with_constants(self, solver):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought you had to use the pytest fixture for this to work?

if len(new_args) == 0:
return [BoolVal(parity)], []
if parity: # negate last argument
new_args[-1] = ~new_args[-1]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens if new_args[-1] is an expression? Then it will introduce a complex negation, right?
Ideally, we want to negate a variable here (see the .negate() of xor).

If there is no variable in any of the args, we can indeed negate this one, but we'll have to run push_down_negation again once we move that transformation before decompose (which I currently have in a local branch)

@IgnaceBleukx
Copy link
Copy Markdown
Collaborator

not sure what should now remain of #778

#778 introduces proper bound computation for Comparisons too. I think that is something we want, but defineatly not urgent to add

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.

Decompose before simplify_boolean for Xor

2 participants