Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. Exponentiating by
squaring is a general method for fast computation of large integer
powers of a number. Some variants are commonly referred to as
square-and-multiply algorithms or binary exponentiation. In additive
notation the appropriate term is double-and-add. These can be of quite
general use: for example in modular arithmetic or powering of matrices.A
brief analysis shows that such an algorithm uses log2n squarings and at
most log2n multiplications. For n < about 4 this is computationally
more efficient than naïvely multiplying the base with itself repeatedly.