Module contents
Lesson 3 of 20Review 90 min

Sequences, series and completeness of the real numbers

Review real sequences and series from the supremum axiom through Bolzano–Weierstrass and Cauchy criteria, then measure convergence order and rate.

After this lesson you can

  • State the supremum axiom and use it to prove bounded monotone sequence convergence.
  • Prove Bolzano–Weierstrass and equivalence of convergence and the Cauchy condition in ℝ.
  • Choose and apply comparison, ratio, root, condensation and Leibniz series tests.
  • Distinguish absolute and conditional convergence and explain Riemann rearrangement.
  • Empirically estimate error-sequence convergence order and rate and predict iteration count.

Before you start

Motivation: convergence without knowing the limit

Almost everything a machine computes is a sequence limit. Gradient descent produces θ0,θ1,θ2,…\theta_0, \theta_1, \theta_2, \dots; Newton’s method x0,x1,x2,…x_0, x_1, x_2, \dots; value iteration in a decision problem functions V0,V1,V2,…V_0, V_1, V_2, \dots; a stochastic optimizer a cloud of iterates that should approach something. Every algorithmic guarantee is ultimately a theorem about real sequences:

  • Gradient descent with strongly convex loss and suitable step: L(θk)−L∗≤(1−μ/L)k (L(θ0)−L∗)\Loss(\theta_k) - \Loss^* \le (1 - \mu/L)^k\,(\Loss(\theta_0) - \Loss^*). Geometrically decreasing error (proved in gradient descent).
  • Newton near a simple root: ∣xk+1−x∗∣≤M∣xk−x∗∣2\abs{x_{k+1} - x^*} \le M\abs{x_k - x^*}^2. Correct digits double at each step (Newton’s quadratic convergence).
  • Discounted return in reinforcement learning: G=∑t≥0γtrtG = \sum_{t \ge 0} \gamma^t r_t. A convergent series because γ<1\gamma < 1 and rewards are bounded (discounted return).
  • SGD with step ηk=c/k\eta_k = c/k: error falling only as O(1/k)\bigO(1/k), with a proof using series such as ∑ηk=∞\sum \eta_k = \infty and ∑ηk2<∞\sum \eta_k^2 < \infty.

All share a deeper problem: we do not know the limit. That is what we want to calculate. How can convergence be proved without knowing where? Completeness of the real numbers says R\R has no holes: if sequence terms crowd together, there is a real number they approach. This lesson reviews first-year real analysis around that question and ends with an everyday tool rarely included in analysis courses: measuring and reading convergence speed.

Completeness: the supremum axiom

Let A⊆RA \subseteq \R. Number uu is an upper bound of AA if a≤ua \le u for every a∈Aa \in A; if one exists, AA is bounded above.

The formulations are equivalent: if no element of AA exceeds s−εs - \eps, then s−εs - \eps is an upper bound smaller than ss. The supremum need not belong to AA: sup⁡{1−1/n:n≥1}=1\sup\{1 - 1/n : n \ge 1\} = 1, which is not in the set. If it belongs, it is the maximum.

This is completeness of the real numbers. Together with ordered-field rules (addition, multiplication and inequalities), it characterizes R\R up to isomorphism: it is the only property R\R adds to what Q\Q already has. The rest of this lesson follows from it.

Why ℚ is insufficient

Proof

A rational s≤0s \le 0 is not an upper bound because 1∈A1 \in A; therefore let s>0s > 0 be rational. Since 2\sqrt 2 is irrational (if s2=2s^2 = 2 with irreducible s=m/ns = m/n, m2=2n2m^2 = 2n^2 forces mm even, then nn too, contradiction), either s2<2s^2 < 2 or s2>2s^2 > 2. In each case construct a rational showing ss is not the supremum. Consider

t=s−s2−2s+2=2s+2s+2,t2−2=2(s2−2)(s+2)2.t = s - \frac{s^2 - 2}{s + 2} = \frac{2s + 2}{s + 2}, \qquad t^2 - 2 = \frac{2(s^2 - 2)}{(s + 2)^2}.

Both identities follow by expansion. If s2<2s^2 < 2, then t>st > s and t2<2t^2 < 2: t∈At \in A and ss is not an upper bound. If s2>2s^2 > 2, then t<st < s and t2>2t^2 > 2, so every q∈Aq \in A satisfies q2<2<t2q^2 < 2 < t^2, i.e. q<tq < t: tt is a smaller upper bound than ss, so ss is not least. In both cases tt is rational because ss is.

∎

In R\R the supremum exists and its square is exactly 2: with s=sup⁡As = \sup A, the same tt from the argument (now real) excludes s2<2s^2 < 2 and s2>2s^2 > 2. Thus 2\sqrt 2 exists. The hole in Q\Q at 2\sqrt 2 is real and visible through a sequence. The convergents of 2\sqrt 2, rationals pn/qnp_n/q_n with p1=q1=1p_1 = q_1 = 1 and (pn+1,qn+1)=(pn+2qn, pn+qn)(p_{n+1}, q_{n+1}) = (p_n + 2q_n,\ p_n + q_n), are

1, 32, 75, 1712, 4129, 9970, 239169, 577408, …1,\ \frac{3}{2},\ \frac{7}{5},\ \frac{17}{12},\ \frac{41}{29},\ \frac{99}{70},\ \frac{239}{169},\ \frac{577}{408},\ \dots

Induction on nn verifies pn2−2qn2=(−1)np_n^2 - 2q_n^2 = (-1)^n: the step is (p+2q)2−2(p+q)2=−(p2−2q2)(p + 2q)^2 - 2(p + q)^2 = -(p^2 - 2q^2). Hence (pn/qn)2−2=±1/qn2(p_n/q_n)^2 - 2 = \pm 1/q_n^2, which tends to zero but never vanishes. Terms crowd together (consecutive terms differ by 1/(qnqn+1)1/(q_n q_{n+1})), but their limit is irrational.

InteractiveThe Cauchy window
Convergents of 2\sqrt 2: ana_n versus nn
  • tail n≥Nn \ge N
  • outside the band
  • band of width ε\varepsilon
√2, not in ℚ
  • tail diameter dNd_N
  • jump ∣aN+1−aN∣|a_{N+1} - a_N|
  • ε\varepsilon
Sequence
0.01
3
Tail diameter dNd_N0.016670.01667
Jump ∣aN+1−aN∣|a_{N+1} - a_N|0.016670.01667
Does the tail fit in the band?no
Smallest NN for this ε\varepsilon4
aN=pN/qNa_N = p_N/q_N7/57/5
aN2−2=±1/qN2a_N^2 - 2 = \pm 1/q_N^2−1/25-1/25
The tail still leaves the band. Drag NN right: N=4N = 4 suffices.
Choose width ε\varepsilon and drag tail start NN. The band covers terms ana_n with n≥Nn \ge N; the tail fits if all pairs differ by less than ε\varepsilon. Below on a log scale: tail diameter dN=sup⁡m,n≥N∣am−an∣d_N = \sup_{m, n \ge N}\abs{a_m - a_n} versus consecutive jump. With convergents of 2\sqrt 2, the tail fits every band but readout aN2−2=±1/qN2a_N^2 - 2 = \pm 1/q_N^2 never vanishes: there is no limit in Q\mathbb{Q}. Compare harmonic sums HnH_n and sin⁡n\sin\sqrt n: their jumps tend to zero, yet can you fit the tail?

The figure anticipates the central idea. Whether a sequence tail fits increasingly narrow bands can be checked without knowing the limit: compare terms with each other. In R\R this ensures a limit; in Q\Q it does not. Completeness belongs to the space, not the sequence.

The Archimedean property

Proof

If N\N were bounded, it would have supremum ss. Then s−1s - 1 would not be an upper bound, so some n∈Nn \in \N satisfies n>s−1n > s - 1, i.e. n+1>sn + 1 > s with n+1∈Nn + 1 \in \N. Contradiction. For the second form take n>1/εn > 1/\eps.

∎

This seems obvious but does not follow from ordered-field axioms: non-Archimedean ordered fields with infinitesimals exist, such as rational functions p(t)/q(t)p(t)/q(t) ordered by behavior as t→∞t \to \infty. The property makes 1/n→01/n \to 0 and Q\Q dense in R\R: between reals x<yx < y lies a rational, because choosing n>1/(y−x)n > 1/(y - x) puts some multiple m/nm/n between them.

Limit of a sequence

The definition is the discrete epsilon–delta limit: instead of x→ax \to a, the index tends to infinity.

This is the limit of a sequence, from which routine properties follow. Limits are unique: if an→La_n \to L and an→L′a_n \to L', with ε=∣L−L′∣/2\eps = \abs{L - L'}/2 their neighborhoods are disjoint and ana_n cannot be in both. Every convergent sequence is bounded: with ε=1\eps = 1, from NN onward terms lie in (L−1,L+1)(L - 1, L + 1), with finitely many before. Limits respect sums, products, quotients with nonzero denominator limit, and nonstrict inequalities; if an≤bn≤cna_n \le b_n \le c_n with an,cn→La_n, c_n \to L, also bn→Lb_n \to L (the squeeze theorem). A function is continuous at LL iff it preserves sequence limits: an→La_n \to L implies f(an)→f(L)f(a_n) \to f(L). This permits passing to the limit in iteration xk+1=g(xk)x_{k+1} = g(x_k) with continuous gg: if xk→x∗x_k \to x^*, then x∗=g(x∗)x^* = g(x^*). Probability generalizes this to random-variable sequences in nonequivalent ways, including almost-sure convergence, convergence in probability and convergence in distribution; choosing the right one is part of stating the law of large numbers or SGD convergence.

Bounded monotone sequences

Proof

Let (an)(a_n) be increasing and bounded. Set {an}\{a_n\} is nonempty and bounded, so by the supremum axiom has supremum ss. Given ε>0\eps > 0, s−εs - \eps is not an upper bound: some NN satisfies aN>s−εa_N > s - \eps. Since the sequence increases, s−ε<aN≤an≤ss - \eps < a_N \le a_n \le s for all n≥Nn \ge N, i.e. ∣an−s∣<ε\abs{a_n - s} < \eps. Apply this to (−an)(-a_n) for the decreasing case.

∎

This first theorem proves convergence without knowing the limit: monotonicity and a bound suffice. It analyzes the Babylonian iteration for 2\sqrt 2, Newton’s method applied to x2−2x^2 - 2:

xk+1=12(xk+2xk),x0=2.x_{k+1} = \frac{1}{2}\Big(x_k + \frac{2}{x_k}\Big), \qquad x_0 = 2.

Arithmetic–geometric mean gives xk+1≥xk⋅2/xk=2x_{k+1} \ge \sqrt{x_k \cdot 2/x_k} = \sqrt 2 for all k≥0k \ge 0 (if xk>0x_k > 0, all iterates are positive by induction). Also xk+1−xk=(2−xk2)/(2xk)≤0x_{k+1} - x_k = (2 - x_k^2)/(2x_k) \le 0 because xk2≥2x_k^2 \ge 2. The sequence decreases and is bounded below, so converges to L≥2>0L \ge \sqrt 2 > 0; passing to the limit gives L=(L+2/L)/2L = (L + 2/L)/2, i.e. L2=2L^2 = 2. Logical order matters: first prove existence, only then calculate. Skipping that step would likewise “prove” xk+1=2xkx_{k+1} = 2x_k with x0=1x_0 = 1 converges to 00 because L=2LL = 2L.

All iterates are rational if x0x_0 is: from x0=1x_0 = 1 come 3/23/2, 17/1217/12, 577/408577/408, 665857/470832665857/470832, exactly convergents pn/qnp_n/q_n with n=2,4,8,16n = 2, 4, 8, 16. Newton traverses convergents at doubling indices: this is quadratic convergence, as we will see.

Upper and lower limits

A bounded sequence may not converge, but two numbers summarize long-run behavior. For each nn let sn=sup⁡k≥naks_n = \sup_{k \ge n} a_k. Removing terms cannot increase the supremum, so (sn)(s_n) decreases; similarly in=inf⁡k≥naki_n = \inf_{k \ge n} a_k increases.

Always lim inf⁡an≤lim sup⁡an\liminf a_n \le \limsup a_n, and a sequence converges iff they are equal and finite, their common value being the limit: if in≤an≤sni_n \le a_n \le s_n and both endpoints have the same limit, squeeze finishes the proof. The upper limit is the largest subsequential limit and lower limit the smallest. For an=(−1)n(1+1/n)a_n = (-1)^n(1 + 1/n), lim sup⁡an=1\limsup a_n = 1 and lim inf⁡an=−1\liminf a_n = -1: it oscillates without convergence. We use these in ratio and root tests, generally stated with lim sup⁡\limsup because the limit may not exist.

Bolzano–Weierstrass and Cauchy sequences

A bounded sequence need not converge, but always has a part that does. A subsequence of (an)(a_n) is (anj)j≥1(a_{n_j})_{j \ge 1} with strictly increasing indices n1<n2<⋯n_1 < n_2 < \cdots.

Proof

Call index mm a peak if am≥ana_m \ge a_n for all n>mn > m: no later term exceeds ama_m. If infinitely many peaks m1<m2<⋯m_1 < m_2 < \cdots exist, am1≥am2≥⋯a_{m_1} \ge a_{m_2} \ge \cdots is a decreasing subsequence. If finitely many exist, choose n1n_1 after all of them. Since n1n_1 is not a peak, some n2>n1n_2 > n_1 satisfies an2>an1a_{n_2} > a_{n_1}; since n2n_2 is not a peak either, some n3>n2n_3 > n_2 satisfies an3>an2a_{n_3} > a_{n_2}, and so on. Each index depends on previous ones: recursive construction justified by strong induction. The result is strictly increasing.

∎

This is the Bolzano–Weierstrass theorem. In R\R it is immediate: the preceding lemma’s monotone subsequence is bounded and converges by monotone convergence. In Rd\R^d extract a subsequence with convergent first coordinate, then a subsequence of it with convergent second coordinate, and so on dd times; the last works for all coordinates simultaneously, and in Rd\R^d coordinate convergence equals norm convergence. Lesson 5 shows this means closed bounded subsets of Rd\R^d are compact, and why it fails in infinite dimensions.

A Cauchy sequence is exactly one passing the window test: for every width ε\eps some tail fits in a band of that width. The definition mentions no limit, making it appropriate for algorithms.

The forward implication holds in any space: if an→La_n \to L, given ε\eps choose NN with ∣an−L∣<ε/2\abs{a_n - L} < \eps/2 for n≥Nn \ge N; then ∣am−an∣≤∣am−L∣+∣L−an∣<ε\abs{a_m - a_n} \le \abs{a_m - L} + \abs{L - a_n} < \eps. The converse uses completeness: a Cauchy sequence is bounded, Bolzano–Weierstrass gives a convergent subsequence, and a Cauchy sequence with a convergent subsequence converges to the same limit. Exercises reconstruct this. In Q\Q Bolzano–Weierstrass fails precisely: convergents of 2\sqrt 2 are Cauchy and none of their subsequences converges in Q\Q.

Contractions: the pattern of most proofs

How do we prove algorithm iterates are Cauchy in practice? Usually as follows.

Proof

By induction, ∣xj+1−xj∣≤cj∣x1−x0∣\abs{x_{j+1} - x_j} \le c^j\abs{x_1 - x_0}. For m>km > k, triangle inequality and geometric-series sum give

∣xm−xk∣≤∑j=km−1∣xj+1−xj∣≤∣x1−x0∣∑j=k∞cj=ck1−c∣x1−x0∣,\abs{x_m - x_k} \le \sum_{j = k}^{m - 1}\abs{x_{j+1} - x_j} \le \abs{x_1 - x_0}\sum_{j = k}^{\infty} c^j = \frac{c^k}{1 - c}\abs{x_1 - x_0},

which tends to zero as k→∞k \to \infty uniformly in mm. The sequence is Cauchy and converges by completeness. Letting m→∞m \to \infty in the inequality gives the bound.

∎

The bound is an a priori estimate: the first step already says how many iterations suffice without knowing x∗x^*. Summing from step kk instead gives the a posteriori estimate ∣xk−x∗∣≤c1−c∣xk−xk−1∣\abs{x_k - x^*} \le \frac{c}{1 - c}\abs{x_k - x_{k-1}}, using the last observed step and justifying stopping when steps become small (if a bound on cc is known). With g(x)=cos⁡xg(x) = \cos x on [0,1][0, 1], ∣g′(x)∣=∣sin⁡x∣≤sin⁡1<0.85\abs{g'(x)} = \abs{\sin x} \le \sin 1 < 0.85, and the mean-value theorem gives ∣xk+1−xk∣≤0.85 ∣xk−xk−1∣\abs{x_{k+1} - x_k} \le 0.85\,\abs{x_k - x_{k-1}}: iteration xk+1=cos⁡xkx_{k+1} = \cos x_k converges from any point of [0,1][0, 1] to unique fixed point x∗≈0.739085x^* \approx 0.739085. Generalized to function spaces, this is the Banach fixed-point theorem, proving convergence of reinforcement-learning value iteration.

Series

A series ∑k≥1ak\sum_{k \ge 1} a_k is not literally an infinite sum: it is the sequence of partial sums Sn=a1+⋯+anS_n = a_1 + \cdots + a_n.

Deciding this efficiently is series convergence; a collection of tests helps. The fundamental example is the geometric series: for r≠1r \neq 1, Sn=∑k=0n−1rk=(1−rn)/(1−r)S_n = \sum_{k=0}^{n-1} r^k = (1 - r^n)/(1 - r), converging to 1/(1−r)1/(1 - r) if ∣r∣<1\abs{r} < 1 and diverging if ∣r∣≥1\abs{r} \ge 1. The second is a telescoping series: if ak=bk−bk+1a_k = b_k - b_{k+1}, then Sn=b1−bn+1S_n = b_1 - b_{n+1}, and the series converges iff (bn)(b_n) converges.

Applied to partial sums, Cauchy’s criterion yields the Cauchy criterion for series: ∑ak\sum a_k converges iff for every ε>0\eps > 0 some NN satisfies ∣an+1+⋯+am∣<ε\abs{a_{n+1} + \cdots + a_m} < \eps for all m>n≥Nm > n \ge N. Taking m=n+1m = n + 1 gives the best-known necessary condition.

The necessary condition and harmonic series

If ∑ak\sum a_k converges, then ak=Sk−Sk−1→S−S=0a_k = S_k - S_{k-1} \to S - S = 0. The converse is false: the harmonic series ∑1/k\sum 1/k diverges despite 1/k→01/k \to 0. Oresme’s 14th-century proof groups terms into blocks summing to at least 1/21/2:

1+12+(13+14)+(15+⋯+18)+⋯ ≥ 1+12+12+12+⋯1 + \frac12 + \Big(\frac13 + \frac14\Big) + \Big(\frac15 + \cdots + \frac18\Big) + \cdots \ \ge\ 1 + \frac12 + \frac12 + \frac12 + \cdots

so H2m≥1+m/2→∞H_{2^m} \ge 1 + m/2 \to \infty. It diverges very slowly: Hn=ln⁡n+γ+O(1/n)H_n = \ln n + \gamma + \bigO(1/n) with Euler–Mascheroni constant γ≈0.5772\gamma \approx 0.5772, and about 1.5×10431.5 \times 10^{43} terms are needed for the sum to exceed 100.

Nonnegative terms: comparison

If ak≥0a_k \ge 0, partial sums increase, and monotone convergence makes the series convergent iff (Sn)(S_n) is bounded. Everything else follows.

The first follows by bounding partial sums. For the second, eventually c2bk≤ak≤2c bk\frac{c}{2}b_k \le a_k \le 2c\,b_k, so use the first in both directions. For example ∑1/(k2+3k)\sum 1/(k^2 + 3k) converges by limit comparison with ∑1/k2\sum 1/k^2, and ∑1/(2k−1)\sum 1/(2k - 1) diverges by comparison with the harmonic series.

Ratio and root

Comparison with a geometric series yields two tests requiring no guessed comparator.

Proof

Root: if ρ<1\rho < 1 choose rr with ρ<r<1\rho < r < 1. By definition of lim sup⁡\limsup, ∣ak∣1/k<r\abs{a_k}^{1/k} < r from some kk, i.e. ∣ak∣<rk\abs{a_k} < r^k, so geometric comparison gives convergence. If ρ>1\rho > 1 infinitely many kk satisfy ∣ak∣>1\abs{a_k} > 1 and terms do not tend to zero. Ratio: if ∣ak+1/ak∣≤r<1\abs{a_{k+1}/a_k} \le r < 1 for k≥Kk \ge K, induction gives ∣ak∣≤∣aK∣ rk−K\abs{a_k} \le \abs{a_K}\,r^{k - K}, again geometric. If ∣ak+1∣≥∣ak∣\abs{a_{k+1}} \ge \abs{a_k} eventually, ∣ak∣\abs{a_k} does not tend to zero.

∎

The boundary is a classic trap. For ∑1/k\sum 1/k and ∑1/k2\sum 1/k^2 both ratio and root tend to 1, yet one diverges and the other converges: 1 says nothing. The root test is strictly stronger: always lim inf⁡∣ak+1/ak∣≤lim inf⁡∣ak∣1/k≤lim sup⁡∣ak∣1/k≤lim sup⁡∣ak+1/ak∣\liminf \abs{a_{k+1}/a_k} \le \liminf \abs{a_k}^{1/k} \le \limsup \abs{a_k}^{1/k} \le \limsup \abs{a_{k+1}/a_k}. With ak=2−k+(−1)ka_k = 2^{-k + (-1)^k} ratios alternate between 22 and 1/81/8, so ratio test is inconclusive, while ∣ak∣1/k=2−1+(−1)k/k→1/2\abs{a_k}^{1/k} = 2^{-1 + (-1)^k/k} \to 1/2 and the series converges (in fact to 1). Ratio is more convenient with factorials: for ∑k!/kk\sum k!/k^k, ak+1/ak=(k/(k+1))k→1/ea_{k+1}/a_k = (k/(k+1))^k \to 1/e. Root test also gives a power series convergence radius.

Cauchy condensation and integration

For slowly decreasing terms such as 1/(kln⁡k)1/(k\ln k), geometric tests yield 1 and fail. Finer tools are needed.

Proof

Group terms into dyadic blocks Bj={2j,…,2j+1−1}B_j = \{2^j, \dots, 2^{j+1} - 1\} of 2j2^j terms each. Since the sequence decreases, every term of BjB_j lies between a2j+1a_{2^{j+1}} and a2ja_{2^j}, so

2ja2j+1≤∑k∈Bjak≤2ja2j.2^j a_{2^{j+1}} \le \sum_{k \in B_j} a_k \le 2^j a_{2^j}.

Summing in j≥0j \ge 0 gives 12∑j≥12ja2j≤∑k≥1ak≤∑j≥02ja2j\frac{1}{2}\sum_{j \ge 1} 2^{j} a_{2^{j}} \le \sum_{k \ge 1} a_k \le \sum_{j \ge 0} 2^j a_{2^j}. Partial sums of either series are bounded iff those of the other are.

∎

This turns Oresme’s argument into a test. Thus ∑1/(kln⁡k)\sum 1/(k\ln k) diverges because its condensed series is ∑j2j/(2j jln⁡2)=1ln⁡2∑j1/j\sum_j 2^j/(2^j\,j\ln 2) = \frac{1}{\ln 2}\sum_j 1/j; ∑1/(kln⁡2k)\sum 1/(k \ln^2 k) converges because its condensed series is a constant times ∑1/j2\sum 1/j^2. The most important case ∑1/kp\sum 1/k^p is an exercise.

The continuous version compares the series with an improper integral. If ff is positive and decreasing on [1,∞)[1, \infty) and ak=f(k)a_k = f(k), each term lies between integrals of ff on neighboring intervals, ∫kk+1f≤ak≤∫k−1kf\int_k^{k+1} f \le a_k \le \int_{k-1}^{k} f. Summing, the series converges iff ∫1∞f\int_1^\infty f converges, and remainder lies between two integrals:

∫n+1∞f(x) ⁣dx ≤ Rn=∑k>nak ≤ ∫n∞f(x) ⁣dx.\int_{n+1}^\infty f(x)\dd x \ \le\ R_n = \sum_{k > n} a_k \ \le\ \int_n^\infty f(x)\dd x.

For ∑1/k2\sum 1/k^2 this gives 1/(n+1)≤Rn≤1/n1/(n+1) \le R_n \le 1/n: with 1000 terms error is almost exactly 10−310^{-3} (actual 0.000999500.00099950). A convergent series can require many terms for few digits, and the integral bound estimates how many.

Alternating series: Leibniz

Proof

Even partial sums S2mS_{2m} increase because S2m+2−S2m=b2m+1−b2m+2≥0S_{2m+2} - S_{2m} = b_{2m+1} - b_{2m+2} \ge 0. Odd sums decrease similarly, and S2m≤S2m+1S_{2m} \le S_{2m+1} because S2m+1−S2m=b2m+1≥0S_{2m+1} - S_{2m} = b_{2m+1} \ge 0. Thus S2≤S4≤⋯≤S5≤S3≤S1S_2 \le S_4 \le \cdots \le S_5 \le S_3 \le S_1: intervals [S2m,S2m+1][S_{2m}, S_{2m+1}] nest and lengths b2m+1b_{2m+1} tend to zero. Both sequences are monotone and bounded, converging to the same value. Limit SS lies between consecutive partial sums, hence ∣S−Sn∣≤∣Sn+1−Sn∣=bn+1\abs{S - S_n} \le \abs{S_{n+1} - S_n} = b_{n+1}.

∎

The alternating harmonic series 1−12+13−14+⋯1 - \frac12 + \frac13 - \frac14 + \cdots converges to ln⁡2\ln 2 (integrate 1/(1+x)=∑(−x)k1/(1 + x) = \sum (-x)^k termwise on [0,1][0, 1], justified in power series). Leibniz’s bound is easy and often pessimistic: it guarantees error 10−310^{-3} with 999999 terms, while 500500 actually suffice because real error resembles bn+1/2b_{n+1}/2.

Which test to use

Term formTestExample
Does not tend to 0Necessary condition: diverges∑k/(k+1)\sum k/(k+1)
Difference of termsTelescoping∑1/(k(k+1))\sum 1/(k(k+1))
Powers rkr^k, factorialsRatio or root∑k!/kk\sum k!/k^k, ∑k52−k\sum k^5 2^{-k}
Polynomial ratioLimit comparison with 1/kp1/k^p∑(k+1)/(k3−2)\sum (k + 1)/(k^3 - 2)
Decreases like 1/(kln⁡qk)1/(k \ln^q k)Condensation or integral∑1/(kln⁡2k)\sum 1/(k \ln^2 k)
Alternating signs, decreasing magnitudeLeibniz plus error bound∑(−1)k/k\sum (-1)^k/\sqrt k
Arbitrary signsAbsolute convergence∑sin⁡(k)/k2\sum \sin(k)/k^2

Absolute and conditional convergence

If ∑∣ak∣\sum\abs{a_k} converges, so does ∑ak\sum a_k: triangle inequality gives ∣an+1+⋯+am∣≤∣an+1∣+⋯+∣am∣\abs{a_{n+1} + \cdots + a_m} \le \abs{a_{n+1}} + \cdots + \abs{a_m}, transferring the Cauchy criterion for absolute values to the original series. Alternating harmonic convergence is conditional: Leibniz gives convergence, but absolute values form the harmonic series. The distinction between absolute and conditional convergence seems technical until terms are reordered.

Proof

Given ε>0\eps > 0 choose NN with ∑k>N∣ak∣<ε\sum_{k > N}\abs{a_k} < \eps. Since σ\sigma is bijective, some MM has {σ(1),…,σ(M)}⊇{1,…,N}\{\sigma(1), \dots, \sigma(M)\} \supseteq \{1, \dots, N\}. For m≥Mm \ge M, difference ∑k≤maσ(k)−∑k≤Nak\sum_{k \le m} a_{\sigma(k)} - \sum_{k \le N} a_k is a sum of distinct terms aja_j with j>Nj > N, so its magnitude is below ε\eps. Hence ∣∑k≤maσ(k)−S∣<2ε\abs{\sum_{k \le m} a_{\sigma(k)} - S} < 2\eps for every m≥Mm \ge M. Absolute convergence of the rearranged series follows similarly with ∣ak∣\abs{a_k}.

∎

Riemann rearrangement theorem

For conditionally convergent series the opposite happens, in an extreme form.

Proof

Separate positive terms p1,p2,…p_1, p_2, \dots and magnitudes of negative ones q1,q2,…q_1, q_2, \dots, each in original order (zeros may be interleaved anywhere). Both series ∑pi\sum p_i and ∑qj\sum q_j diverge: if both converged the series would converge absolutely; if only one converged, partial sums of ∑ak\sum a_k would diverge. Also pi,qj→0p_i, q_j \to 0 because ak→0a_k \to 0.

The greedy algorithm: start S=0S = 0; if S≤TS \le T add the next positive; if S>TS > T add the next negative. Since ∑pi=∞\sum p_i = \infty it cannot stay below TT forever; since ∑qj=∞\sum q_j = \infty it cannot stay above either. It crosses TT infinitely often and uses every term of both lists, so is a rearrangement. After the first crossing, if Sn>TS_n > T, the last positive was added from a sum ≤T\le T, and only subtractions without crossing TT have followed; hence 0<Sn−T≤puˊltimo0 < S_n - T \le p_{\text{último}}. Similarly if Sn≤TS_n \le T, then 0≤T−Sn≤quˊltimo0 \le T - S_n \le q_{\text{último}}. Since last-used terms tend to zero, Sn→TS_n \to T. To diverge to +∞+\infty replace the fixed target with increasing targets 1,2,3,…1, 2, 3, \dots.

∎
InteractiveRearrange to reach any number
1+13+15+17+19+111+113+115+117+119+⋯1 +\tfrac{1}{3} +\tfrac{1}{5} +\tfrac{1}{7} +\tfrac{1}{9} +\tfrac{1}{11} +\tfrac{1}{13} +\tfrac{1}{15} +\tfrac{1}{17} +\tfrac{1}{19} + \cdots
  • positive step
  • negative step
  • target TT
  • natural order: ln⁡2\ln 2
Series
Rearrangement
3.14
n = 40 000
Partial sum SnS_n3.14003
∣Sn−T∣|S_n - T|0.001560.00156
Positives / negatives used39 703 / 297
Positives per negative (predicted e2(T−ln⁡2)e^{2(T-\ln 2)})133.7  (133.9)133.7\ \ (133.9)
Last positive / negative1.3⋅10−5 / 0.001681.3 \cdot 10^{-5} \,/\, 0.00168
Positive and negative sums diverge separately: there are always terms left to cross TT again, and error is bounded by the last term used.
The greedy algorithm rearranges 1−12+13−14+⋯1 - \tfrac12 + \tfrac13 - \tfrac14 + \cdots to reach target TT: blue steps are positives 1/(2i−1)1/(2i - 1) and red negatives −1/(2j)-1/(2j). Horizontal axis is logarithmic to show initial steps and all 40,000 terms. Play with T=πT = \pi: after 76 positive terms it crosses the target then oscillates around it with decreasing amplitude. Compare positive-to-negative count with e2(T−ln⁡2)e^{2(T - \ln 2)}. Try T=−2T = -2 and blocks p:qp{:}q. Then switch to ∑(−1)k+1/k2\sum (-1)^{k+1}/k^2, which converges absolutely: why does greedy get stuck?

The figure reveals a regularity the theorem does not state. If a rearrangement uses positives and negatives in asymptotic ratio α\alpha (e.g. blocks of pp positives and qq negatives, α=p/q\alpha = p/q), after mm blocks the partial sum is

∑i≤pm12i−1−∑j≤qm12j=(H2pm−12Hpm)−12Hqm ⟶ ln⁡2+12ln⁡pq,\sum_{i \le pm}\frac{1}{2i - 1} - \sum_{j \le qm}\frac{1}{2j} = \Big(H_{2pm} - \tfrac12 H_{pm}\Big) - \tfrac12 H_{qm} \ \longrightarrow\ \ln 2 + \tfrac12\ln\frac{p}{q},

using Hn=ln⁡n+γ+o(1)H_n = \ln n + \gamma + o(1): the γ\gamma terms cancel, leaving ln⁡(2pm)−12ln⁡(pm)−12ln⁡(qm)\ln(2pm) - \frac12\ln(pm) - \frac12\ln(qm). To reach TT greedy must use ratio α=e2(T−ln⁡2)\alpha = e^{2(T - \ln 2)}: about 134 positives per negative for T=πT = \pi, and T=−10T = -10 would need order e−21.4≈5×10−10e^{-21.4} \approx 5 \times 10^{-10} positives per negative; merely crossing −10-10 the first time needs roughly 2.7×1082.7 \times 10^8 negatives. The next cell checks the block formula.

[ ]Block rearrangements of the alternating harmonic seriesBrowser
import math
import numpy as np

def suma_por_bloques(p, q, bloques):
    """Suma parcial tras `bloques` bloques de p positivos 1/(2i-1) y q negativos -1/(2j)."""
    i = np.arange(1, p * bloques + 1)
    j = np.arange(1, q * bloques + 1)
    return np.sum(1.0 / (2 * i - 1)) - np.sum(1.0 / (2 * j))

print(" p  q   suma tras 10^5 bloques   ln 2 + ln(p/q)/2   diferencia")
for p, q in [(1, 1), (2, 1), (1, 2), (3, 1), (1, 4), (134, 1)]:
    s = suma_por_bloques(p, q, 100_000)
    pred = math.log(2) + 0.5 * math.log(p / q)
    print(f"{p:3d} {q:2d}   {s:20.10f}   {pred:16.10f}   {s - pred:.1e}")

# en la serie absolutamente convergente sum (-1)^(k+1)/k^2, el patrón no importa
def suma_bloques_cuadrados(p, q, bloques):
    i = np.arange(1, p * bloques + 1, dtype=np.float64)   # en float: (2i)^2 desborda los enteros de 32 bits
    j = np.arange(1, q * bloques + 1, dtype=np.float64)
    return np.sum(1.0 / (2 * i - 1) ** 2) - np.sum(1.0 / (2 * j) ** 2)

print("\nserie de 1/k^2 alternada, pi^2/12 =", round(math.pi**2 / 12, 10))
for p, q in [(1, 1), (2, 1), (1, 4)]:
    print(f"  bloques {p}:{q} -> {suma_bloques_cuadrados(p, q, 100_000):.10f}")

Pattern 1:11{:}1 is natural order and gives ln⁡2\ln 2; two positives per negative give 32ln⁡2≈1.0397\frac32\ln 2 \approx 1.0397; for the absolutely convergent series every rearrangement gives π2/12\pi^2/12, as the theorem says. Greedy reveals why: positive reserves sum only π2/8\pi^2/8 and negatives π2/24\pi^2/24, so for distant targets it exhausts corrective capacity, remains forever on one side and leaves terms unused.

Orders of convergence

Knowing xk→x∗x_k \to x^* is insufficient to choose an algorithm: iteration count matters. Let ek=∣xk−x∗∣e_k = \abs{x_k - x^*} be nonzero error.

This is convergence order and rate in Nocedal and Wright’s terminology. Q means quotient: definitions use consecutive-error ratios. A weaker version is R-linear (root) convergence: ek≤εke_k \le \varepsilon_k for some Q-linearly convergent εk\varepsilon_k. It permits errors not falling at every step but falling overall, like ek=2−k(2+(−1)k)e_k = 2^{-k}(2 + (-1)^k) whose ratios alternate between 1/61/6 and 3/23/2. Large-step gradient descent on ill-conditioned problems often behaves this way.

The four classes have distinctive graphical signatures:

  • Linear: ek≈Crke_k \approx C r^k, hence log⁡10ek≈klog⁡10r+c\log_{10} e_k \approx k\log_{10} r + c. A straight line on semilog axes, slope log⁡10r\log_{10} r. Each step gains the same number of digits: −log⁡10r-\log_{10} r. At r=0.9r = 0.9, one digit every 22 steps; at r=0.5r = 0.5, one bit per step.
  • Quadratic: log⁡ek+1≈2log⁡ek+log⁡M\log e_{k+1} \approx 2\log e_k + \log M. On semilog the curve plunges: correct digits double each step.
  • Sublinear: ek≈Ck−pe_k \approx C k^{-p}, hence log⁡ek≈−plog⁡k+c\log e_k \approx -p\log k + c. On semilog it flattens; it is a straight line on log-log axes, slope −p-p.
  • Superlinear without order: ek=1/k!e_k = 1/k! satisfies ek+1/ek=1/(k+1)→0e_{k+1}/e_k = 1/(k+1) \to 0 but ek+1/ekq→∞e_{k+1}/e_k^q \to \infty for every q>1q > 1. There is a continuum between linear and quadratic.
InteractiveReading convergence speed
  • 1/k
  • 1/k²
  • 0.9ᵏ
  • 0.5ᵏ
  • Newton √2
  • x = cos x
Scale
Sequences
3
eke_k2.12⋅10−62.12 \cdot 10^{-6}
Correct digits at kk and k+1k+15.67 → 11.80
ek+1/eke_{k+1}/e_k (linear rate)7.51⋅10−77.51 \cdot 10^{-7}
ek+1/ek2e_{k+1}/e_k^2 (quadratic constant)0.35360.3536
Estimated order qkq_k2.000
Local slope: semilog / log-log−6.124 / −49.02
First kk with ek≤10−10e_k \le 10^{-10}4
ek+1/ek→0e_{k+1}/e_k \to 0 and ek+1/ek2→1/(22)≈0.354e_{k+1}/e_k^2 \to 1/(2\sqrt 2) \approx 0.354: quadratic. Correct digits double each step.
Six error sequences overlaid: 1/k1/k, 1/k21/k^2, 0.9k0.9^k, 0.5k0.5^k, Newton for 2\sqrt 2 from x0=1x_0 = 1 and the cos⁡x\cos x fixed point from x0=1x_0 = 1. Both iteration errors use exact recurrences without subtracting nearly equal numbers, allowing tracking below machine precision. Switch linear, semilog and log-log scales and find straight curves. Select a sequence and move kk: readouts exactly match definition quantities. Which ratio stabilizes in each case? How many digits does Newton gain per step?

The figure shows all this. On linear axes all six look alike: all “go to zero.” On semilog 0.9k0.9^k and 0.5k0.5^k are straight, cosine fixed point becomes straight after a few steps (slope log⁡100.674≈−0.17\log_{10} 0.674 \approx -0.17), Newton plunges, and both sublinear curves flatten. On log-log sublinear curves are straight with slopes −1-1 and −2-2. Newton readouts show digit doubling: 0.40.4, 1.11.1, 2.62.6, 5.75.7, 11.811.8, 24.024.0 correct digits at steps 00 through 55 with ek+1/ek2→1/(22)≈0.354e_{k+1}/e_k^2 \to 1/(2\sqrt 2) \approx 0.354.

Where do constants come from? For iteration xk+1=g(xk)x_{k+1} = g(x_k) with differentiable gg and g(x∗)=x∗g(x^*) = x^*, the mean-value theorem gives ek+1=∣g′(ξk)∣ eke_{k+1} = \abs{g'(\xi_k)}\,e_k with ξk\xi_k between xkx_k and x∗x^*, so ek+1/ek→∣g′(x∗)∣e_{k+1}/e_k \to \abs{g'(x^*)}. If 0<∣g′(x∗)∣<10 < \abs{g'(x^*)} < 1 convergence is linear at that rate: for cosine, ∣−sin⁡x∗∣≈0.674\abs{-\sin x^*} \approx 0.674. If g′(x∗)=0g'(x^*) = 0, second-order Taylor gives ek+1≈12∣g′′(x∗)∣ ek2e_{k+1} \approx \frac12\abs{g''(x^*)}\,e_k^2: quadratic. Newton is exactly the iteration forcing g′(x∗)=0g'(x^*) = 0, and for g(x)=(x+2/x)/2g(x) = (x + 2/x)/2 gives 12g′′(2)=1/(22)\frac12 g''(\sqrt 2) = 1/(2\sqrt 2).

How many iterations

These definitions predict. If ek+1≤r eke_{k+1} \le r\,e_k, then ek≤rke0e_k \le r^k e_0, and reducing error by factor FF requires

k ≥ ln⁡Fln⁡(1/r).k \ \ge\ \frac{\ln F}{\ln(1/r)}.

With r=0.9r = 0.9 and F=106F = 10^6, k≥13.82/0.1054=131.1k \ge 13.82/0.1054 = 131.1: 132 iterations. With r=0.99r = 0.99, 1375. This is why condition number matters in optimization: with strong convexity, gradient-descent rate is order 1−1/κ1 - 1/\kappa and iterations grow linearly with κ\kappa.

In the quadratic case ek+1≤Mek2e_{k+1} \le M e_k^2 becomes Mek+1≤(Mek)2M e_{k+1} \le (M e_k)^2, hence Mek≤(Me0)2kM e_k \le (M e_0)^{2^k}. If Me0<1M e_0 < 1, tolerance ε\varepsilon is reached when

2k ≥ ln⁡(Mε)ln⁡(Me0),k ≥ log⁡2ln⁡(Mε)ln⁡(Me0).2^k \ \ge\ \frac{\ln(M\varepsilon)}{\ln(M e_0)}, \qquad k \ \ge\ \log_2\frac{\ln(M\varepsilon)}{\ln(M e_0)}.

Iteration count grows as the logarithm of the logarithm of precision: going from 10−810^{-8} to 10−1610^{-16} costs one extra step. Once inside region Mek<1M e_k < 1 Newton needs few more steps; reaching it is the hard part.

Implementation from scratch: estimate order

If errors satisfy ek+1≈μ ekqe_{k+1} \approx \mu\,e_k^q, taking logs at two successive steps and subtracting eliminates μ\mu:

q ≈ qk=log⁡(ek+1/ek)log⁡(ek/ek−1),μ≈μk=ek+1ekqk.q \ \approx\ q_k = \frac{\log(e_{k+1}/e_k)}{\log(e_k/e_{k-1})}, \qquad \mu \approx \mu_k = \frac{e_{k+1}}{e_k^{q_k}}.

If the limit is unknown, use steps dk=∣xk+1−xk∣d_k = \abs{x_{k+1} - x_k}, which under at least linear convergence behave like errors: dk=ek ∣1−(xk+1−x∗)/(xk−x∗)∣d_k = e_k\,\abs{1 - (x_{k+1} - x^*)/(x_k - x^*)} and their ratio tends to a constant. The cell implements this estimator on four cases. To observe several quadratic Newton steps without float64’s 10−1610^{-16}, Babylonian iteration uses decimal at 120 digits. The final block tests Aitken acceleration: if ek+1≈r eke_{k+1} \approx r\,e_k, combination xk−(Δxk)2/Δ2xkx_k - (\Delta x_k)^2/\Delta^2 x_k with Δxk=xk+1−xk\Delta x_k = x_{k+1} - x_k and Δ2xk=xk+2−2xk+1+xk\Delta^2 x_k = x_{k+2} - 2x_{k+1} + x_k removes the leading error term (exact for a x∗+Crkx^* + C r^k sequence; for iteration xk+1=g(xk)x_{k+1} = g(x_k) leaves order-ek2e_k^2 error).

[ ]Convergence-order estimatorBrowser
import math
from decimal import Decimal, getcontext

def estimate_order(e):
    """Órdenes q_k y constantes mu_k = e_{k+1} / e_k^q_k a partir de errores e_0, e_1, ... (positivos)."""
    q, mu = [], []
    for k in range(1, len(e) - 1):
        a, b, c = e[k - 1], e[k], e[k + 1]
        if min(a, b, c) <= 0 or a == b:
            break
        qk = math.log(c / b) / math.log(b / a)
        q.append(qk)
        mu.append(math.exp(math.log(c) - qk * math.log(b)))
    return q, mu

def steps_from_iterates(x):
    """Sin conocer el límite: d_k = |x_{k+1} - x_k| se comporta como e_k si la convergencia es al menos lineal."""
    return [abs(b - a) for a, b in zip(x, x[1:])]

# 1. Iteración babilónica (Newton) para raíz de 2, con 120 cifras para ver varios pasos cuadráticos
getcontext().prec = 120
r2 = Decimal(2).sqrt()
x = Decimal(1)
x_newton, e_newton = [], []
for _ in range(8):
    x_newton.append(x)
    e_newton.append(float(abs(x - r2)))
    x = (x + 2 / x) / 2
q, mu = estimate_order(e_newton)
print("Newton para raíz de 2")
print("  errores:", " ".join(f"{v:.1e}" for v in e_newton))
print("  q_k    :", " ".join(f"{v:.3f}" for v in q))
print("  mu_k   :", " ".join(f"{v:.3f}" for v in mu), "  1/(2 raíz de 2) =", round(1 / (2 * math.sqrt(2)), 3))
q_d, _ = estimate_order([float(v) for v in steps_from_iterates(x_newton)])
print("  sin conocer el límite, q_k con los pasos d_k:", " ".join(f"{v:.3f}" for v in q_d))

# 2. Punto fijo de cos: lineal con tasa |cos'(x*)| = sen x*
xs = [1.0]
for _ in range(80):
    xs.append(math.cos(xs[-1]))
xstar = xs[-1]
for _ in range(100):
    xstar = math.cos(xstar)
e_cos = [abs(v - xstar) for v in xs]
ratios = [b / a for a, b in zip(e_cos[:40], e_cos[1:40])]
print("\nPunto fijo de cos: x* =", xstar)
print("  e_{k+1}/e_k en k = 5, 15, 30:", [round(ratios[k], 4) for k in (5, 15, 30)], "  sen x* =", round(math.sin(xstar), 4))
d = steps_from_iterates(xs)
print("  sin conocer x*, d_{k+1}/d_k en k = 30:", round(d[31] / d[30], 4))

# 3. Sumas parciales de la serie de 1/k^2: sublineal, e_n ~ 1/n
S, e_zeta = 0.0, []
for n in range(1, 2001):
    S += 1 / n**2
    e_zeta.append(math.pi**2 / 6 - S)
print("\nSumas de 1/k^2: e_{n+1}/e_n en n = 10, 100, 1000:", [round(e_zeta[n] / e_zeta[n - 1], 5) for n in (10, 100, 1000)])
print("  n * e_n en n = 10, 100, 1000:", [round(n * e_zeta[n - 1], 4) for n in (10, 100, 1000)])

# 4. Aceleración de Aitken sobre el punto fijo de cos
def aitken(x):
    return [x[k] - (x[k + 1] - x[k]) ** 2 / (x[k + 2] - 2 * x[k + 1] + x[k]) for k in range(len(x) - 2)]

xa = aitken(xs[:16])
print("\nAitken sobre cos: error original, error acelerado, su cociente y acelerado / original^2")
for k in (2, 5, 8, 11):
    ea = abs(xa[k] - xstar)
    print(f"  k = {k:2d}: {e_cos[k]:.1e}   {ea:.1e}   {ea / e_cos[k]:.1e}   {ea / e_cos[k] ** 2:.3f}")

# 5. Predicción del número de iteraciones
def iters_linear(e0, rate, tol):
    return math.ceil(math.log(tol / e0) / math.log(rate))

def iters_quadratic(e0, M, tol):
    # e_{k+1} <= M e_k^2  implica  M e_k <= (M e_0)^(2^k)
    return math.ceil(math.log2(math.log(M * tol) / math.log(M * e0)))

pred = iters_linear(e_cos[0], math.sin(xstar), 1e-10)
real = next(k for k, v in enumerate(e_cos) if v <= 1e-10)
print(f"\ncos hasta 1e-10: predicción {pred}, real {real}")
predN = iters_quadratic(e_newton[0], 1 / (2 * math.sqrt(2)), 1e-16)
realN = next(k for k, v in enumerate(e_newton) if v <= 1e-16)
print(f"Newton hasta 1e-16: predicción {predN}, real {realN}")

Newton’s qkq_k settle at 2.0002.000 from the third step and μk\mu_k at 0.3540.354, Taylor’s predicted constant; using steps dkd_k instead of errors, without 2\sqrt 2, reaches the same 2.0002.000. Cosine ratios rise toward 0.6736=sin⁡x∗0.6736 = \sin x^* and step ratios dkd_k give the same rate without knowing x∗x^*: this is what a sound stopping criterion does. Sums of 1/k21/k^2 have ratios tending to 1 (sublinear) and nen→1n e_n \to 1, consistent with the integral bound. Aitken reduces cosine error by factors falling from 10−210^{-2} to 5×10−45 \times 10^{-4}; the last column shows why: accelerated error is almost exactly 0.15 ek20.15\,e_k^2. Since ek≈Crke_k \approx C r^k the accelerated sequence remains linear but at rate r2≈0.45r^2 \approx 0.45 instead of 0.670.67; its ratio to original error tends to zero. Restarting iteration from each accelerated value instead yields Steffensen’s derivative-free quadratic method. Predicted counts match actual: 55 for cosine and 5 for Newton.

With libraries: high precision and summation order

For high-digit series summation, mpmath uses arbitrary precision and nsum does more than termwise addition: by default (method="r+s") it sums increasingly long segments and extrapolates partial sums with Richardson extrapolation and the Shanks transformation until consecutive estimates agree; method="e" estimates the tail by Euler–Maclaurin. This systematizes Aitken’s idea (Richardson extrapolation appears in numerical methods).

[ ]Series to 50 digits: mpmath.nsumBrowser
from mpmath import mp, mpf, nsum, inf, pi, log, zeta, fsum
import numpy as np

mp.dps = 50

s1 = nsum(lambda k: 1 / k**2, [1, inf])
print("nsum 1/k^2           :", s1)
print("pi^2/6               :", pi**2 / 6)
S1000 = fsum(mpf(1) / k**2 for k in range(1, 1001))
print("suma de 1000 términos:", S1000, "  resto:", mp.nstr(pi**2 / 6 - S1000, 8))

s2 = nsum(lambda k: (-1) ** (k + 1) / mpf(k), [1, inf])
print("\nnsum armónica alternada:", s2)
print("ln 2                   :", log(2))

# una serie que converge de forma desesperadamente lenta: resto ~ 10 n^(-0.1)
s = mpf("1.1")
z = zeta(s)
print("\nzeta(1.1)             :", mp.nstr(z, 20))
directa = float(np.sum(1.0 / np.arange(1, 10**6 + 1, dtype=np.float64) ** 1.1))
print("suma de 10^6 términos :", directa, "  le faltan", mp.nstr(z - directa, 6))
for d in (15, 20):
    with mp.workdps(d):
        print(f"nsum con {d} cifras    :", mp.nstr(nsum(lambda k: 1 / mpf(k) ** s, [1, inf]), 10))

# lo que sí funciona: sumar n términos y estimar la cola con Euler-Maclaurin
n = 1000
Sn = fsum(1 / mpf(k) ** s for k in range(1, n + 1))
cola_integral = mpf(n) ** (1 - s) / (s - 1)                          # integral de x^-s de n a infinito
cola_em = cola_integral - mpf(n) ** (-s) / 2 + s * mpf(n) ** (-s - 1) / 12
print(f"S_1000 + integral     : {mp.nstr(Sn + cola_integral, 15)}   error {mp.nstr(z - Sn - cola_integral, 3)}")
print(f"S_1000 + Euler-Maclaurin: {mp.nstr(Sn + cola_em, 15)}   error {mp.nstr(z - Sn - cola_em, 3)}")

nsum reproduces π2/6\pi^2/6 and ln⁡2\ln 2 to all 50 digits, whereas 1000 terms of ∑1/k2\sum 1/k^2 leave remainder 0.000999500.00099950, as the integral bound predicted. The third case is most instructive. ∑1/k1.1\sum 1/k^{1.1} converges to ζ(1.1)≈10.5844\zeta(1.1) \approx 10.5844, but a million terms total only 8.07268.0726, and integral bound Rn≈10 n−0.1R_n \approx 10\,n^{-0.1} says order 104010^{40} terms are needed for error below 10−310^{-3}. nsum fails without warning: 6.446.44 at 15 working digits and 6.676.67 at 20, two different false values. Extrapolations assume a geometric or integer-power 1/n1/n tail, whereas this one decreases as n−0.1n^{-0.1}. What works is the lesson’s approach: sum 1000 terms and estimate remainder by integral for error 2.5×10−42.5 \times 10^{-4}; adding the first two Euler–Maclaurin corrections −f(n)/2−f′(n)/12-f(n)/2 - f'(n)/12 reduces it to 5×10−155 \times 10^{-15}. Convergence, computability by summation and computation by a library are distinct; always check numerical sums against a bound or known value.

Finally, summation order. Float32 machine epsilon is 2−23≈1.2×10−72^{-23} \approx 1.2 \times 10^{-7}: when accumulated sum is 1.641.64, adding a term below half the floating-point spacing, about 6×10−86 \times 10^{-8}, does not change it. In natural order every term of ∑1/k2\sum 1/k^2 from k≈4000k \approx 4000 is lost.

[ ]Floating-point summation orderBrowser
import math
import numpy as np

n = 10**6
t = (1.0 / np.arange(1, n + 1, dtype=np.float64) ** 2).astype(np.float32)
exacta = math.pi**2 / 6 - 1 / (n + 0.5)      # suma de n términos, con el resto aproximado por la integral

hacia_delante = np.cumsum(t, dtype=np.float32)[-1]       # suma secuencial: 1 + 1/4 + 1/9 + ...
hacia_atras = np.cumsum(t[::-1], dtype=np.float32)[-1]   # de los términos pequeños a los grandes
por_pares = np.sum(t, dtype=np.float32)                   # NumPy suma por pares (árbol)
fsum = math.fsum(t.astype(np.float64))                    # suma exacta de los float32, redondeada una vez

for nombre, v in [("hacia delante", hacia_delante), ("hacia atrás", hacia_atras), ("por pares", por_pares), ("math.fsum", fsum)]:
    print(f"{nombre:14s} {float(v):.9f}   error relativo {abs(float(v) - exacta) / exacta:.1e}")
print("valor de referencia", f"{exacta:.9f}")

Forward summation leaves relative error order 10−410^{-4}, a thousand float32 epsilons; adding small terms first or pairwise reduces it to machine precision. The series converges absolutely and its exact sum is order-independent; accumulated rounding depends on order. In practice sum small terms first, use pairwise or compensated sums, or accumulate at higher precision. See pairwise summation and Kahan compensated summation.

Common mistakes

Exercises

NumericA telescoping sum
Calculate ∑k=1∞1k(k+1)\sum_{k=1}^{\infty} \frac{1}{k(k+1)}.
QuizWhen the ratio tends to 1
For a positive-term series, ak+1/ak→1a_{k+1}/a_k \to 1. What follows?
QuizCauchy in ℚ without a limit in ℚ
Which rational sequences are Cauchy but have no limit in Q\mathbb{Q}?

More than one answer may be correct.

QuizClassify convergence orders
Let eke_k be a method’s error sequence. Which classifications are correct?

More than one answer may be correct.

NumericHow many iterations?
An iteration converges linearly with ek+1=0.9 eke_{k+1} = 0.9\,e_k. What is the smallest iteration count reducing error by factor 10610^6, i.e. satisfying ek≤10−6 e0e_k \le 10^{-6}\,e_0?
QuizLinear or quadratic?
Method A converges linearly with ek=10−2ke_k = 10^{-2k}. Method B converges quadratically with ek+1=ek2e_{k+1} = e_k^2 and e0=0.9e_0 = 0.9. Iterations cost the same. Which first reaches error ek≤10−9e_k \le 10^{-9}?
NumericCosine fixed-point rate
Iteration xk+1=cos⁡xkx_{k+1} = \cos x_k converges to fixed point x∗≈0.739085x^* \approx 0.739085. What is its linear convergence rate lim⁡kek+1/ek\lim_k e_{k+1}/e_k?
NumericTwo positives per negative
Rearrange the alternating harmonic series using two positives per negative: 1+13−12+15+17−14+⋯1 + \frac13 - \frac12 + \frac15 + \frac17 - \frac14 + \cdots What is its sum?
NumericWhat Leibniz guarantees
By the Leibniz bound, what is the smallest term count nn of 1−12+13−⋯1 - \frac12 + \frac13 - \cdots that guarantees ∣ln⁡2−Sn∣≤10−3\abs{\ln 2 - S_n} \le 10^{-3}?
ProofEvery Cauchy sequence converges
Prove: Every Cauchy sequence (an)(a_n) of real numbers converges.
0
Let (an)(a_n) be Cauchy. Use Bolzano–Weierstrass, where completeness enters.

Step 1 of 4. What must you first establish to apply Bolzano–Weierstrass?

ProofThe 1/kᵖ series by condensation
Prove: Series ∑k≥11/kp\sum_{k \ge 1} 1/k^p converges iff p>1p > 1.
0
Cauchy condensation says that for decreasing ak≥0a_k \ge 0, ∑ak\sum a_k converges iff ∑j≥02ja2j\sum_{j \ge 0} 2^j a_{2^j} converges.

Step 1 of 4. What if p≤0p \le 0?

CodeRearrange toward a target
Implement rearrange_to_target(target, n_terms) applying Riemann’s greedy algorithm to the alternating harmonic series and returning its first n_terms partial sums S1,…,SnS_1, \dots, S_n. Start at S=0S = 0; at each step if S≤TS \le T add the next unused positive 1,13,15,…1, \frac13, \frac15, \dots; if S>TS > T subtract the next unused negative 12,14,16,…\frac12, \frac14, \frac16, \dots. Tests check, among other things, the proof bound: after the first crossing, if Sn>TS_n > T then Sn−TS_n - T does not exceed the last positive used, and if Sn≤TS_n \le T then T−SnT - S_n does not exceed the last negative used.
def rearrange_to_target(target, n_terms):
  """Sumas parciales S_1, ..., S_n de la reordenación voraz de 1 - 1/2 + 1/3 - 1/4 + ..."""
  sums = []
  s = 0.0
  # tu código: si s <= target, suma el siguiente positivo 1/(2i - 1); si no, resta el siguiente 1/(2j)
  return sums
Shift+Enter to run

Summary

Key idea
Completeness of R\R turns the Cauchy condition, which compares only terms, into convergence: algorithms can therefore be proved convergent without knowing the limit. Once convergent, speed matters, read from successive-error ratios and the scale where the error curve is straight.
  • The supremum axiom distinguishes R\R from Q\Q. It yields the Archimedean property, bounded monotone convergence, Bolzano–Weierstrass and Cauchy’s criterion.
  • A rational Cauchy sequence may have no rational limit, such as convergents pn/qnp_n/q_n of 2\sqrt 2. Consecutive jumps tending to zero do not suffice for Cauchy.
  • Contracting steps ∣xk+1−xk∣≤c∣xk−xk−1∣\abs{x_{k+1} - x_k} \le c\abs{x_k - x_{k-1}} with c<1c < 1 yield a Cauchy sequence, a priori bound ∣xk−x∗∣≤ck∣x1−x0∣/(1−c)\abs{x_k - x^*} \le c^k\abs{x_1 - x_0}/(1 - c) and a posteriori bound ∣xk−x∗∣≤c∣xk−xk−1∣/(1−c)\abs{x_k - x^*} \le c\abs{x_k - x_{k-1}}/(1 - c): the core of Banach’s theorem.
  • For series: nonvanishing terms imply divergence; comparison, ratio and root compare with geometric series and cannot decide boundary 1; condensation and integration handle scales 1/kp1/k^p and 1/(kln⁡qk)1/(k\ln^q k); Leibniz gives alternating convergence and an error bound.
  • Absolute convergence permits rearrangement without changing the sum. A conditionally convergent series can be rearranged to any sum; for alternating harmonic series, asymptotic positive-negative ratio α\alpha yields ln⁡2+12ln⁡α\ln 2 + \frac12\ln\alpha.
  • Linear convergence at rate rr is a semilog line of slope log⁡10r\log_{10} r and needs ln⁡F/ln⁡(1/r)\ln F/\ln(1/r) steps to reduce error by factor FF; quadratic doubles digits and takes order log⁡2log⁡(1/ε)\log_2\log(1/\varepsilon) steps; sublinear k−pk^{-p} is a log-log line of slope −p-p. Order can be estimated by qk=log⁡(ek+1/ek)/log⁡(ek/ek−1)q_k = \log(e_{k+1}/e_k)/\log(e_k/e_{k-1}) using steps even without knowing the limit.