Z3py returns 使用 pow() 函数的方程未知
Z3py returns unknown for equation using pow() function
Z3py returns 未知以下使用 pow() 函数的简单问题。
import z3;
goal = z3.Goal();
goal = z3.Then('purify-arith','nlsat');
solver = goal.solver();
x = z3.Real('x');
solver.add(x <= 1.8);
solver.add(x >= 0);
z = 10**x;
#z = pow(10,x) returns same result
solver.add(z >= 0, z <= 1.8);
print solver.check()
returns
unknown
显然x = 0, z = 1
是一个令人满意的解决方案。任何关于改变方程构建方式或修改策略的建议都将受到赞赏。
可能有一些错误,但以下returns是x = 0
和z = 1
的模型,尽管它给出了未知数。假设 Python API 也显示了这个模型,你可以创建一个简单的 hack 来提取模型并将其添加到断言中进行检查,类似于这如何防止未来模型重用旧模型值:Z3: finding all satisfying models
示例如下(rise4fun link: http://rise4fun.com/Z3/dPnI):
(declare-const x Real)
(declare-const z Real)
(assert (>= x 0.0))
(assert (<= x 1.8))
(assert (= z (^ 10.0 x)))
(assert (<= z 1.8))
(assert (>= z 0.0))
(apply (repeat (then purify-arith simplify ctx-simplify ctx-solver-simplify nlsat qfnra-nlsat))) ; gives:
; (goals
;(goal
; (>= x 0.0)
; (<= x (/ 9.0 5.0))
; (<= (^ 10.0 x) (/ 9.0 5.0))
; (>= (^ 10.0 x) 0.0)
; :precision precise :depth 44)
;)
; (apply (repeat (then (repeat purify-arith) (repeat simplify) (repeat ctx-simplify) (repeat ctx-solver-simplify) (repeat nlsat) (repeat qfnra-nlsat))))
(check-sat) ; unknown
;(check-sat-using qfnra-nlsat) ; unknown
(get-model) ; gives x = 0.0 and z = 1.0 even though unknown from check-sat
; could extract 0 and 1 in python API and check whether it's sat:
(assert (= x 0))
(assert (= z 1))
(check-sat) ; sat
您可能也对此相关 post 感兴趣:
为了完整起见,这里是 Python 中似乎可行的模型提取想法(使用 4.3.3,可能是从不稳定的版本构建的,但不久前可能):
import z3;
print z3.get_version_string();
goal = z3.Goal();
goal = z3.Then('purify-arith','nlsat');
#solver = goal.solver();
solver = z3.Solver();
x = z3.Real('x');
z = z3.Real('z');
solver.add(x <= 1.8);
solver.add(x >= 0);
solver.add(z == 10.0 ** x);
# z = 10**x;
#z = pow(10,x) returns same result
solver.add(z >= 0, z <= 1.8);
print solver
print solver.check()
print solver.model()
m = solver.model()
solver.add(x == m[x])
solver.add(z == m[z])
print solver
print solver.check()
这给出:
D:\>python exponent.py
4.3.3
[x <= 9/5, x >= 0, z == 10**x, z >= 0, z <= 9/5]
unknown
[x = 0, z = 1]
[x <= 9/5,
x >= 0,
z == 10**x,
z >= 0,
z <= 9/5,
x == 0,
z == 1]
sat
Z3py returns 未知以下使用 pow() 函数的简单问题。
import z3;
goal = z3.Goal();
goal = z3.Then('purify-arith','nlsat');
solver = goal.solver();
x = z3.Real('x');
solver.add(x <= 1.8);
solver.add(x >= 0);
z = 10**x;
#z = pow(10,x) returns same result
solver.add(z >= 0, z <= 1.8);
print solver.check()
returns
unknown
显然x = 0, z = 1
是一个令人满意的解决方案。任何关于改变方程构建方式或修改策略的建议都将受到赞赏。
可能有一些错误,但以下returns是x = 0
和z = 1
的模型,尽管它给出了未知数。假设 Python API 也显示了这个模型,你可以创建一个简单的 hack 来提取模型并将其添加到断言中进行检查,类似于这如何防止未来模型重用旧模型值:Z3: finding all satisfying models
示例如下(rise4fun link: http://rise4fun.com/Z3/dPnI):
(declare-const x Real)
(declare-const z Real)
(assert (>= x 0.0))
(assert (<= x 1.8))
(assert (= z (^ 10.0 x)))
(assert (<= z 1.8))
(assert (>= z 0.0))
(apply (repeat (then purify-arith simplify ctx-simplify ctx-solver-simplify nlsat qfnra-nlsat))) ; gives:
; (goals
;(goal
; (>= x 0.0)
; (<= x (/ 9.0 5.0))
; (<= (^ 10.0 x) (/ 9.0 5.0))
; (>= (^ 10.0 x) 0.0)
; :precision precise :depth 44)
;)
; (apply (repeat (then (repeat purify-arith) (repeat simplify) (repeat ctx-simplify) (repeat ctx-solver-simplify) (repeat nlsat) (repeat qfnra-nlsat))))
(check-sat) ; unknown
;(check-sat-using qfnra-nlsat) ; unknown
(get-model) ; gives x = 0.0 and z = 1.0 even though unknown from check-sat
; could extract 0 and 1 in python API and check whether it's sat:
(assert (= x 0))
(assert (= z 1))
(check-sat) ; sat
您可能也对此相关 post 感兴趣:
为了完整起见,这里是 Python 中似乎可行的模型提取想法(使用 4.3.3,可能是从不稳定的版本构建的,但不久前可能):
import z3;
print z3.get_version_string();
goal = z3.Goal();
goal = z3.Then('purify-arith','nlsat');
#solver = goal.solver();
solver = z3.Solver();
x = z3.Real('x');
z = z3.Real('z');
solver.add(x <= 1.8);
solver.add(x >= 0);
solver.add(z == 10.0 ** x);
# z = 10**x;
#z = pow(10,x) returns same result
solver.add(z >= 0, z <= 1.8);
print solver
print solver.check()
print solver.model()
m = solver.model()
solver.add(x == m[x])
solver.add(z == m[z])
print solver
print solver.check()
这给出:
D:\>python exponent.py
4.3.3
[x <= 9/5, x >= 0, z == 10**x, z >= 0, z <= 9/5]
unknown
[x = 0, z = 1]
[x <= 9/5,
x >= 0,
z == 10**x,
z >= 0,
z <= 9/5,
x == 0,
z == 1]
sat