Theorem: Nat.Primrec'.to_prim
File: Mathlib/Computability/Primrec.lean

tactic: induction pf
state_before: n : ℕ
f : Vector ℕ n → ℕ
pf : Primrec' f
⊢ Primrec f

tactic: case zero => exact .const 0
state_before: case zero
n : ℕ
f : Vector ℕ n → ℕ
⊢ Primrec fun x => 0

case succ
n : ℕ
f : Vector ℕ n → ℕ
⊢ Primrec fun v => Nat.succ (head v)

case get
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
i✝ : Fin n✝
⊢ Primrec fun v => Vector.get v i✝

case comp
n : ℕ
f : Vector ℕ n → ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Fin n✝ → Vector ℕ m✝ → ℕ
a✝¹ : Primrec' f✝
a✝ : ∀ (i : Fin n✝), Primrec' (g✝ i)
a_ih✝¹ : Primrec f✝
a_ih✝ : ∀ (i : Fin n✝), Primrec (g✝ i)
⊢ Primrec fun a => f✝ (ofFn fun i => g✝ i a)

case prec
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Vector ℕ (n✝ + 2) → ℕ
a✝¹ : Primrec' f✝
a✝ : Primrec' g✝
a_ih✝¹ : Primrec f✝
a_ih✝ : Primrec g✝
⊢ Primrec fun v => Nat.rec (f✝ (tail v)) (fun y IH => g✝ (y ::ᵥ IH ::ᵥ tail v)) (head v)

tactic: case succ => exact _root_.Primrec.succ.comp .vector_head
state_before: case succ
n : ℕ
f : Vector ℕ n → ℕ
⊢ Primrec fun v => Nat.succ (head v)

case get
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
i✝ : Fin n✝
⊢ Primrec fun v => Vector.get v i✝

case comp
n : ℕ
f : Vector ℕ n → ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Fin n✝ → Vector ℕ m✝ → ℕ
a✝¹ : Primrec' f✝
a✝ : ∀ (i : Fin n✝), Primrec' (g✝ i)
a_ih✝¹ : Primrec f✝
a_ih✝ : ∀ (i : Fin n✝), Primrec (g✝ i)
⊢ Primrec fun a => f✝ (ofFn fun i => g✝ i a)

case prec
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Vector ℕ (n✝ + 2) → ℕ
a✝¹ : Primrec' f✝
a✝ : Primrec' g✝
a_ih✝¹ : Primrec f✝
a_ih✝ : Primrec g✝
⊢ Primrec fun v => Nat.rec (f✝ (tail v)) (fun y IH => g✝ (y ::ᵥ IH ::ᵥ tail v)) (head v)

tactic: case get n i => exact Primrec.vector_get.comp .id (.const i)
state_before: case get
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
i✝ : Fin n✝
⊢ Primrec fun v => Vector.get v i✝

case comp
n : ℕ
f : Vector ℕ n → ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Fin n✝ → Vector ℕ m✝ → ℕ
a✝¹ : Primrec' f✝
a✝ : ∀ (i : Fin n✝), Primrec' (g✝ i)
a_ih✝¹ : Primrec f✝
a_ih✝ : ∀ (i : Fin n✝), Primrec (g✝ i)
⊢ Primrec fun a => f✝ (ofFn fun i => g✝ i a)

case prec
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Vector ℕ (n✝ + 2) → ℕ
a✝¹ : Primrec' f✝
a✝ : Primrec' g✝
a_ih✝¹ : Primrec f✝
a_ih✝ : Primrec g✝
⊢ Primrec fun v => Nat.rec (f✝ (tail v)) (fun y IH => g✝ (y ::ᵥ IH ::ᵥ tail v)) (head v)

tactic: case comp m n f g _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i)
state_before: case comp
n : ℕ
f : Vector ℕ n → ℕ
m✝ n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Fin n✝ → Vector ℕ m✝ → ℕ
a✝¹ : Primrec' f✝
a✝ : ∀ (i : Fin n✝), Primrec' (g✝ i)
a_ih✝¹ : Primrec f✝
a_ih✝ : ∀ (i : Fin n✝), Primrec (g✝ i)
⊢ Primrec fun a => f✝ (ofFn fun i => g✝ i a)

case prec
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Vector ℕ (n✝ + 2) → ℕ
a✝¹ : Primrec' f✝
a✝ : Primrec' g✝
a_ih✝¹ : Primrec f✝
a_ih✝ : Primrec g✝
⊢ Primrec fun v => Nat.rec (f✝ (tail v)) (fun y IH => g✝ (y ::ᵥ IH ::ᵥ tail v)) (head v)

tactic: case prec n f g _ _ hf hg =>
  exact
    .nat_rec' .vector_head (hf.comp Primrec.vector_tail)
      (hg.comp <|
        Primrec.vector_cons.comp (Primrec.fst.comp .snd) <|
        Primrec.vector_cons.comp (Primrec.snd.comp .snd) <|
          (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂
state_before: case prec
n : ℕ
f : Vector ℕ n → ℕ
n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
g✝ : Vector ℕ (n✝ + 2) → ℕ
a✝¹ : Primrec' f✝
a✝ : Primrec' g✝
a_ih✝¹ : Primrec f✝
a_ih✝ : Primrec g✝
⊢ Primrec fun v => Nat.rec (f✝ (tail v)) (fun y IH => g✝ (y ::ᵥ IH ::ᵥ tail v)) (head v)

tactic: exact .const 0
state_before: n : ℕ
f : Vector ℕ n → ℕ
⊢ Primrec fun x => 0

tactic: exact _root_.Primrec.succ.comp .vector_head
state_before: n : ℕ
f : Vector ℕ n → ℕ
⊢ Primrec fun v => Nat.succ (head v)

tactic: exact Primrec.vector_get.comp .id (.const i)
state_before: n✝ : ℕ
f : Vector ℕ n✝ → ℕ
n : ℕ
i : Fin n
⊢ Primrec fun v => Vector.get v i

tactic: exact hf.comp (.vector_ofFn fun i => hg i)
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
m n : ℕ
f : Vector ℕ n → ℕ
g : Fin n → Vector ℕ m → ℕ
a✝¹ : Primrec' f
a✝ : ∀ (i : Fin n), Primrec' (g i)
hf : Primrec f
hg : ∀ (i : Fin n), Primrec (g i)
⊢ Primrec fun a => f (ofFn fun i => g i a)

tactic: exact
  .nat_rec' .vector_head (hf.comp Primrec.vector_tail)
    (hg.comp <|
      Primrec.vector_cons.comp (Primrec.fst.comp .snd) <|
      Primrec.vector_cons.comp (Primrec.snd.comp .snd) <|
        (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂
state_before: n✝ : ℕ
f✝ : Vector ℕ n✝ → ℕ
n : ℕ
f : Vector ℕ n → ℕ
g : Vector ℕ (n + 2) → ℕ
a✝¹ : Primrec' f
a✝ : Primrec' g
hf : Primrec f
hg : Primrec g
⊢ Primrec fun v => Nat.rec (f (tail v)) (fun y IH => g (y ::ᵥ IH ::ᵥ tail v)) (head v)