Exercise · Volume 1 · 1.2.2-25
Exercise 1.2.2-25
not stated yet in Lean solution written
| Rating | 22 |
|---|---|
| Kind | K1, prove: show that a stated fact is true from the written solution |
| Section | Section 1.2.2 of Volume 1. Companion chapter: Numbers, powers and logarithms |
The task
Show that the shift-and-subtract algorithm terminates and that it computes for .
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
Find what is invariant in steps L3 and L4 about and . It is a relation between , and .
Hint 2
Find the quantity that does not change when is replaced by and grows by a table entry.
Hint 3
For the end, count how often step L4 can run: how large is the decrease in each time, and how small can be if ?
Solution
Show the solution
Setting. Numbers have bits after the binary point, and a right shift cuts the bits that fall off. Write for the table entries. The input is the number with , and is the variable of the algorithm.
(1) The value of . Claim: at L2, L3 and L4 the variable equals , the number with the bits after place cut. This holds after L1 for . A shift of right by one place gives , because for every real . So step L3, which halves and adds to , keeps the claim. Step L4 sets from the new , so the claim holds after it too. Write with .
(2) The reduction. Step L4 runs only when L3 found , and it replaces by . So after L4, , and holds at each pass through L2. Without the cut () the new value is exactly , so drops by while L4 adds to . Hence stays constant, and it equals at the end if the cuts are ignored.
(3) Termination. Claim: if then step L3 stops with , and the value is at least . The variable is on the grid of multiples of , so gives . Also always, since only decreases. For , , so and the test of L3 fails. Thus L3 stops at some . For and , , so . Now each execution of L4 lowers by at least , and stays true. The number of executions is finite, and the only way out is L2 with . So the algorithm terminates, and at the end .
(4) Value of the result. At the end is the sum of the table entries used. Without cuts, exactly. With the cuts, the new is a little larger than , so each L4 adds a small error to the sum , and at the end . The sum of these errors is bounded in Exercise 1.2.2-26, and it goes to as grows. So approximates .
Check
Take , and . A python run with bits and exact table values ends with after executions of L4. It gives against the true value . The difference lies between and the bound of Exercise 1.2.2-26.
Remarks
This is the method of Briggs for tables of logarithms. It uses the same idea as a division by repeated subtraction of shifted values: the quotient is not formed, only a running sum of constants. Exercise 1.2.2-28 gives the matching method for powers.
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.