我想在另一個模型中使用一個模型的輸出(在我的情況下坐下來和不滿足)。在這裏,模型是對一組邏輯公式中涉及的常量(本例中爲Z3表達式)的令人滿意的分配。我的目標可以簡要解釋如下。我可以在另一個SMT表達式中使用SMT程序的結果嗎?
我的問題可以詳細描述如下:我有一個形式化的問題P,一組邏輯公式(表達式)對應一些約束(C)。在這些表達式中,一個(例如,Ai> 0)是我的目標。執行模型/形式化P返回sat,如果所有的約束都是可滿足的。請注意,Ai = 0始終是可能的。 現在,我想找到一組特定變量對應的約束(C),確保Ai> 0(對於任何i)是不可能的。 目前,我正在通過編寫一個程序(使用C#)來開發一個基於DFS的約束搜索算法(即約束值),並通過「push /流行」。雖然我試圖讓搜索更好,但這對我沒有多大幫助。對於較大的問題規模而言效率很低。如果我能夠用P來創建另一個SMT程序(模型)來搜索這樣一個可滿足的集合,那將是非常好的。
問題P(短SMT LIB 2版原問題)目前形式化如下:
(declare-fun th1() Real)
(declare-fun th2() Real)
(declare-fun th3() Real)
(declare-fun th4() Real)
(declare-fun th5() Real)
(declare-fun l1() Real)
(declare-fun l2() Real)
(declare-fun l3() Real)
(declare-fun l4() Real)
(declare-fun l5() Real)
(declare-fun l6() Real)
(declare-fun l7() Real)
(declare-fun p1() Real)
(declare-fun p2() Real)
(declare-fun p3() Real)
(declare-fun p4() Real)
(declare-fun p5() Real)
(declare-fun sl1() Int)
(declare-fun sl2() Int)
(declare-fun sl3() Int)
(declare-fun sl4() Int)
(declare-fun sl5() Int)
(declare-fun sl6() Int)
(declare-fun sl7() Int)
(declare-fun sp1() Int)
(declare-fun sp2() Int)
(declare-fun sp3() Int)
(declare-fun sp4() Int)
(declare-fun sp5() Int)
(declare-fun a1() Int)
(declare-fun a2() Int)
(declare-fun a3() Int)
(declare-fun a4() Int)
(declare-fun a5() Int)
(declare-fun na() Int)
(declare-fun ns() Int)
(declare-fun attack() Bool)
;;;; System
(assert (and (= l1 (* (- th2 th1) 17.0))
(= l2 (* (- th5 th1) 4.5))
(= l3 (* (- th3 th2) 5.05))
(= l4 (* (- th4 th2) 5.65))
(= l5 (* (- th5 th2) 5.75))
(= l6 (* (- th4 th3) 5.85))
(= l7 (* (- th5 th4) 23.75))
(= p1 (+ l1 l2))
(= p2 (+ l1 l3 l4 l5))
(= p3 (+ l3 l6))
(= p4 (+ l4 l6 l7))
(= p5 (+ l2 l5 l7))
)
)
;;;; Secured measurements
(assert (and (or (= sl1 0) (= sl1 1))
(or (= sl2 0) (= sl2 1))
(or (= sl3 0) (= sl3 1))
(or (= sl4 0) (= sl4 1))
(or (= sl5 0) (= sl5 1))
(or (= sl6 0) (= sl6 1))
(or (= sl7 0) (= sl7 1))
(or (= sp1 0) (= sp1 1))
(or (= sp2 0) (= sp2 1))
(or (= sp3 0) (= sp3 1))
(or (= sp4 0) (= sp4 1))
(or (= sp5 0) (= sp5 1))
)
)
(assert (and (=> (not (= l1 0.0)) (= sl1 0))
(=> (not (= l2 0.0)) (= sl2 0))
(=> (not (= l3 0.0)) (= sl3 0))
(=> (not (= l4 0.0)) (= sl4 0))
(=> (not (= l5 0.0)) (= sl5 0))
(=> (not (= l6 0.0)) (= sl6 0))
(=> (not (= l7 0.0)) (= sl7 0))
(=> (not (= p1 0.0)) (= sp1 0))
(=> (not (= p2 0.0)) (= sp2 0))
(=> (not (= p3 0.0)) (= sp3 0))
(=> (not (= p4 0.0)) (= sp4 0))
(=> (not (= p5 0.0)) (= sp5 0))
)
)
(assert (and (= sl1 1) (= sl2 1)))
;;;; Attacks
(assert (and (or (= a1 0) (= a1 1))
(or (= a2 0) (= a2 1))
(or (= a3 0) (= a3 1))
(or (= a4 0) (= a4 1))
(or (= a5 0) (= a5 1))
)
)
(assert (and
(= (not (= th1 0.0)) (= a1 1))
(= (not (= th2 0.0)) (= a2 1))
(= (not (= th3 0.0)) (= a3 1))
(= (not (= th4 0.0)) (= a4 1))
(= (not (= th5 0.0)) (= a5 1))
)
)
(assert (= th1 0.0)) // Base condition
(assert (= na (+ a1 a2 a3 a4 a5)))
(assert (=> attack (> na 1)))
;;;; Check for satisfiable model
(assert attack)
(check-sat)
(get-model)
(exit)
我想合成的安全措施(即,找到「SL」的分配和「SP」而言),這樣就沒有攻擊(即NA爲0)給定的約束,例如,如下:
(assert (= ns (+ sl1 sl2 sl3 sl4 sl5 sl6 sl7 sp1 sp2 sp3 sp4 sp5)))
(assert (<= ns 4))
在這種情況下,斷言(即「(斷言(和(= sl11)(= sl21)))')將被評論。目前,我開發了一個C#程序,它分配'sl'和'sp',聲明它們類似於(assert(和(= sl1 1)(= sl2 1)...))'',並執行給定的程序看看是否有任何可能的攻擊。當程序返回不成功時,我就完成了(即na> 1是不可能的)。有沒有辦法只用SMT(Z3)解決問題?
可否請你澄清你所說的「模式」是什麼意思?這聽起來像你的意思是模型是一個系統的描述(例如,一種防止或允許攻擊路徑的安全策略,然後你以某種方式使用Z3來證明存在或不存在),而你可能意味着模型在模型的理論意義,例如,對一組邏輯公式中涉及的常量(在這種情況下爲Z3表達式)的令人滿意的分配。請參閱以下內容:http://stackoverflow.com/questions/13395391/z3-finding-all-satisfying-models http://stackoverflow.com/questions/16000953/z3-check-if-model-is-unique – Taylor 2013-05-01 02:37:27
Both方式,模型可以被定義。但是,我認爲第二個定義,即對一組邏輯公式(本例中爲Z3表達式)所涉及常量的滿意分配將是最好的定義模型 – Ashiq 2013-05-01 06:45:36
您能否提供一個簡單的P,C,和Ais幫助你理解你在問什麼(理想情況下,對於所涉及的所有事情,例如在SMT-LIB格式中使用適當的排序)?這聽起來就像你正在通過搜索約束C的值來解決SAT問題,這很難理解你要問什麼,因爲你可能編碼這個,並得到Z3爲你解決SAT問題,所以一個例子會真的有幫助。 – Taylor 2013-05-01 15:08:44