MathLabs

Grade 6

Sets and set operations

A set is a well-defined collection of objects, its elements; x∈Ax \in A says xx belongs to AA. One set is a subset of another, A⊆BA \subseteq B, when every element of AA is also in BB. From two sets we build new ones: the union A∪BA \cup B (elements in AA or in BB), the intersection A∩BA \cap B (elements in both), and the difference A∖BA \setminus B (in AA but not BB). These operations obey algebra-like laws such as the distributive law A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C), and counting elements of a union follows the inclusion-exclusion rule ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|, both proved rigorously here and applied to survey data and search-engine filters.

IntuitionBoxes of objects: what belongs where

Imagine two overlapping boxes of toys: box AA holds building blocks, box BB holds cars. Some toys are block-cars and sit in both boxes at once. Asking "x∈Ax \in A?" is asking whether a specific toy xx is inside box AA. Asking "A⊆BA \subseteq B?" is asking whether every single toy in box AA is also somewhere in box BB. Combining the two boxes into one pile gives the union A∪BA \cup B; keeping only toys that are in both boxes gives the intersection A∩BA \cap B; taking box AA and throwing out anything also in box BB gives the difference A∖BA \setminus B. The network widget below lets you drag elements between two circles and watch the four operations recompute live.

Interactive network diagram of two overlapping sets A and B with the intersection highlighted
Venn diagram of three sets A,B,CA, B, C showing union, pairwise intersections, and the central triple intersection A∩B∩CA\cap B\cap C.

SchoolFormal definitions and a comparison table

Definition: Set, element, subset

A set AA is a collection of distinct objects; each object xx with x∈Ax \in A is called an element of AA. Set AA is a subset of set BB, written A⊆BA \subseteq B, when every element of AA is also an element of BB; two sets are equal exactly when A⊆BA \subseteq B and B⊆AB \subseteq A hold simultaneously.

A∪B={x:x∈A∨x∈B}A \cup B = \{x : x \in A \lor x \in B\}

The union A∪B={x:x∈A∨x∈B}A \cup B = \{x : x \in A \lor x \in B\} collects an element as soon as it belongs to at least one of the two sets. Dually, the intersection keeps only elements shared by both sets.

A∩B={x:x∈A∧x∈B}A \cap B = \{x : x \in A \land x \in B\}
Set operations on A={1,2,3}A=\{1,2,3\} and B={2,3,4}B=\{2,3,4\}
OperationDefinitionResult
Union A∪BA \cup BA∪B={x:x∈A∨x∈B}A \cup B = \{x : x \in A \lor x \in B\}{1,2,3,4}\{1,2,3,4\}
Intersection A∩BA \cap BA∩B={x:x∈A∧x∈B}A \cap B = \{x : x \in A \land x \in B\}{2,3}\{2,3\}
Difference A∖BA \setminus BA∖B={x:x∈A∧x∉B}A \setminus B = \{x : x \in A \land x \notin B\}{1}\{1\}
Subset A⊆BA \subseteq Bevery element of AA is in BBfalse (1∉B1 \notin B)

UndergraduateTwo key theorems, with full proofs

For any three sets AA, BB, CC: A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C).

Why is it true?

Just as multiplication distributes over addition in ordinary algebra, intersection distributes over union in set algebra. This lets you rewrite a filter such as "in category AA, and (on sale BB or new arrival CC)" as two separately manageable filters combined by a union, which is exactly how database and search-engine query planners simplify boolean filters.

Proof

We prove set equality by showing both inclusions, using an arbitrary element x0x_0 (element-chasing).

(⊆\subseteq) Suppose x0∈A∩(B∪C)x_0 \in A \cap (B \cup C). By the definition of intersection this means x0∈Ax_0 \in A and x0∈B∪Cx_0 \in B \cup C. By the definition of union, x0∈B∪Cx_0 \in B \cup C means x0∈Bx_0 \in B or x0∈Cx_0 \in C. Consider the two cases separately. Case 1: x0∈Bx_0 \in B. Combined with x0∈Ax_0 \in A, this gives x0∈A∩Bx_0 \in A \cap B. Case 2: x0∈Cx_0 \in C. Combined with x0∈Ax_0 \in A, this gives x0∈A∩Cx_0 \in A \cap C. In either case x0x_0 lies in x0∈A∩Bx_0 \in A \cap B or in x0∈A∩Cx_0 \in A \cap C, so x0∈(A∩B)∪(A∩C)x_0 \in (A \cap B) \cup (A \cap C).

(⊇\supseteq) Suppose x0∈(A∩B)∪(A∩C)x_0 \in (A \cap B) \cup (A \cap C). By the definition of union this means x0∈A∩Bx_0 \in A \cap B or x0∈A∩Cx_0 \in A \cap C. If x0∈A∩Bx_0 \in A \cap B, then x0∈Ax_0 \in A and x0∈Bx_0 \in B, hence x0∈B∪Cx_0 \in B \cup C (since x0x_0 is in BB, it is in BB or CC), so x0∈A∩(B∪C)x_0 \in A \cap (B \cup C). If instead x0∈A∩Cx_0 \in A \cap C, then x0∈Ax_0 \in A and x0∈Cx_0 \in C, hence x0∈B∪Cx_0 \in B \cup C, so again x0∈A∩(B∪C)x_0 \in A \cap (B \cup C).

Since every element of the left-hand side lies in the right-hand side and vice versa, the two sets contain exactly the same elements, so A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C). This finishes the proof.

For any two finite sets AA and BB: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|, where ∣A∣|A|, ∣B∣|B|, ∣A∩B∣|A \cap B|, ∣A∪B∣|A \cup B| denote the number of elements of each set.

Why is it true?

Simply adding ∣A∣|A| and ∣B∣|B| double-counts every element that is in both sets, so subtracting ∣A∩B∣|A \cap B| once corrects the overcount. This is exactly the arithmetic behind reading a two-circle Venn diagram from survey data: people who like both coffee and tea must not be counted twice when asking how many people like at least one.

Proof

The key idea is to split A∪BA \cup B into three pairwise-disjoint pieces and count each piece once.

First, partition each set using the other: A=(A∖B)∪(A∩B)A = (A \setminus B) \cup (A \cap B) and B=(B∖A)∪(A∩B)B = (B \setminus A) \cup (A \cap B). In each equation the two pieces on the right are disjoint, because (A∖B)∩(A∩B)=∅(A\setminus B) \cap (A \cap B) = \varnothing (an element outside BB cannot simultaneously be inside BB) and likewise (B∖A)∩(A∩B)=∅(B\setminus A) \cap (A \cap B) = \varnothing. Since a finite set's size equals the sum of the sizes of any partition into disjoint pieces, this gives ∣A∣=∣A∖B∣+∣A∩B∣|A| = |A \setminus B| + |A \cap B| and ∣B∣=∣B∖A∣+∣A∩B∣|B| = |B \setminus A| + |A \cap B|.

Next, observe that A∪BA \cup B itself splits into three pairwise-disjoint pieces: A∪B=(A∖B)∪(B∖A)∪(A∩B)A \cup B = (A \setminus B) \cup (B \setminus A) \cup (A \cap B). Indeed A∖BA\setminus B, B∖AB\setminus A, A∩BA\cap B are pairwise disjoint (an element in A∖BA\setminus B is not in BB, hence not in A∩BA \cap B or in B∖AB \setminus A; symmetrically for the others), and their union recovers exactly the elements that are in AA or in BB. Counting this partition gives ∣A∪B∣=∣A∖B∣+∣B∖A∣+∣A∩B∣|A \cup B| = |A \setminus B| + |B \setminus A| + |A \cap B|.

Finally substitute: from ∣A∣=∣A∖B∣+∣A∩B∣|A| = |A \setminus B| + |A \cap B| we get ∣A∖B∣|A \setminus B| =∣A∣−∣A∩B∣= |A| - |A\cap B|, and from ∣B∣=∣B∖A∣+∣A∩B∣|B| = |B \setminus A| + |A \cap B| we get ∣B∖A∣|B \setminus A| =∣B∣−∣A∩B∣= |B| - |A\cap B|. Plugging both into ∣A∪B∣=∣A∖B∣+∣B∖A∣+∣A∩B∣|A \cup B| = |A \setminus B| + |B \setminus A| + |A \cap B| gives ∣A∪B∣=(∣A∣−∣A∩B∣)+(∣B∣−∣A∩B∣)+∣A∩B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = (|A| - |A\cap B|) + (|B| - |A\cap B|) + |A\cap B| = |A| + |B| - |A\cap B|, which is exactly ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. This finishes the proof.

UndergraduateReal-World Applications and Worked Examples

Set operations are the backbone of two everyday tools. In survey analysis, a two-circle Venn diagram of respondents who like product AA and product BB is read off using ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|: total interest is not the raw sum, because people in A∩BA \cap B would be counted twice. In search-engine and e-commerce filters, combining "category AA" AND "on sale BB" is literally the intersection A∩BA \cap B, combining with OR is the union A∪BA \cup B, and excluding a tag with NOT is the difference A∖BA \setminus B; the distributive law A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C) is what lets a query planner rewrite "AA and (BB or CC)" into "(AA and BB) or (AA and CC)" without changing the results.

Example: Reading a survey with inclusion–exclusion

A school surveys 120120 students. 7070 say they play soccer, 4545 say they play basketball, and 2525 say they play both. How many students play at least one of the two sports, and how many play neither?

Solution

Let AA be the set of students who play soccer and BB the set who play basketball, so ∣A∣=70|A| = 70, ∣B∣=45|B| = 45, ∣A∩B∣=25|A \cap B| = 25.

By the inclusion–exclusion theorem proved above, ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. Substituting the numbers: ∣A∪B∣=70+45−25=90|A \cup B| = 70 + 45 - 25 = 90. So 9090 students play at least one of the two sports.

Since the total surveyed is 120120, the number playing neither sport is the complement of A∪BA \cup B inside the whole group of 120120 students: 120−90=30120 - 90 = 30.

Notice the common mistake of simply adding 70+45=11570+45=115: this would double-count the 2525 students who play both, which is exactly why the theorem subtracts ∣A∩B∣|A \cap B| once.

Example: Simplifying a search filter with the distributive law

An online store's catalog is a set UU of products. Let AA be "in the Shoes category", BB be "on sale", and CC be "new arrival". A shopper's filter is "in Shoes, and (on sale or new arrival)", i.e. A∩(B∪C)A \cap (B \cup C). Show this is the same product list as running two separate simpler filters and merging the results, and explain why a search engine prefers the second form.

Solution

By the distributive law proved above, A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C). Applying it here with A=A= Shoes, B=B= on sale, C=C= new arrival: A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C).

The left-hand side A∩(B∪C)A \cap (B \cup C) describes a single combined filter: first build the set B∪CB \cup C of everything on sale or new, then intersect with Shoes. The right-hand side describes two independent simple filters, "Shoes on sale" (A∩BA\cap B) and "new Shoes" (A∩CA \cap C), whose results are then merged with a union.

Because the theorem guarantees both sides list exactly the same products, a query planner is free to choose whichever execution is faster. Running two simple single-condition filters (each of which can use a fast pre-built index for one category) and merging with a union is usually cheaper than evaluating a nested "or inside an and" expression directly, so real search engines rewrite queries into the right-hand form before executing them.

Concretely, if Shoes ={1,2,3,4,5}=\{1,2,3,4,5\}, on sale ={2,4,6}=\{2,4,6\}, new arrival ={1,4,7}=\{1,4,7\}, then B∪C={1,2,4,6,7}B\cup C=\{1,2,4,6,7\} and A∩(B∪C)={1,2,4}A\cap(B\cup C)=\{1,2,4\}; separately A∩B={2,4}A\cap B=\{2,4\} and A∩C={1,4}A\cap C=\{1,4\}, whose union is again {1,2,4}\{1,2,4\}, confirming the two computations agree.

Let A={2,4,6,8}A=\{2,4,6,8\}. Which statement is correct?

A class has 3030 students; 1818 like math, 1515 like physics, and 99 like both. How many like at least one of the two subjects?

A shopping site lets you filter "brand AA" OR "under 50 dollars (BB)". Which set operation computes the results shown?

With A={1,2,3}A=\{1,2,3\}, B={2,3}B=\{2,3\}, C={3,4}C=\{3,4\}, does A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C) hold, and what is the common value?

References

  1. Paul R. Halmos (1960). Naive Set Theory
  2. Kenneth H. Rosen (2019). Discrete Mathematics and Its Applications