# Trick to Apply the Chain Rule FAST - Peeling the Onion

In this post, I’m going to teach you how to quickly apply the **chain rule** multiple times using a technique that I like to call **“Peeling the Onion.”** Using this technique, you’ll be able to quickly differentiate complicated functions, like the one below.

Contrary to what the name suggests, the technique of “Peeling the Onion” will not make you cry. Actually, it’s going to do the opposite – you’re going to be able to do these complicated derivatives *without* crying, like you would usually do if you had to write out the chain rule over and over and over again.

Before we get into this technique of “Peeling the Onion”, though, let’s recap what the chain rule is, because “Peeling the Onion” is ultimately just a method to speed up the chain rule.

The chain rule says that if we have some expression, say, $(x^2+1)^{10}$, and we want to differentiate that expression, we can make it simpler by lumping up some of these terms into another variable, say, $u$. The full expression simplifies – it’s just $u^{10}$, and that’s what we want to take the derivative of.

We can do that just like normal using the power rule, but the only catch is that we have to multiply by $\frac{du}{dx}$ afterwards.

But that’s okay, because taking the derivative of $u$ is simpler. The variable $u$ is just $x^2+1$, so we can substitute that back into the expression and simplify.

There we have it, that’s the derivative!

This was a very simple example. If we want to differentiate a more complicated expression, like $\left( \sin(x^2) + 1 \right)^{10}$, then we need to apply the chain rule multiple times. You’ll see how this gets kind of complicated.

We start out the same way by lumping up some terms into $u$, and then it’s just the derivative of $u^{10}$ that we want to find.

Just like last time, we apply the power rule, and the catch is that we have to multiply by $\frac{du}{dx}$. Again, we substitute back in for $u$, but this time we still run into some trouble when we try to differentiate $\sin(x^2)+1$.

We need to apply the chain rule again, lump up that $x^2$ into a single variable, say, $w$, and then the derivative simplifies: it’s just the derivative of $\sin(w)+1$, which we can actually compute. Again, the catch is that we have to multiply by $\frac{dw}{dx}$ afterwards.

Thankfully $w$ is pretty simple, it’s just $x^2$, so we substitute that in and simplify.

There, we’ve got it! But only after a fair amount of blood, sweat, and tears. If you thought this was bad, then imagine how painful it would be to differentiate an expression which required, say, 5 iterations of the chain rule. Here we only had 2 iterations, with $u$ and $w$, so imagine if we had to do this for 3 more iterations – that would be more than twice the amount of work we did here.

This is where the technique of “Peeling the Onion” comes to make life a whole lot easier. Let’s look at that same expression, $\left( \sin(x^2)+1 \right)^{10}$, and this time let’s think of it in terms of layers. The power of $10$ is the outermost layer, and then the next layer (the middle layer) will be the $\sin( \, ) + 1$, and then the third layer (the innermost layer) will be the $x^2$.

When we differentiate this, we start with the outer layer and we differentiate that first.

The rest of the stuff that we fill in, we have to differentiate in the same way.

When we evaluate the derivative, again we’re just looking at the outermost layer. But now we’ve already peeled off one layer, so it’s the $\sin( \, )+1$ that we want to differentiate. It’s just $\cos( \, )$.

We fill in the next layer, $x^2$, and that’s what we have to differentiate. It’s straightforward, just $2x$, and there we go – there’s our answer.

Once you practice this “Peeling the Onion” technique a couple times, you’ll get to the stage where you can do it all in one step: first differentiate the outer layer, and then multiply by the derivative of the next layer, and then multipy by the derivative of the layer after that, and so on. It’s like we’re peeling an onion one layer at a time.

Now that we see how “Peeling the Onion” works on a 3-layer onion, let’s try something crazy. Remember that expression at the very beginning of the post, that had an extroardinarily long derivative? Let’s differentiate it. We’ll do this by “Peeling the Onion,” and it’s just going to take a single step of work.

This expression is a little sneaky, because $\sin^2$ actually means take the square *after* you’ve taken the $\sin$. So the outermost layer is really the squared.

Then after that is the $\sin( \, )$, and after that is the $x + e^\square$, and the next layer is in the power of $e$, the $\tan( \, )$, and the final layer (the innermost layer) is the $3x$ inside of the $\tan( \, )$.

Let’s go ahead and peel this onion! The first step is to peel the outer layer, the squared. For that, we just use the power rule.

We fill in the inner layers and then peel the next layer, which is the $\sin( \, )$.

We continue on filling in and peeling the next layer, which is $x + e^\square$, and because the next layer is entirely in the power of $e$, it’s only the $e$ that gets multiplied by the derivative. So we’re going to multiply by something inside of the parentheses.

The thing that we multiply by, will be the result of peeling the next layer. The next layer is the $\tan( \, )$, and the derivative of $\tan( \, )$ is $\sec^2( \, )$.

Inside of that is the $3x$, which is our final layer, and the derivative of $3x$ is just $3$.

There we go, we’ve got it! That’s the derivative.

## Leave a Comment