Functions are rules that take a value as input and give corresponding output value. The algebra of functions define sum, difference, product and quotient of two functions. Composition of functions is another way of combining two functions, using which the output of a function is inputted into another function.

Function composition is a powerful algebraic tool that allows treatment of a variable over a chain of function rules. The composition f o g, read as "f of g" is got by inputting g(x) into f.

## Define Composition of Functions

Given two functions f and g, the composition of functions f o g is defined by
(f o g)(x) = f(g(x)

The domain is fog is the set of all x in the domain of g such that g(x) is in the domain of f.
In a similar manner (g o f)(x) = g(f(x)) is defined for all x in the domain of f such that f(x) is in the domain of g.

Example:
Suppose f(x) = 2x + 3  and  g(x) = $\frac{x}{2}$

f o g = f(g(x)) = f($\frac{x}{2}$) = 2 $\times$ $\frac{x}{2}$ + 3  = x + 3

g o f = g(f(x)) = g(2x + 3) = $\frac{2x + 3}{2}$ = x + $\frac{3}{2}$

In general (f o g)(x) $\neq$ (g o f)(x).

## Composition of Functions Domain

The composition of two functions may or may not exist. The composition f o g can be defined only when the range of g shares common elements with the domain of f.

In other words, the domain of f o g is a subset of the domain of g such that g(x) is a subset of f(x).

Example:
Suppose f(x) = $\sqrt{x+4}$ and g(x) = 2x - 3

Step 1: Here the domain of g(x) is all real numbers and domain of f(x) is [-4, ∞).

Consider the composition f o g.
f o g = f(g(x)) = f(2x -3) = $\sqrt{2x-3+4}$ = $\sqrt{2x+1}$

The domain of f o g is given by 2x + 1 ≥ 0 of x ≥ -0.5

Thus the domain of the composition is [-0.5, ∞)

Step 2: Consider the composition g o f

g o f = g(f(x)) = g($\sqrt{x+4}$) = 2($\sqrt{x+4}$) - 3.

Since the range of g(x) is a subset of domain of f, the domain of the composition g o f is same as that of f(x).

Domain of g o f is [-4, ∞).

Step 3: Suppose we have another function defined as h(x) = - x2 - 5. The maximum value of this function is -5 and hence the range of the function (-∞, -5] . These values are not found in the domain of f.

Hence the composition f(h(x)) is not possible and we say f o h does not exist.

When we try to find the function algebraically,

f o h = f(h(x)) = f( -x2 -5) = $\sqrt{-x^{2}-5+4}$ = $\sqrt{-x^{2}-1}$

You may note here the expression under the radical is always negative and thus the function cannot be defined for any value of x.

Thus the domain of the composition can be determined easily by checking the expression defining the composition.

## Composition of Inverse Functions

Suppose the functions f and g are inverses of each other, that is f-1 (x) = g(x) and g-1 (x) = f(x).
What will be the result of such compositions?
The composition of two inverse functions result in the identity function I(x) = x.
That means (f o f-1)(x) = x = (f-1 o f)(x)

Example:
Let us consider the function f(x) = 2x - 6 and its inverse f(x) = $\frac{x+6}{2}$

(f o f-1)(x) = f(f-1(x)) = 2(f o f-1)(x) - 6 = x + 6 - 6 = 0

(f-1 o f)(x) = f-1(f(x)) = $\frac{2x-6+6}{2}$ = $\frac{2x}{2}$ = x

This property can be used as a test whether two functions are inverses of each other.
Two functions f and g are inverse functions if and only if both of their compositions are the identity function.
that is (f o g)(x) = x = (g o f)(x).

## Composition of Functions Examples

### Solved Examples

Question 1: Given that f(x) = x2 + x - 2   and g(x) = x + 5
Find the compositions f o g and g o f and determine the domain of fog.
Solution:

f o g = f(g(x)) = f( x + 5) = (x + 5)2 + (x + 5) - 2 = x2 + 10x + 25 + x + 5 - 2 = x2 + 11x + 28.

f o g is a quadratic function with domain as set of all real numbers and the range of g(x) is also all real.
Hence the domain of f o g is all real numbers.

Question 2: Let f(x) = 3x + 1 and g(x) = 2x2.  Evaluate the following:   f(g(0)), g(f(-$\frac{1}{3}$)), f(g(2)) and g(f(-1)).
Solution:

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

g(f(-$\frac{1}{3}$)) = g(3(-$\frac{1}{3}$) + 1) = g(-1 + 1) = g(0) = 2(0)2 = 0

f(g(2)) = f(2.22) = f(8) = 3(8) + 1 = 25

g(f(-1)) = g(3(-1) + 1) = g(- 3 + 1) = g(- 2) = 2(- 2)2 = 8

Question 3: Determine whether f(x) = $\frac{1}{2}$x - 4 and g(x) = 2x + 8 are inverse functions.
Let us find the compositions f o g and g o f.
Solution:

(f o g)(x) = f(g(x)) = $\frac{1}{2}$ (2x + 8) - 4 = x + 4 - 4 = x

(g o f)(x) = g(f(x)) = 2($\frac{1}{2}$x - 4) + 8 = x - 8 + 8 = x

=> (f o g)(x) = x = (g o f)(x)

As both the compositions are identity functions f and g are inverses of each other.