0xBUFF / docs

Matrix multiplication

Follow rows, columns, partial products, and result cells in the matrix domain.

Version scope — v0.0.2 (historical schema 1). This page and its examples use @0xbuff/throughline@0.0.2, the version pinned by this documentation app. They do not describe the unreleased schema-2 API intended for v0.2.0. See compatibility and upgrading.

The matrix domain explains ordinary matrix multiplication, one output cell at a time. Its steps are deterministic and computed from the two supplied numeric grids.

Input

```thl matrix
A = [[1,2],[3,4]]
B = [[5,6],[7,8]]
```

Each operand must be rectangular, with 1–4 rows and 1–4 columns, containing finite JSON numbers. The column count of A must equal the row count of B. The operands can appear in either order, but both must be present exactly once.

The result for this example is:

C = [[19,22],
     [43,50]]

What each step explains

Throughline creates four result beats, in row-major order:

BeatDot productResult
C[0][0]1×5 + 2×719
C[0][1]1×6 + 2×822
C[1][0]3×5 + 4×743
C[1][1]3×6 + 4×850

For every cell, the generated beat focuses the selected A row and B column, writes the one result cell, updates the Terms work row with pairwise products, emits labeled read transfers, and provides a calculation note.

The result matrix C begins filled with the "·" placeholder to make yet-to-be-calculated cells visible.

Inspect the final result

import { compile } from "@0xbuff/throughline";

const trace = compile([
  "thl matrix",
  "A = [[1,2],[3,4]]",
  "B = [[5,6],[7,8]]",
].join("\n"));

console.log(trace.frames.length); // 5: initial + four output cells
console.log(
  trace.frames.at(-1)?.state.entities.find((entity) => entity.id === "C")?.value,
); // [[19, 22], [43, 50]]

Non-square matrices

Square input is not required. For instance, a 1×3 row multiplied by a 3×1 column is valid:

```thl matrix
A = [[2,3,4]]
B = [[5],[6],[7]]
```

Its single output is [[56]].

Scope

This domain implements multiplication, not addition, determinants, transposes, inverses, or symbolic algebra. For other matrix stories, author explicit steps with flow.

On this page