Foundations to Frontier
Tests
A. Mathematical Foundations › A1 Prerequisites and Mathematical Thinking

Summation and Product Notation

Σ and Π are the shorthand for "add them all up" and "multiply them all together". Almost every formula in machine learning is written with them.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Adding up a list

You put ₹2 in your piggy bank on Monday, ₹3 on Tuesday, ₹5 on Wednesday. How much is in it? You add them all up: 2 + 3 + 5 = 10. Mathematicians have a special symbol that means “add them all up”. It’s the Greek letter Σ (sigma), which is a capital S for “sum”.

The staircase trick

A famous story says that a young Carl Friedrich Gauss was asked to add 1 + 2 + 3 + … + 100. Instead of adding one number at a time, he spotted a trick. Build a staircase of blocks, then put an upside-down copy next to it:

The staircase trick
1 + 2 + … + 5 = 15 blocks. Can you count them without adding one by one? Press the button.

Two staircases always make a rectangle, and counting a rectangle is easy: just multiply! So 1 + 2 + … + 100 is half of 100 × 101, which is 5050.

Multiplying a list

Sometimes we multiply instead. You have 3 shirts and 4 pairs of trousers. How many outfits? 3 × 4 = 12. With 2 hats as well, it’s 3 × 4 × 2 = 24. The symbol for “multiply them all together” is Π (pi), which is a capital P for “product”.

Why AI cares

A robot vacuum adds up every little move it makes to know how far it has gone. An AI adds up its mistakes on thousands of examples to see how well it’s doing. That’s Σ at work.

📝 Quick check (Level 0)
0/3 answered
  1. 1. You save ₹4 every day for 5 days. How much do you have?
  2. 2. What does Σ tell you to do?
  3. 3. Using the staircase trick, what is 1 + 2 + … + 10?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Reading Σ

∑i=14i2=12+22+32+42=30\sum_{i=1}^{4} i^2 = 1^2 + 2^2 + 3^2 + 4^2 = 30
Part Name Meaning
ii index the counter that changes
i=1i = 1 (below) lower limit where the counter starts
44 (above) upper limit where it stops (included)
i2i^2 term what you add for each value of the counter

The letter used for the index doesn’t matter: ∑i=14i2\sum_{i=1}^4 i^2 and ∑k=14k2\sum_{k=1}^4 k^2 are the same number. That’s why it’s called a dummy variable.

Reading Π

∏i=15i=1×2×3×4×5=120=5!\prod_{i=1}^{5} i = 1 \times 2 \times 3 \times 4 \times 5 = 120 = 5!

The product of 1,2,…,n1, 2, \dots, n is called nn factorial, written n!n!.

Lists of data

Data is usually a list x1,x2,…,xnx_1, x_2, \dots, x_n. The little number is the subscript: x3x_3 is the third value. The mean (average) is:

xˉ=1n∑i=1nxi\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i

Worked example. Sensor readings x=(4,8,15,16,23,42)x = (4, 8, 15, 16, 23, 42), so n=6n = 6. Then ∑xi=108\sum x_i = 108 and xˉ=108/6=18\bar x = 108 / 6 = 18.

Two simple rules

  • Adding a constant nn times: ∑i=1nc=nc\sum_{i=1}^{n} c = nc. For example, ∑i=1107=70\sum_{i=1}^{10} 7 = 70.
  • Pulling out a constant: ∑i=1nc xi=c∑i=1nxi\sum_{i=1}^n c\,x_i = c \sum_{i=1}^n x_i.
Common mistake

Python counts from 0: the first item of a list is x[0]. Most maths books count from 1. When you turn a formula into code, ∑i=1n\sum_{i=1}^{n} usually becomes for i in range(n), with x[i] standing for xi+1x_{i+1}. Off-by-one errors are the most common bug in this kind of code.

📝 Quick check (Level 1)
0/3 answered
  1. 1. What is Σ from k = 0 to 3 of 2ᵏ?
  2. 2. What is 4!?
  3. 3. How many terms are in Σ from i = 3 to 10?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Rules for working with sums

Rule Formula
Linearity ∑i(a xi+b yi)=a∑ixi+b∑iyi\sum_i (a\,x_i + b\,y_i) = a\sum_i x_i + b \sum_i y_i
Splitting ∑i=1nxi=∑i=1mxi+∑i=m+1nxi\sum_{i=1}^{n} x_i = \sum_{i=1}^{m} x_i + \sum_{i=m+1}^{n} x_i
Shifting the index ∑i=1nxi=∑j=0n−1xj+1\sum_{i=1}^{n} x_i = \sum_{j=0}^{n-1} x_{j+1}
Empty sum and product ∑i=10xi=0,∏i=10xi=1\sum_{i=1}^{0} x_i = 0, \quad \prod_{i=1}^{0} x_i = 1
Product of sums (∑iai)(∑jbj)=∑i∑jaibj\left(\sum_i a_i\right)\left(\sum_j b_j\right) = \sum_i \sum_j a_i b_j
Common mistake

∑ixiyi≠(∑ixi)(∑iyi)\sum_i x_i y_i \ne \left(\sum_i x_i\right)\left(\sum_i y_i\right) in general. Also, ∑ixi2≠(∑ixi)2\sum_i x_i^2 \ne \left(\sum_i x_i\right)^2. These are among the most common algebra slips in ML derivations.

Closed forms you should know

∑i=1ni=n(n+1)2,∑i=1ni2=n(n+1)(2n+1)6,∑i=1ni3=(n(n+1)2)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}, \qquad \sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}, \qquad \sum_{i=1}^{n} i^3 = \left(\frac{n(n+1)}{2}\right)^2

Geometric series. For r≠1r \ne 1:

∑k=0n−1rk=1−rn1−r\sum_{k=0}^{n-1} r^k = \frac{1 - r^n}{1 - r}

Double sums

A double sum adds over a grid. When the limits don’t depend on each other, you can swap the order:

∑i=1m∑j=1naij=∑j=1n∑i=1maij\sum_{i=1}^{m}\sum_{j=1}^{n} a_{ij} = \sum_{j=1}^{n}\sum_{i=1}^{m} a_{ij}

Matrix multiplication is a sum. For C=ABC = AB:

Cij=∑kAikBkjC_{ij} = \sum_{k} A_{ik} B_{kj}

Physicists often drop the Σ and sum over any index that appears twice. This is Einstein notation: Cij=AikBkjC_{ij} = A_{ik}B_{kj}. NumPy’s np.einsum(“ik,kj->ij”, A, B) uses exactly this idea.

Products and logarithms

Since log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b, a log turns a product into a sum:

log⁡∏i=1npi=∑i=1nlog⁡pi\log \prod_{i=1}^{n} p_i = \sum_{i=1}^{n} \log p_i

This is why machine learning maximises the log-likelihood. The product of thousands of small probabilities becomes too small for a computer to store, but the sum of their logs stays well behaved. You’ll see why in Practice Code 5.

Σ in AI, robotics and data science

Formula Where it appears
1n∑i(yi−y^i)2\frac{1}{n}\sum_i (y_i - \hat y_i)^2 Mean squared error: the regression loss
−∑iyilog⁡y^i-\sum_i y_i \log \hat y_i Cross-entropy: the classification loss
x⋅w=∑ixiwi\mathbf{x}\cdot\mathbf{w} = \sum_i x_i w_i A neuron’s weighted input
ezi∑jezj\frac{e^{z_i}}{\sum_j e^{z_j}} Softmax (A1-4)
∑jαijvj\sum_j \alpha_{ij} v_j Attention in Transformers: a weighted sum of values
pn=p0+∑t=1nΔptp_n = p_0 + \sum_{t=1}^n \Delta p_t Robot odometry: position as a running sum of small moves
SUM(sales) GROUP BY region A sum over each group of rows in SQL
🐍 Exercise 1: sums by hand
Using loops or sum() (no NumPy), write mean, variance (population: divide by n) and dot.
📝 Quick check (Level 2)
0/3 answered
  1. 1. What is Σᵢ₌₁ⁿ (3xᵢ + 2)?
  2. 2. C = AB where A is 3×4 and B is 4×5. How many multiplications go into one entry Cᵢⱼ?
  3. 3. What is the empty product Πᵢ₌₁⁰ xᵢ?

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Telescoping sums

A sum telescopes when its terms cancel in pairs:

∑k=1n(ak+1−ak)=an+1−a1\sum_{k=1}^{n} (a_{k+1} - a_k) = a_{n+1} - a_1
Theorem (geometric series)

For r≠1r \ne 1, ∑k=0n−1rk=1−rn1−r\sum_{k=0}^{n-1} r^k = \frac{1-r^n}{1-r}.

Proof. Let S=∑k=0n−1rkS = \sum_{k=0}^{n-1} r^k. Then S−rS=∑k=0n−1(rk−rk+1)=1−rnS - rS = \sum_{k=0}^{n-1} (r^k - r^{k+1}) = 1 - r^n by telescoping. Divide by 1−r1 - r. ∎

Theorem (sum of squares)

∑k=1nk2=n(n+1)(2n+1)6\sum_{k=1}^n k^2 = \frac{n(n+1)(2n+1)}{6}.

Proof by telescoping. Expand (k+1)3−k3=3k2+3k+1(k+1)^3 - k^3 = 3k^2 + 3k + 1. Summing from k=1k=1 to nn, the left side telescopes to (n+1)3−1(n+1)^3 - 1. So 3∑k2+3⋅n(n+1)2+n=(n+1)3−13\sum k^2 + 3\cdot\tfrac{n(n+1)}{2} + n = (n+1)^3 - 1. Solve for ∑k2\sum k^2 and simplify. ∎

A second example: 1k(k+1)=1k−1k+1\frac{1}{k(k+1)} = \frac1k - \frac1{k+1}, so ∑k=1n1k(k+1)=1−1n+1\sum_{k=1}^n \frac{1}{k(k+1)} = 1 - \frac{1}{n+1}.

Swapping a triangular double sum

When the inner limit depends on the outer index, swapping changes the limits:

∑i=1n∑j=inaij=∑j=1n∑i=1jaij\sum_{i=1}^{n}\sum_{j=i}^{n} a_{ij} = \sum_{j=1}^{n}\sum_{i=1}^{j} a_{ij}

Both sides add over the same triangle 1≤i≤j≤n1 \le i \le j \le n. Drawing the grid is the safest way to get the new limits right. For example, ∑k=1∞k2k=∑k=1∞∑j=1k12k=∑j=1∞∑k=j∞12k=∑j=1∞12j−1=2\sum_{k=1}^{\infty} \frac{k}{2^k} = \sum_{k=1}^\infty \sum_{j=1}^{k} \frac{1}{2^k} = \sum_{j=1}^\infty \sum_{k=j}^\infty \frac{1}{2^k} = \sum_{j=1}^\infty \frac{1}{2^{j-1}} = 2.

Infinite series

An infinite sum ∑k=1∞ak\sum_{k=1}^\infty a_k means the limit of the partial sums Sn=∑k=1nakS_n = \sum_{k=1}^n a_k, if that limit exists.

  • Geometric: ∑k=0∞rk=11−r\sum_{k=0}^\infty r^k = \frac{1}{1-r} when ∣r∣<1|r| < 1, since rn→0r^n \to 0. It diverges when ∣r∣≥1|r| \ge 1.
  • Harmonic series diverges.
Theorem (Oresme, c. 1350)

∑k=1∞1k=∞\sum_{k=1}^\infty \frac1k = \infty.

Proof. Group the terms: 1+12+(13+14)+(15+⋯+18)+⋯1 + \tfrac12 + \left(\tfrac13 + \tfrac14\right) + \left(\tfrac15 + \dots + \tfrac18\right) + \cdots. Each bracket is at least 12\tfrac12, because it has 2m2^{m} terms, each at least 2−(m+1)2^{-(m+1)}. Infinitely many halves add up to infinity. ∎

How fast does it grow? Comparing with the area under 1/x1/x:

ln⁡(n+1)≤Hn=∑k=1n1k≤1+ln⁡n\ln(n+1) \le H_n = \sum_{k=1}^n \frac1k \le 1 + \ln n
  • p-series: ∑1/kp\sum 1/k^p converges if and only if p>1p > 1. For example, ∑1/k2=π2/6\sum 1/k^2 = \pi^2/6 (Euler, 1734).
  • Rearrangements: if ∑∣ak∣\sum |a_k| converges (absolute convergence), any reordering gives the same sum. If not, Riemann’s rearrangement theorem says the terms can be reordered to sum to any number you like. Order matters for infinite sums.
Why AI cares

The step sizes in classic stochastic gradient descent must satisfy ∑tηt=∞\sum_t \eta_t = \infty and ∑tηt2<∞\sum_t \eta_t^2 < \infty (Robbins and Monro, 1951). ηt=1/t\eta_t = 1/t works because of exactly the two facts above: the harmonic series diverges and ∑1/t2\sum 1/t^2 converges.

Exercise 3.1: Show that the sum of k·k! for k = 1 to n equals (n+1)! − 1

k⋅k!=(k+1)!−k!k \cdot k! = (k+1)! - k!, so the sum telescopes to (n+1)!−1!(n+1)! - 1!. ∎

Exercise 3.2: Prove by induction that 1³ + 2³ + … + n³ = (1 + 2 + … + n)²

Base n=1n=1: 1=11 = 1. Step: we need (n(n+1)2)2+(n+1)3=((n+1)(n+2)2)2\left(\tfrac{n(n+1)}{2}\right)^2 + (n+1)^3 = \left(\tfrac{(n+1)(n+2)}{2}\right)^2. Factor (n+1)2/4(n+1)^2/4 from both sides: n2+4(n+1)=(n+2)2n^2 + 4(n+1) = (n+2)^2. ✅ ∎

📝 Quick check (Level 3)
0/3 answered
  1. 1. Which series converges?
  2. 2. What is the infinite sum of (1/3)ᵏ for k = 0, 1, 2, …?
  3. 3. Swapping Σᵢ₌₁ⁿ Σⱼ₌₁ⁱ aᵢⱼ gives…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Summing on a real computer

Floating-point numbers keep about 16 significant digits (float64), or about 7 (float32). Adding a tiny number to a big one can lose the tiny one completely. The rounding errors of naive left-to-right summation can grow in proportion to nn.

  • Kahan (compensated) summation (Kahan, 1965) tracks the lost low-order bits in a separate variable. Its error bound doesn’t grow with nn.
  • Pairwise summation adds in a tree, with error growing like log⁡n\log n. NumPy’s np.sum uses it.
  • Higham (1993) analysed these methods in detail.
🐍 Exercise 2 (research): naive vs Kahan summation
Run the solution to see the naive sum lose 100,000 tiny terms, while Kahan's method keeps them. Try implementing kahan_sum yourself first.
Why this matters for deep learning

On a GPU, a big sum is split across thousands of threads, and the order of additions can change from run to run. Since floating-point addition isn’t associative, (a+b)+c≠a+(b+c)(a + b) + c \ne a + (b + c), so two identical training runs can produce slightly different numbers. Reproducible deep learning needs deterministic reductions, and low-precision training (fp16, bf16, fp8) needs careful accumulation in higher precision.

Gradients of sums, and stochastic optimization

A training loss is a sum over the dataset: L(θ)=1n∑i=1nℓi(θ)L(\theta) = \frac1n\sum_{i=1}^n \ell_i(\theta). The gradient is linear, so ∇L=1n∑i∇ℓi\nabla L = \frac1n\sum_i \nabla \ell_i. Picking a random mini-batch BB gives an unbiased estimate of that sum:

E[1∣B∣∑i∈B∇ℓi]=∇L\mathbb{E}\Big[\tfrac{1}{|B|}\textstyle\sum_{i\in B}\nabla \ell_i\Big] = \nabla L

This one fact, the linearity of Σ, is why stochastic gradient descent works (Robbins and Monro, 1951) and why we can train on datasets far too big to fit in memory.

Einstein notation and tensor contraction

Einstein introduced the summation convention in 1916 to keep the equations of general relativity readable. Today, einsum expresses most deep-learning operations, such as attention scores “bhqd,bhkd->bhqk”. The order in which a chain of contractions is evaluated can change the cost by orders of magnitude, so finding a good order is itself a research problem (see opt_einsum, Smith and Gray, 2018).

Running sums in robotics

Dead reckoning estimates a robot’s position as a running sum of small measured moves. If each step has an independent random error with standard deviation σ\sigma, the error of the sum after nn steps has standard deviation σn\sigma\sqrt n. Drift grows without bound, which is why robots need external corrections like GPS, landmarks, or SLAM loop closures (T3). A small constant bias is even worse: it grows like nn.

References

  1. N. Oresme (c. 1350). Quaestiones super geometriam Euclidis. (First proof that the harmonic series diverges.)
  2. L. Euler (1734/35). “De summis serierum reciprocarum.” (The Basel problem: Σ 1/k² = π²/6.)
  3. A. Einstein (1916). “Die Grundlage der allgemeinen Relativitätstheorie.” Annalen der Physik, 49.
  4. H. Robbins and S. Monro (1951). “A stochastic approximation method.” Annals of Mathematical Statistics, 22(3).
  5. W. Kahan (1965). “Further remarks on reducing truncation errors.” Communications of the ACM, 8(1).
  6. N. Higham (1993). “The accuracy of floating point summation.” SIAM Journal on Scientific Computing, 14(4).
  7. D. Smith and J. Gray (2018). “opt_einsum: A Python package for optimizing contraction order for einsum-like expressions.” Journal of Open Source Software, 3(26).
  8. R. Graham, D. Knuth, O. Patashnik (1994). Concrete Mathematics, 2nd ed. Addison-Wesley. Chapter 2, “Sums”.