德摩根规则解释
您能否尽可能简单地解释一下德摩根规则(例如,向仅拥有中学数学背景)?
Could you please explain the De Morgan's rules as simply as possible (e.g. to someone with only a secondary school mathematics background)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
布尔代数概述
我们有两个值:
T
和F
。我们可以通过三种方式组合这些值:
NOT
、AND
和OR
。NOT
NOT
是最简单的:NOT T = F
NOT F = T
我们可以将其写成一个真值表 :
为了简洁
起见,将
NOT
视为补码,即将一个值转换为另一个值。AND
AND
适用于两个值:仅当其两个参数(
的值)时,
和AND
才是T
真值表中的 xy
)为T
,否则为F
。OR
OR
当至少一个参数为T
时为T
:组合
我们可以定义更复杂的组合。例如,我们可以写一个
x AND (y OR z)
真值表,第一行如下。一旦我们知道如何计算
x AND (y OR z)
,我们就可以填写表格的其余部分。要评估组合,请评估各个部分并从那里开始工作。括号显示首先评估哪些部分。你从普通算术中学到的知识将帮助你解决这个问题。假设您有
10 - (3 + 5)
。首先,您评估括号中的部分以获取并像往常一样评估它以获得答案,
2
。评估这些表达式的工作方式类似。我们从上面知道了 OR 的工作原理,因此我们可以稍微扩展我们的表:
现在几乎就像我们回到了 x AND y 表。我们只需替换 y OR z 的值并进行评估。在第一行中,我们的
which 与which 相同,
只是
T
。我们对
x
、y
和z
的所有 8 个可能值(x
的 2 个可能值)重复相同的过程> 乘以y
的 2 个可能值乘以z
的 2 个可能值)以获得某些表达式可能比其需要的更复杂。例如,
换句话说,
NOT (NOT x)
等价只是x
。DeMorgan 规则
DeMorgan 规则是方便的技巧,让我们可以在符合特定模式的等效表达式之间进行转换:
NOT (x AND y) = (NOT x) OR (NOT y)
NOT (x OR y ) ) = (NOT x) AND (NOT y)
(您可能会认为这是
NOT
如何通过简单的AND
和OR
进行分布> 表达式。)您的常识可能已经理解这些规则!例如,想一想“你不能同时出现在两个地方”这样的民间智慧。我们可以让它符合第一条规则的第一部分:
应用规则,这是“你不在这里或你不在那里”的另一种说法。
练习:你会如何用简单的英语表达第二条规则?
对于第一条规则,让我们看一下等号左侧表达式的真值表。
现在是右侧:
两个表中的最终值相同。这证明了表达式是等价的。
练习:证明表达式
NOT (x OR y)
和(NOT x) AND (NOT y)
是等价的。Overview of boolean algebra
We have two values:
T
andF
.We can combine these values in three ways:
NOT
,AND
, andOR
.NOT
NOT
is the simplest:NOT T = F
NOT F = T
We can write this as a truth table:
For conciseness
Think of
NOT
as the complement, that is, it turns one value into the other.AND
AND
works on two values:AND
isT
only when both its arguments (the values ofx
andy
in the truth table) areT
— andF
otherwise.OR
OR
isT
when at least one of its arguments isT
:Combining
We can define more complex combinations. For example, we can write a truth table for
x AND (y OR z)
, and the first row is below.Once we know how to evaluate
x AND (y OR z)
, we can fill in the rest of the table.To evaluate the combination, evaluate the pieces and work up from there. The parentheses show which parts to evaluate first. What you know from ordinary arithmetic will help you work it out. Say you have
10 - (3 + 5)
. First you evaluate the part in parentheses to getand evaluate that as usual to get the answer,
2
.Evaluating these expressions works similarly. We know how
OR
works from above, so we can expand our table a little:Now it's almost like we're back to the
x AND y
table. We simply substitute the value ofy OR z
and evaluate. In the first row, we havewhich is the same as
which is simply
T
.We repeat the same process for all 8 possible values of
x
,y
, andz
(2 possible values ofx
times 2 possible values ofy
times 2 possible values ofz
) to getSome expressions may be more complex than they need to be. For example,
In other words,
NOT (NOT x)
is equivalent to justx
.DeMorgan's rules
DeMorgan's rules are handy tricks that let us convert between equivalent expressions that fit certain patterns:
NOT (x AND y) = (NOT x) OR (NOT y)
NOT (x OR y) = (NOT x) AND (NOT y)
(You might think of this as how
NOT
distributes through simpleAND
andOR
expressions.)Your common sense probably already understands these rules! For example, think of the bit of folk wisdom that "you can't be in two places at once." We could make it fit the first part of the first rule:
Applying the rule, that's another way of saying "you're not here or you're not there."
Exercise: How might you express the second rule in plain English?
For the first rule, let's look at the truth table for the expression on the left side of the equals sign.
Now the righthand side:
The final values are the same in both tables. This proves that the expressions are equivalent.
Exercise: Prove that the expressions
NOT (x OR y)
and(NOT x) AND (NOT y)
are equivalent.看了一些答案,我想我可以通过使用实际上彼此相关的条件来更好地解释它。
德摩根定律指的是这样一个事实:有两种相同的方式可以编写两个条件的任意组合 - 具体来说,
AND
组合(两个条件都必须为真)和OR
组合(其中任何一个都可以是真的)。示例如下:德摩根定律第 1 部分
声明:爱丽丝有一个兄弟姐妹。
条件:爱丽丝有一个兄弟
或
爱丽丝有一个姐妹。相反:爱丽丝是独生子(
没有
有兄弟姐妹)。条件:爱丽丝
没有
有兄弟,并且
她没有
有姐妹。换句话说:
NOT [A OR B] = [NOT A] AND [NOT B]
德摩根定律第 2 部分
声明: Bob 是一名汽车司机。
条件:鲍勃有一辆车
并且
鲍勃有驾照。相反:鲍勃
不是
汽车司机。条件:鲍勃
没有
有汽车,或
鲍勃没有
有驾照。换句话说:
NOT [A AND B] = [NOT A] OR [NOT B]
。我认为这对于 12 岁的孩子来说不会那么困惑。它肯定比所有这些关于真值表的废话更容易混淆(即使我看到所有这些都感到困惑)。
Looking over some of the answers, I think I can explain it better by using conditions that are actually related to each other.
DeMorgan's Law refers to the fact that there are two identical ways to write any combination of two conditions - specifically, the
AND
combination (both conditions must be true), and theOR
combination (either one can be true). Examples are:Part 1 of DeMorgan's Law
Statement: Alice has a sibling.
Conditions: Alice has a brother
OR
Alice has a sister.Opposite: Alice is an only child (does
NOT
have a sibling).Conditions: Alice does
NOT
have a brother,AND
she doesNOT
have a sister.In other words:
NOT [A OR B] = [NOT A] AND [NOT B]
Part 2 of DeMorgan's Law
Statement: Bob is a car driver.
Conditions: Bob has a car
AND
Bob has a license.Opposite: Bob is
NOT
a car driver.Conditions: Bob does
NOT
have a car,OR
Bob doesNOT
have a license.In other words:
NOT [A AND B] = [NOT A] OR [NOT B]
.I think this would be a little less confusing to a 12-year-old. It's certainly less confusing than all this nonsense about truth tables (even I'm getting confused looking at all of those).
它只是重述真值陈述的一种方法,它可以提供更简单的方法来编写条件语句来完成同样的事情。
用简单的英语来说:
当某物不是这个或那个时,它也不是这个或不是那个。
当某件事不是这个或那个时,它也不是这个或不是那个。
注意:鉴于英语中“or”一词的不精确性,我在前面的示例中使用它来表示非排他性或。
例如,以下伪代码是等效的:
如果不是(A 或 B)...
如果(非 A)且(非 B)...
如果非(A 且 B)...
如果不是(A)或不是(B)...
It is just a way to restate truth statements, which can provide simpler ways of writing conditionals to do the same thing.
In plain English:
When something is not This or That, it is also not this and not that.
When something is not this and that, it is also not this or not that.
Note: Given the imprecision of the English language on the word 'or' I am using it to mean a non-exclusive or in the preceding example.
For example the following pseudo-code is equivalent:
If NOT(A OR B)...
IF (NOT A) AND (NOT B)....
IF NOT(A AND B)...
IF NOT(A) OR NOT(B)...
如果您是一名正在寻找未成年饮酒者的警察,您可以执行以下操作之一,德摩根定律表示它们的作用相同:
公式 1(A 和 B)
配方 2(非(非 A 或非 B))
顺便说一句,这不是我的例子。据我所知,这是科学实验的一部分,其中以不同的方式表达相同的规则,以找出人们理解它们的能力有多大差异。
If you're a police officer looking for underage drinkers, you can do one of the following, and De Morgan's law says they amount to the same thing:
FORMULATION 1 (A AND B)
FORMULATION 2 (NOT(NOT A OR NOT B))
This, by the way, isn't my example. As far as I know, it was part of a scientific experiment where the same rule was expressed in different ways to find out how much of a difference it made in peoples' ability to understand them.
“他既没有汽车,也没有公共汽车。”与“他没有汽车,也没有公共汽车”的意思相同。
“他没有汽车和公共汽车。”与“他要么没有汽车,要么没有公共汽车,我不确定是哪一个,也许他两者都没有”的意思是一样的。
当然,用简单的英语来说“他没有汽车和公共汽车。”强烈暗示他至少拥有这两件事中的一件。但是,严格来说,从逻辑的角度来看,如果他不具备其中任何一个,那么该陈述也是正确的。
形式上:
在英语中,“或”往往意味着一种选择,你不这样做两者兼而有之。在逻辑中,“或”始终与英语中的“和/或”含义相同。
这是一个真值表,显示了它是如何工作的:
第一种情况:not(cor或bus)=(非汽车)和(非公共汽车)
第二种情况:not(汽车和公共汽车)=(非汽车)或(非公共汽车)
"He doesn't have either a car or a bus." means the same thing as "He doesn't have a car, and he doesn't have a bus."
"He doesn't have a car and a bus." means the same thing as "He either doesn't have a car, or doesn't have a bus, I'm not sure which, maybe he has neither."
Of course, in plain english "He doesn't have a car and a bus." has a strong implication that he has at least one of those two things. But, strictly speaking, from a logic standpoint the statement is also true if he doesn't have either of them.
Formally:
In english, 'or' tends to mean a choice, that you don't have both things. In logic, 'or' always means the same as 'and/or' in English.
Here's a truth table that shows how this works:
First case: not (cor or bus) = (not car) and (not bus)
Second case: not (car and bus) = (not car) or (not bus)
画一个简单的维恩图,两个相交的圆。把A放在左边,B放在右边。现在(A和B)显然是相交位。所以 NOT(A 和 B) 是不在相交位中的所有内容,即两个圆的其余部分。给它上色。
像以前一样再画两个相交的圆圈,A 和 B。现在 NOT(A) 是右圆 (B) 中的所有内容,但不是交集,因为这显然是 A 和 B。将其涂上颜色。类似地,NOT(B) 是左圆中的所有内容,但不是交集,因为那是 B 也是 A。给它涂上颜色。
两幅图看起来一样。您已经证明 NOT(A 和 B) = NOT(A) 或 NOT(B)。另一个案例留给学生作为练习。
Draw a simple Venn diagram, two intersecting circles. Put A in the left and B in the right. Now (A and B) is obviously the intersecting bit. So NOT(A and B) is everything that's not in the intersecting bit, the rest of both circles. Colour that in.
Draw another two circles like before, A and B, intersecting. Now NOT(A) is everything that's in the right circle (B), but not the intersection, because that's obviously A as well as B. Colour this in. Similarly NOT(B) is everything in the left circle but not the intersection, because that's B as well as A. Colour this in.
Two drawings look the same. You've proved that NOT(A and B) = NOT(A) or NOT(B). T'other case is left as an exercise for the student.
德摩根定律允许您以不同的方式陈述一系列逻辑运算。它适用于逻辑和集合论,在集合论中,您可以使用补集来表示“非”,使用交集来表示“与”,使用并集来表示“或”。
德摩根定律允许您简化逻辑表达式,执行与乘法的分配性质非常相似的运算。
因此,如果您在类似 C 的语言中具有以下内容,
那么它在逻辑上等同于:
它也可以像这样工作:
变成
当然,您可以反向进行。
使用真值表很容易看出这些陈述的等价性。在真值表中,您只需布置变量 (x, y, z) 并列出这些变量的所有输入组合。然后,您可以为每个谓词或逻辑表达式提供列,并为给定的输入确定表达式的值。任何计算机科学、计算机工程或电气工程的大学课程都可能会让你对必须构建的真值表的数量和大小感到疯狂。
那么为什么要学习它们呢?我认为计算最大的原因是它可以提高更大逻辑表达式的可读性。有些人不喜欢在表达式前面使用逻辑 not
!
,因为他们认为如果错过它可能会让别人感到困惑。然而,使用德摩根定律对芯片门级的影响是有用的,因为某些门类型更快、更便宜,或者您已经为它们使用了整个集成电路,因此您可以减少所需的芯片封装数量。结果。DeMorgan's Law allows you to state a string of logical operations in different ways. It applies to logic and set theory, where in set theory you use complement for not, intersection for and, and union for or.
DeMorgan's Law allows you to simplify a logical expression, performing an operation that is rather similar to the distributive property of multiplication.
So, if you have the following in a C-like language
It is logically equivalent to:
It also works like so:
turns into
And you can, of course, go in reverse.
The equivalence of these statements is easy to see using something called a truth table. In a truth table, you simply lay out your variables (x, y, z) and list all the combinations of inputs for these variables. You then have columns for each predicate, or logical expression, and you determine for the given inputs, the value of the expression. Any university curriculum for computer science, computer engineering, or electrical engineering will likely drive you bonkers with the number and size of truth tables you must construct.
So why learn them? I think the biggest reason in computing is that it can improve readability of larger logical expressions. Some people don't like using logical not
!
in front of expressions, as they think it can confuse someone if they miss it. The impact of using DeMorgan's Law on the gate level of chips is useful, however, because certain gate types are faster, cheaper, or you're already using a whole integrated circuit for them so you can reduce the number of chip packages required for the outcome.不知道为什么我这些年来一直保留这个,但它在很多场合都被证明是有用的。感谢我十年级的数学老师贝利先生。他称之为德摩根定理。
当您将否定移入或移出括号时,逻辑运算符(AND、OR)会发生变化。
Not sure why I've retained this all these years, but it has proven useful on a number of occasions. Thanks to Mr Bailey, my grade 10 math teacher. He called it deMorgan's Theorem.
When you move the negation in or out of the brackets, the logical operator (AND, OR) changes.