[英]Simplfying Expression : Z3 SMT Solver
Executing the following query with the Z3 solver:使用 Z3 求解器执行以下查询:
(declare-const c0 Int)
(declare-const c1 Int)
(declare-const c2 Int)
(assert (exists ((c0_s Int) (c1_s Int) (c2_s Int))
(and
(= (+ c0 c1 c2) 5) (>= c0 0) (>= c1 1) (>= c2 1)
(= c0_s c0) (= c1_s (- c1 1)) (= c2_s (+ c2 1))
(= c2_s 3) (= (+ c0_s c1_s) 2)
))
)
(apply (then qe ctx-solver-simplify propagate-ineqs))
produces the following output:产生以下输出:
(goals
(goal
(>= c0 0)
(<= c0 2)
(>= c1 1)
(<= c1 3)
(<= (+ (* (- 1) c0) (* (- 1) c1)) (- 3))
(<= (+ c1 c0) 3)
(= c2 2)
:precision precise :depth 3)
)
where I was expecting a result from the Z3 solver like this:我期待 Z3 求解器的结果是这样的:
(goals
(goal
(>= c0 0)
(<= c0 2)
(>= c1 1)
(<= c1 3)
(= (+ c1 c0) 3)
(= c2 2)
:precision precise :depth 3)
)
Can anyone explain why Z3 is producing such a complex result instead of what I expected?谁能解释为什么 Z3 产生如此复杂的结果而不是我的预期? Is there a way to get Z3 to simplify this output?
有没有办法让 Z3 简化这个输出?
You may get a more detailed answer from a member of the core Z3 team, but from my experience working with Z3's integer solver at a low level, I can give a bit of intuition as to why this is happening.您可能会从核心 Z3 团队的成员那里得到更详细的答案,但根据我在低级别使用 Z3 整数求解器的经验,我可以对为什么会发生这种情况给出一些直觉。
Briefly, in order to solve integer equations, Z3's integer theory solver expects all of its constraints to appear in a very particular and restricted form.简而言之,为了求解整数方程,Z3 的整数理论求解器希望其所有约束都以非常特殊和受限的形式出现。 Expressions that do not follow this form must be rewritten before they are presented to the solver.
不遵循这种形式的表达式在呈现给求解器之前必须重写。 Normally this happens internally by a theory rewriter, and any expression can be used in the input constraint set without issue.
通常,这由理论重写器在内部发生,并且可以在输入约束集中使用任何表达式而不会出现问题。
The restrictions that apply here (that I am aware of), which help explain why you are seeing this strange-looking output, are as follows:此处适用的限制(我知道)有助于解释为什么您会看到这个看起来很奇怪的输出,如下所示:
(= ab)
as two separate inequality constraints (<= ab)
and (>= ab)
.(= ab)
为两个单独的不等式约束(<= ab)
和(>= ab)
。 This is why you're seeing two separate constraints over your variables in the model instead of just one equality. In short, what you're seeing is likely an artifact of how the arithmetic theory solver represents constraints internally.简而言之,您所看到的可能是算术理论求解器如何在内部表示约束的人工制品。
Since the output of your instance is a goal and not a model or proof, these expressions may not have been fully simplified yet, as I believe that intermediate goals are not always simplified (but I don't have experience with this part of the solver).由于您的实例的输出是一个目标而不是模型或证明,因此这些表达式可能尚未完全简化,因为我相信中间目标并不总是简化(但我对求解器的这部分没有经验)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.