## Substitution Rule

The Substitution Rule is another technique for integrating complex functions and is the corresponding process of integration as the chain rule is to differentiation.

The Substitution Rule is applicable to a wide variety of integrals, but is most performant when the integral in question is of the form:

$$\int F\big(g(x)\big) g^\prime (x) \space dx$$

Which is similar in form to the Chain Rule:

$$\frac{d}{dx} \big[ F\big(x\big)\big] = F^\prime \big(g(x)\big) g^\prime(x)$$

Expressing the function $g(x)$ more compactly as $u = g(x)$, we make a 'substitution', which gives:

$$\int F^\prime \big(g(x)\big) g^\prime(x) \space dx = F\big(g(x)\big) + C$$$$= F(u) + C = \int F^\prime (u) \space du$$

Or,

$$\int f(u) \space u^\prime \space dx = \int f(u) \space du$$

We can also write the substitution by replacing $F^\prime = f$:

$$\int f\big(g(x)\big) g^\prime (x) \space dx = \int f(u) \space du$$

Concisely stated, the Substitution Rule for Indefinite Integrals can be defined as:

If $u = g(x)$ is a differentiable function on an interval $[a, b]$ and $f$ is continutous on that interval, then:

$$\int f\big(g(x)\big) g^\prime (x) \space dx = \int f(u) \space du$$

## The Substitution Rule for Definite Integrals¶

The Substitution Rule for Definite Integrals is similar to the case of indefinite integrals; however, we make sure to specify that $f$ must be a continuous function on the range of $u$. The definition for the definite integral case is thus a slight restatement of the indefinite integral case:

If $g^\prime$ is continuous on an interval $[a, b]$ and $f$ is continuous on the range of $u = g(x)$, then:

$$\int_a^b f\big(g(x)\big) g^\prime \space dx = \int_{g(a)}^{g(b)} f(u) \space du$$

## Substitution Rule for Simplifying Symmetric Integrals¶

Another interesting use for the Substitution Rule for Definite Integrals is the simplification of even and odd functions. Even functions are defined as:

$$f(-x) = f(x)$$

While odd functions are defined as:

$$f(x) = -f(x)$$

The integrals of definite even and odd functions can be simplified based onthe following definitions. Assuming the function $f$ is continuous on an interval $[-a, a]$:

• If $f$ is even, then $\int_{-a}^a \space f(x) \space dx = 2 \int_0^a f(x) \space dx$
• If $f$ is odd, then $\int_{-a}^a \space f(x) \space dx = 0$

## Examples¶

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

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


### Example 1: Compute the indefinite integral $\int x \sin{x^2} \space dx$¶

We choose the substitution $u = x^2$, therefore:

$$du = 2x \space dx$$$$dx = \frac{1}{2} \frac{du}{x}$$

We then proceed to substitute $u$ into the original integral and solve:

$$\int x \sin{u} \space dx$$$$\int \big(x \sin{u} \big) \big(\frac{1}{2} \frac{du}{x} \big)$$

Factor out the $\frac{1}{2}$ and cancel the $x$:

$$\frac{1}{2} \int \sin{u} \space du$$

Integrating $\sin{u}$ with respect to $u$ yields $-\cos{u}$. Lastly, replace $u$ with $x^2$ and add the constant of integration:

$$-\frac{1}{2} \cos{x^2} + C$$

We can verify our solution using SymPy's integrate() function.

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

Out:
$$- \frac{1}{2} \cos{\left (x^{2} \right )}$$

### Example 2: Integrate the indefinite integral $\int (3x - 2)^{20} \space dx$¶

This would be quite the chore of an integral to solve without the Substitution Rule! Start by choosing to substitute $u = 3x - 2$. Thus,

$$u = 3x - 2, \qquad du = 3 \space dx, \qquad dx = \frac{1}{3} du$$

As before, we replace $dx$ back into the integral:

$$\int (u)^{20} \bigg(\frac{1}{3} du \bigg)$$

Factor out $\frac{1}{3}$ and compute the integral:

$$\frac{1}{3} \int u^{20}$$$$\bigg(\frac{1}{3} \bigg) \bigg(\frac{1}{21} u^{21} \bigg)$$

Then cleaning up the terms and replacing $3x - 2$ back into the integral gives:

$$\frac{1}{63} u^{21}$$$$\frac{1}{63} (3x - 2)^{21} + C$$

Unfortunately, SymPy isn't much help in verifying this answer as it expands the polynomial and performs the integration.

In :
simplify(integrate((3 * x - 2) ** 20, x))

Out:
$$\frac{x}{7} \left(1162261467 x^{20} - 16271660538 x^{19} + 108477736920 x^{18} - 458017111440 x^{17} + 1374051334320 x^{16} - 3114516357792 x^{15} + 5536917969408 x^{14} - 7909882813440 x^{13} + 9228196615680 x^{12} - 8886411555840 x^{11} + 7109129244672 x^{10} - 4739419496448 x^{9} + 2633010831360 x^{8} - 1215235768320 x^{7} + 462946959360 x^{6} - 144027942912 x^{5} + 36006985728 x^{4} - 7060193280 x^{3} + 1045954560 x^{2} - 110100480 x + 7340032\right)$$

Luckily, as we know Integration by Substitution is the corresponding procedure for integration as the Chain Rule is for differentiation. Thus, we should arrive at the original function by performing the Chain Rule on the integrated function:

$$\frac{dy}{dx} = \frac{dy}{du} \frac{du}{dx}$$$$u = 3x - 2, \qquad \frac{du}{dx} = 3, \qquad \frac{dy}{du} = \frac{21}{63}u^{20} = \frac{1}{3}u^{20}$$$$F^\prime (x) = \bigg( \frac{1}{3}(3x - 2)^{20} \bigg) \bigg( 3 \bigg)$$$$= (3x - 2)^{20}$$

### Example 3: $\int (x + 1) \sqrt{2x + x^2} \space dx$¶

Choose $u = 2x + x^2$. Therefore,

$$du = 2 + 2x \space dx, \qquad dx = \frac{du}{2 + 2x}$$

Factor out the $\frac{1}{2}$ and find the integral:

$$\frac{1}{2} \int \sqrt{u} \space du = \frac{2}{3}u^{\frac{3}{2}}$$

Then,

$$\bigg(\frac{1}{2} \bigg) \bigg( \frac{2}{3}u^{\frac{3}{2}} \bigg)$$$$\frac{1}{3} (2x + x^2)^{\frac{3}{2}}$$

Or, rewritten with an $x$ term factored:

$$\frac{1}{3} \bigg(x (x + 2) \bigg)^\frac{3}{2}$$
In :
simplify(integrate((x + 1) * sqrt(2 * x + x ** 2), x))

Out:
$$\frac{1}{3} \left(x \left(x + 2\right)\right)^{\frac{3}{2}}$$

### Example 4: Integrate $\int \sin{\pi x} \space dx$¶

We choose the substitution $u = \pi x$.

$$du = \pi \space dx, \qquad dx = \frac{du}{\pi}$$$$\int \sin{u} \space du = -\cos{u}$$$$\bigg(-\cos{u} \bigg) \bigg(\frac{du}{\pi} \bigg)$$$$-\frac{1}{\pi} \cos{\pi x}$$
In :
integrate(sin(pi * x), x)

Out:
$$- 0.318309886183791 \cos{\left (3.14159265358979 x \right )}$$

### Example 5: Integrate $\int e^x \sqrt{1 + e^x} \space dx$¶

Start by substituting $u = 1 + e^x$.

$$du = e^x \space dx, \qquad dx = \frac{du}{e^x}$$$$\int \sqrt{u} = \frac{2}{3} u^\frac{3}{2}$$$$\big(e^x \big) \bigg(\sqrt{u} \bigg) \space dx$$$$\big(e^x \big) \bigg(\sqrt{u} \bigg) \space \frac{du}{e^x}$$$$\int \sqrt{u} \space du$$$$\frac{2}{3}u^\frac{3}{2}$$$$\frac{2}{3} \big(1 + e^x \big)^\frac{3}{2}$$
In :
integrate(e ** x * sqrt(1 + e ** x), x)

Out:
$$0.666666666666667 \cdot 2.71828182845905^{x} \sqrt{2.71828182845905^{x} + 1} + 0.666666666666667 \sqrt{2.71828182845905^{x} + 1}$$