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}\{1, 2, 2\} = \{2, 1\}. Roster notation lists the elements, as in A={2,4,6}A = \{2, 4, 6\}. Set-builder notation states a membership rule, as in A={x∈Z:1≤x≤6 and x even}A = \{x \in \mathbb{Z} : 1 \le x \le 6 \text{ and } x \text{ even}\}, where Z\mathbb{Z} is the set of integers. Write x∈Ax \in A when xx is an element of AA, and A⊆BA \subseteq B when every element of AA is also in BB. The empty set ∅\varnothing has no elements and is a subset of every set. The cardinality of {2,4,6}\{2, 4, 6\} is 3.


The power set of AA, written P(A)\mathcal{P}(A), is the set of all subsets of AA. If ∣A∣=n|A| = n, then ∣P(A)∣=2n|\mathcal{P}(A)| = 2^n. Building a subset means deciding, for each of the nn elements, whether it is in or out.


Example: For A={a,b,c}A = \{a, b, c\}, P(A)\mathcal{P}(A) holds ∅\varnothing, three one-element sets, three two-element sets and AA itself, for 23=82^3 = 8 subsets.


Sets A1,A2,…,AnA_1, A_2, \dots, A_n labelled by an index ii form an indexed family. Their union and intersection are written compactly:


⋃i=1nAi={x:x∈Ai for at least one i},⋂i=1nAi={x:x∈Ai for every i}\bigcup_{i=1}^{n} A_i = \{x : x \in A_i \text{ for at least one } i\}, \qquad \bigcap_{i=1}^{n} A_i = \{x : x \in A_i \text{ for every } i\}


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}U = \{1, 2, 3, 4, 5, 6\}, A={1,2,3,4}A = \{1, 2, 3, 4\} and B={3,4,5}B = \{3, 4, 5\}.


Operation

Notation

xx belongs when

Result

Union

A∪BA \cup B

x∈Ax \in A or x∈Bx \in B

{1,2,3,4,5}\{1, 2, 3, 4, 5\}

Intersection

A∩BA \cap B

x∈Ax \in A and x∈Bx \in B

{3,4}\{3, 4\}

Difference

A−BA - B

x∈Ax \in A and x∉Bx \notin B

{1,2}\{1, 2\}

Complement

A‾\overline{A}

x∈Ux \in U and x∉Ax \notin A

{5,6}\{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)A \cap (B \cup C) = (A \cap B) \cup (A \cap C) and A∪(B∩C)=(A∪B)∩(A∪C)A \cup (B \cap C) = (A \cup B) \cap (A \cup C).
  • De Morgan: A∪B‾=A‾∩B‾\overline{A \cup B} = \overline{A} \cap \overline{B} and A∩B‾=A‾∪B‾\overline{A \cap B} = \overline{A} \cup \overline{B}.
  • Difference: A−B=A∩B‾A - B = A \cap \overline{B}.

To prove X=YX = Y directly, show X⊆YX \subseteq Y and Y⊆XY \subseteq 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∣|A| and ∣B∣|B| counts every element of A∩BA \cap 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:


∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|


∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣A∩C∣−∣B∩C∣+∣A∩B∩C∣|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|


Two overlapping circles labelled A and B inside a rectangle labelled U, dividing it into four regions marked A only, A ∩ B, B only and neither.


Example: In a class, 48 students passed the programming quiz, 35 passed the logic quiz and 20 passed both. Then 48+35−20=6348 + 35 - 20 = 63 students passed at least one quiz. If the class has 70 students, 70−63=770 - 63 = 7 passed neither.



What to remember

  • A set is determined only by its elements; order and repetition do not matter.
  • ∣P(A)∣=2n|\mathcal{P}(A)| = 2^n when ∣A∣=n|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 PP, JJ and CC be the sets of students who know Python, Java and C, and let the universal set UU 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∪CP \cup J \cup 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:


∣P∪J∪C∣=(120+90+65)−(50+30+25)+15=275−105+15=185|P \cup J \cup C| = (120 + 90 + 65) - (50 + 30 + 25) + 15 = 275 - 105 + 15 = 185


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∪CP \cup J \cup C within UU. Its size is the size of UU minus the result of part a):


∣P∪J∪C‾∣=∣U∣−∣P∪J∪C∣=230−185=45|\overline{P \cup J \cup C}| = |U| - |P \cup J \cup C| = 230 - 185 = 45


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 PP but in neither JJ nor CC. Subtracting both pairwise overlaps from ∣P∣|P| removes the 15 three-language students twice, so add them back once:


∣P∣−∣P∩J∣−∣P∩C∣+∣P∩J∩C∣=120−50−30+15|P| - |P \cap J| - |P \cap C| + |P \cap J \cap C| = 120 - 50 - 30 + 15


This gives ________ students who know Python only. The same reasoning gives ________ for Java only, from 90−50−25+1590 - 50 - 25 + 15, and ________ for C only, from 65−30−25+1565 - 30 - 25 + 15. Adding the three regions:


55+30+25=11055 + 30 + 25 = 110


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=185110 + 60 + 15 = 185, which matches part a).

Match each set-theory term with the description of the set or relationship it names. Assume that all sets lie inside a fixed universal set.

Match each term
A.

Every element that lies in both given sets at once

B.

Every element of the first set that is missing from the second

C.

Every element that lies in at least one of the two given sets

D.

Two sets that share no element

E.

The collection of all subsets of a given set

F.

Every element of the universal set lying outside the given set

Complement

Difference

Union

Intersection

Disjoint sets

Power set

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Let AA, BB and CC be subsets of a universal set UU. Which expression is equal to A∩(B∪C)‾\overline{A \cap (B \cup C)} for every possible choice of AA, BB and CC?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

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.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice