Exercise 3: Correctly Negating "is_admin or is_owner" — Possible Solution ==================================================================== THE CORRECT NEGATION, VIA DE MORGAN'S LAW ------------------------------ This chapter's own De Morgan's Law states: (x+y)' = x'.y' Here x = is_admin, y = is_owner, and the original condition is is_admin or is_owner (x+y). The correct negation is therefore: NOT is_admin AND NOT is_owner WHAT GOES WRONG WITH "not is_admin or not is_owner" ------------------------------ This uses OR instead of AND - it's applying NOT to each piece individually but keeping the original OR, rather than switching OR to AND as De Morgan's Law actually requires. Checking both versions against the TRUE negation of the original condition, across all 4 combinations: is_admin=0, is_owner=0: original=False. True negation=True. Correct (AND) version: True. Incorrect (OR) version: True. Both happen to match here. is_admin=0, is_owner=1: original=True. True negation=False. Correct (AND) version: False. Incorrect (OR) version: True. The incorrect version is WRONG here. is_admin=1, is_owner=0: original=True. True negation=False. Correct (AND) version: False. Incorrect (OR) version: True. The incorrect version is WRONG here. is_admin=1, is_owner=1: original=True. True negation=False. Correct (AND) version: False. Incorrect (OR) version: False. Both happen to match here. RESULT ------------------------------ The incorrect "or" version gives the WRONG answer exactly when the user is one or the other (admin only, or owner only) - precisely the two most common real cases. In a real access-control check, this bug would incorrectly grant access to someone who is only an admin OR only an owner (but not both) to a resource that should have been restricted to neither - a genuine, security-relevant mistake, not just a cosmetic difference. WHY THIS WORKS AS AN ANSWER ------------------------------ The correct negation is derived directly from this chapter's own De Morgan's Law (naming x and y explicitly), and the incorrect version's failure is demonstrated with a full truth table comparison against the TRUE negation, showing specifically which two real-world cases it gets wrong and what the practical consequence (incorrectly granted access) would be - not just asserting the incorrect version is "wrong" in the abstract.