Repository navigation
Conversation
intView flattens a * (view.a * x + view.b) + b into a single affine view by computing the composed coefficients in int arithmetic. Either product can leave the int range even when every value the expression can take is small. For x in [46341, 46342], flattening (x - 46341) * 46341 computes b as 46341 * -46341, which does not fit and wraps to a positive number. The corrupted view then prunes valid solutions and returns assignments that violate the posted constraint. Compute the composed coefficients in long, and keep the nested view when either of them does not fit in an int. That falls back to the same IntAffineView construction the non-flattening branch already used, so no new view type is needed and views stay enabled.
ArthurGodet
requested changes
Sep 6, 2026
ArthurGodet
left a comment
Collaborator
There was a problem hiding this comment.
Just a small change to do (to keep simplified imbricated if/else-if), but otherwise, changes seem fine to me. Thanks for your contribution !
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
ArthurGodet
approved these changes
Sep 7, 2026
cprudhom
approved these changes
Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1244.
IViewFactory#intViewflattens a nested affine view by composing the coefficients inintarithmetic:Either product can leave the
intrange even when every value the expression can take is small. In the reported case,xranges over[46341, 46342]and the composed expression is at most46341, but flattening(x - 46341) * 46341computesbvas46341 * -46341 = -2147488281, which underflows and wraps to+2147479015. The view built from that is wrong in both directions: a valid solution is pruned and the model reported unsatisfiable, and an assignment that violates the posted constraint is returned as a solution.Changes proposed in this PR:
longand keep the nested view when either does not fit in anint, falling back to thenew IntAffineView<>(var, a, b)construction the non-flattening branch already used. No new view type is needed and views stay enabled.IntAffineViewTest, one per direction reported in the issue.On scope: the issue also suggests guarding the scaled bounds of the base variable, in addition to the coefficients. I left that out. It only changes behaviour when
avandbvboth fit butav * basedoes not, and in that situation this patch and the current code take the same branch, so I could not write a test that distinguishes them. I would rather not add a condition with no regression test behind it. Worth noting if you do want it covered:getLB()andgetUB()compute(...) * a + bas a singleintexpression, so an overflowing intermediate cancels there and the bound is still correct;contains()is the one that would suffer, because it doesvalue -= band then divides, and the division does not undo the wrap. Happy to add it if you would like it handled.I did not touch
CHANGES.md, since there is no unreleased section to add to.Verified with a negative control: reverting only
IViewFactory.javaand keeping the tests fails exactly the two new tests out of 150 in the class, withexpected [true] but found [false]for the pruned solution andexpected [46342] but found [46341]for the invalid one. Restoring the fix passes all 150.@chocoteam/core-developer