In
linear algebra
Linear algebra is the branch of mathematics concerning linear equations such as:
:a_1x_1+\cdots +a_nx_n=b,
linear maps such as:
:(x_1, \ldots, x_n) \mapsto a_1x_1+\cdots +a_nx_n,
and their representations in vector spaces and through matrices.
...
, the Strassen algorithm, named after
Volker Strassen
Volker Strassen (born April 29, 1936) is a German mathematician, a professor emeritus in the department of mathematics and statistics at the University of Konstanz.
For important contributions to the analysis of algorithms he has received many aw ...
, is an
algorithm for matrix multiplication
Because matrix multiplication is such a central operation in many numerical algorithms, much work has been invested in making matrix multiplication algorithms efficient. Applications of matrix multiplication in computational problems are found in m ...
. It is faster than the standard matrix multiplication algorithm for large matrices, with a better
asymptotic complexity
In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
, although the naive algorithm is often better for smaller matrices. The Strassen algorithm is slower than
the fastest known algorithms for extremely large matrices, but such
galactic algorithms are not useful in practice, as they are much slower for matrices of practical size. For small matrices even faster algorithms exist.
Strassen's algorithm works for any
ring
Ring may refer to:
* Ring (jewellery), a round band, usually made of metal, worn as ornamental jewelry
* To make a sound with a bell, and the sound made by a bell
:(hence) to initiate a telephone connection
Arts, entertainment and media Film and ...
, such as plus/multiply, but not all
semirings, such as
min-plus or
boolean algebra
In mathematics and mathematical logic, Boolean algebra is a branch of algebra. It differs from elementary algebra in two ways. First, the values of the variables are the truth values ''true'' and ''false'', usually denoted 1 and 0, whereas in e ...
, where the naive algorithm still works, and so called
combinatorial matrix multiplication.
History
Volker Strassen
Volker Strassen (born April 29, 1936) is a German mathematician, a professor emeritus in the department of mathematics and statistics at the University of Konstanz.
For important contributions to the analysis of algorithms he has received many aw ...
first published this algorithm in 1969 and thereby proved that the
general matrix multiplication algorithm wasn't optimal. The Strassen algorithm's publication resulted in more research about matrix multiplication that led to both asymptotically lower bounds and improved computational upper bounds.
Algorithm
Let
,
be two
square matrices
In mathematics, a square matrix is a matrix with the same number of rows and columns. An ''n''-by-''n'' matrix is known as a square matrix of order Any two square matrices of the same order can be added and multiplied.
Square matrices are often ...
over a
ring
Ring may refer to:
* Ring (jewellery), a round band, usually made of metal, worn as ornamental jewelry
* To make a sound with a bell, and the sound made by a bell
:(hence) to initiate a telephone connection
Arts, entertainment and media Film and ...
, for example matrices whose entries are integers or the real numbers. The goal of matrix multiplication is to calculate the matrix product
. The following exposition of the algorithm assumes that all of these matrices have sizes that are powers of two (i.e.,
), but this is only conceptually necessary -- if the matrices
,
are not of type
, the "missing" rows and columns can be filled with zeros to obtain matrices with sizes of powers of two -- though real implementations of the algorithm do not do this in practice.
The Strassen algorithm partitions
,
and
into equally sized
block matrices
In mathematics, a block matrix or a partitioned matrix is a matrix that is '' interpreted'' as having been broken into sections called blocks or submatrices. Intuitively, a matrix interpreted as a block matrix can be visualized as the original mat ...
:
with
. The naive algorithm would be:
:
This construction does not reduce the number of multiplications: 8 multiplications of matrix blocks are still needed to calculate the
matrices, the same number of multiplications needed when using standard matrix multiplication.
The Strassen algorithm defines instead new matrices:
:
using only 7 multiplications (one for each
) instead of 8. We may now express the
in terms of
:
:
We recursively iterate this division process until the
submatrices
In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns, which is used to represent a mathematical object or a property of such an object.
For example,
\begi ...
degenerate into numbers (elements of the ring
). If, as mentioned above, the original matrix had a size that was not a power of 2, then the resulting product will have zero rows and columns just like
and
, and these will then be stripped at this point to obtain the (smaller) matrix
we really wanted.
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. 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).
A more recent study (2016) observed benefits for matrices as small as 512 and a benefit around 20%.
Winograd form
It is possible to reduce the number of matrix additions by instead using the following form discovered by Winograd:
where u = (c - a)(C - D), v = (c + d)(C - A), w = aA + (c + d - a)(A + D - C). This reduces the number of matrix additions and subtractions from 18 to 15. The number of matrix multiplications is still 7, and the asymptotic complexity is the same.
Asymptotic complexity
The outline of the algorithm above showed that one can get away with just 7, instead of the traditional 8, matrix-matrix multiplications for the sub-blocks of the matrix. On the other hand, one has to do additions and subtractions of blocks, though this is of no concern for the overall complexity: Adding matrices of size
requires only
operations whereas multiplication is substantially more expensive (traditionally
addition or multiplication operations).
The question then is how many operations exactly one needs for Strassen's algorithms, and how this compares with the standard matrix multiplication that takes approximately
(where
) arithmetic operations, i.e. an asymptotic complexity
.
The number of additions and multiplications required in the Strassen algorithm can be calculated as follows: let
be the number of operations for a
matrix. Then by recursive application of the Strassen algorithm, we see that
, for some constant
that depends on the number of additions performed at each application of the algorithm. Hence
, i.e., the asymptotic complexity for multiplying matrices of size
using the Strassen algorithm is
. The reduction in the number of arithmetic operations however comes at the price of a somewhat reduced
numerical stability, 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.
Strassen's algorithm needs to be compared to the "naive" way of doing the matrix multiplication that would require 8 instead of 7 multiplications of sub-blocks. This would then give rise to the complexity one expects from the standard approach:
. The comparison of these two algorithms shows that ''asymptotically'', Strassen's algorithm is faster: There exists a size
so that matrices that are larger are more efficiently multiplied with Strassen's algorithm than the "traditional" way. However, the asymptotic statement does not imply that Strassen's algorithm is ''always'' faster even for small matrices, and in practice this is in fact not the case: For small matrices, the cost of the additional additions of matrix blocks outweighs the savings in the number of multiplications. There are also other factors not captured by the analysis above, such as the difference in cost on today's hardware between loading data from memory onto processors vs. the cost of actually doing operations on this data. As a consequence of these sorts of considerations, Strassen's algorithm is typically only used on "large" matrices. This kind of effect is even more pronounced with alternative algorithms such as the one by
Coppersmith and Winograd: While ''asymptotically'' even faster, the cross-over point
is so large that the algorithm is not generally used on matrices one encounters in practice.
Rank or bilinear complexity
The bilinear complexity or rank of a
bilinear map
In mathematics, a bilinear map is a function combining elements of two vector spaces to yield an element of a third vector space, and is linear in each of its arguments. Matrix multiplication is an example.
Definition
Vector spaces
Let V, W ...
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 mathematics, abuse of notation occurs when an author uses a mathematical notation in a way that is not entirely formally correct, but which might help simplify the exposition or suggest the correct intuition (while possibly minimizing errors an ...
)
:
In other words, the rank of a bilinear map is the length of its shortest bilinear computation. The existence of Strassen's algorithm shows that the rank of
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 space
In mathematics, any vector space ''V'' has a corresponding dual vector space (or just dual space for short) consisting of all linear forms on ''V'', together with the vector space structure of pointwise addition and scalar multiplication by const ...
s 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.)
It can be shown that the total number of elementary multiplications
required for matrix multiplication is tightly asymptotically bound to the rank
, i.e.
, or more specifically, since the constants are known,
. One useful property of the rank is that it is submultiplicative for
tensor product
In mathematics, the tensor product V \otimes W of two vector spaces and (over the same field) is a vector space to which is associated a bilinear map V\times W \to V\otimes W that maps a pair (v,w),\ v\in V, w\in W to an element of V \otimes W ...
s, and this enables one to show that
matrix multiplication can be accomplished with no more than
elementary multiplications for any
. (This
-fold tensor product of the
matrix multiplication map with itself — an
-th tensor power—is realized by the recursive step in the algorithm shown.)
Cache behavior
Strassen's algorithm is
cache oblivious. Analysis of its
cache
Cache, caching, or caché may refer to:
Places United States
* Cache, Idaho, an unincorporated community
* Cache, Illinois, an unincorporated community
* Cache, Oklahoma, a city in Comanche County
* Cache, Utah, Cache County, Utah
* Cache County ...
behavior algorithm has shown it to incur
:
cache misses during its execution, assuming an idealized cache of size
(i.e. with
lines of length
).
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, a
does not need to be padded to
, since it could be subdivided down to
matrices and conventional multiplication can then be used 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
. They can be split so that the upper-left portion is
and the lower-right is
. Wherever the operations require it, dimensions of
are zero padded to
first. Note, for instance, that the product
is only used in the lower row of the output, so is only required to be
rows high; and thus the left factor
used to generate it need only be
rows high; accordingly, there is no need to pad that sum to
rows; it is only necessary to pad
to
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