(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
答案 0 :(得分:2)
例如
!(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
(多行分解,因为一行太长)
注意上面,因为我们有一个表达式作为其中一个术语,我们递归地应用了DeMorgan定律(准确地说是两次)。
更多例子
!(A > B || A + B == 0) = A <= B && A + B != 0
!(A >= 2 && A < 8) = A < 2 || A >= 8
答案 1 :(得分:0)
您可以使用此等式!(a && b) = !a || !b
一步一步:
!((previous = 4 || previous = 5) && current = 2)
!(previous = 4 || previous = 5) || !(current = 2)
(previous != 4 && previous != 5) || current != 2