A149 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A14 · Lesson 9 · Lab: sequences and series in code

Thresholds, tail brackets, accelerated sums, pairings and root tests

Lessons 1 to 8 were about sequences and series in the abstract: ε and N, bounds on tails, rearrangements, countable sets, limsup. In this lab you'll make each idea concrete in code. You'll find ε–N thresholds by search and compare them with the formulas from proofs, bracket ζ(3) with integrals, accelerate a slowly converging alternating series, check that the Cantor pairing really is a bijection, and watch the root test's k-th roots settle where the ratio test can't decide.

  • The stems are |ak|1/k for ak=2−k (k even) and 3−k (k odd). They alternate between exactly ½ and exactly ⅓.
  • The limsup is ½ < 1, so the root test says the series converges. The ratios ak+1ak, by contrast, alternate between values going to 0 and to ∞: the ratio test is silent.
  • In the lab you'll compute both sequences and confirm what each test sees.

Predict

A proof shows |3n+1n+2−3|=5n+2. For ε = 0.0003, what N does a computer search find?

Name it

Searching for N

To find the least N with |an−L|<ε for all n ≥ N, record the last n that fails, and stop once you've gone far past it (for monotone tails, a few times further is plenty). A search can't prove "for all n", but it checks a proof's N and exposes a wrong one.

Brackets and acceleration

For a decreasing positive f, SN+∫N+1∞f≤S≤SN+∫N∞f. The midpoint of the bracket is usually far more accurate than SN. For alternating series, repeatedly average neighboring partial sums (lesson 7's example, done systematically).

Pairing in code

math.isqrt gives exact integer square roots, so the inverse pairing w=⌊8k+1−12⌋, n=k−w(w+1)2, m=w−n can be computed without floating-point error.

Worked example

Bracket ζ(3)=∑k−3 using ten terms.

Show the solution
  1. Partial sum. S10=1.197532
  2. Bound the tail with integrals. ∫11∞x−3dx=1242 ∫10∞x−3dx=1200
  3. Bracket. Adding these to S10 gives the bracket [1.201664, 1.202532], whose midpoint is 1.202098.
  4. Compare with the true value. The true value is 1.2020569, so the midpoint's error is 4×10−5, against S10's 0.0045.
  5. Going further. The same idea with more terms or with the Euler–Maclaurin correction gives many digits from a short sum.

Answer ζ(3) lies in [1.201664, 1.202532], and the midpoint 1.202098 is off by about 4×10−5.

Worked example

Accelerate the first 20 partial sums of 1−12+13−⋯.

Show the solution
  1. The raw partial sum. S20=0.668771 which is 0.024 below ln⁡2=0.693147.
  2. Average neighbors three times. Using the last few partial sums, this leaves an error of 2.9×10−6, more than 8000 times smaller than before, for no extra terms.
  3. Why it works. The partial sums alternate around the limit with slowly shrinking swings; each averaging cancels most of the current swing.

Answer three rounds of averaging cut the error from 0.024 to 2.9×10−6.

Check

For |an−L|=5n+2, what is the least N with |an−L|<0.001 for all n ≥ N?

Check

Inverting the Cantor pairing at k = 100, which diagonal w = m + n is it on?

Check

Write first_N(a, L, eps) that searches for the least N with |a(n)−L|<ε for all n ≥ N (track the last failing n; stop when n exceeds ten times that plus 100). Set N1 for an=3n+1n+2, L = 3, ε = 0.0003, and N2 for an=n2n, L = 0, ε = 0.001.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Set lo and hi to the integral-test bracket for ζ(3) from S10, and mid to its midpoint.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Set S to the first 20 partial sums of ∑(−1)k+1k (a NumPy array), then average neighbors three times (A = (A[:-1] + A[1:]) / 2) and set err_raw and err_acc to the errors of S[-1] and the last averaged value against ln 2.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write pair(m, n) and unpair(k) for the Cantor pairing (use math.isqrt). Set ok to whether pair(*unpair(k)) == k for all k below 10 000, and distinct to the number of different values of pair(m, n) for 0 ≤ m, n < 100.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

For ak=2−k (k even) and 3−k (k odd), set roots to |ak|1/k for k = 1 to 200, and ratios to ak+1ak for k = 1 to 30. Set limsup_est to the largest root among k ≥ 100, and ratio_max to the largest ratio.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why can a computer search check a proof's N but never replace the proof?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.