2.1  Functions and Composition

Chapter 1 made sets, pairs and relations precise. A relation from A to B is a subset of A×B (Definition 1.4.3), and among the examples of Section 1.4 the graph of squaring relates each real number to exactly one number, while the unit circle relates 0 to two numbers and 2 to none. This chapter is about the first kind of relation. This section gives it its name, function, says when two functions are equal, uses functions to make families, sequences and the set YX precise, and composes them. The rest of the chapter asks what a function does to its inputs and to its codomain (Section 2.2), builds functions from pieces (Section 2.3), undoes them (Section 2.4), and applies them to whole sets (Section 2.5).

2.1.1. What is a function?

Everyone has used functions since school, and the everyday definition is “a rule that assigns to each input one output”. Look at the word “rule”. The rules x↦x2 and x↦(x+1)2−2x−1 are different: one squares, the other adds, squares, subtracts, and subtracts again. Yet on every real number they give the same answer, and nobody would call them different functions. Other functions have no rule at all that one could write down. A table of measured temperatures, one per day, assigns to each day one number, and no formula produces it.

So the rule is not what matters. What matters is which output goes with which input: the set of input–output pairs. That set is a relation, and Section 1.4 said exactly when two relations are the same, namely when they contain the same pairs. So we forget the rule and keep the pairs. One more piece of data is needed, the set in which the outputs are declared to lie; the reason is given after the definition.

A function is its graph, with a declared target.

Definition 2.1.1 (Function)

Let X and Y be sets. A function from X to Y, written f:X→Y, is given by a relation G⊆X×Y, the graph of f, such that for every x∈X there is exactly one y∈Y with (x,y)∈G, together with the set Y, the codomain of f. Formally, f is the pair (G,Y). The set X is the domain of f. For x∈X, the unique y with (x,y)∈G is written f(x), the value of f at x. We write (x,y)∈f for (x,y)∈G, and x↦f(x) for the whole function when its domain and codomain are clear.

In symbols, the condition on the graph is ∀x∈X  ∃!y∈Y  (x,y)∈G, where, as with the bounded quantifiers of Logic and Proof, Definition 5.1.1, ∃!y∈Y ψ abbreviates ∃!y(y∈Y∧ψ).

The whole definition is the quantifier pattern ∀∃!. By Logic and Proof, Definition 5.8.1, “∃!y” is an existence claim and a uniqueness claim, and by Logic and Proof, Proposition 5.8.1 the uniqueness claim may be stated without reference to the witness; so the condition on the graph is two clauses:

  • (Fn1) (existence) for every x∈X there is at least one y∈Y with (x,y)∈G: every input has an output;
  • (Fn2) (uniqueness) for every x∈X and all y,y′∈Y, if (x,y)∈G and (x,y′)∈G, then y=y′: no input has two outputs.

In words: the graph is a set of input–output pairs, with inputs from X and outputs from Y; (Fn1) says no input is left without an output, and (Fn2) says no input is given two. The codomain Y is where outputs are allowed to lie. It need not consist of outputs: x↦x2 can be declared as a function from R to R, although no output is negative. The set of outputs that actually occur is the range of f, {y∈Y:∃x∈X  f(x)=y}, which Section 2.5 will call the image of X and write f(X). The domain needs no slot of its own in the pair (G,Y): by (Fn1) every x∈X occurs as a first coordinate in G, and since G⊆X×Y, nothing else does. So the graph determines the domain.

The notation f(x) is well defined. Writing “the y with (x,y)∈f” is legitimate only if there is one, and only one. Clause (Fn1) supplies one, and clause (Fn2) says that any two are equal; together they license the article “the”. This gives the equivalence that every argument with functions uses: (∗∗)(x,y)∈f⟺y=f(x)(x∈X, y∈Y). For (⇐): (x,f(x))∈f by the choice of f(x), and if y=f(x) then (x,y)∈f by substituting equals (=E, Logic and Proof, Definition 5.7.1). For (⇒): both (x,y) and (x,f(x)) lie in f, so y=f(x) by (Fn2). Two consequences follow at once. Equal inputs give equal outputs: if x1=x2, then f(x1)=f(x2). And every value lies in the codomain: f(x)∈Y for every x∈X.

Functions given by formulas. Most functions in this book are introduced by a formula: “let f:R→R, f(x)=x2”. This means the function whose graph is {(x,y)∈R2:y=x2}. Clause (Fn2) holds for any such graph: if y=x2 and y′=x2, then y=y′. So for a formula only (Fn1) needs checking, and it says: for each x in the domain, the formula makes sense and its value lies in the codomain. For x2 on R both are clear. For “f:R→R, f(x)=1/x” the formula makes no sense at x=0, and (Fn1) fails there; for “f:R→[0,∞), f(x)=x2” the value must be checked to lie in [0,∞), which it does, since squares are nonnegative.

A function whose domain is a product A×B is a function of two variables. Its inputs are pairs, and we write f(a,b) rather than f((a,b)). Addition (m,n)↦m+n from N×N to N is an example.

Example (First functions)

Check (Fn1) and (Fn2), and find the range, for each of the following.

  • (a) f:{1,2,3}→{a,b} with graph {(1,a),(2,b),(3,a)}.

  • (b) The identity function idX:X→X, idX(x)=x, for a set X.

  • (c) A constant function X→Y, x↦c, for a fixed c∈Y.

  • (d) The indicator function 1A:X→{0,1} of a subset A⊆X: 1A(x)={1if x∈A,0if x∈X∖A.

Solution.

  • (a) The graph is a subset of {1,2,3}×{a,b}. Each of 1, 2, 3 occurs as a first coordinate (Fn1), and each occurs exactly once, so no input has two outputs (Fn2). So f is a function, with f(1)=a, f(2)=b, f(3)=a. Its range is {a,b}, the whole codomain. A function on a small finite set is often given this way, by listing its values; no formula is needed.

  • (b) The graph is the diagonal {(x,x):x∈X}. For each x, the pair (x,x) is in it (Fn1); and if (x,y) is in it, then (x,y)=(z,z) for some z∈X, and the characteristic property (Definition 1.4.1) gives x=z=y (Fn2). The range is X.

  • (c) The graph is X×{c}. For each x∈X, (x,c) is in it (Fn1); if (x,y) is in it, then y∈{c} by the membership test (∗) for pairs in a product (Definition 1.4.2), so y=c (Fn2). If X has an element, the range is {c}. If X=∅, the range is ∅.

  • (d) The graph is (A×{1})∪((X∖A)×{0}). For (Fn1), let x∈X. By excluded middle (Logic and Proof, Proposition 2.5.3), x∈A or x∉A; in the first case (x,1) is in the graph, in the second x∈X∖A and (x,0) is. For (Fn2), the two cases cannot both hold, so x never receives both 0 and 1, and each case gives only one pair with first coordinate x. The range is {0,1} if A has an element and X∖A has an element; it is {0} if A=∅ and X has an element, {1} if A=X and X has an element, and ∅ if X=∅. This is the first function of the chapter whose existence clause needs excluded middle: the definition by cases is a function only because every x falls into one of the cases.

The next example collects relations that fail to be functions. Each failure is one clause, and it pays to say which.

Example (Relations that are not functions)
  • (a) Is the unit circle S={(x,y)∈R2:x2+y2=1} the graph of a function R→R?

  • (b) “Send a fraction p/q to its numerator p.” Is this a function from Q to Z? As a relation it is N:={(r,p)∈Q×Z:∃q∈Z>0  r=p/q}.

Solution.

  • (a) No, and both clauses fail, at different points. Clause (Fn2) fails at x=0: both (0,1) and (0,−1) lie in S, and 1≠−1. Clause (Fn1) fails at x=2: a pair (2,y)∈S would need y2=1−4=−3, and no real square is negative. Restricting the inputs to [−1,1] repairs (Fn1) but not (Fn2); keeping only the upper half, y≥0, repairs (Fn2) as well, and gives the function [−1,1]→R, x↦1−x2.

  • (b) No. Clause (Fn1) holds: every rational number is p/q for some p∈Z and q∈Z>0. But (Fn2) fails, because a rational number has many ways of being written as a fraction. Since 12=24, both (12,1) and (12,2) lie in N, and 1≠2. The “rule” gives an output that depends on how the input is written, not on the input. A function may not do that, since its value is attached to the input itself. This is why definitions of the form “write x as …, then send it to …” must be checked for well-definedness, a check that returns in Chapter 5 for functions defined on classes. Here the repair is to fix the way of writing: let q0 be the least q∈Z>0 with rq∈Z (such q exist, by the first sentence, so there is a least one by well-ordering, proved in Chapter 3; a least element is unique), and send r to rq0. This is a function.

Second readingWhy each clause, and why a codomain

Why this definition. Each clause has a job, and dropping one lets in the failures of Example (Relations that are not functions). Without (Fn1), a “function” could be undefined at some inputs, like 1/x at 0; then f(x) would not name anything, and statements “for every x∈X” about f(x) would lose their meaning. Without (Fn2), f(x) would not name one thing, and f(12) in part (b) would be both 1 and 2. The graph replaces the rule because two rules can describe one function, and sets are compared by their elements.

Why is the codomain part of the data? A relation is a set, so if a function were only its graph, two functions with the same graph would be equal (Definition 1.2.1), whatever target was declared. The graph of x↦x2 as a function [0,∞)→R is the same set as its graph as a function [0,∞)→[0,∞). But these should be different functions, because the second reaches every point of its target and the first does not: this is the property called surjectivity in Section 2.2, and Example (Squaring, three ways) there shows it changing with the codomain. Recording the codomain in the pair (G,Y) keeps the two apart. Many books take the same convention, some without saying so.

Warning. A formula is not yet a function. “The function 1/x” names no function until a domain and a codomain are given, and the domain must be chosen so that (Fn1) holds: x↦1/x is a function R∖{0}→R, and there is no function R→R given by this formula. Likewise x makes sense on [0,∞) and not on R. When you meet “let f(x)=…”, ask first where x lives and where f(x) is meant to lie.

Quick check. Which of these relations on {1,2,3} are graphs of functions {1,2,3}→{1,2,3}: {(1,2),(2,2),(3,2)}, {(1,1),(2,2)}, {(1,3),(2,1),(3,2),(2,3)}? For each that is not, name the clause that fails.

Solution. The first is a function: the constant function with value 2. The second fails (Fn1) at 3, which has no output. The third fails (Fn2) at 2, which has the two outputs 1 and 3.

2.1.2. When are two functions equal?

A function is a pair (G,Y), so two functions are equal when their graphs are equal and their codomains are equal. In practice we compare functions by their values, and the next result says that this is the same test.

Proposition 2.1.1 (Equality of Functions)

Let f:X→Y and g:X′→Y′ be functions. Then f=g if and only if X=X′, Y=Y′, and f(x)=g(x) for every x∈X.

Idea. Write f=(G,Y) and g=(G′,Y′). The characteristic property of pairs splits f=g into “same graph” and “same codomain”. Two graphs are equal when they have the same elements, and by (∗∗) an element of a graph is a pair (x,f(x)); so “same graph” is “same inputs, same outputs”.

Proof. Write f=(G,Y) and g=(G′,Y′), as in Definition 2.1.1.

(⇒) Suppose f=g. By the characteristic property of pairs (Definition 1.4.1), G=G′ and Y=Y′. The domain is determined by the graph, as the set of first coordinates of its elements, so X=X′. Let x∈X. By (∗∗), (x,f(x))∈G=G′, so (x,f(x))∈g, and (∗∗) for g gives f(x)=g(x).

(⇐) Suppose X=X′, Y=Y′, and f(x)=g(x) for every x∈X. We show G⊆G′. Let p∈G. Since G⊆X×Y, p=(x,y) with x∈X and y∈Y. By (∗∗), y=f(x), so y=g(x) by the hypothesis, and then p=(x,y)∈G′ by (∗∗) for g. The same argument with f and g exchanged gives G′⊆G, so G=G′ by Proposition 1.2.1. Since also Y=Y′, the characteristic property gives (G,Y)=(G′,Y′), that is, f=g.

So to show two functions equal, check three things: the same domain, the same codomain, and the same value at an arbitrary point. To show them different, one witness suffices: a point where the values differ, or a difference in domain or codomain.

Example (Equal and unequal functions)

Decide which of these functions are equal.

  • (a) f,g:R→R, f(x)=(x+1)2−2x−1 and g(x)=x2.

  • (b) h,k:R→R, h(x)=|x| and k(x)=x2.

  • (c) s1:[0,∞)→R and s2:[0,∞)→[0,∞), both given by x↦x2.

Solution.

  • (a) Equal. The domains are both R and the codomains both R. For every real x, (x+1)2−2x−1=x2+2x+1−2x−1=x2. By Proposition 2.1.1, f=g: two rules, one function.

  • (b) Equal. Same domain and codomain, and for every real x, x2=|x|: the number |x| is nonnegative and its square is x2, and x2 is by definition the nonnegative number with square x2, which is unique by Logic and Proof, Theorem 2.4.5.

  • (c) Not equal. They have the same domain, the same values, and even the same graph; but their codomains R and [0,∞) are different sets (−1 is in one and not the other), so by Proposition 2.1.1 s1≠s2.

Restriction. A function can be cut down to a smaller domain. For f:X→Y and A⊆X, the restriction of f to A is the function f|A:A→Y,f|A(a):=f(a), whose graph is G∩(A×Y): the pairs of f whose input lies in A. The squaring function R→R restricted to [0,∞) is s1 of part (c). The bar in f|A is one of the uses of a vertical bar that the book’s colon-for-set-builder convention keeps free.

2.1.3. Families, sequences, and the set of all functions

Section 1.3 used families of sets (Ai)i∈I and described them informally, as “a set Ai for each index i∈I”. We can now say exactly what a family is, once its members are known to lie in some set. A family of subsets of X indexed by I is a function I→P(X), i↦Ai, with the power set P(X) as the codomain the definition asks for. More generally, if S is a set whose elements are sets, a family of members of S indexed by I is a function I→S. A codomain must be named, because there is no set of all sets (Theorem 1.2.4). The value of a family at i is written Ai rather than A(i), and the family is written (Ai)i∈I, in parentheses because it is indexed. A family is not the same thing as its set of values {Ai:i∈I}: the family (Ai)i∈{1,2} with A1=A2={0} has two indices and one value.

In the same way, a sequence of real numbers (an)n≥1 is a function Z>0→R, n↦an, with the value at n written an. The sequence (1/n) is the function n↦1/n, and its set of values is {1/n:n≥1}. Sequences are the main object of Analysis on the Real Line.

Finally, all functions from X to Y form a set, written YX:={f∈P(X×Y)×{Y}:f is a function from X to Y}.

Second readingWhere YX comes from

It is a set by the working rules of Section 1.2: every function X→Y is a pair (G,Y) with G∈P(X×Y), so YX is the subset of P(X×Y)×{Y} cut out by the condition of Definition 2.1.1, and this product is a set by (W2), (W4), and (W5), so YX is a set by specification (W1).

The letters are in this order because, for finite sets, YX has mn elements when Y has m and X has n, as the next example suggests; counting is the business of Section 4.1. The set {0,1}N of all sequences of zeros and ones, indexed from 0, plays a leading role in Chapter 4.

Example (All functions between two small sets)

List the elements of {0,1}{1,2}, and say which are indicator functions of subsets of {1,2}.

Solution. A function f:{1,2}→{0,1} is determined by its two values f(1) and f(2) (Proposition 2.1.1), and each may be 0 or 1. So there are four:

f(1) f(2) graph indicator of
0 0 {(1,0),(2,0)} ∅
0 1 {(1,0),(2,1)} {2}
1 0 {(1,1),(2,0)} {1}
1 1 {(1,1),(2,1)} {1,2}

Every one of them is an indicator function: f=1A for A={x∈{1,2}:f(x)=1}. The four subsets of {1,2} and the four functions correspond one to one.

The correspondence at the end of the example, between subsets of X and functions X→{0,1}, holds for every set X: send f to {x∈X:f(x)=1} and A to 1A. So counting the subsets of a finite set and counting the functions from it to {0,1} are one problem, which Section 4.1 solves.

A game with five strings. A string of five symbols 0 or 1, such as 01101, is a function {1,…,5}→{0,1}: its value at k is its k-th symbol. One player lists five strings, say 00000, 11111, 01010, 10101, 00111; the other must write a string not on the list. Searching all 32 always works, but is there a rule that builds a missing string from any list of five in five steps? Try one. Chapter 4 comes back to this game.

Quick check. Which string is the indicator function of {1,4}⊆{1,…,5}? What is the value at 2 of the string 01100?

Solution. The indicator of {1,4} has value 1 at 1 and 4 and value 0 elsewhere, so it is the string 10010. The value of 01100 at 2 is its second symbol, 1.

The empty set gives the degenerate cases, and they are worth settling now, since they are the test cases of many later statements.

Proposition 2.1.2 (Functions and the Empty Set)
  • (a) For every set Y there is exactly one function from ∅ to Y: the pair (∅,Y), called the empty function.

  • (b) If X is nonempty (it has an element), there is no function from X to ∅.

Second readingThe empty function, proved

Proof.

  • (a) Existence. The empty relation satisfies ∅⊆∅×Y, since ∅ is a subset of every set (Section 1.2). The condition of Definition 2.1.1 reads “for every x, if x∈∅, then there is exactly one y∈Y with (x,y)∈∅”. For each x the hypothesis x∈∅ is false, so the implication holds (Logic and Proof, Proposition 2.1.2). So (∅,Y) is a function from ∅ to Y.

    Uniqueness. Let (G,Y) be any function from ∅ to Y. Its graph satisfies G⊆∅×Y=∅, by the mirror-image ∅ law of Proposition 1.4.1. So an element of G would be an element of ∅; G has no elements, and G=∅ by Proposition 1.2.3. Hence (G,Y)=(∅,Y).

  • (b) Let x0∈X, and suppose f:X→∅ were a function. By (Fn1) there would be y∈∅ with (x0,y)∈f; but ∅ has no elements. So there is no such function [¬I].

In the notation YX: the set Y∅ has exactly one element for every Y, including Y=∅; and ∅X=∅ whenever X is nonempty. The empty function ∅→Y returns in Section 2.4 as the witness that a hypothesis there cannot be dropped.

Quick check. How many elements do {0,1}∅ and ∅{0} have?

Solution. The set {0,1}∅ has exactly one element, the empty function (∅,{0,1}), by Proposition 2.1.2 (a). The set ∅{0} has none, by Proposition 2.1.2 (b), since {0} has the element 0.

2.1.4. Composition

Two functions can be applied one after the other when the outputs of the first are inputs of the second. Temperature in degrees Celsius, as a function of the day, followed by the conversion to degrees Fahrenheit, gives temperature in Fahrenheit as a function of the day.

Definition 2.1.2 (Composition)

Let f:X→Y and g:Y→Z be functions, the codomain of f being the domain of g. Their composite is the function g∘f:X→Z,(g∘f)(x):=g(f(x)), read “g after f”.

This is a function by the remark on formulas: for x∈X, the value f(x) lies in Y, the domain of g, so g(f(x)) makes sense, and it lies in Z. Its graph is {(x,z)∈X×Z:z=g(f(x))}. The order of the letters is the order of the formula g(f(x)), which is the reverse of the order in which the functions act: f acts first.

Example (The order of composition matters)

Let f,g:R→R, f(x)=x+1 and g(x)=2x. Compute g∘f and f∘g, and decide whether they are equal.

Solution. By Definition 2.1.2, (g∘f)(x)=g(x+1)=2x+2 and (f∘g)(x)=f(2x)=2x+1. At x=0 the values are 2 and 1, so by Proposition 2.1.1 g∘f≠f∘g. In words: “add one, then double” is not “double, then add one”. (In fact the two composites differ at every x, since 2x+2≠2x+1; one point already suffices.)

The next example composes two functions that look as if they cancel each other, and finds that they do so in one order only.

Example (Square root after squaring, and squaring after square root)

Let q:R→[0,∞), q(x)=x2, and r:[0,∞)→R, r(t)=t. Which of r∘q and q∘r are defined? Compute them, and compare each with an identity function.

Solution. The composite r∘q. It is defined, since the codomain [0,∞) of q is the domain of r (Definition 2.1.2). It is a function R→R with (r∘q)(x)=x2=|x|, by Example (Equal and unequal functions) (b). It is not idR: its value at −1 is 1, and idR(−1)=−1.

The composite q∘r. It is defined as well, since the codomain R of r is the domain of q. It is a function [0,∞)→[0,∞) with (q∘r)(t)=(t)2=t(t≥0), because t is by definition a number whose square is t. The functions q∘r and id[0,∞) have the same domain, the same codomain and the same value at every point, so q∘r=id[0,∞) by Proposition 2.1.1.

So one order gives an identity function and the other does not. Applying r and then q returns every input; applying q and then r loses the sign. So q undoes r, but r does not undo q.

Second readingComposites defined in one order only

Composition can also fail to be defined in one order only. For f:{1,2}→R and g:R→R, the composite g∘f:{1,2}→R is defined, and f∘g is not: g’s outputs are real numbers, and f accepts only 1 and 2.

Composition is not commutative, but it is associative, and the identity functions do nothing.

Proposition 2.1.3 (Composition Is Associative)

Let f:X→Y, g:Y→Z, and h:Z→W be functions. Then h∘(g∘f)=(h∘g)∘f, and f∘idX=f=idY∘f.

Proof. Both sides of the first equation are functions from X to W, by Definition 2.1.2. For x∈X, applying Definition 2.1.2 twice on each side gives (h∘(g∘f))(x)=h((g∘f)(x))=h(g(f(x)))=(h∘g)(f(x))=((h∘g)∘f)(x). So the two functions agree at every point, and they are equal by Proposition 2.1.1. Likewise f∘idX and idY∘f are functions from X to Y with values f(idX(x))=f(x) and idY(f(x))=f(x), so both equal f.

Because of associativity, we write h∘g∘f without brackets: every way of bracketing gives the same function, x↦h(g(f(x))).

The identity functions play for composition the part that the number 1 plays for multiplication: by the second statement of Proposition 2.1.3, composing with an identity changes nothing. The analogy stops at division. A number a≠0 can be cancelled from ab=ac; a function f can be cancelled from f∘g=f∘h only under a condition on f. And in Example (Square root after squaring, and squaring after square root), q∘r=id[0,∞) although r∘q≠idR: one composite of two functions can be an identity while the other is not.

Quick check. Find h:R→R with h∘g=f, for f(x)=2x+3 and g(x)=x+1.

Solution. The function g turns x into y=x+1, and x is recovered as y−1. So put h(y):=2(y−1)+3=2y+1. Check: h(g(x))=2(x+1)+1=2x+3=f(x) for every x, so h∘g=f by Proposition 2.1.1.

Quick check. For f,g:R→R, f(x)=x2 and g(x)=x−3, compute (g∘f)(2) and (f∘g)(2).

Solution. (g∘f)(2)=g(4)=1 and (f∘g)(2)=f(−1)=1. The values agree at this point, but the functions are different: at x=0, (g∘f)(0)=−3 and (f∘g)(0)=9. Agreement at one point proves nothing about equality; disagreement at one point proves inequality.

2.1.5. Exercises

A. Check your understanding

Exercise (A1)
  • (a) Let X={1,2,3} and let f:X→X be given by f(1)=2, f(2)=3, f(3)=3. Write the graph of f, and list the values of f∘f and f∘f∘f.
  • (b) Which of the formulas 1/(x2+1), x−1, 1/(x2−1) define a function R→R? For each that does not, name a point where (Fn1) fails.
  • (c) Are f,g:Z→Z, f(n)=n2−n and g(n)=n(n−1), equal? Are h,k:{0,1}→Z, h(x)=x2 and k(x)=x, equal?
  • (d) How many elements do {0}{1,2,3} and ∅{1} have? Name them.

Solution.

  • (a) The graph is {(1,2),(2,3),(3,3)}. For f∘f: f(f(1))=f(2)=3, f(f(2))=f(3)=3, f(f(3))=f(3)=3, so f∘f sends every point to 3. Then f∘f∘f=f∘(f∘f) sends every point to f(3)=3: it is the constant function with value 3, and equal to f∘f.

  • (b) The formula 1/(x2+1) defines a function R→R: x2+1≥1, so the denominator is never 0. The formula x−1 does not: at x=0 it asks for −1, and no real number has square −1 (it fails at every x<1). The formula 1/(x2−1) does not: it fails at 1 and at −1, where the denominator is 0.

  • (c) Yes: both have domain and codomain Z, and n2−n=n(n−1) for every integer n, so f=g by Proposition 2.1.1. Yes again: h(0)=0=k(0) and h(1)=1=k(1), so h and k agree at both points of their common domain; two rules, one function.

  • (d) The set {0}{1,2,3} has exactly one element, the constant function with value 0 (Example (First functions) (c)). A function {1,2,3}→{0} must send each of 1, 2, 3 to 0, so any two such functions agree at every point and are equal by Proposition 2.1.1. The set ∅{1} has no element: a function {1}→∅ would need a value at 1 (Proposition 2.1.2 (b)).

B. Practice

Exercise (B1: Composites of real functions)

Let f,g:R→R, f(x)=x2+1 and g(x)=2x−3.

  • (a) Compute g∘f and f∘g.
  • (b) Find every x∈R with (g∘f)(x)=(f∘g)(x).
  • (c) Find a function h:R→R with h∘g=f, and check it.

Solution.

  • (a) By Definition 2.1.2, (g∘f)(x)=2(x2+1)−3=2x2−1 and (f∘g)(x)=(2x−3)2+1=4x2−12x+10.

  • (b) The equation 2x2−1=4x2−12x+10 is equivalent to 2x2−12x+11=0. Its discriminant is 144−88=56=4⋅14, so by the quadratic formula x=12±2144=3±1214. These two numbers are the only points where the composites agree.

  • (c) The function g turns x into y=2x−3, and x is recovered as (y+3)/2. So put h(y):=(y+32)2+1=y2+6y+134. Check: for every x∈R, h(g(x))=((2x−3)+32)2+1=x2+1=f(x), and h∘g and f both go from R to R, so h∘g=f by Proposition 2.1.1.

Exercise (B2: A map of the plane)

Let s:R2→R2, s(x,y)=(x+y,x−y).

  • (a) Show that (s∘s)(x,y)=(2x,2y) for all x,y∈R.
  • (b) Find a function t:R2→R2 with t∘s=idR2, and check that also s∘t=idR2. (Hint: solve u=x+y, v=x−y for x and y.)

Solution.

  • (a) (s∘s)(x,y)=s(x+y,x−y)=((x+y)+(x−y),(x+y)−(x−y))=(2x,2y).

  • (b) Part (a) suggests halving after applying s. Put t(u,v):=(u+v2,u−v2). Then t(s(x,y))=t(x+y,x−y)=(2x/2,2y/2)=(x,y), and s(t(u,v))=(u+v2+u−v2,u+v2−u−v2)=(u,v). Each computation compares two pairs coordinate by coordinate (Definition 1.4.1). All four functions go from R2 to R2, so t∘s=idR2 and s∘t=idR2 by Proposition 2.1.1.

Exercise (B3: Families and their values)
  • (a) Write the family An=[−1/n,1/n], n∈Z>0, as a function, naming a codomain.
  • (b) Give two different families (Ai)i∈N and (Bi)i∈N of subsets of N with the same set of values {∅,N}.
  • (c) Is i↦{i} a function N→P(N)? A function N→N?

Solution.

  • (a) The function Z>0→P(R), n↦[−1/n,1/n]. Each value is a subset of R, so it lies in P(R).

  • (b) Let Ai=∅ for even i and Ai=N for odd i. Every i∈N is even or odd, and not both (Theorem 1.1.2), so each i receives exactly one value and (Fn1), (Fn2) hold. Let B0=∅ and Bi=N for i≥1. Both families have the set of values {∅,N}. They differ at the index 2: A2=∅ and B2=N. So they are different functions (Proposition 2.1.1) with the same values.

  • (c) Yes: for each i∈N, {i}⊆N, so {i}∈P(N). No: {i}∉N, since the elements of N are numbers and no number is a set (the working convention of Section 1.2). So (Fn1) fails for the codomain N: the only candidate value at i does not lie in it.

C. Going deeper

Exercise (C1: Functions equal to their own square)

In this exercise, a function f:X→X with f∘f=f is called idempotent.

  • (a) Let f:X→X be idempotent. Show that f(y)=y for every y in the range of f.
  • (b) Show that x↦|x| on R is idempotent, and that x↦−x is not.
  • (c) Find all idempotent functions {1,2}→{1,2}.

Solution.

  • (a) Let y be in the range of f: y=f(x) for some x∈X. Then f(y)=f(f(x))=(f∘f)(x)=f(x)=y.

  • (b) For every real x, |x|≥0, so ||x||=|x|; the two functions x↦||x|| and x↦|x| agree everywhere and are equal by Proposition 2.1.1. For m(x)=−x: m(m(1))=−(−1)=1, while m(1)=−1, so m∘m≠m.

  • (c) A function {1,2}→{1,2} is determined by its two values (Proposition 2.1.1), so there are four: the identity, the constant function with value 1, the constant function with value 2, and the swap σ with σ(1)=2, σ(2)=1. The identity is idempotent by Proposition 2.1.3. A constant function c with value a gives c(c(x))=c(a)=a=c(x). The swap is not: σ(σ(1))=σ(2)=1, and σ(1)=2. So there are three idempotent functions.

Exercise (C2: Find the error)

“Claim: if f,g:R→R and g∘f=f∘g, then f=g. Proof: Let x∈R. Then g(f(x))=f(g(x)). Cancelling the outer functions on both sides, f(x)=g(x). So f=g.”

Find the first wrong step, and show that the claim is false.

Solution. The first two steps are correct: g(f(x))=f(g(x)) is the hypothesis g∘f=f∘g at the point x. The wrong step is “cancelling the outer functions”. The two sides apply different outer functions, g on the left and f on the right, and nothing licenses passing from an equation g(a)=f(b) to a=b.

The claim is false. Let f(x)=x+1 and g(x)=x+2. Then (g∘f)(x)=(x+1)+2=x+3 and (f∘g)(x)=(x+2)+1=x+3, so g∘f=f∘g by Proposition 2.1.1. But f(0)=1≠2=g(0), so f≠g.

Marking scheme. (10 points) - 3: locates the step “cancelling the outer functions” as the first wrong one. - 3: says why it fails: the outer functions on the two sides are different, so from g(a)=f(b) one cannot conclude a=b. - 4: a counterexample with both claims checked: the two composites are equal, and f and g differ at a named point.

Fatal errors (0 for the step): blaming the step g(f(x))=f(g(x)); a counterexample in which f∘g≠g∘f.