Math Fundamentals18 sections · 814 units
Open in Course

De Morgan's Laws - Example

Concrete application

Suppose you have !(age >= 18 && hasID). This means the person fails at least one requirement. Apply De Morgan: age < 18 || !hasID.

Both expressions are equivalent. The first wraps the condition in negation. The second distributes the negation inside. The second form is often clearer when writing if statements.

De Morgan's Laws let you refactor conditions. If you see nested negations like !(!(a) || !(b)), you can simplify to a && b using the laws repeatedly.