z3 - Simplify function interpretation in model -


in smt: check uniqueness , totality of function gave function axiomatization , asked z3 model. because solving quantifiers in undecidable in general, z3 times out.

here modified version in "int" case modelled single value:

(declare-datatypes () ((abc int error none))) (declare-fun f (abc abc) abc) (assert (forall ((x abc)) (=> (or (= x int) (= x error) (= x none)) (= (f none x) none)))) (assert (forall ((x abc)) (=> (or (= x int) (= x error) (= x none)) (= (f x none) none)))) (assert (forall ((x abc)) (=> (or (= x int) (= x error)) (= (f error x) error)))) (assert (forall ((x abc)) (=> (or (= x int) (= x error)) (= (f x error) error)))) (assert (forall ((x abc) (y abc)) (=> (and (= x int) (= y int)) (= (f x y) int)))) (check-sat) (get-model) 

because there finitely many cases, z3 gives answer quickly:

sat (model   (define-fun k!26 ((x!0 abc)) abc     (ite (= x!0 error) error     (ite (= x!0 int) int       none)))   (define-fun f!28 ((x!0 abc) (x!1 abc)) abc     (ite (and (= x!0 error) (= x!1 int)) error     (ite (and (= x!0 int) (= x!1 error)) error     (ite (and (= x!0 error) (= x!1 error)) error     (ite (and (= x!0 int) (= x!1 int)) int       none)))))   (define-fun k!27 ((x!0 abc)) abc     (ite (= x!0 error) error     (ite (= x!0 int) int       none)))   (define-fun f ((x!0 abc) (x!1 abc)) abc     (f!28 (k!27 x!0) (k!26 x!1))) ) 

both k!26 , k!27 return input (this seen checking 3 cases). possible simplify model eliminating these 2 functions automatically?

optimally have following, although see might not possible:

(define-fun f ((x!0 abc) (x!1 abc)) abc   (ite (or (= x!0 none) (= x!1 none)) none   (ite (or (= x!0 error) (= x!1 error)) error     int))) 

i'm using z3py, both general z3-specific , z3py-specific answers welcome.

i don't think there's can guide z3 provide "simpler" answer here; model generated depends on how proof done , simple changes problem can have unpredictable results. in particular, model can change next version of z3.

having said that, common trick eval terms in model. since current problem involves finite domain, can enumerate it. if add following lines @ end of script:

(eval (f int   int)) (eval (f int   error)) (eval (f int   none)) (eval (f error int)) (eval (f error error)) (eval (f error none)) (eval (f none  int)) (eval (f none  error)) (eval (f none  none)) 

then z3 print:

int error none error error none none none none 

perhaps can use output construct "simpler" model yourself. of course, works if domain finite; can use same trick evaluate "interesting" parts of input domain, depending on problem.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -