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.
- Code to program.
Code.toClockedcompiles a code constructor by constructor: composition isbind, primitive recursion is Lean recursion, and unbounded search isClockedComp.rfind. The compiled program computes the code relative to every partial oracle (eval_toClocked); it does not depend on the oracle. - Program to code. A clocked program is a shallow embedding: its continuations are arbitrary
Lean functions, so a program may compute a function that is not recursive in its oracle. The
admissible programs are those whose dialogue is computable (
ClockedComp.dialogue): the next move (query or result) for each input, fuel and list of answers received so far. Such a family is an oracle machine: its control is computable and only the answers come from the oracle. Such a family is computed by a single code relative to every partial oracle (ClockedComp.exists_code_eval). The code runs the definition ofClockedComp.eval: it searches for the least fuel that finishes, and runs each fuel by iterating the dialogue (OracleComp.interpret_eq_rfind). - Characterization. Relative to a partial oracle
g, a partial function is recursive ingiff some family of clocked programs with computable dialogue computes it againstg(recursiveIn_iff_exists_clockedComp). The forward direction istoClocked, whose dialogue is computable (Code.computable_dialogue_toClocked). The proof goes through the play of a family (ClockedComp.play), the next move together with the answers left over, whose computability is closed underpure, queries,bind,map,rfindand iteratedbind.
Main definitions #
Cslib.natOracleSpec: the interface of a single oracleℕ →. ℕ.Cslib.OracleComp.nextMove,Cslib.OracleComp.replies: the next move of a program after given answers, and the answers it has received after a number of steps.Cslib.OracleComp.play: the next move, with the answers a finished program has not used.Cslib.ClockedComp.dialogue,Cslib.ClockedComp.play: the dialogue and the play of a family of clocked programs.Nat.RecursiveIn.Code.toClocked: the clocked program of a code.
Main results #
Cslib.OracleComp.interpret_eq_rfind: running a program is iterating its dialogue.Nat.RecursiveIn.Code.eval_toClocked: code to program, for every partial oracle.Cslib.ClockedComp.exists_code_eval,Cslib.ClockedComp.recursiveIn_eval: program to code, with one code for every partial oracle.Cslib.ClockedComp.computable_play_bind,.computable_play_rfind,.computable_play_natRecand their siblings: computable plays are closed under the program constructors.Nat.RecursiveIn.Code.computable_dialogue_toClocked: compiled programs have computable dialogues.Nat.RecursiveIn.Code.recursiveIn_iff_exists_clockedComp: recursiveness in a partial oracle is computability by clocked programs querying it.
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).
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.
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.
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.
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.
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.
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.
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.