Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Encodings.RecursiveParser

Native decoding of flat constructor streams #

RecursiveEncoding.readNode interprets each constructor token by its arity and constructor. When constructing a node writes that token followed by its children's streams, the generic prefix parser accepts exactly the complete one-root forests. Its successful output has exactly the original token stream as its encoding. Consequently decoding typed tokens has a native polynomial-time certificate whenever token arities can be read in polynomial time and have a fixed bound. This does not supply a decoder for arbitrary bit-word embeddings of scalar fields.

def Turing.MultiTapeTM.RecursiveEncoding.readNode {τ α : Type} (arity : τ → ℕ) (make : (token : τ) → (Fin (arity token) → α) → α) (token : τ) :

Interpret a constructor token using its recursive arity and constructor function.

theorem Turing.MultiTapeTM.RecursiveEncoding.parseFuel_readNode_sound {τ α : Type} (arity : τ → ℕ) (make : (token : τ) → (Fin (arity token) → α) → α) (tokens : α → List τ) (htokens : ∀ (token : τ) (children : Fin (arity token) → α), tokens (make token children) = token :: List.flatMap tokens (List.ofFn children)) (fuel : ℕ) (stream : List τ) (value : α) (rest : List τ) :
Cslib.PrefixParser.parseFuel (readNode arity make) fuel stream = some (value, rest) → tokens value ++ rest = stream ∧ Forest arity 1 (tokens value)

Every successful node parse produces a complete tree prefix and preserves its suffix.

theorem Turing.MultiTapeTM.RecursiveEncoding.parseFuel_readNode_complete {τ α : Type} (arity : τ → ℕ) (make : (token : τ) → (Fin (arity token) → α) → α) (tokens : α → List τ) (htokens : ∀ (token : τ) (children : Fin (arity token) → α), tokens (make token children) = token :: List.flatMap tokens (List.ofFn children)) (fuel : ℕ) (tree : List τ) :
Forest arity 1 tree → tree.length ≤ fuel → ∀ (rest : List τ), ∃ (value : α), Cslib.PrefixParser.parseFuel (readNode arity make) fuel (tree ++ rest) = some (value, rest) ∧ tokens value = tree

A complete node stream is parsed with fuel at least its token count, preserving every following token. No semantic inhabitant or field decoder is required.

theorem Turing.MultiTapeTM.RecursiveEncoding.decode_readNode_tokens {τ α : Type} (arity : τ → ℕ) (make : (token : τ) → (Fin (arity token) → α) → α) (tokens : α → List τ) (htokens : ∀ (token : τ) (children : Fin (arity token) → α), tokens (make token children) = token :: List.flatMap tokens (List.ofFn children)) (stream : List τ) :
Option.map tokens (Cslib.PrefixParser.decode (readNode arity make) stream) = if isTree arity stream = true then some stream else none

Decoding succeeds exactly on complete node streams, and re-encoding its value recovers every input token. Missing operands and trailing input are rejected.

theorem Turing.MultiTapeTM.RecursiveEncoding.decode_readNode_polyTime {τ α : Type} {encToken : τ ↪ List Bool} {encTree : α ↪ List Bool} (arity : τ → ℕ) (make : (token : τ) → (Fin (arity token) → α) → α) (tokens : α → List τ) (htokens : ∀ (token : τ) (children : Fin (arity token) → α), tokens (make token children) = token :: List.flatMap tokens (List.ofFn children)) (henc : ∀ (value : α), encTree value = (encList encToken) (tokens value)) (harity : ComputableInPolyTime arity encToken encUnary) {maximum : ℕ} (hmax : ∀ (token : τ), arity token ≤ maximum) :

Typed constructor-stream decoding has a native polynomial-time certificate. Its machine validates the stream and emits its original encoded word; it need not build semantic Lean values. The token embedding supplies no decoder for arbitrary bit words.