Skip to content
The Lumenary
Early undergraduateUndergraduate (first year) 120 min

Calculus of one variable

Limits made precise, the mean value theorem as the engine of calculus, and infinite series that tell you exactly how wrong your approximation is — and when to stop trusting it.

Formally verified · 18 LeanComputationally tested · 2 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

How does a calculator know sin 0.3?

Press sin 0.3 on a calculator and 0.29552020666…0.29552020666\ldots appears instantly. The chip did not draw a triangle. It added up a handful of terms of

sin⁡x=x−x33!+x55!−x77!+⋯\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \cdots

(real libraries also use range reduction and carefully tuned polynomials, but the idea is the same). Two questions turn this trick into mathematics. Why does the infinite sum equal sin⁡x\sin x? And how many terms are enough for ten correct digits? The answer to both is Taylor's theorem with remainder, and its proof rests on a chain of results — limits, derivatives, the mean value theorem — that is the backbone of this lesson.

The same chain answers questions an engineer in Lagos, a pharmacologist in São Paulo or a climate modeller in Pune meets daily: if a quantity changes at a known rate, how much has it changed in total? (Integrate.) If a function has derivative zero, must it be constant? (Yes — but only on an interval, and the proof needs the mean value theorem.) If an infinite sum's terms shrink to zero, does the sum settle down? (Not necessarily: 1+12+13+⋯1 + \tfrac12 + \tfrac13 + \cdots grows without bound.)

This lesson is a university-level treatment of calculus of one variable. It assumes the informal ideas of introductory calculus, exponentials and logarithms, sequences and geometric series and trigonometry, and makes them precise.

IntuitionH

Zooming in and adding up

Zoom in on the graph of a differentiable function and it looks more and more like a straight line. The slope of that line is the derivative: the derivative is the best linear approximation,

f(a+h)≈f(a)+f′(a) h,with an error that is small compared with h.f(a + h) \approx f(a) + f'(a)\,h, \qquad \text{with an error that is small compared with } h.

Chop an interval into thin strips and add up "height × width": that is a Riemann sum, and as the strips get thinner the sums approach the integral. The fundamental theorem of calculus says these two processes undo each other.

Both ideas rest on the word approach. Newton and Leibniz worked with "vanishing quantities" and "infinitesimals" that were sometimes zero and sometimes not, and Bishop Berkeley mocked them as "the ghosts of departed quantities" (1734). The repair, completed in the nineteenth century by Cauchy, Bolzano and Weierstrass, replaced motion and infinitesimals by a game with inequalities: you name a tolerance ε\varepsilon; I must find a closeness δ\delta that guarantees it.

The ε–δ game for x² at a = 3

A limit is a promise: for every tolerance ε there is a δ. Choose δ and see whether the graph stays inside the band.

Claim: limx→3 (x²) = 9Your move: find δ > 0 so that every x with 0 < |x − a| < δ satisfies |f(x) − L| < ε.

  • f(x) = x²
  • ε-band L ± ε
  • δ-window a ± δ
  • graph outside the band

The challenge ε

Not yet: near x ≈ 3.083 the graph leaves the band (|f(x) − L| ≈ 0.502). Try a smaller δ.

Checked at 2,118 sample points: evidence, not a proof.

Try shrinking ε\varepsilon: you can always find a working δ\delta, but it must shrink too. Then move the claimed limit LL away from 99 and watch every δ\delta fail once ε\varepsilon is small. (The widget samples thousands of points: that is evidence, not proof. The proof is in the worked examples below.)

DefinitionsH

Definitions

Throughout, functions are real-valued and defined on subsets of R\R.

Definition— limit

Let ff be defined on an open interval around aa, except possibly at aa itself. We write lim⁡x→af(x)=L\lim_{x \to a} f(x) = L if for every ε>0\varepsilon > 0 there is δ>0\delta > 0 such that

0<∣x−a∣<δ  ⟹  ∣f(x)−L∣<ε.0 < |x - a| < \delta \implies |f(x) - L| < \varepsilon.

One-sided limits x→a+x \to a^+ and x→a−x \to a^- use only a<x<a+δa < x < a + \delta or a−δ<x<aa - \delta < x < a.

Definition— continuity

ff is continuous at aa (a point of its domain DD) if for every ε>0\varepsilon > 0 there is δ>0\delta > 0 such that ∣f(x)−f(a)∣<ε|f(x) - f(a)| < \varepsilon for all x∈Dx \in D with ∣x−a∣<δ|x - a| < \delta. It is continuous on DD if it is continuous at every point of DD.

The order of the quantifiers matters: δ\delta may depend on ε\varepsilon and on aa. If one δ\delta works for all a∈Da \in D at once, ff is uniformly continuous on DD.

Definition— derivative

Let ff be defined on an open interval containing aa. Then ff is differentiable at aa, with derivative f′(a)f'(a), if the limit

f′(a)=lim⁡h→0f(a+h)−f(a)hf'(a) = \lim_{h \to 0} \frac{f(a + h) - f(a)}{h}

exists (as a real number). Higher derivatives f′′,f′′′,…,f(n)f'', f''', \dots, f^{(n)} are defined by repeating. ff is of class CnC^n on an interval if f(n)f^{(n)} exists and is continuous there, and smooth (C∞C^\infty) if it is CnC^n for every nn.

Definition— Riemann integral

Let ff be bounded on [a,b][a, b]. A tagged partition is a choice of points a=x0<x1<⋯<xn=ba = x_0 < x_1 < \cdots < x_n = b together with tags ti∈[xi−1,xi]t_i \in [x_{i-1}, x_i]; its mesh is max⁡i(xi−xi−1)\max_i (x_i - x_{i-1}). The Riemann sum is S=∑i=1nf(ti) (xi−xi−1)S = \sum_{i=1}^n f(t_i)\,(x_i - x_{i-1}). We say ff is Riemann integrable with integral I=∫abf(x) dxI = \int_a^b f(x)\,dx if for every ε>0\varepsilon > 0 there is δ>0\delta > 0 such that ∣S−I∣<ε|S - I| < \varepsilon for every tagged partition of mesh less than δ\delta.

Every continuous function on [a,b][a, b] is Riemann integrable, and so is every monotone function; both facts are proved in real analysis (the first using uniform continuity). We use freely the elementary properties: linearity, additivity over adjacent intervals, and the estimate ∣∫abg∣≤(b−a)sup⁡[a,b]∣g∣\left|\int_a^b g\right| \le (b - a)\sup_{[a, b]} |g|.

Definition— improper integral

If ff is integrable on [a,b][a, b] for every b>ab > a, then ∫a∞f(x) dx=lim⁡b→∞∫abf(x) dx\int_a^\infty f(x)\,dx = \lim_{b \to \infty} \int_a^b f(x)\,dx when this limit exists (the integral converges). Integrals of functions that are unbounded near an endpoint are defined by the same kind of limit.

Definition— convergent series

The series ∑n=0∞an\sum_{n=0}^\infty a_n converges to SS if its partial sums sN=∑n=0Nans_N = \sum_{n=0}^N a_n satisfy sN→Ss_N \to S. It converges absolutely if ∑∣an∣\sum |a_n| converges, and conditionally if it converges but not absolutely.

Definition— Taylor polynomial and Taylor series

If ff is nn times differentiable at aa, its Taylor polynomial of degree nn at aa is

Tn(x)=∑k=0nf(k)(a)k! (x−a)k,T_n(x) = \sum_{k=0}^{n} \frac{f^{(k)}(a)}{k!}\,(x - a)^k,

and Rn(x)=f(x)−Tn(x)R_n(x) = f(x) - T_n(x) is the remainder. If ff is smooth, its Taylor series at aa is ∑k=0∞f(k)(a)(x−a)k/k!\sum_{k=0}^\infty f^{(k)}(a)(x - a)^k/k! (a Maclaurin series when a=0a = 0). ff is (real) analytic at aa if its Taylor series converges to ff on some interval around aa.

Worked examplesH

Worked examples and non-examples

Example— An ε–δ proof: x² is continuous

Fix aa and ε>0\varepsilon > 0. Since ∣x2−a2∣=∣x−a∣ ∣x+a∣|x^2 - a^2| = |x - a|\,|x + a|, we must control ∣x+a∣|x + a|. If ∣x−a∣<1|x - a| < 1 then ∣x+a∣≤∣x−a∣+2∣a∣<2∣a∣+1|x + a| \le |x - a| + 2|a| < 2|a| + 1. So choose

δ=min⁡(1,ε2∣a∣+1).\delta = \min\left(1, \frac{\varepsilon}{2|a| + 1}\right).

Then ∣x−a∣<δ|x - a| < \delta gives ∣x2−a2∣<δ (2∣a∣+1)≤ε|x^2 - a^2| < \delta\,(2|a| + 1) \le \varepsilon. Notice that δ\delta depends on aa: near a=1000a = 1000 you must stay much closer. In fact x2x^2 is not uniformly continuous on R\R. (This exact argument is checked by Lean below.)

Example— A derivative from the definition, and a corner

For f(x)=xnf(x) = x^n (n≥1n \ge 1), the binomial theorem gives (a+h)n−anh=nan−1+(n2)an−2h+⋯+hn−1→nan−1\frac{(a + h)^n - a^n}{h} = n a^{n-1} + \binom n2 a^{n-2}h + \cdots + h^{n-1} \to n a^{n-1}.

For f(x)=∣x∣f(x) = |x| at 00: the difference quotient ∣h∣/h|h|/h is 11 for h>0h > 0 and −1-1 for h<0h < 0, so the limit does not exist. ∣x∣|x| is continuous but not differentiable at 00. Continuity does not imply differentiability — Weierstrass (1872) even built a function continuous everywhere and differentiable nowhere.

Example— Three integration techniques

  • Substitution (u=x2u = x^2, du=2x dxdu = 2x\,dx): ∫0πxsin⁡(x2) dx=12∫0πsin⁡u du=1.\displaystyle\int_0^{\sqrt\pi} x \sin(x^2)\,dx = \tfrac12\int_0^{\pi} \sin u\,du = 1.
  • Integration by parts (u=xu = x, dv=exdxdv = e^x dx): ∫01xex dx=[xex]01−∫01ex dx=e−(e−1)=1.\displaystyle\int_0^1 x e^x\,dx = \big[x e^x\big]_0^1 - \int_0^1 e^x\,dx = e - (e - 1) = 1.
  • Partial fractions: 1x(x+1)=1x−1x+1\dfrac{1}{x(x + 1)} = \dfrac1x - \dfrac1{x+1}, so ∫1Ndxx(x+1)=ln⁡2NN+1→ln⁡2\displaystyle\int_1^N \frac{dx}{x(x+1)} = \ln\frac{2N}{N + 1} \to \ln 2 as N→∞N \to \infty: a convergent improper integral.

Example— Series: convergent, divergent, and conditionally convergent

  • ∑1/n2\sum 1/n^2 converges (integral test, p=2>1p = 2 > 1); Euler found its sum, π2/6\pi^2/6, in the 1730s.
  • ∑1/n\sum 1/n diverges although 1/n→01/n \to 0: group the terms as 1+12+(13+14)+(15+⋯+18)+⋯1 + \tfrac12 + (\tfrac13 + \tfrac14) + (\tfrac15 + \cdots + \tfrac18) + \cdots, each bracket at least 12\tfrac12.
  • ∑(−1)n+1/n=1−12+13−⋯\sum (-1)^{n+1}/n = 1 - \tfrac12 + \tfrac13 - \cdots converges (to ln⁡2\ln 2) by the alternating series test, but not absolutely. By Riemann's rearrangement theorem its terms can be reordered to converge to any real number you like: conditional convergence depends on the order of the terms.
ProofH

Derivatives and the mean value theorem

Theorem— Proposition (differentiable implies continuous)

If ff is differentiable at aa, then ff is continuous at aa.

Proof

For h≠0h \ne 0, f(a+h)−f(a)=h⋅f(a+h)−f(a)hf(a + h) - f(a) = h \cdot \dfrac{f(a + h) - f(a)}{h}, and as h→0h \to 0 this tends to 0⋅f′(a)=00 \cdot f'(a) = 0.

∎

To prove the chain rule cleanly we use a reformulation of the derivative due to Carathéodory, which avoids dividing by quantities that might be zero.

Theorem— Lemma (Carathéodory's criterion)

ff is differentiable at aa if and only if there is a function φ\varphi, continuous at aa, with f(x)−f(a)=φ(x)(x−a)f(x) - f(a) = \varphi(x)(x - a) for all xx near aa. In that case f′(a)=φ(a)f'(a) = \varphi(a).

Proof

If f′(a)f'(a) exists, put φ(x)=f(x)−f(a)x−a\varphi(x) = \frac{f(x) - f(a)}{x - a} for x≠ax \ne a and φ(a)=f′(a)\varphi(a) = f'(a); continuity of φ\varphi at aa is exactly the definition of f′(a)f'(a). Conversely, given φ\varphi, the difference quotient equals φ(x)\varphi(x) for x≠ax \ne a, which tends to φ(a)\varphi(a).

∎

Theorem— Theorem (chain rule)

If ff is differentiable at aa and gg is differentiable at f(a)f(a), then g∘fg \circ f is differentiable at aa and (g∘f)′(a)=g′(f(a)) f′(a)(g \circ f)'(a) = g'(f(a))\,f'(a).

Proof

Write f(x)−f(a)=φ(x)(x−a)f(x) - f(a) = \varphi(x)(x - a) and g(y)−g(f(a))=ψ(y)(y−f(a))g(y) - g(f(a)) = \psi(y)(y - f(a)) with φ\varphi continuous at aa, ψ\psi continuous at f(a)f(a), φ(a)=f′(a)\varphi(a) = f'(a), ψ(f(a))=g′(f(a))\psi(f(a)) = g'(f(a)). Then

g(f(x))−g(f(a))=ψ(f(x)) (f(x)−f(a))=ψ(f(x)) φ(x) (x−a).g(f(x)) - g(f(a)) = \psi(f(x))\,\big(f(x) - f(a)\big) = \psi(f(x))\,\varphi(x)\,(x - a).

The function x↦ψ(f(x))φ(x)x \mapsto \psi(f(x))\varphi(x) is continuous at aa, because ff is continuous at aa (previous proposition) and ψ\psi at f(a)f(a). By Carathéodory's criterion, (g∘f)′(a)=ψ(f(a))φ(a)=g′(f(a))f′(a)(g \circ f)'(a) = \psi(f(a))\varphi(a) = g'(f(a))f'(a).

∎

The product, quotient and inverse-function rules are proved in the same spirit. The theorems that make derivatives useful rest on one deep fact about the real line, proved in real analysis from the completeness of R\R (see the topology viewpoint below):

Theorem— Theorem (extreme value theorem)

A continuous function on a closed bounded interval [a,b][a, b] attains a maximum and a minimum value.

Theorem— Lemma (Fermat's interior extremum theorem)

If ff has a local maximum or minimum at an interior point cc and is differentiable at cc, then f′(c)=0f'(c) = 0.

Proof

Say cc is a local maximum: f(c+h)≤f(c)f(c + h) \le f(c) for ∣h∣|h| small. For small h>0h > 0 the quotient f(c+h)−f(c)h\frac{f(c + h) - f(c)}{h} is ≤0\le 0, so its limit f′(c)≤0f'(c) \le 0; for small h<0h < 0 it is ≥0\ge 0, so f′(c)≥0f'(c) \ge 0. Hence f′(c)=0f'(c) = 0. A minimum is a maximum of −f-f.

∎

Theorem— Theorem (Rolle)

If ff is continuous on [a,b][a, b], differentiable on (a,b)(a, b), and f(a)=f(b)f(a) = f(b), then f′(c)=0f'(c) = 0 for some c∈(a,b)c \in (a, b).

Proof

By the extreme value theorem ff attains a maximum MM and a minimum mm on [a,b][a, b]. If both are attained only at the endpoints, then M=m=f(a)M = m = f(a), so ff is constant and every c∈(a,b)c \in (a, b) works. Otherwise one of them is attained at some c∈(a,b)c \in (a, b), and f′(c)=0f'(c) = 0 by Fermat's lemma.

∎

Theorem— Theorem (mean value theorem)

If ff is continuous on [a,b][a, b] and differentiable on (a,b)(a, b), where a<ba < b, then

f′(c)=f(b)−f(a)b−afor some c∈(a,b).f'(c) = \frac{f(b) - f(a)}{b - a} \quad \text{for some } c \in (a, b).

Proof

Let m=f(b)−f(a)b−am = \frac{f(b) - f(a)}{b - a} and tilt the graph: g(x)=f(x)−m(x−a)g(x) = f(x) - m(x - a). Then gg is continuous on [a,b][a, b], differentiable on (a,b)(a, b), and g(a)=f(a)=g(b)g(a) = f(a) = g(b) (check: g(b)=f(b)−(f(b)−f(a))=f(a)g(b) = f(b) - (f(b) - f(a)) = f(a)). Rolle's theorem gives cc with 0=g′(c)=f′(c)−m0 = g'(c) = f'(c) - m.

∎

Theorem— Corollary (what the sign of f′ tells you)

Let ff be differentiable on an interval II.

  1. If f′=0f' = 0 on II, then ff is constant on II.
  2. If f′>0f' > 0 on II, then ff is strictly increasing on II (and if f′≥0f' \ge 0, increasing).

Proof

For x<yx < y in II, the mean value theorem on [x,y][x, y] gives f(y)−f(x)=f′(c)(y−x)f(y) - f(x) = f'(c)(y - x) for some c∈(x,y)⊆Ic \in (x, y) \subseteq I. If f′=0f' = 0 the right side is 00; if f′>0f' > 0 it is positive.

∎

The interval matters: f(x)=x/∣x∣f(x) = x/|x| has derivative 00 on R∖{0}\R \setminus \{0\} but is not constant. This corollary is what makes antiderivatives unique up to a constant on an interval.

Theorem— Theorem (Cauchy's mean value theorem)

If f,gf, g are continuous on [a,b][a, b] and differentiable on (a,b)(a, b), then for some c∈(a,b)c \in (a, b),

(f(b)−f(a)) g′(c)=(g(b)−g(a)) f′(c).\big(f(b) - f(a)\big)\,g'(c) = \big(g(b) - g(a)\big)\,f'(c).

Proof

Apply Rolle's theorem to h(x)=(f(b)−f(a))g(x)−(g(b)−g(a))f(x)h(x) = \big(f(b) - f(a)\big)g(x) - \big(g(b) - g(a)\big)f(x); a short computation gives h(a)=f(b)g(a)−f(a)g(b)=h(b)h(a) = f(b)g(a) - f(a)g(b) = h(b).

∎

Theorem— Theorem (L'Hôpital's rule, 0/0 form)

Let f,gf, g be differentiable on (a,a+r)(a, a + r) with g′≠0g' \ne 0 there, and suppose f(x)→0f(x) \to 0 and g(x)→0g(x) \to 0 as x→a+x \to a^+. If f′(x)g′(x)→L\dfrac{f'(x)}{g'(x)} \to L as x→a+x \to a^+, then f(x)g(x)→L\dfrac{f(x)}{g(x)} \to L as x→a+x \to a^+. The same holds for left-hand and two-sided limits.

Proof

Set f(a)=g(a)=0f(a) = g(a) = 0; then f,gf, g are continuous on [a,x][a, x] for every x∈(a,a+r)x \in (a, a + r). First, g(x)≠0g(x) \ne 0: otherwise Rolle's theorem on [a,x][a, x] would give a zero of g′g'. Cauchy's theorem on [a,x][a, x] gives cx∈(a,x)c_x \in (a, x) with f(x) g′(cx)=g(x) f′(cx)f(x)\,g'(c_x) = g(x)\,f'(c_x), that is,

f(x)g(x)=f′(cx)g′(cx).\frac{f(x)}{g(x)} = \frac{f'(c_x)}{g'(c_x)}.

Given ε>0\varepsilon > 0, choose δ∈(0,r)\delta \in (0, r) with ∣f′(c)g′(c)−L∣<ε\left|\frac{f'(c)}{g'(c)} - L\right| < \varepsilon for a<c<a+δa < c < a + \delta. For a<x<a+δa < x < a + \delta we have a<cx<x<a+δa < c_x < x < a + \delta, so ∣f(x)g(x)−L∣<ε\left|\frac{f(x)}{g(x)} - L\right| < \varepsilon.

∎

Example— L'Hôpital twice, and the hypotheses that matter

lim⁡x→0ex−1−xx2=lim⁡x→0ex−12x=lim⁡x→0ex2=12.\displaystyle\lim_{x \to 0} \frac{e^{x} - 1 - x}{x^2} = \lim_{x \to 0} \frac{e^x - 1}{2x} = \lim_{x \to 0} \frac{e^x}{2} = \frac12. Each step is legitimate because the previous quotient was of the form 0/00/0 and the next limit exists. By contrast, lim⁡x→0x+1x+2=12\lim_{x \to 0} \frac{x + 1}{x + 2} = \frac12 by continuity, while blindly differentiating gives 11: the rule only applies to indeterminate forms.

Secants become a tangent

Shrink h and watch the secant line turn into the tangent: its slope approaches the derivative.

PQ
  • f(x) = sin(x)
  • secant through P and Q
  • tangent line (numerical slope)

Slope of the secant PQ

(f(x₀ + h) − f(x₀)) / h = (0.9771 − 0.7071) / 1 = 0.27

Slope of the tangent at P

f′(0.785) ≈ 0.7071

Numerical estimate (central difference with a tiny step).

Difference quotients as h shrinks

h(f(x₀ + h) − f(x₀)) / h
10.26995
0.10.6706
0.010.70356
0.0010.70675

As h shrinks, Q slides towards P, the secant turns into the tangent, and its slope settles on the derivative f′(x₀).

ProofH

Integration and the fundamental theorem

Theorem— Theorem (fundamental theorem of calculus, part 1)

Let ff be integrable on [a,b][a, b] and F(x)=∫axf(t) dtF(x) = \int_a^x f(t)\,dt. If ff is continuous at x0∈(a,b)x_0 \in (a, b), then FF is differentiable at x0x_0 and F′(x0)=f(x0)F'(x_0) = f(x_0).

Proof

For h≠0h \ne 0 small, additivity gives

F(x0+h)−F(x0)h−f(x0)=1h∫x0x0+h(f(t)−f(x0)) dt.\frac{F(x_0 + h) - F(x_0)}{h} - f(x_0) = \frac1h \int_{x_0}^{x_0 + h} \big(f(t) - f(x_0)\big)\,dt.

Given ε>0\varepsilon > 0, continuity gives δ>0\delta > 0 with ∣f(t)−f(x0)∣<ε|f(t) - f(x_0)| < \varepsilon when ∣t−x0∣<δ|t - x_0| < \delta. For 0<∣h∣<δ0 < |h| < \delta the integral above has absolute value at most ∣h∣ ε|h|\,\varepsilon, so the left side is at most ε\varepsilon in absolute value.

∎

In particular every continuous function on an interval has an antiderivative.

Theorem— Theorem (fundamental theorem of calculus, part 2)

Let FF be continuous on [a,b][a, b] and differentiable on (a,b)(a, b) with F′=fF' = f there, and suppose ff is integrable on [a,b][a, b]. Then

∫abf(x) dx=F(b)−F(a).\int_a^b f(x)\,dx = F(b) - F(a).

Proof

Take any partition a=x0<⋯<xn=ba = x_0 < \cdots < x_n = b. By the mean value theorem 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 F(xi)−F(xi−1)=f(ti)(xi−xi−1)F(x_i) - F(x_{i-1}) = f(t_i)(x_i - x_{i-1}). Summing, the left side telescopes:

F(b)−F(a)=∑i=1nf(ti) (xi−xi−1).F(b) - F(a) = \sum_{i=1}^n f(t_i)\,(x_i - x_{i-1}).

So F(b)−F(a)F(b) - F(a) is a Riemann sum, for partitions of every mesh. As the mesh tends to 00 these sums tend to ∫abf\int_a^b f; hence the two numbers are equal.

∎

Theorem— Corollary (integration by parts and substitution)

If u,vu, v are C1C^1 on [a,b][a, b], then ∫abu v′ dx=[uv]ab−∫abu′ v dx\int_a^b u\,v'\,dx = \big[u v\big]_a^b - \int_a^b u'\,v\,dx. If φ\varphi is C1C^1 on [a,b][a, b] and ff is continuous on an interval containing φ([a,b])\varphi([a, b]), then ∫abf(φ(t)) φ′(t) dt=∫φ(a)φ(b)f(x) dx\int_a^b f(\varphi(t))\,\varphi'(t)\,dt = \int_{\varphi(a)}^{\varphi(b)} f(x)\,dx.

Proof

For parts, (uv)′=u′v+uv′(uv)' = u'v + uv' is continuous, so part 2 gives ∫ab(u′v+uv′)=[uv]ab\int_a^b (u'v + uv') = [uv]_a^b; rearrange. For substitution, let FF be an antiderivative of ff (part 1). By the chain rule (F∘φ)′=f(φ) φ′(F \circ \varphi)' = f(\varphi)\,\varphi', so both sides equal F(φ(b))−F(φ(a))F(\varphi(b)) - F(\varphi(a)) by part 2.

∎

Theorem— Proposition (p-integrals)

∫1∞dxxp\displaystyle\int_1^\infty \frac{dx}{x^p} converges if and only if p>1p > 1, and then equals 1p−1\dfrac{1}{p - 1}.

Proof

For p≠1p \ne 1, ∫1bx−p dx=b1−p−11−p\int_1^b x^{-p}\,dx = \frac{b^{1-p} - 1}{1 - p}, which tends to 1p−1\frac{1}{p - 1} if p>1p > 1 and to ∞\infty if p<1p < 1. For p=1p = 1 the integral is ln⁡b→∞\ln b \to \infty.

∎

Riemann sums for ∫₀¹ eˣ dx = e − 1

Approximate the area under a curve with thin strips, and watch the error shrink as the strips get thinner.

  • f(x) = exp(x)

Midpoint sum with 8 strips

M8 = 1.717164

Exact value of the integral

∫01 f(x) dx = 1.718282

Error (sum − integral)

−0.001118

All four rules with n = 8

RuleSumError
Left (L8)1.613126−0.105156
Right (R8)1.8279110.109629
Midpoint (M8)1.717164−0.001118
Trapezoid (T8)1.7205190.002237

Double n and watch the error: left and right sums roughly halve it, midpoint and trapezoid sums cut it to about a quarter.

Compare the four rules as you double the number of strips: the left-rule error roughly halves, while the midpoint and trapezoid errors drop by a factor of about four. The experiment below measures these rates.

ProofH

Series and convergence tests

All the tests rest on the monotone convergence theorem (a bounded increasing sequence of reals converges), which is one form of the completeness of R\R. For a series with non-negative terms, the partial sums increase, so such a series converges exactly when its partial sums are bounded.

Theorem— Theorem (comparison test)

If 0≤an≤bn0 \le a_n \le b_n for all nn and ∑bn\sum b_n converges, then ∑an\sum a_n converges.

Proof

The partial sums of ∑an\sum a_n increase and are bounded by ∑n=0∞bn\sum_{n=0}^\infty b_n.

∎

Theorem— Theorem (absolute convergence implies convergence)

If ∑∣an∣\sum |a_n| converges, then ∑an\sum a_n converges.

Proof

Since −∣an∣≤an≤∣an∣-|a_n| \le a_n \le |a_n|, we have 0≤an+∣an∣≤2∣an∣0 \le a_n + |a_n| \le 2|a_n|, so ∑(an+∣an∣)\sum (a_n + |a_n|) converges by comparison. Then ∑an=∑(an+∣an∣)−∑∣an∣\sum a_n = \sum (a_n + |a_n|) - \sum |a_n| is a difference of two convergent series.

∎

Theorem— Theorem (ratio test)

Suppose an≠0a_n \ne 0 for large nn and ∣an+1/an∣→ρ|a_{n+1}/a_n| \to \rho. If ρ<1\rho < 1, then ∑an\sum a_n converges absolutely; if ρ>1\rho > 1, it diverges. If ρ=1\rho = 1 the test says nothing.

Proof

If ρ<1\rho < 1, pick rr with ρ<r<1\rho < r < 1. For n≥Nn \ge N we have ∣an+1∣≤r∣an∣|a_{n+1}| \le r|a_n|, so ∣an∣≤∣aN∣ rn−N|a_n| \le |a_N|\,r^{n - N}, and ∑∣an∣\sum |a_n| converges by comparison with a geometric series. If ρ>1\rho > 1 then ∣an+1∣>∣an∣|a_{n+1}| > |a_n| for large nn, so an↛0a_n \not\to 0 and the series diverges (its partial sums cannot settle if the terms do not tend to 00). For ρ=1\rho = 1: ∑1/n\sum 1/n diverges while ∑1/n2\sum 1/n^2 converges, and both have ρ=1\rho = 1.

∎

Theorem— Theorem (integral test)

Let ff be positive, continuous and decreasing on [1,∞)[1, \infty). Then ∑n≥1f(n)\sum_{n \ge 1} f(n) converges if and only if ∫1∞f(x) dx\int_1^\infty f(x)\,dx converges.

Proof

Because ff decreases, f(k+1)≤∫kk+1f≤f(k)f(k + 1) \le \int_k^{k+1} f \le f(k) for each k≥1k \ge 1. Summing over k=1,…,N−1k = 1, \dots, N - 1:

∑n=2Nf(n)  ≤  ∫1Nf(x) dx  ≤  ∑n=1N−1f(n).\sum_{n=2}^{N} f(n) \;\le\; \int_1^N f(x)\,dx \;\le\; \sum_{n=1}^{N-1} f(n).

All three quantities increase with NN. If the integral converges, the left inequality bounds the partial sums; if the series converges, the right inequality bounds ∫1Nf\int_1^N f, which then converges as N→∞N \to \infty (and ∫1bf\int_1^b f increases in bb).

∎

With f(x)=x−pf(x) = x^{-p} and the pp-integrals: ∑1/np\sum 1/n^p converges if and only if p>1p > 1.

Theorem— Theorem (alternating series test)

If bnb_n decreases to 00, then ∑n≥1(−1)n+1bn\sum_{n \ge 1} (-1)^{n+1} b_n converges to some SS, and ∣S−sN∣≤bN+1|S - s_N| \le b_{N+1}.

Proof

The even partial sums increase, since s2k+2=s2k+(b2k+1−b2k+2)s_{2k+2} = s_{2k} + (b_{2k+1} - b_{2k+2}), and the odd ones decrease, since s2k+1=s2k−1−(b2k−b2k+1)s_{2k+1} = s_{2k-1} - (b_{2k} - b_{2k+1}); also s2k≤s2k+1≤s1s_{2k} \le s_{2k+1} \le s_1. Both subsequences are monotone and bounded, so they converge, and to the same limit because s2k+1−s2k=b2k+1→0s_{2k+1} - s_{2k} = b_{2k+1} \to 0. The limit SS lies between any two consecutive partial sums, so ∣S−sN∣≤∣sN+1−sN∣=bN+1|S - s_N| \le |s_{N+1} - s_N| = b_{N+1}.

∎

The p-series: slide p across 1

Add the terms one by one. Do the partial sums Sₙ settle down, or keep growing?

Examples
an =
  • partial sums Sₙ
  • terms aₙ

S300 = a1 + … + a300 = 1.641606

Partial sums on a screen are evidence, never proof: a series can look settled and still diverge, as the harmonic series does.

ProofH

Taylor's theorem

Theorem— Theorem (Taylor's theorem with Lagrange remainder)

Let f(n)f^{(n)} be continuous on the closed interval between aa and x≠ax \ne a, and let f(n+1)f^{(n+1)} exist on the open interval between them. Then for some ξ\xi strictly between aa and xx,

f(x)=∑k=0nf(k)(a)k!(x−a)k+f(n+1)(ξ)(n+1)!(x−a)n+1.f(x) = \sum_{k=0}^{n} \frac{f^{(k)}(a)}{k!}(x - a)^k + \frac{f^{(n+1)}(\xi)}{(n + 1)!}(x - a)^{n+1}.

Proof

Keep xx fixed and let the base point vary: for tt between aa and xx put

F(t)=f(x)−∑k=0nf(k)(t)k!(x−t)k,G(t)=(x−t)n+1.F(t) = f(x) - \sum_{k=0}^{n} \frac{f^{(k)}(t)}{k!}(x - t)^k, \qquad G(t) = (x - t)^{n+1}.

Differentiating term by term, the sum telescopes (the derivative of the kk-th term is f(k+1)(t)k!(x−t)k−f(k)(t)(k−1)!(x−t)k−1\frac{f^{(k+1)}(t)}{k!}(x - t)^k - \frac{f^{(k)}(t)}{(k-1)!}(x - t)^{k-1} for k≥1k \ge 1), leaving

F′(t)=−f(n+1)(t)n!(x−t)n,G′(t)=−(n+1)(x−t)n.F'(t) = -\frac{f^{(n+1)}(t)}{n!}(x - t)^n, \qquad G'(t) = -(n + 1)(x - t)^n.

Now F(x)=0F(x) = 0, F(a)=Rn(x)F(a) = R_n(x), G(x)=0G(x) = 0 and G(a)=(x−a)n+1G(a) = (x - a)^{n+1}. Cauchy's mean value theorem on the interval between aa and xx gives ξ\xi strictly between them with (F(x)−F(a))G′(ξ)=(G(x)−G(a))F′(ξ)\big(F(x) - F(a)\big)G'(\xi) = \big(G(x) - G(a)\big)F'(\xi), that is, Rn(x) (n+1)(x−ξ)n=(x−a)n+1 f(n+1)(ξ)n!(x−ξ)nR_n(x)\,(n + 1)(x - \xi)^n = (x - a)^{n+1}\,\frac{f^{(n+1)}(\xi)}{n!}(x - \xi)^n. Since ξ≠x\xi \ne x we may cancel (x−ξ)n(x - \xi)^n, which gives the formula.

∎

For n=0n = 0 this is the mean value theorem. The remainder formula is a certificate of accuracy: if ∣f(n+1)∣≤M|f^{(n+1)}| \le M between aa and xx, then ∣Rn(x)∣≤M∣x−a∣n+1/(n+1)!|R_n(x)| \le M|x - a|^{n+1}/(n+1)!.

Theorem— Corollary (the exponential series)

For every real xx, ex=∑n=0∞xnn!\displaystyle e^x = \sum_{n=0}^\infty \frac{x^n}{n!}. Similarly sin⁡x=∑(−1)nx2n+1(2n+1)!\sin x = \sum (-1)^n \frac{x^{2n+1}}{(2n+1)!} and cos⁡x=∑(−1)nx2n(2n)!\cos x = \sum (-1)^n \frac{x^{2n}}{(2n)!} for all xx.

Proof

Every derivative of ete^t is ete^t, so Taylor's theorem at 00 gives ∣Rn(x)∣=eξ∣x∣n+1/(n+1)!≤e∣x∣∣x∣n+1/(n+1)!|R_n(x)| = e^{\xi}|x|^{n+1}/(n+1)! \le e^{|x|}|x|^{n+1}/(n+1)!. For fixed xx, the numbers cn=∣x∣n/n!c_n = |x|^n/n! satisfy cn+1/cn=∣x∣/(n+1)→0c_{n+1}/c_n = |x|/(n + 1) \to 0, so cn→0c_n \to 0 (by the ratio argument above). Hence Rn(x)→0R_n(x) \to 0. For sin⁡\sin and cos⁡\cos use ∣f(n+1)∣≤1|f^{(n+1)}| \le 1.

∎

Example— How many terms for sin 0.3?

The Maclaurin polynomial x−x3/6+x5/120x - x^3/6 + x^5/120 of sin⁡\sin is also T6T_6, since the x6x^6 coefficient is 00. With ∣sin⁡(7)∣≤1|\sin^{(7)}| \le 1 the error at x=0.3x = 0.3 is at most 0.37/7!≈4.3×10−80.3^7/7! \approx 4.3 \times 10^{-8}. Three terms already give seven correct decimals; the experiment below compares such bounds with the actual errors.

Is every smooth function the sum of its Taylor series? Cauchy showed in 1823 that the answer is no.

Theorem— Theorem (a smooth function that is not analytic)

Let f(x)=e−1/x2f(x) = e^{-1/x^2} for x≠0x \ne 0 and f(0)=0f(0) = 0. Then ff is smooth on R\R and f(n)(0)=0f^{(n)}(0) = 0 for every nn. So its Taylor series at 00 is identically zero, yet f(x)>0f(x) > 0 for every x≠0x \ne 0.

Proof

Step 1. For each integer m≥0m \ge 0, lim⁡x→0∣x∣−me−1/x2=0\lim_{x \to 0} |x|^{-m} e^{-1/x^2} = 0. Indeed, with y=1/x2→∞y = 1/x^2 \to \infty, this is ym/2e−y→0y^{m/2} e^{-y} \to 0, because ey≥yk/k!e^y \ge y^{k}/k! for every kk (one term of its series) — take k>m/2k > m/2.

Step 2. For x≠0x \ne 0, f(n)(x)=Pn(1/x) e−1/x2f^{(n)}(x) = P_n(1/x)\,e^{-1/x^2} for some polynomial PnP_n. This holds for n=0n = 0 with P0=1P_0 = 1, and if it holds for nn, then by the chain and product rules

f(n+1)(x)=(−1x2Pn′(1/x)+2x3Pn(1/x))e−1/x2=Pn+1(1/x) e−1/x2f^{(n+1)}(x) = \Big(-\frac{1}{x^2}P_n'(1/x) + \frac{2}{x^3}P_n(1/x)\Big)e^{-1/x^2} = P_{n+1}(1/x)\,e^{-1/x^2}

with Pn+1(u)=2u3Pn(u)−u2Pn′(u)P_{n+1}(u) = 2u^3 P_n(u) - u^2 P_n'(u).

Step 3. By induction, f(n)(0)f^{(n)}(0) exists and equals 00. For n=0n = 0 this is the definition. If f(n)(0)=0f^{(n)}(0) = 0, then

f(n+1)(0)=lim⁡h→0f(n)(h)−0h=lim⁡h→01hPn(1/h) e−1/h2=0,f^{(n+1)}(0) = \lim_{h \to 0} \frac{f^{(n)}(h) - 0}{h} = \lim_{h \to 0} \frac1h P_n(1/h)\,e^{-1/h^2} = 0,

because 1hPn(1/h)\frac1h P_n(1/h) is a finite combination of powers h−mh^{-m}, and each h−me−1/h2→0h^{-m}e^{-1/h^2} \to 0 by Step 1. Steps 2 and 3, together with Step 1 again, also show each f(n)f^{(n)} is continuous at 00, so ff is smooth.

∎

Flat at 0, yet not zero

Move the sliders and trace along the curves to read off values.

  • f(x) = exp(−1/x²)
  • its Taylor series at 0
  • f(x) = exp(−1/x²): y = 0.3679
  • its Taylor series at 0: y = 0

Near 00 the graph is so flat that no polynomial can see it: every Taylor polynomial at 00 is the zero polynomial. The lesson? Taylor's theorem says f=Tn+Rnf = T_n + R_n — always true — but whether Rn→0R_n \to 0 must be proved, function by function, usually with the Lagrange bound.

Formal mathematicsF

Calculus in Lean and Mathlib

Mathlib has a large, general library of calculus: HasDerivAt f f' x says ff has derivative f′f' at xx, ∫ x in a..b, f x is the interval integral (defined via Lebesgue integration, which agrees with the Riemann integral for Riemann-integrable functions), HasSum a s says a series converges (unconditionally) to ss, and taylorWithinEval gives Taylor polynomials. The lesson's module re-proves several results from more basic library facts — these are marked independent — and cites others directly.

First, continuity. Mathlib defines it with neighbourhood filters; for real functions this unfolds to exactly our ε–δ definition, and the example x2x^2 is proved with the same δ=min⁡(1,ε/(2∣a∣+1))\delta = \min(1, \varepsilon/(2|a| + 1)) as on paper, each calc line matching a step of the human proof:

continuousAt_iff_eps_deltaLean 4Applies a library theoremFormally verified
/-- Mathlib defines continuity with neighbourhood filters; for real functions this is exactly
the ε–δ definition of the lesson. This applies Mathlib's `Metric.continuousAt_iff` and
`Real.dist_eq` (the distance on `ℝ` is `|x - y|`). -/
theorem continuousAt_iff_eps_delta (f : ℝ → ℝ) (a : ℝ) :
    ContinuousAt f a ↔ ∀ ε > 0, ∃ δ > 0, ∀ x, |x - a| < δ → |f x - f a| < ε := by
  simp only [Metric.continuousAt_iff, Real.dist_eq]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
sq_eps_deltaLean 4Proved here from basic factsFormally verified
/-- The squaring function is continuous at every point, proved directly with ε and δ as in the
lesson: take `δ = min 1 (ε / (2|a| + 1))`. If `|x - a| < δ` then `|x + a| ≤ |x - a| + 2|a|
< 2|a| + 1`, so `|x² - a²| = |x - a| |x + a| < δ (2|a| + 1) ≤ ε`. -/
theorem sq_eps_delta (a ε : ℝ) (hε : 0 < ε) :
    ∃ δ > 0, ∀ x : ℝ, |x - a| < δ → |x ^ 2 - a ^ 2| < ε := by
  have hpos : 0 < 2 * |a| + 1 := by positivity
  refine ⟨min 1 (ε / (2 * |a| + 1)), lt_min one_pos (div_pos hε hpos), fun x hx => ?_⟩
  have h1 : |x - a| < 1 := lt_of_lt_of_le hx (min_le_left _ _)
  have h2 : |x - a| < ε / (2 * |a| + 1) := lt_of_lt_of_le hx (min_le_right _ _)
  have hsum : |x + a| < 2 * |a| + 1 :=
    calc |x + a| = |(x - a) + 2 * a| := by ring_nf
      _ ≤ |x - a| + |2 * a| := abs_add_le _ _
      _ = |x - a| + 2 * |a| := by rw [abs_mul, abs_two]
      _ < 1 + 2 * |a| := by linarith
      _ = 2 * |a| + 1 := by ring
  calc |x ^ 2 - a ^ 2| = |x - a| * |x + a| := by rw [← abs_mul]; ring_nf
    _ ≤ |x - a| * (2 * |a| + 1) := by
        exact mul_le_mul_of_nonneg_left hsum.le (abs_nonneg _)
    _ < ε / (2 * |a| + 1) * (2 * |a| + 1) := by
        exact mul_lt_mul_of_pos_right h2 hpos
    _ = ε := div_mul_cancel₀ ε hpos.ne'
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

The chain rule is a single application of Mathlib's HasDerivAt.comp (Mathlib's proof is the general one for maps between normed spaces — see the multivariable lesson):

chain_ruleLean 4Applies a library theoremFormally verified
/-- The chain rule: if `f` has derivative `f'` at `x` and `g` has derivative `g'` at `f x`,
then `g ∘ f` has derivative `g' · f'` at `x`. This applies Mathlib's `HasDerivAt.comp`. -/
theorem chain_rule {f g : ℝ → ℝ} {f' g' x : ℝ} (hf : HasDerivAt f f' x)
    (hg : HasDerivAt g g' (f x)) : HasDerivAt (g ∘ f) (g' * f') x :=
  hg.comp x hf
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

The mean value theorem, derived from Rolle's theorem by tilting the graph exactly as in the human proof, next to Mathlib's own version:

mvt_from_rolleLean 4Proved here from basic factsFormally verified
/-- **The mean value theorem**, derived from Rolle's theorem exactly as in the lesson. Tilt
the graph: `g x = f x - m (x - a)` with `m = (f b - f a)/(b - a)` has `g a = g b`, so Rolle's
theorem (Mathlib's `exists_hasDerivAt_eq_zero`) gives `c` with `g' c = f' c - m = 0`. -/
theorem mvt_from_rolle {f f' : ℝ → ℝ} {a b : ℝ} (hab : a < b)
    (hfc : ContinuousOn f (Icc a b)) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) :
    ∃ c ∈ Ioo a b, f' c = (f b - f a) / (b - a) := by
  set m := (f b - f a) / (b - a) with hm
  have hba : b - a ≠ 0 := sub_ne_zero.mpr hab.ne'
  -- The tilted function and its derivative.
  let g : ℝ → ℝ := fun x => f x - m * (x - a)
  have hgc : ContinuousOn g (Icc a b) :=
    hfc.sub (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
  have hgab : g a = g b := by
    simp only [g, sub_self, mul_zero, sub_zero, hm]
    field_simp
    ring
  have hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (f' x - m) x := by
    intro x hx
    have hlin : HasDerivAt (fun x => m * (x - a)) m x := by
      simpa using ((hasDerivAt_id x).sub_const a).const_mul m
    exact (hff' x hx).sub hlin
  obtain ⟨c, hc, hc0⟩ := exists_hasDerivAt_eq_zero hab hgc hgab hgg'
  exact ⟨c, hc, sub_eq_zero.mp hc0⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
mvtLean 4Applies a library theoremFormally verified
/-- Mathlib's own **mean value theorem**, `exists_hasDerivAt_eq_slope`. Same statement as
`mvt_from_rolle`; Mathlib proves it from Cauchy's mean value theorem. -/
theorem mvt {f f' : ℝ → ℝ} {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b))
    (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) :
    ∃ c ∈ Ioo a b, f' c = (f b - f a) / (b - a) :=
  exists_hasDerivAt_eq_slope f f' hab hfc hff'
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

Its two most-used consequences, each proved from mvt_from_rolle:

const_of_deriv_zeroLean 4Proved here from basic factsFormally verified
/-- A function on `ℝ` whose derivative is zero everywhere is constant. Proof from the mean
value theorem: for `x < y`, some `c` has `0 = f' c = (f y - f x)/(y - x)`, so `f y = f x`. -/
theorem const_of_deriv_zero {f : ℝ → ℝ} (hf : ∀ x, HasDerivAt f 0 x) (x y : ℝ) :
    f x = f y := by
  -- It suffices to treat `x < y`; the case `x = y` is trivial and `x > y` is symmetric.
  have key : ∀ u v : ℝ, u < v → f u = f v := by
    intro u v huv
    obtain ⟨c, -, hc⟩ := mvt_from_rolle (f' := fun _ => 0) huv
      (fun t _ => (hf t).continuousAt.continuousWithinAt) (fun t _ => hf t)
    have hvu : v - u ≠ 0 := sub_ne_zero.mpr huv.ne'
    have : f v - f u = 0 := by
      have := hc.symm
      rwa [div_eq_zero_iff, or_iff_left hvu] at this
    linarith
  rcases lt_trichotomy x y with h | rfl | h
  · exact key x y h
  · rfl
  · exact (key y x h).symm
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
strictMono_of_deriv_posLean 4Proved here from basic factsFormally verified
/-- A function whose derivative is positive everywhere is strictly increasing. Proof from the
mean value theorem: for `x < y`, `f y - f x = f'(c) (y - x)` with `f'(c) > 0` and `y - x > 0`. -/
theorem strictMono_of_deriv_pos {f f' : ℝ → ℝ} (hf : ∀ x, HasDerivAt f (f' x) x)
    (hpos : ∀ x, 0 < f' x) : StrictMono f := by
  intro x y hxy
  obtain ⟨c, -, hc⟩ := mvt_from_rolle hxy
    (fun t _ => (hf t).continuousAt.continuousWithinAt) (fun t _ => hf t)
  have hyx : 0 < y - x := sub_pos.mpr hxy
  have hdiff : f y - f x = f' c * (y - x) := by
    rw [hc]; field_simp
  have : 0 < f y - f x := by rw [hdiff]; exact mul_pos (hpos c) hyx
  linarith
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

L'Hôpital's rule appears in Mathlib in many variants (one-sided, at infinity, with deriv); here is the two-sided 0/00/0 form. Note that the conclusion is about the punctured neighbourhood filter 𝓝[≠] a, i.e. x→ax \to a with x≠ax \ne a:

lhopitalLean 4Applies a library theoremFormally verified
/-- **L'Hôpital's rule**, two-sided `0/0` form: if `f` and `g` have derivatives `f'`, `g'` near
`a`, `g'` does not vanish near `a`, `f, g → 0` at `a`, and `f'/g' → l`, then `f/g → l` as
`x → a` with `x ≠ a`. This applies Mathlib's `HasDerivAt.lhopital_zero_nhds`, which is proved
from Cauchy's mean value theorem as in the lesson. -/
theorem lhopital {f g f' g' : ℝ → ℝ} {a l : ℝ}
    (hff' : ∀ᶠ x in 𝓝 a, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in 𝓝 a, HasDerivAt g (g' x) x)
    (hg' : ∀ᶠ x in 𝓝 a, g' x ≠ 0) (hfa : Tendsto f (𝓝 a) (𝓝 0)) (hga : Tendsto g (𝓝 a) (𝓝 0))
    (hdiv : Tendsto (fun x => f' x / g' x) (𝓝 a) (𝓝 l)) :
    Tendsto (fun x => f x / g x) (𝓝[≠] a) (𝓝 l) :=
  HasDerivAt.lhopital_zero_nhds hff' hgg' hg' hfa hga hdiv
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

The fundamental theorem of calculus, and two integrals computed with it. Integration by parts found the antiderivative (x−1)ex(x - 1)e^x; Lean only needs to check it, by differentiating:

ftcLean 4Applies a library theoremFormally verified
/-- **Fundamental theorem of calculus** (evaluation form): if `F' = f` on `[a, b]` and `f` is
integrable there, then `∫ₐᵇ f = F b - F a`. This applies Mathlib's
`intervalIntegral.integral_eq_sub_of_hasDerivAt`. -/
theorem ftc {F f : ℝ → ℝ} {a b : ℝ} (hF : ∀ x ∈ uIcc a b, HasDerivAt F (f x) x)
    (hint : IntervalIntegrable f MeasureTheory.volume a b) :
    ∫ x in a..b, f x = F b - F a :=
  intervalIntegral.integral_eq_sub_of_hasDerivAt hF hint
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
integral_sqLean 4Proved here from basic factsFormally verified
/-- `∫₀¹ x² dx = 1/3`, computed with the fundamental theorem and the antiderivative `x³/3`. -/
theorem integral_sq : ∫ x in (0 : ℝ)..1, x ^ 2 = 1 / 3 := by
  have hF : ∀ x ∈ uIcc (0 : ℝ) 1, HasDerivAt (fun x : ℝ => x ^ 3 / 3) (x ^ 2) x := by
    intro x _
    have := (hasDerivAt_pow 3 x).div_const 3
    convert this using 1
    push_cast
    ring
  rw [ftc hF ((continuous_pow 2).intervalIntegrable 0 1)]
  norm_num
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
integral_x_expLean 4Proved here from basic factsFormally verified
/-- `∫₀¹ x eˣ dx = 1`. Integration by parts *finds* the antiderivative `(x - 1) eˣ`; the
fundamental theorem then *checks* it: `((x - 1) eˣ)' = eˣ + (x - 1) eˣ = x eˣ`. -/
theorem integral_x_exp : ∫ x in (0 : ℝ)..1, x * Real.exp x = 1 := by
  have hF : ∀ x ∈ uIcc (0 : ℝ) 1,
      HasDerivAt (fun x : ℝ => (x - 1) * Real.exp x) (x * Real.exp x) x := by
    intro x _
    have := ((hasDerivAt_id' x).sub_const 1).mul (Real.hasDerivAt_exp x)
    convert this using 1
    ring
  have hcont : Continuous fun x : ℝ => x * Real.exp x := by fun_prop
  rw [ftc hF (hcont.intervalIntegrable 0 1)]
  simp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

Series need care with words. In Mathlib, Summable a means unconditional convergence (the sum does not depend on the order of the terms), which for real series is equivalent to absolute convergence. So the alternating harmonic series is not Summable in Mathlib, although its partial sums converge. The proof that absolute convergence implies convergence follows the lesson line by line (0≤an+∣an∣≤2∣an∣0 \le a_n + |a_n| \le 2|a_n|, then subtract), and the second version restates the conclusion in terms of partial sums, exactly as in the lesson. The pp-series test is cited from Mathlib, which proves it by Cauchy condensation rather than the integral test:

summable_of_absLean 4Proved here from basic factsFormally verified
/-- **An absolutely convergent series converges.** The lesson's proof: `0 ≤ aₙ + |aₙ| ≤ 2|aₙ|`,
so `∑ (aₙ + |aₙ|)` converges by comparison, and `aₙ = (aₙ + |aₙ|) - |aₙ|` is a difference of two
convergent series. (Mathlib states the general fact as `Summable.of_norm`.) -/
theorem summable_of_abs {a : ℕ → ℝ} (h : Summable fun n => |a n|) : Summable a := by
  have hsum : Summable fun n => a n + |a n| := by
    refine Summable.of_nonneg_of_le (fun n => ?_) (fun n => ?_) (h.mul_left 2)
    · linarith [neg_abs_le (a n)]
    · linarith [le_abs_self (a n)]
  have : a = fun n => (a n + |a n|) - |a n| := by
    funext n; ring
  rw [this]
  exact hsum.sub h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
partial_sums_converge_of_absLean 4Proved here from basic factsFormally verified
/-- The same theorem in the lesson's language of partial sums: if `∑ |aₙ|` converges, then the
partial sums `a₀ + ⋯ + a_{N-1}` converge to a limit. (In Mathlib, `Summable` means
*unconditional* convergence, which for real series is the same as absolute convergence; so
`Summable` gives convergent partial sums, via `HasSum.tendsto_sum_nat`, but a conditionally
convergent series such as `∑ (-1)ⁿ/(n+1)` is *not* `Summable`.) -/
theorem partial_sums_converge_of_abs {a : ℕ → ℝ} (h : Summable fun n => |a n|) :
    ∃ S, Tendsto (fun N => ∑ n ∈ Finset.range N, a n) atTop (𝓝 S) :=
  ⟨_, (summable_of_abs h).hasSum.tendsto_sum_nat⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
p_seriesLean 4Applies a library theoremFormally verified
/-- The `p`-series test: `∑ 1/nᵖ` converges if and only if `p > 1`. This applies Mathlib's
`Real.summable_one_div_nat_rpow` (proved there with Cauchy condensation). -/
theorem p_series (p : ℝ) : Summable (fun n : ℕ => 1 / (n : ℝ) ^ p) ↔ 1 < p :=
  Real.summable_one_div_nat_rpow
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

Taylor's theorem with Lagrange remainder and the exponential series are cited from Mathlib:

taylor_lagrangeLean 4Applies a library theoremFormally verified
/-- **Taylor's theorem with Lagrange remainder.** If `f` is `n` times continuously
differentiable on the closed interval between `x₀` and `x`, and its `n`-th derivative is
differentiable inside, then `f x - Pₙ(x) = f⁽ⁿ⁺¹⁾(ξ) (x - x₀)ⁿ⁺¹/(n+1)!` for some `ξ` strictly
between. This applies Mathlib's `taylor_mean_remainder_lagrange`. (Mathlib's derivatives here
are taken *within* the interval, which agrees with the ordinary ones for smooth `f`.) -/
theorem taylor_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ ≠ x)
    (hf : ContDiffOn ℝ n f (uIcc x₀ x))
    (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (uIcc x₀ x)) (uIoo x₀ x)) :
    ∃ ξ ∈ uIoo x₀ x, f x - taylorWithinEval f n (uIcc x₀ x) x₀ x =
      iteratedDerivWithin (n + 1) f (uIcc x₀ x) ξ * (x - x₀) ^ (n + 1) / (n + 1).factorial :=
  taylor_mean_remainder_lagrange hx hf hf'
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
exp_seriesLean 4Applies a library theoremFormally verified
/-- `eˣ = ∑ xⁿ/n!` for every real `x`. This applies Mathlib's
`NormedSpace.expSeries_div_hasSum_exp` together with `Real.exp_eq_exp_ℝ`, which identifies the
real exponential with the exponential series. -/
theorem exp_series (x : ℝ) : HasSum (fun n : ℕ => x ^ n / n.factorial) (Real.exp x) := by
  rw [Real.exp_eq_exp_ℝ]
  exact NormedSpace.expSeries_div_hasSum_exp x
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

Finally, the misconception "smooth implies analytic". Mathlib's expNegInvGlue is the one-sided cousin of Cauchy's function: e−1/xe^{-1/x} for x>0x > 0 and 00 for x≤0x \le 0. Mathlib proves it is smooth. We prove that all its derivatives vanish at 00, by a different route from the human proof above: the function is identically zero to the left of 00, so its derivatives vanish there, and continuity of the derivatives carries the zeros to 00:

flat_iteratedDeriv_zeroLean 4Proved here from basic factsFormally verified
/-- Mathlib's `expNegInvGlue` is `exp (-1/x)` for `x > 0` and `0` for `x ≤ 0`; it is smooth
(`expNegInvGlue.contDiff`). **Every derivative of it at `0` is `0`**, so its Taylor series at
`0` is the zero series. Proof: on `(-∞, 0)` the function is locally zero, so each iterated
derivative vanishes there; iterated derivatives of a smooth function are continuous, so the
value at `0` is the limit from the left, which is `0`. -/
theorem flat_iteratedDeriv_zero (n : ℕ) : iteratedDeriv n expNegInvGlue 0 = 0 := by
  have hcont : Continuous (iteratedDeriv n expNegInvGlue) :=
    (expNegInvGlue.contDiff (n := ⊤)).continuous_iteratedDeriv n (by exact_mod_cast le_top)
  -- The iterated derivative vanishes at every negative point.
  have hneg : ∀ x : ℝ, x < 0 → iteratedDeriv n expNegInvGlue x = 0 := by
    intro x hx
    have hloc : expNegInvGlue =ᶠ[𝓝 x] fun _ => (0 : ℝ) := by
      filter_upwards [gt_mem_nhds hx] with y hy
      exact expNegInvGlue.zero_of_nonpos hy.le
    rw [hloc.iteratedDeriv_eq n]
    simp
  -- Take the limit from the left.
  have hlim : Tendsto (iteratedDeriv n expNegInvGlue) (𝓝[<] 0)
      (𝓝 (iteratedDeriv n expNegInvGlue 0)) :=
    (hcont.tendsto 0).mono_left nhdsWithin_le_nhds
  have hzero : Tendsto (iteratedDeriv n expNegInvGlue) (𝓝[<] 0) (𝓝 0) := by
    refine tendsto_const_nhds.congr' ?_
    filter_upwards [self_mem_nhdsWithin] with x hx
    exact (hneg x hx).symm
  exact tendsto_nhds_unique hlim hzero
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor
flat_posLean 4Applies a library theoremFormally verified
/-- …and yet `expNegInvGlue x > 0` for every `x > 0`: the function is not the sum of its
(zero) Taylor series on any interval `(0, r)`. This applies Mathlib's
`expNegInvGlue.pos_of_pos`. -/
theorem flat_pos {x : ℝ} (hx : 0 < x) : 0 < expNegInvGlue x :=
  expNegInvGlue.pos_of_pos hx
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/SingleVariableCalculus.leanTry it in the Lean web editor

What is and is not formalised here. Formalised: everything displayed above. Independently proved: the ε–δ example, the mean value theorem from Rolle, its two corollaries, both integrals, absolute convergence (in both forms), and the flatness of expNegInvGlue. Cited from Mathlib: the ε–δ characterisation, the chain rule, L'Hôpital's rule, the fundamental theorem, the pp-series test, Taylor's theorem and the exponential series. Not formalised here: the extreme value theorem and Rolle's theorem themselves (Mathlib has both, as IsCompact.exists_isMaxOn and exists_hasDerivAt_eq_zero, and our mean value theorem uses the latter), the Riemann-sum definition of the integral, and the two-sided function e−1/x2e^{-1/x^2} (whose flatness needs the polynomial bookkeeping of the human proof).

ComputationC

Error bounds versus actual errors

Taylor's theorem promises an upper bound on the error. How good is the promise? The first experiment computes Taylor polynomials of exe^x and sin⁡x\sin x exactly (with rational arithmetic), compares the actual error with the Lagrange bound, and then looks at Cauchy's flat function, where the Taylor polynomials stay at zero.

Taylor polynomials: Lagrange bound versus actual errorPythonExact computationNumerical approximationComputationally tested
"""Taylor polynomials: the Lagrange error bound against the actual error.

Taylor's theorem says f(x) = T_n(x) + R_n(x) with
R_n(x) = f^(n+1)(xi) x^(n+1) / (n+1)! for some xi between 0 and x. Bounding
|f^(n+1)| gives a guaranteed error bound. This experiment computes Taylor
polynomials of exp and sin exactly (rational arithmetic), compares the actual
error (against the library functions) with the Lagrange bound, finds how many
terms of the series for e give ten correct digits, and shows Cauchy's flat
function exp(-1/x^2), whose Taylor polynomials at 0 are all zero.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

import math
from fractions import Fraction

def exp_taylor(x, n):
    """Exact value of the Maclaurin polynomial sum_{k=0}^{n} x^k / k!."""
    if n < 0:
        raise ValueError("degree must be non-negative")
    x = Fraction(x)
    term = Fraction(1)
    total = Fraction(1)
    for k in range(1, n + 1):
        term = term * x / k
        total += term
    return total

def sin_taylor(x, n):
    """Exact value of the Maclaurin polynomial of sin of degree n."""
    if n < 0:
        raise ValueError("degree must be non-negative")
    x = Fraction(x)
    total = Fraction(0)
    for k in range(1, n + 1, 2):
        sign = -1 if (k - 1) // 2 % 2 else 1
        total += sign * x**k / math.factorial(k)
    return total

def exp_bound(x, n):
    """Lagrange bound on |exp(x) - T_n(x)|: e^max(x,0) |x|^(n+1) / (n+1)!.

    The unknown point xi lies between 0 and x, so e^xi <= e^max(x, 0).
    """
    return math.exp(max(x, 0)) * abs(x) ** (n + 1) / math.factorial(n + 1)

def sin_bound(x, n):
    """Lagrange bound on |sin(x) - T_n(x)|, using |sin^(m+1)| <= 1.

    For odd n the next coefficient of sin is zero, so T_n = T_(n+1) and the
    remainder of degree m = n + 1 gives a sharper bound.
    """
    m = n + 1 if n % 2 else n
    return abs(x) ** (m + 1) / math.factorial(m + 1)

def degree_for_e(tolerance):
    """Least n whose Lagrange bound 3/(n+1)! for |e - T_n(1)| is below tolerance."""
    n = 0
    while 3 / math.factorial(n + 1) >= tolerance:
        n += 1
    return n

def flat(x):
    """Cauchy's smooth function: exp(-1/x^2) for x != 0, and 0 at 0."""
    return 0.0 if x == 0 else math.exp(-1 / x**2)

def error_rows(f, poly, bound, x, degrees):
    """Rows (n, actual error, bound) for the given degrees."""
    rows = []
    for n in degrees:
        actual = abs(f(x) - float(poly(Fraction(x), n)))
        rows.append((n, actual, bound(x, n)))
    return rows

def main():
    cases = [
        ("exp", math.exp, exp_taylor, exp_bound, 1, [2, 4, 6, 8, 10]),
        ("exp", math.exp, exp_taylor, exp_bound, -2, [2, 4, 8, 12, 16]),
        ("sin", math.sin, sin_taylor, sin_bound, 0.3, [1, 3, 5, 7]),
    ]
    print("Maclaurin polynomials: actual error versus Lagrange bound")
    for name, f, poly, bound, x, degrees in cases:
        print(f"f = {name}, x = {x}")
        print("   n    actual error   Lagrange bound   bound / actual")
        for n, actual, b in error_rows(f, poly, bound, x, degrees):
            print(f"  {n:2d}    {actual:.3e}      {b:.3e}        {b / actual:7.2f}")
    n = degree_for_e(1e-10)
    print(f"Degree n with 3/(n+1)! < 1e-10 (ten digits of e): n = {n}")
    approx = float(exp_taylor(1, n))
    print(f"  T_{n}(1) = {approx:.12f}, error {abs(math.e - approx):.1e}")
    print("Cauchy's flat function: every T_n at 0 is the zero polynomial")
    for x in [0.5, 0.2, 0.1]:
        print(f"  x = {x}: f(x) = {flat(x):.3e} = error of T_n for every n")
    print()
    print("Epistemic status: the polynomial values are exact rationals; the")
    print("errors are measured against floating-point exp and sin, so they are")
    print("numerical evidence for these x and n only. That the bound holds for")
    print("every x and n is Taylor's theorem; that exp is the sum of its series")
    print("is the lesson's corollary. For the flat function no degree helps.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Numerical integration has error bounds too. For a function with continuous second derivative, the midpoint rule with nn strips on [a,b][a, b] has error at most (b−a)324n2max⁡∣f′′∣\frac{(b - a)^3}{24 n^2}\max|f''|, and the trapezoid rule at most (b−a)312n2max⁡∣f′′∣\frac{(b-a)^3}{12 n^2}\max|f''|; Simpson's rule, for C4C^4 functions, at most (b−a)5180n4max⁡∣f(4)∣\frac{(b - a)^5}{180 n^4}\max|f^{(4)}|. (These are theorems, proved with Taylor's theorem; see a numerical analysis text.) The second experiment measures the rates on ∫01ex dx=e−1\int_0^1 e^x\,dx = e - 1:

Riemann sums and Simpson's rule: measured rates of convergencePythonNumerical approximationComputationally tested
"""How fast do Riemann sums converge? Left, midpoint, trapezoid and Simpson.

For the integral of e^x over [0, 1] (exact value e - 1) we compute four
approximations with n = 4, 8, ..., 64 strips and measure the observed order
of convergence: if the error behaves like C / n^p, doubling n divides it by
2^p, so p = log2(error(n) / error(2n)). Theory (proved with Taylor's theorem)
predicts p = 1 for the left rule, 2 for the midpoint and trapezoid rules and
4 for Simpson's rule, for smooth integrands.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

import math

def left_sum(f, a, b, n):
    """Left Riemann sum with n equal strips."""
    h = (b - a) / n
    return h * sum(f(a + i * h) for i in range(n))

def midpoint_sum(f, a, b, n):
    """Midpoint rule with n equal strips."""
    h = (b - a) / n
    return h * sum(f(a + (i + 0.5) * h) for i in range(n))

def trapezoid_sum(f, a, b, n):
    """Trapezoid rule with n equal strips."""
    h = (b - a) / n
    inner = sum(f(a + i * h) for i in range(1, n))
    return h * (0.5 * f(a) + inner + 0.5 * f(b))

def simpson_sum(f, a, b, n):
    """Composite Simpson's rule with n equal strips (n must be even)."""
    if n <= 0 or n % 2:
        raise ValueError("Simpson's rule needs a positive even number of strips")
    h = (b - a) / n
    odd = sum(f(a + i * h) for i in range(1, n, 2))
    even = sum(f(a + i * h) for i in range(2, n, 2))
    return h / 3 * (f(a) + 4 * odd + 2 * even + f(b))

def observed_order(error_n, error_2n):
    """Estimate p from errors with n and 2n strips, assuming error ~ C / n^p."""
    return math.log2(abs(error_n) / abs(error_2n))

RULES = [
    ("left", left_sum),
    ("midpoint", midpoint_sum),
    ("trapezoid", trapezoid_sum),
    ("Simpson", simpson_sum),
]

def error_table(f, a, b, exact, ns):
    """Map each rule name to its list of signed errors (approximation - exact)."""
    return {name: [rule(f, a, b, n) - exact for n in ns] for name, rule in RULES}

def main():
    exact = math.e - 1
    ns = [4, 8, 16, 32, 64]
    table = error_table(math.exp, 0.0, 1.0, exact, ns)
    print("Integral of e^x over [0, 1] = e - 1; signed errors (approx - exact)")
    print("   n        left       midpoint     trapezoid      Simpson")
    for i, n in enumerate(ns):
        row = "  ".join(f"{table[name][i]:+.3e}" for name, _ in RULES)
        print(f"  {n:2d}  {row}")
    print("Observed order p = log2(E(n) / E(2n)):")
    for name, _ in RULES:
        errs = table[name]
        orders = [observed_order(errs[i], errs[i + 1]) for i in range(len(ns) - 1)]
        shown = ", ".join(f"{p:.2f}" for p in orders)
        print(f"  {name:<9} {shown}")
    ratio = table["midpoint"][-1] / table["trapezoid"][-1]
    print(f"Midpoint error / trapezoid error at n = 64: {ratio:+.4f}")
    print("(about -1/2, so (2M + T)/3 - Simpson with 2n strips - cancels them)")
    print()
    print("Epistemic status: floating-point evidence for one smooth integrand.")
    print("The orders 1, 2, 2, 4 agree with the error theorems for these rules,")
    print("which are proved with Taylor's theorem and need f to be smooth enough;")
    print("for a function with a kink or a singularity the rates can be worse.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Both experiments are numerical evidence about particular functions and particular nn. The theorems in the lesson are what guarantee the behaviour for all nn.

Explore

Explore: Taylor polynomials and their limits

Raise the degree and watch the Taylor polynomials of sin⁡x\sin x hug the graph on wider and wider intervals — the series converges for every xx. Then switch to ln⁡(1+x)\ln(1 + x) or 1/(1−x)1/(1 - x), whose series converge only on a bounded interval, however high the degree.

Taylor polynomials

Polynomials built from the derivatives at 0 hug the function more and more closely, but only inside the interval of convergence.

  • f(x) = sin x
  • Taylor polynomial T5

T5(x) = x − x³/3! + x⁵/5!

The Taylor series of sin x converges for every real x: at any fixed x, enough terms bring Tₙ(x) as close to f(x) as you like. Far from 0 you simply need more terms.
  • f(2) = 0.9093
  • T5(2) = 0.93333
  • |f − T5| = 0.02404

The function 1/(1+x2)1/(1 + x^2) is smooth on all of R\R, yet its Maclaurin series 1−x2+x4−⋯1 - x^2 + x^4 - \cdots converges only for ∣x∣<1|x| < 1. Below, the partial sum of degree 2N2N is written in closed form as 1−(−x2)N+11+x2\frac{1 - (-x^2)^{N+1}}{1 + x^2}. Slide NN up and watch the partial sums converge inside (−1,1)(-1, 1) and blow up outside. Nothing on the real line explains the barrier at ±1\pm 1; the analysis viewpoint below does.

Graphing functions

Move the sliders and trace along the curves to read off values.

  • 1/(1 + x²)
  • partial sum of degree 2N
  • 1/(1 + x²): y = 0.5
  • partial sum of degree 2N: y = 0
Exercises

Exercises

1. Calculus of one variable

Warm-upHuman

We want ∣x2−9∣<ε|x^2 - 9| < \varepsilon whenever ∣x−3∣<δ|x - 3| < \delta. Following the lesson's recipe δ=min⁡(1,ε/(2∣a∣+1))\delta = \min\big(1, \varepsilon/(2|a| + 1)\big) with a=3a = 3, which δ\delta does it give for ε=0.7\varepsilon = 0.7?

Choose one

2. Calculus of one variable

Warm-upHuman

Compute lim⁡x→01−cos⁡(4x)x2\displaystyle\lim_{x \to 0} \frac{1 - \cos(4x)}{x^2}.

3. Calculus of one variable

CoreHuman

For f(x)=∣x∣f(x) = |x| on [−1,2][-1, 2], the chord slope is f(2)−f(−1)2−(−1)=13\frac{f(2) - f(-1)}{2 - (-1)} = \frac13, but f′(x)∈{−1,1}f'(x) \in \{-1, 1\} wherever it exists. Which hypothesis of the mean value theorem fails?

Choose one

4. Calculus of one variable

CoreHuman

Compute ∫1eln⁡x dx\displaystyle\int_1^e \ln x\,dx.

5. Calculus of one variable

CoreHuman

Which of these series converge? (Select all that apply.)

Choose all that apply

6. Calculus of one variable

CoreHuman

Using the Lagrange bound ∣e−Tn(1)∣≤e(n+1)!|e - T_n(1)| \le \dfrac{e}{(n + 1)!} for the Maclaurin polynomial of exe^x at x=1x = 1, what is the smallest degree nn that guarantees ∣e−Tn(1)∣<10−6|e - T_n(1)| < 10^{-6}? (Use e<3e < 3 if you like; the answer is the same.)

7. Calculus of one variable

CoreHuman

A student writes: lim⁡x→0x2+1x+1=lim⁡x→02x1=0\displaystyle\lim_{x \to 0} \frac{x^2 + 1}{x + 1} = \lim_{x \to 0} \frac{2x}{1} = 0. What is wrong?

Choose one

8. Calculus of one variable

StretchHuman

Let f(x)=e−1/x2f(x) = e^{-1/x^2} for x≠0x \ne 0 and f(0)=0f(0) = 0. On which set does ff equal the sum of its Maclaurin series?

Choose one

9. Calculus of one variable

StretchFormal

Which Lean statement correctly formalises the mean value theorem? (Here Icc a b is [a,b][a, b] and Ioo a b is (a,b)(a, b).)

Choose one

10. Calculus of one variable

StretchComputational

Write exp_taylor(x, n) returning Tn(x)=∑k=0nxk/k!T_n(x) = \sum_{k=0}^{n} x^k/k!, and degree_needed(x, tol) returning the least n≥0n \ge 0 for which the Lagrange bound emax⁡(x,0) ∣x∣n+1/(n+1)!e^{\max(x, 0)}\,|x|^{n+1}/(n+1)! is less than tol. Then check that Tn(x)T_n(x) really is within tol of math.exp(x).

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"A smooth function equals its Taylor series." Cauchy's function e−1/x2e^{-1/x^2} (with value 00 at 00) is smooth, all its derivatives at 00 vanish, and so its Taylor series at 00 is 00 — which equals the function only at x=0x = 0. Taylor's theorem f=Tn+Rnf = T_n + R_n always holds; convergence of the series to ff requires Rn(x)→0R_n(x) \to 0, which must be proved.

Misconception

"L'Hôpital's rule works for any quotient." It applies only to indeterminate forms 0/00/0 or ∞/∞\infty/\infty, and only when the limit of f′/g′f'/g' exists. lim⁡x→0x+1x+2=12\lim_{x \to 0} \frac{x + 1}{x + 2} = \frac12, but differentiating top and bottom gives 11. And the rule is not always the honest route: computing lim⁡x→0sin⁡xx\lim_{x \to 0} \frac{\sin x}{x} with L'Hôpital uses sin⁡′(0)=cos⁡0=1\sin'(0) = \cos 0 = 1 — which is that limit, so the argument is circular.

Misconception

"If an→0a_n \to 0, then ∑an\sum a_n converges." The condition an→0a_n \to 0 is necessary but not sufficient: the harmonic series diverges. (It grows like ln⁡N\ln N — very slowly, which is why computer experiments can mislead.)

Misconception

"∫−11dxx2=[−1x]−11=−2\int_{-1}^{1} \frac{dx}{x^2} = \Big[-\frac1x\Big]_{-1}^{1} = -2." A positive function cannot have negative integral. The fundamental theorem needs an antiderivative on the whole interval, and 1/x21/x^2 is unbounded at 00. As an improper integral, ∫01dx/x2\int_0^1 dx/x^2 diverges, so the integral does not exist.

Misconception

"A derivative is always continuous." f(x)=x2sin⁡(1/x)f(x) = x^2\sin(1/x) (with f(0)=0f(0) = 0) is differentiable everywhere, with f′(0)=0f'(0) = 0, but f′(x)=2xsin⁡(1/x)−cos⁡(1/x)f'(x) = 2x\sin(1/x) - \cos(1/x) has no limit as x→0x \to 0. Derivatives do, however, always have the intermediate value property (Darboux's theorem).

ViewpointsH

Many ways of seeing

Topology— Why [a, b] is special: connectedness and compactness

The intermediate value theorem and the extreme value theorem look like facts about functions, but they are facts about the interval. A continuous image of a connected space is connected, and the connected subsets of R\R are exactly the intervals: that is the intermediate value theorem. A continuous image of a compact space is compact, and [a,b][a, b] is compact by the Heine–Borel theorem; a compact subset of R\R is closed and bounded, so it contains its supremum and infimum: that is the extreme value theorem. Rolle's theorem, the mean value theorem, and through them all of calculus, therefore rest on two topological properties of [a,b][a, b]. Over Q\Q both fail: x2−2x^2 - 2 changes sign on [1,2]∩Q[1, 2] \cap \Q without a rational zero. See point-set topology.

Geometry— Tangent lines, parallel secants and curvature

The mean value theorem has a picture: some tangent line is parallel to the chord from (a,f(a))(a, f(a)) to (b,f(b))(b, f(b)). The derivative is the slope of the best linear approximation; the second derivative measures how the graph bends away from its tangent. For the graph of ff, the curvature is κ=∣f′′∣/(1+f′2)3/2\kappa = |f''|/(1 + f'^2)^{3/2}, and the circle of radius 1/κ1/\kappa through the point with the same tangent — the osculating circle — matches the curve to second order, just as the tangent line matches it to first order. Taylor polynomials are the higher-order version of the same idea: TnT_n is the unique polynomial of degree at most nn agreeing with ff to order nn at aa. See curves and surfaces.

Algebra— Differentiation is a derivation; dual numbers compute it

Algebraically, D=d/dxD = d/dx is a linear map satisfying the Leibniz rule D(fg)=(Df)g+f(Dg)D(fg) = (Df)g + f(Dg) — a derivation. On polynomials, DD is determined by D(x)=1D(x) = 1 and these two rules, with no limits at all. A clean way to compute derivatives mechanically uses the dual numbers R[ε]/(ε2)\R[\varepsilon]/(\varepsilon^2): for a polynomial pp, p(a+ε)=p(a)+p′(a) εp(a + \varepsilon) = p(a) + p'(a)\,\varepsilon exactly, because all higher powers of ε\varepsilon vanish. Extending this to exp⁡\exp, sin⁡\sin and the other elementary functions (via exp⁡(a+ε)=ea+eaε\exp(a + \varepsilon) = e^a + e^a\varepsilon, and so on) gives forward-mode automatic differentiation, which computes exact derivatives of programs; the chain rule is just composition of maps of dual numbers. The truncated Taylor polynomial is the analogous computation in R[ε]/(εn+1)\R[\varepsilon]/(\varepsilon^{n+1}).

Number theory— The series for e proves that e is irrational

Taylor's theorem with remainder gives arithmetic information. Suppose e=p/qe = p/q with integers p,q≥1p, q \ge 1. Multiply e=∑k≥01/k!e = \sum_{k \ge 0} 1/k! by q!q!:

q! e−∑k=0qq!k!=∑k>qq!k!=1q+1+1(q+1)(q+2)+⋯<1q+1+1(q+1)2+⋯=1q≤1.q!\,e - \sum_{k=0}^{q} \frac{q!}{k!} = \sum_{k > q} \frac{q!}{k!} = \frac{1}{q+1} + \frac{1}{(q+1)(q+2)} + \cdots < \frac1{q+1} + \frac1{(q+1)^2} + \cdots = \frac1q \le 1.

The left side is an integer (both q! e=(q−1)! pq!\,e = (q-1)!\,p and every q!/k!q!/k! with k≤qk \le q are integers), and the right side shows it lies strictly between 00 and 11. Contradiction: ee is irrational (Fourier's proof, published 1815). The same idea — a quantity that is a positive integer but smaller than 11 — drives the proofs that π\pi is irrational and that ee is transcendental (Hermite, 1873). See real numbers.

Analysis— Why 1/(1 + x²) stops at |x| = 1: look in the complex plane

The Maclaurin series of 1/(1+x2)1/(1 + x^2) is the geometric series ∑(−x2)n\sum (-x^2)^n, which converges exactly for ∣x∣<1|x| < 1 — although the function is smooth and bounded on all of R\R. The explanation is invisible on the real line. A power series ∑cnzn\sum c_n z^n converges on a disc ∣z∣<R|z| < R in the complex plane (and diverges for ∣z∣>R|z| > R), and the function 1/(1+z2)1/(1 + z^2) has poles at z=±iz = \pm i, at distance 11 from 00. By a theorem of complex analysis, the Taylor series of a function holomorphic on a disc converges to it on the whole disc; and it cannot converge on any larger disc, because that disc would contain a pole: the sum of a power series is continuous (indeed holomorphic) on its disc of convergence and would agree with 1/(1+z2)1/(1 + z^2) near the pole, where that function is unbounded. So R=1R = 1, and the real series is trapped in (−1,1)(-1, 1). Complex differentiability is so rigid that it forces analyticity — the opposite of the real world, where Cauchy's e−1/x2e^{-1/x^2} is smooth but not analytic. (Its complex version e−1/z2e^{-1/z^2} has an essential singularity at 00.)

Physics— Velocity, acceleration and Newton's fluxions

Newton called derivatives fluxions: the rate at which a "flowing quantity" changes in time. If x(t)x(t) is position, x′(t)x'(t) is velocity and x′′(t)x''(t) acceleration, and the fundamental theorem says displacement is the integral of velocity. The mean value theorem has a famous reading: if you drive 120120 km in 1.51.5 hours, at some instant your speedometer read exactly 8080 km/h — the reasoning behind the average-speed cameras used on highways in many countries. Taylor's theorem, cut off at second order, is the physicist's universal approximation: near a stable equilibrium every smooth potential looks like V(x0)+12V′′(x0)(x−x0)2V(x_0) + \tfrac12 V''(x_0)(x - x_0)^2, which is why harmonic oscillators are everywhere (see classical mechanics). That reasoning is a heuristic until one bounds the neglected remainder.

History & global context

History and global context

  • Ancient methods of exhaustion. Archimedes (3rd century BCE) found the area of a parabolic segment and the volume of a sphere by squeezing them between inscribed and circumscribed figures. In China, Liu Hui (3rd century CE) approximated π\pi with polygons of up to 3072 sides, and Zu Chongzhi and his son Zu Gengzhi (5th–6th centuries) used a principle equivalent to Cavalieri's to find the volume of a sphere.
  • Sums of powers and volumes. Ibn al-Haytham (Cairo, c. 1000) summed fourth powers of integers to find the volume of a solid obtained by rotating a parabola.
  • The Kerala school. Mādhava of Saṅgamagrāma (c. 1340–1425) and his successors in Kerala, India, found infinite series for arctan⁡\arctan, sin⁡\sin and cos⁡\cos, including π4=1−13+15−⋯\frac\pi4 = 1 - \frac13 + \frac15 - \cdots, together with correction terms to accelerate convergence. The work is preserved in texts such as Jyeṣṭhadeva's Yuktibhāṣā (c. 1530), which gives justifications.
  • The calculus of Newton and Leibniz. Pierre de Fermat found tangents and maxima (1630s); Isaac Barrow saw the inverse relation between tangents and areas. Isaac Newton developed his method of fluxions in 1665–66 (published much later), and Gottfried Wilhelm Leibniz published his differential calculus in 1684, with the notation dxdx and ∫\int we still use; the priority dispute that followed divided British and continental mathematics for a century. In Japan, Takebe Katahiro (1722) found a power series for the square of the arcsine.
  • Series and functions. Brook Taylor published his series in 1715 and Colin Maclaurin popularised the special case in 1742. Michel Rolle proved his theorem for polynomials (1691). Guillaume de l'Hôpital's textbook of 1696 contains the rule now named after him; it was taught to him by Johann Bernoulli. Leonhard Euler made functions and power series the centre of analysis (Introductio, 1748). Joseph-Louis Lagrange gave the remainder in the form above (1797).
  • Rigour. Bernard Bolzano proved the intermediate value theorem (1817). Augustin-Louis Cauchy's Cours d'analyse (1821) and Résumé (1823) defined limits, continuity, derivatives and integrals in essentially modern terms, proved the mean value theorem, and gave the function e−1/x2e^{-1/x^2}. Bernhard Riemann defined his integral in 1854. Karl Weierstrass made the ε–δ language standard in his Berlin lectures of the 1860s and constructed a continuous, nowhere-differentiable function (1872).
Further reading

Further reading

  • Michael Spivak, Calculus (1967; 4th edition 2008) — rigorous, beautiful and full of challenging problems; the model for this lesson's level.
  • Tom M. Apostol, Calculus, Volume 1 (2nd edition 1967) — integration before differentiation, with careful proofs.
  • Richard Courant and Fritz John, Introduction to Calculus and Analysis, Volume I (1965) — strong on applications and intuition.
  • Stephen Abbott, Understanding Analysis (2001; 2nd edition 2015) — the natural next step into real analysis.
  • Ernst Hairer and Gerhard Wanner, Analysis by Its History (1996) — the theorems of this lesson in their historical order, with original figures.
  • Otto Toeplitz, The Calculus: A Genetic Approach (1963).

Next in the Lumenary: multivariable calculus, ordinary differential equations, real analysis and numerical methods.