DeMorgan’s Laws

DeMorgan’s laws were developed by Augustus De Morgan in the 1800s. They show how to handle the negation of a complex conditional.

  • not (a and b) is the same as (not a) or (not b)
  • not (a or b) is the same as (not a) and (not b)

Notice that an and is changed to an or by negation and an or to an and.

Java uses ! to indicate negation. Applying DeMorgan’s Laws to !(x < 3 && y > 2) means that this complex conditional will be true when (x >= 3 || y <= 2) and !(x < 3 || y > 2) is the same as (x >= 3 && y <= 2).

For more information about DeMorgan’s laws see http://en.wikipedia.org/wiki/De_Morgan’s_laws.

Next Section - Common Mistakes