TExcelTAD
Home › Calculus in Depth › Sigma Notation

Sigma Notation

Sigma notation is the shorthand for long sums: ∑\sum for "add these up". This reference lesson covers the notation, its algebra rules, the closed forms for sums of powers and telescoping sums. You need them for Riemann sums and series, and every loop that accumulates a total is one.

The notation

∑i=mnai=am+am+1+⋯+an\sum_{i=m}^{n} a_i = a_m + a_{m+1} + \cdots + a_n

ii is the index (a dummy variable: any letter works), mm and nn are the lower and upper limits, and aia_i is the term. Some examples:

∑i=15i2=1+4+9+16+25=55∑k=032k=1+2+4+8=15∑j=241j=12+13+14=1312\begin{aligned} \sum_{i=1}^{5} i^2 &= 1 + 4 + 9 + 16 + 25 = 55 \\ \sum_{k=0}^{3} 2^k &= 1 + 2 + 4 + 8 = 15 \\ \sum_{j=2}^{4} \frac{1}{j} &= \frac{1}{2} + \frac{1}{3} + \frac{1}{4} = \frac{13}{12} \end{aligned}

As a program, ∑i=mnai\sum_{i=m}^{n} a_i is literally sum(a(i) for i in range(m, n + 1)). Watch the off-by-one: Python's range excludes the upper end, sigma notation includes it.

Rules

Rule Statement
Constant multiple ∑c⋅ai=c⋅∑ai\sum c \cdot a_i = c \cdot \sum a_i
Sum and difference ∑(ai±bi)=∑ai±∑bi\sum (a_i \pm b_i) = \sum a_i \pm \sum b_i
Constant term ∑i=1nc=n⋅c\sum_{i=1}^{n} c = n \cdot c
Index shift ∑i=1nai=∑j=0n−1aj+1\sum_{i=1}^{n} a_i = \sum_{j=0}^{n-1} a_{j+1}
Split the range ∑i=1nai=∑i=1kai+∑i=k+1nai\sum_{i=1}^{n} a_i = \sum_{i=1}^{k} a_i + \sum_{i=k+1}^{n} a_i

There is no product rule: ∑aibi\sum a_ib_i is not (∑ai)(∑bi)(\sum a_i)(\sum b_i), and ∑ai2\sum a_i^2 is not (∑ai)2(\sum a_i)^2.

Closed forms for power sums

∑i=1n1=n∑i=1ni=n(n+1)2∑i=1ni2=n(n+1)(2n+1)6∑i=1ni3=[n(n+1)2]2∑i=0n−1ri=1−rn1−r(r≠1, geometric)\begin{aligned} \sum_{i=1}^{n} 1 &= n \\ \sum_{i=1}^{n} i &= \frac{n(n + 1)}{2} \\ \sum_{i=1}^{n} i^2 &= \frac{n(n + 1)(2n + 1)}{6} \\ \sum_{i=1}^{n} i^3 &= \left[\frac{n(n + 1)}{2}\right]^2 \\ \sum_{i=0}^{n-1} r^i &= \frac{1 - r^n}{1 - r} && (r \ne 1,\ \text{geometric}) \end{aligned}

Each is proved by induction. For example, for the sum of squares: it holds for n=1n = 1 (1=1⋅2⋅3/61 = 1 \cdot 2 \cdot 3/6), and if it holds for nn then

n(n+1)(2n+1)6+(n+1)2=(n+1)[n(2n+1)+6(n+1)]6=(n+1)(2n2+7n+6)6=(n+1)(n+2)(2n+3)6\frac{n(n+1)(2n+1)}{6} + (n+1)^2 = \frac{(n+1)[n(2n+1) + 6(n+1)]}{6} = \frac{(n+1)(2n^2 + 7n + 6)}{6} = \frac{(n+1)(n+2)(2n+3)}{6}

which is the formula with n+1n + 1 in place of nn. SymPy finds these closed forms symbolically:

python · try it yourself
import sympy as sp

i, n = sp.symbols('i n', integer=True, positive=True)
for term in [i, i**2, i**3, 2*i - 1]:
    print(f"sum of {str(term):6} for i=1..n =", sp.factor(sp.summation(term, (i, 1, n))))
print("check n = 100:", sum(k**2 for k in range(1, 101)), 100 * 101 * 201 // 6)
sum of i      for i=1..n = n*(n + 1)/2
sum of i**2   for i=1..n = n*(n + 1)*(2*n + 1)/6
sum of i**3   for i=1..n = n**2*(n + 1)**2/4
sum of 2*i - 1 for i=1..n = n**2
check n = 100: 338350 338350

Notice the last one: the first nn odd numbers always add up to a perfect square.

Telescoping sums

When each term is a difference bi+1−bib_{i+1} - b_i, almost everything cancels:

∑i=1n(bi+1−bi)=bn+1−b1∑i=1n1i(i+1)=∑(1i−1i+1)=1−1n+1\begin{aligned} \sum_{i=1}^{n} (b_{i+1} - b_i) &= b_{n+1} - b_1 \\ \sum_{i=1}^{n} \frac{1}{i(i+1)} &= \sum \left(\frac{1}{i} - \frac{1}{i+1}\right) = 1 - \frac{1}{n+1} \end{aligned}

This is the discrete version of the Fundamental Theorem of Calculus, and the trick behind several series in Series.

Sums and areas

The power sums let you compute a Riemann sum exactly and then take the limit. With nn equal strips under y=x2y = x^2 on [0,1][0, 1] and right endpoints xi=i/nx_i = i/n:

Rn=∑i=1n(in)2⋅1n=1n3⋅n(n+1)(2n+1)6→26=13as n→∞R_n = \sum_{i=1}^{n} \left(\frac{i}{n}\right)^2 \cdot \frac{1}{n} = \frac{1}{n^3} \cdot \frac{n(n+1)(2n+1)}{6} \to \frac{2}{6} = \frac{1}{3} \quad \text{as } n \to \infty

That is exactly how areas are first defined in Areas and Distances. The gentle survey of sums is Riemann Sums.

python · try it yourself
from fractions import Fraction

def right_sum(n):
    return sum(Fraction(i, n)**2 * Fraction(1, n) for i in range(1, n + 1))

for n in [4, 10, 100, 1000]:
    exact = Fraction(n * (n + 1) * (2 * n + 1), 6 * n**3)
    print(n, right_sum(n) == exact, float(exact))
4 True 0.46875
10 True 0.385
100 True 0.33835
1000 True 0.3338335

In software

  • Loops are sums. A nested loop for i in range(n): for j in range(i): ... runs ∑i=0n−1i=n(n−1)2\sum_{i=0}^{n-1} i = \frac{n(n - 1)}{2} times, which is why it is O(n2)O(n^2). Insertion sort's worst case and comparing every pair in a list both give this count. A triple loop over j<i<kj < i < k gives roughly n3/6n^3/6.
  • Closed forms beat loops. Summing 1..n with a formula is O(1)O(1); a loop is O(n)O(n). Interview problems ("find the missing number in 1..n") use n(n+1)2\frac{n(n + 1)}{2}.
  • Geometric sums give the cost of doubling arrays (1+2+4+⋯+n<2n1 + 2 + 4 + \cdots + n < 2n, so appends are O(1)O(1) amortised) and the total of a geometric decay schedule.

Exercises

Exercise 1: Expand and evaluate

Evaluate ∑k=14(3k−2)\sum_{k=1}^{4} (3k - 2).

Answer
Solution

1+4+7+10=221 + 4 + 7 + 10 = 22. With the rules: 3⋅∑k−∑2=3⋅10−8=223 \cdot \sum k - \sum 2 = 3 \cdot 10 - 8 = 22.

Exercise 2: Use the formulas

Find a closed form for ∑i=1n(2i+1)2\sum_{i=1}^{n} (2i + 1)^2 and evaluate it for n=10n = 10.

Answer

4n3+12n2+11n3=n(4n2+12n+11)3\frac{4n^3 + 12n^2 + 11n}{3} = \frac{n(4n^2 + 12n + 11)}{3}, which is 1770 for n=10n = 10.

Solution
(2i+1)2=4i2+4i+1∑=4⋅n(n+1)(2n+1)6+4⋅n(n+1)2+n=23n(n+1)(2n+1)+2n(n+1)+nn=10:23⋅10⋅11⋅21+2⋅110+10=1540+220+10=1770\begin{aligned} (2i + 1)^2 &= 4i^2 + 4i + 1 \\ \sum &= 4 \cdot \frac{n(n+1)(2n+1)}{6} + 4 \cdot \frac{n(n+1)}{2} + n \\ &= \tfrac{2}{3}n(n+1)(2n+1) + 2n(n+1) + n \\ n = 10{:}\quad &\tfrac{2}{3} \cdot 10 \cdot 11 \cdot 21 + 2 \cdot 110 + 10 = 1540 + 220 + 10 = 1770 \end{aligned}
python · try it yourself
import sympy as sp
i, n = sp.symbols('i n', integer=True, positive=True)
s = sp.summation((2*i + 1)**2, (i, 1, n))
print(sp.factor(s), s.subs(n, 10), sum((2*k + 1)**2 for k in range(1, 11)))
n*(4*n**2 + 12*n + 11)/3 1770 1770

Exercise 3: Telescope

Evaluate ∑i=1n(i+1−i)\sum_{i=1}^{n} (\sqrt{i + 1} - \sqrt{i}) and ∑i=2991i2−1\sum_{i=2}^{99} \frac{1}{i^2 - 1}.

Answer

n+1−1\sqrt{n + 1} - 1; and 1465119800≈0.7399\frac{14651}{19800} \approx 0.7399.

Solution

The first telescopes to n+1−1\sqrt{n+1} - \sqrt{1}. For the second, 1i2−1=12(1i−1−1i+1)\frac{1}{i^2 - 1} = \frac{1}{2}\left(\frac{1}{i - 1} - \frac{1}{i + 1}\right); the sum keeps the first two positive terms and the last two negative ones:

12(1+12−199−1100)=12(32−1999900)=12⋅14850−1999900=1465119800≈0.7399\frac{1}{2}\left(1 + \frac{1}{2} - \frac{1}{99} - \frac{1}{100}\right) = \frac{1}{2}\left(\frac{3}{2} - \frac{199}{9900}\right) = \frac{1}{2} \cdot \frac{14850 - 199}{9900} = \frac{14651}{19800} \approx 0.7399

Check in code:

python · try it yourself
from fractions import Fraction
s = sum(Fraction(1, i * i - 1) for i in range(2, 100))
print(s, float(s))
14651/19800 0.7399494949494949

Exercise 4: Count loop iterations

How many times does the innermost line run in for i in range(n): for j in range(i, n): count += 1? Give the formula and check it for n=50n = 50.

Answer

n(n+1)2\frac{n(n + 1)}{2}, which is 1275 for n=50n = 50.

Solution

For each ii the inner loop runs n−in - i times: ∑i=0n−1(n−i)=n+(n−1)+⋯+1=n(n+1)2\sum_{i=0}^{n-1} (n - i) = n + (n - 1) + \cdots + 1 = \frac{n(n + 1)}{2}.

python · try it yourself
n, count = 50, 0
for i in range(n):
    for j in range(i, n):
        count += 1
print(count, n * (n + 1) // 2)
1275 1275

Test yourself

What is ∑i=1100i\sum_{i=1}^{100} i?

  1. 5000
  2. 5050
  3. 10100
  4. 4950

Which equation is FALSE in general?

  1. ∑5ai=5∑ai\sum 5a_i = 5\sum a_i
  2. ∑(ai+bi)=∑ai+∑bi\sum (a_i + b_i) = \sum a_i + \sum b_i
  3. ∑aibi=(∑ai)(∑bi)\sum a_ib_i = (\sum a_i)(\sum b_i)
  4. ∑i=1n7=7n\sum_{i=1}^{n} 7 = 7n

A loop compares every pair (i,j)(i, j) with i<ji < j in a list of nn items. How many comparisons?

  1. n2n^2
  2. nlog⁡nn \log n
  3. 2n2^n
  4. n(n−1)2\frac{n(n - 1)}{2}