If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Equivalent compound Booleans

Many logical expressions use a mix of NOT, AND, and OR. Though compound logical expressions can seem complicated, there are some useful logical equivalence rules that can help.
We are going to consider two rules that were known by Greek and Medieval logicians. However, they were named for the logician Augustus De Morgan who wrote them down in the 1800s, so they're commonly called De Morgan’s Laws.

Rule #1

Let's start with a real world example:
The countries of Egypt and Sudan claim different areas of land as part of their country. A very unique aspect of this particular border is that there is actually an area of land that neither Egypt nor Sudan claims. This arises because the area is an uninhabited part of the Sahara desert and more importantly accepting that area of land would mean giving up a larger and inhabited area of land that both countries claim. A picture of the area is below:
Simplified map showing Egypt's claim (yellow and green), the Sudan's claim (blue and green), the Hala'ib Triangle (green) and Bir Tawil (white)
Land claimed by Egypt (Yellow), Sudan (Blue), Both (Green), Neither (white)
We can describe that area of land in English:
The desert area is not claimed by Egypt and also not claimed by Sudan.
That's logically equivalent to this statement:
The desert area is not claimed by Egypt or Sudan.
Hopefully reading both statements makes it clear that they describe the same thing. If not, read the sentences again and think about why they are the same. It may also be helpful to look at the map again. On the map the statements describe the area in white (signifying that neither country claims the land).
Simplified map showing Egypt's claim (yellow and green), the Sudan's claim (blue and green), the Hala'ib Triangle (green) and Bir Tawil (white)
Land claimed by Egypt (Yellow), Sudan (Blue), Both (Green), Neither (white)
Now, translating the original English sentence into pseudocode:
NOT claimedByEgypt AND NOT claimedBySudan
That condition is the same as:
NOT (claimedByEgypt OR claimedBySudan)
The general form of this logical equivalence rule is:
ExpressionEquivalent
NOT A AND NOT BNOT (A OR B)
Keep in mind that the equivalence holds in both directions. That means if you see this condition...
NOT (A OR B)
...you can change it to:
NOT A AND NOT B
...and it will have the same meaning!
Check Your Understanding
Consider this boolean expression about the categorization of rice:
NOT foodType = "fruit" AND NOT foodType = "vegetable"
Which of the following expressions is logically equivalent?
Choose 1 answer:

Rule #2

To understand a similar rule let’s look at a unique road tunnel in the Marin Headlands, an area near San Francisco, California. This tunnel is only wide enough to support vehicle travel in a single direction at a time.
View of a car in a narrow tunnel only wide enough for one direction
The narrow tunnel is wide enough for a single vehicle
Due to this constraint, the tunnel is nicknamed the “Five-Minute Tunnel”, since it has traffic lights at either end that allow traffic only in one direction for five minute intervals.
Tunnel entrance with 5 minute red light controlling the one lane entrance
The tunnel entrance with a 5 minute red light that controls traffic.
What's a logical rule that would keep this tunnel safe? To prevent collisions, we need to ensure the traffic in each direction cannot travel at the same time. This could be stated as:
The tunnel is not used (at the same time) by Eastbound traffic and Westbound traffic.
Translating that rule into pseudocode:
NOT (eastboundTraffic AND westboundTraffic)
That's logically equivalent to this condition:
NOT eastboundTraffic OR NOT westboundTraffic
The second pseudocode condition might feel harder to parse than the first, but it makes more sense when you think about the rules of the tunnel in another way: In at least one direction, there is no traffic using the tunnel. Either there's no traffic going east (NOT eastboundTraffic) or no traffic going in the other direction (NOT westboundtraffic).
Both conditions describe the rules of the tunnel equally well since they are logically equivalent.
The general form of this rule is:
ExpressionEquivalent
NOT (A AND B)NOT A OR NOT B

Breaking down the rules

There are many ways to think about this rule. For this condition:
NOT (A AND B)
It is like distributing the NOT to A, B and the AND.
  • A becomes NOT A
  • B becomes NOT B
  • AND becomes OR
So distributing looks like:
NOT A   NOT AND   NOT B
NOT A   OR        NOT B
The distribution approach also works for the first rule mentioned.
Starting with:
NOT (A OR B)
Distributing:
NOT A   NOT OR   NOT B
After negating OR:
NOT A   AND      NOT B

Want to join the conversation?