taocp

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

Volume C1 · Basic concepts · TAOCP Section 1.2.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
  1. Numbers, powers and logarithms

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 bxb^x in four steps: for integer xx by a recursion, for fractions xx by roots, for real xx by squeezing between the powers with finite decimal exponents, and for a base b<1b < 1 by a reduction to b>1b > 1. The logarithm log⁡by\log_b y 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 lg⁡\lg and ln⁡\ln. It ends with a way to compute log⁡10x\log_{10} x 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 n+0.d1d2d3…n + 0.d_1 d_2 d_3 \ldots as the definition and reads it as a sequence of bounds that squeeze the number. Each new digit cuts the interval of width 10−k10^{-k} 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, bnb^n is a product, and the laws of exponents come from induction. For a fraction p/qp/q, the power is the qqth root of bpb^p. For a real exponent, take the decimal truncations tkt_k of the exponent. Then btkb^{t_k} is a known number that rises with kk, and btk+10−kb^{t_k + 10^{-k}} is a known number that falls with kk. The gap between the two shrinks to zero, so exactly one number lies between all the pairs. That number is bxb^x.

A logarithm reads the squeeze backwards. Given yy, find the integer nn and the digits d1,d2,…d_1, d_2, \ldots one at a time, so that bb to the power of each truncation stays at or below yy. The limit is log⁡by\log_b y. This is a proof that the logarithm exists. It is also the first method of computation, because it is an algorithm: compare yy with powers of bb.

The three rules of the logarithm are the laws of exponents in a different dress. The law bx+y=bxbyb^{x+y} = b^x b^y gives log⁡b(xy)=log⁡bx+log⁡by\log_b(xy) = \log_b x + \log_b y. The law (bx)y=bxy(b^x)^y = b^{xy} gives log⁡b(cy)=ylog⁡bc\log_b(c^y) = y \log_b c. A change of the base multiplies the logarithm by a constant, and two bases compare through one number, log⁡bc\log_b c.

Squaring gives the bits of a logarithm. If 1≤x<101 \le x < 10, then log⁡10x\log_{10} x is in [0,1)[0, 1). Squaring xx doubles the logarithm. So the first binary digit of log⁡10x\log_{10} x is 11 exactly when x2≥10x^2 \ge 10, and then dividing by 1010 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 …,−2,−1,0,1,2,…\ldots, -2, -1, 0, 1, 2, \ldots. A rational number is a quotient p/qp/q of two integers with q>0q > 0. A real number is a number that a decimal expansion names (see eq. 1.2.2(1) below). A complex number is z=x+iyz = x + iy with xx and yy real and i2=−1i^2 = -1. For real u≤vu \le v, the closed interval [u..v][u \ldotp\ldotp v] is the set of xx with u≤x≤vu \le x \le v, the open interval (u..v)(u \ldotp\ldotp v) is the set with u<x<vu < x < v, and the two half-open intervals [u..v)[u \ldotp\ldotp v) and (u..v](u \ldotp\ldotp v] keep one end point. The end point −∞-\infty or ∞\infty 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 2/42/4 and 1/21/2 are equal. A rational number is in lowest terms when pp and qq 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 (1..2)(1 \ldotp\ldotp 2) and the pair (1,2)(1, 2). In Lean, the integers are ℤ, the rational numbers are ℚ, the real numbers are ℝ and the complex numbers are ℂ, and the interval [u..v][u \ldotp\ldotp v] is Set.Icc u v.

Example. The number −7/3-7/3 is rational with p=−7p = -7 and q=3q = 3. The number 0.50.5 is rational, since 0.5=1/20.5 = 1/2. The number 2\sqrt{2} is real and not rational (a proof is in the next block). The interval [0..∞)[0 \ldotp\ldotp \infty) is the set of the nonnegative real numbers. The interval (1..2](1 \ldotp\ldotp 2] contains 22 and does not contain 11.

For the claim that 2\sqrt2 is not rational: suppose 2=p/q\sqrt2 = p/q in lowest terms. Then p2=2q2p^2 = 2q^2, so pp is even, p=2rp = 2r, and 4r2=2q24r^2 = 2q^2 gives q2=2r2q^2 = 2r^2, so qq is even too. This contradicts the lowest terms. The same style of proof appears in the exercise on log⁡102\log_{10} 2 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 n+0.d1d2d3…n + 0.d_1 d_2 d_3 \ldots, where nn is an integer, each did_i is one of the digits 0,1,…,90, 1, \ldots, 9, and the digits are not all equal to 99 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 nn may be negative, and the digits after the point are always counted upward from the integer part. So −0.5-0.5 is the number −1+0.5000…-1 + 0.5000\ldots, and its integer part is −1-1. The ban on a tail of nines is a rule of form: it makes the expansion unique. Without the rule, 0.4999…0.4999\ldots and 0.5000…0.5000\ldots 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 3/83/8 has the expansion 0+0.375000…0 + 0.375000\ldots. The fraction 1/71/7 has the expansion 0+0.142857 142857…0 + 0.142857\,142857\ldots, a repeating block. The number −0.5-0.5 is −1+0.5000…-1 + 0.5000\ldots. The string 1+0.2399999…1 + 0.2399999\ldots with an endless tail of nines is not an expansion in this sense. The number that it would name is 1+0.24000…=1.241 + 0.24000\ldots = 1.24, 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 xx be a real number. For each integer k≥0k \ge 0 let tk=n+d1/10+⋯+dk/10kt_k = n + d_1/10 + \cdots + d_k/10^k (so t0=nt_0 = n). Each real number xx has exactly one such expansion. The expansion x=n+0.d1d2…x = n + 0.d_1 d_2 \ldots means that tk≤x<tk+110kfor each k≥0.t_k \le x < t_k + \frac{1}{10^k} \qquad \text{for each } k \ge 0.

Node: TA6FMM8TYB · Lean: TAOCP.S1_2_2.eq2 (partial) · status: proved

Explanation. The bounds say that tkt_k is xx cut off after kk 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 xx.

Example. Take x=22/7=3.142857…x = 22/7 = 3.142857\ldots. The values tkt_k and tk+10−kt_k + 10^{-k} for k=0,…,4k = 0, \ldots, 4 are

kk tkt_k tk+10−kt_k + 10^{-k} tk≤22/7<t_k \le 22/7 < 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 tkt_k equals ⌊10kx⌋/10k\lfloor 10^k x \rfloor / 10^k. For example 104⋅22/7=31428.57…10^4 \cdot 22/7 = 31428.57\ldots, and its floor is 3142831428.

Proof. Existence. For k≥0k \ge 0 let ak=⌊10kx⌋a_k = \lfloor 10^k x \rfloor, the greatest integer not above 10kx10^k x (Section 1.2.4 treats the floor function in detail). Put n=a0n = a_0 and dk=ak−10ak−1d_k = a_k - 10 a_{k-1} for k≥1k \ge 1. From ak−1≤10k−1x<ak−1+1a_{k-1} \le 10^{k-1} x < a_{k-1} + 1 we get 10ak−1≤10kx<10ak−1+1010 a_{k-1} \le 10^k x < 10 a_{k-1} + 10. Since aka_k is the greatest integer at most 10kx10^k x, it lies in [10ak−1,10ak−1+9][10 a_{k-1}, 10 a_{k-1} + 9], so 0≤dk≤90 \le d_k \le 9. By induction on kk, ak=10ktka_k = 10^k t_k, which gives tk≤x<tk+10−kt_k \le x < t_k + 10^{-k}. It remains to show that the digits do not all equal 99 from a place KK on. Suppose they do. Then for k>Kk > K we have ak=10k−KaK+(10k−K−1)a_k = 10^{k-K} a_K + (10^{k-K} - 1), and so x≥ak/10k=aK/10K+10−K−10−kx \ge a_k / 10^k = a_K/10^K + 10^{-K} - 10^{-k} for each k>Kk > K. Letting kk grow gives x≥(aK+1)/10Kx \ge (a_K + 1)/10^K. But x<(aK+1)/10Kx < (a_K + 1)/10^K. This is a contradiction.

Uniqueness. Let n+0.d1d2…n + 0.d_1 d_2 \ldots be any expansion of xx with the bounds of the theorem. Then 10ktk10^k t_k is an integer, and 10ktk≤10kx<10ktk+110^k t_k \le 10^k x < 10^k t_k + 1. The only integer with this property is ⌊10kx⌋\lfloor 10^k x \rfloor. So 10ktk=ak10^k t_k = a_k for each kk, and nn and each digit dk=10ktk−10⋅10k−1tk−1d_k = 10^k t_k - 10 \cdot 10^{k-1} t_{k-1} are fixed by xx. □\square

Definition C1.1.2.2.4 (the absolute value of a complex number, TAOCP eq. 1.2.2(3)). For z=x+iyz = x + iy with real xx and yy, the absolute value is ∣z∣=x2+y2|z| = \sqrt{x^2 + y^2}. The conjugate of zz is zˉ=x−iy\bar z = x - iy.

Node: TAKY3A91VT · Lean: TAOCP.S1_2_2.eq3 · status: proved

Explanation. The absolute value is the distance of the point (x,y)(x, y) from the origin of the plane. For real zz it is the usual absolute value. The conjugate satisfies zzˉ=x2+y2=∣z∣2z \bar z = x^2 + y^2 = |z|^2, since (x+iy)(x−iy)=x2−i2y2=x2+y2(x + iy)(x - iy) = x^2 - i^2 y^2 = x^2 + y^2. This identity gives the main property of the absolute value: ∣zw∣=∣z∣ ∣w∣|zw| = |z|\,|w| for all complex zz and ww. The book does not use complex numbers much, but the product rule is the base of many bounds later.

Example. For z=3+4iz = 3 + 4i we get ∣z∣=9+16=5|z| = \sqrt{9 + 16} = 5 and zzˉ=25z \bar z = 25. For z=1+2iz = 1 + 2i and w=3−iw = 3 - i, the product is zw=3−i+6i−2i2=5+5izw = 3 - i + 6i - 2i^2 = 5 + 5i, so ∣zw∣=50=52|zw| = \sqrt{50} = 5\sqrt2. The values are ∣z∣=5|z| = \sqrt5 and ∣w∣=10|w| = \sqrt{10}, and 5⋅10=50\sqrt5 \cdot \sqrt{10} = \sqrt{50}.

Proof of the product rule. The conjugate of a product is the product of the conjugates: zw‾=zˉwˉ\overline{zw} = \bar z \bar w, by a direct expansion of (x+iy)(u+iv)=(xu−yv)+i(xv+yu)(x + iy)(u + iv) = (xu - yv) + i(xv + yu) and of (x−iy)(u−iv)=(xu−yv)−i(xv+yu)(x - iy)(u - iv) = (xu - yv) - i(xv + yu). Then ∣zw∣2=zw zw‾=zzˉ wwˉ=∣z∣2∣w∣2|zw|^2 = zw\,\overline{zw} = z \bar z\, w \bar w = |z|^2 |w|^2. Both sides are nonnegative, so the square roots agree: ∣zw∣=∣z∣∣w∣|zw| = |z||w|. □\square

Definition C1.1.2.2.5 (integer powers, TAOCP eq. 1.2.2(4)). Let bb be a positive real number. The power bnb^n for an integer nn is given by b0=1b^0 = 1, then bn=bn−1bb^n = b^{n-1} b for n>0n > 0, and bn=bn+1/bb^n = b^{n+1}/b for n<0n < 0.

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 bn=bn−1bb^{n} = b^{n-1}b is to hold for all nn: solve for bn−1b^{n-1} and put n=0n = 0 to get b−1=1/bb^{-1} = 1/b. So the definition is the only one that keeps the upward rule true everywhere. The base bb may be any nonzero number in this definition; the book fixes b>0b > 0 for the later use of roots. In Lean the power with an integer exponent is zpow, written b ^ n with n : ℤ.

Example. With b=2b = 2 the upward rule gives 21=22^1 = 2, 22=42^2 = 4, 23=82^3 = 8. The downward rule gives 2−1=20/2=1/22^{-1} = 2^0/2 = 1/2, 2−2=2−1/2=1/42^{-2} = 2^{-1}/2 = 1/4, 2−3=1/8=0.1252^{-3} = 1/8 = 0.125. For b=3/2b = 3/2 and n=4n = 4: 81/16=5.062581/16 = 5.0625. For the negative base −3-3, the same rules give (−3)−3=−1/27(-3)^{-3} = -1/27, because (−3)3=−27(-3)^3 = -27 and the downward rule gives (−3)−3=((−3)−2)/(−3)=(1/9)/(−3)=−1/27(-3)^{-3} = ((-3)^{-2})/(-3) = (1/9)/(-3) = -1/27.

Theorem C1.1.2.2.6 (the laws of exponents for integers, TAOCP eq. 1.2.2(5)). Let b>0b > 0 and let xx and yy be integers. Then bx+y=bxby,(bx)y=bxy.b^{x+y} = b^x b^y, \qquad (b^x)^y = b^{xy}.

Node: TAHES3Y1A1 · Lean: TAOCP.S1_2_2.eq5_int · status: not stated yet

Explanation. The two laws are the reason that the notation bnb^n 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 xx and yy. The logarithm rules below are the same laws read in the other direction.

Example. Take b=2b = 2, x=5x = 5, y=−3y = -3. Then 2x+y=22=42^{x+y} = 2^2 = 4, and 25⋅2−3=32/8=42^5 \cdot 2^{-3} = 32/8 = 4. For the second law, x=−2x = -2 and y=3y = 3 give (2−2)3=(1/4)3=1/64(2^{-2})^3 = (1/4)^3 = 1/64 and 2−6=1/642^{-6} = 1/64.

Proof. First, bn+1=bnbb^{n+1} = b^n b for all integers nn. For n≥0n \ge 0 this is the definition at n+1>0n + 1 > 0. For n<0n < 0 the definition at nn says bn=bn+1/bb^n = b^{n+1}/b, which is the same statement.

The law bx+y=bxbyb^{x+y} = b^x b^y, for a fixed xx. For y≥0y \ge 0 use induction on yy. The case y=0y = 0 says bx=bx⋅1b^x = b^x \cdot 1. If it holds for yy, then bx+y+1=bx+yb=bxbyb=bxby+1b^{x+y+1} = b^{x+y} b = b^x b^y b = b^x b^{y+1}. For y<0y < 0 use induction downward from y=0y = 0. If bx+y+1=bxby+1b^{x+y+1} = b^x b^{y+1}, then bx+y=bx+y+1/b=bxby+1/b=bxbyb^{x+y} = b^{x+y+1}/b = b^x b^{y+1}/b = b^x b^y.

The law (bx)y=bxy(b^x)^y = b^{xy}, for a fixed xx. Let c=bxc = b^x. For y≥0y \ge 0 use induction on yy. The case y=0y = 0 says c0=1=b0c^0 = 1 = b^0. If cy=bxyc^y = b^{xy}, then cy+1=cyc=bxybx=bxy+x=bx(y+1)c^{y+1} = c^y c = b^{xy} b^x = b^{xy + x} = b^{x(y+1)} by the first law. For y<0y < 0 use induction downward. If cy+1=bx(y+1)c^{y+1} = b^{x(y+1)}, then cy=cy+1/c=bxy+x/bx=bxyc^y = c^{y+1}/c = b^{xy + x}/b^x = b^{xy}. □\square

Definition C1.1.2.2.7 (rational powers, TAOCP eq. 1.2.2(6)). Let b>0b > 0 and let p/qp/q be a rational number with q>0q > 0. Then bp/qb^{p/q} is the positive number vv with vq=bpv^q = b^p, that is, the qqth root of bpb^p.

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 vv must exist and be unique. Second, the value must not depend on the way that the rational number is written, since p/q=ap/aqp/q = ap/aq. 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 21/22^{1/2} 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. 82/38^{2/3} is the cube root of 82=648^2 = 64, which is 44. The value (0.125)−2/3(0.125)^{-2/3} is the cube root of (0.125)−2=64(0.125)^{-2} = 64, so it is again 44. Also 43/24^{3/2} is the square root of 6464, which is 88, and 46/44^{6/4} is the fourth root of 46=40964^6 = 4096, which is 88 again.

Proof that the root exists and is unique. Let u>0u > 0 and let m≥1m \ge 1 be an integer. Uniqueness: if 0<v<w0 < v < w then vm<wmv^m < w^m, because each factor of vv is below the matching factor of ww, so there is at most one positive vv with vm=uv^m = u. Existence: let SS be the set of positive vv with vm≤uv^m \le u. It is not empty, since it contains min⁡(1,u)\min(1, u), and it is bounded above by max⁡(1,u)\max(1, u) (a number v>max⁡(1,u)v > \max(1, u) has vm≥v>uv^m \ge v > u). Let ss be its least upper bound. Suppose sm<us^m < u. For 0<ε<10 < \varepsilon < 1, the difference (s+ε)m−sm=ε∑j=0m−1(s+ε)jsm−1−j≤εm(s+1)m−1(s + \varepsilon)^m - s^m = \varepsilon \sum_{j=0}^{m-1} (s+\varepsilon)^j s^{m-1-j} \le \varepsilon m (s+1)^{m-1}. For small ε\varepsilon this is less than u−smu - s^m, so s+ε∈Ss + \varepsilon \in S, which contradicts that ss is an upper bound. Suppose sm>us^m > u. For 0<ε<s0 < \varepsilon < s, sm−(s−ε)m≤εmsm−1s^m - (s - \varepsilon)^m \le \varepsilon m s^{m-1}, so for small ε\varepsilon we get (s−ε)m>u(s - \varepsilon)^m > u. Each v∈Sv \in S has vm≤u<(s−ε)mv^m \le u < (s - \varepsilon)^m, so v<s−εv < s - \varepsilon. Then s−εs - \varepsilon is an upper bound smaller than ss, which is a contradiction. So sm=us^m = u. □\square

Proof that the value does not depend on the writing. Let ww be the qqth root of bpb^p, so wq=bpw^q = b^p. For an integer a≥1a \ge 1, waq=(wq)a=(bp)a=bapw^{aq} = (w^q)^a = (b^p)^a = b^{ap} by the law for integers. So ww is also the aqaqth root of bapb^{ap}, and bap/aq=bp/qb^{ap/aq} = b^{p/q}. If p/q=p′/q′p/q = p'/q', then bp/q=bpq′/qq′b^{p/q} = b^{pq'/qq'} and bp′/q′=bp′q/q′qb^{p'/q'} = b^{p'q/q'q}, and the two exponents are equal as integer pairs because pq′=p′qpq' = p'q. □\square

Proof of the laws for rational exponents. Write two rational numbers with a common denominator DD: x=P/Dx = P/D and y=R/Dy = R/D. Let c=b1/D2c = b^{1/D^2}, the positive number with cD2=bc^{D^2} = b. Then bP/D=cDPb^{P/D} = c^{DP}, since (cDP)D=cD2P=bP(c^{DP})^D = c^{D^2 P} = b^P. In the same way bR/D=cDRb^{R/D} = c^{DR}, and b(P+R)/D=cD(P+R)b^{(P+R)/D} = c^{D(P+R)}. So the first law holds: bxby=cDPcDR=cD(P+R)=bx+yb^x b^y = c^{DP} c^{DR} = c^{D(P+R)} = b^{x+y} by the integer law. For the second law, (bx)y=(cDP)R/D(b^x)^y = (c^{DP})^{R/D}. The positive number cPc^P satisfies (cP)D=cPD(c^P)^D = c^{PD}, so (cDP)1/D=cP(c^{DP})^{1/D} = c^P, and then (cDP)R/D=(cP)R=cPR(c^{DP})^{R/D} = (c^P)^R = c^{PR}. On the other side, bxy=bPR/D2=cPRb^{xy} = b^{PR/D^2} = c^{PR}, because (cPR)D2=(cD2)PR=bPR(c^{PR})^{D^2} = (c^{D^2})^{PR} = b^{PR}. The two sides agree. □\square

Definition C1.1.2.2.8 (real powers, TAOCP eq. 1.2.2(7)). Let b>1b > 1 and let x=n+0.d1d2…x = n + 0.d_1 d_2 \ldots be a real number, with tkt_k as in eq. 1.2.2(2). Then bxb^x is the unique real number that satisfies the bounds below. For b=1b = 1 the power is bx=1b^x = 1. For 0<b<10 < b < 1 the power is bx=(1/b)−xb^x = (1/b)^{-x}. btk≤bx<btk+10−kfor each k≥0.b^{t_k} \le b^x < b^{t_k + 10^{-k}} \qquad \text{for each } k \ge 0.

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 tkt_k and tk+10−kt_k + 10^{-k} are rational, so the two bounds are rational powers, which are defined. The lower bounds rise with kk and the upper bounds fall with kk. The definition claims that exactly one real number lies in all these intervals, and that this number is the right value of bxb^x. The claim has two parts: the width of the kkth 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 b=2b = 2 and x=π=3.14159265…x = \pi = 3.14159265\ldots. The intervals for the first values of kk are (to 5 decimals)

kk tkt_k lower bound 2tk2^{t_k} upper bound 2tk+10−k2^{t_k + 10^{-k}}
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 2π2^\pi is 8.82498…8.82498\ldots, and it is inside each interval. The width falls by a factor of about 1010 at each step, as the proof below predicts.

Proof that the definition makes sense. Let b>1b > 1. First, brb^r is strictly increasing in the rational rr. If t>0t > 0 is rational, t=p/qt = p/q with p,q>0p, q > 0, then bp>1b^p > 1, and the qqth root vv of bpb^p is above 11, since v≤1v \le 1 would give vq≤1v^q \le 1. So for rational r<sr < s we have bs/br=bs−r>1b^s/b^r = b^{s - r} > 1 by the rational laws. The lower bounds btkb^{t_k} do not fall with kk, since tk≤tk+1t_k \le t_{k+1}. The upper bounds do not rise: tk+1+10−k−1=tk+(dk+1+1)10−k−1≤tk+10−kt_{k+1} + 10^{-k-1} = t_k + (d_{k+1} + 1) 10^{-k-1} \le t_k + 10^{-k}. Each interval is nonempty since tk<tk+10−kt_k < t_k + 10^{-k}.

Now the width. For N=10kN = 10^k and c=b1/Nc = b^{1/N} write c=1+yc = 1 + y with y>0y > 0. Bernoulli's inequality says (1+y)N≥1+Ny(1 + y)^N \ge 1 + Ny (induction on NN: (1+y)N+1≥(1+Ny)(1+y)≥1+(N+1)y(1+y)^{N+1} \ge (1 + Ny)(1 + y) \ge 1 + (N+1)y). So b=cN≥1+Nyb = c^N \ge 1 + Ny, which gives y≤(b−1)/Ny \le (b - 1)/N, that is b1/10k−1≤b−110k.b^{1/10^k} - 1 \le \frac{b - 1}{10^k}. Hence the width of the kkth interval is btk(b10−k−1)≤bn+1(b−1)/10kb^{t_k}(b^{10^{-k}} - 1) \le b^{n+1}(b - 1)/10^k, using tk≤n+1t_k \le n + 1. 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 bxb^x. If xx is itself rational, the rational power bxb^x lies in all the intervals, because tk≤x<tk+10−kt_k \le x < t_k + 10^{-k} and brb^r is strictly increasing in rational rr; so the new definition agrees with the old one. □\square

The laws for real exponents. Let b>1b > 1. The number bxb^x equals the least upper bound of the set of brb^r with rr rational and r≤xr \le x. Indeed, each such brb^r is at most bxb^x: if r<xr < x, then r<tkr < t_k for large kk, since tk≥x−10−kt_k \ge x - 10^{-k}, and br≤btk≤bxb^r \le b^{t_k} \le b^x; if r=xr = x the two numbers are equal. And the numbers btkb^{t_k} themselves come as close to bxb^x as the width of the interval allows. With this fact the laws follow. For the first law, the set of the sums r+sr + s with r≤xr \le x and s≤ys \le y rational contains each rational q<x+yq < x + y (split qq as r+sr + s with rr slightly below xx, using y−(q−x)>0y - (q - x) > 0 room). So bxby=sup⁡br⋅sup⁡bs=sup⁡br+s=bx+yb^x b^y = \sup b^r \cdot \sup b^s = \sup b^{r+s} = b^{x+y}. The first step uses that a product of two suprema of positive sets is the supremum of the products. For the second law, with x>0x > 0, first prove (bx)r=bxr(b^x)^r = b^{xr} for rational r=p/qr = p/q: (bx)p=bxp(b^x)^p = b^{xp} by the first law applied pp times, and (bxp/q)q=bxp(b^{xp/q})^q = b^{xp} by the first law applied qq times, so bxp/qb^{xp/q} is the qqth root of (bx)p(b^x)^p. For real yy, both (bx)y(b^x)^y and bxyb^{xy} are suprema: (bx)y=sup⁡(bx)r=sup⁡bxr(b^x)^y = \sup (b^x)^r = \sup b^{xr} over rational r≤yr \le y, and bxy=sup⁡bsb^{xy} = \sup b^s over rational s≤xys \le xy. Each bxrb^{xr} is at most bxyb^{xy}, since xr≤xyxr \le xy and btb^t is increasing in real tt (by the first law and bt>1b^t > 1 for t>0t > 0). Conversely each rational s<xys < xy has a rational rr with s/x<r<ys/x < r < y, so bs≤bxrb^s \le b^{xr}. The two suprema agree. The cases x<0x < 0, x=0x = 0 and b<1b < 1 reduce to this one by b−x=1/bxb^{-x} = 1/b^x and by the definition bx=(1/b)−xb^x = (1/b)^{-x}.

Example C1.1.2.2.9 (two powers of 10 near 2, TAOCP eq. 1.2.2(8)). The two numbers 100.3010299910^{0.30102999} and 100.3010300010^{0.30103000} surround the number 22: 100.30102999=1.9999999739…,100.30103000=2.0000000199…10^{0.30102999} = 1.9999999739\ldots, \qquad 10^{0.30103000} = 2.0000000199\ldots

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 22, and the exponents differ by 10−810^{-8}. Since 10x10^x is strictly increasing in xx, any exponent xx with 10x=210^x = 2 lies between 0.301029990.30102999 and 0.301030000.30103000. This gives eight correct decimal places of xx.

Example. The first value is 1.99999997392…1.99999997392\ldots and the second is 2.00000001997…2.00000001997\ldots (computed with 40 digits of precision). Their relative distance from 22 is about 1.3×10−81.3 \times 10^{-8} and 10−810^{-8}. A check by the law of exponents: 100.30103000/100.30102999=100.00000001=1+2.3026×10−8+…10^{0.30103000} / 10^{0.30102999} = 10^{0.00000001} = 1 + 2.3026 \times 10^{-8} + \ldots, and the quotient of the two numbers above is 2.00000001997/1.99999997392=1.0000000230…2.00000001997/1.99999997392 = 1.0000000230\ldots. The two agree.

Proof. Each claim is an exact statement about integers. Write 0.30102999=30102999/1080.30102999 = 30102999/10^8. By eq. 1.2.2(6), 1030102999/10810^{30102999/10^8} is below 22 if and only if 1030102999<210810^{30102999} < 2^{10^8}, because the 10810^8th power is strictly increasing. In the same way, 1030103000/108>210^{30103000/10^8} > 2 if and only if 1030103000>210810^{30103000} > 2^{10^8}. 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. □\square

Definition C1.1.2.2.10 (the logarithm, TAOCP eq. 1.2.2(9)). Let b>0b > 0, b≠1b \ne 1, and y>0y > 0. The logarithm of yy to the base bb, written log⁡by\log_b y, is the real number xx with bx=yb^x = y. It exists, and it is unique. By the definition, y=blog⁡by,x=log⁡b(bx).y = b^{\log_b y}, \qquad x = \log_b(b^x).

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 x↦bxx \mapsto b^x and y↦log⁡byy \mapsto \log_b y are inverse to each other. The base 11 is excluded, since 1x=11^x = 1 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. log⁡28=3\log_2 8 = 3, since 23=82^3 = 8. log⁡100.001=−3\log_{10} 0.001 = -3. log⁡1/28=−3\log_{1/2} 8 = -3, because (1/2)−3=8(1/2)^{-3} = 8. log⁡210=3.3219…\log_2 10 = 3.3219\ldots, since 23.3219≈102^{3.3219} \approx 10. log⁡b1=0\log_b 1 = 0 for each admissible bb, and log⁡bb=1\log_b b = 1. The value log⁡b(−1)\log_b(-1) is not defined, since bx>0b^x > 0 for each real xx.

Proof. Let first b>1b > 1 and y>0y > 0. Uniqueness: bxb^x is strictly increasing in xx (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 nn as the largest integer with bn≤yb^n \le y. Such an nn exists, since the powers bnb^n grow without bound as n→∞n \to \infty and fall to 00 as n→−∞n \to -\infty. Suppose that tk−1t_{k-1} has been chosen with btk−1≤y<btk−1+10−(k−1)b^{t_{k-1}} \le y < b^{t_{k-1} + 10^{-(k-1)}}. Choose dkd_k as the largest digit in {0,…,9}\{0, \ldots, 9\} with btk−1+dk/10k≤yb^{t_{k-1} + d_k/10^k} \le y. Digit 00 works. If dk<9d_k < 9, the maximality gives y<btk+10−ky < b^{t_k + 10^{-k}}. If dk=9d_k = 9, then tk+10−k=tk−1+10−(k−1)t_k + 10^{-k} = t_{k-1} + 10^{-(k-1)} and the bound is the one known from the step before. So btk≤y<btk+10−kb^{t_k} \le y < b^{t_k + 10^{-k}} for each kk. Let xx be the number n+0.d1d2…n + 0.d_1 d_2 \ldots if the digits do not end in an endless tail of 99s. If they do end in nines from the place KK, then y≥btky \ge b^{t_k} for all kk and btk→btK+10−Kb^{t_k} \to b^{t_K + 10^{-K}}, which contradicts y<btK+10−Ky < b^{t_K + 10^{-K}}. So the expansion is valid. Both yy and bxb^x lie in the interval [btk,btk+10−k)[b^{t_k}, b^{t_k + 10^{-k}}) for each kk, the widths go to zero, and so y=bxy = b^x.

For 0<b<10 < b < 1 we have bx=(1/b)−xb^x = (1/b)^{-x} by definition, so y=bxy = b^x if and only if −x-x is the logarithm of yy to the base 1/b1/b. This gives existence and uniqueness. The two displayed equations are the definition itself. □\square

Example C1.1.2.2.11 (the value of log⁡102\log_{10} 2, TAOCP eq. 1.2.2(10)). From eq. 1.2.2(8), log⁡102=0.30102999…\log_{10} 2 = 0.30102999\ldots

Node: TAT7EWGNPG · status: not stated yet

Explanation. The exponent xx with 10x=210^x = 2 is greater than 0.301029990.30102999 and less than 0.301030000.30103000, since the two powers in eq. 1.2.2(8) lie on the two sides of 22 and 10x10^x is strictly increasing. By eq. 1.2.2(2), these two bounds fix the first eight digits after the point: 0.301029990.30102999. The next digits are 56…56\ldots, so the full value is 0.3010299956…0.3010299956\ldots. 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 xx agrees with log⁡102\log_{10} 2 in its first kk places, then 10x10^x can be just below 22 or at least 22, for each kk. So no finite number of digits of xx tells whether the expansion of 10x10^x starts with 1.9991.999 or with 2.0002.000 (exercise 1.2.2-11).

Example. The value gives quick estimates. Since 100.30103≈210^{0.30103} \approx 2, we get 210=10242^{10} = 1024 and log⁡101024=3.0103\log_{10} 1024 = 3.0103. Also log⁡105=1−log⁡102=0.69897\log_{10} 5 = 1 - \log_{10} 2 = 0.69897.

Proof that log⁡102\log_{10} 2 is irrational. Suppose log⁡102=p/q\log_{10} 2 = p/q with positive integers pp and qq. Then 10p/q=210^{p/q} = 2, so 10p=2q10^p = 2^q. The left side is divisible by 55 and the right side is not, since its only prime factor is 22. This is a contradiction. □\square

Theorem C1.1.2.2.12 (the logarithm of a product, TAOCP eq. 1.2.2(11)). Let b>0b > 0, b≠1b \ne 1, x>0x > 0 and y>0y > 0. Then log⁡b(xy)=log⁡bx+log⁡by.\log_b(xy) = \log_b x + \log_b y.

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 log⁡10\log_{10} makes a multiplication into an addition and two lookups. The rule also gives log⁡b(x/y)=log⁡bx−log⁡by\log_b(x/y) = \log_b x - \log_b y (exercise 1.2.2-15), since log⁡b(1/y)=−log⁡by\log_b(1/y) = -\log_b y.

Example. log⁡106=log⁡102+log⁡103=0.30103+0.47712=0.77815\log_{10} 6 = \log_{10} 2 + \log_{10} 3 = 0.30103 + 0.47712 = 0.77815. A direct computation gives log⁡106=0.778151…\log_{10} 6 = 0.778151\ldots. Also log⁡212=log⁡23+log⁡24=1.58496+2=3.58496\log_2 12 = \log_2 3 + \log_2 4 = 1.58496 + 2 = 3.58496.

Proof. Let u=log⁡bxu = \log_b x and v=log⁡byv = \log_b y, so that bu=xb^u = x and bv=yb^v = y. By the first law of exponents, xy=bubv=bu+vxy = b^u b^v = b^{u+v}. So bb to the power u+vu + v is xyxy. By uniqueness of the logarithm, log⁡b(xy)=u+v\log_b(xy) = u + v. □\square

Theorem C1.1.2.2.13 (the logarithm of a power, TAOCP eq. 1.2.2(12)). Let b>0b > 0, b≠1b \ne 1, c>0c > 0 and let yy be real. Then log⁡b(cy)=ylog⁡bc.\log_b(c^y) = y \log_b c.

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 210002^{1000} is 10001000 times the logarithm of 22. It also gives the number of digits of a large integer: the positive integer NN has ⌊log⁡10N⌋+1\lfloor \log_{10} N \rfloor + 1 decimal digits.

Example. log⁡10(210)=10×0.30103=3.0103\log_{10}(2^{10}) = 10 \times 0.30103 = 3.0103, and 210=10242^{10} = 1024 has 44 digits. log⁡10(31000)=1000×0.4771212547…=477.12…\log_{10}(3^{1000}) = 1000 \times 0.4771212547\ldots = 477.12\ldots, so 310003^{1000} has 478478 digits.

Proof. Let L=log⁡bcL = \log_b c, so c=bLc = b^L. By the second law of exponents, cy=(bL)y=bLyc^y = (b^L)^y = b^{Ly}. So bb to the power LyLy is cyc^y, and by uniqueness log⁡b(cy)=Ly=ylog⁡bc\log_b(c^y) = Ly = y \log_b c. □\square

Definition C1.1.2.2.14 (the binary logarithm, TAOCP eq. 1.2.2(13)). The binary logarithm of x>0x > 0 is lg⁡x=log⁡2x\lg x = \log_2 x.

Node: TAR1FK2HA8 · Lean: TAOCP.S1_2_2.eq13 · status: proved

Explanation. Binary logarithms count halvings. A number of size nn that is halved at each step reaches 11 in about lg⁡n\lg n 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 lg⁡\lg for it from this section on. A log⁡\log with no base is rare in the book. It appears mostly where the base changes only a constant factor, as inside the OO-notation. In Lean, Real.logb 2 is the binary logarithm.

Example. lg⁡32=5\lg 32 = 5, lg⁡1024=10\lg 1024 = 10, lg⁡(1/8)=−3\lg(1/8) = -3, lg⁡1000=9.9658…\lg 1000 = 9.9658\ldots (since 210=10242^{10} = 1024 is a little above 10001000). A positive integer NN has ⌊lg⁡N⌋+1\lfloor \lg N \rfloor + 1 bits: N=1000N = 1000 has 1010 bits, since 29=512≤1000<1024=2102^9 = 512 \le 1000 < 1024 = 2^{10}.

Theorem C1.1.2.2.15 (the change of the base, TAOCP eq. 1.2.2(14)). Let b,c>0b, c > 0 with b≠1b \ne 1 and c≠1c \ne 1, and let x>0x > 0. Then log⁡cx=log⁡bxlog⁡bc.\log_c x = \frac{\log_b x}{\log_b c}.

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 lg⁡x=log⁡10x/log⁡102\lg x = \log_{10} x / \log_{10} 2 and log⁡10x=ln⁡x/ln⁡10\log_{10} x = \ln x/\ln 10. With x=bx = b the rule gives log⁡cb=1/log⁡bc\log_c b = 1/\log_b c (exercise 1.2.2-20).

Example. lg⁡1000=log⁡101000/log⁡102=3/0.30103=9.9658\lg 1000 = \log_{10} 1000 / \log_{10} 2 = 3/0.30103 = 9.9658. log⁡210=1/log⁡102=3.3219\log_2 10 = 1/\log_{10} 2 = 3.3219. log⁡8x=lg⁡x/lg⁡8=13lg⁡x\log_8 x = \lg x/\lg 8 = \tfrac13 \lg x, which shows that the claim log⁡8x=12lg⁡x\log_8 x = \tfrac12 \lg x of exercise 1.2.2-18 is false.

Proof. By eq. 1.2.2(9), x=clog⁡cxx = c^{\log_c x}. Apply log⁡b\log_b and use the rule for a power: log⁡bx=log⁡b(clog⁡cx)=(log⁡cx)(log⁡bc)\log_b x = \log_b (c^{\log_c x}) = (\log_c x)(\log_b c). Divide by log⁡bc\log_b c, which is not zero since c≠1c \ne 1. □\square

Definition C1.1.2.2.16 (the natural logarithm, TAOCP eq. 1.2.2(15)). The natural logarithm is ln⁡x=log⁡ex\ln x = \log_e x, where e=2.718281828459045…e = 2.718281828459045\ldots is the base of natural logarithms.

Node: TA0T0P4C7M · Lean: TAOCP.S1_2_2.eq15 · status: proved

Explanation. The book does not define ee at this point. A standard definition is e=lim⁡n→∞(1+1/n)ne = \lim_{n \to \infty} (1 + 1/n)^n, and with this base the area under the curve y=1/ty = 1/t from t=1t = 1 to t=xt = x equals ln⁡x\ln x for each x>1x > 1. These two facts are proofs of calculus, and C1 does not repeat them. For the use here, ln⁡\ln is a logarithm like the other ones, and each rule above holds for it. In analysis and in the later sections of the book, ln⁡\ln 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 r=1r = 1 (one hundred percent) per year, with nn payments, is (1+1/n)n(1 + 1/n)^n. For n=1,2,4,12,365,10000n = 1, 2, 4, 12, 365, 10000 the values are 22, 2.252.25, 2.44142.4414, 2.61302.6130, 2.71462.7146 and 2.71812.7181. They approach ee. The value ln⁡10=2.302585…\ln 10 = 2.302585\ldots gives log⁡107=ln⁡7/ln⁡10=1.945910/2.302585=0.845098\log_{10} 7 = \ln 7/\ln 10 = 1.945910/2.302585 = 0.845098.

Theorem C1.1.2.2.17 (a bound that gives the digits of a logarithm, TAOCP eq. 1.2.2(16)). Let b>1b > 1, y>0y > 0, and let k≥0k \ge 0 be an integer. Let m=⌊10klog⁡by⌋m = \lfloor 10^k \log_b y \rfloor. Then mm is the one integer with the property below, and m/10km/10^k is log⁡by\log_b y rounded down to kk decimal places. bm≤y10k<bm+1.b^m \le y^{10^k} < b^{m+1}.

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 yy to the power 10k10^k and see between which two powers of bb the result lies. The method is impractical, since y10ky^{10^k} is a huge number, but it is exact and it explains the next method.

Example. Take y=2y = 2 and b=10b = 10. For k=1k = 1: 210=10242^{10} = 1024 lies between 10310^3 and 10410^4, so m=3m = 3 and log⁡102∈[0.3,0.4)\log_{10} 2 \in [0.3, 0.4). For k=2k = 2: 2100=1.2676…×10302^{100} = 1.2676\ldots \times 10^{30}, so m=30m = 30 and log⁡102∈[0.30,0.31)\log_{10} 2 \in [0.30, 0.31). For k=3k = 3: 21000=1.0715…×103012^{1000} = 1.0715\ldots \times 10^{301}, so m=301m = 301 and log⁡102∈[0.301,0.302)\log_{10} 2 \in [0.301, 0.302). For y=3y = 3: 310=590493^{10} = 59049 gives m=4m = 4, 3100=5.15…×10473^{100} = 5.15\ldots \times 10^{47} gives m=47m = 47, and 31000=1.32…×104773^{1000} = 1.32\ldots \times 10^{477} gives m=477m = 477, and so log⁡103=0.477…\log_{10} 3 = 0.477\ldots.

Proof. Put x=log⁡byx = \log_b y. By the rule for a power, log⁡b(y10k)=10kx\log_b(y^{10^k}) = 10^k x. Since b>1b > 1, the function s↦bss \mapsto b^s is strictly increasing, and so is its inverse. An integer mm satisfies bm≤y10k<bm+1b^m \le y^{10^k} < b^{m+1} if and only if m≤10kx<m+1m \le 10^k x < m + 1, that is m=⌊10kx⌋m = \lfloor 10^k x \rfloor. □\square

Definition C1.1.2.2.18 (the binary expansion of a logarithm, TAOCP eq. 1.2.2(17)). For x>0x > 0, the binary expansion of log⁡10x\log_{10} x is the representation below, where nn is an integer and each bkb_k is 00 or 11 (the bits). log⁡10x=n+b12+b24+b38+⋯ ,\log_{10} x = n + \frac{b_1}{2} + \frac{b_2}{4} + \frac{b_3}{8} + \cdots,

Node: TA3K5VA1YD · Lean: TAOCP.S1_2_2.eq17 (partial) · status: proved

Explanation. This is eq. 1.2.2(1) in base 22 instead of base 1010, applied to a logarithm. The integer part nn is the exponent of the power of 1010 in the scientific form of xx: it is the integer with 1≤x/10n<101 \le x / 10^n < 10. The fractional part is log⁡10(x/10n)\log_{10}(x/10^n), a number in [0,1)[0, 1), and the bits bkb_k are its binary digits. The rule on the tail is the same as for decimal digits: the bits are not all 11 from some place on (exercise 1.2.2-5 asks for the matching definition of the real numbers).

Example. log⁡102=0.3010299956…\log_{10} 2 = 0.3010299956\ldots has the bits 0100110100010000010011010…0100110100010000010011010\ldots (computed by the method of eq. 1.2.2(18); see the run below). So log⁡102=0/2+1/4+0/8+0/16+1/32+1/64+…=0.25+0.03125+0.015625+…\log_{10} 2 = 0/2 + 1/4 + 0/8 + 0/16 + 1/32 + 1/64 + \ldots = 0.25 + 0.03125 + 0.015625 + \ldots. For x=3000x = 3000: n=3n = 3, since 3000/103=33000 / 10^3 = 3, and log⁡103000=3+log⁡103=3.4771…\log_{10} 3000 = 3 + \log_{10} 3 = 3.4771\ldots.

Theorem C1.1.2.2.19 (the invariant of the squaring method, TAOCP eq. 1.2.2(19)). Let x>0x > 0, let nn be the integer with 1≤x/10n<101 \le x/10^n < 10, and let x0=x/10nx_0 = x/10^n. Define bkb_k and xkx_k for k≥1k \ge 1 by the rule of eq. 1.2.2(18) (see the algorithm below). Then for each k≥0k \ge 0, 1≤xk=x2k102k(n+b1/2+⋯+bk/2k)<10.1 \le x_k = \frac{x^{2^k}}{10^{2^k (n + b_1/2 + \cdots + b_k/2^k)}} < 10.

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 xkx_k is the original xx raised to the 2k2^kth power and divided by the power of 1010 that is just enough to bring it back into [1,10)[1, 10). The exponent of 1010 is 2k2^k times the part of the logarithm found so far. The invariant gives the correctness of the method.

Example. Take x=3x = 3, so n=0n = 0 and x0=3x_0 = 3. After k=3k = 3 steps the bits are b1b2b3=0 1 1b_1 b_2 b_3 = 0\,1\,1, so b1/2+b2/4+b3/8=3/8b_1/2 + b_2/4 + b_3/8 = 3/8. The invariant says x3=38/108⋅3/8=6561/1000=6.561x_3 = 3^8 / 10^{8 \cdot 3/8} = 6561/1000 = 6.561. This is the value in the table of the worked run below.

Proof. Induction on kk. For k=0k = 0, x0=x/10nx_0 = x/10^n, and the statement is 1≤x/10n<101 \le x/10^n < 10, which is how nn was chosen. Suppose the formula holds for k−1k - 1, and write sk−1=n+b1/2+⋯+bk−1/2k−1s_{k-1} = n + b_1/2 + \cdots + b_{k-1}/2^{k-1}, so xk−1=x2k−1/102k−1sk−1x_{k-1} = x^{2^{k-1}}/10^{2^{k-1} s_{k-1}} and 1≤xk−1<101 \le x_{k-1} < 10. Then xk−12=x2k/102ksk−1x_{k-1}^2 = x^{2^k}/10^{2^k s_{k-1}} and 1≤xk−12<1001 \le x_{k-1}^2 < 100. If xk−12<10x_{k-1}^2 < 10, then bk=0b_k = 0 and xk=xk−12x_k = x_{k-1}^2. Then sk=sk−1s_k = s_{k-1}, the formula holds, and 1≤xk<101 \le x_k < 10. If xk−12≥10x_{k-1}^2 \ge 10, then bk=1b_k = 1 and xk=xk−12/10x_k = x_{k-1}^2/10. Then sk=sk−1+1/2ks_k = s_{k-1} + 1/2^k, so 102ksk=102ksk−1⋅1010^{2^k s_k} = 10^{2^k s_{k-1}} \cdot 10, and the formula holds. Also 1≤xk<101 \le x_k < 10 since 10≤xk−12<10010 \le x_{k-1}^2 < 100. □\square

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 x>0x > 0 and a number K≥0K \ge 0 of bits. The output is the integer nn and the bits b1,…,bKb_1, \ldots, b_K of eq. 1.2.2(17), the first KK places of the binary expansion of log⁡10x\log_{10} x.

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 1≤z<101 \le z < 10, then log⁡10z∈[0,1)\log_{10} z \in [0, 1) and log⁡10(z2)=2log⁡10z∈[0,2)\log_{10}(z^2) = 2 \log_{10} z \in [0, 2). Doubling a binary fraction moves its first bit to the integer place. So the first bit of log⁡10z\log_{10} z is 11 exactly when z2≥10z^2 \ge 10. In that case divide z2z^2 by 1010 to take away the integer part, and the new number lies again in [1,10)[1, 10). 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 zz in the place of the sequence x0,x1,…x_0, x_1, \ldots, so that z=xkz = x_k after pass kk.

A worked run. Take x=3x = 3, so n=0n = 0 and z=3z = 3. The table lists xkx_k (exact up to k=5k = 5, then rounded to 15 significant digits), the bit, and the partial sum sk=b1/2+⋯+bk/2ks_k = b_1/2 + \cdots + b_k/2^k. The true value is log⁡103=0.4771212547…\log_{10} 3 = 0.4771212547\ldots

kk xk−12x_{k-1}^2 bkb_k xkx_k sks_k log⁡103−sk\log_{10} 3 - s_k
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 log⁡103\log_{10} 3 are 0 1 1 1 1 0 1 00\,1\,1\,1\,1\,0\,1\,0. The gap in the last column is always at least 00 and less than 2−k2^{-k}, as the proof below shows. The pass k=3k = 3 checks the invariant: x3=38/103=6.561x_3 = 3^8/10^3 = 6.561. 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 kk, 1≤z=x2k/102ksk<101 \le z = x^{2^k}/10^{2^k s_k} < 10, where sk=n+b1/2+⋯+bk/2ks_k = n + b_1/2 + \cdots + b_k/2^k. The theorem above proves that the invariant holds at the start (k=0k = 0) and is kept by each pass. Now take the logarithm to the base 1010 of the invariant: 0≤2k(log⁡10x−sk)<10 \le 2^k (\log_{10} x - s_k) < 1. So sk≤log⁡10x<sk+12k.s_k \le \log_{10} x < s_k + \frac{1}{2^k}. This is the property of the output: the bits b1,…,bKb_1, \ldots, b_K are the first KK bits of log⁡10x\log_{10} x, and they fix log⁡10x\log_{10} x to an interval of width 2−K2^{-K}. The same inequality for each KK shows that the infinite sequence of bits is the binary expansion of log⁡10x\log_{10} x. The algorithm stops, since the loop runs exactly KK times.

The cost. The loop has KK passes. Each pass has one squaring, one comparison with 1010, and at most one division by 1010. So the total cost is KK squarings, KK comparisons and at most KK divisions by 1010 (a shift of the decimal point, in a decimal computer). To get mm decimal places of log⁡10x\log_{10} x takes K≈mlg⁡10=3.32 mK \approx m \lg 10 = 3.32\,m passes. This is much less work than the method of eq. 1.2.2(16), which raises yy to a power with 10m10^m in the exponent.

The effect of rounding. A real machine keeps zz to a fixed number of digits. Suppose that each computed square is zk−1′2(1+ηk)z'_{k-1}{}^2 (1 + \eta_k) with ∣log⁡10(1+ηk)∣≤c|\log_{10}(1 + \eta_k)| \le c, that the division by 1010 is exact, that the first value has ∣log⁡10(z0′/z0)∣≤c|\log_{10}(z'_0/z_0)| \le c, and that each computed zk′z'_k stays in [1,10)[1, 10). Let L=log⁡10xL = \log_{10} x, ℓk=log⁡10zk′\ell_k = \log_{10} z'_k and Tk=2k(L−sk)T_k = 2^k(L - s_k), where sk=n+b1/2+⋯+bk/2ks_k = n + b_1/2 + \cdots + b_k/2^k. Then ℓk=2ℓk−1+log⁡10(1+ηk)−bk\ell_k = 2\ell_{k-1} + \log_{10}(1 + \eta_k) - b_k and Tk=2Tk−1−bkT_k = 2T_{k-1} - b_k. So Ek=ℓk−TkE_k = \ell_k - T_k satisfies Ek=2Ek−1+log⁡10(1+ηk)E_k = 2E_{k-1} + \log_{10}(1 + \eta_k) with ∣E0∣≤c|E_0| \le c, and therefore ∣EK∣≤c(2K+2K−1+⋯+1)=c(2K+1−1)<2K+1c|E_K| \le c(2^K + 2^{K-1} + \cdots + 1) = c(2^{K+1} - 1) < 2^{K+1} c. Now L−sK=(ℓK−EK)/2KL - s_K = (\ell_K - E_K)/2^K and 0≤ℓK<10 \le \ell_K < 1, so −2c<L−sK<2−K+2c.-2c < L - s_K < 2^{-K} + 2c. The computed bits give log⁡10x\log_{10} x with an error below 2−K+2c2^{-K} + 2c. 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 log⁡102\log_{10} 2: 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 lg⁡x≈ln⁡x+log⁡10x\lg x \approx \ln x + \log_{10} x 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 22, 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 bxb^x.

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 ⌊10kx⌋/10k\lfloor 10^k x \rfloor / 10^k. The uniqueness of the expansion is not stated.
  • Eqs. (4) and (5): TAOCP.S1_2_2.ipow follows the recursion of the book, and TAOCP.S1_2_2.eq4 shows that it agrees with the integer power of Mathlib. TAOCP.S1_2_2.eq5_int is the law for integer exponents, and TAOCP.S1_2_2.eq5_add and TAOCP.S1_2_2.eq5_mul are the same laws for real exponents.
  • Eq. (7): x ^ y for real yy is the power of Mathlib, which Real.rpow defines with Real.exp and Real.log, not by the squeeze of the book. The statements TAOCP.S1_2_2.eq7 and TAOCP.S1_2_2.eq7_digits show 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 as Real.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 x,y>0x, y > 0 and c>0c > 0, and they hold for each base bb. The handbook asks for b>0b > 0 and b≠1b \ne 1, so the Lean statements are more general.
  • Eq. (16): the statement gives the integer m=⌊10kx⌋m = \lfloor 10^k x \rfloor with the two bounds, and it does not say that mm is the only such integer.
  • Eq. (17): the statement is the bound that eq. (19) gives, 0≤log⁡10x−sk<2−k0 \le \log_{10} x - s_k < 2^{-k} for the sum sks_k of nn and the first kk bits. It does not define the infinite expansion.
  • Eq. (18): the numbers are TAOCP.S1_2_2.xSeq, the bits are TAOCP.S1_2_2.bBit and the exponent sum is TAOCP.S1_2_2.eSeq. They work on ℝ, so they are not computable.
  • Eq. (19): TAOCP.S1_2_2.eq19 starts from x0x_0 with 1≤x0<101 \le x_0 < 10, and TAOCP.S1_2_2.eq19_book has the form of the book with x0=x/10nx_0 = x / 10^n.

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 log⁡0=0\log 0 = 0. The book's logarithm is defined only for x>0x > 0, so each statement keeps the hypothesis 0<x0 < x where it matters. The binary logarithm lg⁡\lg 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 bp/qb^{p/q} as a root is due to Nicole Oresme (about 1360). John Wallis (1655) and Isaac Newton (1669) gave the way to define bxb^x 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 1010 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 lg⁡\lg 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: bxb^x is continuous and strictly increasing with range (0,∞)(0, \infty), 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 100.3010299910^{0.30102999} in eq. 1.2.2(8), to twelve significant digits, is 1.99999997392…1.99999997392\ldots, 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 bxb^x first for integers, then for fractions, then for all real xx, and the logarithm as the inverse of the power. It derives the three rules for logarithms, introduces the binary logarithm lg⁡\lg and the natural logarithm ln⁡\ln, 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.