BEI - Equivalent Boolean Expressions (Lesson)
Equivalent Boolean Expressions
Introduction
Augustus De Morgan was an English mathematician and logician whose major contribution to the field of mathematics was his interpretation of logic. He created what is known as De Morgan’s Laws which have many applications. We will apply De Morgan’s Laws to our logic operators. De Morgan’s Laws state:
Not( A and B) is the same as Not A or Not B
Not(A or B) is the same as Not A and Not B
This law is very similar to the distributive property in math. It is as if you are distributing the Not outside the parenthesis to each item inside the parenthesis, including the compound operator.
De Morgan's Laws
De Morgan’s Laws can be translated in Java. Assume that a and b represent boolean expressions or values:
!(a && b) is the same as !a || !b
!(a || b) is the same as !a && !b
As stated, the negation is distributed to all values and operators. The negation can also be applied to conditional operators.
The following table shows Java conditionals and their negations:
For example, !(a>=b) can be written as !a<!b. Notice how the conditional was changed.
You may recall truth tables from various math courses. A truth table can be used to show all possible outcomes of logical operations on variables.
This is a truth table that you might see in math:
p | q | p^q |
T | T | T |
T | F | F |
F | T | F |
F | F | F |
The variables p and q can be true or false as shown in the first and second columns. The third column shows the value of “p and q”.
We can use this same logic with our Java operators. Using p and q for different boolean values we can make a truth table to show the results of p && q and p || q.
p | q | p&&q | p||q |
T | T | T | T |
T | F | F | T |
F | T | F | T |
F | F | F | F |
Click on "Runestone Academy" below to open the required reading that is listed.
Runestone Academy: AP CSA – Java Review Links to an external site.
READ: 5.5 – De Morgan’s Laws
Boolean Expression Review
Click below to begin the Boolean Expression Review Activity.
Practice-It!
- Go to the PracticeIt website Links to an external site..
- Log into account.
- Click on Start Practicing!
- Go to the most recent edition.
- Click on Chapter 4: Conditional Execution.
- Complete Exercise 4.12.
Boolean Expressions and if Statements Test Review
Go to AP Classroom Links to an external site..
Complete Progress Check(s) 3.
IMAGES CREATED BY GAVS and AUGUSTUS DE MORGAN IMAGE
Links to an external site.