diff --git a/books/bookvol10.4.pamphlet b/books/bookvol10.4.pamphlet index 9abbe53..aef7b71 100644 --- a/books/bookvol10.4.pamphlet +++ b/books/bookvol10.4.pamphlet @@ -135210,6 +135210,22 @@ RepeatedDoubling(S):Exports ==Implementation where @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{package REPSQ RepeatedSquaring} +This code computes $x^n$ by repeated squaring. It takes advantage of the +law of exponents so that if $n=a*b$ then +$x^n = x^a x^b$ +It also takes advantage of the fact that $n$ has a binary representation +so that a one-bit right-shift of a number divides it by 2. Thus we get +three cases: +$+\begin{array}{l} + n = 1 \rightarrow x^1 \\ + n \textrm{\ \ odd} \rightarrow \textrm{repeatedsquare}(x*x,n/2)*x \\ + n \textrm{\ even} \rightarrow \textrm{repeatedsquare}(x*x,n/2) +\end{array} +$ + +Since each recursive call divides $n$ by $2$ the algorithm is O(log(n)). + \pagehead{RepeatedSquaring}{REPSQ} \pagepic{ps/v104repeatedsquaring.ps}{REPSQ}{1.00} diff --git a/changelog b/changelog index 6ee8bca..8bbd5f3 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,5 @@ +20091218 tpd src/axiom-website/patches.html 20091218.02.tpd.patch +20091218 tpd books/bookvol10.4 document RepeatedSquaring 20091218 tpd src/axiom-website/patches.html 20091218.01.tpd.patch 20091218 tpd src/interp/posit.lisp move functions to bookvol5 20091218 tpd src/interp/vmlisp.lisp move functions to bookvol5 diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 53b13bd..2cf660b 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -2314,5 +2314,7 @@ books/bookvol10.3 rewrite doublefloat to use typed macros
books/bookvol5 )describe no longer needs cat, dom, pkg arg
20091218.01.tpd.patch books/bookvol5 tree shake code from cparse, posit, vmlisp
+20091218.02.tpd.patch +books/bookvol10.4 document RepeatedSquaring