-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/List/Attach.lean
theorem attach_filterMap {l : List α} {f : α → Option β} :
    (l.filterMap f).attach = l.attach.filterMap
      fun ⟨x, h⟩ => (f x).pbind (fun b m => some ⟨b, mem_filterMap.mpr ⟨x, h, m⟩⟩)

Proof state:
case cons.h_1
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ map (fun x_1 => ⟨x_1.val, ⋯⟩) (attach ?m.60801) =
    filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

case cons.h_1
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ (match f x with
    | none => filterMap f xs
    | some b => b :: filterMap f xs) =
    ?m.60801

α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ List β

Tactic:
rotate_left

Result:
case cons.h_1
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ (match f x with
    | none => filterMap f xs
    | some b => b :: filterMap f xs) =
    ?m.60801

α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ List β

case cons.h_1
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : f x = none
⊢ map (fun x_1 => ⟨x_1.val, ⋯⟩) (attach ?m.60801) =
    filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

Proof state:
case cons.h_2.intro.intro.e_tail.e_f.h.a
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝¹ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
a : β
h✝ : a ∈ f x
h : f x = some a
x✝ : { x // x ∈ xs }
a✝ :
  { x_1 //
    x_1 ∈
      match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs }
⊢ a✝ ∈
      Option.map
        ((fun x_1 => ⟨x_1.val, ⋯⟩) ∘ fun x =>
          match x with
          | ⟨y, h⟩ => ⟨y, ⋯⟩)
        (match x✝ with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩) ↔
    a✝ ∈ ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) x✝

Tactic:
simp

Result:
no goals

Proof state:
case cons
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
⊢ (match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs).attach =
    match (f x).pbind fun a h => some ⟨a, ⋯⟩ with
    | none => filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach
    | some b =>
      b :: filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

Tactic:
split <;> rename_i h

Result:
case cons.h_1
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
h : ((f x).pbind fun a h => some ⟨a, ⋯⟩) = none
⊢ (match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs).attach =
    filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

case cons.h_2
α : Type u_1
β : Type u_2
f : α → Option β
x : α
xs : List α
ih :
  (filterMap f xs).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      xs.attach
x✝ :
  Option
    { x_1 //
      x_1 ∈
        match f x with
        | none => filterMap f xs
        | some b => b :: filterMap f xs }
b✝ :
  { x_1 //
    x_1 ∈
      match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs }
h : ((f x).pbind fun a h => some ⟨a, ⋯⟩) = some b✝
⊢ (match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs).attach =
    b✝ :: filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach