37. Cartesian Products

37.1 Definition: Cartesian product of two sets

Let $A$ and $B$ be sets. $A\times B$ is the set of all ordered pairs whose first coordinate is an element of $A$ and whose second coordinate is an element of $B$. $A\times B$ is called the Cartesian product of $A$ and $B$ (in that order).

37.1.1 Example if $A=\{1,2\}$ and $B=\{2,3,4\}$, then

$$A\times B=\left\{\langle 1,2\rangle,\langle 1,3\rangle,\langle 1,4\rangle,\langle 2,2\rangle,\langle 2,3\rangle,\langle 2,4\rangle\right\}$$

and

$$B\times A=\left\{\langle 2,1\rangle,\langle 2,2\rangle,\langle 3,1\rangle,\langle 3,2\rangle,\langle 4,1\rangle,\langle 4,2\rangle\right\}$$

37.1.2 Exercise Write out the elements of $\{1,2\}\times\{a,b\}$. (Answer on page 244.)

37.2 Theorem

If $A$ is any set, then $A\times\emptyset=\emptyset\times A=\emptyset$.

37.2.1 Exercise Prove Theorem 37.2.

37.2.2 Example $\mathrm{R}\times\mathrm{R}$ is often called the “real plane”, since it consists of all ordered pairs of real numbers, and each ordered pair represents a point in the plane once a coordinate system is given. Graphs of straight lines and curves are subsets of $\mathrm{R}\times\mathrm{R}$. For example, the $x$-axis is $\left\{\langle x,0\rangle\mid x\in\mathrm{R}\right\}$ and the parabola $y=x^{2}$ is $\left\{\langle x,y\rangle\mid x\in\mathrm{R}\wedge y=x^{2}\right\}$, which could be written $\left\{\langle x,x^{2}\rangle\mid x\in\mathrm{R}\right\}$ (recall the discussion in Section 19.2).

37.3 Definition: diagonal

For any set $A$, the subset $\left\{\langle a,a\rangle\mid a\in A\right\}$ of $A\times A$ of all pairs whose two coordinates are the same is called the diagonal of $A$, denoted $\Delta_{A}$.

37.3.1 Worked Exercise Write out the diagonal of $\{1,2\}\times\{1,2\}$.

Answer $\{\langle 1,1\rangle,\langle 2,2\rangle\}$.

37.3.2 Example The diagonal $\Delta_{\mathrm{R}}$ of $\mathrm{R}\times\mathrm{R}$ is the 45-degree line from lower left to upper right. It is the graph of the equation $y=x$.

37.4 Cartesian products in general

The notion of Cartesian product can be generalized to more than two factors using the idea of tuple.

37.5 Definition: Cartesian product

Let $A_{1},A_{2},\ldots,A_{n}$ be sets — in other words, let $\langle A_{i}\rangle_{i\in\mathbf{n}}$ be an $n$-tuple of sets. Then $A_{1}\times A_{2}\times\cdots\times A_{n}$ is the set

$$\left\{\langle a_{1},a_{2},\ldots,a_{n}\rangle\mid(\forall i{:}\mathbf{n})(a_{i}\in A_{i})\right\} \tag{37.1}$$

of all $n$-tuples whose $i$th coordinate lies in $A_{i}$.

37.5.1 Example The set $\mathrm{R}\times\mathrm{Z}\times\mathrm{R}$ has triples as elements; it contains as an element the ordered triple $\langle\pi,-2,3\rangle$, but not, for example, $\langle-2,\pi,3\rangle$.

37.5.2 Warning Observe that $\mathrm{R}\times\mathrm{N}\times\mathrm{R}$, $(\mathrm{R}\times\mathrm{N})\times\mathrm{R}$ and $\mathrm{R}\times(\mathrm{N}\times\mathrm{R})$ are three different sets; in fact, any two of them are disjoint. Of course, in an obvious sense they all represent the same data.

37.5.3 Example Consider the set

$$D=\{\langle m,n\rangle\mid m\text{ divides }n\}$$

where $m$ and $n$ are of type integer. Thus $\langle 3,6\rangle$, $\langle-3,6\rangle$ and $\langle 5,0\rangle$ are elements of $D$ but not $\langle 3,5\rangle$. $D$ is not a Cartesian product, although it is a (proper) subset of the cartesian product $\mathrm{Z}\times\mathrm{Z}$. The point is that a pair in $A\times B$ can have any element of $A$ as its first coordinate and any element of $B$ as its second coordinate, regardless of what the first coordinate is. In $D$ what the second coordinate is depends on what the first coordinate is.

A set such as $D$ is a relation, a concept discussed later.

37.6 Exercise set

Exercises 37.6.1 through 37.6.6 give “facts” which may or may not be correct for all sets $A$, $B$ and $C$. State whether each “fact” is true for all sets $A$, $B$ and $C$, or false for some sets $A$, $B$ or $C$, and for those that are not true for all sets, give examples of sets for which they are false.

37.6.1 $A\times A=A$. (Answer on page 244.)

37.6.2 $A\times B=B\times A$.

37.6.3 $A\cup(B\times C)=(A\cup B)\times(A\cup C)$.

37.6.4 $A\cap(B\times C)=(A\cap B)\times(A\cap C)$.

37.6.5 $A\times(B\times C)=(A\times B)\times C$.

37.6.6 $\mathcal{P}(A\times B)=\mathcal{P}(A)\times\mathcal{P}(B)$.

37.7 Exercise set

The statements in problems 37.7.1 through 37.7.3 are true for all sets $A$, $B$ and $C$, except that in some cases some of the sets $A$, $B$ and $C$ have to be nonempty if the statement is to be true for all other sets named. Amend the statement in each case so that it is true.

37.7.1 For all sets $A$, $B$ and $C$, $A\times C=B\times C\Rightarrow A=B$. (Answer on page 244.)

37.7.2 For all sets $A$ and $B$, $A\times B=B\times A\Rightarrow A=B$.

37.7.3 For all sets $A$, $B$ and $C$, $A\subseteq B\Rightarrow(A\times C)\subseteq(B\times C)$.

37.8 Cartesian product in Mathematica

The dmfuncs.m package contains the command CartesianProduct, which gives the Cartesian product of a sequence of sets. For example,

CartesianProduct[{1,2},{a,b,c},{x,y}] produces

{{1, a, x}, {1, a, y}, {1, b, x}, {1, b, y}, {1, c, x}, {1, c, y},

{2, a, x}, {2, a, y}, {2, b, x}, {2, b, y}, {2, c, x}, {2, c, y}}

37.8.1 Exercise (Mathematica) The command CartesianProduct mentioned in 37.8 works on any lists, not just sets (see 17.2, page 27). Write a precise description of the result given when CartesianProduct is applied to a sequence of lists, some of which contain repeated entries.

37.9 Exponential notation

If all the sets in a Cartesian product are the same, exponential notation is also used. Thus $A^{2}=A\times A$, $A^{3}=A\times A\times A$, and in general

$$A^{n}=A\times A\times\cdots\times A$$

($n$ times). These are called Cartesian powers of $A$; in particular, $A^{2}$ is the Cartesian square of $A$. This notation is extended to 0 and 1 by setting $A^{0}=\{\langle\rangle\}$ (the singleton set containing the null tuple as an element) and $A^{1}=A$.

37.9.1 Exercise Let $A=\{1,2\}$ and $B=\{3,4,5\}$. Write all the elements of each set:

$$\begin{array}{ll} \text{a) } A^{0} & \text{f) } B\times A \\ \text{b) } A^{1} & \text{g) } A\times A\times B \\ \text{c) } A^{2} & \text{h) } A\times(A\times B) \\ \text{d) } A^{3} & \text{i) } (A\times B)\cup A \\ \text{e) } A\times B & \text{j) } (A\times B)\cap A \end{array}$$

(Answer on page 244.)

37.9.2 Exercise For each pair of numbers $\langle m,n\rangle\in\{1,2,3,4,5,6,7\}\times\{1,2,3,4,5,6,7\}$, state whether item $m$ in the first column is an element of the set in item $n$ of the second column. $A=\{1,3,7\}$, $B=\{1,2,3,4,5\}$.

$$\begin{array}{rlrl} 1. & \langle 3,5\rangle & 1. & A\times A \\ 2. & \langle 3,3\rangle & 2. & A^{3} \\ 3. & \langle 3,3,5\rangle & 3. & A\times B \\ 4. & \left\{\langle 3,5\rangle,\langle 7,5\rangle\right\} & 4. & B\times A \\ 5. & \langle\{3,7\},\{3,5\}\rangle & 5. & \mathcal{P}(A\times B) \\ 6. & \emptyset & 6. & \mathcal{P}A\times\mathcal{P}B \\ 7. & \langle 1,7,7\rangle & 7. & B^{2} \end{array}$$

(Answer on page 244.)

Pages 52–55 of the book (PDF).