When we have a function #g(x)#, we don't necessarily have to substitute a variable or a number for #x#. Instead, we can also substitute an expression or a function #h(x)# for #x#.

If we substitute the function #\green{h(x)}# for #x# in the function #\blue{g(x)}#, we get a new function \[f(x)=\blue{g(}\green{h(x)}\blue{)}\] This new function is called the composition of #\blue{g}# and #\green{h}#.

**Example**

#\blue{g(x)}=\blue{\sqrt{x}}# and #\green{h(x)}=\green{x+3}# give:

\[f(x)=\blue{g(}\green{h(x)}\blue{)}=\blue{\sqrt{\green{x+3}}}\]

The compositions #\blue{g(\green{h(x)})}# and #\green{h( \blue{g(x)})}# are generally not equal to each other. We can, for example, choose #\blue{x^2}# and #\green{x+1}#. This gives us:

\[\begin{array}{crl}\blue{g( \green{h(x)})} &=& \blue{(\green{x+1})^2}=x^2+2x+1\\ \green{h(\blue{g(x)})} &=& x^2+1\end{array}\]

This means #\blue{g( \green{h(x)})}# and #\green{h( \blue{g(x)})}# are different functions.

When we write #\blue{g(x)}=\blue{\sqrt{x}}# and #\green{h(x)}=\green{x+3}#, the variable # x # in #\blue{g(x)}# has nothing to do with the variable #x# in #\green{ h(x) }#. The # x # in these functions only has meaning when combined with # \blue{g(x)}= \ldots# or #\green{ h(x) }= \ldots#. We might as well write #\blue{g(h)} = \blue{\sqrt{h}}#. Now # h # is the variable. Regardless of what variable we use for #\green{g(x)}#, the formula #\blue{g(}\green{h(x)}\blue{)}=\blue{\sqrt{\green{x+3}}}# still holds.

Say #\blue{g(h)}=\blue{h^4}# and #\green{h(x)}=\green{x^2-5x}#. Then # f(x)=\blue{g(}\green{h(x)}\blue{)}=\blue{\left(\green{x^2 - 5x} \right)^{4}} #.

The composition looks as follows.

Note that we used the alternative notation as mentioned in the subbox "Notation".

It is important to be able to recognize these composite functions and to be able to split them into easier functions.

\[\begin{array}{llll}f(x)=&\sqrt{x+2}&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(x)}=\blue{\sqrt{x}}\quad\text{and}\quad\green{h(x)}=\green{x+2}\\\\f(x)=&\sin(x^2)&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(x)}=\blue{\sin(x)}\quad\text{and}\quad\green{h(x)}=\green{x^2}\\\\f(x)=&(x^3-4x)^6&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(x)}=\blue{x^6}\quad\text{and}\quad\green{h(x)}=\green{x^3-4x}\end{array}\]

We can prevent confusion between different #x#'s by writing the function #g(x)# as #g(h)#. By doing this, the examples above can be rewritten as:

\[\begin{array}{llll}f(x)=&\sqrt{x+2}&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(h)}=\blue{\sqrt{h}}\quad\text{and}\quad\green{h(x)}=\green{x+2}\\\\f(x)=&\sin(x^2)&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(h)}=\blue{\sin(h)}\quad\text{and}\quad\green{h(x)}=\green{x^2}\\\\f(x)=&(x^3-4x)^6&=\blue{g(}\green{h(x)}\blue{)}\quad\text{gives}\quad\blue{g(h)}=\blue{h^6}\quad\text{and}\quad\green{h(x)}=\green{x^3-4x}\end{array}\]

Recognising these compositions is a matter of practice.

The function \[f(x)=4+\sqrt{x+4}\] is composed of which functions #g# and #h#? That is, for which #g# and #h# does #f(x)=g(h(x))# apply?