Composition of Functions

Chaining functions

When the output set of one function feeds the input set of another, the two can be chained.

Definition. Let f:A→Bf : A \to B and g:B→Cg : B \to C. The composition of ff and gg, written g∘fg \circ f (read "gg of ff"), is the function g∘f:A→Cg \circ f : A \to C given by (g∘f)(x)=g(f(x)),∀ x∈A(g \circ f)(x) = g\big(f(x)\big), \quad \forall\, x \in A

Read it right to left: ff acts first, then gg acts on the result. The middle set BB must match — ff's outputs must be legal inputs for gg.

Worked chain on finite sets. Let f:{2,3,4,5}→{3,4,5,9}f : \{2,3,4,5\} \to \{3,4,5,9\} with f(2)=3f(2) = 3, f(3)=4f(3) = 4, f(4)=f(5)=5f(4) = f(5) = 5, and g:{3,4,5,9}→{7,11,15}g : \{3,4,5,9\} \to \{7,11,15\} with g(3)=g(4)=7g(3) = g(4) = 7, g(5)=g(9)=11g(5) = g(9) = 11. Then (g∘f)(2)=g(3)=7,(g∘f)(3)=g(4)=7,(g∘f)(4)=g(5)=11,(g∘f)(5)=g(5)=11(g \circ f)(2) = g(3) = 7, \quad (g \circ f)(3) = g(4) = 7, \quad (g \circ f)(4) = g(5) = 11, \quad (g \circ f)(5) = g(5) = 11

Order matters: g∘f≠f∘gg \circ f \neq f \circ g in general

For f(x)=cos⁡xf(x) = \cos x and g(x)=3x2g(x) = 3x^2 on R\mathbb{R}: (g∘f)(x)=g(cos⁡x)=3cos⁡2x,(f∘g)(x)=f(3x2)=cos⁡(3x2)(g \circ f)(x) = g(\cos x) = 3\cos^2 x, \qquad (f \circ g)(x) = f(3x^2) = \cos(3x^2) At x=0x = 0:  (g∘f)(0)=3cos⁡20=3\ (g \circ f)(0) = 3\cos^2 0 = 3 while (f∘g)(0)=cos⁡0=1(f \circ g)(0) = \cos 0 = 1. One disagreement is enough: g∘f≠f∘gg \circ f \neq f \circ g. Composition is not commutative — but it is associative: h∘(g∘f)=(h∘g)∘fh \circ (g \circ f) = (h \circ g) \circ f whenever the chains make sense, because both sides send xx to h(g(f(x)))h(g(f(x))).

How composition interacts with one-one and onto

Two facts that exams (especially JEE) probe:

Fact 1. If g∘fg \circ f is one-one, then ff must be one-one (a collision in ff would survive into g∘fg \circ f) — but gg need not be.

Fact 2. If g∘fg \circ f is onto, then gg must be onto (everything in CC is reached through gg) — but ff need not be.

And in the convenient direction: the composite of two one-one functions is one-one; the composite of two onto functions is onto; hence the composite of two bijections is a bijection.

Invertible Functions

Undoing a function

Definition. A function f:X→Yf : X \to Y is invertible if there exists a function g:Y→Xg : Y \to X such that g∘f=IXandf∘g=IYg \circ f = I_X \quad \text{and} \quad f \circ g = I_Y where IXI_X and IYI_Y are the identity functions. The function gg is called the inverse of ff, written f−1f^{-1}.

Both equations matter: gg must undo ff from the left and from the right.

The central theorem

Theorem. ff is invertible if and only if ff is one-one and onto (bijective).

Why: if ff has an inverse, then ff cannot collide (the inverse could not decide where to send the shared image) and cannot miss any yy (the inverse must send every yy somewhere that maps back to it). Conversely a bijection pairs XX and YY perfectly, and "follow the pairing backwards" defines the inverse.

This theorem is a labour-saving device: to prove invertibility you may simply prove one-one and onto — no formula for f−1f^{-1} required. When the formula is required, use the template below.

Computing an inverse (the template)

Step 1 — set y=f(x)y = f(x) and solve for xx in terms of yy.

Step 2 — the solution defines g(y)g(y); state its domain (the co-domain of ff).

Step 3 — verify both compositions: g(f(x))=xg(f(x)) = x and f(g(y))=yf(g(y)) = y.

Worked inverse. f:N→Yf : \mathbb{N} \to Y, f(x)=4x+3f(x) = 4x + 3, where Y={y∈N:y=4x+3 for some x∈N}Y = \{y \in \mathbb{N} : y = 4x + 3 \text{ for some } x \in \mathbb{N}\}.

Step 1: y=4x+3⇒x=y−34y = 4x + 3 \Rightarrow x = \dfrac{y - 3}{4}.

Step 2: define g:Y→Ng : Y \to \mathbb{N} by g(y)=y−34g(y) = \dfrac{y - 3}{4} (a natural number by the definition of YY).

Step 3: g(f(x))=(4x+3)−34=xg(f(x)) = \dfrac{(4x + 3) - 3}{4} = x and f(g(y))=4⋅y−34+3=yf(g(y)) = 4 \cdot \dfrac{y - 3}{4} + 3 = y. Both identities hold, so ff is invertible with f−1(y)=y−34f^{-1}(y) = \dfrac{y - 3}{4}. ■\blacksquare

Note how the co-domain was chosen to be exactly the range — that choice is what made ff onto and hence invertible.

Properties worth memorising

(f−1)−1=f,(g∘f)−1=f−1∘g−1  (socks-shoes rule: undo in reverse order)\big(f^{-1}\big)^{-1} = f, \qquad (g \circ f)^{-1} = f^{-1} \circ g^{-1} \ \ (\text{socks-shoes rule: undo in reverse order})

A function can even be its own inverse (a self-inverse function): f(x)=4x+36x−4f(x) = \dfrac{4x + 3}{6x - 4}, x≠23x \neq \frac{2}{3}, satisfies (f∘f)(x)=x(f \circ f)(x) = x, so f−1=ff^{-1} = f. Other self-inverse examples: f(x)=−xf(x) = -x,  f(x)=1x\ f(x) = \frac{1}{x},  f(x)=a−x\ f(x) = a - x.

Common mistakes to avoid

Mistake 1 — f−1(x)f^{-1}(x) vs 1f(x)\frac{1}{f(x)}. The inverse function is not the reciprocal. f(x)=2xf(x) = 2x has f−1(x)=x2f^{-1}(x) = \frac{x}{2}, not 12x\frac{1}{2x}.

Mistake 2 — inverting a non-bijection. f(x)=x2f(x) = x^2 on R\mathbb{R} has no inverse; only after restricting to [0,∞)[0, \infty) (making it bijective onto [0,∞)[0, \infty)) does x\sqrt{x} become its inverse.

Mistake 3 — checking only one composition. g∘f=IXg \circ f = I_X alone does not prove invertibility in general; the definition demands both g∘f=IXg \circ f = I_X and f∘g=IYf \circ g = I_Y.

Mistake 4 — wrong order in (g∘f)−1(g \circ f)^{-1}. It is f−1∘g−1f^{-1} \circ g^{-1}, not g−1∘f−1g^{-1} \circ f^{-1} — you take off shoes before socks.

Solved Examples

Example 1 — Composing along finite tables

Let f:{2,3,4,5}→{3,4,5,9}f : \{2, 3, 4, 5\} \to \{3, 4, 5, 9\} and g:{3,4,5,9}→{7,11,15}g : \{3, 4, 5, 9\} \to \{7, 11, 15\} be defined by f(2)=3f(2) = 3, f(3)=4f(3) = 4, f(4)=f(5)=5f(4) = f(5) = 5, and g(3)=g(4)=7g(3) = g(4) = 7, g(5)=g(9)=11g(5) = g(9) = 11. Find g∘fg \circ f.

Step 1 — push each element through both tables: (g∘f)(2)=g(f(2))=g(3)=7(g \circ f)(2) = g(f(2)) = g(3) = 7 (g∘f)(3)=g(f(3))=g(4)=7(g \circ f)(3) = g(f(3)) = g(4) = 7 (g∘f)(4)=g(f(4))=g(5)=11(g \circ f)(4) = g(f(4)) = g(5) = 11 (g∘f)(5)=g(f(5))=g(5)=11(g \circ f)(5) = g(f(5)) = g(5) = 11

Answer: g∘fg \circ f sends 2↦72 \mapsto 7, 3↦73 \mapsto 7, 4↦114 \mapsto 11, 5↦115 \mapsto 11. (Note 1515 in the final co-domain is never reached — composition can lose surjectivity.)

Example 2 — Order matters

Find g∘fg \circ f and f∘gf \circ g for f(x)=cos⁡xf(x) = \cos x and g(x)=3x2g(x) = 3x^2 on R\mathbb{R}, and show g∘f≠f∘gg \circ f \neq f \circ g.

Step 1 — compose both ways: (g∘f)(x)=g(cos⁡x)=3cos⁡2x,(f∘g)(x)=f(3x2)=cos⁡(3x2)(g \circ f)(x) = g(\cos x) = 3\cos^2 x, \qquad (f \circ g)(x) = f(3x^2) = \cos(3x^2)

Step 2 — find one point of disagreement: at x=0x = 0,  3cos⁡20=3\ 3\cos^2 0 = 3 but cos⁡0=1\cos 0 = 1.

Answer: g∘f≠f∘gg \circ f \neq f \circ g — composition is not commutative, and a single differing value proves it.

Example 3 — A composition that simplifies

If f:R→Rf : \mathbb{R} \to \mathbb{R} is f(x)=8x3f(x) = 8x^3 and g:R→Rg : \mathbb{R} \to \mathbb{R} is g(x)=x1/3g(x) = x^{1/3}, find g∘fg \circ f and f∘gf \circ g.

Step 1 — g∘fg \circ f: (g∘f)(x)=g(8x3)=(8x3)1/3=2x(g \circ f)(x) = g(8x^3) = (8x^3)^{1/3} = 2x

Step 2 — f∘gf \circ g: (f∘g)(x)=f(x1/3)=8(x1/3)3=8x(f \circ g)(x) = f(x^{1/3}) = 8\big(x^{1/3}\big)^3 = 8x

Answer: (g∘f)(x)=2x(g \circ f)(x) = 2x and (f∘g)(x)=8x(f \circ g)(x) = 8x — both linear, but different: yet another reminder that the order of composition matters.

Example 4 — Proving invertibility and finding the inverse

Let f:N→Yf : \mathbb{N} \to Y, f(x)=4x+3f(x) = 4x + 3, where Y={y∈N:y=4x+3Y = \{y \in \mathbb{N} : y = 4x + 3 for some x∈N}x \in \mathbb{N}\}. Show that ff is invertible and find its inverse.

Step 1 — solve y=f(x)y = f(x) for xx: y=4x+3y = 4x + 3 gives x=y−34x = \dfrac{y - 3}{4}, a natural number for every y∈Yy \in Y by the very definition of YY.

Step 2 — define the candidate inverse: g:Y→Ng : Y \to \mathbb{N},  g(y)=y−34\ g(y) = \dfrac{y - 3}{4}.

Step 3 — verify both compositions: g(f(x))=(4x+3)−34=x,f(g(y))=4(y−34)+3=yg(f(x)) = \frac{(4x + 3) - 3}{4} = x, \qquad f(g(y)) = 4\left(\frac{y - 3}{4}\right) + 3 = y

Answer: g∘f=INg \circ f = I_{\mathbb{N}} and f∘g=IYf \circ g = I_Y, so ff is invertible with f−1(y)=y−34f^{-1}(y) = \dfrac{y - 3}{4}.

Example 5 — Another linear inverse

Let f:R→Rf : \mathbb{R} \to \mathbb{R} be f(x)=10x+7f(x) = 10x + 7. Find the function g:R→Rg : \mathbb{R} \to \mathbb{R} such that g∘f=f∘g=IRg \circ f = f \circ g = I_{\mathbb{R}}.

Step 1 — solve: y=10x+7⇒x=y−710y = 10x + 7 \Rightarrow x = \dfrac{y - 7}{10}, so define g(y)=y−710g(y) = \dfrac{y - 7}{10}.

Step 2 — verify: g(f(x))=(10x+7)−710=x,f(g(y))=10⋅y−710+7=yg(f(x)) = \frac{(10x + 7) - 7}{10} = x, \qquad f(g(y)) = 10 \cdot \frac{y - 7}{10} + 7 = y

Answer: g(y)=y−710g(y) = \dfrac{y - 7}{10} — i.e. f−1f^{-1} reverses "multiply by 10, add 7" as "subtract 7, divide by 10", undoing the steps in reverse order.

Example 6 — A self-inverse function

Show that f(x)=4x+36x−4f(x) = \dfrac{4x + 3}{6x - 4}, defined for x≠23x \neq \frac{2}{3}, satisfies (f∘f)(x)=x(f \circ f)(x) = x. What is f−1f^{-1}?

Step 1 — compute f(f(x))f(f(x)) over a common denominator: f(f(x))=4⋅4x+36x−4+36⋅4x+36x−4−4=16x+12+18x−126x−424x+18−24x+166x−4f(f(x)) = \frac{4 \cdot \frac{4x+3}{6x-4} + 3}{6 \cdot \frac{4x+3}{6x-4} - 4} = \frac{\frac{16x + 12 + 18x - 12}{6x-4}}{\frac{24x + 18 - 24x + 16}{6x-4}}

Step 2 — simplify: the (6x−4)(6x - 4)'s cancel, leaving f(f(x))=34x34=xf(f(x)) = \frac{34x}{34} = x

Answer: f∘ff \circ f is the identity, so ff is invertible and f−1=ff^{-1} = f — a self-inverse function. Applying it twice always returns the starting value.

Example 7 — Using the bijection theorem instead of a formula

Show that the parity-swap function f:N→Nf : \mathbb{N} \to \mathbb{N}, f(x)=x+1f(x) = x + 1 for odd xx and f(x)=x−1f(x) = x - 1 for even xx, is invertible, and find f−1f^{-1}.

Step 1 — ff is bijective (proved in the previous section: it pairs 1↔21 \leftrightarrow 2, 3↔4,…3 \leftrightarrow 4, \ldots), so by the theorem it is invertible.

Step 2 — find the inverse by undoing the pairing: the inverse must send 2↦1,1↦2,4↦3,3↦4,…2 \mapsto 1, 1 \mapsto 2, 4 \mapsto 3, 3 \mapsto 4, \ldots — which is exactly what ff itself does.

Answer: f−1=ff^{-1} = f: swapping each odd number with its even successor is its own undo. (Verify: f(f(x))=xf(f(x)) = x — an odd xx goes to x+1x + 1, even, which returns to xx.)