Learn
Lesson · Sets, Relations, and Functions · Functions

Composition and Inverse Functions

(g ∘ f)(x) = g(f(x)) — right to left. Composition preserves injectivity and surjectivity, and an inverse function exists exactly when f is a bijection.

(g ∘ f)(x) = g(f(x)) apply f FIRST f ∘ g ≠ g ∘ f in general f⁻¹ exists ⟺ f is a bijection f⁻¹ ∘ f = id_A f ∘ f⁻¹ = id_B
Compose right to left

Core ideas

What this lesson establishes

Composition is how functions are built out of simpler ones, and the inverse is the question of whether the building can be undone.

1

Composition reads right to left

g ∘ f applies f first. The notation matches g(f(x)), which is why it looks backwards until you read it as substitution.

2

Composition is associative, not commutative

(h ∘ g) ∘ f = h ∘ (g ∘ f) always. f ∘ g = g ∘ f almost never.

3

An inverse needs a bijection

Not injective means two inputs share an output, so the inverse could not choose. Not surjective means some output has no input, so the inverse would be undefined there.

The material

Composition and inversion

The definitions, what composition preserves, and the inverse theorem.

Definition · Composition

For f : A → B and g : B → C, the composition g ∘ f : A → C is defined by (g ∘ f)(a) = g(f(a)). It requires the codomain of f to be contained in the domain of g.

Order matters twice over. g ∘ f and f ∘ g are different functions when both are defined, and often only one of them is defined at all — the types have to line up.

Theorem · Associativity

(h ∘ g) ∘ f = h ∘ (g ∘ f) whenever the compositions are defined.

Both sides send a to h(g(f(a))). Two functions with the same domain, the same codomain and the same value everywhere are equal.

□

Theorem · Composition preserves the properties

If f and g are both injective, so is g ∘ f. If both are surjective, so is g ∘ f. If both are bijective, so is g ∘ f.

Injective: suppose g(f(x)) = g(f(y)). Injectivity of g gives f(x) = f(y), and injectivity of f gives x = y.

Surjective: take c ∈ C. Surjectivity of g gives b ∈ B with g(b) = c; surjectivity of f gives a ∈ A with f(a) = b. Then (g ∘ f)(a) = c.

□

The converses are weaker and worth knowing. If g ∘ f is injective then f must be injective — but g need not be. If g ∘ f is surjective then g must be surjective — but f need not be. Each is a short argument and each catches a plausible false claim.

Definition · Inverse function

g : B → A is an inverse of f : A → B when g ∘ f = id_A and f ∘ g = id_B. When it exists it is unique and is written f⁻¹.

Theorem · Inverses exist exactly for bijections

f : A → B has an inverse if and only if f is a bijection.

Suppose f is a bijection. For each b ∈ B, surjectivity gives at least one a with f(a) = b and injectivity gives at most one, so exactly one. Defining f⁻¹(b) to be that a is a legitimate function, and it satisfies both identities by construction.

Conversely, suppose g is an inverse. If f(x) = f(y) then applying g gives x = y, so f is injective. And for any b, f(g(b)) = b, so g(b) is a preimage of b and f is surjective.

□

Uniqueness follows quickly: if g and h are both inverses then g = g ∘ id = g ∘ (f ∘ h) = (g ∘ f) ∘ h = id ∘ h = h. The chain uses associativity, which is why associativity was worth stating.

Example · Finding an inverse

f : ℝ → ℝ, f(x) = 3x − 5. Set y = 3x − 5 and solve: x = (y + 5)/3, so f⁻¹(y) = (y + 5)/3. Check: f(f⁻¹(y)) = 3((y+5)/3) − 5 = y. Both directions should be checked, because solving for x proves only one of them.

Theorem · Inverse of a composition

(g ∘ f)⁻¹ = f⁻¹ ∘ g⁻¹ when both inverses exist — the order reverses. Undoing "socks then shoes" is "shoes off, then socks".

Interactive

Injective, surjective, bijective

Built by hand, classified by counting

f : A → BChoose where each element of A is sent
hit oncehit twice or morenever hit

Method

Composing and inverting

Check the types, then work inside out.

1

Check the codomain and domain line up

g ∘ f needs f's outputs to be legal inputs for g. A type mismatch is not a subtlety; the composition does not exist.

2

Evaluate inside out

(g ∘ f)(3) is g(f(3)). Compute f(3) first. Half of all composition errors are order errors.

3

To invert, verify bijectivity first

No bijection, no inverse. Solving y = f(x) for x and finding two solutions or none is the same discovery arrived at slowly.

4

Check both identities

f⁻¹ ∘ f = id and f ∘ f⁻¹ = id. Solving for x naturally establishes one; the other is a separate substitution.

Composition and inverses

Score 0 / 0

Composition is not commutative

f(x) = 2x and g(x) = x + 3, both ℝ → ℝ.

(g ∘ f)(x) = g(f(x)) = g(2x) = 2x + 3 (f ∘ g)(x) = f(g(x)) = f(x + 3) = 2x + 6 At x = 1: g∘f gives 5, f∘g gives 8. Different functions. Inverses: f⁻¹(y) = y/2 g⁻¹(y) = y − 3 (g ∘ f)⁻¹(y) = (y − 3)/2 f⁻¹(g⁻¹(y)) = f⁻¹(y − 3) = (y − 3)/2 agree g⁻¹(f⁻¹(y)) = g⁻¹(y/2) = y/2 − 3 does NOT

The last two lines are the order-reversal law being tested rather than asserted. (g ∘ f)⁻¹ = f⁻¹ ∘ g⁻¹, and composing the inverses in the original order gives a different function entirely.

Common mistakes

1
Composing left to rightg ∘ f applies f first. The notation follows g(f(x)), and reading it the other way produces a different function silently.
2
Writing f⁻¹ for a function that is not a bijectionThe preimage f⁻¹(T) of a set always exists; the inverse function does not. The shared notation is a genuine trap.
3
Checking only one of the two inverse identitiesg ∘ f = id_A alone makes g a left inverse, which is weaker. Both identities are needed for g = f⁻¹.

Check your understanding

✓
Finish when you can invert a composition in the right order.

With f(x) = 3x + 1 and g(x) = x − 4 on ℝ, compute g ∘ f and (g ∘ f)⁻¹ directly, then check the answer equals f⁻¹ ∘ g⁻¹. If the two agree you have the order right.

Note: Bijections from a set to itself are called permutations, and under composition they form a group: associative, with identity, and every element invertible. Combinatorics and Counting counts them — there are n! — and that count is the reason permutations appear everywhere in combinatorics.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.