DeMorgan’s
Law shows how to simplify expressions in which not operators (!) is applied to terms joined by the && or ||
operators.
The computer doesn’t care, but humans generally have a hard
time comprehending logical conditions with not operators applied to and/or
expressions. De Morgan’s law, named after the mathematician Augustus Law
(1805-1871), can be used to simplify these Boolean expressions. De Morgan’s law
has two forms: one for negation of an and expression and one for the negation of an or expression:
!(A && B) is
the same as !A || !B
!(A || B) is the same
as !A && !B
Pay particular attention to the face that the
and and
or operators are reversed by moving the not inwards. For example, the
negation of “the
input is S or the input M”,
!(input.equals(“S”) || input.equals(“M”))
is equivalent to
!input.equals(
“S”) && !input.equals(“M”)
or
!(0 < amount && amount < 1000)
is equivalent to
!(0 < amount ) ||
(amount < 1000)
which can be further simplified to
0 >=
amount || amount >= 1000
Note that the opposite of <is>=, not >!
Figure them out make sure they are equivalent.
We can discuss this Wednesday