## Integration by Parts

Integration by parts is another technique for simplifying integrands. As we saw in previous posts, each differentiation rule has a corresponding integration rule. In the case of integration by parts, the corresponding differentiation rule is the Product Rule. The technique of integration by parts allows us to simplify integrands of the form: $$\int f(x) g(x) dx$$

Examples of this form include: $$\int x \cos{x} \space dx, \qquad \int e^x \cos{x} \space dx, \qquad \int x^2 e^x \space dx$$

As integration by parts is the product rule applied to integrals, it helps to state the Product Rule again. The Product Rule is defined as: $$\frac{d}{dx} \big[ f(x)g(x) \big] = f^{\prime}(x) g(x) + f(x) g^{\prime}(x)$$

When we apply the product rule to indefinite integrals, we can restate the rule as:

$$\int \frac{d}{dx} \big[f(x)g(x)\big] \space dx = \int \big[f^{\prime} g(x) + f(x) g^{\prime}(x) \big] \space dx$$

Then, rearranging so we get $f(x)g^{\prime}(x) \space dx$ on the left side of the equation:

$$\int f(x)g^{\prime}(x) \space dx = \int \frac{d}{dx} \big[f(x)g(x)\big] \space dx - \int f^{\prime}(x)g(x) \space dx$$

Which gives us the integration by parts formula! The formula is typically written in differential form:

$$\int u \space dv = uv - \int v \space du$$

## Examples¶

The following examples walkthrough several problems that can be solved using integration by parts. We also employ the wonderful SymPy package for symbolic computation to confirm our answers. To use SymPy later to verify our answers, we load the modules we will require and initialize several variables for use with the SymPy library.

In :
from sympy import symbols, limit, diff, sin, cos, log, tan, sqrt, init_printing, plot, integrate
from mpmath import ln, e, pi, cosh, sinh

init_printing()
x = symbols('x')
y = symbols('y')


Example 1: Evaluate the integrand $\int x \sin{\frac{x}{2}} \space dx$

Recalling the differential form of the integration by parts formula, $\int u \space dv = uv - \int v \space du$, we set $u = x$ and $dv = \sin{\frac{x}{2}}$

Solving for the derivative of $u$, we arrive at $du = 1 \space dx = dx$. Next, we find the antiderivative of $dv$. To find this antiderivative, we employ the Substitution Rule.

$$u = \frac{1}{2}x, \qquad du = {1}{2} \space dx, \qquad \frac{du}{dx} = 2$$$$y = \sin{u}, \qquad dy = -\cos{u} \space du, \qquad \frac{dy}{du} = -\cos{u}$$

Therefore, $v = -2 \cos{\frac{x}{2}}$

Entering these into the integration by parts formula:

$$-2x\cos{\frac{x}{2}} - (-2)\int \cos{\frac{x}{2}}$$

Then, solving for the integrand $\int \cos{\frac{x}{2}}$, we employ the Substitution Rule again as before to arrive at $2\sin{\frac{x}{2}}$ (the steps in solving this integrand are the same as before when we solved for $\int \sin{\frac{x}{2}}$). Thus, the integral is evaluated as:

$$-2x\cos{\frac{x}{2}} + 4\sin{\frac{x}{2}} + C$$

Using SymPy's integrate, we can verify our answer is correct (SymPy does not include the constant of integration $C$).

In :
integrate(x * sin(x / 2), x)

Out:
$$- 2 x \cos{\left (\frac{x}{2} \right )} + 4 \sin{\left (\frac{x}{2} \right )}$$

Example 2: Evaluate $\int t^2 \cos{t} \space dt$

We start by setting $u = t^2$ and $dv = \cos{t}$. The derivative of $t^2$ is $2t$, thus $du = 2t \space dt$, or $\frac{du}{dt} = 2t$. Integrating $dv = \cos{t}$ gives us $v = \sin{t} \space du$. Entering these into the integration by parts formula:

$$t^2 \sin{t} - 2\int t \sin{t}$$

Therefore, we must do another round of integration by parts to solve $\int t \sin{t}$.

$$u = t, \qquad du = dt$$

$$dv = \sin{t}, \qquad v = -\cos{t} \space du$$

Putting these together into the integration by parts formula with the above:

$$t^2 \sin{t} - 2 \big(-t \cos{t} + \int \cos{t} \space dt \big)$$

Which gives us the solution:

$$t^2 \sin{t} + 2t \cos{t} - 2 \sin{t} + C$$

As before, we can verify that our answer is correct by leveraging SymPy.

In :
t = symbols('t')
integrate(t ** 2 * cos(t), t)

Out:
$$t^{2} \sin{\left (t \right )} + 2 t \cos{\left (t \right )} - 2 \sin{\left (t \right )}$$

Example 3: $\int x e^x \space dx$

Here, we set $u = x$ and $dv = e^x$. Therefore, $du = dx$ and $v = e^x \space dx$. Putting these together in the integration by parts formula:

$$xe^x - \int e^x$$

As the integral of $e^x$ is just $e^x$, our answer is:

$$xe^x - e^x + C$$

We can again verify our answer is accurate using SymPy.

In :
integrate(x * e ** x, x)

Out:
$$2.71828182845905^{x} \left(1.0 x - 1.0\right)$$