Look at the graph: f(g(x)) is navy and g(f(x)) is amber. The two starting functions are drawn thin and dashed.
Type a number in Trace x = to follow one input through both compositions, step by step.
Composition
f after g
(f∘g)(x)=x2+1
g after f
(g∘f)(x)=x2+1
Domain of f ∘ g
[0,∞)
Domain of g ∘ f
R
How it was found
f(x)=x2+1 and g(x)=x.
For f∘g, put g(x) in place of every x in f: f(g(x))=x2+1.
For g∘f, put f(x) in place of every x in g: g(f(x))=x2+1.
The order matters: the two results are usually different functions. A composition is defined only where the inner function is defined and its output is allowed in the outer one.
At x=4: g(4)=2, then f(2)=5; the other way, f(4)=17, then g(17)=4.1231.
Type one function in the f(x) box and another in the g(x) box. The calculator builds both compositions at once:
f∘g, read "f after g": g acts first, then f acts on the result. Its formula is f(g(x)).
g∘f, read "g after f": f acts first, then g. Its formula is g(f(x)).
Each formula is written first as the plain substitution, and then, when that reads better, in a tidied form after an equals sign.
The Trace x = box follows a single number through both compositions. The last line of How it was found shows the intermediate value and the final one for each order, and the two results are marked on the graph.
Reading the answer
DemoThe domain of a composition
Step 0 of 4
There are four boxes:
f after g: the formula of (f∘g)(x)=f(g(x)).
g after f: the formula of (g∘f)(x)=g(f(x)).
Domain of f ∘ g and Domain of g ∘ f: the inputs each composition accepts.
On the graph, f(g(x)) is the navy curve and g(f(x)) is the amber one. The original f and g are thin dashed curves, so you can see what the compositions were built from.
When the traced number is outside a domain, the trace says undefined at the step where it fails. That is the quickest way to see why a number is left out.
What a composition is
To compose two functions is to feed the output of one into the other. The composition f∘g is the function
(f∘g)(x)=f(g(x)).
The function written on the right, next to x, acts first. With f(x)=2x+1 and g(x)=x2: to find (f∘g)(2), first g(2)=4, then f(4)=9.
As a formula, put the whole of g(x) in place of every x in f: f(g(x))=2(x2)+1=2x2+1.
The order matters
Swapping the order usually gives a different function. With the same f(x)=2x+1 and g(x)=x2:
f(g(x))=2x2+1,g(f(x))=(2x+1)2=4x2+4x+1.
At x=2 the first gives 9 and the second gives 25.
Putting on socks and then shoes is not the same as shoes and then socks. In the same way, "square, then double and add one" is not "double and add one, then square".
Some pairs do give the same result in both orders. The most important case: a function and its inverse, where both orders return x.
f(g(x))=2x2+1 (navy) and g(f(x))=(2x+1)2 (amber) are different functions.
The domain of a composition
A number x is in the domain of f∘g when two things hold:
1. x is in the domain of g, so that g(x) exists; 2. g(x) is in the domain of f, so that f can take it.
With f(x)=x and g(x)=x2−4: g accepts everything, but f needs g(x)≥0, that is x2≥4. The domain of f∘g is (−∞,−2]∪[2,∞).
The other order, g(f(x))=(x)2−4, needs x≥0 for the inner root. Its formula simplifies to x−4, but its domain stays [0,∞): the domain is decided before simplifying.
x2−4 exists only where x2−4≥0: left of −2 and right of 2.
Composition with a simple inner or outer function
Many transformations are compositions with a line.
Let g(x)=x−2 and f(x)=x1. Then f(g(x))=x−21: the inner function changes the input, and the graph of f moves 2 to the right. And g(f(x))=x1−2: the outer function changes the output, and the graph moves 2 down.
The same pattern holds in general. A change made inside acts on x and moves the graph sideways; a change made outside acts on the value and moves the graph up or down.
x1 (dashed): changed inside it moves right (navy), changed outside it moves down (amber).
Reading a formula as a composition
Going the other way is just as useful: a complicated formula can be split into an inner and an outer function.
x2+1 is f(g(x)) with inner g(x)=x2+1 and outer f(x)=x. sin(3x) has inner 3x and outer sin. (2x−5)4 has inner 2x−5 and outer x4.
To find the pieces, ask what is done last when you evaluate the formula at a number: that last step is the outer function. This reading is exactly what the chain rule of calculus needs.
Common mistakes
Multiplying instead of composing.(f∘g)(x) is f(g(x)), not f(x)⋅g(x).
Reading the order backwards. In f∘g, the function on the right, g, acts first.
Assuming the order does not matter.f(g(x)) and g(f(x)) are usually different.
Substituting into only one x. Every x in the outer function is replaced: for f(x)=x2+x, f(g(x))=g(x)2+g(x).
Finding the domain from the simplified formula.(x)2 simplifies to x but is defined only for x≥0.