在此示例中(在此處找到:z3py),我可以將c
與例如Color.green
。z3py將數據類型/枚舉與字符串進行比較
Color = Datatype('Color')
Color.declare('red')
Color.declare('green')
Color.declare('blue')
Color = Color.create()
# Let c be a constant of sort Color
c = Const('c', Color)
# Then, c must be red, green or blue
prove(Or(c == Color.green,
c == Color.blue,
c == Color.red))
在我的應用程序有比較c
爲Python字符串: 我想是這樣的:
c = Const('c', Color)
solve(c == "green") # this doesn't work, but it works with Color.green
的方法效果如爲IntSort
(見下文),但不是我自己的數據類型。
i = Int("i")
solve(i < 10)
我想過創建名稱到值的全局映射(類似於你的「簡寫」),但我希望有一種「官方」方式。 你認爲有可能通過合理的努力來實現這樣的事情嗎? – stklik
請參閱下面的我的(潛在)解決方案。我沒有發現任何python測試運行,所以我不想創建拉請求。 @尼古拉 - Bjorner – stklik