-
Notifications
You must be signed in to change notification settings - Fork 25
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
Safening of partial functions #515
base: master
Are you sure you want to change the base?
Conversation
@IgnaceBleukx @Wout4 Please revise just the text in the comment, see if we can get that right. (small clean-ups/renamings/reorderings to the code will follow from getting the description right) |
I wrote out the 'why' part a bit more explicitly. Following the text, I think we should not 'safen' top-level expressions. If solvers like ortools want to be picky and not even allow a '0' in the domain for div, then within the solver interface we should detect that and call the relevant safen function there (or safen that specific constraint there knowing that the nearest boolean context is true)? |
I restructured the code following the explanation in comments. There is one mismatch... in the explanation, I wrote about a 'guard'; however, in the safen functions, we don't really introduce a guard/guard conditions... its more like a flag, and we use that flag for multiple things. |
The alternative would be:
which seems intuitive, but some (even toplevel) tests are failing with this. (some tests were already failing before too) |
I went through the Frisch and Stuckey paper again. Ignace implementation followed that paper's rewrite faithfully. But they didn't provide much of a constructive explanation of why this is the right rewrite. Please proofread. I also added an intuitive example and explanation of the side-effects of this transformation, that Also, I think the implementation for toplevel partials was incomplete, nbc was not added to toplevel. However, I believe we should NOT do the rewrite for toplevel exprs, as for that case its the strict semantics anyway (unless all solvers don't accept 0 in div/mod like ortools does? seems to be more its design choice?) |
good point on the fuzzing, I think we can do a check to only fuse safe expressions. |
Took me a while to get the more elaborate code of (Side thought: when we do CSE, we should also test whether the negated expr already exists in the store!) ToplevelnessI modified the behaviour of the transformation to act differently when toplevel. Essentially, we don't safen whenever the neirest Boolean context is toplevel, except when asked for it explicitly in the function args. This was needed for both OR-Tools (due to the API) and Z3 (due to underspecification of Fuzz testingRegarding the semantic fusion in our fuzz-tester, we certainly cannot fuse unsafe expressions...
So the model will always be UNSAT... So here we are changing the Boolean context of the unsafe expression... |
Started on a
safening
transformation for partial functions.Largely based on
but some trickery was required for
div
as we do not allow domains with a hole in it.For now, this is quite dumb: no care is taken to the context of an expression, nor whether it is top-level.
For example,
arr[x] == 2
will be safened and thus introduce a bunch of extra variables/constraints.I think it's reasonable to leave this expression "unsafe" and just let the solver to its thing with it (TODO).
BUT, in the case of division it's more tricky, as the actual API of e.g., OR-Tools does not accept
0
in the denominator's domain.So for that one, we actually do need safening at toplevel... (hence I did it this way for now)
A solution to this is to also introduce a
supported
list for this transformation but it feels quite hacky...This PR only includes safening for
div
andElement
, but the same can be implemented formod
I believe.