Grade 6
Sets and set operations
A set is a well-defined collection of objects, its elements; says belongs to . One set is a subset of another, , when every element of is also in . From two sets we build new ones: the union (elements in or in ), the intersection (elements in both), and the difference (in but not ). These operations obey algebra-like laws such as the distributive law , and counting elements of a union follows the inclusion-exclusion rule , 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 holds building blocks, box holds cars. Some toys are block-cars and sit in both boxes at once. Asking "?" is asking whether a specific toy is inside box . Asking "?" is asking whether every single toy in box is also somewhere in box . Combining the two boxes into one pile gives the union ; keeping only toys that are in both boxes gives the intersection ; taking box and throwing out anything also in box gives the difference . The network widget below lets you drag elements between two circles and watch the four operations recompute live.
SchoolFormal definitions and a comparison table
Definition: Set, element, subset
A set is a collection of distinct objects; each object with is called an element of . Set is a subset of set , written , when every element of is also an element of ; two sets are equal exactly when and hold simultaneously.
The union 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.
| Operation | Definition | Result |
|---|---|---|
| Union | ||
| Intersection | ||
| Difference | ||
| Subset | every element of is in | false () |
UndergraduateTwo key theorems, with full proofs
For any three sets , , : .
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 , and (on sale or new arrival )" 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 (element-chasing).
() Suppose . By the definition of intersection this means and . By the definition of union, means or . Consider the two cases separately. Case 1: . Combined with , this gives . Case 2: . Combined with , this gives . In either case lies in or in , so .
() Suppose . By the definition of union this means or . If , then and , hence (since is in , it is in or ), so . If instead , then and , hence , so again .
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 . This finishes the proof.
For any two finite sets and : , where , , , denote the number of elements of each set.
Why is it true?
Simply adding and double-counts every element that is in both sets, so subtracting 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 into three pairwise-disjoint pieces and count each piece once.
First, partition each set using the other: and . In each equation the two pieces on the right are disjoint, because (an element outside cannot simultaneously be inside ) and likewise . Since a finite set's size equals the sum of the sizes of any partition into disjoint pieces, this gives and .
Next, observe that itself splits into three pairwise-disjoint pieces: . Indeed , , are pairwise disjoint (an element in is not in , hence not in or in ; symmetrically for the others), and their union recovers exactly the elements that are in or in . Counting this partition gives .
Finally substitute: from we get , and from we get . Plugging both into gives , which is exactly . 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 and product is read off using : total interest is not the raw sum, because people in would be counted twice. In search-engine and e-commerce filters, combining "category " AND "on sale " is literally the intersection , combining with OR is the union , and excluding a tag with NOT is the difference ; the distributive law is what lets a query planner rewrite " and ( or )" into "( and ) or ( and )" without changing the results.
Example: Reading a survey with inclusion–exclusion
A school surveys students. say they play soccer, say they play basketball, and say they play both. How many students play at least one of the two sports, and how many play neither?
Solution
Let be the set of students who play soccer and the set who play basketball, so , , .
By the inclusion–exclusion theorem proved above, . Substituting the numbers: . So students play at least one of the two sports.
Since the total surveyed is , the number playing neither sport is the complement of inside the whole group of students: .
Notice the common mistake of simply adding : this would double-count the students who play both, which is exactly why the theorem subtracts once.
Example: Simplifying a search filter with the distributive law
An online store's catalog is a set of products. Let be "in the Shoes category", be "on sale", and be "new arrival". A shopper's filter is "in Shoes, and (on sale or new arrival)", i.e. . 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, . Applying it here with Shoes, on sale, new arrival: .
The left-hand side describes a single combined filter: first build the set of everything on sale or new, then intersect with Shoes. The right-hand side describes two independent simple filters, "Shoes on sale" () and "new Shoes" (), 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 , on sale , new arrival , then and ; separately and , whose union is again , confirming the two computations agree.
Let . Which statement is correct?
A class has students; like math, like physics, and like both. How many like at least one of the two subjects?
A shopping site lets you filter "brand " OR "under 50 dollars ()". Which set operation computes the results shown?
With , , , does hold, and what is the common value?
References
- Paul R. Halmos (1960). Naive Set Theory
- Kenneth H. Rosen (2019). Discrete Mathematics and Its Applications