De Morgans Law

Logical Operators

De Morgans Law

🙋 Need help? Ask an expert now!

De Morgan's Law is helpful to remember for the AP exam because it will be useful with questions regarding boolean expressions. De Morgan's Law show how the NOT operator (!) can be distributed when it exists outside a set of parenthesis. Look below for a few examples of how De Morgan's Law works.

DeMorgansLawExample.java
package exlcode;

public class DeMorgansLawExample {
  
  public static boolean exampleVariableOne = true;
  public static boolean exampleVariableTwo = false;

  public static void main(String[] args) {
    // The two boolean expressions below are equal
    if (!(exampleVariableOne && exampleVariableTwo)) {
      System.out.println("The boolean expression is true");
    } else {
      System.out.println("The boolean expression is false");
    }
    if (!exampleVariableOne || !exampleVariableTwo) {
      System.out.println("The boolean expression is true");
    } else {
      System.out.println("The boolean expression is false");
    }
  }
}

Some of the more common iterations for De Morgan's Law:

  1. !(A && B) is the same as !A || !B
  2. !(A || B) is the same as !A && !B
  3. !(C > D) is the same as C <= D
  4. !(C < D) is the same as C >= D
  5. !(C >= D) is the same as C < D
  6. !(C <= D) is the same as C > D
  7. !(E == F) is the same as E != F
  8. !(E != F) is the same as E == F

Remember, you do not have to limit yourself to two operands when you work with the "AND" operator and the "OR" operator. !(A && B && C) is the same as !A||!B||!C. For the iterations shown above, A and B have to be boolean values, C and D have to be numbers and E and F may be a variety of data types.

Edit Me on GitHub!

Application Question

Which of the following expressions is equivalent to: !(varOne || varTwo)