6.4 Composing functions

Definition 6.32 (Composition of functions).

Given functions f:ABf:A\to B and g:BCg:B\to C we can create a new function gf:ACg\circ f:A\to C defined by gf:xg(f(x))g\circ f:x\mapsto g(f(x)).

Let’s check explicitly that gfg\circ f really does fit the formal definition of a function from Definition 6.1. We need to define a graph HH such that:

  1. (i)

    for every xAx\in A, there exists yCy\in C such that (x,y)H(x,y)\in H; and

  2. (ii)

    if (x,y)H(x,y)\in H and (x,z)H(x,z)\in H then y=zy=z.

Let

F={(x,y)A×B:y=f(x)}andG={(y,z)B×C:z=g(y)}F=\{(x,y)\in A\times B:y=f(x)\}\qquad\text{and}\qquad G=\{(y,z)\in B\times C:z% =g(y)\}

be the graphs of the functions f:ABf\colon A\to B and g:BCg\colon B\to C. Define the graph of the composition by

H={(x,z)A×C:yB with (x,y)F and (y,z)G}.H\;=\;\{(x,z)\in A\times C\;:\;\exists\,y\in B\text{ with }(x,y)\in F\text{ % and }(y,z)\in G\}.

Note that this means, for every (x,z)H(x,z)\in H, there exists some yBy\in B such that (x,y)F(x,y)\in F and (y,z)G(y,z)\in G. Hence, by definition of FF and GG, y=f(x)y=f(x) and z=g(y)=g(f(x))=gf(x)z=g(y)=g(f(x))=g\circ f(x).

We now check the two criteria for our graph HH from Definition 6.1.

  1. (i)

    Existence. Fix xAx\in A. Since FF is the graph of the function ff, there exists yBy\in B with (x,y)F(x,y)\in F. Because GG is the graph of the function gg and its domain is all of BB, for that yy there exists zCz\in C with (y,z)G(y,z)\in G. Thus (x,z)H(x,z)\in H. Hence for every xAx\in A there is some zCz\in C with (x,z)H(x,z)\in H.

  2. (ii)

    Uniqueness. Suppose (x,z)H(x,z)\in H and (x,w)H(x,w)\in H. Then there exist y,yBy,y^{\prime}\in B with (x,y)F(x,y)\in F, (y,z)G(y,z)\in G and (x,y)F(x,y^{\prime})\in F, (y,w)G(y^{\prime},w)\in G. Because FF is the graph of a function, (x,y)(x,y) and (x,y)(x,y^{\prime}) force y=yy=y^{\prime}. Now since GG is the graph of a function and (y,z),(y,w)G(y,z),(y,w)\in G, we obtain z=wz=w, as required.

Therefore HH satisfies the existence requirement (i) and the uniqueness requirement (ii), so it is indeed the graph of a function from AA to CC. This function is precisely the composition gfg\circ f, given by (gf)(x)=g(f(x))(g\circ f)(x)=g(f(x)).

Definition 6.33 (Identity Function).

For any set XX, the identity function idX:XXid_{X}:X\rightarrow X on XX is defined by idX(x)=xid_{X}(x)=x for all xXx\in X.

Example 6.34.

Let X={1,3}X=\{1,3\} and Y={2,4,5}Y=\{2,4,5\} and let f:XYf:X\rightarrow Y and g:YXg:Y\rightarrow X be functions defined by f(1)=2f(1)=2, f(3)=4f(3)=4, g(2)=1g(2)=1, and g(4)=g(5)=3g(4)=g(5)=3. Then the composition function gf:XYg\circ f:X\to Y is given by gf(1)=g(f(1))=g(2)=1g\circ f(1)=g(f(1))=g(2)=1 and gf(3)=g(f(3))=g(4)=3.g\circ f(3)=g(f(3))=g(4)=3. In particular, we have gf=idXg\circ f=id_{X}.