How do De Morgan's laws let you rewrite a negated boolean expression into an equivalent one?
Topic 3.6 Equivalent Boolean Expressions: apply De Morgan's laws and truth tables to produce equivalent boolean expressions and to simplify negations of compound conditions.
A focused answer to AP CSA Topic 3.6, covering De Morgan's laws for negating && and ||, using truth tables to prove equivalence, simplifying double negation, and rewriting conditions to remove a leading !, with a fully worked example.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topic 3.6) wants you to recognize and produce equivalent boolean expressions: two expressions that give the same result for every combination of inputs. The headline tool is De Morgan's laws, which tell you how to push a ! (negation) inside a compound && or || expression. You should also be able to confirm equivalence with a truth table and to simplify a double negation. This is heavily tested in multiple choice, where you must spot the one equivalent rewrite among near-misses.
What equivalence means
De Morgan's laws
These let you remove an outer ! from a compound condition, which often reads more clearly. For instance, !(score >= 60 && attendance >= 80) becomes score < 60 || attendance < 80 ("failed on either count").
Negating relational operators
When you push a negation onto a single comparison, the operator flips to its opposite:
!(x > y)isx <= y!(x >= y)isx < y!(x < y)isx >= y!(x <= y)isx > y!(x == y)isx != y!(x != y)isx == y
A frequent error is negating > to < (it is <=) or >= to <= (it is <). The boundary case is what changes: the negation of "greater than" includes equality.
Double negation
!!A simplifies to A: applying ! twice returns the original value. So !(!ready) is just ready. Watch for this hidden inside De Morgan rewrites.
Proving equivalence with a truth table
A truth table lists every combination of the input variables and the result of each expression. If the two result columns match in every row, the expressions are equivalent.
Try this
Q1. Rewrite !(p || q) without the leading !. [1 point]
- Cue.
!p && !q- De Morgan flips||to&&and negates each operand.
Q2. Explain why !(x >= 5) is x < 5 and not x <= 5. [2 points]
- Cue.
x >= 5includesx == 5; its negation must exclude5, leaving everything strictly less than 5, sox < 5.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2022 (style)1 marksMultiple choice. Which of the following is equivalent to the expression `!(x > 0 && y < 5)` for all values of `x` and `y`?
(A) `x <= 0 || y >= 5`
(B) `x < 0 && y > 5`
(C) `x <= 0 && y >= 5`
(D) `x > 0 || y < 5`
(E) `!x > 0 || !y < 5`
Show worked answer →
The answer is (A).
By De Morgan's law, !(A && B) equals !A || !B. Here A is x > 0 and B is y < 5. Negating each: !(x > 0) is x <= 0, and !(y < 5) is y >= 5. The AND becomes an OR. So the equivalent is x <= 0 || y >= 5. (C) wrongly keeps the AND; (B) negates incorrectly; (E) is not valid Java and mis-negates.
Markers reward applying De Morgan's law: negation flips && to || and negates each operand, and !(>) becomes <=, !(<) becomes >=.
AP 2020 (style)3 marksFree response (code writing). A `boolean` expression `!(a >= 10 || b == 0)` appears in a program. Rewrite it as an equivalent expression that does not use the leading `!` operator, and write a one-line comment justifying your rewrite by naming the rule used.
Show worked answer →
A 3-point question testing De Morgan's law applied to ||.
// De Morgan: !(P || Q) becomes !P && !Q
boolean result = (a < 10 && b != 0);
Point 1: !(P || Q) becomes !P && !Q, flipping || to &&. Point 2: !(a >= 10) is a < 10, and !(b == 0) is b != 0. Point 3: the comment names De Morgan's law as the justification. A common error is to flip the operands but keep ||, or to negate >= to > instead of <.
Related dot points
- Topic 3.5 Compound Boolean Expressions: combine boolean expressions with the logical operators && (and), || (or) and ! (not), applying short-circuit evaluation.
A focused answer to AP CSA Topic 3.5, covering the logical operators && , || and !, their truth tables, operator precedence and short-circuit evaluation, why short-circuiting prevents errors, and how to trace a compound condition, with a fully worked example.
- Topic 3.1 Boolean Expressions: evaluate expressions formed with the relational operators (<, >, <=, >=, ==, !=) that produce a boolean result of true or false.
A focused answer to AP CSA Topic 3.1, covering the six relational operators, how they compare numeric primitives to produce a boolean, the difference between == and =, comparing doubles, and how relational operators combine with arithmetic, with a fully traced worked evaluation.
- Topic 3.4 else if Statements: use an if / else if / else chain so that the first true condition runs its block and the rest are skipped, selecting exactly one outcome.
A focused answer to AP CSA Topic 3.4, covering the if / else if / else chain, why the first true condition wins and later ones are skipped, why ordering matters, the role of the final else, and how to trace a multi-branch decision, with a fully worked example.
- Topic 3.3 if-else Statements: use a two-way if-else statement so that exactly one of two code blocks runs depending on whether the boolean condition is true or false.
A focused answer to AP CSA Topic 3.3, covering two-way selection with if-else, the guarantee that exactly one branch runs, how the else attaches to the nearest if, nested if-else, and how to trace each branch, with a fully worked example.
- Topic 3.7 Comparing Objects: compare object references with == and !=, compare object contents with equals, and detect a null reference, understanding the difference between identity and equality.
A focused answer to AP CSA Topic 3.7, covering reference equality with == and !=, content equality with the equals method, comparing against null, why two equal-looking objects can be unequal by ==, and using equals/compareTo for Strings, with a fully worked example.
Sources & how we know this
- AP Computer Science A Course and Exam Description — College Board (2025)