Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.LogSpace.CounterProgram.Words

Word and list operations with counters, in logarithmic space #

Counter programs (Turing.CounterProgram) for operations that need a counter of logarithmic length, so that they are not finite-state transductions:

Each program reads the length n of the framed first component and the unary second component into registers (headerCode), and keeps its registers below the input length, so it computes its function in logarithmic space by Turing.CounterProgram.computableInLogSpace_of_reachesOut. None of this uses logarithmic-space composition, apart from the fun_prop forms at the end. The rules of LogSpace/Words are imported publicly, so that fun_prop has the full rule set.

Main definitions #

Main results #

References #

The input frame w ++ replicate k true #

Reading the header: the length of the framed word and the unary count #

The header code: label 0 and 1 count the framed word into register 0, labels 2 and 3 count the unary tail into register 1; it exits at label 4.

Instances For

    The run of headerCode: from the initial registers it stores the length of the framed word in register 0 and the unary count in register 1, and exits at label 4, without emitting.

    Emitting bits of the framed word #

    The body emitting the bit at index reg 2 + reg 3 · reg 1, if any, then continuing at 7. With reg 3 = 0 this is the bit at the loop index; with reg 3 = 1 it is offset by k.

    Instances For

      A program emitting w[i + o·k] for i below the bound of its loop, where o ∈ {0, 1} is the initial value of register 3, set by the instruction at label 4.

      Instances For

        Enumerating 0, …, n - 1 #

        The program enumerating 0, …, n - 1 in unary, as a list: labels 0 and 1 count the unary input into register 0; the loop at 2 runs register 1 over the elements, and the inner loop at 5 writes the framed unary digits of each element with register 2.

        Instances For

          Looking up an element of a list #

          The program looking up the element at a unary index in a list: the header reads the length n of the list encoding and the index k; the loop at 4 skips k framed elements with register 2 as the position, guarded by reg 2 < n; if an element remains, the code at 11 writes true and copies the element's digits.

          Instances For

            The first k bits of a word, with k in unary, in logarithmic space.

            A word without its first k bits, with k in unary, in logarithmic space.

            The list 0, …, n - 1, in unary, in logarithmic space.

            Looking up the element at a unary index in a list, in logarithmic space.

            Automation #

            theorem Turing.MultiTapeTM.ComputableInLogSpace.bitsTake' {γ : Type} {encIn : γ ↪ List Bool} {w : γ → List Bool} {k : γ → ℕ} (hw : ComputableInLogSpace w encIn encBits) (hk : ComputableInLogSpace k encIn encUnary) :
            ComputableInLogSpace (fun (a : γ) => List.take (k a) (w a)) encIn encBits

            The first k bits of a computed word, in the form used by fun_prop.

            theorem Turing.MultiTapeTM.ComputableInLogSpace.bitsDrop' {γ : Type} {encIn : γ ↪ List Bool} {w : γ → List Bool} {k : γ → ℕ} (hw : ComputableInLogSpace w encIn encBits) (hk : ComputableInLogSpace k encIn encUnary) :
            ComputableInLogSpace (fun (a : γ) => List.drop (k a) (w a)) encIn encBits

            A computed word without its first k bits, in the form used by fun_prop.

            theorem Turing.MultiTapeTM.ComputableInLogSpace.getElem?' {γ : Type} {encIn : γ ↪ List Bool} {α : Type} {enc : α ↪ List Bool} {l : γ → List α} {k : γ → ℕ} (hl : ComputableInLogSpace l encIn (encList enc)) (hk : ComputableInLogSpace k encIn encUnary) :
            ComputableInLogSpace (fun (a : γ) => (l a)[k a]?) encIn (encOption enc)

            Looking up a computed unary index in a computed list, in the form used by fun_prop.