Documentation

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

Named native compiler witnesses #

This internal module retains actual deterministic machine terms through a small construction kernel. NativeCompiler is data, not a second computability predicate: it packages a finite-state machine, its state encoding, independent time and workspace maps, and a tidy computation proof. NativeCompiler.computesInTimeAndSpace exposes the recorded machine to plain consumers, while NativeCompiler.computableInTimeAndSpace forgets it into the existing existential predicate.

The resource coordinates stay componentwise. NativeCompiler.staticBits is the exact encoded length of the compiler machine; NativeCompiler.inputBits and NativeCompiler.outputBits are the exact encoded source and emitted-result lengths; time and workspace apply only when that machine is executed. In particular, using a precompiled result does not pay compiler runtime, but a result used as code still carries its outputBits program-size charge. No scalar total is built into this kernel. Each coordinate counts one concrete artifact occurrence: a separately stored copy must be charged again by the enclosing certificate. Thus a payload hardwired into the compiler description and a copy emitted as output are distinct artifacts, not double counting. The constructor clocks charge their actual copying, framing, rewinding and intermediate marshalling; they provide no free scan of an encoded program through finite control.

The constructors use the existing machine combinators directly. In particular, they do not select a machine from ComputableInPolyTime, ComputableInO, ComputableInDegree, or a normal-form existence theorem. Their resource formulas retain the constants of those combinators. The exact static program charge is NativeCompiler.staticBits, the eDesc length of the packaged machine under its recorded state encoding.

The constructors assemble fixed machine terms at the proof level; they are not a free dynamic code generator. The functions and encodings in their types specify behavior and resource expressions, not callbacks executed outside the packaged machine. A compiler that receives descriptions at runtime must itself be a NativeCompiler whose machine performs that encoded transformation. Oracle handlers, query/service implementations and universal interpretation are not coordinates of this deterministic kernel and must be added separately by constructions that use them.

This is a bounded internal prerequisite for concrete compilers. It does not claim that an arbitrary existential computability proof can be extracted into a NativeCompiler.

Main definitions #

Main results #

structure Turing.MultiTapeTM.Internal.NativeCompiler {α : Type u_1} {β : Type u_2} (f : α → β) (encIn : α ↪ List Bool) (encOut : β ↪ List Bool) :
Type (max 1 u_1)

A named finite-state native machine computing f, with independent exact-form resource maps. This is internal construction data, not a parallel public computability calculus.

  • tapeCount : ℕ

    Number of work tapes of the named machine.

  • State : Type

    Finite control-state type of the named machine.

  • stateFintype : Fintype self.State

    The control-state type is explicitly finite.

  • The actual explicit transition table.

  • stateEncoding : self.State ↪ ℕ

    State encoding used for the exact universal description.

  • time : α → ℕ

    Native time bound when this machine is executed, kept separate from workspace.

  • workspace : α → ℕ

    Native workspace bound when this machine is executed, kept separate from time.

  • computes (a : α) : self.table.toTM.ComputesTidilyInTimeAndSpace (encIn a) (encOut (f a)) (self.time a) (self.workspace a)

    Direct tidy computation certificate for the named machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.sumStateEncoding {S₁ S₂ : Type} (left : S₁ ↪ ℕ) (right : S₂ ↪ ℕ) :
S₁ ⊕ S₂ ↪ ℕ

Constructive disjoint-union encoding used by the core constructors.

def Turing.MultiTapeTM.Internal.NativeCompiler.prodStateEncoding {S₁ S₂ : Type} (left : S₁ ↪ ℕ) (right : S₂ ↪ ℕ) :
S₁ × S₂ ↪ ℕ

Constructive product encoding used by the core constructors.

Constructive optional-state encoding used by the core constructors.

Constructive encoding of the transducer machine's source state, pending output bit and end-of-input flag.

One past the largest code that a state numbering assigns. This bounds the codes in use; it is not the cardinality of the state type.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.stateEncoding_lt_stateEncodingBound {State : Type} [Fintype State] (stateEncoding : State ↪ ℕ) (state : State) :
stateEncoding state < stateEncodingBound stateEncoding

Every state code lies strictly below stateEncodingBound.

def Turing.MultiTapeTM.Internal.NativeCompiler.description {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :

The exact universal description obtained by enumerating the retained transition table.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.description_holds {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) (state : compiler.State) (input : Option Bool) (work : Fin compiler.tapeCount → Option Bool) :
compiler.description.Holds (map compiler.stateEncoding Universal.eBit compiler.table.toTM) (compiler.stateEncoding state) (Option.map (⇑Universal.eBit) input) (Option.map ⇑Universal.eBit ∘ work)

The recorded description contains the packaged table's transition at every state and choice of symbols under the recorded state and symbol encodings.

def Turing.MultiTapeTM.Internal.NativeCompiler.inputBits {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (_compiler : NativeCompiler f encIn encOut) (a : α) :

Exact length of the compiler input under its recorded encoding. This is a separate resource coordinate, not runtime charged merely for presenting an already encoded input.

def Turing.MultiTapeTM.Internal.NativeCompiler.outputBits {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (_compiler : NativeCompiler f encIn encOut) (a : α) :

Exact length of the compiler output under its recorded encoding. When the output is executable code, this is its emitted program-size charge even if compilation itself is offline.

def Turing.MultiTapeTM.Internal.NativeCompiler.staticBits {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :

Exact unary-model static program length of the named machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.stateBound {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :

stateEncodingBound of the recorded control-state encoding.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.stateEncoding_lt_stateBound {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) (state : compiler.State) :
compiler.stateEncoding state < compiler.stateBound

Every recorded state code lies strictly below stateBound.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.description_table_length {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :
compiler.description.table.length = Fintype.card compiler.State * 3 ^ (compiler.tapeCount + 1)

The retained description has one row for every control state, input symbol and tuple of work tape symbols.

def Turing.MultiTapeTM.Internal.NativeCompiler.maxEntryBits {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :

Largest encoded transition-row length in the retained compiler description.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.staticBits_le {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :
compiler.staticBits ≤ 2 * compiler.tapeCount + 2 * compiler.stateBound + 2 + compiler.description.table.length * (2 * compiler.maxEntryBits + 1)

A concrete upper bound on the full unary-encoded description of a retained compiler. It charges every transition row and every state code; clients can substitute exact row counts while keeping large finite tables symbolic.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.computesInTimeAndSpace {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :
compiler.table.toTM.ComputesFunInTimeAndSpace encIn encOut f compiler.time compiler.workspace

Forget tidiness while retaining the same named machine and independent bounds.

theorem Turing.MultiTapeTM.Internal.NativeCompiler.computableInTimeAndSpace {α : Type u_1} {β : Type u_2} {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (compiler : NativeCompiler f encIn encOut) :
ComputableInTimeAndSpace f encIn encOut compiler.time compiler.workspace

Forget the construction data into the existing plain existential computability predicate. This direction packages the recorded machine; it does not extract a machine from that predicate.

def Turing.MultiTapeTM.Internal.NativeCompiler.ofInputEq {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : β → γ} {encIn : α ↪ List Bool} {encMid : β ↪ List Bool} {encOut : γ ↪ List Bool} (compiler : NativeCompiler f encMid encOut) (toInput : α → β) (henc : ∀ (input : α), encIn input = encMid (toInput input)) :
NativeCompiler (fun (input : α) => f (toInput input)) encIn encOut

Retype the semantic input of a named compiler when its actual input word is unchanged. The same machine is retained and no runtime callback is introduced.

def Turing.MultiTapeTM.Internal.NativeCompiler.ofOutputEq {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β} {g : α → γ} {encIn : α ↪ List Bool} {encMid : β ↪ List Bool} {encOut : γ ↪ List Bool} (compiler : NativeCompiler f encIn encMid) (henc : ∀ (input : α), encOut (g input) = encMid (f input)) :
NativeCompiler g encIn encOut

Retype the semantic output of a named compiler when the actual emitted word is unchanged. The same machine and resource maps are retained.

The named copy-and-rewind machine.

def Turing.MultiTapeTM.Internal.NativeCompiler.const {α : Type u_1} {β : Type u_2} (encIn : α ↪ List Bool) (encOut : β ↪ List Bool) (b : β) :
NativeCompiler (Function.const α b) encIn encOut

A named constant-output machine with its exact output-length clock and zero workspace.

def Turing.MultiTapeTM.Internal.NativeCompiler.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} {g : α → β} {f : β → γ} {encIn : α ↪ List Bool} {encMid : β ↪ List Bool} {encOut : γ ↪ List Bool} (outer : NativeCompiler f encMid encOut) (inner : NativeCompiler g encIn encMid) :
NativeCompiler (fun (a : α) => f (g a)) encIn encOut

Direct composition of two named machines. The result contains the choice-free MultiTapeMachine.comp table and retains every constant from its exact time and workspace theorem.

def Turing.MultiTapeTM.Internal.NativeCompiler.append {α : Type u_1} {left right : α → List Bool} {encIn : α ↪ List Bool} (leftCompiler : NativeCompiler left encIn encBits) (rightCompiler : NativeCompiler right encIn encBits) :
NativeCompiler (fun (input : α) => left input ++ right input) encIn encBits

Concatenate the raw-word outputs of two named machines on the same input.

def Turing.MultiTapeTM.Internal.NativeCompiler.encodeFrame {β : Type u_1} (enc : β ↪ List Bool) :
NativeCompiler (fun (b : β) => frame (enc b)) enc encBits

The named finite-state transducer that frames an encoded value.

def Turing.MultiTapeTM.Internal.NativeCompiler.pair {α : Type u} {β : Type v} {γ : Type w} {f : α → β} {g : α → γ} {encIn : α ↪ List Bool} {encLeft : β ↪ List Bool} {encRight : γ ↪ List Bool} (left : NativeCompiler f encIn encLeft) (right : NativeCompiler g encIn encRight) :
NativeCompiler (fun (a : α) => (f a, g a)) encIn (encPair encLeft encRight)

Direct standard-pair construction from two named machines on a common input. The left encoded output is framed by encodeFrame, then the right output is appended.