Z3 如何检查模型是否满足新的 assertion/constraint

Z3 How to check whether a model satisfies a new assertion/constraint

我正在使用 z3py 进行编码。请参阅以下示例。

from z3 import *

x = Int('x')
y = Int('y')

s = Solver()

s.add(x+y>3)

if s.check()==sat:
    m = s.model()
    # how to check whether model m satisfies x+y<5 ?
    print(m)

您可以计算模型中的表达式:

from z3 import *

x = Int('x')
y = Int('y')

s = Solver()

s.add(x+y>3)

if s.check()==sat:
    m = s.model()
    print(m)
    print(m.evaluate(x+y<5))

这会打印:

[x = 4, y = 0]
True