taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Volume C1 · Basic concepts · TAOCP Section 1.2.3

Sums and products

Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.

Read it next to Section 1.2.3 of the book. The nodes and the exercises of the section.

Contents
  1. Sums and products

Sums and products

Overview

Section 1.2.3 of TAOCP sets up the notation for sums and products. A sum ∑R(j)aj\sum_{R(j)} a_j runs over all integers jj that satisfy a relation R(j)R(j), so the limits of a sum can be any condition, not only a pair of end points. The section gives four rules for working with such sums: the distributive law, the change of the index variable, the interchange of two sums, and the splitting or merging of the domain. It uses the rules to derive the sum of a geometric progression and of an arithmetic progression, and the identity of eq. 1.2.3(13) for a double sum with j≤ij \le i. It then introduces the bracket [statement][\text{statement}], which is 11 for a true statement and 00 for a false one, and shows that the bracket makes the four rules mechanical. It ends with the Kronecker delta, the product notation, and sums in several indices at once. The section uses induction (Section 1.2.1) only for the remarks on the exercises, and it uses real numbers (Section 1.2.2) for the infinite sums.

The ideas

A sum is a function of a set. The symbol ∑R(j)aj\sum_{R(j)} a_j means: find the set of integers jj for which the relation R(j)R(j) holds, and add the numbers aja_j for these jj. The order does not matter. The sum of an empty set is 00. When the set is infinite, the definition uses limits, and then some rules need care.

Four rules do most of the work. To distribute, multiply each term of one sum with each term of the other. To change the index, rename it or replace jj by c±jc \pm j. To interchange, add the same array of terms by columns instead of by rows. To change the domain, split a range into parts or merge two ranges, and correct for the terms that lie in both. Each rule is a fact about adding a finite list of numbers in a different order or in groups.

The manipulation is a method of discovery. The book proves the sum of a geometric progression by writing the sum twice in two forms, not by induction, and the same idea gives the sum of an arithmetic progression. The point is that a person who does not know the formula can find it. C1 shows these derivations, and it also shows the check by induction, so that the reader sees both ways.

The bracket turns a range into a factor. If [R(j)][R(j)] is 11 when R(j)R(j) is true and 00 when it is false, then ∑R(j)aj=∑jaj[R(j)]\sum_{R(j)} a_j = \sum_j a_j [R(j)], where jj now runs over all integers. A change in the range of summation becomes a change in a product of brackets, and a statement about brackets is an ordinary statement about numbers that a person can check. This is why the change of variable, the interchange of two sums and the splitting of a domain all follow from rules for sums over all integers.

Infinite sums need a condition. For a finite set the four rules always hold. For an infinite set, the sum of a divergent series is not defined, and an absolutely convergent series (one for which the sum of the absolute values is finite) can be handled by all the rules. The book states this in notes and leaves the proofs to the exercises. C1 proves the cases that are used later: the distributive law and the shift j↦c±jj \mapsto c \pm j for any convergent sums, and the general change of index and the interchange for absolutely convergent sums. C1 gives a counterexample for the interchange without this condition.

C1 takes one step that the book does not take: it states one fact on finite sums first (the sum over a finite set does not depend on the order or on the grouping) and uses it in each proof. The book's proofs are by the examples and are short.

Definitions, results and proofs

Definition C1.1.2.3.1 (the sum with an index from 1 to nn, TAOCP eq. 1.2.3(1)). For numbers a1,a2,…a_1, a_2, \ldots and an integer n≥0n \ge 0, the sum a1+a2+⋯+ana_1 + a_2 + \cdots + a_n is written ∑j=1naj\sum_{j=1}^n a_j. For n=0n = 0 the sum is empty, and its value is 00.

Node: TAP5K3XRDB · status: not stated yet

Explanation. The notation a1+a2+⋯+ana_1 + a_2 + \cdots + a_n with dots has a clear meaning only when n≥3n \ge 3 or so. The ∑\sum sign with limits gives the meaning for each nn, including n=0n = 0 and n=1n = 1. The rule for n=0n = 0 is the one that keeps the later formulas true: for example ∑j=1n(aj+bj)\sum_{j=1}^n (a_j + b_j) splits into two sums for each n≥0n \ge 0 only if the empty sum is the neutral element 00 of the addition. In Lean, this sum is Finset.sum (Finset.Icc 1 n) a, and the empty sum is 0.

Example. ∑j=14j2=1+4+9+16=30\sum_{j=1}^4 j^2 = 1 + 4 + 9 + 16 = 30. ∑j=11aj=a1\sum_{j=1}^1 a_j = a_1. ∑j=10aj=0\sum_{j=1}^0 a_j = 0 for each sequence aa. The sum ∑j=1n1\sum_{j=1}^{n} 1 is nn, the number of terms.

Definition C1.1.2.3.2 (the sum over a relation, TAOCP eq. 1.2.3(2)). Let R(j)R(j) be a relation on the integer jj, and suppose that only finitely many integers satisfy it. Then ∑R(j)aj\sum_{R(j)} a_j is the sum of the numbers aja_j over all integers jj with R(j)R(j) true. If no integer satisfies R(j)R(j), the sum is 00. When two or more conditions stand under the ∑\sum sign, all of them must hold.

Node: TA229MTBV7 · status: not stated yet

Explanation. The relation can be any statement about jj: 1≤j≤n1 \le j \le n, "jj is even", 0≤j2≤100 \le j^2 \le 10, or a mix. The sum ∑1≤j≤naj\sum_{1 \le j \le n} a_j is the same as ∑j=1naj\sum_{j=1}^n a_j when nn is an integer, and it is still meaningful when nn is not an integer: for n=3.14n = 3.14 it is a1+a2+a3a_1 + a_2 + a_3. The notation counts each integer once. This means that the sum depends on the set {j:R(j)}\{j : R(j)\} and on the function j↦ajj \mapsto a_j, not on the way that the set is written. In Lean, this is a sum over a Finset, or finsum when the set is not known to be finite.

Example. ∑0≤j≤10, j evenj=0+2+4+6+8+10=30\sum_{0 \le j \le 10,\ j \text{ even}} j = 0 + 2 + 4 + 6 + 8 + 10 = 30. The relation 0≤j2≤100 \le j^2 \le 10 holds for j=−3,−2,…,3j = -3, -2, \ldots, 3, so ∑0≤j2≤10j2=9+4+1+0+1+4+9=28\sum_{0 \le j^2 \le 10} j^2 = 9 + 4 + 1 + 0 + 1 + 4 + 9 = 28. The relation 0≤j≤50 \le j \le 5 and j oddj \text{ odd} is satisfied by 1,3,51, 3, 5 only.

A fact on finite sums, used in each proof below. Let FF be a finite set of integers (or of pairs of integers), and let ff be a function with numbers as values. The sum ∑x∈Ff(x)\sum_{x \in F} f(x) does not depend on the order of the terms, and it can be formed in groups: if FF is split into disjoint parts F1,…,FrF_1, \ldots, F_r, then ∑Ff=∑F1f+⋯+∑Frf\sum_F f = \sum_{F_1} f + \cdots + \sum_{F_r} f. The proof is by induction on the number of elements of FF. For ∣F∣=0|F| = 0 both sides are 00. For ∣F∣=m+1|F| = m + 1, remove one element x0x_0 of the last part FrF_r (or any element). The sum over FF is the sum over F∖{x0}F \setminus \{x_0\} plus f(x0)f(x_0), by commutativity of the addition, and the induction hypothesis applies to the smaller set with the same grouping, one part now smaller. The result is the same sum written in a different order, which is equal by the commutative and associative laws of the addition. □\square

Definition C1.1.2.3.3 (an infinite sum, TAOCP eq. 1.2.3(3)). Let R(j)R(j) be a relation that is true for infinitely many integers. Form the two limits below, one for the indices j≥0j \ge 0 and one for the indices j<0j < 0. When both limits exist, the sum ∑R(j)aj\sum_{R(j)} a_j is convergent, and its value is the sum of the two limits. When one of them does not exist, the sum is divergent and has no value. ∑R(j)aj=lim⁡n→∞∑R(j)0≤j≤naj+lim⁡n→∞∑R(j)−n≤j<0aj.\sum_{R(j)} a_j = \lim_{n \to \infty} \sum_{\substack{R(j) \\ 0 \le j \le n}} a_j + \lim_{n \to \infty} \sum_{\substack{R(j) \\ -n \le j < 0}} a_j.

Node: TA6XKFMSAA · status: not stated yet

Explanation. The definition cuts the integers into the nonnegative part and the negative part and sums each part by its own limit. This avoids the trap that a single limit of symmetric windows would hide: a series like ∑jj\sum_j j has symmetric partial sums 00, but it is not convergent in this sense. The definition also fixes the order of the terms in each part, namely the order of the index. The word convergent has the usual meaning for a sum of a sequence indexed by j≥0j \ge 0. In Lean, a convergent sum is HasSum, and tsum is its value; the definition of HasSum uses limits over all finite sets, not over the order of jj, so it is equal to the sum of the book only for absolutely convergent series (see eq. 1.2.3(5)).

Example. ∑j≥02−j\sum_{j \ge 0} 2^{-j} is convergent: the partial sums are 2−2−n2 - 2^{-n}, and the limit is 22. The sum over all integers ∑j2−∣j∣\sum_j 2^{-|j|} has the nonnegative part 22 and the negative part ∑j≥12−j=1\sum_{j \ge 1} 2^{-j} = 1, so its value is 33. The sum ∑j≥11/j\sum_{j \ge 1} 1/j is divergent: the partial sums grow without bound, because the block of terms from 2m+12^m + 1 to 2m+12^{m+1} has 2m2^m terms that are each at least 2−m−12^{-m-1}, so it adds at least 1/21/2, and H2m≥1+m/2H_{2^m} \ge 1 + m/2. The value H1000=7.485…H_{1000} = 7.485\ldots is still small, and the growth is slow. The sum ∑j≥1(−1)j+1/j\sum_{j \ge 1} (-1)^{j+1}/j is convergent, with the value ln⁡2=0.6931…\ln 2 = 0.6931\ldots.

Theorem C1.1.2.3.4 (the distributive law, TAOCP eq. 1.2.3(4)). For finite sets RR and SS of integers, (∑R(i)ai)(∑S(j)bj)=∑R(i)(∑S(j)aibj).\Bigl(\sum_{R(i)} a_i\Bigr)\Bigl(\sum_{S(j)} b_j\Bigr) = \sum_{R(i)} \Bigl(\sum_{S(j)} a_i b_j\Bigr).

Node: TAT0EPRN7R · Lean: TAOCP.S1_2_3.eq4 · status: proved

Scope. The same holds for infinite sums when both sums on the left are convergent (exercise 1.2.3-5). Absolute convergence is not needed.

Explanation. The product of two sums is the sum of all products of a term of the first with a term of the second. The right side groups these products by the value of ii: for each ii it takes the sum aibja_i b_j over jj. It is the rule that a person already uses to expand (a1+a2)(b1+b2+b3)(a_1 + a_2)(b_1 + b_2 + b_3). In C1, as in the book, a double sum ∑R(i)∑S(j)aij\sum_{R(i)} \sum_{S(j)} a_{ij} has no parentheses: the inner sum is always the one on the right.

Example. Let R={1,2}R = \{1, 2\} with a1=1a_1 = 1, a2=2a_2 = 2 and S={1,2,3}S = \{1, 2, 3\} with b1=3b_1 = 3, b2=4b_2 = 4, b3=5b_3 = 5. The left side is 3⋅12=363 \cdot 12 = 36. The right side groups by ii: for i=1i = 1 the inner sum is 1⋅(3+4+5)=121 \cdot (3 + 4 + 5) = 12, for i=2i = 2 it is 2⋅12=242 \cdot 12 = 24, and the total is 3636.

Proof. Finite case. Fix SS and the numbers bjb_j, and put B=∑SbjB = \sum_S b_j. The claim is (∑Rai)B=∑RaiB\bigl(\sum_R a_i\bigr) B = \sum_R a_i B and aiB=∑Saibja_i B = \sum_S a_i b_j. The second part is the repeated distributive law a(b1+⋯+bs)=ab1+⋯+absa (b_1 + \cdots + b_s) = ab_1 + \cdots + ab_s for numbers, which follows from the two-term law by induction on ss. The first part has the same form: induction on ∣R∣|R|. For ∣R∣=0|R| = 0 both sides are 00. If R=R′∪{i0}R = R' \cup \{i_0\}, then (∑R′ai+ai0)B=(∑R′ai)B+ai0B=∑R′aiB+ai0B=∑RaiB\bigl(\sum_{R'} a_i + a_{i_0}\bigr) B = \bigl(\sum_{R'} a_i\bigr) B + a_{i_0} B = \sum_{R'} a_i B + a_{i_0} B = \sum_R a_i B.

Infinite case. Let A=∑RaiA = \sum_R a_i and B=∑SbjB = \sum_S b_j be convergent in the sense of eq. 1.2.3(3). Fix ii. Each partial sum of the inner sum ∑S(j)aibj\sum_{S(j)} a_i b_j is aia_i times the partial sum of BB with the same range, by the finite case. A constant factor goes through a limit, so both limits of eq. 1.2.3(3) exist for the inner sum, and its value is aiBa_i B. The outer sum is then ∑R(i)aiB\sum_{R(i)} a_i B. By the same argument with the constant BB, it is convergent and its value is ABAB. □\square

Theorem C1.1.2.3.5 (the change of the index, TAOCP eq. 1.2.3(5)). Let R(i)R(i) be a relation and let pp be a function from the integers to the integers. Suppose that pp maps the set {j:R(p(j))}\{j : R(p(j))\} one to one onto the set {i:R(i)}\{i : R(i)\}. Then ∑R(i)ai=∑R(j)aj=∑R(p(j))ap(j).\sum_{R(i)} a_i = \sum_{R(j)} a_j = \sum_{R(p(j))} a_{p(j)}.

Node: TARPT5ZEHK · Lean: TAOCP.S1_2_3.eq5, TAOCP.S1_2_3.eq5_book · status: proved

Scope. The first equality only renames the index. The second one is a change of the index by the function pp. For a finite set it always holds. For an infinite sum it holds for p(j)=c+jp(j) = c + j and p(j)=c−jp(j) = c - j with any integer cc, and for each pp when ∑R(i)∣ai∣\sum_{R(i)} |a_i| is finite.

Explanation. The condition on pp says that pp matches the set of the values jj with R(p(j))R(p(j)) one to one with the set of the values ii with R(i)R(i). So the right sum has the same terms as the left sum, in another order. The two important cases are the shift p(j)=c+jp(j) = c + j and the reflection p(j)=c−jp(j) = c - j. They are used in almost each manipulation of a sum, and the book asks the reader to study the shift example of eq. 1.2.3(6) with care. In a convergent series that is not absolutely convergent, a general pp can change the value: a reordering of the terms of ∑(−1)j+1/j\sum (-1)^{j+1}/j that takes two positive terms for one negative term has the sum 32ln⁡2\tfrac32 \ln 2 in the place of ln⁡2\ln 2 (this is a standard fact of analysis; Riemann proved that the rearrangements of a conditionally convergent series reach every real value). The exercise 1.2.3-8 asks for an example for a related fault of the interchange.

Example. Let aj=j2a_j = j^2, R(i)R(i) be 0≤i≤40 \le i \le 4, and p(j)=4−jp(j) = 4 - j. The left side is 0+1+4+9+16=300 + 1 + 4 + 9 + 16 = 30. The relation R(p(j))R(p(j)) is 0≤4−j≤40 \le 4 - j \le 4, that is 0≤j≤40 \le j \le 4, and the right side is ∑0≤j≤4(4−j)2=16+9+4+1+0=30\sum_{0 \le j \le 4} (4 - j)^2 = 16 + 9 + 4 + 1 + 0 = 30. For a map that is not a permutation, p(j)=j2p(j) = j^2 with the relation 0≤i≤100 \le i \le 10 takes the values i=0,1,4,9i = 0, 1, 4, 9 and the sum ∑R(p(j))ap(j)\sum_{R(p(j))} a_{p(j)} counts i=1,4,9i = 1, 4, 9 twice. Eq. 1.2.3(18) below gives the exact value in such a case.

Proof. Finite case. By the hypothesis, pp restricted to J={j:R(p(j))}J = \{j : R(p(j))\} is a bijection onto I={i:R(i)}I = \{i : R(i)\}. The sum over JJ of ap(j)a_{p(j)} has one term aia_i for each i∈Ii \in I, by the match i=p(j)i = p(j), so it is the sum over II of aia_i in a different order, which is equal by the fact on finite sums.

The shift and the reflection for a convergent infinite sum. First, a remark on windows. Let Un=∑R(i),0≤i≤naiU_n = \sum_{R(i), 0 \le i \le n} a_i and Vm=∑R(i),−m≤i<0aiV_m = \sum_{R(i), -m \le i < 0} a_i, and let TT be the value lim⁡Un+lim⁡Vm\lim U_n + \lim V_m of eq. 1.2.3(3). The sum of the terms with −m≤i≤n-m \le i \le n is Un+VmU_n + V_m, so it tends to TT when mm and nn tend to infinity independently. Now let p(j)=c+jp(j) = c + j. The terms with −m≤j≤n-m \le j \le n of the new sum are the terms aia_i of the old sum with −m+c≤i≤n+c-m + c \le i \le n + c. This is a window of the same kind, with the end points −(m−c)-(m - c) and n+cn + c, which both tend to infinity. So the window sums of the new sum tend to TT in the same independent sense, and in particular both limits of eq. 1.2.3(3) exist for the new sum, and their sum is TT. The case of p(j)=c−jp(j) = c - j is the same: the window −m≤j≤n-m \le j \le n of the new sum matches the window c−n≤i≤c+mc - n \le i \le c + m of the old sum.

The absolutely convergent case. Let ∑R(i)∣ai∣\sum_{R(i)} |a_i| be convergent and let TT be the value of ∑R(i)ai\sum_{R(i)} a_i. For each ε>0\varepsilon > 0 there is an MM such that the sum of ∣ai∣|a_i| over the i∈Ii \in I with ∣i∣>M|i| > M is less than ε\varepsilon. Let F1⊂F2⊂⋯F_1 \subset F_2 \subset \cdots be finite sets with union II. Take k0k_0 such that FkF_k contains all i∈Ii \in I with ∣i∣≤M|i| \le M for k≥k0k \ge k_0. Then for such kk both ∣T−∑I,∣i∣≤Mai∣|T - \sum_{I, |i| \le M} a_i| and ∣∑Fkai−∑I,∣i∣≤Mai∣|\sum_{F_k} a_i - \sum_{I, |i| \le M} a_i| are at most ε\varepsilon, so ∣∑Fkai−T∣≤2ε|\sum_{F_k} a_i - T| \le 2\varepsilon. This shows that the sum is the limit along any sequence of finite sets that grows to II. Apply this to JJ, the set of the jj with R(p(j))R(p(j)): the sums of the absolute values over finite parts of JJ are bounded by the sum of ∣ai∣|a_i| over II, so the new sum is absolutely convergent too. Take Jk={j∈J:∣p(j)∣≤k}J_k = \{j \in J : |p(j)| \le k\}. These are finite sets that grow to JJ (each JkJ_k is finite, since pp is a bijection of JJ onto II and only finitely many i∈Ii \in I have ∣i∣≤k|i| \le k). By the finite case, ∑Jkap(j)=∑I,∣i∣≤kai→T\sum_{J_k} a_{p(j)} = \sum_{I, |i| \le k} a_i \to T. So the new sum has the value TT. □\square

Example C1.1.2.3.6 (a shift of the index, TAOCP eq. 1.2.3(6)). For integers n≥1n \ge 1: ∑1≤j≤naj=∑1≤j−1≤naj−1=∑2≤j≤n+1aj−1.\sum_{1 \le j \le n} a_j = \sum_{1 \le j - 1 \le n} a_{j-1} = \sum_{2 \le j \le n + 1} a_{j-1}.

Node: TABDYK947N · Lean: TAOCP.S1_2_3.eq6 · status: proved

Explanation. This is eq. 1.2.3(5) with p(j)=j−1p(j) = j - 1. The relation 1≤j−1≤n1 \le j - 1 \le n is the same as 2≤j≤n+12 \le j \le n + 1, by adding 11 to each part. The index moves up by one, and the term moves down by one. Both of these shifts are needed to get a sum into a form where it can be combined with another sum: the derivation of eq. 1.2.3(14) below uses exactly this shift.

Example. Let aj=j2a_j = j^2 and n=4n = 4. The left side is 1+4+9+16=301 + 4 + 9 + 16 = 30. The right side is ∑j=25(j−1)2=1+4+9+16=30\sum_{j=2}^{5} (j - 1)^2 = 1 + 4 + 9 + 16 = 30. The same four numbers appear, with the label jj moved by one.

Theorem C1.1.2.3.7 (the interchange of two sums, TAOCP eq. 1.2.3(7)). For finite sets RR and SS, ∑R(i)∑S(j)aij=∑S(j)∑R(i)aij.\sum_{R(i)} \sum_{S(j)} a_{ij} = \sum_{S(j)} \sum_{R(i)} a_{ij}.

Node: TA09P1QYVS · Lean: TAOCP.S1_2_3.eq7 · status: proved

Scope. For infinite sets, the interchange is valid when ∑R(i)∑S(j)∣aij∣\sum_{R(i)} \sum_{S(j)} |a_{ij}| exists, and also when one of RR and SS is finite and each infinite sum that occurs is convergent.

Explanation. The array (aij)(a_{ij}) with i∈Ri \in R and j∈Sj \in S can be summed by rows or by columns. The two results are equal. The interchange is useful because often one of the two inner sums has a closed form and the other does not. For infinite sets, the order matters, as the counterexample below shows.

Example. Take the array aij=i+10ja_{ij} = i + 10j with i∈{1,2}i \in \{1, 2\} and j∈{1,2,3}j \in \{1, 2, 3\}. By rows: row 11 is 11+21+31=6311 + 21 + 31 = 63 and row 22 is 12+22+32=6612 + 22 + 32 = 66, so the total is 129129. By columns: column 11 is 11+12=2311 + 12 = 23, column 22 is 21+22=4321 + 22 = 43, column 33 is 31+32=6331 + 32 = 63, and the total is 129129.

Proof. Finite case: by induction on ∣S∣|S|. For ∣S∣=0|S| = 0 both sides are 00. If S=S′∪{j0}S = S' \cup \{j_0\}, then ∑R∑Saij=∑R(∑S′aij+aij0)=∑R∑S′aij+∑Raij0\sum_R \sum_S a_{ij} = \sum_R (\sum_{S'} a_{ij} + a_{ij_0}) = \sum_R \sum_{S'} a_{ij} + \sum_R a_{ij_0}, by eq. 1.2.3(8) (proved in the next block, from the commutativity of the addition alone). By the induction hypothesis, the first part is ∑S′∑Raij\sum_{S'} \sum_R a_{ij}, and the whole is ∑S′∑Raij+∑Raij0=∑S∑Raij\sum_{S'} \sum_R a_{ij} + \sum_R a_{ij_0} = \sum_S \sum_R a_{ij}. For the absolutely convergent case, first let all aij≥0a_{ij} \ge 0. A sum of nonnegative terms in the sense of eq. 1.2.3(3) is the least upper bound of its finite partial sums. Let KK run over the finite sets of pairs (i,j)(i, j) with R(i)R(i) and S(j)S(j). Each ∑Kaij\sum_K a_{ij} is at most the sum by rows, since the terms are not negative. A finite part of the outer sum by rows is a finite sum of inner sums, and each inner sum is the least upper bound of its own finite parts, so that finite part is the least upper bound of some of the ∑Kaij\sum_K a_{ij}. Hence the sum by rows is the least upper bound of all ∑Kaij\sum_K a_{ij}. The same holds for the sum by columns, so the two iterated sums are equal. For real aija_{ij}, write aij=bij−cija_{ij} = b_{ij} - c_{ij} with bij=max⁡(aij,0)b_{ij} = \max(a_{ij}, 0) and cij=max⁡(−aij,0)c_{ij} = \max(-a_{ij}, 0). Both are nonnegative and at most ∣aij∣|a_{ij}|, so their iterated sums are finite and do not depend on the order. Subtract them with eq. 1.2.3(8) for convergent sums. For complex aija_{ij}, apply this to the real and the imaginary parts. The case with one finite range is the sum of a finite number of convergent sums, which is eq. 1.2.3(8) for infinite sums. □\square

A counterexample without the condition. Let R=S={1,2,3,…}R = S = \{1, 2, 3, \ldots\} and let aii=1a_{ii} = 1, ai+1,i=−1a_{i+1,i} = -1 and all other aij=0a_{ij} = 0. For fixed i≥2i \ge 2, the row has the two nonzero terms aii=1a_{ii} = 1 and ai,i−1=−1a_{i,i-1} = -1, so the row sum is 00. Row 11 has only a11=1a_{11} = 1, so its sum is 11. The sum of the row sums is 11. For each fixed jj, the column has ajj=1a_{jj} = 1 and aj+1,j=−1a_{j+1,j} = -1, so each column sum is 00 and the sum of the column sums is 00. So ∑i∑jaij=1\sum_i \sum_j a_{ij} = 1 and ∑j∑iaij=0\sum_j \sum_i a_{ij} = 0. A computer check with i,j≤200i, j \le 200 agrees: the sum of the first 199199 row sums is 11, and each column sum is 00. The double sum of the absolute values is infinite here, so the first condition fails.

Theorem C1.1.2.3.8 (the sum of a sum, TAOCP eq. 1.2.3(8)). For a finite set RR and numbers bib_i and cic_i, ∑R(i)(bi+ci)=∑R(i)bi+∑R(i)ci.\sum_{R(i)} (b_i + c_i) = \sum_{R(i)} b_i + \sum_{R(i)} c_i.

Node: TAS2J49EG5 · Lean: TAOCP.S1_2_3.eq8 · status: proved

Scope. The same holds for infinite sums when the two sums on the right are convergent.

Explanation. This is the special case of eq. 1.2.3(7) where SS has two elements, ai1=bia_{i1} = b_i and ai2=cia_{i2} = c_i. It says that a sum is additive in its terms. Together with the rule ∑Rcai=c∑Rai\sum_R c a_i = c \sum_R a_i, which is the special case of eq. 1.2.3(4), it says that the sum is a linear function of the sequence of terms.

Example. With bj=jb_j = j and cj=j2c_j = j^2 over 1≤j≤41 \le j \le 4: ∑(j+j2)=2+6+12+20=40\sum (j + j^2) = 2 + 6 + 12 + 20 = 40, and ∑j+∑j2=10+30=40\sum j + \sum j^2 = 10 + 30 = 40.

Proof. For a finite RR, induction on ∣R∣|R|. The case ∣R∣=0|R| = 0 is 0=0+00 = 0 + 0. For R=R′∪{i0}R = R' \cup \{i_0\}, the sum ∑R(bi+ci)=∑R′(bi+ci)+(bi0+ci0)\sum_R (b_i + c_i) = \sum_{R'} (b_i + c_i) + (b_{i_0} + c_{i_0}). By the induction hypothesis this is ∑R′bi+∑R′ci+bi0+ci0\sum_{R'} b_i + \sum_{R'} c_i + b_{i_0} + c_{i_0}, and by the commutative law of the addition it is (∑R′bi+bi0)+(∑R′ci+ci0)=∑Rbi+∑Rci\bigl(\sum_{R'} b_i + b_{i_0}\bigr) + \bigl(\sum_{R'} c_i + c_{i_0}\bigr) = \sum_R b_i + \sum_R c_i. For infinite sums, each of the two limits of eq. 1.2.3(3) is a limit of a sum of two sequences of partial sums, and the limit of a sum is the sum of the limits when both exist. □\square

Theorem C1.1.2.3.9 (the interchange when the inner range depends on the outer index, TAOCP eq. 1.2.3(9)). Let R(i)R(i) and S(i,j)S(i, j) be relations, with finitely many pairs (i,j)(i, j) for which both hold. Define R′(i,j)R'(i, j) as the relation "R(i)R(i) and S(i,j)S(i, j)", and define S′(j)S'(j) as the relation "R′(i,j)R'(i, j) holds for at least one integer ii". Then ∑R(i)∑S(i,j)aij=∑S′(j)∑R′(i,j)aij.\sum_{R(i)} \sum_{S(i,j)} a_{ij} = \sum_{S'(j)} \sum_{R'(i,j)} a_{ij}.

Node: TAP3JGY2XE · Lean: TAOCP.S1_2_3.eq9 · status: proved

Explanation. Both sides add the number aija_{ij} once for each pair (i,j)(i, j) that satisfies R(i)R(i) and S(i,j)S(i, j). The left side groups the pairs by ii. The right side groups them by jj. The relations S′S' and R′R' are the correct new limits: S′(j)S'(j) keeps only the columns jj that have a term, and R′(i,j)R'(i, j) keeps in column jj the rows ii that have a term. The relation S′S' can be hard to write in a simple form, and the example of eq. 1.2.3(10) shows a case where it is easy. Eq. 1.2.3(7) is the special case where S(i,j)S(i, j) does not depend on ii.

Example. Let R(i)R(i) be 1≤i≤41 \le i \le 4 and S(i,j)S(i, j) be "j≥1j \ge 1 and jj divides ii", with aij=i/ja_{ij} = i/j. The condition j≥1j \ge 1 is needed: without it, the negative divisors jj of ii are in the range too. By rows: i=1i = 1 gives 11; i=2i = 2 gives 2+1=32 + 1 = 3; i=3i = 3 gives 3+1=43 + 1 = 4; i=4i = 4 gives 4+2+1=74 + 2 + 1 = 7; the total is 1515. By columns: S′(j)S'(j) is 1≤j≤41 \le j \le 4. For j=1j = 1 the terms are i/1i/1 for i=1,…,4i = 1, \ldots, 4, total 1010. For j=2j = 2 the rows with 2∣i2 \mid i are i=2,4i = 2, 4, total 1+2=31 + 2 = 3. For j=3j = 3 only i=3i = 3, total 11. For j=4j = 4 only i=4i = 4, total 11. The sum is 10+3+1+1=1510 + 3 + 1 + 1 = 15.

Proof. Let PP be the set of pairs (i,j)(i, j) with R′(i,j)R'(i, j). It is finite by the hypothesis. Group the sum ∑Paij\sum_P a_{ij} by the first coordinate: the pairs with a given ii form the set {(i,j):S(i,j)}\{(i, j) : S(i, j)\} if R(i)R(i) and are absent otherwise, so the grouped sum is ∑R(i)∑S(i,j)aij\sum_{R(i)} \sum_{S(i,j)} a_{ij}. Group the same sum by the second coordinate: the pairs with a given jj are those with R′(i,j)R'(i, j), and the column jj is not empty exactly when S′(j)S'(j) holds. So the grouped sum is ∑S′(j)∑R′(i,j)aij\sum_{S'(j)} \sum_{R'(i,j)} a_{ij}. By the fact on finite sums, the two groupings of ∑Paij\sum_P a_{ij} have the same value. □\square

Example C1.1.2.3.10 (a triangle of indices, TAOCP eq. 1.2.3(10)). For n≥1n \ge 1, ∑i=1n∑j=1iaij=∑j=1n∑i=jnaij.\sum_{i=1}^n \sum_{j=1}^i a_{ij} = \sum_{j=1}^n \sum_{i=j}^n a_{ij}.

Node: TA05RYNQEA · Lean: TAOCP.S1_2_3.eq10 · status: proved

Explanation. Here R(i)R(i) is 1≤i≤n1 \le i \le n and S(i,j)S(i, j) is 1≤j≤i1 \le j \le i. The relation S′(j)S'(j) is "there is an ii with 1≤i≤n1 \le i \le n and 1≤j≤i1 \le j \le i", which means 1≤j≤n1 \le j \le n: such an ii needs 1≤j≤i≤n1 \le j \le i \le n, and for 1≤j≤n1 \le j \le n the choice i=ni = n works. The relation R′(i,j)R'(i, j) is 1≤i≤n1 \le i \le n and 1≤j≤i1 \le j \le i, that is j≤i≤nj \le i \le n together with 1≤j1 \le j. The picture is a triangle of cells: the left side adds it by rows, the right side by columns.

Example. For n=3n = 3, written out, the left side is a11+(a21+a22)+(a31+a32+a33)a_{11} + (a_{21} + a_{22}) + (a_{31} + a_{32} + a_{33}) and the right side is (a11+a21+a31)+(a22+a32)+a33(a_{11} + a_{21} + a_{31}) + (a_{22} + a_{32}) + a_{33}. With aij=ija_{ij} = ij the two sums are 1+(2+4)+(3+6+9)=251 + (2 + 4) + (3 + 6 + 9) = 25 and (1+2+3)+(4+6)+9=25(1 + 2 + 3) + (4 + 6) + 9 = 25.

Theorem C1.1.2.3.11 (the sum over a union and an intersection, TAOCP eq. 1.2.3(11)). Let R(j)R(j) and S(j)S(j) be relations with finite sums. Then ∑R(j)aj+∑S(j)aj=∑R(j) or S(j)aj+∑R(j) and S(j)aj.\sum_{R(j)} a_j + \sum_{S(j)} a_j = \sum_{R(j) \text{ or } S(j)} a_j + \sum_{R(j) \text{ and } S(j)} a_j.

Node: TAK6H7XXM8 · Lean: TAOCP.S1_2_3.eq11 · status: proved

Scope. For infinite sums the same holds when three of the four sums are convergent, and then the fourth is too.

Explanation. A term that is in both ranges is counted twice on the left, and the right side counts it once in the union and once in the intersection. A term that is in only one of the ranges is counted once on each side. This is the rule of inclusion and exclusion for two sets, with a weight on each element. It is used when two ranges overlap in one or two indices, as in the next block, or when they do not overlap at all, so that the second sum on the right is empty.

Example. Let aj=ja_j = j, R(j)R(j) be 1≤j≤41 \le j \le 4 and S(j)S(j) be 3≤j≤63 \le j \le 6. The left side is 10+18=2810 + 18 = 28. The union is 1≤j≤61 \le j \le 6 with sum 2121, the intersection is {3,4}\{3, 4\} with sum 77, and 21+7=2821 + 7 = 28.

Proof. Finite case. Let A={j:R(j)}A = \{j : R(j)\} and B={j:S(j)}B = \{j : S(j)\}. Split AA into the disjoint parts A∖BA \setminus B and A∩BA \cap B, and BB into B∖AB \setminus A and A∩BA \cap B. By the fact on finite sums, ∑A=∑A∖B+∑A∩B\sum_A = \sum_{A \setminus B} + \sum_{A \cap B} and ∑B=∑B∖A+∑A∩B\sum_B = \sum_{B \setminus A} + \sum_{A \cap B}. Add: ∑A+∑B=(∑A∖B+∑B∖A+∑A∩B)+∑A∩B=∑A∪B+∑A∩B\sum_A + \sum_B = \bigl(\sum_{A \setminus B} + \sum_{B \setminus A} + \sum_{A \cap B}\bigr) + \sum_{A \cap B} = \sum_{A \cup B} + \sum_{A \cap B}, because A∪BA \cup B is the disjoint union of the three parts. Infinite case: the identity holds for each pair of window sums by the finite case, and the limits of the four window sums exist when three of them do, because the fourth is a combination of the three by the identity. □\square

Example C1.1.2.3.12 (two ranges that share one index, TAOCP eq. 1.2.3(12)). For integers 1≤m≤n1 \le m \le n, ∑1≤j≤maj+∑m≤j≤naj=∑1≤j≤naj+am.\sum_{1 \le j \le m} a_j + \sum_{m \le j \le n} a_j = \sum_{1 \le j \le n} a_j + a_m.

Node: TA745K9V0X · Lean: TAOCP.S1_2_3.eq12 · status: proved

Explanation. This is eq. 1.2.3(11) with R(j)R(j) equal to 1≤j≤m1 \le j \le m and S(j)S(j) equal to m≤j≤nm \le j \le n. The union is 1≤j≤n1 \le j \le n. The intersection is j=mj = m only, so its sum is the single term ama_m. A person who sums the first mm terms and then the terms from mm to nn counts ama_m twice, and the formula takes it away once.

Example. Let aj=2ja_j = 2^j, m=3m = 3 and n=6n = 6. The left side is (2+4+8)+(8+16+32+64)=14+120=134(2 + 4 + 8) + (8 + 16 + 32 + 64) = 14 + 120 = 134. The right side is (2+4+8+16+32+64)+8=126+8=134(2 + 4 + 8 + 16 + 32 + 64) + 8 = 126 + 8 = 134.

Theorem C1.1.2.3.13 (the sum over a triangle of products, TAOCP eq. 1.2.3(13)). For numbers a0,…,ana_0, \ldots, a_n, ∑i=0n∑j=0iaiaj=12((∑i=0nai)2+∑i=0nai2).\sum_{i=0}^n \sum_{j=0}^i a_i a_j = \frac12 \Bigl(\Bigl(\sum_{i=0}^n a_i\Bigr)^2 + \sum_{i=0}^n a_i^2\Bigr).

Node: TAQS8MZ2E4 · Lean: TAOCP.S1_2_3.eq13, TAOCP.S1_2_3.eq13_div · status: proved

Explanation. The left side is the sum of the products aiaja_i a_j for all pairs with j≤ij \le i. The full square sum ∑i∑jaiaj\sum_i \sum_j a_i a_j is the square of the sum, and it has each product with i≠ji \ne j twice (as aiaja_i a_j and as ajaia_j a_i) and each square ai2a_i^2 once. So the triangle (which has each product once, with the diagonal) is half of the square plus half of the diagonal. This is the first example of how the four rules together give a formula. The generalization to three indices is exercise 1.2.3-29.

Example. For n=2n = 2 and (a0,a1,a2)=(1,2,3)(a_0, a_1, a_2) = (1, 2, 3): the triangle has the products a0a0=1a_0 a_0 = 1, a1a0=2a_1 a_0 = 2, a1a1=4a_1 a_1 = 4, a2a0=3a_2 a_0 = 3, a2a1=6a_2 a_1 = 6, a2a2=9a_2 a_2 = 9, with the sum 2525. The right side is 12(62+14)=12⋅50=25\tfrac12 (6^2 + 14) = \tfrac12 \cdot 50 = 25, since ∑ai=6\sum a_i = 6 and ∑ai2=1+4+9=14\sum a_i^2 = 1 + 4 + 9 = 14.

Proof. Let S1=∑0≤j≤i≤naiajS_1 = \sum_{0 \le j \le i \le n} a_i a_j be the triangle sum and S2=∑0≤i≤j≤naiajS_2 = \sum_{0 \le i \le j \le n} a_i a_j. By the rename of eq. 1.2.3(5) (swap the names ii and jj) and the equality ajai=aiaja_j a_i = a_i a_j, S2=S1S_2 = S_1. The square {0≤i,j≤n}\{0 \le i, j \le n\} is the union of the two triangles j≤ij \le i and i≤ji \le j, and their intersection is the diagonal i=ji = j. By eq. 1.2.3(11), S1+S2=∑0≤i,j≤naiaj+∑0≤i≤naiaiS_1 + S_2 = \sum_{0 \le i, j \le n} a_i a_j + \sum_{0 \le i \le n} a_i a_i. The first sum is (∑iai)(∑jaj)\bigl(\sum_i a_i\bigr)\bigl(\sum_j a_j\bigr) by eq. 1.2.3(4), and the second is ∑iai2\sum_i a_i^2. Since S1=S2S_1 = S_2, this gives 2S1=(∑ai)2+∑ai22S_1 = (\sum a_i)^2 + \sum a_i^2. □\square

Theorem C1.1.2.3.14 (the sum of a geometric progression, TAOCP eq. 1.2.3(14)). Let x≠1x \ne 1 and n≥0n \ge 0. Then ∑0≤j≤naxj=a 1−xn+11−x.\sum_{0 \le j \le n} a x^j = a \, \frac{1 - x^{n+1}}{1 - x}.

Node: TA1ZHGJJ22 · Lean: TAOCP.S1_2_3.eq14 · status: proved

Explanation. The terms a,ax,ax2,…a, ax, ax^2, \ldots each get the factor xx from the one before. The derivation of the book does not guess the answer. It writes the sum SS in two ways, one by splitting off the first term and one by pulling out the factor xx and shifting, and it solves the equation for SS. For x=1x = 1 the formula has the form 0/00/0, and the sum is (n+1)a(n + 1)a (exercise 1.2.3-11). The case n=−1n = -1 also works if the sum is empty: the formula gives a(1−x0)/(1−x)=0a(1 - x^0)/(1 - x) = 0 (exercise 1.2.3-9).

Example. For a=3a = 3, x=2x = 2 and n=5n = 5: 3(1+2+4+8+16+32)=3⋅63=1893(1 + 2 + 4 + 8 + 16 + 32) = 3 \cdot 63 = 189, and the formula gives 3(1−64)/(1−2)=3⋅63=1893(1 - 64)/(1 - 2) = 3 \cdot 63 = 189. For a=1a = 1, x=1/7x = 1/7 and n=3n = 3: the sum is 1+1/7+1/49+1/343=400/3431 + 1/7 + 1/49 + 1/343 = 400/343, and the formula gives (1−7−4)/(1−1/7)=(2400/2401)(7/6)=400/343(1 - 7^{-4})/(1 - 1/7) = (2400/2401)(7/6) = 400/343.

Proof. Let S=∑0≤j≤naxjS = \sum_{0 \le j \le n} a x^j. Split off the first term by eq. 1.2.3(11), since the range 0≤j≤n0 \le j \le n is the union of {0}\{0\} and 1≤j≤n1 \le j \le n and they do not overlap: S=a+∑1≤j≤naxjS = a + \sum_{1 \le j \le n} a x^j. In the last sum, pull out xx by eq. 1.2.3(4): ∑1≤j≤naxj=x∑1≤j≤naxj−1\sum_{1 \le j \le n} a x^j = x \sum_{1 \le j \le n} a x^{j-1}. Shift the index by eq. 1.2.3(6) with j→j+1j \to j + 1: ∑1≤j≤naxj−1=∑0≤j≤n−1axj\sum_{1 \le j \le n} a x^{j-1} = \sum_{0 \le j \le n-1} a x^j. This is the sum SS without its last term: ∑0≤j≤n−1axj=S−axn\sum_{0 \le j \le n-1} a x^j = S - a x^n by eq. 1.2.3(11) again. So S=a+x(S−axn)=a+xS−axn+1S = a + x(S - a x^n) = a + xS - a x^{n+1}. Then (1−x)S=a−axn+1(1 - x) S = a - a x^{n+1}, Since x≠1x \ne 1, division by 1−x1 - x gives eq. 1.2.3(14). □\square

A proof by induction, for comparison. For n=0n = 0 both sides are aa. If the formula holds for nn, then the sum to n+1n + 1 is a(1−xn+1)/(1−x)+axn+1=a(1−xn+1+xn+1−xn+2)/(1−x)=a(1−xn+2)/(1−x)a(1 - x^{n+1})/(1 - x) + a x^{n+1} = a(1 - x^{n+1} + x^{n+1} - x^{n+2})/(1 - x) = a(1 - x^{n+2})/(1 - x). This proof checks a formula that a person must already have. The derivation above finds it.

Theorem C1.1.2.3.15 (the sum of an arithmetic progression, TAOCP eq. 1.2.3(15)). For n≥0n \ge 0, ∑0≤j≤n(a+bj)=a(n+1)+12bn(n+1).\sum_{0 \le j \le n} (a + bj) = a(n + 1) + \tfrac12 b n (n + 1).

Node: TA002PWA11 · Lean: TAOCP.S1_2_3.eq15 · status: proved

Explanation. The terms a,a+b,a+2b,…a, a + b, a + 2b, \ldots increase by the same step bb. The first term is aa and the last term is a+bna + bn, so their mean is a+12bna + \tfrac12 bn. The terms are placed symmetrically about this mean, and the sum is n+1n + 1 copies of it. The proof of the book reverses the order of the terms with the reflection j→n−jj \to n - j and adds the sum to itself, so that the terms of the sum cancel their dependence on jj.

Example. For a=5a = 5, b=3b = 3, n=4n = 4 the terms are 5,8,11,14,175, 8, 11, 14, 17 with the sum 5555. The formula gives 5⋅5+12⋅3⋅4⋅5=25+30=555 \cdot 5 + \tfrac12 \cdot 3 \cdot 4 \cdot 5 = 25 + 30 = 55. With a=0a = 0 and b=1b = 1 the formula gives the sum of the first nn integers, 12n(n+1)\tfrac12 n(n+1).

Proof. Let S=∑0≤j≤n(a+bj)S = \sum_{0 \le j \le n} (a + bj). Reflect the index by eq. 1.2.3(5) with p(j)=n−jp(j) = n - j: the relation 0≤n−j≤n0 \le n - j \le n is 0≤j≤n0 \le j \le n, so S=∑0≤j≤n(a+b(n−j))=∑0≤j≤n(a+bn−bj)S = \sum_{0 \le j \le n} (a + b(n - j)) = \sum_{0 \le j \le n} (a + bn - bj). Add this to the original form of SS with eq. 1.2.3(8): 2S=∑0≤j≤n((a+bj)+(a+bn−bj))=∑0≤j≤n(2a+bn)2S = \sum_{0 \le j \le n} \bigl((a + bj) + (a + bn - bj)\bigr) = \sum_{0 \le j \le n} (2a + bn). The terms do not depend on jj, and there are n+1n + 1 of them, so 2S=(n+1)(2a+bn)2S = (n + 1)(2a + bn) and S=(n+1)(a+12bn)=a(n+1)+12bn(n+1)S = (n + 1)(a + \tfrac12 bn) = a(n + 1) + \tfrac12 bn(n + 1). □\square

Definition C1.1.2.3.16 (the bracket of a statement, TAOCP eq. 1.2.3(16)). For a statement PP, the bracket is [P]=1[P] = 1 if PP is true and [P]=0[P] = 0 if PP is false.

Node: TA4DR5SCA3 · Lean: TAOCP.S1_2_3.eq16 · status: proved

Explanation. The bracket turns a logical value into a number, so that it can be added and multiplied. Then [P and Q]=[P][Q][P \text{ and } Q] = [P][Q], [not P]=1−[P][\text{not } P] = 1 - [P], and [P or Q]=[P]+[Q]−[P][Q][P \text{ or } Q] = [P] + [Q] - [P][Q]. The convention is due to K. E. Iverson. In Lean, it is if P then 1 else 0, and Mathlib has the same convention as Set.indicator.

Example. [3<5]=1[3 < 5] = 1 and [3=5]=0[3 = 5] = 0. The number of primes up to 1010 is ∑j=110[j is prime]=4\sum_{j=1}^{10} [j \text{ is prime}] = 4, since the bracket is 11 for j=2,3,5,7j = 2, 3, 5, 7 and 00 for the other six values. The sum ∑j=110[j is even] j=2+4+6+8+10=30\sum_{j=1}^{10} [j \text{ is even}] \, j = 2 + 4 + 6 + 8 + 10 = 30.

Theorem C1.1.2.3.17 (a sum over a relation as a sum over all integers, TAOCP eq. 1.2.3(17)). Let aja_j be defined for each integer jj, and let only finitely many jj satisfy R(j)R(j). Then the sum over R(j)R(j) equals a sum with no relation, in which jj takes every integer value: ∑R(j)aj=∑jaj[R(j)].\sum_{R(j)} a_j = \sum_j a_j [R(j)].

Node: TATAK9SZM9 · Lean: TAOCP.S1_2_3.eq17, TAOCP.S1_2_3.eq17_all · status: proved

Explanation. On the right, a term with R(j)R(j) false is aj⋅0=0a_j \cdot 0 = 0, and a term with R(j)R(j) true is aj⋅1=aja_j \cdot 1 = a_j. So the sum over all integers has only finitely many terms that are not zero, and it is a sum in the sense of the definition. The relation has moved from below the ∑\sum sign into the term, and it can be handled with algebra.

Example. With aj=j2a_j = j^2 and R(j)R(j) equal to 0≤j≤30 \le j \le 3: ∑R(j)aj=0+1+4+9=14\sum_{R(j)} a_j = 0 + 1 + 4 + 9 = 14. In the sum over all integers, the terms with j<0j < 0 or j>3j > 3 are 00 and the others are aja_j, so the total is 1414.

Proof. Split the integers into the set A={j:R(j)}A = \{j : R(j)\} and its complement. On AA the term aj[R(j)]a_j [R(j)] is aja_j. Outside AA it is 00. So the sum over all integers is the sum over AA of aja_j plus a sum of zeros, and a sum of zeros is 00. □\square

Theorem C1.1.2.3.18 (the bracket form of the change of index, TAOCP eq. 1.2.3(18)). Let pp be a function on the integers, and let finitely many integers jj satisfy R(p(j))R(p(j)). Then ∑R(p(j))ap(j)=∑iai [R(i)]∑j[i=p(j)].\sum_{R(p(j))} a_{p(j)} = \sum_i a_i \, [R(i)] \sum_j [i = p(j)].

Node: TADNS4HBGD · Lean: TAOCP.S1_2_3.eq18 · status: proved

Scope. In particular, if pp matches the jj with R(p(j))R(p(j)) one to one with the ii with R(i)R(i), the inner sum is 11 whenever R(i)R(i) holds, and the right side is ∑R(i)ai\sum_{R(i)} a_i.

Explanation. The identity proves eq. 1.2.3(5) from eq. 1.2.3(17) and the interchange of two sums. It also gives the true value of the sum when pp is not a permutation: each value ii is counted as many times as there are jj with p(j)=ip(j) = i. This is the reason for the care that the book asks for in a change of the index.

Example. Take ai=ia_i = i, R(i)R(i) equal to 0≤i≤100 \le i \le 10, and p(j)=j2p(j) = j^2. The left side is ∑0≤j2≤10j2=28\sum_{0 \le j^2 \le 10} j^2 = 28 (the values j=−3,…,3j = -3, \ldots, 3). The inner sum ∑j[i=j2]\sum_j [i = j^2] is 11 for i=0i = 0, is 22 for i=1,4,9i = 1, 4, 9 (since j=±1,±2,±3j = \pm 1, \pm 2, \pm 3), and is 00 for the other ii. So the right side is 0⋅1+(1+4+9)⋅2=280 \cdot 1 + (1 + 4 + 9) \cdot 2 = 28.

Proof. By eq. 1.2.3(17), ∑R(p(j))ap(j)=∑jap(j)[R(p(j))]\sum_{R(p(j))} a_{p(j)} = \sum_j a_{p(j)} [R(p(j))]. For each jj, write ap(j)[R(p(j))]=∑iai[R(i)][i=p(j)]a_{p(j)} [R(p(j))] = \sum_i a_i [R(i)] [i = p(j)]: in the sum over ii only the term with i=p(j)i = p(j) is not zero. This gives a double sum over jj and ii with only finitely many nonzero terms. Interchange the two sums by eq. 1.2.3(7) (valid, since only finitely many terms are nonzero) to get ∑iai[R(i)]∑j[i=p(j)]\sum_i a_i [R(i)] \sum_j [i = p(j)]. □\square

Definition C1.1.2.3.19 (the Kronecker delta, TAOCP eq. 1.2.3(19)). The Kronecker delta of two integers ii and jj is δij=[i=j]\delta_{ij} = [i = j], that is 11 if i=ji = j and 00 if i≠ji \ne j.

Node: TAX4BE9YWF · Lean: TAOCP.S1_2_3.eq19 (partial) · status: proved

Explanation. The delta is the bracket of the equality. Its most useful property is that it picks one term out of a sum: ∑jδijaj=ai\sum_j \delta_{ij} a_j = a_i when the range of jj contains ii, since all the terms except one are zero. It is the entry (i,j)(i, j) of the identity matrix. The notation is due to L. Kronecker (1868), and the general bracket is due to Iverson (1962).

Example. δ33=1\delta_{33} = 1 and δ34=0\delta_{34} = 0. For aj=j2a_j = j^2 and i=4i = 4 with the range 1≤j≤61 \le j \le 6: ∑j=16δ4jj2=16\sum_{j=1}^6 \delta_{4j} j^2 = 16. The sum over jj of δij\delta_{ij} over the whole range is 11 if ii is in the range and 00 if not. The identity matrix of order 33 is the array with δij\delta_{ij} in row ii and column jj, namely 11 on the diagonal and 00 elsewhere.

Definition C1.1.2.3.20 (the product over a relation, TAOCP eq. 1.2.3(20)). For a relation R(j)R(j) that is true for finitely many integers jj, the product ∏R(j)aj\prod_{R(j)} a_j is the product of the numbers aja_j over all jj with R(j)R(j). If no integer satisfies R(j)R(j), the product is 11.

Node: TA1PQTX9YZ · Lean: TAOCP.S1_2_3.eq20 (partial) · status: proved

Explanation. The empty product is 11, not 00, for the same reason that the empty sum is 00: 11 is the neutral element of the multiplication, and with this choice the product of the concatenation of two ranges is still the product of the two products. The rules for sums have the same form for products, with multiplication in the place of addition: the change of the index (eq. 1.2.3(5)), the interchange of two products and the rule for the union and the intersection. For the last rule, ∏Raj⋅∏Saj=∏R or Saj⋅∏R and Saj\prod_{R} a_j \cdot \prod_{S} a_j = \prod_{R \text{ or } S} a_j \cdot \prod_{R \text{ and } S} a_j, and the proof is the proof of eq. 1.2.3(11) with products. For positive terms, the logarithm turns the product into a sum: log⁡b∏R(j)aj=∑R(j)log⁡baj\log_b \prod_{R(j)} a_j = \sum_{R(j)} \log_b a_j (exercise 1.2.3-24), by eq. 1.2.2(11). In Lean, this is Finset.prod.

Example. ∏j=15j=120\prod_{j=1}^5 j = 120. ∏1≤j≤0aj=1\prod_{1 \le j \le 0} a_j = 1. For the product ∏j=2n(1−1/j2)\prod_{j=2}^n (1 - 1/j^2) with n=4n = 4: 34⋅89⋅1516=360576=58\tfrac34 \cdot \tfrac89 \cdot \tfrac{15}{16} = \tfrac{360}{576} = \tfrac58, which is (n+1)/(2n)(n + 1)/(2n) at n=4n = 4. The same formula is the subject of exercise 1.2.3-28.

Theorem C1.1.2.3.21 (the bracket form of the change of the order of two sums, TAOCP eq. 1.2.3(21)). Let R(i)R(i) and S(i,j)S(i, j) be relations, and let S′(j)S'(j) and R′(i,j)R'(i, j) be as in eq. 1.2.3(9). Then, for all integers ii and jj, [R(i)] [S(i,j)]=[R(i) and S(i,j)]=[S′(j)] [R′(i,j)].[R(i)] \, [S(i, j)] = [R(i) \text{ and } S(i, j)] = [S'(j)] \, [R'(i, j)].

Node: TA542PET6X · Lean: TAOCP.S1_2_3.eq21 · status: proved

Explanation. The identity is an equality of numbers that are 00 or 11. It says that "row ii is in the range and the cell is in the row's range" is the same condition as "column jj is in the range and the cell is in the column's range". With it, eq. 1.2.3(9) follows by an interchange over all integers: ∑i∑jaij[R(i)][S(i,j)]=∑j∑iaij[S′(j)][R′(i,j)]\sum_i \sum_j a_{ij} [R(i)] [S(i, j)] = \sum_j \sum_i a_{ij} [S'(j)] [R'(i, j)], where only finitely many terms are nonzero. This is the proof that the book gives for the triangle of eq. 1.2.3(10).

Example. The triangle has R(i)R(i) equal to 1≤i≤n1 \le i \le n and S(i,j)S(i, j) equal to 1≤j≤i1 \le j \le i. Then [1≤i≤n][1≤j≤i]=[1≤j≤i≤n]=[1≤j≤n][j≤i≤n][1 \le i \le n][1 \le j \le i] = [1 \le j \le i \le n] = [1 \le j \le n][j \le i \le n]. A check of this for n=4n = 4 over all pairs −3≤i,j≤7-3 \le i, j \le 7 shows that the two sides are equal for each of the 121121 pairs. For the single pair (i,j)=(3,2)(i, j) = (3, 2) the left side is 1⋅11 \cdot 1 and the right side is 1⋅11 \cdot 1; for (2,3)(2, 3) both are 00.

Proof. The first equality is the rule [P][Q]=[P and Q][P][Q] = [P \text{ and } Q] for brackets: the product is 11 if and only if both factors are 11. For the second, R′(i,j)R'(i, j) is the statement "R(i)R(i) and S(i,j)S(i, j)", so [R′(i,j)]=[R(i) and S(i,j)][R'(i, j)] = [R(i) \text{ and } S(i, j)]. It remains to show [S′(j)][R′(i,j)]=[R′(i,j)][S'(j)][R'(i, j)] = [R'(i, j)]. If R′(i,j)R'(i, j) is false, both sides are 00. If R′(i,j)R'(i, j) is true, then ii is an integer with R(i)R(i) and S(i,j)S(i, j), so S′(j)S'(j) is true, and both sides are 11. □\square

Example C1.1.2.3.22 (a sum over the partitions of an integer, TAOCP eq. 1.2.3(22)). For an integer n≥1n \ge 1, the sum below has one term for each way to write nn as a sum of positive integers in nonincreasing order, with zeros added at the end to make nn numbers: ∑j1+⋯+jn=nj1≥⋯≥jn≥0aj1…jn.\sum_{\substack{j_1 + \cdots + j_n = n \\ j_1 \ge \cdots \ge j_n \ge 0}} a_{j_1 \ldots j_n}.

Node: TAMFDQ9WXX · status: not stated yet

Explanation. The relation under the ∑\sum sign has nn indices, and the sum has one term for each tuple (j1,…,jn)(j_1, \ldots, j_n) that makes the relation true. Here the relation says that the jj are in nonincreasing order, are not negative, and add up to nn. Such a tuple is a partition of nn with the zero parts added. So the number of terms is the number p(n)p(n) of partitions of nn (see Section 1.2.1). The block needs care because the same letter nn is the number of indices and the number to be partitioned. The reader must not read the relation as "each jj is at most nn" and think of nnn^n terms.

Example. For n=4n = 4 the tuples are (4,0,0,0)(4,0,0,0), (3,1,0,0)(3,1,0,0), (2,2,0,0)(2,2,0,0), (2,1,1,0)(2,1,1,0) and (1,1,1,1)(1,1,1,1): five terms, and p(4)=5p(4) = 5. For n=5n = 5 the tuples are (5,0,0,0,0)(5,0,0,0,0), (4,1,0,0,0)(4,1,0,0,0), (3,2,0,0,0)(3,2,0,0,0), (3,1,1,0,0)(3,1,1,0,0), (2,2,1,0,0)(2,2,1,0,0), (2,1,1,1,0)(2,1,1,1,0) and (1,1,1,1,1)(1,1,1,1,1), which are seven terms, and p(5)=7p(5) = 7. For n=6n = 6 there are eleven terms.

Proof that the number of terms is p(n)p(n). A tuple (j1,…,jn)(j_1, \ldots, j_n) with j1≥⋯≥jn≥0j_1 \ge \cdots \ge j_n \ge 0 and sum nn has at most nn positive entries, since each positive entry is at least 11 and the sum is nn. Remove the zero entries to get a partition of nn into positive parts in nonincreasing order. Conversely, a partition of nn has at most nn parts, and adding zeros at the end gives exactly nn entries. The two maps are inverse to each other. □\square

Algorithms and programs

Section 1.2.3 has no algorithm, no program and no cost analysis. The manipulations of sums are the method of the section, and each of them is a block of the previous part.

The exercises

The table has the exercises of Section 1.2.3. The kind is the class of spec 06.3 that C1 proposes, and the Lean column names the solved theorem of tamnd/taocp-lean at main, when one exists. The marker ▶ is the book's mark of a recommended exercise.

Exercise Rating Markers Kind Lean Solution
1.2.3-1 10 ▶ K3 TAOCP.S1_2_3.Ex1.solved X1, 1.2.3-1
1.2.3-2 01 K3 TAOCP.S1_2_3.Ex2.solved X1, 1.2.3-2
1.2.3-3 13 ▶ informal not yet stated X1, 1.2.3-3
1.2.3-4 10 K1 TAOCP.S1_2_3.Ex4.solved X1, 1.2.3-4
1.2.3-5 20 ▶ HM K1 TAOCP.S1_2_3.Ex5.solved X1, 1.2.3-5
1.2.3-6 20 HM K1 TAOCP.S1_2_3.Ex6.solved X1, 1.2.3-6
1.2.3-7 23 HM K1 TAOCP.S1_2_3.Ex7.solved X1, 1.2.3-7
1.2.3-8 25 HM K1 TAOCP.S1_2_3.Ex8.solved X1, 1.2.3-8
1.2.3-9 05 ▶ informal not yet stated X1, 1.2.3-9
1.2.3-10 05 informal not yet stated X1, 1.2.3-10
1.2.3-11 03 K3 TAOCP.S1_2_3.Ex11.solved X1, 1.2.3-11
1.2.3-12 10 K3 TAOCP.S1_2_3.Ex12.solved X1, 1.2.3-12
1.2.3-13 10 K3 TAOCP.S1_2_3.Ex13.solved X1, 1.2.3-13
1.2.3-14 11 K3 TAOCP.S1_2_3.Ex14.solved X1, 1.2.3-14
1.2.3-15 22 ▶ M K3 TAOCP.S1_2_3.Ex15.solved X1, 1.2.3-15
1.2.3-16 22 M K1 TAOCP.S1_2_3.Ex16.solved X1, 1.2.3-16
1.2.3-17 00 ▶ M K3 TAOCP.S1_2_3.Ex17.solved X1, 1.2.3-17
1.2.3-18 20 M informal not yet stated X1, 1.2.3-18
1.2.3-19 20 K3 TAOCP.S1_2_3.Ex19.solved X1, 1.2.3-19
1.2.3-20 25 ▶ K1 TAOCP.S1_2_3.Ex20.solved X1, 1.2.3-20
1.2.3-21 25 ▶ M informal not yet stated X1, 1.2.3-21
1.2.3-22 20 ▶ informal not yet stated X1, 1.2.3-22
1.2.3-23 10 informal not yet stated X1, 1.2.3-23
1.2.3-24 20 K1 TAOCP.S1_2_3.Ex24.solved X1, 1.2.3-24
1.2.3-25 15 ▶ K2 TAOCP.S1_2_3.Ex25.solved X1, 1.2.3-25
1.2.3-26 25 informal not yet stated X1, 1.2.3-26
1.2.3-27 20 M K1 TAOCP.S1_2_3.Ex27.solved X1, 1.2.3-27
1.2.3-28 22 M K3 TAOCP.S1_2_3.Ex28.solved X1, 1.2.3-28
1.2.3-29 30 ▶ M informal not yet stated X1, 1.2.3-29
1.2.3-30 23 ▶ M K1 TAOCP.S1_2_3.Ex30.solved X1, 1.2.3-30
1.2.3-31 20 M K3 TAOCP.S1_2_3.Ex31.solved X1, 1.2.3-31
1.2.3-32 20 M K1 TAOCP.S1_2_3.Ex32.solved X1, 1.2.3-32
1.2.3-33 30 ▶ M K1 TAOCP.S1_2_3.Ex33.solved X1, 1.2.3-33
1.2.3-34 25 M K1 TAOCP.S1_2_3.Ex34.solved X1, 1.2.3-34
1.2.3-35 20 HM informal not yet stated X1, 1.2.3-35
1.2.3-36 23 M K1 TAOCP.S1_2_3.Ex36.solved X1, 1.2.3-36
1.2.3-37 24 ▶ M K1 TAOCP.S1_2_3.Ex37.solved X1, 1.2.3-37
1.2.3-38 25 ▶ M K1 TAOCP.S1_2_3.Ex38.solved X1, 1.2.3-38
1.2.3-39 23 M K1 TAOCP.S1_2_3.Ex39.solved X1, 1.2.3-39
1.2.3-40 24 M informal not yet stated X1, 1.2.3-40
1.2.3-41 26 M informal not yet stated X1, 1.2.3-41
1.2.3-42 18 M K3 TAOCP.S1_2_3.Ex42.solved X1, 1.2.3-42
1.2.3-43 24 M informal not yet stated X1, 1.2.3-43
1.2.3-44 26 ▶ M informal not yet stated X1, 1.2.3-44
1.2.3-45 25 ▶ M informal not yet stated X1, 1.2.3-45
1.2.3-46 30 ▶ M informal not yet stated X1, 1.2.3-46

The order to do them. Start with the exercises of rating 10 or lower, which test the meaning of the notation: the empty range, a range with a bound that is not an integer, and the difference between a change of the index and a change of the relation. Then do the short M-rated exercises on the geometric and arithmetic progressions, which use the manipulation of the section in place of induction. The HM-rated exercises are about infinite sums and need the limits of Section 1.2.2. The exercises with a rating of 25 or more are the harder uses of the rules, and the last ones need the determinant of a matrix as well as the product notation. Do the recommended exercises (marked ▶) first, and leave the rest for a second reading.

Lean

The Lean code of tamnd/taocp-lean at main has the file TAOCP/V1/S1_2_3.lean, in the namespace TAOCP.S1_2_3. It states eqs. (4) to (21) and the product forms of rules (b), (c) and (d). The Node lines name the declarations. Where the Lean statement is weaker, the Node line says "partial".

Not yet stated: the sum with an index from 1 to nn (eq. (1)), the sum over a relation (eq. (2)), the infinite sum (eq. (3)) and the sum over the partitions of an integer (eq. (22)). The infinite sums of eq. (3) have no Lean statement of the rules of the section.

The points where Lean differs from the book are these.

  • The statements sum over a Finset ℤ, and the relation R(j)R(j) of the book becomes the finite set of its solutions. Eq. (9) writes the relation S(i,j)S(i, j) as j ∈ t i. The values are in an additive commutative monoid, a semiring or a field, as each statement needs, and not only in the real numbers.
  • Eq. (5): TAOCP.S1_2_3.eq5 takes a finite set t that p maps one to one onto s. TAOCP.S1_2_3.eq5_book has the condition of the book, that each i in s has exactly one j with p j = i, and it sums over the set of all such j with a finsum.
  • Eq. (10) is stated for natural numbers, so it includes n=0n = 0, which the handbook leaves out.
  • Eq. (13): TAOCP.S1_2_3.eq13 has no division, and says that twice the triangle sum is the square of the sum plus the sum of the squares. TAOCP.S1_2_3.eq13_div has the factor 1/21/2 in a field of characteristic zero, which is the form of the handbook.
  • Eqs. (14) and (15) sum over Finset.range (n + 1) in a field. Eq. (14) has the hypothesis x≠1x \ne 1, as the book does.
  • Eq. (17): TAOCP.S1_2_3.eq17 sums the brackets over the finite set s, and TAOCP.S1_2_3.eq17_all sums over all integers, as the book does.
  • Eq. (18) in Lean needs no condition on pp. It holds for each finite set of indices, and it gives eq. (5) when pp takes each value of s once.
  • Eq. (19) is stated by its main use, a sum against δij\delta_{ij} picks out one term. It is not a definition of δij\delta_{ij}. The bracket is TAOCP.iverson.
  • Eq. (20) states only that the empty product is 11. It does not define the product over a relation.
  • The Lean file has also TAOCP.S1_2_3.example1, which splits a sum into the even and the odd indices, and the products of rules (b), (c) and (d): TAOCP.S1_2_3.eq5_prod, TAOCP.S1_2_3.eq7_prod and TAOCP.S1_2_3.eq11_prod.

A sum of Mathlib is Finset.sum, and tsum is the sum of an infinite series. Mathlib's tsum is defined by unconditional convergence. It agrees with the book's sum, defined with the order of the index, exactly for absolutely convergent series. For a series that converges but not absolutely, HasSum can be false while the book's sum exists. A faithful Lean statement of a rule of this section for an infinite series needs Summable of the absolute values, or a direct definition of the limit of eq. (3).

The exercises of the table with a name in the Lean column have statements in TAOCP/Problems/S1_2_3/ and solutions in TAOCP/Solutions/S1_2_3/. The name in the table is the theorem solved of the solution file. The other exercises are not yet stated.

Notes and history

The notation ∑\sum for a sum is due to Leonhard Euler (1755). The notation with limits above and below the sign was introduced by J. Fourier (1820). The convention that a relation can stand under the sign, with no limit above, is common in the work of the author of the book on the analysis of algorithms, and it is the form that makes eqs. 1.2.3(9) and 1.2.3(11) usable. The bracket [P][P] was proposed by K. E. Iverson in 1962 in a notation for programming, and the bracket form was spread by the book on concrete mathematics. The Kronecker delta is from 1868. A history and a defense of the bracket notation is in the article of D. E. Knuth in the American Mathematical Monthly, volume 99 (1992), pages 403 to 422.

The warnings about infinite sums are theorems of analysis. The independence of the sum from the order of the terms, for absolutely convergent series, is due to P. G. L. Dirichlet (1837), and B. Riemann (1854) proved that a conditionally convergent series can be rearranged to have any sum. The interchange of the order of summation for double series with absolutely convergent terms is the theorem often called after Fubini (for the integral) and after Tonelli (for nonnegative terms). The reference in the book for the infinite case is a textbook of analysis of the time, and any modern analysis text proves the same results.

The identity of Binet of exercise 1.2.3-30 was found by J. Binet in 1812 and has the inequality of Cauchy and Schwarz as a consequence. The matrices of the last exercises are classical. The determinants of the Vandermonde and of the Cauchy matrix are in many books on linear algebra, and the Hilbert matrix of exercise 1.2.3-45 is used as a test for the numerical methods that invert a matrix.

The project has no errata of Section 1.2.3 to report.

Section 1.2.3 of TAOCP gives the notation for sums and products that the rest of the book uses in each analysis. It defines the sum over all integers that satisfy a relation, states four rules for changing a sum (distributing, changing the index, interchanging two sums and splitting the domain), and shows how to derive the sum of a geometric and of an arithmetic progression with these rules and not by induction. It adds the bracket notation of Iverson, the Kronecker delta and the product notation. This chapter of C1 explains each item of the section, proves each rule in full for finite sums, states exactly when the rules hold for infinite sums, and checks the examples by computation.

The source of this page. Something is wrong? Report it.