Steply

f(x) = x^2 + 1, g(x) = x - 2, find f(g(x)) and g(f(x))

Step by step, with the reason for every step · Composition order · Algebra 2

Step by step

The question

Question: find f(g(x)) and g(f(x)) for f(x) = x² + 1 and g(x) = x − 2.

f(x) = x2 + 1
g(x) = x − 2

1 Find f(g(x))

f(g(x)) is a function inside a function.

Like with brackets, we start inside.

First g(x).

inside first: g(x)

g(x) is x − 2.

So f(g(x)) is f(x − 2).

f(g(x)) = f(x − 2)

Put (x − 2) in place of every x in f.

We keep it in brackets.

= (x − 2)2 + 1

A square means the bracket times itself.

(x − 2)² is x − 2 times x − 2.

( )² = ( )( )

Careful!

We can't just square each part.

x² + 4 is wrong.

The middle part is missing.

Careful: not (x − 2)2 = x² + 4 ✗

So we write the bracket two times.

= (x − 2)(x − 2) + 1

Each part of the first bracket multiplies the whole second bracket.

(a + b)(c + d) = a(c + d) + b(c + d)

The parts of the first bracket are x and −2.

Each one takes the whole second bracket.

= x(x − 2) − 2(x − 2) + 1

What is in front of a bracket multiplies every part inside.

a(b + c) = ab + ac

So we write each part times what is in front.

= x(x) + x(−2) + (−2)(x) + (−2)(−2) + 1
− × − = +

Watch the signs.

x times x is x².

x times (−2) is −2x.

(−2) times x is −2x.

(−2) times (−2) is 4.

= x2 − 2x − 2x + 4 + 1

Terms are the parts between the + and − signs.

Like terms are the same kind: same letters, same powers.

All the x terms go together.

Plain numbers go together.

Each colour is one kind.

like terms = same letters,
same powers

−2x − 2x is −4x.

4 + 1 is 5.

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

So the expression is x² − 4x + 5.

f(g(x)) = x2 − 4x + 5

2 Find g(f(x))

g(f(x)) is a function inside a function.

Like with brackets, we start inside.

First f(x).

f(x) is x² + 1.

So g(f(x)) is g(x² + 1).

g(f(x)) = g(x2 + 1)

Put (x² + 1) in place of every x in g.

We keep it in brackets.

= (x2 + 1) − 2

A bracket with a plus or nothing in front can just be removed.

( ) away

Now we have x² + 1 − 2.

= x2 + 1 − 2

Terms are the parts between the + and − signs.

Like terms are the same kind: same letters, same powers.

Plain numbers go together.

Each colour is one kind.

like terms = same letters,
same powers

1 − 2 is −1.

1 − 2 = −1

So the expression is x² − 1.

g(f(x)) = x2 − 1

3 Compare

x² − 4x + 5 and x² − 1 are not the same.

So the order matters!

x² − 4x + 5 ≠ x² − 1

4 Check

Let's check with a number: x = 1.

g of 1 is −1, then f of −1 is 2.

f(g(1)) = f(−1) = 2

f of 1 is 2, then g of 2 is 0.

Different, as we found.

g(f(1)) = g(2) = 0

And our rules give the same numbers: x² − 4x + 5 gives 2, x² − 1 gives 0.

They are right!

x² − 4x + 5 → 2, x² − 1 → 0

Let's look back.

First: find f(g(x)).

Then: find g(f(x)).

Then: compare.

Last: check.

Answer
x² − 4x + 5 ≠ x² − 1

Your turn

Try this one yourself, then check:

f(x) = x2 + 3, g(x) = 3x − 1, find f(g(x)) and g(f(x))
Show the answer
9x² − 6x + 4 ≠ 3x² + 8

More from Composition order

The whole lesson: Composition order →