Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Compose Two Functions

Composing means using the output of one function as the input of another. In (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)) the inner function gg acts first, and its whole formula goes in wherever ff has an xx.

Recognize the task

The question shows a small circle or nested brackets: (f∘g)(x)(f \circ g)(x), (g∘f)(4)(g \circ f)(4), f(g(x))f(g(x)), f(f(x))f(f(x)). Typical tasks: a formula for the composite, its value at one number, or its domain. Test: read the expression from the right. The function written last (closest to xx) acts first.
Composition is defined in the function composition lesson.

Two ways to do it

Formula firstusual
(f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x))
Substitute the whole inner formula into the outer one (composition of functions), then simplify.
Inside out at a pointone value
(f∘g)(a)=f(g(a))(f \circ g)(a) = f\big(g(a)\big)
For one input, compute g(a)g(a) first and then evaluate ff at that number (evaluating at a point).

Steps

StepOn f(x)=x2−4f(x) = x^2 - 4, g(x)=2x+1g(x) = 2x + 1, find (f∘g)(x)(f \circ g)(x)
1Identify the inner function. In f∘gf \circ g the function on the right acts first.inner g(x)=2x+1g(x) = 2x + 1, outer ff
2Substitute the whole inner formula into the outer one. Replace every xx in ff with (2x+1)(2x + 1), keeping the brackets.Substitution ↗f(g(x))=(2x+1)2−4f(g(x)) = (2x + 1)^2 - 4
3Expand and simplify. Expand the brackets only after the substitution.4x2+4x+1−4=4x2+4x−34x^2 + 4x + 1 - 4 = 4x^2 + 4x - 3
4Find the domain. Use the domain of a composition: xx must be in the domain of gg, and g(x)g(x) in the domain of ff.both are polynomials: R\mathbb{R}
5Check at one point. Compare the formula with the inside-out value at an easy input.g(1)=3g(1) = 3, f(3)=5f(3) = 5; 4+4−3=54 + 4 - 3 = 5 ✓

Worked examples

Example 1 · a value at one point

inside out
f(x)=x2+1f(x) = x^2 + 1, g(x)=3x−2g(x) = 3x - 2; find (f∘g)(4)(f \circ g)(4)
g(4)=3(4)−2=10g(4) = 3(4) - 2 = 10
inner function first
(f∘g)(4)=f(10)=101(f \circ g)(4) = f(10) = 101
then the outer one

Example 2 · the other order

formula
f(x)=x2−4f(x) = x^2 - 4, g(x)=2x+1g(x) = 2x + 1; find (g∘f)(x)(g \circ f)(x)
ff acts first now
g(f(x))=2(x2−4)+1g(f(x)) = 2(x^2 - 4) + 1
substitute all of f(x)f(x)
(g∘f)(x)=2x2−7(g \circ f)(x) = 2x^2 - 7
differs from f∘gf \circ g

Example 3 · a composite with a restricted domain

domain
f(x)=xf(x) = \sqrt{x}, g(x)=x−3g(x) = x - 3
(f∘g)(x)=x−3(f \circ g)(x) = \sqrt{x - 3}
substitute
g(x)≥0⇒x≥3g(x) \geq 0 \Rightarrow x \geq 3
ff needs a non-negative input
domain [3,∞)[3, \infty)
Follow an input through both machines in the composition visualizer.

See it happen

Picture two machines in a row. The input enters gg, and whatever comes out is fed straight into ff. Swapping the machines changes what each one receives, which is why f∘gf \circ g and g∘fg \circ f are usually different. An input can be lost at either machine: if gg rejects it, or if gg produces something ff cannot accept. That is where the two domain conditions come from.

Common mistakes

Multiplying instead of composing

✗ (f∘g)(4)=f(4)⋅g(4)=17⋅10=170(f \circ g)(4) = f(4) \cdot g(4) = 17 \cdot 10 = 170
✓ (f∘g)(4)=f(g(4))=f(10)=101(f \circ g)(4) = f(g(4)) = f(10) = 101

Distributing to the first term only

✗ 2(x2−4)+1=2x2−4+1=2x2−32(x^2 - 4) + 1 = 2x^2 - 4 + 1 = 2x^2 - 3
✓ 2(x2−4)+1=2x2−8+1=2x2−72(x^2 - 4) + 1 = 2x^2 - 8 + 1 = 2x^2 - 7

Reading the domain from the simplified formula

✗ f(x)=x2f(x) = x^2, g(x)=xg(x) = \sqrt{x}: f(g(x))=xf(g(x)) = x, domain R\mathbb{R}
✓ g(−4)g(-4) does not exist, so the domain is [0,∞)[0, \infty)

Composing in the wrong order

✗ (f∘g)(x)=g(f(x))(f \circ g)(x) = g(f(x))
✓ (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)): the right-hand function acts first
See non-commutativity in the lesson.