NLA-lib Explorer

NLAlib.Ops.ScalarProducts.sum_writes_word

Library · theorem

The streamed loop returns the actual machine sum, using only the declared accumulator and temporary. Inputs can share a buffer or repeat words; their accessed cells stay outside the two-cell write footprint. Empty products return literal zero. Shared by the trees of NLAlib.HutchPlusPlus.projectProbes, NLAlib.HutchPlusPlus.accumulate, NLAlib.CGS2.cgs2ExtendFinish and 17 more.

NLAlib.Ops.ScalarProducts.sum_writes_word {Op Tst : Type} [Ops.Has Ops.ScalarOp Op] {K : Type}
  {M : Ops.Machine K} {I : Ops.Interp Op Tst K} {tape : Ops.Tape K} {m : Ops.Mem K}
  (hS : Ops.IsScalar M I) {n sx sy : ℕ} {x y t out : ℕ × ℕ} (xs ys : ℕ → K)
  (hl : m.Live [x, y, t, out]) (hX : ∀ j < n, m.store.readBlock x.1 (x.2 + sx * j) 1 = some [xs j])
  (hY : ∀ j < n, m.store.readBlock y.1 (y.2 + sy * j) 1 = some [ys j])
  (hDX :
    ∀ j < n,
      (Ops.Store.inBlock t.1 t.2 1 ⊔ Ops.Store.inBlock out.1 out.2 1).Disj
        (Ops.Store.inBlock x.1 (x.2 + sx * j) 1))
  (hDY :
    ∀ j < n,
      (Ops.Store.inBlock t.1 t.2 1 ⊔ Ops.Store.inBlock out.1 out.2 1).Disj
        (Ops.Store.inBlock y.1 (y.2 + sy * j) 1))
  (hTO : Ops.Fp.Disj (Ops.Store.inBlock t.1 t.2 1) (Ops.Store.inBlock out.1 out.2 1))
  (ht : t.2 + 1 ≤ m.store.len t.1) (ho : out.2 + 1 ≤ m.store.len out.1) :
  Ops.Writes Ops.Mode.total I tape Ops.ScalarProducts.sum (Ops.Env.frame [n, sx, sy] [x, y, t, out])
    (Ops.Store.inBlock t.1 t.2 1 ⊔ Ops.Store.inBlock out.1 out.2 1)
    (fun m' ↦
      m'.pos = m.pos ∧
        m'.store.readBlock out.1 out.2 1 = some [Ops.ScalarProducts.sumWord M xs ys n])
    m

Full source on GitHub

Import NLAlib.Ops.Blas.ScalarProducts.