Volume C1 · Basic concepts · TAOCP Section 1.2.2
Numbers, powers and logarithms
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.2 of the book. The nodes and the exercises of the section.
Contents
Numbers, powers and logarithms
Overview
Section 1.2.2 of TAOCP lists the kinds of number that the book uses: integers, rational numbers, real numbers and complex numbers. It defines a real number by its decimal expansion and gives the bounds that the expansion means. Then it defines the power in four steps: for integer by a recursion, for fractions by roots, for real by squeezing between the powers with finite decimal exponents, and for a base by a reduction to . The logarithm is the inverse of this power. The section proves nothing in detail, and it leaves the proofs of the laws to the exercises. It derives the rules for the logarithm of a product, of a power and of a change of base, and it introduces and . It ends with a way to compute in binary, one bit for each squaring. The section uses the induction of Section 1.2.1. The handbook proves the laws here in full, because the later sections use them without comment.
The ideas
A real number is a decimal expansion. The book does not build the real numbers from the rational numbers by cuts or by Cauchy sequences. It takes an expansion as the definition and reads it as a sequence of bounds that squeeze the number. Each new digit cuts the interval of width into ten parts and picks one. C1 follows this plan and proves one fact that the book takes for granted: each number has exactly one such expansion, so no two expansions mean the same number.
Every power is a squeeze. For an integer exponent, is a product, and the laws of exponents come from induction. For a fraction , the power is the th root of . For a real exponent, take the decimal truncations of the exponent. Then is a known number that rises with , and is a known number that falls with . The gap between the two shrinks to zero, so exactly one number lies between all the pairs. That number is .
A logarithm reads the squeeze backwards. Given , find the integer and the digits one at a time, so that to the power of each truncation stays at or below . The limit is . This is a proof that the logarithm exists. It is also the first method of computation, because it is an algorithm: compare with powers of .
The three rules of the logarithm are the laws of exponents in a different dress. The law gives . The law gives . A change of the base multiplies the logarithm by a constant, and two bases compare through one number, .
Squaring gives the bits of a logarithm. If , then is in . Squaring doubles the logarithm. So the first binary digit of is exactly when , and then dividing by takes away the digit. Repeating this gives all the bits. The method is correct by the invariant of eq. 1.2.2(19), which C1 proves by induction as in Section 1.2.1.
The order of C1 differs a little from the order of the book. C1 proves first that a real number has a unique expansion, then the laws for integer powers, then the existence of roots, which the book states without proof. The proof of the existence of the logarithm and the law of the real power are also given in full here.
Definitions, results and proofs
Definition C1.1.2.2.1 (the number systems, TAOCP Section 1.2.2). The integers are . A rational number is a quotient of two integers with . A real number is a number that a decimal expansion names (see eq. 1.2.2(1) below). A complex number is with and real and . For real , the closed interval is the set of with , the open interval is the set with , and the two half-open intervals and keep one end point. The end point or is allowed on an open end.
Node: TAYVMS9JTS · status: not stated yet
Explanation. The five sets nest: the integers are inside the rational numbers, which are inside the real numbers, which are inside the complex numbers. The same rational number has many names, since and are equal. A rational number is in lowest terms when and have no common factor. The book works with real numbers, and it uses the complex numbers only when the real numbers make a topic harder. The interval notation with two dots avoids the confusion between an interval and the pair . In Lean, the integers are ℤ, the rational numbers are ℚ, the real numbers are ℝ and the complex numbers are ℂ, and the interval is Set.Icc u v.
Example. The number is rational with and . The number is rational, since . The number is real and not rational (a proof is in the next block). The interval is the set of the nonnegative real numbers. The interval contains and does not contain .
For the claim that is not rational: suppose in lowest terms. Then , so is even, , and gives , so is even too. This contradicts the lowest terms. The same style of proof appears in the exercise on below.
Definition C1.1.2.2.2 (a real number as a decimal expansion, TAOCP eq. 1.2.2(1)). A decimal expansion is an expression , where is an integer, each is one of the digits , and the digits are not all equal to from some place on. The real number that it names is the one that satisfies the bounds of eq. 1.2.2(2).
Node: TAVBEJT77H · status: not stated yet
Explanation. The integer part may be negative, and the digits after the point are always counted upward from the integer part. So is the number , and its integer part is . The ban on a tail of nines is a rule of form: it makes the expansion unique. Without the rule, and would be two names for one number. The next block proves that the expansions of this form are in one-to-one match with the real numbers.
Example. The fraction has the expansion . The fraction has the expansion , a repeating block. The number is . The string with an endless tail of nines is not an expansion in this sense. The number that it would name is , and that one has its own expansion.
Theorem C1.1.2.2.3 (the bounds of a decimal expansion, TAOCP eq. 1.2.2(2)). Let be a real number. For each integer let (so ). Each real number has exactly one such expansion. The expansion means that
Node: TA6FMM8TYB · Lean: TAOCP.S1_2_2.eq2 (partial) · status: proved
Explanation. The bounds say that is cut off after places, always rounded down. The pair of bounds is the real meaning of the infinite string of digits, since an infinite sum cannot be written out. The uniqueness is the reason to have the rule about the tail of nines, and it is what lets the book compare two real numbers by comparing digits from the left (exercise 1.2.2-6). The bounds are used in eq. 1.2.2(7) with the exponent in the place of .
Example. Take . The values and for are
| upper bound? | |||
|---|---|---|---|
| 0 | 3 | 4 | yes |
| 1 | 3.1 | 3.2 | yes |
| 2 | 3.14 | 3.15 | yes |
| 3 | 3.142 | 3.143 | yes |
| 4 | 3.1428 | 3.1429 | yes |
Each equals . For example , and its floor is .
Proof. Existence. For let , the greatest integer not above (Section 1.2.4 treats the floor function in detail). Put and for . From we get . Since is the greatest integer at most , it lies in , so . By induction on , , which gives . It remains to show that the digits do not all equal from a place on. Suppose they do. Then for we have , and so for each . Letting grow gives . But . This is a contradiction.
Uniqueness. Let be any expansion of with the bounds of the theorem. Then is an integer, and . The only integer with this property is . So for each , and and each digit are fixed by .
Definition C1.1.2.2.4 (the absolute value of a complex number, TAOCP eq. 1.2.2(3)). For with real and , the absolute value is . The conjugate of is .
Node: TAKY3A91VT · Lean: TAOCP.S1_2_2.eq3 · status: proved
Explanation. The absolute value is the distance of the point from the origin of the plane. For real it is the usual absolute value. The conjugate satisfies , since . This identity gives the main property of the absolute value: for all complex and . The book does not use complex numbers much, but the product rule is the base of many bounds later.
Example. For we get and . For and , the product is , so . The values are and , and .
Proof of the product rule. The conjugate of a product is the product of the conjugates: , by a direct expansion of and of . Then . Both sides are nonnegative, so the square roots agree: .
Definition C1.1.2.2.5 (integer powers, TAOCP eq. 1.2.2(4)). Let be a positive real number. The power for an integer is given by , then for , and for .
Node: TAQFZ535TS · Lean: TAOCP.S1_2_2.eq4, TAOCP.S1_2_2.ipow · status: proved
Explanation. The rule has two parts. Upward, it builds each positive power from the one before it by one multiplication. Downward, it builds each negative power from the one after it by one division. The downward rule is forced if the rule is to hold for all : solve for and put to get . So the definition is the only one that keeps the upward rule true everywhere. The base may be any nonzero number in this definition; the book fixes for the later use of roots. In Lean the power with an integer exponent is zpow, written b ^ n with n : ℤ.
Example. With the upward rule gives , , . The downward rule gives , , . For and : . For the negative base , the same rules give , because and the downward rule gives .
Theorem C1.1.2.2.6 (the laws of exponents for integers, TAOCP eq. 1.2.2(5)). Let and let and be integers. Then
Node: TAHES3Y1A1 · Lean: TAOCP.S1_2_2.eq5_int · status: not stated yet
Explanation. The two laws are the reason that the notation is useful. The first turns a sum of exponents into a product of powers, and the second turns the power of a power into a product of exponents. Section 1.2.2 first proves them for integers, and extends them to fractions and then to all real and . The logarithm rules below are the same laws read in the other direction.
Example. Take , , . Then , and . For the second law, and give and .
Proof. First, for all integers . For this is the definition at . For the definition at says , which is the same statement.
The law , for a fixed . For use induction on . The case says . If it holds for , then . For use induction downward from . If , then .
The law , for a fixed . Let . For use induction on . The case says . If , then by the first law. For use induction downward. If , then .
Definition C1.1.2.2.7 (rational powers, TAOCP eq. 1.2.2(6)). Let and let be a rational number with . Then is the positive number with , that is, the th root of .
Node: TA6T2TS35A · Lean: TAOCP.S1_2_2.eq6, TAOCP.S1_2_2.eq6_pow, TAOCP.S1_2_2.eq6_root · status: proved
Explanation. The definition is only good if three things hold. First, the root must exist and be unique. Second, the value must not depend on the way that the rational number is written, since . Third, the laws of exponents must still hold. The three claims are proved below. The root of a positive number is the first place where a real number is needed that is not rational, since is not rational. The idea of the definition is due to Oresme, and it is the basis of the later definition for real exponents.
Example. is the cube root of , which is . The value is the cube root of , so it is again . Also is the square root of , which is , and is the fourth root of , which is again.
Proof that the root exists and is unique. Let and let be an integer. Uniqueness: if then , because each factor of is below the matching factor of , so there is at most one positive with . Existence: let be the set of positive with . It is not empty, since it contains , and it is bounded above by (a number has ). Let be its least upper bound. Suppose . For , the difference . For small this is less than , so , which contradicts that is an upper bound. Suppose . For , , so for small we get . Each has , so . Then is an upper bound smaller than , which is a contradiction. So .
Proof that the value does not depend on the writing. Let be the th root of , so . For an integer , by the law for integers. So is also the th root of , and . If , then and , and the two exponents are equal as integer pairs because .
Proof of the laws for rational exponents. Write two rational numbers with a common denominator : and . Let , the positive number with . Then , since . In the same way , and . So the first law holds: by the integer law. For the second law, . The positive number satisfies , so , and then . On the other side, , because . The two sides agree.
Definition C1.1.2.2.8 (real powers, TAOCP eq. 1.2.2(7)). Let and let be a real number, with as in eq. 1.2.2(2). Then is the unique real number that satisfies the bounds below. For the power is . For the power is .
Node: TA5VGG8ZP8 · Lean: TAOCP.S1_2_2.eq7, TAOCP.S1_2_2.eq7_digits, TAOCP.S1_2_2.rpow_eq_one_div_rpow_neg (partial) · status: proved
Explanation. The numbers and are rational, so the two bounds are rational powers, which are defined. The lower bounds rise with and the upper bounds fall with . The definition claims that exactly one real number lies in all these intervals, and that this number is the right value of . The claim has two parts: the width of the th interval goes to zero, and the nested intervals have one common point. The second part is the completeness of the real numbers. The first part needs a bound on the width.
Example. Take and . The intervals for the first values of are (to 5 decimals)
| lower bound | upper bound | ||
|---|---|---|---|
| 0 | 3 | 8 | 16 |
| 1 | 3.1 | 8.57419 | 9.18959 |
| 2 | 3.14 | 8.81524 | 8.87656 |
| 3 | 3.141 | 8.82135 | 8.82747 |
| 4 | 3.1415 | 8.82441 | 8.82502 |
The value of is , and it is inside each interval. The width falls by a factor of about at each step, as the proof below predicts.
Proof that the definition makes sense. Let . First, is strictly increasing in the rational . If is rational, with , then , and the th root of is above , since would give . So for rational we have by the rational laws. The lower bounds do not fall with , since . The upper bounds do not rise: . Each interval is nonempty since .
Now the width. For and write with . Bernoulli's inequality says (induction on : ). So , which gives , that is Hence the width of the th interval is , using . This goes to zero.
A sequence of nested closed intervals of widths that go to zero has exactly one common point, by the completeness of the real numbers. This point is . If is itself rational, the rational power lies in all the intervals, because and is strictly increasing in rational ; so the new definition agrees with the old one.
The laws for real exponents. Let . The number equals the least upper bound of the set of with rational and . Indeed, each such is at most : if , then for large , since , and ; if the two numbers are equal. And the numbers themselves come as close to as the width of the interval allows. With this fact the laws follow. For the first law, the set of the sums with and rational contains each rational (split as with slightly below , using room). So . The first step uses that a product of two suprema of positive sets is the supremum of the products. For the second law, with , first prove for rational : by the first law applied times, and by the first law applied times, so is the th root of . For real , both and are suprema: over rational , and over rational . Each is at most , since and is increasing in real (by the first law and for ). Conversely each rational has a rational with , so . The two suprema agree. The cases , and reduce to this one by and by the definition .
Example C1.1.2.2.9 (two powers of 10 near 2, TAOCP eq. 1.2.2(8)). The two numbers and surround the number :
Node: TAJFAWPZ3F · status: not stated yet
Explanation. The example shows how the squeeze of eq. 1.2.2(7) is used to learn a number. Each exponent is a rational number with a finite decimal expansion, so each power is computed by roots. The two results are on opposite sides of , and the exponents differ by . Since is strictly increasing in , any exponent with lies between and . This gives eight correct decimal places of .
Example. The first value is and the second is (computed with 40 digits of precision). Their relative distance from is about and . A check by the law of exponents: , and the quotient of the two numbers above is . The two agree.
Proof. Each claim is an exact statement about integers. Write . By eq. 1.2.2(6), is below if and only if , because the th power is strictly increasing. In the same way, if and only if . These two comparisons of integers can be decided by exact arithmetic, and the digits shown above come from a computation with 40 digits of precision.
Definition C1.1.2.2.10 (the logarithm, TAOCP eq. 1.2.2(9)). Let , , and . The logarithm of to the base , written , is the real number with . It exists, and it is unique. By the definition,
Node: TAGZ83HEKX · Lean: TAOCP.S1_2_2.eq9_rpow_logb, TAOCP.S1_2_2.eq9_logb_rpow · status: not stated yet
Explanation. The two equations say that and are inverse to each other. The base is excluded, since takes only one value. The proof of existence reads eq. 1.2.2(7) from right to left: given the value, find the exponent digit by digit. The proof is a method, and Section 1.2.2 uses the same method later as a way to compute a logarithm.
Example. , since . . , because . , since . for each admissible , and . The value is not defined, since for each real .
Proof. Let first and . Uniqueness: is strictly increasing in (shown in the proof of eq. 1.2.2(7), and by the first law for real exponents), so two exponents with the same power are equal. Existence: choose the integer as the largest integer with . Such an exists, since the powers grow without bound as and fall to as . Suppose that has been chosen with . Choose as the largest digit in with . Digit works. If , the maximality gives . If , then and the bound is the one known from the step before. So for each . Let be the number if the digits do not end in an endless tail of s. If they do end in nines from the place , then for all and , which contradicts . So the expansion is valid. Both and lie in the interval for each , the widths go to zero, and so .
For we have by definition, so if and only if is the logarithm of to the base . This gives existence and uniqueness. The two displayed equations are the definition itself.
Example C1.1.2.2.11 (the value of , TAOCP eq. 1.2.2(10)). From eq. 1.2.2(8),
Node: TAT7EWGNPG · status: not stated yet
Explanation. The exponent with is greater than and less than , since the two powers in eq. 1.2.2(8) lie on the two sides of and is strictly increasing. By eq. 1.2.2(2), these two bounds fix the first eight digits after the point: . The next digits are , so the full value is . This number is irrational, which is exercise 1.2.2-10 and is proved below. The number also shows that a few digits of an exponent do not always fix the digits of the power. If agrees with in its first places, then can be just below or at least , for each . So no finite number of digits of tells whether the expansion of starts with or with (exercise 1.2.2-11).
Example. The value gives quick estimates. Since , we get and . Also .
Proof that is irrational. Suppose with positive integers and . Then , so . The left side is divisible by and the right side is not, since its only prime factor is . This is a contradiction.
Theorem C1.1.2.2.12 (the logarithm of a product, TAOCP eq. 1.2.2(11)). Let , , and . Then
Node: TAVXQEFH0N · Lean: TAOCP.S1_2_2.eq11 · status: proved
Explanation. The logarithm turns a product into a sum. This was the reason for the invention of logarithm tables: a table of makes a multiplication into an addition and two lookups. The rule also gives (exercise 1.2.2-15), since .
Example. . A direct computation gives . Also .
Proof. Let and , so that and . By the first law of exponents, . So to the power is . By uniqueness of the logarithm, .
Theorem C1.1.2.2.13 (the logarithm of a power, TAOCP eq. 1.2.2(12)). Let , , and let be real. Then
Node: TAD8ZTHRVQ · Lean: TAOCP.S1_2_2.eq12 · status: proved
Explanation. The exponent comes down in front of the logarithm. This rule is what makes a logarithm a tool for big powers: the logarithm of is times the logarithm of . It also gives the number of digits of a large integer: the positive integer has decimal digits.
Example. , and has digits. , so has digits.
Proof. Let , so . By the second law of exponents, . So to the power is , and by uniqueness .
Definition C1.1.2.2.14 (the binary logarithm, TAOCP eq. 1.2.2(13)). The binary logarithm of is .
Node: TAR1FK2HA8 · Lean: TAOCP.S1_2_2.eq13 · status: proved
Explanation. Binary logarithms count halvings. A number of size that is halved at each step reaches in about steps. For this reason the binary logarithm measures the depth of a binary tree, the number of comparisons in a binary search, and the number of bits of an integer. The book uses the short symbol for it from this section on. A with no base is rare in the book. It appears mostly where the base changes only a constant factor, as inside the -notation. In Lean, Real.logb 2 is the binary logarithm.
Example. , , , (since is a little above ). A positive integer has bits: has bits, since .
Theorem C1.1.2.2.15 (the change of the base, TAOCP eq. 1.2.2(14)). Let with and , and let . Then
Node: TAV0DK3C55 · Lean: TAOCP.S1_2_2.eq14 · status: proved
Explanation. Two logarithms of the same number differ by a constant factor that depends only on the two bases. So a table of logarithms to one base gives the logarithms to every base, by one multiplication. The special cases are and . With the rule gives (exercise 1.2.2-20).
Example. . . , which shows that the claim of exercise 1.2.2-18 is false.
Proof. By eq. 1.2.2(9), . Apply and use the rule for a power: . Divide by , which is not zero since .
Definition C1.1.2.2.16 (the natural logarithm, TAOCP eq. 1.2.2(15)). The natural logarithm is , where is the base of natural logarithms.
Node: TA0T0P4C7M · Lean: TAOCP.S1_2_2.eq15 · status: proved
Explanation. The book does not define at this point. A standard definition is , and with this base the area under the curve from to equals for each . These two facts are proofs of calculus, and C1 does not repeat them. For the use here, is a logarithm like the other ones, and each rule above holds for it. In analysis and in the later sections of the book, is the logarithm with the simplest derivative and series. In Lean, Real.log is the natural logarithm, and Real.logb b x equals Real.log x / Real.log b, which is the rule of the change of base.
Example. The compound interest of one unit of money at the rate (one hundred percent) per year, with payments, is . For the values are , , , , and . They approach . The value gives .
Theorem C1.1.2.2.17 (a bound that gives the digits of a logarithm, TAOCP eq. 1.2.2(16)). Let , , and let be an integer. Let . Then is the one integer with the property below, and is rounded down to decimal places.
Node: TA34KYJZZN · Lean: TAOCP.S1_2_2.eq16 (partial) · status: proved
Explanation. This is the simplest method to find a logarithm, and it needs only exact powers. Raise to the power and see between which two powers of the result lies. The method is impractical, since is a huge number, but it is exact and it explains the next method.
Example. Take and . For : lies between and , so and . For : , so and . For : , so and . For : gives , gives , and gives , and so .
Proof. Put . By the rule for a power, . Since , the function is strictly increasing, and so is its inverse. An integer satisfies if and only if , that is .
Definition C1.1.2.2.18 (the binary expansion of a logarithm, TAOCP eq. 1.2.2(17)). For , the binary expansion of is the representation below, where is an integer and each is or (the bits).
Node: TA3K5VA1YD · Lean: TAOCP.S1_2_2.eq17 (partial) · status: proved
Explanation. This is eq. 1.2.2(1) in base instead of base , applied to a logarithm. The integer part is the exponent of the power of in the scientific form of : it is the integer with . The fractional part is , a number in , and the bits are its binary digits. The rule on the tail is the same as for decimal digits: the bits are not all from some place on (exercise 1.2.2-5 asks for the matching definition of the real numbers).
Example. has the bits (computed by the method of eq. 1.2.2(18); see the run below). So . For : , since , and .
Theorem C1.1.2.2.19 (the invariant of the squaring method, TAOCP eq. 1.2.2(19)). Let , let be the integer with , and let . Define and for by the rule of eq. 1.2.2(18) (see the algorithm below). Then for each ,
Node: TA73S9TGH1 · Lean: TAOCP.S1_2_2.eq19, TAOCP.S1_2_2.eq19_book · status: proved
Explanation. The statement is a loop invariant, in the sense of Section 1.2.1. It says that at each step the number is the original raised to the th power and divided by the power of that is just enough to bring it back into . The exponent of is times the part of the logarithm found so far. The invariant gives the correctness of the method.
Example. Take , so and . After steps the bits are , so . The invariant says . This is the value in the table of the worked run below.
Proof. Induction on . For , , and the statement is , which is how was chosen. Suppose the formula holds for , and write , so and . Then and . If , then and . Then , the formula holds, and . If , then and . Then , so , and the formula holds. Also since .
Algorithms and programs
Algorithm C1.1.2.2.20 (the bits of a common logarithm, TAOCP eq. 1.2.2(18)). The input is a real number and a number of bits. The output is the integer and the bits of eq. 1.2.2(17), the first places of the binary expansion of .
Node: TAZ9CREP22 · Lean: TAOCP.S1_2_2.xSeq, TAOCP.S1_2_2.bBit, TAOCP.S1_2_2.eSeq (partial) · status: not stated yet
The idea. If , then and . Doubling a binary fraction moves its first bit to the integer place. So the first bit of is exactly when . In that case divide by to take away the integer part, and the new number lies again in . Its logarithm is the fraction that remains after the first bit. The step repeats on the new number.
The steps.
Log10Bits(x, K): -- x > 0, K >= 0
n := the integer with 1 <= x / 10^n < 10
z := x / 10^n
for k := 1 to K:
z := z * z
if z >= 10: b[k] := 1; z := z / 10
else: b[k] := 0
return n, b[1..K]
The book writes the same rule as two equations with two cases. The loop above keeps one variable in the place of the sequence , so that after pass .
A worked run. Take , so and . The table lists (exact up to , then rounded to 15 significant digits), the bit, and the partial sum . The true value is
| 0 | 3 | 0 | |||
| 1 | 9 | 0 | 9 | 0 | 0.47712 |
| 2 | 81 | 1 | 8.1 | 0.25 | 0.22712 |
| 3 | 65.61 | 1 | 6.561 | 0.375 | 0.10212 |
| 4 | 43.046721 | 1 | 4.3046721 | 0.4375 | 0.03962 |
| 5 | 18.53020188851841 | 1 | 1.853020188851841 | 0.46875 | 0.00837 |
| 6 | 3.43368382029251 | 0 | 3.43368382029251 | 0.46875 | 0.00837 |
| 7 | 11.7901845777386 | 1 | 1.17901845777386 | 0.4765625 | 0.00056 |
| 8 | 1.39008452377145 | 0 | 1.39008452377145 | 0.4765625 | 0.00056 |
The first eight bits of are . The gap in the last column is always at least and less than , as the proof below shows. The pass checks the invariant: . The Lean definition of the algorithm works on real numbers, so this chapter shows no #eval to compare.
Proof of correctness. The invariant is the statement of eq. 1.2.2(19): after pass , , where . The theorem above proves that the invariant holds at the start () and is kept by each pass. Now take the logarithm to the base of the invariant: . So This is the property of the output: the bits are the first bits of , and they fix to an interval of width . The same inequality for each shows that the infinite sequence of bits is the binary expansion of . The algorithm stops, since the loop runs exactly times.
The cost. The loop has passes. Each pass has one squaring, one comparison with , and at most one division by . So the total cost is squarings, comparisons and at most divisions by (a shift of the decimal point, in a decimal computer). To get decimal places of takes passes. This is much less work than the method of eq. 1.2.2(16), which raises to a power with in the exponent.
The effect of rounding. A real machine keeps to a fixed number of digits. Suppose that each computed square is with , that the division by is exact, that the first value has , and that each computed stays in . Let , and , where . Then and . So satisfies with , and therefore . Now and , so The computed bits give with an error below . Exercise 1.2.2-27 asks for the same bound with separate errors for rounding down and rounding up. The early errors are the costly ones: an error of the first pass is doubled at each later pass, and this is why a program keeps extra digits.
The exercises
The table has the exercises of Section 1.2.2. The kind is the class of spec 06.3 that C1 proposes, and the Lean column names the solved theorem of tamnd/taocp-lean at main, when one exists. The marker ▶ is the book's mark of a recommended exercise.
| Exercise | Rating | Markers | Kind | Lean | Solution |
|---|---|---|---|---|---|
| 1.2.2-1 | 00 | K2 | TAOCP.S1_2_2.Ex1.solved |
X1, 1.2.2-1 | |
| 1.2.2-2 | 00 | K2 | TAOCP.S1_2_2.Ex2.solved |
X1, 1.2.2-2 | |
| 1.2.2-3 | 02 | K3 | TAOCP.S1_2_2.Ex3.solved |
X1, 1.2.2-3 | |
| 1.2.2-4 | 05 | ▶ | K3 | TAOCP.S1_2_2.Ex4.solved |
X1, 1.2.2-4 |
| 1.2.2-5 | 05 | informal | not yet stated | X1, 1.2.2-5 | |
| 1.2.2-6 | 10 | informal | not yet stated | X1, 1.2.2-6 | |
| 1.2.2-7 | 23 | M | K1 | TAOCP.S1_2_2.Ex7.solved |
X1, 1.2.2-7 |
| 1.2.2-8 | 25 | K1 | TAOCP.S1_2_2.Ex8.solved |
X1, 1.2.2-8 | |
| 1.2.2-9 | 23 | M | K1 | TAOCP.S1_2_2.Ex9.solved |
X1, 1.2.2-9 |
| 1.2.2-10 | 18 | K1 | TAOCP.S1_2_2.Ex10.solved |
X1, 1.2.2-10 | |
| 1.2.2-11 | 10 | ▶ | K2 | TAOCP.S1_2_2.Ex11.solved |
X1, 1.2.2-11 |
| 1.2.2-12 | 02 | K1 | TAOCP.S1_2_2.Ex12.solved |
X1, 1.2.2-12 | |
| 1.2.2-13 | 23 | ▶ M | K1 | TAOCP.S1_2_2.Ex13.solved |
X1, 1.2.2-13 |
| 1.2.2-14 | 15 | K1 | TAOCP.S1_2_2.Ex14.solved |
X1, 1.2.2-14 | |
| 1.2.2-15 | 10 | K2 | TAOCP.S1_2_2.Ex15.solved |
X1, 1.2.2-15 | |
| 1.2.2-16 | 00 | K3 | TAOCP.S1_2_2.Ex16.solved |
X1, 1.2.2-16 | |
| 1.2.2-17 | 05 | ▶ | informal | TAOCP.S1_2_2.Ex17.solved |
X1, 1.2.2-17 |
| 1.2.2-18 | 10 | K2 | TAOCP.S1_2_2.Ex18.solved |
X1, 1.2.2-18 | |
| 1.2.2-19 | 20 | ▶ | K2 | TAOCP.S1_2_2.Ex19.solved |
X1, 1.2.2-19 |
| 1.2.2-20 | 10 | K3 | TAOCP.S1_2_2.Ex20.solved |
X1, 1.2.2-20 | |
| 1.2.2-21 | 15 | K3 | TAOCP.S1_2_2.Ex21.solved |
X1, 1.2.2-21 | |
| 1.2.2-22 | 20 | ▶ | K1 | TAOCP.S1_2_2.Ex22.solved |
X1, 1.2.2-22 |
| 1.2.2-23 | 25 | M | K1 | TAOCP.S1_2_2.Ex23.solved |
X1, 1.2.2-23 |
| 1.2.2-24 | 15 | informal | not yet stated | X1, 1.2.2-24 | |
| 1.2.2-25 | 22 | informal | not yet stated | X1, 1.2.2-25 | |
| 1.2.2-26 | 27 | M | informal | not yet stated | X1, 1.2.2-26 |
| 1.2.2-27 | 25 | ▶ M | informal | not yet stated | X1, 1.2.2-27 |
| 1.2.2-28 | 30 | M | informal | not yet stated | X1, 1.2.2-28 |
| 1.2.2-29 | 20 | HM | K3 | TAOCP.S1_2_2.Ex29.solved |
X1, 1.2.2-29 |
| 1.2.2-30 | 12 | K3 | TAOCP.S1_2_2.Ex30.solved |
X1, 1.2.2-30 |
The order to do them. First do 1.2.2-1, 2, 3 and 4. They are quick checks of the definitions of the section: the smallest positive rational, a tail of nines, a negative power and a negative fractional power. Then do 1.2.2-12, 14, 15, 16, 17, 18, 20 and 21, which are short exercises on the rules of the logarithm; exercise 1.2.2-14 is the proof of eq. 1.2.2(12) that C1 gives above. Exercises 1.2.2-7, 9, 13 and 8 are the proofs that the book leaves out: the laws for integer exponents, the laws for rational exponents, the bound of Bernoulli that squeezes a real power, and the existence of the root. C1 proves each of these in the text, in its own form, so a reader can compare. Exercises 1.2.2-10 and 11 are about : it is irrational, and so no finite number of digits of the exponent decides the digits of the power. Exercises 1.2.2-19, 22 and 30 apply the logarithm to the size of a number, to the approximation and to a simplification. Exercise 1.2.2-29 is a calculus exercise about the best base. Exercises 1.2.2-24 to 28 belong to the computation of logarithms: 24 changes the method of eq. 1.2.2(18) to base , 25 and 26 give a second method with shifts and additions and its error, 27 is the error bound of the squaring method, whose first form is proved in this chapter, and 28 is the matching method for the power .
Lean
The Lean code of tamnd/taocp-lean at main has the file TAOCP/V1/S1_2_2.lean, in the namespace TAOCP.S1_2_2. It states eqs. (2) to (9) and (11) to (17) and (19), and it defines the loop of eq. (18). The Node lines name the declarations. Where the Lean statement is weaker than the handbook, the Node line says "partial".
Not yet stated: the number systems and the intervals (the first definition), the expansion of eq. (1) with its uniqueness, and the two numerical examples of eqs. (8) and (10). The definition of the loop of eq. (18) works on real numbers, so it has no run with #eval.
The points where Lean differs from the book are these.
- Eq. (2) is stated as the two bounds with . The uniqueness of the expansion is not stated.
- Eqs. (4) and (5):
TAOCP.S1_2_2.ipowfollows the recursion of the book, andTAOCP.S1_2_2.eq4shows that it agrees with the integer power of Mathlib.TAOCP.S1_2_2.eq5_intis the law for integer exponents, andTAOCP.S1_2_2.eq5_addandTAOCP.S1_2_2.eq5_mulare the same laws for real exponents. - Eq. (7):
x ^ yfor real is the power of Mathlib, whichReal.rpowdefines withReal.expandReal.log, not by the squeeze of the book. The statementsTAOCP.S1_2_2.eq7andTAOCP.S1_2_2.eq7_digitsshow that this power lies between the two bounds of the squeeze. They do not say that only one number lies between all the bounds, so they do not state the definition of the book in full. - Eq. (9): the logarithm is
Real.logb, which Mathlib defines asReal.log x / Real.log b. The two statements say that the power and the logarithm are inverse. The existence and the uniqueness of the logarithm are not stated as such. - Eqs. (11) and (12) in Lean need only and , and they hold for each base . The handbook asks for and , so the Lean statements are more general.
- Eq. (16): the statement gives the integer with the two bounds, and it does not say that is the only such integer.
- Eq. (17): the statement is the bound that eq. (19) gives, for the sum of and the first bits. It does not define the infinite expansion.
- Eq. (18): the numbers are
TAOCP.S1_2_2.xSeq, the bits areTAOCP.S1_2_2.bBitand the exponent sum isTAOCP.S1_2_2.eSeq. They work onℝ, so they are not computable. - Eq. (19):
TAOCP.S1_2_2.eq19starts from with , andTAOCP.S1_2_2.eq19_bookhas the form of the book with .
The other Mathlib names that the statements use are Real.logb, Real.log, Real.exp, Int.floor and the norm ‖z‖ on ℂ. Mathlib's Real.log is defined on all nonzero reals as the logarithm of the absolute value, and . The book's logarithm is defined only for , so each statement keeps the hypothesis where it matters. The binary logarithm is Real.logb 2, by TAOCP.S1_2_2.eq13.
The exercises 1.2.2-1 to 4, 7 to 23, 29 and 30 have statements in TAOCP/Problems/S1_2_2/ and solutions in TAOCP/Solutions/S1_2_2/. The name in the table is the theorem solved of the solution file. The exercises 5, 6 and 24 to 28 are not yet stated.
Notes and history
The definition of as a root is due to Nicole Oresme (about 1360). John Wallis (1655) and Isaac Newton (1669) gave the way to define for a real exponent by a sequence of rational exponents. Logarithms were first printed by John Napier in 1614, after he worked out the natural logarithm, in a slightly changed form, around 1590. Henry Briggs published tables of base in 1624, and the method of Briggs, with a series of root extractions, is the ancestor of the shift-and-add method of exercise 1.2.2-25. F. Cajori traced the history of the logarithm and the exponential in seven papers in volume 20 (1913) of the American Mathematical Monthly. The short symbol for the binary logarithm was suggested by E. M. Reingold.
The definition of the real numbers by decimal expansions is for teaching. Modern analysis defines them by Dedekind cuts (1872) or by Cauchy sequences (G. Cantor, 1872), and proves that each real number has a decimal expansion with the uniqueness rule of this chapter. The proof of the existence of the logarithm in this chapter is the proof for the uniqueness and the existence of an inverse function from the order and the completeness of the real numbers. In a modern text it is shorter: is continuous and strictly increasing with range , so it has an inverse. The account here follows the digit method of the book, because the same digit method is the algorithm of eq. 1.2.2(16) and eq. 1.2.2(18).
The squaring method of eq. 1.2.2(18) is a form of the old method of finding the digits of a logarithm by repeated squaring. Methods that use shifts and additions only, in the style of Briggs, are in exercises 1.2.2-25 and 28. Methods of the same kind compute the trigonometric functions: the CORDIC method of J. E. Volder (1959) and the pseudo-division of J. E. Meggitt (1962).
The project has no errata of Section 1.2.2 to report for the statements of the text. The value of in eq. 1.2.2(8), to twelve significant digits, is , as given in the example of that block.
Section 1.2.2 of TAOCP fixes the number systems of the book and builds the exponential and the logarithm on them. It defines a real number by its decimal expansion, a power first for integers, then for fractions, then for all real , and the logarithm as the inverse of the power. It derives the three rules for logarithms, introduces the binary logarithm and the natural logarithm , and ends with a method that computes a logarithm one binary digit at a time. This chapter of C1 explains each item of the section, proves each claim in full, and checks the numbers by computation.
The source of this page. Something is wrong? Report it.