CoqEAL seqmatrix multiplication refinement — List (List R) row-col product #
This file extends the CoqEAL seqmatrix add-refinement of SeqMatrix.lean from
addition to multiplication.
CoqEAL's seqmatrix refines MathComp matrices 'M[R]_(m,n) to lists of lists.
SeqMatrix.lean ported the Radd_seqmx square (concrete row-wise addMx
refines the abstract entrywise add). Matrix multiplication is the next
refinement: it is a foldl-shaped dot-product of rows against columns. Here we
build the concrete row-major multiply mulMx and prove the multiplication
refinement square
entry (mulMx p ncols m n) i j = ∑ k : Fin p, entry m i k * entry n k j
(the sum runs over the shared/contraction dimension p), under the well-formed
rectangular hypotheses that the row index is in range and the contracted row has
length p. This is the CoqEAL Rmul_seqmx-shaped square restricted to the
dimension-matching case — a correct restricted statement, as opposed to an
unproven fully-general one.
A matrix-vector product A · v is mulMx with a single-column right operand,
recorded as the specialization matVec / getD_matVec. The suite's frontier —
fast matrix multiply (Strassen), and the linear-solve, determinant, and
normal-form developments — is in the CoqEAL aggregator.
The CoqEAL seqmatrix refinement relation (re-stated here matching
SeqMatrix.entry): a row-major list of lists denotes the abstract entry
function ℕ → ℕ → R, with absent rows and entries 0.
Instances For
List dot product Σ pᵢ·qᵢ, truncating at the shorter length. This is the
inner fold that matrix multiplication contracts over.
Equations
Instances For
Dot-product refinement. Over two length-p lists, the concrete
dotProd equals the abstract finite sum of pointwise products. This is the
induction-on-the-shared-dimension core that the multiply square reuses.
Column j (first p rows) of a matrix n: the length-p list
[entry n 0 j, …, entry n (p-1) j]. Materializing the column lets the
row-col product reuse the row-shaped dotProd.
Equations
- Transfer.Examples.CoqEAL.SeqMatrixMul.column n p j = List.map (fun (k : ℕ) => Transfer.Examples.CoqEAL.SeqMatrixMul.entry n k j) (List.range p)
Instances For
Concrete (computational) row-major matrix multiply. Row i of the
product is the length-ncols list whose j-th entry is the dot product of
row i of m with column j of n; p is the shared (contraction)
dimension and ncols the column count of the result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Row i of mulMx (in range) is the explicit map of dot products.
The CoqEAL Rmul_seqmx refinement square (well-formed case). The
concrete row-col list multiply mulMx refines the abstract entrywise matrix
product: entry (i,j) is the sum over the shared dimension p of
entry m i k * entry n k j. Hypotheses pin the well-formed rectangular
shape — the result row i is present (hi), the output has a j-th column
(hj), and the contracted row i of m has length p (hrow).
Functional form of the multiply square (over the fixed in-range row i,
in-bounds columns, well-formed contracted row) — the commuting square the
ReprTransfer registry consumes (concrete mulMx ↦ abstract entrywise
product).
Specialization: matrix-vector product #
A matrix-vector product A · v is mulMx with a single-column right operand. We
give the direct form: the concrete matVec maps each row of A to its dot
product with v, and refines the abstract matrix-vector product
(A·v)_i = ∑_k A_{i,k} v_k.
Concrete matrix-vector product: each row of A dotted with v.
Equations
- Transfer.Examples.CoqEAL.SeqMatrixMul.matVec A v = List.map (fun (r : List R) => Transfer.Examples.CoqEAL.SeqMatrixMul.dotProd r v) A
Instances For
Matrix-vector refinement square (well-formed case). The i-th entry of
the concrete A · v equals the abstract sum ∑ k, A_{i,k} v_k over the
shared dimension p, given the row is in range, the row has length p, and
v has length p.
Agreement with Mathlib Matrix.mulVec #
The matrix-vector refinement square above (getD_matVec) relates the concrete
List-rep matVec to a raw Finset sum ∑ k, A_{i,k} v_k. This section
relates that sum to the linear-algebra operation: the abstract matrix-vector product
Matrix.mulVec of Mathlib, under the canonical conversion from the seq-matrix
representation to a Matrix (Fin m) (Fin p) R and from the coefficient List
to a Fin p → R vector.
This certifies the concrete matrix-vector product as Mathlib's Matrix.mulVec
under the canonical conversions — the data refinement carried up to the real
linear-algebra operation.
Convert a seq-matrix A : List (List R) to an abstract
Matrix (Fin m) (Fin p) R via the entry function.
Equations
- Transfer.Examples.CoqEAL.SeqMatrixMul.toMatrix A m p = Matrix.of fun (i : Fin m) (j : Fin p) => Transfer.Examples.CoqEAL.SeqMatrixMul.entry A ↑i ↑j
Instances For
Convert a coefficient List R to an abstract column vector Fin p → R.
Equations
- Transfer.Examples.CoqEAL.SeqMatrixMul.toVec v p j = v.getD (↑j) 0
Instances For
Matrix-vector refinement = Mathlib Matrix.mulVec. Under the canonical
seq-matrix → Matrix and List → Fin p → R conversions, the i-th entry
of the concrete matVec A v equals the abstract Matrix.mulVec of the
converted matrix applied to the converted vector — the data refinement carried
up to the real linear-algebra operation.