Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 2: Set Operations

Chapter 1 introduced sets, membership, subsets, cardinality, and common number sets. This chapter builds directly on that notation by showing how sets can be combined, compared, and reduced.

Universe and Complement

The universe and set complement describe what is not contained in a given set. A universe first establishes the context in which a complement is defined.

Definition: Universe

Set A and two elements shown inside the surrounding universe U.
Figure 2.1. A diagram showing the universe as a large rectangular region containing all relevant elements, with a set represented as a subset inside it.

The universe, often denoted as , refers to a set that contains all the objects or elements relevant to a particular discussion or problem. It serves as the context within which all other sets are defined and interpreted.

Examples: Universes

The universe depends on the context of the problem. The following examples show how changing the universe changes what the named subsets mean.

  1. Let the universe be the set of all lowercase English letters: The following subsets can then be defined:

    • , the set of vowels.
    • , the set of consonants.

    Here, provides a clear context: and together cover all letters in the alphabet.

  2. Let the universe be the set of all real numbers: The following subsets can then be defined:

    • . The set of all real numbers strictly between and .
    • . The set of all real numbers between 2 and 5, including the endpoints.
    • . The set of all real numbers greater than 3.

    In this case, defines the entire number line, and each of these sets represents a subset of it.

Definition: Set Difference

Overlapping sets A and B with the part of A outside B highlighted.
Figure 2.2. The highlighted region is : the part of outside .

The set difference of two sets and , denoted by , is the set of all elements that are in but not in .

The notation says that an element must belong to and not belong to . In other words, set difference removes from all elements that also belong to .

The alternative notation is also used for set difference. This book uses to distinguish the operation from numerical subtraction.

Examples: Set Difference

In each example below, keeps only the elements that belong to and not to .

  1. Taking and gives Thus, the irrational numbers are precisely the real numbers that are not rational.

  2. Let and . Then: These are the vowels that are not in the set .

  3. Let and . The elements in that are not in are:

  4. Let and . The fruits in that are not in are:

  5. Let and . Since and contain the same elements, the difference is: That is, the difference is the empty set because there is nothing in that is not in .

  6. Let and . Then: The difference consists of the endpoints of the closed interval that are not part of the open interval .

These examples show that the set difference identifies what belongs only to the first set and not to the second.

A complement is a special case of set difference in which a set is subtracted from the universe.

Definition: Complement

Universe U with the diagonally hatched region outside set A highlighted as the complement of A.
Figure 2.3. Diagram illustrating the complement of a set within the universe , highlighting all elements in that are not in .

The complement of a set , denoted by or , consists of all elements in the universe that are not in . In other words:

The notations and are both common. This book usually uses in set calculations; also appears when emphasizing the parallel with logical negation. The overline notation is another common alternative.

The expression states that is not an element of . The complement therefore describes what is not included in a set within the context of a given universe.

Examples: Complements

Each complement is taken relative to a chosen universe, so must first be stated or described.

  1. Let and . The complement of is: Here, contains the elements of that are not in .

  2. Let be the set of vowels in the English alphabet. If the universe is the set of all lowercase letters, then the complement is: Here, the complement is expressed verbally to save space, although all consonants could also be listed explicitly.

  3. Let be a standard deck of playing cards, and let be the set of all spades. The complement is: In this context, represents every card that is not a spade.

  4. Let and . The complement of is: This means contains all real numbers less than or equal to 10.

These examples illustrate how the complement operation identifies everything outside a given set, relative to a specified universe .

Union and Intersection

Union and intersection describe how two sets can be combined or compared. These operations are especially useful when a problem involves the words "or" and "and."

Definition: Union

Overlapping sets A and B with all of both sets highlighted.
Figure 2.4. The highlighted region is : everything in , in , or in both.

Let and be sets.

The union of and , written , is the set of all elements that are in , in , or in both:

Here, "or" is inclusive: an element belongs to if it belongs to at least one of the two sets.

Definition: Intersection

Overlapping sets A and B with only their shared part highlighted.
Figure 2.5. The highlighted region is : the part shared by and .

Let and be sets.

The intersection of and , written , is the set of all elements that are in both and :

Example: Union of Finite Sets

Let

The union contains every element that appears in at least one of the sets:

Example: Intersection of Finite Sets

Let

The intersection contains only the elements that appear in both sets:

The examples above illustrate that union and intersection create new sets from old ones. Since these operations are used repeatedly in mathematics, it is useful to know a few basic rules for rewriting expressions involving them.

Properties: Union and Intersection

Let , , and be sets. The following identities hold:

Table 2.1. Basic properties of union and intersection.

PropertyUnionIntersection
Commutative law
Associative law
Distributive law
Identity law
Idempotent law
Absorption law

These laws say that some changes in grouping or order do not change the set being described. They follow the meanings above: union collects elements from either set or both, while intersection keeps only the shared elements.

Properties: Complements and De Morgan's Laws

When and are subsets of a universe , the following identities hold:

De Morgan's laws describe how a complement changes unions and intersections:

The following examples illustrate both laws using finite sets.

Example: De Morgan's First Law

Let

First, form the union and then take its complement:

Alternatively, take the two complements first:

Their intersection is

Both methods produce the same set, illustrating that .

Universe U containing overlapping sets A and B, with elements 7 and 8 in the shaded region outside both sets.
Figure 2.6. The shaded region contains and , the elements that are outside and also outside . It can therefore be described as either or .

Example: De Morgan's Second Law

Let

First, form the intersection and then take its complement:

Alternatively, take the two complements first:

Their union is

Both methods produce the same set, illustrating that .

Universe U containing overlapping sets A and B, with every region except their overlap shaded.
Figure 2.7. The shaded region contains every element that is not shared by and . It can therefore be described as either or .

Note: Disjoint Sets

Two sets are called disjoint if they have no elements in common. In symbols, and are disjoint if

For example, and are disjoint.

For finite sets, union and intersection also support counting without double-counting. This becomes especially useful in Chapter 15, where sample spaces and events are represented as sets.

Note: Counting a Union

For finite sets and ,

The subtraction is needed because the elements in are counted once in and once again in .

For example, if , , and , then

If and are disjoint, then , so the formula becomes .

Set Operations on Intervals

When sets are subsets of the real line, union and intersection can often be described using intervals. This connects set notation with interval notation.

Example: Overlapping Intervals

Let

The intersection contains the real numbers that lie in both intervals:

The union contains the real numbers that lie in at least one of the intervals:

The endpoint is not included in the intersection because , while is included because and .

Aligned number lines for A equals the closed interval from 0 to 3, B equals the open interval from 2 to 5, their intersection, and their union.
Figure 2.8. The overlap gives , while the full region covered by either interval gives .

Example: Disjoint Intervals

Let

These intervals do not overlap, so

Their union is

This union cannot be written as one interval because there is a gap between and .

Aligned number lines for two disjoint intervals C and D, their empty intersection, and their two-part union.
Figure 2.9. The gap between and makes their intersection empty and leaves their union in two separate parts.

Other Set Operations

A few other foundational set operations are commonly used in mathematics and data science. These operations are not developed in detail here, but the table below provides a brief overview.

Table 2.2. Additional set operations and their meanings.

SymbolOperationDescription
Cartesian product of and The set of all ordered pairs where and
The power setThe set of all subsets of , including the empty set () and itself