First phase of binary decrement: flipping the trailing zeros onto an accumulator, within cost
ProvedMIPRE.Cost.Prog.decLoop_runsIn the ambient cost model (binary-tree data, = number of nodes, bit strings encoded as cons-chains of bits, numerals written least significant bit first, timed semantics charging one unit per rule plus the size of every value read), the decrement program decProg works in two phases. This lemma analyzes the first phase, the loop loop decBody, whose state is a pair : as long as the leading bit of is it is removed and a is pushed onto the accumulator; at the first bit the loop stops with the pair , where is what follows that bit.
Let , let , let be any environment and let satisfy
Here is exactly the size of the encoded input string , is exactly the size of the encoded accumulator , and the additional covers the growth of the state during the loop (each converted bit removes two nodes from the string and adds four to the accumulator). Then there is a cost with
started on the state , the loop halts with the pair .
The lemma is the inductive core of decProg_runs, the cost analysis of binary decrement (the second phase reverses onto to obtain ); decrement, in turn, is one of the two arithmetic primitives of the bit-query program behind succinct descriptions.
Formalization Note. The statement is about the loop Prog.loop decBody of MIPRE.Cost.Prog.decProg, with the generalized accumulator needed for the induction. The slack hypothesis on is stated with the explicit sizes and so that the bound is a single product; each iteration costs at most because the loop state is copied by var reads whose cost is its size. The strings are lists of Booleans (List Bool) with the least significant bit first, and is List.replicate j false ++ true :: rest.
import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Data.List.Basic import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Notation import Mathlib.Data.Nat.Size import Mathlib.Tactic.Ring import Definitions.Def_MIPRE_Foundations_Cost_Basic import Definitions.Def_MIPRE_Foundations_Cost_Encoding import Definitions.Def_MIPRE_Foundations_Cost_PolyTime import Definitions.Def_MIPRE_Foundations_Cost_Closure import Definitions.Def_MIPRE_Foundations_Cost_Loops import Definitions.Def_MIPRE_Foundations_Cost_Unary import Definitions.Def_MIPRE_Foundations_Cost_Numeric open MIPRE open MIPRE.Cost open MIPRE.Cost.Prog
theorem MIPRE.Cost.Prog.decLoop_runs (j : ℕ) (rest : BitStr) (i : ℕ) (env : Env) (S : ℕ)
(hS : 2 * j + (encode rest).size + 4 + (4 * i + 1) + 2 * j ≤ S) :
∃ t ≤ (j + 1) * (S + 15),
Eval (.cons (encode (List.replicate j false ++ true :: rest))
(encode (List.replicate i true)) :: env) (.loop decBody)
(.cons (encode (false :: List.replicate (i + j) true)) (encode rest)) t := by sorry