Exercise · Volume 1 · 1.2.2-24
Exercise 1.2.2-24
not stated yet in Lean solution written
| Rating | 15 |
|---|---|
| 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
Change the squaring method at the end of the section so that it produces binary logarithms.
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
Ask which steps of the method of Eqs. (17) and (18) depend on the base .
Hint 2
Check Eq. (19) with the new base and look at what the bits mean.
Solution
Show the solution
Choose the integer with , and set . For put Then for all , and by induction , where . The relation gives , that is . So .
The method is simpler than the decimal one. The division by is a shift of the binary point, and the bits are the binary digits of the logarithm directly, so no binary-to-decimal conversion is needed.
Check
Take , so and . The squares are (bit , ), (bit ), (bit ), (bit ) and so on. The bits give , and the true value is .
Remarks
The same scheme works for any base : compare the square with and divide by . It is natural for because the final answer is wanted in binary.
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.