Set Reasoning: Operations, Laws and Inclusion–Exclusion
Programs filter records, database queries combine result sets, and type checkers test membership. Each of these is reasoning about sets. This lesson covers the notation for describing sets, the operations that combine them, and the laws that rewrite a set expression into a simpler one. It ends with the counting rule for overlapping sets, which avoids counting anything twice.
Describing sets
A set is an unordered collection of distinct elements, so {1,2,2}={2,1}. Roster notation lists the elements, as in A={2,4,6}. Set-builder notation states a membership rule, as in A={x∈Z:1≤x≤6 and x even}, where Z is the set of integers. Write x∈A when x is an element of A, and A⊆B when every element of A is also in B. The empty set ∅ has no elements and is a subset of every set. The cardinality of {2,4,6} is 3.
The power set of A, written P(A), is the set of all subsets of A. If ∣A∣=n, then ∣P(A)∣=2n. Building a subset means deciding, for each of the n elements, whether it is in or out.
Example: For A={a,b,c}, P(A) holds ∅, three one-element sets, three two-element sets and A itself, for 23=8 subsets.
Sets A1,A2,…,An labelled by an index i form an indexed family. Their union and intersection are written compactly:
Operations and the laws of set algebra
Each operation is defined by a membership condition built from and, or and not. The table uses U={1,2,3,4,5,6}, A={1,2,3,4} and B={3,4,5}.
Operation | Notation | x belongs when | Result |
|---|---|---|---|
Union | A∪B | x∈A or x∈B | {1,2,3,4,5} |
Intersection | A∩B | x∈A and x∈B | {3,4} |
Difference | A−B | x∈A and x∈/B | {1,2} |
Complement | A | x∈U and x∈/A | {5,6} |
These conditions are logical connectives, so every law of logic has a set version. The ones you will use most are:
- Distributive: A∩(B∪C)=(A∩B)∪(A∩C) and A∪(B∩C)=(A∪B)∩(A∪C).
- De Morgan: A∪B=A∩B and A∩B=A∪B.
- Difference: A−B=A∩B.
To prove X=Y directly, show X⊆Y and Y⊆X: take an arbitrary element of one side and show that it lies in the other. You can also use the laws to rewrite one side into the other. A single counterexample disproves an identity, but no number of examples proves one.
Counting overlapping sets
Adding ∣A∣ and ∣B∣ counts every element of A∩B twice, once in each set. The principle of inclusion and exclusion corrects this. It subtracts the overlaps, then adds back anything that was removed too often:
Example: In a class, 48 students passed the programming quiz, 35 passed the logic quiz and 20 passed both. Then 48+35−20=63 students passed at least one quiz. If the class has 70 students, 70−63=7 passed neither.
What to remember
- A set is determined only by its elements; order and repetition do not matter.
- ∣P(A)∣=2n when ∣A∣=n.
- Union, intersection, difference and complement correspond to or, and, and-not, and not.
- Prove identities by mutual inclusion or with the laws; disprove them with one counterexample.
- For inclusion–exclusion, add the single sets, subtract the pairwise overlaps and add back the triple overlap.
Example: Counting language skills with inclusion–exclusion
A department surveys all 230 students in its first-year computer science program about the languages they can program in:
- 120 know Python, 90 know Java and 65 know C.
- 50 know both Python and Java, 30 know both Python and C, and 25 know both Java and C.
- 15 know all three languages.
Let P, J and C be the sets of students who know Python, Java and C, and let the universal set U be the 230 surveyed students.
a) How many students know at least one of the three languages?
Knowing at least one language means belonging to P∪J∪C, so apply inclusion–exclusion for three sets.
The three single-set sizes add to ________ students, and the three pairwise intersections add to ________ students. Subtract the overlaps, then add the triple intersection back once:
So 185 students know at least one of the languages.
b) How many students know none of the three languages?
Knowing none of the languages means belonging to the complement of P∪J∪C within U. Its size is the size of U minus the result of part a):
So 45 students know none of the three languages.
c) How many students know exactly one language?
Count each single-language region separately. Students who know Python only are in P but in neither J nor C. Subtracting both pairwise overlaps from ∣P∣ removes the 15 three-language students twice, so add them back once:
This gives ________ students who know Python only. The same reasoning gives ________ for Java only, from 90−50−25+15, and ________ for C only, from 65−30−25+15. Adding the three regions:
So 110 students know exactly one language.
As a check, the students who know exactly two languages are each pairwise overlap minus the 15 in all three. That gives 35, 15 and 10, for a total of ________. Then 110+60+15=185, which matches part a).
Let A, B and C be subsets of a universal set U. Which expression is equal to A∩(B∪C) for every possible choice of A, B and C?
How many integers from 1 to 1000 inclusive are divisible by 6, by 15, or by both? Give your answer as an exact whole number.