Skip to content

some more typing of core#907

Merged
tias merged 15 commits intomasterfrom
mypy_core3
Apr 22, 2026
Merged

some more typing of core#907
tias merged 15 commits intomasterfrom
mypy_core3

Conversation

@tias
Copy link
Copy Markdown
Collaborator

@tias tias commented Apr 3, 2026

one notable change is about 'implies' and simplification...

one principle is that we typically don't simplify expressions at creation time, only at transformation time (subject to some exceptions).

I now make this more explicit, making 'simplify' an option to implies (which we don't activate anywhere at the moment). So for the user we wont delete expressions and variables unexpectedly, and for us, if we want it to activate we can.

@tias tias requested a review from IgnaceBleukx April 3, 2026 21:33
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.

Great, that should do away with a lot of weird cases in the transformation stack...
Maybe also add the optional argument to expressions.utils.implies? We use it when we're not sure the lhs is an expression

Comment thread cpmpy/expressions/core.py
Comment thread cpmpy/expressions/core.py Outdated
Comment thread cpmpy/expressions/core.py Outdated
@tias tias mentioned this pull request Apr 7, 2026
13 tasks
@tias tias requested a review from IgnaceBleukx April 15, 2026 09:20
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.

Minor comments on docs, and one potential simplification in implies that we can always do, regardless of the simplify arg

Comment thread cpmpy/expressions/core.py Outdated
Comment thread cpmpy/expressions/core.py
Comment thread cpmpy/expressions/core.py Outdated
Comment thread cpmpy/expressions/core.py Outdated
Comment thread cpmpy/expressions/core.py Outdated
Expression: the implication constraint or a BoolVal if simplified

Simplification rules:
- BoolVal(True) -> other :: other (BoolVal-ified if needed)
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.

We can always apply this one, it does not remove user vars

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... but then the doc needs to be updated,

you are suggesting that we do:

  • if self is true, we post other
  • otherwise, if simplify then we remove other else we post the reification as is

while now, we do 'simplify' -> simplify it; 'no simplify' -> post as is

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, I would be in favor of updating the docs and always doing the simplification.
It is in line with what we do for sum/prod etc, when there is a neutral element.
E.g., x + 0 remains x, instead of writing a sum.

It also ties to #342

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.

Done.

Getting the typing right makes me realize/fear we should introduce a stricter
BoolExprLike: TypeAlias = Union["Expression", bool, np.bool_] # subtype of ExprLike (bool subtype int)

which should be a separate PR as it will affect all logical constraints/operators/functions?

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.

Why would we need that? I would expect methods on expressions to always return an expression? Even if it is a BoolVal, it should be a CPMpy Expression object and not a Python/Numpy bool

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.

for user-facing functions like implies: can take a BoolExpr, can not take an int...

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.

(so for the argument, not the return type idd)

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.

Aha yes I see; indeed...

Comment thread cpmpy/expressions/utils.py Outdated
Copy link
Copy Markdown
Collaborator Author

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

see 2 remaining comments

@tias tias requested a review from IgnaceBleukx April 21, 2026 15:47
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.

A few more things

Comment thread cpmpy/expressions/core.py Outdated
Comment thread cpmpy/expressions/variables.py Outdated
Comment thread cpmpy/tools/xcsp3/globals.py Outdated
@tias tias requested a review from IgnaceBleukx April 22, 2026 09:25
@tias tias merged commit 2b75f7e into master Apr 22, 2026
10 checks passed
@tias tias deleted the mypy_core3 branch April 22, 2026 10:10
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.

2 participants