我正在尝试使用来自http://rise4fun.com/Z3/tutorial/guide的量词示例的 Z3 。
这两个示例适用于 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”断言的模式。结果应该是“未知”和“不满意”。
我正在使用来自http://research.microsoft.com/projects/z3/z3-3.2.tar.gz的 Z3 3.2 的 linux 版本
我通过 z3 binary 尝试了这两个示例
./z3 -smt2 ex1.smt
./z3 -smt2 ex2.smt
结果是正确的。
但是,当我使用 ocaml api 时,这两个示例都是“未知的”。
我试过了:
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 ;;
谢谢!