Functions

draftReviewed by Claude Opus 5.5 (LLM)

A function assigns to each element of one set exactly one element of another. Almost every mathematical construction uses them: sequences are functions, so are the operations of arithmetic, and the structure-preserving maps of algebra and geometry are functions with extra properties. Functions are also how sets are compared, since a function that pairs off the elements of two sets shows that they have the same size.

This topic gives the formal definition, the standard ways of building and combining functions, how functions act on subsets, and the properties of being injective, surjective and invertible.

Conventions

Builds on

Sets, in particular Cartesian products, double inclusion, indexed families and power sets. Informal familiarity with proof by induction.

What a function is

A function is often first met as a rule, such as “square the input”, or as a table listing an output for each input. What matters in both cases is the same: each allowed input has exactly one output. The set of pairs (input, output) records all of this, and gives a definition that does not depend on any rule being written down.

Definition 1 (Function)

A function ff from a set AA to a set BB, written f:A→Bf : A \to B, consists of the sets AA and BB together with a subset G⊆A×BG \subseteq A \times B such that for every a∈Aa \in A there is exactly one b∈Bb \in B with (a,b)∈G(a, b) \in G.

The set AA is the domain of ff, the set BB is its codomain, and GG is its graph. The unique bb with (a,b)∈G(a, b) \in G is the value of ff at aa, written f(a)f(a).

Example 2

The function f:R→Rf : \mathbb{R} \to \mathbb{R} given by f(x)=x2f(x) = x^2 has as its graph the parabola {(x,x2):x∈R}\{(x, x^2) : x \in \mathbb{R}\}.

For A={1,2,3}A = \{1, 2, 3\} and B={x,y,z}B = \{x, y, z\}, the table f(1)=xf(1) = x, f(2)=xf(2) = x, f(3)=yf(3) = y describes the function with graph {(1,x),(2,x),(3,y)}\{(1, x), (2, x), (3, y)\}. Two inputs may share a value, and an element of the codomain, here zz, need not be a value at all.

Each input must have a value, and only one. Those are the two ways an attempted definition can fail.

Example 3
  • The rule x↦1/xx \mapsto 1/x does not define a function R→R\mathbb{R} \to \mathbb{R}, since 00 has no value. It does define a function R∖{0}→R\mathbb{R} \setminus \{0\} \to \mathbb{R}.
  • The rule n↦n−1n \mapsto n - 1 does not define a function N→N\mathbb{N} \to \mathbb{N}. It sends 11 to 00, which is not in the codomain, so 11 has no value in N\mathbb{N}. It does define a function N→N0\mathbb{N} \to \mathbb{N}_0.
  • “The yy with y2=xy^2 = x” does not define a function [0,∞)→R[0, \infty) \to \mathbb{R}, since 44 would have both 22 and −2-2 as values.
  • The unit circle {(x,y)∈R2:x2+y2=1}\{(x, y) \in \mathbb{R}^2 : x^2 + y^2 = 1\} is not the graph of a function R→R\mathbb{R} \to \mathbb{R}. The input 00 is paired with two values, and the input 22 with none.
Remark 4

A rule that refers to a particular way of writing its input must give the same output for every way of writing that input. Such a rule is called well defined. For example, "p/q↦pp/q \mapsto p" does not define a function Q→Z\mathbb{Q} \to \mathbb{Z}, because 1/2=2/41/2 = 2/4 would have both 11 and 22 as values.

Since a graph is determined by the values, a function is determined by its domain, its codomain and its values.

Proposition 5 (Equality of functions)

Functions ff and gg are equal if and only if they have the same domain AA, the same codomain, and f(a)=g(a)f(a) = g(a) for every a∈Aa \in A.

Proof

A function consists of its domain, codomain and graph, so we must show that functions with the same domain and codomain have the same graph exactly when they have the same values. If the graphs are equal, then (a,f(a))(a, f(a)) lies in the graph of gg, so f(a)=g(a)f(a) = g(a) by uniqueness of the value. If the values are equal, each graph is the set of pairs (a,f(a))(a, f(a)) with a∈Aa \in A, so the graphs are equal.

So x↦x2x \mapsto x^2 as a function R→R\mathbb{R} \to \mathbb{R} and as a function R→[0,∞)\mathbb{R} \to [0, \infty) are different functions, even though they have the same values. The difference matters for surjectivity.

Remark 6

Some authors define a function to be just its graph, a set of pairs in which no two pairs have the same first entry. The domain can be recovered from such a set, but the codomain cannot. So with that definition, being surjective, which means that every element of the codomain is a value, only makes sense relative to a stated codomain.

Example 7 (The empty function)

For any set BB, the empty set is a subset of ∅×B=∅\emptyset \times B = \emptyset that vacuously satisfies the condition, so there is exactly one function ∅→B\emptyset \to B. It is called the empty function, with the codomain BB understood from context. If A≠∅A \ne \emptyset, there is no function A→∅A \to \emptyset, since an element of AA would need a value.

Several familiar objects are functions under other names.

Remark 8
  • A sequence (an)n∈N(a_n)_{n \in \mathbb{N}} in a set BB is a function N→B\mathbb{N} \to B, written with ana_n in place of a(n)a(n).
  • An nn-tuple in BB can be regarded as a function {1,…,n}→B\{1, \dots, n\} \to B.
  • A function f:A1×A2→Bf : A_1 \times A_2 \to B on a product has a single input, the pair (a1,a2)(a_1, a_2), but we write f(a1,a2)f(a_1, a_2) instead of f((a1,a2))f((a_1, a_2)) and speak of a function of two variables. Addition of real numbers is a function R×R→R\mathbb{R} \times \mathbb{R} \to \mathbb{R}.
Remark 9

An indexed family (Ai)i∈I(A_i)_{i \in I} can be regarded as a function on II whose value at ii is the set AiA_i, for instance with codomain {Ai:i∈I}\{A_i : i \in I\}. The choice of codomain plays no role for families, as long as every AiA_i is an element of it. It cannot be “the set of all sets”, because there is no such set.

Definition 10 (Set of functions)

BAB^A is the set of all functions from AA to BB.

This is a set, because for fixed AA and BB a function is determined by its graph, and the graphs are elements of P(A×B)\mathcal{P}(A \times B). The exponential notation is explained by the count of functions between finite sets.

Standard constructions

Some functions come up so often, in every part of mathematics, that they have names of their own.

Definition 11 (Identity and constant functions)

The identity function on AA is idA:A→A\mathrm{id}_A : A \to A with idA(a)=a\mathrm{id}_A(a) = a. A function f:A→Bf : A \to B is constant if there is some b∈Bb \in B with f(a)=bf(a) = b for every a∈Aa \in A.

Definition 12 (Inclusion and restriction)

If S⊆AS \subseteq A, the inclusion of SS in AA is the function S→AS \to A given by s↦ss \mapsto s. The restriction of f:A→Bf : A \to B to SS is the function f∣S:S→Bf|_S : S \to B given by f∣S(s)=f(s)f|_S(s) = f(s). We also say that ff is an extension of f∣Sf|_S.

The inclusion of SS in AA is not the identity on SS unless S=AS = A, because the codomains differ.

Definition 13 (Projections)

The projections of A×BA \times B are the functions π1:A×B→A\pi_1 : A \times B \to A with π1(a,b)=a\pi_1(a, b) = a and π2:A×B→B\pi_2 : A \times B \to B with π2(a,b)=b\pi_2(a, b) = b.

An nn-tuple with ai∈Aia_i \in A_i can be regarded as a function on {1,…,n}\{1, \dots, n\} whose value at ii lies in AiA_i. Read this way, a product no longer needs its factors to be listed in order, so it can have any index set.

Definition 14 (Product of a family)

Let (Ai)i∈I(A_i)_{i \in I} be an indexed family of sets. Its product ∏i∈IAi\prod_{i \in I} A_i is the set of all functions x:I→⋃i∈IAix : I \to \bigcup_{i \in I} A_i with x(i)∈Aix(i) \in A_i for every i∈Ii \in I. We usually write xix_i for x(i)x(i). For each j∈Ij \in I, the projection πj:∏i∈IAi→Aj\pi_j : \prod_{i \in I} A_i \to A_j is given by πj(x)=xj\pi_j(x) = x_j.

Example 15

For I={1,2}I = \{1, 2\}, A1={a,b}A_1 = \{a, b\} and A2={0,1,2}A_2 = \{0, 1, 2\}, the product has six elements, one for each pair in A1×A2A_1 \times A_2. The product ∏n∈N{0,1}\prod_{n \in \mathbb{N}} \{0, 1\} is the set of sequences of zeros and ones.

For I={1,…,n}I = \{1, \dots, n\}, elements of the product correspond to nn-tuples, so it matches the Cartesian product of A1,…,AnA_1, \dots, A_n under this identification. When I≠∅I \ne \emptyset and every AiA_i equals AA, the product is AIA^I. If some AiA_i is empty, the product is empty. The product of the empty family has exactly one element, the empty function.

Definition 16 (Characteristic function)

For S⊆AS \subseteq A, the characteristic function of SS is the function χS:A→{0,1}\chi_S : A \to \{0, 1\} with χS(a)=1\chi_S(a) = 1 if a∈Sa \in S and χS(a)=0\chi_S(a) = 0 if a∉Sa \notin S. It is also called the indicator function, and is sometimes written 1S\mathbf{1}_S.

Composition

Applying one function after another gives a new function, provided that the codomain of the first is the domain of the second.

Definition 17 (Composition)

For f:A→Bf : A \to B and g:B→Cg : B \to C, the composition of gg and ff is the function g∘f:A→Cg \circ f : A \to C given by (g∘f)(a)=g(f(a))(g \circ f)(a) = g(f(a)).

Note the order: g∘fg \circ f applies ff first.

Example 18

Let f,g:R→Rf, g : \mathbb{R} \to \mathbb{R} with f(x)=x+1f(x) = x + 1 and g(x)=x2g(x) = x^2. Then (g∘f)(x)=(x+1)2(g \circ f)(x) = (x + 1)^2 and (f∘g)(x)=x2+1(f \circ g)(x) = x^2 + 1. These differ at x=1x = 1, with values 44 and 22, so g∘f≠f∘gg \circ f \ne f \circ g. For functions between different sets, one of the two compositions may not even be defined.

Proposition 19 (Composition laws)

For f:A→Bf : A \to B, g:B→Cg : B \to C and h:C→Dh : C \to D:

  1. h∘(g∘f)=(h∘g)∘fh \circ (g \circ f) = (h \circ g) \circ f;
  2. f∘idA=ff \circ \mathrm{id}_A = f and idB∘f=f\mathrm{id}_B \circ f = f.
Proof

For (1), both sides have domain AA and codomain DD, and for each a∈Aa \in A both have the value h(g(f(a)))h(g(f(a))). So they are equal. For (2), each function has domain AA and codomain BB, and for each a∈Aa \in A each has the value f(a)f(a).

Because of (1), we can write h∘g∘fh \circ g \circ f without brackets.

Images and preimages

A function acts on single elements, but it also carries whole subsets of its domain to subsets of its codomain, and subsets of its codomain back to subsets of its domain.

Definition 20 (Image)

Let f:A→Bf : A \to B and S⊆AS \subseteq A. The image of SS under ff is f(S)={f(s):s∈S}f(S) = \{f(s) : s \in S\}, a subset of BB. The set f(A)f(A) is the image of ff.

Definition 21 (Preimage)

Let f:A→Bf : A \to B and T⊆BT \subseteq B. The preimage, or inverse image, of TT under ff is f−1(T)={a∈A:f(a)∈T}f^{-1}(T) = \{a \in A : f(a) \in T\}, a subset of AA. The preimage f−1({b})f^{-1}(\{b\}) of a single element is called the fibre of ff over bb.

Example 22

Let f:R→Rf : \mathbb{R} \to \mathbb{R} with f(x)=x2f(x) = x^2. Then

  • f([−1,2])=[0,4]f([-1, 2]) = [0, 4];
  • f−1([1,4])=[−2,−1]∪[1,2]f^{-1}([1, 4]) = [-2, -1] \cup [1, 2];
  • f−1({4})={−2,2}f^{-1}(\{4\}) = \{-2, 2\};
  • f−1((−∞,0))=∅f^{-1}((-\infty, 0)) = \emptyset.
Remark 23

The notation f(S)f(S) uses the same parentheses as the value f(a)f(a). This is ambiguous only when something is both an element and a subset of the domain. That is rare, but it can happen: if A={1,{1}}A = \{1, \{1\}\}, then {1}∈A\{1\} \in A and {1}⊆A\{1\} \subseteq A, so f({1})f(\{1\}) could mean the value at the element {1}\{1\} or the image of the subset {1}\{1\}. Writing f[S]f[S] avoids the problem. The notation f−1(T)f^{-1}(T) does not claim that an inverse function exists: it is defined for every ff.

Both operations respect inclusion.

Proposition 24 (Monotonicity of image and preimage)

Let f:A→Bf : A \to B. If S1⊆S2⊆AS_1 \subseteq S_2 \subseteq A, then f(S1)⊆f(S2)f(S_1) \subseteq f(S_2). If T1⊆T2⊆BT_1 \subseteq T_2 \subseteq B, then f−1(T1)⊆f−1(T2)f^{-1}(T_1) \subseteq f^{-1}(T_2).

Proof

If b∈f(S1)b \in f(S_1), then b=f(s)b = f(s) for some s∈S1⊆S2s \in S_1 \subseteq S_2, so b∈f(S2)b \in f(S_2). If a∈f−1(T1)a \in f^{-1}(T_1), then f(a)∈T1⊆T2f(a) \in T_1 \subseteq T_2, so a∈f−1(T2)a \in f^{-1}(T_2).

Membership in a preimage is a statement about a single value f(a)f(a), so preimages interact perfectly with set operations.

Theorem 25 (Preimages and set operations)

Let f:A→Bf : A \to B, let (Ti)i∈I(T_i)_{i \in I} be a family of subsets of BB, and let T⊆BT \subseteq B. Then:

  1. f−1(⋃i∈ITi)=⋃i∈If−1(Ti)f^{-1}\bigl(\bigcup_{i \in I} T_i\bigr) = \bigcup_{i \in I} f^{-1}(T_i);
  2. if I≠∅I \ne \emptyset, then f−1(⋂i∈ITi)=⋂i∈If−1(Ti)f^{-1}\bigl(\bigcap_{i \in I} T_i\bigr) = \bigcap_{i \in I} f^{-1}(T_i);
  3. f−1(B∖T)=A∖f−1(T)f^{-1}(B \setminus T) = A \setminus f^{-1}(T).
Proof

For a∈Aa \in A, each of the following is equivalent to the next: aa lies in the left side of (1); f(a)∈Tif(a) \in T_i for some ii; a∈f−1(Ti)a \in f^{-1}(T_i) for some ii; aa lies in the right side of (1). Statement (2) is the same with “for every ii” in place of “for some ii”. For (3), a∈f−1(B∖T)a \in f^{-1}(B \setminus T) if and only if f(a)∉Tf(a) \notin T, which holds if and only if a∉f−1(T)a \notin f^{-1}(T).

Images behave well with unions, but not with intersections, because different elements can have the same value.

Theorem 26 (Images and set operations)

Let f:A→Bf : A \to B and let (Si)i∈I(S_i)_{i \in I} be a family of subsets of AA. Then:

  1. f(⋃i∈ISi)=⋃i∈If(Si)f\bigl(\bigcup_{i \in I} S_i\bigr) = \bigcup_{i \in I} f(S_i);
  2. if I≠∅I \ne \emptyset, then f(⋂i∈ISi)⊆⋂i∈If(Si)f\bigl(\bigcap_{i \in I} S_i\bigr) \subseteq \bigcap_{i \in I} f(S_i).
Proof

For (1), bb lies in the left side if and only if b=f(a)b = f(a) for some aa lying in some SiS_i, which says exactly that b∈f(Si)b \in f(S_i) for some ii. For (2), if b=f(a)b = f(a) with aa in every SiS_i, then b∈f(Si)b \in f(S_i) for every ii.

Example 27

The inclusion in (2) can be strict. For f(x)=x2f(x) = x^2 on R\mathbb{R}, let S1=[−1,0]S_1 = [-1, 0] and S2=[0,1]S_2 = [0, 1]. Then f(S1∩S2)=f({0})={0}f(S_1 \cap S_2) = f(\{0\}) = \{0\}, while f(S1)∩f(S2)=[0,1]f(S_1) \cap f(S_2) = [0, 1].

Images of complements are no better. For S=[0,∞)S = [0, \infty), we have f(R∖S)=(0,∞)f(\mathbb{R} \setminus S) = (0, \infty) and R∖f(S)=(−∞,0)\mathbb{R} \setminus f(S) = (-\infty, 0), and neither is a subset of the other.

Image and preimage are not inverse operations, though each comes close.

Proposition 28 (Image of preimage, preimage of image)

Let f:A→Bf : A \to B, S⊆AS \subseteq A and T⊆BT \subseteq B. Then:

  1. S⊆f−1(f(S))S \subseteq f^{-1}(f(S));
  2. f(f−1(T))=T∩f(A)f(f^{-1}(T)) = T \cap f(A), and in particular f(f−1(T))⊆Tf(f^{-1}(T)) \subseteq T.
Proof

For (1), if s∈Ss \in S then f(s)∈f(S)f(s) \in f(S), so s∈f−1(f(S))s \in f^{-1}(f(S)).

For (2), an element bb of f(f−1(T))f(f^{-1}(T)) has the form f(a)f(a) with f(a)∈Tf(a) \in T, so b∈T∩f(A)b \in T \cap f(A). Conversely, if b∈T∩f(A)b \in T \cap f(A), then b=f(a)b = f(a) for some aa, and a∈f−1(T)a \in f^{-1}(T) because f(a)=b∈Tf(a) = b \in T. So b∈f(f−1(T))b \in f(f^{-1}(T)).

Example 29

For f(x)=x2f(x) = x^2 on R\mathbb{R}, the set S=[0,1]S = [0, 1] has f−1(f(S))=[−1,1]≠Sf^{-1}(f(S)) = [-1, 1] \ne S, and the set T=[−1,1]T = [-1, 1] has f(f−1(T))=[0,1]≠Tf(f^{-1}(T)) = [0, 1] \ne T.

For composites, images and preimages can be taken one function at a time.

Proposition 30

For f:A→Bf : A \to B, g:B→Cg : B \to C, S⊆AS \subseteq A and U⊆CU \subseteq C, we have (g∘f)(S)=g(f(S))(g \circ f)(S) = g(f(S)) and (g∘f)−1(U)=f−1(g−1(U))(g \circ f)^{-1}(U) = f^{-1}(g^{-1}(U)).

Proof

An element of CC lies in (g∘f)(S)(g \circ f)(S) if and only if it equals g(f(s))g(f(s)) for some s∈Ss \in S, and that says exactly that it lies in g(f(S))g(f(S)). For the second identity, a∈(g∘f)−1(U)a \in (g \circ f)^{-1}(U) if and only if g(f(a))∈Ug(f(a)) \in U, if and only if f(a)∈g−1(U)f(a) \in g^{-1}(U), if and only if a∈f−1(g−1(U))a \in f^{-1}(g^{-1}(U)).

Injective, surjective and bijective functions

The two features of a function that the definition leaves open are whether different inputs can share a value, and whether every element of the codomain is a value.

Definition 31 (Injective)

A function f:A→Bf : A \to B is injective if for all a,a′∈Aa, a' \in A, f(a)=f(a′)f(a) = f(a') implies a=a′a = a'. Equivalently, different elements have different values, or each fibre has at most one element.

Definition 32 (Surjective)

A function f:A→Bf : A \to B is surjective if f(A)=Bf(A) = B. That is, for every b∈Bb \in B there is some a∈Aa \in A with f(a)=bf(a) = b. Equivalently, each fibre has at least one element.

Definition 33 (Bijective)

A function is bijective, or a bijection, if it is both injective and surjective. Equivalently, each fibre has exactly one element.

The words “injection” and “surjection” are also used. Every identity function idA\mathrm{id}_A is bijective, directly from these definitions.

Four arrow diagrams between sets A and B: a function that is neither injective nor surjective, one that is injective only, one that is surjective only, and a bijection

Remark 34

To prove that ff is injective, assume f(a)=f(a′)f(a) = f(a') and deduce a=a′a = a'. To prove that ff is surjective, take an arbitrary b∈Bb \in B and find an aa with f(a)=bf(a) = b. For f:R→Rf : \mathbb{R} \to \mathbb{R} with f(x)=2x+3f(x) = 2x + 3: if 2a+3=2a′+32a + 3 = 2a' + 3 then a=a′a = a', and for any bb the number a=(b−3)/2a = (b - 3)/2 has f(a)=bf(a) = b.

Both properties depend on the sets involved as well as on the rule.

Example 35 (The same rule on different sets)

The rule x↦x2x \mapsto x^2 gives four different functions:

  • R→R\mathbb{R} \to \mathbb{R} is neither injective nor surjective;
  • R→[0,∞)\mathbb{R} \to [0, \infty) is surjective but not injective;
  • [0,∞)→R[0, \infty) \to \mathbb{R} is injective but not surjective;
  • [0,∞)→[0,∞)[0, \infty) \to [0, \infty) is bijective.

More generally, any function f:A→Bf : A \to B becomes surjective when its codomain is replaced by f(A)f(A), and an injective function then becomes a bijection A→f(A)A \to f(A).

Theorem 36 (Composition and injectivity, surjectivity)

Let f:A→Bf : A \to B and g:B→Cg : B \to C.

  1. If ff and gg are injective, then g∘fg \circ f is injective.
  2. If ff and gg are surjective, then g∘fg \circ f is surjective.
  3. If ff and gg are bijective, then g∘fg \circ f is bijective.
  4. If g∘fg \circ f is injective, then ff is injective.
  5. If g∘fg \circ f is surjective, then gg is surjective.
Proof

For (1), if g(f(a))=g(f(a′))g(f(a)) = g(f(a')), then f(a)=f(a′)f(a) = f(a') because gg is injective, and so a=a′a = a' because ff is injective.

For (2), take c∈Cc \in C. Since gg is surjective, c=g(b)c = g(b) for some b∈Bb \in B, and since ff is surjective, b=f(a)b = f(a) for some a∈Aa \in A. Then (g∘f)(a)=c(g \circ f)(a) = c.

Statement (3) combines (1) and (2).

For (4), if f(a)=f(a′)f(a) = f(a'), then g(f(a))=g(f(a′))g(f(a)) = g(f(a')), so a=a′a = a' because g∘fg \circ f is injective.

For (5), each c∈Cc \in C equals g(f(a))g(f(a)) for some a∈Aa \in A, which is a value of gg at the element f(a)f(a).

Example 37

In (4), gg need not be injective, and in (5), ff need not be surjective. Let f:{1}→{1,2}f : \{1\} \to \{1, 2\} be the inclusion and let g:{1,2}→{1}g : \{1, 2\} \to \{1\} be constant. Then g∘fg \circ f is bijective, but ff is not surjective and gg is not injective.

The inclusions and failures found for images and preimages come exactly from functions not being injective or surjective.

Theorem 38 (Characterizations by images and preimages)

For f:A→Bf : A \to B, the following are equivalent:

  1. ff is injective;
  2. f−1(f(S))=Sf^{-1}(f(S)) = S for every S⊆AS \subseteq A;
  3. f(S1∩S2)=f(S1)∩f(S2)f(S_1 \cap S_2) = f(S_1) \cap f(S_2) for all S1,S2⊆AS_1, S_2 \subseteq A;
  4. f(A∖S)⊆B∖f(S)f(A \setminus S) \subseteq B \setminus f(S) for every S⊆AS \subseteq A.

Also, the following are equivalent:

  1. ff is surjective;
  2. f(f−1(T))=Tf(f^{-1}(T)) = T for every T⊆BT \subseteq B;
  3. B∖f(S)⊆f(A∖S)B \setminus f(S) \subseteq f(A \setminus S) for every S⊆AS \subseteq A.
Proof

(1) implies (2): by the earlier proposition it is enough to show f−1(f(S))⊆Sf^{-1}(f(S)) \subseteq S. If f(a)∈f(S)f(a) \in f(S), then f(a)=f(s)f(a) = f(s) for some s∈Ss \in S, and a=s∈Sa = s \in S by injectivity.

(2) implies (1): if f(a)=f(a′)f(a) = f(a'), then a′∈f−1(f({a}))={a}a' \in f^{-1}(f(\{a\})) = \{a\}, so a′=aa' = a.

(1) implies (3): the inclusion ⊆\subseteq holds in general. If b∈f(S1)∩f(S2)b \in f(S_1) \cap f(S_2), then b=f(s1)=f(s2)b = f(s_1) = f(s_2) with s1∈S1s_1 \in S_1 and s2∈S2s_2 \in S_2. By injectivity s1=s2s_1 = s_2, which then lies in S1∩S2S_1 \cap S_2, so b∈f(S1∩S2)b \in f(S_1 \cap S_2).

(3) implies (1): if a≠a′a \ne a' but f(a)=f(a′)f(a) = f(a'), then S1={a}S_1 = \{a\} and S2={a′}S_2 = \{a'\} give f(S1∩S2)=∅f(S_1 \cap S_2) = \emptyset and f(S1)∩f(S2)={f(a)}f(S_1) \cap f(S_2) = \{f(a)\}, contradicting (3).

(1) implies (4): let b∈f(A∖S)b \in f(A \setminus S), so b=f(a)b = f(a) with a∉Sa \notin S. If also b=f(s)b = f(s) with s∈Ss \in S, then a=s∈Sa = s \in S by injectivity, a contradiction. So b∉f(S)b \notin f(S).

(4) implies (1): if a≠a′a \ne a' but f(a)=f(a′)f(a) = f(a'), take S={a}S = \{a\}. Then f(a′)∈f(A∖S)f(a') \in f(A \setminus S), but f(a′)=f(a)∈f(S)f(a') = f(a) \in f(S), contradicting (4).

(5) and (6): f(f−1(T))=T∩f(A)f(f^{-1}(T)) = T \cap f(A) by the earlier proposition. If f(A)=Bf(A) = B this equals TT. Conversely, taking T=BT = B gives f(f−1(B))=f(A)f(f^{-1}(B)) = f(A), so if (6) holds then f(A)=Bf(A) = B.

(5) implies (7): let b∈B∖f(S)b \in B \setminus f(S). By surjectivity b=f(a)b = f(a) for some a∈Aa \in A, and a∉Sa \notin S because b∉f(S)b \notin f(S). So b∈f(A∖S)b \in f(A \setminus S).

(7) implies (5): taking S=∅S = \emptyset gives B⊆f(A)B \subseteq f(A).

Inverses

An inverse undoes a function. Undoing can happen on one side only, and it is the one-sided versions that correspond to injectivity and surjectivity.

Definition 39 (Left, right and two-sided inverses)

Let f:A→Bf : A \to B and g:B→Ag : B \to A. Then gg is a left inverse of ff if g∘f=idAg \circ f = \mathrm{id}_A, and a right inverse of ff if f∘g=idBf \circ g = \mathrm{id}_B. It is a two-sided inverse, or simply an inverse, if it is both.

Theorem 40 (Left inverses and injectivity)

Let f:A→Bf : A \to B. If ff has a left inverse, then ff is injective. Conversely, if ff is injective and A≠∅A \ne \emptyset, then ff has a left inverse.

Proof

If g∘f=idAg \circ f = \mathrm{id}_A, then g∘fg \circ f is injective, so ff is injective by part (4) of the theorem on composition.

Conversely, let ff be injective and choose some a0∈Aa_0 \in A. Define g:B→Ag : B \to A as follows. If b∈f(A)b \in f(A), let g(b)g(b) be the element aa with f(a)=bf(a) = b, which is unique by injectivity. If b∉f(A)b \notin f(A), let g(b)=a0g(b) = a_0. Then g(f(a))=ag(f(a)) = a for every a∈Aa \in A.

The condition A≠∅A \ne \emptyset is needed: the empty function ∅→B\emptyset \to B is injective, but if B≠∅B \ne \emptyset there is no function B→∅B \to \emptyset at all.

Theorem 41 (Right inverses and surjectivity)

A function f:A→Bf : A \to B is surjective if and only if it has a right inverse.

Proof

If f∘g=idBf \circ g = \mathrm{id}_B, then f∘gf \circ g is surjective, so ff is surjective by part (5) of the theorem on composition.

Conversely, let ff be surjective. Each fibre f−1({b})f^{-1}(\{b\}) is nonempty, so we can choose one element g(b)g(b) from it for each b∈Bb \in B. Then f(g(b))=bf(g(b)) = b for every b∈Bb \in B.

Remark 42

The proof above makes one choice for each b∈Bb \in B, possibly infinitely many at once. Justifying that requires the axiom of choice, which states that for any family of nonempty sets one element can be chosen from each. In terms of products, it says that the product of any family of nonempty sets is nonempty, since an element of the product is exactly such a choice. In fact, the statement that every surjection has a right inverse is equivalent to the axiom of choice. No such axiom is needed when BB is finite, or when there is an explicit way to pick, such as taking the least element of each fibre when A=NA = \mathbb{N}.

Example 43

One-sided inverses are generally not unique. On N0\mathbb{N}_0, let f(n)=2nf(n) = 2n, and let g(n)=⌊n/2⌋g(n) = \lfloor n/2 \rfloor, where ⌊x⌋\lfloor x \rfloor is the greatest integer at most xx. Then g∘f=idN0g \circ f = \mathrm{id}_{\mathbb{N}_0}, so gg is a left inverse of ff, and ff is a right inverse of gg.

Here ff is injective but not surjective, and gg is surjective but not injective. The function n↦2n+1n \mapsto 2n + 1 is another right inverse of gg. The function g′g' with g′(n)=n/2g'(n) = n/2 for even nn and g′(n)=0g'(n) = 0 for odd nn is another left inverse of ff.

If a function has inverses on both sides, the choices disappear.

Theorem 44 (Bijections and inverses)

Let f:A→Bf : A \to B.

  1. If gg is a left inverse of ff and hh is a right inverse of ff, then g=hg = h.
  2. ff is bijective if and only if it has a two-sided inverse.
  3. A two-sided inverse of ff is unique when it exists. It is written f−1f^{-1}.
Proof

For (1), by the composition laws, g=g∘idB=g∘(f∘h)=(g∘f)∘h=idA∘h=h.g = g \circ \mathrm{id}_B = g \circ (f \circ h) = (g \circ f) \circ h = \mathrm{id}_A \circ h = h.

For (2), if ff is bijective, then each b∈Bb \in B has exactly one a∈Aa \in A with f(a)=bf(a) = b. Define g(b)g(b) to be this aa. Then g(f(a))=ag(f(a)) = a and f(g(b))=bf(g(b)) = b for all aa and bb, so gg is a two-sided inverse, with no appeal to the axiom of choice. Conversely, a two-sided inverse is both a left and a right inverse, so ff is injective and surjective by the previous two theorems.

For (3), if gg and hh are both two-sided inverses, then g=hg = h by (1).

Example 45

The function f:R→Rf : \mathbb{R} \to \mathbb{R} with f(x)=2x+3f(x) = 2x + 3 is bijective, and solving y=2x+3y = 2x + 3 for xx gives f−1(y)=(y−3)/2f^{-1}(y) = (y - 3)/2. The exponential function R→(0,∞)\mathbb{R} \to (0, \infty) is bijective with inverse ln⁡\ln. On [0,∞)[0, \infty), the function x↦x2x \mapsto x^2 is bijective with inverse x↦xx \mapsto \sqrt{x}.

Remark 46

When ff is bijective, the symbol f−1f^{-1} has two meanings, the inverse function and the preimage. They agree: the preimage of TT under ff equals the image of TT under the function f−1f^{-1}.

Corollary 47 (Inverse laws)

If f:A→Bf : A \to B and g:B→Cg : B \to C are bijective, then f−1f^{-1} and g∘fg \circ f are bijective, with (f−1)−1=f(f^{-1})^{-1} = f and (g∘f)−1=f−1∘g−1(g \circ f)^{-1} = f^{-1} \circ g^{-1}.

Proof

The equations f−1∘f=idAf^{-1} \circ f = \mathrm{id}_A and f∘f−1=idBf \circ f^{-1} = \mathrm{id}_B say that ff is a two-sided inverse of f−1f^{-1}, so f−1f^{-1} is bijective with inverse ff. Next, g∘fg \circ f is bijective by part (3) of the theorem on composition, and by the composition laws,

(f−1∘g−1)∘(g∘f)=f−1∘(g−1∘g)∘f=f−1∘f=idA,(f^{-1} \circ g^{-1}) \circ (g \circ f) = f^{-1} \circ (g^{-1} \circ g) \circ f = f^{-1} \circ f = \mathrm{id}_A,

and similarly (g∘f)∘(f−1∘g−1)=idC(g \circ f) \circ (f^{-1} \circ g^{-1}) = \mathrm{id}_C. So f−1∘g−1f^{-1} \circ g^{-1} is the two-sided inverse of g∘fg \circ f.

The order reverses for the same reason as with socks and shoes: the last thing done is the first thing undone.

Functions between finite sets

Counting a set means pairing off its elements with 1,2,…,n1, 2, \dots, n, and such a pairing is a bijection. This makes precise the idea of size that Sets uses informally. Below, m,n∈N0m, n \in \mathbb{N}_0 and {1,…,0}=∅\{1, \dots, 0\} = \emptyset. The first step is to show that a set cannot be counted in two ways with different results.

Lemma 48 (Injections between initial segments)

If there is an injective function {1,…,m}→{1,…,n}\{1, \dots, m\} \to \{1, \dots, n\}, then m≤nm \le n.

Proof

We use induction on mm, for all nn at once. The case m=0m = 0 is immediate. Let f:{1,…,m+1}→{1,…,n}f : \{1, \dots, m + 1\} \to \{1, \dots, n\} be injective. Then n≥1n \ge 1, since m+1m + 1 must have a value. Let τ\tau be the bijection of {1,…,n}\{1, \dots, n\} that exchanges f(m+1)f(m + 1) and nn and fixes every other element (so τ\tau is the identity if f(m+1)=nf(m + 1) = n). Then τ∘f\tau \circ f is injective and has value nn at m+1m + 1, so it never takes the value nn on {1,…,m}\{1, \dots, m\}. Restricting it to {1,…,m}\{1, \dots, m\} and replacing the codomain by {1,…,n−1}\{1, \dots, n - 1\} therefore gives an injective function {1,…,m}→{1,…,n−1}\{1, \dots, m\} \to \{1, \dots, n - 1\}. By the induction hypothesis m≤n−1m \le n - 1, so m+1≤nm + 1 \le n.

Definition 49 (Finite set and size)

A set AA is finite if there is a bijection {1,…,n}→A\{1, \dots, n\} \to A for some n∈N0n \in \mathbb{N}_0. This nn, which is unique, is the size of AA, written ∣A∣\lvert A \rvert. A set that is not finite is infinite.

Proposition 50 (Size is well defined)

If there are bijections {1,…,m}→A\{1, \dots, m\} \to A and {1,…,n}→A\{1, \dots, n\} \to A, then m=nm = n.

Proof

If ff and gg are such bijections, then g−1∘fg^{-1} \circ f and f−1∘gf^{-1} \circ g are bijections between {1,…,m}\{1, \dots, m\} and {1,…,n}\{1, \dots, n\}, so the lemma gives m≤nm \le n and n≤mn \le m.

The following basic facts about size can be proved from this definition, by induction where needed, and are used freely below:

For finite sets, functions can be counted, and the conditions of being injective and surjective become statements about sizes. The starting point is that the fibres of a function divide up its domain.

Proposition 51 (Sizes of fibres)

For a function f:A→Bf : A \to B between finite sets,

∣A∣=∑b∈B∣f−1({b})∣.(∗)\lvert A \rvert = \sum_{b \in B} \lvert f^{-1}(\{b\}) \rvert. \tag{$*$}
Proof

Each element of AA lies in exactly one fibre, so AA is the disjoint union of the fibres, and its size is the sum of theirs.

The next two theorems follow from this equation.

Theorem 52 (Pigeonhole principle)

Let f:A→Bf : A \to B be a function between finite sets, and let k∈Nk \in \mathbb{N}. If ∣A∣>k∣B∣\lvert A \rvert > k \lvert B \rvert, then some fibre of ff has more than kk elements. In particular, if ∣A∣>∣B∣\lvert A \rvert > \lvert B \rvert, then ff is not injective.

Proof

If every fibre had at most kk elements, then (∗)(*) would give ∣A∣≤k∣B∣\lvert A \rvert \le k \lvert B \rvert. The last statement is the case k=1k = 1.

Remark 53

There is a matching statement for surjections. If ff is surjective, every term of (∗)(*) is at least 1, so ∣A∣≥∣B∣\lvert A \rvert \ge \lvert B \rvert. Hence if ∣A∣<∣B∣\lvert A \rvert < \lvert B \rvert, then ff is not surjective.

Example 54

Among 13 people, two share a birth month. Among 100 people, at least 9 share a birth month, since 100>8⋅12100 > 8 \cdot 12. For n∈Nn \in \mathbb{N}, among any n+1n + 1 integers, two have the same remainder on division by nn, so their difference is divisible by nn.

Theorem 55 (Equal finite sizes)

Let f:A→Bf : A \to B be a function between finite sets with ∣A∣=∣B∣\lvert A \rvert = \lvert B \rvert. Then ff is injective if and only if ff is surjective, and so each of these is equivalent to ff being bijective.

Proof

In (∗)(*), the sum has ∣B∣\lvert B \rvert terms and equals ∣B∣\lvert B \rvert. If ff is injective, every term is at most 1, and if ff is surjective, every term is at least 1. In either case the total can only equal ∣B∣\lvert B \rvert if every term is exactly 1, which means that ff is bijective.

This fails for infinite sets: the functions n↦2nn \mapsto 2n and n↦⌊n/2⌋n \mapsto \lfloor n/2 \rfloor on N0\mathbb{N}_0 are respectively injective but not surjective, and surjective but not injective. The same equation shows that a bijection between finite sets forces them to have the same size. Extending that idea, so that two possibly infinite sets have the same size when there is a bijection between them, is the starting point of the theory of cardinality.

Proposition 56 (Counting functions)

Let AA and BB be finite with ∣A∣=m\lvert A \rvert = m and ∣B∣=n\lvert B \rvert = n.

  1. There are nmn^m functions A→BA \to B, so ∣BA∣=∣B∣∣A∣\lvert B^A \rvert = \lvert B \rvert^{\lvert A \rvert}. Here 00=10^0 = 1.
  2. If m≤nm \le n, there are n!/(n−m)!n!/(n - m)! injective functions A→BA \to B, with 0!=10! = 1. If m>nm > n, there are none.
  3. If m=nm = n, there are n!n! bijections A→BA \to B.
Proof

We use induction on mm for (1) and for the first claim of (2). For m=0m = 0, the only function is the empty function, which is injective, and n0=n!/n!=1n^0 = n!/n! = 1.

Now let ∣A∣=m+1\lvert A \rvert = m + 1, choose a∈Aa \in A and let A′=A∖{a}A' = A \setminus \{a\}. A function f:A→Bf : A \to B is determined by its restriction to A′A' and its value f(a)f(a), and these can be chosen independently. So there are nm⋅n=nm+1n^m \cdot n = n^{m+1} functions.

If also m+1≤nm + 1 \le n, then ff is injective exactly when f∣A′f|_{A'} is injective and f(a)∉f(A′)f(a) \notin f(A'). Since f∣A′f|_{A'} is injective, f(A′)f(A') has mm elements, so there are n−mn - m possible values of f(a)f(a), for a total of n!(n−m)!(n−m)=n!(n−m−1)!\frac{n!}{(n - m)!} (n - m) = \frac{n!}{(n - m - 1)!} injective functions.

The second claim of (2) is the pigeonhole principle. For (3), when m=nm = n the bijections are exactly the injections, and there are n!/0!=n!n!/0! = n! of them.

Remark 57

Surjections are harder to count, because whether a function is surjective depends on all of its values together. The number of surjective functions from a set of size mm to a set of size nn is ∑k=0n(−1)k(nk)(n−k)m\sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m, with 00=10^0 = 1. This follows from the general form of the inclusion-exclusion principle, and is not proved here.

Characteristic functions connect functions with subsets. They also explain why 2A2^A is another notation for the power set, with 22 read as the two-element set {0,1}\{0, 1\}.

Proposition 58 (Subsets and characteristic functions)

For any set AA, the function P(A)→{0,1}A\mathcal{P}(A) \to \{0, 1\}^A given by S↦χSS \mapsto \chi_S is a bijection, with inverse given by h↦h−1({1})h \mapsto h^{-1}(\{1\}).

Proof

For S⊆AS \subseteq A, the set χS−1({1})\chi_S^{-1}(\{1\}) is exactly SS. For h:A→{0,1}h : A \to \{0, 1\}, let S=h−1({1})S = h^{-1}(\{1\}). Then χS(a)=1\chi_S(a) = 1 exactly when h(a)=1h(a) = 1, and both functions take only the values 00 and 11, so χS=h\chi_S = h. The two functions are therefore inverses of each other.

Combined with the count of functions, this gives ∣P(A)∣=2n\lvert \mathcal{P}(A) \rvert = 2^n for a set with nn elements, a result proved directly in Sets.

Summary

Sources