Volume C1 · Basic concepts · TAOCP Section 1.2.5
Permutations and factorials
Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.
Read it next to Section 1.2.5 of the book. The nodes and the exercises of the section.
Contents
Permutations and factorials
Overview
Section 1.2.5 of TAOCP counts the ways to put distinct objects in a row, and it names the answer . It builds the permutations of objects from those of objects in two ways, and it states the first facts about : how large it is (Stirling's formula), which primes divide it and how often (Legendre's rule), and what could mean when is not an integer. It uses the sum as a model of a function that has an easy extension. It then looks at two series of Stirling that fail or may succeed as definitions of , and at the limit of Euler that succeeds. From Euler's limit it takes the gamma function, the reflection formula and the contour integral of Hankel. It ends with the falling and rising powers and , which the rest of the book uses all the time. The section uses the product and sum notation of Section 1.2.3 and the floor function of Section 1.2.4. It uses the exponential function and the number of Section 1.2.2. Its proofs of Stirling's formula and of the series (11) and (12) need the binomial coefficients of Section 1.2.6, and this chapter says where.
The ideas
To count orders, choose the places one at a time. There are choices for the first place, for the second, and so on. The count does not depend on which objects stand in the earlier places, only on how many are left. This is why the count is a product , and why it is when you try to fill more places than you have objects.
A construction by induction is a proof of a count. If each order of objects gives exactly orders of objects, and each order of objects comes from exactly one order of objects, then the count of objects is times the count of . The section gives two such constructions: insert the largest object in one of places, or add a new last element and rename. They give the same count but different lists, and different programs use different lists.
Rapid growth is the main property of . The number is about where a search over all orders stops being practical. Stirling's formula says how fast the growth is: is close to , and the relative error is about .
The prime factors of come from counting multiples. A prime divides once for each multiple of in , one more time for each multiple of , and so on. This is Legendre's rule, eq. (8).
An easy rule can fail to extend. The value has no meaning from the product (4). The sum shows the problem on a small case: the formula extends the sum to every real , but the extension is a choice, because many functions agree with a sum on the integers. For the choice must keep the rule and must be smooth in a sense that the section makes precise only by examples. The extension that works is Euler's limit (13), which defines the gamma function.
Falling and rising powers are the products that counting gives. The count of eq. (2) is a falling power, and it is a polynomial in for each fixed . Its twin with plus signs is the rising power. Section 1.2.6 and later sections write sums and series in these powers, because they behave under differences as ordinary powers behave under derivatives.
C1 does some things in a different order from the book. It proves the count of -permutations first by the product rule, then by induction, and it proves Stirling's formula in full with two monotone sequences and Wallis's product, a route that differs from the proof of Section 1.2.11.2. It proves Stirling's series (11) by counting permutations that move exactly elements, which the book defers to Section 1.2.6. It proves the reflection formula (16) and Hankel's integral (17) from the product (15), so that the reader sees one thread from (13) to (17).
Definitions, results and proofs
Definition (a permutation and a -permutation, TAOCP Section 1.2.5). Put distinct objects in a row, each of them once: the row is a permutation of the objects. For , a -permutation of the objects is an arrangement in a row of of them, chosen from the . A permutation of objects is an -permutation.
Node: TASWXB1M5H · Lean: Equiv.Perm, from Mathlib · status: not stated yet
Explanation. Order matters and no object is used twice. The objects can be letters, numbers or anything else, and only their number counts. Two arrangements are the same if each place holds the same object. In Lean, a permutation of a type α is an element of Equiv.Perm α, a bijection of α with itself, and a list of the objects in a row corresponds to the values of this bijection on . A -permutation corresponds to an injective function from to the set of objects, a term of Fin k ↪ α, from Mathlib. The two views are the same, since the row is the function .
Example. The set has permutations. Its -permutations are , which are in all. The set has one -permutation, the empty row. The set has no -permutation, since a row of three distinct objects needs three objects.
Example (the six orders of three letters, TAOCP eq. 1.2.5(1)). The permutations of are .
Node: TADVJN5M00 · Lean: TAOCP.S1_2_5.eq1 · status: proved
Explanation. The list is the whole set, in the order of the alphabet. It has six terms. A reader can see why: , or leads, and the other two letters can follow in two orders. The list is the smallest case where the structure of the count shows. For the two orders and do not tell much, and for the list has terms and it is easy to lose one.
Example. The six rows, sorted as in the alphabet, are the six outputs of the Python call itertools.permutations('abc'). The same call on four letters gives rows, of which six start with , six with , six with and six with . This is the first sign of the count .
Theorem (the number of -permutations, TAOCP eq. 1.2.5(2)). Let be the number of -permutations of objects. For each the count is the product below. For it counts the permutations of objects, and for the product is , which is also the right count:
Node: TA5084B8HM · Lean: TAOCP.S1_2_5.eq2, TAOCP.S1_2_5.card_perm · status: proved
Explanation. A -permutation is made place by place. The first place gets any of the objects. The second place gets any object that is not in the first, so are left. After places are full, objects are left for the next place. The count of the choices is the product of these numbers. The formula is a polynomial of degree in , and Section 1.2.5 gives this polynomial a name in eq. (18). In Lean, Nat.descFactorial n k is this product, and for k > n it is since a factor is for . Mathlib states the count of injective functions as Fintype.card_embedding_eq, and the count of permutations as Fintype.card_perm.
Example. A club has members and wants a chair, a secretary and a treasurer, all different. The number of ways is . A computer check with math.perm(5, 3) gives . For all five members in a row, . For the product has the factor and the count is .
Proof. The proof is by induction on , for fixed . For there is exactly one -permutation, the empty row, and the product with no factor is . Suppose that for some with . Each -permutation is a -permutation (its first places) followed by one more object that is not among those . For each -permutation there are exactly such objects. So the map that cuts off the last place sends the set of -permutations onto the set of -permutations, and each -permutation has exactly preimages. Then . For the same argument holds if the number of objects that are left is read as , and the product has the factor from on.
Example (the six orders of three numbers, and two ways to go up one size, TAOCP eq. 1.2.5(3)). The permutations of are . There are two methods that build the permutations of from those of .
Node: TA2BNR00CJ · Lean: TAOCP.S1_2_5.eq3, TAOCP.S1_2_5.card_perm_succ · status: proved
Explanation. The relabeling to numbers is only to make the constructions work with order. The two methods make new permutations from each old one.
Method 1 (insert the largest). From , insert the number in each of the places: before , between two neighbors, or after . Method 2 (add a last element and rename). From and a number with , add to each that is at least , and put at the right end. The first step makes a permutation of and the last step fills the gap. The pseudocode of the two methods is as follows.
Method1(a, n): -- a is a permutation of 1..n-1
for i := 0 to n-1:
yield a[1..i] ++ [n] ++ a[i+1..n-1]
Method2(a, n):
for k := 1 to n:
b := [ (x >= k ? x+1 : x) for x in a ]
yield b ++ [k]
A worked run. Take and .
| or | Method 1 result | Method 2 result |
|---|---|---|
| 0 or 1 | ||
| 1 or 2 | ||
| 2 or 3 | ||
| 3 or 4 |
Each method gives four permutations of . The list of Method 2 for : the numbers with raised by become , and then is added at the end: .
Why each method gives every permutation once. Take a permutation of . In Method 1, comes from the permutation that is with the entry removed, and from no other. The place of in tells which of the insertions made it. In Method 2, comes from the permutation made of with each entry larger than lowered by , together with . Both inverse maps are well defined, so each method is a bijection from {permutations of } { choices} onto {permutations of }. Hence the count satisfies .
Example. With and the single permutation of two numbers, Method 1 gives and Method 2 gives . Do the same for and the six rows of the list above appear, with no repetition.
Definition (the factorial, TAOCP eq. 1.2.5(4)). For a positive integer ,
Node: TAE960YGFQ · Lean: TAOCP.S1_2_5.eq4 · status: proved
Explanation. The number , read " factorial", counts the orders of objects, so it equals . The two products and are the same by the commutative law of multiplication. In Lean, Nat.factorial n, written n !, is defined by 0! = 1 and (n+1)! = (n+1) * n!. The product form of eq. (4) is a theorem there (Finset.prod_range_add_one_eq_factorial).
Example. The first values are , , , , , , , , , . The number has decimal digits and begins with the digits .
Proof of the digit count. The number of decimal digits of is . A sum of logarithms gives , so the number has digits. The leading digits come from the fractional part: .
Definition (the factorial of zero, TAOCP eq. 1.2.5(5)). .
Node: TA2HWE9VM8 · Lean: TAOCP.S1_2_5.eq5 · status: proved
Explanation. The product of zero factors is by the convention for empty products (Section 1.2.3). The convention is also the right count: a set with no objects has exactly one arrangement, the empty row. The value keeps the formula true for , and the formula of eq. (21), , true for . The same convention gives in Section 1.2.6.
Example. For and , . If were the formula would break, and if it were any number other than the count would be wrong.
Theorem (the recursion of the factorial, TAOCP eq. 1.2.5(6)). For each positive integer ,
Node: TA2MWKDW86 · Lean: TAOCP.S1_2_5.eq6 · status: proved
Explanation. This is the rule behind both methods of building permutations: each permutation of objects makes permutations of objects. It is also the single rule that, with , fixes the factorials of all nonnegative integers. Later in the section the same rule, of eq. (14), is the one that the extension to real numbers must keep. In Lean it is Nat.factorial_succ n : (n + 1)! = (n + 1) * n !, with the index shifted by one.
Example. and .
Proof. For the claim is , which is by eq. (5). For , split off the last factor of the product (4): .
Theorem (Stirling's approximation, TAOCP eq. 1.2.5(7)). For each ,
Node: TAX5X8WQPJ · Lean: TAOCP.S1_2_5.eq7 (partial) · status: proved
Explanation. The bound says that the ratio of to tends to as . This limit is the meaning of the sign in the formula of eq. (7). The formula says that is about times . The factor is the main growth. The factor is a correction of lower order. The sharper bound shows that the ratio exceeds by less than , which is a little more than : the bound is for and for , and the true excess is and . In practice the formula is used in the form , which turns a product into a sum that can be added. The book proves (7) in Section 1.2.11.2 and gives a cruder bound in exercise 24. In Lean, Mathlib has the statement as a limit: Stirling.stirlingSeq n is and Stirling.tendsto_stirlingSeq_sqrt_pi says that it tends to , which is the same claim, since .
Example. The table compares with the formula.
| ratio | ||||
|---|---|---|---|---|
| 5 | 120 | 118.019 | 1.01678 | 1.01667 |
| 6 | 720 | 710.078 | 1.01397 | 1.01389 |
| 10 | 3628800 | 3598695.619 | 1.00837 | 1.00833 |
| 20 | 2432902008176640000 | 1.00418 | 1.00417 |
For the formula gives against , so it is low by about . The last two columns show that the ratio is close to , and the proof below gives the bound.
Proof. The plan has three parts: the sequence has a limit with , and by Wallis's product. This proof is not the proof of Section 1.2.11.2.
Part 1: the sequence decreases. From , So . Put . Then and . The series holds for , so All terms are positive, so . Also each term is at most the term of , so
Part 2: the limit exists. The sequence decreases. The sequence increases, since by the bound of Part 1. Then , so is bounded below by . A decreasing sequence that is bounded below has a limit . The limit of is also , because . Since decreases strictly to , each . Since increases strictly to , each , that is .
Part 3: the value of . Let . Integration by parts gives , with and . So and . Since , the sequence decreases, so . Thus , which says Now , and in terms of this is (because and , and the powers of cancel). Let : , so . Comparing with the first limit, , so .
The strict form. With , the bound is the claim . The ratio to the formula is always greater than , as the table shows.
Theorem (the exponent of a prime in , Legendre's rule, TAOCP eq. 1.2.5(8)). Let be a prime and . The largest with is
Node: TABMAWKDEM · Lean: TAOCP.S1_2_5.eq8, TAOCP.S1_2_5.eq8_padic · status: proved
Explanation. The sum is written as an infinite sum, but it has finitely many nonzero terms, since as soon as . Each term can come from the one before it by an integer division, since (Section 1.2.4). This gives a fast way to find : divide by , throw away the remainder, add the quotient to a sum, and repeat with the quotient. Mathlib states the rule as Nat.Prime.emultiplicity_factorial, with the sum on a finite range Finset.Ico 1 b for any larger than .
Example. For and : , , and , so . That is why ends in exactly zeros: , so there are pairs . For all the exponents are
| 2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 | |
|---|---|---|---|---|---|---|---|---|---|
| 22 | 10 | 6 | 3 | 2 | 1 | 1 | 1 | 1 |
so . A run of a short program confirms the product.
Proof. Fix . The number of that are multiples of is . Let be the exponent of in , that is the largest with . Then is a multiple of exactly when , so is counted in the term of the sum for each from to , and in no other term. Hence is counted times in all, and The exponent of in the product is the sum of the exponents of in the factors, which is . For the shortcut, let . For an integer , is equivalent to , and since is an integer this is equivalent to , that is . So , which is the claim.
A closed form with the digits of . If with , then , and summing over gives , where is the sum of the digits. For and the digits are and , as before.
Definition (the termial, TAOCP eq. 1.2.5(9)). For a positive integer the termial of is
Node: TAV952E1A7 · Lean: TAOCP.S1_2_5.termial · status: not stated yet
Explanation. The name is the book's own, and it is a game: the termial is to the sum what the factorial is to the product. It is useful as a laboratory. The sum has a closed form, which extends to all real at once, and the question of what should mean for non-integers is easier to see with this model first. Mathlib does not name the termial, but Finset.sum_range_id_mul_two n : (∑ i ∈ range n, i) * 2 = n * (n - 1) is its closed form, with the sum over (use for ).
Example. , , , , , and each is .
Theorem (the closed form of the termial, TAOCP eq. 1.2.5(10)). For each positive integer , The right side defines for each real , and then for all real .
Node: TA3MNK0ZC3 · Lean: TAOCP.S1_2_5.eq10, TAOCP.S1_2_5.termialReal (partial) · status: proved
Explanation. The formula is the arithmetic series of Section 1.2.3 (that section's eq. (15)). The book uses it to show how an extension of a function from the integers to the reals can be found: pick a formula that holds for integers and that makes sense for real arguments. For the termial this is easy and the extension is polynomial. The identity is the analogue of , and it is the rule that the extension keeps.
Example. For : . The recursion checks: . For the formula gives .
Proof. Write and . Add the two rows place by place: each of the places sums to , so . For the recursion, for real , .
The extension of a function from to the reals is not unique: the function also satisfies the recursion and agrees with at the integers. For the termial the polynomial is the natural choice. For the book looks for the analogous natural choice, and the next four equations show what fails and what works.
Theorem (a series for that fails as a definition, Stirling's series, TAOCP eq. 1.2.5(11)). Let . For each nonnegative integer the sum below has finitely many nonzero terms and the equation holds. For each that is not a nonnegative integer, the series does not converge:
Node: TATD2K1CQE · status: not stated yet
Explanation. Each term is a falling power times a constant, so for an integer the term is when , and the sum has terms. This looks like a good formula for that makes sense for other , but it is not: at a non-integer no falling power is , and the terms do not tend to . The coefficient is the partial sum of the series of , so , and counts the permutations of objects that leave no object in its place (the derangements). The book states (11) and defers the proof to Section 1.2.6; the proof below is by counting and does not need that section.
Example. For the coefficients are , , , , , and . The terms are and their sum is . For the terms are and the sum is . For the terms are , and the term for is : they grow and the sum does not exist.
Proof of the formula for an integer . Let . By induction on , and , because . The first values are . Next, counts the permutations of that fix no point. By the rule of inclusion and exclusion, the number of permutations that fix none of the points is , because the sum over a set of points that are fixed counts permutations. Now count all permutations of by the set of the points that they move (the points that are not fixed). A set with occurs for exactly permutations, since the permutation is the identity outside and a permutation of without a fixed point inside . There are sets of size , so Here is the number of subsets of size (Section 1.2.6) and is the count of eq. (2) for the ordered choices of points. The proof uses no result that depends on eq. (11).
Proof of the divergence. Suppose that is not a nonnegative integer. Then for each , so for all , and . Since , the terms satisfy . A series whose terms do not tend to does not converge. Here is eventually increasing, so it does not tend to .
Theorem (a series for , TAOCP eq. 1.2.5(12)). There is exactly one sequence of real numbers for which the equation below holds for each nonnegative integer . It is .
Node: TAKJDAFN4G · status: not stated yet
Explanation. This is Stirling's second attempt. The series is the expansion of in falling powers, in the form that Newton found for any function: each term has a constant made from the differences of . At an integer the sum is finite, so it equals for trivial reasons. The hard part is not in the theorem above: it is the claim that the series also converges at non-integers and gives of the right value. Stirling could not prove this. Hermite proved it in 1900 (the book cites this). C1 does not prove Hermite's theorem, and the book does not either. What C1 proves is that the coefficients are forced, so the question has no choice in it. The first coefficients are , , , and .
Example. For : for and after. The sum is about , and (the exact coefficients give the same digits). For : gives as above.
Proof. Let for and let . Let be the shift, , so . The operators and commute, so the binomial theorem holds for : . Apply this to at : . Likewise , so . Since and , the formula holds with , which is the stated value. For uniqueness, suppose that equals for each integer . At only is nonzero in the sum, so . At each next , the term is the only one that is new, and , so is fixed by and the .
Definition (the factorial as Euler's limit, TAOCP eq. 1.2.5(13)). For each real or complex number that is not a negative integer, the limit below exists, and it is the value of . For a negative integer the denominator contains the factor for large , and the value is taken to be infinite.
Node: TAXD28BRRQ · Lean: TAOCP.S1_2_5.eq13 (partial) · status: proved
Explanation. This is the extension that works. It is built from one idea: the ratio is a product of factors that are each about when is large, so for integer . Solving for gives the form of the limit. For an integer the product is and the limit reduces to by an exact calculation. For a non-integer the same formula is used as a definition, and the convergence has to be proved. Mathlib states the limit in the form of eq. (15): Real.GammaSeq s m is the quotient of (15) with , and Real.GammaSeq_tendsto_Gamma says that it tends to Real.Gamma s. At that quotient is the quotient of (13) times , a factor that tends to . Exercises 8 and 22 of the book explain why (13) is a reasonable choice.
Example. For the quotient is , which is for , for and for , so it tends to . For the quotient for is , and .
Proof that the limit is for integer . The product is , so the quotient equals Each of the factors tends to , so the product tends to and the limit is .
Proof that the limit exists for each real that is not a negative integer. The same proof works for complex with the principal values of the powers. Write . Since (the product telescopes to ), and , The first factor tends to . The factors of the product are with . For , Taylor expansion of the two logarithms gives and , so with a constant that depends on only. The series converges, so the series of the logarithms converges absolutely, and the partial products converge to a nonzero limit (no factor is zero since is not a negative integer).
Theorem (the gamma function and the factorial, TAOCP eq. 1.2.5(14)). For each that is not a negative integer,
Node: TAT6P5YAK2 · Lean: TAOCP.S1_2_5.eq14, TAOCP.S1_2_5.eq14_factorial (partial) · status: proved
Explanation. This is a change of notation due to Legendre. The function is the factorial moved one step to the left. It is neater in many formulas, for instance in those with and in the integral . The identity is the rule for real . In Mathlib, Real.Gamma_add_one says Real.Gamma (s + 1) = s * Real.Gamma s for s ≠ 0, and Real.Gamma_nat_eq_factorial says Real.Gamma (n + 1) = n !.
Example. , and . So , the value that Stirling found.
Proof. Let be the quantity of eq. (15), so . Then . The first factor tends to by (13) and the second tends to , so . For the recursion, , since . Let to get .
Definition (the gamma function as a limit, TAOCP eq. 1.2.5(15)). For not zero and not a negative integer,
Node: TAN3FDZEVK · Lean: TAOCP.S1_2_5.eq15 (partial) · status: proved
Explanation. This is (13) with a different bookkeeping: the factor moves from the numerator to the denominator, so that the quotient has a pole at and at each negative integer, where one denominator factor is . The graph of on the real line has a pole at each of and a single minimum for , at where (the book's Fig. 7). In Mathlib, Real.Gamma is defined by the integral for and by the functional equation for the rest, and it agrees with the limit by Real.GammaSeq_tendsto_Gamma.
Example. . For the quantity is , for it is and for it is , which tends to .
Proof. Divide the formula (13) by . Since and , the limit of is . The quantity under the limit is .
Remark (an integral form). For , . Indeed, by integrations by parts, . The substitution gives . Since and , the theorem of dominated convergence gives for (exercises 19 and 20 of the book). This integral is the form in which Mathlib defines , and the next two proofs use it.
Theorem (the reflection formula, TAOCP eq. 1.2.5(16)). For each that is not an integer,
Node: TAAPFX3WDA · Lean: TAOCP.S1_2_5.eq16 (partial) · status: proved
Explanation. Since , the formula says . It links the values at and at . It shows that never takes the value (the right side is never ), and it gives the value at once. It is the tool that makes an entire function (exercise 1.2.7-24 of the book). In Mathlib it is Complex.Gamma_mul_Gamma_one_sub (z : ℂ) : Gamma z * Gamma (1 - z) = π / sin (π * z).
Example. For : , so (the root is positive since for by the integral). Then . For : , and a numerical check gives , , whose product is .
Proof. The proof uses the product formula of Euler for the sine, (the book gives it in exercise 23 as a known fact, and C1 takes it as the input). By (15) with and by (13) with , the product of the two limits is the limit of the product: The powers and cancel. The denominator is . Divide numerator and denominator by : the quotient is . As this tends to .
Theorem (Hankel's contour integral for , TAOCP eq. 1.2.5(17)). Let the path of integration come from below the negative real axis, go counterclockwise around the origin, and return to above the negative real axis, and let have its principal value. Then for each complex ,
Node: TAZDRQAGCW · status: not stated yet
Explanation. The formula holds at each , also where is infinite: there . The integral converges for each because decays like on the two branches to , and it is an analytic function of with no poles. So is an entire function. Hankel's formula is used when a proof needs itself, without the poles of .
Example. For the integrand has no branch cut, so the two infinite branches cancel and the path is a closed circle around . By the residue theorem the integral is times the coefficient of in , which is . So the right side is . For and each negative integer, is entire, the closed path gives , and , as it must.
Proof. Take first. Shrink the path to the two sides of the negative real axis and a small circle of radius . On the circle and its length is , so its contribution is . On the lower side with from to , so , and . This part gives . On the upper side with from to , which gives . The sum is . Divide by and use (16): . Both sides are entire functions of (the integral is entire since the integrand is entire in and the convergence is uniform on compact sets), and they agree on the half plane , so they agree everywhere by the identity theorem.
Definition (the falling power, TAOCP eq. 1.2.5(18)). For a positive integer and any , the falling power , read " to the falling", is the product below. By the convention for empty products .
Node: TAYMSEK4R4 · Lean: TAOCP.fallingPow, TAOCP.S1_2_5.eq18 · status: proved
Explanation. The falling power is the product of factors that start at and fall by each time. It is a polynomial in of degree . The number of eq. (2) is , and . In Lean, TAOCP.fallingPow x k is the value of descPochhammer R k at , for in any ring. For natural numbers it agrees with Nat.descFactorial n k of Mathlib, by TAOCP.fallingPow_natCast.
Example. . For a non-integer: and . For with a natural number, .
Definition (the rising power, TAOCP eq. 1.2.5(19)). For a positive integer and any , the rising power , read " to the rising", is the product below, and .
Node: TAHQZSJ0KG · Lean: TAOCP.risingPow, TAOCP.S1_2_5.eq19 · status: proved
Explanation. The rising power has the same factors but they grow. Like the falling power, it is a polynomial of degree in . It also counts: for a positive integer , the number is the number of multisets of size whose elements come from kinds. In Lean, TAOCP.risingPow x k is the value of ascPochhammer R k at . In Mathlib, Nat.ascFactorial n k equals in the current convention (earlier versions started at ), and TAOCP.risingPow_natCast links the two.
Example. , and .
Theorem (falling and rising powers are related, TAOCP eq. 1.2.5(20)). For each integer and each ,
Node: TAEYMGYQSX · Lean: TAOCP.fallingPow_eq_risingPow, TAOCP.S1_2_5.eq20_left, TAOCP.S1_2_5.eq20_right · status: not stated yet
Explanation. Two reductions follow. A rising power is a falling power that starts at the other end, and it is a falling power of with a sign. So each result about one kind gives a result about the other. In Lean, TAOCP.fallingPow_eq_risingPow x k : fallingPow x k = risingPow (x - k + 1) k is the first equality with replaced by , and TAOCP.risingPow_neg x k : risingPow (-x) k = (-1) ^ k * fallingPow x k is the second with replaced by . For natural numbers Mathlib has Nat.add_descFactorial_eq_ascFactorial' (n k : ℕ) : (n + k - 1).descFactorial k = n.ascFactorial k.
Example. With , : , and . With , all three expressions equal .
Proof. The factors of are . List them from the last to the first: . This is the product , which is . For the second equality, the factor equals , so .
Theorem (falling and rising powers by factorials and gamma, TAOCP eq. 1.2.5(21)). Whenever the quotients are defined,
Node: TA2Z3K9STM · Lean: TAOCP.risingPow_eq_Gamma_div, TAOCP.S1_2_5.eq21_falling, TAOCP.S1_2_5.eq21_rising · status: not stated yet
Explanation. The right sides make sense for each for which the two gamma values exist, so they define and for non-integer too. This is the use that the book suggests. The conditions are that and are not poles (are not nonpositive integers) for the first formula, and the same for and in the second. In Lean, TAOCP.risingPow_eq_Gamma_div states the second formula for real that is not or a negative integer. For natural numbers, Nat.descFactorial_eq_div (h : k ≤ n) : n.descFactorial k = n ! / (n - k)! is the first formula, and Nat.ascFactorial_eq_div (n k : ℕ) : (n + 1).ascFactorial k = (n + k)! / n ! is the second with .
Example. For , : . For , : , which is . For the rising power with , : .
Proof. Apply the rule of (14) times: . Dividing by gives the first formula, and by (14). Likewise , and dividing by gives . The use of the rule stops short of a pole because the quotients are defined.
A law of exponents for the falling powers. For nonnegative integers and , . The factors of are ; the first are and the last start at . For , , both sides are . This is not the law : the second factor is shifted. For the rising powers the law is .
Algorithms and programs
The section has no algorithm and no program. Its two constructions of permutations (Method 1 and Method 2) and its procedure for the exponent of a prime are given as pseudocode with worked runs in the blocks of eq. (3) and eq. (8).
The exercises
The table has the 25 exercises of Section 1.2.5. The kind is the class of spec 06.3 that C1 proposes. The marker ▶ is the mark of the book for a recommended exercise.
| Exercise | Rating | Markers | Kind | Lean | Solution |
|---|---|---|---|---|---|
| 1.2.5-1 | 00 | K3 | not yet stated | X1, 1.2.5-1 | |
| 1.2.5-2 | 10 | K1 | not yet stated | X1, 1.2.5-2 | |
| 1.2.5-3 | 10 | K3 | not yet stated | X1, 1.2.5-3 | |
| 1.2.5-4 | 13 | ▶ | K3 | not yet stated | X1, 1.2.5-4 |
| 1.2.5-5 | 15 | K3 | not yet stated | X1, 1.2.5-5 | |
| 1.2.5-6 | 17 | ▶ | K3 | not yet stated | X1, 1.2.5-6 |
| 1.2.5-7 | 10 | M | K1 | not yet stated | X1, 1.2.5-7 |
| 1.2.5-8 | 15 | HM | K1 | not yet stated | X1, 1.2.5-8 |
| 1.2.5-9 | 10 | M | K3 | not yet stated | X1, 1.2.5-9 |
| 1.2.5-10 | 20 | ▶ HM | K2 | not yet stated | X1, 1.2.5-10 |
| 1.2.5-11 | 15 | M | K1 | not yet stated | X1, 1.2.5-11 |
| 1.2.5-12 | 22 | ▶ M | K3 | not yet stated | X1, 1.2.5-12 |
| 1.2.5-13 | 23 | M | K1 | not yet stated | X1, 1.2.5-13 |
| 1.2.5-14 | 28 | ▶ M | K1 | not yet stated | X1, 1.2.5-14 |
| 1.2.5-15 | 15 | HM | K3 | not yet stated | X1, 1.2.5-15 |
| 1.2.5-16 | 15 | HM | K1 | not yet stated | X1, 1.2.5-16 |
| 1.2.5-17 | 20 | HM | K1 | not yet stated | X1, 1.2.5-17 |
| 1.2.5-18 | 20 | M | K1 | not yet stated | X1, 1.2.5-18 |
| 1.2.5-19 | 22 | HM | K1 | not yet stated | X1, 1.2.5-19 |
| 1.2.5-20 | 21 | HM | K1 | not yet stated | X1, 1.2.5-20 |
| 1.2.5-21 | 25 | HM | K1 | not yet stated | X1, 1.2.5-21 |
| 1.2.5-22 | 20 | ▶ HM | informal | not yet stated | X1, 1.2.5-22 |
| 1.2.5-23 | 20 | HM | K1 | not yet stated | X1, 1.2.5-23 |
| 1.2.5-24 | 21 | ▶ HM | K1 | not yet stated | X1, 1.2.5-24 |
| 1.2.5-25 | 20 | M | K2 | not yet stated | X1, 1.2.5-25 |
The order to do them: start with 1.2.5-1, 2 and 3, which fix the counts of eq. (2) and the two methods of eq. (3). Then do 1.2.5-4, 5 and 6, which are three computations with eqs. (4), (7) and (8). Exercises 1.2.5-7, 9 and 10 go with the termial and the first values of , and 1.2.5-10 asks at which real the rule holds. Exercises 1.2.5-11 and 12 are Legendre's rule in the digits of (the closed form after eq. (8) in this chapter is the answer of 12), and 1.2.5-13 and 14 take the factorial modulo a prime, with Wilson's theorem as the first case. Exercise 1.2.5-15 is a small step on permanents, and 1.2.5-21 is the chain rule for higher derivatives. The group 1.2.5-8, 16, 17, 18, 19, 20, 22 and 23 is the analysis of eqs. (11), (13), (15) and (16): 8 and 22 justify Euler's limit, 16 is the divergence proved in this chapter, 19 and 20 give the integral for that the remark after eq. (15) uses, and 23 is eq. (16). Exercise 1.2.5-24 is a simple bound on that needs only , and 1.2.5-25 asks for the law of exponents of the falling powers, which this chapter states and proves after eq. (21).
Lean
The Lean code of tamnd/taocp-lean at main has the file TAOCP/V1/S1_2_5.lean, in the namespace TAOCP.S1_2_5. It states eqs. (1) to (8), (10) and (13) to (16) and (18) to (21). The falling and rising powers are defined in TAOCP/Notation/Pochhammer.lean as TAOCP.fallingPow and TAOCP.risingPow. The file TAOCP/Solutions/S1_2_5.lean imports no exercise yet. The Node lines name the declarations. Where the Lean statement is weaker, the Node line says "partial". The block on the permutations as a definition names Equiv.Perm of Mathlib.
Not yet stated: the series of eqs. (11) and (12) and Hankel's integral of eq. (17).
The points where Lean differs from the book are these.
- Eqs. (1) and (3) list the permutations of
['a', 'b', 'c']and of[1, 2, 3]as a set.TAOCP.S1_2_5.card_permandTAOCP.S1_2_5.card_perm_succgive the count and the recurrence of the two construction methods. - Eq. (2) counts the injections of
Fin kintoFin n, and the result is the falling power. - Eq. (7) states Stirling's approximation as an asymptotic equivalence (the ratio tends to 1). The two-sided bound of the handbook is not stated.
- Eq. (8) is stated with a bound above on the sum, and
TAOCP.S1_2_5.eq8_padicstates it withpadicValNat. Division onℕrounds down, son / p ^ kis . - Eq. (10) is stated for natural . The termial of a real number is
TAOCP.S1_2_5.termialReal, and the rule for real is not stated. - Eqs. (13), (15) and (16) are stated for real numbers, not for complex numbers. Mathlib gives at the poles, so
TAOCP.S1_2_5.eq15andTAOCP.S1_2_5.eq16hold there but say nothing.TAOCP.S1_2_5.eq13asks that is not a negative integer. - Eq. (14):
TAOCP.S1_2_5.eq14is the recursion for real , andTAOCP.S1_2_5.eq14_factorialis for natural only. The statement for real is the definition by eq. (13), and it is not a separate declaration. - Eq. (21): the Gamma forms are stated for real with the hypothesis that the Gamma arguments are not poles.
The Mathlib names that the statements use are these. The factorial is Nat.factorial. The falling and rising powers have the bridges Nat.descFactorial and Nat.ascFactorial, and Nat.ascFactorial n k is . The gamma function is Real.Gamma and Complex.Gamma, with Real.Gamma_nat_eq_factorial, Real.GammaSeq_tendsto_Gamma for the limit of eq. (13), Complex.Gamma_mul_Gamma_one_sub and Real.Gamma_mul_Gamma_one_sub for the reflection formula, and Real.eq_Gamma_of_log_convex (Bohr and Mollerup) for the uniqueness of the extension. Stirling's formula is Stirling.tendsto_stirlingSeq_sqrt_pi. Derangements, for the proof of eq. (11), are numDerangements and card_derangements_eq_numDerangements.
Notes and history
The count of arrangements is old: Indian texts of the 12th century (Bhaskara II) give the rule. The sign is due to Christian Kramp (1808). Before him Euler used and Gauss wrote . Legendre's sign stands for .
James Stirling published his approximation in the Methodus Differentialis (1730). Abraham de Moivre found the form with an unknown constant, and Stirling found that the constant is . The proof above finds the constant with Wallis's product (1655). The improvement is an asymptotic series, which does not converge, as the book says. The two-sided bound of the proof above is of the kind that H. Robbins gave in 1955, with and in the exponents.
Euler gave the limit (13) in a letter to Goldbach of October 13, 1729. Euler also found an integral for in 1730. The change of variable turns his integral into the form . The reflection formula is Euler's, and the contour integral is due to Hermann Hankel (1864). Hermite's proof that Stirling's series (12) defines the factorial for non-integers is from 1900. H. Bohr and J. Mollerup proved in 1922 that the gamma function is the only function on that is positive, log-convex, equal to at and that obeys . This explains why the choice in eq. (13) is not arbitrary. Wilson's theorem and Legendre's rule are old: Leibniz knew the first and Legendre stated the second in 1808.
The derangement numbers that the proof of eq. (11) uses were counted by Pierre Rémond de Montmort in 1708, in the problem of the matches. The word "permanent" of exercise 1.2.5-15 goes back to Cauchy (1812), and Thomas Muir gave it its present meaning.
The project has no errata of Section 1.2.5 to report.
Section 1.2.5 of TAOCP counts the orders of objects and gives the number its first properties: its size, its prime factors and its extension to non-integer arguments. The section is short, but it holds the gamma function, the falling and rising powers of the later sections, and the first look at Stirling's formula. This chapter of C1 explains each of the 21 numbered equations and the definition of a permutation, proves each claim in full, and shows the reader how to check every number by hand or by a short program.
The source of this page. Something is wrong? Report it.