Theorem: Nat.Partrec.Code.evaln_sound
File: Mathlib/Computability/PartrecCode.lean

tactic: simp [evaln] at h
state_before: x✝ : Code
n x : ℕ
h : x ∈ evaln 0 x✝ n
⊢ x ∈ eval x✝ n

tactic: 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
state_before: k : ℕ
c : Code
n x : ℕ
h : x ∈ evaln (k + 1) c n
⊢ x ∈ eval c n

tactic: iterate 4 simpa [pure, PFun.pure, eq_comm] using h
state_before: case zero.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
n x : ℕ
left✝ : n ≤ k
h : pure 0 = some x
⊢ x ∈ pure 0 n

case succ.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
n x : ℕ
left✝ : n ≤ k
h : pure (Nat.succ n) = some x
⊢ x = Nat.succ n

case left.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
n x : ℕ
left✝ : n ≤ k
h : pure (unpair n).fst = some x
⊢ x = (unpair n).fst

case right.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
n x : ℕ
left✝ : n ≤ k
h : pure (unpair n).snd = some x
⊢ x = (unpair n).snd

case pair.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cf n = some a ∧ ∃ a_1, evaln (k + 1) cg n = some a_1 ∧ Nat.pair a a_1 = x
⊢ ∃ a, a ∈ eval cf n ∧ ∃ a_1, a_1 ∈ eval cg n ∧ Nat.pair a a_1 = x

case comp.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cg n = some a ∧ evaln (k + 1) cf a = some x
⊢ ∃ a, a ∈ eval cg n ∧ x ∈ eval cf a

case prec.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h :
  Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      (unpair n).snd =
    some x
⊢ x ∈
    Nat.rec (eval cf (unpair n).fst)
      (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) (unpair n).snd

case rfind'.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
h :
  ∃ a,
    evaln (k + 1) cf n = some a ∧
      (if a = 0 then pure (unpair n).snd else evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1))) =
        some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: simpa [pure, PFun.pure, eq_comm] using h
state_before: case right.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
n x : ℕ
left✝ : n ≤ k
h : pure (unpair n).snd = some x
⊢ x = (unpair n).snd

case pair.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cf n = some a ∧ ∃ a_1, evaln (k + 1) cg n = some a_1 ∧ Nat.pair a a_1 = x
⊢ ∃ a, a ∈ eval cf n ∧ ∃ a_1, a_1 ∈ eval cg n ∧ Nat.pair a a_1 = x

case comp.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cg n = some a ∧ evaln (k + 1) cf a = some x
⊢ ∃ a, a ∈ eval cg n ∧ x ∈ eval cf a

case prec.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h :
  Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      (unpair n).snd =
    some x
⊢ x ∈
    Nat.rec (eval cf (unpair n).fst)
      (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) (unpair n).snd

case rfind'.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
h :
  ∃ a,
    evaln (k + 1) cf n = some a ∧
      (if a = 0 then pure (unpair n).snd else evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1))) =
        some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: rcases h with ⟨y, ef, z, eg, rfl⟩
state_before: case pair.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cf n = some a ∧ ∃ a_1, evaln (k + 1) cg n = some a_1 ∧ Nat.pair a a_1 = x
⊢ ∃ a, a ∈ eval cf n ∧ ∃ a_1, a_1 ∈ eval cg n ∧ Nat.pair a a_1 = x

tactic: exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩
state_before: case pair.intro.intro.intro.intro.intro
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n : ℕ
left✝ : n ≤ k
y : ℕ
ef : evaln (k + 1) cf n = some y
z : ℕ
eg : evaln (k + 1) cg n = some z
⊢ ∃ a, a ∈ eval cf n ∧ ∃ a_1, a_1 ∈ eval cg n ∧ Nat.pair a a_1 = Nat.pair y z

tactic: rcases h with ⟨y, eg, ef⟩
state_before: case comp.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h : ∃ a, evaln (k + 1) cg n = some a ∧ evaln (k + 1) cf a = some x
⊢ ∃ a, a ∈ eval cg n ∧ x ∈ eval cf a

tactic: exact ⟨_, hg _ _ eg, hf _ _ ef⟩
state_before: case comp.intro.intro.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
y : ℕ
eg : evaln (k + 1) cg n = some y
ef : evaln (k + 1) cf y = some x
⊢ ∃ a, a ∈ eval cg n ∧ x ∈ eval cf a

tactic: revert h
state_before: case prec.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
h :
  Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      (unpair n).snd =
    some x
⊢ x ∈
    Nat.rec (eval cf (unpair n).fst)
      (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) (unpair n).snd

tactic: induction' n.unpair.2 with m IH generalizing x <;> simp
state_before: case prec.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x : ℕ
left✝ : n ≤ k
⊢ Nat.rec (evaln (k + 1) cf (unpair n).fst)
        (fun n_1 n_ih =>
          Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
            evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
        (unpair n).snd =
      some x →
    x ∈
      Nat.rec (eval cf (unpair n).fst)
        (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) (unpair n).snd

tactic: apply hf
state_before: case prec.intro.zero
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
x : ℕ
⊢ evaln (k + 1) cf (unpair n).fst = some x → x ∈ eval cf (unpair n).fst

tactic: refine' fun y h₁ h₂ => ⟨y, IH _ _, _⟩
state_before: case prec.intro.succ
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
m : ℕ
IH :
  ∀ (x : ℕ),
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
              evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
          m =
        some x →
      x ∈
        Nat.rec (eval cf (unpair n).fst)
          (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m
x : ℕ
⊢ ∀ (x_1 : ℕ),
    evaln k (prec cf cg) (Nat.pair (unpair n).fst m) = some x_1 →
      evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair m x_1)) = some x →
        ∃ a,
          a ∈
              Nat.rec (eval cf (unpair n).fst)
                (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m ∧
            x ∈ eval cg (Nat.pair (unpair n).fst (Nat.pair m a))

tactic: have := evaln_mono k.le_succ h₁
state_before: case prec.intro.succ.refine'_1
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
m : ℕ
IH :
  ∀ (x : ℕ),
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
              evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
          m =
        some x →
      x ∈
        Nat.rec (eval cf (unpair n).fst)
          (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m
x y : ℕ
h₁ : evaln k (prec cf cg) (Nat.pair (unpair n).fst m) = some y
h₂ : evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair m y)) = some x
⊢ Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      m =
    some y

tactic: simp [evaln, Bind.bind] at this
state_before: case prec.intro.succ.refine'_1
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
m : ℕ
IH :
  ∀ (x : ℕ),
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
              evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
          m =
        some x →
      x ∈
        Nat.rec (eval cf (unpair n).fst)
          (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m
x y : ℕ
h₁ : evaln k (prec cf cg) (Nat.pair (unpair n).fst m) = some y
h₂ : evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair m y)) = some x
this : y ∈ evaln (Nat.succ k) (prec cf cg) (Nat.pair (unpair n).fst m)
⊢ Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      m =
    some y

tactic: exact this.2
state_before: case prec.intro.succ.refine'_1
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
m : ℕ
IH :
  ∀ (x : ℕ),
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
              evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
          m =
        some x →
      x ∈
        Nat.rec (eval cf (unpair n).fst)
          (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m
x y : ℕ
h₁ : evaln k (prec cf cg) (Nat.pair (unpair n).fst m) = some y
h₂ : evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair m y)) = some x
this :
  Nat.pair (unpair n).fst m ≤ k ∧
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
        (fun n_1 n_ih =>
          Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
            evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
        m =
      some y
⊢ Nat.rec (evaln (k + 1) cf (unpair n).fst)
      (fun n_1 n_ih =>
        Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
          evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
      m =
    some y

tactic: exact hg _ _ h₂
state_before: case prec.intro.succ.refine'_2
k : ℕ
c : Code
n✝ x✝¹ : ℕ
h : x✝¹ ∈ evaln (k + 1) c n✝
cf cg : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
hg : ∀ (n x : ℕ), x ∈ evaln (k + 1) cg n → x ∈ eval cg n
n x✝ : ℕ
left✝ : n ≤ k
m : ℕ
IH :
  ∀ (x : ℕ),
    Nat.rec (evaln (k + 1) cf (unpair n).fst)
          (fun n_1 n_ih =>
            Option.bind (evaln k (prec cf cg) (Nat.pair (unpair n).fst n_1)) fun i =>
              evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair n_1 i)))
          m =
        some x →
      x ∈
        Nat.rec (eval cf (unpair n).fst)
          (fun y IH => Part.bind IH fun i => eval cg (Nat.pair (unpair n).fst (Nat.pair y i))) m
x y : ℕ
h₁ : evaln k (prec cf cg) (Nat.pair (unpair n).fst m) = some y
h₂ : evaln (k + 1) cg (Nat.pair (unpair n).fst (Nat.pair m y)) = some x
⊢ x ∈ eval cg (Nat.pair (unpair n).fst (Nat.pair m y))

tactic: rcases h with ⟨m, h₁, h₂⟩
state_before: case rfind'.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h✝ : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
h :
  ∃ a,
    evaln (k + 1) cf n = some a ∧
      (if a = 0 then pure (unpair n).snd else evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1))) =
        some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: by_cases m0 : m = 0 <;> simp [m0] at h₂
state_before: case rfind'.intro.intro.intro
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
h₂ :
  (if m = 0 then pure (unpair n).snd else evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1))) = some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: exact
  ⟨0, ⟨by simpa [m0] using hf _ _ h₁, fun {m} => (Nat.not_lt_zero _).elim⟩, by
    injection h₂ with h₂; simp [h₂]⟩
state_before: case pos
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : m = 0
h₂ : pure (unpair n).snd = some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: simpa [m0] using hf _ _ h₁
state_before: k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : m = 0
h₂ : pure (unpair n).snd = some x
⊢ 0 ∈ eval cf (Nat.pair (unpair n).fst (0 + (unpair n).snd))

tactic: injection h₂ with h₂
state_before: k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : m = 0
h₂ : pure (unpair n).snd = some x
⊢ 0 + (unpair n).snd = x

tactic: simp [h₂]
state_before: k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : m = 0
h₂ : (unpair n).snd = x
⊢ 0 + (unpair n).snd = x

tactic: have := evaln_sound h₂
state_before: case neg
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : ¬m = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: simp [eval] at this
state_before: case neg
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : ¬m = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some x
this : x ∈ eval (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1))
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩
state_before: case neg
k : ℕ
c : Code
n✝ x✝ : ℕ
h : x✝ ∈ evaln (k + 1) c n✝
cf : Code
hf : ∀ (n x : ℕ), x ∈ evaln (k + 1) cf n → x ∈ eval cf n
n x : ℕ
left✝ : n ≤ k
m : ℕ
h₁ : evaln (k + 1) cf n = some m
m0 : ¬m = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some x
this :
  ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + ((unpair n).snd + 1))) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0) ∧
      a + ((unpair n).snd + 1) = x
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = x

tactic: refine'
  ⟨y + 1, ⟨by simpa [add_comm, add_left_comm] using hy₁, fun {i} im => _⟩, by
    simp [add_comm, add_left_comm]⟩
state_before: case neg.intro.intro.intro
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
⊢ ∃ a,
    (0 ∈ eval cf (Nat.pair (unpair n).fst (a + (unpair n).snd)) ∧
        ∀ {m : ℕ}, m < a → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + (unpair n).snd)) ∧ ¬a = 0) ∧
      a + (unpair n).snd = y + ((unpair n).snd + 1)

tactic: cases' i with i
state_before: case neg.intro.intro.intro
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
i : ℕ
im : i < y + 1
⊢ ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (i + (unpair n).snd)) ∧ ¬a = 0

tactic: simpa [add_comm, add_left_comm] using hy₁
state_before: k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
⊢ 0 ∈ eval cf (Nat.pair (unpair n).fst (y + 1 + (unpair n).snd))

tactic: simp [add_comm, add_left_comm]
state_before: k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
⊢ y + 1 + (unpair n).snd = y + ((unpair n).snd + 1)

tactic: exact ⟨m, by simpa using hf _ _ h₁, m0⟩
state_before: case neg.intro.intro.intro.zero
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
im : Nat.zero < y + 1
⊢ ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (Nat.zero + (unpair n).snd)) ∧ ¬a = 0

tactic: simpa using hf _ _ h₁
state_before: k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
im : Nat.zero < y + 1
⊢ m ∈ eval cf (Nat.pair (unpair n).fst (Nat.zero + (unpair n).snd))

tactic: rcases hy₂ (Nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩
state_before: case neg.intro.intro.intro.succ
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
i : ℕ
im : Nat.succ i < y + 1
⊢ ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (Nat.succ i + (unpair n).snd)) ∧ ¬a = 0

tactic: exact ⟨z, by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hz, z0⟩
state_before: case neg.intro.intro.intro.succ.intro.intro
k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
i : ℕ
im : Nat.succ i < y + 1
z : ℕ
hz : z ∈ eval cf (Nat.pair (unpair n).fst (i + ((unpair n).snd + 1)))
z0 : ¬z = 0
⊢ ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (Nat.succ i + (unpair n).snd)) ∧ ¬a = 0

tactic: simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hz
state_before: k : ℕ
c : Code
n✝ x : ℕ
h : x ∈ evaln (k + 1) c n✝
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).fst (y + ((unpair n).snd + 1)))
hy₂ : ∀ {m : ℕ}, m < y → ∃ a, a ∈ eval cf (Nat.pair (unpair n).fst (m + ((unpair n).snd + 1))) ∧ ¬a = 0
h₂ : evaln k (rfind' cf) (Nat.pair (unpair n).fst ((unpair n).snd + 1)) = some (y + ((unpair n).snd + 1))
i : ℕ
im : Nat.succ i < y + 1
z : ℕ
hz : z ∈ eval cf (Nat.pair (unpair n).fst (i + ((unpair n).snd + 1)))
z0 : ¬z = 0
⊢ z ∈ eval cf (Nat.pair (unpair n).fst (Nat.succ i + (unpair n).snd))