4

Z3 中是否有办法证明/显示给定模型是唯一的并且不存在其他解决方案?

一个小例子来演示

(declare-const a1 Int)
(declare-const a2 Int)
(declare-const a3 Int)
(declare-const b1 Int)
(declare-const b2 Int)
(declare-const b3 Int)
(declare-const c1 Int)
(declare-const c2 Int)
(declare-const c3 Int)
(declare-const ra Int)
(declare-const rb Int)
(declare-const rc Int)
(declare-const r1 Int)
(declare-const r2 Int)
(declare-const r3 Int)
(assert (>= a1 0))
(assert (>= a2 0))
(assert (>= a3 0))
(assert (>= b1 0))
(assert (>= b2 0))
(assert (>= b3 0))
(assert (>= c1 0))
(assert (>= c2 0))
(assert (>= c3 0))
(assert (<= a1 9))
(assert (<= a2 9))
(assert (<= a3 9))
(assert (<= b1 9))
(assert (<= b2 9))
(assert (<= b3 9))
(assert (<= c1 9))
(assert (<= c2 9))
(assert (<= c3 9))
(assert (= ra 38))
(assert (= rb 1))
(assert (= rc 27))
(assert (= r1 55))
(assert (= r2 72))
(assert (= r3 6))
(assert (= ra (- (* a1 a2) a3)))
(assert (= rb (- (- b1 b2) b3)))
(assert (= rc (* (* c1 c2) c3)))
(assert (= r1 (- (* a1 b1) c1)))
(assert (= r2 (* (+ a2 b2) c2)))
(assert (= r3 (- (+ a3 b3) c3)))
(check-sat)
(get-model)

我知道以下模型是独一无二的,但我可以使用一些 Z3 选项或添加断言来确保这一点吗?

(model 
  (define-fun c3 () Int
    3)
  (define-fun c2 () Int
    9)
  (define-fun c1 () Int
    1)
  (define-fun b3 () Int
    5)
  (define-fun b2 () Int
    2)
  (define-fun b1 () Int
    8)
  (define-fun a3 () Int
    4)
  (define-fun a2 () Int
    6)
  (define-fun a1 () Int
    7)
  (define-fun r3 () Int
    6)
  (define-fun r2 () Int
    72)
  (define-fun r1 () Int
    55)
  (define-fun rc () Int
    27)
  (define-fun rb () Int
    1)
  (define-fun ra () Int
    38)
)

为了澄清起见,我通过 de JAVA API 使用 Z3

4

1 回答 1

6

是的:想法是断言找到的模型分配的值是唯一可能的分配,因此它是唯一的。这可以通过添加一个断言来完成,该断言声明所有常量都不等于它们分配的模型值。

对于您的示例,这将是:

(assert (not (and
  (= c3 3)
  (= c2 9)
  (= c1 1)
  (= b3 5)
  (= b2 2)
  (= b1 8)
  (= a3 4)
  (= a2 6)
  (= a1 7)
  (= r3 6)
  (= r2 72)
  (= r1 55)
  (= rc 27)
  (= rb 1)
  (= ra 38))))
(check-sat) ; unsat => no other model exists

如果您尝试更改任何值(例如,将 c3 = 3 更改为 c3 = 4),这将再次变得令人满意。这是您完整示例的rise@fun 链接:http ://rise4fun.com/Z3/nD5n

有关如何使用 API 以编程方式执行此操作的更多详细信息,请参阅以下问题和答案:

Z3:找到所有满意的模型

(Z3Py) 检查方程的所有解

请注意,根据第二个链接答案中的评论,您不能仅使用 SMT-lib 前端以编程方式执行此操作,如果您想自动执行此过程,则必须使用 API 遍历找到的模型。

于 2013-04-14T16:17:26.247 回答