Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

ExTeX --- Sums and Subscripts

Score:0/0/0
Actions:

Sums and Subscripts

Math Refresher 4, Bernd Gärtner(12 July, 2023)

1Sums

Let’s recall the Theorem “Kleiner Gauß”: Let nNn\in \N . Then the sum of all numbers between 11 and nn is n(n+1)/2n(n+1)/2. There are (many) more theorems and other mathematical contexts that involve sums, and it would be cumbersome to always talk about the sum of all numbers of this and that form. Therefore, mathematicians have come up with a notation for sums. In this notation, Kleiner Gauß reads as follows: Let nNn\in \N . Then

i=1ni=n(n+1)2.\displaystyle \sum _{i=1}^n i = \frac {n(n+1)}{2}.
Here, \sum is the greek letter Sigma (for sum). When the sum appears in normal text, it is typeset as i=1ni\sum _{i=1}^n i. In writing this, we are saying that we sum up all values ii for which ii is between 11 (the lower summation bound) and nn (the upper summation bound). Hence, the summation variable ii “goes through” the values 1,2,...,n1,2,...,n, where the variable nn itself is a placeholder for an actual integer, for example 100100. If you have ever seen a loop variable in a programming language, this concept is familiar to you.

Gauß’ original insight that surprised his teacher can be obtained by setting nn to 100100:

i=1100i=5050.\displaystyle \sum _{i=1}^{100} i = 5050.

For n=0n=0 (the smallest natural number), the theorem would give us

i=10i=0.\displaystyle \sum _{i=1}^{0} i = 0.

This might look strange but is correct if we agree (as we previously did) that the sum is 00 if the upper summation bound is smaller than the lower one.

With this notation, we can do more things. For example,

i=1100i2\displaystyle \sum _{i=1}^{100} i^2
is the sum of the squares of the numbers between 11 and 100100, so 1+4+9+16++100001+4+9+16+\cdots +10000. We don’t know what Gauß would have done if the task would have been to compute this sum, but we know that a significantly more complicated variant of Gauß’ trick still works and gives the answer for all upper summation bounds nn:
i=1ni2=n(n+1)(2n+1)6.\displaystyle \sum _{i=1}^{n} i^2 = \frac {n(n+1)(2n+1)}{6}.
In particular,
i=1100i2=1001012016=338350.\displaystyle \sum _{i=1}^{100} i^2 = \frac {100\cdot 101\cdot 201}{6} = 338350.

Instead of squaring the summation variable ii, we could apply any function ff that gives an answer f(i)f(i) for every ii between the lower and the upper summation bound. At this point, the saving over the natural language becomes apparent. No one wants to write (or read) “the sum of all squares of the reciprocals of the numbers between 11 and nn”, when instead, we can write

i=1n(1i)2.\displaystyle \sum _{i=1}^{n} \left (\frac {1}{i}\right )^2.

Lower and upper summation bounds are integers, and they can also be negative. Summation variables are not always called ii; in fact, i,j,ki,j,k are the most frequently used ones. So for example,

k=22k=(2)+(1)+0+1+2=0.\displaystyle \sum _{k=-2}^{2} k = (-2) + (-1) + 0 + 1 + 2 = 0.

There are rare cases where the summation variable does not actually occur behind the Σ\Sigma . For example, consider the sum

k=1101.\displaystyle \sum _{k=1}^{10} 1.
You may ask what this is good for, but apart from that, there is no reason to get confused. This sum is just 1+1++11+1+\cdots +1, with one 11 for every kk between 11 and 1010. Hence, k=1101=10\sum _{k=1}^{10} 1=10.

Exercise 1.

What are the values of the following sums?

  • i=35i\sum _{i=3}^{5}i

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • i=53i\sum _{i=5}^3i

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • i=13(i+1)\sum _{i=1}^3(i+1)

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • k=20k\sum _{k=-2}^{0}k

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • k=mn1\sum _{k=m}^n 1, where we assume that nmn\geq m.

    Input (Single Choice)
    • nmn-m
    • nm+1n-m+1
    • nm1n-m-1
    • 00

    Decide which of the provided answers is correct and select it by clicking on the corresponding box, thus marking it with a blue border like so:

    • Unselected
    • Selected
    • Unselected

    Exactly one of the provided answers is correct.

Exercise 2.

Bring the sums in Σ\Sigma ‐notation into the same order as the following sums in natural language.

  • The sum of all numbers between nn and mm.

  • The sum of all numbers between mm and nn.

  • The sum of all even numbers between 1010 and 100100.

  • The sum of all odd numbers between 1010 and 100100.

  • The sum of all absolute values of numbers between 10-10 and 1010.

  • The sum of all numbers between 10-10 and 1010.

Input (Sequence)
  • i=1010i\sum _{i=-10}^{10}|i|
  • i=5502i\sum _{i=5}^{50} 2i
  • i=nmi\sum _{i=n}^{m} i
  • i=1010i\sum _{i=-10}^{10}i
  • i=549(2i+1)\sum _{i=5}^{49} (2i+1)
  • i=mni\sum _{i=m}^{n} i

Bring the provided items into the correct order by clicking and grabbing the corresponding boxes.

For example, if you were asked to put the integers 1 to 5 in descending order, then the following input would be expected:

  • 5
  • 4
  • 3
  • 2
  • 1

2Summing over sets and conditions

Sometimes, it is unnatural or even impossible to write a sum in Σ\Sigma ‐notation in the way we did before. As an example, consider “the sum of all even numbers between 1010 and 100100” from Exercise 2. Here, the solution i=5502i\sum _{i=5}^{50} 2i seems to be a bit of a workaround. We would prefer to directly sum over the even numbers between 1010 and 100100. This can be done as follows. We let S={10,12,...,100}S=\{ 10,12,...,100\} be the set of even numbers between 11 and 100100 and then simply write

iSi.\displaystyle \sum _{i\in S} i.
This notation means that the summation variable ii “goes through” all elements of the set SS. In which order we go through SS doesn’t and shouldn’t matter, as the elements are in the bag SS in no particular order. Luckily, this works out, since summation is commutative, meaning that the result does not depend on the summation order. We have 1+2+3=61+2+3=6 and also 3+1+2=63+1+2=6.

In the previous example, we had to introduce an extra set constant SS, or we could have written

i{10,12,...,100}i.\displaystyle \sum _{i\in \{ 10,12,...,100\} } i.
Both variants have disadvantages. When reading iSi\sum _{i\in S} i, the reader has to remember what SS was, and writing the set out explicitly, as in i{10,12,...,100}i\sum _{i\in \{ 10,12,...,100\} } i, may look complicated, in particular if the set has no short notation.

Another alternative is the following:

10i100;i eveni.\displaystyle \sum _{10\leq i\leq 100; \scriptsize i \text { even}} i.
Here, we have a condition below the Σ\Sigma , and the meaning is that we sum over all ii satisfying the condition; in this case, being between 1010 and 100100 and even; so the semicolon in the condition stands for “and”.

There is no generally preferable notation here, it always depends on the sum in question. The goal should always be to write down the sum such that it is unambiguous and at the same time as readable as possible.

Exercise 3.

What are the values of the following sums?

Inputs (Number)
1<i<10;i oddi=\displaystyle \sum _{\mathclap {1< i < 10; \scriptsize i \text { odd}}}^{\phantom {|}}i =
i{5,4,...,3,4}i  =\displaystyle \sum _{\mathclap {i\in \{ -5,-4,...,3,4\} }}^{\phantom {|}}i \; =
ii=\displaystyle \sum _{i\in \emptyset }^{\phantom {|}} i =

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

3Subscripts

Suppose we have a vector such as (5,4,1,1,3,6,8)(5,4,1,1,3,-6,8). Now we want to express “the sum of all elements of the vector” using Σ\Sigma ‐notation. How do we do this? The idea is simple:

i=17i-th element of (5,4,1,1,3,6,8).\displaystyle \sum _{i=1}^7 i\text {-th element of } (5,4,1,1,3,-6,8).
Except that writing “ii‐th element of (5,4,1,1,3,6,8)(5,4,1,1,3,-6,8)” is cumbersome. You also realize that it doesn’t matter whether the vector is (5,4,1,1,3,6,8)(5,4,1,1,3,-6,8), and whether it has length 77 to begin with. Using a variable for the vector, and one for its length, we can talk about the sum of all elements of an nn‐vector vv as
i=1ni-th element of v.\displaystyle \sum _{i=1}^n i\text {-th element of } v.
To simplify this further (and get rid of all remaining traces of prose), mathematicians prefer to write this as
i=1nvi.\displaystyle \sum _{i=1}^nv_i.
Here, the ii in viv_i is a subscript, and viv_i denotes the ii‐th element of vector vv. This also allows us to write the nn‐vector vv as v=(v1,v2,...,vn)v=(v_1,v_2,...,v_n). Let’s say we only want to sum up the elements of vv at odd positions, i.e. the first, the third, and so on. Then we can write
iSnvi,\displaystyle \sum _{i\in S}^nv_i,
where SS is the set of odd numbers between 11 and nn. Alternatively, we could write
1in;i oddvi.\displaystyle \sum _{1\leq i\leq n;\scriptsize i \text { odd}}v_i.

Exercise 4.

Let v=(5,4,1,1,3,6,8)v=(5,4,1,1,3,-6,8). What are the values of the following sums?

Inputs (Number)
i=16vi=\displaystyle \sum _{i=1}^6 v_i =
i=16vi+1=\displaystyle \sum _{i=1}^6 v_{i+1} =
i{1,3,...,7}vi=\displaystyle \sum _{i\in \{ 1,3,...,7\} }^{\phantom {|}}v_i =

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

There is another use of subscripts. We know how to talk about one function ff, one set SS, one natural number nn, one real number xx, and so on. But let’s say we want to talk about two or even more functions. We could call them f,g,h,...f,g,h,..., but that way, we quickly run out of letters. It is more practical to talk about two functions called f1,f2f_1,f_2, three sets called S1,S2,S3S_1,S_2, S_3, or four integers called n1,n2,n3,n4n_1,n_2,n_3,n_4. When we have just two (maybe at most three) objects, for example integers, naming them n,n,nn,n',n'' is also common.

4Matrices and two subscripts

A vector is tuple of numbers such as v=(6,5,6,4,3)v=(6,5,6,4,3). The first number is v1=6v_1=6, the second one is v2=5v_2=5, and so on. But sometimes, numbers are ordered in a two‐dimensional fashion. For example, if we specify a function with two arguments via a value table, the entries of the table form a two‐dimensional matrix. Recall the example from before, f(x,y)=xyf(x,y)=x^y with value table

y=01234x=0111111012342014916301827644011681256\displaystyle \begin {array}{r|rrrrr}& y=0 & 1 & 2 & 3 & 4 \\ \hline x=0 & 1 & 1 & 1 & 1 & 1 \\ 1 & 0 & 1 & 2 & 3 & 4 \\ 2 & 0 & 1 & 4 & 9 & 16 \\ 3 & 0 & 1 & 8 & 27 & 64 \\ 4 & 0 & 1 & 16 & 81 & 256\end {array}

The function values form a 5×55\times 5‐matrix

M=(11111012340149160182764011681256),\displaystyle M = \left (\begin {array}{rrrrr}1 & 1 & 1 & 1 & 1 \\ 0 & 1 & 2 & 3 & 4 \\ 0 & 1 & 4 & 9 & 16 \\ 0 & 1 & 8 & 27 & 64 \\ 0 & 1 & 16 & 81 & 256\end {array}\right ),
a two‐dimensional collection of numbers. How would we sum up all elements of MM in Σ\Sigma ‐notation? We would write
i=15j=15Mi,j.\displaystyle \sum _{i=1}^5\sum _{j=1}^5 M_{i,j}.
Here, Mi,jM_{i,j} has two subscripts, one for the row and one for the column. So Mi,jM_{i,j} is the element of MM in row ii and column jj. For example, M2,4=3M_{2,4}=3 and M4,1=0M_{4,1}=0 in the example above. Sometimes, you also see MijM_{ij} (subscripts not separated by a comma), and this works fine if the subscripts are variables. But if they are not, then there is a problem: writing M24M_{24} instead of M2,4M_{2,4} could create confusion; the reader might think that M24M_{24} is the 2424‐th element of a vector called MM.

In i=15j=15Mi,j\sum _{i=1}^5\sum _{j=1}^5 M_{i,j}, we have a double sum. This is to be read as

i=15(j=15Mi,j),\displaystyle \sum _{i=1}^5\left (\sum _{j=1}^5 M_{i,j}\right ),
i.e. in evaluating the double sum, we first compute the five inner sums j=15Mi,j\sum _{j=1}^5 M_{i,j} for i=1,2,3,4,5i=1,2,3,4,5; the outer sum then adds up these 5 inner sums. Using conditions, this can also be written as a single sum
1i,j5Mi,j.\displaystyle \sum _{1\leq i,j\leq 5} M_{i,j}.
This means that ii and jj go through all possible combinations where both ii and jj are between 11 and 55.

We can also have three or more subscripts if numbers are ordered in a three‐ or even higher‐dimensional structure, but this is rarely needed, so we will not discuss it.

An obvious but useful feature of double sums is that the order of summation can be interchanged without changing the result. If MM is an n×mn\times m matrix (nn rows, mm columns), then

i=1nj=1mMij=j=1mi=1nMij.\displaystyle \sum _{i=1}^n \sum _{j=1}^m M_{ij} = \sum _{j=1}^m \sum _{i=1}^n M_{ij}.
Indeed, the first double sum adds up the elements of MM row by row: each inner sum is the sum of all elements in one row. The second double sum adds up the elements column by column: each inner sum is the sum of all elements in one column. But as summation is commutative, it doesn’t matter whether we sum rowwise or columnwise, the result will always be the same.

Exercise 5.

Let

M=(11111012340149160182764011681256,).\displaystyle M = \left (\begin {array}{rrrrr}1 & 1 & 1 & 1 & 1 \\ 0 & 1 & 2 & 3 & 4 \\ 0 & 1 & 4 & 9 & 16 \\ 0 & 1 & 8 & 27 & 64 \\ 0 & 1 & 16 & 81 & 256,\end {array}\right ).
What are the values of the following sums?
  • i=13j=45Mi,j\displaystyle \sum _{i=1}^3 \sum _{j=4}^5 M_{i,j}

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • 1i,j2Mi,j\displaystyle \sum _{1\leq i,j\leq 2} M_{i,j}

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  • iRjCMi,j\displaystyle \sum _{i\in R}\sum _{j\in C} M_{i,j}, where R={1,3,5}R=\{ 1,3,5\} and C={2,4}C=\{ 2,4\}

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

5Back to sets

Subscripts and conditions—so far just defining ranges to sum over—can directly be used to define sets, not only in the context of sums. For example, the set of all natural numbers between 1 and 100 (that we have previously written as {1,2,...,100}\{ 1,2,...,100\} could also be defined as {iN:1i100}\{ i\in \N : 1\leq i\leq 100\} . This notation means that the set consists of all natural numbers ii that satisfy the condition after the colon. Unlike for example in the sum

1i100i,\displaystyle \sum _{1\leq i\leq 100} i,
we have to say that what kind of number the set contains, and by writing iN:...i\in \N :..., we indicate that these are natural numbers. In the sum, this extra piece of information is not needed, since summation variables are integers anyway.

This way of defining sets is really flexible and lets you express many things in a concise way. As an example, let’s imagine that you are repeatedly running some track, and each time you record your run time (in minutes rounded down, say). If you have run the track a total of nn times, the result is an nn‐vector vv that may look like this: (19,18,19,20,17,17,16,17,16,15)(19, 18, 19, 20, 17, 17, 16, 17, 16, 15). Now you want to know in which runs you have beaten your previous record. In the example, these are the runs 2, 5, 7, 10.

But now, given any nn‐vector vv, how do you express the set of runs in which you have beaten your previous record? Here is a way to do it, using conditions, subscripts, and functions (we also always have those!):

S={iN:2in;vi<min(v1,...,vi1)}.\displaystyle S = \{ i\in \N : 2\leq i\leq n; v_i < \min (v_1,...,v_{i-1})\} .
Here, min\min is a (quite self‐explanatory) function that can take several arguments and does the natural thing: the function value is the minimum (the smallest) value among its arguments. Then the condition vi<min(v1,...,vi1)v_i < \min (v_1,...,v_{i-1}) says that the run time in the ii‐th run is smaller than in all the runs before, so the ii‐th run establishes a new record. Hence, in the set SS, we collect all runs between 22 and nn that establish a new record.

Exercise 6.

  • Select the elements contained in the set S={kN:1k5}S=\{ k\in \N : -1\leq k\leq 5\} .

    Input (Multiple Choice)
    • 1-1
    • 00
    • 11
    • 22
    • 33
    • 44
    • 55
    • 66
    • 77
    • 88
    • 99
    • 1010

    Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

    • Unselected
    • Selected
    • Unselected
    • Selected

    Any number of the provided answers can be correct, including zero.

  • Select the elements contained in the set S={kZ:1k5}S=\{ k\in \Z : -1\leq k\leq 5\} .

    Input (Multiple Choice)
    • 1-1
    • 00
    • 11
    • 22
    • 33
    • 44
    • 55
    • 66
    • 77
    • 88
    • 99
    • 1010

    Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

    • Unselected
    • Selected
    • Unselected
    • Selected

    Any number of the provided answers can be correct, including zero.

  • Select the elements contained in the set S={kN:2k10;k even}S=\{ k\in \N : 2\leq k\leq 10; k \text { even}\} .

    Input (Multiple Choice)
    • 1-1
    • 00
    • 11
    • 22
    • 33
    • 44
    • 55
    • 66
    • 77
    • 88
    • 99
    • 1010

    Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

    • Unselected
    • Selected
    • Unselected
    • Selected

    Any number of the provided answers can be correct, including zero.

  • Let v=(0,1,1,2,3,4,4,5,5,5,6)v=(0,1,1,2,3,4,4,5,5,5,6) be a vector (of length 1111). Select the elements contained in the set S={kN:1k10;vk=vk+1}S=\{ k\in \N : 1\leq k\leq 10; v_k=v_{k+1}\} .

    Input (Multiple Choice)
    • 1-1
    • 00
    • 11
    • 22
    • 33
    • 44
    • 55
    • 66
    • 77
    • 88
    • 99
    • 1010

    Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

    • Unselected
    • Selected
    • Unselected
    • Selected

    Any number of the provided answers can be correct, including zero.