[英]How to simplify x && (!y || (y && z))
Is there a better way to check whether x && (!y || (y && z))
is true? 有没有更好的方法来检查
x && (!y || (y && z))
是否正确? I guess I could create a function for that and do something like x && not_or_and(y, z)
to mitigate some of the pain. 我想我可以为此创建一个函数,然后执行
x && not_or_and(y, z)
来减轻某些痛苦。 But is this really all I can do? 但这真的是我能做的吗?
Ignoring side effects in the expressions, this is logically equivalent 忽略表达式中的副作用,这在逻辑上是等效的
x && (!y || z)
The additional check you're doing in for y
in (y && z)
is redundant, because if you get to the point where you need to check that part of the expression at all, you've already determined that !y
is false, which implies that y
is true. 您在
(y && z)
中为y
进行的额外检查是多余的,因为如果到达需要完全检查表达式的那一部分的位置,则您已经确定!y
为假,这意味着y
为真。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.