-- Mathlib/MeasureTheory/PiSystem.lean
theorem mem_generatePiSystem_iUnion_elim {α β} {g : β → Set (Set α)} (h_pi : ∀ b, IsPiSystem (g b))
    (t : Set α) (h_t : t ∈ generatePiSystem (⋃ b, g b)) :
    ∃ (T : Finset β) (f : β → Set α), (t = ⋂ b ∈ T, f b) ∧ ∀ b ∈ T, f b ∈ g b

Proof state:
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
h_t : t ∈ generatePiSystem (⋃ b, g b)
⊢ ∃ T f, t = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Tactic:
induction' h_t with s h_s s t' h_gen_s h_gen_t' h_nonempty h_s h_t'

Result:
case base
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s : Set α
h_s : s ∈ ⋃ b, g b
⊢ ∃ T f, s = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

case inter
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s t' : Set α
h_gen_s : generatePiSystem (⋃ b, g b) s
h_gen_t' : generatePiSystem (⋃ b, g b) t'
h_nonempty : (s ∩ t').Nonempty
h_s : ∃ T f, s = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b
h_t' : ∃ T f, t' = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b
⊢ ∃ T f, s ∩ t' = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Proof state:
case pos
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
a : α
b : β
hbs : b ∉ T_s
hbt : b ∈ T_t'
h1 : True ∧ a ∈ f_t' b
⊢ True ∧ a ∈ f_t' b

Tactic:
exact h1

Result:
no goals

Proof state:
case inter.intro.intro.intro.intro.intro.intro
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
⊢ ∃ T f, (⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Tactic:
use T_s ∪ T_t', fun b : β =>
  if b ∈ T_s then if b ∈ T_t' then f_s b ∩ f_t' b else f_s b
  else if b ∈ T_t' then f_t' b else (∅ : Set α)

Result:
case h
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
⊢ (⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b =
      ⋂ b ∈ T_s ∪ T_t',
        (fun b => if b ∈ T_s then if b ∈ T_t' then f_s b ∩ f_t' b else f_s b else if b ∈ T_t' then f_t' b else ∅) b ∧
    ∀ b ∈ T_s ∪ T_t',
      (fun b => if b ∈ T_s then if b ∈ T_t' then f_s b ∩ f_t' b else f_s b else if b ∈ T_t' then f_t' b else ∅) b ∈ g b

Proof state:
case base.intro.intro.intro
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s : Set α
b : β
h_s_in_t' : s ∈ (fun b => g b) b
⊢ ∃ T f, s = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Tactic:
refine ⟨{b}, fun _ => s, ?_⟩

Result:
case base.intro.intro.intro
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s : Set α
b : β
h_s_in_t' : s ∈ (fun b => g b) b
⊢ s = ⋂ b_1 ∈ {b}, (fun x => s) b_1 ∧ ∀ b_1 ∈ {b}, (fun x => s) b_1 ∈ g b_1

Proof state:
case inter
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s t' : Set α
h_gen_s : generatePiSystem (⋃ b, g b) s
h_gen_t' : generatePiSystem (⋃ b, g b) t'
h_nonempty : (s ∩ t').Nonempty
h_s : ∃ T f, s = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b
h_t' : ∃ T f, t' = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b
⊢ ∃ T f, s ∩ t' = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Tactic:
rcases h_t' with ⟨T_t', ⟨f_t', ⟨rfl, h_t'⟩⟩⟩

Result:
case inter.intro.intro.intro
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t s : Set α
h_gen_s : generatePiSystem (⋃ b, g b) s
h_s : ∃ T f, s = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
h_nonempty : (s ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
⊢ ∃ T f, s ∩ ⋂ b ∈ T_t', f_t' b = ⋂ b ∈ T, f b ∧ ∀ b ∈ T, f b ∈ g b

Proof state:
case h.left.h
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
a : α
⊢ a ∈ (⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b ↔
    a ∈ ⋂ b ∈ T_s ∪ T_t', if b ∈ T_s then if b ∈ T_t' then f_s b ∩ f_t' b else f_s b else if b ∈ T_t' then f_t' b else ∅

Tactic:
simp_rw [Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union, or_imp]

Result:
case h.left.h
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
a : α
⊢ ((∀ i ∈ T_s, a ∈ f_s i) ∧ ∀ i ∈ T_t', a ∈ f_t' i) ↔
    ∀ (i : β),
      (i ∈ T_s → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅) ∧
        (i ∈ T_t' → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅)

Proof state:
case h.left.h
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
a : α
⊢ ((∀ i ∈ T_s, a ∈ f_s i) ∧ ∀ i ∈ T_t', a ∈ f_t' i) ↔
    ∀ (i : β),
      (i ∈ T_s → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅) ∧
        (i ∈ T_t' → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅)

Tactic:
rw [← forall_and]

Result:
case h.left.h
α : Type u_3
β : Type u_4
g : β → Set (Set α)
h_pi : ∀ (b : β), IsPiSystem (g b)
t : Set α
T_t' : Finset β
f_t' : β → Set α
h_t' : ∀ b ∈ T_t', f_t' b ∈ g b
h_gen_t' : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_t', f_t' b)
T_s : Finset β
f_s : β → Set α
h_s : ∀ b ∈ T_s, f_s b ∈ g b
h_gen_s : generatePiSystem (⋃ b, g b) (⋂ b ∈ T_s, f_s b)
h_nonempty : ((⋂ b ∈ T_s, f_s b) ∩ ⋂ b ∈ T_t', f_t' b).Nonempty
a : α
⊢ (∀ (x : β), (x ∈ T_s → a ∈ f_s x) ∧ (x ∈ T_t' → a ∈ f_t' x)) ↔
    ∀ (i : β),
      (i ∈ T_s → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅) ∧
        (i ∈ T_t' → a ∈ if i ∈ T_s then if i ∈ T_t' then f_s i ∩ f_t' i else f_s i else if i ∈ T_t' then f_t' i else ∅)