It is known that the multiplication of an $N \times M$ matrix with an $M \times P$ matrix can be performed using fewer multiplications than what the naive $NMP$ approach suggests. The most famous instance of this is Strassen's algorithm for multiplying two $2\times 2$ matrices in 7 instead of 8 multiplications. This gives rise to the constraint satisfaction problem of fast matrix multiplication, where a set of $R < NMP$ multiplication terms must be chosen and combined such that they satisfy correctness constraints on the output matrix. Despite its highly combinatorial nature, this problem has not been exhaustively examined from that perspective, as evidenced for example by the recent deep reinforcement learning approach of AlphaTensor. In this work, we propose a simple yet novel Constraint Programming approach to find non-commutative algorithms for fast matrix multiplication or provide proof of infeasibility otherwise. We propose a set of symmetry-breaking constraints and valid inequalities that are particularly helpful in proving infeasibility. On the feasible side, we find that exploiting solver performance variability in conjunction with a sparsity-based problem decomposition enables finding solutions for larger (feasible) instances of fast matrix multiplication. Our experimental results using CP Optimizer demonstrate that we can find fast matrix multiplication algorithms for matrices up to $3\times 3$ in a short amount of time.
翻译:摘要:众所周知,一个 $N \times M$ 矩阵与一个 $M \times P$ 矩阵的乘法,可以用比朴素 $NMP$ 方法更少的乘法次数完成。最著名的实例是 Strassen 算法,它通过 7 次而非 8 次乘法实现两个 $2\times 2$ 矩阵的相乘。这引出了快速矩阵乘法的约束满足问题:必须选择并组合一组 $R < NMP$ 个乘积项,使其满足输出矩阵的正确性约束。尽管该问题具有高度组合性质,但尚未从这一角度得到详尽研究,例如 AlphaTensor 近期采用的深度强化学习方法即为例证。在本工作中,我们提出一种简单而新颖的约束规划方法,用于寻找快速矩阵乘法的非交换算法,或在不可行时给出不可行性证明。我们提出了一组对称性打破约束和有效不等式,这些特别有助于证明不可行性。在可行方面,我们发现利用求解器性能的变异性,并结合基于稀疏性的问题分解,能够为更大(可行)的快速矩阵乘法实例找到解。我们使用 CP Optimizer 进行的实验结果表明,该方法能在短时间内找到高达 $3\times 3$ 矩阵的快速矩阵乘法算法。