Section 5.1 Introduction to Relations
A relation \(R\) from set \(A\) to set \(B\) is any subset of the Cartesian product \(A \times B\text{,}\) indicating that \(R \subseteq A \times B\text{.}\) We can ask Sage to decide if \(R\) is a relation from \(A\) to \(B\text{.}\) First, construct the Cartesian product \(C = A \times B\text{.}\) Then, build the set \(S\) of all subsets of \(C\text{.}\) Finally, ask if \(R\) is a subset of \(S\text{.}\)
Recall the Cartesian product consists of all possible ordered pairs \((a, b)\text{,}\) where \(a \in A\) and \(b \in B\text{.}\) Each pair combines an element from set \(A\) with an element from set \(B\text{.}\)
In this example, an element in the set \(A\) relates to an element in \(B\) if the element from \(A\) is twice the element from \(B\text{.}\)
Let’s use relations to explore matching items of clothes. Let’s define two sets, jackets and shirts, as examples:
\begin{equation*}
\text{jackets} = \{j_1, j_2, j_3\}
\end{equation*}
\begin{equation*}
\text{shirts} = \{s_1, s_2, s_3, s_4\}
\end{equation*}
The Cartesian product of jackets and shirts includes all possible combinations of jackets with shirts.
Since the Cartesian product returns all the possible combinations, some jackets and shirts will clash. Let’s create a relation from jackets to shirts based on matching the items of clothing.