09.12.2012 Views

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.5 RELATIVE PRIMALITY 121<br />

we get the simple <strong>for</strong>mula M(S) = S, by induction on the length of S. Isn’t<br />

that nice? (The letters L and R serve dual roles, as matrices and as letters in<br />

the string representation.) For example,<br />

M(LRRL) = LRRL = (;;)(;:)(;$(;;) = (f;)(;;) = (ii);<br />

the ancestral fractions that enclose LRRL = $ are 5 and f. And this construction<br />

gives us the answer to Question 2:<br />

f ( S ) = f((L Z,)) = s (4.34)<br />

How about Question l? That’s easy, now that we understand the fundamental<br />

connection between tree nodes and 2 x 2 matrices. Given a pair of<br />

positive integers m and n, with m I n, we can find the position of m/n in<br />

the Stern-Brocot tree by “binary search” as follows:<br />

s := I;<br />

while m/n # f(S) do<br />

if m/n < f(S) then (output(L); S := SL)<br />

else (output(R); S := SR)<br />

This outputs the desired string of L’s and R’s.<br />

There’s also another way to do the same job, by changing m and n instead<br />

of maintaining the state S. If S is any 2 x 2 matrix, we have<br />

f(RS) = f(S)+1<br />

because RS is like S but with the top row added to the bottom row. (Let’s<br />

look at it in slow motion:<br />

n’<br />

m + n m’fn’<br />

hence f(S) = (m+m’)/(n+n’) and f(RS) = ((m+n)+(m’+n’))/(n+n’).)<br />

If we carry out the binary search algorithm on a fraction m/n with m > n,<br />

the first output will be R; hence the subsequent behavior of the algorithm will<br />

have f(S) exactly 1 greater than if we had begun with (m - n)/n instead of<br />

m/n. A similar property holds <strong>for</strong> L, and we have<br />

m<br />

m - n<br />

- = f(RS) w ~ = f(S)) when m > n;<br />

n n<br />

m<br />

- = f(LS)<br />

n<br />

m<br />

- = f(S)) when m < n.<br />

n - m

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!