Z3 发现模型与公理不一致



当使用 z3-solver 模块 (4.8.0.0) 在 Python 3.6.7 上运行此代码时,z3 返回的模型似乎对公理无效。

f = z3.Function('f', z3.IntSort(), z3.IntSort(), z3.IntSort())
x = z3.Int('x')
s = z3.Solver()
s.add(f(1, 10) == 42)
s.add(z3.ForAll([x], f(2, x) == f(1, x)))
s.check()
m = s.model()
print(m.eval(f(1, 10)))  # print 0
print(m.eval(f(2, 10)))  # print 0

为什么我们没有得到我们可以期望的 42 分? 公理或函数有问题吗?

看起来您的安装可能会被破坏,因为我无法复制这个:

$ cat a.py
import z3
f = z3.Function('f', z3.IntSort(), z3.IntSort(), z3.IntSort())
x = z3.Int('x')
s = z3.Solver()
s.add(f(1, 10) == 42)
s.add(z3.ForAll([x], f(2, x) == f(1, x)))
print s.sexpr()
s.check()
m = s.model()
print(m.eval(f(1, 10)))  # print 0
print(m.eval(f(2, 10)))  # print 0
$ python a.py
(declare-fun f (Int Int) Int)
(assert (= (f 1 10) 42))
(assert (forall ((x Int)) (= (f 2 x) (f 1 x))))
42
42

请注意,我在您的代码中添加了print s.sexpr(),它很好地打印了生成的 SMTLib。你看到的一样吗?

最新更新