Main content
AP®︎/College Computer Science Principles
Course: AP®︎/College Computer Science Principles > Unit 3
Lesson 6: Logical equivalenceEquivalent simple Booleans
A logical statement is equivalent to another statement if it is true in the same situations that the other statement is true, and false in the situations where the other statement is false.
Let's start off with some basic logical equivalences. These may seem simple, but they will serve as important building blocks for more complex logical equivalences later.
Equivalences with NOT
This may be the simplest equivalence rule:
Equivalence | ||
---|---|---|
NOT true | ≡ | false |
NOT false | ≡ | true |
Whenever we see the expression in the first column, we can replace it with the expression in the last column, and our logical statement will have the same meaning.
The following statements are logically equivalent according to this rule:
when is_hot_out is NOT true, I wear a sweater
when is_hot_out is false, I wear a sweater
Two NOT 's
It is also important to know that two
NOT
operators on an expression have the same value as the expression without any NOT
operators:Equivalence | ||
---|---|---|
NOT (NOT A) | ≡ | A |
NOT Equal
When programming, it's also possible to apply
NOT
to the result of an expression using the equality operator:NOT (speedLimit = carSpeed)
Or in words: check if
speedLimit
is equal to carSpeed
, then apply NOT
to the result. This expression will be false
when the variables are equal and true
when they are not equal.Programming languages typically include another operator to describe the same idea, the inequality operator:
speedLimit ≠ carSpeed
Or in words: check if
speedLimit
is not equal to carSpeed
.These two expressions describe the same idea, thus, we have another logical equivalence:
Equivalence | ||
---|---|---|
NOT (A = B) | ≡ | A ≠ B |
NOT <, NOT >
A similar idea can be applied to the less than (<) and greater than (>) operators.
Consider this expression:
NOT (carSpeed < speedLimit)
Or in words: check if
carSpeed
is less than speedLimit
, then return the negation.If
carSpeed
is less than speedLimit
, the whole expression is false. Any other relationship makes the expression true.Let's walk through this example with real values:
carSpeed ← 50
speedLimit ← 40
NOT (carSpeed < speedLimit)
We can replace the variables with their values:
NOT (50 < 40)
Since
50 < 40
is false, the inner portion is false:NOT (false)
Then we negate
false
to find the final result:true
Similarly, if
carSpeed
was 40, the result would also be true.As you might see from this example, an expression of the form
NOT (A < B)
is equivalent to A ≥ B
.In words, this is saying:
If it's not ‘less than’, it must be ‘greater than or equal to’.
It should also make sense that the rule holds for the other pair:
If it's not ‘greater than’, it must be ‘less than or equal to’.
So, the rules are:
Equivalence | ||
---|---|---|
NOT (A < B) | ≡ | A ≥ B |
NOT (A > B) | ≡ | A ≤ B . |
Equivalences with ≤ and ≥
The symbols ≤ and ≥ are shortcuts for longer expressions. When we speak the names of these operators we say an expression like "less than OR equal to", and in fact, that gives us another set of equivalence rules:
Equivalence | ||
---|---|---|
A ≤ B | ≡ | A < B OR A = B |
A ≥ B | ≡ | A > B OR A = B |
Want to join the conversation?
- my brain is fried(3 votes)
- well if u need help. i would say pick python for beginnners. i cant describe how much it has helped me to understand everything,otherwise i would not even know whats happening(3 votes)
- Hi,
In the check your understanding part of Equivalences with ≤ and ≥, the question only asks "days ≥ 365" instead of NOT(days ≥ 365), the NOT is missing(2 votes)- It all seems to make sense to me.
They're asking you which expression equivalent to 'days ≥ 365', so we can say that 'days ≥ 365' = 'NOT(days < 365)'(2 votes)
- What distinguishes a logical statement with a logical expression? Are they synonymous?(1 vote)
- A logical expression is a logical operator, or a Boolean operator. From looking around a little, a logical statement also seems to be synonymous with a logical operator, so I think they are synonymous terms.(0 votes)
- If logical equivalences can be expressed in a similar manner, doesn't it become redundant to express it in such a way? For instance, wouldn't "NOT (NOT false)" become cleaner as "true"? In what scenarios would it be practical for one to implement logical equivalencies? Why?(0 votes)
- You may start with a boolean expression in a complex form. Using boolean equivalencies, you can simplify it so that it is easier to understand and faster to compute.(0 votes)