Documentation

CslibFrontier.Foundations.Computability.RecursiveInClocked

Oracle codes as clocked oracle programs #

Oracle codes Nat.RecursiveIn.Code and clocked oracle programs Cslib.ClockedComp querying a single oracle ℕ →. ℕ (the interface Cslib.natOracleSpec) compute the same partial functions.

Main definitions #

Main results #

Implementation notes #

A query to a point where the oracle is undefined diverges, as in Nat.RecursiveIn, so the characterization holds for partial oracles. The dialogue of a bind needs to know how many answers its first part consumed; the play records the answers left over, and the dialogue is read off it (ClockedComp.computable_dialogue_of_play).

@[reducible, inline]

The interface of a single oracle ℕ →. ℕ: a query is a number and so is its answer.

The next move of a program over natOracleSpec once it has received the answers rs to its first queries: its next query, or its result. Answers after the result are ignored.

The play of a program over natOracleSpec on the answers rs: its next query once the answers run out, or its result together with the answers it has not used.

theorem Cslib.OracleComp.play_bind {α β : Type} (T : OracleComp natOracleSpec α) (f : α → OracleComp natOracleSpec β) (rs : List ℕ) :
(T >>= f).play rs = Sum.elim Sum.inl (fun (p : α × List ℕ) => (f p.1).play p.2) (T.play rs)

Playing T >>= f plays T, then f of its result on the answers left over.

One step of running a program against g: ask its next query and append the answer, or stay put once the program has a result.

The answers T has received from g after t steps.

theorem Cslib.OracleComp.replies_liftBind {α : Type} (g : ℕ →. ℕ) (q : ℕ) (k : ℕ → OracleComp natOracleSpec α) (t : ℕ) :
replies g (PFunctor.FreeM.liftBind q k) (t + 1) = (g q).bind fun (r : ℕ) => Part.map (fun (x : List ℕ) => r :: x) (replies g (k r) t)
theorem Cslib.OracleComp.mem_interpret_iff {α : Type} (g : ℕ →. ℕ) (T : OracleComp natOracleSpec α) (a : α) :
a ∈ interpret g T ↔ ∃ (t : ℕ), ∃ rs ∈ replies g T t, T.nextMove rs = Sum.inr a

A program returns a against g iff some finite reply trace leads to the result a.

theorem Cslib.OracleComp.replies_dom_of_le {α : Type} {g : ℕ →. ℕ} {T : OracleComp natOracleSpec α} {m t : ℕ} :
(replies g T t).Dom → m ≤ t → (replies g T m).Dom
theorem Cslib.OracleComp.interpret_eq_rfind {α : Type} [Inhabited α] (g : ℕ →. ℕ) (T : OracleComp natOracleSpec α) :
interpret g T = (Nat.rfind fun (t : ℕ) => Part.map (fun (rs : List ℕ) => (T.nextMove rs).isRight) (replies g T t)).bind fun (t : ℕ) => Part.map (fun (rs : List ℕ) => Sum.elim (fun (x : ℕ) => default) id (T.nextMove rs)) (replies g T t)

Running a program against g iterates stepReplies up to the first step whose next move is a result, and returns that result.

The dialogue of a family of clocked programs on natural numbers: the next move of the program for input n run with fuel k, after it has received the answers rs. A family whose dialogue is computable is an oracle machine: its control is computable, and only the answers to its queries come from the oracle.

Program to code. A family of clocked programs whose dialogue is computable is computed by a single oracle code, relative to every partial oracle. The code follows the definition of ClockedComp.eval: it searches for the least fuel that finishes, running each fuel by iterating the dialogue and querying the oracle at each requested point.

Every family of clocked programs with computable dialogue computes a function recursive in the oracle it queries.

def Cslib.ClockedComp.play {σ β : Type} (P : σ → ClockedComp natOracleSpec β) :

The play of a family of clocked programs over natOracleSpec: for an input, a fuel and the answers received so far, the next query, or the result of the run together with the unused answers.

@[simp]
theorem Cslib.ClockedComp.play_apply {σ β : Type} (P : σ → ClockedComp natOracleSpec β) (x : σ) (k : ℕ) (rs : List ℕ) :
play P ((x, k), rs) = (P x k).run.play rs
theorem Cslib.ClockedComp.play_run_bind {β γ : Type} (P : ClockedComp natOracleSpec β) (f : β → ClockedComp natOracleSpec γ) (k : ℕ) (rs : List ℕ) :
((P >>= f) k).run.play rs = Sum.elim Sum.inl (fun (p : Option β × List ℕ) => p.1.elim (Sum.inr (none, p.2)) fun (a : β) => (f a k).run.play p.2) ((P k).run.play rs)

Play the run with fuel k of P >>= f: play P, then f on its result with the answers left over.

A family with computable play has a computable dialogue.

Closure of computable plays under the program constructors.

theorem Cslib.ClockedComp.computable_play_comp {σ τ β : Type} [Primcodable σ] [Primcodable τ] [Primcodable β] {P : σ → ClockedComp natOracleSpec β} (hP : Computable (play P)) {g : τ → σ} (hg : Computable g) :
Computable (play fun (y : τ) => P (g y))
theorem Cslib.ClockedComp.computable_play_pure {σ β : Type} [Primcodable σ] [Primcodable β] {f : σ → β} (hf : Computable f) :
Computable (play fun (x : σ) => pure (f x))
theorem Cslib.ClockedComp.computable_play_query {σ : Type} [Primcodable σ] {f : σ → ℕ} (hf : Computable f) :
Computable (play fun (x : σ) => query (f x))
theorem Cslib.ClockedComp.computable_play_bind {σ β γ : Type} [Primcodable σ] [Primcodable β] [Primcodable γ] {P : σ → ClockedComp natOracleSpec β} {f : σ → β → ClockedComp natOracleSpec γ} (hP : Computable (play P)) (hf : Computable (play fun (y : σ × β) => f y.1 y.2)) :
Computable (play fun (x : σ) => P x >>= f x)
theorem Cslib.ClockedComp.computable_play_map {σ β γ : Type} [Primcodable σ] [Primcodable β] [Primcodable γ] {P : σ → ClockedComp natOracleSpec β} {f : σ → β → γ} (hP : Computable (play P)) (hf : Computable₂ f) :
Computable (play fun (x : σ) => f x <$> P x)
theorem Cslib.ClockedComp.computable_play_rfind {σ : Type} [Primcodable σ] {p : σ × ℕ → ClockedComp natOracleSpec Bool} (hp : Computable (play p)) :
Computable (play fun (x : σ) => rfind fun (i : ℕ) => p (x, i))
theorem Cslib.ClockedComp.computable_play_natRec {σ β : Type} [Primcodable σ] [Primcodable β] {m : σ → ℕ} {P : σ → ClockedComp natOracleSpec β} {g : σ × ℕ × β → ClockedComp natOracleSpec β} (hm : Computable m) (hP : Computable (play P)) (hg : Computable (play g)) :
Computable (play fun (x : σ) => Nat.rec (P x) (fun (y : ℕ) (ih : ClockedComp natOracleSpec β) => do let i ← ih g (x, y, i)) (m x))

Compile an oracle code to a clocked program querying the oracle, constructor by constructor: composition is bind, primitive recursion is Lean recursion on the counter, and unbounded search is ClockedComp.rfind.

The compiled program of a code is stable against every partial oracle.

Code to program. The compiled program computes the code relative to every partial oracle.

The compiled program of a code has a computable play.

The dialogue of the compiled program of a code is computable.

Codes and clocked programs compute the same functions. Relative to a partial oracle g, a partial function is recursive in g if and only if it is computed against g by a family of clocked programs querying g whose dialogue is computable.