【问题标题】:Arrays and Quantifier数组和量词
【发布时间】:2012-08-28 15:45:53
【问题描述】:

我正在尝试在 Z3 中使用数组和量词来查找给定文本中的子字符串。

我的代码如下:

(declare-const a (Array Int Int))
(declare-const x Int)

;; a|A
(assert (or (= (select a 0) 61) (= (select a 0) 41)))
;; b|B
(assert (or (= (select a 1) 62) (= (select a 1) 42)))
;; c|C
(assert (or (= (select a 2) 63) (= (select a 2) 43)))

(assert (>= x 0))
(assert (< x 3))

(assert (exists ((i Int)) (= (select a i) 72) ))
(check-sat)

Z3 在不应该的时候说那是 SAT。我对 Z3 和 SMT 理论比较陌生,而且我无法弄清楚我的代码有什么问题。

【问题讨论】:

    标签: z3 smt


    【解决方案1】:

    在您的示例中,实际上可以通过将 i 设为 0、1、2 范围之外的任何自然数来满足。因此,例如,如果您让 i = 3,因为您没有将数组限制在索引 3 处无论如何,a[3] 有可能是 72。

    这是一个链接,显示了在 Z3@Rise 界面上对您的示例的满意分配(模型),以及接下来描述的修复:http://rise4fun.com/Z3/E6YI

    为防止这种情况发生,一种方法是将 i 的范围限制为您已分配的数组索引之一。也就是说,将 i 限制在 0 到 2 之间。

    (declare-const a (Array Int Int))
    (declare-const x Int)
    
    ;; a|A
    (assert (or (= (select a 0) 61) (= (select a 0) 41)))
    ;; b|B
    (assert (or (= (select a 1) 62) (= (select a 1) 42)))
    ;; c|C
    (assert (or (= (select a 2) 63) (= (select a 2) 43)))
    
    (assert (>= x 0))
    (assert (< x 3))
    
    (assert (exists ((i Int)) (= (select a i) 72)))
    (check-sat)
    (get-model) ; model gives i == 3 with a[i] == 72
    
    (assert (exists ((i Int)) (and (>= i 0) (<= i 2) (= (select a i) 72) )))
    (check-sat)
    

    【讨论】:

    • 看起来你正试图用 x 来实现这一点。而不是我提出的约束,你可以等效地做(假设你有 0 (assert (exists ((i Int)) (and (= i x) (= (select a i) 72) )))
    猜你喜欢
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    相关资源
    最近更新 更多