2.2  Injections and Surjections

Section 2.1 defined functions and composed them. This section asks the two basic questions about a function, and gives each its method of proof and its way of failing. We then ask what composition does to the two properties, and find the half of each converse that survives. After the maps that every subset, product and power set carries, and a set of examples from arithmetic and calculus, we read injectivity and surjectivity in a second way: as permission to cancel f from an equation between composites.

2.2.1. Injective, surjective, bijective

Two questions can be asked of any function f:X→Y, and much of mathematics turns on them. First: can we recover the input from the output, or can two different inputs give the same output? Second: is every point of the codomain an output? The first question is about how f treats X; the second is about how it covers Y.

Injective functions

An injective function never sends two different inputs to the same output.

Definition 2.2.1 (Injective)

A function f:X→Y is injective (an injection, or one-to-one) if, for all x1,x2∈X, f(x1)=f(x2) implies x1=x2. In symbols: ∀x1∈X  ∀x2∈X  (f(x1)=f(x2)→x1=x2).

In words: if two inputs give the same output, they were the same input. By Logic and Proof, Proposition 2.3.2, the definition gives the contrapositive form ∀x1∈X  ∀x2∈X  (x1≠x2→f(x1)≠f(x2)): different inputs give different outputs. The two forms are equivalent; the way back, from the contrapositive form to the definition, is Logic and Proof, Proposition 2.5.2, which uses RAA. A proof of injectivity usually uses the form of the definition, because an equation f(x1)=f(x2) is something to compute with, while an inequation x1≠x2 is not.

The negation is found by the laws of Logic and Proof, Chapter 6 for negating bounded quantifiers and implications: “f is not injective” is ∃x1∈X  ∃x2∈X  (f(x1)=f(x2)∧x1≠x2). So a failure of injectivity is shown by two witnesses: two different inputs with the same output.

Surjective functions

A surjective function reaches every point of its codomain.

Definition 2.2.2 (Surjective)

A function f:X→Y is surjective (a surjection, or onto) if, for every y∈Y, there exists x∈X with f(x)=y. In symbols: ∀y∈Y  ∃x∈X  f(x)=y.

In words: every point of the codomain is an output; equivalently, the range of f is all of Y. An x with f(x)=y is called a preimage of y. The definition does not ask for the preimage to be unique. Negating as before, “f is not surjective” is ∃y∈Y  ∀x∈X  f(x)≠y, so a failure of surjectivity is shown by one witness: a point of the codomain that no input reaches.

Surjectivity depends on the codomain, which is why Definition 2.1.1 records it: s1 and s2 of Example (Equal and unequal functions) have the same graph, and we shall see that s2 is surjective and s1 is not.

Warning. Surjectivity cannot be checked by trying some y. The function f:R→R, f(x)=x2+x, reaches 0=f(0), 2=f(1), 6=f(2), and 12=f(3), and a reader who tries these may believe it reaches everything. It does not reach −1: x2+x=−1 would mean x2+x+1=0, but x2+x+1=(x+12)2+34>0 for every real x. Concluding “for every y” from a few instances is entry (N1) of the catalogue in Logic and Proof, Chapter 8.

Bijective functions

Definition 2.2.3 (Bijective)

A function is bijective (a bijection) if it is both injective and surjective.

A bijection is a function in which every point of the codomain is reached exactly once: for every y∈Y there is exactly one x∈X with f(x)=y. This is the ∃! of Definition 2.1.1 again, now read from the codomain side, and its two halves are the two properties.

Second readingWhy a bijection reaches each point once

In the terms of Example (Method: existence and uniqueness), the two halves are these. Existence of such an x, for every y, is surjectivity. Uniqueness is injectivity: if f(x1)=y=f(x2), injectivity gives x1=x2; and conversely, if every y has at most one preimage, then f(x1)=f(x2) makes x1 and x2 two preimages of the same point y:=f(x1), so x1=x2.

Worked examples

Example (Method: proving injectivity)

Template. “Let x1,x2∈X with f(x1)=f(x2).” Compute until x1=x2. To refute injectivity, name two different inputs with one output.

When to use it. Any claim that f is injective. The equation form of Definition 2.2.1 is the one to compute with, as the paragraph after the definition explains.

The usual failure. Starting from x1=x2 and reaching f(x1)=f(x2), which proves the wrong implication (entry (N5) of Logic and Proof, Example (What is not allowed); a warning below shows it on squaring); or assuming x1≠x2 and never using it.

Example (Method: proving surjectivity)

Template. On scrap paper, solve f(x)=y for x, working backwards, and note what the solving needed. The proof runs forwards: “Let y∈Y. Put x:=…”, check x∈X, check f(x)=y. To refute surjectivity, name one y∈Y and show that f(x)=y has no solution in X.

When to use it. Any claim that f is surjective.

The usual failure. Writing the scratch work as the proof, so that the proof assumes y=f(x) and never checks that the x it found lies in X; and testing a few y (entry (N1), the warning after Definition 2.2.2).

The two methods meet in one function whose surjectivity has to be found, not guessed.

Example (Solving backwards, proving forwards)

Let f:R→(−1,1), f(x)=x/(1+|x|). Show that f is a function, and that it is injective and surjective.

Idea (Scratch work). A function into (−1,1). The denominator is safe, since 1+|x|≥1>0, and |f(x)|=|x|/(1+|x|)<1. Note also that f(x) has the sign of x, and f(0)=0.

Injectivity. If f(x1)=f(x2), then x1 and x2 have the same sign. In each case |x| is x or −x for both, and clearing denominators should finish it.

Surjectivity, backwards. The absolute value suggests cases on the sign of y (Example (Method: proof by cases)). For y≥0, look for x≥0: y=x1+x⟺y+yx=x⟺x=y1−y. For y<0, look for x<0: y=x1−x⟺y−yx=x⟺x=y1+y. Both answers are x=y/(1−|y|), one formula, and it needs |y|≠1. That is why the codomain is the open interval. As givens and goal:

Givens Goal
y∈(−1,1) some x∈R with x/(1+|x|)=y
x:=y/(1−|y|), defined since |y|<1 f(x)=y: the one check left

Solution. Function. For every real x, 1+|x|>0, and |f(x)|=|x|/(1+|x|)<1, so f(x)∈(−1,1).

Injective. Let f(x1)=f(x2). Since f(x) has the sign of x, x1 and x2 are both ≥0 or both <0. In the first case x1/(1+x1)=x2/(1+x2) gives x1+x1x2=x2+x1x2, so x1=x2. In the second, x1/(1−x1)=x2/(1−x2) gives x1−x1x2=x2−x1x2, so x1=x2 in the same way.

Surjective. Let y∈(−1,1) and put x:=y/(1−|y|), a real number since 1−|y|>0. Then |x|=|y|/(1−|y|), so 1+|x|=1/(1−|y|), and f(x)=x1+|x|=x(1−|y|)=y.

The order is the one the box prescribes. The solving went backwards and needed two cases; the proof goes forwards, states one formula for x, and checks it once.

Quick check. Show that n↦5n−2, as a function Z→Z, is injective and not surjective.

Solution. Injective: 5n1−2=5n2−2 gives 5n1=5n2, so n1=n2. Not surjective: the witness is 0. The equation 5n−2=0 means 5n=2, and no integer solves it: if n≥1, then 5n≥5; if n≤0, then 5n≤0.

Example (Deciding injective and surjective)

For each function below, decide with proof whether it is injective and whether it is surjective.

  • (a) f:R→R, f(x)=3x−5.

  • (b) g:Z→Z, g(n)=3n.

  • (c) h:{1,2,3}→{a,b}, with h(1)=a, h(2)=b, h(3)=a.

  • (d) k:{1,2}→{a,b,c}, with k(1)=a, k(2)=c.

Solution.

  • (a) Injective. Let x1,x2∈R with 3x1−5=3x2−5. Adding 5 and dividing by 3 gives x1=x2.

    Surjective. On scrap paper, 3x−5=y gives x=(y+5)/3. Now the proof: let y∈R, and put x:=(y+5)/3. Then x∈R, and f(x)=3⋅y+53−5=y. So f is bijective.

  • (b) Injective. Let n1,n2∈Z with 3n1=3n2. Dividing by 3 gives n1=n2.

    Not surjective. The witness is 1∈Z. If n≥1, then 3n≥3; if n≤0, then 3n≤0. So 3n≠1 for every integer n, and 1 has no preimage. (Solving 3n=1 gives n=13, which is not in the domain Z: the same formula on Q would be surjective.)

  • (c) Not injective: h(1)=a=h(3) and 1≠3. Surjective: the codomain has two points, and a=h(1), b=h(2). For a finite codomain, checking every point is a proof: the instances are all the cases.

  • (d) Injective: the two inputs have the different outputs a≠c, and there are no other pairs of different inputs to check. Not surjective: b is not an output, since the only outputs are k(1)=a and k(2)=c.

Parts (c) and (d) show two more things. A function from a three-element set to a two-element set cannot be injective, and one from a two-element set to a three-element set cannot be surjective: there are too many inputs in the first case and too few in the second.

Second readingDrawing finite pictures

And the finite pictures are worth drawing: two columns of dots, with an arrow from each input to its output. Injective means no dot on the right receives two arrows; surjective means every dot on the right receives at least one.

The key example of the section is one formula read as three different functions.

Example (Squaring, three ways)

For each of the three functions, settle both questions: injective or not, surjective or not.

  • (a) q1:R→R, q1(x)=x2.

  • (b) q2:[0,∞)→R, q2(x)=x2.

  • (c) q3:[0,∞)→[0,∞), q3(x)=x2.

Solution.

  • (a) Not injective: q1(1)=1=q1(−1) and 1≠−1. Not surjective: the witness is −1∈R, since x2≥0>−1 for every real x. So q1 is neither.

  • (b) Injective. Let x1,x2≥0 with x12=x22. Then x12≤x22, so x1≤x2 by Logic and Proof, Theorem 2.4.5, which applies since both numbers are nonnegative; and likewise x2≤x1. Hence x1=x2. Not surjective: the witness −1 still works, for the same reason.

  • (c) Injective, by the same proof as in (b): injectivity concerns only the domain and the values, and these are the same as for q2. Surjective. Let y∈[0,∞). A nonnegative real number has a nonnegative square root, so put x:=y. Then x∈[0,∞) and q3(x)=(y)2=y. So q3 is bijective.

The same rule gives three different functions. Shrinking the domain from R to [0,∞) removed the two witnesses ±1 against injectivity. Shrinking the codomain to [0,∞) removed the witness −1 against surjectivity. The graphs of q2 and q3 are the same set; only the declared codomain differs, and surjectivity changes with it.

Warning. Injectivity is not the defining property of a function read backwards. Every function satisfies “if x1=x2, then f(x1)=f(x2)”: equal inputs give equal outputs, which is part of f(x) being well defined. Injectivity is the converse, “if f(x1)=f(x2), then x1=x2”. A “proof” of injectivity that starts from x1=x2 and reaches f(x1)=f(x2) has proved the wrong implication, entry (N5) of Logic and Proof, Chapter 8’s catalogue, and it “proves” q1 injective, which is false.

Quick check. Is n↦n+1 surjective as a function N→N? As a function Z→Z?

Solution. On N: no. The witness is 0, since n+1≥1 for every n∈N, so n+1=0 has no solution in N. On Z: yes. For m∈Z, the integer m−1 satisfies (m−1)+1=m. Both functions are injective, since n1+1=n2+1 gives n1=n2.

2.2.2. Composites of injections and surjections

Both properties survive composition. This is the first theorem about functions whose proof uses the definitions and nothing else, and it shows the two proof shapes of the last subsection working together.

Theorem 2.2.1 (Composites of Injections and Surjections)

Let f:X→Y and g:Y→Z be functions.

  • (a) If f and g are injective, then g∘f is injective.

  • (b) If f and g are surjective, then g∘f is surjective.

  • (c) If f and g are bijective, then g∘f is bijective.

Idea. For (a), start from equal outputs of g∘f. They are equal outputs of g, at the points f(x1) and f(x2); peel off g by its injectivity, then f by its. For (b), work backwards along the chain X→Y→Z: to reach z∈Z, first find a point of Y that g sends to z, then a point of X that f sends there. Part (c) is (a) and (b) together.

Proof.

  • (a) Let x1,x2∈X with (g∘f)(x1)=(g∘f)(x2), that is, g(f(x1))=g(f(x2)) by Definition 2.1.2. The points f(x1) and f(x2) lie in Y, and g is injective, so f(x1)=f(x2) [∀E, →E: injectivity of g at f(x1),f(x2)]. Since f is injective, x1=x2 [∀E, →E: injectivity of f at x1,x2]. So g∘f is injective.

  • (b) Let z∈Z. Since g is surjective, there is y∈Y with g(y)=z [∃E: the name y is fresh]. Since f is surjective, there is x∈X with f(x)=y [∃E: x is fresh]. Then (g∘f)(x)=g(f(x))=g(y)=z, so z has the preimage x under g∘f [∃I, witness x]. Since z∈Z was arbitrary, g∘f is surjective.

  • (c) If f and g are bijective, they are injective and surjective, so g∘f is injective by (a) and surjective by (b), that is, bijective.

Second readingPart (a) as a derivation

Part (a) is short enough to see whole at level 0 of Logic and Proof, Section 8.3, a full derivation. Here is its derivation, with the quantifiers bounded and handled by the bounded rules (Logic and Proof, Proposition 6.1.1), and (g∘f)(u) already unwound to g(f(u)) by Definition 2.1.2. Premises 1 and 2 are the injectivity of f and of g; premise 3 says that f maps X into Y, which the prose used in the clause “the points f(x1) and f(x2) lie in Y”.

1∀u∈X∀v∈X(f(u)=f(v)→u=v)
2∀u∈Y∀v∈Y(g(u)=g(v)→u=v)
3∀u∈Xf(u)∈Y
4x1x1∈X
5x2x2∈X
6g(f(x1))=g(f(x2))
7f(x1)∈Y∀E 3, 4
8f(x2)∈Y∀E 3, 5
9∀v∈Y(g(f(x1))=g(v)→f(x1)=v)∀E 2, 7
10g(f(x1))=g(f(x2))→f(x1)=f(x2)∀E 9, 8
11f(x1)=f(x2)→E 10, 6
12∀v∈X(f(x1)=f(v)→x1=v)∀E 1, 4
13f(x1)=f(x2)→x1=x2∀E 12, 5
14x1=x2→E 13, 11
15g(f(x1))=g(f(x2))→x1=x2→I 6–14
16∀v∈X(g(f(x1))=g(f(v))→x1=v)∀I 5–15
17∀u∈X∀v∈X(g(f(u))=g(f(v))→u=v)∀I 4–16

Compare it with the prose of (a). “Let x1,x2∈X” opens the two flagged boxes of lines 4 and 5, and “with g(f(x1))=g(f(x2))” is the assumption of line 6. The first tagged sentence is lines 7–11, and the second is lines 12–14. The closing “so g∘f is injective” stands for lines 15–17, the closing lines of →I and of the two ∀I’s; by the convention of Logic and Proof, Chapter 8 on silent steps, the prose may state their result without naming them. The two tags in the prose mark the only steps where a hypothesis is used, and that is what the proof is about.

Second readingEach hypothesis is needed

Each hypothesis is needed. In (a), dropping the injectivity of g breaks the conclusion: with f=idR and g=q1, squaring on R, the composite g∘f=q1 is not injective, although f is. Dropping the injectivity of f instead, with f=q1 and g=idR, gives the same composite. In (b), with f=idR and g=q1, the composite q1 is not surjective, although f is; with f=q1 and g=idR, again g∘f=q1 is not surjective, although g is.

The converses fail. If g∘f is injective, g need not be: take f:{1}→{1,2}, f(1)=1, and the constant function g:{1,2}→{1}. Then g∘f=id{1}, a bijection, while g is not injective, since g(1)=g(2), and f is not surjective, since 2 is not a value. Half of each converse survives.

Proposition 2.2.2 (Partial Converses for Composites)

Let f:X→Y and g:Y→Z be functions.

  • (a) If g∘f is injective, then f is injective.

  • (b) If g∘f is surjective, then g is surjective.

Idea. For (a), equal values of f stay equal after g is applied, and then the injectivity of g∘f takes over. For (b), a preimage of z under g∘f gives one under g, by passing through f. The example above shows that neither half can be swapped: there g∘f is bijective, g is not injective, and f is not surjective.

Proof.

  • (a) Suppose g∘f is injective. Let x1,x2∈X with f(x1)=f(x2); we must show x1=x2. Applying g to both sides gives g(f(x1))=g(f(x2)), because a function gives equal outputs at equal inputs. By Definition 2.1.2, this says (g∘f)(x1)=(g∘f)(x2). Since g∘f is injective, x1=x2. So f is injective.

  • (b) Let z∈Z. Since g∘f is surjective, there is x∈X with (g∘f)(x)=z. Let y:=f(x), an element of Y. Then g(y)=g(f(x))=(g∘f)(x)=z, by Definition 2.1.2. So z has a preimage under g, namely y. Since z was arbitrary, g is surjective.

In particular, if g∘f=idX, then f is injective by (a), since idX is; Section 2.4 proves this again as Theorem 2.4.1 (a).

2.2.3. Structure maps

Every subset, product and power set comes with maps of its own. They are the first test cases for the two questions, and the answers depend on the sets involved, sometimes only on whether a set is empty.

Example (The maps that come with sets)

Let X and Y be sets, and A⊆X. Decide whether each of the following maps is injective and whether it is surjective.

  • (a) The inclusion map A→X, a↦a.

  • (b) The projection p1:X×Y→X, p1(x,y)=x.

  • (c) The diagonal map δX:X→X×X, δX(x)=(x,x).

  • (d) The complement map c:P(X)→P(X), c(S)=X∖S.

Solution.

  • (a) Injective: the value at a point of A is the point itself, so equal values come from equal points. Surjective exactly when A=X. The values are the points of A, so every x∈X is a value if and only if X⊆A, that is, since A⊆X, if and only if A=X.

  • (b) Surjective exactly when Y has an element or X=∅. If y0∈Y, then each x∈X is the value p1(x,y0). If X=∅, there is no point of X to reach, and p1 is surjective vacuously. If Y=∅ and X has an element x0, then X×Y=∅ (Proposition 1.4.1), so p1 has no values at all, and it misses x0. Injectivity of p1 is the Quick check below. The second projection p2:X×Y→Y, p2(x,y)=y, behaves in the same way, with the roles of X and Y exchanged.

  • (c) Injective: if (x,x)=(x′,x′), then x=x′ by Definition 1.4.1. Not surjective as soon as X has two points x≠x′: the pair (x,x′) is not a value, since (z,z)=(x,x′) would give x=z=x′. If X has at most one element, δX is surjective, and so bijective: X×X is ∅ or {(x,x)}, and each of its pairs is a value.

  • (d) Bijective. We write S, T for subsets of X, to keep them apart from the fixed A. First, c(c(S))=S for every S⊆X. Let x be arbitrary. By a chain of equivalences (Example (Method: a chain of equivalences)), x∈X∖(X∖S)⟺x∈X∧¬(x∈X∧x∉S)[definition of ∖, twice]⟺x∈X∧(x∉X∨x∈S)[De Morgan; double negation]⟺x∈X∧x∈S[drop the disjunct x∉X]⟺x∈S[S⊆X] The step tagged De Morgan uses De Morgan (d), (c) (Logic and Proof, Proposition 2.5.5) applied to the second conjunct, together with ¬¬(x∈S)⊣⊢x∈S (Logic and Proof, Proposition 2.5.1); from left to right both steps use RAA. In the step that drops the disjunct, from left to right, the disjunct x∉X clashes with the conjunct x∈X, so disjunctive syllogism (Logic and Proof, Proposition 2.3.4) leaves x∈S; from right to left, ∨I puts the disjunct back. In the last step, from right to left, x∈S gives x∈X because S⊆X. By Definition 1.2.1, X∖(X∖S)=S.

Now c is injective: if c(S)=c(T), then S=c(c(S))=c(c(T))=T. And c is surjective: each T⊆X is the value of c at c(T), since c(c(T))=T.

So c∘c=idP(X) (Proposition 2.1.1): applying c twice changes nothing.

Quick check. When is the projection p1:X×Y→X injective?

Solution. Exactly when X=∅ or Y has at most one element. If x∈X and y≠y′ in Y, then (x,y)≠(x,y′) (Definition 1.4.1), and both have the value x: two witnesses against injectivity. If X=∅, then X×Y=∅ (Proposition 1.4.1), and p1 is the empty function, injective vacuously. If Y has at most one element and p1(x,y)=p1(x′,y′), then x=x′, and y=y′ because both lie in Y; so (x,y)=(x′,y′).

2.2.4. Examples from algebra and calculus

The methods of the first subsection now meet maps from school mathematics. Three times below, a single feature decides an answer: a coefficient, a theorem of Chapter 1, and an order property.

Example (Maps from arithmetic)

Decide whether each map is injective and whether it is surjective.

  • (a) For integers a≠0 and b, the map Z→Z, n↦an+b.

  • (b) The map N×N→N, (m,n)↦mn.

  • (c) The map φ:Z×{0,1}→Z, φ(q,r)=2q+r.

Solution.

  • (a) The maps n↦3n and n↦5n−2 of the first subsection generalize. Injective: an1+b=an2+b gives a(n1−n2)=0, so n1=n2, since a≠0 and a product of integers is 0 only if a factor is. Surjective exactly when a=1 or a=−1. If a=±1, then a2=1; for m∈Z put n:=a(m−b), and then an+b=a2(m−b)+b=m. If a≠±1, then |a|≥2, and b+1 is not a value: an+b=b+1 means an=1, which is false for n=0, and false for n≠0 because then |an|=|a||n|≥2.

  • (b) Surjective: each k∈N is the value at (k,1). Not injective: (1,2)≠(2,1) (Definition 1.4.1), and both are sent to 2. Any formula symmetric in m and n fails injectivity in the same way; the sum (m,n)↦m+n is Exercise B1 (b).

  • (c) Surjective: by Theorem 1.1.2, every n∈Z is 2k or 2k+1 for some k∈Z, that is, φ(k,0) or φ(k,1). Injective: let 2q+r=2q′+r′. If r=r′, then 2q=2q′, so q=q′, and the pairs are equal (Definition 1.4.1). If r≠r′, then, since r,r′∈{0,1}, the cases (r,r′)=(0,1) and (1,0) remain (Example (Method: proof by cases)). The equation is symmetric in the two pairs, so the second case is the first with the pairs exchanged, and we may assume r=0 and r′=1; now 2q=2q′+1 is an integer that is both even and odd, which Theorem 1.1.2 excludes. So φ is a bijection.

So “every integer is even or odd, and not both” is exactly the statement that φ is a bijection: “even or odd” is surjectivity, and “not both” is injectivity.

For real functions, injectivity often comes from order. A function that keeps every strict inequality, or reverses every one, cannot take a value twice.

Proposition 2.2.3 (Strictly Monotone Maps Are Injective)

Let A,B⊆R and f:A→B. Call f strictly increasing if, for all x,x′∈A, x<x′ implies f(x)<f(x′), and strictly decreasing if x<x′ implies f(x)>f(x′). If f is strictly increasing or strictly decreasing, then f is injective.

Proof. We use the contrapositive form of Definition 2.2.1. Let x,x′∈A with x≠x′. By trichotomy, x<x′ or x′<x, and since the claim is symmetric in x and x′, we may assume x<x′. Then f(x)<f(x′) or f(x)>f(x′), as f is increasing or decreasing; in either case f(x)≠f(x′).

Example (Maps from calculus)

Decide whether each map is injective and whether it is surjective.

  • (a) R→R, x↦x3.

  • (b) The floor map R→Z, x↦⌊x⌋, where ⌊x⌋ is the unique integer m with m≤x<m+1.

  • (c) Differentiation of polynomials of degree at most 2, recorded on coefficients: since a+bx+cx2 has derivative b+2cx, this is the map D:R3→R2, D(a,b,c)=(b,2c).

Solution.

  • (a) Injective. The map is strictly increasing. Let x<y. Then y3−x3=(y−x)(x2+xy+y2),x2+xy+y2=(x+12y)2+34y2. The second expression is positive unless x=y=0: if y≠0, then 34y2>0; if y=0, it equals x2, which is positive unless x=0. And x=y=0 is excluded by x<y. So both factors are positive, x3<y3, and Proposition 2.2.3 applies. Surjective: every real y has a real cube root y3, with (y3)3=y. So the map is bijective.

  • (b) Surjective: for n∈Z, ⌊n⌋=n, since n≤n<n+1. Not injective: ⌊0⌋=0=⌊12⌋, since 0≤12<1.

  • (c) Surjective: for (u,v)∈R2, D(0,u,v/2)=(u,v). Not injective: D(0,0,0)=(0,0)=D(1,0,0); a constant has derivative 0. In general the first coordinate a of a preimage is free: it is the constant of integration.

In (a), injectivity came from an order property, not from the equation x13=x23. Exercise B1 (c) uses the same property on Z.

Quick check. Is n↦n2 injective as a map N→N? As a map Z→N? Is either surjective?

Solution. On N it is injective, because it is strictly increasing. Let n<m. If m2≤n2, then m≤n by (⇐) of Logic and Proof, Theorem 2.4.5 (both numbers are ≥0), which trichotomy excludes, since n<m. So n2<m2, and Proposition 2.2.3 applies with A=B=N. On Z it is not injective: (−1)2=1=12. Neither map is surjective: 2 is not the square of an integer, since |n|≤1 gives n2≤1, and |n|≥2 gives n2≥4.

2.2.5. Cancellation

For numbers, ab=ac with a≠0 gives b=c. For functions, an equation f∘g=f∘h does not always give g=h. Squaring, the function q1 of Example (Squaring, three ways), satisfies q1∘idR=q1∘(−idR), where −idR is the function x↦−x, because x2=(−x)2; yet idR≠−idR, since their values at 1 differ. The failure is made of the two witnesses 1 and −1 against the injectivity of q1. Before reading on, guess which property of f makes cancellation on the left legal, and which property makes it legal on the right.

Theorem 2.2.4 (Cancellation)

Let f:X→Y be a function.

  • (a) f is injective if and only if, for every set W and all functions g,h:W→X, f∘g=f∘h implies g=h.

  • (b) f is surjective if and only if, for every set Z and all functions g,h:Y→Z, g∘f=h∘f implies g=h.

Injections cancel on the left, and surjections on the right.

Idea (Scratch work). The two directions (⇒) only unwind Proposition 2.1.1: to show g=h, compare the values at an arbitrary point. The directions (⇐) are the content. Their hypothesis speaks about functions and their goal about points, so the gap is to turn points into functions. For (a), the bridge is that a point of X is as good as a function from a one-element set into X: the point x gives the function {0}→X, 0↦x.

Givens Goal
cancellation on the left; x1,x2∈X with f(x1)=f(x2) x1=x2
the hypothesis needs functions into X g,h:{0}→X, g(0):=x1, h(0):=x2
(f∘g)(0)=f(x1)=f(x2)=(f∘h)(0) f∘g=f∘h, so g=h: the gap closes at x1=g(0)=h(0)=x2

For (b), argue by contrapositive. If a point y0∈Y is missed by f, then two functions on Y that differ only at y0 cannot be told apart after f, because f never arrives at y0. Two values suffice: take the constant function 0 and the indicator function of {y0} (Example (First functions) (d)), both Y→{0,1}.

Proof.

  • (a) (⇒) Suppose f is injective. Let W be a set and g,h:W→X functions with f∘g=f∘h, and let w∈W. Then f(g(w))=f(h(w)) by Definition 2.1.2, so g(w)=h(w) by the injectivity of f. Since g and h have the same domain and codomain and agree at every point, g=h (Proposition 2.1.1).

    (⇐) Suppose the cancellation property of (a) holds, and let x1,x2∈X with f(x1)=f(x2). Define g,h:{0}→X by g(0):=x1 and h(0):=x2; each is a function, with one input and one value. The composites agree at 0, the only point of their domain: (f∘g)(0)=f(x1)=f(x2)=(f∘h)(0). So f∘g=f∘h (Proposition 2.1.1), and the hypothesis with W={0} gives g=h. Therefore x1=g(0)=h(0)=x2, and f is injective.

  • (b) (⇒) Suppose f is surjective. Let Z be a set and g,h:Y→Z functions with g∘f=h∘f, and let y∈Y. By surjectivity there is x∈X with f(x)=y [∃E: the name x is fresh], and then g(y)=g(f(x))=(g∘f)(x)=(h∘f)(x)=h(f(x))=h(y). So g=h (Proposition 2.1.1).

(⇐) It suffices to prove the contrapositive: if f is not surjective, then the cancellation property of (b) fails. The step back from the contrapositive to (⇐) is Logic and Proof, Proposition 2.5.2, which uses RAA. Suppose f is not surjective. Negating the bounded quantifiers of Definition 2.2.2 (Logic and Proof, Proposition 6.2.3, a classical law), there is y0∈Y with f(x)≠y0 for every x∈X. Let Z:={0,1}, let g:Y→Z be the constant function 0, and let h:=1{y0}:Y→Z. For every x∈X we have f(x)≠y0, so h(f(x))=0=g(f(x)); hence g∘f=h∘f (Proposition 2.1.1). But h(y0)=1≠0=g(y0), so g≠h. This proves the contrapositive, and with it (⇐).

The proofs needed only W={0} and Z={0,1}: maps from a one-point set detect injectivity, and maps into a two-point set detect surjectivity.

Example (Method: cancel an injection or a surjection)

Template. To prove g=h, find a function f with f∘g=f∘h and f injective, or with g∘f=h∘f and f surjective. Compute the two composites, often with Proposition 2.1.3; prove that f is injective or surjective; then cancel by Theorem 2.2.4.

When to use it. When g and h are known through equations rather than formulas, or when the composites are easier to compute than g and h themselves.

The usual failure. Canceling a non-injective f on the left, as with squaring before Theorem 2.2.4; and canceling on the wrong side. An injection does not cancel on the right: f:{0}→{0,1}, f(0)=0, is injective, and g=id{0,1} and the constant h=0 satisfy g∘f=h∘f, with g≠h.

Example (Canceling the parity map)

Let g,h:Z→Z be functions.

  • (a) Suppose g(2q+r)=h(2q+r) for all q∈Z and r∈{0,1}. Show that g=h by cancellation.

  • (b) Suppose only that g(2q)=h(2q) for all q∈Z. Must g=h?

Solution.

  • (a) Let φ:Z×{0,1}→Z, φ(q,r)=2q+r, be the map of Example (Maps from arithmetic) (c). The hypothesis says that (g∘φ)(q,r)=(h∘φ)(q,r) at every point of Z×{0,1}, so g∘φ=h∘φ (Proposition 2.1.1). The map φ is surjective (Example (Maps from arithmetic) (c)), so it cancels on the right (Theorem 2.2.4 (b)): g=h.

  • (b) No. The hypothesis now says g∘ψ=h∘ψ for ψ:Z→Z, ψ(q)=2q, and ψ is not surjective: 1=2q would make 1 even, while 1 is odd, and Theorem 1.1.2 says no integer is both. Here is a pair that the hypothesis cannot tell apart. Let O⊆Z be the set of odd integers, g:=idZ, and h(n):=n+1O(n), with the indicator function of Example (First functions) (d). Then h(2q)=2q=g(2q) for every q∈Z, since 2q is even and so not odd; but h(1)=2≠1=g(1).

The odd numbers, the points that ψ misses, are exactly where g and h may differ: they play the part of y0 in the proof of Theorem 2.2.4 (b).

Quick check. Functions g,h:R→R satisfy 2g(x)+1=2h(x)+1 for every real x. Which function is canceled, on which side, and why is that allowed? Could t↦t2 be canceled in the same way?

Solution. The function u:R→R, u(t)=2t+1, is canceled on the left: the hypothesis says u∘g=u∘h, and u is injective, since 2t1+1=2t2+1 gives t1=t2. So g=h by Theorem 2.2.4 (a). Squaring cannot be canceled in this way, because it is not injective: g=idR and h=−idR satisfy g(x)2=h(x)2 for every x, and g≠h.

Second readingPart (a) by cancellation

Part (a) of Proposition 2.2.2 has a second proof by cancellation. Suppose g∘f is injective, and let u,v:W→X with f∘u=f∘v. Then (g∘f)∘u=g∘(f∘u)=g∘(f∘v)=(g∘f)∘v by Proposition 2.1.3, so u=v, because the injective g∘f cancels on the left (Theorem 2.2.4 (a), (⇒)). So f cancels on the left, and it is injective by the same theorem, (⇐). Part (b) is the mirror image, with surjections canceled on the right.

Remark (Looking ahead). Chapter 3 proves the division algorithm, which makes (q,r)↦qn+r a bijection Z×{0,…,n−1}→Z for every integer n≥1, as Example (Maps from arithmetic) (c) did for n=2. Chapter 4 proves the facts of Example (Deciding injective and surjective) (c), (d) in general, from the pigeonhole principle of the lattice-point puzzle of Section 1.1, and, in an exercise, counts the injections between finite sets.

2.2.6. Exercises

A. Check your understanding

Exercise (A1)
  • (a) Define “f:X→Y is injective” in symbols, and write its negation in symbols.
  • (b) Is the empty function ∅→{1} injective? Is it surjective? Justify your answers.
  • (c) Which of these relations on {1,2,3} are graphs of functions {1,2,3}→{1,2,3}? For each that is not, name the clause of the definition that fails. R1={(1,2),(2,2),(3,1)}, R2={(1,1),(2,3)}, R3={(1,1),(1,2),(2,2),(3,3)}.
  • (d) How many functions {1,2}→{a,b,c} are there, and how many of them are injective? Answer by listing.

Solution.

  • (a) f is injective: ∀x1∈X ∀x2∈X (f(x1)=f(x2)→x1=x2) (Definition 2.2.1). Its negation: ∃x1∈X ∃x2∈X (f(x1)=f(x2)∧x1≠x2). The bounds stay as they are, and the negated implication becomes “hypothesis and not conclusion”, by the negation laws of Logic and Proof, Chapter 6.

  • (b) Injective: yes. The condition “for all x1,x2∈∅, …” holds vacuously, since there are no x1∈∅ (Logic and Proof, Proposition 2.1.2). Surjective: no. The witness is 1: there is no x∈∅ at all, so none with value 1.

  • (c) R1 is a function (1↦2, 2↦2, 3↦1). R2 is not: clause (Fn1) fails at 3, which has no output. R3 is not: clause (Fn2) fails at 1, which has the two outputs 1 and 2.

  • (d) A function f:{1,2}→{a,b,c} is determined by the pair of values (f(1),f(2)) (Proposition 2.1.1), and each value can be any of the three letters. Listing the pairs: (a,a), (a,b), (a,c),(b,a), (b,b), (b,c),(c,a), (c,b), (c,c). There are 9 functions. A function on {1,2} is injective exactly when f(1)≠f(2), since 1 and 2 are the only two different inputs. Removing the three pairs with equal entries, on the diagonal of the list, leaves 6 injective functions.

B. Practice

Exercise (B1: Five functions)

Determine which of the following are injective, which are surjective, and which are not functions at all. Justify your answers.

  • (a) Z→Z, n↦2n.
  • (b) N×N→N, (m,n)↦m+n.
  • (c) Z→Z, n↦n3.
  • (d) R→(−1,1), x↦x/1+x2.
  • (e) Z>0→Z>0, n↦n+(−1)n.

Solution.

  • (a) Injective: 2n1=2n2 gives n1=n2. Not surjective: the witness is 1, which is odd, while every 2n is even, and no integer is both even and odd (Theorem 1.1.2).

  • (b) Not injective: (1,2)≠(2,1) (Definition 1.4.1), and both are sent to 3. Surjective: for k∈N, the pair (0,k) lies in N×N and is sent to k.

  • (c) Injective: x↦x3 is strictly increasing on R (Example (Maps from calculus) (a)), so also on Z, and Proposition 2.2.3 applies. Not surjective: the witness is 2. If n≤1, then n3≤1; if n≥2, then n3≥8. So n3≠2 for every integer n.

  • (d) A function: for every x, 1+x2>x2≥0, so 1+x2 is defined and exceeds x2=|x|; hence |x/1+x2|<1, and the value lies in (−1,1). Injective. Suppose y=x/1+x2. The denominator is positive, so y has the sign of x, and squaring gives y2(1+x2)=x2, that is, x2(1−y2)=y2. Since |y|<1 (shown above), 1−y2>0, so x2=y2/(1−y2). Of the square roots of this number, x is the one with the sign of y: x=y1−y2. So x is determined by y: two inputs with the same output y are both equal to y/1−y2, hence equal. Surjective. Let y∈(−1,1) and put x:=y/1−y2, a real number since 1−y2>0. Then 1+x2=1/(1−y2), so 1+x2=1/1−y2, and x1+x2=y1−y2⋅1−y2=y. So the function is bijective. (For example, x=34↦3/45/4=35, and y=35 comes back to x=3/54/5=34.) The same plan as in Example (Solving backwards, proving forwards) works, with 1+x2 in place of 1+|x| and squaring in place of the split by sign.

  • (e) Not a function Z>0→Z>0: at n=1 the formula gives 1+(−1)=0, and 0∉Z>0, so (Fn1) fails at 1. This is the planted failure: the question whether it is injective or surjective does not arise. (On N={0,1,2,…} the same formula is a function, and a bijection: it swaps 0↔1, 2↔3, and so on.)

Exercise (B2: Put the proof in order)

Let f:X→Y and g:Y→Z be functions. The following lines contain a proof that if g∘f is surjective and g is injective, then f is surjective, shuffled, together with two lines that do not belong. Write the six correct lines in an order that makes a proof, and say why each of the other two lines fails.

  • (i) Since g is injective, f(x)=y.

  • (ii) Let z∈Z.

  • (iii) Then g(y)∈Z.

  • (iv) Since y was arbitrary, f is surjective.

  • (v) Since g∘f is surjective, there is x∈X with g(f(x))=g(y).

  • (vi) Let y∈Y.

  • (vii) Since f is injective, x=y.

  • (viii) So y has the preimage x under f.

Solution. The order is (vi), (iii), (v), (i), (viii), (iv):

Let y∈Y. Then g(y)∈Z. Since g∘f is surjective, there is x∈X with g(f(x))=g(y). Since g is injective, f(x)=y. So y has the preimage x under f. Since y was arbitrary, f is surjective.

No other order is admissible. Each line uses the one before it: (iii) needs the y of (vi); (v) applies the surjectivity of g∘f at the point g(y) of (iii) [∃E: the name x is fresh], using Definition 2.1.2 to write (g∘f)(x) as g(f(x)); (i) applies the injectivity of g to the equation of (v), at the points f(x) and y of Y; (viii) is the ∃I that (i) makes possible; and (iv) closes the ∀I opened by (vi).

The distractor (ii) opens with an arbitrary element of the wrong set. The goal “f is surjective” is ∀y∈Y ∃x∈X f(x)=y, so the proof must take an arbitrary y∈Y; the point of Z that the proof needs is g(y), and it is built, not given. The distractor (vii) uses a hypothesis the statement does not have, since nothing says f is injective; and it equates a point of X with a point of Y, which is not what the goal asks for.

The hypothesis “g injective” is needed. In the example before Proposition 2.2.2, g∘f=id{1} is surjective and f is not; there g is not injective.

Exercise (B3: Examples on the natural numbers)

Give an example of a function N→N that is surjective and not injective, and one that is injective and not surjective. Check each property.

Solution. Surjective, not injective. Let s(0):=0 and s(n):=n−1 for n≥1; for n≥1, n−1∈N, so s:N→N is a function. It is surjective: for m∈N, m+1≥1, so s(m+1)=m. It is not injective: s(0)=0=s(1) and 0≠1.

Injective, not surjective. Let t(n):=n+1. It is injective: n1+1=n2+1 gives n1=n2. It is not surjective: 0 is not an output, since n+1≥1.

Many other answers are correct. An answer to the first part must have: every value in N (so it is a function into N); at least one value taken at two different inputs, with the two inputs named; and every m∈N reached, with a preimage given as a formula in m, since checking some m is not enough. An answer to the second part must have: values in N; a proof that equal outputs come from equal inputs; and one named natural number that is never reached, with the reason.

Exercise (B4: Prove or disprove)

Prove each true statement by the methods of Example (Method: proving injectivity) and Example (Method: proving surjectivity), and refute each false one with a concrete counterexample.

  • (a) The function Z→Z, n↦n2+n, is injective.
  • (b) The function R→R, x↦x3+2x, is injective.
  • (c) The function Z×Z→Z, (m,n)↦2m+3n, is surjective.
  • (d) The function Z×Z→Z, (m,n)↦2m+4n, is surjective.
  • (e) The formula x↦x2+4x defines a bijection from [−2,∞) to [−4,∞).

Solution.

  • (a) False. The inputs 0 and −1 are different, and both are sent to 0: 02+0=0=(−1)2+(−1).

  • (b) True. Let x3+2x=y3+2y. Then 0=(x3−y3)+2(x−y)=(x−y)(x2+xy+y2+2), and x2+xy+y2+2=(x+12y)2+34y2+2≥2>0. A product of two reals is 0 only if a factor is 0, so x−y=0, that is, x=y.

  • (c) True. Let k∈Z. The pair (−k,k) lies in Z×Z, and 2(−k)+3k=k. (The scrap-paper search: 3−2=1, so multiply that solution of 2m+3n=1 by k.)

  • (d) False. The witness is 1. For all integers m and n, 2m+4n=2(m+2n) is even, and 1 is odd; no integer is both (Theorem 1.1.2). So 2m+4n≠1.

  • (e) True. First, the formula is a function into [−4,∞): x2+4x=(x+2)2−4≥−4. Injective: let x1,x2≥−2 with x12+4x1=x22+4x2. Then (x1+2)2=(x2+2)2, and both bases are ≥0, so x1+2=x2+2 by Logic and Proof, Theorem 2.4.5 (used twice, as in Example (Squaring, three ways) (b)), and x1=x2. Surjective: let y≥−4 and put x:=−2+y+4, defined since y+4≥0. Then x≥−2, and x2+4x=(x+2)2−4=(y+4)−4=y.

Exercise (B5: Prove or disprove)

Let f:X→Y and g:Y→Z be functions in (a) and (b). Prove each true statement, and refute each false one with a concrete counterexample.

  • (a) If g∘f is injective and g is surjective, then f is surjective.
  • (b) If g∘f is surjective and f is injective, then g is injective.
  • (c) If g,h:R→R satisfy g(x)3=h(x)3 for every real x, then g=h.
  • (d) If g,h:R→R satisfy g(x2)=h(x2) for every real x, then g=h.
  • (e) If g,h:R→R satisfy g(x3)=h(x3) for every real x, then g=h.

Solution.

  • (a) False. Let X={1}, Y={1,2}, Z={1}, f(1)=1, and g the constant function 1. Then g∘f is injective, since its domain has one element; g is surjective, since 1=g(1); and 2 is not a value of f.

  • (b) False. On N, let f(n)=2n, and let g(m)=m/2 for even m and g(m)=(m−1)/2 for odd m. By Theorem 1.1.2 each m∈N falls under exactly one case, and in each case g(m)∈N; so g:N→N is a function. Then g(f(n))=2n/2=n, so g∘f=idN (Proposition 2.1.1), which is surjective. And f is injective, since 2n1=2n2 gives n1=n2. But g(0)=0=g(1), so g is not injective.

  • (c) True. Let k:R→R, k(t)=t3. The hypothesis says k∘g=k∘h, and k is injective (Example (Maps from calculus) (a)). Canceling k on the left (Theorem 2.2.4 (a)) gives g=h.

  • (d) False. Let g=idR and h(t)=|t|. Then g(x2)=x2=|x2|=h(x2) for every x, since x2≥0; but g(−1)=−1≠1=h(−1). Squaring R→R is not surjective, so it cannot be canceled on the right, and g and h differ exactly on the negative numbers, which squaring misses.

  • (e) True. With k as in (c), the hypothesis says g∘k=h∘k, and k is surjective, since every real number has a real cube root (Example (Maps from calculus) (a)). Canceling k on the right (Theorem 2.2.4 (b)) gives g=h.

C. Going deeper

Exercise (C1: Exit check: composites)

Let f:X→Y and g:Y→Z be functions.

  • (a) Prove that if g∘f is injective and f is surjective, then g is injective.
  • (b) Give an example in which g∘f is injective and g is not injective, and say which hypothesis of (a) fails.

Solution.

  • (a) Suppose g∘f is injective and f is surjective. Let y1,y2∈Y with g(y1)=g(y2); we must show y1=y2. Since f is surjective, there are x1,x2∈X with f(x1)=y1 and f(x2)=y2 [∃E, twice: the names x1 and x2 are fresh and different]. Then, by Definition 2.1.2, (g∘f)(x1)=g(y1)=g(y2)=(g∘f)(x2), so x1=x2, since g∘f is injective. Hence y1=f(x1)=f(x2)=y2, and g is injective.

  • (b) Take the example before Proposition 2.2.2: f:{1}→{1,2}, f(1)=1, and g:{1,2}→{1}, g(1)=g(2)=1. Then g∘f:{1}→{1} is injective, because its domain has only one element: if x1,x2∈{1}, then x1=1=x2. And g is not injective: g(1)=g(2) with 1≠2. The hypothesis of (a) that fails is the surjectivity of f: 2 is not a value of f.

Marking scheme. (10 points) - 2: fixes arbitrary y1,y2∈Y with g(y1)=g(y2) and states the goal y1=y2 (or, for a contrapositive proof, fixes y1≠y2 and aims for g(y1)≠g(y2)). - 3: names preimages x1, x2 under f, with fresh and different names, by the surjectivity of f. - 3: rewrites g(y1)=g(y2) as an equation of values of g∘f, invokes the injectivity of g∘f (in contrapositive form, if the proof is contrapositive), and returns to y1=y2 through f. - 2: an example with explicit sets and functions, both claims checked (g∘f injective; two different points with the same value under g), and the failing hypothesis named.

Fatal errors (0 for the step): assuming g is injective; one name for both preimages, so that y1=f(x)=y2 is assumed from the start (entry (N4) of Logic and Proof, Chapter 8’s catalogue); starting from y1=y2 and deriving g(y1)=g(y2) (the converse, entry (N5)).

Exercise (C2: When the composite is a bijection)
  • (a) Give functions f,g:N→N with g∘f bijective and neither f nor g bijective.
  • (b) Let f:X→Y and g:Y→Z be functions. Prove that if g∘f is bijective and f is surjective, then f and g are both bijective.

Solution.

  • (a) Let f(n)=n+1, and let g(0)=0 and g(m)=m−1 for m≥1; both are functions N→N, since m−1∈N for m≥1. Then g(f(n))=(n+1)−1=n, since n+1≥1; so g∘f=idN (Proposition 2.1.1), which is bijective. But f misses 0, since n+1≥1, so f is not surjective; and g(0)=0=g(1), so g is not injective.

  • (b) Suppose g∘f is bijective and f is surjective. Since g∘f is injective, f is injective by Proposition 2.2.2 (a); with the hypothesis, f is bijective. Since g∘f is surjective, g is surjective by Proposition 2.2.2 (b). Since g∘f is injective and f is surjective, g is injective: for y1,y2∈Y with g(y1)=g(y2), choose x1,x2∈X with f(x1)=y1 and f(x2)=y2; then (g∘f)(x1)=(g∘f)(x2), so x1=x2, and y1=y2. So g is bijective too.