Documentation

CslibFrontier.Foundations.Computability.RecursiveInCode

Codes for oracle computations #

Mathlib defines Nat.RecursiveIn O f inductively, as the closure of the basic functions and the oracles in O under pairing, composition, primitive recursion and unbounded search. That is the right notion of relative computability, but diagonal constructions need an enumeration of the oracle computations together with finite, stage-bounded approximations. This file supplies both: an oracle analogue Nat.RecursiveIn.Code of Mathlib's Nat.Partrec.Code, with evaluation Code.eval g relative to an oracle g and stage-bounded evaluation Code.evaln σ k against a finite oracle prefix σ : List ℕ.

The stage-bounded evaluator queries the oracle only below the stage: at stage k it reads at most the first k entries of σ (Code.evaln_take). Its completeness for total oracles gives the use principle (Code.exists_use): a convergent oracle computation depends on only finitely many oracle values.

Main definitions #

Main results #

Implementation notes #

The open Mathlib PR mathlib4#38973 (Mathlib/Computability/SingleOracle) proposes overlapping infrastructure: oracle codes Oracle.Single.Code with eval and a relativized evaln, a code for evaln, and the jump, related back to RecursiveIn. Its oracles are total functions and its evaln reads the whole oracle. Nothing here is ported from it. This file instead builds on merged Mathlib's Nat.RecursiveIn with partial oracles, and its evaln runs against a finite prefix List ℕ, which gives evaln_take and exists_use directly. Upstreaming must be reconciled with that PR, which CONTRIBUTING.md lists among the upstream coordination threads.

References #

Codes for computations relative to an oracle. The constructors mirror the constructors of Nat.RecursiveIn, with oracle standing for the single oracle g passed to Code.eval. The rfind' constructor follows Mathlib's Nat.Partrec.Code.rfind'.

Instances For

    The Gödel numbering of oracle codes, following Nat.Partrec.Code.encodeCode with the extra atomic code oracle numbered 4.

    @[irreducible]

    The inverse of encodeCode.

    @[instance_reducible]

    Oracle codes are denumerable, via encodeCode and ofNatCode.

    The evaluation of an oracle code relative to the oracle g. Apart from the oracle case, which returns g, this is Mathlib's Nat.Partrec.Code.eval.

    Embed a code for an ordinary partial recursive function into the oracle code language.

    @[simp]

    The embedded code computes the original function relative to any oracle.

    Unbounded search with initial offset zero, taking the search parameter as its input.

    theorem Nat.RecursiveIn.Code.eval_rfind (g : ℕ →. ℕ) (c : Code) (a : ℕ) :
    eval g c.rfind a = Nat.rfind fun (n : ℕ) => (fun (m : ℕ) => decide (m = 0)) <$> eval g c (Nat.pair a n)

    Ordinary unbounded search finds the least trial for which the trial code outputs zero.

    @[irreducible]

    Stage-bounded evaluation of an oracle code against the finite oracle prefix σ. evaln σ k c n is defined only for inputs n < k, it runs with recursion depth bounded by k, and an oracle query at n returns σ[n]?, so it fails if σ is too short. This is Mathlib's Nat.Partrec.Code.evaln with an oracle case.

    theorem Nat.RecursiveIn.Code.evaln_bound {σ : List ℕ} {k : ℕ} {c : Code} {n x : ℕ} :
    x ∈ evaln σ k c n → n < k

    A stage-k computation is defined only on inputs below k.

    theorem Nat.RecursiveIn.Code.evaln_mono_of_agree {σ₁ σ₂ : List ℕ} {K : ℕ} (hσ : ∀ i < K, ∀ (y : ℕ), σ₁[i]? = some y → σ₂[i]? = some y) {k₁ k₂ : ℕ} {c : Code} {n x : ℕ} :
    k₁ ≤ K → k₁ ≤ k₂ → x ∈ evaln σ₁ k₁ c n → x ∈ evaln σ₂ k₂ c n

    Monotonicity of stage-bounded evaluation in the stage and the oracle prefix, where the larger prefix need only agree with the smaller one below the smaller stage.

    theorem Nat.RecursiveIn.Code.evaln_mono {σ₁ σ₂ : List ℕ} (hσ : σ₁ <+: σ₂) {k₁ k₂ : ℕ} {c : Code} {n x : ℕ} (hl : k₁ ≤ k₂) (h : x ∈ evaln σ₁ k₁ c n) :
    x ∈ evaln σ₂ k₂ c n

    Stage-bounded evaluation is monotone in the stage and in the oracle prefix.

    theorem Nat.RecursiveIn.Code.evaln_take (σ : List ℕ) (k : ℕ) (c : Code) (n : ℕ) :
    evaln (List.take k σ) k c n = evaln σ k c n

    The use of a stage-k computation is below k: it reads only the first k oracle values.

    theorem Nat.RecursiveIn.Code.evaln_sound {g : ℕ →. ℕ} {σ : List ℕ} (hσ : ∀ (i : ℕ) (h : i < σ.length), σ[i] ∈ g i) {k : ℕ} {c : Code} {n x : ℕ} :
    x ∈ evaln σ k c n → x ∈ eval g c n

    Soundness of stage-bounded evaluation: a result computed against the prefix σ is a value of the evaluation relative to every oracle g extending σ.

    The prefix of length N of a total oracle f, as a list of values f 0, …, f (N - 1).

    @[simp]
    @[simp]
    theorem Nat.RecursiveIn.Code.getElem_prefixOf (f : ℕ → ℕ) {N i : ℕ} (h : i < (prefixOf f N).length) :
    (prefixOf f N)[i] = f i
    theorem Nat.RecursiveIn.Code.prefixOf_prefix (f : ℕ → ℕ) {N₁ N₂ : ℕ} (h : N₁ ≤ N₂) :
    prefixOf f N₁ <+: prefixOf f N₂
    theorem Nat.RecursiveIn.Code.prefixOf_mem (f : ℕ → ℕ) (N i : ℕ) (h : i < (prefixOf f N).length) :
    (prefixOf f N)[i] ∈ ↑f i

    Every total oracle extends each of its prefixes.

    theorem Nat.RecursiveIn.Code.evaln_complete {f : ℕ → ℕ} {c : Code} {n x : ℕ} :
    x ∈ eval (↑f) c n ↔ ∃ (N : ℕ) (k : ℕ), x ∈ evaln (prefixOf f N) k c n

    Completeness of stage-bounded evaluation for total oracles: every convergent computation relative to f converges at some stage against some finite prefix of f.

    theorem Nat.RecursiveIn.Code.mem_eval_iff_exists_evaln {f : ℕ → ℕ} {c : Code} {n x : ℕ} :
    x ∈ eval (↑f) c n ↔ ∃ (s : ℕ), x ∈ evaln (prefixOf f s) s c n

    Completeness with a single stage parameter: a convergent computation relative to the total oracle f converges at some stage s against the prefix of f of length s.

    theorem Nat.RecursiveIn.Code.eval_eq_rfindOpt (f : ℕ → ℕ) (c : Code) (n : ℕ) :
    eval (↑f) c n = rfindOpt fun (s : ℕ) => evaln (prefixOf f s) s c n

    Evaluation relative to a total oracle is the limit of the stage-bounded approximations.

    theorem Nat.RecursiveIn.Code.exists_use {f : ℕ → ℕ} {c : Code} {n x : ℕ} (h : x ∈ eval (↑f) c n) :
    ∃ (N : ℕ), ∀ (g : ℕ → ℕ), (∀ i < N, g i = f i) → x ∈ eval (↑g) c n

    The use principle: if a computation relative to the total oracle f converges, then there is a bound N such that the computation converges to the same value relative to every total oracle agreeing with f below N.

    theorem Nat.RecursiveIn.rfind' {O : Set (ℕ →. ℕ)} {f : ℕ →. ℕ} (hf : Nat.RecursiveIn O f) :
    Nat.RecursiveIn O (unpaired fun (a m : ℕ) => Part.map (fun (x : ℕ) => x + m) (Nat.rfind fun (n : ℕ) => (fun (m : ℕ) => decide (m = 0)) <$> f (Nat.pair a (n + m))))

    Nat.RecursiveIn O is closed under the unbounded search with offset used by Code.rfind'.

    A partial function is recursive in the single oracle g if and only if it is the evaluation of some oracle code relative to g. This is the oracle analogue of Nat.Partrec.Code.exists_code.

    f ≤ᵀ g holds if and only if f is the evaluation of some oracle code relative to g.

    Only countably many partial functions are Turing reducible to a given oracle.

    A Turing degree has only countably many degrees below it.