taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.1-12

Exercise 1.2.1-12

proved in Lean solution written

RatingM25
MarkersM (mathematical)
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 1.2.1 of Volume 1. Companion chapter: Mathematical induction

The task

Describe how the extended Algorithm E can run on inputs u+v2u + v\sqrt2 with integers uu and vv using only integer arithmetic, and show that for m=1m = 1, n=2n = \sqrt2 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 q=⌊c/d⌋q = \lfloor c/d \rfloor in step E2. Ask how to decide the sign of u+v2u + v\sqrt2 with integers.

Hint 2

For the second part, write down the first few remainders for m=1m = 1, n=2n = \sqrt2 and look for a pattern. Put ε=2−1\varepsilon = \sqrt2 - 1.

Hint 3

The remainders are the powers of ε\varepsilon, and a power of a nonzero number is never 00.

Solution

Show the solution

Part 1: exact arithmetic. Store each of m,n,c,d,rm, n, c, d, r as a pair of integers (u,v)(u, v) that stands for u+v2u + v\sqrt2. Sums, differences and products of such numbers are pairs again, since (u+v2)(u′+v′2)=(uu′+2vv′)+(uv′+u′v)2(u + v\sqrt2)(u' + v'\sqrt2) = (uu' + 2vv') + (uv' + u'v)\sqrt2. Equality is equality of both components, because 2\sqrt2 is irrational: u+v2=u′+v′2u + v\sqrt2 = u' + v'\sqrt2 with v≠v′v \ne v' would give 2=(u−u′)/(v′−v)\sqrt2 = (u - u')/(v' - v) as a ratio of integers.

The sign of u+v2u + v\sqrt2 is found with integers only. If uu and vv are both ≥0\ge 0 the number is ≥0\ge 0, and it is 00 only when u=v=0u = v = 0. If both are ≤0\le 0 the number is ≤0\le 0. If u>0>vu > 0 > v, the number is positive exactly when u2>2v2u^2 > 2v^2 (it cannot be 00). If u<0<vu < 0 < v, the number is positive exactly when 2v2>u22v^2 > u^2.

With the sign test, the step E2 is done for d>0d > 0 as follows. The quotient qq is the integer with c−qd≥0c - qd \ge 0 and c−(q+1)d<0c - (q+1)d < 0. Start from q=0q = 0, and add 11 while c−(q+1)d≥0c - (q+1)d \ge 0, or subtract 11 while c−qd<0c - qd < 0. Each test is a sign test. Then r=c−qdr = c - qd has the form u+v2u + v\sqrt2 again. The variables q,a,b,a′,b′q, a, b, a', b' stay integers. So the whole algorithm uses only integer pairs. (A guess for qq from a decimal value of 2\sqrt2 saves time, but the sign test makes the result exact.)

Part 2: no termination for m=1m = 1 and n=2n = \sqrt2. Put ε=2−1\varepsilon = \sqrt2 - 1, so 0<ε<10 < \varepsilon < 1, and ε2=3−22=1−2ε\varepsilon^2 = 3 - 2\sqrt2 = 1 - 2\varepsilon. The first pass has c=1c = 1, d=2d = \sqrt2: the quotient is 00 and r=1r = 1. The next pass has c=2c = \sqrt2, d=1d = 1, with q=1q = 1 and r=εr = \varepsilon. The next pass has (c,d)=(1,ε)(c, d) = (1, \varepsilon). Here 1/ε=2+1=2.414…1/\varepsilon = \sqrt2 + 1 = 2.414\ldots, so q=2q = 2 and r=1−2ε=ε2r = 1 - 2\varepsilon = \varepsilon^2.

Claim: for each k≥0k \ge 0 some pass has (c,d)=(εk,εk+1)(c, d) = (\varepsilon^k, \varepsilon^{k+1}) and gives r=εk+2r = \varepsilon^{k+2}. The pass (1,ε)(1, \varepsilon) is the case k=0k = 0. For the step, c/d=1/ε=2.414…c/d = 1/\varepsilon = 2.414\ldots has q=2q = 2, and r=εk−2εk+1=εk(1−2ε)=εk+2r = \varepsilon^k - 2\varepsilon^{k+1} = \varepsilon^k(1 - 2\varepsilon) = \varepsilon^{k+2}. The next pass has (c,d)=(εk+1,εk+2)(c, d) = (\varepsilon^{k+1}, \varepsilon^{k+2}). All remainders are positive, so step E3 never finds r=0r = 0, and the algorithm does not stop. □\square

Check

In exact pairs, the quotients and remainders for m=1m = 1, n=2n = \sqrt2 are (q,r)=(0,1)(q, r) = (0, 1), (1,−1+2)(1, -1 + \sqrt2), (2,3−22)(2, 3 - 2\sqrt2), (2,−7+52)(2, -7 + 5\sqrt2), (2,17−122)(2, 17 - 12\sqrt2), (2,−41+292)(2, -41 + 29\sqrt2), from a python3 run with the sign test above. After the first, these remainders are ε,ε2,ε3,ε4,ε5\varepsilon, \varepsilon^2, \varepsilon^3, \varepsilon^4, \varepsilon^5. For example ε3=−7+52≈0.0711\varepsilon^3 = -7 + 5\sqrt2 \approx 0.0711 and 0.414213≈0.07110.41421^3 \approx 0.0711.

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 m/nm/n (Section 4.5.3), and for 1/21/\sqrt2 this fraction is infinite. Another extension lets the quotient qq itself be a number u+v2u + v\sqrt2, with uu and vv the integers nearest to the two components of c/dc/d. Then the norm ∣u2−2v2∣|u^2 - 2v^2| of the remainder drops at each pass and the algorithm always stops, because the ring ℤ[2]\mathbb Z[\sqrt2] 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.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.