Skip to content

Xor decomp simpl#908

Merged
tias merged 5 commits into
masterfrom
xor_decomp_simpl
Apr 21, 2026
Merged

Xor decomp simpl#908
tias merged 5 commits into
masterfrom
xor_decomp_simpl

Conversation

@tias

@tias tias commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

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

@IgnaceBleukx IgnaceBleukx left a comment

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.

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

Comment thread tests/test_globalconstraints.py
Comment thread cpmpy/expressions/globalconstraints.py Outdated
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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, changed it to search for variables first.

Note that in the .negate(), I don't think we should be calling recurse_negate? I'm not actually sure where the negate pipeline comes from... I've removed the recurse_negate in it

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 think it came from when we weren't sure where to put negation either... Meanwhile I'm convinced it should go before decompose (currently it's right before flattening); so then globals cannot introduce negation anymore.

@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

@tias tias mentioned this pull request Apr 7, 2026
@IgnaceBleukx IgnaceBleukx self-requested a review April 13, 2026 11:50

@IgnaceBleukx IgnaceBleukx left a comment

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.

Looks good, and fixes some open issues indeed.

From what I can see it closes #747

Does not fix #827 #620 it seems, they are also XOR-decomp related, but can probably also be reproduced without xor...

Good to go in for me!

Comment thread cpmpy/expressions/globalconstraints.py
@tias

tias commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator Author

#827, #620, have not looked in detail but it all seems to boil down to the same thing: how to handle constants (e.g. in decompose).

Its revealed in #929 that we should make sure our decomps only return Expressions, which I think would fix these issues.

That is/can be done as part of our typing effort #913

@tias tias merged commit 721ad39 into master Apr 21, 2026
10 checks passed
@tias tias deleted the xor_decomp_simpl branch April 21, 2026 15:30
@tias tias mentioned this pull request Apr 21, 2026
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

3 participants