taocp

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

Exercise · Volume 1 · 1.2.2-27

Exercise 1.2.2-27

not stated yet in Lean solution written

RatingM25
MarkersM (mathematical), recommended
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 1.2.2 of Volume 1. Companion chapter: Numbers, powers and logarithms

The task

Show that the squaring method for log⁡10x\log_{10} x stays within the stated error limits when each square is replaced by an approximate value yky_k.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Define Ek=102kLkxk′E_k = 10^{2^k L_k} x'_k, where LkL_k is the number n+b1/2+⋯+bk/2kn + b_1/2 + \cdots + b_k/2^k that the method has built after kk steps. Compare with Eq. (19).

Hint 2

Prove by induction that EkE_k lies between x2k(1−δ)2k+1−1x^{2^k}(1 - \delta)^{2^{k+1}-1} and x2k(1+ϵ)2k+1−1x^{2^k}(1 + \epsilon)^{2^{k+1}-1}.

Hint 3

Take logarithms, and use 1≤xk′<101 \le x'_k < 10.

Solution

Show the solution

Assume 0≤δ<10 \le \delta < 1 and ϵ≥0\epsilon \ge 0. Let xk′=yk/10bkx'_k = y_k / 10^{b_k} with bk∈{0,1}b_k \in \{0, 1\} chosen so that 1≤xk′<101 \le x'_k < 10, which is possible because 1≤yk<1001 \le y_k < 100. Put Lk=n+b1/2+⋯+bk/2kL_k = n + b_1/2 + \cdots + b_k/2^k, and L0=nL_0 = n. The method returns log⁡′x=Lk\log' x = L_k.

Claim: for k≥0k \ge 0, x2k(1−δ)2k+1−1≤Ek≤x2k(1+ϵ)2k+1−1,Ek=102kLkxk′.x^{2^k}(1 - \delta)^{2^{k+1}-1} \le E_k \le x^{2^k}(1 + \epsilon)^{2^{k+1}-1}, \qquad E_k = 10^{2^k L_k} x'_k.

For k=0k = 0, E0=10nx0′E_0 = 10^n x'_0, and the given condition says x(1−δ)≤E0≤x(1+ϵ)x(1 - \delta) \le E_0 \le x(1 + \epsilon), so the claim holds with the exponent 21−1=12^1 - 1 = 1.

Step. Since Lk=Lk−1+bk/2kL_k = L_{k-1} + b_k/2^k, 2kLk=2kLk−1+bk2^k L_k = 2^k L_{k-1} + b_k. Hence Ek=102kLk−1+bk⋅yk10−bk=102kLk−1yk.E_k = 10^{2^k L_{k-1} + b_k} \cdot y_k 10^{-b_k} = 10^{2^k L_{k-1}} y_k. By the hypothesis on yky_k, (xk−1′)2(1−δ)≤yk≤(xk−1′)2(1+ϵ)(x'_{k-1})^2(1 - \delta) \le y_k \le (x'_{k-1})^2(1 + \epsilon). Also 102kLk−1(xk−1′)2=(102k−1Lk−1xk−1′)2=Ek−1210^{2^k L_{k-1}} (x'_{k-1})^2 = (10^{2^{k-1} L_{k-1}} x'_{k-1})^2 = E_{k-1}^2. So Ek−12(1−δ)≤Ek≤Ek−12(1+ϵ)E_{k-1}^2 (1 - \delta) \le E_k \le E_{k-1}^2 (1 + \epsilon). Insert the claim for k−1k - 1: the lower bound becomes x2k(1−δ)2(2k−1)+1=x2k(1−δ)2k+1−1x^{2^k} (1 - \delta)^{2(2^k - 1) + 1} = x^{2^k} (1 - \delta)^{2^{k+1}-1}, and the upper bound in the same way. This proves the claim.

Logarithms. Take log⁡10\log_{10} of the claim and use 0≤log⁡10xk′<10 \le \log_{10} x'_k < 1: 2kLk+1>2kLk+log⁡10xk′≥2klog⁡10x+(2k+1−1)log⁡10(1−δ),2^k L_k + 1 > 2^k L_k + \log_{10} x'_k \ge 2^k \log_{10} x + (2^{k+1} - 1)\log_{10}(1 - \delta), 2kLk≤2kLk+log⁡10xk′≤2klog⁡10x+(2k+1−1)log⁡10(1+ϵ).2^k L_k \le 2^k L_k + \log_{10} x'_k \le 2^k \log_{10} x + (2^{k+1} - 1) \log_{10}(1 + \epsilon). Divide by 2k2^k. As log⁡10(1−δ)≤0\log_{10}(1 - \delta) \le 0, (2−2−k)log⁡10(1−δ)≥2log⁡10(1−δ)(2 - 2^{-k})\log_{10}(1 - \delta) \ge 2\log_{10}(1 - \delta), and as log⁡10(1+ϵ)≥0\log_{10}(1 + \epsilon) \ge 0, (2−2−k)log⁡10(1+ϵ)≤2log⁡10(1+ϵ)(2 - 2^{-k})\log_{10}(1 + \epsilon) \le 2\log_{10}(1 + \epsilon). So log⁡10x+2log⁡10(1−δ)−2−k<Lk≤log⁡10x+2log⁡10(1+ϵ).□\log_{10} x + 2\log_{10}(1 - \delta) - 2^{-k} < L_k \le \log_{10} x + 2\log_{10}(1 + \epsilon). \qquad \square

Check

A python run of 20002000 random cases, with random xx in [1,10)[1, 10), kk up to 2525, δ\delta and ϵ\epsilon in {0,10−3,10−2}\{0, 10^{-3}, 10^{-2}\} and random errors inside these limits, gave results inside the two limits in every case.

Remarks

The errors do not grow as the exponent grows: the factor 2k+1−12^{k+1} - 1 in the exponent is cancelled by the division by 2k2^k, so the total error stays near 2δ2\delta or 2ϵ2\epsilon plus the term 2−k2^{-k} from the truncation of the series.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.