The composition of two functions f and g is defined by (f ° g)(x) = f(g(x)).

Let f(x) = x2 - x + 1, and g(x) = 3x - 2. Then:

(f ° g)(5) = f(g(5)) = f(13) = 157.
(g ° f)(5) = g(f(5)) = g(21) = 61.

Do not confuse the composition (f ° g) with the product (f x g). The composition (f ° g)(x) means "evaluate g at x, then evaluate f at the result g(x)". The product (f x g)(x) means "evaluate f and g at x and multiply the results".

Composition is not commutative. In other words, f ° g is generally not equal to g ° f. (See the example above.)

While (f ° g)(x) can be evaluated at any x by evaluating g at x, then evaluating f at the result, we often wish to simplify the formula for the composition. Using the same functions as in the last example, f(x) = x2 - x + 1, and g(x) = 3x - 2, we get:

 (f ° g)(x) = f(3x - 2) = (3x - 2)2 - (3x - 2) + 1 = (9x2 -12x + 4)-(3x-2)+1 = 9x2 - 15x + 7.
 (g ° f)(x) = g(x2 - x + 1) = 3(x2 - x + 1) -2 = 3x2 - 3x + 1.

 Using these formulas, we get the same results that we got in the previous example:

(f ° g)(5) = (9 x 25) - (15 x 5) + 7 =157.
(g ° f)(5) = (3 x 25) - (3 x 5) + 1 = 61.

Click the PRACTICE button to practice composition of functions
Click the DEMO button to geometrically explore the composition of two functions.