Documentation

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

State-returning calls between query machines #

QueryMachine.withCalls suspends a caller while a callee runs on the same original input. A request supplies the callee's initial state, and returning supplies its final state to the caller. Callee emissions are discarded: this construction does not store or return an output word. In particular, any data retained across a call is part of the explicit machine state.

Main definitions #

Main results #

def Turing.QueryMachine.withCalls {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) :
QueryMachine (σ ⊕ σ × τ)

Suspend the caller on a request and resume it with the callee's final state. Both machines read the same original input. Only ordinary caller steps emit output; call entry, callee steps, and return emit nothing. The suspended caller and callee states are stored explicitly.

theorem Turing.QueryMachine.withCalls_step_normal {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (h : request s = none) :
(M.withCalls N request resume).step w (Sum.inl s) = Sum.inl (M.step w s)

Without a request, a composite step is precisely a caller step, including halted states.

theorem Turing.QueryMachine.withCalls_step_call {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (t : τ) (hs : M.halted s = false) (h : request s = some t) :
(M.withCalls N request resume).step w (Sum.inl s) = Sum.inr (s, t)

Entering a call takes one step and preserves the suspended caller state.

theorem Turing.QueryMachine.withCalls_step_subroutine {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (t : τ) (h : N.halted t = false) :
(M.withCalls N request resume).step w (Sum.inr (s, t)) = Sum.inr (s, N.step w t)

A live callee step reads exactly the bit that the callee reads on the original input.

theorem Turing.QueryMachine.withCalls_step_return {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (t : τ) (h : N.halted t = true) :
(M.withCalls N request resume).step w (Sum.inr (s, t)) = Sum.inl (resume s t)

Returning from a halted callee takes one additional step.

theorem Turing.QueryMachine.withCalls_runFrom_subroutine_prefix {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (start : τ) (T : ℕ) (hpre : ∀ i < T, N.halted (N.runFrom w start i) = false) :
(M.withCalls N request resume).runFrom w (Sum.inr (s, start)) T = Sum.inr (s, N.runFrom w start T)

Up to its first halt, the callee is simulated step for step.

theorem Turing.QueryMachine.withCalls_runFrom_return {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (start : τ) (T : ℕ) (hpre : ∀ i < T, N.halted (N.runFrom w start i) = false) (hhalt : N.halted (N.runFrom w start T) = true) :
(M.withCalls N request resume).runFrom w (Sum.inr (s, start)) (T + 1) = Sum.inl (resume s (N.runFrom w start T))

A callee that first halts at T returns its final state at time T + 1.

theorem Turing.QueryMachine.withCalls_runFrom_call {σ : Type u_1} {τ : Type u_2} (M : QueryMachine σ) (N : QueryMachine τ) (request : σ → Option τ) (resume : σ → τ → σ) (w : List Bool) (s : σ) (start : τ) (T : ℕ) (hs : M.halted s = false) (hrequest : request s = some start) (hpre : ∀ i < T, N.halted (N.runFrom w start i) = false) (hhalt : N.halted (N.runFrom w start T) = true) :
(M.withCalls N request resume).runFrom w (Sum.inl s) (T + 2) = Sum.inl (resume s (N.runFrom w start T))

Entry and return add two steps to the running time of a state-returning call.