# Gödel Numbering for Partial Recursive Functions. #

This file defines Nat.Partrec.Code, an inductive datatype describing code for partial recursive functions on ℕ. It defines an encoding for these codes, and proves that the constructors are primitive recursive with respect to the encoding.

It also defines the evaluation of these codes as partial functions using PFun, and proves that a function is partially recursive (as defined by Nat.Partrec) if and only if it is the evaluation of some code.

## Main Definitions #

• Nat.Partrec.Code: Inductive datatype for partial recursive codes.
• Nat.Partrec.Code.encodeCode: A (computable) encoding of codes as natural numbers.
• Nat.Partrec.Code.ofNatCode: The inverse of this encoding.
• Nat.Partrec.Code.eval: The interpretation of a Nat.Partrec.Code as a partial function.

## Main Results #

• Nat.Partrec.Code.rec_prim: Recursion on Nat.Partrec.Code is primitive recursive.
• Nat.Partrec.Code.rec_computable: Recursion on Nat.Partrec.Code is computable.
• Nat.Partrec.Code.smn: The $S_n^m$ theorem.
• Nat.Partrec.Code.exists_code: Partial recursiveness is equivalent to being the eval of a code.
• Nat.Partrec.Code.evaln_prim: evaln is primitive recursive.
• Nat.Partrec.Code.fixed_point: Roger's fixed point theorem.

## References #

theorem Nat.Partrec.rfind' {f : } (hf : ) :
Nat.Partrec (Nat.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)))) Code for partial recursive functions from ℕ to ℕ. See Nat.Partrec.Code.eval for the interpretation of these constructors. Instances For Returns a code for the constant function outputting a particular natural. Equations Instances For theorem Nat.Partrec.Code.const_inj {n₁ : } {n₂ : } : n₁ = n₂ A code for the identity function. Equations Instances For Given a code c taking a pair as input, returns a code using n as the first argument to c. Equations Instances For An encoding of a Nat.Partrec.Code as a ℕ. Equations Instances For @[irreducible] A decoder for Nat.Partrec.Code.encodeCode, taking any ℕ to the Nat.Partrec.Code it represents. Equations • One or more equations did not get rendered due to their size. Instances For Equations • One or more equations did not get rendered due to their size. theorem Nat.Partrec.Code.rec_prim' {α : Type u_1} {σ : Type u_2} [] [] {c : } (hc : ) {z : ασ} (hz : ) {s : ασ} (hs : ) {l : ασ} (hl : ) {r : ασ} (hr : ) {pr : ασ} (hpr : Primrec₂ pr) {co : ασ} (hco : Primrec₂ co) {pc : ασ} (hpc : Primrec₂ pc) {rf : ασ} (hrf : Primrec₂ rf) : let PR := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => pr a (cf, cg, hf, hg); let CO := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => co a (cf, cg, hf, hg); let PC := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => pc a (cf, cg, hf, hg); let RF := fun (a : α) (cf : Nat.Partrec.Code) (hf : σ) => rf a (cf, hf); let F := fun (a : α) (c : Nat.Partrec.Code) => Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a); Primrec fun (a : α) => F a (c a) theorem Nat.Partrec.Code.rec_prim {α : Type u_1} {σ : Type u_2} [] [] {c : } (hc : ) {z : ασ} (hz : ) {s : ασ} (hs : ) {l : ασ} (hl : ) {r : ασ} (hr : ) {pr : αNat.Partrec.CodeNat.Partrec.Codeσσσ} (hpr : Primrec fun (a : α × ) => pr a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {co : αNat.Partrec.CodeNat.Partrec.Codeσσσ} (hco : Primrec fun (a : α × ) => co a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {pc : αNat.Partrec.CodeNat.Partrec.Codeσσσ} (hpc : Primrec fun (a : α × ) => pc a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {rf : αNat.Partrec.Codeσσ} (hrf : Primrec fun (a : ) => rf a.1 a.2.1 a.2.2) : let F := fun (a : α) (c : Nat.Partrec.Code) => Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (pr a) (co a) (pc a) (rf a); Primrec fun (a : α) => F a (c a) Recursion on Nat.Partrec.Code is primitive recursive. theorem Nat.Partrec.Code.rec_computable {α : Type u_1} {σ : Type u_2} [] [] {c : } (hc : ) {z : ασ} (hz : ) {s : ασ} (hs : ) {l : ασ} (hl : ) {r : ασ} (hr : ) {pr : ασ} (hpr : ) {co : ασ} (hco : ) {pc : ασ} (hpc : ) {rf : ασ} (hrf : ) : let PR := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => pr a (cf, cg, hf, hg); let CO := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => co a (cf, cg, hf, hg); let PC := fun (a : α) (cf cg : Nat.Partrec.Code) (hf hg : σ) => pc a (cf, cg, hf, hg); let RF := fun (a : α) (cf : Nat.Partrec.Code) (hf : σ) => rf a (cf, hf); let F := fun (a : α) (c : Nat.Partrec.Code) => Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a); Computable fun (a : α) => F a (c a) Recursion on Nat.Partrec.Code is computable. The interpretation of a Nat.Partrec.Code as a partial function. • Nat.Partrec.Code.zero: The constant zero function. • Nat.Partrec.Code.succ: The successor function. • Nat.Partrec.Code.left: Left unpairing of a pair of ℕ (encoded by Nat.pair) • Nat.Partrec.Code.right: Right unpairing of a pair of ℕ (encoded by Nat.pair) • Nat.Partrec.Code.pair: Pairs the outputs of argument codes using Nat.pair. • Nat.Partrec.Code.comp: Composition of two argument codes. • Nat.Partrec.Code.prec: Primitive recursion. Given an argument of the form Nat.pair a n: • If n = 0, returns eval cf a. • If n = succ k, returns eval cg (pair a (pair k (eval (prec cf cg) (pair a k)))) • Nat.Partrec.Code.rfind': Minimization. For f an argument of the form Nat.pair a m, rfind' f m returns the least a such that f a m = 0, if one exists and f b m terminates for b < a Equations Instances For @[simp] theorem Nat.Partrec.Code.eval_prec_zero (cf : Nat.Partrec.Code) (cg : Nat.Partrec.Code) (a : ) : (cf.prec cg).eval (Nat.pair a 0) = cf.eval a Helper lemma for the evaluation of prec in the base case. theorem Nat.Partrec.Code.eval_prec_succ (cf : Nat.Partrec.Code) (cg : Nat.Partrec.Code) (a : ) (k : ) : (cf.prec cg).eval (Nat.pair a k.succ) = do let ih(cf.prec cg).eval (Nat.pair a k) cg.eval (Nat.pair a (Nat.pair k ih)) Helper lemma for the evaluation of prec in the recursive case. Equations @[simp] theorem Nat.Partrec.Code.eval_const (n : ) (m : ) : .eval m = @[simp] theorem Nat.Partrec.Code.eval_curry (c : Nat.Partrec.Code) (n : ) (x : ) : (c.curry n).eval x = c.eval (Nat.pair n x) theorem Nat.Partrec.Code.curry_inj {c₁ : Nat.Partrec.Code} {c₂ : Nat.Partrec.Code} {n₁ : } {n₂ : } (h : c₁.curry n₁ = c₂.curry n₂) : c₁ = c₂ n₁ = n₂ theorem Nat.Partrec.Code.smn : ∃ (f : ), ∀ (c : Nat.Partrec.Code) (n x : ), (f c n).eval x = c.eval (Nat.pair n x) The$S_n^m\$ theorem: There is a computable function, namely Nat.Partrec.Code.curry, that takes a program and a ℕ n, and returns a new program using n as the first argument.

theorem Nat.Partrec.Code.exists_code {f : } :
∃ (c : Nat.Partrec.Code), c.eval = f

A function is partial recursive if and only if there is a code implementing it. Therefore, eval is a universal partial recursive function.

@[irreducible]

A modified evaluation for the code which returns an Option ℕ instead of a Part ℕ. To avoid undecidability, evaln takes a parameter k and fails if it encounters a number ≥ k in the course of its execution. Other than this, the semantics are the same as in Nat.Partrec.Code.eval.

Equations
Instances For
theorem Nat.Partrec.Code.evaln_bound {k : } {c : Nat.Partrec.Code} {n : } {x : } :
x n < k
theorem Nat.Partrec.Code.evaln_mono {k₁ : } {k₂ : } {c : Nat.Partrec.Code} {n : } {x : } :
k₁ k₂x x
theorem Nat.Partrec.Code.evaln_sound {k : } {c : Nat.Partrec.Code} {n : } {x : } :
x x c.eval n
theorem Nat.Partrec.Code.evaln_complete {c : Nat.Partrec.Code} {n : } {x : } :
x c.eval n ∃ (k : ), x
theorem Nat.Partrec.Code.evaln_prim :
Primrec fun (a : ) => Nat.Partrec.Code.evaln a.1.1 a.1.2 a.2

The Nat.Partrec.Code.evaln function is primitive recursive.

theorem Nat.Partrec.Code.fixed_point {f : } (hf : ) :
∃ (c : Nat.Partrec.Code), (f c).eval = c.eval

Roger's fixed-point theorem: Any total, computable f has a fixed point: That is, under the interpretation given by Nat.Partrec.Code.eval, there is a code c such that c and f c have the same evaluation.

theorem Nat.Partrec.Code.fixed_point₂ {f : } (hf : ) :
∃ (c : Nat.Partrec.Code), c.eval = f c