Documentation

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

Named native streaming folds #

This module retains an explicit stream table assembled from named callback compilers. The framed initial state is copied directly from the input prefix, list elements are decoded one frame at a time, and the input list is never copied to work tapes. The construction records the exact callback-lifting, loop, finalization, cleanup and rewind bounds from the stream kernel.

No machine is selected from an existential computability certificate. The only supplied bounds are sMax, for the peak lifted callback workspace, and lMax, for the encoded state and element lengths along this particular fold. The per-round clock is the explicit construction formula.

Main definitions #

Read one standard framed value, emitting its contents and stopping after its closing marker.

frameValueReader removes exactly one layer of standard framing.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFramedNext {Alpha : Type u_1} {Sigma : Type u_2} {next : Sigma × Alpha → Sigma} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} (compiler : NativeCompiler next (encPair encS encA) encS) :
NativeCompiler (fun (input : Sigma × Alpha) => frame (encS (next input))) (encPair encS encA) encBits

The next-state callback followed by the retained framing transducer required by the explicit stream table.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamUnframedFinish {Sigma : Type u_1} {Phi : Type u_2} {finish : Sigma → Phi} {encS : Sigma ↪ List Bool} {encF : Phi ↪ List Bool} (compiler : NativeCompiler finish encS encF) :
NativeCompiler finish (encFramed encS) encF

The final callback preceded by the retained typed unframing transducer required by the explicit stream table.

def Turing.MultiTapeTM.Internal.NativeCompiler.inputFromWordTime {Alpha : Type u_1} {Beta : Type u_2} {f : Alpha → Beta} {encIn : Alpha ↪ List Bool} {encOut : Beta ↪ List Bool} (compiler : NativeCompiler f encIn encOut) (input : Alpha) :

Exact clock of a tidy callback lifted to emit from a selected work tape.

def Turing.MultiTapeTM.Internal.NativeCompiler.inputFromWordWorkspace {Alpha : Type u_1} {Beta : Type u_2} {f : Alpha → Beta} {encIn : Alpha ↪ List Bool} {encOut : Beta ↪ List Bool} (K : ℕ) (compiler : NativeCompiler f encIn encOut) (input : Alpha) :

Construction-derived workspace bound for a tidy callback lifted to emit from a selected work tape in a K-tape stream machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.onWordsTime {Alpha : Type u_1} {Beta : Type u_2} {f : Alpha → Beta} {encIn : Alpha ↪ List Bool} {encOut : Beta ↪ List Bool} (compiler : NativeCompiler f encIn encOut) (input : Alpha) :

Exact clock of a tidy callback lifted to write its output between selected work tapes.

def Turing.MultiTapeTM.Internal.NativeCompiler.onWordsWorkspace {Alpha : Type u_1} {Beta : Type u_2} {f : Alpha → Beta} {encIn : Alpha ↪ List Bool} {encOut : Beta ↪ List Bool} (K : ℕ) (compiler : NativeCompiler f encIn encOut) (input : Alpha) :

Construction-derived workspace bound for a tidy callback lifted to write its output between selected work tapes in a K-tape stream machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPairTapeCount {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {Phi : Type u_4} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {finish : Sigma → Phi} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} {encF : Phi ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (finishCompiler : NativeCompiler finish encS encF) :

The exact number of tapes in the retained pair-stream assembly.

Explicit stream-machine assembly #

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPairTable {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {Phi : Type u_4} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {finish : Sigma → Phi} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} {encF : Phi ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (finishCompiler : NativeCompiler finish encS encF) :

The retained pair-stream program as one explicit, choice-free transition table.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPairRoundCost {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (input : Sigma × List Alpha) (j : ℕ) :

Exact time charged to round j. Outside the list range it is zero; the stream machine uses this function only over Finset.range input.2.length.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPairTime {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {Phi : Type u_4} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {finish : Sigma → Phi} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} {encF : Phi ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (finishCompiler : NativeCompiler finish encS encF) (input : Sigma × List Alpha) :

Construction-derived clock of the retained pair-stream machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPairWorkspace {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {Phi : Type u_4} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {finish : Sigma → Phi} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} {encF : Phi ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (finishCompiler : NativeCompiler finish encS encF) (sMax lMax : Sigma × List Alpha → ℕ) (input : Sigma × List Alpha) :

Construction-derived workspace bound of the retained pair-stream machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.streamFoldPair {Alpha : Type u_1} {Sigma : Type u_2} {Epsilon : Type u_3} {Phi : Type u_4} {Omega : Type u_5} {next : Sigma × Alpha → Sigma} {emit : Sigma × Alpha → Epsilon} {finish : Sigma → Phi} {result : Sigma × List Alpha → Omega} {encA : Alpha ↪ List Bool} {encS : Sigma ↪ List Bool} {encE : Epsilon ↪ List Bool} {encF : Phi ↪ List Bool} {encOut : Omega ↪ List Bool} (nextCompiler : NativeCompiler next (encPair encS encA) encS) (emitCompiler : NativeCompiler emit (encPair encS encA) encE) (finishCompiler : NativeCompiler finish encS encF) (hresult : ∀ (input : Sigma × List Alpha), encOut (result input) = streamEmit next (fun (pair : Sigma × Alpha) => encE (emit pair)) input.1 input.2 ++ encF (finish (streamState input.1 next input.2 input.2.length))) (sMax lMax : Sigma × List Alpha → ℕ) (hspace : ∀ (input : Sigma × List Alpha) (j : ℕ) (hj : j < input.2.length), have pair := (streamState input.1 next input.2 j, input.2[j]); inputFromWordWorkspace (nextCompiler.streamFoldPairTapeCount emitCompiler finishCompiler) emitCompiler pair + onWordsWorkspace (nextCompiler.streamFoldPairTapeCount emitCompiler finishCompiler) nextCompiler.streamFramedNext pair ≤ sMax input) (hstate : ∀ (input : Sigma × List Alpha), ∀ j ≤ input.2.length, (encS (streamState input.1 next input.2 j)).length ≤ lMax input) (helem : ∀ (input : Sigma × List Alpha) (j : ℕ) (hj : j < input.2.length), (encA input.2[j]).length ≤ lMax input) :
NativeCompiler result (encPair encS (encList encA)) encOut

Retain the concrete pair-prefix streaming fold. sMax bounds the sum of the two lifted callback workspaces in each round; lMax bounds every encoded stream state and element.