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 ; Newton’s method ; value iteration in a decision problem functions ; 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: . Geometrically decreasing error (proved in gradient descent).
- Newton near a simple root: . Correct digits double at each step (Newton’s quadratic convergence).
- Discounted return in reinforcement learning: . A convergent series because and rewards are bounded (discounted return).
- SGD with step : error falling only as , with a proof using series such as and .
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 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 . Number is an upper bound of if for every ; if one exists, is bounded above.
The formulations are equivalent: if no element of exceeds , then is an upper bound smaller than . The supremum need not belong to : , 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 up to isomorphism: it is the only property adds to what already has. The rest of this lesson follows from it.
Why ℚ is insufficient
Proof
A rational is not an upper bound because ; therefore let be rational. Since is irrational (if with irreducible , forces even, then too, contradiction), either or . In each case construct a rational showing is not the supremum. Consider
Both identities follow by expansion. If , then and : and is not an upper bound. If , then and , so every satisfies , i.e. : is a smaller upper bound than , so is not least. In both cases is rational because is.
∎In the supremum exists and its square is exactly 2: with , the same from the argument (now real) excludes and . Thus exists. The hole in at is real and visible through a sequence. The convergents of , rationals with and , are
Induction on verifies : the step is . Hence , which tends to zero but never vanishes. Terms crowd together (consecutive terms differ by ), but their limit is irrational.
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 this ensures a limit; in it does not. Completeness belongs to the space, not the sequence.
The Archimedean property
Proof
If were bounded, it would have supremum . Then would not be an upper bound, so some satisfies , i.e. with . Contradiction. For the second form take .
∎This seems obvious but does not follow from ordered-field axioms: non-Archimedean ordered fields with infinitesimals exist, such as rational functions ordered by behavior as . The property makes and dense in : between reals lies a rational, because choosing puts some multiple between them.
Limit of a sequence
The definition is the discrete epsilon–delta limit: instead of , the index tends to infinity.
This is the limit of a sequence, from which routine properties follow. Limits are unique: if and , with their neighborhoods are disjoint and cannot be in both. Every convergent sequence is bounded: with , from onward terms lie in , with finitely many before. Limits respect sums, products, quotients with nonzero denominator limit, and nonstrict inequalities; if with , also (the squeeze theorem). A function is continuous at iff it preserves sequence limits: implies . This permits passing to the limit in iteration with continuous : if , then . 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 be increasing and bounded. Set is nonempty and bounded, so by the supremum axiom has supremum . Given , is not an upper bound: some satisfies . Since the sequence increases, for all , i.e. . Apply this to for the decreasing case.
∎This first theorem proves convergence without knowing the limit: monotonicity and a bound suffice. It analyzes the Babylonian iteration for , Newton’s method applied to :
Arithmetic–geometric mean gives for all (if , all iterates are positive by induction). Also because . The sequence decreases and is bounded below, so converges to ; passing to the limit gives , i.e. . Logical order matters: first prove existence, only then calculate. Skipping that step would likewise “prove” with converges to because .
All iterates are rational if is: from come , , , , exactly convergents with . 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 let . Removing terms cannot increase the supremum, so decreases; similarly increases.
Always , and a sequence converges iff they are equal and finite, their common value being the limit: if 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 , and : it oscillates without convergence. We use these in ratio and root tests, generally stated with 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 is with strictly increasing indices .
Proof
Call index a peak if for all : no later term exceeds . If infinitely many peaks exist, is a decreasing subsequence. If finitely many exist, choose after all of them. Since is not a peak, some satisfies ; since is not a peak either, some satisfies , 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 it is immediate: the preceding lemma’s monotone subsequence is bounded and converges by monotone convergence. In extract a subsequence with convergent first coordinate, then a subsequence of it with convergent second coordinate, and so on times; the last works for all coordinates simultaneously, and in coordinate convergence equals norm convergence. Lesson 5 shows this means closed bounded subsets of are compact, and why it fails in infinite dimensions.
A Cauchy sequence is exactly one passing the window test: for every width 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 , given choose with for ; then . 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 Bolzano–Weierstrass fails precisely: convergents of are Cauchy and none of their subsequences converges in .
Contractions: the pattern of most proofs
How do we prove algorithm iterates are Cauchy in practice? Usually as follows.
Proof
By induction, . For , triangle inequality and geometric-series sum give
which tends to zero as uniformly in . The sequence is Cauchy and converges by completeness. Letting in the inequality gives the bound.
∎The bound is an a priori estimate: the first step already says how many iterations suffice without knowing . Summing from step instead gives the a posteriori estimate , using the last observed step and justifying stopping when steps become small (if a bound on is known). With on , , and the mean-value theorem gives : iteration converges from any point of to unique fixed point . Generalized to function spaces, this is the Banach fixed-point theorem, proving convergence of reinforcement-learning value iteration.
Series
A series is not literally an infinite sum: it is the sequence of partial sums .
Deciding this efficiently is series convergence; a collection of tests helps. The fundamental example is the geometric series: for , , converging to if and diverging if . The second is a telescoping series: if , then , and the series converges iff converges.
Applied to partial sums, Cauchy’s criterion yields the Cauchy criterion for series: converges iff for every some satisfies for all . Taking gives the best-known necessary condition.
The necessary condition and harmonic series
If converges, then . The converse is false: the harmonic series diverges despite . Oresme’s 14th-century proof groups terms into blocks summing to at least :
so . It diverges very slowly: with Euler–Mascheroni constant , and about terms are needed for the sum to exceed 100.
Nonnegative terms: comparison
If , partial sums increase, and monotone convergence makes the series convergent iff is bounded. Everything else follows.
The first follows by bounding partial sums. For the second, eventually , so use the first in both directions. For example converges by limit comparison with , and 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 choose with . By definition of , from some , i.e. , so geometric comparison gives convergence. If infinitely many satisfy and terms do not tend to zero. Ratio: if for , induction gives , again geometric. If eventually, does not tend to zero.
∎The boundary is a classic trap. For and both ratio and root tend to 1, yet one diverges and the other converges: 1 says nothing. The root test is strictly stronger: always . With ratios alternate between and , so ratio test is inconclusive, while and the series converges (in fact to 1). Ratio is more convenient with factorials: for , . Root test also gives a power series convergence radius.
Cauchy condensation and integration
For slowly decreasing terms such as , geometric tests yield 1 and fail. Finer tools are needed.
Proof
Group terms into dyadic blocks of terms each. Since the sequence decreases, every term of lies between and , so
Summing in gives . Partial sums of either series are bounded iff those of the other are.
∎This turns Oresme’s argument into a test. Thus diverges because its condensed series is ; converges because its condensed series is a constant times . The most important case is an exercise.
The continuous version compares the series with an improper integral. If is positive and decreasing on and , each term lies between integrals of on neighboring intervals, . Summing, the series converges iff converges, and remainder lies between two integrals:
For this gives : with 1000 terms error is almost exactly (actual ). A convergent series can require many terms for few digits, and the integral bound estimates how many.
Alternating series: Leibniz
Proof
Even partial sums increase because . Odd sums decrease similarly, and because . Thus : intervals nest and lengths tend to zero. Both sequences are monotone and bounded, converging to the same value. Limit lies between consecutive partial sums, hence .
∎The alternating harmonic series converges to (integrate termwise on , justified in power series). Leibniz’s bound is easy and often pessimistic: it guarantees error with terms, while actually suffice because real error resembles .
Which test to use
| Term form | Test | Example |
|---|---|---|
| Does not tend to 0 | Necessary condition: diverges | |
| Difference of terms | Telescoping | |
| Powers , factorials | Ratio or root | , |
| Polynomial ratio | Limit comparison with | |
| Decreases like | Condensation or integral | |
| Alternating signs, decreasing magnitude | Leibniz plus error bound | |
| Arbitrary signs | Absolute convergence |
Absolute and conditional convergence
If converges, so does : triangle inequality gives , 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 choose with . Since is bijective, some has . For , difference is a sum of distinct terms with , so its magnitude is below . Hence for every . Absolute convergence of the rearranged series follows similarly with .
∎Riemann rearrangement theorem
For conditionally convergent series the opposite happens, in an extreme form.
Proof
Separate positive terms and magnitudes of negative ones , each in original order (zeros may be interleaved anywhere). Both series and diverge: if both converged the series would converge absolutely; if only one converged, partial sums of would diverge. Also because .
The greedy algorithm: start ; if add the next positive; if add the next negative. Since it cannot stay below forever; since it cannot stay above either. It crosses infinitely often and uses every term of both lists, so is a rearrangement. After the first crossing, if , the last positive was added from a sum , and only subtractions without crossing have followed; hence . Similarly if , then . Since last-used terms tend to zero, . To diverge to replace the fixed target with increasing targets .
∎The figure reveals a regularity the theorem does not state. If a rearrangement uses positives and negatives in asymptotic ratio (e.g. blocks of positives and negatives, ), after blocks the partial sum is
using : the terms cancel, leaving . To reach greedy must use ratio : about 134 positives per negative for , and would need order positives per negative; merely crossing the first time needs roughly negatives. The next cell checks the block formula.
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 is natural order and gives ; two positives per negative give ; for the absolutely convergent series every rearrangement gives , as the theorem says. Greedy reveals why: positive reserves sum only and negatives , so for distant targets it exhausts corrective capacity, remains forever on one side and leaves terms unused.
Orders of convergence
Knowing is insufficient to choose an algorithm: iteration count matters. Let 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: for some Q-linearly convergent . It permits errors not falling at every step but falling overall, like whose ratios alternate between and . Large-step gradient descent on ill-conditioned problems often behaves this way.
The four classes have distinctive graphical signatures:
- Linear: , hence . A straight line on semilog axes, slope . Each step gains the same number of digits: . At , one digit every 22 steps; at , one bit per step.
- Quadratic: . On semilog the curve plunges: correct digits double each step.
- Sublinear: , hence . On semilog it flattens; it is a straight line on log-log axes, slope .
- Superlinear without order: satisfies but for every . There is a continuum between linear and quadratic.
The figure shows all this. On linear axes all six look alike: all “go to zero.” On semilog and are straight, cosine fixed point becomes straight after a few steps (slope ), Newton plunges, and both sublinear curves flatten. On log-log sublinear curves are straight with slopes and . Newton readouts show digit doubling: , , , , , correct digits at steps through with .
Where do constants come from? For iteration with differentiable and , the mean-value theorem gives with between and , so . If convergence is linear at that rate: for cosine, . If , second-order Taylor gives : quadratic. Newton is exactly the iteration forcing , and for gives .
How many iterations
These definitions predict. If , then , and reducing error by factor requires
With and , : 132 iterations. With , 1375. This is why condition number matters in optimization: with strong convexity, gradient-descent rate is order and iterations grow linearly with .
In the quadratic case becomes , hence . If , tolerance is reached when
Iteration count grows as the logarithm of the logarithm of precision: going from to costs one extra step. Once inside region Newton needs few more steps; reaching it is the hard part.
Implementation from scratch: estimate order
If errors satisfy , taking logs at two successive steps and subtracting eliminates :
If the limit is unknown, use steps , which under at least linear convergence behave like errors: and their ratio tends to a constant. The cell implements this estimator on four cases. To observe several quadratic Newton steps without float64’s , Babylonian iteration uses decimal at 120 digits. The final block tests Aitken acceleration: if , combination with and removes the leading error term (exact for a sequence; for iteration leaves order- error).
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 settle at from the third step and at , Taylor’s predicted constant; using steps instead of errors, without , reaches the same . Cosine ratios rise toward and step ratios give the same rate without knowing : this is what a sound stopping criterion does. Sums of have ratios tending to 1 (sublinear) and , consistent with the integral bound. Aitken reduces cosine error by factors falling from to ; the last column shows why: accelerated error is almost exactly . Since the accelerated sequence remains linear but at rate instead of ; 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).
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 and to all 50 digits, whereas 1000 terms of leave remainder , as the integral bound predicted. The third case is most instructive. converges to , but a million terms total only , and integral bound says order terms are needed for error below . nsum fails without warning: at 15 working digits and at 20, two different false values. Extrapolations assume a geometric or integer-power tail, whereas this one decreases as . What works is the lesson’s approach: sum 1000 terms and estimate remainder by integral for error ; adding the first two Euler–Maclaurin corrections reduces it to . 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 : when accumulated sum is , adding a term below half the floating-point spacing, about , does not change it. In natural order every term of from is lost.
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 , 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
More than one answer may be correct.
More than one answer may be correct.
Step 1 of 4. What must you first establish to apply Bolzano–Weierstrass?
Step 1 of 4. What if ?
rearrange_to_target(target, n_terms) applying Riemann’s greedy algorithm to the alternating harmonic series and returning its first n_terms partial sums . Start at ; at each step if add the next unused positive ; if subtract the next unused negative . Tests check, among other things, the proof bound: after the first crossing, if then does not exceed the last positive used, and if then 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 sumsSummary
- The supremum axiom distinguishes from . 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 of . Consecutive jumps tending to zero do not suffice for Cauchy.
- Contracting steps with yield a Cauchy sequence, a priori bound and a posteriori bound : 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 and ; 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 yields .
- Linear convergence at rate is a semilog line of slope and needs steps to reduce error by factor ; quadratic doubles digits and takes order steps; sublinear is a log-log line of slope . Order can be estimated by using steps even without knowing the limit.