Theorem: Nat.Partrec'.to_part
File: Mathlib/Computability/Halting.lean

tactic: induction pf
state_before: n : ℕ
f : Vector ℕ n →. ℕ
pf : Partrec' f
⊢ _root_.Partrec f

tactic: case prim n f hf => exact hf.to_prim.to_comp
state_before: case prim
n : ℕ
f : Vector ℕ n →. ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
a✝ : Primrec' f✝
⊢ _root_.Partrec ↑f✝

case comp
n : ℕ
f : Vector ℕ n →. ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
g✝ : Fin n✝ → Vector ℕ m✝ →. ℕ
a✝¹ : Partrec' f✝
a✝ : ∀ (i : Fin n✝), Partrec' (g✝ i)
a_ih✝¹ : _root_.Partrec f✝
a_ih✝ : ∀ (i : Fin n✝), _root_.Partrec (g✝ i)
⊢ _root_.Partrec fun v => (mOfFn fun i => g✝ i v) >>= f✝

case rfind
n : ℕ
f : Vector ℕ n →. ℕ
n✝ : ℕ
f✝ : Vector ℕ (n✝ + 1) → ℕ
a✝ : Partrec' ↑f✝
a_ih✝ : _root_.Partrec ↑f✝
⊢ _root_.Partrec fun v => Nat.rfind fun n => Part.some (decide (f✝ (n ::ᵥ v) = 0))

tactic: case comp m n f g _ _ hf hg => exact (Partrec.vector_mOfFn fun i => hg i).bind (hf.comp snd)
state_before: case comp
n : ℕ
f : Vector ℕ n →. ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
g✝ : Fin n✝ → Vector ℕ m✝ →. ℕ
a✝¹ : Partrec' f✝
a✝ : ∀ (i : Fin n✝), Partrec' (g✝ i)
a_ih✝¹ : _root_.Partrec f✝
a_ih✝ : ∀ (i : Fin n✝), _root_.Partrec (g✝ i)
⊢ _root_.Partrec fun v => (mOfFn fun i => g✝ i v) >>= f✝

case rfind
n : ℕ
f : Vector ℕ n →. ℕ
n✝ : ℕ
f✝ : Vector ℕ (n✝ + 1) → ℕ
a✝ : Partrec' ↑f✝
a_ih✝ : _root_.Partrec ↑f✝
⊢ _root_.Partrec fun v => Nat.rfind fun n => Part.some (decide (f✝ (n ::ᵥ v) = 0))

tactic: case rfind n f _ hf =>
  have := hf.comp (vector_cons.comp snd fst)
  have :=
    ((Primrec.eq.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
      this).to₂.partrec₂
  exact _root_.Partrec.rfind this
state_before: case rfind
n : ℕ
f : Vector ℕ n →. ℕ
n✝ : ℕ
f✝ : Vector ℕ (n✝ + 1) → ℕ
a✝ : Partrec' ↑f✝
a_ih✝ : _root_.Partrec ↑f✝
⊢ _root_.Partrec fun v => Nat.rfind fun n => Part.some (decide (f✝ (n ::ᵥ v) = 0))

tactic: exact hf.to_prim.to_comp
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
n : ℕ
f : Vector ℕ n → ℕ
hf : Primrec' f
⊢ _root_.Partrec ↑f

tactic: exact (Partrec.vector_mOfFn fun i => hg i).bind (hf.comp snd)
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
m n : ℕ
f : Vector ℕ n →. ℕ
g : Fin n → Vector ℕ m →. ℕ
a✝¹ : Partrec' f
a✝ : ∀ (i : Fin n), Partrec' (g i)
hf : _root_.Partrec f
hg : ∀ (i : Fin n), _root_.Partrec (g i)
⊢ _root_.Partrec fun v => (mOfFn fun i => g i v) >>= f

tactic: have := hf.comp (vector_cons.comp snd fst)
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
n : ℕ
f : Vector ℕ (n + 1) → ℕ
a✝ : Partrec' ↑f
hf : _root_.Partrec ↑f
⊢ _root_.Partrec fun v => Nat.rfind fun n_1 => Part.some (decide (f (n_1 ::ᵥ v) = 0))

tactic: have :=
  ((Primrec.eq.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
    this).to₂.partrec₂
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
n : ℕ
f : Vector ℕ (n + 1) → ℕ
a✝ : Partrec' ↑f
hf : _root_.Partrec ↑f
this : _root_.Partrec fun a => ↑f (a.snd ::ᵥ a.fst)
⊢ _root_.Partrec fun v => Nat.rfind fun n_1 => Part.some (decide (f (n_1 ::ᵥ v) = 0))

tactic: exact _root_.Partrec.rfind this
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ →. ℕ
n : ℕ
f : Vector ℕ (n + 1) → ℕ
a✝ : Partrec' ↑f
hf : _root_.Partrec ↑f
this✝ : _root_.Partrec fun a => ↑f (a.snd ::ᵥ a.fst)
this : Partrec₂ fun a => ↑fun b => decide ((fun a => id a = 0) (f ((a, b).snd ::ᵥ (a, b).fst)))
⊢ _root_.Partrec fun v => Nat.rfind fun n_1 => Part.some (decide (f (n_1 ::ᵥ v) = 0))