The **chain rule** is a differentiation rule used for finding the derivative of a **composite function.** A composite function is a function that can be written as the composition of two or more functions, e.g., $f(g(x))$. The chain rule allows us to break down the derivative of the composite function into the derivatives of its **inner and outer functions.**

## The Chain Rule Formula

If $h(x)=f(g(x))$, where $f$ and $g$ are both differentiable functions, then the derivative of $h$ is given by:

$${h}^{\prime}(x)={f}^{\prime}(g(x))\xb7{g}^{\prime}(x)$$In other words, to find the derivative of $h(x)$:

- First, take the derivative of the outer function $f$, treating the inner function $g(x)$ as the input variable.
- Next, multiply by the derivative of the inner function $g$.

This can be intuitively understood as:

- ${f}^{\prime}(g(x))$ represents the rate of change of $f$ with respect to $g(x)$
- ${g}^{\prime}(x)$ represents the rate of change of $g(x)$ with respect to $x$
- Multiplying these together gives the overall rate of change of $f(g(x))$ with respect to $x$, via the chain rule.

## What is a Composite Function?

A composite function is a function that is formed by **combining** two or more functions, where the output of one function becomes the input of the next function. If $f$ and $g$ are two functions, then the composite function $h(x)=f(g(x))$ is the function obtained by applying $f$ to the output of $g$.

In the notation $f(g(x))$:

- $g$ is called the
**inner function** - $f$ is called the
**outer function**

The composite function $h(x)$ can be evaluated by first evaluating the inner function $g(x)$, and then evaluating the outer function $f$ at the value of $g(x)$.

### Example

Let $f(x)={x}^{2}$ and $g(x)=3x+1$. Then the composite function $h(x)=f(g(x))$ is:

$h(x)=f(g(x))=(3x+1{)}^{2}=9{x}^{2}+6x+1$

Here, we first evaluate $g(x)=3x+1$, and then square the result to obtain $h(x)$.

Composite functions can be more complex, involving multiple inner and outer functions. For example, $\mathrm{sin}(\mathrm{ln}({x}^{2}+1))$ is a composite function where:

- The inner function is ${x}^{2}+1$
- The middle function is $\mathrm{ln}(x)$
- The outer function is $\mathrm{sin}(x)$

Here, we would have to apply the chain rule several times to calculate the derivative.

## Steps to Apply the Chain Rule

**Identify the composite function:**Ensure that the given function is a composite function, meaning one function is nested inside another.**Identify the inner and outer functions:**Determine which function is the inner function (the one being evaluated first) and which is the outer function (the one that takes the result of the inner function as its input).**Find the derivative of the outer function:**Differentiate the outer function, treating the inner function as a variable.**Find the derivative of the inner function:**Differentiate the inner function with respect to its variable.**Multiply the derivatives:**Multiply the results from steps 3 and 4.**Simplify the result:**If necessary, simplify the final expression obtained from step 5.

## When to Use the Chain Rule

The chain rule is used when differentiating a composite function of the form $f(g(x))$. If the composite function can be written as an outer function $f$ applied to an inner function $g$, i.e. $h(x)=f(g(x))$, then the chain rule applies.

Some common examples where the chain rule is applicable include:

- Functions raised to a power, e.g. $({x}^{2}+1{)}^{3}$
- Trigonometric functions with a non-trivial input, e.g. $\mathrm{sin}({x}^{3})$, $\mathrm{tan}(\sqrt{x})$
- Exponential or logarithmic functions with a non-trivial input, e.g. ${e}^{\mathrm{cos}(x)}$, $\mathrm{ln}({x}^{2}+1)$

## Examples

Let’s look at a couple examples to solidify our understanding.

### Example 1

Find the derivative of $h(x)=(3{x}^{2}+1{)}^{5}$

We can rewrite $h$ as a composite function: $f(g(x))$ where $f(x)={x}^{5}$ and $g(x)=3{x}^{2}+1$

Applying the chain rule:

${h}^{\prime}(x)={f}^{\prime}(g(x))\xb7{g}^{\prime}(x)$

${f}^{\prime}(x)=5{x}^{4}$, so ${f}^{\prime}(g(x))=5(3{x}^{2}+1{)}^{4}$

${g}^{\prime}(x)=6x$

Therefore, ${h}^{\prime}(x)=5(3{x}^{2}+1{)}^{4}\xb76x=30x(3{x}^{2}+1{)}^{4}$

### Example 2

Find the derivative of $h(x)=\mathrm{sin}(\mathrm{ln}(x))$

Rewriting as a composite function: $f(x)=\mathrm{sin}(x)$, $g(x)=\mathrm{ln}(x)$

Applying the chain rule:

${h}^{\prime}(x)={f}^{\prime}(g(x))\xb7{g}^{\prime}(x)$

${f}^{\prime}(x)=\mathrm{cos}(x)$, so ${f}^{\prime}(g(x))=\mathrm{cos}(\mathrm{ln}(x))$

${g}^{\prime}(x)=\frac{1}{x}$

Therefore, ${h}^{\prime}(x)=\mathrm{cos}(\mathrm{ln}(x))\xb7\frac{1}{x}=\frac{\mathrm{cos}(\mathrm{ln}(x))}{x}$