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.3.1-8

Exercise 1.3.1-8

not stated yet in Lean solution written

Rating15
KindK8, compute by machine: find a number or an object by a large computation from the written solution
SectionSection 1.3.1 of Volume 1. Companion chapter: Description of MIX

The task

Compute rA and rX after the DIV of the section when the dividend has the bytes 12,34,0,3,112, 34, 0, 3, 1 and a minus sign.

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 cell holds − 0 0 0 2 0-\,0\,0\,0\,2\,0, the number −2b-2b, and rA is −0-0 before the instruction.

Hint 2

Only the magnitude of rAX matters for the quotient. Write the dividend as a polynomial in bb.

Solution

Show the solution

The dividend has the magnitude

n=12b4+34b3+0⋅b2+3b+1,n = 12 b^4 + 34 b^3 + 0 \cdot b^2 + 3 b + 1,

and the divisor has the magnitude d=2bd = 2b. Now

n=2b (6b3+17b2+1)+(b+1),n = 2b\,(6 b^3 + 17 b^2 + 1) + (b + 1),

because 2b⋅6b3=12b42b \cdot 6b^3 = 12 b^4, 2b⋅17b2=34b32b \cdot 17 b^2 = 34 b^3, 2b⋅1=2b2b \cdot 1 = 2b, and 3b−2b=b3b - 2b = b. The remainder b+1b + 1 is less than 2b2b. So the quotient is 6b3+17b2+0⋅b+16 b^3 + 17 b^2 + 0 \cdot b + 1, with the bytes 0,6,17,0,10, 6, 17, 0, 1. The remainder has the bytes 0,0,0,1,10, 0, 0, 1, 1.

The signs: rA and the cell are both negative, so rA becomes ++. The sign of rX is the old sign of rA, which was −-. The result is

rA=+ 0 6 17 0 1,rX=− 0 0 0 1 1.\text{rA} = +\ 0\ 6\ 17\ 0\ 1, \qquad \text{rX} = -\ 0\ 0\ 0\ 1\ 1.

The result does not depend on bb.

Check

python3 with divmod(12*b**4+34*b**3+3*b+1, 2*b) for b=64b = 64 and b=100b = 100 gives digits [0,6,17,0,1][0, 6, 17, 0, 1] and [0,0,0,1,1][0, 0, 0, 1, 1] in both cases.

Remarks

In the original example the byte pair is 12,3512, 35, and the odd byte 3535 leaves the half byte b/2b/2 in the quotient, so there the result depends on bb. This is why the table shows question marks there.

This solution is drafted, 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.