Documentation

Complexity.Computability.GenericRAM.Native.BooleanFold

Streaming local Boolean assignments #

The runtime dimension is unary and the current index is binary. The existing lowBits decoder returns exactly that many bits, padding or truncating on arbitrary indices. Its certificate below is derived from direct native list/bit primitives; no legacy polynomial-time bridge is used. The assignment list in the correctness specification is not constructed by the streaming loop.

This is the local Boolean-vector component of the enumeration in [OAI26c], Lemma 3.2 and Proposition 3.4, pp. 22–26. It is not a mixed-radix or subset-pair enumerator, and gives no polynomial-time bound for a whole loop with exponentially many rounds.

The fixed decoder reads its runtime width in unary and its runtime index in binary. The actual machine has polynomial time and charged workspace in their complete pair encoding.

Bounds selected from the direct fixed decoder machine; the machine is uniform in both runtime width and index. This is not a separate finite machine for every width.

Instances For

    Both selected decoder resource bounds are polynomial in the full encoded input length.

    Each valid binary index decodes to its word in the existing finite enumeration order.

    The conceptual sequence of decoded indices is exactly the old materializing enumeration. Only this specification uses the list of all indices.

    Distinct valid indices decode to distinct runtime words.

    theorem Cslib.GenericRAM.BooleanFold.decoder_coverage (n : ℕ) (word : List Bool) (hw : word.length = n) :
    ∃! j : Fin (2 ^ n), BitString.lowBits n ↑j = word

    Every runtime word of the declared length is decoded by exactly one valid index.

    Construct the exponential visit count in binary, in linear time in the unary dimension. Only n + 1 output bits are produced; no unary representation of 2 ^ n is constructed.

    Instances For

      The binary visit count has exactly one more bit than the dimension.

      def Cslib.GenericRAM.BooleanFold.visit {β : Type} (body : (ℕ × List Bool) × β → β) (p : ℕ × ℕ × β) :
      ℕ × β

      Decode the current index, retain the runtime dimension and invoke the full captured body.

      Instances For
        def Cslib.GenericRAM.BooleanFold.runPrefix {β : Type} (body : (ℕ × List Bool) × β → β) (n j : ℕ) (initial : β) :

        A prefix of the streaming assignment traversal, retaining width and captured accumulator.

        Instances For
          def Cslib.GenericRAM.BooleanFold.run {β : Type} (body : (ℕ × List Bool) × β → β) (n : ℕ) (initial : β) :

          The whole traversal, including its completed index and retained dimension.

          Instances For
            @[simp]
            theorem Cslib.GenericRAM.BooleanFold.prefix_width {β : Type} (body : (ℕ × List Bool) × β → β) (n j : ℕ) (initial : β) :
            (runPrefix body n j initial).2.1 = n

            The dimension is preserved at every prefix, independent of the body.

            theorem Cslib.GenericRAM.BooleanFold.prefix_accumulator {β : Type} (body : (ℕ × List Bool) × β → β) (n j : ℕ) (initial : β) :
            (runPrefix body n j initial).2.2 = List.foldl (fun (acc : β) (i : ℕ) => body ((n, BitString.lowBits n i), acc)) initial (List.range j)

            Every prefix visits the decoded words in increasing index order.

            theorem Cslib.GenericRAM.BooleanFold.run_accumulator {β : Type} (body : (ℕ × List Bool) × β → β) (n : ℕ) (initial : β) :
            (run body n initial).2.2 = List.foldl (fun (acc : β) (word : List Bool) => body ((n, word), acc)) initial (BitString.enumList n)

            The streaming traversal agrees with the existing enumeration, hence covers every runtime word of length n exactly once in that enumeration's order. The right side is specification-only.

            theorem Cslib.GenericRAM.BooleanFold.length_prefix_le {β : Type} {encB : β ↪ List Bool} (body : (ℕ × List Bool) × β → β) (n j B : ℕ) (initial : β) (hj : j ≤ 2 ^ n) (hB : (encB (runPrefix body n j initial).2.2).length ≤ B) :

            The full live state contains the binary index, retained unary width and accumulator. No word list or exponential history contributes to this prefix bound.

            The decoded word itself always has the declared runtime dimension, even on arbitrary indices. This bounds temporary callback input as well as the persistent state.

            Construct the actual native captured callback, retaining width outside the user body. Only the supplied body's certificate is assumed; decoder/preparation efficiency is proved here.

            Instances For

              A polynomial native body gives a polynomial native visit, in the COMPLETE encoded index/width/captured-state input. This is a per-visit result, not a whole-loop bound.

              noncomputable def Cslib.GenericRAM.BooleanFold.certificate {β : Type} {encB : β ↪ List Bool} {α : Type} {encIn : α ↪ List Bool} {dimension : α → ℕ} {initial : α → β} {body : (ℕ × List Bool) × β → β} (cn : NativeCertificate dimension encIn Turing.MultiTapeTM.encUnary) (ci : NativeCertificate initial encIn encB) (cb : NativeCertificate body (Turing.MultiTapeTM.encPair (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) encB) encB) :

              A single native machine handles all runtime dimensions. Count construction, initialization, decoding and captured callback costs are included. The inherited IndexFold bounds retain maximum live-state/workspace and linear-in-visit-count time; no exponential whole-loop PT claim is made.

              Instances For