Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.LogSpace.QueryMachine.CallSpace

Native space certificates for same-input calls #

The composite stores a caller state or a suspended caller paired with a callee state, encoded by Turing.QueryMachine.encWithCalls. These component certificates charge that compact encoded state, independently of the original read-only input. Calls return the callee state; they do not accumulate its output stream.

@[reducible, inline]
abbrev Turing.QueryMachine.encWithCalls {σ τ : Type} (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) :
σ ⊕ σ × τ ↪ List Bool

The encoding of the states of M.withCalls N request resume: one tag bit, then either a caller state (.inl s) or a suspended caller paired with the callee state (.inr (s, t)), with the caller framed.

theorem Turing.QueryMachine.withCalls_encoding_inl_length {σ τ : Type} (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (s : σ) :
((encWithCalls encS encT) (Sum.inl s)).length = (encS s).length + 1

A caller state pays only its payload and the sum tag.

theorem Turing.QueryMachine.withCalls_encoding_inr_length {σ τ : Type} (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (s : σ) (t : τ) :
((encWithCalls encS encT) (Sum.inr (s, t))).length = 2 * (encS s).length + (encT t).length + 2

A suspended call stores one caller and one callee, with explicit framing overhead.

theorem Turing.QueryMachine.withCalls_halted_inSpace {σ τ : Type} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (hhalted : MultiTapeTM.ComputableInSpace M.halted encS MultiTapeTM.encBool fun (s : σ) => (encS s).length) :
MultiTapeTM.ComputableInSpace (M.withCalls N request resume).halted (encWithCalls encS encT) MultiTapeTM.encBool fun (s : σ ⊕ σ × τ) => ((encWithCalls encS encT) s).length

The composite halt test uses only the caller's halt test.

theorem Turing.QueryMachine.withCalls_finish_inSpace {σ τ : Type} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (hfinish : MultiTapeTM.ComputableInSpace M.finish encS MultiTapeTM.encBits fun (s : σ) => (encS s).length) :
MultiTapeTM.ComputableInSpace (M.withCalls N request resume).finish (encWithCalls encS encT) MultiTapeTM.encBits fun (s : σ ⊕ σ × τ) => ((encWithCalls encS encT) s).length

Only the caller contributes the final output word.

theorem Turing.QueryMachine.withCalls_query_inSpace {σ τ : Type} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (hqueryM : MultiTapeTM.ComputableInSpace M.query encS MultiTapeTM.encNat fun (s : σ) => (encS s).length) (hqueryN : MultiTapeTM.ComputableInSpace N.query encT MultiTapeTM.encNat fun (t : τ) => (encT t).length) (hrequest : MultiTapeTM.ComputableInSpace request encS (MultiTapeTM.encOption encT) fun (s : σ) => (encS s).length) :
MultiTapeTM.ComputableInSpace (M.withCalls N request resume).query (encWithCalls encS encT) MultiTapeTM.encNat fun (s : σ ⊕ σ × τ) => ((encWithCalls encS encT) s).length

A call queries the original input through its active machine, without copying that input.

theorem Turing.QueryMachine.withCalls_emit_inSpace {σ τ : Type} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (hemit : MultiTapeTM.ComputableInSpace M.emit (encStateRead encS) MultiTapeTM.encBits fun (p : σ × Option Bool) => ((encStateRead encS) p).length) (hrequest : MultiTapeTM.ComputableInSpace request encS (MultiTapeTM.encOption encT) fun (s : σ) => (encS s).length) :
MultiTapeTM.ComputableInSpace (M.withCalls N request resume).emit (encStateRead (encWithCalls encS encT)) MultiTapeTM.encBits fun (p : (σ ⊕ σ × τ) × Option Bool) => ((encStateRead (encWithCalls encS encT)) p).length

The callee output stream is discarded, so only ordinary caller steps emit.

theorem Turing.QueryMachine.withCalls_next_inSpace {σ τ : Type} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (encS : σ ↪ List Bool) (encT : τ ↪ List Bool) (hnextM : MultiTapeTM.ComputableInSpace M.next (encStateRead encS) encS fun (p : σ × Option Bool) => ((encStateRead encS) p).length) (hnextN : MultiTapeTM.ComputableInSpace N.next (encStateRead encT) encT fun (p : τ × Option Bool) => ((encStateRead encT) p).length) (hhaltedN : MultiTapeTM.ComputableInSpace N.halted encT MultiTapeTM.encBool fun (t : τ) => (encT t).length) (hrequest : MultiTapeTM.ComputableInSpace request encS (MultiTapeTM.encOption encT) fun (s : σ) => (encS s).length) (hresume : MultiTapeTM.ComputableInSpace (fun (p : σ × τ) => resume p.1 p.2) (MultiTapeTM.encPair encS encT) encS fun (p : σ × τ) => ((MultiTapeTM.encPair encS encT) p).length) :
MultiTapeTM.ComputableInSpace (M.withCalls N request resume).next (encStateRead (encWithCalls encS encT)) (encWithCalls encS encT) fun (p : (σ ⊕ σ × τ) × Option Bool) => ((encStateRead (encWithCalls encS encT)) p).length

Entering, running and returning from a call preserve linear compact-state space.