Exercise · Volume 1 · 1.2.1-12
Exercise 1.2.1-12
proved in Lean solution written
| Rating | M25 |
|---|---|
| Markers | M (mathematical) |
| Kind | K1, prove: show that a stated fact is true from the written solution |
| Section | Section 1.2.1 of Volume 1. Companion chapter: Mathematical induction |
The task
Describe how the extended Algorithm E can run on inputs with integers and using only integer arithmetic, and show that for , it never stops.
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
The only new point is the quotient in step E2. Ask how to decide the sign of with integers.
Hint 2
For the second part, write down the first few remainders for , and look for a pattern. Put .
Hint 3
The remainders are the powers of , and a power of a nonzero number is never .
Solution
Show the solution
Part 1: exact arithmetic. Store each of as a pair of integers that stands for . Sums, differences and products of such numbers are pairs again, since . Equality is equality of both components, because is irrational: with would give as a ratio of integers.
The sign of is found with integers only. If and are both the number is , and it is only when . If both are the number is . If , the number is positive exactly when (it cannot be ). If , the number is positive exactly when .
With the sign test, the step E2 is done for as follows. The quotient is the integer with and . Start from , and add while , or subtract while . Each test is a sign test. Then has the form again. The variables stay integers. So the whole algorithm uses only integer pairs. (A guess for from a decimal value of saves time, but the sign test makes the result exact.)
Part 2: no termination for and . Put , so , and . The first pass has , : the quotient is and . The next pass has , , with and . The next pass has . Here , so and .
Claim: for each some pass has and gives . The pass is the case . For the step, has , and . The next pass has . All remainders are positive, so step E3 never finds , and the algorithm does not stop.
Check
In exact pairs, the quotients and remainders for , are , , , , , , from a python3 run with the sign test above. After the first, these remainders are . For example and .
Remarks
The assertions A1 to A6 stay true throughout this run, so a proof of them cannot show that the algorithm stops. Exercise 1.2.1-13 adds a clock that proves the stop for integers. With integer quotients the algorithm computes the regular continued fraction of (Section 4.5.3), and for this fraction is infinite. Another extension lets the quotient itself be a number , with and the integers nearest to the two components of . Then the norm of the remainder drops at each pass and the algorithm always stops, because the ring is Euclidean.
This solution is checked, and a person has not reviewed it yet. The source.
In Lean
proved The statement and its proof are in Lean. The kernel accepts the proof, and it uses the standard axioms only.
- Problem:
TAOCP.S1_2_1.Ex12.statementaxioms: Classical.choice, Quot.sound, propext - Solution:
TAOCP.S1_2_1.Ex12.solvedaxioms: Classical.choice, Quot.sound, propext
The status is computed from the Lean build. The node of the map.
Something is wrong? Report it.