Docsity

Numerical Stability and Complexity of Matrix Multiplication Algorithms, Papers of Computer Science

Toggle sidebar
bg1
COMPUTATIONAL COMPLEXITY
AND NUMERICAL STABILITY
Webb Miller*
Computer Science Dept.
Penn State
University Park, Pa. 16802
ABSTRACT: Limiting consideration to algorithms
satisfying various numerical stability require-
ments may change lower bounds for computational
complexity and/or make lower bounds easier to
prove. We will show that, under a sufficiently
strong restriction upon numerical stability, any
algorithm for multiplying two n x n matrices using
only +, - and x requires at least n 3 multiplica-
tions. We conclude with a survey of results con-
cerning the numerical stability of several algori-
thms which have been considered by complexity
theorists.
I. Introduction
Proofs of lower bounds for the computational
complexity of a given problem must generally con-
sider only a few measurements of cost and ignore
the others. For example a discussion of the com-
plexity of the problem of sorting a list of items
may count only the number of comparisons, disre-
garding issues like non-comparison operations,
storage requirements and programming simplicity.
When the problem under consideration in-
volves real (i.e., floating-point) arithmetic,
then another factor is relevant, namely the pro-
pagation of rounding errors. In a recent survey
of arithmetic complexity Borodin [2, p. 174]
remarks:
But eventually we will have to
develop results which simultaneously
talk about arithmetic costs, and the
"robustness" or "stability" of the
algorithm. Perhaps if we were more
formal about the numerical properties
of an algorithm, then it might be
easier to produce non trivial lower
bounds.
Of course many people have given simulta-
neous consideration to complexity and stability.
In particular numerical analysts are daily
faced with the trade-off between stability and
the operation count. Moreover, investigations
have been made of the effects of rounding errors
upon several algorithms of interest to complexity
theorists (for a survey see section 6).
Rather~ the first sentence quoted from
Borodin seems to suggest the possible existence of
problems for which the fastest algorithms must be
less than optimal with regard to stability. One
motivation for this paper is to present several
such examples. Thus we are interested in the ef-
fects upon complexity lower bounds of various
stability requirements (essentially the opposite
problem of maximizing stability subject to complex-
ity constraints is investigated by Babuska [i] and
Viten'ko [15]).
However, our primary motivation is to be found
in Borodin's second sentence. When we limit con-
sideration to all programs (in a given language)
which evaluate a fixed function and which satisfy
a certain stability ~e~uirement it is entirely
possible that the fastest programs are excluded.
More intriguing to us is the possibility that the
remaining programs have a simple structure which
makes finding a program that is optimal with re-
spect to some measurement of cost substantially
easier than if arbitrary (and less stable) pro-
grams are allowed to compete.
Here we have focussed on the evaluation of
systems of bilinear forms by programs which apply
only the operations +, - and ×. For simplicity we
have not allowed constants, though almost every-
thing carries over with minor modifications. One
of our results is that if only such programs meet-
ing a very restrictive stability requirement are
3
considered, then n multiplications are needed to
find the product of two n x n matrices. Under a
somewhat relaxed stability assumption we will
show that computing the product of a 2 x 2 matrix
and a 2 x n matrix requires at least 7n/2 multi-
plications. In each case, if the stability re-
quirement is dropped, then faster algorithms can
be found and tight lower bounds seem to become
harder to verify (they are not yet known).
The concepts of numerical stability which we
employ are closely related to those currently used
by experts in roundoff analysis (e.g., Wilkinson
[16,17]). They are idealized in at least two re-
spects. First they use very few of the actual
properties of floating-point arithmetic. This
creates a tendency for pessimistic results in that
algorithms may be more stable than we can prove
(see the remarks by Kahan [9, pp. 1232-1234] on
Viten'ko [15]. Second we consider only the first-
order effects of rounding errors, so algorithms
*Most of the work for this paper was done at the
IBM Thomas J. Watson Research Center.
317
pf3
pf4
pf5

Partial preview of the text

Download Numerical Stability and Complexity of Matrix Multiplication Algorithms and more Papers Computer Science in PDF only on Docsity!

COMPUTATIONAL COMPLEXITY

AND NUMERICAL STABILITY

Webb Miller* Computer Science Dept. Penn State University Park, Pa. 16802

ABSTRACT: Limiting consideration to algorithms satisfying various numerical stability require- ments may change lower bounds for computational complexity and/or make lower bounds easier to prove. We will show that, under a sufficiently strong restriction upon numerical stability, any algorithm for multiplying two n x n matrices using only +, - and x requires at least n 3 multiplica- tions. We conclude with a survey of results con- cerning the numerical stability of several algori- thms which have been considered by complexity theorists.

I. Introduction

Proofs of lower bounds for the computational complexity of a given problem must generally con- sider only a few measurements of cost and ignore the others. For example a discussion of the com- plexity of the problem of sorting a list of items may count only the number of comparisons, disre- garding issues like non-comparison operations, storage requirements and programming simplicity.

When the problem under consideration in- volves real (i.e., floating-point) arithmetic, then another factor is relevant, namely the pro- pagation of rounding errors. In a recent survey of arithmetic complexity Borodin [2, p. 174] remarks:

But eventually we will have to develop results which simultaneously talk about arithmetic costs, and the "robustness" or "stability" of the algorithm. Perhaps if we were more formal about the numerical properties of an algorithm, then it might be easier to produce non trivial lower bounds.

Of course many people have given simulta- neous consideration to complexity and stability. In particular numerical analysts are daily faced with the trade-off between stability and the operation count. Moreover, investigations have been made of the effects of rounding errors upon several algorithms of interest to complexity theorists (for a survey see section 6).

Rather~ the first sentence quoted from Borodin seems to suggest the possible existence of problems for which the fastest algorithms must be

less than optimal with regard to stability. One motivation for this paper is to present several such examples. Thus we are interested in the ef- fects upon complexity lower bounds of various stability requirements (essentially the opposite problem of maximizing stability subject to complex- ity constraints is investigated by Babuska [i] and Viten'ko [15]).

However, our primary motivation is to be found in Borodin's second sentence. When we limit con- sideration to all programs (in a given language) which evaluate a fixed function and which satisfy a certain stability ~e~uirement it is entirely possible that the fastest programs are excluded. More intriguing to us is the possibility that the remaining programs have a simple structure which makes finding a program that is optimal with re- spect to some measurement of cost substantially easier than if arbitrary (and less stable) pro- grams are allowed to compete.

Here we have focussed on the evaluation of systems of bilinear forms by programs which apply only the operations +, - and ×. For simplicity we have not allowed constants, though almost every- thing carries over with minor modifications. One of our results is that if only such programs meet- ing a very restrictive stability requirement are considered, then n 3 multiplications are needed to find the product of two n x n matrices. Under a somewhat relaxed stability assumption we will show that computing the product of a 2 x 2 matrix and a 2 x n matrix requires at least 7n/2 multi- plications. In each case, if the stability re- quirement is dropped, then faster algorithms can be found and tight lower bounds seem to become harder to verify (they are not yet known).

The concepts of numerical stability which we employ are closely related to those currently used by experts in roundoff analysis (e.g., Wilkinson [16,17]). They are idealized in at least two re- spects. First they use very few of the actual properties of floating-point arithmetic. This creates a tendency for pessimistic results in that algorithms may be more stable than we can prove (see the remarks by Kahan [9, pp. 1232-1234] on Viten'ko [15]. Second we consider only the first- order effects of rounding errors, so algorithms

*Most of the work for this paper was done at the IBM Thomas J. Watson Research Center.

may be less stable than results like ours suggest. (In section 5 we will detail several more reasons why the practical significance of the results given here is not especially great.)

We hope that this paper offers supporting evidence for Borodin's cited belief and for our conviction that numerical analysts and complexity theorists can benefit from an exchange of ideas.

  1. Numerical stability of polynomial programs

A polynomial program is a sequence of in- structions of the form

V ~- W#X (2-1) where # is one of +, - or x. For simplicity we require that each operand, W or X, is a variable (initial or defined).

We can think of the program as specifying a sequence of floating-point operations to be per- formed on the data d = (dl,...,dn). In many con-

texts it is helpful to take the alternative point of view that the program specifies symbolic opera- tions to be performed on multivariate polynomicals in the initial variables d. Any resulting poly- nomial V(d) has integer coefficients and no con- stant term.

Let V be a defined variable of such a program, i.e., V appears on the left of a unique instruction (2-1). If we omit tile instruction defining V and consider V an initial variable, then any variable Z can be considered a polynomial Z(d,V).

Define

~z

AZv(i) ~ ~v(d,V(d))'V(!)

The polynomial AZv(d) measures the sensitivity of the numerical evaluation of Z(d) to a floating- point rounding error committed in the operation producing V(d). For suppose that the evaluation is performed exactly except that V(d)(l+6) is used in place of V(d). The induced error is Z(d,V(d)(l+6)) - Z(! )

= Z ( d , V ( d ) ( l + ~ ) ) - Z (! , V ( d ) )

~ 6 •Az v (d~ i. ! for small 6.

For example let d = (al,a2,bl,b2) and con- sider

T ÷ a I x @ 2 U + b I x "b 2

V ÷ a I + b 2 W ÷ a 2 + b I (2-2) X + V x W Y + X - T

Z ÷ y - u

One easily computes

Z(d) = alb I + a2b 2

Z(d,W) - (a I + b2)W - ala 2 - blb 2

~Z

~ (! , W ) = a I + b 2

AZw(d) = (a I + b2)(a 2 + b I)

Stability conditions can sometimes be inter- preted as restricting the form of certain polynomi- als AZv(d). I f

~Z ~V(i,v(i)) ~ 0 (2-3)

then the form of V(d) is also restricted since

V(!) '~(!,V(d_~) = AZv(d_).

Our g0al in the remainder of this section is to ex- hibit a useful condition which guarantees (2-3).

Let Z be a defined variable of a polynomial program. Consider the following process for marking certain instructions of the program. If Z is de- fined by an addition or subtraction, then mark that instruction. If an instruction

V ÷ X#Y , # is + or - is marked and if X and/or Y is defined by + or -, then mark those instructions.

Now delete any unmarked instructions. The set l(Z) of initial (i.e., undefined) variables of the resulting polynomial program contains only variables which were originally either initial or defined by multiplication (take I(Z) = {Z} if Z is defined by multiplication).

Clearly Z is a linear combination of the U in l(Z). Specifically, there exists a unique integer iz(U) for each U in I(Z) such that in the resulting program

Z E ~ I (^) iz(U)'U

The dependence of Z on I(Z) is essentially the same in the original program. In particular,

Z(d) ~ ~ I iz(U)'U(~) (2-4)

and for any defined variable V we have

Z(!'V) ~ ~ I iz(U)'U(!'V) (2-5)

For an example of these notions recall (2-2). We find that I(Z) = {T,U,X} and

1 = iz(X ) = -iz(T ) = -iz(U )

Theorem i.i. If V is a defined variable in l(Z) and if iz(V) # 0, then

~v(d,V(d)) ~ 0

Proof: If U in I(Z) is originally defined bY a multiplication then U may depend on V in the sense that

~-~(d,V(d)) ~ 0

The only other U in l(Z) are originally initial variables and do not depend on V. From (2-5) we compute

U ÷ a I x b I

V ÷ a I x b 2

W ÷ a 2 x b I

X ÷ a 2 x b 2

Y ~ - U + Y

Z ÷ Y + W

B ÷ Z + X

One easily computes

ABu(a,b) = alb I

But if a I = b I = i = - a 2 = - b2, then

.Z]~a i ~B (a,b)]__ = 0

It follows that the program does not have weak

stability. On the other hand, one easily sees that

it possesses restricted Brent stability. Of course

this B is not a permutation bilinear form.

Theorem 3.3. Let V in I(B) be defined by a

multiplication and suppose that iB(V) # 0 and that

V(~,b) ~ 0. If B has Brent stability then the de-

finition of V must be of the form

Ll(a) x L2(b) (or L2(b) x Ll(a) )

where L I and L 2 are linear (e.g., Ll(a) = Z~ia i

with integers ~i ).

Proof: The condition ABv(a,D) = O(lal'Ibl)

can be seen to require that AB V be bilinear.

Theorem i.i shows that V must be bilinear. The

result follows. D

Theorem 3.3 shows that example (2-2), an

instance of Winograd's method for inner products,

does not possess Brent stability (see also Brent

[3,4]).

The next result shows that if we add to the

hypotheses of Theorem 3.3 the assumption of re___-

stricted Brent stability, then any term appear-

ing in V must appear in B. The intuitive reason

is that otherwise a term, ~ijaibj, must cancel

algebraically in a later ± operation, and cor-

responding numerical cancellation creates an

e r r o r not O ( ] ( ~ , b ) lB).

Theorem 3.4. Let V in I(B) be defined by a

multiplication and suppose iB(V) # 0. Write

V(a,b) = ~ n i j a i b j •

If nij # 0, then the coefficient °iJ in B (3-1) is

nonzero.

Proof: From ABv(a,b) = 0(l(a,b) IB) we may

conclude that if aib j appears in AB V then it ap-

pears in B. The result follows from the fact that

if V(~,b) ~ 0, then AB V must be a constant multi-

ple of V. D

Theorem 3.5. Suppose that B is a permutation

bilinear form evaluated by a polynomial program and

that B has strong stability (or equivalently, that

B has restricted Brent stability--see Proposition

3.2)q If alb j appears in B with nonzero coeffi-

cient, then there is a multiplication in the pro-

gram of the form

(~ai) x (~bj)

Proof: The term aib j must appear in some V in

I(B) satisfying iB(V) # 0 (see (2-4)). If V is de-

fined by

( ~ l a l ) x ( ~ j b j )

where, say, ~i' ~I and ~j are nonzero, i # I, then

a term alb j must appear in B by Theorem 3.4. This

contradicts the assumption that B is a permutation

bilinear form.

Two remarks are in order. If a permutation

bilinear form B is computed by directly finding its

terms and adding and subtracting them to get B,

then B has strong stability. Second, if B is not a

permutation bilinear form, then such programs may

lack strong stability (see (3-2)) and ?fast" pro-

grams may possess it (for example, the evaluation

B = (al+a 2) (bl+b 2)).

4. Speed sacrifices stability

We will say that a polynomial program to

evaluate a system of s bilinear forms

m n

Bk(~,~) ~ Z ~ °ij k aibj; k = 1 ..... s (4-i)

i=l j=l

possesses, e.g., simultaneous Brent stability if

each B k has Brent stability. In this section we

will draw two conclusions from our previous re-

suits.

Conclusion i. Any polynomial program for

(4-1) which has simultaneous Brent stability can

make use of multiplications only of the form

Ll(a) x L2(b)

Example 4.1. Any polynomial program of the

"LI(~) × L2(b)" form to multiply a 2 × 2 matrix

times a 2 × n matrix requires at least [7n/2]

multiplications, and this bound can be achieved

(Hopcroft and Kerr [8]). However, Winograd's

method requires only 3n + 2 multiplications. Thus

if n ~ 5, then requiring simultaneous Brent

stability increases the minimum number of multipli-

cations. Moreover, the requirement seems to

simplify the verification of lower bounds, since it

is not known if Winograd's method is optimal.

Example 4.2. Often one does not count multi- plications which are "preconditioning", i.e., which produce only polynomials in a alone or in b alone. To reduce the number of multiplications in a poly- nomial program by preconditioning, one must sacri- fice simultaneous Brent stability.

Example 4.3. It can be shown that any program of the "LI(i) × L2(b)" form must exhibit simul-

taneous Brent stability. Thus Strassen's algori- thm for matrix multiplication has simultaneous Brent stability (see also Brent [3]).

Conclusion 2. If each B k is a permutation bi-

linear form, then any polynomial program with si- multaneous strong stability must perform t multi- plications, where t is the number of pairs (i,j) such that some ~ijk in (4-1) is nonzero.

Example 4.4. The n 3 multiplications in the usual algorithm for multiplying n x n matrices make it optimal among polynomial programs with simul- taneous strong stability. For general polynomial programs the arithmetic complexity of matrix multi- plication seems far from resolved.

Example 4.5. Conclusion 2 also applies to the multiplication of complex numbers or polynomials (i.e., computing the coefficients of the product of polynomials). Consider

(a I + a2i ) x (b I + b2i )

i.e., computing

Bl(a,b) = alb I - a2b 2 = real part

B2(a,b) = alb 2 + a2b I = imaginary part.

If we compute B I = X - Y and B 2 = X - Z where

X = (a I + a2)b 1

y = a2(b I + b 2)

Z = al(b I - b2)

then our previous results indicate that the in- fluence of roundoff error upon B I should be

"unduly large" for a , b such that

l(~,k) IBl << l~l'l~I

The correct result for (0.0015 + l. Oli) × (i.01 + O.O01i)

is B I = 0.000505, whereas computing in "three- digit floating-point arithmetic", i.e., rounding symmetrically to three digits after each operation, gives 0.00051 with the usual method, and 0.0 with the "fast" method.

  1. Caveat

The practical value of the above results is limited by several factors.

  1. They consider only polynomial operations. If a system of bilinear forms can be evaluated in n

multiplications, then it can be evaluated with n multiplications of the form

Ll(a,b) × L2(a_,b)

for linear L i (Winograd [18]. Such polynomial pro-

grams (with constants) are "nearly Brent stable" in the sense that ABv(a,b ) = 0([max{lail,lbjl}12 )

for all B and defined V. They can be given simul- taneous Brent stability be scaling a and b to have roughly the same size (see Brent [3,4] for a special case).

  1. Sometimes it costs as much to run a "more stable" algorithm in single precision as it costs to run a fast algorithm in double precision.
    1. For a particular method, range of data, machine

and software ad hoc roundoff analyses will often

override general results like ours.

  1. Some known stability results

This section contains a brief review of sta- bility results concerning algorithms of (possible) interest to complexity theorists. (a) Evaluation of a polynomial

n (^) i p(x) = ~'- aix i=

given x, a0, ..., a n. A popular stability __,c°ndi- tion is that the computed value be exactly ~ a i x i

where each relative difference lai-ail/lail is small. Following our approach this might be for- malized as

APv(x,a ) = 0(ZlaixlI)

for all defined variables V. There is nothing uni- quely plausible about this requirement, and others have been considered, e.g., [i0]. However, the condition does seem to be widely applicable. Both Horner's role and the naive method are easily seen to be stable in this sense. Also, Wozniakowski [19] has verified this property for a family of algorithms of Shaw and Traub [14] for evaluating a polynomial and its normalized de- rivat ives. (b) Polynomial evaluation with precondition- ing. Workers involved in producing subroutines for evaluating common functions have considered the possible use of the Pan and Motzkin-Belaga forms. However, these procedures are too often contaminat- ed by numerical errors (see Rice [13] or pp. 67-

of Hart, et al. [7]).*

(c) Interpolation. A semi-formal roundoff analysis of Lagrange's formula can be found on pp. 287-291 of Dorn and McCracken [6]. It seems natural to compare Lagrange's or Newton's form with fast methods [2], both in their use for evaluating

*On the other hand, preliminary work by M. Rabin and S. Winograd indicates the existence of stable preconditioning methods of practical value.