A research project investigating fast matrix multiplication algorithms for small matrix formats, from 2x2x2 to 16x16x16. The primary goal is to discover efficient schemes
with coefficients restricted to the ternary set {-1, 0, 1}, focusing on all tensor shapes satisfying max(n₁, n₂, n₃) ≤ 16.
This repository documents the search for fast matrix multiplication (FMM) schemes using a custom meta flip graph method. The search focuses on schemes that use only the
coefficients -1, 0, and 1, denoted as ZT. This constraint is significant for practical implementations where computational complexity and hardware efficiency are critical.
Key insight: several known optimal schemes originally found over the rationals (Q) or integers (Z) have been successfully rediscovered with minimal, ternary
coefficients. This can lead to more efficient and hardware-friendly implementations.
For a detailed history of discoveries and improvements, see the CHANGELOG.md.
- Meta Flip Graph meets Serendipitous Product: new Fast Matrix Multiplication results (arxiv)
- Fast Matrix Multiplication in Small Formats: Discovering New Schemes with an Open-Source Flip Graph Framework (arxiv)
- A 58-Addition, Rank-23 Scheme for General 3x3 Matrix Multiplication (arxiv)
- Parallel Heuristic Exploration for Additive Complexity Reduction in Fast Matrix Multiplication (arxiv)
- Fast Matrix Multiplication via Ternary Meta Flip Graphs (arxiv)
- New best ranks and rediscoveries
- Rank comparison across rings
- Additions reduction and leading coefficients
The research employs a multi-stage approach using custom-built tools:
ternary_flip_graph: core flip graph exploration toolkit
A comprehensive CPU-based toolkit for discovering fast matrix multiplication algorithms using flip graph techniques. Supports multiple coefficient sets
({0, 1}, {0, 1, 2}, {-1, 0, 1}) and provides tools for rank minimization, complexity optimization, alternative scheme discovery, and meta operations
for transforming schemes between dimensions.
ternary_addition_reducer: addition reduction tool
A high-performance tool for optimizing the number of arithmetic additions in fast matrix multiplication algorithms with ternary coefficients. It implements multiple heuristic strategies to find near-optimal computation schemes, significantly reducing the additive cost of matrix multiplications schemes.
This script starts from an existing binary (Z2) scheme and discovers new, non-identical schemes for the same dimensions. It works by:
- Randomly preserving coefficients from the original
U,V,Wmatrices with configurable probabilities; - Solving the resulting Brent equations using the CryptoMiniSat SAT solver;
- Exploring the solution space around known schemes.
python find_alternative_schemes.py -i <input_scheme_path> -o <output_dir> [options]-pu,-pv,-pw- probability thresholds for preservingU,V,Wcoefficients (default:0.8)--max-time- sat solver timeout in seconds (default:20)-f- maximum flip iterations for more effective search-t- number of sat solver threads
This script lifts binary (Z2) schemes to the ternary integer coefficient set (ZT, coefficients {-1, 0, 1})
using OR-Tools SAT solver.
python lift_schemes.py -i <input_dir> -o <output_dir> [options]--max-time- maximum lifting time per scheme in seconds--max-solutions- maximum number of ternary solutions to find--sort-scheme- output schemes in "canonical" form-f- force re-lifting of existing schemes
This research consolidates and analyzes schemes from several leading sources in the field:
| Source | Description |
|---|---|
| FMM catalogue | The central repository for known fast matrix multiplication algorithms (fmm.univ-lille.fr). |
| MMC — Matrix Multiplication Catalog | Large catalog tracking history and fields, maintained by @blacelle (matmulcatalog). |
| Alpha Tensor | Schemes from DeepMind's AlphaTensor project (https://github.com/google-deepmind/alphatensor/tree/main/algorithms). |
| Alpha Evolve | Schemes from DeepMind's AlphaEvolve project (mathematical_results.ipynb). |
| Original Flip Graph | Foundational work by Jakob Moosbauer (flips). |
| Adaptive flip graph | Improved flip graph approach (adap). |
| Symmetric flip graph | Flip graphs with symmetry (symmetric-flips). |
| Meta Flip Graph | Advanced flip graph techniques by M. Kauers et al. (matrix-multiplication). |
| FMM Add Reduction | Work on additive reductions by @werekorren (fmm_add_reduction). |
| LITA | Local Improvements to Trilinear Aggregation by @khoruzhii (lita). |
| fmm_schemes | New fast matrix multiplication schemes by @MerlijnW70 (fmm_schemes). |
| cloudroom-math | Cloudroom Math: new matrix multiplication algorithms found by AI agents by @matyasstoch (cloudroom-math) |
| mizopl | Near optimal ternary schemes from @mizopl |
| stapleton | Schemes from @Joshua Stapleton |
| arhancanli | Schemes from quantavane-fmm-records discovered by @Arhan Canli |
| gsidebottom | Schemes from mat_mul discovered by @Greg Sidebottom |
This repository uses two JSON formats for storing matrix-multiplication schemes:
- Full scheme format (
.json) - complete description with human-readable bilinear products and the matricesU,V,W; - Reduced scheme format (
_reduced.json) - compact representation used after additive-complexity reduction.
Both formats are described below.
This is the primary format used in the repository.
Each file describes a bilinear algorithm for multiplying an n₁×n₂ by n₂×n₃ using mmultiplications.
{
"n": [n₁, n₂, n₃],
"m": rank,
"z2": false,
"u": [...],
"v": [...],
"w": [...],
"multiplications": [...],
"elements": [...]
}
n- array[n₁, n₂, n₃]describing the dimensions (Aisn₁ × n₂,Bisn₂ × n₃);m- number of bilinear multiplications (rank);z2- whether coefficients are in Z2 field (true) or in any other (false);multiplications(human-readable) - list of expressionsm_k = (linear form in A) * (linear form in B);elements(human-readable) - expressions for each entryc_{ij}as linear combination of them_k;u(machine-readable) - matrix encoding the linear form ofA, sizem × (n₁·n₂);v(machine-readable) - matrix encoding the linear form ofB, sizem × (n₂·n₃);w(machine-readable) - matrix encoding the linear form ofCᵀ, sizem × (n₃·n₁);
This format is intended for reproducibility and human and machine readability.
Scheme (2, 2, 2: 7):
{
"n": [2, 2, 2],
"m": 7,
"z2": false,
"multiplications": [
"m1 = (a11 + a22) * (b11 + b22)",
"m2 = (a12 - a22) * (b21 + b22)",
"m3 = (-a11 + a21) * (b11 + b12)",
"m4 = (a11 + a12) * (b22)",
"m5 = (a11) * (b12 - b22)",
"m6 = (a22) * (-b11 + b21)",
"m7 = (a21 + a22) * (b11)"
],
"elements": [
"c11 = m1 + m2 - m4 + m6",
"c12 = m4 + m5",
"c21 = m6 + m7",
"c22 = m1 + m3 + m5 - m7"
],
"u": [
[1, 0, 0, 1],
[0, 1, 0, -1],
[-1, 0, 1, 0],
[1, 1, 0, 0],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 1]
],
"v": [
[1, 0, 0, 1],
[0, 0, 1, 1],
[1, 1, 0, 0],
[0, 0, 0, 1],
[0, 1, 0, -1],
[-1, 0, 1, 0],
[1, 0, 0, 0]
],
"w": [
[1, 0, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[-1, 0, 1, 0],
[0, 0, 1, 1],
[1, 1, 0, 0],
[0, 1, 0, -1]
]
}The reduced scheme format is used to store bilinear algorithms after additive-complexity reduction. It contains both the "fresh-variable" representation (used during common-subexpression elimination) and the final reduced linear forms.
{
"n": [n₁, n₂, n₃],
"m": rank,
"z2": false,
"complexity": {"naive": x, "reduced": y},
"u_fresh": [...],
"v_fresh": [...],
"w_fresh": [...],
"u": [...],
"v": [...],
"w": [...]
}
n,m,z2- these fields have the same meaning as in the full scheme format (matrix dimensions, number of bilinear multiplications and binary field flag);
naive- total number of additions before any reduction;reduced- number of additions after elimination of common subexpressions and simplification.
The reducer may introduce fresh intermediate variables to eliminate repeated subexpressions.
These are stored in three arrays: u_fresh, v_fresh and w_fresh.
Each array contains sparse linear forms written as:
[{ "index": i, "value": c }, ...]
Fresh-variable indices are allocated in consecutive blocks:
- For
U: original indices:0 ... n₁·n₂ - 1, fresh indices start from: n1·n2; - For
V: original indices:0 ... n₂·n₃ - 1, fresh indices start from: n2·n3; - For
W: original indices:0 ... m - 1, fresh indices start from: m.
Thus the reducer’s intermediate variables do not collide with original matrix entries. Each list entry corresponds to one intermediate expression introduced during reduction.
After performing additive-complexity minimization, the reducer outputs the final optimized linear forms in u, v and w.
u and v arrays have exactly m rows each, w have n₃·n₁ rows, and each row represents a sparse linear form:
[{ "index": i, "value": c }, ...]
Reduced (2, 2, 2: 7) from 24 to 15 additions:
{
"n": [2, 2, 2],
"m": 7,
"z2": true,
"complexity": {"naive": 24, "reduced": 15},
"u_fresh": [
[{"index": 2, "value": 1}, {"index": 3, "value": 1}],
[{"index": 1, "value": 1}, {"index": 4, "value": 1}]
],
"v_fresh": [
[{"index": 2, "value": 1}, {"index": 3, "value": 1}],
[{"index": 1, "value": 1}, {"index": 4, "value": 1}]
],
"w_fresh": [
[{"index": 2, "value": 1}, {"index": 3, "value": 1}],
[{"index": 0, "value": 1}, {"index": 7, "value": 1}]
],
"u": [
[{"index": 4, "value": 1}],
[{"index": 2, "value": 1}],
[{"index": 1, "value": 1}],
[{"index": 5, "value": 1}],
[{"index": 0, "value": 1}],
[{"index": 0, "value": 1}, {"index": 5, "value": 1}],
[{"index": 1, "value": 1}, {"index": 3, "value": 1}]
],
"v": [
[{"index": 4, "value": 1}],
[{"index": 0, "value": 1}, {"index": 5, "value": 1}],
[{"index": 2, "value": 1}],
[{"index": 5, "value": 1}],
[{"index": 0, "value": 1}],
[{"index": 1, "value": 1}],
[{"index": 1, "value": 1}, {"index": 3, "value": 1}]
],
"w": [
[{"index": 2, "value": 1}, {"index": 4, "value": 1}],
[{"index": 1, "value": 1}, {"index": 6, "value": 1}, {"index": 7, "value": 1}],
[{"index": 5, "value": 1}, {"index": 8, "value": 1}],
[{"index": 6, "value": 1}, {"index": 8, "value": 1}]
]
}The repository provides a Scheme class with a load method that supports all scheme formats used here:
- Full scheme format (
.json); - Addition-reduced scheme format (
reduced.json); - Maple format (
.m) - Plain text expressions (
.exp) - Maple tensor representation (
.tensor.mpl)
This allows seamless integration of schemes produced by different tools and sources.
from src.schemes.scheme import Scheme
scheme = Scheme.load("scheme.json")
scheme.show() # print the scheme in human-readable format
scheme.show_tensors() # print the scheme in (a)*(b)*(c) format
# scheme saving
scheme.save("scheme.json") # save in json format
scheme.save_maple("scheme.m") # save in maple format
scheme.save_txt("scheme.txt") # save in txt format
scheme.save_tensor_mpl("scheme.tensor.mpl") # save in tensor.mpl formatThis project is for research purposes. Please use the following citation when referencing this code or dataset in your academic work:
@article{perminov2026meta,
title={Meta Flip Graph meets Serendipitous Product: new Fast Matrix Multiplication results},
author={Perminov, Andrew I},
journal={arXiv preprint arXiv:2606.02480},
url={https://arxiv.org/abs/2606.02480},
year={2026}
}@article{perminov2026fast,
title={Fast Matrix Multiplication in Small Formats: Discovering New Schemes with an Open-Source Flip Graph Framework},
author={Perminov, Andrew I},
journal={arXiv preprint arXiv:2603.02398},
url={https://arxiv.org/abs/2603.02398},
year={2026}
}@article{perminov202558,
title={A 58-Addition, Rank-23 Scheme for General 3x3 Matrix Multiplication},
author={Perminov, Andrew I},
journal={arXiv preprint arXiv:2512.21980},
url={https://arxiv.org/abs/2512.21980},
year={2025}
}@article{perminov2025parallel,
title={Parallel Heuristic Exploration for Additive Complexity Reduction in Fast Matrix Multiplication},
author={Perminov, Andrew I},
journal={arXiv preprint arXiv:2512.13365},
url={https://arxiv.org/abs/2512.13365},
year={2025}
}@article{perminov2025fast,
title={Fast Matrix Multiplication via Ternary Meta Flip Graphs},
author={Perminov, Andrew I},
journal={arXiv preprint arXiv:2511.20317},
url={https://arxiv.org/abs/2511.20317},
year={2025}
}