NLA-lib Explorer

NLAlib.Ops.writes_fillRel₂

Library · theorem

The two loops that fill a matrix with values known only by a relation, by columns in the layout L (a matrix stored by rows is the layout of its transpose).

NLAlib.Ops.writes_fillRel₂ {Op Tst K : Type} {md : Ops.Mode} {I : Ops.Interp Op Tst K}
  {τ : Ops.Tape K} {ρ : Ops.Env} {m : Ops.Mem K} [Nonempty K] {n₁ n₂ : Ops.IExp}
  {body : Ops.Stmt Op Tst} (L : Ops.MatLayout) (hL : L.Valid)
  (hn₁ : Ops.IExp.eval ρ.idx n₁ = some L.cols)
  (hn₂ : ∀ (j : ℕ), Ops.IExp.eval (ρ.pushIdx j).idx n₂ = some L.rows) (R : ℕ → ℕ → K → Prop)
  (pos : ℕ → ℕ) (hpos : m.pos = pos 0)
  (hstep :
    ∀ j < L.cols,
      ∀ i < L.rows,
        ∀ (m' : Ops.Mem K),
          Ops.Store.EqOff (L.upto j i) m.store m'.store →
            (∃ A,
                m'.store.HoldsMatUpto L A j i ∧
                  (∀ i' < L.rows, ∀ j' < j, R i' j' (A i' j')) ∧ ∀ i' < i, R i' j (A i' j)) →
              m'.pos = pos (j * L.rows + i) →
                Ops.Writes md I τ body ((ρ.pushIdx j).pushIdx i)
                  (Ops.Store.inBlock L.buf (L.cell i j) 1)
                  (fun m'' ↦
                    (∃ x, m''.store.get L.buf (L.cell i j) = some x ∧ R i j x) ∧
                      m''.pos = pos (j * L.rows + i + 1))
                  m') :
  Ops.Writes md I τ (Ops.Stmt.loop n₁ (Ops.Stmt.loop n₂ body)) ρ L.fp
    (fun m' ↦
      (∃ A, m'.store.HoldsMat L A ∧ ∀ i < L.rows, ∀ j < L.cols, R i j (A i j)) ∧
        m'.pos = pos (L.cols * L.rows))
    m

Full source on GitHub

Import NLAlib.Ops.Logic.Loop.