使用Exists量词检查断言的意外结果

时间:2015-08-20 17:09:32

标签: z3 z3py

我是Z3Py(和Z3)的新手。以下代码按预期返回unsat

from z3 import Ints, Tactic, Exists, And, Implies, ForAll, Bool, Solver, IntSort, BoolSort, Function

s = Solver()
t, a, t0 = Ints('t a t0')
p = Function('p', IntSort(), IntSort(), BoolSort())
facts = [
    t >= 1,
    t <= 2,
    Implies(And([t>0, t <= 1]), p(t, 1) == False),
    Implies(And([t>1, t <= 2]), p(t, 1) == True),
]
query = Implies(t == 2, Exists(t0, And([t0 == t, t0 >= 1, t0 <= 2, p(t0, 1) == True])))
f = Implies(And(facts), query)
s.add(Tactic('qe')(Not(f)).as_expr())
print s.check()  # unsat means f is valid

如果我现在将query更改为

    query = Implies(t == 1, Exists(t0, And([t0 > t, t0 >= 1, t0 <= 2, p(t0, 1) == True])))

它打印sat虽然我期待unsat,因为t0 == 2是量词的必要见证。非常感谢您的任何见解,谢谢。

1 个答案:

答案 0 :(得分:1)

回答了我自己的问题。我的假设太弱了。以下版本的facts完成了这项工作:

facts = [
    t >= 1,
    t <= 2,
    ForAll(t, Implies(And([t>0, t <= 1]), p(t, 1) == False)),
    ForAll(t, Implies(And([t>1, t <= 2]), p(t, 1) == True)),
]