computing powers by repeated squaring
From time to time, there arise occasions where one wants to raise anumber to a large integer power. While one can compute bymultiplying by itself times, not only does this entail alarge expenditure of effort when is large, but roundoff errorscan accumulate. A more efficient approach is to first rise topowers of two by successive squaring, then multiply to obtain .This procedure will now be explained by computing .
The first step is to express as a sum of powers of two, i.e. inbase 2. In our example, we have .
By the basic properties of exponentiation, we therefore have.
The next step is to raise 1.08145 to powers of two, which we accomplishby repeatedly squaring like so: (In order to guard against roundofferror, we work with more decimal places than needed and round off at theend of the computation.)
Finally, we multiply together the appropriate powers to obtain ouranswer:
Hence, we compute .
Note that this computation involved only 12 multiplicationsas opposed to 186 multiplications. More generally, we willrequire repeated squarings and up to multiplications of the repeated squares, or a total of between and multiplications to compute this way.
More generally, the same method can be used to compute when is a complex number or a matrix, or something evenmore general, such as an element of a group. Thus thisapproach can be adapted to computing exponentials andtrigonometric functions
, numerical approximation of differentialequation
, and the like.