A universal oracle code for partial oracles #
There is a single oracle code u that, relative to every partial oracle g : ℕ →. ℕ, evaluates
the code with index e at n: eval g u ⟨e, n⟩ = eval g (ofNat Code e) n
(Nat.RecursiveIn.Code.exists_universal_partial). The code does not depend on the oracle. This
is the relativized enumeration theorem for the semantics of Code.eval, in which a query at a
point where the oracle is undefined diverges.
The universal code for total oracles, Code.exists_universal, searches over stages and reads an
oracle prefix, so it queries points that the simulated computation may never query; relative to a
partial oracle that search can diverge on a convergent computation. The code here queries the
oracle only on demand. It keeps a finite table of the answers obtained so far and runs the
simulated code against the table (Code.evalAsk). The run either finishes, or stops at the first
query the table cannot answer; the code then asks the oracle at that point, records the answer,
and runs again.
- Soundness (
Code.evalAsk_sound): against a table that agrees withg, a finished run gives a value ofeval g c n, and a request is at a point outside the table. - Completeness (
Code.evalAsk_complete): ifeval g c nconverges tox, there is a boundNsuch that against every table agreeing withgthe run finishes withxor requests a pointq < Noutside the table at whichgis defined. So every query of the simulation is a query of the real computation, and after at mostNnew answers the run finishes.
A run against a table is itself an oracle computation relative to a total oracle that presents the table. The code for it is a primitive recursive translation of the simulated code, and the universal code for total oracles evaluates it.
Main definitions #
Nat.RecursiveIn.Code.evalAsk: the run of a code against an answer table.
Main results #
Nat.RecursiveIn.Code.evalAsk_sound,Nat.RecursiveIn.Code.evalAsk_complete: runs against tables agreeing with the oracle computeeval, and request only answers the computation uses.Nat.RecursiveIn.Code.exists_universal_partial: a universal code for all partial oracles.
Implementation notes #
Cslib.ClockedComp.exists_code_eval in RecursiveInClocked.lean turns a family of oracle
programs with a computable dialogue into one code for all partial oracles, and each compiled
code has a computable dialogue. A universal code would need the dialogue of all compiled codes
to be computable jointly in the code, which that file does not prove; this file instead compiles
runs against tables into codes and uses the universal code for total oracles.
Relation to the unrelativized enumeration theorem #
Kleene's enumeration theorem gives one partial recursive function that evaluates every partial
recursive function from its index and argument [Kle43]; it has no oracle. The Lean statement
∃ u, ∀ g e n, eval g u (Nat.pair e n) = eval g (ofNat Code e) n extends it in two ways.
- Semantics. The evaluated functions are those of oracle codes relative to a partial oracle
g, in the library's sequential oracle-code semanticsCode.eval g: oracle answers are bound withPart.bindalong the run of the code,preciterates from0,rfind'tests0, 1, 2, …and stops at the first zero, and a query at a point wheregis undefined makes the whole computation diverge. A computation converges only if every query on its run is answered, soumust not queryganywhere else; it queries only the points that the simulated run requests. - Quantifier order. The universal code
uis chosen before the oracle: the sameuworks for every partial oracleg, every indexeand every inputn. Without the oracle, this is Kleene's statement: one fixed evaluator for all indices and arguments.
References #
- S. C. Kleene, Recursive predicates and quantifiers, §10, equation (35), p. 58
(checked):
φ(x₁, …, xₙ) ≃ Φₙ(e, x₁, …, xₙ)for every partial recursiveφwith Gödel numbere, whereΦₙ(z, x₁, …, xₙ) = U(μy Tₙ(z, x₁, …, xₙ, y))is a fixed partial recursive function; soΦₙenumerates the partial recursive functions ofnvariables. - Y. N. Moschovakis, Kleene's amazing second recursion theorem, p. 190
(checked): universal partial functions
φⁿwithφⁿ(e, x⃗) = {e}(x⃗), which, for the recursion theorem, Kleene takes from his enumeration theorem.
Runs against an answer table #
Evaluation of a code against the answer table h : ℕ → Option ℕ, in the order in which
Code.eval runs the computation. The run returns inr v if it finishes with v using only
answers in h, and inl q at the first query q that h does not answer.
Soundness of runs against an answer table. If the table h agrees with the oracle g
wherever it answers, a finished run against h gives a value of the evaluation relative to g,
and a request is at a point that h does not answer.
Completeness of runs against an answer table. If a computation relative to g
converges to x, there is a bound N such that against every table h agreeing with g, the
run either finishes with x or requests an answer at a point q < N that h does not answer and
where g is defined.
Compiling runs against an answer table into codes #
Asking the oracle on demand #
The universal code #
A universal oracle code for partial oracles. One code u evaluates, relative to every
partial oracle g, the code with index e at n when given Nat.pair e n. The code does not
depend on the oracle. Relativized form of Kleene's enumeration theorem [Kle43].