Free lesson

Every lesson is free, no account needed. Make a free account to save your progress.

Live classGet practice + mocks
  1. Home
  2. Lesson Library
  3. Function composition
UPCAT Math Review · Functions

Function Composition

One machine feeding another — and the order changes the answer.

Given f(x) = 2x + 3 and g(x) = x² − 1

Find (f ∘ g)(2).

Evaluating first.

f(x) is a rule. Whatever goes in the bracket replaces every x.

f(2) = 2(2) + 3 = 7

a number in

f(a) = 2a + 3

a letter in

f(x + 1) = 2(x + 1) + 3 = 2x + 5

a whole expression in

The bracket is a slot. Keeping the substituted expression in its own brackets protects it from the operations around it.

Composition works inside out.

start

2

g →

then

3

f →

end

9

(f ∘ g)(2) = f(g(2))

g runs first

g(2) = 4 − 1 = 3

the inner one

f(3) = 6 + 3 = 9

feed it into f

The right-hand function goes first

f ∘ g reads “f of g”, so g is the one touching the input. It runs first even though it is written second.

Swap them and the answer changes.

(g ∘ f)(2) = g(f(2))

now f runs first

f(2) = 7

the inner one

g(7) = 49 − 1 = 48

very different from 9

(f ∘ g)(2) = 9  ·  (g ∘ f)(2) = 48

Composition is not commutative. Socks then shoes is not shoes then socks.

Composing as formulas.

(f ∘ g)(x) = f(x² − 1)

put g into f's slot

= 2(x² − 1) + 3

f doubles and adds 3

= 2x² + 1

expand and tidy

(g ∘ f)(x) = (2x + 3)² − 1

the other way

= 4x² + 12x + 8

expand the square first

(2x + 3)² is not 4x² + 9

The middle term is 2(2x)(3) = 12x. Squaring a binomial always leaves three terms.

When do the two orders agree? With f(x) = 5x + m and g(x) = 2x + 3: f(g(x)) = 5(2x + 3) + m = 10x + 15 + m, and g(f(x)) = 2(5x + m) + 3 = 10x + 2m + 3. The x terms already match, so set the constants equal: 15 + m = 2m + 3, m = 12.

A fraction fed into itself.

For f(x) = 1x + 2, simplify f(f(x)).

f(f(x)) = 1 ÷ (1x + 2 + 2)

the whole of f(x) goes in the slot

1x + 2 + 2 = 1 + 2x + 4x + 2 = 2x + 5x + 2

one fraction on the bottom

1 ÷ 2x + 5x + 2 = x + 22x + 5

dividing by a fraction flips it

f(f(x)) is not f(x) × f(x)

1(x + 2)² multiplies f by itself. Check at x = 0: f(0) = ½, then f(½) = 1 ÷ 2½ = 25, and 0 + 20 + 5 = 25 ✓.

Three layers work the same way, one at a time. For f(x) = 3x + 2: f(f(x)) = 3(3x + 2) + 2 = 9x + 8, then f(f(f(x))) = 3(9x + 8) + 2 = 27x + 26.

Backwards: one function and the composite are given.

(a) f(x) = 3x − 2 and f(g(x)) = 12x + 7. Find g(x).  (b) h(x) = x − 3 and g(h(x)) = x² − 6x + 14. Find g(x).

(a) 3·g(x) − 2 = 12x + 7

outer known: treat g(x) as the unknown

3·g(x) = 12x + 9 → g(x) = 4x + 3

solve like any equation

(b) let u = x − 3, so x = u + 3

inner known: name it

g(u) = (u + 3)² − 6(u + 3) + 14

rewrite every x as u + 3

= u² + 6u + 9 − 6u − 18 + 14 = u² + 5

the u terms cancel

g(x) = x² + 5

rename the letter

Always check by composing forward: 3(4x + 3) − 2 = 12x + 7 ✓, and (x − 3)² + 5 = x² − 6x + 14 ✓. In (b), (x − 3)² + 5 is g(x − 3); the answer must be written with plain x.

Variations: a negative in the middle, two answers, an input the outside refuses.

The inner value comes out negative. f(x) = x² − 3x and g(x) = 1 − 2x. Find (f ∘ g)(2).

g(2) = 1 − 4 = −3

inner first

f(−3) = (−3)² − 3(−3)

−3 goes in with its brackets

= 9 + 9 = 18

minus times minus is plus

What is different: the value passed along is negative, so every sign in the outer rule matters.

Dropping the brackets gives 0

Writing −3² − 3 × 3 = −9 − 9, or 9 − 9 = 0, loses a sign. Substitute (−3) with its brackets every time.

Solving a composite equation. f(x) = 2x − 1 and g(x) = x². Solve (g ∘ f)(x) = 25.

(2x − 1)² = 25

f goes inside g

2x − 1 = 5 or 2x − 1 = −5

a square has two roots

x = 3 or x = −2

check: f(−2) = −5, and (−5)² = 25 ✓

What is different: the unknown is the starting input. Taking only +5 loses half the answer.

An input the outside function refuses. f(x) = √x and g(x) = x − 6. Find (f ∘ g)(x), its domain, and (f ∘ g)(2).

(f ∘ g)(x) = √x − 6

g goes inside the root

x − 6 ≥ 0, so x ≥ 6

the root needs a non-negative inside

g(2) = −4, f(−4) = √−4

undefined — 2 is outside the domain

What is different: g accepts 2 happily, but its output must also be a legal input for f.

Composing with the inverse.

A function and its inverse cancel each other out.

f(f⁻¹(x)) = x    and    f⁻¹(f(x)) = x

f(x) = 2x + 3

our function

f⁻¹(x) = (x − 3) ÷ 2

undo, in reverse order

f(f⁻¹(9)) = f(3) = 9

back where we started

That is the standard way to test a claimed inverse — compose the two and see whether x comes back unchanged.

On the exam

Composition comes as a number (often read from a table — look up the inner value, then the outer), as a formula, or backwards with g(x) unknown. Whatever the form, run the right-hand function first, and check a formula answer by plugging in x = 0 or 1 on both sides.

Check: formulas against the numbers.

2x² + 1 at x = 2 8 + 1 = 9 matches ✓
4x² + 12x + 8 at x = 2 16 + 24 + 8 = 48 matches ✓
at x = 0 f(g(0)) = f(−1) = 1 2(0)² + 1 = 1 ✓

Remember the flow

Inner first · Substitute into the slot · Tidy

Order matters — f ∘ g is not g ∘ f.
Now you try

Practice problem

Given f(x) = 3x − 1 and g(x) = x² + 2

Find (f ∘ g)(3).