Sequences
A sequence is an ordered list of numbers that goes on forever: . Every iterative algorithm, from Newton's method to training a neural network, produces one, and the main question is always the same: does it settle down to a limit?
Two ways to define a sequence
| Style | Example | Terms |
|---|---|---|
| Explicit formula | ||
| Explicit formula | ||
| Recursive (from the previous term) | , | |
| Recursive (two previous terms) | , |
An explicit formula lets you jump straight to the 1000th term. A recursive one is what loops compute naturally: each iteration uses the previous result.
Convergence
A sequence converges to a limit if its terms get and stay as close to as you like:
If no such exists, the sequence diverges: it may blow up (), or oscillate ().
Useful limits:
| Sequence | Limit |
|---|---|
| , , | 0 |
| with | 0 |
| with | (diverges) |
| 1 | |
| (Fibonacci ratios) |
The limit laws from Limit Laws and Limits at Infinity apply: for example because the top and bottom are both dominated by their terms.
import math
print(" n (1+1/n)^n F(n+2)/F(n+1)")
a, b = 1, 1
for n in range(1, 41):
a, b = b, a + b # now b = F(n+2), a = F(n+1)
if n in (1, 2, 5, 10, 20, 40):
print(f"{n:2d} {(1 + 1 / n) ** n:12.8f} {b / a:14.10f}")
print(f"limits: e = {math.e:.8f}, phi = {(1 + 5 ** 0.5) / 2:.10f}") n (1+1/n)^n F(n+2)/F(n+1)
1 2.00000000 2.0000000000
2 2.25000000 1.5000000000
5 2.48832000 1.6250000000
10 2.59374246 1.6179775281
20 2.65329771 1.6180339850
40 2.68506384 1.6180339887
limits: e = 2.71828183, phi = 1.6180339887
The Fibonacci ratios settle very fast, very slowly: two convergent sequences can approach their limits at very different rates.
Monotone and bounded
A sequence is increasing if , decreasing if , and bounded if all terms stay between two fixed numbers. The monotone convergence theorem says: a sequence that is monotone and bounded always converges. This is often the easiest way to prove a limit exists without knowing its value.
In software: iterate until it stops changing
Algorithms that improve an answer step by step produce sequences, and code must decide when to stop. The Babylonian square-root method is a recursive sequence:
It is Newton's method applied to .
def babylonian_sqrt(S, tol=1e-12):
x = S if S > 1 else 1.0
n = 0
while True:
nxt = (x + S / x) / 2
n += 1
print(f"x{n} = {nxt:.15f}")
if abs(nxt - x) < tol: # stop when the sequence stops changing
return nxt
x = nxt
root = babylonian_sqrt(2)
print("math.sqrt(2) =", 2 ** 0.5)x1 = 1.500000000000000
x2 = 1.416666666666667
x3 = 1.414215686274510
x4 = 1.414213562374690
x5 = 1.414213562373095
x6 = 1.414213562373095
math.sqrt(2) = 1.4142135623730951
The number of correct digits roughly doubles each step (quadratic convergence). Other places you meet sequences:
- Gradient descent: the loss after each training step is a sequence; "converged" means it stopped decreasing meaningfully.
- Exponential moving averages (Adam optimizer, smoothed FPS counters) are recursive sequences.
- Pseudo-random generators are recursive sequences designed not to show a pattern.
- Animations:
pos += (target − pos) · 0.1each frame is a sequence that converges totargetgeometrically.
Note: Stopping when two terms are close does not prove convergence: changes by less and less but grows forever (see Series and Convergence). In practice combine a tolerance with a maximum number of iterations.
Exercises
Exercise 1: Write the terms
List to for and give the limit.
Answer
; limit .
Solution
Exercise 2: Converge or diverge?
Decide for each: a) , b) , c) , d) .
Answer
a) converges to 0, b) converges to 0, c) diverges, d) converges to 0.
Solution
Exercise 3: Find the fixed point
The recursive sequence , , converges. Find its limit by hand, then confirm numerically.
Answer
2
Solution
If , then also , so :
import math
a = 0.0
for n in range(1, 21):
a = math.sqrt(2 + a)
print(f"{a:.12f}")1.999999999998
Exercise 4: Smoothing an animation
Each frame, a UI element moves 20% of the remaining distance to its target: , . Find a formula for and the first frame where it is within 0.5 px of 100.
Answer
; frame .
Solution
The gap obeys , so . We need , i.e. .
p, n = 0.0, 0
while 100 - p >= 0.5:
p += 0.2 * (100 - p)
n += 1
print(n, round(p, 4))24 99.5278
Test yourself
What is the limit of ?
- 2
- 0
- It diverges
Which sequence diverges?
A sequence is increasing and every term is below 10. What can you conclude?
- It converges to 10
- It diverges
- Nothing
- It converges to some limit