Exercise · Volume 1 · 1.1-2
Exercise 1.1-2
not stated yet in Lean solution written
| Rating | 15 |
|---|---|
| Kind | K1, prove: show that a stated fact is true from the written solution |
| Section | Section 1.1 of Volume 1. Companion chapter: Algorithms |
The task
Show that at the start of step E1, apart from the first time, the value of is larger than the value of .
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 step leads back to step E1, and what values and have just before that step.
Hint 2
Use the fact that the remainder is less than .
Solution
Show the solution
The first execution of step E1 is at the start of the algorithm. Each later execution of E1 comes from step E3. Take such a later execution and call the values of , and in the previous pass of step E1 , and . Step E1 gives . Step E2 sends control to E3 only when , and step E3 sets and . So at the new execution of E1 the values are and , and gives .
Check
Take and . At the first E1 the pair is , so . At the second it is . At the third it is , because . At the fourth it is , because , and there . In each case after the first, .
Remarks
This is why the first pass of E1 is wasted when : it only swaps the numbers. Exercise 1.1-3 and the swap step in the C1 chapter of Section 1.1 deal with that cost. Exercise 1.1-7 counts the pass again.
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.