# Strassen algorithm

In the mathematical discipline of linear algebra, **the Strassen algorithm**, named after Volker Strassen, is an algorithm used for matrix multiplication. It is faster than the standard matrix multiplication algorithm and is useful in practice for large matrices, but would be slower than the fastest known algorithms for extremely large matrices.

## History

Volker Strassen is a German mathematician born in 1936. He is well known for his works on probability, but in the computer science and algorithms he’s mostly recognized because of his algorithm for matrix multiplication that’s still one of the main methods that outperforms the general matrix multiplication algorithm.

Strassen firstly published this algorithm in 1969 and proved that the n^3 algorithm isn’t the optimal one. Actually the given solution by Strassen is slightly better, but his contribution is enormous because this resulted in many more researches about matrix multiplication that led to some faster approaches, i.e. the Coppersmith-Winograd algorithm with O(n^2,3737).

## Algorithm

Let *A*, *B* be two square matrices over a ring *R*. We want to calculate the matrix product *C* as

If the matrices *A*, *B* are not of type 2^{n} x 2^{n} we fill the missing rows and columns with zeros.

We partition *A*, *B* and *C* into equally sized block matrices

with

then

With this construction we have not reduced the number of multiplications. We still need 8 multiplications to calculate the *C _{i,j}* matrices, the same number of multiplications we need when using standard matrix multiplication.

Now comes the important part. We define new matrices

only using 7 multiplications (one for each *M*_{k}) instead of 8. We may now express the *C*_{i,j} in terms of *M*_{k}, like this:

We iterate this division process *n* times (recursively) until the submatrices degenerate into numbers (elements of the ring *R*). The resulting product will be padded with zeroes just like *A* and *B*, and should be stripped of the corresponding rows and columns.

Practical implementations of Strassen's algorithm switch to standard methods of matrix multiplication for small enough submatrices, for which those algorithms are more efficient. The particular crossover point for which Strassen's algorithm is more efficient depends on the specific implementation and hardware. Earlier authors had estimated that Strassen's algorithm is faster for matrices with widths from 32 to 128 for optimized implementations.^{[1]} However, it has been observed that this crossover point has been increasing in recent years, and a 2010 study found that even a single step of Strassen's algorithm is often not beneficial on current architectures, compared to a highly optimized traditional multiplication, until matrix sizes exceed 1000 or more, and even for matrix sizes of several thousand the benefit is typically marginal at best (around 10% or less).^{[2]}

## Asymptotic complexity

The standard matrix multiplication takes approximately 2*N*^{3} (where
*N* = 2^{n}) arithmetic operations (additions and multiplications); the asymptotic complexity is O(*N*^{3}).

The number of additions and multiplications required in the Strassen algorithm can be calculated as follows: let *f*(*n*) be the number of operations for a 2^{n} × 2^{n} matrix. Then by recursive application of the Strassen algorithm, we see that *f*(*n*) = 7*f*(*n*-1) + *l*4^{n}, for some constant *l* that depends on the number of additions performed at each application of the algorithm. Hence *f*(*n*) = (7 + o(1))^{n}, i.e., the asymptotic complexity for multiplying matrices of size *N* = 2^{n} using the Strassen algorithm is

The reduction in the number of arithmetic operations however comes at the price of a somewhat reduced numerical stability,^{[3]} and the algorithm also requires significantly more memory compared to the naive algorithm. Both initial matrices must have their dimensions expanded to the next power of 2, which results in storing up to four times as many elements, and the seven auxiliary matrices each contain a quarter of the elements in the expanded ones.

### Rank or bilinear complexity

The bilinear complexity or **rank** of a bilinear map is an important concept in the asymptotic complexity of matrix multiplication. The rank of a bilinear map over a field **F** is defined as (somewhat of an abuse of notation)

In other words, the rank of a bilinear map is the length of its shortest bilinear computation.^{[4]} The existence of Strassen's algorithm shows that the rank of 2×2 matrix multiplication is no more than seven. To see this, let us express this algorithm (alongside the standard algorithm) as such a bilinear computation. In the case of matrices, the dual spaces **A*** and **B*** consist of maps into the field **F** induced by a scalar **double-dot product**, (i.e. in this case the sum of all the entries of a Hadamard product.)

Standard algorithm | Strassen algorithm | ||||||

i |
f(_{i}a) |
g(_{i}b) |
w_{i} |
f(_{i}a) |
g(_{i}b) |
w
_{i} | |

1 | |||||||

2 | |||||||

3 | |||||||

4 | |||||||

5 | |||||||

6 | |||||||

7 | |||||||

8 | |||||||

It can be shown that the total number of elementary multiplications *L* required for matrix multiplication is tightly asymptotically bound to the rank *R*, i.e. , or more specifically, since the constants are known, One useful property of the rank is that it is submultiplicative for tensor products, and this enables one to show that 2^{n}×2^{n}×2^{n} matrix multiplication can be accomplished with no more than 7^{n} elementary multiplications for any *n*. (This *n*-fold tensor product of the 2×2×2 matrix multiplication map with itself—an *n*th tensor power—is realized by the recursive step in the algorithm shown.)

## Implementation considerations

The description above states that the matrices are square, and the size is a power of two, and that padding should be used if needed. This restriction allows the matrices to be split in half, recursively, until limit of scalar multiplication is reached. The restriction simplifies the explanation, and analysis of complexity, but is not actually necessary; and in fact, padding the matrix as described will increase the computation time and can easily eliminate the fairly narrow time savings obtained by using the method in the first place.

A good implementation will observe the following:

- It is not necessary or desirable to use the Strassen algorithm down to the limit of scalars. Compared to conventional matrix multiplication, the algorithm adds a considerable workload in addition/subtractions; so below a certain size, it will be better to use conventional multiplication. Thus, for instance, if you start with matrices that are 1600x1600, there is no need to pad to 2048x2048, since you could subdivide down to 25x25 and then use conventional multiplication at that level.

- The method can indeed be applied to square matrices of any dimension. If the dimension is even, they are split in half as described. If the dimension is odd, zero padding by one row and one column is applied first. Such padding can be applied on-the-fly and lazily, and the extra rows and columns discarded as the result is formed. For instance, suppose the matrices are 199x199. They can be split so that the upper-left portion is 100x100 and the lower-right is 99x99. Wherever the operations require it, dimensions of 99 are zero padded to 100 first. Note, for instance, that the product is only used in the lower row of the output, so is only required to be 99 rows highs; and thus the left factor used to generate it need only be 99 rows high; accordingly, there is no need to pad that sum to 100 rows; it is only necessary to pad to 100 columns to match .

Furthermore there is no need for the matrices to be square. Non-square matrices can be split in half using the same methods, yielding smaller non-square matrices. If the matrices are sufficiently non-square it will be worthwhile reducing the initial operation to more square products, using simple methods which are essentially , for instance:

- A product of size [2
*N*x*N*] * [*N*x 10*N*] can be done as 20 separate [*N*x*N*] * [*N*x*N*] operations, arranged to form the result;

- A product of size [
*N*x 10*N*] * [10*N*x*N*] can be done as 100 separate [*N*x*N*] * [*N*x*N*] operations, summed to form the result.

These techniques will make the implementation more complicated, compared to simply padding to a power-of-two square; however, it is a reasonable assumption that anyone undertaking an implementation of Strassen, rather than conventional, multiplication, will place a higher priority on computational efficiency than on simplicity of the implementation.

## See also

- Computational complexity of mathematical operations
- Gauss–Jordan elimination
- Coppersmith–Winograd algorithm
- Z-order matrix representation
- Karatsuba algorithm, for multiplying
*n*-digit integers in instead of in time - Gauss's complex multiplication algorithm multiplies two complex numbers using 3 real multiplications instead of 4

## References

- ↑ {{#invoke:citation/CS1|citation |CitationClass=citation }}.
- ↑ P. D'Alberto and A. Nicolau, "Using recursion to boost ATLAS's performance,"
*Lecture Notes in Computer Science*, vol. 4759, pp. 142-151 (2010). - ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ Burgisser, Clausen, and Shokrollahi.
*Algebraic Complexity Theory.*Springer-Verlag 1997.

- Strassen, Volker,
*Gaussian Elimination is not Optimal*, Numer. Math. 13, p. 354-356, 1969 - Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein.
*Introduction to Algorithms*, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 28: Section 28.2: Strassen's algorithm for matrix multiplication, pp. 735–741.

## External links

- Weisstein, Eric W., "Strassen's Formulas",
*MathWorld*. (also includes formulas for fast matrix inversion) - Tyler J. Earnest,
*Strassen's Algorithm on the Cell Broadband Engine*

*Simple Strassen's algorithms implementation in C (easy for education purposes)*