Theory:

Given two functions \(f(x)\) and \(g(x)\), then the composition \(f \circ g\) is computed as follows:
Working rule:
Step 1: Rewrite the given composition as \((f \circ g)(x)\) \(=\) \(f\left(g(x)\right)\).
 
Step 2: Using the individual functions as a reference, replace the variable \(x\) in the outside function with the inside function.
 
Step 3: Simplify the obtained function.
Example:
If \(f(x) = x -6\) and \(g(x) = x^2\), then find \(f \circ g\).
 
Solution:
 
\((f \circ g)(x)\) \(=\) \(f\left(g(x)\right)\)
 
\(=\) \(f\left(x^2\right)\)
 
\(=\) \(x^2 -6\)
    Important!
  • A function can also be composed with itself. If \(f\) is a function, then its composition with itself is given by \((f \circ f)(x)\) \(=\) \(f\left(f(x)\right)\).
  • The composition of function is not commutative. That is, \(f \circ g\) \(\neq\) \(g \circ f\).
Example:
If \(f(x) = x - 6\) and \(g(x) = x^2\), then check whether the composition of the two functions are commutative.
 
Solution:
 
First, let us find \((f \circ g)\).
 
\((f \circ g)(x)\) \(=\) \(f\left(g(x)\right)\)
 
\(=\) \(f\left(x^2\right)\)
 
\(=\) \(x^2 -6\)
 
Now, let us find \((g \circ f)\).
 
\((g \circ f)(x)\) \(=\) \(g\left(f(x)\right)\)
 
\(=\) \(g\left(x - 6\right)\)
 
\(=\) \(\left(x -6\right)^2\)
 
\(=\) \(x^2 - 12x + 36\)
 
It is observed that \(f \circ g\) \(\neq\) \(g \circ f\).
 
Therefore, the composition of the two functions \(f\) and \(g\) are not commutative.