Set Operations and Venn Diagrams
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn the four core set operations, how to picture them with Venn diagrams, the set-theory versions of De Morgan’s laws, and the inclusion-exclusion principle for counting overlapping collections.
The Concept
Section titled “The Concept”Let and be sets inside a universal set .
Everything in either set. The OR is inclusive, so elements in both are included once.
Intersection
Section titled “Intersection”Only what’s in both.
If , the sets are disjoint. They share nothing.
Difference
Section titled “Difference”Also written . Everything in that isn’t in .
Difference is not commutative. , a different answer.
Complement
Section titled “Complement”Everything in the universe that isn’t in . This only makes sense once you’ve fixed . If and , then . Change and the complement changes.
Symmetric difference
Section titled “Symmetric difference”In one or the other, but not both. This is the set version of exclusive or.
Venn diagrams
Section titled “Venn diagrams”Shading the four operations side by side is the fastest way to keep them straight:
Draw as a rectangle and each set as a circle inside it. Two overlapping circles carve the rectangle into 4 regions:
- In only
- In both ()
- In only
- In neither (outside both circles, but inside )
Three circles carve it into 8 regions. That’s again, one region per pattern of in/out decisions, exactly like the power set.
Venn diagrams are excellent for building intuition and for solving counting problems where you know some overlaps. They are not a proof technique for general claims, but they’ll almost always tell you whether a claim is worth trying to prove.
The correspondence with logic
Section titled “The correspondence with logic”Set operations and logical connectives are the same structure in different clothing:
| Sets | Logic | Meaning |
|---|---|---|
| or | ||
| and | ||
| not | ||
| implies | ||
| iff | ||
| contradiction | always false | |
| tautology | always true |
So every law from the logic lessons has a set-theory twin. Including these:
- De Morgan’s laws - and
- Distributive laws - and
- Identity - and
- Complement - and
Inclusion-exclusion
Section titled “Inclusion-exclusion”Here’s the counting question. If and , how big is ?
Not 18, unless the sets are disjoint. Adding the cardinalities counts everything in the overlap twice, so you subtract the overlap once to fix it:
For three sets it gets more interesting. Add the singles, subtract the pairs, add the triple back:
The alternating signs keep going for more sets. The reason the triple intersection comes back with a plus sign: it was added 3 times by the singles, then subtracted 3 times by the pairs, leaving it at zero. So you add it once more to count it exactly once.
Here are all 8 regions filled in for the developer survey in Example 3 below. Notice that the counts only work out if you start from the centre and work outward:
Worked Examples
Section titled “Worked Examples”Example 1: Compute all the operations.
, , .
Solution.
Quick check of De Morgan: , and . Match.
Example 2: Inclusion-exclusion with two sets.
In a class of 30 students, 18 take Spanish, 15 take French, and 7 take both. How many take at least one language? How many take neither?
Solution.
26 students take at least one. Then
4 students take neither.
Sanity check with the four Venn regions: Spanish only is , French only is , both is 7, neither is 4. Total . Good.
Example 3: Inclusion-exclusion with three sets.
A survey of 100 developers found:
- 60 use Python, 45 use JavaScript, 30 use Rust
- 25 use Python and JavaScript, 15 use Python and Rust, 10 use JavaScript and Rust
- 5 use all three
How many use at least one? How many use none?
Solution.
90 use at least one, so use none of the three.
Example 4: Fill in a three-circle Venn diagram.
Using the numbers from Example 3, find how many use only Python.
Solution. Always work from the center outward.
- All three: 5
- Python and JavaScript but not Rust:
- Python and Rust but not JavaScript:
- JavaScript and Rust but not Python:
- Python only:
So 25 developers use Python and nothing else. Doing this in the wrong order, outside-in, is how people end up double-counting.
Example 5: Prove a set identity.
Show that .
Solution. Prove both containments.
: Let . By definition and . Since , we have . So and , meaning .
: Let . Then and , so . Therefore .
Both directions hold, so the sets are equal. ∎
This identity is handy because it converts a difference into an intersection, which lets you apply De Morgan and the distributive laws.
Real-World Applications
Section titled “Real-World Applications”SQL is set operations with different keywords. UNION is union, INTERSECT is intersection, EXCEPT or MINUS is difference, and NOT IN is a complement relative to whatever your universe happens to be. Understanding inclusion-exclusion is how you avoid reporting inflated totals when your categories overlap.
Search engines apply set operations to term-matching document sets. A query with a minus sign is a set difference.
Version control merges are essentially symmetric differences: which lines changed in one branch but not the other.
Inclusion-exclusion is the tool for any “at least one” counting question. How many passwords contain at least one digit or one symbol? How many customers bought product A or B? How many students are eligible for at least one scholarship? All the same computation, and all of them go wrong if you just add.
Marketing audience overlap is the everyday version. If a campaign reaches 40,000 people on one platform and 35,000 on another, the total reach is not 75,000 unless nobody uses both platforms, which is never.
Retrying will remove your ✅ checkmark until you pass again.