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-26

Exercise 1.2.2-26

not stated yet in Lean solution written

RatingM27
MarkersM (mathematical)
KindK4, find an estimate: give an asymptotic form or a bound from the written solution
SectionSection 1.2.2 of Volume 1. Companion chapter: Numbers, powers and logarithms

The task

Give a rigorous upper bound for the error of the algorithm of Exercise 1.2.2-25, in terms of the number of bits used.

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

Express the new xx of step L4 with the cut error θ\theta of Exercise 1.2.2-25, and write down how the logarithm of xx changes.

Hint 2

Sum these changes over all the executions of L4. Telescope.

Hint 3

Count the executions of L4 by looking at how the interval for x−1x - 1 shrinks when kk grows.

Solution

Show the solution

Use the setting and the symbols of Exercise 1.2.2-25. Let the table entry in use be ck′c'_k with ∣ck′−ck∣≤η|c'_k - c_k| \le \eta. This includes the rounding of the table and the rounding of the additions to yy. Let NN be the number of executions of L4, and let x0x_0 be the input.

Error of one step. At the jjth execution of L4 with index kk, the new value is x−z=x(1−2−k)+θx - z = x(1 - 2^{-k}) + \theta with 0≤θ<2−p0 \le \theta < 2^{-p}. Since the new value is at least 11, x(1−2−k)≥1−θ>1−2−px(1 - 2^{-k}) \ge 1 - \theta > 1 - 2^{-p}. So log⁡b(x−z)=log⁡bx−ck+uj,uj=log⁡b(1+θx(1−2−k)),\log_b(x - z) = \log_b x - c_k + u_j,\qquad u_j = \log_b\Bigl(1 + \frac{\theta}{x(1 - 2^{-k})}\Bigr), and 0≤uj<log⁡b(1+2−p/(1−2−p))=−log⁡b(1−2−p)≤21−p/ln⁡b0 \le u_j < \log_b(1 + 2^{-p}/(1 - 2^{-p})) = -\log_b(1 - 2^{-p}) \le 2^{1-p}/\ln b. The last step uses −ln⁡(1−t)≤t/(1−t)≤2t-\ln(1 - t) \le t/(1 - t) \le 2t for 0<t≤1/20 < t \le 1/2.

Sum. The final xx is 11, so 0=log⁡bx0−∑ckj+∑uj0 = \log_b x_0 - \sum c_{k_j} + \sum u_j. The result is y=∑ckj′y = \sum c'_{k_j}, hence y−log⁡bx0=∑(ckj′−ckj)+∑uj,y - \log_b x_0 = \sum (c'_{k_j} - c_{k_j}) + \sum u_j, and therefore −Nη≤y−log⁡bx0≤N(η+21−p/ln⁡b).-N\eta \le y - \log_b x_0 \le N\bigl(\eta + 2^{1-p}/\ln b\bigr).

Count of NN. With k=1k = 1 the step L4 runs only if x−⌊x/2⌋p≥1x - \lfloor x/2 \rfloor_p \ge 1. This happens only for x=2−2−px = 2 - 2^{-p}, and then the new xx is 11 and the run ends, so it counts at most once. Let k≥2k \ge 2 and take the first time L4 runs with this kk. It is reached from L3, so the test at index k−1k - 1 failed to pass: x−⌊x21−k⌋p<1x - \lfloor x 2^{1-k} \rfloor_p < 1, which gives x(1−21−k)<1x(1 - 2^{1-k}) < 1. As 1−21−k≥1/21 - 2^{1-k} \ge 1/2 and x<2x < 2, x−1<x⋅21−k<22−kx - 1 < x \cdot 2^{1-k} < 2^{2-k}. Each execution with this kk lowers xx by z≥2−k−1z \ge 2^{-k-1}: for k<pk < p, z≥2−k−2−p≥2−k−1z \ge 2^{-k} - 2^{-p} \ge 2^{-k-1}, and for k=pk = p, z=2−pz = 2^{-p}. Since x−1x - 1 stays at least 00, the number jj of executions with this kk has j⋅2−k−1≤x−1<22−kj \cdot 2^{-k-1} \le x - 1 < 2^{2-k}, so j≤7j \le 7. There are p−1p - 1 values k=2,…,pk = 2, \ldots, p, hence N≤7(p−1)+1<7pN \le 7(p - 1) + 1 < 7p. □\square

With an exact table (η=0\eta = 0) the bound reads 0≤y−log⁡bx0<14p 2−p/ln⁡b0 \le y - \log_b x_0 < 14p\,2^{-p}/\ln b.

Check

A python run with p=12p = 12, b=2b = 2 and exact table values, over all 40964096 inputs x0=1+i 2−12x_0 = 1 + i\,2^{-12} with 0≤i<40960 \le i < 4096, gives errors between 00 and 0.001510.00151, always below N 21−p/ln⁡2N\,2^{1-p}/\ln 2, with at most N=11N = 11 executions of L4. The proved bound 14p 2−p/ln⁡2=0.05914p\,2^{-p}/\ln 2 = 0.059 is far from sharp, since the count 7p7p is a crude worst case.

Remarks

The true number of executions is close to pp, so the error is about p 2−pp\,2^{-p} in practice. The bound shows only that the loss is a small multiple of the precision, which is the point of the exercise.

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.