Diferentes resultados entre z3 binary y z3 api

I'm trying out Z3 with quantifier examples from http://rise4fun.com/Z3/tutorial/guide .

The two example works fine with the online version of Z3 ( I guess it would be 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)

y

(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)

The difference is the pattern we used for the "forall" assertion. The result should be "unknow" and "unsat".

I'm using the linux version of Z3 3.2 from http://research.microsoft.com/projects/z3/z3-3.2.tar.gz

I tried the two examples through z3 binary

./z3 -smt2 ex1.smt

./z3 -smt2 ex2.smt

El resultado es correcto.

However, when I was using the ocaml api, the two examples are both "unknow".

He intentado:

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

y

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 ;;

¡Gracias!

preguntado el 03 de mayo de 12 a las 21:05

1 Respuestas

There is a typo in the OCaml code.

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))

El problema es el Z3.mk_not. Las ! in the SMT input is not a negation. In SMT 2.0, ! is used to "attach" attributes to formulas. In the example above, the attribute is the pattern.

Respondido el 20 de junio de 20 a las 10:06

Thanks a lot. However, still confusions here. The result by using parser is "unknow" which should be "unsat". And with my typo example, it is "unsat" with "MBQI" turned on. Can you suggest a paper on model based quantifier instantiation? - Naituida

The two examples in your questions are from the Z3 guide. The purpose of the first example is to demonstrate limitations of heuristic quantifier instantiation based on patterns. That is, Z3 will fail to prove the formula to be unsat when the pattern (f (g x)) is provided and MBQI is disabled. The unknown answer is the expected one. Regarding MBQI papers, an introduction is provided at: research.microsoft.com/en-us/um/people/leonardo/ijcar10.pdf, the actual algorithm is based on the theoretical ideas presented at: research.microsoft.com/en-us/um/people/leonardo/ci.pdf - Leonardo de Mora

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.