A relation $R$ from set $A$ to set $B$ is any subset of $A \times B$. So a relation simply selects the ordered pairs that satisfy some rule, leaving the rest out:
For each relation we name three sets:
| Term | Meaning |
|---|---|
| Domain | set of all first components in $R$ — the inputs actually used |
| Range | set of all second components in $R$ — the outputs actually produced |
| Codomain | the whole target set $B$ — every output that could appear |
The range is always a subset of the codomain ($\text{range} \subseteq B$), but they need not be equal — the codomain is the "menu", the range is "what was ordered".
Counting relations: a relation is a subset of $A \times B$, which has $n(A)\cdot n(B)$ pairs. Since a set with $k$ elements has $2^k$ subsets, the number of possible relations from $A$ to $B$ is
Relations are often given by a rule, e.g. $R = \{(x, y) : y = x + 1,\ x \in A\}$, which you then list in roster form by testing each input.
Deeper Insight — a relation is a filter, and that is the bridge to functions: The whole content of this idea is "subset of the Cartesian product". $A \times B$ offers every possible pairing; a relation keeps only the pairings that obey a chosen condition — it is a filter on pairings. Reading the definition this way makes the domain/range distinction obvious: the domain is which inputs survived the filter, the range is which outputs they map to. It also explains the codomain, the subtlest of the three: we declare a target set $B$ in advance (the codomain) before we know which of its members will actually be hit (the range). This advance declaration is exactly what makes the next section possible — a function is nothing more than a relation with one extra rule imposed on the filter ("each input is used once, and exactly once"), so understanding a relation as a constrained subset is the conceptual key to the rest of the chapter.