Documentation

CertifiedGaps.Trace.PackedHorner

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 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 #

Main results #

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.

  • mask : List ℕ

    The magnitudes of the band entries, row by row.

Instances For

    The column coupled to row k by the band.

    Equations
    Instances For

      A banded integer matrix: diagonal pos - neg, bands hops with nonpositive entries and bands phops with nonnegative entries.

      • pos : List ℕ

        The positive parts of the diagonal entries.

      • neg : List ℕ

        The negative parts of the diagonal entries.

      • hops : List Hop

        The off-diagonal bands with nonpositive entries -m_h(k).

      • phops : List Hop

        The off-diagonal bands with nonnegative entries m_h(k) (none for most matrices).

      Instances For

        (D x)_k = (p_k - q_k) x_k - ∑_{hops} m_h(k) x_{nb_h(k)} + ∑_{phops} m_h(k) x_{nb_h(k)}.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          The banded matrix on Fin d.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Every band stays inside {0, …, d - 1}: a nonzero entry in row k < d couples to a column < d.

            Equations
            Instances For
              def CertifiedGaps.Trace.Packed.extend {d : ℕ} (X : Fin d → ℤ) (n : ℕ) :

              A vector on Fin d, extended by zero to ℕ.

              Equations
              Instances For
                theorem CertifiedGaps.Trace.Packed.extend_fin {d : ℕ} (X : Fin d → ℤ) (k : Fin d) :
                extend X ↑k = X k
                theorem CertifiedGaps.Trace.Packed.Band.InRange.nb_lt {D : Band} {d : ℕ} (hD : D.InRange d) {h : Hop} (hh : h ∈ D.hops ++ D.phops) {k : ℕ} (hk : k < d) (hm : h.mask.getD k 0 ≠ 0) :
                h.nb k < d

                The neighbour of a row in range is in range.

                theorem CertifiedGaps.Trace.Packed.sum_ite_val_eq {d : ℕ} (X : Fin d → ℤ) (n : ℕ) (c : ℤ) :
                ∑ l : Fin d, (if ↑l = n then c else 0) * X l = c * extend X n

                Summing against the indicator of one index n picks extend X n.

                theorem CertifiedGaps.Trace.Packed.sum_list_sum_mul {d : ℕ} (L : List Hop) (g : Hop → Fin d → ℤ) (X : Fin d → ℤ) :
                ∑ l : Fin d, (List.map (fun (h : Hop) => g h l) L).sum * X l = (List.map (fun (h : Hop) => ∑ l : Fin d, g h l * X l) L).sum

                Exchanging a finite sum with the sum over a list.

                theorem CertifiedGaps.Trace.Packed.Band.matrix_mulVec (D : Band) {d : ℕ} (X : Fin d → ℤ) (k : Fin d) :
                (D.matrix d).mulVec X k = D.apply (extend X) ↑k

                The banded matrix acts by the band formula.

                theorem CertifiedGaps.Trace.Packed.Band.apply_congr {D : Band} {d : ℕ} (hD : D.InRange d) {x y : ℕ → ℤ} (hxy : ∀ n < d, x n = y n) {k : ℕ} (hk : k < d) :
                D.apply x k = D.apply y k

                Changing a vector away from {0, …, d - 1} does not change the band formula in a row k < d, when the bands stay in range.

                The column recursion #

                def CertifiedGaps.Trace.Packed.specStep (D : Band) (s r : ℕ) (t : ℤ) (x : ℕ → ℤ) :
                ℕ → ℤ

                One step of column r of the integer Horner recursion: x ↦ ⌊D x / s⌋ + t e_r.

                Equations
                Instances For
                  def CertifiedGaps.Trace.Packed.specCol (D : Band) (s r : ℕ) (cs : List ℤ) :
                  ℕ → ℤ

                  Column r of the integer Horner recursion with coefficients cs (last one first).

                  Equations
                  Instances For
                    theorem CertifiedGaps.Trace.Packed.hornerList_eq_specCol {D : Band} {d : ℕ} (hD : D.InRange d) (s : ℕ) (r : Fin d) (cs : List ℤ) (k : Fin d) :
                    hornerList (D.matrix d) s r cs k = specCol D s (↑r) cs ↑k

                    The column recursion is hornerList of the banded matrix.

                    theorem CertifiedGaps.Trace.Packed.hornerFloor_eq_specCol {D : Band} {d : ℕ} (hD : D.InRange d) (s : ℕ) (c : ℕ → ℤ) (r : Fin d) (K : ℕ) (k : Fin d) :
                    hornerFloor (D.matrix d) s c r K k = specCol D s (↑r) (List.map c (List.range (K + 1))) ↑k

                    hornerFloor of the banded matrix in terms of the column recursion.

                    theorem CertifiedGaps.Trace.Packed.hornerList_submatrix {ι : Type u_1} {κ : Type u_2} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] (M : Matrix κ κ ℤ) (e : ι ≃ κ) (s : ℕ) (r : ι) (l : List ℤ) (w : ι) :
                    hornerList (M.submatrix ⇑e ⇑e) s r l w = hornerList M s (e r) l (e w)

                    hornerList commutes with relabelling the index set.

                    theorem CertifiedGaps.Trace.Packed.hornerFloor_submatrix {ι : Type u_1} {κ : Type u_2} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] (M : Matrix κ κ ℤ) (e : ι ≃ κ) (s : ℕ) (c : ℕ → ℤ) (r : ι) (K : ℕ) (w : ι) :
                    hornerFloor (M.submatrix ⇑e ⇑e) s c r K w = hornerFloor M s c (e r) K (e w)

                    hornerFloor commutes with relabelling the index set.

                    List helpers #

                    a + m y, entrywise.

                    Equations
                    Instances For

                      The rows coupled by a band: entry k is row nb k (zero outside the list).

                      Equations
                      Instances For
                        theorem CertifiedGaps.Trace.Packed.getD_axpy (a m y : List ℕ) (k : ℕ) :
                        k < a.length → k < m.length → k < y.length → (axpy a m y).getD k 0 = a.getD k 0 + m.getD k 0 * y.getD k 0
                        theorem CertifiedGaps.Trace.Packed.getD_mulList (m y : List ℕ) (k : ℕ) :
                        k < m.length → k < y.length → (mulList m y).getD k 0 = m.getD k 0 * y.getD k 0
                        theorem CertifiedGaps.Trace.Packed.mask_mul_getD_shift {d : ℕ} {h : Hop} (ys : List ℕ) (hys : ys.length = d) {k : ℕ} (hr : h.mask.getD k 0 ≠ 0 → (h.up = true → k + h.off < d) ∧ (h.up = false → h.off ≤ k)) :
                        h.mask.getD k 0 * (h.shift ys).getD k 0 = h.mask.getD k 0 * ys.getD (h.nb k) 0

                        The shifted list holds the neighbouring rows wherever the band entry is nonzero.

                        The accumulated nonpositive band products q_k y_k + ∑_{hops} m_h(k) y_{nb_h(k)} of all rows.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          The accumulated nonnegative products p_k y_k + ∑_{phops} m_h(k) y_{nb_h(k)} of all rows.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem CertifiedGaps.Trace.Packed.foldl_axpy_spec (ys : List ℕ) (L : List Hop) (acc : List ℕ) :
                            (∀ h ∈ L, acc.length ≤ h.mask.length) → acc.length ≤ ys.length → (List.foldl (fun (acc : List ℕ) (h : Hop) => axpy acc h.mask (h.shift ys)) acc L).length = acc.length ∧ ∀ k < acc.length, (List.foldl (fun (acc : List ℕ) (h : Hop) => axpy acc h.mask (h.shift ys)) acc L).getD k 0 = acc.getD k 0 + (List.map (fun (h : Hop) => h.mask.getD k 0 * (h.shift ys).getD k 0) L).sum

                            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 s of the recursion X ← ⌊D X / s⌋ + t I.

                            • S : ℕ

                              The shift of the magic division.

                            • M : ℕ

                              The multiplier of the magic division.

                            Instances For

                              The bias B = 2^b.

                              Equations
                              Instances For

                                Entries stay in [-2^(b-1), 2^(b-1)).

                                Equations
                                Instances For

                                  The arithmetic conditions under which no lane overflows and the magic division is exact for lanes up to 2 s B.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem CertifiedGaps.Trace.Packed.magic_div {s S M U u : ℕ} (hs : 0 < s) (h1 : 2 ^ S ≤ M * s) (h2 : U * (M * s - 2 ^ S) < 2 ^ S) (hu : u ≤ U) :
                                    u * M / 2 ^ S = u / s

                                    Floor division by a magic multiplication: ⌊u M / 2^S⌋ = ⌊u / s⌋ for u ≤ U when M s ≥ 2^S and U (M s - 2^S) < 2^S.

                                    theorem CertifiedGaps.Trace.Packed.pack_list_sum {w d : ℕ} {α : Type u_1} (L : List α) (f : α → ℕ → ℕ) :
                                    (pack w d fun (r : ℕ) => (List.map (fun (a : α) => f a r) L).sum) = (List.map (fun (a : α) => pack w d (f a)) L).sum

                                    The packed sum over a list.

                                    One step of the packed recursion #

                                    def CertifiedGaps.Trace.Packed.rowVal (P : Params) (LM tk a c b : ℕ) :

                                    The new row: ⌊(a + c - b) / s⌋ lane by lane (by the magic division), plus the identity term tk. Here a packs the diagonal and nonnegative band products, b the nonpositive ones, and a + c - b holds (D X)_k + s B in every lane.

                                    Equations
                                    Instances For
                                      def CertifiedGaps.Trace.Packed.idTerm (P : Params) (t col₀ nc k : ℕ) :

                                      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
                                        def CertifiedGaps.Trace.Packed.finish (P : Params) (LM HM T hR t : ℕ) :
                                        List ℕ → List ℕ → List ℕ → List ℕ → Option (List ℕ)

                                        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
                                        Instances For
                                          theorem CertifiedGaps.Trace.Packed.finish_spec (P : Params) (LM HM T hR t : ℕ) (es cs as bs out : List ℕ) :
                                          finish P LM HM T hR t es cs as bs = some out → out.length = min (min (min es.length cs.length) as.length) bs.length ∧ ∀ i < out.length, out.getD i 0 = rowVal P LM (t * es.getD i 0) (as.getD i 0) (cs.getD i 0) (bs.getD i 0) ∧ rowVal P LM (t * es.getD i 0) (as.getD i 0) (cs.getD i 0) (bs.getD i 0) + hR &&& HM = T

                                          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
                                            def CertifiedGaps.Trace.Packed.Inv (P : Params) (d nc : ℕ) (col : ℕ → ℕ) (ys : List ℕ) (x : ℕ → ℕ → ℤ) :

                                            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
                                              def CertifiedGaps.Trace.Packed.UnitsOk (P : Params) (d nc : ℕ) (col : ℕ → ℕ) (E : List ℕ) :

                                              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
                                                def CertifiedGaps.Trace.Packed.step (P : Params) (D : Band) (cstP E : List ℕ) (LM HM T hR t : ℕ) (ys : List ℕ) :

                                                One step of the packed recursion, all columns at once.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  theorem CertifiedGaps.Trace.Packed.length_foldl_axpy {d : ℕ} {ys : List ℕ} {L : List Hop} (hm : ∀ h ∈ L, h.mask.length = d) {p : List ℕ} (hp : p.length = d) (hy : ys.length = d) :
                                                  (List.foldl (fun (acc : List ℕ) (h : Hop) => axpy acc h.mask (h.shift ys)) (mulList p ys) L).length = d

                                                  The accumulated band products over a diagonal have one entry per row.

                                                  theorem CertifiedGaps.Trace.Packed.getD_foldl_axpy {P : Params} {D : Band} {d nc : ℕ} {col : ℕ → ℕ} {x : ℕ → ℕ → ℤ} {ys : List ℕ} (hD : D.InRange d) (hinv : Inv P d nc col ys x) {L : List Hop} (hL : ∀ h ∈ L, h ∈ D.hops ++ D.phops) (hm : ∀ h ∈ L, h.mask.length = d) {p : List ℕ} (hp : p.length = d) {k : ℕ} (hk : k < d) :
                                                  (List.foldl (fun (acc : List ℕ) (h : Hop) => axpy acc h.mask (h.shift ys)) (mulList p ys) L).getD k 0 = pack P.w nc fun (r : ℕ) => p.getD k 0 * (x (col r) k + ↑P.B).toNat + (List.map (fun (h : Hop) => h.mask.getD k 0 * (x (col r) (h.nb k) + ↑P.B).toNat) L).sum

                                                  The accumulated band products of row k, lane by lane.

                                                  theorem CertifiedGaps.Trace.Packed.bandSum_spec {P : Params} {D : Band} {d : ℕ} (hD : D.InRange d) (hb : 1 ≤ P.b) {y : ℕ → ℤ} (hbd : ∀ n < d, -↑P.half ≤ y n ∧ y n < ↑P.half) {k : ℕ} (hk : k < d) (L : List Hop) :
                                                  (∀ h ∈ L, h ∈ D.hops ++ D.phops) → ↑(List.map (fun (h : Hop) => h.mask.getD k 0 * (y (h.nb k) + ↑P.B).toNat) L).sum = (List.map (fun (h : Hop) => ↑(h.mask.getD k 0) * y (h.nb k)) L).sum + ↑P.B * ↑(List.map (fun (h : Hop) => h.mask.getD k 0) L).sum ∧ |(List.map (fun (h : Hop) => ↑(h.mask.getD k 0) * y (h.nb k)) L).sum| ≤ ↑(List.map (fun (h : Hop) => h.mask.getD k 0) L).sum * ↑P.half

                                                  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.

                                                  theorem CertifiedGaps.Trace.Packed.lane_identity {P : Params} {D : Band} {d : ℕ} {cst : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) {y : ℕ → ℤ} (hbd : ∀ n < d, -↑P.half ≤ y n ∧ y n < ↑P.half) {k : ℕ} (hk : k < d) :
                                                  have pos := D.pos.getD k 0 * (y k + ↑P.B).toNat + (List.map (fun (h : Hop) => h.mask.getD k 0 * (y (h.nb k) + ↑P.B).toNat) D.phops).sum + cst.getD k 0; have neg := D.neg.getD k 0 * (y k + ↑P.B).toNat + (List.map (fun (h : Hop) => h.mask.getD k 0 * (y (h.nb k) + ↑P.B).toNat) D.hops).sum; neg ≤ pos ∧ ↑(pos - neg) = D.apply y k + ↑P.s * ↑P.B ∧ pos - neg ≤ 2 * P.s * P.B

                                                  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].

                                                  theorem CertifiedGaps.Trace.Packed.idTerm_eq (P : Params) (t col₀ nc k : ℕ) :
                                                  idTerm P t col₀ nc k = pack P.w nc fun (r : ℕ) => if col₀ + r = k then t else 0

                                                  The identity term of row k is the packed vector with t in the lane of column k.

                                                  theorem CertifiedGaps.Trace.Packed.step_spec {P : Params} {D : Band} {d nc : ℕ} {col : ℕ → ℕ} {cst : List ℕ} {x : ℕ → ℕ → ℤ} {ys : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) {E : List ℕ} (hE : UnitsOk P d nc col E) {t : ℕ} (ht : t ≤ P.B) (hinv : Inv P d nc col ys x) {ys' : List ℕ} (h : step P D (List.map (fun (x : ℕ) => x * repunit P.w nc) cst) E ((2 ^ (P.w - P.S) - 1) * repunit P.w nc) ((2 ^ P.w - 2 ^ P.b) * repunit P.w nc) (2 ^ P.b * repunit P.w nc) (P.half * repunit P.w nc) t ys = some ys') :
                                                  Inv P d nc col ys' fun (c k : ℕ) => specStep D P.s c (↑t) (x c) k

                                                  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 #

                                                  def CertifiedGaps.Trace.Packed.runCols (P : Params) (D : Band) (cst : List ℕ) (d : ℕ) (E : List ℕ) (nc : ℕ) (cs : List ℕ) :

                                                  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
                                                    theorem CertifiedGaps.Trace.Packed.runCols_spec {P : Params} {D : Band} {d nc : ℕ} {col : ℕ → ℕ} {cst E : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) (hE : UnitsOk P d nc col E) (cs : List ℕ) :
                                                    (∀ t ∈ cs, t ≤ P.B) → ∀ {ys : List ℕ}, runCols P D cst d E nc cs = some ys → Inv P d nc col ys fun (c k : ℕ) => specCol D P.s c (List.map Nat.cast cs) k

                                                    Correctness of the packed recursion. If it succeeds, row k packs the lanes specCol D s (col r) cs k + B of the columns.

                                                    theorem CertifiedGaps.Trace.Packed.runCols_lane {P : Params} {D : Band} {d nc : ℕ} {col : ℕ → ℕ} {cst E : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) (hE : UnitsOk P d nc col E) {cs : List ℕ} (hcs : ∀ t ∈ cs, t ≤ P.B) {ys : List ℕ} (h : runCols P D cst d E nc cs = some ys) {k r : ℕ} (hk : k < d) (hr : r < nc) :
                                                    ↑(ys.getD k 0 >>> (P.w * r) % 2 ^ P.w) - ↑P.B = specCol D P.s (col r) (List.map Nat.cast cs) k

                                                    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
                                                    Instances For
                                                      theorem CertifiedGaps.Trace.Packed.windowUnits_ok (P : Params) (d col₀ nc : ℕ) :
                                                      UnitsOk P d nc (fun (x : ℕ) => col₀ + x) (windowUnits P d col₀ nc)

                                                      The window units are the units of the columns col₀ + r.

                                                      def CertifiedGaps.Trace.Packed.run (P : Params) (D : Band) (cst : List ℕ) (d col₀ nc : ℕ) (cs : List ℕ) :

                                                      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
                                                      Instances For
                                                        theorem CertifiedGaps.Trace.Packed.run_spec {P : Params} {D : Band} {d col₀ nc : ℕ} {cst : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) (cs : List ℕ) (hcs : ∀ t ∈ cs, t ≤ P.B) {ys : List ℕ} (h : run P D cst d col₀ nc cs = some ys) :
                                                        Inv P d nc (fun (x : ℕ) => col₀ + x) ys fun (c k : ℕ) => specCol D P.s c (List.map Nat.cast cs) k

                                                        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.

                                                        theorem CertifiedGaps.Trace.Packed.run_lane {P : Params} {D : Band} {d col₀ nc : ℕ} {cst : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) {cs : List ℕ} (hcs : ∀ t ∈ cs, t ≤ P.B) {ys : List ℕ} (h : run P D cst d col₀ nc cs = some ys) {k r : ℕ} (hk : k < d) (hr : r < nc) :
                                                        ↑(ys.getD k 0 >>> (P.w * r) % 2 ^ P.w) - ↑P.B = specCol D P.s (col₀ + r) (List.map Nat.cast cs) k

                                                        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
                                                          Instances For
                                                            theorem CertifiedGaps.Trace.Packed.laneSq_eq (P : Params) (v : List ℕ) (y : ℕ) :
                                                            laneSq P y v = ∑ r ∈ Finset.range v.length, v.getD r 0 * (↑(y >>> (P.w * r) % 2 ^ P.w) - ↑P.B).natAbs ^ 2
                                                            theorem CertifiedGaps.Trace.Packed.sum_zipWith_eq {f : ℕ → ℕ → ℕ} (u ys : List ℕ) (d : ℕ) :
                                                            u.length = d → ys.length = d → (List.zipWith f u ys).sum = ∑ k ∈ Finset.range d, f (u.getD k 0) (ys.getD k 0)
                                                            theorem CertifiedGaps.Trace.Packed.runCols_numerator {P : Params} {D : Band} {d nc : ℕ} {col : ℕ → ℕ} {cst E : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) (hE : UnitsOk P d nc col E) {cs : List ℕ} (hcs : ∀ t ∈ cs, t ≤ P.B) {ys : List ℕ} (h : runCols P D cst d E nc cs = some ys) {u v : List ℕ} (hu : u.length = d) (hv : v.length = nc) :
                                                            ↑(numerator P u v ys) = ∑ k ∈ Finset.range d, ∑ r ∈ Finset.range nc, ↑(u.getD k 0) * ↑(v.getD r 0) * specCol D P.s (col r) (List.map Nat.cast cs) k ^ 2

                                                            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}².

                                                            theorem CertifiedGaps.Trace.Packed.run_numerator {P : Params} {D : Band} {d col₀ nc : ℕ} {cst : List ℕ} (hP : P.Ok) (hD : D.InRange d) (hR : D.RowsOk P cst d) {cs : List ℕ} (hcs : ∀ t ∈ cs, t ≤ P.B) {ys : List ℕ} (h : run P D cst d col₀ nc cs = some ys) {u v : List ℕ} (hu : u.length = d) (hv : v.length = nc) :
                                                            ↑(numerator P u v ys) = ∑ k ∈ Finset.range d, ∑ r ∈ Finset.range nc, ↑(u.getD k 0) * ↑(v.getD r 0) * specCol D P.s (col₀ + r) (List.map Nat.cast cs) k ^ 2

                                                            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
                                                            Instances For

                                                              The row sums ∑_h m_h(k) of the band entries.

                                                              Equations
                                                              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 range condition of one band, along its list of entries from row k.

                                                                  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
                                                                      theorem CertifiedGaps.Trace.Packed.getD_addList (a b : List ℕ) (k : ℕ) :
                                                                      k < a.length → k < b.length → (addList a b).getD k 0 = a.getD k 0 + b.getD k 0
                                                                      theorem CertifiedGaps.Trace.Packed.maskSums_spec (d : ℕ) (L : List Hop) (acc : List ℕ) :
                                                                      acc.length = d → (∀ h ∈ L, h.mask.length = d) → (List.foldl (fun (acc : List ℕ) (h : Hop) => addList acc h.mask) acc L).length = d ∧ ∀ k < d, (List.foldl (fun (acc : List ℕ) (h : Hop) => addList acc h.mask) acc L).getD k 0 = acc.getD k 0 + (List.map (fun (h : Hop) => h.mask.getD k 0) L).sum
                                                                      theorem CertifiedGaps.Trace.Packed.rowCheck_spec (P : Params) (ps qs cs ms ms' : List ℕ) :
                                                                      rowCheck P ps qs cs ms ms' = true → qs.length = ps.length ∧ cs.length = ps.length ∧ ms.length = ps.length ∧ ms'.length = ps.length ∧ ∀ k < ps.length, ps.getD k 0 + qs.getD k 0 + ms.getD k 0 + ms'.getD k 0 ≤ 2 * P.s ∧ cs.getD k 0 + P.B * (ps.getD k 0 + ms'.getD k 0) = P.B * (P.s + qs.getD k 0 + ms.getD k 0)
                                                                      theorem CertifiedGaps.Trace.Packed.hopCheck_spec (up : Bool) (off d k₀ : ℕ) (ms : List ℕ) :
                                                                      hopCheck up off d k₀ ms = true → ∀ i < ms.length, ms.getD i 0 ≠ 0 → (up = true → k₀ + i + off < d) ∧ (up = false → off ≤ k₀ + i)

                                                                      The constants c_k = B (s + q_k + m_k - p_k - m'_k) of Band.RowsOk, along the lists.

                                                                      Equations
                                                                      Instances For
                                                                        theorem CertifiedGaps.Trace.Packed.Band.check_spec {D : Band} {P : Params} {cst : List ℕ} {d : ℕ} (h : D.check P cst d = true) :
                                                                        D.InRange d ∧ D.RowsOk P cst d

                                                                        The Boolean check gives the band conditions.