Summation and Product Notation
Sigma adds a whole list without writing every plus, Pi multiplies one. Means, losses and likelihoods are all Sigma in disguise, and logs turn Pi into Sigma.
Why Does This Exist?
ML sums constantly: over examples, over classes, over sequence positions, over pixels. Writing every term is impossible at a million examples and unreadable at ten. Summation notation compresses the whole loop into one line: means add through . Product notation does the same for multiplication, and it appears wherever independent probabilities multiply into likelihoods.
Reading this notation is non-negotiable: every loss, every expectation and every gradient is written in it. Writing it keeps derivations honest about what varies with the index and what is constant. Expectations build directly on it in expectation, variance and covariance; the other great consumer, matrix products as sums, is matrix multiplication.
The one idea you need first. The letter under Sigma is a counter that walks from the bottom number to the top one, and the rule beside it says what to add per stop. walks through 1, 2, 3, 4 and adds the squares.
Think of It Like This
A cashier's tally tape
A receipt tape lists each item and the register adds them: same operation per line, running total at the end. Sigma is the tape header ("add the price column, all lines") and the total in one line, without reprinting every item.
The index is the line number. The bounds say which lines count. The rule names the column. Constants factor out exactly like a store-wide discount applies once to the total, not per line.
Where it stops: tapes are finite and ordered, and Sigma usually is too, but analysis sums to infinity with convergence questions no register ever faces. Finite ML sums stay firmly in cashier territory.
How It Actually Works
Anatomy of : says add, is the index, and are the lower and upper bounds, is the rule. Expand by walking: .
Three manipulations cover most derivations. Constants factor out: . Sums split: . Index shifts relabel freely: summing to of is the same total. The mean is the signature application: .
Products mirror all of it: . And the bridge between them: , the log that rescues likelihoods from underflow, detailed in logarithms.
Worked example: a sum of squares, a product, and a mean
Sum: . Each term computed, then one addition chain.
Product: . Note : the factorial is Pi notation in disguise.
Mean of : , count , mean . The diagram above expands the sum-of-squares version of this same routine.
Code
import math
terms: list[int] = [1, 4, 9, 16]print(sum(v**2 for v in [1, 2, 3, 4])) # -> 30print(math.prod([1, 2, 3, 4])) # -> 24print(sum(terms) / len(terms)) # -> 7.5sum over a generator is Sigma transcribed: rule on the left, walk on the right. math.prod is Pi. The third line warns against skimming: the mean of the squares is , not the square of the mean.
Watch Out For
Translating 1-based math to 0-based code
Math writes ; Python writes sum(a[i] for i in range(n)) with a[0] first. The translation shifts every index by one, and hand-rolled loops that start at 1 skip the first element and read one past the last. The symptom is a loss averaged over examples with an out-of-bounds crash waiting at the edge.
Write the generator form and let range own the counting. When indices must match a paper, assert the first and last index explicitly.
Splitting a sum of products into products of sums
is not . With : the left side is , the right side is . Splitting is legal across addition, never across multiplication inside the rule. Dot products and covariances are exactly this shape, so the slip corrupts the most-used sums in ML.
Expand on two-element vectors whenever a derivation factors inside a Sigma. If the factors both vary with the index, they stay inside together.
The Quick Version
- walks the index and adds the rule; walks and multiplies.
- Constants factor out, sums split over addition, indices relabel freely.
- ; ; mean is one th of a sum.
- : the underflow rescue for multiplied probabilities.
- Math counts from 1, Python from 0: translate the bounds, never the habit.