Could you please explain the deMorgan rules as simply as possible (e.g. to someone with only a secondary school mathematics background) ?
相关问题
- Chaining methods with &&
-
operator |= on std::vector
- True + True = 2. Elegantly perform boolean arithme
- tensorflow: check if a scalar boolean tensor is Tr
- OR, AND Operator
相关文章
- tensorflow: check if a scalar boolean tensor is Tr
- OR, AND Operator
- VBA: Why would the Not operator stop working? [dup
- Why are products called minterms and sums called m
- The operator > is undefined for the argument type(
- Is there a less convoluted way to compare file ver
- Three.js polygon triangulation fails in pseudo dup
- Is there XNOR (Logical biconditional) operator in
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.
We have two values:
T
andF
.We can combine these values in three ways:
NOT
,AND
, andOR
.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
works on two values:AND
isT
only when both its arguments (the values ofx
andy
in the truth table) areT
— andF
otherwise.OR
isT
when at least one of its arguments isT
: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 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.