Theorem: Nat.Partrec.of_primrec
File: Mathlib/Computability/Partrec.lean

tactic: induction hf with
| zero => exact zero
| succ => exact succ
| left => exact left
| right => exact right
| pair _ _ pf pg =>
  refine (pf.pair pg).of_eq_tot fun n => ?_
  simp [Seq.seq]
| comp _ _ pf pg =>
  refine (pf.comp pg).of_eq_tot fun n => ?_
  simp
| prec _ _ pf pg =>
  refine (pf.prec pg).of_eq_tot fun n => ?_
  simp only [unpaired, PFun.coe_val, bind_eq_bind]
  induction n.unpair.2 with
  | zero => simp
  | succ m IH =>
    simp only [mem_bind_iff, mem_some_iff]
    exact ⟨_, IH, rfl⟩
state_before: f : ℕ → ℕ
hf : Nat.Primrec f
⊢ Partrec ↑f
state_after: no goals

tactic: exact zero
state_before: case zero
f : ℕ → ℕ
⊢ Partrec ↑fun x => 0
state_after: no goals

tactic: exact succ
state_before: case succ
f : ℕ → ℕ
⊢ Partrec ↑Nat.succ
state_after: no goals

tactic: exact left
state_before: case left
f : ℕ → ℕ
⊢ Partrec ↑fun n => (unpair n).1
state_after: no goals

tactic: exact right
state_before: case right
f : ℕ → ℕ
⊢ Partrec ↑fun n => (unpair n).2
state_after: no goals

tactic: refine (pf.pair pg).of_eq_tot fun n => ?_
state_before: case pair
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
⊢ Partrec ↑fun n => Nat.pair (f✝ n) (g✝ n)
state_after: case pair
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ Nat.pair (f✝ n) (g✝ n) ∈ Seq.seq (Nat.pair <$> ↑f✝ n) fun x => ↑g✝ n

tactic: simp [Seq.seq]
state_before: case pair
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ Nat.pair (f✝ n) (g✝ n) ∈ Seq.seq (Nat.pair <$> ↑f✝ n) fun x => ↑g✝ n
state_after: no goals

tactic: refine (pf.comp pg).of_eq_tot fun n => ?_
state_before: case comp
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
⊢ Partrec ↑fun n => f✝ (g✝ n)
state_after: case comp
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ f✝ (g✝ n) ∈ ↑g✝ n >>= ↑f✝

tactic: simp
state_before: case comp
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ f✝ (g✝ n) ∈ ↑g✝ n >>= ↑f✝
state_after: no goals

tactic: refine (pf.prec pg).of_eq_tot fun n => ?_
state_before: case prec
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
⊢ Partrec ↑(unpaired fun z n => Nat.rec (f✝ z) (fun y IH => g✝ (Nat.pair z (Nat.pair y IH))) n)
state_after: case prec
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ unpaired (fun z n => Nat.rec (f✝ z) (fun y IH => g✝ (Nat.pair z (Nat.pair y IH))) n) n ∈
    unpaired
      (fun a n =>
        Nat.rec (↑f✝ a)
          (fun y IH => do
            let i ← IH
            ↑g✝ (Nat.pair a (Nat.pair y i)))
          n)
      n

tactic: simp only [unpaired, PFun.coe_val, bind_eq_bind]
state_before: case prec
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ unpaired (fun z n => Nat.rec (f✝ z) (fun y IH => g✝ (Nat.pair z (Nat.pair y IH))) n) n ∈
    unpaired
      (fun a n =>
        Nat.rec (↑f✝ a)
          (fun y IH => do
            let i ← IH
            ↑g✝ (Nat.pair a (Nat.pair y i)))
          n)
      n
state_after: case prec
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) (unpair n).2 ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) (unpair n).2

tactic: induction n.unpair.2 with
| zero => simp
| succ m IH =>
  simp only [mem_bind_iff, mem_some_iff]
  exact ⟨_, IH, rfl⟩
state_before: case prec
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) (unpair n).2 ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) (unpair n).2
state_after: no goals

tactic: simp
state_before: case prec.zero
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n : ℕ
⊢ Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) 0 ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) 0
state_after: no goals

tactic: simp only [mem_bind_iff, mem_some_iff]
state_before: case prec.succ
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n m : ℕ
IH :
  Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) m ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) m
⊢ Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) (m + 1) ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) (m + 1)
state_after: case prec.succ
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n m : ℕ
IH :
  Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) m ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) m
⊢ ∃
    a ∈
      Nat.rec (Part.some (f✝ (unpair n).1))
        (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) m,
    g✝
        (Nat.pair (unpair n).1
          (Nat.pair m (Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) m))) =
      g✝ (Nat.pair (unpair n).1 (Nat.pair m a))

tactic: exact ⟨_, IH, rfl⟩
state_before: case prec.succ
f f✝ g✝ : ℕ → ℕ
a✝¹ : Nat.Primrec f✝
a✝ : Nat.Primrec g✝
pf : Partrec ↑f✝
pg : Partrec ↑g✝
n m : ℕ
IH :
  Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) m ∈
    Nat.rec (Part.some (f✝ (unpair n).1))
      (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) m
⊢ ∃
    a ∈
      Nat.rec (Part.some (f✝ (unpair n).1))
        (fun y IH => IH.bind fun i => Part.some (g✝ (Nat.pair (unpair n).1 (Nat.pair y i)))) m,
    g✝
        (Nat.pair (unpair n).1
          (Nat.pair m (Nat.rec (f✝ (unpair n).1) (fun y IH => g✝ (Nat.pair (unpair n).1 (Nat.pair y IH))) m))) =
      g✝ (Nat.pair (unpair n).1 (Nat.pair m a))
state_after: no goals