TL;DR
A set is a collection of objects, where each object is either in the collection or not. Sets are combined with a small number of operations: union (everything in either set), intersection (everything in both), difference (what one set has that the other lacks), and complement (everything outside a set). These four cover almost every "and", "or" and "not" you will meet when counting or describing groups.
Where you'll see it: in probability, where events are sets of outcomes (probability), in counting problems where you must avoid double counting (counting principles), and in the definition of a Convex Set.
Intuition
A bag with a label
Think of a set as a labelled bag. Some things are in the bag and everything else is out. The bag does not care about order or about how many times you put something in: the bag holding a, b and a again is the same bag as the one holding a and b. The objects inside are called elements, and we write to say that is an element of .
Sets turn words into shapes: "people who own a bike or a car" is a combination of two bags, and a small set of rules answers questions about bags.
Combining bags
Suppose holds the people who ride to work and holds the people who take the train. Four natural questions come up:
- Who uses at least one of the two? That is the union, .
- Who uses both? That is the intersection, .
- Who rides but does not take the train? That is the difference, .
- Who does not ride at all? That is the complement, , taken relative to the whole group everyone belongs to, called the universe .
flowchart LR A[Set A] --> U[Union: in A or in B] B[Set B] --> U A --> I[Intersection: in A and in B] B --> I A --> D[Difference: in A but not B] B --> D A --> C[Complement of A: in the universe but not in A]
The diagram is only a map of which operation answers which question. The formal rules below say exactly what each operation returns.
The math
Definitions
A set is a collection of distinct objects, called its elements. We write if is an element of , and if it is not. Two sets are equal exactly when they have the same elements. A set with no elements is the empty set, written .
Sets are written by listing elements in braces, for example , or by describing them, for example , read "the set of all such that is an even whole number". The braces are part of the notation here, not punctuation.
Fix a universe , the set of all things under discussion. Then, for sets and inside , the basic operations are:
"Or" here is inclusive: an element in both sets belongs to the union. The symmetric difference collects the elements that are in exactly one of the two sets.
A subset means every element of is also in . Two sets are disjoint when .
Key results
The operations obey simple rules that let you rewrite expressions. Some of the most used are:
- Commutativity: and .
- Associativity: , and the same for intersection.
- Distributivity: .
- De Morgan's laws:
Read the first law as: "not (in A or in B)" means "not in A and not in B". Negation swaps "or" with "and".
Counting with union
The size of a set, , is the number of its elements. When the sets overlap, adding sizes counts the overlap twice. The correction is the inclusion-exclusion formula for two sets:
For three sets it becomes
Each pairwise overlap is subtracted once too often, and the triple overlap is added back once.
Worked examples
Let the universe be , with and .
- Union: . Every element of either set, with 4 and 5 listed once.
- Intersection: .
- Difference: , the elements of that lacks.
- Complement: , everything in that is not in .
- Check inclusion-exclusion: , and . The two sides agree.
A class of 30 students is the universe. Let be the 18 students who play soccer and be the 12 who play chess. Five students play both.
- Students in at least one club: .
- Students in neither club: .
- Only soccer: .
- Only chess: .
- Check the total: . Every student is counted exactly once, so the answer is consistent.
Use the same , and as before. We check .
- Left side: , so .
- Right side: , and .
- Their intersection is .
- The two sides match. Interpretation: the numbers outside both sets are exactly the numbers outside and also outside .
Tradeoffs and failure modes
The everyday words that set operations stand for are less precise than the operations. The common mistakes are below.
| Situation | Problem | Better choice |
|---|---|---|
| Adding the sizes of overlapping groups | Elements in both groups are counted twice | Subtract the intersection, as in inclusion-exclusion |
| Reading "or" as exclusive | Elements in both sets get left out | Say "exactly one of" and use the symmetric difference |
| Taking a complement with no universe | "Not A" has no fixed meaning | Name the universe first |
| Expecting repeats to count | A set keeps only one copy of each element | Use a multiset or a list when counting repeats |
| Describing a set by any rule | Some rules, such as "the set of all sets that do not contain themselves", lead to paradox | Use the axioms of set theory, which restrict which collections may be formed |
History
Sets appeared in mathematics gradually. Mathematicians such as Bernard Bolzano discussed collections of numbers in the mid-1800s, but the modern theory is usually dated to Georg Cantor's work in the 1870s. Cantor was studying infinite sets of real numbers and showed that some infinities are larger than others. In the late 1800s and early 1900s, Gottlob Frege, Bertrand Russell and others found paradoxes in unrestricted set formation, and the response was axiomatic set theory, which is still the foundation of most of mathematics today.
Logic came at the problem from the other side. George Boole's The Mathematical Analysis of Logic (1847) treated "and", "or" and "not" as algebraic operations on classes, and Augustus De Morgan published his laws of negation in the same decade. John Venn introduced the diagrams that bear his name in 1880 as a way to picture these operations. The diagrams caught on in teaching because they make the operations visible.
Check yourself
QuestionLet and in the universe . What are , and ?Show answer
, because every element of either set appears once. , the only element in both. , the elements of the universe not in .
QuestionIn a group of 40 people, 25 like tea, 20 like coffee and 8 like neither. How many like both?Show answer
The number who like at least one is . Inclusion-exclusion gives , so . Therefore .
QuestionWhy is it not enough to add the sizes of two sets to find the size of their union?Show answer
Adding counts every element in the overlap twice, once for each set that contains it. The correction is to subtract the size of the intersection once, which is exactly what the inclusion-exclusion formula does.
QuestionA survey asks which of two products customers have bought, and a manager says the number who bought neither is the size of the universe minus the size of the union. Why is this correct, and what would go wrong if the universe were not stated?Show answer
The universe is all surveyed customers, and the complement of the union is the set of customers outside both products. Subtracting the union from the universe gives exactly that set. If the universe were not fixed, "bought neither" would have no definite meaning, because the complement of a set depends on what it is taken relative to.
Sources
- Set (mathematics), Wikipedia: https://en.wikipedia.org/wiki/Set_(mathematics)
- Algebra of sets, Wikipedia: https://en.wikipedia.org/wiki/Algebra_of_sets
- De Morgan's laws, Wikipedia: https://en.wikipedia.org/wiki/De_Morgan%27s_laws