cntP_run (KFM S2: counting loops with an expression test, and products)
ProvedNLogN.KFM.cntP_runThe following holds (Lean statement, in the scope of module Solutions.KFMS2):
theorem NLogN.KFM.cntP_run (n tst : Ex HS) (rd : Fin HS) (P : ℕ → Prop) [DecidablePred P] (s : IState HS)
(N : ℕ) (hd56 : rd.val < 56) (hdI : rd ≠ NLogN.KFM.sI) (hn : n.Clean) (hnd : rd ∉ n.regs)
(hnok : n.ok s) (hN : n.eval s = N) (ht : tst.Clean) (htd : rd ∉ tst.regs)
(htst : ∀ x, 1 ≤ x → x ≤ N → tst.ok (xSt s x) ∧ (tst.eval (xSt s x) < 0 ↔ P x)) :
(cntP n tst rd).ok s ∧ (cntP n tst rd).run s =
s.upd rd (.int (∑ x ∈ Finset.Icc 1 N, if P x then (1 : ℤ) else 0) :: s.G rd)
Context. The lemma belongs to the part KFM S2: counting loops with an expression test, and products.
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.cntP_run (n tst : Ex HS) (rd : Fin HS) (P : ℕ → Prop) [DecidablePred P] (s : IState HS)
(N : ℕ) (hd56 : rd.val < 56) (hdI : rd ≠ NLogN.KFM.sI) (hn : n.Clean) (hnd : rd ∉ n.regs)
(hnok : n.ok s) (hN : n.eval s = N) (ht : tst.Clean) (htd : rd ∉ tst.regs)
(htst : ∀ x, 1 ≤ x → x ≤ N → tst.ok (xSt s x) ∧ (tst.eval (xSt s x) < 0 ↔ P x)) :
(cntP n tst rd).ok s ∧ (cntP n tst rd).run s =
s.upd rd (.int (∑ x ∈ Finset.Icc 1 N, if P x then (1 : ℤ) else 0) :: s.G rd) := by sorry