Steply

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

Step by step, with the reason for every step · Composition and inverse functions · Algebra 2

Step by step

The question

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

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

1 Work out the inside

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

Like with brackets, we start inside.

First f(x).

inside first: f(x)

f(x) is x − 1.

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

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

2 Put it in

Put (x − 1) in place of every x in g.

We keep it in brackets.

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

3 Write the square out

A square means the bracket times itself.

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

( )² = ( )( )

Careful!

We can't just square each part.

x² + 1 is wrong.

The middle part is missing.

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

So we write the bracket two times.

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

4 Split the first bracket

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 −1.

Each one takes the whole second bracket.

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

5 Open the brackets

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

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

a(b + c) = ab + ac

So we write each part times what is in front.

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

Watch the signs.

x times x is x².

x times (−1) is −x.

(−1) times x is −x.

(−1) times (−1) is 1.

= x2 − x − x + 1 + x − 1

6 Group like terms

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

We move like terms next to each other.

Each term takes its sign with it.

= x2 − x − x + x + 1 − 1

−x − x + x is −x.

1 − 1 is 0.

−x − x + x = −x
1 − 1 = 0

So the expression is x² − x.

g(f(x)) = x2 − x

7 Check

Let's check.

We pick a number for each letter: x = 2.

We put it into the start.

Start: (2 − 1)2 + (2 − 1) = (1)2 + 1 = 1 + 1
= 2

Now into our answer.

Answer: 22 − 2 = 4 − 2 = 2

Both give 2.

Same value, so x² − x is right!

Both give 2

Let's look back.

First: work out the inside.

Then: put it in.

Then: write the square out.

Then: split the first bracket.

Then: open the brackets.

Then: group like terms.

Last: check.

Answer
g(f(x)) = x2 − x

Your turn

Try this one yourself, then check:

g(x) = x2 − x, f(x) = x + 1, find g(f(x))
Show the answer
g(f(x)) = x2 + x

More from Composition and inverse functions

The whole lesson: Composition and inverse functions →