1

的反义词是(previous = 4 || previous = 5) && current = 2什么?

我知道我可以把它写成!((previous = 4 || previous = 5) && current = 2),但现在它变成了一种会追捕我的东西,直到我找到答案。你如何在括号内分配负数?

这就是我的想法,但对我来说似乎不对。

!((previous = 4 || previous = 5) && current = 2

!(previous = 4 || previous = 5) || current != 2

(previous != 4 && previous != 5) || current != 2

4

2 回答 2

2

德摩根定律指出,当你取一个表达式的补码时(也就是说,当你取反时),你可以简单地交换所有的 OR 和 AND,并对每一项取反以获得所需的结果。

例如

!(A && B) = !A || !B

!(A || B) = !A && !B

!(A && !B) = !A || B

因此,应用这两个简单的规则,

!((previous = 4 || previous = 5) && current = 2) 
=
!(previous = 4 || previous = 5) || current != 2
=
(previous != 4 && previous != 5) || current != 2

(因为一行太长而分成多行)

注意上面,因为我们有一个表达式作为术语之一,所以我们递归地应用了德摩根定律(准确地说是两次)。

更多示例

!(A > B || A + B == 0) = A <= B && A + B != 0

!(A >= 2 && A < 8) = A < 2 || A >= 8
于 2013-09-17T18:10:47.717 回答
0

你可以用这个方程得到答案!(a && b) = !a || !b

所以一步一步:

!((previous = 4 || previous = 5) && current = 2)
!(previous = 4 || previous = 5) || !(current = 2)
(previous != 4 && previous != 5) || current != 2
于 2013-09-17T18:00:21.820 回答