Documentation

Complexitylib.Classes.PCP.Internal.DataScan

Scanning a serialized Data value #

Data.toBits writes a value as balanced brackets: false opens a node, its children follow in order, and true closes it. Reading one child back out of such a string is a single left-to-right pass keeping a bracket depth and a count of the children already passed, collecting bits only while inside the child asked for.

This module writes that pass in the form recFoldClamp accepts, so that polynomial-time computability comes from the general fold rather than from a bespoke machine. The fold recurses head-then-tail, so it runs right to left; the caller therefore hands it the reversed string.

The state is pair (unary depth) (pair (unary count) collected) and the workspace is the requested index in unary. Every component stays below the length of the string being scanned, so a linear clamp suffices.

Main definitions #

Main results #

Reading the packed fold argument #

recFoldClamp hands each step pair (pair W st) t, with W the workspace, st the state built so far and t the unscanned tail.

The workspace: the index of the child being extracted, in unary.

Equations
Instances For

    The state carried by the scan.

    Equations
    Instances For

      The number of children already passed, in unary.

      Equations
      Instances For

        Append the current bit, but only while inside the requested child.

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

          The two steps #

          A closing bracket: rise one level, and if that returns to the top level, one more child has been passed.

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

            Polynomial time #

            The scan. On pair (unary i) s it runs the two steps over s, keeping every intermediate state within p.eval bits, and returns the collected bits.

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

              The fold runs the model #

              The state the fold carries is the model's state written out: two unary counters and the collected bits. Once that is checked step by step, the fold and the model agree, provided the clamp is wide enough never to truncate.

              The model's state, written out as a bitstring.

              Equations
              Instances For
                theorem Complexity.DataScan.pack_length (st : × × List Bool) :
                (pack st).length = 2 * st.1 + 2 * st.2.1 + st.2.2.length + 4
                theorem Complexity.DataScan.collect_pack (i : ) (st : × × List Bool) (t : List Bool) (b : Bool) :
                collect (pair (pair (List.replicate i true) (pack st)) t) b = if st.2.1 = i then st.2.2 ++ [b] else st.2.2

                The state stays small #

                theorem Complexity.DataScan.runSpec_bounds (i : ) (s : List Bool) (d c : ) (acc : List Bool) :
                (runSpec i (d, c, acc) s).1 d + s.length (runSpec i (d, c, acc) s).2.1 c + s.length (runSpec i (d, c, acc) s).2.2.length acc.length + s.length

                The fold runs the model. Reading the reversed string with the clamped fold gives exactly the model's state, as long as the clamp is wide enough.

                The packaged scan #

                A clamp wide enough for any scan: the state never exceeds 5 n + 4 bits.

                Equations
                Instances For

                  The scan's argument: the index in unary paired with the reversed string, the order the fold consumes.

                  Equations
                  Instances For
                    theorem Complexity.DataScan.scanArg_mem_FP {a b : List BoolList Bool} (ha : a FP) (hb : b FP) :
                    (fun (z : List Bool) => scanArg (a z).length (b z)) FP

                    The scan extracts the child. Reading the concatenated serializations of xs returns the i-th one, or nothing when there is no such child.

                    How many children there are, in unary: the same pass, reading off the counter instead of the collected bits.

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

                      The bits strictly between the outer brackets of a serialized list.