11. Improper integrals
The Riemann integral of §4.2 needs a bounded function on a bounded interval. Two ways to break that:
Type 1: infinite interval. \displaystyle\int_1^\infty\frac{dx}{x^2}
Type 2: unbounded integrand. \displaystyle\int_0^1\frac{dx}{\sqrt x}
Neither is a Riemann integral. Both are defined as limits of ones that are.
Type 1
\int_a^\infty f(x)\,dx = \lim_{b\to\infty}\int_a^bf(x)\,dx
If the limit exists and is finite, the integral converges; otherwise it diverges.
\int_1^\infty\frac{dx}{x^2} = \lim_{b\to\infty}\left[-\frac1x\right]_1^b = \lim_{b\to\infty}\left(1-\frac1b\right) = 1
A region of infinite extent with finite area. The strip keeps going forever, but it thins fast enough that the total is finite.
\int_1^\infty\frac{dx}{x} = \lim_{b\to\infty}\Big[\ln x\Big]_1^b = \lim_{b\to\infty}\ln b = \infty
Diverges. \frac1x doesn't thin fast enough.
The two functions look similar and behave completely differently. How fast the tail decays is the whole question, and it's the same question §7 asks about series.
Both ends infinite: split at any convenient point, and both halves must converge independently:
\int_{-\infty}^{\infty}f = \int_{-\infty}^{c}f + \int_c^\infty f
You may not take a symmetric limit \lim_{b\to\infty}\int_{-b}^b. That's the Cauchy principal value, a genuinely different and weaker object — for f(x)=x it gives 0 while the integral diverges.
Type 2
If f blows up at an endpoint, retreat from it and take a limit:
\int_a^bf = \lim_{t\to a^+}\int_t^bf \qquad\text{(singularity at } a\text{)}
\int_0^1\frac{dx}{\sqrt x} = \lim_{t\to0^+}\Big[2\sqrt x\Big]_t^1 = \lim_{t\to0^+}\left(2-2\sqrt t\right) = 2
Converges, despite the function running to infinity — the spike is narrow enough.
\int_0^1\frac{dx}{x} = \lim_{t\to0^+}\Big[\ln x\Big]_t^1 = \lim_{t\to0^+}\left(-\ln t\right) = \infty
Diverges. Same threshold function, again.
A singularity in the middle must be split. This is the trap §4.4 flagged:
\int_{-1}^1\frac{dx}{x^2} = \int_{-1}^0 + \int_0^1
and both halves diverge, so the integral does. Blindly evaluating \left[-\frac1x\right]_{-1}^1 = -2 gives a negative answer for a positive integrand — a nonsense result from applying the Fundamental Theorem where its continuity hypothesis fails.
Check the integrand for singularities inside the interval before evaluating.
The p-test
Both examples turned on the same threshold, and it's worth stating as a rule:
\int_1^\infty\frac{dx}{x^p} \text{ converges} \iff p>1
\int_0^1\frac{dx}{x^p} \text{ converges} \iff p<1
The conditions are opposite, and p=1 fails both. The logic:
- Near infinity, you need fast decay, so a large p helps.
- Near zero, you need a mild singularity, so a small p helps.
- \frac1x is exactly on the boundary at both ends and fails at both.
\int_0^\infty\frac{dx}{x^p} therefore never converges, for any p: whatever makes one end work breaks the other.
This test does most of the work in practice, both directly and through comparison.
Comparison
You rarely need the exact value — only whether it's finite. And for that you can compare against something you know.
If 0\le f\le g on [a,\infty): if \int g converges so does \int f; if \int f diverges so does \int g.
Bigger converges ⟹ smaller converges. Smaller diverges ⟹ bigger diverges.
\int_1^\infty\frac{dx}{x^2+1}
Since \frac{1}{x^2+1} < \frac{1}{x^2} and \int_1^\infty\frac{dx}{x^2} converges, this converges too. No antiderivative needed — though here we happen to know it's \arctan.
\int_1^\infty e^{-x^2}dx
For x\ge1, x^2\ge x, so e^{-x^2}\le e^{-x}, and \int_1^\infty e^{-x}dx = e^{-1} converges. Therefore this does.
And it has no elementary antiderivative (§4.0) — so comparison is the only way to establish convergence. That's the technique's real value.
The limit comparison variant is often easier: if \lim_{x\to\infty}\frac{f}{g} = L with 0<L<\infty, then \int f and \int g do the same thing. It saves you from having to get an inequality in the right direction.
The Gaussian
\int_{-\infty}^\infty e^{-x^2}dx = \sqrt\pi
Infinite interval, no elementary antiderivative, and an exact answer involving \pi — from an integrand with no circle anywhere in sight.
The trick is to square it and switch to polar coordinates, which is §11.5. It's worth flagging now because this integral is the normalising constant of the normal distribution, and it's why \frac{1}{\sqrt{2\pi}} appears in front of every Gaussian density in the statistics course.
Doing it in Python
Convergence and divergence, side by side:
import sympy as sp
x = sp.Symbol('x', positive=True)
cases = [
("int_1^oo 1/x^2", 1/x**2, 1, sp.oo),
("int_1^oo 1/x", 1/x, 1, sp.oo),
("int_0^1 1/sqrt(x)", 1/sp.sqrt(x), 0, 1),
("int_0^1 1/x", 1/x, 0, 1),
("int_0^oo e^-x", sp.exp(-x), 0, sp.oo),
("int_-oo^oo e^-x^2", sp.exp(-x**2), -sp.oo, sp.oo),
]
for name, f, a, b in cases:
print(f"{name:<22} = {sp.integrate(f, (x, a, b))}")
Watching one converge and one not:
from math import log
print(f"{'b':>10} {'int_1^b dx/x^2':>18} {'int_1^b dx/x':>16}")
for b in (10, 100, 10_000, 10**8, 10**16):
print(f"{b:>10.0e} {1 - 1/b:>18.10f} {log(b):>16.6f}")
print("\nthe left column stalls at 1. the right one grows forever --")
print("slowly (logarithmically), but without bound.")
The p-test at both ends:
import sympy as sp
x = sp.Symbol('x', positive=True)
print(f"{'p':>6} {'int_1^oo x^-p':>16} {'int_0^1 x^-p':>16}")
for p in (sp.Rational(1,2), 1, sp.Rational(3,2), 2, 3):
tail = sp.integrate(x**(-p), (x, 1, sp.oo))
head = sp.integrate(x**(-p), (x, 0, 1))
print(f"{str(p):>6} {str(tail):>16} {str(head):>16}")
print("\nconverges at infinity iff p > 1; converges at zero iff p < 1.")
print("p = 1 fails both, so int_0^oo x^-p never converges for any p.")
The trap from §4.4, and what actually happens:
import sympy as sp
x = sp.Symbol('x')
print("naively applying the Fundamental Theorem to int_{-1}^{1} dx/x^2:")
F = -1/x
print(f" [{F}] from -1 to 1 = {F.subs(x, 1) - F.subs(x, -1)}")
print(" a negative number, for a strictly positive integrand.\n")
print("splitting at the singularity, which is what the definition requires:")
print(f" int_{{-1}}^{{0}} : {sp.integrate(1/x**2, (x, -1, 0))}")
print(f" int_{{0}}^{{1}} : {sp.integrate(1/x**2, (x, 0, 1))}")
print(f" total : {sp.integrate(1/x**2, (x, -1, 1))}")
Comparison, where no antiderivative exists:
from math import exp
def integrate(f, a, b, n=200000):
w = (b - a) / n
return sum(f(a + (i + 0.5) * w) for i in range(n)) * w
print(f"{'b':>6} {'int_1^b e^-x^2':>18} {'int_1^b e^-x':>16} {'ratio':>10}")
for b in (2, 4, 8, 16, 32):
small = integrate(lambda t: exp(-t*t), 1, b)
big = integrate(lambda t: exp(-t), 1, b)
print(f"{b:>6} {small:>18.12f} {big:>16.12f} {small/big:>10.6f}")
print(f"\ne^-x^2 <= e^-x for x >= 1, and the bigger one converges to "
f"{exp(-1):.10f}.")
print("so the smaller one converges too -- established without any antiderivative,")
print("which is the only option since e^-x^2 has none.")
The Gaussian:
import sympy as sp
from math import exp, sqrt, pi
x = sp.Symbol('x')
exact = sp.integrate(sp.exp(-x**2), (x, -sp.oo, sp.oo))
def integrate(f, a, b, n=2_000_000):
w = (b - a) / n
return sum(f(a + (i + 0.5) * w) for i in range(n)) * w
print(f"exact : {exact} = {float(exact):.10f}")
print(f"numeric over [-8,8]: {integrate(lambda t: exp(-t*t), -8, 8):.10f}")
print(f"sqrt(pi) : {sqrt(pi):.10f}")
print("\nno elementary antiderivative, an infinite interval, and the answer")
print("is sqrt(pi). section 11.5 explains where the circle comes from.")
Worked example
Does \displaystyle\int_2^\infty\frac{dx}{x\ln x} converge?
The integrand looks like it decays slightly faster than \frac1x, which is right on the divergence boundary — so this genuinely needs computing rather than guessing.
Substitute u = \ln x, du = \frac{dx}{x} (§4.5). Limits: $x=2\Rightarrow u=\ln2$; x=b \Rightarrow u = \ln b:
\int_2^b\frac{dx}{x\ln x} = \int_{\ln2}^{\ln b}\frac{du}{u} = \Big[\ln u\Big]_{\ln2}^{\ln b} = \ln(\ln b) - \ln(\ln 2)
Now take b\to\infty. \ln b\to\infty, so \ln(\ln b)\to\infty:
\boxed{\text{diverges}}
Just barely. \ln(\ln b) grows about as slowly as anything in mathematics — at b = 10^{100} it's only about 5.4 — but it grows without bound, and that's all that matters.
The moral: the boundary at p=1 is sharp, and a logarithmic factor is not enough to cross it. Compare:
| Integral | Behaviour |
|---|---|
| \int_2^\infty\frac{dx}{x} | diverges |
| \int_2^\infty\frac{dx}{x\ln x} | diverges |
| \int_2^\infty\frac{dx}{x(\ln x)^2} | converges (to \frac{1}{\ln2}) |
One more log factor tips it. This hierarchy reappears verbatim in §7.6's integral test for series, and it's why the p-series boundary is equally sharp there.
Your turn
1. \displaystyle\int_1^\infty\frac{dx}{x^3}
2. \displaystyle\int_0^1\frac{dx}{x^{2/3}}
3. \displaystyle\int_0^\infty e^{-x}dx
4. Does \displaystyle\int_1^\infty\frac{dx}{\sqrt{x^3+1}} converge?
Solutions
1. p=3>1, so it converges by the p-test. Value:
\lim_{b\to\infty}\left[-\frac{1}{2x^2}\right]_1^b = \lim_{b\to\infty}\left(\frac12-\frac{1}{2b^2}\right) = \boxed{\frac12}
2. Singularity at 0, and p = \frac23 < 1, so it converges:
\lim_{t\to0^+}\Big[3x^{1/3}\Big]_t^1 = \lim_{t\to0^+}\left(3-3t^{1/3}\right) = \boxed{3}
3.
\lim_{b\to\infty}\Big[-e^{-x}\Big]_0^b = \lim_{b\to\infty}\left(1-e^{-b}\right) = \boxed{1}
This is the total probability of an Exponential(1) distribution, and the fact that it's exactly 1 is what makes e^{-x} a valid density on [0,\infty).
4. Converges, by comparison.
For x\ge1, x^3+1 > x^3, so
\frac{1}{\sqrt{x^3+1}} < \frac{1}{\sqrt{x^3}} = \frac{1}{x^{3/2}}
and \int_1^\infty x^{-3/2}dx converges since p = \frac32 > 1. Bigger converges, so smaller does. ✓
Limit comparison is even cleaner here. With g = x^{-3/2}:
\lim_{x\to\infty}\frac{1/\sqrt{x^3+1}}{1/\sqrt{x^3}} = \lim_{x\to\infty}\sqrt{\frac{x^3}{x^3+1}} = 1
A finite nonzero limit, so the two integrals share a fate — and g's is known. Limit comparison saves you from getting the inequality direction right, which is where the plain version most often goes wrong.
Check yourself in code
Evaluate six improper integrals with SymPy, including divergent ones.
Print the value of each — SymPy returns oo for divergence.
Print exactly this:
1/x^2 on [1,oo) = 1
1/x on [1,oo) = oo
1/sqrt(x) on (0,1] = 2
1/x on (0,1] = oo
e^-x on [0,oo) = 1
e^(-x^2) on (-oo,oo) = sqrt(pi)
import sympy as sp
x = sp.Symbol('x')
cases = [
("1/x^2 on [1,oo)", 1/x**2, 1, sp.oo),
("1/x on [1,oo)", 1/x, 1, sp.oo),
("1/sqrt(x) on (0,1]", 1/sp.sqrt(x), 0, 1),
("1/x on (0,1]", 1/x, 0, 1),
("e^-x on [0,oo)", sp.exp(-x), 0, sp.oo),
("e^(-x^2) on (-oo,oo)", sp.exp(-x**2), -sp.oo, sp.oo),
]
for name, f, a, b in cases:
print(f"{name:<24} = ...")
import sympy as sp
x = sp.Symbol('x')
cases = [
("1/x^2 on [1,oo)", 1/x**2, 1, sp.oo),
("1/x on [1,oo)", 1/x, 1, sp.oo),
("1/sqrt(x) on (0,1]", 1/sp.sqrt(x), 0, 1),
("1/x on (0,1]", 1/x, 0, 1),
("e^-x on [0,oo)", sp.exp(-x), 0, sp.oo),
("e^(-x^2) on (-oo,oo)", sp.exp(-x**2), -sp.oo, sp.oo),
]
for name, f, a, b in cases:
print(f"{name:<24} = {sp.integrate(f, (x, a, b))}")
An improper integral is a limit of proper ones — retreat from the infinity, then let the boundary go. The p-test settles most cases and its two halves point opposite ways: \int_1^\infty x^{-p} needs p>1, \int_0^1x^{-p} needs p<1, and \frac1x fails both. When there's no antiderivative, comparison decides convergence without ever computing the value — which is the only available route for things like e^{-x^2}. And a singularity inside the interval must be split out, or the Fundamental Theorem will hand you a confident wrong number.
Next: what to do when there's no antiderivative and you need an actual number.