taocp

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

Volume P2 · Concrete mathematics

Sums and their manipulation

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.

Contents
  1. The notation for sums and products
  2. The laws of sums
  3. Multiple sums

The notation for sums and products

Statement

A sum is a short way to write a1+a2+⋯+ana_1 + a_2 + \cdots + a_n with no dots. The dots hide a rule, and a reader can read the rule in more than one way. This section gives the rule in a form that has one meaning. The terms aja_j are numbers: integers, rationals, reals or complex numbers. All the results hold in every commutative ring, and the reader can keep that case in mind.

Definition P2.1.1 (sum with limits). Let mm and nn be integers and let am,am+1,…a_m, a_{m+1}, \dots be numbers. The sum ∑k=mnak\sum_{k=m}^{n} a_k is 00 when n<mn < m, and it is (∑k=mn−1ak)+an\bigl(\sum_{k=m}^{n-1} a_k\bigr) + a_n when n≥mn \ge m. The letter kk is the index of summation, mm is the lower limit and nn is the upper limit. Another form of the same sum is ∑m≤k≤nak\sum_{m \le k \le n} a_k. The index is a bound variable: ∑k=mnak\sum_{k=m}^{n} a_k and ∑j=mnaj\sum_{j=m}^{n} a_j are the same number.

Lean: Mathlib Finset.sum over Finset.Icc m n, or over Finset.range n for the limits 00 and n−1n - 1; the recursive step is Finset.sum_range_succ (proved in Mathlib).

Example P2.1.2. The definition gives ∑k=14k2=1+4+9+16=30\sum_{k=1}^{4} k^2 = 1 + 4 + 9 + 16 = 30 and ∑k=03(2k+1)=1+3+5+7=16\sum_{k=0}^{3} (2k + 1) = 1 + 3 + 5 + 7 = 16. The index does not occur in the value. A formula such as ∑k=1nk2\sum_{k=1}^{n} k^2 is a function of nn only.

Example P2.1.3. The sum ∑k=53ak\sum_{k=5}^{3} a_k has its upper limit below its lower limit, so its value is 00. It is not −a4-a_4, and it is not a3+a4+a5a_3 + a_4 + a_5. For each n≥0n \ge 0 the definition gives ∑k=1n1=n\sum_{k=1}^{n} 1 = n; for n=0n = 0 the sum is empty and the value is 00, which agrees.

Definition P2.1.4 (sum over a relation). Let R(j)R(j) be a relation on the integers that is true for a finite set FF of integers, and let aja_j be a number for each j∈Fj \in F. Write the elements of FF in a list j1,j2,…,jNj_1, j_2, \dots, j_N, each element once. The sum ∑R(j)aj\sum_{R(j)} a_j is ∑t=1Najt\sum_{t=1}^{N} a_{j_t}. When FF is empty the sum is 00, the empty sum. The lemma below shows that the value does not depend on the order of the list. The same definition applies to a relation on any set, for example on pairs of integers.

Lean: Mathlib Finset.sum over the Finset Finset.filter R s of a finite set s; the empty sum is Finset.sum_empty (proved in Mathlib).

Example P2.1.5. The sum ∑p prime, p<20p\sum_{p \text{ prime},\, p < 20} p is 2+3+5+7+11+13+17+19=772 + 3 + 5 + 7 + 11 + 13 + 17 + 19 = 77. Here R(p)R(p) is the relation "pp is prime and p<20p < 20". The sum ∑d∣12d\sum_{d \mid 12} d, over the positive divisors of 1212, is 1+2+3+4+6+12=281 + 2 + 3 + 4 + 6 + 12 = 28.

Example P2.1.6. The relation m≤j≤nm \le j \le n gives back the sum with limits: ∑m≤j≤naj=∑j=mnaj\sum_{m \le j \le n} a_j = \sum_{j=m}^{n} a_j. The relation j2=2j^2 = 2 is true for no integer, so ∑j2=2aj=0\sum_{j^2 = 2} a_j = 0 for every family aja_j.

Lemma P2.1.7 (order of the terms). Let FF be a finite set with NN elements and let axa_x be a number for each x∈Fx \in F. Let x1,…,xNx_1, \dots, x_N and y1,…,yNy_1, \dots, y_N be two lists that each contain every element of FF once. Then ax1+⋯+axN=ay1+⋯+ayNa_{x_1} + \cdots + a_{x_N} = a_{y_1} + \cdots + a_{y_N}.

Lean: Mathlib defines Finset.sum through Multiset, so the independence of the order is part of the definition; Finset.sum_list_count and List.Perm.sum_eq state forms of it (proved in Mathlib).

Proof. Use induction on NN. For N=0N = 0 both lists are empty and both sums are 00. Let N≥1N \ge 1. The element yNy_N is xix_i for one index ii. By the associative and commutative laws for two terms, ax1+⋯+axN=(ax1+⋯+axi−1+axi+1+⋯+axN)+axia_{x_1} + \cdots + a_{x_N} = (a_{x_1} + \cdots + a_{x_{i-1}} + a_{x_{i+1}} + \cdots + a_{x_N}) + a_{x_i}. The list x1,…,xi−1,xi+1,…,xNx_1, \dots, x_{i-1}, x_{i+1}, \dots, x_N and the list y1,…,yN−1y_1, \dots, y_{N-1} each contain every element of F∖{yN}F \setminus \{y_N\} once. This set has N−1N - 1 elements, so the induction hypothesis says that their sums are equal. So ax1+⋯+axN=(ay1+⋯+ayN−1)+ayNa_{x_1} + \cdots + a_{x_N} = (a_{y_1} + \cdots + a_{y_{N-1}}) + a_{y_N}, which is the claim. □\square

Definition P2.1.8 (Iverson bracket). Let PP be a statement that is true or false. The Iverson bracket [P][P] is 11 when PP is true and 00 when PP is false. A term aj[R(j)]a_j [R(j)] is aja_j when R(j)R(j) is true and 00 when it is false, also when aja_j has no value; the bracket is a "strong zero".

Lean: TAOCP.iverson in TAOCP/Notation (tamnd/taocp-lean main), defined as if P then 1 else 0, with TAOCP.iverson_true and TAOCP.iverson_false; Mathlib has Finset.sum_boole for the sum of such terms (proved in Mathlib).

Example P2.1.9. [7 is prime]=1[7 \text{ is prime}] = 1, [6 is prime]=0[6 \text{ is prime}] = 0 and [k is even]+[k is odd]=1[k \text{ is even}] + [k \text{ is odd}] = 1 for each integer kk. The number of primes up to 2020 is ∑k=120[k is prime]=8\sum_{k=1}^{20} [k \text{ is prime}] = 8.

Example P2.1.10. The sum ∑k=110[k is odd] k\sum_{k=1}^{10} [k \text{ is odd}]\, k is 1+3+5+7+9=251 + 3 + 5 + 7 + 9 = 25. The bracket chooses the terms, and the sum runs over a simple range. The term [k≠0]/k[k \ne 0] / k is defined for all integers kk: it is 1/k1/k for k≠0k \ne 0 and 00 for k=0k = 0.

Definition P2.1.11 (Kronecker delta). For integers ii and jj, the Kronecker delta is δij=[i=j]\delta_{ij} = [i = j]. So δij=1\delta_{ij} = 1 when i=ji = j and δij=0\delta_{ij} = 0 when i≠ji \ne j, and δij=δji\delta_{ij} = \delta_{ji}.

Lean: Mathlib writes if i = j then 1 else 0, and Pi.single and Finsupp.single for the family j↦δijj \mapsto \delta_{ij}; Finset.sum_ite_eq evaluates ∑jδijaj\sum_j \delta_{ij} a_j (proved in Mathlib).

Example P2.1.12. For each integer ii the family j↦δijajj \mapsto \delta_{ij} a_j has one term that can be nonzero, the term with j=ij = i. So ∑jδijaj=ai\sum_{j} \delta_{ij} a_j = a_i, where the sum is over all integers in the sense of the definition of finite support below.

Example P2.1.13. The n×nn \times n identity matrix is the matrix with entries δij\delta_{ij} for 1≤i,j≤n1 \le i, j \le n. Its trace is ∑i=1nδii=n\sum_{i=1}^{n} \delta_{ii} = n. The product of two matrices AA and BB has the entries ∑k=1naikbkj\sum_{k=1}^{n} a_{ik} b_{kj}, and with BB the identity this sum is ∑kaikδkj=aij\sum_{k} a_{ik} \delta_{kj} = a_{ij}.

Proposition P2.1.14 (algebra of brackets). For statements PP and QQ:

  1. [P and Q]=[P][Q][P \text{ and } Q] = [P][Q];
  2. [not P]=1−[P][\text{not } P] = 1 - [P];
  3. [P or Q]=[P]+[Q]−[P][Q][P \text{ or } Q] = [P] + [Q] - [P][Q];
  4. [P]2=[P][P]^2 = [P];
  5. if PP and QQ are never both true, then [P or Q]=[P]+[Q][P \text{ or } Q] = [P] + [Q].

Lean: rule 1 is TAOCP.iverson_mul_iverson in TAOCP/Notation (tamnd/taocp-lean main); rules 2 to 5 are not yet stated, and for if then else the four cases are closed by split_ifs and simp.

Proof. Each side of each equation depends only on the truth values of PP and QQ, so it is enough to check the four cases. If PP and QQ are both true, then rule 1 reads 1=1⋅11 = 1 \cdot 1, rule 3 reads 1=1+1−11 = 1 + 1 - 1, and rule 2 reads 0=1−10 = 1 - 1. If PP is true and QQ is false, rule 1 reads 0=1⋅00 = 1 \cdot 0 and rule 3 reads 1=1+0−01 = 1 + 0 - 0. The case with PP false and QQ true is the same with the roles exchanged. If both are false, rule 1 reads 0=00 = 0, rule 2 reads 1=1−01 = 1 - 0 and rule 3 reads 0=00 = 0. Rule 4 holds because 02=00^2 = 0 and 12=11^2 = 1. Rule 5 is rule 3 with [P][Q]=[P and Q]=0[P][Q] = [P \text{ and } Q] = 0. □\square

Definition P2.1.15 (sum with finite support). Let aja_j be a number for each integer jj and let R(j)R(j) be a relation. Suppose that only finitely many integers jj have R(j)R(j) true and aj≠0a_j \ne 0. Then ∑R(j)aj\sum_{R(j)} a_j is the sum of aja_j over this finite set. The family has finite support on RR. When R(j)R(j) is true for all jj the sum is written ∑jaj\sum_{j} a_j. When R(j)R(j) is true for only finitely many jj, the new sum equals the sum of the definition above, since the terms that are left out are 00.

Lean: Mathlib finsum, written ∑ᶠ j, a j, with the hypothesis that Function.support a is finite; or Finset.sum over an explicit Finset that contains the support (Finset.sum_subset moves between the two, proved in Mathlib).

Example P2.1.16. A polynomial p(x)=∑jcjxjp(x) = \sum_{j} c_j x^j has coefficients cjc_j for all integers jj, with cj=0c_j = 0 for j<0j < 0 and for jj above the degree. For (1+x)3=1+3x+3x2+x3(1 + x)^3 = 1 + 3x + 3x^2 + x^3 the coefficients are 1,3,3,11, 3, 3, 1 at j=0,1,2,3j = 0, 1, 2, 3, and ∑jcj=p(1)=8\sum_j c_j = p(1) = 8. The sum over all integers has finite support.

Example P2.1.17. The relation j≥0j \ge 0 is true for infinitely many jj, but the family aj=[j∣6] ja_j = [j \mid 6]\, j is 00 for j≥0j \ge 0 outside the set {1,2,3,6}\{1, 2, 3, 6\}. So ∑j≥0[j∣6] j=1+2+3+6=12\sum_{j \ge 0} [j \mid 6]\, j = 1 + 2 + 3 + 6 = 12. The convention [0∣6]=0[0 \mid 6] = 0 holds since 66 is not a multiple of 00.

Definition P2.1.18 (product). Let R(j)R(j) be a relation and aja_j numbers, and suppose that only finitely many jj with R(j)R(j) have aj≠1a_j \ne 1. The product ∏R(j)aj\prod_{R(j)} a_j is the product of aja_j over this finite set, in any order. The product over an empty set is 11, the empty product. With limits, ∏k=mnak\prod_{k=m}^{n} a_k is 11 for n<mn < m and (∏k=mn−1ak)an\bigl(\prod_{k=m}^{n-1} a_k\bigr) a_n for n≥mn \ge m. The lemma on the order of the terms holds for products with the same proof.

Lean: Mathlib Finset.prod, finprod (written ∏ᶠ), Finset.prod_empty and Finset.prod_range_succ (proved in Mathlib).

Example P2.1.19. The factorial is n!=∏k=1nkn! = \prod_{k=1}^{n} k. The empty product gives 0!=10! = 1, and the recursive step gives n!=(n−1)! nn! = (n - 1)!\, n for n≥1n \ge 1. Section 2.1 uses these facts. The product of the positive divisors of 1212 is ∏d∣12d=1⋅2⋅3⋅4⋅6⋅12=1728=123\prod_{d \mid 12} d = 1 \cdot 2 \cdot 3 \cdot 4 \cdot 6 \cdot 12 = 1728 = 12^3.

Example P2.1.20. For n≥0n \ge 0, ∏k=1n(1+1/k)=n+1\prod_{k=1}^{n} (1 + 1/k) = n + 1. The factor 1+1/k1 + 1/k is (k+1)/k(k + 1)/k. For n=0n = 0 the product is empty and equals 11. If the claim holds for n−1n - 1, then the product for nn is n⋅(n+1)/n=n+1n \cdot (n + 1)/n = n + 1.

Proposition P2.1.21 (disjoint relations). Let RR and SS be relations that are never both true and that are each true for finitely many integers. Then ∑R(j) or S(j)aj=∑R(j)aj+∑S(j)aj\sum_{R(j) \text{ or } S(j)} a_j = \sum_{R(j)} a_j + \sum_{S(j)} a_j and ∏R(j) or S(j)aj=∏R(j)aj∏S(j)aj\prod_{R(j) \text{ or } S(j)} a_j = \prod_{R(j)} a_j \prod_{S(j)} a_j. The value 00 for the empty sum is the only value that keeps the first rule true when SS is false for all jj, and the value 11 for the empty product is the only value that keeps the second rule true when the terms are nonzero.

Lean: Mathlib Finset.sum_union and Finset.prod_union, with a disjointness hypothesis (proved in Mathlib).

Proof. Let FF and GG be the finite sets where RR and SS are true. They are disjoint. Write FF as a list x1,…,xMx_1, \dots, x_M and GG as a list y1,…,yNy_1, \dots, y_N. The list x1,…,xM,y1,…,yNx_1, \dots, x_M, y_1, \dots, y_N contains every element of F∪GF \cup G once. By the associative law its sum is (ax1+⋯+axM)+(ay1+⋯+ayN)(a_{x_1} + \cdots + a_{x_M}) + (a_{y_1} + \cdots + a_{y_N}), and by the lemma on the order of the terms this is the sum over F∪GF \cup G. The same argument works for products. Now let SS be false for all jj and let ee be the value of the empty sum. The rule reads ∑R(j)aj=∑R(j)aj+e\sum_{R(j)} a_j = \sum_{R(j)} a_j + e, so e=0e = 0. For products, let ee be the value of the empty product, let RR be true at one integer jj only, with aj≠0a_j \ne 0, and let SS be false for all integers. The rule reads aj=ajea_j = a_j e, and division by aja_j gives e=1e = 1. □\square

Definition P2.1.22 (infinite sum). Let R(j)R(j) be a relation and aja_j numbers such that infinitely many jj have R(j)R(j) true and aj≠0a_j \ne 0. Split the indices at 00. The sum ∑R(j)aj\sum_{R(j)} a_j is the number lim⁡n→∞∑R(j), 0≤j<naj  +  lim⁡n→∞∑R(j), −n≤j<0aj,\lim_{n \to \infty} \sum_{R(j),\ 0 \le j < n} a_j \; + \; \lim_{n \to \infty} \sum_{R(j),\ -n \le j < 0} a_j, when both limits exist and are finite. When one of them does not exist, the sum has no value. Each sum inside a limit is a finite sum of the earlier definitions.

Lean: Mathlib tsum (written ∑'), HasSum and Summable, which use all finite subsums and so agree with this definition only when the terms are absolutely summable; P5 makes the comparison precise.

Example P2.1.23. For n≥1n \ge 1, ∑0≤k<n2−k=2−21−n\sum_{0 \le k < n} 2^{-k} = 2 - 2^{1-n}. This holds for n=1n = 1, where both sides are 11, and the step from nn to n+1n + 1 adds 2−n2^{-n} to both sides, since 2−21−n+2−n=2−2−n2 - 2^{1-n} + 2^{-n} = 2 - 2^{-n}. The limit is 22, so ∑k≥02−k=2\sum_{k \ge 0} 2^{-k} = 2; the negative part is empty. For the family 2−∣j∣2^{-|j|} over all integers, the negative part is ∑1≤k≤n2−k=1−2−n\sum_{1 \le k \le n} 2^{-k} = 1 - 2^{-n}, with limit 11. So ∑j2−∣j∣=3\sum_{j} 2^{-|j|} = 3.

Example P2.1.24. The sum ∑k≥0(−1)k\sum_{k \ge 0} (-1)^k has no value. Its partial sums are 1,0,1,0,…1, 0, 1, 0, \dots, and this sequence has no limit. A grouping of the terms as (1−1)+(1−1)+⋯(1 - 1) + (1 - 1) + \cdots suggests 00, and a grouping as 1+(−1+1)+⋯1 + (-1 + 1) + \cdots suggests 11. The definition refuses both, and P5 explains when a grouping is safe.

Proposition P2.1.25 (sums of nonnegative terms). Let aj≥0a_j \ge 0 for all jj with R(j)R(j). Then ∑R(j)aj\sum_{R(j)} a_j has a value if and only if the finite subsums ∑j∈Faj\sum_{j \in F} a_j, over finite sets FF of integers with R(j)R(j) true, are bounded. In that case the value is the least upper bound of the finite subsums. So for every bijection pp from the set where SS is true onto the set where RR is true, ∑S(i)ap(i)=∑R(j)aj\sum_{S(i)} a_{p(i)} = \sum_{R(j)} a_j, with one side defined when the other is.

Lean: Mathlib hasSum_iff_tendsto_nat_of_nonneg and summable_of_sum_le give forms of this for nonnegative real terms (proved in Mathlib); Equiv.tsum_eq is the change of variable.

Proof. Let Pn=∑R(j), 0≤j<najP_n = \sum_{R(j),\, 0 \le j < n} a_j and Qn=∑R(j), −n≤j<0ajQ_n = \sum_{R(j),\, -n \le j < 0} a_j. Since the terms are nonnegative, both sequences are nondecreasing. A nondecreasing sequence of reals has a finite limit if and only if it is bounded, and then the limit is its least upper bound. Each finite set FF lies in the interval −n≤j<n-n \le j < n for some nn, so ∑j∈Faj≤Pn+Qn\sum_{j \in F} a_j \le P_n + Q_n. Each Pn+QnP_n + Q_n is itself a finite subsum. So the finite subsums are bounded exactly when Pn+QnP_n + Q_n is bounded, that is, when both PnP_n and QnQ_n are bounded. Then the least upper bound of the finite subsums is lim⁡(Pn+Qn)=lim⁡Pn+lim⁡Qn\lim (P_n + Q_n) = \lim P_n + \lim Q_n. For the last claim, pp maps the finite subsets where SS is true one to one onto the finite subsets where RR is true, and it keeps the value of each finite subsum. So the two sets of finite subsums are the same, with the same least upper bound. □\square

Proof

The proofs of this section reduce each claim to a finite sum over a finite set. The lemma on the order of the terms does the main work. It makes the sum over a relation well defined, and every later law of Section 1.2 uses it. Its proof is an induction on the number of terms that moves one term to the end of the list.

The bracket turns a statement into a number. The rules for brackets follow from a check of the four cases of two truth values. This check is short, and it is complete, since a bracket expression depends only on the truth values of its statements.

The infinite sum is a limit of finite sums. For nonnegative terms the order of the terms does not matter, by the proposition on sums of nonnegative terms. For terms of both signs the order can matter, and P5 gives the theory of absolute convergence that decides when it does.

Examples

Example P2.1.26 (counting with brackets). The number of integers kk with 1≤k≤1001 \le k \le 100 that are divisible by 22 or by 33 is ∑k=1100[2∣k or 3∣k]\sum_{k=1}^{100} [2 \mid k \text{ or } 3 \mid k]. Rule 3 of the algebra of brackets and rule 1 with [2∣k][3∣k]=[6∣k][2 \mid k][3 \mid k] = [6 \mid k] give ∑k=1100[2∣k]+∑k=1100[3∣k]−∑k=1100[6∣k]=50+33−16=67.\sum_{k=1}^{100} [2 \mid k] + \sum_{k=1}^{100} [3 \mid k] - \sum_{k=1}^{100} [6 \mid k] = 50 + 33 - 16 = 67. A direct count by computer gives 6767 too.

Example P2.1.27 (divisors). The number of positive divisors of n≥1n \ge 1 is ∑d∣n1=∑k=1n[k∣n]\sum_{d \mid n} 1 = \sum_{k=1}^{n} [k \mid n]. The second form has limits, and the bracket keeps the divisors. For n=12n = 12 the bracket is 11 at k=1,2,3,4,6,12k = 1, 2, 3, 4, 6, 12 and the sum is 66. The sum of the divisors is ∑k=1nk[k∣n]\sum_{k=1}^{n} k [k \mid n], which is 2828 for n=12n = 12.

Example P2.1.28 (a sum over all integers). The family aj=[j2≤10](10−j2)a_j = [j^2 \le 10] (10 - j^2) has finite support: the bracket is 11 only for −3≤j≤3-3 \le j \le 3. So ∑jaj=1+6+9+10+9+6+1=42\sum_j a_j = 1 + 6 + 9 + 10 + 9 + 6 + 1 = 42. The bracket gives a clear meaning to the sum over all integers, and it is not needed to state the range of jj in the sum sign.

Example P2.1.29 (an index that is not an integer). The relation can run over any set. Let R(A)R(A) be "AA is a subset of {1,2,3}\{1, 2, 3\}". Then ∑R(A)∣A∣=0+1+1+1+2+2+2+3=12\sum_{R(A)} |A| = 0 + 1 + 1 + 1 + 2 + 2 + 2 + 3 = 12, a sum of eight terms, one for each subset. The lemma on the order of the terms makes this sum well defined although the subsets have no natural order.

Exercises

  1. [10] Compute ∑k=−23k2\sum_{k=-2}^{3} k^2, ∑k=42k2\sum_{k=4}^{2} k^2 and ∏k=42k\prod_{k=4}^{2} k.
  2. [15] Compute ∑k=130[k is odd or 5∣k] k\sum_{k=1}^{30} [k \text{ is odd or } 5 \mid k]\, k with the algebra of brackets.
  3. [M15] Prove that ([P]−[Q])2=[exactly one of P and Q is true]([P] - [Q])^2 = [\text{exactly one of } P \text{ and } Q \text{ is true}].
  4. [M18] Write ∑d∣36d\sum_{d \mid 36} d as a sum with limits and a bracket, and compute it.
  5. [M20] Decide which of the families aj=[j2≤50] j3a_j = [j^2 \le 50]\, j^3, bj=[j≥0] 2−jb_j = [j \ge 0]\, 2^{-j} and cj=[∣j∣≤3](j2−1)c_j = [|j| \le 3] (j^2 - 1), over all integers jj, have finite support, and compute ∑jaj\sum_j a_j and ∑jcj\sum_j c_j.
  6. [M20] Let c>0c > 0 and let R(j)R(j) be true for finitely many jj. Prove that ∏R(j)caj=c∑R(j)aj\prod_{R(j)} c^{a_j} = c^{\sum_{R(j)} a_j}, and use ∑k=1nk=n(n+1)/2\sum_{k=1}^{n} k = n(n+1)/2 to find ∏k=1n2k\prod_{k=1}^{n} 2^k.
  7. [M20] Prove that ∑i=1n∑j=1nδi,j+1=n−1\sum_{i=1}^{n} \sum_{j=1}^{n} \delta_{i,j+1} = n - 1 for n≥1n \ge 1, and that ∑i=1n∑j=1nδijaibj=∑i=1naibi\sum_{i=1}^{n} \sum_{j=1}^{n} \delta_{ij} a_i b_j = \sum_{i=1}^{n} a_i b_i.
  8. [M22] Prove that ∑0≤k<n3−k=32(1−3−n)\sum_{0 \le k < n} 3^{-k} = \tfrac{3}{2} (1 - 3^{-n}) for n≥0n \ge 0, and find ∑j3−∣j∣\sum_j 3^{-|j|} over all integers jj.
  9. [HM26] Let aj=1/ja_j = 1/j for j≠0j \ne 0 and a0=0a_0 = 0. Show that ∑−n≤j≤naj=0\sum_{-n \le j \le n} a_j = 0 for every nn, but that ∑jaj\sum_j a_j has no value in the sense of the definition of the infinite sum.

Lean

The finite sum of this section is Mathlib Finset.sum, written ∑ i ∈ s, f i, and the finite product is Finset.prod. The sum with limits ∑k=0n−1ak\sum_{k=0}^{n-1} a_k is ∑ k ∈ Finset.range n, a k, and ∑k=mnak\sum_{k=m}^{n} a_k is a sum over Finset.Icc m n. The recursive step of the definition is Finset.sum_range_succ, and the empty sum and product are Finset.sum_empty and Finset.prod_empty.

A sum over a relation becomes a sum over Finset.filter, and Finset.sum_filter turns it into a sum with if then else, which is the Iverson bracket. The project defines the bracket as TAOCP.iverson P, which is if P then 1 else 0, in TAOCP/Notation of tamnd/taocp-lean (spec 06.1), with the lemmas TAOCP.iverson_true, TAOCP.iverson_false and TAOCP.iverson_mul_iverson. A sum with finite support over all integers is Mathlib finsum, which takes the value 00 when the support is infinite, so a statement about it carries the hypothesis that the support is finite.

The infinite sum is Mathlib tsum, with the predicates HasSum and Summable. Mathlib's definition uses the limit over all finite subsets, so it gives a value only to sums that converge without regard to order. The definition of this section, with two limits of partial sums, agrees with it for nonnegative terms and, more generally, for absolutely convergent sums. P5 states the comparison.

Notes and history

Euler used the letter Σ\Sigma for sums in the eighteenth century, and Fourier put the limits of the index below and above the sign in the 1820s. TAOCP Section 1.2.3 introduces the notation with limits as eq. 1.2.3(1) and the sum over a relation as eq. 1.2.3(2), and it treats the infinite sum as two limits in eq. 1.2.3(3). The bracket notation is eq. 1.2.3(16) and the Kronecker delta is eq. 1.2.3(19).

Kenneth Iverson used a bracket for the truth value of a statement in his language APL in 1962. Knuth made the bracket a standard tool of discrete mathematics in a paper on notation in 1992, and the spine text GKP94 uses it from Chapter 2 on. The Kronecker delta is named after Leopold Kronecker, who used it in the theory of determinants.

The infinite sum returns in P5, with absolute convergence, the interchange of limits and the asymptotic methods of TAOCP Section 1.2.11. The proposition on nonnegative terms is the part of that theory that the next sections need.

The laws of sums

Statement

This section proves the rules that change one sum into another. Each rule is a fact about finite sums, and each proof reduces to the laws of addition and multiplication for two terms. The relations RR, SS below are true for finitely many integers, or the families have finite support in the sense of Section 1.1, so all sums are finite.

Theorem P2.1.30 (distributive law). For a number cc, c∑R(i)ai=∑R(i)c aic \sum_{R(i)} a_i = \sum_{R(i)} c\, a_i. For two families, (∑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).

Lean: Mathlib Finset.mul_sum, Finset.sum_mul and Finset.sum_mul_sum (proved in Mathlib).

Proof. Let FF be the finite set where RR is true, and use induction on its size NN. For N=0N = 0 both sides of the first claim are 00, since c⋅0=0c \cdot 0 = 0. For N≥1N \ge 1 take one element xx of FF. By the proposition on disjoint relations in Section 1.1, ∑Fai=∑F∖{x}ai+ax\sum_{F} a_i = \sum_{F \setminus \{x\}} a_i + a_x. So c∑Fai=c∑F∖{x}ai+c axc \sum_F a_i = c \sum_{F \setminus \{x\}} a_i + c\, a_x by the distributive law for two terms, and the induction hypothesis turns the first term into ∑F∖{x}c ai\sum_{F \setminus \{x\}} c\, a_i. The sum of the two terms is ∑Fc ai\sum_F c\, a_i. For the second claim let B=∑S(j)bjB = \sum_{S(j)} b_j. The first claim, used twice, gives (∑R(i)ai)B=∑R(i)aiB=∑R(i)∑S(j)aibj\bigl(\sum_{R(i)} a_i\bigr) B = \sum_{R(i)} a_i B = \sum_{R(i)} \sum_{S(j)} a_i b_j. □\square

Theorem P2.1.31 (sum of two families). ∑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.

Lean: Mathlib Finset.sum_add_distrib (proved in Mathlib).

Proof. Use induction on the size NN of the set FF where RR is true. For N=0N = 0 all three sums are 00. For N≥1N \ge 1 take x∈Fx \in F and let G=F∖{x}G = F \setminus \{x\}. Then ∑F(bi+ci)=∑G(bi+ci)+(bx+cx)\sum_F (b_i + c_i) = \sum_G (b_i + c_i) + (b_x + c_x). By the induction hypothesis this is ∑Gbi+∑Gci+bx+cx\sum_G b_i + \sum_G c_i + b_x + c_x. The laws of addition for two terms reorder this as (∑Gbi+bx)+(∑Gci+cx)=∑Fbi+∑Fci\bigl(\sum_G b_i + b_x\bigr) + \bigl(\sum_G c_i + c_x\bigr) = \sum_F b_i + \sum_F c_i. □\square

Theorem P2.1.32 (change of variable). Let pp be a bijection from the set of integers jj with S(j)S(j) true onto the set of integers ii with R(i)R(i) true. Then ∑R(i)ai=∑S(j)ap(j).\sum_{R(i)} a_i = \sum_{S(j)} a_{p(j)}.

Lean: Mathlib Finset.sum_nbij' (with an explicit inverse), Finset.sum_bij' and Finset.sum_equiv (proved in Mathlib).

Proof. Let j1,…,jNj_1, \dots, j_N list the set where SS is true, each element once. Since pp is a bijection, the list p(j1),…,p(jN)p(j_1), \dots, p(j_N) contains every integer ii with R(i)R(i) true exactly once. By the definition of the sum over a relation, ∑R(i)ai=ap(j1)+⋯+ap(jN)\sum_{R(i)} a_i = a_{p(j_1)} + \cdots + a_{p(j_N)}, and the right side is ∑S(j)ap(j)\sum_{S(j)} a_{p(j)} by the same definition. □\square

Corollary P2.1.33 (shift and reflection). For each integer cc, ∑R(i)ai=∑R(j+c)aj+c=∑R(c−j)ac−j\sum_{R(i)} a_i = \sum_{R(j + c)} a_{j + c} = \sum_{R(c - j)} a_{c - j}. With limits, ∑k=mnak=∑k=m+cn+cak−c\sum_{k=m}^{n} a_k = \sum_{k=m+c}^{n+c} a_{k-c} and ∑k=mnak=∑k=mnam+n−k\sum_{k=m}^{n} a_k = \sum_{k=m}^{n} a_{m+n-k}.

Lean: Mathlib Finset.sum_Ico_add and Finset.sum_range_reflect (proved in Mathlib).

Proof. The maps j↦j+cj \mapsto j + c and j↦c−jj \mapsto c - j are bijections of the integers, with inverses i↦i−ci \mapsto i - c and i↦c−ii \mapsto c - i. Each maps the set where R(j+c)R(j + c), or R(c−j)R(c - j), is true onto the set where RR is true. The theorem on the change of variable gives the first two equations. For the forms with limits, take R(i)R(i) to be m≤i≤nm \le i \le n. The relation m≤k−c≤nm \le k - c \le n is m+c≤k≤n+cm + c \le k \le n + c, and the shift by −c-c gives the third equation. The relation m≤m+n−k≤nm \le m + n - k \le n is m≤k≤nm \le k \le n, and the reflection with c=m+nc = m + n gives the fourth. □\square

Proposition P2.1.34 (sums with the bracket). If the family aja_j has finite support on RR, then ∑R(j)aj=∑jaj[R(j)].\sum_{R(j)} a_j = \sum_{j} a_j [R(j)]. If pp is a bijection of the integers onto the integers, then ∑jaj[R(j)]=∑jap(j)[R(p(j))]\sum_{j} a_j [R(j)] = \sum_{j} a_{p(j)} [R(p(j))].

Lean: Mathlib Finset.sum_filter for the first equation, and finsum_comp_equiv for the second, a sum with finite support over a type such as ℤ (proved in Mathlib).

Proof. The term aj[R(j)]a_j [R(j)] is aja_j when R(j)R(j) is true and 00 otherwise. So the family aj[R(j)]a_j [R(j)] has finite support on all integers, its nonzero terms are the nonzero terms aja_j with R(j)R(j) true, and the two sums add the same nonzero numbers. For the second claim, apply the theorem on the change of variable to the family bj=aj[R(j)]b_j = a_j [R(j)], over the finite set FF where bj≠0b_j \ne 0, with the bijection pp from p−1(F)p^{-1}(F) onto FF. Then ∑jbj=∑jbp(j)\sum_j b_j = \sum_j b_{p(j)}, and bp(j)=ap(j)[R(p(j))]b_{p(j)} = a_{p(j)} [R(p(j))]. □\square

Theorem P2.1.35 (interchange of the order). For numbers aija_{ij}, ∑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}.

Lean: Mathlib Finset.sum_comm (proved in Mathlib).

Proof. Use induction on the size NN of the set GG where SS is true. For N=0N = 0 each inner sum on the left is empty, so the left side is ∑R(i)0=0\sum_{R(i)} 0 = 0, and the right side is an empty sum. For N≥1N \ge 1 take y∈Gy \in G and let G′=G∖{y}G' = G \setminus \{y\}. The left side is ∑R(i)(∑j∈G′aij+aiy)\sum_{R(i)} \bigl(\sum_{j \in G'} a_{ij} + a_{iy}\bigr). The theorem on the sum of two families splits it as ∑R(i)∑j∈G′aij+∑R(i)aiy\sum_{R(i)} \sum_{j \in G'} a_{ij} + \sum_{R(i)} a_{iy}. By the induction hypothesis the first part is ∑j∈G′∑R(i)aij\sum_{j \in G'} \sum_{R(i)} a_{ij}, and adding the term for j=yj = y gives ∑j∈G∑R(i)aij\sum_{j \in G} \sum_{R(i)} a_{ij}. □\square

Corollary P2.1.36 (interchange in a triangle). For n≥0n \ge 0, ∑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}.

Lean: Mathlib Finset.sum_sigma' together with Finset.sum_comm', which allows the inner range to depend on the outer index (proved in Mathlib).

Proof. For 1≤i≤n1 \le i \le n the inner sum on the left is ∑j=1naij[j≤i]\sum_{j=1}^{n} a_{ij} [j \le i], since the bracket removes the terms with j>ij > i. So the left side is ∑i=1n∑j=1naij[j≤i]\sum_{i=1}^{n} \sum_{j=1}^{n} a_{ij} [j \le i], a sum over a square. The theorem on the interchange of the order turns it into ∑j=1n∑i=1naij[j≤i]\sum_{j=1}^{n} \sum_{i=1}^{n} a_{ij} [j \le i]. For 1≤j≤n1 \le j \le n the inner sum is ∑i=jnaij\sum_{i=j}^{n} a_{ij}. □\square

Theorem P2.1.37 (change of the domain). For two relations RR and SS, ∑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.

Lean: Mathlib Finset.sum_union_inter (proved in Mathlib).

Proof. Rules 1 and 3 of the algebra of brackets of Section 1.1 give [R(j)]+[S(j)]=[R(j) or S(j)]+[R(j) and S(j)][R(j)] + [S(j)] = [R(j) \text{ or } S(j)] + [R(j) \text{ and } S(j)] for each jj. Multiply by aja_j and sum over all jj. The theorem on the sum of two families splits each side into two sums, and the proposition on sums with the bracket turns each of the four sums into a sum over a relation. □\square

Corollary P2.1.38 (overlapping ranges). For integers 1≤m≤n1 \le m \le n, ∑j=1maj+∑j=mnaj=∑j=1naj+am.\sum_{j=1}^{m} a_j + \sum_{j=m}^{n} a_j = \sum_{j=1}^{n} a_j + a_m.

Lean: Mathlib Finset.sum_range_add_sum_Ico covers the case without overlap (proved in Mathlib); this form follows with one more use of Finset.sum_range_succ.

Proof. Take R(j)R(j) to be 1≤j≤m1 \le j \le m and S(j)S(j) to be m≤j≤nm \le j \le n. Since m≤nm \le n, the relation "R(j)R(j) or S(j)S(j)" is 1≤j≤n1 \le j \le n, and the relation "R(j)R(j) and S(j)S(j)" is j=mj = m. The theorem on the change of the domain gives the claim. □\square

Theorem P2.1.39 (laws for products). Let the relations be true for finitely many integers. Then ∏R(j)bjcj=∏R(j)bj∏R(j)cj,∏R(i)ai=∏S(j)ap(j),∏R(i)∏S(j)aij=∏S(j)∏R(i)aij,\prod_{R(j)} b_j c_j = \prod_{R(j)} b_j \prod_{R(j)} c_j, \qquad \prod_{R(i)} a_i = \prod_{S(j)} a_{p(j)}, \qquad \prod_{R(i)} \prod_{S(j)} a_{ij} = \prod_{S(j)} \prod_{R(i)} a_{ij}, where pp is a bijection as in the theorem on the change of variable, and ∏R(j)aj∏S(j)aj=∏R(j) or S(j)aj∏R(j) and S(j)aj.\prod_{R(j)} a_j \prod_{S(j)} a_j = \prod_{R(j) \text{ or } S(j)} a_j \prod_{R(j) \text{ and } S(j)} a_j. For an integer e≥0e \ge 0, (∏R(j)aj)e=∏R(j)aje\bigl(\prod_{R(j)} a_j\bigr)^e = \prod_{R(j)} a_j^e.

Lean: Mathlib Finset.prod_mul_distrib, Finset.prod_nbij', Finset.prod_comm, Finset.prod_union_inter and Finset.prod_pow (proved in Mathlib).

Proof. The proofs of the theorems on the sum of two families, the change of variable and the interchange of the order use only the associative and commutative laws of addition, the empty sum 00 and the induction on the number of terms. Multiplication has the same laws, and the empty product is 11. So the same proofs, with products in place of sums, give the first three equations. The proof of the change of the domain used brackets, so it needs a new form. Let FF and GG be the sets where RR and SS are true. The set FF is the disjoint union of F∖GF \setminus G and F∩GF \cap G, and F∪GF \cup G is the disjoint union of F∖GF \setminus G and GG. The proposition on disjoint relations of Section 1.1 gives ∏Faj∏Gaj=∏F∖Gaj∏F∩Gaj∏Gaj=∏F∪Gaj∏F∩Gaj\prod_F a_j \prod_G a_j = \prod_{F \setminus G} a_j \prod_{F \cap G} a_j \prod_G a_j = \prod_{F \cup G} a_j \prod_{F \cap G} a_j. The last claim is the first equation used e−1e - 1 times, by induction on ee; for e=0e = 0 both sides are 11. □\square

Theorem P2.1.40 (telescoping sum). Let ff be a function on the integers and let m≤nm \le n. Then ∑k=mn−1(f(k+1)−f(k))=f(n)−f(m).\sum_{k=m}^{n-1} \bigl(f(k+1) - f(k)\bigr) = f(n) - f(m). If f(k)≠0f(k) \ne 0 for m≤k≤nm \le k \le n, then ∏k=mn−1f(k+1)/f(k)=f(n)/f(m)\prod_{k=m}^{n-1} f(k+1)/f(k) = f(n)/f(m).

Lean: Mathlib Finset.sum_range_sub and Finset.prod_range_div (proved in Mathlib, for the range 00 to n−1n - 1).

Proof. Use induction on nn, starting at n=mn = m. For n=mn = m the sum is empty and the right side is f(m)−f(m)=0f(m) - f(m) = 0. For the step from nn to n+1n + 1, the recursive definition of the sum with limits adds the term f(n+1)−f(n)f(n+1) - f(n) to the left side. The right side becomes f(n)−f(m)+f(n+1)−f(n)=f(n+1)−f(m)f(n) - f(m) + f(n+1) - f(n) = f(n+1) - f(m). The proof for products is the same, with f(n)/f(m)⋅f(n+1)/f(n)=f(n+1)/f(m)f(n)/f(m) \cdot f(n+1)/f(n) = f(n+1)/f(m). □\square

Proof

The laws have short proofs, and the proofs share one plan. Each law holds for one or two terms by the axioms of a commutative ring. An induction on the number of terms carries it to all finite sums. The lemma on the order of the terms of Section 1.1 allows the induction to remove any element of the finite set, not only the last one.

The bracket turns a sum over a relation into a sum over all integers with finite support. A rule about relations then becomes a rule about numbers 00 and 11. The theorem on the change of the domain and the corollary on the interchange in a triangle are proved in this way. Section 1.3 uses the same method for the general change of the order of summation.

The telescoping sum is the discrete form of the fundamental theorem of calculus. Chapter 3 builds the finite calculus on it.

Examples

Example P2.1.41 (a telescoping sum). For k≥1k \ge 1, 1k(k+1)=1k−1k+1=f(k+1)−f(k)\frac{1}{k(k+1)} = \frac{1}{k} - \frac{1}{k+1} = f(k+1) - f(k) with f(k)=−1/kf(k) = -1/k. So ∑k=1n1k(k+1)=f(n+1)−f(1)=1−1n+1.\sum_{k=1}^{n} \frac{1}{k(k+1)} = f(n+1) - f(1) = 1 - \frac{1}{n+1}. For n=3n = 3 this gives 12+16+112=34\tfrac12 + \tfrac16 + \tfrac1{12} = \tfrac34, which agrees.

Example P2.1.42 (factorials). For k≥0k \ge 0, (k+1)!−k!=k! (k+1−1)=k⋅k!(k+1)! - k! = k!\,(k + 1 - 1) = k \cdot k!. So ∑k=0nk⋅k!=(n+1)!−0!=(n+1)!−1\sum_{k=0}^{n} k \cdot k! = (n+1)! - 0! = (n+1)! - 1. For n=3n = 3 the sum is 0+1+4+18=23=4!−10 + 1 + 4 + 18 = 23 = 4! - 1.

Example P2.1.43 (reflection). Let S=∑k=0n(n−2k)S = \sum_{k=0}^{n} (n - 2k). The reflection k↦n−kk \mapsto n - k maps the range 0≤k≤n0 \le k \le n onto itself, and it changes the term n−2kn - 2k into n−2(n−k)=2k−nn - 2(n - k) = 2k - n. So S=∑k=0n(2k−n)=−SS = \sum_{k=0}^{n} (2k - n) = -S, and S=0S = 0. No formula for ∑k\sum k is needed.

Example P2.1.44 (a product that telescopes). For n≥2n \ge 2, ∏k=2n(1−1k2)=∏k=2nk−1k∏k=2nk+1k=1n⋅n+12=n+12n.\prod_{k=2}^{n} \Bigl(1 - \frac{1}{k^2}\Bigr) = \prod_{k=2}^{n} \frac{k-1}{k} \prod_{k=2}^{n} \frac{k+1}{k} = \frac{1}{n} \cdot \frac{n+1}{2} = \frac{n+1}{2n}. The first step is the law ∏bkck=∏bk∏ck\prod b_k c_k = \prod b_k \prod c_k, and each product on the right telescopes, with f(k)=1/kf(k) = 1/k and f(k)=k+1f(k) = k + 1 after a shift of the index. For n=3n = 3 the product is 34⋅89=23=46\tfrac34 \cdot \tfrac89 = \tfrac23 = \tfrac{4}{6}.

Example P2.1.45 (an interchange that helps). The sum ∑i=1n∑j=in1/j\sum_{i=1}^{n} \sum_{j=i}^{n} 1/j has an inner sum with no closed form. The corollary on the interchange in a triangle, read from right to left, changes it into ∑j=1n∑i=1j1/j\sum_{j=1}^{n} \sum_{i=1}^{j} 1/j. The inner sum is now j⋅(1/j)=1j \cdot (1/j) = 1, so the whole sum is nn.

Exercises

  1. [M15] Prove that ∑k=1nk(k+1)!=1−1(n+1)!\sum_{k=1}^{n} \frac{k}{(k+1)!} = 1 - \frac{1}{(n+1)!} for n≥0n \ge 0.
  2. [M18] Find a closed form for ∑k=1nk2+k−1k(k+1)\sum_{k=1}^{n} \frac{k^2 + k - 1}{k(k+1)}.
  3. [M20] Prove that ∑k=1n1k(k+1)(k+2)=14−12(n+1)(n+2)\sum_{k=1}^{n} \frac{1}{k(k+1)(k+2)} = \frac14 - \frac{1}{2(n+1)(n+2)} for n≥0n \ge 0.
  4. [M20] Let ak=an−ka_k = a_{n-k} for 0≤k≤n0 \le k \le n. Prove that ∑k=0nk ak=n2∑k=0nak\sum_{k=0}^{n} k\, a_k = \frac{n}{2} \sum_{k=0}^{n} a_k.
  5. [M20] Evaluate ∏k=2nk3−1k3+1\prod_{k=2}^{n} \frac{k^3 - 1}{k^3 + 1} for n≥2n \ge 2, and find its limit as n→∞n \to \infty.
  6. [M22] Prove the rule for three relations: ∑R or S or Taj=∑Raj+∑Saj+∑Taj−∑R and Saj−∑R and Taj−∑S and Taj+∑R and S and Taj\sum_{R \text{ or } S \text{ or } T} a_j = \sum_R a_j + \sum_S a_j + \sum_T a_j - \sum_{R \text{ and } S} a_j - \sum_{R \text{ and } T} a_j - \sum_{S \text{ and } T} a_j + \sum_{R \text{ and } S \text{ and } T} a_j, where the index jj is left out of the relations.
  7. [M22] Prove that ∑k=12n(−1)k+1k=∑k=n+12n1k\sum_{k=1}^{2n} \frac{(-1)^{k+1}}{k} = \sum_{k=n+1}^{2n} \frac{1}{k} for n≥1n \ge 1.
  8. [M22] The map p(j)=⌊j/2⌋p(j) = \lfloor j/2 \rfloor maps {0,1,2,3}\{0, 1, 2, 3\} onto {0,1}\{0, 1\}. Show that ∑0≤j≤3ap(j)≠∑0≤i≤1ai\sum_{0 \le j \le 3} a_{p(j)} \ne \sum_{0 \le i \le 1} a_i in general. Then prove that for every map pp from the set where SS is true into the set where RR is true, ∑S(j)ap(j)=∑R(i)ai N(i)\sum_{S(j)} a_{p(j)} = \sum_{R(i)} a_i\, N(i), where N(i)N(i) is the number of jj with S(j)S(j) and p(j)=ip(j) = i.
  9. [M20] Use the interchange in a triangle to evaluate ∑i=1n∑j=inij\sum_{i=1}^{n} \sum_{j=i}^{n} \frac{i}{j}.
  10. [M20] Let am,am+1,…a_m, a_{m+1}, \dots be numbers. Prove that there is a function ff on the integers k≥mk \ge m with f(k+1)−f(k)=akf(k+1) - f(k) = a_k for all k≥mk \ge m, and that two such functions differ by a constant.
  11. [M25] Use a telescoping sum with f(k)=(k−1)k(k+1)/3f(k) = (k-1)k(k+1)/3 to evaluate ∑k=1nk(k+1)\sum_{k=1}^{n} k(k+1), and then find ∑k=1nk(k+1)(k+2)\sum_{k=1}^{n} k(k+1)(k+2) in the same way.

Lean

The laws of this section are in Mathlib for Finset.sum and Finset.prod, and the names follow one scheme: a law for products has a name with prod, and the attribute to_additive makes the law for sums, with sum in the name. The distributive law is Finset.mul_sum and Finset.sum_mul. The sum of two families is Finset.sum_add_distrib. The interchange of the order is Finset.sum_comm, and Finset.sum_comm' allows ranges that depend on the outer index, as in a triangle.

The change of variable has several forms. Finset.sum_nbij' takes a map and its inverse, Finset.sum_bij' allows the map to depend on the proof that the index is in the set, and Finset.sum_equiv takes an Equiv. The reflection of a range is Finset.sum_range_reflect. The change of the domain is Finset.sum_union_inter. The telescoping sum is Finset.sum_range_sub, the form for sums of Finset.prod_range_div.

The project writes the sums of TAOCP with the bracket as Finset.sum over an explicit range with TAOCP.iverson in the term (spec 06.1). A law above for a sum with brackets then follows from its Mathlib form, after TAOCP.iverson is unfolded to if then else.

Notes and history

TAOCP Section 1.2.3 gives the laws of this section as eqs. 1.2.3(4) to 1.2.3(8), with the change of the domain in eqs. 1.2.3(11) and 1.2.3(12). The bracket forms are eqs. 1.2.3(17) and 1.2.3(18), and the laws for products are eq. 1.2.3(20). The interchange in a triangle, eq. 1.2.3(10), is a special case of the general rule of Section 1.3.

The laws for finite sums are as old as algebra, but their use as a calculus of manipulations is newer. TAOCP made the sum over a relation and the change of the domain standard tools in the analysis of algorithms, and GKP94 Chapter 2 develops the same laws with the bracket from the start. Each law here has the same proof in every commutative ring, so the laws hold for sums of integers, of polynomials and of matrices with commuting entries alike.

Multiple sums

Statement

A sum can run over pairs, triples or longer lists of integers. This section turns such a sum into sums over one index at a time, and it gives the general rule for the change of the order of summation. The rule has a short proof with the bracket. The section ends with sums over the solutions of an equation j1+⋯+jm=nj_1 + \cdots + j_m = n, which TAOCP uses for partitions.

Definition P2.1.46 (multiple sum). Let R(i,j)R(i, j) be a relation on pairs of integers that is true for finitely many pairs, and let aija_{ij} be numbers. The double sum ∑R(i,j)aij\sum_{R(i,j)} a_{ij} is the sum of aija_{ij} over the finite set of pairs where RR is true, as in the definition of the sum over a relation of Section 1.1. In the same way a relation on lists (j1,…,jm)(j_1, \dots, j_m) gives a multiple sum. The bracket form is ∑i,jaij[R(i,j)]\sum_{i,j} a_{ij} [R(i,j)].

Lean: Mathlib Finset.sum over a Finset of pairs, such as Finset.product s t or (s ×ˢ t).filter R (proved in Mathlib to split by Finset.sum_product and Finset.sum_filter).

Example P2.1.47. The sum ∑1≤i<j≤3ij\sum_{1 \le i < j \le 3} i j runs over the pairs (1,2)(1,2), (1,3)(1,3) and (2,3)(2,3). Its value is 2+3+6=112 + 3 + 6 = 11. The sum ∑1≤i,j≤n1\sum_{1 \le i, j \le n} 1 counts the pairs in a square and is n2n^2.

Example P2.1.48. The sum ∑i+j=4, i,j≥0aibj\sum_{i + j = 4,\ i, j \ge 0} a_i b_j runs over the five pairs (0,4),(1,3),(2,2),(3,1),(4,0)(0,4), (1,3), (2,2), (3,1), (4,0). It is a0b4+a1b3+a2b2+a3b1+a4b0a_0 b_4 + a_1 b_3 + a_2 b_2 + a_3 b_1 + a_4 b_0, the coefficient of x4x^4 in the product of the polynomials ∑iaixi\sum_i a_i x^i and ∑jbjxj\sum_j b_j x^j.

Proposition P2.1.49 (iterated sums). If R(i,j)R(i, j) is true for finitely many pairs, then ∑R(i,j)aij=∑i∑jaij[R(i,j)]=∑j∑iaij[R(i,j)].\sum_{R(i,j)} a_{ij} = \sum_{i} \sum_{j} a_{ij} [R(i,j)] = \sum_{j} \sum_{i} a_{ij} [R(i,j)]. Each outer sum has finite support, and each inner sum is finite.

Lean: Mathlib Finset.sum_sigma', Finset.sum_product and Finset.sum_comm (proved in Mathlib).

Proof. Let PP be the finite set of pairs where RR is true, and let II be the finite set of first coordinates of pairs in PP. For i∈Ii \in I let PiP_i be the set of pairs in PP with first coordinate ii. The sets PiP_i are disjoint and their union is PP. The proposition on disjoint relations of Section 1.1, with an induction on the size of II, gives ∑Paij=∑i∈I∑(i,j)∈Piaij\sum_{P} a_{ij} = \sum_{i \in I} \sum_{(i,j) \in P_i} a_{ij}. The inner sum is ∑jaij[R(i,j)]\sum_j a_{ij} [R(i,j)], and for i∉Ii \notin I this sum is 00. This proves the first equation. The same argument with the second coordinate proves the second one. □\square

Theorem P2.1.50 (general change of the order). Let R(i)R(i), S(i,j)S(i, j), S′(j)S'(j) and R′(i,j)R'(i, j) be relations such that [R(i)] [S(i,j)]=[S′(j)] [R′(i,j)][R(i)]\,[S(i,j)] = [S'(j)]\,[R'(i,j)] for all integers ii and jj, and suppose that this bracket is 11 for finitely many pairs. 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}. The relations S′(j)S'(j): "there is an ii with R(i)R(i) and S(i,j)S(i,j)", and R′(i,j)R'(i,j): "R(i)R(i) and S(i,j)S(i,j)", always satisfy the condition.

Lean: Mathlib Finset.sum_comm' (proved in Mathlib), whose hypothesis is the condition of the theorem in the form of an equivalence of memberships.

Proof. By the proposition on sums with the bracket of Section 1.2, the left side is ∑i[R(i)]∑jaij[S(i,j)]\sum_i [R(i)] \sum_j a_{ij} [S(i,j)]. The distributive law moves [R(i)][R(i)] inside, so the left side is ∑i∑jaij[R(i)][S(i,j)]\sum_i \sum_j a_{ij} [R(i)][S(i,j)]. The hypothesis changes the bracket product into [S′(j)][R′(i,j)][S'(j)][R'(i,j)]. The proposition on iterated sums exchanges the two sums, and the same two steps in reverse give ∑S′(j)∑R′(i,j)aij\sum_{S'(j)} \sum_{R'(i,j)} a_{ij}. For the last claim, if R(i)R(i) and S(i,j)S(i,j) are both true, then S′(j)S'(j) and R′(i,j)R'(i,j) are both true, and both sides of the condition are 11. If one of R(i)R(i), S(i,j)S(i,j) is false, then R′(i,j)R'(i,j) is false and both sides are 00. □\square

Corollary P2.1.51 (sums along diagonals). For n≥0n \ge 0, ∑i=0n∑j=0n−iaij=∑s=0n∑i=0sai, s−i.\sum_{i=0}^{n} \sum_{j=0}^{n-i} a_{ij} = \sum_{s=0}^{n} \sum_{i=0}^{s} a_{i,\, s-i}.

Lean: Mathlib Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk gives the inner sum over the diagonal i+j=si + j = s (proved in Mathlib).

Proof. The left side is the sum of aija_{ij} over the pairs with i,j≥0i, j \ge 0 and i+j≤ni + j \le n. The map (i,j)↦(i,s)(i, j) \mapsto (i, s) with s=i+js = i + j is a bijection from this set onto the set of pairs (i,s)(i, s) with 0≤i≤s≤n0 \le i \le s \le n; its inverse is (i,s)↦(i,s−i)(i, s) \mapsto (i, s - i). The theorem on the change of variable of Section 1.2, applied to pairs, turns the sum into ∑0≤i≤s≤nai, s−i\sum_{0 \le i \le s \le n} a_{i,\, s-i}. The general change of the order, with R(i)R(i): 0≤i≤n0 \le i \le n, S(i,s)S(i, s): i≤s≤ni \le s \le n, S′(s)S'(s): 0≤s≤n0 \le s \le n and R′(i,s)R'(i, s): 0≤i≤s0 \le i \le s, gives the right side. The condition holds, since both bracket products are [0≤i≤s≤n][0 \le i \le s \le n]. □\square

Definition P2.1.52 (symmetric family). A family aija_{ij}, for 1≤i,j≤n1 \le i, j \le n, is symmetric if aij=ajia_{ij} = a_{ji} for all ii and jj.

Lean: Mathlib Matrix.IsSymm for a matrix with A𝖳=AA^{\mathsf T} = A.

Example P2.1.53. The family aij=1a_{ij} = 1 is symmetric, and so is aij=min⁡(i,j)a_{ij} = \min(i, j) and aij=∣i−j∣a_{ij} = |i - j|. The family aij=ia_{ij} = i is not symmetric when n≥2n \ge 2, since a12=1a_{12} = 1 and a21=2a_{21} = 2.

Example P2.1.54. For numbers x1,…,xnx_1, \dots, x_n, the family aij=xixja_{ij} = x_i x_j is symmetric. Its sum over the square is ∑i,jxixj=(∑ixi)2\sum_{i,j} x_i x_j = \bigl(\sum_i x_i\bigr)^2, by the distributive law of Section 1.2. The theorem on the square of a sum below uses this family.

Proposition P2.1.55 (symmetric sums). For a symmetric family aija_{ij}, 1≤i,j≤n1 \le i, j \le n, ∑1≤i<j≤naij=12(∑i=1n∑j=1naij−∑i=1naii),∑1≤i≤j≤naij=12(∑i=1n∑j=1naij+∑i=1naii).\sum_{1 \le i < j \le n} a_{ij} = \frac12 \Bigl(\sum_{i=1}^{n} \sum_{j=1}^{n} a_{ij} - \sum_{i=1}^{n} a_{ii}\Bigr), \qquad \sum_{1 \le i \le j \le n} a_{ij} = \frac12 \Bigl(\sum_{i=1}^{n} \sum_{j=1}^{n} a_{ij} + \sum_{i=1}^{n} a_{ii}\Bigr).

Lean: not in Mathlib in this form; Mathlib has Finset.sum_product and Finset.sum_comm for the steps, and Finset.offDiag and Finset.diag for the parts of the square.

Proof. Let U=∑1≤i<j≤naijU = \sum_{1 \le i < j \le n} a_{ij}, L=∑1≤j<i≤naijL = \sum_{1 \le j < i \le n} a_{ij} and D=∑i=1naiiD = \sum_{i=1}^{n} a_{ii}. Each pair in the square has exactly one of i<ji < j, i=ji = j and i>ji > j, so the sum over the square is U+D+LU + D + L, by the proposition on disjoint relations. The map (i,j)↦(j,i)(i, j) \mapsto (j, i) is a bijection from the pairs with i<ji < j onto the pairs with i>ji > j. By the change of variable and the symmetry, L=∑1≤i<j≤naji=UL = \sum_{1 \le i < j \le n} a_{ji} = U. So the square is 2U+D2U + D, which gives the first formula. The second sum is U+D=12(2U+D)+12DU + D = \frac12 (2U + D) + \frac12 D, which gives the second formula. □\square

Theorem P2.1.56 (square of a sum). For numbers a0,…,ana_0, \dots, a_n, ∑0≤j≤i≤naiaj=12((∑i=0nai)2+∑i=0nai2),∑0≤j<i≤naiaj=12((∑i=0nai)2−∑i=0nai2).\sum_{0 \le j \le i \le n} a_i a_j = \frac12 \biggl(\Bigl(\sum_{i=0}^{n} a_i\Bigr)^2 + \sum_{i=0}^{n} a_i^2\biggr), \qquad \sum_{0 \le j < i \le n} a_i a_j = \frac12 \biggl(\Bigl(\sum_{i=0}^{n} a_i\Bigr)^2 - \sum_{i=0}^{n} a_i^2\biggr).

Lean: Mathlib Finset.sum_mul_sum gives the square as a sum over the square of indices (proved in Mathlib); the two formulas are not stated in this form.

Proof. The family aiaja_i a_j is symmetric, its sum over the square 0≤i,j≤n0 \le i, j \le n is (∑iai)2\bigl(\sum_i a_i\bigr)^2, and its diagonal sum is ∑iai2\sum_i a_i^2. The proposition on symmetric sums, with the indices 00 to nn in place of 11 to nn, gives both formulas; the sums over j≤ij \le i and j<ij < i are the sums over i≤ji \le j and i<ji < j with the names of the indices exchanged. □\square

Definition P2.1.57 (sums over the solutions of an equation). Let m≥1m \ge 1 and n≥0n \ge 0. The sum ∑j1+⋯+jm=naj1…jm\sum_{j_1 + \cdots + j_m = n} a_{j_1 \dots j_m}, with the condition j1,…,jm≥0j_1, \dots, j_m \ge 0 understood, runs over all lists of mm nonnegative integers with sum nn. With the extra condition j1≥j2≥⋯≥jm≥0j_1 \ge j_2 \ge \cdots \ge j_m \ge 0 it runs over the partitions of nn into at most mm parts. A partition of nn is a list j1≥⋯≥jn≥0j_1 \ge \cdots \ge j_n \ge 0 with sum nn; its parts are its nonzero entries.

Lean: Mathlib Finset.Nat.antidiagonalTuple m n is the Finset of lists of mm natural numbers with sum nn, and Nat.Partition n is the type of partitions of nn (proved in Mathlib to be finite, with Fintype).

Example P2.1.58. For m=2m = 2 the sum ∑j1+j2=naj1bj2\sum_{j_1 + j_2 = n} a_{j_1} b_{j_2} is ∑k=0nakbn−k\sum_{k=0}^{n} a_k b_{n-k}, the coefficient of xnx^n in a product of two polynomials. For m=3m = 3 and n=2n = 2 the lists are (2,0,0)(2,0,0), (0,2,0)(0,2,0), (0,0,2)(0,0,2), (1,1,0)(1,1,0), (1,0,1)(1,0,1) and (0,1,1)(0,1,1), six in all.

Example P2.1.59. The partitions of 44 in the form j1≥j2≥j3≥j4≥0j_1 \ge j_2 \ge j_3 \ge j_4 \ge 0 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). So ∑j1+⋯+j4=4, j1≥⋯≥j4≥01=5\sum_{j_1 + \cdots + j_4 = 4,\ j_1 \ge \cdots \ge j_4 \ge 0} 1 = 5, the number of partitions of 44.

Proposition P2.1.60 (number of solutions). For m≥1m \ge 1 and n≥0n \ge 0 the number of lists (j1,…,jm)(j_1, \dots, j_m) of nonnegative integers with j1+⋯+jm=nj_1 + \cdots + j_m = n is (n+m−1m−1)\binom{n + m - 1}{m - 1}.

Lean: Mathlib has no lemma for the size of Finset.Nat.antidiagonalTuple m n; it has Sym.card_sym_eq_choose (proved in Mathlib), the count of multisets of size nn from mm elements, which is the same count in another form: jtj_t is the number of copies of element tt.

Proof. Write a list as a row of n+m−1n + m - 1 symbols: j1j_1 stars, a bar, j2j_2 stars, a bar, and so on, with m−1m - 1 bars in all. The row has nn stars and m−1m - 1 bars. Each row of nn stars and m−1m - 1 bars comes from exactly one list: j1j_1 is the number of stars before the first bar, jtj_t is the number between bar t−1t - 1 and bar tt, and jmj_m is the number after the last bar. So the lists correspond one to one to the choices of the m−1m - 1 places of the bars among n+m−1n + m - 1 places, and there are (n+m−1m−1)\binom{n + m - 1}{m - 1} such choices. □\square

Proposition P2.1.61 (two forms of a partition). Let n≥1n \ge 1. For a partition j1≥⋯≥jn≥0j_1 \ge \cdots \ge j_n \ge 0 of nn and 1≤r≤n1 \le r \le n, let krk_r be the number of indices tt with jt=rj_t = r. The map (j1,…,jn)↦(k1,…,kn)(j_1, \dots, j_n) \mapsto (k_1, \dots, k_n) is a bijection from the partitions of nn onto the lists of nonnegative integers with k1+2k2+⋯+nkn=nk_1 + 2k_2 + \cdots + n k_n = n. So for every function gg, ∑j1+⋯+jn=nj1≥⋯≥jn≥0g(k1,…,kn)=∑k1+2k2+⋯+nkn=ng(k1,…,kn).\sum_{\substack{j_1 + \cdots + j_n = n \\ j_1 \ge \cdots \ge j_n \ge 0}} g(k_1, \dots, k_n) = \sum_{k_1 + 2 k_2 + \cdots + n k_n = n} g(k_1, \dots, k_n).

Lean: Mathlib Nat.Partition stores a partition as a multiset of parts, and Multiset.count r gives krk_r; the bijection is not stated in this form.

Proof. The map lands in the right set. Every entry jtj_t lies between 00 and nn, and the entries with jt=0j_t = 0 add nothing, so grouping the indices tt by the value r=jtr = j_t gives n=∑tjt=∑r=1nr krn = \sum_{t} j_t = \sum_{r=1}^{n} r\, k_r. The map has an inverse. Given (k1,…,kn)(k_1, \dots, k_n) with ∑rkr=n\sum r k_r = n, form the list that has knk_n entries equal to nn, then kn−1k_{n-1} entries equal to n−1n - 1, and so on down to k1k_1 entries equal to 11, and then zeros. The number of nonzero entries is ∑rkr≤∑rrkr=n\sum_r k_r \le \sum_r r k_r = n, so zeros fill the list to length nn. This list is nonincreasing and has sum nn, and its value counts are k1,…,knk_1, \dots, k_n. A nonincreasing list is fixed by its value counts, so the two maps are inverse to each other. The equation of sums is the theorem on the change of variable for this bijection. □\square

Proof

All proofs of this section come from two facts. A multiple sum over a finite set of pairs is an iterated sum, by the proposition on iterated sums. A relation becomes a bracket, and the bracket turns a statement about ranges into an identity between numbers 00 and 11.

The general change of the order is then three lines. The hard part in an application is to find S′S' and R′R'. The method is always the same: write the condition "R(i)R(i) and S(i,j)S(i, j)" as a chain of inequalities, and solve the chain for ii with jj fixed. The relation S′(j)S'(j) is the condition on jj for the solution set to be nonempty, and R′(i,j)R'(i, j) is the solution set.

The two forms of a partition are an example of a change of variable between two descriptions of the same object. TAOCP uses both forms, and the proposition allows a sum in one form to be read in the other.

Examples

Example P2.1.62 (pairs below the diagonal). The family aij=1a_{ij} = 1 is symmetric. The proposition on symmetric sums gives the number of pairs with 1≤i≤j≤n1 \le i \le j \le n as 12(n2+n)=n(n+1)/2\frac12 (n^2 + n) = n(n+1)/2, and the number with i<ji < j as 12(n2−n)=n(n−1)/2\frac12 (n^2 - n) = n(n-1)/2. No formula for ∑k\sum k is used.

Example P2.1.63 (products of pairs). The theorem on the square of a sum gives ∑1≤i<j≤nij=12((∑k=1nk)2−∑k=1nk2)\sum_{1 \le i < j \le n} i j = \frac12 \bigl((\sum_{k=1}^{n} k)^2 - \sum_{k=1}^{n} k^2\bigr). Section 2.2 proves ∑k=1nk=n(n+1)/2\sum_{k=1}^{n} k = n(n+1)/2 and ∑k=1nk2=n(n+1)(2n+1)/6\sum_{k=1}^{n} k^2 = n(n+1)(2n+1)/6. With these values the sum is 12(n2(n+1)24−n(n+1)(2n+1)6)=(n−1)n(n+1)(3n+2)24.\frac12 \Bigl(\frac{n^2 (n+1)^2}{4} - \frac{n(n+1)(2n+1)}{6}\Bigr) = \frac{(n-1) n (n+1)(3n+2)}{24}. For n=3n = 3 this is 2⋅3⋅4⋅11/24=112 \cdot 3 \cdot 4 \cdot 11 / 24 = 11, which agrees with the example after the definition of the multiple sum.

Example P2.1.64 (divisors, counted twice). Let d(n)d(n) be the number of positive divisors of nn. Then ∑n=1Nd(n)=∑n=1N∑e∣n1\sum_{n=1}^{N} d(n) = \sum_{n=1}^{N} \sum_{e \mid n} 1. Take R(n)R(n): 1≤n≤N1 \le n \le N and S(n,e)S(n, e): e∣ne \mid n, with e≥1e \ge 1. The condition "1≤n≤N1 \le n \le N and e∣ne \mid n" means that nn is a multiple of ee in the range 11 to NN. Such an nn exists exactly when 1≤e≤N1 \le e \le N. So S′(e)S'(e) is 1≤e≤N1 \le e \le N and R′(n,e)R'(n, e) is "1≤n≤N1 \le n \le N and e∣ne \mid n", and ∑n=1Nd(n)=∑e=1N∑1≤n≤N, e∣n1=∑e=1N⌊Ne⌋,\sum_{n=1}^{N} d(n) = \sum_{e=1}^{N} \sum_{1 \le n \le N,\ e \mid n} 1 = \sum_{e=1}^{N} \Bigl\lfloor \frac{N}{e} \Bigr\rfloor, since the multiples of ee in the range are e,2e,…,⌊N/e⌋ee, 2e, \dots, \lfloor N/e \rfloor e. Chapter 4 treats the floor function. For N=6N = 6 both sides are 1414: on the left 1+2+2+3+2+41 + 2 + 2 + 3 + 2 + 4, on the right 6+3+2+1+1+16 + 3 + 2 + 1 + 1 + 1.

Example P2.1.65 (a product of polynomials). Let p(x)=∑i=0Naixip(x) = \sum_{i=0}^{N} a_i x^i and q(x)=∑j=0Nbjxjq(x) = \sum_{j=0}^{N} b_j x^j. By the distributive law, p(x)q(x)=∑i=0N∑j=0Naibjxi+jp(x) q(x) = \sum_{i=0}^{N} \sum_{j=0}^{N} a_i b_j x^{i+j}. For s≤Ns \le N the terms with i+j=si + j = s all have i,j≤Ni, j \le N, and the corollary on sums along diagonals collects them: the coefficient of xsx^s is ∑i=0saibs−i\sum_{i=0}^{s} a_i b_{s-i}. With all ai=bj=1a_i = b_j = 1 the coefficient is s+1s + 1 for 0≤s≤N0 \le s \le N.

Exercises

  1. [M15] Compute ∑1≤i<j≤4ij\sum_{1 \le i < j \le 4} i j from the theorem on the square of a sum, and check the value by a list of the six terms.
  2. [M20] Let a1,…,ana_1, \dots, a_n be positive. Prove that ∑j=1n∑k=1naj/ak≥n2\sum_{j=1}^{n} \sum_{k=1}^{n} a_j / a_k \ge n^2.
  3. [M22] Prove that ∑i=1n∑j=1nmin⁡(i,j)=∑m=1nm2\sum_{i=1}^{n} \sum_{j=1}^{n} \min(i, j) = \sum_{m=1}^{n} m^2.
  4. [M20] Prove that ∑1≤i<j≤n(j−i)=∑d=1n−1d(n−d)\sum_{1 \le i < j \le n} (j - i) = \sum_{d=1}^{n-1} d (n - d), and compute the value for n=5n = 5.
  5. [M22] List the partitions of 44 in the form (k1,k2,k3,k4)(k_1, k_2, k_3, k_4) of the proposition on the two forms of a partition, and find the number of all lists (j1,j2,j3,j4)(j_1, j_2, j_3, j_4) of nonnegative integers with sum 44.
  6. [M25] Change the order of summation in ∑i=0n∑j=i2iaij\sum_{i=0}^{n} \sum_{j=i}^{2i} a_{ij}, so that the outer sum runs over jj.
  7. [M25] Let aij=1a_{ij} = 1 for j=ij = i, aij=−1a_{ij} = -1 for j=i+1j = i + 1, and aij=0a_{ij} = 0 otherwise, for i,j≥0i, j \ge 0. Show that ∑i≥0∑j≥0aij=0\sum_{i \ge 0} \sum_{j \ge 0} a_{ij} = 0 and ∑j≥0∑i≥0aij=1\sum_{j \ge 0} \sum_{i \ge 0} a_{ij} = 1. Which hypothesis of the theorem on the interchange of the order fails?
  8. [M25] Prove the identity of Lagrange, (∑i=1nai2)(∑i=1nbi2)−(∑i=1naibi)2=∑1≤i<j≤n(aibj−ajbi)2\bigl(\sum_{i=1}^{n} a_i^2\bigr) \bigl(\sum_{i=1}^{n} b_i^2\bigr) - \bigl(\sum_{i=1}^{n} a_i b_i\bigr)^2 = \sum_{1 \le i < j \le n} (a_i b_j - a_j b_i)^2 for real numbers, and deduce the inequality of Cauchy for sums.
  9. [M20] Prove that ∑n=1Nσ(n)=∑e=1Ne⌊N/e⌋\sum_{n=1}^{N} \sigma(n) = \sum_{e=1}^{N} e \lfloor N/e \rfloor, where σ(n)\sigma(n) is the sum of the positive divisors of nn, and check it for N=6N = 6.
  10. [M28] Let p(n)p(n) be the number of partitions of nn, with p(0)=1p(0) = 1. Prove that the total number of parts equal to 11, over all partitions of n≥1n \ge 1, is ∑m=1np(n−m)\sum_{m=1}^{n} p(n - m). Check the claim for n=4n = 4.
  11. [M30] Let Sr=∑i=1nairS_r = \sum_{i=1}^{n} a_i^r. Prove that ∑1≤i<j<k≤naiajak=16(S13−3S1S2+2S3)\sum_{1 \le i < j < k \le n} a_i a_j a_k = \frac16 (S_1^3 - 3 S_1 S_2 + 2 S_3).

Lean

The multiple sums of this section are in Mathlib as sums over Finsets of pairs or of tuples. Finset.sum_product splits a sum over s ×ˢ t into an iterated sum, and Finset.sum_sigma' does the same when the inner range depends on the outer index. Finset.sum_comm' is the general change of the order: its hypothesis is that a pair is in the first description of the domain if and only if it is in the second, which is the condition [R(i)][S(i,j)]=[S′(j)][R′(i,j)][R(i)][S(i,j)] = [S'(j)][R'(i,j)] in the language of sets.

The diagonals i+j=si + j = s are Finset.antidiagonal s, and Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk changes a sum over a diagonal into a sum over a range. The lists of mm natural numbers with sum nn are Finset.Nat.antidiagonalTuple m n, and the partitions of nn are Nat.Partition n. The square of a sum is Finset.sum_mul_sum in its expanded form; the two formulas of the theorem on the square of a sum are not stated in Mathlib, and the project plans no name for them.

The identity of Lagrange of Exercise 8 gives the inequality of Cauchy, which Mathlib states for sums in an ordered semiring as Finset.sum_mul_sq_le_sq_mul_sq (proved in Mathlib), and for inner product spaces as real_inner_mul_inner_self_le.

Notes and history

TAOCP states the general change of the order as eq. 1.2.3(9), with the bracket condition of eq. 1.2.3(21), and its first example is the triangle of eq. 1.2.3(10). The square of a sum is eq. 1.2.3(13), and the sum over partitions is eq. 1.2.3(22). The second form of a partition, with the counts krk_r, appears in TAOCP where a formula of Faà di Bruno type needs it, and the proposition on the two forms of a partition allows a reader to pass between them.

The theory of partitions goes back to Euler, who counted them with generating functions; P3 continues that story. The count of the lists of nonnegative integers with a given sum by stars and bars is a standard argument of elementary combinatorics, and Chapter 6 gives the binomial coefficient that it uses. The identity of Lagrange of Exercise 8 dates from 1773.

The results of Chapter 1 and the equations of TAOCP Section 1.2.3 that they prove:

TAOCP 1.2 Result of P2
1.2.3 eq. 1 Definition P2.1.1
1.2.3 eq. 2 Definition P2.1.4
1.2.3 eq. 3 Definition P2.1.22, with a pointer to P5
1.2.3 eqs. 4 to 8 Theorems P2.1.30, P2.1.31, P2.1.32, P2.1.35 and P2.1.37
1.2.3 eq. 9 Theorem P2.1.50
1.2.3 eq. 10 Corollary P2.1.36 and Theorem P2.1.50
1.2.3 eqs. 11, 12 Theorem P2.1.37 and Corollary P2.1.38
1.2.3 eq. 13 Theorem P2.1.56
1.2.3 eq. 16 Definition P2.1.8
1.2.3 eqs. 17, 18 Proposition P2.1.34
1.2.3 eq. 19 Definition P2.1.11
1.2.3 eq. 20 Theorem P2.1.39
1.2.3 eq. 21 Proposition P2.1.14 and Theorem P2.1.50
1.2.3 eq. 22 Definition P2.1.57 and Proposition P2.1.61

This chapter teaches the notation for sums and the rules that change one sum into another. A sum is the most common object in the analysis of an algorithm: the running time of a loop is a sum of the costs of its steps, and the average cost is a sum over the inputs. A reader who can move an index, split a range and change the order of two sums can follow most of the computations of TAOCP Section 1.2 line by line.

Section 1.1 fixes the notation. It defines the sum with limits, the sum over a relation and the sum over all integers with finite support. It introduces the Iverson bracket and the Kronecker delta, defines products with the empty product, and takes a first look at infinite sums, with a pointer to P5. Section 1.2 proves the laws: the distributive law, the sum of two families, the change of variable, the change of the domain, the interchange of the order and the telescoping sum, with the same laws for products. Section 1.3 treats multiple sums: the general rule for the change of the order, the symmetric sums, the square of a sum and the sums over the solutions of an equation j1+⋯+jm=nj_1 + \cdots + j_m = n, with the two forms of a partition.

The chapter is the base of TAOCP Section 1.2.3, and it proves the equations of that section that are not about special sums. The equations 1.2.3(1), 1.2.3(2), 1.2.3(16) and 1.2.3(19) are in Section 1.1, the laws 1.2.3(4) to 1.2.3(8), 1.2.3(11), 1.2.3(12), 1.2.3(17), 1.2.3(18) and 1.2.3(20) are in Section 1.2, and the multiple sums 1.2.3(9), 1.2.3(10), 1.2.3(13), 1.2.3(21) and 1.2.3(22) are in Section 1.3. The table at the end of Section 1.3 gives the result of this chapter for each equation. The special sums of Section 1.2.3, the geometric and the arithmetic sum, are in Chapter 2.

The chapter assumes P1: proofs by induction, finite sets and bijections, and the counting of subsets. It uses the limit of a sequence of real numbers only in the part on infinite sums. Every later chapter of P2 uses the laws of this chapter without a reference, and the reader who knows them can go to Chapter 2 at once.

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