Matrix multiplication · OpenAI mathematics
How fast can you multiply two grids?
Games use grids of numbers to move things around a scene. Simulations and neural networks multiply these grids too. Double the side length of two square grids and the basic method needs eight times as many multiplications. How much of that work can you avoid and still get every answer exactly right?
Take an answer apartWhere does one answer come from?
Choose the top-left cell in Answer. It starts at 7. Follow the highlighted row in the first grid and column in the second. Pair their numbers in order, multiply each pair, then add the three products.
First matrix A
Second matrix B
Answer AB
Row 1 of A and column 2 of B give 11. This cell uses three multiplications.
Take the answer apart
Pair the first number in the row with the first in the column, then do the same for the second and third. Each layer shows one of those products at the selected cell. Stack them up and add them.
Row 1, column 2. Add the three highlighted products to get this answer cell.
Choose a cell from the answer tableTry Double this row to see which answers change. Making the original nine answers separately takes 27 multiplications. When you double the side length, the row count, column count and number of pairs per answer all double. That makes eight times the work. See how the new rate changes that.
Double the input. How much more work?
The usual method does the pairing you just tried for every cell. OpenAI’s result describes growth by a number called an exponent. An exponent of 9/4 means the work grows like the width raised to the power 9/4. What does that mean when you double the width?
At the 9/4 rate, what happens when the side length doubles?
Make a guess to reveal both growth rates.
These are power-law comparisons. An exponent describes growth at large sizes. An implementation’s speed also depends on constants, the machine and the sizes run.
Can three multiplications do the work of four?
Faster methods mix inputs before multiplying, then recover the wanted pieces. The upper-bound paper uses that idea on polynomials. This exercise lets you do the smallest interesting case by hand.
Directly expanding (a + bx)(c + dx) takes four products of input coefficients. The product is a quadratic, so its values at three distinct points determine it. Multiplying at those points uses three products. Recover the coefficients with additions, subtractions and division by the constant two.
Recover a quadratic
Evaluate the two polynomials, multiply their values, then recover the three coefficients. Try changing b to zero. Can you tell which terms change?
P(x) = 2 + 3x, Q(x) = 4 + x
| Point x | P(x) | Q(x) | P(x) · Q(x) |
|---|---|---|---|
| 0 | 2 | 4 | 8 |
| 1 | 5 | 5 | 25 |
| −1 | −1 | 3 | −3 |
Evaluate P and Q at 0, 1 and −1. At 0 you see just their constant terms.
m₀ = 8The sample at zero leaves only the constant.(25 − (−3))/2 = 14Subtract the ±1 samples. The even terms cancel.(25 + (−3))/2 − 8 = 3Average the ±1 samples. Remove the constant.8 + 14x + 3x²
Why the signs recover the missing information
Write the product as u + vx + wx². At zero its value gives u. At 1 and −1, the even terms agree and the odd terms have opposite signs. Subtract those two values and divide by two to get v. Add them, divide by two, and subtract u to get w. For the initial inputs, this gives 8 + 14x + 3x².
This calculation uses three distinct points and a field where two is invertible. The research extends its exponent statements to other fields with additional arguments.
Could we get away with just two products?
Keep the original example’s results of 8 at zero and 25 at one. Move the slider to make a rival curve. Can the two samples tell you which curve is the real product?
8 + 14x + 3x²8 + 12x + 5x²Both curves give 8 at zero and 25 at one. Choose another offset or reveal the third measurement.
Each rival adds a multiple of x(x − 1) to the original. That term vanishes at 0 and 1. At −1 it becomes twice the multiplier, so the third measurement removes the ambiguity.
Turn the primitive into an exponent
For two polynomials with a coefficients each, the product has at most 2a − 1 coefficients. Evaluation and interpolation use that many products. The matrix construction combines three versions of this primitive, balancing the roles of its three groups of variables.
Amir Shpilka’s exposition proves that repeated copies of the balanced block can encode matrix multiplication with an effective side-length growth of at least Λa per block. The multiplication count grows by at most (2a − 1)³ per block. Comparing these two growth rates gives an upper bound on the exponent.
Explore a bound from the paper
Increase the number of coefficients. Watch the upper bound approach 2.25.
For this block size the bound is about 0.26156 above the limiting exponent.
Theorem 1.1 in mathematical notation
Shpilka’s rate bound is Λₐ = (3a − 1)/2 · ∏(1 + 1/(3i)), with i = 1,…,a−1. The upper bound plotted here is 3 log(2a − 1) / log Λₐ. Since Λₐ > a^(4/3) for a ≥ 2, this is less than (9/4) log(2a − 1) / log a. The logarithm ratio tends to one.
The interactive computes the published bound. The theorem is what justifies treating the balanced blocks as a matrix multiplication construction.
Why a construction is only half the answer
An upper bound tells you there is a way to multiply this fast in the specified asymptotic model. To conclude the exponent is exactly 9/4, a lower bound must constrain every eligible circuit. The November paper describes the same tensor two ways. One has three shared indices of size n. A rank decomposition has one common label selecting among r terms.
Compare the two price calculations
Use the paper’s critical tripod numbers. Change the matrix size to see how many terms a shared label would have to distinguish.
At n = 256, a shared label needs at least 18 bits to account for a price of 48 at 8/3 per bit.
Monotonicity says that the tensor’s price is at most the price of making it from the shared label. At the critical rates, 6 log₂ n ≤ (8/3) log₂ r implies r ≥ n^(9/4).
In this formula, price is a quantity defined by the proof. The shared label chooses one term from a decomposition. More terms mean more choices for that label. The inequality turns the geometry into a minimum number of terms.
How this comparison enters the full lower bound
The proof assumes a strict improvement on 9/4 and works out which price geometries that assumption would rule out. In particular it would forbid the critical tripod shown here. The resulting constraints let the authors assign compatible prices across a family of tensors. They use those prices, together with sorting and a concentration estimate, to compress a network below a separate lower bound. That contradiction rules out the assumed improvement. The exercise isolates the ratio that sets the target.
What the exponent measures
It is the infimum of exponents for arithmetic operation counts as the matrix side length grows. It does not specify wall-clock time or guarantee a fast implementation at a particular size. The November paper also states bounds that account for division. Its linked Lean scope document distinguishes those statements from what is formalized for division-free circuits.
Try the idea on a new case
Fast exponent. Slow demo?
Someone times two programs on an 8 × 8 matrix. The one with the smaller exponent loses. Could the theorem and the benchmark both be right?
The smaller exponent should always win.
Try comparing 8n9/4 with n³. At n = 8, the first takes about 861 operations and the second takes 512. The factor of 8 matters at small sizes.
They tell us different things.
Yes. An exponent controls how the work grows as the inputs get large. A benchmark at one size also depends on fixed costs, implementation and hardware.
Follow the two bounds
- OpenAI’s October upper boundThe polynomial tensor construction and the initial scope of the upper bound.
- Shpilka’s exposition and explicit algorithmSections 1.1 and 1.2 explain the primitive and state the rate used by the exercise.
- OpenAI’s November lower bound and Lean scopeSee the three-wire comparison in the introduction and the linked formalized statement.
See how a better arrangement at one size differs from a proof about growth.