Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not operator #225

Merged
merged 27 commits into from
Apr 27, 2023
Merged

Not operator #225

merged 27 commits into from
Apr 27, 2023

Conversation

Wout4
Copy link
Collaborator

@Wout4 Wout4 commented Feb 13, 2023

No description provided.

@Wout4
Copy link
Collaborator Author

Wout4 commented Feb 13, 2023

Branches from someglobals

@JoD
Copy link
Collaborator

JoD commented Feb 14, 2023

It is hard to review when the diff also contains other MRs.

Thinking about how to resolve this...

Maybe:
If this MR needs the others, we need to get those in the master first.
If not, this MR needs to based on the master.

Copy link
Collaborator

@tias tias left a comment

Choose a reason for hiding this comment

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

also in line 517 of core.py, there is something weird...

we check that if 'x == 1' and x is_bool, then it is just 'x'. And because we overwrite 'eq' for this, we also need to overwrite hash, which is a bit ugly.

But we (I) implemented it rather inconsistently... we do not check for != 0, or that !=1 on bool would be == 0... or (after this commit) that ==0 should be ~x. I wonder though that may be we should leave it the way the user wrote it here, and leave it for 'normalize' to normalize these? (removing can be here, normalizing would be in a separate commit ; )

cpmpy/expressions/core.py Outdated Show resolved Hide resolved
cpmpy/expressions/core.py Outdated Show resolved Hide resolved
cpmpy/expressions/core.py Show resolved Hide resolved
@IgnaceBleukx
Copy link
Collaborator

Will the new transformation push_down_negation also be part of this pull request?

# Conflicts:
#	cpmpy/expressions/__init__.py
#	cpmpy/expressions/globalconstraints.py
#	tests/test_globalconstraints.py
@Wout4
Copy link
Collaborator Author

Wout4 commented Apr 21, 2023

also in line 517 of core.py, there is something weird...

we check that if 'x == 1' and x is_bool, then it is just 'x'. And because we overwrite 'eq' for this, we also need to overwrite hash, which is a bit ugly.

But we (I) implemented it rather inconsistently... we do not check for != 0, or that !=1 on bool would be == 0... or (after this commit) that ==0 should be ~x. I wonder though that may be we should leave it the way the user wrote it here, and leave it for 'normalize' to normalize these? (removing can be here, normalizing would be in a separate commit ; )

Is overwriting hash a big drawback? Otherwise it could be great to get rid of all these cases in our code where we have to take into account that we can compare booleans with 0. But maybe it is a futile effort anyway because we still allow boolexpr == numexpr?

@tias
Copy link
Collaborator

tias commented Apr 21, 2023

Getting rid of all cases is through a normalize transformation, e.g. to also capture boolvar() >= 1 etc.

Our design principle is that expressions as posted should be as close as possible to what the user wrote (e.g. when they print it immediately after). So we can remove trivial things like a + 0 :: a, and I guess b == 1 to b, but nothing too clever/surprising.

cpmpy/solvers/z3.py Outdated Show resolved Hide resolved
@Wout4
Copy link
Collaborator Author

Wout4 commented Apr 24, 2023

Ok so i think we will leave it to a separate transformation to do these cleanups, also the push down negation will be in another pr

@Wout4 Wout4 marked this pull request as ready for review April 24, 2023 12:17
Copy link
Collaborator

@tias tias left a comment

Choose a reason for hiding this comment

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

Great.

One bonus point comment, and one future thought.

Great extensive tests as well! Do merge!

(I have 3 deprecation warnings when running the tests locally, you might want to fix those in a separate commit)

cpmpy/expressions/core.py Outdated Show resolved Hide resolved
if hasattr(expr, "decompose_negation"):
# for global constraints where the negation of the decomposition is not equivalent
# to the negated global constraint (due to auxiliary variables, i.e. Circuit)
return Operator('and', expr.decompose_negation())
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are not very consistent with the use of our builtin-overwritten any() and Operator('and',...).

one benefit of all() is that it removes constants from the args, one benefit of Operator is that we dont have to import our all, and that we save the effort of a function call and going over the loop...

we were already not consistent, so not for you to fix in this PR, but to keep in mind that we might want to make it consistent at some point...

@Wout4 Wout4 merged commit 0b2fcf5 into master Apr 27, 2023
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.

4 participants