Study smarter with Fiveable
Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.
Boolean logic is the foundation of every decision your program makes. When you write an IF statement, combine conditions with AND or OR, or check whether a user meets multiple criteria, you're using Boolean operations. The AP exam tests whether you can trace through conditional logic, predict program output when multiple conditions combine, and recognize equivalent expressions in both multiple-choice questions and the Create Performance Task.
You're being tested on more than just knowing that AND requires both inputs to be true. The exam expects you to understand how to negate compound conditions and when two different-looking expressions actually do the same thing. Don't just memorize truth tables. Know how each operation behaves in real code and when to use one over another.
These three operations form the backbone of all conditional logic in programming. Every complex Boolean expression on the AP exam can be broken down into combinations of these.
AND. Use it whenever multiple criteria must all be satisfied. For example, checking if a test score is in a range: score >= 0 AND score <= 100.x โ 0 AND (10/x > 2) is safe because if x is 0, the division never runs.isStudent OR isSenior.NOT(A AND B) negates the whole compound condition, not just A.Compare: AND vs. OR both combine two conditions, but AND requires all to be true while OR requires any to be true. If an FRQ asks you to check whether a value falls within a range, you need AND (e.g., x >= 0 AND x <= 100). If checking whether a value matches one of several options, you need OR (e.g., color = "red" OR color = "blue").
These operations build on the core three to handle special cases. XOR appears occasionally on the exam, and understanding how negation combines with AND/OR is critical for expression simplification.
NOT(A AND B). It outputs true for every input combination except .NOT(A OR B). It outputs true only for the input combination.Compare: NAND vs. NOR are both negated versions of core operations. NAND negates AND (false only when all inputs are true), while NOR negates OR (true only when all inputs are false). Recognizing these as NOT(A AND B) and NOT(A OR B) connects directly to De Morgan's Laws.
These techniques help you verify Boolean expressions, prove equivalence, and simplify complex conditions. The AP exam tests these skills when you need to trace code or identify equivalent program segments.
A truth table lists every possible input combination alongside the output for a given expression. For an expression with variables, you'll have rows.
Building a truth table (step by step):
For example, here's the truth table for A AND B:
| A | B | A AND B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
Boolean expressions combine variables using AND, OR, and NOT to represent complex conditions in a single statement. Simplification reduces complexity while preserving the same behavior, which leads to more readable code.
A few useful identities to know:
These two laws tell you how to distribute a NOT across a compound condition. They come up constantly on the exam.
NOT(A AND B) equals (NOT A) OR (NOT B). Negating an AND flips it to OR and negates each part.NOT(A OR B) equals (NOT A) AND (NOT B). Negating an OR flips it to AND and negates each part.The pattern: when you push a NOT inward, the operator flips (AND becomes OR, OR becomes AND) and each individual condition gets negated.
Example: NOT(score >= 70 AND attendance >= 80) becomes score < 70 OR attendance < 80. Notice how AND flipped to OR, and each comparison flipped to its opposite.
Compare: Truth tables vs. De Morgan's Laws serve different purposes. Truth tables prove equivalence by exhaustive checking (works for any expressions but takes more time). De Morgan's Laws give you a direct algebraic transformation (faster when you spot a negated AND or OR). Use truth tables when you're unsure; use De Morgan's when the pattern is clear.
Two expressions are logically equivalent when they produce identical truth values for every possible input combination. The exam tests this by showing code segments and asking which produces the same output, requiring you to recognize transformed expressions.
You can prove equivalence using truth tables, algebraic manipulation, or known identities like De Morgan's Laws and double negation. When in doubt on the exam, pick a few test values and plug them into both expressions. If any value produces different results, they're not equivalent.
| Concept | Best Examples |
|---|---|
| Requires all conditions true | AND operation |
| Requires at least one condition true | OR operation |
| Inverts a single value | NOT operation |
| True when inputs differ | XOR operation |
| Negated compound operations | NAND, NOR |
| Systematic verification | Truth tables |
| Negation transformation | De Morgan's Laws |
| Expression optimization | Boolean simplification, logical equivalence |
If x = 5 and y = 10, what does (x > 3) AND (y < 8) evaluate to, and why does short-circuit evaluation NOT skip the second condition here?
Which two operations are universal gates, and what property makes them "universal"?
Using De Morgan's Laws, rewrite NOT(score >= 70 AND attendance >= 80) as an equivalent expression without the outer NOT.
Compare AND and XOR: for which input combination do they produce different outputs, and why does this matter when checking conditions?
An FRQ shows two code segments: one uses NOT(A OR B) and the other uses (NOT A) AND (NOT B). How would you demonstrate these are logically equivalent using a truth table?