Geometric series

Level FundamentalDifficulty ★★★★★Concept⌖ Open in the map

What is it?

∑k≥0rk=11−r\sum_{k\ge0} r^k = \frac{1}{1 - r} for ∣r∣<1|r| < 1. The one series everyone can sum in closed form — and the one behind dynamic arrays, divide-and-conquer recurrences and the discounted rewards of reinforcement learning.

Intuition

Multiply S=1+r+r2+…S = 1 + r + r^2 + \dots by rr and subtract: everything cancels except the 1, so S(1−r)=1S(1 - r) = 1. When r=1/2r = 1/2: 1+12+14+⋯=21 + \frac12 + \frac14 + \dots = 2 — the total is dominated by the first terms, which is why the last level of a halving recursion costs as much as all the rest.

Formulas

∑k=0n−1rk=1−rn1−r,∑k=0∞rk=11−r  (∣r∣<1)\sum_{k=0}^{n-1} r^k = \frac{1 - r^n}{1 - r}, \qquad \sum_{k=0}^{\infty} r^k = \frac{1}{1 - r}\ \ (|r| < 1)
Gt=∑k=0∞γkrt+k≤rmax⁡1−γG_t = \sum_{k=0}^{\infty}\gamma^k r_{t+k} \le \frac{r_{\max}}{1 - \gamma}
discounted return in reinforcement learning

Example

A dynamic array doubles its capacity when full. Inserting nn elements copies at most 1+2+4+⋯+n/2<n1 + 2 + 4 + \dots + n/2 < n elements in total — O(1)O(1) amortized per insertion. With growth factor 1.5 the bound is 11−2/3=3\frac{1}{1 - 2/3} = 3 copies per element.

Where it shows up in computing

  • Algorithm analysis and complexity★★★★★fundamentalScientific computing and algorithms

    Amortized analysis of dynamic arrays and the master theorem cases are geometric sums.

  • Queueing theory and performance★★★★★frequentOptimization and systems

    In an M/M/1 queue the number of customers is geometric: P(N=n)=(1−ρ)ρnP(N = n) = (1 - \rho)\rho^n.

Where it shows up in AI

  • Reinforcement learning★★★★★fundamentalAI and machine learning

    Discounting with γ<1\gamma < 1 makes the infinite return a convergent geometric-type series.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1AI

An agent gets reward 1 every step forever, with γ=0.99\gamma = 0.99. What is the return? What is the "effective horizon"?

Solution

∑0.99k=10.01=100\sum 0.99^k = \frac{1}{0.01} = 100. Rewards beyond about 11−γ=100\frac{1}{1-\gamma} = 100 steps contribute little: the effective horizon is ~100 steps.

↑ ↓ to navigate · ↵ · Esc