Live data from Hacker News

Is Matrix Multiplication Ugly?

mathenchant.wordpress.com

21–30 of 113 posts

Re: Is Matrix Multiplication Ugly?

#21
Matrix multiplication libraries are ugly. They either give up on performance or have atrocious interfaces ... sometimes both.

Using matrix multiplication is also ugly when it's literally millions of times less efficient then a proper solution.

Re: Is Matrix Multiplication Ugly?

#22
post #4

I think this sentence: > But matrix multiplication, to which our civilization is now devoting so many of its marginal resources, has all the elegance of a man hammering a nail into a board. is the most interesting one. A man hammering a nail into a board can be both beautiful and elegant! If you've ever seen someone effortlessly hammer nail after nail into wood without having to think hardly at all about what they're…

Yes!

>The fast Fourier transform viewed as a sparse matrix factorization of the DFT

Riffing further on the Fourier connection: are you planning to explore the link between matmul and differentiation?

Using the "Pauli-Z" matrix that you introduced without a straightforward motivation, eg.

(I took it that you intended it to be a "backyard instance" of "dual numbers")

Re: Is Matrix Multiplication Ugly?

#23

Do you disagree with my take or think I’m missing Witt’s point? I’d be happy to hear from people who disagree with me.

The inelegance to me isn't in the definition of the operation, but that it's doing a huge amount of brute-force work to mix every part of the input with every other part, when the answer really only depends on a tiny fraction of the input. If we somehow "just knew" what parts to look at, we could get the answer much more efficiently.

Of course that doesn't really make any sense at the matrix level. And (from what I understand) techniques like MoE move in that direction. So the criticism doesn't really make sense anymore, except in that brains are still much much more efficient than LLMs so we know that we could do better.

Re: Is Matrix Multiplication Ugly?

#24

> But matrix multiplication, to which our civilization is now devoting so many of its marginal resources, has all the elegance of a man hammering a nail into a board. Elegance is a silly critique. Imagine instead we were spending trillions on floral bouquets, calligraphy, and porcelain tea sets. I would argue that would be a bad allocation of resources. What matters to me is whether it solves the problems we have. No…

"Creeping elegance", I guess: https://en.wiktionary.org/wiki/creeping_elegance

But elegant can mean minimal, restrained, parsimonious, sparing. That's different from a bunch a paraphernalia and flowery nonsense.

Re: Is Matrix Multiplication Ugly?

#25

Earlier quoted context omitted.

I think you're right that the inelegant part is how AI seems to just consist of endless loops of multiplication. I say this as a graphics programmer who realized years ago that all those beautiful images were just lots of MxNs, and AI takes this to a whole new level. When I was in college they told us most of computing resources were used doing Linear Programming. I wonder when that crossed over to graphics or AI (or…

> When I was in college they told us most of computing resources were used doing Linear Programming. I seriously doubt that was ever true, except perhaps for a very brief time in the 1950s or 60s. Linear programming is an incredibly niche application of computing used so infrequently that I've never seen it utilised anywhere despite being a consultant that has visited hundreds of varied customers including big busine…

The first two results from Google with "Voronoi astro" gave two different uses than the one I knew about (sampling fibre bundles): https://galaxyproject.org/news/2025-06-11-voronoi-astronomy/ https://arxiv.org/abs/2511.14697

Re: Is Matrix Multiplication Ugly?

#26

Do you disagree with my take or think I’m missing Witt’s point? I’d be happy to hear from people who disagree with me.

If the O( n ^3) schoolbook multiplication were the best that could be done, then I'd totally agree that "it's simply the nature of matrices to have a bulky multiplication process". Yet there's a whole series of algorithms (from the Strassen algorithm onward) that use ever-more-clever ways to recursively batch things up and decrease the asymptotic complexity, most of which aren't remotely practical. And for all I know…

For anyone interested, there is a introductory survey of the current lower bound at: https://en.wikipedia.org/wiki/Computational_complexity_of_ma...

Re: Is Matrix Multiplication Ugly?

#27
Matmuls (and GEMM) are a hardware-friendly way to stuff a lot of FLOPS into an operation. They also happen to be really useful as a constant-step discrete version of applying a mapping to a 1D scalar field.

I've mentioned it before, but I'd love for sparse operations to be more widespread in HPC hardware and software.

Re: Is Matrix Multiplication Ugly?

#28

Do you disagree with my take or think I’m missing Witt’s point? I’d be happy to hear from people who disagree with me.

I think 4x4 matrices for 3D transforms (esp homogenous coordinates) are very elegant. I think the intended critique is that the huge n*m matrices used in ML are not elegant - but the point is made poorly by pointing out properties of general matrices. In ML matrices are just "data", or "weights". There are no interesting properties to these matrices. In a way a Neumann (https://en.wikipedia.org/wiki/Von_Neumann%27s_elephant) Elephant. Now, this might just be what it is needed for ML to work and deal with messy real world data! But mathematically it is not elegant.

Re: Is Matrix Multiplication Ugly?

#29
Well function composition f(g(x)) is not the same as g(f(x)) and when you represent f and g as matrices relative to some suitable set of basis functions then obviously AB and BA should be different. If the multiplication was defined any different, that wouldn’t work.

Re: Is Matrix Multiplication Ugly?

#30
post #4

I think this sentence: > But matrix multiplication, to which our civilization is now devoting so many of its marginal resources, has all the elegance of a man hammering a nail into a board. is the most interesting one. A man hammering a nail into a board can be both beautiful and elegant! If you've ever seen someone effortlessly hammer nail after nail into wood without having to think hardly at all about what they're…

A somewhat more beautiful matmul for neural networks is given by the Monarch paper: https://arxiv.org/abs/2204.00595

Generally, low-rank and block-diagonal matrices are both great strategies for producing expressive matmuls with fewer parameters. We can view the FFT as a particularly deft example of factorizing one big matmul into a number of block-diagonal matmuls, greatly reducing the overall number of multiplications by minimizing the block size. However, on a G/TPU, we have a lot more parallelism available, so the sweet spot for size of the blocks may be larger than 2x2...

We can also mix low-rank, block diagonal, and residual connections to get the best of both worlds:

x' = (L@x + B@x + x)

The block-diagonal matrix does 'local' work, and the low-rank matrix does 'broadcast' work. I find it pretty typical to be able to replace a single dense matmul with this kind of structure and save ~90% of the params with no quality cost... (and sometimes the regularization actually helps!)

Post reply on HN