Polymorphic row-major runtime matrices (Cslib.RowTable) #
Cslib.RowTable α represents a dense matrix of runtime dimensions numRows × numCols stored in
row-major order as rows : List (List α). Out-of-bounds reads via RowTable.entry default to 0,
making RowTable.toMatrix total on arbitrary (possibly ragged) tables while forming a two-sided
equivalence with Matrix (Fin m) (Fin n) α on RowTable.WellFormed tables.
Main definitions #
Cslib.RowTable: explicit row-major matrix record(numRows, numCols, rows).Cslib.RowTable.WellFormed: rectangular shape predicate (rows.length = numRowsand each row has lengthnumCols).Cslib.RowTable.entry: total(i, j)lookup defaulting to0out of bounds.Cslib.RowTable.tabulate: build a well-formedm × nRowTable αfromg : ℕ → ℕ → α.Cslib.RowTable.toMatrix,Cslib.RowTable.ofMatrix: conversion betweenRowTable αandMatrix (Fin m) (Fin n) α.Cslib.RowTable.map: entrywise functorial map preserving dimensions andWellFormed.
Main results #
Cslib.RowTable.toMatrix_ofMatrix,Cslib.RowTable.ofMatrix_toMatrix: round-trip equivalence betweenMatrix (Fin m) (Fin n) αand well-formedRowTable α.Cslib.RowTable.toMatrix_map,Cslib.RowTable.map_ofMatrix:RowTable.mapcommutes withtoMatrix(for zero-preserving maps) andofMatrix.Cslib.RowTable.eq_of_wellFormed_of_entry_eq,Cslib.RowTable.tabulate_entry: extensionality and canonical re-tabulation of well-formed tables.
@[instance_reducible]
Rectangular shape invariant and functorial map #
@[instance_reducible]
theorem Cslib.RowTable.WellFormed.map {α : Type u_1} {β : Type u_2} {T : RowTable α} (hT : T.WellFormed) (f : α → β) :
(RowTable.map f T).WellFormed
map preserves WellFormed.
theorem Cslib.RowTable.wellFormed_tabulate {α : Type u_1} (m n : ℕ) (g : ℕ → ℕ → α) :
(tabulate m n g).WellFormed
Every tabulated m × n RowTable is WellFormed.
theorem Cslib.RowTable.wellFormed_ofMatrix {α : Type u_1} {m n : ℕ} (A : Matrix (Fin m) (Fin n) α) :
(ofMatrix A).WellFormed
ofMatrix A is always WellFormed.
theorem Cslib.RowTable.eq_of_wellFormed_of_entry_eq {α : Type u_1} [Zero α] {A B : RowTable α} (hA : A.WellFormed) (hB : B.WellFormed) (hr : A.numRows = B.numRows) (hc : A.numCols = B.numCols) (h : ∀ i < A.numRows, ∀ j < A.numCols, A.entry i j = B.entry i j) :
A = B
Two WellFormed tables of equal dimensions are equal when their in-bounds entries agree.
theorem Cslib.RowTable.tabulate_entry {α : Type u_1} [Zero α] {T : RowTable α} (hT : T.WellFormed) :
Re-tabulating a WellFormed table from entry recovers it unchanged.
theorem Cslib.RowTable.ofMatrix_toMatrix {α : Type u_1} [Zero α] {T : RowTable α} (hT : T.WellFormed) :
Converting a WellFormed table to a Matrix and back via ofMatrix recovers T.