简体   繁体   English

如何比较两个逻辑表达式的相等性?

[英]How to compare two logical expressions for equality?

I have two logical expression (just examples): 我有两个逻辑表达式(仅作为示例):

!(n >= x || n < -y) !(n> = x || n <-y)

and

n < x && n >= -y n <x && n> = -y

Are there any tools out there to compare expressions like these to see if they are logically equal for all values? 是否有工具可以比较这些表达式,以查看它们在逻辑上对于所有值是否相等? Or just to help me find the most compact/simple form? 还是只是为了帮助我找到最紧凑/最简单的形式?

The "most compact/simple form" answer would depend on your notion of compactness/simplicity. “最紧凑/最简单的形式”的答案将取决于您的紧凑/简单概念。 For instance, you can perform a number of simplification steps such as conversion to the conjunctive normal form (elimination of ||) followed by negation elimination (replacing !(n > y) by (n <= y)). 例如,您可以执行许多简化步骤,例如转换为合取范式(消除||),然后消除否定符号(将!(n> y)替换为(n <= y))。

Equivalence of formulas F and G can be checked by taking the conjunction of F and the negation of G and checking for satisfiability of F && !G with, eg, a constraints solver. 公式F和G的等价关系可以通过将F与G的取反结合起来并使用约束求解器检查F &&!G的可满足性来检查。 You should be careful with your domain though since the result depends on your domain (integers, rationals, reals): 2 < n && n < 3 is not satisfiable for the integers, but it is satisfiable for the reals! 但是,您应谨慎对待自己的域,因为结果取决于您的域(整数,有理数,实数):2 <n && n <3对于整数不是可满足的,但对于实数是可满足的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM