Exercises 1.16 - 1.19 | |
1.16Design a procedure that evolves an iterative exponentiation process that
uses successive squaring and uses a logarithmic number of steps, as does
| |
1.17The exponentiation algorithms in this section are based on performing exponentiation by means of repeated multiplication. In a similar way, one can perform integer multiplication by means of repeated addition. The following multiplication procedure (in which it is assumed that our language can only add, not multiply) is analogous to the expt procedure: | |
This algorithm takes a number of steps that is linear in \(b\). Now suppose we include, together with addition, operations
Using these, design a multiplication procedure analogous to | |
1.18Using the results of exercises 1.16 and 1.17, devise a procedure that generates an iterative process for multiplying two integers in terms of adding, doubling, and halving and uses a logarithmic number of steps | |
1.19There is a clever algorithm for computing the Fibonacci numbers in a
logarithmic number of steps. Recall the transformation of the state
variables \(a\) and \(b\) in the $$a \leftarrow a + b \mbox{ and } b \leftarrow a$$ Call this transformation \(T\), and observe that applying \(T\) over and over again n times, starting with 1 and 0, produces the pair \(Fib(n + 1)\) and \(Fib(n)\). In other words, the Fibonacci numbers are produced by applying \(Tn\), the nth power of the transformation \(T\), starting with the pair \((1, 0)\). Now consider \(T\) to be the special case of \(p = 0\) and \(q = 1\) in a family of transformations \(Tpq\), where \(Tpq\) transforms the pair \((a,b)\) according to $$a \leftarrow bq + aq + ap$$ and $$b \leftarrow bp + aq$$ Show that if we apply such a transformation \(Tpq\) twice, the effect
is the same as using a single transformation \(Tp'q'\) of the same form, and
compute \(p'\) and \(q'\) in terms of \(p\) and \(q\). This gives us
an explicit way to square these transformations, and thus we can compute
\(Tn\) using successive squaring, as in the | |