2014-07-16 422 views
5

當使用.smt2文件時,我注意到了Z3 4.3.1的一些奇怪行爲。爲什麼0 = 0.5?

如果我這樣做(assert (= 0 0.5))這將是滿足的。但是,如果我切換訂單並執行(assert (= 0.5 0)),則不能滿足要求。

我爲所發生的事情的猜測是,如果第一個參數是一個整數,它施放他們都爲整數(四捨五入0.5下降到0),然後做比較。如果我將「0」更改爲「0.0」,則按預期工作。這與我所使用的大多數編程語言形成了鮮明對比,如果其中任何一個參數都是浮點數,它們都會被轉換爲浮點數並進行比較。這真的是Z3的預期行爲嗎?

+0

http://rise4fun.com/z3/tutorial指出:「...與大多數編程語言不同,Z3不會自動將整數轉換爲實數,反之亦然......」 –

+1

Oki,所以如果沒有隱式轉換時,斷言在類型檢查時應該被拒絕。 –

+0

@PetrVepřek想知道當你聲稱'0.5等於0'時哪些語言會自動將0.5轉換爲0 ... – MxyL

回答

2

嚴格來說,Z3默認情況下不符合SMT 2.0標準,這就是其中一種情況。我們可以添加

(set-option :smtlib2-compliant true) 

然後這個查詢確實被拒絕了。

3

我們的一個實習生,誰SMT2保守延伸與多態性的工作已經注意到了同樣的奇怪的行爲,當他試圖在理解公式混合整數和實數是如何類型檢查:

Z3(http://rise4fun.com/z3)說,下面的例子是SAT,並且發現模型X = 1

(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= x 1.5)) 
(check-sat) 
(get-model) 
(exit) 

但是,它說,下面的 「等效」 的例子在UNSAT

(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= 1.5 x)) 
(check-sat) 
(exit) 

所以,這不符合對稱性謂詞的對稱性。所以,我認爲這是一個錯誤。

5

我認爲這是缺少類型檢查的結果; z3太寬鬆了。它應該簡單地拒絕這樣的查詢,因爲它們根本沒有形成。

根據該SMT-Lib的標準,V2(http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.0-r10.12.21.pdf);第30頁;核心理論正是如此定義:

(theory Core 
:sorts ((Bool 0)) 
:funs ((true Bool) (false Bool) (not Bool Bool) 
     (=> Bool Bool Bool :right-assoc) (and Bool Bool Bool :left-assoc) 
     (or Bool Bool Bool :left-assoc) (xor Bool Bool Bool :left-assoc) 
     (par (A) (= A A Bool :chainable)) 
     (par (A) (distinct A A Bool :pairwise)) 
     (par (A) (ite Bool A A A)) 
    ) 
:definition 
"For every expanded signature Sigma, the instance of Core with that signature 
is the theory consisting of all Sigma-models in which: 
    - the sort Bool denotes the set {true, false} of Boolean values; 
    - for all sorts s in Sigma, 
     - (= s s Bool) denotes the function that 
     returns true iff its two arguments are identical; 
     - (distinct s s Bool) denotes the function that 
     returns true iff its two arguments are not identical; 
     - (ite Bool s s) denotes the function that 
     returns its second argument or its third depending on whether 
     its first argument is true or not; 
     - the other function symbols of Core denote the standard Boolean operators 
     as expected. 
     " 
    :values "The set of values for the sort Bool is {true, false}." 
) 

因此,通過定義平等,需要輸入各種各樣是相同的;因此上述查詢應被拒絕爲無效。

有可能是Z3的交換機或迫使越來越嚴格的類型檢查比它在默認情況下其他一些設置;但是我希望這個案例能夠被最輕鬆的實現所捕獲。

0

一種可能的解決方案是

(declare-fun x() Real) 
(declare-fun y() Real) 
(assert (= x 0)) 
(assert (= y 0.5)) 
(check-sat) 
(push) 
(assert (= x y)) 
(check-sat) 
(pop) 

並且輸出是

sat 
unsat 
1

Z3不是唯一SMT求解器,類型檢查這些例子:

  • CVC4接受他們(即使帶有選項--smtlib-strict),並在上述兩個公式的情況下都回答UNSAT。

  • Yices接受他們和答案UNSAT(改變邏輯QF_LIA後,因爲它不支持AUFLIRA)。

  • 有(組邏輯QF_LIA),Z3發出一個錯誤:(錯誤 「行3列17:邏輯不支持實數」)。

  • Alt-Ergo在這兩種情況下都會提示「輸入錯誤:Int和Real無法統一」。但是,Alt-Ergo的SMT2解析器非常有限,並沒有經過嚴格測試,因爲我們專注於它的本地多態語言。所以,不應該把它作爲參考。

我認爲開發人員通常假設Int和Real之間存在「隱式」的子類型關係。這就是爲什麼這些例子通過Z3,CVC4和Yices(也可能是其他類型)成功進行類型檢查的原因。

+1

然後它們都違反了SMT-Lib規範。據我所知,每個標準都沒有「分型」關係。也不清楚這種關係一般意味着什麼。我建議你應該在SMT-Lib郵件列表中提出這個問題,並在此尋求澄清:http://www.cs.nyu.edu/mailman/listinfo/smt-lib –

4

不要依賴任何求解器的隱式類型轉換。相反, 使用to_realto_int進行顯式類型轉換。只發送 井型公式給求解器。然後Mohamed Iguernelala的例子成爲以下內容。

(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= (to_real x) 1.5)) 
(check-sat) 
(exit) 

(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= 1.5 (to_real x))) 
(check-sat) 
(exit) 

這兩個都返回UNSAT在Z3和CVC4。相反,如果您真的想要找到 的模型,那麼x = 1您應該使用以下的一個 。

(set-option :produce-models true) 
(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= (to_int 1.5) x)) 
(check-sat) 
(get-model) 
(exit) 

(set-option :produce-models true) 
(set-logic AUFLIRA) 
(declare-fun x() Int) 
(assert (= x (to_int 1.5))) 
(check-sat) 
(get-model) 
(exit) 

這兩個與x = 1在Z3和CVC4返回飽和

一旦你使所有的類型轉換都是顯式的,並且只處理良好類型的公式,那麼等於的參數順序就不再重要了(爲了正確性)。

+0

「不要依賴隱式*任何*」說起來容易做起來難。這是隱含的,它沒有被要求就發生。 –

+1

我同意!但討論的是「工具」,而不是「使用它們的人」和「他們應該如何使用它們」。我們開發工具來幫助我們。在這裏,SMT解決者應該說這些例子不是很好的類型。否則,這是一個錯誤。 –

+0

是的,這是一個錯誤。工具有錯誤。要防守。爲您擁有的工具編寫代碼,而不是您想要的工具。 –

1

Jochen Hoenicke給出了關於「混合實數和整數」的答案(在SMT-LIB郵件列表中)。它是:

I just wanted to point out, that the syntax may be officially correct. There is an extension in AUFLIRA and AUFNIRA.

From http://smtlib.cs.uiowa.edu/logics/AUFLIRA.smt2

"For every operator op with declaration (op Real Real s) for some sort s, and every term t1, t2 of sort Int and t of sort Real, the expression - (op t1 t) is syntactic sugar for (op (to_real t1) t) - (op t t1) is syntactic sugar for (op t (to_real t1)) - (/ t1 t2) is syntactic sugar for (/ (to_real t1) (to_real t2)) "

+1

我認爲平等是否是延伸的一部分還是有點模棱兩可的;因爲平等是邏輯上更爲基本的概念。我希望標準在這一點上是明確的。 在這兩種情況下,原始問題都保持打開狀態:Z3在任何情況下都會出現錯誤:它應該將查詢視爲無效,或者正確對待「=」並按照先前的觀察結果回答這兩個問題。 –

相關問題