Theorem: Turing.ToPartrec.stepRet_eval
File: Mathlib/Computability/TMToPartrec.lean

tactic: induction k generalizing v
state_before: k : Cont
v : List ℕ
⊢ eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v

tactic: case halt =>
  simp only [mem_eval, Cont.eval, map_pure]
  exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩)
state_before: case halt
v : List ℕ
⊢ eval step (stepRet Cont.halt v) = Cfg.halt <$> Cont.eval Cont.halt v

case cons₁
a✝² : Code
a✝¹ : List ℕ
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₁ a✝² a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.cons₁ a✝² a✝¹ a✝) v

case cons₂
a✝¹ : List ℕ
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₂ a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.cons₂ a✝¹ a✝) v

case comp
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.comp a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.comp a✝¹ a✝) v

case fix
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.fix a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.fix a✝¹ a✝) v

tactic: case cons₁ fs as k IH =>
  rw [Cont.eval, stepRet, code_is_ok]
  simp only [← bind_pure_comp, bind_assoc]; congr ; funext v'
  rw [reaches_eval]; swap; exact ReflTransGen.single rfl
  rw [stepRet, IH, bind_pure_comp]
state_before: case cons₁
a✝² : Code
a✝¹ : List ℕ
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₁ a✝² a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.cons₁ a✝² a✝¹ a✝) v

case cons₂
a✝¹ : List ℕ
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₂ a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.cons₂ a✝¹ a✝) v

case comp
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.comp a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.comp a✝¹ a✝) v

case fix
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.fix a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.fix a✝¹ a✝) v

tactic: case cons₂ ns k IH => rw [Cont.eval, stepRet]; exact IH
state_before: case cons₂
a✝¹ : List ℕ
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₂ a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.cons₂ a✝¹ a✝) v

case comp
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.comp a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.comp a✝¹ a✝) v

case fix
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.fix a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.fix a✝¹ a✝) v

tactic: case comp f k IH =>
  rw [Cont.eval, stepRet, code_is_ok]
  simp only [← bind_pure_comp, bind_assoc]; congr ; funext v'
  rw [reaches_eval]; swap; exact ReflTransGen.single rfl
  rw [IH, bind_pure_comp]
state_before: case comp
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.comp a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.comp a✝¹ a✝) v

case fix
a✝¹ : Code
a✝ : Cont
a_ih✝ : ∀ {v : List ℕ}, eval step (stepRet a✝ v) = Cfg.halt <$> Cont.eval a✝ v
v : List ℕ
⊢ eval step (stepRet (Cont.fix a✝¹ a✝) v) = Cfg.halt <$> Cont.eval (Cont.fix a✝¹ a✝) v

tactic: simp only [mem_eval, Cont.eval, map_pure]
state_before: v : List ℕ
⊢ eval step (stepRet Cont.halt v) = Cfg.halt <$> Cont.eval Cont.halt v

tactic: exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩)
state_before: v : List ℕ
⊢ eval step (stepRet Cont.halt v) = pure (Cfg.halt v)

tactic: rw [Cont.eval, stepRet, code_is_ok]
state_before: fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₁ fs as k) v) = Cfg.halt <$> Cont.eval (Cont.cons₁ fs as k) v

tactic: simp only [← bind_pure_comp, bind_assoc]
state_before: fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (do
      let v_1 ← Code.eval fs as
      eval step (Cfg.ret (Cont.cons₂ v k) v_1)) =
    Cfg.halt <$>
      (fun v => do
          let ns ← Code.eval fs as
          Cont.eval k (List.headI v :: ns))
        v

tactic: congr
state_before: fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (do
      let v_1 ← Code.eval fs as
      eval step (Cfg.ret (Cont.cons₂ v k) v_1)) =
    do
    let x ← Code.eval fs as
    let a ← Cont.eval k (List.headI v :: x)
    pure (Cfg.halt a)

tactic: funext v'
state_before: case e_a
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (fun v_1 => eval step (Cfg.ret (Cont.cons₂ v k) v_1)) = fun x => do
    let a ← Cont.eval k (List.headI v :: x)
    pure (Cfg.halt a)

tactic: rw [reaches_eval]
state_before: case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step (Cfg.ret (Cont.cons₂ v k) v') = do
    let a ← Cont.eval k (List.headI v :: v')
    pure (Cfg.halt a)

tactic: swap
state_before: case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step ?m.199598 = do
    let a ← Cont.eval k (List.headI v :: v')
    pure (Cfg.halt a)

case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Reaches step (Cfg.ret (Cont.cons₂ v k) v') ?m.199598

fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Cfg

tactic: exact ReflTransGen.single rfl
state_before: case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Reaches step (Cfg.ret (Cont.cons₂ v k) v') ?m.199598

case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step ?m.199598 = do
    let a ← Cont.eval k (List.headI v :: v')
    pure (Cfg.halt a)

fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Cfg

tactic: rw [stepRet, IH, bind_pure_comp]
state_before: case e_a.h
fs : Code
as : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step (stepRet (Cont.cons₂ v k) v') = do
    let a ← Cont.eval k (List.headI v :: v')
    pure (Cfg.halt a)

tactic: rw [Cont.eval, stepRet]
state_before: ns : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (stepRet (Cont.cons₂ ns k) v) = Cfg.halt <$> Cont.eval (Cont.cons₂ ns k) v

tactic: exact IH
state_before: ns : List ℕ
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (stepRet k (List.headI ns :: v)) = Cfg.halt <$> (fun v => Cont.eval k (List.headI ns :: v)) v

tactic: rw [Cont.eval, stepRet, code_is_ok]
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (stepRet (Cont.comp f k) v) = Cfg.halt <$> Cont.eval (Cont.comp f k) v

tactic: simp only [← bind_pure_comp, bind_assoc]
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (do
      let v ← Code.eval f v
      eval step (Cfg.ret k v)) =
    Cfg.halt <$> (fun v => Code.eval f v >>= Cont.eval k) v

tactic: congr
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (do
      let v ← Code.eval f v
      eval step (Cfg.ret k v)) =
    do
    let x ← Code.eval f v
    let a ← Cont.eval k x
    pure (Cfg.halt a)

tactic: funext v'
state_before: case e_a
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ (fun v => eval step (Cfg.ret k v)) = fun x => do
    let a ← Cont.eval k x
    pure (Cfg.halt a)

tactic: rw [reaches_eval]
state_before: case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step (Cfg.ret k v') = do
    let a ← Cont.eval k v'
    pure (Cfg.halt a)

tactic: swap
state_before: case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step ?m.200290 = do
    let a ← Cont.eval k v'
    pure (Cfg.halt a)

case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Reaches step (Cfg.ret k v') ?m.200290

f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Cfg

tactic: exact ReflTransGen.single rfl
state_before: case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Reaches step (Cfg.ret k v') ?m.200290

case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step ?m.200290 = do
    let a ← Cont.eval k v'
    pure (Cfg.halt a)

f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ Cfg

tactic: rw [IH, bind_pure_comp]
state_before: case e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v v' : List ℕ
⊢ eval step (stepRet k v') = do
    let a ← Cont.eval k v'
    pure (Cfg.halt a)

tactic: rw [Cont.eval, stepRet]
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (stepRet (Cont.fix f k) v) = Cfg.halt <$> Cont.eval (Cont.fix f k) v

tactic: simp only [bind_pure_comp]
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (if List.headI v = 0 then stepRet k (List.tail v) else stepNormal f (Cont.fix f k) (List.tail v)) =
    Cfg.halt <$>
      (fun v =>
          if List.headI v = 0 then Cont.eval k (List.tail v) else Code.eval (Code.fix f) (List.tail v) >>= Cont.eval k)
        v

tactic: split_ifs
state_before: f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
⊢ eval step (if List.headI v = 0 then stepRet k (List.tail v) else stepNormal f (Cont.fix f k) (List.tail v)) =
    Cfg.halt <$>
      if List.headI v = 0 then Cont.eval k (List.tail v) else Code.eval (Code.fix f) (List.tail v) >>= Cont.eval k

tactic: simp only [← bind_pure_comp, bind_assoc, cont_eval_fix (code_is_ok _)]
state_before: case inr
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : ¬List.headI v = 0
⊢ eval step (stepNormal f (Cont.fix f k) (List.tail v)) =
    Cfg.halt <$> (Code.eval (Code.fix f) (List.tail v) >>= Cont.eval k)

tactic: congr
state_before: case inr
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : ¬List.headI v = 0
⊢ (do
      let v ← Code.eval (Code.fix f) (List.tail v)
      eval step (Cfg.ret k v)) =
    do
    let x ← Code.eval (Code.fix f) (List.tail v)
    let a ← Cont.eval k x
    pure (Cfg.halt a)

tactic: funext
state_before: case inr.e_a
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : ¬List.headI v = 0
⊢ (fun v => eval step (Cfg.ret k v)) = fun x => do
    let a ← Cont.eval k x
    pure (Cfg.halt a)

tactic: rw [bind_pure_comp, ← IH]
state_before: case inr.e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : ¬List.headI v = 0
x✝ : List ℕ
⊢ eval step (Cfg.ret k x✝) = do
    let a ← Cont.eval k x✝
    pure (Cfg.halt a)

tactic: exact reaches_eval (ReflTransGen.single rfl)
state_before: case inr.e_a.h
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : ¬List.headI v = 0
x✝ : List ℕ
⊢ eval step (Cfg.ret k x✝) = eval step (stepRet k x✝)

tactic: exact IH
state_before: case inl
f : Code
k : Cont
IH : ∀ {v : List ℕ}, eval step (stepRet k v) = Cfg.halt <$> Cont.eval k v
v : List ℕ
h✝ : List.headI v = 0
⊢ eval step (stepRet k (List.tail v)) = Cfg.halt <$> Cont.eval k (List.tail v)