Programs with one oracle #
This file defines TauCeti.Oracle.Single.Code, the programs of partial recursive functions with
access to a single oracle. They are Mathlib's codes Nat.Partrec.Code with one more basic
instruction, oracle, which queries the oracle at its input. Programs are numbered by an explicit
bijection with ℕ, and TauCeti.Oracle.Single.Code.eval O c interprets the program c as a
partial function relative to an oracle O : ℕ →. ℕ. A total oracle O : ℕ → ℕ is the case
fun n => Part.some (O n), and a set oracle is the case of its characteristic function.
The main result is adequacy: for every oracle O, the partial functions computed by programs
relative to O are exactly Mathlib's Nat.RecursiveIn {O} functions. The direction from
programs to Nat.RecursiveIn transfers algorithms written as programs to Mathlib's notion; the
direction from Nat.RecursiveIn to programs transfers statements quantifying over all programs,
such as non-reducibility, back to Mathlib's notion. In particular f is Turing reducible to g
exactly when some program computes f relative to g.
This adequacy is extensional: it is a statement about one fixed oracle, and does not choose a program uniformly in the oracle.
Main definitions #
TauCeti.Oracle.Single.Code: programs with one oracle.TauCeti.Oracle.Single.Code.encodeCode,TauCeti.Oracle.Single.Code.ofNatCode: the numbering of programs and its inverse, packaged as aDenumerableinstance.TauCeti.Oracle.Single.Code.eval: the partial function computed by a program relative to an oracle.Nat.Partrec.Code.toSingleOracleCode: the query-free program of an ordinary Mathlib code.
Main results #
TauCeti.Oracle.Single.Code.primrec₂_pairand its neighbours: the program constructors are primitive recursive on numbers of programs.TauCeti.Oracle.Single.Code.encode_lt_pairand its neighbours: the components of a compound program have smaller numbers.TauCeti.Oracle.Single.Code.primrec_casesOn: case analysis on programs is primitive recursive.TauCeti.Oracle.Single.Code.mem_eval_pair,TauCeti.Oracle.Single.Code.mem_eval_rfind': the values of a pairing, and one step of a search.TauCeti.Oracle.Single.Code.eval_toSingleOracleCode: a query-free program computes the same function as the ordinary code it comes from, relative to every oracle.TauCeti.Oracle.Single.Code.exists_forall_eval_eq_of_partrec: every partial recursive function is computed by one program relative to every oracle.TauCeti.Oracle.Single.Code.exists_code: adequacy,Nat.RecursiveIn {O} f ↔ ∃ c, eval O c = f.TauCeti.Oracle.Single.Code.turingReducible_iff_exists_code: the same for Turing reducibility.
References #
- R. I. Soare, Recursively Enumerable Sets and Degrees, Springer, 1987, Chapter III.1.
- M. Carneiro, Formalizing computability theory via partial recursive functions, ITP 2019. The
numbering, the evaluation and the adequacy proof follow Mathlib's
Nat.Partrec.Code,Nat.Partrec.Code.evalandNat.Partrec.Code.exists_code, extended by the oracle instruction. - The namespace and constructors follow the shape of the single-oracle code proposed by Edwin Park in Mathlib pull request 38973.
Programs of partial recursive functions with access to one oracle. They are Mathlib's codes
Nat.Partrec.Code together with the instruction oracle, which queries the oracle at its input.
See TauCeti.Oracle.Single.Code.eval for the interpretation of the constructors.
- zero : Code
- succ : Code
- left : Code
- right : Code
- oracle : Code
- pair : Code → Code → Code
- comp : Code → Code → Code
- prec : Code → Code → Code
- rfind' : Code → Code
Instances For
Instances For
Numbering programs #
The number of a program: the five basic instructions are 0, …, 4, and a compound program is
4 * k + i + 5, where k codes its components and i < 4 its constructor.
Instances For
The program with a given number, the inverse of TauCeti.Oracle.Single.Code.encodeCode.
Instances For
Decoding a number and encoding the result gives the number back.
Encoding a program and decoding the result gives the program back.
The Denumerable encoding of programs is TauCeti.Oracle.Single.Code.encodeCode.
The Denumerable decoding of programs is TauCeti.Oracle.Single.Code.ofNatCode.
The components of a pairing have smaller numbers.
The components of a composition have smaller numbers.
The components of a primitive recursion have smaller numbers.
The component of a search has a smaller number.
Primitive recursive constructors #
Pairing programs is primitive recursive.
Composing programs is primitive recursive.
Forming the primitive recursion of two programs is primitive recursive.
Forming the search program of a program is primitive recursive.
Case analysis on programs is primitive recursive, uniformly in a parameter: the branch taken is read off the number of the program, and the branches receive its components.
Evaluation #
The partial function computed by a program relative to the oracle O.
zero,succ,left,right: zero, successor, and the two components ofNat.unpair.oracle: the oracleOitself, queried at the input.pair cf cg: pairs the outputs ofcfandcgwithNat.pair.comp cf cg: runscg, thencfon its output.prec cf cg: primitive recursion. On inputNat.pair a 0it returns the output ofcfona, and onNat.pair a (k + 1)the output ofcgonNat.pair a (Nat.pair k i), whereiis the output ofprec cf cgonNat.pair a k.rfind' cf: search from a start. On inputNat.pair a mit returns the leastn ≥ mwith output0fromcfonNat.pair a n, providedcfhalts onNat.pair a kfor everykfrommton.
Instances For
Adequacy #
Every program computes a function recursive in its oracle.
Adequacy for Turing reducibility. f is Turing reducible to g exactly when some program
computes f relative to the oracle g.
Query-free programs #
The query-free program of an ordinary Mathlib code: the same code, never using oracle.
Instances For
Nat.Partrec.Code.toSingleOracleCode is injective: distinct ordinary codes give distinct
programs.
The translation of ordinary codes into query-free programs is primitive recursive.
Query-free programs. Relative to every oracle, the program c.toSingleOracleCode computes
the same function as the ordinary code c.