2

http://rise4fun.com/Z3/tutorial/guideの量指定子の例で Z3 を試しています。

2 つの例は、Z3 のオンライン バージョン (Z3 4.0 だと思います) で正常に動作します。

(set-option :auto-config false) ; disable automatic self configuration
(set-option :mbqi false) ; disable model-based quantifier instantiation
(declare-fun f (Int) Int)
(declare-fun g (Int) Int)
(declare-const a Int)
(declare-const b Int)
(declare-const c Int)
(assert (forall ((x Int))
                (! (= (f (g x)) x)
                   :pattern ((f (g x))))))
(assert (= (g a) c))
(assert (= (g b) c))
(assert (not (= a b)))
(check-sat)

(set-option :auto-config false) ; disable automatic self configuration
(set-option :mbqi false) ; disable model-based quantifier instantiation
(declare-fun f (Int) Int)
(declare-fun g (Int) Int)
(declare-const a Int)
(declare-const b Int)
(declare-const c Int) 
(assert (forall ((x Int))
            (! (= (f (g x)) x)
               :pattern ((g x)))))
(assert (= (g a) c))
(assert (= (g b) c))
(assert (not (= a b)))
(check-sat)

違いは、「forall」アサーションに使用したパターンです。結果は「unnow」および「unsat」になるはずです。

http://research.microsoft.com/projects/z3/z3-3.2.tar.gzの Z3 3.2 の Linux バージョンを使用しています。

z3バイナリで2つの例を試しました

./z3 -smt2 ex1.smt

./z3 -smt2 ex2.smt

結果は正しいです。

ただし、ocaml api を使用していたときは、2 つの例は両方とも「不明」です。

私はもう試した:

Z3.parse_smtlib2_file ctx "ex2.smt" [||] [||] [||] [||];;

let mk_unary_app ctx f x = Z3.mk_app ctx f [|x|];;
let example () = 
  let ctx = Z3.mk_context_x [|("MBQI","false")|] in 
  let int = Z3.mk_int_sort ctx in 
  let f = Z3.mk_func_decl ctx (Z3.mk_string_symbol ctx "f") [|int|] int in
  let g = Z3.mk_func_decl ctx (Z3.mk_string_symbol ctx "g") [|int|] int in
  let a = Z3.mk_const ctx (Z3.mk_string_symbol ctx "a") int in 
  let b = Z3.mk_const ctx (Z3.mk_string_symbol ctx "b") int in 
  let c = Z3.mk_const ctx (Z3.mk_string_symbol ctx "c") int in 
  let sym = Z3.mk_int_symbol ctx 0 in
  let bv = Z3.mk_bound ctx 0 int in
  let pat = Z3.mk_pattern ctx [| Z3.mk_app ctx g [| bv |]  |]  in
  let forall = Z3.mk_forall ctx 0 [| pat |] [|int|] [|sym|] 
    (Z3.mk_not ctx (Z3.mk_eq ctx (Z3.mk_app ctx f [|Z3.mk_app ctx g [|bv|]|]) bv)) in 
  Z3.assert_cnstr ctx forall;
  Z3.assert_cnstr ctx (Z3.mk_eq ctx (mk_unary_app ctx g a) c);
  Z3.assert_cnstr ctx (Z3.mk_eq ctx (mk_unary_app ctx g b) c);
  Z3.assert_cnstr ctx (Z3.mk_not ctx (Z3.mk_eq ctx a b));
  Z3.check ctx ;;

ありがとう!

4

1 に答える 1

1

OCaml コードにタイプミスがあります。

let forall = Z3.mk_forall ctx 0 [| パット |] [|int|] [|sym|]

(Z3.mk_not ctx (Z3.mk_eq ctx (Z3.mk_app ctx f [|Z3.mk_app ctx g [|bv|]|]) bv))

問題は、Z3.mk_not. SMT 入力の!は否定ではありません。SMT 2.0 では、!式に属性を「添付」するために使用されます。上記の例では、属性はパターンです。

于 2012-05-03T20:58:45.300 に答える