Theorem: Computation.of_results_bind
File: Mathlib/Data/Seq/Computation.lean

tactic: induction' k with n IH generalizing s <;> apply recOn s (fun a => _) fun s' => _ <;> intro e h
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
b : β
k : ℕ
⊢ Results (bind s f) b k → ∃ a m n, Results s a m ∧ Results (f a) b n ∧ k = n + m

tactic: simp [thinkN] at h
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
s : Computation α
e : α
h : Results (bind (pure e) f) b Nat.zero
⊢ ∃ a m n, Results (pure e) a m ∧ Results (f a) b n ∧ Nat.zero = n + m

tactic: refine' ⟨e, _, _, results_pure _, h, rfl⟩
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
s : Computation α
e : α
h : Results (f e) b 0
⊢ ∃ a m n, Results (pure e) a m ∧ Results (f a) b n ∧ Nat.zero = n + m

tactic: have := congr_arg head (eq_thinkN h)
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
s e : Computation α
h : Results (bind (think e) f) b Nat.zero
⊢ ∃ a m n, Results (think e) a m ∧ Results (f a) b n ∧ Nat.zero = n + m

tactic: contradiction
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
s e : Computation α
h : Results (bind (think e) f) b Nat.zero
this : head (bind (think e) f) = head (thinkN (pure b) Nat.zero)
⊢ ∃ a m n, Results (think e) a m ∧ Results (f a) b n ∧ Nat.zero = n + m

tactic: simp at h
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s : Computation α
e : α
h : Results (bind (pure e) f) b (Nat.succ n)
⊢ ∃ a m n_1, Results (pure e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: refine' ⟨e, _, n + 1, results_pure _, h, rfl⟩
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s : Computation α
e : α
h : Results (f e) b (Nat.succ n)
⊢ ∃ a m n_1, Results (pure e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: simp at h
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s e : Computation α
h : Results (bind (think e) f) b (Nat.succ n)
⊢ ∃ a m n_1, Results (think e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: exact by
  let ⟨a, m, n', h1, h2, e'⟩ := IH h
  rw [e'] ; exact ⟨a, m.succ, n', results_think h1, h2, rfl⟩
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s e : Computation α
h : Results (bind e f) b n
⊢ ∃ a m n_1, Results (think e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: let ⟨a, m, n', h1, h2, e'⟩ := IH h
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s e : Computation α
h : Results (bind e f) b n
⊢ ∃ a m n_1, Results (think e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: rw [e']
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s e : Computation α
h : Results (bind e f) b n
a : α
m n' : ℕ
h1 : Results e a m
h2 : Results (f a) b n'
e' : n = n' + m
⊢ ∃ a m n_1, Results (think e) a m ∧ Results (f a) b n_1 ∧ Nat.succ n = n_1 + m

tactic: exact ⟨a, m.succ, n', results_think h1, h2, rfl⟩
state_before: α : Type u
β : Type v
γ : Type w
s✝ : Computation α
f : α → Computation β
b : β
n : ℕ
IH : ∀ {s : Computation α}, Results (bind s f) b n → ∃ a m n_1, Results s a m ∧ Results (f a) b n_1 ∧ n = n_1 + m
s e : Computation α
h : Results (bind e f) b n
a : α
m n' : ℕ
h1 : Results e a m
h2 : Results (f a) b n'
e' : n = n' + m
⊢ ∃ a m_1 n, Results (think e) a m_1 ∧ Results (f a) b n ∧ Nat.succ (n' + m) = n + m_1