Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Internal.NativeCompiler.Codec

Named native streaming codecs #

This module retains the actual finite-state transducers used by the first layer of an encoded universal interpreter. NativeCompiler.ofTransducer packages the transducer followed by the existing input rewind, with its constructive state encoding, exact description, linear clock and zero workspace. It does not select a machine from an existential computability certificate.

The named codecs are total on malformed words. In particular, the Boolean decoder uses false on empty input, frame decoders follow the existing incomplete-frame convention, and framesDecoder closes a final incomplete frame. Pair projections reuse those same machines directly rather than treating encoded tuple access as a semantic callback.

Main definitions #

def Turing.MultiTapeTM.Internal.NativeCompiler.ofTransducer {Alpha : Type u_1} {Beta : Type u_2} {State : Type} [Fintype State] {f : Alpha → Beta} {encIn : Alpha ↪ List Bool} {encOut : Beta ↪ List Bool} (transducer : Transducer Bool State) (stateEncoding : State ↪ ℕ) (run_eq : ∀ (input : Alpha), transducer.run transducer.q₀ (encIn input) = encOut (f input)) :
NativeCompiler f encIn encOut

Retain a finite transducer followed by input rewind as a named tidy compiler. Every input bit is read by the transducer and by the rewind; emitted bits are included in the transducer clock.

Prefix a fixed tag bit, streaming the input unchanged after the first transition.

The prefix transducer emits exactly the fixed tag followed by the input.

Retained raw-word prefix operation.

Retained constructor for the standard some tag.

def Turing.MultiTapeTM.Internal.NativeCompiler.sumInl {Alpha : Type u_1} {Beta : Type u_2} (encLeft : Alpha ↪ List Bool) (encRight : Beta ↪ List Bool) :
NativeCompiler Sum.inl encLeft (encSum encLeft encRight)

Retained constructor for the standard left-sum tag.

def Turing.MultiTapeTM.Internal.NativeCompiler.sumInr {Alpha : Type u_1} {Beta : Type u_2} (encLeft : Alpha ↪ List Bool) (encRight : Beta ↪ List Bool) :
NativeCompiler Sum.inr encRight (encSum encLeft encRight)

Retained constructor for the standard right-sum tag.

Retained standard framing with the semantic value type unchanged.

Total Boolean decoder, returning false on empty input and the first symbol otherwise.

def Turing.MultiTapeTM.Internal.NativeCompiler.sumTag {Alpha : Type u_1} {Beta : Type u_2} (encLeft : Alpha ↪ List Bool) (encRight : Beta ↪ List Bool) :

Read the constructor tag of a standard sum encoding.

def Turing.MultiTapeTM.Internal.NativeCompiler.sumPayload {Alpha : Type u_1} {Beta : Type u_2} (encLeft : Alpha ↪ List Bool) (encRight : Beta ↪ List Bool) :
NativeCompiler (fun (value : Alpha ⊕ Beta) => ((encSum encLeft encRight) value).tail) (encSum encLeft encRight) encBits

Emit the untagged payload word of a standard sum encoding.

Explicit encoding of the three list-frame-parser states.

Explicit encoding of the direct unary take/drop kernel's eight control states.

Explicit encoding of the four control states used to clear a work tape and its shadow.

Constructive encoding of the recursively nested control used to clear a list of work tapes.

Decode a framed list of words to their unary lengths in one streaming pass. This uses the same total convention as frames: a final incomplete frame is closed.

While inside a frame, unaryListT emits the unary length of that frame and continues with the remaining framed word.

The streaming decoder emits the standard encoded list of all decoded unary lengths.

def Turing.MultiTapeTM.Internal.NativeCompiler.first {Alpha : Type u} {Beta : Type v} (encFirst : Alpha ↪ List Bool) (encSecond : Beta ↪ List Bool) :
NativeCompiler Prod.fst (encPair encFirst encSecond) encFirst

The first projection of the standard framed pair encoding, using the frame parser directly.

def Turing.MultiTapeTM.Internal.NativeCompiler.second {Alpha : Type u} {Beta : Type v} (encFirst : Alpha ↪ List Bool) (encSecond : Beta ↪ List Bool) :
NativeCompiler Prod.snd (encPair encFirst encSecond) encSecond

The second projection of the standard framed pair encoding, using the frame parser directly.

Total unary decoder: every input symbol contributes one unary output symbol.

Read the standard option constructor tag with one-bit Boolean output.

Test whether a raw word is empty. The machine scans the whole input, emits the standard Boolean encoding and rewinds; malformedness is irrelevant because every raw word is accepted.

Convert the one-bit Boolean encoding to the branch-test encoding: false becomes the empty word and true becomes [true]. Branching consumers must charge this retained conversion rather than interpreting encBool as encTest.

The true-filter transducer realizes the empty/nonempty test encoding on one-bit Booleans.

Retained conversion from one-bit Booleans to empty/nonempty branch tests.

Read the standard option constructor tag in the empty/nonempty branch encoding.

Test whether a unary natural is zero using the same retained empty-word transducer.

Unary zero test in the empty/nonempty branch encoding, including the retained tag conversion.

Saturating predecessor on unary naturals. This is the public headT drop-first-symbol machine, not the private proof-local predecessor transducer from the degree calculus.

Total first-frame decoder, including the existing incomplete-frame behavior.

Remove the frame around a typed encoded value. This retains the same parser as unframeDecoder, with no semantic decoding step.

Split a raw word into framed words, closing a final incomplete frame.

Decode every framed word to its unary length. A final incomplete frame is closed exactly as by frames; no semantic list-map callback is hidden behind this compiler.

def Turing.MultiTapeTM.Internal.NativeCompiler.takeDropUnary {Alpha : Type u_1} (keep : Bool) (enc : Alpha ↪ List Bool) :
NativeCompiler (fun (input : List Alpha × ℕ) => if keep = true then List.take input.2 input.1 else List.drop input.2 input.1) (encPair (encList enc) encUnary) (encList enc)

Retain the direct encoded-list take/drop kernel through its existing tidy normal form. The clock and workspace expose both the kernel bound and the exact normal-form overhead.

def Turing.MultiTapeTM.Internal.NativeCompiler.takeUnary {Alpha : Type u_1} (enc : Alpha ↪ List Bool) :
NativeCompiler (fun (input : List Alpha × ℕ) => List.take input.2 input.1) (encPair (encList enc) encUnary) (encList enc)

Retained linear-time prefix of an encoded list at a unary count.

def Turing.MultiTapeTM.Internal.NativeCompiler.dropUnary {Alpha : Type u_1} (enc : Alpha ↪ List Bool) :
NativeCompiler (fun (input : List Alpha × ℕ) => List.drop input.2 input.1) (encPair (encList enc) encUnary) (encList enc)

Retained linear-time suffix of an encoded list at a unary count.