## Rewriting 5x5 matrix multiplication in terms of 4x4 matrices

Discuss interdimensional programming, Java applets and so forth.

### Rewriting 5x5 matrix multiplication in terms of 4x4 matrices

Is there an easy way to rewrite 5x5 matrix multiplications in terms of 4x4 (or smaller) matrices?

Background: I'm trying to implement 4D projections (5x5 matrix multiplications in homogenous coordinates) in the GPU, which has built-in support for 4x4 matrices but does not have 5x5 matrices. I could implement 5x5 matrices manually, but it would run slower than if I took advantage of built-in matrix types.

Are there any nice decompositions of 5x5 matrix multiplication into multiplications of smaller matrices?
quickfur
Pentonian

Posts: 2775
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North

### Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

I think I figured it out. I really only need 4x5 matrices in general, except for the 4D to 3D projection part, which can be done separately. Well strictly speaking these are 5x5 matrices where the bottom row is 0 0 0 ... 0 1. So let's denote such a matrix by A|a, where A is the upper left 4x4 submatrix and a is the last column of the 4x5 matrix. Then the following formula holds for products of these matrices:

A|a * B|b = (AB)|(Ab + a)

In other words, we can simulate these restricted 5x5 matrices by representing them as 4x4 matrices coupled with an extra 4D vector for its last column. The matrix product can then be simulated using the above formula, which requires only operations on 4x4 matrices and 4D vectors. (Addition and subtraction are of course trivially just the addition and subtraction of the 4x4 matrix and the attached column vectors.)
quickfur
Pentonian

Posts: 2775
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North

### Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Is it possible to add a program code for processing 5x5 matrices?
Challenger007
Dionian

Posts: 32
Joined: Thu Nov 12, 2020 2:51 pm

### Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Challenger007 wrote:Is it possible to add a program code for processing 5x5 matrices?

Of course. But it would be slower than if I used the built-in 4x4 matrix operations, which are likely hardware-accelerated.
quickfur
Pentonian

Posts: 2775
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North