-- 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_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 : ∃ 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

Tactic:
obtain ⟨a, h, w⟩ := h

Result:
case cons.h_2.intro.intro
α : 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 }
a : β
h : a ∈ f x
w : 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

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
⊢ (filterMap f (x :: xs)).attach =
    filterMap
      (fun x_1 =>
        match x_1 with
        | ⟨x_2, h⟩ => (f x_2).pbind fun b m => some ⟨b, ⋯⟩)
      (x :: xs).attach

Tactic:
simp only [filterMap_cons, attach_cons, ih, filterMap_map]

Result:
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

Proof state:
case cons.h_2.intro.intro
α : 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
⊢ (match f x with
      | none => filterMap f xs
      | some b => b :: filterMap f xs).attach =
    ⟨a, ⋯⟩ :: filterMap ((fun x_1 => (f x_1.val).pbind fun a h => some ⟨a, ⋯⟩) ∘ fun x_1 => ⟨x_1.val, ⋯⟩) xs.attach

Tactic:
rw [attach_congr]

Result:
case cons.h_2.intro.intro
α : 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
⊢ map (fun x_1 => ⟨x_1.val, ⋯⟩) (attach ?m.63176) =
    ⟨a, ⋯⟩ :: 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.intro.intro
α : 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
⊢ (match f x with
    | none => filterMap f xs
    | some b => b :: filterMap f xs) =
    ?m.63176

α : 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
⊢ List β

Proof state:
case nil
α : Type u_1
β : Type u_2
f : α → Option β
⊢ (filterMap f []).attach =
    filterMap
      (fun x =>
        match x with
        | ⟨x, h⟩ => (f x).pbind fun b m => some ⟨b, ⋯⟩)
      [].attach

Tactic:
rfl

Result:
no goals