---
title: "De Morgan's Law — AP Comp Sci A Definition & Examples"
description: "De Morgan's law rewrites negated Boolean expressions: !(a && b) ≡ !a || !b and !(a || b) ≡ !a && !b. Master it for AP CSA Topic 2.6 equivalence questions."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 2"
---

# De Morgan's Law — AP Comp Sci A Definition & Examples

## Definition

De Morgan's law is a rule for rewriting negated Boolean expressions in AP CSA: !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b. When the ! distributes across parentheses, it flips each operand AND swaps && with || (EK 2.6.A.2).

## What It Is

De Morgan's law tells you how to push a negation inside [parentheses](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") in a [Boolean expression](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink"). The rule has two halves. First, `!(a && b)` is equivalent to `!a || !b`. Second, `!(a || b)` is equivalent to `!a && !b`. The pattern is the same both times. Negate each piece, then swap the operator. The `&&` becomes `||` and the `||` becomes `&&`.

The intuition is everyday logic. "It's NOT true that I have both homework AND practice" means "I'm missing homework OR I'm missing practice." If the combo fails, at least one piece failed. In Java, this also applies to [relational operators](/ap-comp-sci-a/key-terms/relational-operator "fv-autolink") when you simplify. For example, `!(score < 0 || score > 100)` becomes `score >= 0 && score <= 100`. Notice that negating `score < 0` gives `score >= 0`, not `score > 0`. The negation of `<` is `>=`, because "not less than" includes equal.

## Why It Matters

De Morgan's law lives in Topic 2.6 (Equivalent Boolean Expressions) in [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink"): Selection and Iteration. It directly supports learning objective [AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 2.6.A, comparing equivalent Boolean expressions, and it's named explicitly in EK 2.6.A.2. Two expressions are equivalent when they produce the same value in every case (EK 2.6.A.1), and De Morgan's law is your fastest tool for transforming one expression into another without building a full truth table. Beyond the exam, it's how you untangle messy negated conditions in `if` statements and loop conditions, which makes your selection and iteration code readable instead of a puzzle.

## Connections

### [Truth tables (Unit 2)](/ap-comp-sci-a/key-terms/truth-tables)

[Truth tables](/ap-comp-sci-a/key-terms/truth-tables "fv-autolink") are the proof behind De Morgan's law. If you ever doubt an equivalence, list every combination of true/false for the variables and check that both expressions match in every row. De Morgan's law is the shortcut; truth tables are the receipts.

### Object reference comparisons (Unit 2)

Topic 2.6 also covers comparing references with == and != and checking against [null](/ap-comp-sci-a/key-terms/null "fv-autolink"). You'll often combine these in compound conditions like !(obj == null || obj.equals(other)), and De Morgan's law lets you rewrite that as obj != null && !obj.equals(other).

### Selection statements and loop conditions (Unit 2)

Most De Morgan's questions hide inside if statements and while loops. A [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") that runs 'while not (done or error)' is the same as 'while not done and not error.' Rewriting exit conditions this way is the most common real use of the law in your own code.

## On the AP Exam

De Morgan's law shows up almost exclusively in multiple choice. A typical stem gives you a negated compound expression like `!(score < 0 || score > 100)` and asks which expression could replace it, or hands you two expressions and asks whether they're equivalent for all values. Another common format prints the result of expressions like `!(a && b) || c` for specific boolean values. Your job is mechanical but precise. Distribute the !, flip each operand, swap the operator, and remember that negating relational operators flips them to their opposites (`<` becomes `>=`, `>` becomes `<=`). No released FRQ names De Morgan's law directly, but FRQs constantly require correct boolean conditions, and applying it wrong (forgetting to swap && and ||) produces logic bugs that cost points.

## De Morgan's law vs Simply distributing the ! without swapping operators

The classic trap is rewriting !(a && b) as !a && !b. That's wrong. De Morgan's law requires two moves, not one. You negate each operand AND you swap the operator, so !(a && b) becomes !a || !b. Try a = true, b = false to see why. !(true && false) is true, but !true && !false is false. One counterexample in a truth table proves they aren't equivalent.

## Key Takeaways

- De Morgan's law states that !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b.
- When you distribute a negation, you must do two things: negate each operand and swap && with ||.
- Two Boolean expressions are equivalent only if they evaluate to the same value in every possible case, and a truth table can prove or disprove this.
- Negating a relational operator flips it to its full opposite, so !(x < 5) becomes x >= 5, not x > 5.
- The most common exam mistake is keeping the same operator after distributing the !, which a single truth-table row can expose as wrong.
- Use De Morgan's law to simplify negated conditions in if statements and loops, like turning !(score < 0 || score > 100) into score >= 0 && score <= 100.

## FAQs

### What is De Morgan's law in AP Computer Science A?

It's the rule in Topic 2.6 (EK 2.6.A.2) for rewriting negated Boolean expressions: !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b. The negation moves inside and the operator flips.

### Is !(a && b) the same as !a && !b?

No. !(a && b) equals !a || !b, with the operator swapped to ||. Test a = true, b = false: !(true && false) is true, but !true && !false is false, so they're not equivalent.

### How is De Morgan's law different from using a truth table?

De Morgan's law is a transformation rule that rewrites an expression instantly, while a truth table is the proof method that checks every combination of values (EK 2.6.A.1). On the exam, apply De Morgan's law for speed and fall back on a truth table when you're unsure.

### What is the negation of x < 5?

It's x >= 5, not x > 5. "Not less than 5" includes being equal to 5. Forgetting the equals case is one of the most common point-losers on equivalence MCQs.

### Is De Morgan's law actually tested on the AP CSA exam?

Yes. It's named in the CED under learning objective AP Comp Sci A 2.6.A (EK 2.6.A.2) and shows up in multiple-choice questions asking you to find an equivalent expression or simplify a negated condition like !(score < 0 || score > 100).

## Related Study Guides

- [2.6 Equivalent Boolean Expressions](/ap-comp-sci-a/unit-2/equivalent-boolean-expressions/study-guide/aMDnyFuOcAXnZigLW1vL)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law#resource","name":"De Morgan's Law — AP Comp Sci A Definition & Examples","url":"https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:19.638Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law#term","name":"De Morgan's law","description":"De Morgan's law is a rule for rewriting negated Boolean expressions in AP CSA: !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b. When the ! distributes across parentheses, it flips each operand AND swaps && with || (EK 2.6.A.2).","url":"https://fiveable.me/ap-comp-sci-a/key-terms/de-morgans-law","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is De Morgan's law in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It's the rule in Topic 2.6 (EK 2.6.A.2) for rewriting negated Boolean expressions: !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b. The negation moves inside and the operator flips."}},{"@type":"Question","name":"Is !(a && b) the same as !a && !b?","acceptedAnswer":{"@type":"Answer","text":"No. !(a && b) equals !a || !b, with the operator swapped to ||. Test a = true, b = false: !(true && false) is true, but !true && !false is false, so they're not equivalent."}},{"@type":"Question","name":"How is De Morgan's law different from using a truth table?","acceptedAnswer":{"@type":"Answer","text":"De Morgan's law is a transformation rule that rewrites an expression instantly, while a truth table is the proof method that checks every combination of values (EK 2.6.A.1). On the exam, apply De Morgan's law for speed and fall back on a truth table when you're unsure."}},{"@type":"Question","name":"What is the negation of x < 5?","acceptedAnswer":{"@type":"Answer","text":"It's x >= 5, not x > 5. \"Not less than 5\" includes being equal to 5. Forgetting the equals case is one of the most common point-losers on equivalence MCQs."}},{"@type":"Question","name":"Is De Morgan's law actually tested on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"Yes. It's named in the CED under learning objective AP Comp Sci A 2.6.A (EK 2.6.A.2) and shows up in multiple-choice questions asking you to find an equivalent expression or simplify a negated condition like !(score < 0 || score > 100)."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 2","item":"https://fiveable.me/ap-comp-sci-a/unit-2"},{"@type":"ListItem","position":4,"name":"De Morgan's law"}]}]}
```
