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.
The notation for sums and products
Statement
A sum is a short way to write 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 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 and be integers and let be numbers. The sum is when , and it is when . The letter is the index of summation, is the lower limit and is the upper limit. Another form of the same sum is . The index is a bound variable: and are the same number.
Lean: Mathlib Finset.sum over Finset.Icc m n, or over Finset.range n for the limits and ; the recursive step is Finset.sum_range_succ (proved in Mathlib).
Example P2.1.2. The definition gives and . The index does not occur in the value. A formula such as is a function of only.
Example P2.1.3. The sum has its upper limit below its lower limit, so its value is . It is not , and it is not . For each the definition gives ; for the sum is empty and the value is , which agrees.
Definition P2.1.4 (sum over a relation). Let be a relation on the integers that is true for a finite set of integers, and let be a number for each . Write the elements of in a list , each element once. The sum is . When is empty the sum is , 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 is . Here is the relation " is prime and ". The sum , over the positive divisors of , is .
Example P2.1.6. The relation gives back the sum with limits: . The relation is true for no integer, so for every family .
Lemma P2.1.7 (order of the terms). Let be a finite set with elements and let be a number for each . Let and be two lists that each contain every element of once. Then .
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 . For both lists are empty and both sums are . Let . The element is for one index . By the associative and commutative laws for two terms, . The list and the list each contain every element of once. This set has elements, so the induction hypothesis says that their sums are equal. So , which is the claim.
Definition P2.1.8 (Iverson bracket). Let be a statement that is true or false. The Iverson bracket is when is true and when is false. A term is when is true and when it is false, also when 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. , and for each integer . The number of primes up to is .
Example P2.1.10. The sum is . The bracket chooses the terms, and the sum runs over a simple range. The term is defined for all integers : it is for and for .
Definition P2.1.11 (Kronecker delta). For integers and , the Kronecker delta is . So when and when , and .
Lean: Mathlib writes if i = j then 1 else 0, and Pi.single and Finsupp.single for the family ; Finset.sum_ite_eq evaluates (proved in Mathlib).
Example P2.1.12. For each integer the family has one term that can be nonzero, the term with . So , where the sum is over all integers in the sense of the definition of finite support below.
Example P2.1.13. The identity matrix is the matrix with entries for . Its trace is . The product of two matrices and has the entries , and with the identity this sum is .
Proposition P2.1.14 (algebra of brackets). For statements and :
- ;
- ;
- ;
- ;
- if and are never both true, then .
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 and , so it is enough to check the four cases. If and are both true, then rule 1 reads , rule 3 reads , and rule 2 reads . If is true and is false, rule 1 reads and rule 3 reads . The case with false and true is the same with the roles exchanged. If both are false, rule 1 reads , rule 2 reads and rule 3 reads . Rule 4 holds because and . Rule 5 is rule 3 with .
Definition P2.1.15 (sum with finite support). Let be a number for each integer and let be a relation. Suppose that only finitely many integers have true and . Then is the sum of over this finite set. The family has finite support on . When is true for all the sum is written . When is true for only finitely many , the new sum equals the sum of the definition above, since the terms that are left out are .
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 has coefficients for all integers , with for and for above the degree. For the coefficients are at , and . The sum over all integers has finite support.
Example P2.1.17. The relation is true for infinitely many , but the family is for outside the set . So . The convention holds since is not a multiple of .
Definition P2.1.18 (product). Let be a relation and numbers, and suppose that only finitely many with have . The product is the product of over this finite set, in any order. The product over an empty set is , the empty product. With limits, is for and for . 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 . The empty product gives , and the recursive step gives for . Section 2.1 uses these facts. The product of the positive divisors of is .
Example P2.1.20. For , . The factor is . For the product is empty and equals . If the claim holds for , then the product for is .
Proposition P2.1.21 (disjoint relations). Let and be relations that are never both true and that are each true for finitely many integers. Then and . The value for the empty sum is the only value that keeps the first rule true when is false for all , and the value 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 and be the finite sets where and are true. They are disjoint. Write as a list and as a list . The list contains every element of once. By the associative law its sum is , and by the lemma on the order of the terms this is the sum over . The same argument works for products. Now let be false for all and let be the value of the empty sum. The rule reads , so . For products, let be the value of the empty product, let be true at one integer only, with , and let be false for all integers. The rule reads , and division by gives .
Definition P2.1.22 (infinite sum). Let be a relation and numbers such that infinitely many have true and . Split the indices at . The sum is the number 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 , . This holds for , where both sides are , and the step from to adds to both sides, since . The limit is , so ; the negative part is empty. For the family over all integers, the negative part is , with limit . So .
Example P2.1.24. The sum has no value. Its partial sums are , and this sequence has no limit. A grouping of the terms as suggests , and a grouping as suggests . The definition refuses both, and P5 explains when a grouping is safe.
Proposition P2.1.25 (sums of nonnegative terms). Let for all with . Then has a value if and only if the finite subsums , over finite sets of integers with true, are bounded. In that case the value is the least upper bound of the finite subsums. So for every bijection from the set where is true onto the set where is true, , 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 and . 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 lies in the interval for some , so . Each is itself a finite subsum. So the finite subsums are bounded exactly when is bounded, that is, when both and are bounded. Then the least upper bound of the finite subsums is . For the last claim, maps the finite subsets where is true one to one onto the finite subsets where 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.
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 with that are divisible by or by is . Rule 3 of the algebra of brackets and rule 1 with give A direct count by computer gives too.
Example P2.1.27 (divisors). The number of positive divisors of is . The second form has limits, and the bracket keeps the divisors. For the bracket is at and the sum is . The sum of the divisors is , which is for .
Example P2.1.28 (a sum over all integers). The family has finite support: the bracket is only for . So . The bracket gives a clear meaning to the sum over all integers, and it is not needed to state the range of in the sum sign.
Example P2.1.29 (an index that is not an integer). The relation can run over any set. Let be " is a subset of ". Then , 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
- [10] Compute , and .
- [15] Compute with the algebra of brackets.
- [M15] Prove that .
- [M18] Write as a sum with limits and a bracket, and compute it.
- [M20] Decide which of the families , and , over all integers , have finite support, and compute and .
- [M20] Let and let be true for finitely many . Prove that , and use to find .
- [M20] Prove that for , and that .
- [M22] Prove that for , and find over all integers .
- [HM26] Let for and . Show that for every , but that 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 is ∑ k ∈ Finset.range n, a k, and 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 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 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 , 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 , . For two families,
Lean: Mathlib Finset.mul_sum, Finset.sum_mul and Finset.sum_mul_sum (proved in Mathlib).
Proof. Let be the finite set where is true, and use induction on its size . For both sides of the first claim are , since . For take one element of . By the proposition on disjoint relations in Section 1.1, . So by the distributive law for two terms, and the induction hypothesis turns the first term into . The sum of the two terms is . For the second claim let . The first claim, used twice, gives .
Theorem P2.1.31 (sum of two families). .
Lean: Mathlib Finset.sum_add_distrib (proved in Mathlib).
Proof. Use induction on the size of the set where is true. For all three sums are . For take and let . Then . By the induction hypothesis this is . The laws of addition for two terms reorder this as .
Theorem P2.1.32 (change of variable). Let be a bijection from the set of integers with true onto the set of integers with true. Then
Lean: Mathlib Finset.sum_nbij' (with an explicit inverse), Finset.sum_bij' and Finset.sum_equiv (proved in Mathlib).
Proof. Let list the set where is true, each element once. Since is a bijection, the list contains every integer with true exactly once. By the definition of the sum over a relation, , and the right side is by the same definition.
Corollary P2.1.33 (shift and reflection). For each integer , . With limits, and .
Lean: Mathlib Finset.sum_Ico_add and Finset.sum_range_reflect (proved in Mathlib).
Proof. The maps and are bijections of the integers, with inverses and . Each maps the set where , or , is true onto the set where is true. The theorem on the change of variable gives the first two equations. For the forms with limits, take to be . The relation is , and the shift by gives the third equation. The relation is , and the reflection with gives the fourth.
Proposition P2.1.34 (sums with the bracket). If the family has finite support on , then If is a bijection of the integers onto the integers, then .
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 is when is true and otherwise. So the family has finite support on all integers, its nonzero terms are the nonzero terms with 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 , over the finite set where , with the bijection from onto . Then , and .
Theorem P2.1.35 (interchange of the order). For numbers ,
Lean: Mathlib Finset.sum_comm (proved in Mathlib).
Proof. Use induction on the size of the set where is true. For each inner sum on the left is empty, so the left side is , and the right side is an empty sum. For take and let . The left side is . The theorem on the sum of two families splits it as . By the induction hypothesis the first part is , and adding the term for gives .
Corollary P2.1.36 (interchange in a triangle). For ,
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 the inner sum on the left is , since the bracket removes the terms with . So the left side is , a sum over a square. The theorem on the interchange of the order turns it into . For the inner sum is .
Theorem P2.1.37 (change of the domain). For two relations and ,
Lean: Mathlib Finset.sum_union_inter (proved in Mathlib).
Proof. Rules 1 and 3 of the algebra of brackets of Section 1.1 give for each . Multiply by and sum over all . 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.
Corollary P2.1.38 (overlapping ranges). For integers ,
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 to be and to be . Since , the relation " or " is , and the relation " and " is . The theorem on the change of the domain gives the claim.
Theorem P2.1.39 (laws for products). Let the relations be true for finitely many integers. Then where is a bijection as in the theorem on the change of variable, and For an integer , .
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 and the induction on the number of terms. Multiplication has the same laws, and the empty product is . 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 and be the sets where and are true. The set is the disjoint union of and , and is the disjoint union of and . The proposition on disjoint relations of Section 1.1 gives . The last claim is the first equation used times, by induction on ; for both sides are .
Theorem P2.1.40 (telescoping sum). Let be a function on the integers and let . Then If for , then .
Lean: Mathlib Finset.sum_range_sub and Finset.prod_range_div (proved in Mathlib, for the range to ).
Proof. Use induction on , starting at . For the sum is empty and the right side is . For the step from to , the recursive definition of the sum with limits adds the term to the left side. The right side becomes . The proof for products is the same, with .
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 and . 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 , with . So For this gives , which agrees.
Example P2.1.42 (factorials). For , . So . For the sum is .
Example P2.1.43 (reflection). Let . The reflection maps the range onto itself, and it changes the term into . So , and . No formula for is needed.
Example P2.1.44 (a product that telescopes). For , The first step is the law , and each product on the right telescopes, with and after a shift of the index. For the product is .
Example P2.1.45 (an interchange that helps). The sum has an inner sum with no closed form. The corollary on the interchange in a triangle, read from right to left, changes it into . The inner sum is now , so the whole sum is .
Exercises
- [M15] Prove that for .
- [M18] Find a closed form for .
- [M20] Prove that for .
- [M20] Let for . Prove that .
- [M20] Evaluate for , and find its limit as .
- [M22] Prove the rule for three relations: , where the index is left out of the relations.
- [M22] Prove that for .
- [M22] The map maps onto . Show that in general. Then prove that for every map from the set where is true into the set where is true, , where is the number of with and .
- [M20] Use the interchange in a triangle to evaluate .
- [M20] Let be numbers. Prove that there is a function on the integers with for all , and that two such functions differ by a constant.
- [M25] Use a telescoping sum with to evaluate , and then find 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 , which TAOCP uses for partitions.
Definition P2.1.46 (multiple sum). Let be a relation on pairs of integers that is true for finitely many pairs, and let be numbers. The double sum is the sum of over the finite set of pairs where is true, as in the definition of the sum over a relation of Section 1.1. In the same way a relation on lists gives a multiple sum. The bracket form is .
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 runs over the pairs , and . Its value is . The sum counts the pairs in a square and is .
Example P2.1.48. The sum runs over the five pairs . It is , the coefficient of in the product of the polynomials and .
Proposition P2.1.49 (iterated sums). If is true for finitely many pairs, then 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 be the finite set of pairs where is true, and let be the finite set of first coordinates of pairs in . For let be the set of pairs in with first coordinate . The sets are disjoint and their union is . The proposition on disjoint relations of Section 1.1, with an induction on the size of , gives . The inner sum is , and for this sum is . This proves the first equation. The same argument with the second coordinate proves the second one.
Theorem P2.1.50 (general change of the order). Let , , and be relations such that for all integers and , and suppose that this bracket is for finitely many pairs. Then The relations : "there is an with and ", and : " and ", 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 . The distributive law moves inside, so the left side is . The hypothesis changes the bracket product into . The proposition on iterated sums exchanges the two sums, and the same two steps in reverse give . For the last claim, if and are both true, then and are both true, and both sides of the condition are . If one of , is false, then is false and both sides are .
Corollary P2.1.51 (sums along diagonals). For ,
Lean: Mathlib Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk gives the inner sum over the diagonal (proved in Mathlib).
Proof. The left side is the sum of over the pairs with and . The map with is a bijection from this set onto the set of pairs with ; its inverse is . The theorem on the change of variable of Section 1.2, applied to pairs, turns the sum into . The general change of the order, with : , : , : and : , gives the right side. The condition holds, since both bracket products are .
Definition P2.1.52 (symmetric family). A family , for , is symmetric if for all and .
Lean: Mathlib Matrix.IsSymm for a matrix with .
Example P2.1.53. The family is symmetric, and so is and . The family is not symmetric when , since and .
Example P2.1.54. For numbers , the family is symmetric. Its sum over the square is , 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 , ,
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 , and . Each pair in the square has exactly one of , and , so the sum over the square is , by the proposition on disjoint relations. The map is a bijection from the pairs with onto the pairs with . By the change of variable and the symmetry, . So the square is , which gives the first formula. The second sum is , which gives the second formula.
Theorem P2.1.56 (square of a sum). For numbers ,
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 is symmetric, its sum over the square is , and its diagonal sum is . The proposition on symmetric sums, with the indices to in place of to , gives both formulas; the sums over and are the sums over and with the names of the indices exchanged.
Definition P2.1.57 (sums over the solutions of an equation). Let and . The sum , with the condition understood, runs over all lists of nonnegative integers with sum . With the extra condition it runs over the partitions of into at most parts. A partition of is a list with sum ; its parts are its nonzero entries.
Lean: Mathlib Finset.Nat.antidiagonalTuple m n is the Finset of lists of natural numbers with sum , and Nat.Partition n is the type of partitions of (proved in Mathlib to be finite, with Fintype).
Example P2.1.58. For the sum is , the coefficient of in a product of two polynomials. For and the lists are , , , , and , six in all.
Example P2.1.59. The partitions of in the form are , , , and . So , the number of partitions of .
Proposition P2.1.60 (number of solutions). For and the number of lists of nonnegative integers with is .
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 from elements, which is the same count in another form: is the number of copies of element .
Proof. Write a list as a row of symbols: stars, a bar, stars, a bar, and so on, with bars in all. The row has stars and bars. Each row of stars and bars comes from exactly one list: is the number of stars before the first bar, is the number between bar and bar , and is the number after the last bar. So the lists correspond one to one to the choices of the places of the bars among places, and there are such choices.
Proposition P2.1.61 (two forms of a partition). Let . For a partition of and , let be the number of indices with . The map is a bijection from the partitions of onto the lists of nonnegative integers with . So for every function ,
Lean: Mathlib Nat.Partition stores a partition as a multiset of parts, and Multiset.count r gives ; the bijection is not stated in this form.
Proof. The map lands in the right set. Every entry lies between and , and the entries with add nothing, so grouping the indices by the value gives . The map has an inverse. Given with , form the list that has entries equal to , then entries equal to , and so on down to entries equal to , and then zeros. The number of nonzero entries is , so zeros fill the list to length . This list is nonincreasing and has sum , and its value counts are . 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.
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 and .
The general change of the order is then three lines. The hard part in an application is to find and . The method is always the same: write the condition " and " as a chain of inequalities, and solve the chain for with fixed. The relation is the condition on for the solution set to be nonempty, and 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 is symmetric. The proposition on symmetric sums gives the number of pairs with as , and the number with as . No formula for is used.
Example P2.1.63 (products of pairs). The theorem on the square of a sum gives . Section 2.2 proves and . With these values the sum is For this is , which agrees with the example after the definition of the multiple sum.
Example P2.1.64 (divisors, counted twice). Let be the number of positive divisors of . Then . Take : and : , with . The condition " and " means that is a multiple of in the range to . Such an exists exactly when . So is and is " and ", and since the multiples of in the range are . Chapter 4 treats the floor function. For both sides are : on the left , on the right .
Example P2.1.65 (a product of polynomials). Let and . By the distributive law, . For the terms with all have , and the corollary on sums along diagonals collects them: the coefficient of is . With all the coefficient is for .
Exercises
- [M15] Compute from the theorem on the square of a sum, and check the value by a list of the six terms.
- [M20] Let be positive. Prove that .
- [M22] Prove that .
- [M20] Prove that , and compute the value for .
- [M22] List the partitions of in the form of the proposition on the two forms of a partition, and find the number of all lists of nonnegative integers with sum .
- [M25] Change the order of summation in , so that the outer sum runs over .
- [M25] Let for , for , and otherwise, for . Show that and . Which hypothesis of the theorem on the interchange of the order fails?
- [M25] Prove the identity of Lagrange, for real numbers, and deduce the inequality of Cauchy for sums.
- [M20] Prove that , where is the sum of the positive divisors of , and check it for .
- [M28] Let be the number of partitions of , with . Prove that the total number of parts equal to , over all partitions of , is . Check the claim for .
- [M30] Let . Prove that .
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 in the language of sets.
The diagonals 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 natural numbers with sum are Finset.Nat.antidiagonalTuple m n, and the partitions of 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 , 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 , 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.