0

I have a (get-model) query for Z3 which returns this function:

(define-fun rules ((x!0 Tree)) Bool
(ite (= x!0 (node "mann" (cons (node "adam" nil) nil))) true
(ite (= x!0 (node "mensch" (cons (node "adam" nil) nil))) true
true)))

When using this code:

(declare-datatypes () ((Tree leaf (node (value String) (children TreeList)))
                       (TreeList nil (cons (car Tree) (cdr TreeList)))))
(declare-const list TreeList)
(declare-const fact1 Tree)
(declare-const fact2 Tree)

(assert (not (is-leaf fact1)))
(assert (not (is-leaf fact2)))
(assert (not (= list nil)))

(assert (= (value fact1) "mann"))
(assert (= (value fact2) "adam"))
(assert (= (children fact1) list))

(assert (= fact2 (car list)))


(declare-const list2 TreeList)
(declare-const fact3 Tree)
(declare-const fact4 Tree)

(assert (not (is-leaf fact3)))
(assert (not (is-leaf fact4)))
(assert (not (= list2 nil)))

(assert (= (value fact3) "mensch"))
(assert (= (value fact4) "adam"))
(assert (= (children fact3) list2))

(assert (= fact4 (car list2)))

(declare-fun rules (Tree) Bool)
(assert (= (rules fact1) true))
(assert (=> (rules fact1) (rules fact3)))


(check-sat)
(get-model)

The problem is I need the function "rules" to return false, whenever the argument is not one of the trees I have asserted rules for it to be true, but I can't find a way to edit the last "else" in the function. (get-model) seems to always use the most common answer of the function as it's answer if none of the rules work and since I only have rules for trees which make the answer true it uses true for the else as well, but I can't use the function that way.

M3tag
  • 3
  • 1

1 Answers1

0

It seems you're trying to model Prolog like "closed-world" assumption here. This is not how SMT solvers work: They will find a model that will satisfy all the requirements, and everything else is fair game. That is, if you want no other value to satisfy your rules, then you have to state that explicitly.

You might want to look at datalog modeling though, which seems closer to what you are trying to express: https://rise4fun.com/z3/tutorialcontent/fixedpoints

alias
  • 28,120
  • 2
  • 23
  • 40
  • I read through that site already and I don't think there is anything that helps me there. And you are right, I need to simulate Prolog in Z3 for my bachelor thesis. Iassumed there must be a rule I can use that makes the else of the function false, but everything I do just adds more special cases to rules – M3tag May 04 '18 at 06:39
  • Actually I have to correct myself. I read through it again, and I think I can make it work with this. So thank you for saving my bachelor thesis – M3tag May 04 '18 at 14:49