Article
Same meaning
A shop has two signs. One says: "Discount if you are not an adult." The other says: "Discount if you are under 18." The words are different, but the same people get the discount. Programmers call this logical equivalence, and the AP exam asks about it often.
Same result in every case
A Boolean expression is an expression whose value is true or false, such as age < 18. Two Boolean expressions are logically equivalent when they give the same result in every possible case. "Every possible case" means every possible value of the variables in them.
Here are the two signs as expressions, tested with four ages:
age | age < 18 | NOT (age ≥ 18) |
|---|---|---|
| 10 | true | true |
| 17 | true | true |
| 18 | false | false |
| 40 | false | false |
The two columns match in every row, so these expressions are equivalent. Here is the same test in AP pseudocode, then in Python. The exam shows AP pseudocode, and Python is what you can run. Python writes not where AP writes NOT, and it prints True where AP shows true.
age ← 17 DISPLAY(age < 18) DISPLAY(NOT (age ≥ 18))
Change age to 18, then 40, then 5, and run again. The two lines always match.
Check your understanding
What does it mean for two Boolean expressions to be logically equivalent?
Checking with a truth table
You cannot test every number. But a Boolean variable (one that holds true or false) has only two values, so you can test them all. A truth table lists every combination of values and the result of each expression.
Two Booleans, a and b, make 4 combinations. Each new Boolean doubles the rows, just like each new bit doubles the values a binary number can hold. Three Booleans make 8 rows, and four make 16.
Is a AND b equivalent to b AND a?
| a | b | a AND b | b AND a |
|---|---|---|---|
| true | true | true | true |
| true | false | false | false |
| false | true | false | false |
| false | false | false | false |
All four rows match, so yes. Now try a AND b against a OR b:
| a | b | a AND b | a OR b |
|---|---|---|---|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
Two rows differ, so these are not equivalent. One row that differs is already enough to prove it. But to prove two expressions are equivalent, every row must match. Matching in two or three rows proves nothing.
Check your understanding
A truth table compares two expressions that use three Boolean variables, a, b and c. How many rows does the table need to show every case?
Worked example
Is NOT (a AND b) equivalent to (NOT a) AND (NOT b)? We write brackets so it is clear what each NOT applies to. Fill in a column for each part:
| a | b | a AND b | NOT (a AND b) | NOT a | NOT b | (NOT a) AND (NOT b) |
|---|---|---|---|---|---|---|
| true | true | true | false | false | false | false |
| true | false | false | true | false | true | false |
| false | true | false | true | true | false | false |
| false | false | false | true | true | true | true |
In the second and third rows the fourth column is true and the last column is false. They are not equivalent. The next article shows the right partner for NOT (a AND b).
Common mistakes
- Testing one or two cases and saying "equivalent". Matching in a few cases is not enough. You need every case.
- Thinking "equivalent" means "both true". Two equivalent expressions can both be false. They only have to give the same answer as each other.
- Thinking the same variables means the same meaning.
a AND banda OR buse the same variables and are very different. - Comparing the wrong rows. Always compare two expressions in the same row of the table.
On the exam
You will see "Which of the following is equivalent to…?" with four options. You do not need a full table. Pick values for the variables that make the original expression give true, then check which options also give true. Then pick values that give false. An option that gives a different answer even once is wrong.
Key words
Boolean expression: an expression whose value is true or false.
Logically equivalent: giving the same result in every possible case.
Truth table: a table that lists every combination of values of the variables and the result of each expression.