1.3 Set Operations and Cartesian Products
In Section 1.2, you learned how to describe one set and how to decide whether an object belongs to it. We will now combine two sets. This gives us two useful ways to build new objects:
- Set operations combine or compare membership rules.
- A Cartesian product combines one choice from a first set with one choice from a second set.
By the end of this section, you will be able to compute unions, intersections, differences, complements, and Cartesian products from scratch. You will also be able to explain what each result means instead of only manipulating symbols.
Fix the universe before operating on sets
A universal set, written , is the collection of every object currently under discussion. It is not the set of everything that exists. Its meaning depends on the problem.
For example, if we study the integers from through , we may choose
Every set in that problem is then treated as a subset of . Let
We will use this same example throughout the first half of the section. Keeping one universe fixed prevents an important ambiguity: the phrase “not in ” only tells us which objects to keep after we know which objects are allowed in the first place.
Four set operations, one element at a time
Imagine choosing one element from and asking two yes-or-no questions:
1. Is in ?
2. Is in ?
There are exactly four possible membership regions:
| Is ? | Is ? | Region containing |
|---|---|---|
| yes | no | only |
| yes | yes | both and |
| no | yes | only |
| no | no | neither set |
Every operation below selects one or more of these regions.
Union: keep anything appearing in either set
The union of and , written , contains an element when it is in , in , or in both:
The vertical bar means “such that.” Read the formula as: “the set of elements in such that belongs to or .” Mathematical “or” is inclusive here, so an element in both sets is kept.
For our example, start with the elements of and add the elements of that are not already listed:
Repeated elements are written only once because a set does not record duplicates.
Intersection: keep only shared elements
The intersection, written , contains an element only when it belongs to both sets:
Checking the elements shows that only and pass both membership tests:
Difference: keep one side and remove the overlap
The difference begins with and removes every element that also lies in :
The symbol means “is not an element of.” In the example, remove and from , leaving
Difference has a direction. If we reverse the sets, we begin with instead:
Therefore and are generally different.
Complement: keep everything outside one set
The complement of , written , contains every element of the fixed universe that is not in :
Starting with and removing gives
This is why the universe matters. If the universe changed, the complement could change even when stayed the same.
Check all four regions
For the same , , and , the four disjoint regions are
“Disjoint” means that no element occurs in two of these regions. Together the regions contain every element of . You can therefore use them as an error check: each element of must appear exactly once.
The lab turns the four membership regions into drop zones. Before dropping an object, say its two membership answers aloud—“in , not in ,” for example—and then choose the matching region. This connects the picture to the membership rule.
Counting a union without counting twice
If we add and , every element in is counted once as part of and a second time as part of . Subtracting the size of the intersection removes that extra copy:
In our example,
which agrees with the five listed elements . This reasoning is called inclusion–exclusion for two sets. Later chapters will extend the same counting idea.
Why complements reverse “or” and “and”
The following identities are called De Morgan’s laws:
The notation looks compact, but the idea can be read in ordinary language:
- An element is not in the union only if it is not in and not in .
- An element is not in the intersection if it is not in , or not in , or in neither.
To check the first law, follow one arbitrary element . If , then was accepted by neither set. Thus and , so . The reasoning also runs backward, so the two sets contain exactly the same elements.
The words “and,” “or,” and “not” will become formal logical operations in Chapter 2. Here you only need their ordinary membership meanings.
Ordered pairs remember two positions
Set operations combine membership rules. Our second construction combines choices. Suppose an app has two users,
and three actions,
To describe “Ada performs edit,” we need to store both a user and an action. An ordered pair does this:
The first position and second position have different roles. In general,
Two ordered pairs are equal only when their first coordinates match and their second coordinates match:
The words first coordinate and second coordinate simply name the two positions. No geometric knowledge is required.
Cartesian products generate every possible pair
The Cartesian product contains every ordered pair whose first coordinate comes from and whose second coordinate comes from :
Use a systematic procedure to list it:
1. Choose the first element of .
2. Pair it with every element of .
3. Move to the next element of and repeat.
For and , this produces
We may display the same six pairs as a rectangular table:
The brackets only organize the pairs into rows and columns here. You do not need matrix algebra.
If has choices and has choices, each of the first-coordinate choices has possible partners. Therefore there are pairs. For any finite sets,
In the pixel floor, every cell represents one ordered pair. Its row fixes one coordinate and its column fixes the other. Painting all cells constructs the full Cartesian product; painting only selected cells creates a set of selected pairs.
Such a selected set is called a binary relation from to . For now, “relation” means only “some selected ordered pairs.” Chapter 4 will build the full theory, so no other facts about relations are assumed here.
Chapter bridge
Across this chapter, you learned to recognize discrete states, describe collections as sets, operate on membership, and construct ordered pairs. Notice how often the words “and,” “or,” and “not” appeared in our definitions. Chapter 2 begins with those familiar words and turns them into precise logical statements, one step at a time.