-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Issue with for all in z3 #5044
Comments
You're not quantifying over the right |
I modified the code as below. However, it is returning unsat. This is wrong because for z=16 it is sat. (set-option :smt.auto-config false) ; disable automatic self configuration (check-sat) |
Your formula is effectively saying:
That is, "for all y, y is either greater than -5 or less than 5" -- this is clearly unsat. You probably want an implication here; something like Also, you don't need your "global scope" |
Still not working.. It is returning sat with z=15. But z should be at least 16 (set-option :smt.auto-config false) ; disable automatic self configuration (check-sat) |
Yeah, actually, my idea was bad ... the value of |
Your idea is totally fine @andrewvaughanj, an implication is exactly what's needed here. @Ipsitakoley what are you trying to model? Perhaps you meant to say |
Yeah, I managed to confuse myself 😂
|
@andrewvaughanj and @wintersteiger But I wanted to now if the quantifier variable y can be declared globally. Because, my original problem is quite large and has many constraints. It is infeasible to write them within the quantified formula. For example, if I tried to do something like below, it does not work. (set-option :smt.auto-config false) ; disable automatic self configuration (assert (= x (+ y z))) (check-sat) |
The problem you have is that I think you're going to need to put your quantifiers at the top level if you need to refer to |
I'm afraid that's impossible, as the order of quantifiers makes a difference, i.e. |
In z3py, let me know if the following syntax is correct. It is taken from https://theory.stanford.edu/~nikolaj/programmingz3.html s = SolverFor("NRA") # Quantified Non-linear Real Arithmetic |
Also, the following code should return sat with z>=15. However, it is giving unsat. I think, the quantifier variable 'y' must be defined within the forall scope. Please suggest how to do that in z3py. from z3 import * s = Solver() x = Int('x') s.add(ForAll([y], Implies(And(y>-5,y<5),And(x==y+z,x>10)))) print(s.check()) I have written this following the syntax in https://theory.stanford.edu/~nikolaj/programmingz3.html |
|
My understanding was "for all y there exist x and z such that -5<y<5 implies x==y+z and x>10" And, I am not able to define a variable within forall scope (i.e. forall(...)) in z3py. Please help me with that. |
Nope; your top-level variables (i.e., your
Yeah, I don't think there's anything like Your example is something like: from z3 import *
s = Solver()
z = Int("z")
y = Int("y")
s.add(ForAll([y], Implies(And(y > -5, y < 5), y + z > 10)))
print(s.sexpr()) |
Yup things are clear now. Thank you very much. |
The following code gives a trace with z=15. However, this is not valid for all values of y. The value of z must be at least 16. Please let us know how to get the proper value of z in this scenario.
(set-option :smt.auto-config false) ; disable automatic self configuration
(set-option :smt.mbqi false) ; disable model-based quantifier instantiation
(declare-fun y () Int)
(declare-fun z () Int)
(declare-fun x () Int)
(assert (and (> y (- 5)) (< y 5)))
(assert (= x (+ y z)))
(assert (forall ((y Int)) (> x 10)))
(check-sat)
(get-value (z))
The text was updated successfully, but these errors were encountered: