Topic 2.6 — Comparing Boolean Expressions

Goal: analyze boolean expressions that are written in different ways but represent the same logic, and recognize when two expressions are not equivalent.

The big idea

Two boolean expressions can look different but still be logically equivalent. AP CSA loves questions like: “Which expression means the same thing as the original?”

You’ll use logic rules (especially De Morgan’s Laws) + careful reasoning about ranges.

Quick equivalence examples

  • !(x == y) is equivalent to x != y
  • !(x < y) is equivalent to x >= y
  • !(x > y) is equivalent to x <= y

De Morgan’s Laws (most important rule here)

When you negate a compound condition, you flip AND/OR and negate each part.

Original Equivalent
!(A && B) (!A) || (!B)
!(A || B) (!A) && (!B)

Example: negate a range check

Start with: “x is between 10 and 20 inclusive.”

// In range:
(x >= 10) && (x <= 20)

// NOT in range:
!((x >= 10) && (x <= 20))

// Apply De Morgan:
(x < 10) || (x > 20)

Common trap: mixing up NOT-in-range

NOT-in-range is outside the range (OR), not “both sides at once.”

// WRONG (impossible to be both):
(x < 10) && (x > 20)

// RIGHT:
(x < 10) || (x > 20)

Equivalent conditions in if statements

These two blocks do the same thing:

// Version 1
if (x >= 0) {
  y++;
}

// Version 2
if (!(x < 0)) {
  y++;
}

Sometimes “looks similar” but isn’t equivalent

Be careful: changing parentheses changes meaning.

// Not equivalent in general:
(a && b) || c
a && (b || c)

Try a counterexample: let a=false, b=false, c=true.

Exam mindset

  • Use De Morgan’s Laws when you see ! around parentheses.
  • For “NOT in range,” think “below OR above.”
  • To prove non-equivalence, find a counterexample (one set of values where results differ).
  • Parentheses matter—don’t “distribute” operators incorrectly.

Quick self-check

  1. Rewrite !(A && B) without the outer !.
  2. Rewrite !(A || B) without the outer !.
  3. Rewrite “x is NOT between 5 and 8 inclusive.”
  4. Is !(x == 3) the same as x != 3?
  5. Give a counterexample to show two expressions aren’t equivalent.

← Back to Unit 2 topics