<s>
In	O
numerical	B-General_Concept
analysis	I-General_Concept
,	O
pairwise	B-Algorithm
summation	I-Algorithm
,	O
also	O
called	O
cascade	B-Algorithm
summation	I-Algorithm
,	O
is	O
a	O
technique	O
to	O
sum	O
a	O
sequence	O
of	O
finite-precision	O
floating-point	B-Algorithm
numbers	I-Algorithm
that	O
substantially	O
reduces	O
the	O
accumulated	O
round-off	B-Algorithm
error	I-Algorithm
compared	O
to	O
naively	O
accumulating	O
the	O
sum	O
in	O
sequence	O
.	O
</s>
<s>
Although	O
there	O
are	O
other	O
techniques	O
such	O
as	O
Kahan	B-Algorithm
summation	I-Algorithm
that	O
typically	O
have	O
even	O
smaller	O
round-off	B-Algorithm
errors	I-Algorithm
,	O
pairwise	B-Algorithm
summation	I-Algorithm
is	O
nearly	O
as	O
good	O
(	O
differing	O
only	O
by	O
a	O
logarithmic	O
factor	O
)	O
while	O
having	O
much	O
lower	O
computational	O
costit	O
can	O
be	O
implemented	O
so	O
as	O
to	O
have	O
nearly	O
the	O
same	O
cost	O
(	O
and	O
exactly	O
the	O
same	O
number	O
of	O
arithmetic	O
operations	O
)	O
as	O
naive	O
summation	O
.	O
</s>
<s>
In	O
particular	O
,	O
pairwise	B-Algorithm
summation	I-Algorithm
of	O
a	O
sequence	O
of	O
n	O
numbers	O
xn	O
works	O
by	O
recursively	O
breaking	O
the	O
sequence	O
into	O
two	O
halves	O
,	O
summing	O
each	O
half	O
,	O
and	O
adding	O
the	O
two	O
sums	O
:	O
a	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Its	O
worst-case	O
roundoff	B-Algorithm
errors	I-Algorithm
grow	O
asymptotically	O
as	O
at	O
most	O
O(εlogn )	O
,	O
where	O
ε	O
is	O
the	O
machine	B-Algorithm
precision	I-Algorithm
(	O
assuming	O
a	O
fixed	O
condition	B-Algorithm
number	I-Algorithm
,	O
as	O
discussed	O
below	O
)	O
.	O
</s>
<s>
In	O
comparison	O
,	O
the	O
naive	O
technique	O
of	O
accumulating	O
the	O
sum	O
in	O
sequence	O
(	O
adding	O
each	O
xi	O
one	O
at	O
a	O
time	O
for	O
i	O
=	O
1	O
,...,	O
n	O
)	O
has	O
roundoff	B-Algorithm
errors	I-Algorithm
that	O
grow	O
at	O
worst	O
as	O
O(εn )	O
.	O
</s>
<s>
Kahan	B-Algorithm
summation	I-Algorithm
has	O
a	O
worst-case	B-Algorithm
error	I-Algorithm
of	O
roughly	O
O(ε )	O
,	O
independent	O
of	O
n	O
,	O
but	O
requires	O
several	O
times	O
more	O
arithmetic	O
operations	O
.	O
</s>
<s>
If	O
the	O
roundoff	B-Algorithm
errors	I-Algorithm
are	O
random	O
,	O
and	O
in	O
particular	O
have	O
random	O
signs	O
,	O
then	O
they	O
form	O
a	O
random	O
walk	O
and	O
the	O
error	O
growth	O
is	O
reduced	O
to	O
an	O
average	O
of	O
for	O
pairwise	B-Algorithm
summation	I-Algorithm
.	O
</s>
<s>
In	O
pseudocode	B-Language
,	O
the	O
pairwise	B-Algorithm
summation	I-Algorithm
algorithm	O
for	O
an	O
array	O
of	O
length	O
≥	O
0	O
can	O
be	O
written	O
:	O
</s>
<s>
For	O
some	O
sufficiently	O
small	O
,	O
this	O
algorithm	O
switches	O
to	O
a	O
naive	O
loop-based	O
summation	O
as	O
a	O
base	O
case	O
,	O
whose	O
error	B-Algorithm
bound	I-Algorithm
is	O
O(Nε )	O
.	O
</s>
<s>
The	O
entire	O
sum	O
has	O
a	O
worst-case	B-Algorithm
error	I-Algorithm
that	O
grows	O
asymptotically	O
as	O
O(εlogn )	O
for	O
large	O
n	O
,	O
for	O
a	O
given	O
condition	B-Algorithm
number	I-Algorithm
(	O
see	O
below	O
)	O
.	O
</s>
<s>
In	O
an	O
algorithm	O
of	O
this	O
sort	O
(	O
as	O
for	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
algorithms	I-Algorithm
in	O
general	O
)	O
,	O
it	O
is	O
desirable	O
to	O
use	O
a	O
larger	O
base	O
case	O
in	O
order	O
to	O
amortize	B-General_Concept
the	O
overhead	O
of	O
the	O
recursion	O
.	O
</s>
<s>
Regardless	O
of	O
N	O
,	O
exactly	O
n1	O
additions	O
are	O
performed	O
in	O
total	O
,	O
the	O
same	O
as	O
for	O
naive	O
summation	O
,	O
so	O
if	O
the	O
recursion	O
overhead	O
is	O
made	O
negligible	O
then	O
pairwise	B-Algorithm
summation	I-Algorithm
has	O
essentially	O
the	O
same	O
computational	O
cost	O
as	O
for	O
naive	O
summation	O
.	O
</s>
<s>
(	O
computed	O
with	O
infinite	B-Algorithm
precision	I-Algorithm
)	O
.	O
</s>
<s>
With	O
pairwise	B-Algorithm
summation	I-Algorithm
for	O
a	O
base	O
case	O
N	O
=	O
1	O
,	O
one	O
instead	O
obtains	O
,	O
where	O
the	O
error	O
is	O
bounded	O
above	O
by	O
:	O
</s>
<s>
where	O
ε	O
is	O
the	O
machine	B-Algorithm
precision	I-Algorithm
of	O
the	O
arithmetic	O
being	O
employed	O
(	O
e.g.	O
</s>
<s>
ε10−16	O
for	O
standard	O
double	O
precision	B-Architecture
floating	B-Algorithm
point	I-Algorithm
)	O
.	O
</s>
<s>
Usually	O
,	O
the	O
quantity	O
of	O
interest	O
is	O
the	O
relative	B-Algorithm
error	I-Algorithm
,	O
which	O
is	O
therefore	O
bounded	O
above	O
by	O
:	O
</s>
<s>
In	O
the	O
expression	O
for	O
the	O
relative	B-Algorithm
error	I-Algorithm
bound	O
,	O
the	O
fraction	O
( |xi|	O
/	O
|xi|	O
)	O
is	O
the	O
condition	B-Algorithm
number	I-Algorithm
of	O
the	O
summation	O
problem	O
.	O
</s>
<s>
Essentially	O
,	O
the	O
condition	B-Algorithm
number	I-Algorithm
represents	O
the	O
intrinsic	O
sensitivity	O
of	O
the	O
summation	O
problem	O
to	O
errors	O
,	O
regardless	O
of	O
how	O
it	O
is	O
computed	O
.	O
</s>
<s>
The	O
relative	B-Algorithm
error	I-Algorithm
bound	O
of	O
every	O
(	O
backwards	B-Algorithm
stable	I-Algorithm
)	O
summation	O
method	O
by	O
a	O
fixed	O
algorithm	O
in	O
fixed	O
precision	B-Architecture
(	O
i.e.	O
</s>
<s>
not	O
those	O
that	O
use	O
arbitrary-precision	B-Algorithm
arithmetic	I-Algorithm
,	O
nor	O
algorithms	O
whose	O
memory	O
and	O
time	O
requirements	O
change	O
based	O
on	O
the	O
data	O
)	O
,	O
is	O
proportional	O
to	O
this	O
condition	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
An	O
ill-conditioned	B-Algorithm
summation	O
problem	O
is	O
one	O
in	O
which	O
this	O
ratio	O
is	O
large	O
,	O
and	O
in	O
this	O
case	O
even	O
pairwise	B-Algorithm
summation	I-Algorithm
can	O
have	O
a	O
large	O
relative	B-Algorithm
error	I-Algorithm
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
summands	O
xi	O
are	O
uncorrelated	O
random	O
numbers	O
with	O
zero	O
mean	O
,	O
the	O
sum	O
is	O
a	O
random	O
walk	O
and	O
the	O
condition	B-Algorithm
number	I-Algorithm
will	O
grow	O
proportional	O
to	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
for	O
random	O
inputs	O
with	O
nonzero	O
mean	O
the	O
condition	B-Algorithm
number	I-Algorithm
asymptotes	O
to	O
a	O
finite	O
constant	O
as	O
.	O
</s>
<s>
If	O
the	O
inputs	O
are	O
all	O
non-negative	O
,	O
then	O
the	O
condition	B-Algorithm
number	I-Algorithm
is	O
1	O
.	O
</s>
<s>
Note	O
that	O
the	O
denominator	O
is	O
effectively	O
1	O
in	O
practice	O
,	O
since	O
is	O
much	O
smaller	O
than	O
1	O
until	O
n	O
becomes	O
of	O
order	O
21/ε	O
,	O
which	O
is	O
roughly	O
101015	O
in	O
double	O
precision	B-Architecture
.	O
</s>
<s>
In	O
comparison	O
,	O
the	O
relative	B-Algorithm
error	I-Algorithm
bound	O
for	O
naive	O
summation	O
(	O
simply	O
adding	O
the	O
numbers	O
in	O
sequence	O
,	O
rounding	O
at	O
each	O
step	O
)	O
grows	O
as	O
multiplied	O
by	O
the	O
condition	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
In	O
practice	O
,	O
it	O
is	O
much	O
more	O
likely	O
that	O
the	O
rounding	B-Algorithm
errors	I-Algorithm
have	O
a	O
random	O
sign	O
,	O
with	O
zero	O
mean	O
,	O
so	O
that	O
they	O
form	O
a	O
random	O
walk	O
;	O
in	O
this	O
case	O
,	O
naive	O
summation	O
has	O
a	O
root	B-General_Concept
mean	I-General_Concept
square	I-General_Concept
relative	B-Algorithm
error	I-Algorithm
that	O
grows	O
as	O
and	O
pairwise	B-Algorithm
summation	I-Algorithm
has	O
an	O
error	O
that	O
grows	O
as	O
on	O
average	O
.	O
</s>
<s>
Pairwise	B-Algorithm
summation	I-Algorithm
is	O
the	O
default	O
summation	O
algorithm	O
in	O
NumPy	B-Application
and	O
the	O
Julia	B-Application
technical-computing	I-Application
language	I-Application
,	O
where	O
in	O
both	O
cases	O
it	O
was	O
found	O
to	O
have	O
comparable	O
speed	O
to	O
naive	O
summation	O
(	O
thanks	O
to	O
the	O
use	O
of	O
a	O
large	O
base	O
case	O
)	O
.	O
</s>
<s>
Other	O
software	O
implementations	O
include	O
the	O
HPCsharp	O
library	O
for	O
the	O
C	B-Application
Sharp	I-Application
language	I-Application
and	O
the	O
standard	O
library	O
summation	O
in	O
D	B-Application
.	O
</s>
