Module contents
Lesson 2 of 20Review 90 min

The Riemann integral and the fundamental theorem of calculus

A review of the Riemann integral through Darboux sums, both parts of the fundamental theorem of calculus, frequently used integration techniques (substitution and parts), and improper integrals, with the Gamma function as a first serious example. Convergence of improper integrals is emphasized because it determines whether expectations and moments exist.

After this lesson you can

  • Define the Riemann integral using Darboux sums and decide integrability of monotone, continuous and pathological functions.
  • Prove the fundamental theorem of calculus and use it to relate accumulation to rate of change.
  • Apply substitution and integration by parts while controlling boundary terms.
  • Determine convergence of improper integrals by comparison with powers and exponentials.
  • Define the Gamma function, prove Γ(n + 1) = n!, and recognize it in power-times-exponential integrals.

Before you start

Motivation: almost everything continuous is an integral

In machine learning and probability, the integral appears before any other calculus tool, almost always in disguise:

  • Expectations. If XX has density pp, E[f(X)]=∫f(x) p(x) ⁣dx\E[f(X)] = \int f(x)\,p(x)\dd x. Expected loss, risk R(θ)=E[ℓ(fθ(X),Y)]R(\theta) = \E[\ell(f_\theta(X), Y)], is an integral; empirical loss is a sum approximating it. Whether an expectation exists is a question about convergence of an improper integral, and the answer is not always yes: the Cauchy distribution has no mean.
  • Normalization constants. A density is a nonnegative function divided by its integral. The normal has 2π\sqrt{2\pi}, the Gamma family has Γ(α)\Gamma(\alpha), and in energy-based models, pθ(x)=e−Eθ(x)/Z(θ)p_\theta(x) = e^{-E_\theta(x)}/Z(\theta), all the difficulty lies in Z(θ)=∫e−Eθ(x) ⁣dxZ(\theta) = \int e^{-E_\theta(x)}\dd x.
  • Accumulation. Distribution function F(x)=P(X≤x)F(x) = \Pr(X \le x) accumulates the density, and density is the rate of change of FF. This pair, accumulation and differentiation, is the fundamental theorem of calculus.
  • Sums and integrals at once. A variable that is 0 with probability 0.30.3 and otherwise exponential has no density and is not discrete. Its expectation is neither a sum nor a Riemann integral, but is ∫f ⁣dF\int f\dd F, a Riemann–Stieltjes integral.

This lesson reviews the single-variable Riemann integral with the rigor needed to trust it: when it exists, why the derivative of accumulation is the integrand, how to manipulate it (substitution and parts, without losing boundary terms), when an improper integral converges and how one formula unifies sums and integrals. It ends with function Γ\Gamma, appearing in every moment, volume and normalization in the rest of the course. It uses continuity, the derivative and the mean value theorem from the preceding lesson.

Intuition: trapping area between two staircases

To measure area under a positive curve ff on [a,b][a, b], cut it into vertical strips. In each strip, the rectangle of height equal to the minimum of ff fits under the curve, and the rectangle of height equal to the maximum contains it. The sum of the first gives a lower approximation; the second, an upper one. If refining the strips brings the staircases arbitrarily close, the area is trapped between them and its value is unambiguous. If they do not approach, “area” has no unique meaning.

InteractiveDarboux sums closing in
  • lower sum LL: rectangles of height mim_i
  • U−LU - L: bands between mim_i and MiM_i
U−LU - L with nn equal subintervals (logarithmic scales)
  • U − L, uniform partition
  • reference 1/n
Partition
6
Subintervals6
Mesh ∥P∥\|P\|0.1667
Lower sum L(f,P)L(f, P)0.4623
Upper sum U(f,P)U(f, P)0.6877
U−LU - L0.2254
∫01f\int_0^1 f0.5750
Continuous on [0,1][0, 1], hence uniformly continuous: on short intervals Mi−miM_i - m_i is simultaneously small and U−L→0U - L \to 0.
Blue rectangles are the lower sum, height mi=inf⁡fm_i = \inf f on each subinterval; orange strips run from mim_i to Mi=sup⁡fM_i = \sup f, so their total area is exactly U−LU - L. Increase nn with the continuous function and watch orange vanish. In free mode, drag points or press ‘Refine where most is contributed’ and check refinement never increases U−LU - L. Then try Dirichlet's function (does orange decrease at all?), Thomae's, discontinuous at every rational, and sin⁡(1/x)\sin(1/x). The lower graph shows U−LU - L versus nn on logarithmic axes: the monotone function's slope is that of 1/n1/n.

Four things the figure shows and the rest of the section turns into theorems:

  1. Refining always helps. Adding a partition point never lowers the lower sum or raises the upper sum.
  2. Rate depends on the function. For the continuous and monotone functions, U−LU - L falls like 1/n1/n: the logarithmic graph’s slope is −1-1.
  3. Some functions cannot be trapped. With the rational indicator, every subinterval contains rationals and irrationals, so Mi=1M_i = 1 and mi=0m_i = 0 for any partition. Orange always fills everything.
  4. But many discontinuities do not suffice to prevent it. Thomae’s function jumps at every rational and still U−L→0U - L \to 0, though more slowly than 1/n1/n. With sin⁡(1/x)\sin(1/x), discontinuous only at 0, the gap also closes, but at rate 1/n1/\sqrt{n} (slope −1/2-1/2): near 0, about n/2π\sqrt{n/2\pi} subintervals contain a complete oscillation and each contributes the full amplitude.

Darboux sums

Let f:[a,b]→Rf: [a, b] \to \R be bounded. A partition of [a,b][a, b] is a finite set P={x0,x1,…,xn}P = \{x_0, x_1, \dots, x_n\} with a=x0<x1<⋯<xn=ba = x_0 < x_1 < \cdots < x_n = b. Write Δxi=xi−xi−1\Delta x_i = x_i - x_{i-1} and call the mesh of PP the quantity ∥P∥=max⁡iΔxi\norm{P} = \max_i \Delta x_i. On each subinterval,

mi=inf⁡x∈[xi−1,xi]f(x),Mi=sup⁡x∈[xi−1,xi]f(x),m_i = \inf_{x \in [x_{i-1}, x_i]} f(x), \qquad M_i = \sup_{x \in [x_{i-1}, x_i]} f(x),

which exist because ff is bounded. The lower and upper Darboux sums are

L(f,P)=∑i=1nmi Δxi,U(f,P)=∑i=1nMi Δxi.L(f, P) = \sum_{i=1}^n m_i\,\Delta x_i, \qquad U(f, P) = \sum_{i=1}^n M_i\,\Delta x_i .

A partition QQ is a refinement of PP if P⊆QP \subseteq Q.

Proof

Adding one point suffices, because QQ is obtained from PP by adding points one at a time. Let y∈(xk−1,xk)y \in (x_{k-1}, x_k). On each half, the infimum of ff is at least mkm_k, being an infimum over a smaller set. Calling those infima m′m' and m′′m'', mk Δxk=mk(y−xk−1)+mk(xk−y)≤m′(y−xk−1)+m′′(xk−y)m_k\,\Delta x_k = m_k(y - x_{k-1}) + m_k(x_k - y) \le m'(y - x_{k-1}) + m''(x_k - y), and other terms do not change: LL does not decrease. The argument for UU is the same with suprema. The middle inequality, L(f,Q)≤U(f,Q)L(f, Q) \le U(f, Q), is mi≤Mim_i \le M_i term by term. For the consequence, take the common refinement Q=P1∪P2Q = P_1 \cup P_2: L(f,P1)≤L(f,Q)≤U(f,Q)≤U(f,P2)L(f, P_1) \le L(f, Q) \le U(f, Q) \le U(f, P_2).

∎

Thus any lower sum lies below any upper sum. The supremum of the former and infimum of the latter exist and satisfy

∫ab‾f=sup⁡PL(f,P)  ≤  inf⁡PU(f,P)=∫ab‾f.\underline{\int_a^b} f = \sup_P L(f, P) \;\le\; \inf_P U(f, P) = \overline{\int_a^b} f .

Comparing infima and suprema over all partitions is cumbersome. The following criterion reduces integrability to finding one good partition for each tolerance, as you did in the figure.

Proof

If such a partition exists for every ε\eps, then 0≤∫‾f−∫‾f≤U(f,P)−L(f,P)<ε0 \le \overline{\int} f - \underline{\int} f \le U(f, P) - L(f, P) < \eps for every ε>0\eps > 0, and the two integrals agree. Conversely, if they agree and equal II, by definition of supremum and infimum there are partitions P1P_1 and P2P_2 with L(f,P1)>I−ε/2L(f, P_1) > I - \eps/2 and U(f,P2)<I+ε/2U(f, P_2) < I + \eps/2. Their common refinement PP satisfies, by the lemma, U(f,P)−L(f,P)≤U(f,P2)−L(f,P1)<εU(f, P) - L(f, P) \le U(f, P_2) - L(f, P_1) < \eps.

∎

Riemann sums and mesh

Riemann’s sums choose a point ti∈[xi−1,xi]t_i \in [x_{i-1}, x_i] in each subinterval (a tag; the partition is a tagged partition) and evaluate the function there:

S(f,P,t)=∑i=1nf(ti) Δxi.S(f, P, t) = \sum_{i=1}^n f(t_i)\,\Delta x_i .

Since mi≤f(ti)≤Mim_i \le f(t_i) \le M_i, always L(f,P)≤S(f,P,t)≤U(f,P)L(f, P) \le S(f, P, t) \le U(f, P): Riemann sums are trapped between Darboux sums, whatever the tag. Midpoint, trapezoid and Simpson rules are sums of this kind (or averages of them), so every quadrature method starts here (Newton–Cotes rules). The practical question is whether making the mesh small suffices, without worrying where points fall.

Proof

If Riemann sums converge to II in that sense, take PP with ∥P∥<δ\norm{P} < \delta. Choosing tags where ff is within ε/(b−a)\eps/(b - a) of MiM_i gives U(f,P)≤S+ε≤I+2εU(f, P) \le S + \eps \le I + 2\eps, and similarly L(f,P)≥I−2εL(f, P) \ge I - 2\eps, so U−L≤4εU - L \le 4\eps and ff is integrable by the criterion, with integral II.

Conversely, let ∣f∣≤K\abs{f} \le K with K>0K > 0 and let ε>0\eps > 0. By the criterion there is a partition P0P_0 with U(f,P0)−L(f,P0)<ε/2U(f, P_0) - L(f, P_0) < \eps/2; let k≥1k \ge 1 be its interior points (if none, add one: by the lemma refinement does not increase the gap). Take δ=ε/(8Kk)\delta = \eps/(8Kk) and a partition PP with ∥P∥<δ\norm{P} < \delta. Passing from PP to P∪P0P \cup P_0, only subintervals of PP containing some point of P0P_0 in their interior change, at most kk of them; in each the upper sum changes by at most 2K Δxi<2Kδ2K\,\Delta x_i < 2K\delta. Therefore U(f,P)≤U(f,P∪P0)+2KkδU(f, P) \le U(f, P \cup P_0) + 2Kk\delta and, similarly, L(f,P)≥L(f,P∪P0)−2KkδL(f, P) \ge L(f, P \cup P_0) - 2Kk\delta. Using the lemma,

U(f,P)−L(f,P)≤U(f,P0)−L(f,P0)+4Kkδ<ε2+ε2=ε.U(f, P) - L(f, P) \le U(f, P_0) - L(f, P_0) + 4Kk\delta < \tfrac{\eps}{2} + \tfrac{\eps}{2} = \eps .

Since S(f,P,t)S(f, P, t) and II both lie in [L(f,P),U(f,P)][L(f, P), U(f, P)], ∣S(f,P,t)−I∣<ε\abs{S(f, P, t) - I} < \eps.

∎

Which functions are integrable

Proof

(1) If ff is increasing, on [xi−1,xi][x_{i-1}, x_i] the infimum is f(xi−1)f(x_{i-1}) and supremum f(xi)f(x_i), wherever jumps occur. Then

U−L=∑i=1n(f(xi)−f(xi−1)) Δxi≤∥P∥∑i=1n(f(xi)−f(xi−1))=∥P∥ (f(b)−f(a)),U - L = \sum_{i=1}^n \big(f(x_i) - f(x_{i-1})\big)\,\Delta x_i \le \norm{P}\sum_{i=1}^n \big(f(x_i) - f(x_{i-1})\big) = \norm{P}\,\big(f(b) - f(a)\big),

because the sum telescopes; with Δxi=(b−a)/n\Delta x_i = (b - a)/n the inequality is equality. If ff is decreasing, apply the above to −f-f.

(2) A continuous function on a closed bounded interval is uniformly continuous (Heine–Cantor theorem): given ε>0\eps > 0 there is δ>0\delta > 0 such that ∣x−y∣<δ\abs{x - y} < \delta implies ∣f(x)−f(y)∣<ε/(b−a)\abs{f(x) - f(y)} < \eps/(b - a), the same δ\delta for every point. If ∥P∥<δ\norm{P} < \delta, on every subinterval Mi−mi≤ε/(b−a)M_i - m_i \le \eps/(b - a), and U−L≤∑iε Δxi/(b−a)=εU - L \le \sum_i \eps\,\Delta x_i/(b - a) = \eps.

∎

The first part is more useful than it looks: it gives a certificate. For a monotone function, the true integral lies in [L,U][L, U] and that interval has exact length ∣f(b)−f(a)∣(b−a)/n\abs{f(b) - f(a)}(b - a)/n, with no unknown constants. You will implement this below. The second explains why uniform continuity is needed: with ff continuous on (0,1](0, 1] but unbounded, like 1/x1/x, no partition works, because the first subinterval has M1=∞M_1 = \infty.

The same argument extends to bounded functions with finitely many discontinuities: surround each by an arbitrarily short subinterval, whose contribution to U−LU - L is at most 2sup⁡∣f∣2\sup\abs{f} times its length, and use uniform continuity on the rest. This integrates sin⁡(1/x)\sin(1/x) on [0,1][0, 1], which oscillates infinitely often but is discontinuous only at 0. Infinitely many discontinuities require closer examination.

The difference is not the number of discontinuities but their “size.” The exact result is Lebesgue’s.

Every countable set has measure zero (cover its kk-th point by an interval of length ε/2k+1\eps/2^{k+1}), so Thomae, discontinuous on Q\Q, is integrable, and Dirichlet, discontinuous everywhere, is not. There are also uncountable measure-zero sets, such as the Cantor set, and the Cantor set’s indicator is integrable with integral 0. The proof of the criterion and the theory resolving Dirichlet’s case (it is Lebesgue integrable with integral 0) are in the Lebesgue integral, built on Lebesgue measure.

Properties used without thinking

For ff and gg integrable on [a,b][a, b] and c∈(a,b)c \in (a, b), all follow from Darboux sums:

  • Linearity: ∫(αf+βg)=α∫f+β∫g\int (\alpha f + \beta g) = \alpha\int f + \beta\int g.
  • Monotonicity: if f≤gf \le g, ∫f≤∫g\int f \le \int g. In particular, ∣∫f∣≤∫∣f∣≤(b−a)sup⁡∣f∣\abs{\int f} \le \int \abs{f} \le (b - a)\sup\abs{f}, because ∣f∣\abs{f} is also integrable (Mi−miM_i - m_i does not increase on taking absolute value).
  • Additivity: ff is integrable on [a,c][a, c] and [c,b][c, b], and ∫abf=∫acf+∫cbf\int_a^b f = \int_a^c f + \int_c^b f. With the orientation convention, the formula holds for a,b,ca, b, c in any order.
  • Products and compositions: fgfg is integrable, and φ∘f\varphi \circ f also if φ\varphi is continuous.
  • Changing ff at finitely many points does not change the integral (or integrability).
Proof

By the extreme value theorem, ff attains a minimum mm and maximum MM, and by monotonicity m(b−a)≤∫abf≤M(b−a)m(b - a) \le \int_a^b f \le M(b - a). Number 1b−a∫abf\frac{1}{b - a}\int_a^b f lies between mm and MM, and by the intermediate value theorem is a value f(c)f(c).

∎

The fundamental theorem of calculus

So far integration is a limiting process: no formula. What makes the integral calculable is that accumulation and differentiation are inverse operations. If ff is integrable on [a,b][a, b], the indefinite integral

F(x)=∫axf(t) ⁣dt,x∈[a,b],F(x) = \int_a^x f(t)\dd t, \qquad x \in [a, b],

measures signed area accumulated up to xx. Its increment between xx and x+hx + h is the area of a narrow strip, F(x+h)−F(x)=∫xx+hfF(x + h) - F(x) = \int_x^{x+h} f, and if ff barely changes on the strip, that area is nearly f(x) hf(x)\,h. Dividing by hh: the rate at which area grows is curve height.

InteractiveAccumulation and rate
Integrand ff and signed area accumulated over [0,x][0, x]
Accumulated area F(x)=∫0xf(t) dtF(x) = \int_0^x f(t)\,\mathrm{d}t and its slope
  • positive area
  • negative area
  • height f(x)f(x) and tangent of slope f(x)f(x)
  • strip [x,x+h][x, x + h] and its secant
0.40
xx1.20
F(x)=∫0xfF(x) = \int_0^x f1.8299
Height f(x)f(x)1.0070
F(x+h)−F(x)h\dfrac{F(x + h) - F(x)}{h}0.7563
Where f<0f < 0 area counts negatively and FF decreases. Maxima of FF occur where ff changes sign from ++ to −-.
Above, ff and signed area accumulated at [0,x][0, x] (blue if f>0f > 0, red if f<0f < 0); below, curve F(x)=∫0xfF(x) = \int_0^x f traced by that area, with tangent of slope f(x)f(x) in magenta. The gold strip has area F(x+h)−F(x)F(x + h) - F(x) and its height is the difference quotient. Drag xx or press ‘Traverse’ and compare readouts of f(x)f(x) and the quotient; then reduce hh. Choose the jump function and move xx to 2: FF has a peak and two one-sided slopes. With the function changed at one point, FF does not notice. With the peak, FF is differentiable everywhere with F′=fF' = f: it is class C1C^1, with no corners.

These two statements, the derivative of accumulation is the integrand and the integral of a derivative is the increment, are the fundamental theorem of calculus. The Lipschitz bound in part 1 is immediate: ∣F(y)−F(x)∣=∣∫xyf∣≤K∣y−x∣\abs{F(y) - F(x)} = \abs{\int_x^y f} \le K\abs{y - x}. You will prove the derivative at a continuity point in a guided exercise, using the strip argument.

ProofProof of part 2

Let PP be any partition of [a,b][a, b]. By the mean value theorem applied to GG on each [xi−1,xi][x_{i-1}, x_i], there is ti∈(xi−1,xi)t_i \in (x_{i-1}, x_i) with G(xi)−G(xi−1)=G′(ti) Δxi=f(ti) ΔxiG(x_i) - G(x_{i-1}) = G'(t_i)\,\Delta x_i = f(t_i)\,\Delta x_i. Summing, the telescoping sum gives

G(b)−G(a)=∑i=1nf(ti) Δxi=S(f,P,t),G(b) - G(a) = \sum_{i=1}^n f(t_i)\,\Delta x_i = S(f, P, t),

which lies between L(f,P)L(f, P) and U(f,P)U(f, P). Thus G(b)−G(a)G(b) - G(a) lies between L(f,P)L(f, P) and U(f,P)U(f, P) for every partition; since ff is integrable, the only number with that property is ∫abf\int_a^b f.

∎

Notice what part 2 does not require: ff need not be continuous, only integrable, and GG differentiable throughout the interior with G′=fG' = f. The two assumptions are independent and neither can be omitted:

  • Integrable without an antiderivative. An ff with a jump, like the figure’s, is integrable but is not the derivative of any function on the entire interval: by Darboux’s theorem every derivative has the intermediate value property, which a jump function lacks. Its indefinite integral FF exists, is continuous and has a corner at the jump, with one-sided derivatives f(c−)f(c^-) and f(c+)f(c^+); in the figure, since slope passes from positive to negative, the corner is also a peak.
  • Antiderivative without integrability. G(x)=x2sin⁡(1/x2)G(x) = x^2\sin(1/x^2), with G(0)=0G(0) = 0, is differentiable on all R\R, but G′(x)=2xsin⁡(1/x2)−(2/x)cos⁡(1/x2)G'(x) = 2x\sin(1/x^2) - (2/x)\cos(1/x^2) is unbounded near 0, so G′G' is not Riemann integrable on [0,1][0, 1]. Formula ∫01G′=G(1)−G(0)\int_0^1 G' = G(1) - G(0) still holds as an improper integral, but not as a Riemann integral.

And notice the figure’s third option: f(x)=1.4−0.9∣x−2∣f(x) = 1.4 - 0.9\abs{x - 2} is not differentiable at 2, but is continuous, so F′=fF' = f everywhere and FF is class C1C^1. Integrating smooths by one degree; differentiating removes one. Thus accumulation of noise (a random path, a sum of errors) is more regular than the noise.

Substitution and integration by parts

The fundamental theorem turns every differentiation rule into an integration rule. The two used constantly, grouped as integration techniques, follow from the chain and product rules.

Proof

Since ff is continuous on interval JJ, it has an antiderivative Φ(x)=∫x0xf\Phi(x) = \int_{x_0}^x f on JJ by part 1 of the fundamental theorem. By the chain rule, (Φ∘φ)′=f(φ) φ′(\Phi \circ \varphi)' = f(\varphi)\,\varphi', which is continuous. Apply part 2 to both sides: both equal Φ(φ(β))−Φ(φ(α))\Phi(\varphi(\beta)) - \Phi(\varphi(\alpha)).

∎

φ\varphi need not be injective or monotone: if φ\varphi goes out and back, segments traversed twice cancel with sign. This is specific to one variable and oriented integrals. In several variables, the change-of-variables formula integrates over unoriented sets, requires a bijection and uses ∣det⁡∣\abs{\det} of the Jacobian instead of φ′\varphi'.

Proof

(uv)′=u′v+uv′(uv)' = u'v + uv' is continuous, so by part 2, ∫ab(u′v+uv′)=u(b)v(b)−u(a)v(a)\int_a^b (u'v + uv') = u(b)v(b) - u(a)v(a). Separate the integral of the sum.

∎

Term [uv]ab[uv]_a^b is the boundary term. On a bounded interval it is calculated and that is it. On an unbounded interval or with an integrand singular at an endpoint, integrate on [ε,R][\eps, R] and take limits: the formula still holds if two of the three limits (left side, boundary term and right integral) exist, because then the third does too. Many useful identities reduce to the boundary term vanishing, which must be justified each time.

Improper integrals

The Riemann integral requires a bounded interval and bounded function. Expectations, normalizations and function Γ\Gamma break both conditions. The solution is to integrate where possible and take a limit.

The last condition matters: lim⁡R→∞∫−RRf\lim_{R\to\infty}\int_{-R}^R f, the Cauchy principal value, can exist even when the integral diverges. We will see this with the Cauchy distribution.

Proof

For p≠1p \neq 1, ∫1Rx−p ⁣dx=(R1−p−1)/(1−p)\int_1^R x^{-p}\dd x = (R^{1-p} - 1)/(1 - p), tending to 1/(p−1)1/(p - 1) if p>1p > 1 and to ∞\infty if p<1p < 1. For p=1p = 1, ∫1Rx−1 ⁣dx=ln⁡R→∞\int_1^R x^{-1}\dd x = \ln R \to \infty. At the origin, ∫ε1x−p ⁣dx=(1−ε1−p)/(1−p)\int_\eps^1 x^{-p}\dd x = (1 - \eps^{1-p})/(1 - p) for p≠1p \neq 1 and ln⁡(1/ε)\ln(1/\eps) for p=1p = 1, and the reasoning is the same.

∎

The thresholds are the same, p=1p = 1, but in opposite directions: the tail needs the function to fall quickly (large exponent) and the origin needs it not to blow up quickly (small exponent). Hence no power is integrable on all of (0,∞)(0, \infty). With x↦1/xx \mapsto 1/x the two questions switch: ∫ε1x−p ⁣dx=∫11/εyp−2 ⁣dy\int_\eps^1 x^{-p}\dd x = \int_1^{1/\eps} y^{p - 2}\dd y.

InteractiveDoes the tail converge?
Integrand x−px^{-p} and both areas
tail continues to 10 →
Accumulated area as RR and 1/ε1/\varepsilon increase
  • tail ∫₁ᴿ
  • origin ∫ε¹
  • tail limit
  • area at the origin, [ε,1][\varepsilon, 1]
  • tail area, [1,R][1, R]
Mode
1.50
10
1/10
∫1Rx−p dx\int_1^R x^{-p}\,\mathrm{d}x1.368
∫ε1x−p dx\int_\varepsilon^1 x^{-p}\,\mathrm{d}x4.325
Limits: tail, origin2.000, ∞
p>1p > 1: the tail converges to 1/(p−1)=2.0001/(p - 1) = 2.000 and the origin diverges. No pp makes ∫0∞x−p dx\int_0^\infty x^{-p}\,\mathrm{d}x finite.
In ‘Powers’, orange area is ∫ε1x−p\int_\varepsilon^1 x^{-p} and aqua is ∫1Rx−p\int_1^R x^{-p}; on the right, both versus RR and 1/ε1/\varepsilon, with dashed limits when they exist. Move pp on either side of 1 and move RR and ε\varepsilon away: on each side at most one curve stabilizes. Enable ‘View in u=ln⁡xu = \ln x’: the integrand becomes e(1−p)ue^{(1-p)u} and at p=1p = 1 is constant 1, whose area grows without bound in both directions. In ‘Moments’, Student's t with ν\nu degrees of freedom has ∣x∣kp(x)∼Cx−(ν+1−k)|x|^k p(x) \sim C x^{-(\nu + 1 - k)}: move ν\nu to kk or below and the truncated integral stops stabilizing. With ν=1\nu = 1 and k=1k = 1 (Cauchy) it grows like (2/π)ln⁡R(2/\pi)\ln R.

An antiderivative can almost never be calculated. Instead, compare with powers or exponentials.

Proof

(1) Φ(R)=∫aRf\Phi(R) = \int_a^R f is increasing, because f≥0f \ge 0, and bounded by ∫a∞g\int_a^\infty g. A bounded increasing function has a limit (limits of monotone functions, which is real completeness). (2) For large xx, ℓ2g≤f≤2ℓg\tfrac{\ell}{2}g \le f \le 2\ell g; apply (1) both ways from that point. (3) By the Cauchy criterion for limits, ∫aRh\int_a^R h converges if and only if ∣∫RSh∣→0\abs{\int_R^S h} \to 0 as R,S→∞R, S \to \infty, and ∣∫RSh∣≤∫RS∣h∣\abs{\int_R^S h} \le \int_R^S\abs{h}, which tends to 0 because ∫∣h∣\int\abs{h} converges (Cauchy sequences).

∎

The most used comparison tool is that the exponential beats any power: for every a∈Ra \in \R, xae−x/2→0x^a e^{-x/2} \to 0 as x→∞x \to \infty, so xae−x≤Ca e−x/2x^a e^{-x} \le C_a\,e^{-x/2} for x≥1x \ge 1 and ∫1∞xae−x ⁣dx\int_1^\infty x^a e^{-x}\dd x converges for every aa. Similarly, ∫1∞xae−x2 ⁣dx\int_1^\infty x^a e^{-x^2}\dd x converges for every aa. Near the origin, however, e−x→1e^{-x} \to 1 and the power dominates. In Landau notation, only the integrand’s order of magnitude matters at each problematic endpoint: f(x)∼Cx−qf(x) \sim C x^{-q} at infinity converges if and only if q>1q > 1.

Conditional convergence: sin⁡(x)/x\sin(x)/x

The distinction is not a technicality. The Lebesgue integral admits only absolutely integrable integrands, so sin⁡(x)/x\sin(x)/x is not Lebesgue integrable on [0,∞)[0, \infty) even though its improper Riemann integral exists. And an expectation is defined as E[X]=∫x ⁣dF\E[X] = \int x\dd F only when E∣X∣<∞\E\abs{X} < \infty, that is, when the integral converges absolutely (expectation). With merely conditional convergence, rearranging pieces or taking integration limits to infinity differently can change the result.

Bounded variation and the Riemann–Stieltjes integral

Integral ∫f(x) ⁣dx\int f(x)\dd x weights each piece of the axis by its length Δxi\Delta x_i. To write the expectation of any discrete, continuous or mixed variable as one integral, weight by the probability FF assigns to each piece, F(xi)−F(xi−1)F(x_i) - F(x_{i-1}). Replacing Δxi\Delta x_i by Δgi=g(xi)−g(xi−1)\Delta g_i = g(x_i) - g(x_{i-1}) for a general integrator gg works whenever gg does not oscillate too much.

By the triangle inequality, V(g,P)V(g, P) does not decrease on refining PP, so total variation is the limit of variations of increasingly fine partitions: the length of the graph’s vertical travel.

  • Monotone: Vab(g)=∣g(b)−g(a)∣V_a^b(g) = \abs{g(b) - g(a)}, because the sum telescopes. Every distribution function has total variation 1 on R\R.
  • Lipschitz: if ∣g(x)−g(y)∣≤K∣x−y∣\abs{g(x) - g(y)} \le K\abs{x - y}, Vab(g)≤K(b−a)V_a^b(g) \le K(b - a).
  • C1C^1: Vab(g)=∫ab∣g′∣V_a^b(g) = \int_a^b\abs{g'}. By the mean value theorem, V(g,P)=∑i∣g′(ti)∣ΔxiV(g, P) = \sum_i\abs{g'(t_i)}\Delta x_i is a Riemann sum of ∣g′∣\abs{g'}.
  • Continuous without bounded variation: g(x)=xcos⁡(π/(2x))g(x) = x\cos\big(\pi/(2x)\big), with g(0)=0g(0) = 0, is continuous on [0,1][0, 1]. At points 1/(2k)1/(2k) it equals ±1/(2k)\pm 1/(2k) and at 1/(2k+1)1/(2k + 1) it equals 0. The partition formed by 0, 1 and points 1/j1/j with 2≤j≤2K+12 \le j \le 2K + 1 has V(g,P)≥∑k=1K1/(2k)V(g, P) \ge \sum_{k=1}^{K} 1/(2k), unbounded in KK by divergence of the harmonic series.
Proof

If g=g+−g−g = g_+ - g_- with both increasing, V(g,P)≤V(g+,P)+V(g−,P)=(g+(b)−g+(a))+(g−(b)−g−(a))V(g, P) \le V(g_+, P) + V(g_-, P) = (g_+(b) - g_+(a)) + (g_-(b) - g_-(a)). Conversely, let v(x)=Vax(g)v(x) = V_a^x(g). Variation is additive, Vay=Vax+VxyV_a^y = V_a^x + V_x^y for x<yx < y (partitions of [a,y][a, y] containing xx are pairs of partitions of [a,x][a, x] and [x,y][x, y], and adding xx does not decrease variation). Define g+=12(v+g)g_+ = \tfrac12(v + g) and g−=12(v−g)g_- = \tfrac12(v - g), whose sum is vv and difference gg. For x<yx < y, v(y)−v(x)=Vxy(g)≥∣g(y)−g(x)∣v(y) - v(x) = V_x^y(g) \ge \abs{g(y) - g(x)}, so g+(y)−g+(x)=12(Vxy(g)+g(y)−g(x))≥0g_+(y) - g_+(x) = \tfrac12\big(V_x^y(g) + g(y) - g(x)\big) \ge 0, and similarly for g−g_-.

∎

Consequently everything known about monotone functions carries over to bounded-variation functions: they have one-sided limits everywhere, at most countably many discontinuities, all jumps, and are Riemann integrable.

Proof

(1) By Jordan decomposition and linearity of sums in gg, it suffices to treat increasing gg. By uniform continuity, for ε>0\eps > 0 there is δ\delta such that ∣f(s)−f(t)∣<ε\abs{f(s) - f(t)} < \eps if ∣s−t∣<δ\abs{s - t} < \delta. If ∥P∥,∥Q∥<δ\norm{P}, \norm{Q} < \delta, compare both with common refinement RR: each term f(ti)Δgif(t_i)\Delta g_i of PP is split among the subintervals of RR it contains, with tags less than δ\delta apart, so ∣SP−SR∣≤ε∑iΔgi=ε (g(b)−g(a))\abs{S_P - S_R} \le \eps\sum_i\Delta g_i = \eps\,(g(b) - g(a)), and similarly for QQ. The sums satisfy the Cauchy condition as ∥P∥→0\norm{P} \to 0 and converge. The bound follows from ∣S∣≤sup⁡∣f∣∑i∣Δgi∣≤sup⁡∣f∣ Vab(g)\abs{S} \le \sup\abs{f}\sum_i\abs{\Delta g_i} \le \sup\abs{f}\,V_a^b(g).

(2) By the mean value theorem, Δgi=g′(si)Δxi\Delta g_i = g'(s_i)\Delta x_i with si∈(xi−1,xi)s_i \in (x_{i-1}, x_i), so S(f,g,P,t)=∑if(ti)g′(si)ΔxiS(f, g, P, t) = \sum_i f(t_i)g'(s_i)\Delta x_i, differing from Riemann sum ∑if(ti)g′(ti)Δxi\sum_i f(t_i)g'(t_i)\Delta x_i of fg′fg' by at most sup⁡∣f∣⋅ω(∥P∥) (b−a)\sup\abs{f}\cdot\omega(\norm{P})\,(b - a), where ω\omega is the modulus of uniform continuity of g′g'. The two have the same limit.

(3) If ∥P∥\norm{P} is less than the minimum distance between jumps, each jump lies in one subinterval (or at the shared endpoint of two and is split between them), Δgi\Delta g_i is zero on subintervals without jumps and the sum is ∑kf(ti(k))Jk\sum_k f(t_{i(k)})J_k plus terms sharing one jump, with tags less than ∥P∥\norm{P} from ckc_k. By continuity of ff at ckc_k, it converges to ∑kf(ck)Jk\sum_k f(c_k)J_k.

∎

If XX takes values in (a,b](a, b] and its distribution function is the sum of a step part, with atoms at ckc_k, and a class-C1C^1 part with derivative pp (the density), the theorem says that for continuous ff,

E[f(X)]=∫abf ⁣dF=∑kf(ck) P(X=ck)⏟aˊtomos+∫abf(x) p(x) ⁣dx⏟parte con densidad,\E[f(X)] = \int_a^b f\dd F = \underbrace{\sum_k f(c_k)\,\Pr(X = c_k)}_{\text{átomos}} + \underbrace{\int_a^b f(x)\,p(x)\dd x}_{\text{parte con densidad}},

one formula covers discrete, continuous and mixed cases. Equality E[f(X)]=∫f ⁣dF\E[f(X)] = \int f\dd F holds for any FF, including those with neither atoms nor a density (such as the Cantor function); only the right-hand formula requires the decomposition. For unbounded variables take improper limit ∫−∞∞f ⁣dF=lim⁡∫−RSf ⁣dF\int_{-\infty}^{\infty} f\dd F = \lim\int_{-R}^{S} f\dd F, under the same absolute-convergence condition as before.

InteractiveRiemann–Stieltjes sums and expectations
Integrand ff and values at tags tit_i
Integrator gg and polygonal line of increments Δgi\Delta g_i
Contributions f(ti) Δgif(t_i)\,\Delta g_i from each subinterval (their sum is SS)
  • integrand ff
  • integrator gg (distribution function)
  • tags, increments and contributions
Tag tit_i
10
S=∑if(ti) ΔgiS = \sum_i f(t_i)\,\Delta g_i1.9800
E[X]=∫f dF\E[X] = \int f\,\mathrm{d}F1.9500
Error ∣S−∫f dg∣|S - \int f\,\mathrm{d}g|0.0300
Variation ∑i∣Δgi∣\sum_i |\Delta g_i|1.0000
Atoms and density together: the sum converges to 0.2f(1)+0.3f(2.5)+∫f(x) 18 dx0.2 f(1) + 0.3 f(2.5) + \int f(x)\,\tfrac{1}{8}\,\mathrm{d}x. Neither a sum nor a Riemann integral expresses both alone.
Integrator gg is a distribution function on [0,4][0, 4]; the sum weights the value of ff at each tag by increment Δgi\Delta g_i, made visible by the magenta polygonal line. With the mixed distribution, two subintervals containing atoms get tall bars and the rest thin bars: increase nn and watch SS approach E[f(X)]\E[f(X)]. Switch to discrete and continuous: the same formula becomes a sum and an integral with density. Then choose f=1[x>2.5]f = \ind[x > 2.5], which jumps where gg has an atom, and alternate left and right tags with odd nn. Finally, the integrator without bounded variation: does ∑i∣Δgi∣\sum_i |\Delta g_i| stabilize?

What the figure shows for a shared jump is a theorem: if ff and gg are discontinuous at the same point, ∫f ⁣dg\int f\dd g does not exist. If the point lies inside a subinterval, the tag decides whether to count the jump of gg with the value of ff on one side or the other, and the difference does not shrink under refinement. When it exists, the integral satisfies an integration by parts formula without differentiability assumptions: ∫abf ⁣dg+∫abg ⁣df=f(b)g(b)−f(a)g(a)\int_a^b f\dd g + \int_a^b g\dd f = f(b)g(b) - f(a)g(a).

The Gamma function

The most frequent combination of power and exponential deserves its own name.

The integral converges exactly when x>0x > 0. At infinity, the exponential beats power tx−1t^{x-1} for every xx. At the origin, e−t→1e^{-t} \to 1 and the integrand behaves like tx−1=t−(1−x)t^{x-1} = t^{-(1-x)}, integrable on (0,1](0, 1] if and only if 1−x<11 - x < 1, that is, x>0x > 0.

Proof

(1) ∫0∞e−t ⁣dt=lim⁡R(1−e−R)=1\int_0^\infty e^{-t}\dd t = \lim_R (1 - e^{-R}) = 1. (2) This is integration by parts with two boundary terms to control; you will do it in the guided exercise. (3) By induction using (1) and (2): Γ(n+1)=n Γ(n)=n (n−1)!=n!\Gamma(n + 1) = n\,\Gamma(n) = n\,(n - 1)! = n!. (4) In [ε,R][\eps, R], substitute t=u2t = u^2,  ⁣dt=2u ⁣du\dd t = 2u\dd u:

Γ(12)=∫0∞t−1/2e−t ⁣dt=∫0∞u−1e−u2 2u ⁣du=2∫0∞e−u2 ⁣du=π,\Gamma(\tfrac12) = \int_0^\infty t^{-1/2}e^{-t}\dd t = \int_0^\infty u^{-1}e^{-u^2}\,2u\dd u = 2\int_0^\infty e^{-u^2}\dd u = \sqrt{\pi},

using the Gaussian integral ∫−∞∞e−u2 ⁣du=π\int_{-\infty}^\infty e^{-u^2}\dd u = \sqrt{\pi}, calculated in polar coordinates in the multiple-integrals lesson. Since the integrand is even, half is π/2\sqrt{\pi}/2.

∎

Thus Γ\Gamma is factorial extended to positive reals: Γ(3/2)=12π\Gamma(3/2) = \tfrac12\sqrt{\pi}, Γ(5/2)=34π\Gamma(5/2) = \tfrac34\sqrt{\pi} and, generally, Γ(n+12)=(2n)!4n n!π\Gamma(n + \tfrac12) = \frac{(2n)!}{4^n\,n!}\sqrt{\pi}. It is not the only function interpolating n!n!, but is the unique one that is also log-convex on (0,∞)(0, \infty) and satisfies Γ(1)=1\Gamma(1) = 1 and the recurrence (Bohr–Mollerup theorem). Reading the recurrence backward, Γ(x)=Γ(x+1)/x\Gamma(x) = \Gamma(x + 1)/x, extends it to noninteger negatives, with poles at 0,−1,−2,…0, -1, -2, \dots

What you should learn to recognize is the general form. With t=bxt = bx,

∫0∞xa e−bx ⁣dx=Γ(a+1)ba+1(a>−1, b>0).\int_0^\infty x^{a}\,e^{-bx}\dd x = \frac{\Gamma(a + 1)}{b^{a + 1}} \qquad (a > -1,\ b > 0).

This yields the normalization constant of the Gamma family, ∫0∞xα−1e−βx ⁣dx=Γ(α)/βα\int_0^\infty x^{\alpha - 1}e^{-\beta x}\dd x = \Gamma(\alpha)/\beta^\alpha; exponential moments, E[Xk]=k!/λk\E[X^k] = k!/\lambda^k; and, with u=x2/2u = x^2/2, absolute normal moments, E∣Z∣k=2k/2 Γ(k+12)/π\E\abs{Z}^k = 2^{k/2}\,\Gamma\big(\tfrac{k+1}{2}\big)/\sqrt{\pi}, which the tail figure uses as a reference. Later, Γ\Gamma will give the volume of the ball in nn dimensions, and its growth is described by Stirling’s formula, Γ(x+1)∼2πx (x/e)x\Gamma(x + 1) \sim \sqrt{2\pi x}\,(x/e)^x, obtained by Laplace’s method applied to this same integral.

Implementation from scratch

The first cell implements Darboux sums for piecewise monotone functions: if ff is monotone on each piece, its extrema on each subinterval are at the edges, so LL and UU are computed exactly up to rounding, with n+1n + 1 evaluations per piece. The result is an interval certain to contain the integral, unlike the midpoint rule, which is often more accurate but does not say by how much it is wrong.

[ ]Darboux sums with a certificateBrowser
import numpy as np

def darboux_monotone(f, a, b, n, breaks=()):
    """Sumas inferior y superior de f en [a, b] con n subintervalos iguales por tramo.

    f debe ser monótona en cada tramo [c_j, c_{j+1}] que definen los puntos de ruptura:
    entonces su ínfimo y su supremo en cada subintervalo están en los extremos."""
    cortes = np.array([a, *sorted(breaks), b], dtype=float)
    L = U = 0.0
    for c0, c1 in zip(cortes[:-1], cortes[1:]):
        x = np.linspace(c0, c1, n + 1)
        y = f(x)
        izq, der = y[:-1], y[1:]
        dx = (c1 - c0) / n
        L += dx * np.minimum(izq, der).sum()
        U += dx * np.maximum(izq, der).sum()
    return L, U

def punto_medio(f, a, b, n):
    x = a + (np.arange(n) + 0.5) * (b - a) / n
    return (b - a) / n * f(x).sum()

f = lambda x: np.exp(-x**2)
exacto = 0.7468241328124270    # ∫_0^1 e^{-x^2} dx = (√π/2) erf(1)
print(f"{'n':>6} {'L':>12} {'U':>12} {'U - L':>10} {'error p. medio':>15}")
for n in [4, 16, 64, 256, 1024]:
    L, U = darboux_monotone(f, 0.0, 1.0, n)
    assert L <= exacto <= U
    print(f"{n:6d} {L:12.8f} {U:12.8f} {U - L:10.2e} {abs(punto_medio(f, 0, 1, n) - exacto):15.2e}")

# monótona a trozos: sen x en [0, π] crece hasta π/2 y luego decrece
L, U = darboux_monotone(np.sin, 0.0, np.pi, 100, breaks=[np.pi / 2])
print(f"\n∫_0^π sen x:  {L:.6f} ≤ 2 ≤ {U:.6f}   (U - L = {U - L:.2e})")

# una monótona con saltos: la parte entera en [0, 3.5]
L, U = darboux_monotone(np.floor, 0.0, 3.5, 1000)
print(f"∫_0^3.5 ⌊x⌋:  {L:.6f} ≤ 4.5 ≤ {U:.6f}")

Column U - L is exactly (1−e−1)/n(1 - e^{-1})/n: it divides by 4 each time nn is multiplied by 4. Midpoint error divides by 16 because it is order 1/n21/n^2 for C2C^2 functions (errors in the two halves of each subinterval cancel to first order), but that bound requires knowing f′′f''. Certification and acceleration combine in adaptive quadrature and Gaussian quadrature.

The second cell checks the fundamental theorem: accumulate F(x)=∫0xfF(x) = \int_0^x f with the midpoint rule on a fine grid, differentiate with central differences and compare with ff. At a jump the numerical derivative gives no warning: it returns the average of the one-sided slopes, a number that is not the derivative of anything.

[ ]The fundamental theorem, numericallyBrowser
import numpy as np
import matplotlib.pyplot as plt

def acumulada(f, a, b, m):
    """F(x_j) = ∫_a^{x_j} f en una malla uniforme de m subintervalos (regla del punto medio)."""
    x = np.linspace(a, b, m + 1)
    medios = (x[:-1] + x[1:]) / 2
    F = np.concatenate([[0.0], np.cumsum(f(medios)) * (b - a) / m])
    return x, F

f = lambda x: 1.5 * np.cos(0.9 * x) + 0.3
x, F = acumulada(f, 0.0, 4.0, 4000)
dF = np.gradient(F, x)                       # diferencias centradas en el interior
print("máx |F' - f| con f continua:", f"{np.abs(dF[1:-1] - f(x[1:-1])).max():.1e}")

# con un salto en x = 2, la derivada numérica de F en el salto es el promedio de las laterales
g = lambda x: np.where(x < 2, 0.4 * x + 0.2, 0.4 * x - 1.4)
x, G = acumulada(g, 0.0, 4.0, 4000)
dG = np.gradient(G, x)
i = np.searchsorted(x, 2.0)
print(f"pendiente de G: a la izquierda {dG[i-3]:.4f}, en 2 {dG[i]:.4f}, a la derecha {dG[i+3]:.4f}")

# decaimiento: cota de Darboux U - L frente al error real del punto medio, para e^x en [0, 1]
ns = 2 ** np.arange(2, 15)
cota = [darboux_monotone(np.exp, 0, 1, n)[1] - darboux_monotone(np.exp, 0, 1, n)[0] for n in ns]
err_pm = [abs(punto_medio(np.exp, 0, 1, n) - (np.e - 1)) for n in ns]
p1 = np.polyfit(np.log(ns), np.log(cota), 1)[0]
p2 = np.polyfit(np.log(ns), np.log(err_pm), 1)[0]
print(f"pendientes log-log: cota U - L {p1:.3f},  error del punto medio {p2:.3f}")

plt.loglog(ns, cota, "o-", label="U − L (garantizado)")
plt.loglog(ns, err_pm, "s-", label="error del punto medio")
plt.xlabel("n"); plt.ylabel("error"); plt.legend(); plt.show()

Error of F′F' against ff is of order 10−710^{-7} with ff continuous, combining quadrature error with central-difference error, both order h2h^2. At the jump, the “slope” is 0.20.2, the average of 11 and −0.6-0.6. Graph slopes −1-1 and −2-2 match theory. Systematic numerical integration (Simpson, Gauss, adaptive methods and error analysis) belongs to numerical methods.

With libraries: SciPy and SymPy

scipy.integrate.quad wraps QUADPACK, an adaptive Gauss–Kronrod quadrature library. It accepts infinite bounds (internally changing variables to map [a,∞)[a, \infty) to a bounded interval), returns the value and an absolute-error estimate, and has special routines for oscillatory integrands. scipy.special.gamma evaluates Γ\Gamma directly.

[ ]Gamma and improper integrals with SciPyBrowser
import warnings
import numpy as np
from scipy import integrate, special

# Γ(x) por cuadratura frente a special.gamma
for x in [0.5, 1.0, 2.5, 5.0, 7.3]:
    val, err = integrate.quad(lambda t: t**(x - 1) * np.exp(-t), 0, np.inf)
    print(f"x = {x}:  quad = {val:.12f}   gamma = {special.gamma(x):.12f}   error estimado {err:.0e}")
print("Γ(n + 1) = n! para n = 0..7:", all(special.gamma(n + 1) == special.factorial(n) for n in range(8)))
print("Γ(1/2)² - π =", special.gamma(0.5) ** 2 - np.pi)

# ∫ x^p e^{-x} en [0, ∞) converge si y solo si p > -1; cerca de -1 el valor explota como 1/(p + 1)
for p in [-0.5, -0.9, -0.99]:
    val, _ = integrate.quad(lambda t: t**p * np.exp(-t), 0, np.inf)
    print(f"p = {p}:  quad = {val:.6f}   Γ(p + 1) = {special.gamma(p + 1):.6f}")

# sen(x)/x en [0, ∞): [0, 1] normal y [1, ∞) con la rutina de Fourier (QAWF)
I1, _ = integrate.quad(lambda x: np.sinc(x / np.pi), 0, 1)        # np.sinc(t) = sen(πt)/(πt)
I2, _ = integrate.quad(lambda x: 1 / x, 1, np.inf, weight="sin", wvar=1)
print(f"\n∫_0^∞ sen(x)/x = {I1 + I2:.12f}   π/2 = {np.pi / 2:.12f}")
with warnings.catch_warnings(record=True) as avisos:
    warnings.simplefilter("always")
    ingenuo, err = integrate.quad(lambda x: np.sinc(x / np.pi), 0, 1000)
print(f"quad sin ayuda en [0, 1000]: {ingenuo:.6f}, error estimado {err:.0e}, avisos: {len(avisos)}")

# |sen x|/x: la integral hasta Kπ crece como (2/π) ln(Kπ) más una constante
arcos = [integrate.quad(lambda x: np.abs(np.sinc(x / np.pi)), k * np.pi, (k + 1) * np.pi)[0] for k in range(2000)]
acum = np.cumsum(arcos)
for K in [10, 100, 1000, 2000]:
    R = K * np.pi
    print(f"R = {K:4d}π:  ∫_0^R |sen x|/x = {acum[K - 1]:.4f}   diferencia con (2/π) ln R = {acum[K - 1] - 2 / np.pi * np.log(R):.4f}")

Three readouts. quad reproduces Γ\Gamma to 11 or 12 digits and its error estimate is honest. With the Fourier routine, ∫0∞sin⁡(x)/x\int_0^\infty \sin(x)/x has about 10 digits; unaided, at [0,1000][0, 1000], quad exhausts its subdivisions and warns, with error estimate 0.20.2. And the integral of ∣sin⁡x∣/x\abs{\sin x}/x up to KπK\pi minus (2/π)ln⁡(Kπ)(2/\pi)\ln(K\pi) stabilizes around 1.111.11: it grows logarithmically, exactly the harmonic series’ slow divergence.

SymPy calculates exact antiderivatives and values. But not every elementary function has an elementary antiderivative: a theorem of Liouville (1835) characterizes when one exists, and e−x2e^{-x^2}, sin⁡(x)/x\sin(x)/x or e−x3e^{-x^3} do not have one. SymPy then returns special functions defined precisely as those integrals: erf⁡\operatorname{erf}, Si⁡\operatorname{Si} or the incomplete Gamma.

[ ]What symbolic computation can doBrowser
import sympy as sp

x = sp.symbols("x", positive=True)
n = sp.symbols("n", positive=True, integer=True)

print("∫_0^∞ x^4 e^{-x} =", sp.integrate(x**4 * sp.exp(-x), (x, 0, sp.oo)))
print("∫_0^∞ x^n e^{-x} =", sp.integrate(x**n * sp.exp(-x), (x, 0, sp.oo)))
print("Γ(1/2) =", sp.gamma(sp.Rational(1, 2)), "   Γ(5/2) =", sp.gamma(sp.Rational(5, 2)))
print("∫_0^1 x ln x =", sp.integrate(x * sp.log(x), (x, 0, 1)))
print("∫_0^∞ sen(x)/x =", sp.integrate(sp.sin(x) / x, (x, 0, sp.oo)))

# sin primitiva elemental: SymPy devuelve funciones especiales
print("\nprimitiva de e^{-x^2}:", sp.integrate(sp.exp(-x**2), x))
print("primitiva de sen(x)/x:", sp.integrate(sp.sin(x) / x, x))
print("∫_0^∞ e^{-x^2} =", sp.integrate(sp.exp(-x**2), (x, 0, sp.oo)))

The antiderivative of e−x2e^{-x^2} is π2erf⁡(x)\frac{\sqrt{\pi}}{2}\operatorname{erf}(x), and that of sin⁡(x)/x\sin(x)/x is the sine integral function Si⁡(x)\operatorname{Si}(x). The value at [0,∞)[0, \infty) being π/2\sqrt{\pi}/2 is due to no antiderivative but to a two-dimensional trick (polar coordinates). Symbolic calculations are excellent references to check closed-form answers; for integrals with data, numerical parameters or high dimension, quadrature or Monte Carlo is used.

Common mistakes

Exercises

ProofThe derivative of accumulation
Prove: If ff is continuous on [a,b][a, b] and F(x)=∫axf(t) dtF(x) = \int_a^x f(t)\,\mathrm{d}t, then FF is differentiable at every x∈[a,b]x \in [a, b] (one-sided at endpoints) and F′(x)=f(x)F'(x) = f(x).
0
Fix x∈[a,b)x \in [a, b) and take h>0h > 0 with x+h≤bx + h \le b. Case h<0h < 0 is analogous.

Step 1 of 4. How do you write increment F(x+h)−F(x)F(x + h) - F(x)?

NumericAn apparent singularity
Calculate ∫01xln⁡x dx\int_0^1 x\ln x\,\mathrm{d}x.
ProofThe Gamma recurrence
Prove: For every x>0x > 0, Γ(x+1)=x Γ(x)\Gamma(x + 1) = x\,\Gamma(x).
0
Work on [ε,R][\varepsilon, R] with 0<ε<R0 < \varepsilon < R and take limits ε→0+\varepsilon \to 0^+ and R→∞R \to \infty at the end.

Step 1 of 5. How do you choose the parts in ∫εRtxe−t dt\int_\varepsilon^R t^x e^{-t}\,\mathrm{d}t?

QuizPower times exponential
For which values of p∈Rp \in \mathbb{R} does ∫0∞xpe−x dx\int_0^\infty x^p e^{-x}\,\mathrm{d}x converge?
QuizA negative integral of something positive
Applying the fundamental theorem, ∫−11x−2 dx=[−x−1]−11=−1−1=−2\int_{-1}^{1} x^{-2}\,\mathrm{d}x = \big[-x^{-1}\big]_{-1}^{1} = -1 - 1 = -2, a negative number for a positive integrand. Where is the mistake?
QuizWhich are Riemann integrable on [0, 1]?
Choose all functions Riemann integrable on [0,1][0, 1] (for those undefined at 0, take f(0)=0f(0) = 0).

More than one answer may be correct.

NumericHow many subintervals guarantee six digits?
For f(x)=e−x2f(x) = e^{-x^2} on [0,1][0, 1], which is decreasing, estimate using midpoint (L+U)/2(L + U)/2 of the Darboux sums with nn equal subintervals. What is the smallest nn that guarantees error at most 10−610^{-6}?
NumericA noninteger factorial
Calculate Γ(5/2)\Gamma(5/2).
NumericRecognizing a Gamma
Calculate ∫0∞x3e−2x dx\int_0^\infty x^3 e^{-2x}\,\mathrm{d}x.
NumericA mixed Riemann–Stieltjes integral
Let g(x)=x+⌊x⌋g(x) = x + \lfloor x\rfloor on [0,2][0, 2]. Calculate ∫02x2 dg(x)\int_0^2 x^2\,\mathrm{d}g(x).
CodeIntegration with a guarantee
Implement darboux(f, a, b, n) for ff monotone (increasing or decreasing) on [a,b][a, b], returning the tuple (inferior, superior) of Darboux sums with n equal subintervals; f accepts NumPy arrays. Also implement integrate_to_tol(f, a, b, tol), trying n = 1, 2, 4, 8, ... and returning (valor, n) with the first n for which (superior - inferior) / 2 <= tol, where valor = (inferior + superior) / 2. The distance from valor to the exact integral is thus guaranteed below tol.
import numpy as np

def darboux(f, a, b, n):
  """Devuelve (inferior, superior) para f monótona en [a, b] con n subintervalos iguales."""
  # tu código
  return 0.0, 0.0

def integrate_to_tol(f, a, b, tol):
  """Duplica n desde 1 hasta que (U - L)/2 <= tol; devuelve ((L + U)/2, n)."""
  # tu código
  return 0.0, 1
Shift+Enter to run

Summary

Key idea
The Riemann integral exists when area is trapped between two staircases that close under refinement; the fundamental theorem converts it into an increment of antiderivatives, and everything else (improper integrals, Stieltjes, Gamma) consists of controlled limits of the same idea.
  • Darboux sums L≤∫f≤UL \le \int f \le U move closer under refinement. ff is integrable if and only if U−LU - L can be made smaller than any ε\eps, and then Riemann sums converge as mesh shrinks, with any tags.
  • Monotone functions (with U−L≤∣f(b)−f(a)∣∥P∥U - L \le \abs{f(b) - f(a)}\norm{P}, a certificate) and continuous functions are integrable. Generally, a bounded function is integrable if and only if its discontinuities have measure zero: Thomae yes, Dirichlet no.
  • Fundamental theorem: F(x)=∫axfF(x) = \int_a^x f is Lipschitz and F′=fF' = f at each continuity point; if G′=fG' = f throughout the interior and ff is integrable, ∫abf=G(b)−G(a)\int_a^b f = G(b) - G(a). A jump in ff gives a corner in FF.
  • Substitution and parts are the chain and product rules integrated. On unbounded domains, the boundary term must be proved to vanish.
  • Improper integrals are decided by comparison with x−px^{-p} (threshold p=1p = 1, in opposite directions at 0 and ∞\infty) and exponentials. Absolute convergence matters for expectations: Cauchy has no mean, and Student’s t has moments of order kk if and only if ν>k\nu > k.
  • The Riemann–Stieltjes integral ∫f ⁣dg\int f\dd g, with ff continuous and gg of bounded variation (difference of increasing functions), unifies sums and integrals: E[f(X)]=∫f ⁣dF\E[f(X)] = \int f\dd F for continuous ff and any discrete, continuous or mixed variable.
  • Γ(x)=∫0∞tx−1e−t ⁣dt\Gamma(x) = \int_0^\infty t^{x-1}e^{-t}\dd t converges for x>0x > 0, satisfies Γ(x+1)=xΓ(x)\Gamma(x + 1) = x\Gamma(x), Γ(n+1)=n!\Gamma(n + 1) = n! and Γ(1/2)=π\Gamma(1/2) = \sqrt\pi, and underlies every integral of the form ∫0∞xae−bx ⁣dx=Γ(a+1)/ba+1\int_0^\infty x^a e^{-bx}\dd x = \Gamma(a + 1)/b^{a+1}.