Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Encodings.Recursive

Splitting flat recursive constructor streams #

A token's arity is its number of directly recursive fields. A tree is its constructor token, followed by the streams of its children, in field order. RecursiveEncoding.splitTree separates one complete tree from the following tokens and rejects a stream with missing children. RecursiveEncoding.isTree additionally rejects trailing tokens.

The native polynomial-time certificate operates on encList encToken, which frames each token once. It assumes a native certificate for reading the token arity and a fixed maximum arity. It requires no decoder for the token embedding: its input is a typed token stream. The certificate does not assert efficient decoding of arbitrary bit words or evaluation of arbitrary recursive functions.

inductive Turing.MultiTapeTM.RecursiveEncoding.Forest {τ : Type} (arity : τ → ℕ) :
ℕ → List τ → Prop

A complete forest with pending roots, in prefix constructor order.

  • nil {τ : Type} {arity : τ → ℕ} : Forest arity 0 []

    No roots require no tokens.

  • cons {τ : Type} {arity : τ → ℕ} {pending : ℕ} {token : τ} {tokens : List τ} (rest : Forest arity (pending + arity token) tokens) : Forest arity (pending + 1) (token :: tokens)

    Reading one root replaces it by the token's recursive children.

theorem Turing.MultiTapeTM.RecursiveEncoding.Forest.append {τ : Type} {arity : τ → ℕ} {n m : ℕ} {left right : List τ} (hl : Forest arity n left) (hr : Forest arity m right) :
Forest arity (n + m) (left ++ right)

Concatenating complete forests adds their numbers of roots.

theorem Turing.MultiTapeTM.RecursiveEncoding.Forest.flatten {τ : Type} {arity : τ → ℕ} {children : List (List τ)} (hchildren : ∀ child ∈ children, Forest arity 1 child) :
Forest arity children.length children.flatten

Concatenating tree streams yields a forest with one root per stream.

theorem Turing.MultiTapeTM.RecursiveEncoding.Forest.node {τ : Type} {arity : τ → ℕ} {token : τ} {children : List (List τ)} (hcount : children.length = arity token) (hchildren : ∀ child ∈ children, Forest arity 1 child) :
Forest arity 1 (token :: children.flatten)

A constructor followed by one complete stream per child is a tree.

def Turing.MultiTapeTM.RecursiveEncoding.splitForest {τ : Type} (arity : τ → ℕ) :
ℕ → List τ → Option (List τ × List τ)

Read a specified number of roots, preserving the unconsumed suffix.

def Turing.MultiTapeTM.RecursiveEncoding.splitTree {τ : Type} (arity : τ → ℕ) (tokens : List τ) :
Option (List τ × List τ)

Separate one complete tree from the following constructor tokens.

theorem Turing.MultiTapeTM.RecursiveEncoding.splitForest_eq_some_iff {τ : Type} {arity : τ → ℕ} {pending : ℕ} {tokens front rest : List τ} :
splitForest arity pending tokens = some (front, rest) ↔ Forest arity pending front ∧ front ++ rest = tokens

The splitter succeeds exactly on a complete prefix forest and its untouched suffix.

theorem Turing.MultiTapeTM.RecursiveEncoding.splitTree_eq_some_iff {τ : Type} {arity : τ → ℕ} {tokens front rest : List τ} :
splitTree arity tokens = some (front, rest) ↔ Forest arity 1 front ∧ front ++ rest = tokens

A successful tree split recognizes exactly a complete tree prefix.

theorem Turing.MultiTapeTM.RecursiveEncoding.splitTree_append {τ : Type} {arity : τ → ℕ} {tree : List τ} (h : Forest arity 1 tree) (rest : List τ) :
splitTree arity (tree ++ rest) = some (tree, rest)

Reading an encoded tree leaves any following tree or other suffix untouched.

def Turing.MultiTapeTM.RecursiveEncoding.isTree {τ : Type} (arity : τ → ℕ) (tokens : List τ) :

Recognize exactly one complete tree, rejecting missing children and trailing tokens.

theorem Turing.MultiTapeTM.RecursiveEncoding.isTree_eq_true_iff {τ : Type} {arity : τ → ℕ} {tokens : List τ} :
isTree arity tokens = true ↔ Forest arity 1 tokens

Full-stream recognition holds exactly for a complete one-root forest.

theorem Turing.MultiTapeTM.RecursiveEncoding.splitTree_polyTime {τ : Type} {encToken : τ ↪ List Bool} {arity : τ → ℕ} (harity : ComputableInPolyTime arity encToken encUnary) {maximum : ℕ} (hmax : ∀ (token : τ), arity token ≤ maximum) :
ComputableInPolyTime (splitTree arity) (encList encToken) (encOption (encPair (encList encToken) (encList encToken)))

Splitting one typed tree has a native polynomial-time certificate, assuming only native arity recognition and a fixed arity bound. The returned prefix and suffix retain the token encoding; arbitrary bit-word decoding is a separate operation.

theorem Turing.MultiTapeTM.RecursiveEncoding.isTree_polyTime {τ : Type} {encToken : τ ↪ List Bool} {arity : τ → ℕ} (harity : ComputableInPolyTime arity encToken encUnary) {maximum : ℕ} (hmax : ∀ (token : τ), arity token ≤ maximum) :

Native polynomial-time validity checking for a complete typed token stream. No semantic tree decoder or token decoder is required.