Integer Horner recursions of banded matrices, all columns at once #
The integer Horner recursion X ← ⌊D X / s⌋ + t I of Trace/Horner.lean (hornerFloor, one
column per call) is evaluated here for many columns simultaneously, for a banded integer
matrix D on {0, …, d - 1}:
(D x)_k = (p_k - q_k) x_k - ∑_{h ∈ hops} m_h(k) x_{k ± o_h} + ∑_{h ∈ phops} m_h(k) x_{k ± o_h},
with diagonal p - q (p, q ≥ 0) and off-diagonal bands h (a Hop) of offset o_h, with
nonpositive entries -m_h(k) (hops) or nonnegative entries m_h(k) (phops). Row k of the
matrix X of computed columns is stored as one packed number (Trace/PackedLanes.lean) with
lane r holding X_{k, col r} + B, B = 2^b. Then
- the product
D Xneeds one scalar multiple per band and row: the bandhofD Xin rowkism_h(k)times rowk ± o_h(negAcc,posAcc, built from shifted lists of rows); - the floor division by
sis one multiplication by a magic constantM, one shift and one mask per row (magic_div,pack_shiftRight_and); - the identity term adds
tto lanerof rowcol r(ttimes the unit listE); - one
&&&test per row checks that every new entry lies in[-2^(b-1), 2^(b-1))(lanes_mem_of_and_eq); the biasBand the lane width are chosen so that no lane overflows as long as these tests pass.
The lanes of a row are the columns col 0, …, col (nc - 1) of X, any list of distinct
columns, described by the unit list E with E_k = ∑_{col r = k} 2^(w r) (UnitsOk; runCols).
run is the window of nc consecutive columns col₀, …, col₀ + nc - 1; the whole matrix is the
window col₀ = 0, nc = d. Both return none as soon as a test fails. runCols_spec proves
that if the recursion returns some ys, then lane r of row k is
hornerFloor D s t (col r) K k + B for every k < d, r < nc (through the column recursion
specCol), so that decide +kernel on a packed run certifies all columns of hornerFloor with
a number of kernel steps proportional to d K instead of d² K. The kernel keeps every
intermediate packed row until the end of a declaration, so the memory of a check grows like the
number of kernel steps (about 10 GB for d = 243, K = 192).
Main definitions #
Hop,Band: the banded matrix, andBand.matrixitsFin d × Fin dinteger matrix.Params: lane widthw, bias exponentb, scales, magic shiftSand multiplierM.runCols,run: the packed recursion on a list of columns and on a window;numerator:∑_k u_k ∑_r v_r (lane_r - B)²over the rows.Band.check: the conditions on the band data as one Boolean, linear in the data.
Main results #
Band.matrix_mulVec: the matrix acts by the band formula;hornerFloor_eq_specCol.runCols_spec,runCols_lane,run_spec,run_lane: the packed recursion computeshornerFloorofBand.matrix.runCols_numerator,run_numerator: the weighted sums of squares of the computed columns.hornerFloor_submatrix: relabelling the index set.
Banded matrices #
One band of a banded matrix: row k couples to row k + off (up) or k - off, with the
entry -(mask k) (a band of Band.hops) or mask k (a band of Band.phops).
- up : Bool
Whether the band lies above the diagonal.
- off : ℕ
The distance of the band from the diagonal.
The magnitudes of the band entries, row by row.
Instances For
A banded integer matrix: diagonal pos - neg, bands hops with nonpositive entries and
bands phops with nonnegative entries.
The positive parts of the diagonal entries.
The negative parts of the diagonal entries.
The off-diagonal bands with nonpositive entries
-m_h(k).The off-diagonal bands with nonnegative entries
m_h(k)(none for most matrices).
Instances For
Every band stays inside {0, …, d - 1}: a nonzero entry in row k < d couples to a
column < d.
Equations
Instances For
The column recursion #
Column r of the integer Horner recursion with coefficients cs (last one first).
Equations
- CertifiedGaps.Trace.Packed.specCol D s r cs = List.foldr (CertifiedGaps.Trace.Packed.specStep D s r) 0 cs
Instances For
hornerList commutes with relabelling the index set.
hornerFloor commutes with relabelling the index set.
List helpers #
m y, entrywise.
Equations
- CertifiedGaps.Trace.Packed.mulList (m :: ms) (y :: ys) = m * y :: CertifiedGaps.Trace.Packed.mulList ms ys
- CertifiedGaps.Trace.Packed.mulList x✝¹ x✝ = []
Instances For
Lanes of the band products #
The packed recursion's parameters: lane width w, bias B = 2^b, scale s, and the magic
shift S and multiplier M for the floor division by s.
- w : ℕ
The lane width.
- b : ℕ
The bias exponent: lanes hold
x + 2^b. - s : ℕ
The scale
sof the recursionX ← ⌊D X / s⌋ + t I. - S : ℕ
The shift of the magic division.
- M : ℕ
The multiplier of the magic division.
Instances For
Equations
One step of the packed recursion #
The identity term t e_k of row k in the window of columns col₀, …, col₀ + nc - 1:
t in lane k - col₀ if column k is in the window, else zero.
Equations
Instances For
The new rows, row 0 first, from the units E, the constants and the two accumulated band
products; none as soon as one row fails the range test (v + hR) &&& HM = T.
Equations
- One or more equations did not get rendered due to their size.
- CertifiedGaps.Trace.Packed.finish P LM HM T hR t x✝³ x✝² x✝¹ x✝ = some []
Instances For
The row conditions, checked once per matrix: list lengths, absolute row sums at most 2 s,
and the constants c_k = B (s - p_k + q_k + ∑_{hops} m_h(k) - ∑_{phops} m_h(k)) that make every
lane of a + c - b equal to (D X)_k + s B.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of the packed recursion on the columns col 0, …, col (nc - 1): row k
packs the lanes x (col r) k + B, and every entry lies in [-2^(b-1), 2^(b-1)).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The units of the columns col 0, …, col (nc - 1): E_k has a 1 in every lane r with
col r = k, so that t E_k is the identity term of row k.
Equations
Instances For
The accumulated band products of row k, lane by lane.
A band sum of biased lanes: cast to ℤ, the biases separate, and the unbiased sum is at
most (∑ m) 2^(b-1) in absolute value.
One lane of one row. If every entry of the column y lies in [-2^(b-1), 2^(b-1)),
the lane of the diagonal and nonnegative band products plus c dominates that of the
nonpositive band products, and their difference is (D y)_k + s B ∈ [0, 2 s B].
One step of the packed recursion. If the rows of ys pack the columns x (col r) and
the step succeeds, the new rows pack the columns specStep D s (col r) t (x (col r)), with all
entries in range.
The packed recursion #
The packed Horner recursion on a list of columns. The columns col 0, …, col (nc - 1)
of X ← ⌊D X / s⌋ + t I (coefficients cs, last one first, from X = 0), given by their units
E (UnitsOk), row k packed with lanes X_{k, col r} + B; none if a range test fails.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Correctness of the packed recursion. If it succeeds, row k packs the lanes
specCol D s (col r) cs k + B of the columns.
Lane r of row k of a successful packed run, as an integer: entry (k, col r) of the
recursion.
The units of the window of columns col₀, …, col₀ + nc - 1.
Equations
- CertifiedGaps.Trace.Packed.windowUnits P d col₀ nc = List.map (CertifiedGaps.Trace.Packed.idTerm P 1 col₀ nc) (List.range d)
Instances For
The window units are the units of the columns col₀ + r.
The packed Horner recursion on a window. The columns col₀, …, col₀ + nc - 1 of
X ← ⌊D X / s⌋ + t I (coefficients cs, last one first, from X = 0), row k packed with
lanes X_{k, col₀ + r} + B; none if a range test fails.
Equations
- CertifiedGaps.Trace.Packed.run P D cst d col₀ nc cs = CertifiedGaps.Trace.Packed.runCols P D cst d (CertifiedGaps.Trace.Packed.windowUnits P d col₀ nc) nc cs
Instances For
Correctness of the packed recursion on a window. If it succeeds, row k packs the
lanes specCol D s (col₀ + r) cs k + B of the columns of the window.
Lane r of row k of a successful packed run, as an integer: entry (k, col₀ + r) of the
recursion.
Weighted sums of squares of the computed columns #
∑_r v_r (lane_r(y) - B)² over the lanes of one packed row, peeling one lane at a time.
Equations
Instances For
∑_k u_k ∑_r v_r (X_{k r})² over the rows of a packed run.
Equations
- CertifiedGaps.Trace.Packed.numerator P u v ys = (List.zipWith (fun (uk y : ℕ) => uk * CertifiedGaps.Trace.Packed.laneSq P y v) u ys).sum
Instances For
The weighted sum of squares of the computed columns, from a successful packed run:
∑_k u_k ∑_{r < nc} v_r X_{k, col r}².
The weighted sum of squares of the columns of a window, from a successful packed run:
∑_k u_k ∑_{r < nc} v_r X_{k, col₀ + r}².
A linear-time check of the band conditions #
Entrywise sum of two lists (truncated to the shorter one).
Equations
- CertifiedGaps.Trace.Packed.addList (m :: ms) (y :: ys) = (m + y) :: CertifiedGaps.Trace.Packed.addList ms ys
- CertifiedGaps.Trace.Packed.addList x✝¹ x✝ = []
Instances For
The row sums ∑_h m_h(k) of the band entries.
Equations
- CertifiedGaps.Trace.Packed.maskSums d hops = List.foldl (fun (acc : List ℕ) (h : CertifiedGaps.Trace.Packed.Hop) => CertifiedGaps.Trace.Packed.addList acc h.mask) (List.replicate d 0) hops
Instances For
The row conditions of Band.RowsOk, row by row along the lists: diagonal parts p, q,
constants c, and the row sums m, m' of the nonpositive and nonnegative bands.
Equations
Instances For
The band conditions as one Boolean, evaluated in time linear in the number of entries:
list lengths, Band.InRange and Band.RowsOk.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The constants c_k = B (s + q_k + m_k - p_k - m'_k) of Band.RowsOk, along the lists.
Equations
Instances For
The constants of Band.RowsOk for a band.
Equations
- D.cst P d = CertifiedGaps.Trace.Packed.cstOf P D.pos D.neg (CertifiedGaps.Trace.Packed.maskSums d D.hops) (CertifiedGaps.Trace.Packed.maskSums d D.phops)