有一組這樣的4個公式x - y < 2
x - y > 2
x> 3 y < 4
。當第一個公式被刪除時,可以找到x=4 y=-1
的模型。如何使用z3(api)在第一個公式上用4和-1替換x和y?非常感謝你。如何使用z3將新值賦給文字
回答
您可以使用Z3_substitute
API。這裏是一個使用Z3 Python的例子。我使用Python,因爲它是更方便,we can test it online using rise4fun。我們可以使用Z3 C/C++,.Net或Java API編寫相同的示例。
x, y = Ints('x y')
s = Solver()
s.add(x - y > 2, x > 3, y < 4)
print s.check()
m = s.model()
print m
# We can retrieve the value assigned to x by using m[x].
# The api has a function called substitute that replaces (and simplifies)
# an expression using a substitution.
# The substitution is a sequence of pairs of the form (f, t).
# That is, Z3 will replace f with the term t.
F1 = x - y < 2
# Let us use substitute to replace x with 10
print substitute(F1, (x, IntVal(10)))
# Now, let us replace x and y with values assigned by the model m.
print substitute(F1, (x, m[x]), (y, m[y]))
不錯!非常感謝。 api可以應用於smt2實例嗎? – 2013-04-22 21:22:15
是的,SMT2前端具有'eval'命令。在'(check-sat)'之後,我們可以寫'(eval(<( - x y)2))'。它將評估由Z3生成的模型中的表達式。 – 2013-04-23 00:01:18
與SMT2實例相關,當我們不知道確切的具體公式時,比如我們找到了模型m [i]並用m [i]代替公式[i]的變量,這些變量不能準確知道x1或x2,一世]。它可以工作嗎?非常感謝! – 2013-04-23 09:32:00
- 1. 如何將值賦給DropBox文本propery?
- 2. 如何使用Sql字符串將變量賦值給變量
- 3. 如何使用C#將數據列值賦給特定的字
- 4. 將值賦給Z3中的bool變量C api
- 5. 使用OptionSetTypes,將如何使用和賦值(&=)或或賦值(| =)?
- 6. 如何使用ruby的多重賦值將值賦給void變量?
- 7. 將值賦給window.location.href
- 8. 將參數賦值給賦值?
- 9. 使用SBJson將值賦給json響應
- 10. 使用C#將變量賦值給powershell
- 11. 使用try catch將值賦給C#var
- 12. 如何將值「」hello「」賦值給一個字符串?
- 13. 如何將PHP數組值賦給Javascript?
- 14. 如何將%%參數賦值給變量?
- 15. 如何將值賦給組合框
- 16. 如何將readAsDataURL()的值賦給變量?
- 17. 如何將值賦給@ html.validationfor id?
- 18. 如何賦值給幾個字符串?
- 19. 如何正確地賦值給字段
- 20. 使用指針將字符賦給char *
- 21. 將變量賦值給字符串
- 22. 將值賦給rails_admin列表字段
- 23. haml將值賦給輸入字段
- 24. 將空值賦給DateTime字段
- 25. 將字節值賦給char數組
- 26. 將值賦給字符串指針
- 27. 將分析鍵值賦給字符串
- 28. 將整數賦值給字符串
- 29. 將數組值賦給字段
- 30. R使用if if邏輯將值賦給新列
你不知道。 Z3是一個保護盒,而不是計算器。 – 2013-04-22 18:19:04