Theorem: List.foldlM_eq_foldl
File: Mathlib/Data/List/Basic.lean

tactic: suffices h :
  ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
  by simp [← h (pure b)]
state_before: ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
l : List α
⊢ List.foldlM f b l =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      (pure b) l
state_after: ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
l : List α
⊢ ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b l) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb l

tactic: induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
state_before: ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
l : List α
⊢ ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b l) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb l
state_after: no goals

tactic: simp [← h (pure b)]
state_before: ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
l : List α
h :
  ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b l) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb l
⊢ List.foldlM f b l =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      (pure b) l
state_after: no goals

tactic: intro
state_before: case nil
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
⊢ ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b []) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb []
state_after: case nil
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
mb✝ : m β
⊢ (do
      let b ← mb✝
      List.foldlM f b []) =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      mb✝ []

tactic: simp
state_before: case nil
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
mb✝ : m β
⊢ (do
      let b ← mb✝
      List.foldlM f b []) =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      mb✝ []
state_after: no goals

tactic: intro
state_before: case cons
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
head✝ : α
tail✝ : List α
l_ih :
  ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b tail✝) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb tail✝
⊢ ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b (head✝ :: tail✝)) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb (head✝ :: tail✝)
state_after: case cons
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
head✝ : α
tail✝ : List α
l_ih :
  ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b tail✝) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb tail✝
mb✝ : m β
⊢ (do
      let b ← mb✝
      List.foldlM f b (head✝ :: tail✝)) =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      mb✝ (head✝ :: tail✝)

tactic: simp only [List.foldlM, foldl, ← l_ih, functor_norm]
state_before: case cons
ι : Type u_1
α : Type u
β : Type v
γ : Type w
l₁ l₂ : List α
m : Type v → Type w
inst✝¹ : Monad m
inst✝ : LawfulMonad m
f : β → α → m β
b : β
head✝ : α
tail✝ : List α
l_ih :
  ∀ (mb : m β),
    (do
        let b ← mb
        List.foldlM f b tail✝) =
      foldl
        (fun mb a => do
          let b ← mb
          f b a)
        mb tail✝
mb✝ : m β
⊢ (do
      let b ← mb✝
      List.foldlM f b (head✝ :: tail✝)) =
    foldl
      (fun mb a => do
        let b ← mb
        f b a)
      mb✝ (head✝ :: tail✝)
state_after: no goals