Zero test on a binary numeral runs within cost
ProvedMIPRE.Cost.Prog.isZeroProg_runsWe work in the ambient cost model of the formalization: data are binary trees (Data, built from nil and cons), is the number of nodes of , and a bit string is encoded as the cons-chain of its bits ( nil, cons nil nil). A bit string is read as a binary numeral, least significant bit first. The timed semantics says that the program , run in the environment (a list of data values, variable first), halts with result at cost exactly ; one unit is charged per evaluation rule, and reading a variable or a literal additionally costs the size of the value read.
Let , let be any environment, and let be a bound with . Let isZeroProg be the fixed zero-test program (a loop whose body inspects the leading bit of the state and either stops or continues with the tail). Then there is a cost with
that is, with its input in variable (and arbitrary further variables), the program halts with the encoded Boolean "some bit of is ": the result is nil exactly when the numeral has value , and cons nil nil otherwise.
This is one of the two arithmetic primitives of the bit-query program bitAtProg of the succinct-description machinery: that program walks a string while decrementing a binary index , and tests the index for zero at each step. With (the size of an encoded bit string of length is at most ) the bound becomes the quantity zeroBound of that analysis, one of the sources of the quadratic factor in the time budget of a succinct description.
Formalization Note. The statement is about MIPRE.Cost.Prog.isZeroProg in the model MIPRE.Cost.Eval; the result is encode (l.any id), the encoding of the Boolean l.any id (false nil, true cons nil nil). The bound is quadratic rather than linear because the loop state (the remaining string) is copied, at a cost equal to its size, at each iteration; is any number dominating that size, so that the bound is a single product . The extra environment entries env are inert because the program is closed (well-scoped in one variable).
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.isZeroProg_runs (l : BitStr) (env : Env) (S : ℕ) (hS : (encode l).size ≤ S) :
∃ t ≤ (l.length + 1) * (S + 8),
Eval (encode l :: env) isZeroProg (encode (l.any id)) t := by sorry