l3lab/ntp-mathlib huggingface dataset:
theorem evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n
  | 0, _, n, x, h => by simp [evaln] at h
  | k + 1, c, n, x, h => by
    induction' c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n <;>
        simp [eval, evaln, Bind.bind, Seq.seq] at h ⊢ <;>
      cases' h with _ h
    iterate 4 simpa [pure, PFun.pure, eq_comm] using h
    · -- pair cf cg
      rcases h with ⟨y, ef, z, eg, rfl⟩
      exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩
    · --comp hf hg
      rcases h with ⟨y, eg, ef⟩
      exact ⟨_, hg _ _ eg, hf _ _ ef⟩
    · -- prec cf cg
      revert h
      induction' n.unpair.2 with m IH generalizing x <;> simp
      · apply hf
      · refine' fun y h₁ h₂ => ⟨y, IH _ _, _⟩
        · have := evaln_mono k.le_succ h₁
          simp [evaln, Bind.bind] at this
          exact this.2
        · exact hg _ _ h₂
    · -- rfind' cf
      rcases h with ⟨m, h₁, h₂⟩
      by_cases m0 : m = 0 <;> simp [m0] at h₂
      · exact
          ⟨0, ⟨by simpa [m0] using hf _ _ h₁, fun {m} => (Nat.not_lt_zero _).elim⟩, by
            injection h₂ with h₂; simp [h₂]⟩
      · have := evaln_sound h₂
        simp [eval] at this
        rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩
        refine'
          ⟨y + 1, ⟨by simpa [add_comm, add_left_comm] using hy₁, fun {i} im => _⟩, by
            simp [add_comm, add_left_comm]⟩
        cases' i with i
        · exact ⟨m, by simpa using hf _ _ h₁, m0⟩
        · rcases hy₂ (Nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩
          

Proof state:
case neg.intro.intro.intro.succ.intro.intro
k : ℕ
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : ¬m = 0
y : ℕ
hy₁ : 0 ∈ eval cf (Nat.pair (unpair n).1 (y + ((unpair n).2 + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a ∈ eval cf (Nat.pair (unpair n).1 (m + ((unpair n).2 + 1))), ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).1 ((unpair n).2 + 1)) = some (y + ((unpair n).2 + 1))
i : ℕ
im : Nat.succ i < y + 1
z : ℕ
hz : z ∈ eval cf (Nat.pair (unpair n).1 (i + ((unpair n).2 + 1)))
z0 : ¬z = 0
⊢ ∃ a ∈ eval cf (Nat.pair (unpair n).1 (Nat.succ i + (unpair n).2)), ¬a = 0

Next tactic:
exact ⟨z, by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hz, z0⟩
theorem evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n
  | 0, _, n, x, h => by simp [evaln] at h
  | k + 1, c, n, x, h => by
    induction' c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n <;>
        simp [eval, evaln, Bind.bind, Seq.seq] at h ⊢ <;>
      cases' h with _ h
    iterate 4 simpa [pure, PFun.pure, eq_comm] using h
    · -- pair cf cg
      rcases h with ⟨y, ef, z, eg, rfl⟩
      exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩
    · --comp hf hg
      rcases h with ⟨y, eg, ef⟩
      exact ⟨_, hg _ _ eg, hf _ _ ef⟩
    · -- prec cf cg
      revert h
      induction' n.unpair.2 with m IH generalizing x <;> simp
      · apply hf
      · refine' fun y h₁ h₂ => ⟨y, IH _ _, _⟩
        · have := evaln_mono k.le_succ h₁
          simp [evaln, Bind.bind] at this
          exact this.2
        · exact hg _ _ h₂
    · -- rfind' cf
      rcases h with ⟨m, h₁, h₂⟩
      by_cases m0 : m = 0 <;> simp [m0] at h₂
      · exact
          ⟨0, ⟨by simpa [m0] using hf _ _ h₁, fun {m} => (Nat.not_lt_zero _).elim⟩, by
            injection h₂ with h₂; simp [h₂]⟩
      · have := evaln_sound h₂
        simp [eval] at this
        rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩
        refine'
          ⟨y + 1, ⟨by simpa [add_comm, add_left_comm] using hy₁, fun {i} im => _⟩, by
            simp [add_comm, add_left_comm]⟩
        cases' i with i
        · exact ⟨m, by simpa using hf _ _ h₁, m0⟩
        · rcases hy₂ (Nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩
          exact ⟨z, by 

Proof state:
k : ℕ
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : ¬m = 0
y : ℕ
hy₁ : 0 ∈ eval cf (Nat.pair (unpair n).1 (y + ((unpair n).2 + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a ∈ eval cf (Nat.pair (unpair n).1 (m + ((unpair n).2 + 1))), ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).1 ((unpair n).2 + 1)) = some (y + ((unpair n).2 + 1))
i : ℕ
im : Nat.succ i < y + 1
z : ℕ
hz : z ∈ eval cf (Nat.pair (unpair n).1 (i + ((unpair n).2 + 1)))
z0 : ¬z = 0
⊢ z ∈ eval cf (Nat.pair (unpair n).1 (Nat.succ i + (unpair n).2))

Next tactic:
simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hz
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    

Proof state:
c : Code
n x : ℕ
h : x ∈ eval c n
⊢ ∃ k, x ∈ evaln k c n

Next tactic:
rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · 

Proof state:
case intro
c : Code
n x : ℕ
h✝ : x ∈ eval c n
k : ℕ
h : x ∈ evaln (k + 1) c n
⊢ ∃ k, x ∈ evaln k c n

Next tactic:
exact ⟨k + 1, h⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    

Proof state:
c : Code
n x : ℕ
h : x ∈ eval c n
⊢ ∃ k, x ∈ evaln (k + 1) c n

Next tactic:
induction c generalizing n x
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case zero
n x : ℕ
h : x ∈ eval zero n
⊢ ∃ k, x ∈ evaln (k + 1) zero n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case succ
n x : ℕ
h : x ∈ eval succ n
⊢ ∃ k, x ∈ evaln (k + 1) succ n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case left
n x : ℕ
h : x ∈ eval left n
⊢ ∃ k, x ∈ evaln (k + 1) left n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case right
n x : ℕ
h : x ∈ eval right n
⊢ ∃ k, x ∈ evaln (k + 1) right n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : x ∈ eval (pair a✝¹ a✝) n
⊢ ∃ k, x ∈ evaln (k + 1) (pair a✝¹ a✝) n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : x ∈ eval (comp a✝¹ a✝) n
⊢ ∃ k, x ∈ evaln (k + 1) (comp a✝¹ a✝) n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : x ∈ eval (prec a✝¹ a✝) n
⊢ ∃ k, x ∈ evaln (k + 1) (prec a✝¹ a✝) n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> 

Proof state:
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : x ∈ eval (rfind' a✝) n
⊢ ∃ k, x ∈ evaln (k + 1) (rfind' a✝) n

Next tactic:
simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    

Proof state:
case zero
n x : ℕ
h : x = 0
⊢ (∃ x, n ≤ x) ∧ 0 = x
case succ
n x : ℕ
h : x = Nat.succ n
⊢ (∃ x, n ≤ x) ∧ Nat.succ n = x
case left
n x : ℕ
h : x = (unpair n).1
⊢ (∃ x, n ≤ x) ∧ (unpair n).1 = x
case right
n x : ℕ
h : x = (unpair n).2
⊢ (∃ x, n ≤ x) ∧ (unpair n).2 = x
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
iterate 4 exact ⟨⟨_, le_rfl⟩, h.symm⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 

Proof state:
case zero
n x : ℕ
h : x = 0
⊢ (∃ x, n ≤ x) ∧ 0 = x
case succ
n x : ℕ
h : x = Nat.succ n
⊢ (∃ x, n ≤ x) ∧ Nat.succ n = x
case left
n x : ℕ
h : x = (unpair n).1
⊢ (∃ x, n ≤ x) ∧ (unpair n).1 = x
case right
n x : ℕ
h : x = (unpair n).2
⊢ (∃ x, n ≤ x) ∧ (unpair n).2 = x
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
exact ⟨⟨_, le_rfl⟩, h.symm⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 

Proof state:
case succ
n x : ℕ
h : x = Nat.succ n
⊢ (∃ x, n ≤ x) ∧ Nat.succ n = x
case left
n x : ℕ
h : x = (unpair n).1
⊢ (∃ x, n ≤ x) ∧ (unpair n).1 = x
case right
n x : ℕ
h : x = (unpair n).2
⊢ (∃ x, n ≤ x) ∧ (unpair n).2 = x
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
exact ⟨⟨_, le_rfl⟩, h.symm⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 

Proof state:
case left
n x : ℕ
h : x = (unpair n).1
⊢ (∃ x, n ≤ x) ∧ (unpair n).1 = x
case right
n x : ℕ
h : x = (unpair n).2
⊢ (∃ x, n ≤ x) ∧ (unpair n).2 = x
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
exact ⟨⟨_, le_rfl⟩, h.symm⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 

Proof state:
case right
n x : ℕ
h : x = (unpair n).2
⊢ (∃ x, n ≤ x) ∧ (unpair n).2 = x
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
exact ⟨⟨_, le_rfl⟩, h.symm⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 exact ⟨⟨_, le_rfl⟩, h.symm⟩
    

Proof state:
case pair
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝¹ n, ∃ a_1 ∈ eval a✝ n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝¹ n = some a ∧ ∃ a_1, evaln (k + 1) a✝ n = some a_1 ∧ Nat.pair a a_1 = x
case comp
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h : ∃ a ∈ eval a✝ n, x ∈ eval a✝¹ a
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) a✝ n = some a ∧ evaln (k + 1) a✝¹ a = some x
case prec
a✝¹ a✝ : Code
a_ih✝¹ : ∀ {n x : ℕ}, x ∈ eval a✝¹ n → ∃ k, x ∈ evaln (k + 1) a✝¹ n
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  x ∈
    Nat.rec (eval a✝¹ (unpair n).1) (fun y IH => Part.bind IH fun i => eval a✝ (Nat.pair (unpair n).1 (Nat.pair y i)))
      (unpair n).2
⊢ ∃ k,
    n ≤ k ∧
      Nat.rec (evaln (k + 1) a✝¹ (unpair n).1)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec a✝¹ a✝) (Nat.pair (unpair n).1 n_1)) fun i =>
              evaln (k + 1) a✝ (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2 =
        some x
case rfind'
a✝ : Code
a_ih✝ : ∀ {n x : ℕ}, x ∈ eval a✝ n → ∃ k, x ∈ evaln (k + 1) a✝ n
n x : ℕ
h :
  ∃ a,
    (0 ∈ eval a✝ (Nat.pair (unpair n).1 (a + (unpair n).2)) ∧
        ∀ {m : ℕ}, m < a → ∃ a ∈ eval a✝ (Nat.pair (unpair n).1 (m + (unpair n).2)), ¬a = 0) ∧
      a + (unpair n).2 = x
⊢ ∃ k,
    n ≤ k ∧
      ∃ a,
        evaln (k + 1) a✝ n = some a ∧
          (if a = 0 then some (unpair n).2 else evaln k (rfind' a✝) (Nat.pair (unpair n).1 ((unpair n).2 + 1))) = some x

Next tactic:
case pair cf cg hf hg =>
      rcases h with ⟨x, hx, y, hy, rfl⟩
      rcases hf hx with ⟨k₁, hk₁⟩; rcases hg hy with ⟨k₂, hk₂⟩
      refine' ⟨max k₁ k₂, _⟩
      refine'
        ⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _,
          evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁, _,
          evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂, rfl⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 exact ⟨⟨_, le_rfl⟩, h.symm⟩
    

Proof state:
cf cg : Code
hf : ∀ {n x : ℕ}, x ∈ eval cf n → ∃ k, x ∈ evaln (k + 1) cf n
hg : ∀ {n x : ℕ}, x ∈ eval cg n → ∃ k, x ∈ evaln (k + 1) cg n
n x : ℕ
h : ∃ a ∈ eval cf n, ∃ a_1 ∈ eval cg n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) cf n = some a ∧ ∃ a_1, evaln (k + 1) cg n = some a_1 ∧ Nat.pair a a_1 = x

Next tactic:
case pair cf cg hf hg =>
      rcases h with ⟨x, hx, y, hy, rfl⟩
      rcases hf hx with ⟨k₁, hk₁⟩; rcases hg hy with ⟨k₂, hk₂⟩
      refine' ⟨max k₁ k₂, _⟩
      refine'
        ⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _,
          evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁, _,
          evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂, rfl⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
  ⟨fun h => by
    rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
    · exact ⟨k + 1, h⟩
    induction c generalizing n x <;> simp [eval, evaln, pure, PFun.pure, Seq.seq, Bind.bind] at h ⊢
    iterate 4 exact ⟨⟨_, le_rfl⟩, h.symm⟩
    case pair cf cg hf hg =>
      

Proof state:
cf cg : Code
hf : ∀ {n x : ℕ}, x ∈ eval cf n → ∃ k, x ∈ evaln (k + 1) cf n
hg : ∀ {n x : ℕ}, x ∈ eval cg n → ∃ k, x ∈ evaln (k + 1) cg n
n x : ℕ
h : ∃ a ∈ eval cf n, ∃ a_1 ∈ eval cg n, Nat.pair a a_1 = x
⊢ ∃ k, n ≤ k ∧ ∃ a, evaln (k + 1) cf n = some a ∧ ∃ a_1, evaln (k + 1) cg n = some a_1 ∧ Nat.pair a a_1 = x

Next tactic:
rcases h with ⟨x, hx, y, hy, rfl⟩