z3 - 推理 XOR 时爆炸式内存使用(所有 AC 理论?)

标签 z3

似乎关于 XOR 的推理导致 Z3 的内存使用爆炸式增长(提交 210bca8f456361f696152be909e33a4e8b58607f2)。例如,从 AC 等价于 a+b+c 的东西派生 a+b+c+x+x+y+y+z+z :

(declare-fun known (Bool) Bool)
(declare-fun p (Bool Bool Bool) Bool)

; Lift xor
(assert (forall ((x Bool) (y Bool))
            (=> (and (known x) (known y)) (known (xor x y)))))

; Can reason about xor well
(assert (exists ((a1 Bool) (b1 Bool) (c1 Bool) (ra Bool) (rb Bool) (rc Bool))
            (and (p a1 b1 c1)
                 (known (xor a1 (xor ra rc)))
                 (known (xor b1 (xor rb ra)))
                 (known (xor c1 (xor rc rb))))))

; Assert that we can derive a+b+c.
; Note: The behavior (non-termination) is the same when this example is
;       inverted (forall ... not ...)
(assert (exists ((a1 Bool) (b1 Bool) (c1 Bool))
            (and (p a1 b1 c1)
                 (known (xor a1 (xor b1 c1))))))
(check-sat)

这是可以接受的限制吗?我可以使用替代公式来回答 Z3 这样的查询吗?

连续性:我有 previously misused 这个任务的 HORN 逻辑。

最佳答案

问题在于断言

(assert (forall ((x Bool) (y Bool))
            (=> (and (known x) (known y)) (known (xor x y)))))

对电子匹配引擎来说真的很糟糕。这是用于处理 Z3 中量词的引擎之一。 有许多可能的解决方法。

1) 使用量词消除。您只需将 (check-sat) 替换为 (check-sat-using (then qe smt))

2) 用:weight 属性注释量词。电子匹配引擎将提前停止生成新实例。这是一个例子:

(assert (forall ((x Bool) (y Bool))
        (!  (=> (and (known x) (known y)) (known (xor x y)))
            :weight 10)))

3) 禁用电子匹配引擎。然后,Z3 将仅使用 MBQI(基于模型的量词实例化)引擎,这对于此类问题更为有效。要禁用电子匹配,我们应该使用

(set-option :smt.ematching false)

备注:在 Z3 版本 <= 4.3.1 中,此选项称为 (set-option :ematching false)

关于z3 - 推理 XOR 时爆炸式内存使用(所有 AC 理论?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17494973/

相关文章:

python - 我们如何计算 Z3 sat 求解器的运行时间

z3 - Z3 中的增量求解如何工作?

python - 为字符串约束设置求解器

parsing - Z3 C++,如何解析smt-competition unsat核心实例

z3 - SMTLIB/z3/stp : Meaning of underscore?

z3 - 可以从Z3得到最终的CNF公式吗?

z3 - 我想知道Z3是否支持输入文件包含另一个文件

z3 - 具有自定义理论的 SMT 求解器?

java - 使用 "for all"与未解释的排序 JAVA API

c++ - 在 z3 中设置成员关系