← mapSet Theory

Composition & Inverse Functions

⚗ Dr. Möbius, from the lab

Functions are machines. So what happens when you bolt two machines together — output of one feeding into the input of the next? You get a pipeline, and the math of pipelines hides two bombs: an ordering quirk that screws up everyone without exception, and the first sighting of noncommutativity — the fact that "ff then gg" usually differs from "gg then ff". Matrices will weaponize this later. And then comes the question I love: when can a machine be run backwards? Answer: only when it's a bijection, and the proof is genuinely satisfying. Strap in.

THE BIG IDEA

Composition g∘f runs f then g, is associative but rarely commutative, and a function has an inverse exactly when it is a bijection.

Composition: machines in a pipeline

Take f:ABf : A \to B and g:BCg : B \to C. The output of ff is a legal input for gg, so chain them: feed xx into ff, then feed f(x)f(x) into gg. The result is the composition gfg \circ f, defined by

(gf)(x)=g(f(x)).(g \circ f)(x) = g(f(x)).

It's a single function ACA \to C — the whole pipeline collapsed into one machine.

Now the bomb everyone steps on — and I mean everyone, without exception, at least once: gfg \circ f means "ff first, then gg", even though gg is written first. The notation reads right-to-left because ff is the inner function — it touches xx first. Read gfg \circ f as "gg after ff". Get this backwards and every composition problem you ever do comes out wrong. The inner function fires first; the notation is deliberately counterintuitive, so train the damn reflex now, before it bites you in the eigenvalue lesson.

For the chain to be legal, the codomain of ff must match (or sit inside) the domain of gg — the pipe fittings have to connect. Output type of stage one = input type of stage two.

Associative yes, commutative almost never

Composition has one nice algebraic law and one infamous missing one.

Associative: stacking three machines, it doesn't matter how you group the bolting: (hg)f=h(gf).(h \circ g) \circ f = h \circ (g \circ f). Both sides are just "ff, then gg, then hh" — the pipeline is the pipeline regardless of which joint you mentally assemble first. So we drop parentheses and write hgfh \circ g \circ f.

Commutative? Almost never. In general gffg.g \circ f \ne f \circ g. Order matters, and this is your first sighting of noncommutativity — a property that will dominate the matrix stratum like a goddamn tyrant. Concrete proof: let f(x)=x+1f(x) = x + 1 and g(x)=x2g(x) = x^2 on R\mathbb{R}. Then (gf)(x)=g(x+1)=(x+1)2,(fg)(x)=f(x2)=x2+1.(g \circ f)(x) = g(x+1) = (x+1)^2, \qquad (f \circ g)(x) = f(x^2) = x^2 + 1. At x=1x = 1: (gf)(1)=4(g \circ f)(1) = 4 but (fg)(1)=2(f \circ g)(1) = 2. Different functions. "Square then add one" is not "add one then square" — obviously, once you see it, and yet people assume composition commutes constantly. It does not. Burn that in: the order of operations is part of the operation.

Composition preserves injectivity and surjectivity — with proof

Good news: the nice properties survive the pipeline. Let f:ABf : A \to B and g:BCg : B \to C.

Theorem (injectivity). If ff and gg are both injective, so is gfg \circ f. Proof. Assume (gf)(a)=(gf)(b)(g \circ f)(a) = (g \circ f)(b), i.e. g(f(a))=g(f(b))g(f(a)) = g(f(b)). Since gg is injective, equal gg-outputs force equal inputs: f(a)=f(b)f(a) = f(b). Since ff is injective, this forces a=ba = b. So gfg \circ f is injective. \blacksquare (Peel the machines off one at a time, outermost first.)

Theorem (surjectivity). If ff and gg are both surjective, so is gfg \circ f. Proof. Take an arbitrary cCc \in C. Since gg is surjective, there's a bBb \in B with g(b)=cg(b) = c. Since ff is surjective, there's an aAa \in A with f(a)=bf(a) = b. Then (gf)(a)=g(f(a))=g(b)=c(g \circ f)(a) = g(f(a)) = g(b) = c. So every cc has a preimage — surjective. \blacksquare

Corollary. The composition of two bijections is a bijection. (Both halves survive.) This is exactly why "same size" will be an equivalence relation in the cardinality lesson — bijections compose.

The identity function: the "1" of composition

Every set AA has a do-nothing machine — beautiful in its absolute boredom — the identity function idA:AA\operatorname{id}_A : A \to A defined by idA(x)=x\operatorname{id}_A(x) = x — input comes out untouched. It's the multiplicative-11 of the composition world: bolting it on changes nothing. fidA=f,idBf=ffor f:AB.f \circ \operatorname{id}_A = f, \qquad \operatorname{id}_B \circ f = f \quad \text{for } f : A \to B. Keep id\operatorname{id} in mind — it's the yardstick that defines what an inverse is, and it will show up in proofs constantly from here to the end of this course.

Inverses: running the machine backwards

Now the climax. A function f:ABf : A \to B has an inverse f1:BAf^{-1} : B \to A if running ff then f1f^{-1} (and vice versa) gets you back where you started:

f1f=idAandff1=idB.f^{-1} \circ f = \operatorname{id}_A \qquad \text{and} \qquad f \circ f^{-1} = \operatorname{id}_B.

f1f^{-1} undoes ff: whatever ff did to xx, f1f^{-1} reverses it. And here is the theorem that ties the whole stratum together:

ff has an inverse if and only if ff is a bijection.

Let me show you why, because it's the payoff of the last two lessons. For f1f^{-1} to be a well-defined function that undoes ff:

  • ff must be injective, or undoing is ambiguous. If f(a)=f(a)=bf(a) = f(a') = b with aaa \ne a', then f1(b)f^{-1}(b) wouldn't know whether to return aa or aa' — single-valuedness of f1f^{-1} dies. No collisions allowed.
  • ff must be surjective, or f1f^{-1} isn't total. If some bBb \in B is never an output of ff, then f1(b)f^{-1}(b) has nothing to return — undefined. No orphans allowed.

No collisions and no orphans is exactly bijective. So bijection     \iff invertible. The injective/surjective/bijective machinery from last lesson wasn't bookkeeping — it was the precise diagnosis of which machines can be run backwards, and you've just collected the payoff. This is what rigor buys you: surprising connections that aren't surprising at all once you've defined everything correctly.

Finding f1f^{-1} in practice: solve y=f(x)y = f(x) for xx. For f(x)=3x+1f(x) = 3x + 1 (which we proved bijective): y=3x+1    x=y13y = 3x + 1 \implies x = \tfrac{y - 1}{3}, so f1(y)=y13f^{-1}(y) = \tfrac{y-1}{3}. (That's the very expression the surjectivity proof coughed up last lesson — no accident.) Check it: f1(f(x))=(3x+1)13=3x3=x=id(x)f^{-1}(f(x)) = \tfrac{(3x+1) - 1}{3} = \tfrac{3x}{3} = x = \operatorname{id}(x). ✓ The machine, run backwards, lands you home. And inverses of bijections are themselves bijections — file that away, it makes "same cardinality" symmetric in the boss fight ahead.

🔬 SPECIMENS (worked examples)

Worked example 1 — compose two machines and watch order bite hard

Let f(x)=2xf(x) = 2x and g(x)=x+3g(x) = x + 3 on R\mathbb{R}. Compute (gf)(x)(g \circ f)(x) and (fg)(x)(f \circ g)(x), and evaluate both at x=5x = 5.

(gf)(x)(g \circ f)(x) means ff first, then gg: (gf)(x)=g(f(x))=g(2x)=2x+3.(g \circ f)(x) = g(f(x)) = g(2x) = 2x + 3.

(fg)(x)(f \circ g)(x) means gg first, then ff: (fg)(x)=f(g(x))=f(x+3)=2(x+3)=2x+6.(f \circ g)(x) = f(g(x)) = f(x + 3) = 2(x + 3) = 2x + 6.

These are different functions2x+32x + 3 versus 2x+62x + 6 — so composition does not commute here. Evaluate at x=5x = 5: (gf)(5)=2(5)+3=13,(fg)(5)=2(5)+6=16.(g \circ f)(5) = 2(5) + 3 = 13, \qquad (f \circ g)(5) = 2(5) + 6 = 16.

131613 \ne 16. "Double then add 33" lands somewhere different from "add 33 then double", because in the second pipeline the 33 also gets doubled. Order is part of the operation.

Worked example 2 — find and verify an inverse

Let f:RRf : \mathbb{R} \to \mathbb{R}, f(x)=x42f(x) = \dfrac{x - 4}{2}. Find f1f^{-1} and verify f1f=idf^{-1} \circ f = \operatorname{id}.

First, ff is a nonzero-slope line, hence bijective, so an inverse exists. To find it, set y=f(x)y = f(x) and solve for xx: y=x42    2y=x4    x=2y+4.y = \frac{x - 4}{2} \implies 2y = x - 4 \implies x = 2y + 4.

So f1(y)=2y+4f^{-1}(y) = 2y + 4, i.e. f1(x)=2x+4f^{-1}(x) = 2x + 4.

Verify f1f=idf^{-1} \circ f = \operatorname{id}: compose them and hope to land on xx. f1(f(x))=f1 ⁣(x42)=2x42+4=(x4)+4=x.f^{-1}(f(x)) = f^{-1}\!\left(\frac{x-4}{2}\right) = 2 \cdot \frac{x-4}{2} + 4 = (x - 4) + 4 = x. \quad \checkmark

And the other way, f(f1(x))=(2x+4)42=2x2=xf(f^{-1}(x)) = \dfrac{(2x+4) - 4}{2} = \dfrac{2x}{2} = x. ✓ Both compositions give the identity, so f1f^{-1} genuinely undoes ff. Notice the inverse reverses the operations in reverse order: ff does "subtract 44, then divide by 22"; f1f^{-1} does "multiply by 22, then add 44" — last operation undone first, like taking off shoes before socks.

Worked example 3 — no inverse, and how to surgically fix that (the theorem is merciless)

Explain why f:RRf : \mathbb{R} \to \mathbb{R}, f(x)=x2f(x) = x^2, has no inverse. Then restrict domain and codomain to make it invertible, and give the inverse.

An inverse exists iff ff is a bijection. Check the two failures (from the injective/surjective lesson).

Injectivity fails: f(3)=f(3)=9f(3) = f(-3) = 9. If we tried to define f1(9)f^{-1}(9), it wouldn't know whether to return 33 or 3-3 — the inverse can't be single-valued. Collision blocks undoing.

Surjectivity fails: no real squares to 1-1, so 1R-1 \in \mathbb{R} has no preimage; f1(1)f^{-1}(-1) would have nothing to return — not total. Orphan blocks undoing.

Both bijection conditions fail, so on RR\mathbb{R} \to \mathbb{R} there is no inverse.

The fix: restrict to make it a bijection, exactly as we did last lesson. Take f:[0,)[0,),f(x)=x2.f : [0, \infty) \to [0, \infty), \quad f(x) = x^2. Restricting the domain to [0,)[0,\infty) kills the ±\pm collision (injective); restricting the codomain to [0,)[0,\infty) kills the negative orphans (surjective). Now it's bijective, so an inverse exists. Solve y=x2y = x^2 with x0x \ge 0: x=y(positive root, since x0).x = \sqrt{y} \quad (\text{positive root, since } x \ge 0). So f1(y)=yf^{-1}(y) = \sqrt{y}. Check: f1(f(x))=x2=x=xf^{-1}(f(x)) = \sqrt{x^2} = |x| = x for x0x \ge 0. ✓ The square root is the inverse of squaring only after you've surgically restricted squaring into a bijection. No bijection, no inverse — the theorem is merciless.

☠ KNOWN HAZARDS

  • Reading gfg \circ f left-to-right. It means ff first, then gg. The notation is deliberately backwards — the inner function fires first. Reverse it and every answer flips. I am telling you this for the last time before the matrix stratum, where getting it wrong will hurt.

  • Assuming gf=fgg \circ f = f \circ g. Composition rarely commutes. "Square then add" \ne "add then square". Always respect the order. Writing fgf \circ g when you mean gfg \circ f is an error, not a rounding difference.

  • Confusing f1f^{-1} with 1/f1/f. The inverse function f1f^{-1} undoes ff; it is NOT the reciprocal 1f(x)\tfrac{1}{f(x)}. For f(x)=3xf(x) = 3x, f1(x)=x/3f^{-1}(x) = x/3, not 13x\tfrac{1}{3x}. This confusion is so common it has its own shame category.

  • Inverting a non-bijection. A function with collisions or orphans has no inverse. You must first restrict domain/codomain to make it a bijection (e.g. x2x^2 needs [0,)[0,\infty)) before f1f^{-1} exists. No bijection, no inverse — the theorem is merciless and it will not make exceptions for you.

TL;DR

  • (gf)(x)=g(f(x))(g \circ f)(x) = g(f(x)) — read right-to-left: ff fires first, then gg. The inner function touches xx first.

  • Composition is associative (hgfh\circ g\circ f unambiguous) but almost never commutative: gffgg \circ f \ne f \circ g in general — the first noncommutativity, weaponized later by matrices.

  • Composition preserves injectivity, surjectivity, and hence bijectivity (proved by peeling machines off / chaining preimages).

  • The identity id(x)=x\operatorname{id}(x) = x is the "11" of composition: fid=idf=ff \circ \operatorname{id} = \operatorname{id} \circ f = f.

  • ff is invertible     \iff ff is a bijection. f1f^{-1} undoes ff (f1f=idf^{-1}\circ f = \operatorname{id}); find it by solving y=f(x)y = f(x) for xx.

unlocks