Exercise · Volume 1 · 1.2.2-28
Exercise 1.2.2-28
not stated yet in Lean solution written
| Rating | M30 |
|---|---|
| Markers | M (mathematical) |
| Kind | K5, design an algorithm: give a method for a task, often with a cost bound from the written solution |
| Section | Section 1.2.2 of Volume 1. Companion chapter: Numbers, powers and logarithms |
The task
Give a method to compute for by shifts, additions and subtractions, and bound its error.
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
Turn Exercise 1.2.2-25 around: keep a table of and build as a product of factors .
Hint 2
A multiplication by is .
Hint 3
For the accuracy, compare the rounded table and the cut shifts with the exact values, as in Exercise 1.2.2-26.
Solution
Show the solution
Let , let be the number of bits after the point, and let the table hold for , rounded to with .
Method.
- P1. Set , , .
- P2. If , stop, and is the result.
- P3. If , set and go to P2.
- P4. Set , and go to P2.
Why it works. Each execution of P4 keeps , since . The index goes up only when , so at the end . Therefore is tiny: , and .
Accuracy. Let be the number of executions of P4 and let be the product of the factors used. The computed has been cut in each shift, so each step gives with . Here , so the cut costs at most the relative amount , and the later factors are at most in total. Hence .
The exact subtractions give . With and , , so , and Since , . So For an exact table the number of executions is . For the step P4 runs at most once for each , because when P2 first meets , , and twice is more than that, since . For it runs less than times, as .
Check
Take , , and an exact table. The method gives against , a relative error of , within the bound for .
Remarks
R. Feynman is credited with this method. The final factor can be added by one more multiplication if the last bits matter. The book's answer takes another route, with the complementary variable and factors .
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.