previous | start | next

## DeMorgan's Law(`futval.cpp`)

- Humans generally have a hard time comprehending logical conditions with not operators applied to and/or expressions.

  >     if (!(country == "USA"
  >           && state != "AK"
  >           && state != "HI"))
  >        shipping_charge = 20.00;

- DeMorgan's Law can be used to simplify these Boolean expressions.
- DeMorgan's Law has two forms:

  !(A && B) | is the same as | !A || !B
  !(A || B) | is the same as | !A && !B

- Pay particular attention to the fact that the and and or operators are reversed by moving the not inwards.
- Example:

  >     state != "AK" && state != "HI"

  means

  >     !(state == "AK") && !(state == "HI")

  Applying DeMorgan's Law to the original expression yields

  >     !(state == "AK" || state == "HI")

previous | start | next