/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
theorem iIndepFun.indepFun_finset [IsMarkovKernel κ] (S T : Finset ι) (hST : Disjoint S T)
    (hf_Indep : iIndepFun m f κ μ) (hf_meas : ∀ i, Measurable (f i)) :
    IndepFun (fun a (i : S) => f i a) (fun a (i : T) => f i a) κ μ := by
  -- We introduce π-systems, built from the π-system of boxes which generates `MeasurableSpace.pi`.
  let πSβ := Set.pi (Set.univ : Set S) ''
    Set.pi (Set.univ : Set S) fun i => { s : Set (β i) | MeasurableSet[m i] s }
  let πS := { s : Set Ω | ∃ t ∈ πSβ, (fun a (i : S) => f i a) ⁻¹' t = s }
  have hπS_pi : IsPiSystem πS := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _
  have hπS_gen : (MeasurableSpace.pi.comap fun a (i : S) => f i a) = generateFrom πS := by
    rw [generateFrom_pi.symm, comap_generateFrom]
    congr
  let πTβ := Set.pi (Set.univ : Set T) ''
      Set.pi (Set.univ : Set T) fun i => { s : Set (β i) | MeasurableSet[m i] s }
  let πT := { s : Set Ω | ∃ t ∈ πTβ, (fun a (i : T) => f i a) ⁻¹' t = s }
  have hπT_pi : IsPiSystem πT := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _
  have hπT_gen : (MeasurableSpace.pi.comap fun a (i : T) => f i a) = generateFrom πT := by
    rw [generateFrom_pi.symm, comap_generateFrom]
    congr
  -- To prove independence, we prove independence of the generating π-systems.
  refine IndepSets.indep (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i))
    (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i)) hπS_pi hπT_pi hπS_gen hπT_gen
    ?_
  rintro _ _ ⟨s, ⟨sets_s, hs1, hs2⟩, rfl⟩ ⟨t, ⟨sets_t, ht1, ht2⟩, rfl⟩
  simp only [Set.mem_univ_pi, Set.mem_setOf_eq] at hs1 ht1
  

Proof state:
case intro.intro.intro.intro.intro.intro.intro.intro
α : Type u_1
Ω : Type u_2
ι : Type u_3
β✝ : Type u_4
β' : Type u_5
γ : Type u_6
γ' : Type u_7
_mα : MeasurableSpace α
_mΩ : MeasurableSpace Ω
κ : ↥(kernel α Ω)
μ : Measure α
f✝ : Ω → β✝
g : Ω → β'
β : ι → Type u_8
m : (i : ι) → MeasurableSpace (β i)
f : (i : ι) → Ω → β i
inst✝ : IsMarkovKernel κ
S T : Finset ι
hST : Disjoint S T
hf_Indep : iIndepFun m f κ
hf_meas : ∀ (i : ι), Measurable (f i)
πSβ : Set (Set ((i : { x // x ∈ S }) → β ↑i)) := Set.pi Set.univ '' Set.pi Set.univ fun i => {s | MeasurableSet s}
πS : Set (Set Ω) := {s | ∃ t ∈ πSβ, (fun a i => f (↑i) a) ⁻¹' t = s}
hπS_pi : IsPiSystem πS
hπS_gen : MeasurableSpace.comap (fun a i => f (↑i) a) pi = generateFrom πS
πTβ : Set (Set ((i : { x // x ∈ T }) → β ↑i)) := Set.pi Set.univ '' Set.pi Set.univ fun i => {s | MeasurableSet s}
πT : Set (Set Ω) := {s | ∃ t ∈ πTβ, (fun a i => f (↑i) a) ⁻¹' t = s}
hπT_pi : IsPiSystem πT
hπT_gen : MeasurableSpace.comap (fun a i => f (↑i) a) pi = generateFrom πT
s : Set ((i : { x // x ∈ S }) → β ↑i)
sets_s : (i : { x // x ∈ S }) → Set (β ↑i)
hs2 : Set.pi Set.univ sets_s = s
t : Set ((i : { x // x ∈ T }) → β ↑i)
sets_t : (i : { x // x ∈ T }) → Set (β ↑i)
ht2 : Set.pi Set.univ sets_t = t
hs1 : ∀ (i : { x // x ∈ S }), MeasurableSet (sets_s i)
ht1 : ∀ (i : { x // x ∈ T }), MeasurableSet (sets_t i)
⊢ ∀ᵐ (a : α) ∂μ,
    ↑↑(κ a) ((fun a i => f (↑i) a) ⁻¹' s ∩ (fun a i => f (↑i) a) ⁻¹' t) =
      ↑↑(κ a) ((fun a i => f (↑i) a) ⁻¹' s) * ↑↑(κ a) ((fun a i => f (↑i) a) ⁻¹' t)

Next tactic:
rw [← hs2, ← ht2]