Binary decrement runs within cost
ProvedMIPRE.Cost.Prog.decProg_runsIn the ambient cost model (binary-tree data with the number of nodes, bit strings encoded as cons-chains of bits, numerals written least significant bit first), let decProg be the fixed decrement program. A nonzero binary numeral has the form (its least significant bits are , followed by a and a remainder ), and its predecessor is : the trailing zeros become ones and the first one becomes a zero.
Let and . Then there is a cost with
such that decProg, run on the input , halts with result at cost (Prog.Runs: the run in the one-entry environment holding the input). Here is exactly the size of the encoded input, so the bound is quadratic in the size of the input.
Decrement is one of the two arithmetic primitives of the bit-query program bitAtProg: to answer a query for the -th bit of a string, that program walks the string while decrementing the binary index , testing it for zero at each step. Since every string with a bit splits as , this lemma yields (as decProg_runs') a decrement of every nonzero index within the bound decBound of the bit-query analysis, which is where the factor of the time budget in the definition of a succinct description comes from.
Formalization Note. MIPRE.Cost.Prog.decProg is let_ (cons (var 0) nil) (let_ (loop decBody) revOntoProg): pair the input with an empty accumulator, run the first phase (decLoop_runs), then reverse the accumulated prefix onto the remainder (revOntoProg_runs). The output may be a non-canonical numeral (it can end in bits when does), which is why the specification is by the shape , and the bit-query analysis then speaks of the value bitsVal of a bit string rather than of Nat.bits. The constant and the factor absorb the two phases' bounds and and the pairing prefix.
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.decProg_runs (j : ℕ) (rest : BitStr) :
∃ t ≤ (j + 2) * (10 * (2 * j + (encode rest).size + 4) + 60),
decProg.Runs (encode (List.replicate j false ++ true :: rest))
(encode (List.replicate j true ++ false :: rest)) t := by sorry