我正在學習Z3。我正在使用一些簡單的「isPrime」函數,並偶然發現了一些難以理解的行爲。看似「更簡單」的內聯公式(> q 1)
導致「未知」,而更復雜的定義樂趣(宏)(isPrime q)
導致快速解決方案,即使(isPrime q)
包含(> q 1)
。 http://rise4fun.com/Z3/slg2D。無法解釋如何進行簡單的調整導致「未知」Z3結果
(define-fun isPrime ((x Int)) Bool
(and (> x 1) (not (exists ((z Int) (y Int)) (and (not (= y x)) (and (not (= z x)) (and (> y 1) (> z 1) (= x (* y z)))))))))
(declare-const q Int)
(declare-const r Int)
(assert (and
;with this the '+ 2' variation is sat: 5, 3
;(isPrime q)
(> q 1)
(> r 1)
;always answers sat: 2, 2
;(isPrime (+ (* q r) 1))
;unknown
(isPrime (+ (* q r) 2))
))
(check-sat)
(get-model)
你用Z3做什麼?解決soduku? – tofutim
解決初等數學問題。 –
哪一個是_simpler內聯公式_?你能更清楚地陳述這個問題嗎? – iago