布尔代数 - 为什么不是(真和假)真?

Boolean Algebra - Why is not(True and False) True?

我正在写书 "learn python the hard way"。在练习 27 (http://learnpythonthehardway.org/book/ex27.html) 中,它从布尔代数开始。

所以我的问题是: 为什么 not(True and False) 是真的?

我怎么理解的,应该和False and True一样吧。

你的解释不正确,见De Morgan's laws;具体来说合取的否定是否定的析取

not (True and False)连词的否定 == not(a and b))等价于False or Truea否定的析取 == (not a) or (not b));请注意从 andor!

的切换

你也可以算出步骤:

  • not(True and False)
    • 先算出括号里的部分,True and False -> False
  • 将该结果代回表达式:not(False) -> True.

not (True and False) 首先简化为 not (False),然后进一步简化为 True.

你应该看看 De Morgan's laws,其中(非正式地)指出:

"not (A and B)" is the same as "(not A) or (not B)"

also, "not (A or B)" is the same as "(not A) and (not B)".

所以在你的情况下 not(True and False)not(True) or not(False) 相同,后者与 False or True 相同,即 True

让我们一步一步来:

(True and False) 的计算结果为 (False)

not (False) 的计算结果为 True

足够简单:)

按照运算顺序,括号内的先解,用变量看:

a == True and False == False

not(True and False) == not(a) == not(False) == True

你想到的是:

not(True) and not(False)

这确实是错误的,因为:

a == not(True) == False
b == not(False) == True

not(True) and not(False) == a and b == False and True == False