Chapter 2 Techniques of Integration

2.1 Why integration matters in probability

Differentiation studies local rates of change; integration accumulates small contributions into a total. In probability, this distinction is fundamental. A continuous density describes probability per unit of measurement, while an integral converts that density into an actual probability. The same operation produces expected losses, moments, survival probabilities, and discounted actuarial values.

This chapter is a focused calculus review. The goal is not to catalogue every integration trick, but to recognize the techniques needed later for continuous probability models.

After this chapter, you should be able to:

  • identify an antiderivative and evaluate a definite integral;
  • use substitution and integration by parts;
  • distinguish signed integral from geometric area;
  • approximate an integral numerically in R;
  • determine whether an improper integral converges;
  • interpret integrals that occur in probability, finance, and actuarial science.

2.2 Antiderivatives and definite integrals

An integral can represent either a family of antiderivatives or an accumulated quantity over an interval. Keeping these two meanings separate prevents many errors.

An antiderivative of \(f\) is a function \(F\) satisfying \(F'(x)=f(x)\). The indefinite integral denotes the family \[\int f(x)\,dx=F(x)+C,\] where \(C\) is an arbitrary constant.

The Fundamental Theorem of Calculus connects differentiation and integration. If \(F'(x)=f(x)\) on \([a,b]\), then \[\int_a^b f(x)\,dx=F(b)-F(a).\]

The definite integral is net accumulation: contributions above the horizontal axis are positive and those below it are negative. It is a number, so it does not include an arbitrary constant.

# Exact numerical evaluation of a definite integral in R
integrate(function(x) x^2, lower = 0, upper = 2)
## 2.666667 with absolute error < 3e-14

The result \(8/3\) agrees with \([x^3/3]_0^2\).

2.3 Integration by substitution

Substitution reverses the chain rule. It is useful when an integrand contains a composite expression together with, or close to, its derivative.

If \(u=g(x)\) and \(du=g'(x)\,dx\), then \[\int f(g(x))g'(x)\,dx=\int f(u)\,du.\] For definite integrals, the limits may also be transformed from \(x\)-values to the corresponding \(u\)-values.

Worked example

Evaluate \[\int 6(x^2+2x+3)^6(x+1)\,dx.\]

Let \(u=x^2+2x+3\). Then \(du=2(x+1)\,dx\), so \[\int 6(x^2+2x+3)^6(x+1)\,dx =3\int u^6\,du =\frac{3}{7}u^7+C.\]

Therefore, \[\boxed{\frac{3}{7}(x^2+2x+3)^7+C}.\]

A good substitution simplifies the entire integral. After selecting \(u\), every occurrence of \(x\) and \(dx\) should be replaced before integrating.

2.3.1 Probability connection

For an Exponential density \(f(x)=\lambda e^{-\lambda x}\), the tail probability is \[\mathbb{P}(X>t)=\int_t^\infty \lambda e^{-\lambda x}\,dx=e^{-\lambda t}.\] The substitution \(u=\lambda x\) shows that changing the rate rescales time.

lambda <- 0.4
t <- 5
numerical <- integrate(function(x) lambda * exp(-lambda*x),
                       lower = t, upper = Inf)$value
c(numerical = numerical, formula = exp(-lambda*t))
## numerical   formula 
## 0.1353353 0.1353353

2.4 Integration by parts

Products such as \(x e^x\), \(x^2e^x\), and \(\log x\) do not usually simplify through substitution. Integration by parts reverses the product rule.

If \(u=u(x)\) and \(v=v(x)\) are differentiable, then \[\int u\,dv=uv-\int v\,du.\] For definite integrals, \[\int_a^b u\,dv=[uv]_a^b-\int_a^b v\,du.\]

Worked example

To evaluate \(\int x^2e^x\,dx\), choose \(u=x^2\) and \(dv=e^x\,dx\). Applying the rule twice gives \[\int x^2e^x\,dx=e^x(x^2-2x+2)+C.\]

We can verify the antiderivative by differentiating it symbolically in spirit, or numerically by comparing a definite integral.

numeric_value <- integrate(function(x) x^2 * exp(x), 0, 1)$value
F <- function(x) exp(x) * (x^2 - 2*x + 2)
c(integrate = numeric_value, antiderivative = F(1) - F(0))
##      integrate antiderivative 
##      0.7182818      0.7182818

Expected present values often contain a product of time and an exponential survival or discount factor. Integration by parts turns these products into tractable expressions and is central to deriving moments of lifetime distributions.

2.5 Definite integrals and change of limits

When using substitution in a definite integral, either return to \(x\) before applying the original limits or transform the limits and remain in \(u\). Mixing these approaches is incorrect.

Worked example

Evaluate \[\int_0^1\frac{1}{(1+2x)^4}\,dx.\]

With \(u=1+2x\) and \(du=2\,dx\), the limits become \(u=1\) and \(u=3\): \[\frac12\int_1^3u^{-4}\,du =\left[-\frac{1}{6}u^{-3}\right]_1^3 =\frac{13}{81}.\]

integrate(function(x) 1/(1 + 2*x)^4, 0, 1)
## 0.1604938 with absolute error < 2.4e-10
13/81
## [1] 0.1604938

2.6 Signed integral and geometric area

The signed integral \(\int_a^b f(x)\,dx\) subtracts area below the horizontal axis. The geometric area between the curve and the axis is \[\int_a^b |f(x)|\,dx,\] which is always nonnegative.

Probability densities are nonnegative, so probability integrals already represent area. For a general function that crosses the axis, however, net accumulation and total area are different questions.

f <- function(x) -x * sqrt(pmax(9 - x^2, 0))
signed <- integrate(f, -3, 3)$value
area <- integrate(function(x) abs(f(x)), -3, 3)$value
c(signed_integral = signed, geometric_area = area)
## signed_integral  geometric_area 
##               0              18

The symmetry makes the signed integral zero, while the two regions have total area 18.

2.7 Numerical integration in R

Not every useful integral has an elementary antiderivative. Numerical integration approximates the area using function evaluations. This is especially valuable for custom loss models and likelihood calculations.

A numerical quadrature rule approximates a definite integral by a weighted sum of function values. Accuracy depends on the rule, the number and placement of evaluation points, and the smoothness of the integrand.

2.7.1 Midpoint and trapezoidal rules

For a partition \(a=x_0<\cdots<x_n=b\) of equal width \(h=(b-a)/n\), \[M_n=h\sum_{i=1}^n f\!\left(\frac{x_{i-1}+x_i}{2}\right),\] and \[T_n=h\left[\frac{f(a)+f(b)}2+\sum_{i=1}^{n-1}f(x_i)\right].\]

midpoint <- function(f, a, b, n) {
  h <- (b-a)/n
  mids <- a + ((1:n)-0.5)*h
  h * sum(f(mids))
}
trapezoid <- function(f, a, b, n) {
  h <- (b-a)/n
  x <- seq(a, b, length.out=n+1)
  h * (sum(f(x)) - (f(a)+f(b))/2)
}
f <- function(x) exp(-x^2/2)/sqrt(2*pi)
c(midpoint = midpoint(f, -1, 1, 100),
  trapezoid = trapezoid(f, -1, 1, 100),
  integrate = integrate(f, -1, 1)$value,
  pnorm = pnorm(1)-pnorm(-1))
##  midpoint trapezoid integrate     pnorm 
## 0.6826976 0.6826734 0.6826895 0.6826895

Agreement among several numerical methods is useful evidence, but it is not a proof. R’s integrate() also reports an estimated absolute error, which should be checked when accuracy matters.

2.8 Improper integrals

Probability models frequently extend to infinity. An infinite endpoint is handled through a limit, not by substituting the symbol \(\infty\) as though it were a number.

An improper integral has an infinite interval or an unbounded integrand. For example, \[\int_a^\infty f(x)\,dx =\lim_{b\to\infty}\int_a^b f(x)\,dx.\] It converges when the limit exists and is finite; otherwise it diverges.

Two contrasting examples

The integral \[\int_1^\infty \frac{2}{x^{3/2}}\,dx=4\] converges, whereas \[\int_0^\infty (x^2+1)\,dx\] diverges.

For the power-tail integral, \[\int_1^\infty x^{-p}\,dx\] converges exactly when \(p>1\).

convergent <- integrate(function(x) 2/x^(3/2), 1, Inf)
convergent
## 4 with absolute error < 5.3e-15
# A growing finite upper limit reveals divergence
upper <- c(1, 5, 20, 100)
data.frame(upper,
           integral = upper^3/3 + upper)
##   upper     integral
## 1     1 1.333333e+00
## 2     5 4.666667e+01
## 3    20 2.686667e+03
## 4   100 3.334333e+05

2.8.1 Why convergence matters in probability

A proposed density on \([0,\infty)\) must have a finite integral that can be normalized to one. Even if a density integrates to one, its mean may still be infinite.

Heavy-tailed claim models can have finite total probability but infinite expected claim size. This is not merely a calculus curiosity: it changes whether premium principles based on the mean are mathematically meaningful.

# Pareto density with shape alpha and minimum 1
alpha <- 1.5
dpareto <- function(x) ifelse(x >= 1, alpha/x^(alpha+1), 0)
c(total_probability = integrate(dpareto, 1, Inf)$value,
  expected_loss = integrate(function(x) x*dpareto(x), 1, Inf)$value)
## total_probability     expected_loss 
##                 1                 3

2.9 Applications to probability and risk

2.9.1 From a density to probabilities

If \(X\) has density \(f\), then \[\mathbb{P}(a<X\le b)=\int_a^b f(x)\,dx.\] The integral accumulates the infinitely small probability contributions across the interval.

2.9.2 Expected value as a weighted integral

For a continuous loss \(X\), \[\mathbb{E}(X)=\int_{-\infty}^{\infty}x f(x)\,dx.\] The factor \(x\) gives larger outcomes proportionally more influence, while \(f(x)\,dx\) supplies their probability weight.

If a continuously compounded return \(R\) is modeled by a density \(f_R\), the expected gross growth factor is \[\mathbb{E}(e^R)=\int_{-\infty}^{\infty}e^r f_R(r)\,dr.\] This illustrates why nonlinear transformations cannot generally be evaluated by simply transforming the mean.

For a nonnegative lifetime \(T\) with survival function \(S_T(t)=\mathbb{P}(T>t)\), \[\mathbb{E}(T)=\int_0^\infty S_T(t)\,dt,\] provided the integral converges. This tail-integral identity is widely used in survival and actuarial calculations.

Practice exercises

  1. Evaluate \(\int 4x(x^2+5)^3\,dx\) by substitution.
  2. Evaluate \(\int_0^2 xe^x\,dx\) by integration by parts.
  3. Find both the signed integral and geometric area for \(f(x)=x-1\) on \([0,3]\).
  4. Approximate \(\int_0^1e^{-x^2}\,dx\) with midpoint rules using \(n=10,100,1000\). Compare with integrate().
  5. Determine whether \(\int_1^\infty x^{-0.8}\,dx\) converges.
  6. Verify numerically that an Exponential\((0.25)\) density integrates to one and has mean four.
  7. A Pareto loss has density \(f(x)=2x^{-3}\) for \(x\ge1\). Compute \(\mathbb{P}(X>5)\) and \(\mathbb{E}(X)\).
  8. Explain why \(\int_a^b f(x)\,dx\) can be negative for a general function but cannot be negative when \(f\) is a probability density.
Selected answers
  1. \((x^2+5)^4/2+C\).
  2. \(e^2+1\).
  3. Signed integral \(3/2\); geometric area \(5/2\).
  4. It diverges because \(p=0.8\le1\).
  5. The total probability is 1 and the mean is \(1/0.25=4\).
  6. \(\mathbb{P}(X>5)=1/25\) and \(\mathbb{E}(X)=2\).

2.10 Chapter summary

Substitution reverses the chain rule, while integration by parts reverses the product rule. The Fundamental Theorem evaluates definite integrals from antiderivatives; numerical quadrature handles integrals without convenient closed forms; and improper integrals use limits to decide whether infinite-range accumulation is finite. These tools will reappear when we compute continuous probabilities, moments, survival quantities, and risk measures.