Functions & Transformations

composition of functions

Composing functions means chaining them: you run an input through one function, then pour its output straight into a second. Like an assembly line, the part that leaves the first station becomes the part that enters the next. The combined two-step process is itself a new function.

We write the composition of f after g as (f ∘ g)(x) = f(g(x)), read “f of g of x.” Work from the inside out: first compute g(x), then feed that result into f. The order matters — you do the inner function first, even though it is written second.

Composition is generally not commutative: f(g(x)) and g(f(x)) usually differ. Putting on socks then shoes is not the same as shoes then socks. One important special case ties back to inverses: composing a function with its inverse, in either order, returns the input unchanged, since each undoes the other.

If f(x) = x + 1 and g(x) = x^2, then (f ∘ g)(3) = f(g(3)) = f(9) = 10, but (g ∘ f)(3) = g(4) = 16.

Order matters in composition.