Part IV — Miscellaneous · Chapter 13
Mappings
Chapter 12's functions took numbers to numbers. Nothing in the definition required that. Drop the requirement and the same idea covers isometries of the plane, shuffles of a deck, and the question of when something can be undone.
A hotel has rooms numbered $1, 2, 3, \dots$ without end, and every single room is occupied. A new guest arrives. Can the hotel give them a room of their own without sending anyone away?
- No — full means full
- Yes
With a hundred rooms the answer is obvious. Decide whether infinitely many rooms changes anything.
You should be comfortable with what a function is (Chapter 12) — a mapping is that same definition with the word "numbers" removed. The symmetries of Chapter 6 are the running example.
Three quick ones from earlier chapters, to wake up what this chapter stands on. They are not scored. If one doesn't come to you, its solution says where to look.
If $f(x) = x^2 - 1$, what is $f(-2)$?
Answer: $3$
$(-2)^2 - 1 = 4 - 1 = 3$ — §12.1. Notice that $f(2) = 3$ too: two inputs, one output. This chapter gives that a name.
What is the natural domain of $f(x) = \dfrac{1}{x + 3}$?
- All real numbers.
- All real numbers except $-3$.
- $x > -3$.
Answer: all real numbers except $-3$
Only $x = -3$ makes the denominator zero — §12.1. The domain is part of the function, and in this chapter so is the codomain.
How many symmetries does a square have?
Answer: $8$
Four rotations and four reflections — §6.3. Each one rearranges the four corners; §13.3 calls such a rearrangement a permutation.
13.1 Definition of a mapping
Let $S$ and $T$ be sets. A mapping $f: S \to T$ assigns to each element $x \in S$ exactly one element $f(x) \in T$. We call $S$ the domain and $T$ the codomain. The image of $f$ is the set of elements actually hit: $$f(S) = \{\, f(x) : x \in S \,\} \subseteq T.$$
Only the word "numbers" has been removed from Chapter 12's definition. What that buys is reach: $S$ can be the points of the plane and $T$ the same, giving the isometries of Chapter 6; $S$ can be a set of five cards and $T$ the same five, giving a shuffle; $S$ can be the set of people in a room and $T$ the days of the year, giving each person's birthday.
The codomain is where the values are allowed to land; the image is where they actually do. For $f:\mathbf{R}\to\mathbf{R}$ with $f(x) = x^2$, the codomain is all the real numbers but the image is only $[0,\infty)$. The distinction looks pedantic until §13.2, where "surjective" is precisely the statement that the two coincide.
Let $f: \mathbf{R} \to \mathbf{R}$ be $f(x) = x^2 + 1$. Is $0$ in the image of $f$?
- Yes — $0$ is a real number.
- No — no input is sent to it.
Answer: no
$x^2 \ge 0$ for every real $x$, so $x^2 + 1 \ge 1$ and never equals $0$. The number $0$ is in the codomain — it is a real number — but not in the image, which is $[1, \infty)$.
13.2 Composition and inverses
Given $f: S \to T$ and $g: T \to U$, the composite $g \circ f : S \to U$ is defined by
Read it right to left: $f$ first, then $g$. The codomain of $f$ must match the domain of $g$, or the second step has nothing to work on.
Composition is associative — $(h\circ g)\circ f = h\circ(g\circ f)$, since both send $x$ to $h(g(f(x)))$ — but almost never commutative, as Chapter 6 already showed with a rotation and a reflection.
- $f$ is injective (one-to-one) if different inputs give different outputs: $f(x) = f(y)$ forces $x = y$.
- $f$ is surjective (onto) if every element of $T$ is hit: the image is all of $T$.
- $f$ is bijective if it is both.
Can a mapping from $\{1, 2, 3\}$ to $\{a, b\}$ be injective?
- Yes.
- No.
Answer: no
Three inputs need three different outputs, and only two are available, so two arrows must share a target. (It can be surjective: send $1 \to a$ and $2, 3 \to b$.)
In the arrow diagram: injective means no element on the right receives two arrows; surjective means none receives zero. Bijective means every element on the right receives exactly one — a perfect pairing.
Example 1. The same formula, three different answers
Consider $f(x) = x^2$. Is it injective? Surjective?
- As $f: \mathbf{R}\to\mathbf{R}$: not injective, since $f(2) = f(-2) = 4$. Not surjective either, since nothing maps to $-1$.
- As $f: \mathbf{R}\to[0,\infty)$: still not injective, but now surjective — every $y\ge0$ is $(\sqrt y)^2$.
- As $f: [0,\infty)\to[0,\infty)$: injective (two non-negative numbers with the same square are equal) and surjective. Bijective.
- So the question "is $f$ injective?" is unanswerable until the domain and codomain are specified. $\blacksquare$
This is the sharpest reason the pedantry of §13.1 was worth it. The formula did not change once; the answers changed three times.
Now the payoff. A mapping can be undone exactly when it is bijective.
$f: S\to T$ has an inverse $f^{-1}: T \to S$ — a mapping with $f^{-1}(f(x)) = x$ for all $x\in S$ and $f(f^{-1}(y)) = y$ for all $y\in T$ — if and only if $f$ is bijective.
Why. To define $f^{-1}(y)$ we must name the element sent to $y$. Surjectivity guarantees there is at least one; injectivity guarantees there is at most one. Together they give exactly one, which is what a mapping needs. Conversely, if $f$ has an inverse then $f(x)=f(y)$ gives $x = f^{-1}(f(x)) = f^{-1}(f(y)) = y$, so $f$ is injective; and any $y$ is hit by $f^{-1}(y)$, so $f$ is surjective. $\blacksquare$
Your turn, with help. Finding an inverse
Find the inverse of $f(x) = 3x - 5$, as a mapping from $\mathbf{R}$ to $\mathbf{R}$. Try each step before opening it.
- Give the output a name: $y = 3x - 5$. Undoing $f$ means recovering $x$ from $y$.
-
Solve for $x$
Add $5$: $y + 5 = 3x$. Multiply by $\tfrac13$: $x = \dfrac{y + 5}{3}$.
-
State the inverse and check it
$f^{-1}(y) = \dfrac{y+5}{3}$. Check: $f^{-1}(f(x)) = \dfrac{(3x - 5) + 5}{3} = x$ ✓ and $f(f^{-1}(y)) = 3 \cdot \dfrac{y+5}{3} - 5 = y$ ✓. $\blacksquare$
Every $y$ produced exactly one $x$ — that is the bijection showing itself. Try the same with $f(x) = x^2$ and the step "solve for $x$" gives two answers or none, which is the failure of injectivity and of surjectivity, in that order.
Let $g(x) = 2x + 1$ on the real numbers. What is $g^{-1}(7)$?
Answer: $3$
$g^{-1}(7)$ is the number $x$ with $2x + 1 = 7$, so $x = 3$. You do not need a formula for $g^{-1}$ to evaluate it once: just solve $g(x) = 7$.
Chapter 12's logarithm exists because $x\mapsto a^x$, viewed as a mapping from $\mathbf{R}$ to the positive reals, is a bijection. Restricting the codomain from all reals to the positive ones was not cosmetic — it is what made the inverse exist. And the square root is the inverse of squaring only after the domain has been cut down to $x\ge0$, as in Example 1.
Let $f(x) = 2x + 1$ and $g(x) = x^2$. Then $(g \circ f)(2) = {}$ and $(f \circ g)(2) = {}$ .
Answer: $25$ and $9$
$f(2) = 5$ and $g(5) = 25$; whereas $g(2) = 4$ and $f(4) = 9$. The order of composition matters.
13.3 Permutations
A permutation of a set $S$ is a bijection $\sigma: S \to S$ — a rearrangement of $S$ onto itself.
For a finite set there is a simplification worth knowing: a mapping from a finite set to itself is injective if and only if it is surjective. If no two elements collide, all $n$ outputs are distinct and must fill up all $n$ slots; and if all slots are filled by $n$ outputs, none of them can have collided. So for finite $S$, either property alone makes a permutation. (For infinite sets this fails badly: $n \mapsto n+1$ on the positive integers is injective but misses $1$.)
In how many different orders can three people — say A, B and C — stand in a queue? List them all before you answer.List them, then open
Six: ABC, ACB, BAC, BCA, CAB, CBA. Three choices for the front, then two for the middle, then one left over: $3 \cdot 2 \cdot 1$. The example below is that count for $n$ people.
Example 2. Counting permutations
How many permutations does a set of $n$ elements have?
- Choose the image of the first element: $n$ choices.
- The second must go somewhere different, since $\sigma$ is injective: $n-1$ choices.
- The third: $n-2$ choices; and so on down to $1$ for the last.
- Multiplying, the total is $$n! = n(n-1)(n-2)\cdots 2 \cdot 1.$$ For $n=5$ that is $120$; for a deck of $52$ cards it is a number with $68$ digits. $\blacksquare$
How many permutations does a set of $4$ elements have?
Answer: $24$
$4! = 4 \cdot 3 \cdot 2 \cdot 1 = 24$ — four times as many as for three elements, since the new element can be placed first in $4$ ways.
Permutations are composed like any other mappings, and the composite of two permutations is a permutation. Every permutation has an inverse — undo the rearrangement — and the identity permutation leaves everything alone. Those are the three conditions of Chapter 6 again: the permutations of a set form a group.
Example 3. Composing two permutations
On $\{1,2,3\}$, let $\sigma$ send $1\to2,\, 2\to3,\, 3\to1$, and let $\tau$ swap $1$ and $2$, fixing $3$. Compute $\sigma\circ\tau$ and $\tau\circ\sigma$.
- $\sigma\circ\tau$ means $\tau$ first. $1 \xrightarrow{\tau} 2 \xrightarrow{\sigma} 3$; $2 \to 1 \to 2$; $3 \to 3 \to 1$.
- So $\sigma\circ\tau$ sends $1\to3,\ 2\to2,\ 3\to1$ — the swap of $1$ and $3$.
- The other order: $1 \xrightarrow{\sigma} 2 \xrightarrow{\tau} 1$; $2\to3\to3$; $3\to1\to2$.
- So $\tau\circ\sigma$ sends $1\to1,\ 2\to3,\ 3\to2$ — the swap of $2$ and $3$. A different permutation. $\blacksquare$
Both results are swaps, but of different pairs. Order matters, and the only reliable way to get it right is to track one element at a time, out loud.
With $\sigma$ as in Example 3 ($1 \to 2$, $2 \to 3$, $3 \to 1$), where does $\sigma \circ \sigma$ send $1$?
Answer: $3$
$1 \xrightarrow{\sigma} 2 \xrightarrow{\sigma} 3$. Doing the same for the others: $2 \to 1$ and $3 \to 2$. Apply $\sigma$ a third time and everything is back where it started — $\sigma$ is a rotation of three objects, like a third of a turn.
A set of $3$ elements has permutations, and a set of $4$ elements has .
Answer: $6$ and $24$
$3 \cdot 2 \cdot 1 = 6$ and $4 \cdot 3 \cdot 2 \cdot 1 = 24$.
Practice
Give numerical answers as plain numbers.
How many permutations does a set of $5$ elements have?
Answer: $120$
$5! = 5\times4\times3\times2\times1 = 120$. Each element in turn has one fewer destination available, because a permutation cannot send two elements to the same place.
Which of these mappings $\mathbf{R}\to\mathbf{R}$ is injective?
- $f(x) = x^2$
- $f(x) = |x|$
- $f(x) = 2x + 1$
- $f(x) = \sin x$
Answer: $f(x) = 2x+1$
If $2x+1 = 2y+1$ then $x = y$, so it is injective (and being a non-constant linear function, surjective too, hence bijective). The other three all fail: $f(2) = f(-2)$ for the first two, and $\sin 0 = \sin 2\pi$ for the last.
A mapping $f: S \to T$ has an inverse exactly when it is —
- injective.
- bijective.
- surjective.
- defined on a finite set.
Answer: bijective
Surjectivity guarantees every $y\in T$ has at least one pre-image, so $f^{-1}(y)$ has something to be; injectivity guarantees at most one, so the choice is unambiguous. Either alone is not enough.
Let $f(x) = x + 2$ and $g(x) = x^2 - 6$. What is $(g\circ f)(1)$?
Answer: $3$
$g\circ f$ means $f$ first: $f(1) = 3$, then $g(3) = 9 - 6 = 3$.
The other order gives something else entirely: $g(1) = -5$, then $f(-5) = -3$. The notation puts the last map first, which is the single commonest slip in this chapter.
$S = \{1,2,3,4\}$ and $f$ sends $1\to a$, $2\to a$, $3\to b$, $4\to b$. How many elements does the image of $f$ have?
Answer: $2$
The image is $\{a, b\}$ — only the elements actually hit. Four arrows, but they land on just two targets, so $f$ is not injective. Whether it is surjective depends on the codomain, which was not given.
Which statement about a mapping $f: S \to S$ is true for finite $S$ but can fail for infinite $S$?
- Injective implies surjective.
- Bijective implies invertible.
- Composition is associative.
- The image is a subset of the codomain.
Answer: injective implies surjective
On a finite set, $n$ distinct outputs must fill all $n$ slots. On the positive integers, $n\mapsto n+1$ is injective yet misses $1$ entirely — so it is not surjective.
The other three hold for any sets whatsoever.
On $\{1,2,3\}$, $\sigma$ sends $1\to2,\,2\to3,\,3\to1$ and $\tau$ swaps $1$ and $2$. What does $\sigma\circ\tau$ (apply $\tau$ first) do to $1$?
- Sends it to $2$.
- Sends it to $3$.
- Leaves it at $1$.
- It is undefined.
Answer: sends it to $3$
$\tau$ sends $1$ to $2$, and $\sigma$ sends $2$ to $3$. So $(\sigma\circ\tau)(1) = 3$.
In the other order, $\sigma$ sends $1$ to $2$ and $\tau$ sends $2$ back to $1$, so $(\tau\circ\sigma)(1) = 1$ — a different answer from the same two permutations.
How many injective mappings are there from a set of $5$ elements to a set of $4$?
Answer: $0$
Injectivity would need five distinct outputs among four available elements, which is impossible — two of the five must collide.
This is the pigeonhole principle, and it is the reason that in any group of $400$ people, two share a birthday.
$S$ is the set of people in a room and $T$ the days of the year. Which rule is not a mapping $S \to T$?
- Each person to their birthday.
- Each person to the first of January.
- Each day to the people born on it.
- Each person to the day one week after their birthday.
Answer: each day to the people born on it
It runs the wrong way — from $T$ to $S$ — and worse, it assigns a set of people to each day, possibly empty and possibly large. A mapping must give exactly one element of the codomain.
The second option is a perfectly good mapping, merely a constant one: dull, but legal.
How many bijections are there from $\{1,2,3,4\}$ to itself?
Answer: $24$
Bijections from a finite set to itself are exactly its permutations, and there are $4! = 24$ of them.
Together with composition they form a group — the same structure as the eight symmetries of the square in Chapter 6, which in fact sit inside this one as a subgroup permuting the four corners.
Recap
Yes. Ask every guest to move up one room: $n \mapsto n + 1$. No two guests collide, so the mapping is injective — and room $1$ is now empty, so it is not surjective. On a finite set that cannot happen: injective forces surjective (§13.3), which is why a full hundred-room hotel really is full. The infinite hotel is where that rule breaks.
- A mapping $f: S\to T$ gives each element of $S$ exactly one element of $T$; the image is what it actually hits, which may be smaller than the codomain.
- $g\circ f$ means $f$ first. Composition is associative but not commutative.
- Injective: no collisions. Surjective: nothing missed. Bijective: both.
- $f$ is invertible exactly when it is bijective — surjectivity supplies a pre-image, injectivity makes it unique.
- A permutation is a bijection of a set to itself; a finite set of $n$ elements has $n!$ of them, and they form a group.