Documentation

CslibFrontier.Foundations.Computability.RecursiveInJoin

The Turing join on oracle codes #

The join p ⊕ x (Partrec.join) of two oracles is their least upper bound under ≤ᵀ. This file proves the code-level, uniform form of that fact for the oracle codes Nat.RecursiveIn.Code: the reductions behind p ≤ᵀ p ⊕ x, x ≤ᵀ p ⊕ x and join_le are primitive recursive maps on codes that do not depend on the oracles.

Together, a program querying p ⊕ x corresponds to computations relative to both oracles. A code c relative to p becomes the code c.subst joinLeft relative to p ⊕ x (Code.eval_subst_joinLeft). Conversely, a code c relative to p ⊕ x, given codes a and b computing p and x from an oracle h, becomes the code c.subst (join a b) relative to h (Code.eval_subst_join). Both translations are primitive recursive in the codes and the same for all oracles; Code.exists_primrec_joinLeft, Code.exists_primrec_joinRight and Code.exists_primrec₂_join state them on indices.

Main definitions #

Main results #

Implementation notes #

Code.join a b adds two branches that a primitive recursion code guards by parity: on even inputs the first branch runs a and the second returns 0, and on odd inputs the other way round. The fallback 0 always converges, so the sum converges exactly when the selected branch does. The fixed arithmetic codes are chosen from Mathlib's Nat.Partrec.Code.exists_code, so Code.join, Code.joinLeft and Code.joinRight are noncomputable; they are still constants as far as primitive recursiveness is concerned.

References #

Substituting a code for the oracle #

Replace every oracle query of c by a call to the code d.

@[simp]
theorem Nat.RecursiveIn.Code.eval_subst (g : ℕ →. ℕ) (c d : Code) :
eval g (c.subst d) = eval (eval g d) c

Relative to g, the substituted code runs c relative to the oracle that d computes from g: the code-level form of Nat.RecursiveIn.subst.

Substitution is primitive recursive in both codes.

Fixed arithmetic codes #

noncomputable def Nat.RecursiveIn.Code.primCode {f : ℕ → ℕ} (hf : Nat.Primrec f) :

A code for a primitive recursive function, chosen once from Nat.Partrec.Code.exists_code. It does not query the oracle.

theorem Nat.RecursiveIn.Code.eval_primCode {f : ℕ → ℕ} (hf : Nat.Primrec f) (g : ℕ →. ℕ) (n : ℕ) :
eval g (primCode hf) n = Part.some (f n)

The code primCode hf computes f relative to every oracle.

theorem Nat.RecursiveIn.Code.bind_pfun (x : Part ℕ) (f : ℕ →. ℕ) :
x >>= f = x.bind fun (y : ℕ) => f y

A bind into a partial function, eta-expanded. Under the module system ℕ →. ℕ does not unfold to ℕ → Part ℕ for simp, so binds into partial functions are rewritten by this lemma before Mathlib's Part.bind lemmas apply.

Joining codes #

noncomputable def Nat.RecursiveIn.Code.join (a b : Code) :

The code for the join: relative to any oracle, join a b computes the join of what a and b compute.

@[simp]
theorem Nat.RecursiveIn.Code.eval_join (g : ℕ →. ℕ) (a b : Code) :
eval g (a.join b) = Partrec.join (eval g a) (eval g b)

Relative to every oracle g, the code join a b computes the join of the functions that a and b compute relative to g.

Joining codes is primitive recursive.

The two halves of a joined oracle #

The code that reads the oracle p from the oracle p ⊕ x.

The code that reads the oracle x from the oracle p ⊕ x.

Translating programs #

A code relative to p becomes a code relative to p ⊕ x computing the same function.

A code relative to x becomes a code relative to p ⊕ x computing the same function.

theorem Nat.RecursiveIn.Code.eval_subst_join (h : ℕ →. ℕ) (c a b : Code) :
eval h (c.subst (a.join b)) = eval (Partrec.join (eval h a) (eval h b)) c

A code c relative to p ⊕ x becomes a code relative to h, given codes a and b computing p and x from h: the code-level form of join_le.

The lift along p ≤ᵀ p ⊕ x is a primitive recursive map t on indices, the same for all oracles p and x.

The lift along x ≤ᵀ p ⊕ x is a primitive recursive map t on indices, the same for all oracles p and x.

The least upper bound property on indices: one primitive recursive j, the same for every oracle h, sends indices of p and x relative to h to an index of p ⊕ x relative to h. Composed with primrec₂_subst, it turns a program relative to p ⊕ x into one relative to h (eval_subst_join).