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 bothcondition1
andcondition2
are true.
- Returns
||
(OR):- Returns
true
if at least one of the conditions is true. - Example:
(condition1 || condition2)
is true if eithercondition1
orcondition2
(or both) are true.
- Returns
!
(NOT):- Negates the value of a condition; returns
true
if the condition is false, and vice versa. - Example:
!(condition)
is true ifcondition
is false.
- Negates the value of a condition; returns
De Morgans Law
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
- What is
!(x == 0)
equivalent to?- Apply De Morgan’s Law to find an equivalent expression.
- Negate the expression
(x < -5 || x > 10)
.- Use De Morgan’s Law to rewrite this expression in a different form.
My answers
x != 0
(x >= -5) && (x <= 10)
Truth Tables
- evaluate and shoe equivalency in Boolean expressions
- see al the possible outcomes that we will have.