alphaFeedback

WorksComputer Science

Improved basis-change transformations for 2×22 \times 2 matrix multiplication

AI contributions
  • OpenAI ChatGPT GPT-6 Astra
View details

Abstract

To the best of our knowledge, we present a state-of-the-art change-of-basis algorithm for 2×22 \times 2 matrix multiplication under the Karstadt–Schwartz-style basis change regime [1]. We do this by introducing basis-change matrices BUB_U, BVB_V, and BWB_W that each require only a single addition and hence give rise to a matrix-multiplication algorithm performing 5nlog⁡27−4n2+34n2log⁡2n,5n^{\log_2{7}} - 4n^2 + \frac{3}{4}n^2 \log_2{n}, arithmetic operations when multiplying two n×nn \times n matrices, with nn a power of 22. This improves on the previous best bound, which had last term 32n2log⁡2n\frac{3}{2}n^2\log_2{n}.

Introduction

The Karstadt–Schwartz-style basis change is a well-studied method, and we will not repeat the method here. For background on the Karstadt–Schwartz-style basis-change method, see [1, 2, 3, 4]. Let RR be an arbitrary ring, and let AA, B∈R2×2B \in R^{2 \times2} be matrices over this ring. We use column-major vectorization, A⃗=[a11 a21 a12 a22]T\vec{A} = [a_{11}\ a_{21}\ a_{12}\ a_{22}]^{\mathsf{T}}. Here and below, when counting additions, we will use the convention that a subtraction also counts as an addition, see [4, 5, 6]. Let the matrices UU, VV, W∈Z7×4W \in\mathbb{Z}^{7 \times4} satisfy

AB⃗=WT((UA⃗)⊙(VB⃗)),(1)\vec{AB} = W^{\mathsf{T}}\left((U\vec{A}) \odot(V\vec{B})\right), \tag*{(1)}

for all matrices AA, B∈R2×2B \in R^{2 \times2}. Moreover, let BUB_U, BVB_V, BW∈Z4×4B_W \in\mathbb{Z}^{4 \times4} be invertible over Z\mathbb{Z}. For arbitrary x∈R4x \in R^4, let βU\beta_U, βV\beta_V, βW\beta_W denote the number of additions required to compute respectively BUxB_Ux, BVxB_Vx, and BWxB_Wx. Finally, denote by αU\alpha_U, αV\alpha_V, and αW\alpha_W the number of additions required to compute respectively U~x~\widetilde{U}\tilde{x}, V~x~\widetilde{V}\tilde{x}, and W~Ty\widetilde{W}^{\mathsf{T}}y for arbitrary x∈R4x \in R^4, and y∈R7y \in R^7, with

U~=UBU−1,V~=VBV−1,W~=WBW−1.\widetilde{U} = UB_U^{-1}, \qquad\widetilde{V} = VB_V^{-1}, \qquad\widetilde{W} = WB_W^{-1}.

Theorem 1.1. For n∈Nn \in\mathbb{N} an integer-power of 2 we can multiply matrices AA, B∈Rn×nB \in R^{n \times n} in

(1+αU+αV+αW3)nlog⁡27−αU+αV+αW3n2+βU+βV+βW4n2log⁡2n(2)\left(1 + \frac{\alpha_U + \alpha_V + \alpha_W}{3}\right)n^{\log_2 7} - \frac{\alpha_U + \alpha_V + \alpha_W}{3}n^2 + \frac{\beta_U + \beta_V + \beta_W}{4}n^2\log_2 n \tag*{(2)}

arithmetic operations.

Proof See Claim 2.9, Claim 2.12, and Corollary 2.15 in [1].

Now consider matrices

U=(1000001001000−11100010−101−1−111),V=(10000100−1−1110−11100110−1010010),W=(10001−11−10−1000−11−1010100−1100−10).U=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&-1&1&1\\0&0&0&1\\0&-1&0&1\\-1&-1&1&1\end{pmatrix},\qquad V=\begin{pmatrix}1&0&0&0\\0&1&0&0\\-1&-1&1&1\\0&-1&1&1\\0&0&1&1\\0&-1&0&1\\0&0&1&0\end{pmatrix},\qquad W=\begin{pmatrix}1&0&0&0\\1&-1&1&-1\\0&-1&0&0\\0&-1&1&-1\\0&1&0&1\\0&0&-1&1\\0&0&-1&0\end{pmatrix}.

with basis-change matrices

S=BU=BV=(1000010000100011),S−1=BW=(10000100001000−11).(3)S=B_U=B_V=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&1&1\end{pmatrix},\qquad S^{-1}=B_W=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&-1&1\end{pmatrix}. \tag*{(3)}

It is straightforward to verify that the matrix triple U,V,WU,V,W satisfies equation (1.1), and that BU,BV,B_U,B_V, and BWB_W are invertible over Z\mathbb{Z}. Moreover, clearly βU=βV=βW=1\beta_U=\beta_V=\beta_W=1, giving us the trailing term 34n2log⁡2n\frac{3}{4}n^2\log_2 n in equation (1.2).

We can compute U~,V~,\widetilde{U},\widetilde{V}, and W~\widetilde{W} as follows

U~=UBU−1=(1000001001000−10100010−1−11−1−101),V~=VBV−1=(10000100−1−1010−10100010−1−110010),W~=WBW−1=(10001−10−10−1000−10−10111000100−10).\widetilde{U}=UB_U^{-1}=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&-1&0&1\\0&0&0&1\\0&-1&-1&1\\-1&-1&0&1\end{pmatrix},\qquad \widetilde{V}=VB_V^{-1}=\begin{pmatrix}1&0&0&0\\0&1&0&0\\-1&-1&0&1\\0&-1&0&1\\0&0&0&1\\0&-1&-1&1\\0&0&1&0\end{pmatrix},\qquad \widetilde{W}=WB_W^{-1}=\begin{pmatrix}1&0&0&0\\1&-1&0&-1\\0&-1&0&0\\0&-1&0&-1\\0&1&1&1\\0&0&0&1\\0&0&-1&0\end{pmatrix}.

The linear transformations induced by U~\widetilde{U} and V~\widetilde{V} can be computed using 3 additions each as follows:

s1=x4−x2,s2=s1−x3,s3=s1−x1.s_1=x_4-x_2,\qquad s_2=s_1-x_3,\qquad s_3=s_1-x_1.

such that

U~x=[x1 x3 x2 s1 x4 s2 s3]T\widetilde{U}x=[x_1\ x_3\ x_2\ s_1\ x_4\ s_2\ s_3]^{\mathsf{T}}
V~x=[x1 x2 s3 s1 x4 s2 x3]T.\widetilde{V}x=[x_1\ x_2\ s_3\ s_1\ x_4\ s_2\ x_3]^{\mathsf{T}}.

for all x∈R4x\in\mathbb{R}^4. Therefore αU=αV=3\alpha_U=\alpha_V=3. The linear transformation induced by W~T\widetilde{W}^{\mathsf{T}} can be computed using 6 additions as follows:

t1=M5−M4,t2=t1−M2,y1=M1+M2,y2=t2−M3,y3=M5−M7,y4=t2+M6.\begin{aligned} t_1&=M_5-M_4, & t_2&=t_1-M_2,\\ y_1&=M_1+M_2, & y_2&=t_2-M_3,\\ y_3&=M_5-M_7, & y_4&=t_2+M_6. \end{aligned}

such that

W~TM=[y1 y2 y3 y4]T\widetilde{W}^{\mathsf{T}}M=[y_1\ y_2\ y_3\ y_4]^{\mathsf{T}}

for any M∈R7M\in\mathbb{R}^7. From which it follows that αW=6\alpha_W=6.

By Theorem 1.1 we can thus multiply two n×nn\times n matrices using a Karstadt–Schwartz-style basis-change in

5nlog⁡27−4n2+34n2log⁡2n5n^{\log_2 7}-4n^2+\frac{3}{4}n^2\log_2 n

arithmetic operations, using the basis-change induced by the matrices BU,BV,B_U,B_V, and BWB_W defined in equation (1.3).

Verification

The following Python program provides a simple verification of the scheme.

Small verification script

Figure 1. Small verification script (verify.py).

"""
Artisinally hand-crafted code
"""
import numpy as np
import sympy as sp

inv = np.linalg.inv
S = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 1]]).astype(int)
assert(not any(((S @ inv(S).astype(int)) - np.eye(4)).flatten())) # inv over Z sanity
check

U = np.array( [ [1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, -1, 1, 1], [0, 0, 1, 1],
[0, -1, 0, 1], [-1, -1, 1, 1] ]).astype(int)
V = np.array( [ [1, 0, 0, 0], [0, 1, 0, 0], [-1, -1, 1, 1], [0, -1, 1, 1], [0, 0, 1,
1], [0, -1, 0, 1], [0, 0, 1, 0] ]).astype(int)
W = np.array( [ [1, 0, 0, 0], [1, -1, 1, -1], [0, -1, 0, 0], [0, -1, 1, -1], [0, 1, 0,
1], [0, 0, -1, 1], [0, 0, -1, 0] ]).astype(int)

A_vec = sp.Matrix([sp.Symbol(f"A_{j}{i}", commutative=False) for i in range(1,3) for j
in range(1,3)])
B_vec = sp.Matrix([sp.Symbol(f"B_{j}{i}", commutative=False) for i in range(1,3) for j
in range(1,3)])

# sanity check that U,V,W encodes matrix multiplication
print("#" * 32)
hadamard = sp.matrices.dense.matrix_multiply_elementwise
print(f"{sp.simplify(W.T @ hadamard((U @ A_vec), (V @ B_vec)))=}")

U_tilde = U @ inv(S).astype(int)
V_tilde = V @ inv(S).astype(int)
W_tilde = W @ S
print("#" * 32)
print(f"{U_tilde=}")
print(f"{V_tilde=}")
print(f"{W_tilde.T=}")

def compute_U(x):
    s_1 = x[3] - x[1] # 1 add
    s_2 = s_1 - x[2] # 2 add
    s_3 = s_1 - x[0] # 3 add
    return sp.Matrix([x[0], x[2], x[1], s_1, x[3], s_2, s_3])
def compute_V(x):
    s_1 = x[3] - x[1] # 1 add
    s_2 = s_1 - x[2] # 2 add
    s_3 = s_1 - x[0] # 3 add
    return sp.Matrix([x[0], x[1], s_3, s_1, x[3], s_2, x[2]])
def compute_W(M):
    t_1 = M[4] - M[3] # 1 add
    t_2 = t_1 - M[1] # 2 add
    y_1 = M[0] + M[1] # 3 add
    y_2 = t_2 - M[2] # 4 add
    y_3 = M[4] - M[6] # 5 add
    y_4 = t_2 + M[5] # 6 add
    return sp.Matrix([y_1, y_2, y_3, y_4])

print("#" * 32)
x = sp.Matrix([sp.Symbol(f"x_{i}") for i in range(1,5)])
y = sp.Matrix([sp.Symbol(f"x_{i}") for i in range(1,8)])
print(f"Should be a bunch of zeros only:")
print(f"{U_tilde @ x - compute_U(x)=}")
print(f"{V_tilde @ x - compute_V(x)=}")
print(f"{W_tilde.T @ y - compute_W(y)=}")

Declaration of use of generative AI

GPT-6-Astra was used for finding this result. The manuscript is prepared by me, with minor language editing and grammar help from the machine. I take full responsibility for the final manuscript.

References

  1. [1]Schwartz, O., Vaknin, N.: Pebbling game and alternative basis for high performance matrix multiplication. SIAM Journal on Scientific Computing 45(6), C277–C303 (2023) https://doi.org/10.1137/22M1502719
  2. [2]Karstadt, E., Schwartz, O.: Matrix multiplication, a little faster. Journal of the ACM 67(1), 1–31 (2020) https://doi.org/10.1145/3364504
  3. [3]Karstadt, E., Schwartz, O.: Matrix multiplication, a little faster. In: Proceedings of the 29th ACM Symposium on Parallelism in Algorithms and Architectures. SPAA ’17, pp. 101–110. Association for Computing Machinery, New York, NY, USA (2017). https://doi.org/10.1145/3087556.3087579 . https://doi.org/10.1145/3087556.3087579
  4. [4]Nielsen, H.: A 52-Addition, Rank-23 Scheme for Exact 3 × 3 Matrix Multiplication (2026). https://doi.org/10.48550/arXiv.2609.06588 . https://arxiv.org/abs/2609.06588
  5. [5]Van Zee, F.G., Smith, T.M.: Inducing complex matrix multiplication via the 3m and 4m methods. FLAME Working Note 81, The University of Texas at Austin, Austin, TX, USA (October 2016). https://www.cs.utexas.edu/%7Eflame/pubs/flawn81.pdf
  6. [6]Bläser, M.: Fast matrix multiplication. Theory of Computing Library, Graduate Surveys 5, 1–60 (2013) https://doi.org/10.4086/toc.gs.2013.005

Paper details

vlnc:W_syya4qn5
v1 · latestHistory (1)

published · Fresh — published within the last 30 days

Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0

Original source

  • Computer Science

OpenAI ChatGPT GPT-6 Astra · View statement →

Looking for related papers…
Contents