APrep Open the app

AP Computer Science A · Unit 2: Selection & Iteration

2.6 Equivalent Boolean Expressions

Boolean logic laws

De Morgan's Laws let you rewrite negated compound expressions: `!(a && b)` is equivalent to `!a || !b`, and `!(a || b)` is equivalent to `!a && !b`. These transformations preserve logical meaning while changing the structure — useful for simplifying or clarifying conditions in code.

Short-circuit evaluation

Java's `&&` and `||` use short-circuit evaluation: they stop evaluating as soon as the result is determined. In `a && b`, if `a` is false, `b` is never evaluated. In `a || b`, if `a` is true, `b` is never evaluated. This matters for efficiency and avoiding errors (like null checks before method calls).

Recognizing equivalence

Two Boolean expressions are equivalent if they always produce the same result for every possible input. You can verify equivalence using a truth table — listing all combinations of variable values and comparing outputs. Simplified or rewritten expressions should match the original's truth table exactly.

Key terms

De Morgan's Law (AND)
!(a && b) is equivalent to !a || !b
De Morgan's Law (OR)
!(a || b) is equivalent to !a && !b
Short-circuit evaluation
Java stops evaluating a Boolean expression as soon as the result is determined (e.g., && stops if the first part is false).
Equivalent Boolean expressions
Expressions that produce the same result for every possible combination of input values.
Truth table
A table listing all input combinations and their corresponding output, used to verify logical equivalence.

Try an AP-style question

Which is equivalent to !(a && b)?

  1. !a && !b
  2. !a || !b
  3. a || b
  4. !a && b
Show the answer

B. De Morgan's law.

Practice 8 AP-style questions with instant explanations, flashcards and spaced review.

Study 2.6 free in APrep