Exercise · Volume 1 · 1.2.2-6
Exercise 1.2.2-6
not stated yet in Lean solution written
| Rating | 10 |
|---|---|
| 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 rule that compares two real numbers and from their decimal expansions.
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
Think of how words are put in dictionary order.
Hint 2
Use Eq. (2) to turn the first place where the expansions differ into a strict inequality between the numbers.
Solution
Show the solution
Let and . Compare the sequences and place by place. If they agree in every place, then . Otherwise let be the first place where they differ, and the number with the larger entry at place is the larger number.
Proof. If the sequences agree, then for each both and lie in the same interval of length by Eq. (2), so for all and . Now suppose the first difference is at place with . Let be the common value . Eq. (2) gives . If the first difference is in the integer part with , then Eq. (2) with gives . In both cases , so equal expansions are the only way to get .
Check
Take and . The sequences and agree up to place , and the first difference is at place with , so . The string is not legal. Its legal form is , and the rule then compares with other expansions correctly.
Remarks
The rule needs that expansions never end in infinitely many nines. This is the point of the condition in Eq. (1).
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.