24.13  Fast Matrix Multiplication

Every algorithm in this chapter is built out of matrix products, and every cost we have counted has been counted against them. Section 12 broke one such count: the Fourier matrix is applied in about nlog⁡n operations, although the definition of a matrix–vector product asks for n2. The definition of a matrix product asks for n3 multiplications. This section asks whether n3 is necessary, answers no, and then asks what the answer costs in accuracy.

24.13.1. What a fast algorithm would be

Count the operations that Definition 0.9.9 prescribes. The product AB of two matrices in Mn(F) has n2 entries, each of them a sum of n products, so the recipe performs n3 multiplications and n2(n−1) additions: n3+n2(n−1)=2n3−n2 arithmetic operations in all. Chapter 3 §06 made the same kind of count for an LU factorization and got 23n3, so a product costs about three times a factorization. Nothing so far has suggested that either number could be smaller.

Before asking whether it can be, we need to say what “it” is. A claim that some procedure multiplies matrices in fewer than n3 multiplications is empty until the permitted procedures are fixed, and the fixing has to be done carefully: a procedure allowed to compare two numbers, or to branch on whether an entry is zero, is a different object from one that only computes.

A program is a list of arithmetic instructions, each using the inputs or earlier results, and its cost is the length of the list.

Definition 24.13.1 (Arithmetic cost of a matrix product)

Fix a field F and n≥1, and treat the 2n2 entries of A,B∈Mn(F) as indeterminates. A straight-line program is a finite list g1,…,gN in which each gt is either

  • (i) one of the 2n2 indeterminates, or a constant of F (an input step), or
  • (ii) gr+gs, gr−gs or grgs for some r,s<t (an arithmetic step).

Each gt is then a polynomial in the indeterminates. The program computes the product if for every i,j the polynomial ∑kaikbkj occurs among the gt. Its cost is the number of arithmetic steps, and M(n):=min{cost of a program computing the n×n product} is the arithmetic cost of the n×n product over F.

In words: input steps are free, because they only name the data; the three arithmetic operations each cost 1; and the program must produce all n2 entries as polynomial identities, not merely for the particular numbers at hand. There are no comparisons, no branches and no loops — a straight-line program does the same thing whatever the data are. Division is excluded, which costs nothing here: none of the algorithms below uses it.

Two examples fix the definition. For n=1 the single instruction g3=g1g2 computes a11b11, so M(1)=1. For n=2 the recipe of Definition 0.9.9 is the program that forms the eight products aikbkj and then four sums, at a cost of 12; so M(2)≤12. A degenerate case worth naming: a program that lists only input steps has cost 0 and computes nothing, since no entry of AB is an indeterminate.

The exponent of matrix multiplication is the smallest growth rate a family of such programs can have.

Definition 24.13.2 (The exponent of matrix multiplication)

The exponent of matrix multiplication over F is ω:=inf{τ∈R:M(n)=O(nτ) as n→∞}.

The infimum is over all real τ for which some constant c and some n0 give M(n)≤cnτ for every n≥n0, so ω is a property of the whole family of problems, not of any one algorithm. The set is non-empty, since τ=3 belongs to it by the count above. It is bounded below, and the reason is the only thing about ω that this book proves.

Proposition 24.13.1 (The exponent is at least two)

M(n)≥n2 for every n≥1, and therefore ω≥2.

Proof. Let g1,…,gN be a program computing the n×n product, and fix i,j. The polynomial ∑kaikbkj occurs as some gt. It is not a constant and not an indeterminate, since it is a non-zero sum of degree-two monomials; so gt is an arithmetic step. Distinct pairs (i,j) give distinct polynomials, because ∑kaikbkj determines i and j from the indices appearing in it. Hence the n2 pairs require n2 distinct arithmetic steps, and the cost is at least n2.

Now let τ be admissible, say M(n)≤cnτ for all n≥n0. Then n2≤cnτ, so n2−τ≤c, for all n≥n0. If τ<2 the left side is unbounded, which is impossible; so τ≥2. Every admissible τ is at least 2, and hence so is their infimum.

So 2≤ω≤3, and the question of the section is where in that interval ω lies.

Warning. The exponent is an asymptotic statement and says nothing about any particular size. M(n)=O(nτ) hides a constant, and a program family with a small exponent may carry a constant so large that it loses to the 2n3−n2 recipe at every size anyone computes with. Section 12’s nlog⁡n transform is the exception rather than the rule: there the constant is small. Below, every claim about a size is made with the exact operation count in hand, never from an exponent.

24.13.2. Seven products instead of eight

The classical program for n=2 forms the eight products aikbkj. Its cost is what makes the general recipe cost n3, because a 2×2 block form turns one product of size n into eight of size n/2 — and 8=23 is exactly the recursion that reproduces n3. Reducing eight to seven would change the exponent.

Theorem 24.13.2 (Strassen’s identity)

Let F be a field, let m≥1, and let A,B∈M2m(F) be partitioned into m×m blocks, A=(A11A12A21A22),B=(B11B12B21B22). Define seven products P1=(A11+A22)(B11+B22),P2=(A21+A22)B11,P3=A11(B12−B22),P4=A22(B21−B11),P5=(A11+A12)B22,P6=(A21−A11)(B11+B12),P7=(A12−A22)(B21+B22). Then, with the same block partition of AB, AB=(P1+P4−P5+P7P3+P5P2+P4P1+P3−P2+P6). Only seven products of m×m matrices occur on the right, where Theorem 8.1.1 asks for eight.

Idea. There is no derivation to reproduce: the seven products were found by Strassen, and what a proof can do is check them. What deserves watching during the check is which rules it uses. Every step expands a product of sums by distributivity and then cancels equal terms. No two blocks are ever interchanged, and no block is ever inverted or divided by — only the ring operations of Mm(F) appear. That is the whole point, because blocks do not commute.

Proof. Expand the seven products by distributivity, keeping every factor in its place: P1=A11B11+A11B22+A22B11+A22B22,P2=A21B11+A22B11,P3=A11B12−A11B22,P4=A22B21−A22B11,P5=A11B22+A12B22,P6=A21B11+A21B12−A11B11−A11B12,P7=A12B21+A12B22−A22B21−A22B22. Take the four combinations in turn. For the (1,1) block, P1+P4−P5+P7=A11B11+A11B22+A22B11+A22B22+A22B21−A22B11−A11B22−A12B22+A12B21+A12B22−A22B21−A22B22=A11B11+A12B21, since A11B22, A22B11, A22B22, A22B21 and A12B22 each occur once with each sign. For the (1,2) block, P3+P5=A11B12−A11B22+A11B22+A12B22=A11B12+A12B22. For the (2,1) block, P2+P4=A21B11+A22B11+A22B21−A22B11=A21B11+A22B21. For the (2,2) block, P1+P3−P2+P6=A11B11+A11B22+A22B11+A22B22+A11B12−A11B22−A21B11−A22B11+A21B11+A21B12−A11B11−A11B12=A21B12+A22B22. The four results are the four blocks of AB given by Theorem 8.1.1. This proves the identity.

Two features of that proof matter more than the result. First, it used only addition, subtraction, multiplication and their laws in Mm(F) — never the commutativity of a product, never an inverse, never a division. So the identity would hold with the blocks taken in any ring whatever. Second, the case m=1 is the ordinary 2×2 product with seven scalar multiplications instead of eight, and the case m>1 is the same statement one level up. That self-similarity is what the next theorem exploits.

Example (Seven products on integer data)

Multiply A=(1234) and B=(5678) by Theorem 24.13.2, with blocks of size 1, so that each Pk is a number. Check against the classical product.

Solution. The seven products are P1=(1+4)(5+8)=65,P2=(3+4)⋅5=35,P3=1⋅(6−8)=−2,P4=4⋅(7−5)=8,P5=(1+2)⋅8=24,P6=(3−1)(5+6)=22,P7=(2−4)(7+8)=−30. Then P1+P4−P5+P7=65+8−24−30=19,P3+P5=−2+24=22,P2+P4=35+8=43,P1+P3−P2+P6=65−2−35+22=50. The classical product is (5+146+1615+2818+32)=(19224350), the same.

Warning. The seven products are not seven of the eight classical ones. Not one of P1,…,P7 equals a product aikbkj; each is a product of two combinations. Dropping a classical product and repairing the rest is impossible, and the identity gives no license to do arithmetic in a different order in any other formula. What it gives is one algebraic fact about one bilinear map, and everything below is that fact applied to itself.

Quick check. Does Theorem 24.13.2 still hold over F2, where 1+1=0?

Solution. Yes. The field F was arbitrary, and the proof used only distributivity, associativity and the cancellation of a term against its negative. What changes over F2 is only cosmetic: every minus sign may be written as a plus sign, since −x=x there.

24.13.3. The recursion, and its exact cost

Apply Theorem 24.13.2 with m×m blocks, and each of the seven products is a product of two m×m matrices, to be computed by the same rule. The recursion bottoms out at 1×1 blocks, where a product is one multiplication.

Theorem 24.13.3 (The cost of the recursion)

Let n=2p with p≥0. Applying Theorem 24.13.2 recursively, with the 1×1 case done by a single multiplication, multiplies two matrices in Mn(F) with exactly T(n)=7nlog2⁡7−6n2 arithmetic operations. In particular T(n)=O(nlog2⁡7) and ω≤log2⁡7=2.8073….

Idea. Two counts and one recurrence. Count the block additions in Theorem 24.13.2: ten to build the operands of the seven products, eight to assemble the four blocks of the answer, eighteen in all, each of them (n/2)2 scalar additions. That gives T(n)=7T(n/2)+92n2. Then solve the recurrence exactly, by induction on p rather than by a growth estimate, so that the constants are visible.

Proof. Step 1: the recurrence. Let n=2m with m≥1, and partition A and B into four m×m blocks each. Forming the operands of P1,…,P7 uses the block sums A11+A22, B11+B22, A21+A22, B12−B22, B21−B11, A11+A12, A21−A11, B11+B12, A12−A22 and B21+B22: ten of them. Assembling the answer uses three block additions for the (1,1) block, one for (1,2), one for (2,1) and three for (2,2): eight more. Each block addition is m2 scalar additions, and the seven products cost T(m) each. Hence T(2m)=7T(m)+18m2,T(1)=1.

Step 2: the solution. We show T(2p)=7⋅7p−6⋅4p by induction on p. For p=0 the right side is 7−6=1=T(1). Suppose it holds for p. Taking m=2p, so that m2=4p, T(2p+1)=7(7⋅7p−6⋅4p)+18⋅4p=7⋅7p+1−42⋅4p+18⋅4p=7⋅7p+1−24⋅4p=7⋅7p+1−6⋅4p+1, which is the statement for p+1.

Step 3: reading it in n. With n=2p we have 4p=n2, and 7p=2plog2⁡7=nlog2⁡7. So T(n)=7nlog2⁡7−6n2, which is at most 7nlog2⁡7.

Finally, the recursion is a straight-line program in the sense of Definition 24.13.1: it uses only additions, subtractions and multiplications, and by Theorem 24.13.2 it produces every entry of AB as a polynomial identity. Hence M(n)≤7nlog2⁡7 along the powers of two. For general n, pad A and B with zero rows and columns to the next power of two, which at most doubles n; the product of the padded matrices has AB in its leading block, so M(n)≤7(2n)log2⁡7<49nlog2⁡7 for every n. Therefore τ=log2⁡7 is admissible in Definition 24.13.2, and ω≤log2⁡7.

The number log2⁡7=2.8073… is below 3, and that is the whole content: an operation that looked like an n3 operation is not one. The mechanism is worth naming, because Section 12 used it too. There, the Fourier matrix Fn was factored into a permutation, two copies of Fn/2 and a diagonal factor, and the recurrence C(n)=2C(n/2)+O(n) followed. Here the bilinear map (A,B)↦AB is factored into seven products and eighteen sums, and the recurrence T(n)=7T(n/2)+92n2 follows. In both cases the saving comes from a factorization, and the exponent is decided by the number of recursive calls against the size reduction: 2 calls at half size against a linear overhead gives nlog⁡n; 7 calls at half size against a quadratic overhead gives nlog2⁡7.

Remark. The recursion is not a way to make M(2) smaller than 12. Its own count at n=2 is T(2)=49−24=25: seven multiplications but eighteen additions, against eight and four. What it does is trade one multiplication for fourteen additions at every level, and the trade pays only because the multiplications are what recurse.

24.13.4. What is known about the exponent, and what is not

Theorem 24.13.3 gives ω≤log2⁡7<2.8074, and Proposition 24.13.1 gives ω≥2. Both are proved above. The rest of this subsection is stated and not proved here, and nothing in this book depends on any of it.

Strassen’s bound was the first below 3, and it has been improved many times since. The decisive technique is the laser method of Coppersmith and Winograd, which brought the bound below 2.376; successive refinements of that method by several authors have since pushed the published bound below 2.372. No lower bound better than the ω≥2 proved above is known. Whether ω=2 is an open problem.

Two honest caveats belong with those numbers.

  • The bounds below log2⁡7 are obtained by analyzing families of recursive constructions, not by exhibiting seven-product identities; the algorithms they yield carry constants so large that at every size that arises in practice they are slower than the 2n3−n2 recipe. This is a known feature of the constructions, and it is recorded here, not proved.
  • ω may depend on the field F, and the definition above was made field by field for that reason. The bounds just quoted, and Strassen’s, hold over every field.

Remark. The name bilinear complexity belongs to a related quantity: the least number of multiplications (as opposed to all arithmetic operations) needed to compute a bilinear map, which for the 2×2 product is exactly 7. The lower bound 7 is a theorem of Winograd and is not proved here; Theorem 24.13.2 is the upper half of it. The exponent ω is the same whether it is defined through Definition 24.13.1 or through multiplications alone, which is also not proved here and is not used.

24.13.5. Accuracy: a norm bound, but not an entrywise one

Everything so far was exact algebra. In the floating-point model of Definition 24.1.1 the two algorithms are not interchangeable, and the difference is sharper than “one is less accurate”.

Start with the classical recipe, which inherits Section 1’s analysis directly. Write |A| for the entrywise absolute value (|aij|), as in Chapter 19, and C^ for the computed product. Everything below is real, because Definition 24.1.1 is.

Proposition 24.13.4 (The classical product has a small entrywise error)

Let A,B∈Mn(R) have representable entries, let nu<1, and let C^ be the product computed by Definition 0.9.9, each entry as one inner product taken in the natural order. Then |C^−AB| ≤ γn|A||B| entrywise.

Proof. Fix i and j, and let x be row i of A and y column j of B, both with representable entries. By Definition 0.9.9, (AB)ij=x⊤y, and c^ij is exactly the quantity sn of Theorem 24.1.2. That theorem, applicable since nu<1, gives a Δx with c^ij=(x+Δx)⊤y and |Δxk|≤γn|xk| for every k. Hence |c^ij−(AB)ij|=|∑kΔxkyk|≤∑k|Δxk||yk|≤γn∑k|aik||bkj|, where the first inequality is the triangle inequality and the second substitutes the bound on Δx together with |xk|=|aik|. The right side is γn(|A||B|)ij. Since i and j were arbitrary, this proves the bound.

The bound is entrywise, and that is its strength: the error in the (i,j) entry is measured against the size of the data that produced that entry. If (|A||B|)ij is tiny, the error there is tiny too. In particular, if A and B have non-negative entries, then (|A||B|)ij=(AB)ij and every entry is computed with small relative error.

Strassen’s algorithm satisfies a weaker bound, in which the whole of A and the whole of B appear on the right. Here is the base case, proved.

Proposition 24.13.5 (Strassen’s two-by-two product satisfies a norm bound)

Let A,B∈M2(R) have representable entries, put α=maxi,j|aij| and β=maxi,j|bij|, and let C^ be the result of evaluating Theorem 24.13.2 with m=1, each Pk as written and each of the four combinations left to right. If 6u<1, then maxi,j|c^ij−(AB)ij| ≤ 12γ6αβ.

Idea. Each Pk is built by at most three operations, so the computed P^k carries at most three factors 1+δ. Each output block is a sum of at most four of them, formed by at most three further additions, so each summand carries at most three more. Six factors in all, which is γ6 by Lemma 24.1.1. The only other ingredient is a crude size bound on each Pk.

Proof. Sizes. Each factor of Pk is either a single entry or a sum of two, so |P1|,|P6|,|P7|≤(2α)(2β)=4αβ, while P2,P3,P4,P5 each have a single entry as one factor and so satisfy |Pk|≤2αβ.

Rounding. Fix k. Forming Pk takes at most one addition on each side and then one multiplication: at most three operations, each contributing a factor 1+δ with |δ|≤u by Definition 24.1.1. So P^k is Pk times a product of at most three such factors.

Assembly. Take c^11, computed as ((P^1+P^4)−P^5)+P^7. Each of the three additions contributes one factor 1+δ to every summand already accumulated, so P^1 and P^4 pick up three such factors, P^5 two and P^7 one. Combining with the previous paragraph, each Pm is multiplied by a product of at most six factors 1+δ, which by Lemma 24.1.1 is 1+ψm with |ψm|≤γ6, legitimate because 6u<1. Hence c^11=∑m∈{1,4,5,7}±Pm(1+ψm), with the signs of Theorem 24.13.2. Subtracting c11=P1+P4−P5+P7 and using the triangle inequality, |c^11−c11| ≤ γ6∑m∈{1,4,5,7}|Pm| ≤ γ6(4+2+2+4)αβ=12γ6αβ. The same argument gives |c^22−c22|≤γ6(4+2+2+4)αβ=12γ6αβ for the sum P1+P3−P2+P6. The blocks c^12=P^3+P^5 and c^21=P^2+P^4 use one addition, so four factors and γ4≤γ6 suffice, and ∑m|Pm|≤4αβ there. The largest of the four bounds is 12γ6αβ, which proves the proposition.

A bound of this shape survives the recursion, with a constant that grows with n: for n=2p there is a constant c(n), polynomial in n, with maxi,j|c^ij−(AB)ij| ≤ c(n)umaxi,j|aij|maxi,j|bij|+O(u2). This is not proved here. A bound of this form was first established by Brent, and the constant has been improved since; the induction is longer than this section, and nothing below uses it. What is proved below is that no improvement of it can be entrywise.

Theorem 24.13.6 (Strassen’s algorithm has no useful entrywise error bound)

Work in a model as in Definition 24.1.1, and suppose the set R of representable numbers contains a number ε with ε>0,1+ε∈R,ε2∈R,fl((1+ε)2)=1+2ε. Put A=B=diag(1,ε). Then the C^ of Proposition 24.13.5 has c^22=0, while (AB)22=ε2. Consequently, any constant c for which |C^−AB| ≤ cu|A||B| holds entrywise for this A and B must satisfy c≥1/u.

Idea. Choose the data so that the (2,2) entry of the product is as small as the model can see, while the quantity P1 from which it is assembled has size 1. The term ε2 is then the last bit of (1+ε)2, and the fourth hypothesis says the rounding throws exactly that bit away. Nothing later can put it back, because the remaining steps are exact.

Proof. Write a11=b11=1, a22=b22=ε and a12=a21=b12=b21=0; all are in R, since 0,1,ε∈R. Note first that fl fixes every element of R, because a nearest element of R to a member of R is that member. By Definition 0.9.9, (AB)22=a21b12+a22b22=ε2.

Compute the four quantities that Theorem 24.13.2 combines into the (2,2) entry. The operand sums are fl(a11+a22)=fl(1+ε)=1+ε and likewise for B, both exact by hypothesis; so P^1=fl((1+ε)(1+ε))=fl((1+ε)2)=1+2ε, by the fourth hypothesis. Next P^2=fl(fl(0+ε)⋅1)=ε, and P^3=fl(1⋅fl(0−ε))=−ε, using −R=R; and P^6=fl(fl(0−1)⋅fl(1+0))=fl(−1)=−1. Each of these values lies in R, so each rounding is the identity.

Assemble P1+P3−P2+P6 left to right. In order, fl((1+2ε)+(−ε))=1+ε,fl((1+ε)−ε)=1,fl(1+(−1))=0, every intermediate value being in R and so fixed by fl. Hence c^22=0.

Finally |A||B|=diag(1,ε2), so an entrywise bound at the (2,2) position reads ε2=|0−ε2|≤cuε2. Dividing by ε2>0 gives 1≤cu, that is c≥1/u. This proves the theorem.

The constant 1/u is about 1016 in the arithmetic in common use, so the conclusion is that no entrywise bound worth stating exists: Proposition 24.13.4 holds with c=γ2/u, which is close to 2, and for Strassen’s algorithm the same inequality at n=2 needs a constant larger than the reciprocal of the unit roundoff. The hypotheses of the theorem are not exotic.

They are not vacuous either, and the fourth one fixes the scale of ε. Since 1+ε is representable, Definition 24.1.1 writes fl((1+ε)2)=(1+ε)2(1+δ) with |δ|≤u, and the fourth hypothesis says the left side is 1+2ε, which forces δ=−ε2(1+ε)2,henceε2≤u(1+ε)2. So ε is at most about u: the theorem asks for a quantity small enough that its square falls off the end of the significand, and for nothing else. The next example produces one.

Example (A small entry lost entirely)

Work in binary arithmetic with 53-bit significands, rounding to nearest, so that u=2−53. Verify the hypotheses of Theorem 24.13.6 for ε=2−27, and say what each algorithm returns for the (2,2) entry of the product of A=B=diag(1,2−27).

Solution. The hypotheses. A number is representable when its significand fits in 53 bits. Now ε=2−27 is a power of two, so ε∈R and ε2=2−54∈R. The number 1+2−27 needs bits 0 through 27, that is 28 of them, so it is representable. Finally (1+2−27)2=1+2−26+2−54, which needs 55 bits and is not. In [1,2) the representable numbers are spaced 2−52 apart; our value lies 2−54 above 1+2−26 and 3⋅2−54 below the next one up, so rounding to nearest gives fl((1+2−27)2)=1+2−26=1+2ε. All four hypotheses hold.

The two answers. By Theorem 24.13.6, Strassen’s algorithm returns c^22=0, while the true value is 2−54: the relative error is 1, not a loss of digits but a loss of all of them. The classical recipe computes fl(0⋅0)=0 and then fl(0+fl(2−27⋅2−27))=fl(2−54)=2−54, the exact answer.

The other three entries of the Strassen product also come out exactly right here, and the error 2−54 is invisible when measured against max|aij|max|bij|=1, which is what Proposition 24.13.5 measures it against. That is the whole contrast in one example.

Warning. “No entrywise bound” is not “unstable”. Proposition 24.13.5 is a genuine bound, and for a matrix whose entries are all of comparable size it says as much as Proposition 24.13.4 does. The two part company only when the entries of AB span many orders of magnitude, and then the classical algorithm delivers something Strassen’s does not: small relative error in the small entries. Backward stability in the sense of Definition 24.1.3 is likewise not in question — the failure above is a failure of entrywise accuracy, exactly as Chapter 16 §08 warned that conditioning and stability answer different questions.

24.13.6. Whether to use it

The operation count and the error analysis pull in opposite directions, and the honest summary is a list of exact numbers rather than a verdict. Suppose the recursion is stopped at a base size n0, below which the classical recipe is used, and let n=n02p. The same induction as in Theorem 24.13.3, started from T(n0)=2n03−n02, gives T(n02p)=7p(2n03−n02)+6n02(7p−4p). Three readings of this formula. With n0=1 the recursion runs to scalars, and it is slower than the classical recipe until n exceeds about 654; at n=512 it costs 280902385 operations against 268173312, and at n=1024 it costs 1971035287 against 2146435072. With a classical base case the picture changes completely: a single level of the recursion, p=1, costs 14n03+11n02 against the classical 16n03−4n02 at size 2n0, and the first wins as soon as 2n03>15n02, that is from n0=8, so from n=16. And at n=1024 with n0=64 the count is 1301696512, about 0.61 of the classical one.

So on operation count alone the trade is favorable at sizes that are not large. Three things keep the classical algorithm the one in ordinary use at small and moderate sizes, and none of them is visible in an operation count.

  • Additions are not free in the way the count assumes. The seven products must be stored, and the eighteen block sums read and write whole blocks that the classical recipe never touches. An operation count charges 1 for an addition and 1 for a multiplication and charges nothing for moving a number; on a real machine the movement is often the expensive part, and the recursion moves much more data than it saves in arithmetic.
  • The error bound is weaker, and it is weaker in a way that matters exactly when it is not expected — see Example (A small entry lost entirely).
  • The sizes have to cooperate. The recursion wants even dimensions at every level; an odd size must be padded or handled specially, and the bookkeeping erodes the saving at precisely the moderate sizes where it is thinnest.

The conclusion is not that Theorem 24.13.2 is a curiosity. It is used, at large sizes, with a classical base case and with the accuracy caveat understood. What it is not is a replacement for a definition: AB still means what Definition 0.9.9 says it means, and every theorem in this book about products is untouched. A fast algorithm changes the cost of an operation, never the operation.

24.13.7. Summary and transfer

Chapter 21 closed Part V with a complaint and a promise: “every proof here is an existence or a comparison, and not one of them is an algorithm. That is the subject of Chapter 24.” Thirteen sections later, the promise is paid, and what “compute” turned out to mean can be said in one sentence: a computed answer is the exact answer to a nearby question, and how near depends on the algorithm, while how much that nearness costs depends on the problem.

The chapter’s one new assumption was the floating-point model of Definition 24.1.1, a description of a machine stated as a definition. Everything else was proved from it and from the linear algebra of Chapters 0 to 21.

Four moves carried the chapter.

  • Conditioning belongs to the problem, stability to the algorithm, and the two multiply. Chapter 16 §08 stated the distinction and could not use it; Theorem 24.1.3 makes it a theorem, and every accuracy claim in the chapter is an instance. Transfer: when an answer is wrong, ask first whether any method could have done better. If the condition number says no, do not change the algorithm — change the problem.
  • Measure an answer by a change in the data that makes it exact. A forward error is usually unknowable and a backward error is usually computable, so prove the backward statement and let Theorem 24.1.3 supply the rest (§§01, 02, 03). Transfer: when a quantity you want to bound is out of reach, look for a perturbation of the input that the computed output answers exactly; bounding that is often elementary.
  • Every eigenvalue algorithm iterates, because no finite one can exist. Chapter 11 §08 gave the reason — a finite procedure using arithmetic and radicals would solve the general quintic — and Sections 4 to 7 are what is left once that door is shut: a sequence of subspaces, each cheap to extend, each carrying a certified error bar from Chapter 20. Transfer: when exact solution is impossible in principle, the design question becomes what to iterate in; the Krylov space is the answer whenever the only affordable operation is one matrix–vector product.
  • A fast algorithm is a factorization. The Fourier matrix factors into sparse pieces and the two-by-two product factors into seven multiplications; in both cases the cost follows by solving a recurrence exactly, and in both cases the underlying object is unchanged (§§12, 13). Transfer: to make an operation fast, do not look for a shortcut in the arithmetic. Look for a factorization of the operation itself, and count the recursive calls against the size reduction.

The chapter paid the following promises, in the words in which they were made.

The promise Made in Paid by
“whether a given method keeps that promise is stability, and it is Chapter 24’s subject” Chapter 16 §08 §01
“Chapter 24 draws the distinction properly, defines backward stability, and proves which of the algorithms in this book have it” Chapter 16 §08 §01, §02, §03
“An error analysis of this kind, which measures an answer by a change in the data that makes it exact, is a backward error analysis. Chapter 24 builds on it.” Chapter 20 §04 §01
“Chapter 24 makes this precise” (the ε-pivot failure) Chapter 3 §06 §02
“Chapter 24 reads Gaussian elimination itself as a sequence of Schur complements of 1×1 pivots” Chapter 8 §03 §02
“Cholesky does about half the arithmetic of a general LU factorization … it needs no pivoting” Chapter 13 §02 §02
“Three things are not proved here, and all three belong to Chapter 24” (the second of them being that nothing in that chapter is about arithmetic) Chapter 16 §08 §01, §02, §03
“The conditioning of the least-squares problem itself is not κ2(A) … a term in κ2(A)2 appears even for the QR route” Chapter 16 §08 §03
“Chapter 24 makes ‘sensitivity’ precise and proves the comparison” Chapter 11 §08, quoted again in Chapter 16 §08 §03
“a stable implementation of the QR route loses about log10⁡κ2(A) decimal digits while forming and solving the normal equations loses about 2log10⁡κ2(A) — is still Chapter 24’s to prove” Chapter 16 §08 §03
“Chapter 24 quantifies the loss” (the Householder sign choice) Chapter 11 §08 §03
“Chapter 24 explains why it is the stable one” (reflections against classical Gram–Schmidt) Chapter 11 §02 §03
“Chapter 24 builds an iteration on it” (the Rayleigh quotient) Chapter 17 §01 and Chapter 20 §06 §04
“the iteration x↦Ax is the power method, and Chapter 24 studies how fast it converges” Chapter 19 §04 §04
“Chapter 24 studies it for general matrices, where the rate is governed by the ratio of the two largest eigenvalue moduli” Chapter 19 §08 §04
“the power method, the algorithm that computes a Perron vector at the size of the web, belongs to Chapter 24” Chapter 19 §09 §04
“Chapter 24 develops that iteration and explains why every implementation starts with the reduction proved here” Chapter 11 §08 §05
“algorithms that compute eigenvalues, is the subject of Chapter 24” Chapter 20 §11 §04, §05, §06
“Those steps need a probabilistic model, a reason to prefer squared error, and an argument that the sample answer says something about the population. Chapter 24 supplies them” Chapter 13 §10 §10, for the first two; the third is refused, below
“the graph Laplacian, returns in Chapter 24” Chapter 3 §07 §11
the matrix-tree theorem, “which Chapter 24 completes” Chapter 7 §07 §11
“Chapter 24 develops it, together with the cost accounting that makes ‘quickly’ precise” (the fast Fourier transform) Chapter 12 §09 §12

Some things the chapter did not do, and the chapter’s index collects them in one list. Section 2 proved the backward error of a factorization for the ordering it displays and stated with credit that Chapter 3’s ordering satisfies the same bound; it also showed that the growth bound for partial pivoting is far too large to prove stability, and said so rather than tidying it. Section 3 proved the backward error of a single reflection and stated with credit both the accumulation over a whole factorization and the rates at which classical and modified Gram–Schmidt lose orthogonality. Section 4 stated, and did not prove, that Rayleigh quotient iteration converges at a quadratic rate, not a cubic one, for a general diagonalizable matrix. Section 5 quoted the theorem of Abel and Ruffini, which is why every eigenvalue method here iterates, and proved the first column of the convergence theorem of the QR algorithm while stating the general form with credit. Section 6 stated the classical convergence estimate for the extreme Ritz values and proved the clean special case alone, and described the loss of orthogonality in Lanczos without analyzing it. Section 8 derived the continuous Toda statement only after granting that t↦Q(t) is differentiable, which is analysis this book has not set up; its discrete half, Theorem 24.8.5, rests on nothing unproved. Section 10 proved every deterministic statement about principal components and said plainly that the inference from a sample to a larger population is statistics, which this book does not develop; Chapter 13 §10 promised that inference, and promised as well an account of how a singular value decomposition is actually computed for a large matrix, which no section here gives — §10 says which route to avoid and why, and points at the orthogonal reductions of §§03 and 05, and there it stops. Both over-promises are recorded rather than hidden. In this section, the recursive form of Strassen’s error bound, Winograd’s lower bound of seven multiplications, the equality of the two definitions of ω, everything known about ω below log2⁡7, and Laderman’s twenty-three-product identity were stated with credit and not proved.

Nothing in this book is proved from any of them. Each is quoted exactly where a reader would otherwise expect a proof, and every theorem in the chapter either proves its own case or carries what it needs as an explicit hypothesis; since all of them enter the book here, no earlier chapter can rest on them either. The one place a quoted result is used at all is Exercise (C1: Would twenty-three products for three-by-three beat Strassen?) (b), where Laderman’s identity is handed to the reader as a hypothesis and the deduction from it is the reader’s own. Chapter 21’s quoted fact (A7) was not used anywhere in this chapter, and no analysis beyond Chapter 16’s (A1)–(A6) was imported.

The book’s account of computation ends here. Twenty chapters built objects and proved things about them; this one asked what it costs to produce those objects from data of finite accuracy, and found that the answer splits cleanly in two. How much accuracy the data deserve is a question about the problem, answered by a condition number. How much of that the algorithm delivers is a question about the algorithm, answered by a backward error. Everything in this chapter — the pivoting, the reflections, the shifts, the Krylov spaces, the seven products — is an attempt to keep the second small when the first is out of our hands.

24.13.8. Exercises

A. Check your understanding

Exercise (A1)
  • (a) State how many arithmetic operations Definition 0.9.9 uses for the product of two n×n matrices, separating multiplications from additions.
  • (b) Define the exponent ω, and state what is proved about it in this section.
  • (c) True or false: Theorem 24.13.2 shows that M(2)≤7. Justify your answer.
  • (d) Which properties of m×m matrices does the proof of Theorem 24.13.2 use? Say what would go wrong if the identity had needed two blocks to commute.
  • (e) State the difference between the error bound of Proposition 24.13.4 and that of Proposition 24.13.5, and say for which matrices the difference matters.

Solution.

  • (a) n3 multiplications and n2(n−1) additions, 2n3−n2 operations in all: each of the n2 entries is a sum of n products, needing n multiplications and n−1 additions.

  • (b) ω=inf{τ:M(n)=O(nτ)}, with M(n) the arithmetic cost of Definition 24.13.1. Proved here: ω≥2 (Proposition 24.13.1) and ω≤log2⁡7 (Theorem 24.13.3). Everything else quoted about ω is stated with credit and not proved.

  • (c) False, and for two reasons. The cost of Definition 24.13.1 counts additions as well as multiplications, and Theorem 24.13.2 uses 18 of them, so its cost at n=2 is 25, not 7; indeed M(2)≤12 by the classical program, which is better. The number 7 counts multiplications only.

  • (d) Only the associativity and distributivity of matrix addition and multiplication and the existence of additive inverses, together with Theorem 8.1.1, which says that the blocks of AB are the eight products combined as for a 2×2 matrix. No block is ever inverted and no two are ever interchanged. If some cancellation had required, say, A11B22=B22A11, it would fail for general blocks, which do not commute, and the identity would be true for numbers and false for matrices — so the recursion of Theorem 24.13.3 would be unavailable, which is the only reason the identity is of any interest.

  • (e) Proposition 24.13.4 bounds the (i,j) error by γn(|A||B|)ij, a quantity attached to that entry; Proposition 24.13.5 bounds every error by a multiple of max|aij|max|bij|, a quantity attached to the whole matrices. They agree in strength when all entries of AB are of comparable size, and differ when some entry of the product is far smaller than others, as in Example (A small entry lost entirely).

B. Practice

Exercise (B1: Seven products by hand)

Let A=(2−103) and B=(14−21). Compute P1,…,P7 of Theorem 24.13.2 with blocks of size 1, assemble the four entries, and check the answer against Example (A product of square matrices). Hence state how many multiplications and how many additions you performed.

Solution. With a11=2, a12=−1, a21=0, a22=3 and b11=1, b12=4, b21=−2, b22=1, P1=(2+3)(1+1)=10,P2=(0+3)⋅1=3,P3=2⋅(4−1)=6,P4=3⋅(−2−1)=−9,P5=(2−1)⋅1=1,P6=(0−2)(1+4)=−10,P7=(−1−3)(−2+1)=4. Then c11=10−9−1+4=4,c12=6+1=7,c21=3−9=−6,c22=10+6−3−10=3. So AB=(47−63), which is the product computed in Example (A product of square matrices).

The count: seven multiplications, and ten additions to form the operands together with eight to assemble the answer, so eighteen additions, twenty-five operations in all. The classical route uses eight multiplications and four additions, twelve operations. At this size the exchange is a loss.

Exercise (B2: One block, one level)

Let A=(1021011011020211),B=(1201011020111101), partitioned into 2×2 blocks. Compute P3 and P5 of Theorem 24.13.2, hence the (1,2) block of AB, and verify it against the block formula A11B12+A12B22.

Solution. The blocks are A11=(1001),A12=(2110),B12=(0110),B22=(1101). Then B12−B22=(−101−1) and A11+A12=(3111), so P3=A11(B12−B22)=(−101−1),P5=(3111)(1101)=(3412). Hence P3+P5=(2421). Directly, A11B12=(0110) and A12B22=(2311), whose sum is (2421). The two agree, and by Theorem 8.1.1 this is rows 1,2 and columns 3,4 of AB.

Exercise (B3: Counting the recursion)

Let n=2p.

  • (a) How many multiplications does the recursion of Theorem 24.13.3 perform, as a function of p? How many does the classical recipe perform?
  • (b) Using T(n)=7nlog2⁡7−6n2, compute T(n) and 2n3−n2 for n=8 and n=64.
  • (c) Hence say, for these two sizes, which recipe uses fewer operations.

Solution.

  • (a) Each level replaces one product of size 2m by seven of size m, and a product of size 1 is one multiplication, so the recursion performs 7p=nlog2⁡7 multiplications. The classical recipe performs n3=8p.

  • (b) For n=8, that is p=3: T(8)=7⋅343−6⋅64=2401−384=2017, while 2⋅512−64=960. For n=64, that is p=6: T(64)=7⋅117649−6⋅4096=823543−24576=798967, while 2⋅262144−4096=520192.

  • (c) At both sizes the classical recipe wins, by a factor of about 2.1 at n=8 and about 1.5 at n=64. The ratio is shrinking, and it crosses 1 between n=512 and n=1024; recursing all the way to scalars is a losing strategy at any size a person would compute by hand.

C. Going deeper

Exercise (C1: Would twenty-three products for three-by-three beat Strassen?)

Suppose a ring identity multiplies two 3×3 matrices with q>9 multiplications of combinations of entries, together with some fixed number of additions, and is used recursively on 3×3 block matrices.

  • (a) Show that the recursion performs qp multiplications on matrices of size n=3p, and deduce that it gives ω≤log3⁡q.
  • (b) You are given that such an identity exists with q=23; this is a result of Laderman, which is not proved here. Determine whether recursing on it beats Theorem 24.13.3. Justify your answer.
  • (c) Determine the largest q for which such an identity would beat Theorem 24.13.3.

Hint: compare logarithms to a common base.

Solution.

  • (a) One level replaces a product of size 3m by q products of size m, so by induction on p the recursion performs qp multiplications at size n=3p, the case p=0 being one multiplication. The additions at one level cost Cm2 for a constant C depending only on the identity, so the operation count satisfies T(3m)=qT(m)+Cm2 with T(1)=1. Unrolling, T(3p)=qp+C∑j=0p−1qj9p−1−j=qp+C9p−1(q/9)p−1(q/9)−1 ≤ qp(1+Cq−9), where the last step uses q>9 and drops the −1. So T(n)≤cnlog3⁡q with c=1+C/(q−9), since qp=nlog3⁡q. Padding to a power of three as in Theorem 24.13.3 extends this to all n, so ω≤log3⁡q.

  • (b) No. log3⁡23=ln⁡23/ln⁡3=3.13549…/1.09861…=2.85404…, while log2⁡7=2.80735…. Since 2.854>2.807, the exponent obtained from 23 products at size 3 is worse than Strassen’s.

  • (c) We need log3⁡q<log2⁡7, that is q<3log2⁡7. Now 3log2⁡7=e(log2⁡7)ln⁡3=e3.08398…=21.8498…, so the condition is q≤21. Indeed log3⁡21=3.04452…/1.09861…=2.77124…<log2⁡7, while log3⁡22=3.09104…/1.09861…=2.81359…>log2⁡7. So an identity with 21 multiplications would beat Strassen and one with 22 would not.

Exercise (C2: Where the entrywise bound really fails)

Let ε>0 and A=B=(1εεε).

  • (a) Compute AB and |A||B| exactly, and identify the entry of AB that is smallest as ε→0.
  • (b) Compute P1,…,P7 exactly, and find which of them is largest as ε→0.
  • (c) Suppose ε,2ε,1−ε,1+ε,1+2ε and 2ε2 are representable, and that the model rounds (1+ε)2 to 1+2ε and (ε−1)(1+ε) to −1, each time losing a trailing ε2. Determine c^22, and the least constant c for which |C^−AB|≤cu|A||B| can hold at the (2,2) position.

Hint: with ε=2−27 in 53-bit binary arithmetic, both roundings are what rounding to nearest does.

Solution.

  • (a) AB=(1+ε2ε+ε2ε+ε22ε2), and since every entry of A and B is positive, |A||B|=AB. The smallest entry as ε→0 is the (2,2) entry 2ε2.

  • (b) With a11=b11=1 and all other entries ε, P1=(1+ε)2,P2=2ε,P3=0,P4=ε2−ε,P5=ε+ε2,P6=ε2−1,P7=0. As ε→0 the largest in modulus is P1→1, with P6→−1 beside it; the other five all tend to 0.

  • (c) The (2,2) entry is assembled as P1+P3−P2+P6, and by (b) this is (1+2ε+ε2)+0−2ε+(ε2−1)=2ε2, as it must be. Two of the four terms have modulus close to 1, and the two occurrences of ε2 that survive the cancellation are exactly the two the model throws away: every operand that enters the (2,2) entry — a11+a22=b11+b22=b11+b12=1+ε, a21+a22=2ε, b12−b22=0 and a21−a11=ε−1 — are all representable, so each is formed exactly, and then by hypothesis P^1=1+2ε and P^6=−1, while P^3=0 and P^2=2ε are exact. Assembling left to right, fl((1+2ε)+0)=1+2ε,fl((1+2ε)−2ε)=1,fl(1+(−1))=0, so c^22=0 and the error is 2ε2. Since (|A||B|)22=2ε2 by (a), an entrywise bound there reads 2ε2≤cu⋅2ε2, so the least admissible constant is c=1/u, exactly as in Theorem 24.13.6. The mechanism is the same: a quantity of size ε2 is carried inside numbers of size 1, where the model cannot see it.

Exercise (C3: Only the products recurse)

Suppose someone proposes an identity that multiplies 2×2 matrices with eight multiplications but only two additions, and recurses on it.

  • (a) Write down the recurrence for its operation count with T(1)=1, and solve it exactly for n=2p.
  • (b) Hence determine the exponent it gives, and compare with Theorem 24.13.3.
  • (c) Explain in one sentence what part of an identity the exponent depends on.

Solution.

  • (a) Two block additions of size m×m cost 2m2, so T(2m)=8T(m)+2m2 with T(1)=1. We claim T(2p)=32⋅8p−12⋅4p. For p=0 this is 32−12=1. Assuming it for p and taking m=2p, so m2=4p, T(2p+1)=8(328p−124p)+2⋅4p=328p+1−4⋅4p+2⋅4p=328p+1−124p+1, since −4+2=−2 and −2⋅4p=−124p+1. (Check: T(2)=10, T(4)=88, T(8)=736.)

  • (b) With n=2p this is T(n)=32n3−12n2, so the exponent is 3. Saving additions changed the constant from 2 to 32 and nothing else; Theorem 24.13.3 changed the exponent from 3 to log2⁡7.

  • (c) Only the number of multiplications recurses, so only that number enters the exponent; the additions contribute to the constant.

Found a typo or a mistake? Report it, or read this page’s source

The text of this book is licensed under CC BY-NC-SA 4.0.