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:
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”.
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.
- 1. You save ₹4 every day for 5 days. How much do you have?
- 2. What does Σ tell you to do?
- 3. Using the staircase trick, what is 1 + 2 + … + 10?
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.Reading Σ
| Part | Name | Meaning |
|---|---|---|
| index | the counter that changes | |
| (below) | lower limit | where the counter starts |
| (above) | upper limit | where it stops (included) |
| term | what you add for each value of the counter |
The letter used for the index doesn’t matter: and are the same number. That’s why it’s called a dummy variable.
Reading Π
The product of is called factorial, written .
Lists of data
Data is usually a list . The little number is the subscript: is the third value. The mean (average) is:
Worked example. Sensor readings , so . Then and .
Two simple rules
- Adding a constant times: . For example, .
- Pulling out a constant: .
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, usually becomes for i in range(n), with x[i] standing for . Off-by-one errors are the most common bug in this kind of code.
- 1. What is Σ from k = 0 to 3 of 2ᵏ?
- 2. What is 4!?
- 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 | |
| Splitting | |
| Shifting the index | |
| Empty sum and product | |
| Product of sums |
in general. Also, . These are among the most common algebra slips in ML derivations.
Closed forms you should know
Geometric series. For :
Double sums
A double sum adds over a grid. When the limits don’t depend on each other, you can swap the order:
Matrix multiplication is a sum. For :
Physicists often drop the Σ and sum over any index that appears twice. This is Einstein notation: . NumPy’s np.einsum(“ik,kj->ij”, A, B) uses exactly this idea.
Products and logarithms
Since , a log turns a product into a sum:
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 |
|---|---|
| Mean squared error: the regression loss | |
| Cross-entropy: the classification loss | |
| A neuron’s weighted input | |
| Softmax (A1-4) | |
| Attention in Transformers: a weighted sum of values | |
| Robot odometry: position as a running sum of small moves | |
SUM(sales) GROUP BY region |
A sum over each group of rows in SQL |
- 1. What is Σᵢ₌₁ⁿ (3xᵢ + 2)?
- 2. C = AB where A is 3×4 and B is 4×5. How many multiplications go into one entry Cᵢⱼ?
- 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:
For , .
Proof. Let . Then by telescoping. Divide by . ∎
.
Proof by telescoping. Expand . Summing from to , the left side telescopes to . So . Solve for and simplify. ∎
A second example: , so .
Swapping a triangular double sum
When the inner limit depends on the outer index, swapping changes the limits:
Both sides add over the same triangle . Drawing the grid is the safest way to get the new limits right. For example, .
Infinite series
An infinite sum means the limit of the partial sums , if that limit exists.
- Geometric: when , since . It diverges when .
- Harmonic series diverges.
.
Proof. Group the terms: . Each bracket is at least , because it has terms, each at least . Infinitely many halves add up to infinity. ∎
How fast does it grow? Comparing with the area under :
- p-series: converges if and only if . For example, (Euler, 1734).
- Rearrangements: if 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.
The step sizes in classic stochastic gradient descent must satisfy and (Robbins and Monro, 1951). works because of exactly the two facts above: the harmonic series diverges and converges.
Exercise 3.1: Show that the sum of k·k! for k = 1 to n equals (n+1)! − 1
, so the sum telescopes to . ∎
Exercise 3.2: Prove by induction that 1³ + 2³ + … + n³ = (1 + 2 + … + n)²
Base : . Step: we need . Factor from both sides: . ✅ ∎
- 1. Which series converges?
- 2. What is the infinite sum of (1/3)ᵏ for k = 0, 1, 2, …?
- 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 .
- Kahan (compensated) summation (Kahan, 1965) tracks the lost low-order bits in a separate variable. Its error bound doesn’t grow with .
- Pairwise summation adds in a tree, with error growing like . NumPy’s
np.sumuses it. - Higham (1993) analysed these methods in detail.
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, , 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: . The gradient is linear, so . Picking a random mini-batch gives an unbiased estimate of that sum:
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 , the error of the sum after steps has standard deviation . 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 .
References
- N. Oresme (c. 1350). Quaestiones super geometriam Euclidis. (First proof that the harmonic series diverges.)
- L. Euler (1734/35). “De summis serierum reciprocarum.” (The Basel problem: Σ 1/k² = π²/6.)
- A. Einstein (1916). “Die Grundlage der allgemeinen Relativitätstheorie.” Annalen der Physik, 49.
- H. Robbins and S. Monro (1951). “A stochastic approximation method.” Annals of Mathematical Statistics, 22(3).
- W. Kahan (1965). “Further remarks on reducing truncation errors.” Communications of the ACM, 8(1).
- N. Higham (1993). “The accuracy of floating point summation.” SIAM Journal on Scientific Computing, 14(4).
- 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).
- R. Graham, D. Knuth, O. Patashnik (1994). Concrete Mathematics, 2nd ed. Addison-Wesley. Chapter 2, “Sums”.