Z3とSMTLIBを使用して、複合値の構成/モデルを計算する

StackOverflow https://stackoverflow.com/questions/8387807

  •  28-10-2019
  •  | 
  •  

質問

帰属値を計算するにはどうすればよいですか?これが例です:

(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(assert (AND x (OR y z)))

これにより、2つのモデルが表示されます。

x=true and y=true
x=true and z=true

さて、私が欲しいのはこのようなものです:

(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(declare-fun x.val () Int)
(declare-fun y.val () Int)
(declare-fun z.val () Int)
(assert (= x.val 2))
(assert (= y.val 3))
(assert (= z.val 5))
(assert (AND x (OR y z)))
(assert (> sum 6))

したがって、属性の合計が6を超えるモデルを取得したいと思います。

x=true and z=true

たぶん、配列を使用することはこれを達成する方法です...

役に立ちましたか?

解決

あなたの質問を正しく理解したかどうかはわかりません。各ブール変数に(整数)属性を関連付けたいようです。したがって、各変数はペアです。ブール値と整数属性です。私はそれを想定しています sum 、あなたはtrueに割り当てられた変数の属性の合計を意味しました。その場合、次の方法でZ3でモデル化できます。

;; Enable model construction
(set-option :produce-models true)

;; Declare a new type (sort) that is a pair (Bool, Int).
;; Given a variable x of type/sort WBool, we can write
;;  - (value x) for getting its Boolean value
;;  - (attr x)  for getting the integer "attribute" value
(declare-datatypes () ((WBool (mk-wbool (value Bool) (attr Int)))))

;; Now, we declare a macro int-value that returns (attr x) if
;; (value x) is true, and 0 otherwise
(define-fun int-value ((x WBool)) Int
  (ite (value x) (attr x) 0))

(declare-fun x () WBool)
(declare-fun y () WBool)
(declare-fun z () WBool)

;; Set the attribute values for x, y and z
(assert (= (attr x) 2))
(assert (= (attr y) 3))
(assert (= (attr z) 5))

;; Assert Boolean constraint on x, y and z.
(assert (and (value x) (or (value y) (value z))))

;; Assert that the sum of the attributes of the variables assigned to true is greater than 6.
(assert (> (+ (int-value x) (int-value y) (int-value z)) 6))
(check-sat)
(get-model)

(assert (not (value z)))
(check-sat)

他のヒント

3つの変数を使用すると、次のようなものになると思います。

(define-fun cond_add ((cond Bool) (x Int) (sum Int)) Int
  (ite cond (+ sum x) sum))
(declare-fun sum () Int)
(assert (= sum (cond_add x x.val (cond_add y y.val (cond_add z z.val 0)))))
(assert (> sum 6))

ここでは、マクロを定義します cond_add 対応する条件が保持されたときにアキュムレータに変数を追加する。と sum の条件付き合計を説明するために定義されます x.val, y.valz.val の真理値に基づいています x, yz.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top