Z3 无法通过测试证明两个使用 Kleene 代数的简单程序之间的等价性,但 Mathematica 和 Reduce 能够

标签 z3 abstract-algebra

我们这里的问题是表明

enter image description here

在测试中使用 Kleene 代数。

在 b 的值由 p 保留的情况下,我们有交换条件 bp = pb;两个程序之间的等价性简化为等式

enter image description here

在 b 的值不被 p 保留的情况下,我们有交换性条件 pc = cp;两个程序之间的等价性简化为等式

enter image description here

我正在尝试使用以下 SMT-LIB 代码证明第一个等式

(declare-sort S)
(declare-fun sum (S S) S)
(declare-fun mult (S S) S)
(declare-fun neg (S) S)
(assert (forall ((x S) (y S) (z S)) (= (mult x (sum y z)) (sum (mult x y) (mult y z)))   ) )
(assert (forall ((x S) (y S) (z S)) (= (mult (sum y z) x) (sum (mult y x) (mult z x)))   ) )
(assert (forall ((x S) (y S) (z S)) (= (mult x (mult y z)) (mult (mult x y) z))    ))
(check-sat)
(push)
(declare-fun b () S)
(declare-fun p () S)
(declare-fun q () S)
(declare-fun r () S)
(assert (= (mult b p) (mult p b)) )
(check-sat)
(pop)

但我正在获取超时;也就是说Z3不能满足交换条件bp = pb。请在线运行此示例here .

Z3 无法证明这些方程,但 Mathematica 和 Reduce 可以。 Z3 没有定理证明器那么强大。你同意吗?

最佳答案

使用 Z3 和以下 SMT-LIB 代码证明了第一个方程

(declare-sort S)
(declare-fun e () S)
(declare-fun O () S)
(declare-fun mult (S S) S)
(declare-fun sum  (S S) S)
(declare-fun leq (S S) Bool)
(declare-fun negation (S) S)
(declare-fun test (S) Bool)
(assert (forall ((x S) (y S))  (= (sum x y) (sum y x ))))
(assert (forall ((x S) (y S) (z S)) (= (sum (sum x y) z) (sum x (sum y z)))))
(assert (forall ((x S)) (= (sum O x)  x)))
(assert (forall ((x S)) (= (sum x x)  x)))
(assert (forall ((x S) (y S) (z S)) (= (mult (mult x y) z) (mult x (mult y z)))))
(assert (forall ((x S)) (= (mult e x)  x)))
(assert (forall ((x S)) (= (mult x e)  x)))
(assert (forall ((x S) (y S) (z S)) (= (mult x (sum y z) ) (sum   (mult x y) (mult x z)))))
(assert (forall ((x S) (y S) (z S)) (= (mult (sum x y) z ) (sum   (mult x z) (mult y z)))))
(assert (forall ((x S)) (= (mult x O)  O)))
(assert (forall ((x S)) (= (mult O x)  O)))
(assert (forall ((x S) (y S))  (= (leq x y) (= (sum x y) y))))
(assert (forall ((x S) (y S)) (=> (and (test x) (test y) )  (= (mult x y) (mult y x))) ) )
(assert (forall ((x S)) (=> (test x) (= (sum x (negation x)) e)  ))) 
(assert (forall ((x S)) (=> (test x) (= (mult x (negation x)) O)  ))) 
(check-sat)

(push)
;; bpq + b`pr = p(bq + b`r)
(declare-fun b () S)
(declare-fun p () S)
(declare-fun q () S)
(declare-fun r () S)
(assert (=> (test b) (= (mult p b) (mult b p))   )) 
(assert  (=> (test b) (= (mult p (negation b)) (mult (negation b) p)))) 
(check-sat)
(assert (not (=> (test b) (= (sum (mult b (mult p q)) (mult (negation b) (mult p r) )) 
                                                               (mult p (sum (mult b q) (mult (negation b) r)))))      ) ) 
(check-sat)
(pop)
(echo "Proved: bpq + b`pr = p(bq + b`r)")

输出是

sat
sat
unsat
Proved: bpq + b`pr = p(bq + b`r)

请在线运行此证明here

关于Z3 无法通过测试证明两个使用 Kleene 代数的简单程序之间的等价性,但 Mathematica 和 Reduce 能够,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25108435/

相关文章:

z3 - 将 Z3 用于 MAX-SAT 的问题

haskell - 函数式编程中的代数结构是什么?

haskell - 来自 Hackage 上 'algebra' 包的可交换幺半群

performance - Z3:如何提高性能?

python - z3 规划问题和阻碍世界

optimization - z3 的错误结果

python - Z3PY 将 Int 转换为 Python int

oop - R : Use a different base field/corpus 中的运算符重载和类定义

algorithm - 随机生成关联操作

abstract-algebra - 你如何使用 GAP 来识别一个组?