Chapter 9
18 min read
Section 88 of 353

Improper Integrals: Discontinuous Integrands

The Indefinite Integral and Antiderivatives

Learning Objectives

By the end of this section, you will be able to:

  1. Recognize when an integral is improper due to a discontinuous integrand
  2. Evaluate improper integrals with discontinuities at the left endpoint, right endpoint, or interior of the interval
  3. Apply the p-test for convergence at a discontinuity
  4. Use comparison tests to determine convergence or divergence
  5. Connect these integrals to probability distributions, physics, and machine learning

The Big Picture: When the Integrand Blows Up

"An integral can be improper not only when the limits stretch to infinity, but also when the integrand itself becomes unbounded within the interval."

In the previous section, we explored improper integrals where the limits of integration extended to infinity. Now we tackle the second type of improper integral: those where the integrand has a discontinuity — typically a vertical asymptote — at or within the interval of integration.

Consider the integral 011xdx\int_0^1 \frac{1}{\sqrt{x}} \, dx. At first glance, this looks like a standard definite integral on [0,1][0, 1]. But there is a problem: the function 1x\frac{1}{\sqrt{x}} is undefined at x = 0 and approaches infinity as x0+x \to 0^+.

The Central Question

When an integrand has a vertical asymptote within the interval of integration, the "area" under the curve extends infinitely upward near the discontinuity. Does this infinite height produce a finite or infinite total area?

The answer depends on how fast the function grows as it approaches the discontinuity. Just as with infinite limits, we define these integrals using limits:

  • If the limit exists and is finite, the integral converges
  • If the limit is infinite or does not exist, the integral diverges

Why This Matters

Improper integrals with discontinuous integrands appear throughout mathematics and its applications:

  • Probability: The Beta distribution's normalization constant involves integrals like 01xa1(1x)b1dx\int_0^1 x^{a-1}(1-x)^{b-1} \, dx which have discontinuities when a<1a < 1 or b<1b < 1
  • Physics: Electrostatic potentials near point charges involve 1r\frac{1}{r} singularities
  • Signal Processing: The Hilbert transform involves principal value integrals around singularities
  • Machine Learning: Log-likelihood functions often have boundary behavior requiring careful limit analysis

Historical Context

The study of improper integrals developed alongside the rigorous formulation of calculus in the 18th and 19th centuries.

Augustin-Louis Cauchy (1789–1857)

Cauchy was among the first to systematically study convergence of improper integrals. He recognized that the naive application of the Fundamental Theorem of Calculus could lead to errors when dealing with discontinuous integrands, and he introduced the limit-based definitions we use today.

The Cauchy Principal Value

Cauchy also developed the concept of the principal value of an integral, which provides meaning to certain integrals that would otherwise diverge. For a function with a discontinuity at cc inside [a,b][a, b]:

P.V.abf(x)dx=limϵ0+(acϵf(x)dx+c+ϵbf(x)dx)\text{P.V.} \int_a^b f(x) \, dx = \lim_{\epsilon \to 0^+} \left( \int_a^{c-\epsilon} f(x) \, dx + \int_{c+\epsilon}^b f(x) \, dx \right)

This symmetric approach is used in complex analysis and Fourier theory.


Types of Discontinuous Integrands

Integrands can have discontinuities at different locations within the interval of integration. Each case requires a specific approach:

LocationDefinitionExample
Left EndpointDiscontinuity at x = a∫₀¹ 1/√x dx (singular at x = 0)
Right EndpointDiscontinuity at x = b∫₀¹ 1/√(1-x) dx (singular at x = 1)
Interior PointDiscontinuity at c ∈ (a, b)∫₀² 1/(x-1) dx (singular at x = 1)

In each case, we replace the problematic limit with a variable and take a limit as that variable approaches the point of discontinuity.


Discontinuity at the Left Endpoint

If ff is continuous on (a,b](a, b] but has a discontinuity at x=ax = a, we define:

Left Endpoint Discontinuity

abf(x)dx=limta+tbf(x)dx\int_a^b f(x) \, dx = \lim_{t \to a^+} \int_t^b f(x) \, dx

The integral converges if this limit exists and is finite.

Example: 011xdx\int_0^1 \frac{1}{\sqrt{x}} \, dx

Step 1: Replace the lower limit 0 with tt:

011xdx=limt0+t1x1/2dx\int_0^1 \frac{1}{\sqrt{x}} \, dx = \lim_{t \to 0^+} \int_t^1 x^{-1/2} \, dx

Step 2: Find the antiderivative:

x1/2dx=x1/21/2=2x\int x^{-1/2} \, dx = \frac{x^{1/2}}{1/2} = 2\sqrt{x}

Step 3: Evaluate the limit:

limt0+[2x]t1=limt0+(212t)=20=2\lim_{t \to 0^+} [2\sqrt{x}]_t^1 = \lim_{t \to 0^+} (2\sqrt{1} - 2\sqrt{t}) = 2 - 0 = 2
011xdx=2\int_0^1 \frac{1}{\sqrt{x}} \, dx = 2

The integral converges!

Geometric Insight

Although the curve y=1xy = \frac{1}{\sqrt{x}} goes to infinity at x=0x = 0, it does so "slowly enough" that the total area under the curve between 0 and 1 is finite. The key is that t0\sqrt{t} \to 0 as t0t \to 0.


Discontinuity at the Right Endpoint

If ff is continuous on [a,b)[a, b) but has a discontinuity at x=bx = b, we define:

Right Endpoint Discontinuity

abf(x)dx=limtbatf(x)dx\int_a^b f(x) \, dx = \lim_{t \to b^-} \int_a^t f(x) \, dx

The integral converges if this limit exists and is finite.

Example: 0111xdx\int_0^1 \frac{1}{\sqrt{1-x}} \, dx

Setup: The function has a discontinuity at x=1x = 1.

0111xdx=limt10t(1x)1/2dx\int_0^1 \frac{1}{\sqrt{1-x}} \, dx = \lim_{t \to 1^-} \int_0^t (1-x)^{-1/2} \, dx

Antiderivative: Using u=1xu = 1-x:

(1x)1/2dx=21x\int (1-x)^{-1/2} \, dx = -2\sqrt{1-x}

Evaluate:

limt1[21x]0t=limt1(21t+2)=0+2=2\lim_{t \to 1^-} [-2\sqrt{1-x}]_0^t = \lim_{t \to 1^-} (-2\sqrt{1-t} + 2) = 0 + 2 = 2
0111xdx=2\int_0^1 \frac{1}{\sqrt{1-x}} \, dx = 2

Discontinuity at an Interior Point

If ff has a discontinuity at c(a,b)c \in (a, b), we must split the integral at the discontinuity:

Interior Discontinuity

abf(x)dx=acf(x)dx+cbf(x)dx\int_a^b f(x) \, dx = \int_a^c f(x) \, dx + \int_c^b f(x) \, dx

The integral converges only if both parts converge.

Critical Point

If either of the split integrals diverges, the entire integral diverges. Both must independently converge for the original integral to have a finite value.

Example: 021(x1)2dx\int_0^2 \frac{1}{(x-1)^2} \, dx

Identify: Discontinuity at x=1x = 1.

Split:

021(x1)2dx=011(x1)2dx+121(x1)2dx\int_0^2 \frac{1}{(x-1)^2} \, dx = \int_0^1 \frac{1}{(x-1)^2} \, dx + \int_1^2 \frac{1}{(x-1)^2} \, dx

Evaluate the left integral:

limt10t(x1)2dx=limt1[1x1]0t\lim_{t \to 1^-} \int_0^t (x-1)^{-2} \, dx = \lim_{t \to 1^-} \left[-\frac{1}{x-1}\right]_0^t
=limt1(1t1+101)=limt1(1t11)= \lim_{t \to 1^-} \left(-\frac{1}{t-1} + \frac{1}{0-1}\right) = \lim_{t \to 1^-} \left(-\frac{1}{t-1} - 1\right)

As t1t \to 1^-, we have t10t - 1 \to 0^-, so 1t1+-\frac{1}{t-1} \to +\infty.

The left integral DIVERGES, so the entire integral DIVERGES.

No Need to Check the Other Side

Once we determine that one part diverges, we can conclude that the entire integral diverges. There is no need to evaluate the other part.


Interactive: Visualizing Improper Integrals

Explore how improper integrals behave as we approach the point of discontinuity. Watch the area accumulate and see whether it converges to a finite value or grows without bound:

Improper Integrals with Discontinuities

Approach limit:0.100

Approximate Value:

1.3675

Limit Result:

2

Setup

Discontinuity at x = 0

Limit approach: lim_{a \to 0^+}

Evaluation

As a approaches 0 from the right, sqrt(a) approaches 0, so the integral converges to 2.

CONVERGESThe limit exists and equals 2

The p-Test for Discontinuities

One of the most useful tests for convergence at a discontinuity is the p-test. For integrals of the form ab1(xa)pdx\int_a^b \frac{1}{(x-a)^p} \, dx where the discontinuity is at x=ax = a:

The p-Test for Discontinuities

ab1(xa)pdx{convergesif p<1divergesif p1\int_a^b \frac{1}{(x-a)^p} \, dx \begin{cases} \text{converges} & \text{if } p < 1 \\ \text{diverges} & \text{if } p \geq 1 \end{cases}

(Assuming b>ab > a)

Opposite of the Infinite Interval p-Test!

For infinite intervals, 11xpdx\int_1^\infty \frac{1}{x^p} \, dx converges when p>1p > 1. For discontinuities, the condition is reversed: p<1p < 1 for convergence. This reversal often trips up students!

Why the Difference?

The distinction comes from the antiderivative's behavior:

  • For p1p \neq 1: The antiderivative of xpx^{-p} is x1p1p\frac{x^{1-p}}{1-p}
  • At a discontinuity (near x=0x = 0): We need x1p0x^{1-p} \to 0 as x0+x \to 0^+, which requires 1p>01 - p > 0, i.e., p<1p < 1
  • At infinity: We need x1p0x^{1-p} \to 0 as xx \to \infty, which requires 1p<01 - p < 0, i.e., p>1p > 1
p valueAt Discontinuity (x → 0⁺)At Infinity (x → ∞)
p = 0.5x^(0.5) → 0 ✓ CONVERGESx^(0.5) → ∞ ✗ DIVERGES
p = 1ln(x) → -∞ ✗ DIVERGESln(x) → ∞ ✗ DIVERGES
p = 2x^(-1) → ∞ ✗ DIVERGESx^(-1) → 0 ✓ CONVERGES

Comparison Tests

When the p-test does not directly apply, we can use comparison tests to determine convergence or divergence.

Direct Comparison Test

If 0f(x)g(x)0 \leq f(x) \leq g(x) near the discontinuity:

  • If g(x)dx\int g(x) \, dx converges, then f(x)dx\int f(x) \, dx converges
  • If f(x)dx\int f(x) \, dx diverges, then g(x)dx\int g(x) \, dx diverges

Limit Comparison Test

If limxa+f(x)g(x)=L\lim_{x \to a^+} \frac{f(x)}{g(x)} = L where 0<L<0 < L < \infty, then f(x)dx\int f(x) \, dx and g(x)dx\int g(x) \, dx either both converge or both diverge.

Example: Does 01sinxxdx\int_0^1 \frac{\sin x}{\sqrt{x}} \, dx converge?

Analysis: Near x=0x = 0, we have sinxx\sin x \approx x, so:

sinxxxx=x=x1/2\frac{\sin x}{\sqrt{x}} \approx \frac{x}{\sqrt{x}} = \sqrt{x} = x^{1/2}

Since p=1/2<1p = -1/2 < 1 (we are looking at x1/2x^{1/2}), and the function is bounded near 0, the integral converges.


Worked Examples

Example 1: 01lnxdx\int_0^1 \ln x \, dx

Analysis: lnx\ln x \to -\infty as x0+x \to 0^+. This is a discontinuity at the left endpoint.

Setup:

01lnxdx=limt0+t1lnxdx\int_0^1 \ln x \, dx = \lim_{t \to 0^+} \int_t^1 \ln x \, dx

Integration by parts: Let u=lnxu = \ln x, dv=dxdv = dx:

lnxdx=xlnxx\int \ln x \, dx = x \ln x - x

Evaluate:

limt0+[xlnxx]t1=(101)limt0+(tlntt)\lim_{t \to 0^+} [x \ln x - x]_t^1 = (1 \cdot 0 - 1) - \lim_{t \to 0^+}(t \ln t - t)

Key limit: limt0+tlnt=0\lim_{t \to 0^+} t \ln t = 0 (can be shown using L'Hôpital's rule on lnt1/t\frac{\ln t}{1/t})

01lnxdx=1\int_0^1 \ln x \, dx = -1

Example 2: 011x2dx\int_0^1 \frac{1}{x^2} \, dx

Analysis: Using the p-test with p=2>1p = 2 > 1, we expect divergence.

Verify:

limt0+t1x2dx=limt0+[1x]t1=limt0+(1+1t)\lim_{t \to 0^+} \int_t^1 x^{-2} \, dx = \lim_{t \to 0^+} \left[-\frac{1}{x}\right]_t^1 = \lim_{t \to 0^+} \left(-1 + \frac{1}{t}\right)

As t0+t \to 0^+, 1t+\frac{1}{t} \to +\infty.

The integral DIVERGES to +∞

Example 3: 111x2/3dx\int_{-1}^1 \frac{1}{x^{2/3}} \, dx

Analysis: Discontinuity at x=0x = 0 (interior point). We must split:

111x2/3dx=10x2/3dx+01x2/3dx\int_{-1}^1 \frac{1}{x^{2/3}} \, dx = \int_{-1}^0 x^{-2/3} \, dx + \int_0^1 x^{-2/3} \, dx

Right side: With p=2/3<1p = 2/3 < 1:

01x2/3dx=[3x1/3]01=3(1)3(0)=3\int_0^1 x^{-2/3} \, dx = \left[3x^{1/3}\right]_0^1 = 3(1) - 3(0) = 3

Left side: With substitution u=xu = -x for x<0x < 0:

10x2/3dx=01u2/3du=3\int_{-1}^0 |x|^{-2/3} \, dx = \int_0^1 u^{-2/3} \, du = 3
111x2/3dx=3+3=6\int_{-1}^1 \frac{1}{x^{2/3}} \, dx = 3 + 3 = 6

Real-World Applications

Probability: The Beta Distribution

The Beta distribution is defined by the probability density function:

f(x;α,β)=xα1(1x)β1B(α,β)f(x; \alpha, \beta) = \frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha, \beta)}

where B(α,β)=01xα1(1x)β1dxB(\alpha, \beta) = \int_0^1 x^{\alpha-1}(1-x)^{\beta-1} \, dx is the Beta function. When α<1\alpha < 1, there is a singularity at x=0x = 0; when β<1\beta < 1, there is a singularity at x=1x = 1.

By the p-test, both singularities are integrable (the exponents α1\alpha - 1 and β1\beta - 1 satisfy the convergence condition when the exponent is greater than -1).

Physics: Electrostatic Potential

The electrostatic potential due to a continuous charge distribution often involves integrals of the form:

V=ρ(r)rrdVV = \int \frac{\rho(r')}{|r - r'|} \, dV'

When computing the potential at a point within the charge distribution, the integrand has a 1r\frac{1}{r} singularity. Understanding convergence conditions is essential for correct physical predictions.

Signal Processing: Hilbert Transform

The Hilbert transform, fundamental in signal analysis, is defined as:

H[f](t)=1πP.V.f(τ)tτdτ\mathcal{H}[f](t) = \frac{1}{\pi} \text{P.V.} \int_{-\infty}^{\infty} \frac{f(\tau)}{t - \tau} \, d\tau

The principal value integral is required because of the singularity at τ=t\tau = t.


Machine Learning Connection

Improper integrals with discontinuous integrands appear in several machine learning contexts:

Variational Inference

In variational inference, we often work with the ELBO (Evidence Lower Bound):

L(q)=Eq[logp(x,z)]Eq[logq(z)]\mathcal{L}(q) = \mathbb{E}_q[\log p(x, z)] - \mathbb{E}_q[\log q(z)]

When the variational distribution q(z)q(z) is a Beta distribution with parameters less than 1, the entropy term E[logq]-\mathbb{E}[\log q] involves improper integrals at the boundaries.

Topic Modeling (LDA)

Latent Dirichlet Allocation uses Dirichlet priors (multivariate Beta distributions). The normalization constants and posterior computations involve products of terms like θkαk1\theta_k^{\alpha_k - 1}, which create boundary singularities when αk<1\alpha_k < 1.

Information-Theoretic Quantities

Differential entropy of distributions supported on bounded intervals (like Beta, Uniform, or Truncated Normal) involves evaluating:

h(X)=p(x)logp(x)dxh(X) = -\int p(x) \log p(x) \, dx

When p(x)p(x) \to \infty at the boundary, the integrand p(x)logp(x)p(x) \log p(x) may also become unbounded, requiring careful analysis.


Python Implementation

Evaluating Improper Integrals with Discontinuities

Here's how to numerically evaluate improper integrals with discontinuous integrands and detect convergence or divergence:

Numerical Improper Integrals
🐍improper_integrals.py
15Detecting Discontinuity Location

We handle three cases: discontinuity at left endpoint, right endpoint, or interior. Each requires a different limit approach.

21Left Endpoint Discontinuity

When the discontinuity is at x = a, we integrate from a + epsilon to b, effectively taking the limit as epsilon approaches 0 from the right.

30Interior Discontinuity

For discontinuities inside [a, b], we split into two integrals: from a to c-epsilon and from c+epsilon to b. Both must converge.

37Divergence Detection

We compare results with different epsilon values. If the result changes significantly as epsilon decreases, the integral likely diverges.

54Convergent Example: 1/sqrt(x)

The antiderivative is 2*sqrt(x). As x approaches 0+, sqrt(x) approaches 0, so the integral converges to 2.

72Divergent Example: 1/x^2

The antiderivative is -1/x. As x approaches 0+, -1/x approaches negative infinity, so the integral diverges.

95Symbolic Computation

SymPy handles improper integrals automatically by recognizing singularities and computing the appropriate limits.

110Beta Function in ML

The Beta distribution&apos;s normalization involves improper integrals when shape parameters are less than 1. This is crucial in Bayesian inference.

166 lines without explanation
1import numpy as np
2from scipy import integrate
3import sympy as sp
4from typing import Tuple, Callable, Optional
5
6def improper_integral_discontinuity(
7    f: Callable[[float], float],
8    a: float,
9    b: float,
10    discontinuity_at: float,
11    epsilon: float = 1e-10
12) -> Tuple[float, float, str]:
13    """
14    Evaluate an improper integral with a discontinuity.
15
16    Parameters:
17    - f: The integrand function
18    - a, b: Integration limits
19    - discontinuity_at: Location of the discontinuity
20    - epsilon: How close to approach the discontinuity
21
22    Returns:
23    - result: Approximate integral value
24    - error: Estimated error
25    - status: 'converges' or 'diverges'
26    """
27
28    if discontinuity_at == a:
29        # Discontinuity at left endpoint
30        result, error = integrate.quad(f, a + epsilon, b)
31
32    elif discontinuity_at == b:
33        # Discontinuity at right endpoint
34        result, error = integrate.quad(f, a, b - epsilon)
35
36    else:
37        # Discontinuity inside interval
38        left_result, left_error = integrate.quad(f, a, discontinuity_at - epsilon)
39        right_result, right_error = integrate.quad(f, discontinuity_at + epsilon, b)
40        result = left_result + right_result
41        error = left_error + right_error
42
43    # Check for divergence by testing with smaller epsilon
44    smaller_epsilon = epsilon / 10
45    if discontinuity_at == a:
46        test_result, _ = integrate.quad(f, a + smaller_epsilon, b)
47    elif discontinuity_at == b:
48        test_result, _ = integrate.quad(f, a, b - smaller_epsilon)
49    else:
50        left_test, _ = integrate.quad(f, a, discontinuity_at - smaller_epsilon)
51        right_test, _ = integrate.quad(f, discontinuity_at + smaller_epsilon, b)
52        test_result = left_test + right_test
53
54    # If result changes significantly, likely diverging
55    if abs(test_result - result) > 1.0:
56        status = 'diverges'
57    else:
58        status = 'converges'
59
60    return result, error, status
61
62# Example 1: Convergent integral of 1/sqrt(x) from 0 to 1
63def example_convergent():
64    """
65    Integral of 1/sqrt(x) from 0 to 1
66    This converges to 2 despite the discontinuity at x = 0.
67    """
68    f = lambda x: 1 / np.sqrt(x)
69    result, error, status = improper_integral_discontinuity(f, 0, 1, 0)
70
71    print("Example: Integral of 1/sqrt(x) from 0 to 1")
72    print("=" * 50)
73    print(f"Numerical result: {result:.10f}")
74    print(f"Expected (exact): 2.0")
75    print(f"Error estimate:   {error:.2e}")
76    print(f"Status: {status}")
77    print()
78
79    return result
80
81# Example 2: Divergent integral of 1/x^2 from 0 to 1
82def example_divergent():
83    """
84    Integral of 1/x^2 from 0 to 1
85    This diverges to infinity.
86    """
87    f = lambda x: 1 / (x ** 2)
88    result, error, status = improper_integral_discontinuity(f, 0, 1, 0)
89
90    print("Example: Integral of 1/x^2 from 0 to 1")
91    print("=" * 50)
92    print(f"Numerical result: {result:.2f}")
93    print(f"Expected: Diverges (infinity)")
94    print(f"Status: {status}")
95    print()
96
97    return result
98
99# Example 3: Using SymPy for symbolic evaluation
100def symbolic_examples():
101    """
102    Use SymPy to evaluate improper integrals symbolically.
103    SymPy automatically handles limits for discontinuities.
104    """
105    x = sp.Symbol('x', positive=True)
106
107    examples = [
108        (1/sp.sqrt(x), 0, 1, "1/sqrt(x) on [0,1]"),
109        (sp.ln(x), 0, 1, "ln(x) on [0,1]"),
110        (1/(x**(sp.Rational(2,3))), 0, 1, "1/x^(2/3) on [0,1]"),
111    ]
112
113    print("Symbolic Improper Integrals (using SymPy)")
114    print("=" * 55)
115
116    for expr, a, b, name in examples:
117        result = sp.integrate(expr, (x, a, b))
118        print(f"Integral of {name}: {result}")
119
120    print()
121    return examples
122
123# Example 4: ML Application - Log-likelihood with boundary
124def ml_log_likelihood():
125    """
126    In machine learning, log-likelihood functions often have
127    boundary singularities that require improper integral handling.
128
129    For example, the Beta distribution's normalization constant
130    involves integrals like integral of x^(a-1) * (1-x)^(b-1).
131    """
132    print("Machine Learning: Beta Distribution Normalization")
133    print("=" * 55)
134
135    # Beta function B(a, b) = integral_0^1 x^(a-1) (1-x)^(b-1) dx
136    # When a < 1 or b < 1, this is an improper integral
137
138    from scipy.special import beta
139
140    test_cases = [
141        (0.5, 0.5),  # Both endpoints are singular
142        (0.5, 2.0),  # Left endpoint singular
143        (2.0, 0.5),  # Right endpoint singular
144        (2.0, 2.0),  # No singularities
145    ]
146
147    for a, b in test_cases:
148        # Numerical integration
149        f = lambda x: x**(a-1) * (1-x)**(b-1)
150
151        # Handle potential singularities
152        eps = 1e-10
153        if a < 1 and b < 1:
154            result, _ = integrate.quad(f, eps, 1-eps)
155        elif a < 1:
156            result, _ = integrate.quad(f, eps, 1)
157        elif b < 1:
158            result, _ = integrate.quad(f, 0, 1-eps)
159        else:
160            result, _ = integrate.quad(f, 0, 1)
161
162        exact = beta(a, b)
163
164        print(f"B({a}, {b}): numerical = {result:.6f}, exact = {exact:.6f}")
165
166    print()
167    print("Beta function singularities arise in Bayesian inference,")
168    print("variational inference, and topic modeling (LDA).")
169
170# Run examples
171example_convergent()
172example_divergent()
173symbolic_examples()
174ml_log_likelihood()

Comparison Tests and p-Test

Implementing convergence tests programmatically:

Convergence Testing
🐍convergence_tests.py
7P-Test for Discontinuities

The p-test for discontinuities at x = a states that the integral of 1/(x-a)^p converges if p < 1 and diverges if p >= 1. This is opposite to the p-test for infinite limits!

23Direct Comparison Test

If 0 <= f(x) <= g(x) near the discontinuity and the integral of g converges, then the integral of f also converges. This is the squeezing principle for improper integrals.

48Limit Comparison Test

If the limit of f(x)/g(x) as x approaches the discontinuity is a finite positive number, then both integrals converge or both diverge. This is often easier than direct comparison.

72Removable Singularity

When (1-cos(x))/x^2 approaches 1/2 as x approaches 0, the singularity is removable. The integral converges because the function is actually bounded.

85Conditional Convergence

An integral can converge conditionally (integral of f converges) even when it does not converge absolutely (integral of |f| diverges). Oscillating functions near singularities often exhibit this behavior.

117 lines without explanation
1import numpy as np
2from scipy import integrate
3import warnings
4
5def p_test_convergence(p: float, a: float = 0, b: float = 1) -> str:
6    """
7    Apply the p-test for integrals of 1/(x-a)^p near x = a.
8
9    For discontinuities at the left endpoint:
10    - Converges if p < 1
11    - Diverges if p >= 1
12
13    This is OPPOSITE to the p-test for infinite intervals!
14    """
15    if p < 1:
16        return f"p = {p} < 1: CONVERGES"
17    elif p == 1:
18        return f"p = {p} = 1: DIVERGES (logarithmic)"
19    else:
20        return f"p = {p} > 1: DIVERGES (power growth)"
21
22def comparison_test_example():
23    """
24    Demonstrate the comparison test for improper integrals.
25
26    If 0 <= f(x) <= g(x) near the discontinuity:
27    - If integral of g converges, so does integral of f
28    - If integral of f diverges, so does integral of g
29    """
30    print("Comparison Test for Improper Integrals")
31    print("=" * 50)
32
33    # Example: Does integral of sin(x)/sqrt(x) from 0 to 1 converge?
34    # Near x = 0: sin(x)/sqrt(x) ≈ x/sqrt(x) = sqrt(x)
35    # Since sqrt(x) is integrable near 0, so is sin(x)/sqrt(x)
36
37    f = lambda x: np.sin(x) / np.sqrt(x) if x > 0 else 0
38    g = lambda x: 1 / np.sqrt(x) if x > 0 else 0  # Comparison function
39
40    eps = 1e-10
41
42    f_result, _ = integrate.quad(f, eps, 1)
43    g_result, _ = integrate.quad(g, eps, 1)
44
45    print("Testing: integral of sin(x)/sqrt(x) from 0 to 1")
46    print(f"  Numerical result: {f_result:.6f}")
47    print()
48    print("Comparison: 0 <= sin(x)/sqrt(x) <= 1/sqrt(x) for x in (0, 1]")
49    print(f"  Integral of 1/sqrt(x) from 0 to 1 = {g_result:.6f} (converges)")
50    print("  Therefore, integral of sin(x)/sqrt(x) CONVERGES")
51
52    return f_result
53
54def limit_comparison_test():
55    """
56    Limit Comparison Test:
57    If lim(x->a) f(x)/g(x) = L where 0 < L < infinity,
58    then integral of f and integral of g both converge or both diverge.
59    """
60    print("\nLimit Comparison Test")
61    print("=" * 50)
62
63    # Example: Does integral of (1 - cos(x))/x^2 from 0 to 1 converge?
64    # Near x = 0: (1 - cos(x))/x^2 ≈ (x^2/2)/x^2 = 1/2
65    # Compare with 1/x^2: limit is 1/2 (finite, positive)
66    # BUT: 1/x^2 diverges, so our integral... let's check!
67
68    # Actually, (1-cos(x))/x^2 -> 1/2 as x -> 0, so it's BOUNDED near 0
69    # The singularity is removable! Let's verify.
70
71    f = lambda x: (1 - np.cos(x)) / (x ** 2) if x > 0 else 0.5
72
73    eps = 1e-10
74    result, _ = integrate.quad(f, eps, 1)
75
76    print("Testing: integral of (1 - cos(x))/x^2 from 0 to 1")
77    print(f"  Near x=0: (1-cos(x))/x^2 ≈ (x^2/2)/x^2 = 1/2")
78    print(f"  The function approaches 1/2 as x -> 0 (removable singularity)")
79    print(f"  Numerical result: {result:.6f}")
80    print("  CONVERGES (the apparent singularity is removable)")
81
82    return result
83
84def absolute_convergence():
85    """
86    Absolute Convergence:
87    If integral of |f(x)| converges, then integral of f(x) converges.
88    The converse is not always true (conditional convergence).
89    """
90    print("\nAbsolute vs Conditional Convergence")
91    print("=" * 50)
92
93    # Example: integral of sin(1/x)/x from 0 to 1
94    # This is conditionally convergent but not absolutely convergent!
95
96    f = lambda x: np.sin(1/x) / x if x > 0 else 0
97    f_abs = lambda x: abs(np.sin(1/x) / x) if x > 0 else 0
98
99    eps = 1e-6
100
101    # The integral oscillates wildly near 0
102    result, _ = integrate.quad(f, eps, 1, limit=100)
103
104    # For the absolute value, we'd need special handling
105    # (it oscillates and decays slowly)
106
107    print("Testing: integral of sin(1/x)/x from 0 to 1")
108    print(f"  Numerical result (with cutoff at {eps}): {result:.6f}")
109    print("  This integral CONDITIONALLY CONVERGES")
110    print("  But integral of |sin(1/x)/x| DIVERGES")
111    print("  (similar to the harmonic series in behavior)")
112
113# Demonstrate p-test
114print("P-Test for Discontinuities at x = 0")
115print("=" * 50)
116for p in [0.5, 0.9, 1.0, 1.5, 2.0]:
117    print(f"  {p_test_convergence(p)}")
118print()
119
120comparison_test_example()
121limit_comparison_test()
122absolute_convergence()

Common Mistakes to Avoid

Mistake 1: Ignoring Interior Discontinuities

Wrong: Evaluating 021x1dx\int_0^2 \frac{1}{x-1} \, dx directly as [lnx1]02[\ln|x-1|]_0^2.

Correct: Split at x=1x = 1 and evaluate each part as an improper integral. (This integral actually diverges.)

Mistake 2: Confusing the p-Test Conditions

Wrong: Thinking 011x2dx\int_0^1 \frac{1}{x^2} \, dx converges because p=2>1p = 2 > 1.

Correct: For discontinuities, the condition is p<1p < 1 for convergence. Since p=2>1p = 2 > 1, this integral diverges.

Mistake 3: Not Checking Both Sides

Wrong: For an interior discontinuity, checking only one side of the integral.

Correct: Both parts must converge for the full integral to converge. If either diverges, the whole integral diverges.

Mistake 4: Applying FTC Across Discontinuities

Wrong: Writing 111x2dx=[1x]11=11=2\int_{-1}^1 \frac{1}{x^2} \, dx = \left[-\frac{1}{x}\right]_{-1}^1 = -1 - 1 = -2.

Correct: The function has a discontinuity at x=0x = 0. We must split and take limits. Both parts diverge, so the integral diverges (not -2!).

Mistake 5: Misidentifying Removable Singularities

Trap: The function 1cosxx2\frac{1 - \cos x}{x^2} looks singular at x=0x = 0, but the limit is 12\frac{1}{2}.

Insight: This is a removable singularity. The integral converges because the function is actually bounded.


Test Your Understanding

Question 1 of 8Score: 0/0

When is an integral improper due to a discontinuous integrand?


Summary

Improper integrals with discontinuous integrands require careful handling using limits to avoid the singular points.

Key Definitions

TypeDefinition
Left endpointlim(t→a⁺) ∫ₜᵇ f(x) dx
Right endpointlim(t→b⁻) ∫ₐᵗ f(x) dx
Interior point c∫ₐᶜ f(x) dx + ∫ᶜᵇ f(x) dx (both must converge)

The p-Test (Discontinuities)

IntegralConverges ifDiverges if
∫ₐᵇ 1/(x-a)^p dxp < 1p ≥ 1
∫ₐᵇ 1/(b-x)^p dxp < 1p ≥ 1

Key Takeaways

  1. Identify discontinuities: Check endpoints and interior points for vertical asymptotes
  2. Use limits: Replace problematic points with variables and take limits
  3. Split interior discontinuities: Both parts must converge independently
  4. Apply p-test: Converges if p<1p < 1, diverges if p1p \geq 1
  5. Use comparison: Compare to known convergent/divergent integrals
  6. Watch for removable singularities: Some apparent singularities are actually bounded
The Core Insight:
"A vertical asymptote does not automatically mean infinite area. The integral converges if the function approaches infinity slowly enough that the total area remains finite."
Coming Next: In Comparison Tests for Improper Integrals, we'll develop systematic techniques for determining convergence without explicitly computing the integral.
Loading comments...