如何更改 z3 函数的标准行为?

How can I change the standard behavior of z3 functions?

我有一个 Z3 的(获取模型)查询,return这个函数:

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

使用此代码时:

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

问题是我需要函数 "rules" 到 return false,只要参数不是树中的一棵,我已经断言规则为真,但我找不到一种编辑函数中最后一个 "else" 的方法。 (get-model) 似乎总是使用函数的最常见答案,因为如果 none 规则有效,它就是答案,并且因为我只有树的规则,它使答案为真,所以它也对其他使用真,但我不能那样使用该功能。

您似乎在尝试像 "closed-world" 假设一样对 Prolog 进行建模。这不是 SMT 求解器的工作方式:它们会找到满足所有要求的模型,其他一切都是公平的游戏。也就是说,如果您不想使用其他值来满足您的 rules,那么您必须明确说明。

您可能想查看数据记录建模,这似乎更接近您要表达的内容:https://rise4fun.com/z3/tutorialcontent/fixedpoints