10. Linear Algebra Primitives: Pixels, Vexels, Maxels
The polynumber layer of box arithmetic — Polynumber, Multinumber, degree truncation — gives us a powerful tool for encoding scalar invariants. But DeFi protocols do not operate on scalars alone. A portfolio is a vector of balances. A swap is a linear map between token spaces. A routing graph is a directed structure over token indices. These are linear-algebraic objects, and box arithmetic has a natural foundation for them that requires no fractions, no floating point, and no division.
The three primitives are Pixel, Vexel, and Maxel — defined in §5 of Wildberger's Box Arithmetic Overview.
From multisets to ordered lists
Every primitive introduced so far — natural numbers, polynumbers, multinumbers — is an unordered box. The empty box is the atom; is the same box as , order irrelevant. This is the right foundation for polynomial algebra, where .
To encode vectors and matrices we need ordered data. The solution is the listbox: an encoding of order inside the unordered box world.
A listbox is not a flat sequence — it is a box of prefix sets:
The order is recovered from subset containment: . Each entry is uniquely determined by Proposition 5 in the paper. This construction is the bridge from the unordered box world into ordered, positional data.
Singleton: a 1-listbox
A singleton is the simplest listbox — a single natural number in listbox form. As a box it is , the -th base multinumber. Singletons are the natural basis for vector indices.
Pixel: a 2-listbox
A pixel is a 2-listbox of natural numbers. In box form:
Think of as a matrix index pair: row , column .
Pixels support a non-commutative, partial multiplication — the pixel product (Definition 11):
The result is not zero — it is nothing: no output is produced at all. Wildberger compares it to particle-antiparticle annihilation in physics. In code, pixelProduct returns null / (false, _).
This operation is associative but not commutative. It mirrors matrix index composition exactly: chains row through column to column , just as multiplying matrix entries contributes to .
import { Pixel } from 'boxmath';
new Pixel(3n, 4n).pixelProduct(new Pixel(4n, 11n)); // Pixel(3n, 11n)
new Pixel(3n, 4n).pixelProduct(new Pixel(5n, 11n)); // null — nothing
Transpose
new Pixel(3n, 7n).transpose; // Pixel(7n, 3n)
Pythagorean triples
The pixel algebra has a striking classical connection. For a pixel with :
The triple is a Pythagorean triple. Every primitive Pythagorean triple arises from exactly one such pixel. The ancient Babylonian tablet MS3971 lists Pythagorean triples parametrised by exactly this formula — a connection between Box Arithmetic's ordered pairs and a 4000-year-old mathematical tradition, all without fractions or square roots.
new Pixel(2n, 1n).pythagoreanTriple(); // [3n, 4n, 5n]
new Pixel(3n, 2n).pythagoreanTriple(); // [5n, 12n, 13n]
new Pixel(4n, 3n).pythagoreanTriple(); // [7n, 24n, 25n]
Vexel: a box of singletons
A vexel is a box of singletons with natural-number coefficients:
This is a coefficient vector over the singleton basis — the Box Arithmetic equivalent of a vector in . All operations are exact integer arithmetic.
import { Vexel } from 'boxmath';
const v1 = Vexel.fromArray([1n, 2n, 3n]);
const v2 = Vexel.fromArray([4n, 5n, 6n]);
v1.add(v2).toArray(3); // [5n, 7n, 9n]
v1.dot(v2); // 32n (1·4 + 2·5 + 3·6)
v1.scale(3n).toArray(3); // [3n, 6n, 9n]
A vexel of token balances is the natural representation of a multi-asset portfolio — no scaling factors, no decimal conversions between assets.
Maxel: a box of pixels
A maxel is a box of pixels with natural-number coefficients — a sparse matrix over :
The maxel product is the box of all pixel products between elements of and :
- Pixel products that are nothing are dropped
- Coefficients of identical result pixels are summed
This is exactly matrix multiplication over — but derived from the pixel product, not postulated as an axiom.
import { Pixel, Maxel } from 'boxmath';
// From §5.3, Example 23 of the paper:
// M = 2[0,0] + [1,0] + 3[0,2]
// N = [1,0] + 4[0,1] + 7[2,1] + 5[3,2]
// MN = 29[0,1] + 4[1,1]
const M = new Maxel([
[new Pixel(0n, 0n), 2n],
[new Pixel(1n, 0n), 1n],
[new Pixel(0n, 2n), 3n],
]);
const N = new Maxel([
[new Pixel(1n, 0n), 1n],
[new Pixel(0n, 1n), 4n],
[new Pixel(2n, 1n), 7n],
[new Pixel(3n, 2n), 5n],
]);
M.maxelProduct(N).get(0n, 1n); // 29n
M.maxelProduct(N).get(1n, 1n); // 4n
Transpose
The transpose of a maxel is the box of transposes of its pixels:
This maps directly to the usual matrix transpose: entry of becomes entry of .
Solidity equivalents
All three primitives have isomorphic Solidity implementations in PixelMath.sol:
struct Pixel { uint256 m; uint256 n; }
struct MaxelEntry { Pixel pixel; uint256 coeff; }
// Pixel
function pixelProduct(Pixel memory a, Pixel memory b)
public pure returns (bool ok, Pixel memory result);
function pixelTranspose(Pixel memory p) public pure returns (Pixel memory);
function pythagoreanTriple(Pixel memory p)
public pure returns (bool ok, uint256 a, uint256 b, uint256 c);
// Vexel (dense uint256[])
function vexelAdd(uint256[] memory u, uint256[] memory v) public pure returns (uint256[] memory);
function vexelDot(uint256[] memory u, uint256[] memory v) public pure returns (uint256);
function vexelScale(uint256[] memory u, uint256 scalar) public pure returns (uint256[] memory);
// Maxel (sparse MaxelEntry[])
function maxelProduct(MaxelEntry[] memory M, MaxelEntry[] memory N)
public pure returns (MaxelEntry[] memory);
function maxelTranspose(MaxelEntry[] memory M) public pure returns (MaxelEntry[] memory);
The next section shows these primitives applied to a concrete protocol problem: multi-hop swap routing.
Out of scope for v0: the handed algebra
Sections 5.4–5.5 of the paper describe a richer algebraic structure that emerges when maxels act on vexels. At the pixel level, a singleton can be hit from the left or right by a pixel:
This gives rise to distinct left and right multiplication operators (, ) that compose in a non-associative way — a "handed" algebra. Section 5.5 then connects maxel bases to partially ordered sets and Möbius inversion.
Both threads are mathematically deep and implementable, but have no clear protocol primitive yet. They are left as future work. The current Vexel and Maxel implementations cover the linear-algebraic layer (vectors, matrices, dot products, matrix multiplication) without requiring the handed structure.