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

tactic: have := h1.mem
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
m n : ℕ
h1 : Results s a m
h2 : Results (f a) b n
⊢ Results (bind s f) b (n + m)

tactic: revert m
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
m n : ℕ
h1 : Results s a m
h2 : Results (f a) b n
this : a ∈ s
⊢ Results (bind s f) b (n + m)

tactic: apply memRecOn this _ fun s IH => _
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
⊢ ∀ {m : ℕ}, Results s a m → Results (bind s f) b (n + m)

tactic: intro _ h1
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
⊢ ∀ {m : ℕ}, Results (pure a) a m → Results (bind (pure a) f) b (n + m)

tactic: rw [ret_bind]
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
m✝ : ℕ
h1 : Results (pure a) a m✝
⊢ Results (bind (pure a) f) b (n + m✝)

tactic: rw [h1.len_unique (results_pure _)]
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
m✝ : ℕ
h1 : Results (pure a) a m✝
⊢ Results (f a) b (n + m✝)

tactic: exact h2
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
m✝ : ℕ
h1 : Results (pure a) a m✝
⊢ Results (f a) b (n + 0)

tactic: intro _ h3 _ h1
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
⊢ ∀ (s : Computation α),
    (∀ {m : ℕ}, Results s a m → Results (bind s f) b (n + m)) →
      ∀ {m : ℕ}, Results (think s) a m → Results (bind (think s) f) b (n + m)

tactic: rw [think_bind]
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
s✝ : Computation α
h3 : ∀ {m : ℕ}, Results s✝ a m → Results (bind s✝ f) b (n + m)
m✝ : ℕ
h1 : Results (think s✝) a m✝
⊢ Results (bind (think s✝) f) b (n + m✝)

tactic: cases' of_results_think h1 with m' h
state_before: α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
s✝ : Computation α
h3 : ∀ {m : ℕ}, Results s✝ a m → Results (bind s✝ f) b (n + m)
m✝ : ℕ
h1 : Results (think s✝) a m✝
⊢ Results (think (bind s✝ f)) b (n + m✝)

tactic: cases' h with h1 e
state_before: case intro
α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
s✝ : Computation α
h3 : ∀ {m : ℕ}, Results s✝ a m → Results (bind s✝ f) b (n + m)
m✝ : ℕ
h1 : Results (think s✝) a m✝
m' : ℕ
h : Results s✝ a m' ∧ m✝ = m' + 1
⊢ Results (think (bind s✝ f)) b (n + m✝)

tactic: rw [e]
state_before: case intro.intro
α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
s✝ : Computation α
h3 : ∀ {m : ℕ}, Results s✝ a m → Results (bind s✝ f) b (n + m)
m✝ : ℕ
h1✝ : Results (think s✝) a m✝
m' : ℕ
h1 : Results s✝ a m'
e : m✝ = m' + 1
⊢ Results (think (bind s✝ f)) b (n + m✝)

tactic: exact results_think (h3 h1)
state_before: case intro.intro
α : Type u
β : Type v
γ : Type w
s : Computation α
f : α → Computation β
a : α
b : β
n : ℕ
h2 : Results (f a) b n
this : a ∈ s
s✝ : Computation α
h3 : ∀ {m : ℕ}, Results s✝ a m → Results (bind s✝ f) b (n + m)
m✝ : ℕ
h1✝ : Results (think s✝) a m✝
m' : ℕ
h1 : Results s✝ a m'
e : m✝ = m' + 1
⊢ Results (think (bind s✝ f)) b (n + (m' + 1))