Documentation

MIPRE.Foundations.Cost.Numeric

The closure library, part IV: binary numbers #

Programs on binary numbers presented as bit strings (LSB first, as in Nat.bits), used by the bit-query program of the recursive compression argument: the zero test (isZeroProg) and decrement (decProg). Decrement flips the leading falses to true and the first true to false; it may leave a non-canonical representation (trailing falses), which is why the specifications are in terms of the value bitsVal of a bit string rather than Nat.bits.

Costs: every list walk is quadratic in this model (the loop state is rebuilt each iteration, copying the tail), so bounds have the form (iterations + 1) · (S + c) with S dominating the sizes involved.

Bit strings as data #

@[simp]

The value of a bit string (LSB first), canonical or not.

Equations
Instances For
    @[simp]
    theorem MIPRE.Cost.bitsVal_cons (b : Bool) (l : BitStr) :
    bitsVal (b :: l) = Nat.bit b (bitsVal l)
    theorem MIPRE.Cost.exists_split_of_any (l : BitStr) (h : List.any l id = true) :
    ∃ (j : ) (rest : List Bool), l = List.replicate j false ++ true :: rest

    A bit string with a true bit splits as false^j ++ true :: rest.

    Zero test #

    Body of isZeroProg: walk the bits; stop with nil (zero) at the end, with cons nil nil (nonzero) at the first true bit.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      isZeroProg on a bit string computes encode (l.any id): nil iff the value is zero.

      Equations
      Instances For
        theorem MIPRE.Cost.Prog.isZeroProg_runs (l : BitStr) (env : Env) (S : ) (hS : (encode l).size S) :
        t ≤ (List.length l + 1) * (S + 8), Eval (encode l :: env) isZeroProg (encode (List.any l id)) t

        Decrement #

        Body of the first phase of decProg: on state cons bits acc, a leading false bit is turned into a true pushed on acc; at the first true bit the loop stops with the pair cons (false :: acc) rest, which the second phase (revOntoProg) reverses onto rest.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          decProg on the bits of a nonzero number computes the bits of its predecessor.

          Equations
          Instances For
            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 ((encode (List.replicate j false ++ true :: rest)).cons (encode (List.replicate i true)) :: env) decBody.loop ((encode (false :: List.replicate (i + j) true)).cons (encode rest)) t

            The first phase of decProg on false^j ++ true :: rest with accumulator true^i. The slack S must cover the growth of the accumulator: each converted bit adds two nodes.

            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

            The next level index #

            n ↦ 2 n + 1 on binary numerals: prepend a true bit. This is the "next level" map of the recursive compression argument (the paper's n + 1 would need a carry propagation; 2 n + 1 is one node).

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              @[simp]