【问题标题】:Distinct in z3 SMT and pythonz3 SMT 和 python 的不同之处
【发布时间】:2015-01-08 13:56:13
【问题描述】:

我的问题是“不同”在 z3 python 中有效吗?我比较了以下代码,但似乎没有给出相同的结果:

(declare-const x Int)
(declare-const y Int)
(assert (distinct x y))
(check-sat)
(get-model)

结果是:

sat

  (model 
  (define-fun y () Int
    0)
  (define-fun x () Int
    1)
  )

我添加了否定断言只是为了测试,结果不满意,这是正确的:

(assert (= x y))

unsat
Z3(6, 10): ERROR: model is not available

但是当我在 python 中使用 z3 时,它总是让我坐在下面:

x = Int('x')
y = Int('y')
Distinct(x, y)
s = Solver
s = Solver() 
s.check()

当我添加以下断言时,它应该给我 unsat 但它返回 sat:

s.add(x == y)
[y = 0, x = 0]

这是否意味着我使用了错误的语法?

【问题讨论】:

    标签: z3 z3py


    【解决方案1】:

    `Distinct' 函数只创建一个术语,它不会将自身添加到求解器中。这是一个适合我的示例:

    x = Int('x')
    y = Int('y')
    d = Distinct(x, y)
    
    s = Solver()
    s.add(d) # SAT without this one, UNSAT with
    s.add(x == y)
    print s
    print s.check()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2019-11-01
      相关资源
      最近更新 更多