Skip to the content.
3.1: Boolean Expressions 3.2: If Control Flow 3.3: If Else 3.4: Else If 3.5: Compound Booleans 3.6: Equivalent Booleans 3.7: Comparing Objects 3.8: Homework

Unit 3 Team Teach - 3.6 Equivalent Booleans

Unit 3 Team Teach

3.6 Equivalent Boolean Expressions

  • There are multiple ways to represent the same boolean expression. To show that the are the same expression, wither prove that they can be simplified to the same expression using boolean properties and identitied or prove that they can be the same in all cases.
  • Using De Morgan’s Law to compare and contrast equivalent Boolean expressions

Logical operators reminder

  • && (AND):
    • Returns true only if both conditions are true.
    • Example: (condition1 && condition2) is true if both condition1 and condition2 are true.
  • || (OR):
    • Returns true if at least one of the conditions is true.
    • Example: (condition1 || condition2) is true if either condition1 or condition2 (or both) are true.
  • ! (NOT):
    • Negates the value of a condition; returns true if the condition is false, and vice versa.
    • Example: !(condition) is true if condition is false.

De Morgans Law

Screenshot 2024-09-25 at 3 48 47 AM

Screenshot 2024-09-25 at 3 49 40 AM

Distributing a “not” with a Boolean expression ‘flips’ the relationsal operator to the opposite relational operator

  • ex: !(x > 0) is equivalent to (x<= 0)

Popcorn Hack

Challenge Questions

  1. What is !(x == 0) equivalent to?
    • Apply De Morgan’s Law to find an equivalent expression.

!(x == 0) = (x != 0)

  1. Negate the expression (x < -5 || x > 10).
    • Use De Morgan’s Law to rewrite this expression in a different form. (x < -5 || x > 10) = (x >= -5 && x <= 10)

Truth Tables

  • evaluate and shoe equivalency in Boolean expressions
  • see al the possible outcomes that we will have.

Screenshot 2024-09-25 at 3 13 16 AM

Screenshot 2024-09-25 at 3 19 33 AM