Cost of the generic loop
ProvedNLogN.KFM.genLoop_costCost of the generic loop.
The following holds (Lean statement, in the scope of module Solutions.KFMS0):
theorem NLogN.KFM.genLoop_cost (i a : Fin HS) (n : Ex HS) (body : RS) (s : IState HS) (N : ℕ)
(G : ℕ → ℤ → ℤ) (a0 : ℤ) (La : List Item) (hia : i ≠ a) (hi56 : i.val < 56)
(hn : n.Clean) (hnok : n.ok s) (hN : n.eval s = N) (hw : i ∉ body.writes)
(ha : s.G a = .int a0 :: La)
(hb : ∀ k < N, body.ok (lpSt s i a La N k (accSeq G a0 k)) ∧
body.run (lpSt s i a La N k (accSeq G a0 k)) =
(lpSt s i a La N k (accSeq G a0 k)).upd a (.int (G k (accSeq G a0 k)) :: La))
(B C : ℕ) (hB : zsz (N : ℤ) ≤ B) (hB1 : 1 ≤ B) (hnB : n.Bnd s B)
(hbc : ∀ k < N, body.cost (lpSt s i a La N k (accSeq G a0 k)) ≤ C) :
(rep i n body).cost s ≤ (n.size + 1) * 10 ^ 7 * (B + 2) ^ 2 +
N * (C + 4 * 10 ^ 7 * (B + 2) ^ 2 + 30) + 32
Context. The lemma belongs to the part KFM S0: generic counted loops of register programs (RS.rep) for the setup arithmetic.
Formalization Note. This lemma belongs to the item-language (IL) layer of the integer-multiplication-kappa campaign: tape-level programs (register programs over 64 item stacks of the NLogN multitape framework, definition bundles IntMul_HvdH_M_Defs1–IntMul_HvdH_M_Defs8) that implement the data-movement primitives of the OpenAI preprint Integer multiplication below (field moves, row split/merge, shifts, the uniform Proposition 11 interchange, Lemma 12 with fine -per-element costs, Gaussian record primitives, Proposition 14 pieces) with exact list denotations from the array-model bundles IntMul_Kappa_K_Defs* and explicit cost bounds. All names refer to the definition bundles up to IntMul_Kappa_K_Defs22.
-- OpenAI-preprint / κ-improvement development (integer-multiplication-kappa), generated by skeleton subtraction. import Definitions.Def_IntMul_Kappa_K_Defs22 set_option autoImplicit false set_option relaxedAutoImplicit false set_option maxHeartbeats 1000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false set_option linter.unusedSectionVars false open NLogN open NLogN.KFM open IntMul RS
theorem NLogN.KFM.genLoop_cost (i a : Fin HS) (n : Ex HS) (body : RS) (s : IState HS) (N : ℕ)
(G : ℕ → ℤ → ℤ) (a0 : ℤ) (La : List Item) (hia : i ≠ a) (hi56 : i.val < 56)
(hn : n.Clean) (hnok : n.ok s) (hN : n.eval s = N) (hw : i ∉ body.writes)
(ha : s.G a = .int a0 :: La)
(hb : ∀ k < N, body.ok (lpSt s i a La N k (accSeq G a0 k)) ∧
body.run (lpSt s i a La N k (accSeq G a0 k)) =
(lpSt s i a La N k (accSeq G a0 k)).upd a (.int (G k (accSeq G a0 k)) :: La))
(B C : ℕ) (hB : zsz (N : ℤ) ≤ B) (hB1 : 1 ≤ B) (hnB : n.Bnd s B)
(hbc : ∀ k < N, body.cost (lpSt s i a La N k (accSeq G a0 k)) ≤ C) :
(rep i n body).cost s ≤ (n.size + 1) * 10 ^ 7 * (B + 2) ^ 2 +
N * (C + 4 * 10 ^ 7 * (B + 2) ^ 2 + 30) + 32 := by sorry