我可以用更简单的形式重写这个布尔表达式吗?

can I rewrite this boolean expression in a simpler form?

有没有办法以更简单(但等效)的形式重写此表达式?

!(foo && !bar)

如前所述,这可以用德摩根定律解决。简单规则:

!(A && B) <-> !A || !B

想想这意味着什么:A && B意味着"Both A and B are true."因此,!(A && B)意味着"it's not the case that both A and B are true"——换句话说,它们中的一个或两个都是假的。

!(A || B) <-> !A && !B

这样想:(A || B) 意味着 "either A is true, or B is true (or both A and B are true)." 因此,!(A || B) 意味着 "it's not the case that either A is true or that B is true" - 即两者都不正确。

因此,

!(foo && !bar)

意味着 "foo" 和 "!bar" 都不是真的。至少其中一项必须是假的。

!(foo && !bar) -> (!foo || !!bar) -> (!foo || bar)

重要说明: 约定俗成(在数学上和许多编程语言中)"or" 包含或,因此 (A || B) 表示 "either A is true, B is true, or both are true."

还有一个符号:“->”表示 "implies"(在数学意义上),“<->”表示语句是等价的(即它们相互暗示);这有时也称为 "if and only if" 或简称为 "iff."