Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - chore: Split data.set.pairwise #3117

Closed
wants to merge 10 commits into from
3 changes: 2 additions & 1 deletion Mathlib.lean
Expand Up @@ -948,7 +948,8 @@ import Mathlib.Data.Set.Lattice
import Mathlib.Data.Set.MulAntidiagonal
import Mathlib.Data.Set.NAry
import Mathlib.Data.Set.Opposite
import Mathlib.Data.Set.Pairwise
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Data.Set.Pairwise.Lattice
import Mathlib.Data.Set.Pointwise.Basic
import Mathlib.Data.Set.Pointwise.BigOperators
import Mathlib.Data.Set.Pointwise.Finite
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Algebra/BigOperators/Basic.lean
Expand Up @@ -4,7 +4,7 @@
Authors: Johannes Hölzl

! This file was ported from Lean 3 source module algebra.big_operators.basic
! leanprover-community/mathlib commit 6c5f73fd6f6cc83122788a80a27cdd54663609f4
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 7 in Mathlib/Algebra/BigOperators/Basic.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/algebra/big_operators/basic?range=6c5f73fd6f6cc83122788a80a27cdd54663609f4..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
Expand All @@ -17,7 +17,7 @@
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Multiset.Powerset
import Mathlib.Data.Set.Pairwise
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Tactic.ScopedNS

/-!
Expand Down
1 change: 1 addition & 0 deletions Mathlib/Data/Finset/Basic.lean
Expand Up @@ -9,6 +9,7 @@ Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
! if you have ported upstream changes.
-/
import Mathlib.Data.Multiset.FinsetOps
import Mathlib.Data.Set.Lattice
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we understand why this import is needed here but not in mathlib?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try removing it again with the intermediate backport now in place (once we have a cache)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems that mathlib3 gets it from these tactic imports:

import tactic.apply
import tactic.nth_rewrite
import tactic.monotonicity


/-!
# Finite sets
Expand Down
3 changes: 1 addition & 2 deletions Mathlib/Data/Finset/Option.lean
Expand Up @@ -4,12 +4,11 @@
Authors: Yury Kudryashov, Mario Carneiro, Sean Leather

! This file was ported from Lean 3 source module data.finset.option
! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 7 in Mathlib/Data/Finset/Option.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/data/finset/option?range=9003f28797c0664a49e4179487267c494477d853..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Finset.Card
import Mathlib.Order.Hom.Basic

/-!
# Finite sets in `option α`
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/List/Nodup.lean
Expand Up @@ -4,14 +4,14 @@
Authors: Mario Carneiro, Kenny Lau

! This file was ported from Lean 3 source module data.list.nodup
! leanprover-community/mathlib commit f694c7dead66f5d4c80f446c796a5aad14707f0e
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 7 in Mathlib/Data/List/Nodup.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/data/list/nodup?range=f694c7dead66f5d4c80f446c796a5aad14707f0e..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.List.Lattice
import Mathlib.Data.List.Pairwise
import Mathlib.Data.List.Forall2
import Mathlib.Data.Set.Pairwise
import Mathlib.Data.Set.Pairwise.Basic

/-!
# Lists with no duplicates
Expand Down
7 changes: 6 additions & 1 deletion Mathlib/Data/Multiset/FinsetOps.lean
Expand Up @@ -4,7 +4,7 @@
Authors: Mario Carneiro

! This file was ported from Lean 3 source module data.multiset.finset_ops
! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 7 in Mathlib/Data/Multiset/FinsetOps.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/data/multiset/finset_ops?range=9003f28797c0664a49e4179487267c494477d853..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
Expand Down Expand Up @@ -287,3 +287,8 @@
#align multiset.ndinter_eq_zero_iff_disjoint Multiset.ndinter_eq_zero_iff_disjoint

end Multiset

-- Porting note: `assert_not_exists` has not been ported yet.
-- -- Assert that we define `finset` without the material on the set lattice.
-- -- Note that we cannot put this in `data.finset.basic` because we proved relevant lemmas there.
-- assert_not_exists set.sInter
2 changes: 1 addition & 1 deletion Mathlib/Data/Prod/TProd.lean
Expand Up @@ -4,7 +4,7 @@
Authors: Floris van Doorn

! This file was ported from Lean 3 source module data.prod.tprod
! leanprover-community/mathlib commit 7b78d1776212a91ecc94cf601f83bdcc46b04213
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 7 in Mathlib/Data/Prod/TProd.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/data/prod/tprod?range=7b78d1776212a91ecc94cf601f83bdcc46b04213..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/Set/Intervals/Group.lean
Expand Up @@ -5,12 +5,12 @@
Ported by: Winston Yin

! This file was ported from Lean 3 source module data.set.intervals.group
! leanprover-community/mathlib commit 740acc0e6f9adf4423f92a485d0456fc271482da
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check notice on line 8 in Mathlib/Data/Set/Intervals/Group.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Synchronization

See https://leanprover-community.github.io/mathlib-port-status/file/data/set/intervals/group?range=740acc0e6f9adf4423f92a485d0456fc271482da..c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Set.Intervals.Basic
import Mathlib.Data.Set.Pairwise
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.GroupPower.Lemmas

Expand Down
Expand Up @@ -3,22 +3,22 @@
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl

! This file was ported from Lean 3 source module data.set.pairwise
! leanprover-community/mathlib commit 207cfac9fcd06138865b5d04f7091e46d9320432
! This file was ported from Lean 3 source module data.set.pairwise.basic
Parcly-Taxel marked this conversation as resolved.
Show resolved Hide resolved
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0

Check warning on line 7 in Mathlib/Data/Set/Pairwise/Basic.lean

View workflow job for this annotation

GitHub Actions / Add annotations

Filename changed!

VersionInfo(module='data.set.pairwise', repo='leanprover-community/mathlib', commit='207cfac9fcd06138865b5d04f7091e46d9320432', commit_line_no=7) -> VersionInfo(module='data.set.pairwise.basic', repo='leanprover-community/mathlib', commit='c227d107bbada5d0d9d20287e3282c0a7f1651a0', commit_line_no=7)
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Set.Function
import Mathlib.Logic.Relation
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.Lattice

/-!
# Relations holding pairwise

This file develops pairwise relations and defines pairwise disjoint indexed sets.

We also prove many basic facts about `Pairwise`. It is possible that an intermediate file,
with more imports than `Logic.Pairwise` but not importing `Data.Set.Lattice` would be appropriate
with more imports than `Logic.Pairwise` but not importing `Data.Set.Function` would be appropriate
to hold many of these basic facts.

## Main declarations
Expand Down Expand Up @@ -65,10 +65,6 @@
hs.mono fun i j hij => Disjoint.mono (h i) (h j) hij
#align pairwise_disjoint.mono pairwise_disjoint_mono

-- porting note:
-- alias Function.injective_iff_pairwise_ne ↔ Function.Injective.pairwise_ne _
-- is already present in Mathlib.Logic.Pairwise.

namespace Set

theorem Pairwise.mono (h : t ⊆ s) (hs : s.Pairwise r) : t.Pairwise r :=
Expand Down Expand Up @@ -221,23 +217,6 @@
simp (config := { contextual := true }) [h.eq_iff, Set.Pairwise]
#align set.inj_on.pairwise_image Set.InjOn.pairwise_image

theorem pairwise_unionᵢ {f : ι → Set α} (h : Directed (· ⊆ ·) f) :
(⋃ n, f n).Pairwise r ↔ ∀ n, (f n).Pairwise r := by
constructor
· intro H n
exact Pairwise.mono (subset_unionᵢ _ _) H
· intro H i hi j hj hij
rcases mem_unionᵢ.1 hi with ⟨m, hm⟩
rcases mem_unionᵢ.1 hj with ⟨n, hn⟩
rcases h m n with ⟨p, mp, np⟩
exact H p (mp hm) (np hn) hij
#align set.pairwise_Union Set.pairwise_unionᵢ

theorem pairwise_unionₛ {r : α → α → Prop} {s : Set (Set α)} (h : DirectedOn (· ⊆ ·) s) :
(⋃₀s).Pairwise r ↔ ∀ a ∈ s, Set.Pairwise a r := by
rw [unionₛ_eq_unionᵢ, pairwise_unionᵢ h.directed_val, SetCoe.forall]
#align set.pairwise_sUnion Set.pairwise_unionₛ

end Set

end Pairwise
Expand Down Expand Up @@ -339,16 +318,6 @@
pairwiseDisjoint_union.2 ⟨hs, ht, h⟩
#align set.pairwise_disjoint.union Set.PairwiseDisjoint.union

theorem pairwiseDisjoint_unionᵢ {g : ι' → Set ι} (h : Directed (· ⊆ ·) g) :
(⋃ n, g n).PairwiseDisjoint f ↔ ∀ ⦃n⦄, (g n).PairwiseDisjoint f :=
pairwise_unionᵢ h
#align set.pairwise_disjoint_Union Set.pairwiseDisjoint_unionᵢ

theorem pairwiseDisjoint_unionₛ {s : Set (Set ι)} (h : DirectedOn (· ⊆ ·) s) :
(⋃₀s).PairwiseDisjoint f ↔ ∀ ⦃a⦄, a ∈ s → PairwiseDisjoint a f :=
pairwise_unionₛ h
#align set.pairwise_disjoint_sUnion Set.pairwiseDisjoint_unionₛ

-- classical
theorem PairwiseDisjoint.elim (hs : s.PairwiseDisjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s)
(h : ¬Disjoint (f i) (f j)) : i = j :=
Expand All @@ -374,29 +343,6 @@

end SemilatticeInfBot

section CompleteLattice

variable [CompleteLattice α]

/-- Bind operation for `Set.PairwiseDisjoint`. If you want to only consider finsets of indices, you
can use `Set.PairwiseDisjoint.bunionᵢ_finset`. -/
theorem PairwiseDisjoint.bunionᵢ {s : Set ι'} {g : ι' → Set ι} {f : ι → α}
(hs : s.PairwiseDisjoint fun i' : ι' => ⨆ i ∈ g i', f i)
(hg : ∀ i ∈ s, (g i).PairwiseDisjoint f) : (⋃ i ∈ s, g i).PairwiseDisjoint f := by
rintro a ha b hb hab
simp_rw [mem_unionᵢ] at ha hb
obtain ⟨c, hc, ha⟩ := ha
obtain ⟨d, hd, hb⟩ := hb
obtain hcd | hcd := eq_or_ne (g c) (g d)
· exact hg d hd (hcd.subst ha) hb hab
-- Porting note: the elaborator couldn't figure out `f` here.
· exact (hs hc hd <| ne_of_apply_ne _ hcd).mono
(le_supᵢ₂ (f := fun i (_ : i ∈ g c) => f i) a ha)
(le_supᵢ₂ (f := fun i (_ : i ∈ g d) => f i) b hb)
#align set.pairwise_disjoint.bUnion Set.PairwiseDisjoint.bunionᵢ

end CompleteLattice

/-! ### Pairwise disjoint set of sets -/

theorem pairwiseDisjoint_range_singleton :
Expand All @@ -415,22 +361,6 @@
hs.elim hi hj <| not_disjoint_iff.2 ⟨a, hai, haj⟩
#align set.pairwise_disjoint.elim_set Set.PairwiseDisjoint.elim_set

theorem bunionᵢ_diff_bunionᵢ_eq {s t : Set ι} {f : ι → Set α} (h : (s ∪ t).PairwiseDisjoint f) :
((⋃ i ∈ s, f i) \ ⋃ i ∈ t, f i) = ⋃ i ∈ s \ t, f i := by
refine'
(bunionᵢ_diff_bunionᵢ_subset f s t).antisymm
(unionᵢ₂_subset fun i hi a ha => (mem_diff _).2 ⟨mem_bunionᵢ hi.1 ha, _⟩)
rw [mem_unionᵢ₂]; rintro ⟨j, hj, haj⟩
exact (h (Or.inl hi.1) (Or.inr hj) (ne_of_mem_of_not_mem hj hi.2).symm).le_bot ⟨ha, haj⟩
#align set.bUnion_diff_bUnion_eq Set.bunionᵢ_diff_bunionᵢ_eq

/-- Equivalence between a disjoint bounded union and a dependent sum. -/
noncomputable def bunionᵢEqSigmaOfDisjoint {s : Set ι} {f : ι → Set α} (h : s.PairwiseDisjoint f) :
(⋃ i ∈ s, f i) ≃ Σi : s, f i :=
(Equiv.setCongr (bunionᵢ_eq_unionᵢ _ _)).trans <|
unionEqSigmaOfDisjoint fun ⟨_i, hi⟩ ⟨_j, hj⟩ ne => (h hi hj) fun eq => ne <| Subtype.eq eq
#align set.bUnion_eq_sigma_of_disjoint Set.bunionᵢEqSigmaOfDisjoint

/-- The partial images of a binary function `f` whose partial evaluations are injective are pairwise
disjoint iff `f` is injective . -/
theorem pairwiseDisjoint_image_right_iff {f : α → β → γ} {s : Set α} {t : Set β}
Expand Down Expand Up @@ -466,29 +396,3 @@
theorem pairwise_disjoint_fiber (f : ι → α) : Pairwise (Disjoint on fun a : α => f ⁻¹' {a}) :=
pairwise_univ.1 <| Set.pairwiseDisjoint_fiber f univ
#align pairwise_disjoint_fiber pairwise_disjoint_fiber

section

variable {f : ι → Set α} {s t : Set ι}

theorem Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ (h₀ : (s ∪ t).PairwiseDisjoint f)
(h₁ : ∀ i ∈ s, (f i).Nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) : s ⊆ t := by
rintro i hi
obtain ⟨a, hai⟩ := h₁ i hi
obtain ⟨j, hj, haj⟩ := mem_unionᵢ₂.1 (h <| mem_unionᵢ₂_of_mem hi hai)
rwa [h₀.eq (subset_union_left _ _ hi) (subset_union_right _ _ hj)
(not_disjoint_iff.2 ⟨a, hai, haj⟩)]
#align set.pairwise_disjoint.subset_of_bUnion_subset_bUnion Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ

theorem Pairwise.subset_of_bunionᵢ_subset_bunionᵢ (h₀ : Pairwise (Disjoint on f))
(h₁ : ∀ i ∈ s, (f i).Nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) : s ⊆ t :=
Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ (h₀.set_pairwise _) h₁ h
#align pairwise.subset_of_bUnion_subset_bUnion Pairwise.subset_of_bunionᵢ_subset_bunionᵢ

theorem Pairwise.bunionᵢ_injective (h₀ : Pairwise (Disjoint on f)) (h₁ : ∀ i, (f i).Nonempty) :
Injective fun s : Set ι => ⋃ i ∈ s, f i := fun _ _ h =>
((h₀.subset_of_bunionᵢ_subset_bunionᵢ fun _ _ => h₁ _) <| h.subset).antisymm <|
(h₀.subset_of_bunionᵢ_subset_bunionᵢ fun _ _ => h₁ _) <| h.superset
#align pairwise.bUnion_injective Pairwise.bunionᵢ_injective

end
121 changes: 121 additions & 0 deletions Mathlib/Data/Set/Pairwise/Lattice.lean
@@ -0,0 +1,121 @@
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl

! This file was ported from Lean 3 source module data.set.pairwise.lattice
! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Data.Set.Pairwise.Basic

/-!
# Relations holding pairwise
In this file we prove many facts about `pairwise` and the set lattice.
-/

open Set Function

variable {α β γ ι ι' : Type _} {r p q : α → α → Prop} {s t : Set ι}

namespace Set
variable {f g : ι → α}

theorem pairwise_unionᵢ {f : ι → Set α} (h : Directed (· ⊆ ·) f) :
(⋃ n, f n).Pairwise r ↔ ∀ n, (f n).Pairwise r := by
constructor
· intro H n
exact Pairwise.mono (subset_unionᵢ _ _) H
· intro H i hi j hj hij
rcases mem_unionᵢ.1 hi with ⟨m, hm⟩
rcases mem_unionᵢ.1 hj with ⟨n, hn⟩
rcases h m n with ⟨p, mp, np⟩
exact H p (mp hm) (np hn) hij
#align set.pairwise_Union Set.pairwise_unionᵢ

theorem pairwise_unionₛ {r : α → α → Prop} {s : Set (Set α)} (h : DirectedOn (· ⊆ ·) s) :
(⋃₀s).Pairwise r ↔ ∀ a ∈ s, Set.Pairwise a r := by
rw [unionₛ_eq_unionᵢ, pairwise_unionᵢ h.directed_val, SetCoe.forall]
#align set.pairwise_sUnion Set.pairwise_unionₛ

section PartialOrder
variable [PartialOrder α] [OrderBot α]

theorem pairwiseDisjoint_unionᵢ {g : ι' → Set ι} (h : Directed (· ⊆ ·) g) :
(⋃ n, g n).PairwiseDisjoint f ↔ ∀ ⦃n⦄, (g n).PairwiseDisjoint f :=
pairwise_unionᵢ h
#align set.pairwise_disjoint_Union Set.pairwiseDisjoint_unionᵢ

theorem pairwiseDisjoint_unionₛ {s : Set (Set ι)} (h : DirectedOn (· ⊆ ·) s) :
(⋃₀s).PairwiseDisjoint f ↔ ∀ ⦃a⦄, a ∈ s → PairwiseDisjoint a f :=
pairwise_unionₛ h
#align set.pairwise_disjoint_sUnion Set.pairwiseDisjoint_unionₛ

end PartialOrder

section CompleteLattice
variable [CompleteLattice α]

/-- Bind operation for `Set.PairwiseDisjoint`. If you want to only consider finsets of indices, you
can use `Set.PairwiseDisjoint.bunionᵢ_finset`. -/
theorem PairwiseDisjoint.bunionᵢ {s : Set ι'} {g : ι' → Set ι}
(hs : s.PairwiseDisjoint fun i' : ι' => ⨆ i ∈ g i', f i)
(hg : ∀ i ∈ s, (g i).PairwiseDisjoint f) : (⋃ i ∈ s, g i).PairwiseDisjoint f := by
rintro a ha b hb hab
simp_rw [mem_unionᵢ] at ha hb
obtain ⟨c, hc, ha⟩ := ha
obtain ⟨d, hd, hb⟩ := hb
obtain hcd | hcd := eq_or_ne (g c) (g d)
· exact hg d hd (hcd.subst ha) hb hab
-- Porting note: the elaborator couldn't figure out `f` here.
· exact (hs hc hd <| ne_of_apply_ne _ hcd).mono
(le_supᵢ₂ (f := fun i (_ : i ∈ g c) => f i) a ha)
(le_supᵢ₂ (f := fun i (_ : i ∈ g d) => f i) b hb)
#align set.pairwise_disjoint.bUnion Set.PairwiseDisjoint.bunionᵢ

end CompleteLattice

theorem bunionᵢ_diff_bunionᵢ_eq {s t : Set ι} {f : ι → Set α} (h : (s ∪ t).PairwiseDisjoint f) :
((⋃ i ∈ s, f i) \ ⋃ i ∈ t, f i) = ⋃ i ∈ s \ t, f i := by
refine'
(bunionᵢ_diff_bunionᵢ_subset f s t).antisymm
(unionᵢ₂_subset fun i hi a ha => (mem_diff _).2 ⟨mem_bunionᵢ hi.1 ha, _⟩)
rw [mem_unionᵢ₂]; rintro ⟨j, hj, haj⟩
exact (h (Or.inl hi.1) (Or.inr hj) (ne_of_mem_of_not_mem hj hi.2).symm).le_bot ⟨ha, haj⟩
#align set.bUnion_diff_bUnion_eq Set.bunionᵢ_diff_bunionᵢ_eq

/-- Equivalence between a disjoint bounded union and a dependent sum. -/
noncomputable def bunionᵢEqSigmaOfDisjoint {s : Set ι} {f : ι → Set α} (h : s.PairwiseDisjoint f) :
(⋃ i ∈ s, f i) ≃ Σ i : s, f i :=
(Equiv.setCongr (bunionᵢ_eq_unionᵢ _ _)).trans <|
unionEqSigmaOfDisjoint fun ⟨_i, hi⟩ ⟨_j, hj⟩ ne => (h hi hj) fun eq => ne <| Subtype.eq eq
#align set.bUnion_eq_sigma_of_disjoint Set.bunionᵢEqSigmaOfDisjoint

end Set

section
variable {f : ι → Set α} {s t : Set ι}

theorem Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ (h₀ : (s ∪ t).PairwiseDisjoint f)
(h₁ : ∀ i ∈ s, (f i).Nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) : s ⊆ t := by
rintro i hi
obtain ⟨a, hai⟩ := h₁ i hi
obtain ⟨j, hj, haj⟩ := mem_unionᵢ₂.1 (h <| mem_unionᵢ₂_of_mem hi hai)
rwa [h₀.eq (subset_union_left _ _ hi) (subset_union_right _ _ hj)
(not_disjoint_iff.2 ⟨a, hai, haj⟩)]
#align set.pairwise_disjoint.subset_of_bUnion_subset_bUnion Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ

theorem Pairwise.subset_of_bunionᵢ_subset_bunionᵢ (h₀ : Pairwise (Disjoint on f))
(h₁ : ∀ i ∈ s, (f i).Nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) : s ⊆ t :=
Set.PairwiseDisjoint.subset_of_bunionᵢ_subset_bunionᵢ (h₀.set_pairwise _) h₁ h
#align pairwise.subset_of_bUnion_subset_bUnion Pairwise.subset_of_bunionᵢ_subset_bunionᵢ

theorem Pairwise.bunionᵢ_injective (h₀ : Pairwise (Disjoint on f)) (h₁ : ∀ i, (f i).Nonempty) :
Injective fun s : Set ι => ⋃ i ∈ s, f i := fun _ _ h =>
((h₀.subset_of_bunionᵢ_subset_bunionᵢ fun _ _ => h₁ _) <| h.subset).antisymm <|
(h₀.subset_of_bunionᵢ_subset_bunionᵢ fun _ _ => h₁ _) <| h.superset
#align pairwise.bUnion_injective Pairwise.bunionᵢ_injective

end