z3反例中的数组元素

z3反例中的数组元素,z3,smt,Z3,Smt,z3刀具辅助元件的反例输出 我尝试了下面的python代码,并得到了一个反例 from z3 import Solver, parse_smt2_string s = Solver() #str1="(declare-const x Int) (declare-const y Int) (declare-const z Int) (declare-const a1 (Array Int Int)) (declare-const a2 (Array Int Int)) (declare-const

z3刀具辅助元件的反例输出

我尝试了下面的python代码,并得到了一个反例

from z3 import Solver, parse_smt2_string
s = Solver()
#str1="(declare-const x Int) (declare-const y Int) (declare-const z Int) (declare-const a1 (Array Int Int)) (declare-const a2 (Array Int Int)) (declare-const a3 (Array Int Int))  (assert (= (select a1 x) x)) (assert (= (store a1 x y) a1))"
str1="(define-sort A () (Array Int Int Int)) (define-fun bag-union ((x A) (y A)) A   ((_ map (+ (Int Int) Int)) x y)) (declare-const s1 A) (declare-const s2 A) (declare-const s3 A) (assert (= s3 (bag-union s1 s2))) (assert (= (select s1 0 0) 5)) (assert (= (select s2 0 0) 3)) (assert (= (select s2 1 2) 4))"
s.add(parse_smt2_string(str1))
s.check()
m = s.model()    
for d in m:     
  print(d,m[d])
if str(s.check())=="sat":  
    print(s.model())  
    m = s.model()    
    for d in m: 
        print(d,m[d])


(s2, [(1, 2) -> 4, (0, 0) -> 3, else -> 7719])
(s3, [(1, 2) -> 8859, (0, 0) -> 8, else -> 8955])
(s1, [(1, 2) -> 8855, (0, 0) -> 5, else -> 1236])
(k!1, [(1, 2) -> 4, (0, 0) -> 3, else -> 7719])
(k!2, [(1, 2) -> 8859, (0, 0) -> 8, else -> 8955])
(k!0, [(1, 2) -> 8855, (0, 0) -> 5, else -> 1236])
....
像(k!1,[(1,2)->4,(0,0)->3,else->7719])这样的行让我困惑吗? 它们似乎是重复的行(s2,[(1,2)->4,(0,0)->3,else->7719。
我可以添加一个不显示这些行的选项吗?

您正在将SMTLib和Python输入混合到一个输入中;这样做确实没有充分的理由。可以用Python编程,也可以用SMTLib编程。当您以这种方式使用z3时,您无法访问您定义的变量。如果您直接用z3py编程,那么您可以简单地查询变量的值您已经轻松定义了。除此之外,您最好的选择是简单地检查名称是否为
k!n
格式,并在
for
循环中跳过它

还请注意,这些“辅助”模型变量的输出中打印的内容与z3版本密切相关。当我使用github源代码中最新版本的z3运行您的程序时,它会打印:

(s2, Store(K(Int, 4), 0, 0, 3))
(s1, K(Int, 5))
(s3, Store(K(Int, 9), 0, 0, 8))
[s2 = Store(K(Int, 4), 0, 0, 3),
 s1 = K(Int, 5),
 s3 = Store(K(Int, 9), 0, 0, 8)]
(s2, Store(K(Int, 4), 0, 0, 3))
(s1, K(Int, 5))
(s3, Store(K(Int, 9), 0, 0, 8))

它没有提到
k!n
变量。以这种方式混合两种输入语言只会引起很多混乱。

谢谢,如果我更喜欢使用SMTLib格式输入,并且我还想返回反例以进一步细化guidline,我只需使用命令:m=s.model(),然后是肯定的..但是你无法控制跟踪变量是什么。用Python(或在比SMTLib更高级别的API中)编程的要点是,你可以跟踪变量,并用它们进行进一步的编程。