# Integration by Parts

As mentioned in the introduction to u-substitution, the remaining methods of integration of mostly just variations on substitution, and this next method, called **integration by parts**, is no exception.

Take the following example: $\int x \sin x\ dx$ We'd get frustrated trying to use u-substitution on this one, but we can take a hint from the structure: it's the product of two functions. Go back to what you know about derivatives: in that case we'd use the Product Rule. There's no Product Rule for integration, but it turns out that's still a helpful place to start.

Since $\dfrac{d}{dx} [u(x) \cdot v(x)] = uv' + u'v,$ $\begin{aligned} \int uv' + u'v\ dx &= uv\ \int uv' \ dx + \int u'v \ dx &= uv\ \int u \dfrac{dv}{dx}\ dx + \int v \dfrac{du}{dx}\ dx &= uv\ \int u \ dv + \int v\ du &= uv \end{aligned}$

This all just looks like playing with symbols, but it leads to the formula that we'll use every time we use integration by parts: $\ans{\int u \ dv = uv - \int v \ du}$

The process has some similarities with u-substitution. Basically, we'll write the integral we're given to start with as the left hand side; to do that, we'll define half of it as $u$ and the other half as $dv$. Then we'll need to find $v$ and $du$, and use this formula to rewrite the given integral. After we do, we'll still have the integral $\displaystyle\int v \ du$ to do, but if the process works, it'll be a doable integral.

## First IBP

Evaluate $\displaystyle\int x \sin x\ dx$.

### Solution

Our goal is to match $\displaystyle\int x \sin x\ dx$ to $\displaystyle\int u \ dv$. The differential $dx$ will always be part of $dv$, but the question is, should $u$ be $x$ and $dv$ be $\sin x \ dx$, or should they be swapped?

We'll find a shortcut to answer that question in a moment, but for now, we could just try both options and see which one works.

Try this: let $u=x$ and let $dv = \sin x \ dx$. Then, we need to find $du$ and $v$. We already know how to find $du$ - we'll do it the same way we did it during u-substitution. To find $v$ from $dv$, we'll reverse the process - integrate $dv$.

$\begin{array}{c c} u = x & v = -\cos x\ \downarrow & \uparrow\ du = dx & dv = \sin x \ dx \end{array}$

Now just plug everything into the IBP (integration by parts) formula: $\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int x \sin x \ dx &= (x)(-\cos x) - \int -\cos x \ dx\ &= \ans{-x \cos x + \sin x + C} \end{aligned}$

### Check

Differentiate the answer: $\dfrac{d}{dx}[-x \cos x + \sin x + C] = -\cos x + x \sin x + \cos x = x \sin x$

We happened to pick $u$ and $dv$ in such a way that it worked out, but what if we'd picked them the other way? Let's try that:

$\begin{array}{c c} u = \sin x & v = \dfrac{1}{2}x^2\ du = \cos x \ dx & dv = x \ dx \end{array}$

Plugging these into the formula gives $\begin{aligned} \int u \ dv &= uv - \int v \ du\ &= \dfrac{1}{2}x^2 \sin x - \int \dfrac{1}{2}x^2 \cos x \ dx \end{aligned}$

This results in a *more difficult* integral instead of a simpler one, so we're headed in the wrong direction; that's what happens when we pick $u$ and $dv$ backwards.

We could always try the problem both ways and see which one works, but there's a quicker way.

### How to pick $u$ and $dv$: LIPTE

There's a shortcut to pick $u$ and $dv$ right the first time; there's no magic to it, but there's simply a pattern to what works, and it depends on the types of functions are in the problem.

Like in the example above, there will be two functions, typically multiplied together, and all we have to do is look at what kind of functions these are.

We'll use the acronym **LIPTE** for **L**ogarithmic functions, **I**nverse trig functions, **P**ower functions and polynomials, **T**rigonometric functions, and **E**xponential functions. The function that comes earlier in the list will be $u$ and the other will be $dv$:
$\begin{array}{r l}
u & \textrm{Logarithmic functions}\
\uparrow & \textrm{Inverse trig functions}\
& \textrm{Power functions}\
\downarrow & \textrm{Trig functions}\
dv & \textrm{Exponential functions}
\end{array}$

For instance, in the example above, $x$ is a power function and $\sin x$ is a trig function, so since $x$ comes earlier in the list, we picked that as $u$.

With that, let's do some more examples.

# Examples

Evaluate $\displaystyle\int 5x \ e^x \ dx$.

### Solution

Here again, we have two functions: one ($5x$) is a power function and the other ($e^x$) is an exponential function. Since P comes before E in LIPTE, let $u=5x$ and $dv=e^x$.

Then $\begin{array}{c c} u = 5x & v = e^x\ du = 5 \ dx & dv = e^x \ dx \end{array}$

and plugging these into the formula gives $\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int 5x\ e^x\ dx &= 5x\ e^x - \int 5e^x \ dx\ &= \ans{5x\ e^x - 5e^x + C} \end{aligned}$

$\displaystyle\int x \cos x \ dx$

$\displaystyle\int t \sin (2t) \ dt$

$\displaystyle\int x^2 \sin (\pi x) \ dx$

$x \sin x + \cos x + C$

$-\dfrac{1}{2}t \cos (2t) + \dfrac{1}{4}\sin (2t) + C$

$-\dfrac{1}{\pi}x^2 \cos (\pi x) + \dfrac{2}{\pi^2} x \sin (\pi x) + \dfrac{2}{\pi^3} \cos (\pi x) + C$

## Using IBP Twice

Evaluate $\displaystyle\int x^2 e^x \ dx$.

### Solution

This example looks very similar to the last one, and it starts the same way: $\begin{array}{c c} u = x^2 & v = e^x\ du = 2x \ dx & dv = e^x \ dx \end{array}$

It's only when we plug all this into the formula that we notice the difference: $\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int x^2 e^x\ dx &= x^2 e^x - \int 2xe^x \ dx \end{aligned}$

That integral on the right-hand side isn't one that we can do directly. However, it looks almost identical to the example we just finished doing, so it shouldn't come as a great surprise that we're going to use IBP *again* to finish solving this one.

It's important not to get sloppy in writing all of this down, because that can lead to simple mistakes.

Now if $u=2x$ and $dv=e^x\ dx$ (still using LIPTE), we can use the IBP formula to rewrite $\displaystyle\int 2x e^x \ dx$: $\begin{aligned} \int x^2 e^x\ dx &= x^2 e^x - \int 2xe^x \ dx\ &= x^2e^x - \int u \ dv\ &= x^2e^x - \left(uv - \int v \ du\right)\ &= x^2e^x - \left(2xe^x - \int 2e^x\ dx\right)\ &= \ans{x^2e^x - 2xe^x + 2e^x + C} \end{aligned}$

Notice the parentheses there; it's easy to forget those and have a sign error in your answer.

There are times when, after applying the IBP formula, the integral on the right-hand side needs more work. This may involve using integration by parts again, or it may involve u-substitution or some other method.

Evaluate $\displaystyle\int \dfrac{\ln y}{\sqrt{y}}\ dy$.

### Solution

We've got a log function and a power function, so LIPTE says we should let $u=\ln y$. Now be careful on this next step: you may be tempted to let $dv=\sqrt{y} \ dy$, but if you did, the integral above wouldn't be exactly $\displaystyle\int u\ dv$. In other words, we have to pick $u$ and $dv$ so that the original problem is the *product* of the two. Thus, we should let $dv = \dfrac{1}{\sqrt{y}}\ dy$. To integrate that, rewrite it as $y^{-1/2}$ and apply the Power Rule:
$\begin{array}{c c}
u = \ln y & v = 2y^{1/2}\
du = \dfrac{1}{y} \ dy & dv = y^{-1/2} \ dy
\end{array}$

Once we plug all this into the formula, we can finish integrating: $\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int \dfrac{\ln y}{\sqrt{y}}\ dy &= 2y^{1/2}\ln y - \int 2y^{1/2} \cdot \dfrac{1}{y} \ dy\ &= 2y^{1/2}\ln y - \int 2y^{-1/2} \ dy\ &= 2y^{1/2}\ln y - 4y^{1/2} + C\ &= \ans{2\sqrt{y}\ln y - 4\sqrt{y} + C} \end{aligned}$

$\displaystyle\int p^5 \ \ln p \ dp$

$\dfrac{1}{6}p^6\ \ln p - \dfrac{1}{36}p^6 + C$

## The Natural Log Function

Evaluate $\displaystyle\int \ln x \ dx$.

### Solution

You may be tempted, when you see this, to automatically jump to the answer of $\dfrac{1}{x}$, but that's only if you get the derivative and integral mixed up (which is a common enough mistake). We haven't encountered the *integral* of the natural log function yet, only its derivative.

As you may imagine based on where we see this problem, we're going to use integration by parts to solve it, but the difference from all the other problems is that there only appears to be one function.

Since the function we have occurs at the very top of the LIPTE scale, let's make that $u$ and make $dv$ simply equal $dx$.

Then following the process... $\begin{array}{c c} u = \ln x & v = x\ du = \dfrac{1}{x} \ dx & dv = \ dx \end{array}$

$\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int \ln x \ dx &= x \ln x - \int x \cdot \dfrac{1}{x} \ dx\ &= x \ln x - \int dx\ &= \ans{x \ln x - x + C} \end{aligned}$

At this point, you can memorize the integral of the natural log function if you like, or you can remember that we used integration by parts to find it, and you can re-derive it if needed.

$\displaystyle\int (\ln x)^2 \ dx$

$\begin{array}{c c} u = (\ln x)^2 & v = x\ du = 2\ln x \cdot \dfrac{1}{x} \ dx & dv = \ dx \end{array}$

$\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int (\ln x)^2 \ dx &= x (\ln x)^2 - \int 2 \ln x \ dx\ &= x (\ln x)^2 - 2(x \ln x - x) + C\ &= \ans{x (\ln x)^2 - 2x \ln x + 2x + C} \end{aligned}$

I'll do one final (tricky) example, then leave you with several more to try on your own.

## A Tricky One

Evaluate $\displaystyle\int e^x \sin x \ dx$.

### Solution

Using LIPTE again, we can pick the following: $\begin{array}{c c} u = \sin x & v = e^x\ du = \cos x \ dx & dv = e^x \ dx \end{array}$

Let's try the IBP formula: $\begin{aligned} \int u \ dv &= uv - \int v \ du\ \int e^x \sin x \ dx &= e^x \sin x - \int e^x \cos x \ dx \end{aligned}$

That integral on the right-hand side isn't one we can do directly, but we can use IBP again on it, like we've done before.

For this one, $\begin{array}{c c} u = \cos x & v = e^x\ du = -\sin x \ dx & dv = e^x \ dx \end{array}$

This gets long, but the double IBP looks like this: $\begin{aligned} \int e^x \sin x \ dx &= e^x \sin x - \int e^x \cos x \ dx\ &= e^x \sin x - \left(e^x \cos x + \int e^x \sin x \ dx\right)\ &= e^x \sin x - e^x \cos x - \int e^x \sin x \ dx \end{aligned}$

Well, this is awkward. This new integral *also* needs IBP; in fact, it's the exact integral we started with, so we're stuck in an infinite loop.

Here's the trick: we can **solve** for this integral like it is any variable. Add it to both sides, then divide by 2.
$\begin{aligned}
\int e^x \sin x \ dx &= e^x \sin x - e^x \cos x - \int e^x \sin x \ dx\
2\int e^x \sin x \ dx &= e^x \sin x - e^x \cos x\
\int e^x \sin x \ dx &= \ans{\dfrac{1}{2}e^x \sin x - \dfrac{1}{2}e^x \cos x}
\end{aligned}$

$\displaystyle\int e^{-\theta} \cos (2\theta) \ d\theta$

$\displaystyle\int \cos x \cdot \ln (\sin x) \ dx$

$\displaystyle\int x^4 (\ln x)^2 \ dx$

$\displaystyle\int \dfrac{y}{e^{2y}} \ dy$

$-\dfrac{1}{5}e^{-\theta} \cos (2\theta) + \dfrac{2}{5}e^{-\theta} \sin (2\theta) + C$

$\sin x \cdot \ln (\sin x) - \sin x + C$

$\dfrac{1}{5}x^5 (\ln x)^2 - \dfrac{2}{25}x^5 \ln x + \dfrac{2}{125}x^5 + C$

$-\dfrac{1}{2}ye^{-2y} - \dfrac{1}{4}e^{-2y} + C$