简体   繁体   中英

In Z3, I cannot understand result of quantifier elimination of Exists y. Forall x. (x>=2) => ((y>1) /\ (y<=x))

In Z3-Py, I am performing quantifier elimination (QE) over the following formulae:

  • Exists y. Forall x. (x>=2) => ((y>1) /\ (y<=x))
  • Forall x. Exists y. (x>=2) => ((y>1) /\ (y<=x)) Forall x. Exists y. (x>=2) => ((y>1) /\ (y<=x)) ,

where both x and y are Integers. I did QE in the following way:

x, y = Ints('x, y')

t = Tactic("qe")

negS0= (x >= 2)
s1 = (y > 1)
s2 = (y <= x)

#EA

ea = Goal()
ea.add(Exists([y],Implies(negS0, (ForAll([x], And(s1,s2))))))
ea_qe = t(ea)

print(ea_qe)

#AE

ae = Goal()
ae.add(ForAll([x],Implies(negS0, (Exists([y], And(s1,s2))))))
ae_qe = t(ae)

print(ae_qe)

Result QE for ae is as expected: [[]] (ie, True ). However, as for ea , QE outputs: [[Not(x, >= 2)]] , which is a results that I do not know how to interpret since (1) it has not really performed QE (note the resulting formula still contains x and indeed does not contain y which is the outermost quantified variable) and (2) I do not understand the meaning of the comma in x, >= . I cannot get the model either:

phi = Exists([y],Implies(negS0, (ForAll([x], And(s1,s2)))))

s_def = Solver()
s_def.add(phi)
print(s_def.model())

This results in the error Z3Exception: model is not available .

I think the point is as follows: since (x>=2) is an implication, there are two ways to satisfy the formula; by making the antecedent False or by satisfying the consequent. In the second case, the model would be y=2 . But in the first case, the result of QE would be True , thus we cannot get a single model (as it happens with a universal model):

phi = ForAll([x],Implies(negS0, (Exists([y], And(s1,s2)))))

s_def = Solver()
s_def.add(phi)
print(s_def.model())

In any case, I cannot 'philosophically' understand the meaning of a QE of x where x is part of the (quantifier-eliminated) answer.

Any help?

There are two separate issues here, I'll address them separately.

The mysterious comma This is a common gotcha. You declared:

x, y = Ints('x, y')

That is, you gave x the name "x," and y the name "y". Note the comma after the x in the name. This should be

x, y = Ints('x y')

I guess you can see the difference: The name you gave to the variable x is "x," when you do the first; ie, comma is part of the name. Simply skip the comma on the right hand side, which isn't what you intended anyhow. And the results will start being more meaningful. To be fair, this is a common mistake, and I wish the z3 developers ignored the commas and other punctuation in the string you give; but that's just not the case. They simply break at whitespace.

Quantification

This is another common gotcha. When you write:

ea.add(Exists([y],Implies(negS0, (ForAll([x], And(s1,s2))))))

the x that exists in negS0 is not quantified over by your ForAll , since it's not in the scope. Perhaps you meant:

ea.add(Exists([y],ForAll([x], Implies(negS0, And(s1,s2)))))

It's hard to guess what you were trying to do, but I hope the above makes it clear that the x wasn't quantified. Also, remember that a top-level exist quantifier in a formula is more or less irrelevant. It's equivalent to a top-level declaration for all practical purposes.

Once you make this fix, I think things will become more clear. If not, please ask further clarifying questions. (As a separate question on Stack-overflow; as edits to existing questions only complicate the matters.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM