AP CSP Day 32: Boolean Logic | Cycle 2
Share
Boolean logic errors often arise from confusion between AND and OR, particularly in guard conditions that should exclude invalid inputs. A condition written as (age > 0 AND age < 120) correctly validates age, but flipping to OR creates a condition that is almost always true. AP CSP harder questions present Boolean expressions and ask whether the logic matches the described intent, requiring students to test boundary values to expose the error. Recognizing that NOT distributes differently over AND versus OR (De Morgan's laws) is critical for these analysis questions.
📚 Study the Concept First (Optional) Click to expand ▼
Boolean Logic Errors: Finding the Bug
AND vs. OR Confusion
The most common Boolean error is using AND when OR is needed or vice versa. Conditions like 'accept if the user is a student OR a teacher' vs. 'accept if the user is a student AND a teacher' include very different sets of users. Testing with representative values exposes this error immediately.
Boundary Condition Errors
Strict inequalities (>, <) exclude the boundary value. Non-strict inequalities (>=, <=) include it. Writing > when >= is needed causes the boundary case to fail silently.
Practice Question
For which of the following values of x does the expression NOT (x < 3 OR x > 7) evaluate to true?Applying De Morgan's Law: NOT(x < 3 OR x > 7) is equivalent to (NOT(x < 3)) AND (NOT(x > 7)), which simplifies to (x ≥ 3) AND (x ≤ 7). This means x must be between 3 and 7 inclusive. x = 5 satisfies this condition.
A) x = 1: 1 < 3 is true, so (x < 3 OR x > 7) is true, and NOT of true is false. C) x = 8: 8 > 7 is true, so the inner OR is true, and NOT is false. B) x = 2: 2 < 3 is true, so the inner OR is true, and NOT is false.
Students incorrectly apply NOT by flipping only one part of the OR instead of applying De Morgan's Law properly. NOT distributes over OR by changing it to AND and flipping both conditions.
De Morgan's Laws: NOT(A OR B) = NOT A AND NOT B. NOT(A AND B) = NOT A OR NOT B. Practice these until they are automatic.
Keep Practicing!
Consistent daily practice is the key to AP CSP success.
AP CSP Resources Get 1-on-1 Help