<s>
In	O
mathematics	O
and	O
computer	B-General_Concept
programming	I-General_Concept
,	O
exponentiating	B-Algorithm
by	I-Algorithm
squaring	I-Algorithm
is	O
a	O
general	O
method	O
for	O
fast	O
computation	O
of	O
large	O
positive	O
integer	O
powers	O
of	O
a	O
number	O
,	O
or	O
more	O
generally	O
of	O
an	O
element	O
of	O
a	O
semigroup	O
,	O
like	O
a	O
polynomial	O
or	O
a	O
square	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
Some	O
variants	O
are	O
commonly	O
referred	O
to	O
as	O
square-and-multiply	B-Algorithm
algorithms	I-Algorithm
or	O
binary	B-Algorithm
exponentiation	I-Algorithm
.	O
</s>
<s>
These	O
can	O
be	O
of	O
quite	O
general	O
use	O
,	O
for	O
example	O
in	O
modular	O
arithmetic	O
or	O
powering	O
of	O
matrices	B-Architecture
.	O
</s>
<s>
This	O
algorithm	O
is	O
not	O
tail-recursive	B-Language
.	O
</s>
<s>
This	O
may	O
be	O
implemented	O
as	O
a	O
tail-recursive	B-Language
function	I-Language
:	O
</s>
<s>
This	O
is	O
a	O
problem	O
if	O
the	O
exponent	O
should	O
remain	O
secret	O
,	O
as	O
with	O
many	O
public-key	B-Application
cryptosystems	I-Application
.	O
</s>
<s>
The	O
method	O
works	O
in	O
every	O
semigroup	O
and	O
is	O
often	O
used	O
to	O
compute	O
powers	O
of	O
matrices	B-Architecture
.	O
</s>
<s>
Exponentiation	B-Algorithm
by	I-Algorithm
squaring	I-Algorithm
can	O
be	O
viewed	O
as	O
a	O
suboptimal	O
addition-chain	O
exponentiation	O
algorithm	O
:	O
it	O
computes	O
the	O
exponent	O
by	O
an	O
addition	O
chain	O
consisting	O
of	O
repeated	O
exponent	O
doublings	O
(	O
squarings	O
)	O
and/or	O
incrementing	O
exponents	O
by	O
one	O
(	O
multiplying	O
by	O
x	O
)	O
only	O
.	O
</s>
<s>
in	O
compilers	B-Language
where	O
the	O
chains	O
for	O
small	O
powers	O
have	O
been	O
pre-tabulated	O
)	O
.	O
</s>
<s>
However	O
,	O
there	O
are	O
a	O
number	O
of	O
heuristic	B-Algorithm
algorithms	I-Algorithm
that	O
,	O
while	O
not	O
being	O
optimal	O
,	O
have	O
fewer	O
multiplications	O
than	O
exponentiation	B-Algorithm
by	I-Algorithm
squaring	I-Algorithm
at	O
the	O
cost	O
of	O
additional	O
bookkeeping	O
work	O
and	O
memory	O
usage	O
.	O
</s>
<s>
Regardless	O
,	O
the	O
number	O
of	O
multiplications	O
never	O
grows	O
more	O
slowly	O
than	O
Θ(log n )	O
,	O
so	O
these	O
algorithms	O
only	O
improve	O
asymptotically	O
upon	O
exponentiation	B-Algorithm
by	I-Algorithm
squaring	I-Algorithm
by	O
a	O
constant	O
factor	O
at	O
best	O
.	O
</s>
