/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies

! This file was ported from Lean 3 source module data.set.sigma
! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Data.Set.Image

/-!
# Sets in sigma types

> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.

This file defines `set.sigma`, the indexed sum of sets.
-/

namespace Set

variable {ι ι' : Type _} {α β : ι → Type _} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)}
  {u : Set (Σi, α i)} {x : Σi, α i} {i j : ι} {a : α i}

/- warning: set.range_sigma_mk -> Set.range_sigmaMk is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} (i : ι), Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι α)) (Set.range.{max u1 u2, succ u2} (Sigma.{u1, u2} ι α) (α i) (Sigma.mk.{u1, u2} ι α i)) (Set.preimage.{max u1 u2, u1} (Sigma.{u1, u2} ι α) ι (Sigma.fst.{u1, u2} ι α) (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.hasSingleton.{u1} ι) i))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} (i : ι), Eq.{max (succ u2) (succ u1)} (Set.{max u2 u1} (Sigma.{u2, u1} ι α)) (Set.range.{max u2 u1, succ u1} (Sigma.{u2, u1} ι α) (α i) (Sigma.mk.{u2, u1} ι α i)) (Set.preimage.{max u1 u2, u2} (Sigma.{u2, u1} ι α) ι (Sigma.fst.{u2, u1} ι α) (Singleton.singleton.{u2, u2} ι (Set.{u2} ι) (Set.instSingletonSet.{u2} ι) i))
Case conversion may be inaccurate. Consider using '#align set.range_sigma_mk Set.range_sigmaMkₓ'. -/
@[simp]
theorem range_sigmaMk (i : ι) : range (Sigma.mk i : α i → Sigma α) = Sigma.fst ⁻¹' {i} :=
  by
  apply subset.antisymm
  · rintro _ ⟨b, rfl⟩
    simp
  · rintro ⟨x, y⟩ (rfl | _)
    exact mem_range_self y
#align set.range_sigma_mk Set.range_sigmaMk

/- warning: set.preimage_image_sigma_mk_of_ne -> Set.preimage_image_sigmaMk_of_ne is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {i : ι} {j : ι}, (Ne.{succ u1} ι i j) -> (forall (s : Set.{u2} (α j)), Eq.{succ u2} (Set.{u2} (α i)) (Set.preimage.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun {j : ι} => α j)) (Sigma.mk.{u1, u2} ι (fun {j : ι} => α j) i) (Set.image.{u2, max u1 u2} (α j) (Sigma.{u1, u2} ι (fun {j : ι} => α j)) (Sigma.mk.{u1, u2} ι (fun {j : ι} => α j) j) s)) (EmptyCollection.emptyCollection.{u2} (Set.{u2} (α i)) (Set.hasEmptyc.{u2} (α i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {i : ι} {j : ι}, (Ne.{succ u2} ι i j) -> (forall (s : Set.{u1} (α j)), Eq.{succ u1} (Set.{u1} (α i)) (Set.preimage.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι α) (Sigma.mk.{u2, u1} ι α i) (Set.image.{u1, max u2 u1} (α j) (Sigma.{u2, u1} ι α) (Sigma.mk.{u2, u1} ι α j) s)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} (α i)) (Set.instEmptyCollectionSet.{u1} (α i))))
Case conversion may be inaccurate. Consider using '#align set.preimage_image_sigma_mk_of_ne Set.preimage_image_sigmaMk_of_neₓ'. -/
theorem preimage_image_sigmaMk_of_ne (h : i ≠ j) (s : Set (α j)) :
    Sigma.mk i ⁻¹' (Sigma.mk j '' s) = ∅ := by
  ext x
  simp [h.symm]
#align set.preimage_image_sigma_mk_of_ne Set.preimage_image_sigmaMk_of_ne

/- warning: set.image_sigma_mk_preimage_sigma_map_subset -> Set.image_sigmaMk_preimage_sigmaMap_subset is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {ι' : Type.{u2}} {α : ι -> Type.{u3}} {β : ι' -> Type.{u4}} (f : ι -> ι') (g : forall (i : ι), (α i) -> (β (f i))) (i : ι) (s : Set.{u4} (β (f i))), HasSubset.Subset.{max u1 u3} (Set.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => α i))) (Set.hasSubset.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => α i))) (Set.image.{u3, max u1 u3} (α i) (Sigma.{u1, u3} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u3} ι (fun (i : ι) => α i) i) (Set.preimage.{u3, u4} (α i) (β (f i)) (g i) s)) (Set.preimage.{max u1 u3, max u2 u4} (Sigma.{u1, u3} ι (fun (i : ι) => α i)) (Sigma.{u2, u4} ι' β) (Sigma.map.{u1, u2, u3, u4} ι ι' (fun (i : ι) => α i) β f g) (Set.image.{u4, max u2 u4} (β (f i)) (Sigma.{u2, u4} ι' β) (Sigma.mk.{u2, u4} ι' β (f i)) s))
but is expected to have type
  forall {ι : Type.{u3}} {ι' : Type.{u1}} {α : ι -> Type.{u2}} {β : ι' -> Type.{u4}} (f : ι -> ι') (g : forall (i : ι), (α i) -> (β (f i))) (i : ι) (s : Set.{u4} (β (f i))), HasSubset.Subset.{max u3 u2} (Set.{max u3 u2} (Sigma.{u3, u2} ι α)) (Set.instHasSubsetSet.{max u3 u2} (Sigma.{u3, u2} ι α)) (Set.image.{u2, max u3 u2} (α i) (Sigma.{u3, u2} ι α) (Sigma.mk.{u3, u2} ι α i) (Set.preimage.{u2, u4} (α i) (β (f i)) (g i) s)) (Set.preimage.{max u3 u2, max u4 u1} (Sigma.{u3, u2} ι α) (Sigma.{u1, u4} ι' β) (Sigma.map.{u3, u1, u2, u4} ι ι' α β f g) (Set.image.{u4, max u1 u4} (β (f i)) (Sigma.{u1, u4} ι' β) (Sigma.mk.{u1, u4} ι' β (f i)) s))
Case conversion may be inaccurate. Consider using '#align set.image_sigma_mk_preimage_sigma_map_subset Set.image_sigmaMk_preimage_sigmaMap_subsetₓ'. -/
theorem image_sigmaMk_preimage_sigmaMap_subset {β : ι' → Type _} (f : ι → ι')
    (g : ∀ i, α i → β (f i)) (i : ι) (s : Set (β (f i))) :
    Sigma.mk i '' (g i ⁻¹' s) ⊆ Sigma.map f g ⁻¹' (Sigma.mk (f i) '' s) :=
  image_subset_iff.2 fun x hx => ⟨g i x, hx, rfl⟩
#align set.image_sigma_mk_preimage_sigma_map_subset Set.image_sigmaMk_preimage_sigmaMap_subset

/- warning: set.image_sigma_mk_preimage_sigma_map -> Set.image_sigmaMk_preimage_sigmaMap is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {ι' : Type.{u2}} {α : ι -> Type.{u3}} {β : ι' -> Type.{u4}} {f : ι -> ι'}, (Function.Injective.{succ u1, succ u2} ι ι' f) -> (forall (g : forall (i : ι), (α i) -> (β (f i))) (i : ι) (s : Set.{u4} (β (f i))), Eq.{succ (max u1 u3)} (Set.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => α i))) (Set.image.{u3, max u1 u3} (α i) (Sigma.{u1, u3} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u3} ι (fun (i : ι) => α i) i) (Set.preimage.{u3, u4} (α i) (β (f i)) (g i) s)) (Set.preimage.{max u1 u3, max u2 u4} (Sigma.{u1, u3} ι (fun (i : ι) => α i)) (Sigma.{u2, u4} ι' β) (Sigma.map.{u1, u2, u3, u4} ι ι' (fun (i : ι) => α i) β f g) (Set.image.{u4, max u2 u4} (β (f i)) (Sigma.{u2, u4} ι' β) (Sigma.mk.{u2, u4} ι' β (f i)) s)))
but is expected to have type
  forall {ι : Type.{u3}} {ι' : Type.{u2}} {α : ι -> Type.{u1}} {β : ι' -> Type.{u4}} {f : ι -> ι'}, (Function.Injective.{succ u3, succ u2} ι ι' f) -> (forall (g : forall (i : ι), (α i) -> (β (f i))) (i : ι) (s : Set.{u4} (β (f i))), Eq.{max (succ u3) (succ u1)} (Set.{max u3 u1} (Sigma.{u3, u1} ι α)) (Set.image.{u1, max u3 u1} (α i) (Sigma.{u3, u1} ι α) (Sigma.mk.{u3, u1} ι α i) (Set.preimage.{u1, u4} (α i) (β (f i)) (g i) s)) (Set.preimage.{max u1 u3, max u4 u2} (Sigma.{u3, u1} ι (fun (i : ι) => α i)) (Sigma.{u2, u4} ι' β) (Sigma.map.{u3, u2, u1, u4} ι ι' (fun (i : ι) => α i) β f g) (Set.image.{u4, max u2 u4} (β (f i)) (Sigma.{u2, u4} ι' β) (Sigma.mk.{u2, u4} ι' β (f i)) s)))
Case conversion may be inaccurate. Consider using '#align set.image_sigma_mk_preimage_sigma_map Set.image_sigmaMk_preimage_sigmaMapₓ'. -/
theorem image_sigmaMk_preimage_sigmaMap {β : ι' → Type _} {f : ι → ι'} (hf : Function.Injective f)
    (g : ∀ i, α i → β (f i)) (i : ι) (s : Set (β (f i))) :
    Sigma.mk i '' (g i ⁻¹' s) = Sigma.map f g ⁻¹' (Sigma.mk (f i) '' s) :=
  by
  refine' (image_sigma_mk_preimage_sigma_map_subset f g i s).antisymm _
  rintro ⟨j, x⟩ ⟨y, hys, hxy⟩
  simp only [hf.eq_iff, Sigma.map] at hxy
  rcases hxy with ⟨rfl, hxy⟩; rw [heq_iff_eq] at hxy; subst y
  exact ⟨x, hys, rfl⟩
#align set.image_sigma_mk_preimage_sigma_map Set.image_sigmaMk_preimage_sigmaMap

#print Set.Sigma /-
/-- Indexed sum of sets. `s.sigma t` is the set of dependent pairs `⟨i, a⟩` such that `i ∈ s` and
`a ∈ t i`.-/
protected def Sigma (s : Set ι) (t : ∀ i, Set (α i)) : Set (Σi, α i) :=
  { x | x.1 ∈ s ∧ x.2 ∈ t x.1 }
#align set.sigma Set.Sigma
-/

/- warning: set.mem_sigma_iff -> Set.mem_sigma_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {x : Sigma.{u1, u2} ι (fun (i : ι) => α i)}, Iff (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) x (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (And (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x) s) (Membership.Mem.{u2, u2} (α (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x)) (Set.{u2} (α (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x))) (Set.hasMem.{u2} (α (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x))) (Sigma.snd.{u1, u2} ι (fun (i : ι) => α i) x) (t (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {x : Sigma.{u2, u1} ι (fun (i : ι) => α i)}, Iff (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) x (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (And (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i) x) s) (Membership.mem.{u1, u1} (α (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i) x)) (Set.{u1} (α (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i) x))) (Set.instMembershipSet.{u1} (α (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i) x))) (Sigma.snd.{u2, u1} ι (fun (i : ι) => α i) x) (t (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i) x))))
Case conversion may be inaccurate. Consider using '#align set.mem_sigma_iff Set.mem_sigma_iffₓ'. -/
@[simp]
theorem mem_sigma_iff : x ∈ s.Sigma t ↔ x.1 ∈ s ∧ x.2 ∈ t x.1 :=
  Iff.rfl
#align set.mem_sigma_iff Set.mem_sigma_iff

/- warning: set.mk_sigma_iff -> Set.mk_sigma_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι} {a : α i}, Iff (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i a) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (And (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} {a : α i}, Iff (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i a) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (And (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (Membership.mem.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instMembershipSet.{u1} (α i)) a (t i)))
Case conversion may be inaccurate. Consider using '#align set.mk_sigma_iff Set.mk_sigma_iffₓ'. -/
@[simp]
theorem mk_sigma_iff : (⟨i, a⟩ : Σi, α i) ∈ s.Sigma t ↔ i ∈ s ∧ a ∈ t i :=
  Iff.rfl
#align set.mk_sigma_iff Set.mk_sigma_iff

/- warning: set.mk_mem_sigma -> Set.mk_mem_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι} {a : α i}, (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)) -> (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i a) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} {a : α i}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (Membership.mem.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instMembershipSet.{u1} (α i)) a (t i)) -> (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i a) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.mk_mem_sigma Set.mk_mem_sigmaₓ'. -/
theorem mk_mem_sigma (hi : i ∈ s) (ha : a ∈ t i) : (⟨i, a⟩ : Σi, α i) ∈ s.Sigma t :=
  ⟨hi, ha⟩
#align set.mk_mem_sigma Set.mk_mem_sigma

/- warning: set.sigma_mono -> Set.sigma_mono is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s₁ : Set.{u1} ι} {s₂ : Set.{u1} ι} {t₁ : forall (i : ι), Set.{u2} (α i)} {t₂ : forall (i : ι), Set.{u2} (α i)}, (HasSubset.Subset.{u1} (Set.{u1} ι) (Set.hasSubset.{u1} ι) s₁ s₂) -> (forall (i : ι), HasSubset.Subset.{u2} (Set.{u2} (α i)) (Set.hasSubset.{u2} (α i)) (t₁ i) (t₂ i)) -> (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasSubset.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₂ t₂))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s₁ : Set.{u2} ι} {s₂ : Set.{u2} ι} {t₁ : forall (i : ι), Set.{u1} (α i)} {t₂ : forall (i : ι), Set.{u1} (α i)}, (HasSubset.Subset.{u2} (Set.{u2} ι) (Set.instHasSubsetSet.{u2} ι) s₁ s₂) -> (forall (i : ι), HasSubset.Subset.{u1} (Set.{u1} (α i)) (Set.instHasSubsetSet.{u1} (α i)) (t₁ i) (t₂ i)) -> (HasSubset.Subset.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instHasSubsetSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₂ t₂))
Case conversion may be inaccurate. Consider using '#align set.sigma_mono Set.sigma_monoₓ'. -/
theorem sigma_mono (hs : s₁ ⊆ s₂) (ht : ∀ i, t₁ i ⊆ t₂ i) : s₁.Sigma t₁ ⊆ s₂.Sigma t₂ := fun x hx =>
  ⟨hs hx.1, ht _ hx.2⟩
#align set.sigma_mono Set.sigma_mono

/- warning: set.sigma_subset_iff -> Set.sigma_subset_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {u : Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))}, Iff (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasSubset.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t) u) (forall {{i : ι}}, (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (forall {{a : α i}}, (Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)) -> (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i a) u)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {u : Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))}, Iff (HasSubset.Subset.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instHasSubsetSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t) u) (forall {{i : ι}}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (forall {{a : α i}}, (Membership.mem.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instMembershipSet.{u1} (α i)) a (t i)) -> (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i a) u)))
Case conversion may be inaccurate. Consider using '#align set.sigma_subset_iff Set.sigma_subset_iffₓ'. -/
theorem sigma_subset_iff : s.Sigma t ⊆ u ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃a⦄, a ∈ t i → (⟨i, a⟩ : Σi, α i) ∈ u :=
  ⟨fun h i hi a ha => h <| mk_mem_sigma hi ha, fun h ⟨i, a⟩ ha => h ha.1 ha.2⟩
#align set.sigma_subset_iff Set.sigma_subset_iff

/- warning: set.forall_sigma_iff -> Set.forall_sigma_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {p : (Sigma.{u1, u2} ι (fun (i : ι) => α i)) -> Prop}, Iff (forall (x : Sigma.{u1, u2} ι (fun (i : ι) => α i)), (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) x (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) -> (p x)) (forall {{i : ι}}, (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (forall {{a : α i}}, (Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)) -> (p (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i a))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {p : (Sigma.{u2, u1} ι (fun (i : ι) => α i)) -> Prop}, Iff (forall (x : Sigma.{u2, u1} ι (fun (i : ι) => α i)), (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) x (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) -> (p x)) (forall {{i : ι}}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (forall {{a : α i}}, (Membership.mem.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instMembershipSet.{u1} (α i)) a (t i)) -> (p (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i a))))
Case conversion may be inaccurate. Consider using '#align set.forall_sigma_iff Set.forall_sigma_iffₓ'. -/
theorem forall_sigma_iff {p : (Σi, α i) → Prop} :
    (∀ x ∈ s.Sigma t, p x) ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃a⦄, a ∈ t i → p ⟨i, a⟩ :=
  sigma_subset_iff
#align set.forall_sigma_iff Set.forall_sigma_iff

/- warning: set.exists_sigma_iff -> Set.exists_sigma_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {p : (Sigma.{u1, u2} ι (fun (i : ι) => α i)) -> Prop}, Iff (Exists.{succ (max u1 u2)} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (fun (x : Sigma.{u1, u2} ι (fun (i : ι) => α i)) => Exists.{0} (Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) x (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (fun (H : Membership.Mem.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasMem.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) x (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) => p x))) (Exists.{succ u1} ι (fun (i : ι) => Exists.{0} (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (fun (H : Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) => Exists.{succ u2} (α i) (fun (a : α i) => Exists.{0} (Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)) (fun (H : Membership.Mem.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasMem.{u2} (α i)) a (t i)) => p (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i a))))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {p : (Sigma.{u2, u1} ι (fun (i : ι) => α i)) -> Prop}, Iff (Exists.{succ (max u2 u1)} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (fun (x : Sigma.{u2, u1} ι (fun (i : ι) => α i)) => And (Membership.mem.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instMembershipSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) x (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (p x))) (Exists.{succ u2} ι (fun (i : ι) => And (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (Exists.{succ u1} (α i) (fun (a : α i) => And (Membership.mem.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instMembershipSet.{u1} (α i)) a (t i)) (p (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i a))))))
Case conversion may be inaccurate. Consider using '#align set.exists_sigma_iff Set.exists_sigma_iffₓ'. -/
theorem exists_sigma_iff {p : (Σi, α i) → Prop} :
    (∃ x ∈ s.Sigma t, p x) ↔ ∃ i ∈ s, ∃ a ∈ t i, p ⟨i, a⟩ :=
  ⟨fun ⟨⟨i, a⟩, ha, h⟩ => ⟨i, ha.1, a, ha.2, h⟩, fun ⟨i, hi, a, ha, h⟩ => ⟨⟨i, a⟩, ⟨hi, ha⟩, h⟩⟩
#align set.exists_sigma_iff Set.exists_sigma_iff

/- warning: set.sigma_empty -> Set.sigma_empty is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s (fun (i : ι) => EmptyCollection.emptyCollection.{u2} (Set.{u2} (α i)) (Set.hasEmptyc.{u2} (α i)))) (EmptyCollection.emptyCollection.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasEmptyc.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s (fun (i : ι) => EmptyCollection.emptyCollection.{u1} (Set.{u1} (α i)) (Set.instEmptyCollectionSet.{u1} (α i)))) (EmptyCollection.emptyCollection.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instEmptyCollectionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))))
Case conversion may be inaccurate. Consider using '#align set.sigma_empty Set.sigma_emptyₓ'. -/
@[simp]
theorem sigma_empty : (s.Sigma fun i => (∅ : Set (α i))) = ∅ :=
  ext fun _ => and_false_iff _
#align set.sigma_empty Set.sigma_empty

/- warning: set.empty_sigma -> Set.empty_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {t : forall (i : ι), Set.{u2} (α i)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (EmptyCollection.emptyCollection.{u1} (Set.{u1} ι) (Set.hasEmptyc.{u1} ι)) t) (EmptyCollection.emptyCollection.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasEmptyc.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {t : forall (i : ι), Set.{u1} (α i)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (EmptyCollection.emptyCollection.{u2} (Set.{u2} ι) (Set.instEmptyCollectionSet.{u2} ι)) t) (EmptyCollection.emptyCollection.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instEmptyCollectionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))))
Case conversion may be inaccurate. Consider using '#align set.empty_sigma Set.empty_sigmaₓ'. -/
@[simp]
theorem empty_sigma : (∅ : Set ι).Sigma t = ∅ :=
  ext fun _ => false_and_iff _
#align set.empty_sigma Set.empty_sigma

/- warning: set.univ_sigma_univ -> Set.univ_sigma_univ is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {i : ι}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i_1 : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (_x : ι) => α i) (Set.univ.{u1} ι) (fun (_x : ι) => Set.univ.{u2} (α i))) (Set.univ.{max u1 u2} (Sigma.{u1, u2} ι (fun (i_1 : ι) => α i)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {i : ι}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i_1 : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (_x : ι) => α i) (Set.univ.{u2} ι) (fun (_x : ι) => Set.univ.{u1} (α i))) (Set.univ.{max u2 u1} (Sigma.{u2, u1} ι (fun (i_1 : ι) => α i)))
Case conversion may be inaccurate. Consider using '#align set.univ_sigma_univ Set.univ_sigma_univₓ'. -/
theorem univ_sigma_univ : ((@univ ι).Sigma fun _ => @univ (α i)) = univ :=
  ext fun _ => true_and_iff _
#align set.univ_sigma_univ Set.univ_sigma_univ

/- warning: set.sigma_univ -> Set.sigma_univ is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (_x : ι) => α _x) s (fun (_x : ι) => Set.univ.{u2} (α _x))) (Set.preimage.{max u1 u2, u1} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i)) s)
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (_x : ι) => α _x) s (fun (_x : ι) => Set.univ.{u1} (α _x))) (Set.preimage.{max u1 u2, u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i)) s)
Case conversion may be inaccurate. Consider using '#align set.sigma_univ Set.sigma_univₓ'. -/
@[simp]
theorem sigma_univ : s.Sigma (fun _ => univ : ∀ i, Set (α i)) = Sigma.fst ⁻¹' s :=
  ext fun _ => and_true_iff _
#align set.sigma_univ Set.sigma_univ

/- warning: set.singleton_sigma -> Set.singleton_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {t : forall (i : ι), Set.{u2} (α i)} {i : ι}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.hasSingleton.{u1} ι) i) t) (Set.image.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i) (t i))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} {a : α i}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Singleton.singleton.{u2, u2} ι (Set.{u2} ι) (Set.instSingletonSet.{u2} ι) i) t) (Set.image.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι α) (Sigma.mk.{u2, u1} ι α i) (t i))
Case conversion may be inaccurate. Consider using '#align set.singleton_sigma Set.singleton_sigmaₓ'. -/
@[simp]
theorem singleton_sigma : ({i} : Set ι).Sigma t = Sigma.mk i '' t i :=
  ext fun x => by
    constructor
    · obtain ⟨j, a⟩ := x
      rintro ⟨rfl : j = i, ha⟩
      exact mem_image_of_mem _ ha
    · rintro ⟨b, hb, rfl⟩
      exact ⟨rfl, hb⟩
#align set.singleton_sigma Set.singleton_sigma

/- warning: set.sigma_singleton -> Set.sigma_singleton is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {a : forall (i : ι), α i}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s (fun (i : ι) => Singleton.singleton.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasSingleton.{u2} (α i)) (a i))) (Set.image.{u1, max u1 u2} ι (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (fun (i : ι) => Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i (a i)) s)
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {a : forall (i : ι), α i}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s (fun (i : ι) => Singleton.singleton.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instSingletonSet.{u1} (α i)) (a i))) (Set.image.{u2, max u1 u2} ι (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (fun (i : ι) => Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i (a i)) s)
Case conversion may be inaccurate. Consider using '#align set.sigma_singleton Set.sigma_singletonₓ'. -/
@[simp]
theorem sigma_singleton {a : ∀ i, α i} :
    (s.Sigma fun i => ({a i} : Set (α i))) = (fun i => Sigma.mk i <| a i) '' s :=
  by
  ext ⟨x, y⟩
  simp [and_left_comm, eq_comm]
#align set.sigma_singleton Set.sigma_singleton

/- warning: set.singleton_sigma_singleton -> Set.singleton_sigma_singleton is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {i : ι} {a : forall (i : ι), α i}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.hasSingleton.{u1} ι) i) (fun (i : ι) => Singleton.singleton.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasSingleton.{u2} (α i)) (a i))) (Singleton.singleton.{max u1 u2, max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasSingleton.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i (a i)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {i : ι} {a : forall (i : ι), α i}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Singleton.singleton.{u2, u2} ι (Set.{u2} ι) (Set.instSingletonSet.{u2} ι) i) (fun (i : ι) => Singleton.singleton.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instSingletonSet.{u1} (α i)) (a i))) (Singleton.singleton.{max u2 u1, max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instSingletonSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i (a i)))
Case conversion may be inaccurate. Consider using '#align set.singleton_sigma_singleton Set.singleton_sigma_singletonₓ'. -/
theorem singleton_sigma_singleton {a : ∀ i, α i} :
    (({i} : Set ι).Sigma fun i => ({a i} : Set (α i))) = {⟨i, a i⟩} := by
  rw [sigma_singleton, image_singleton]
#align set.singleton_sigma_singleton Set.singleton_sigma_singleton

/- warning: set.union_sigma -> Set.union_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s₁ : Set.{u1} ι} {s₂ : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (Union.union.{u1} (Set.{u1} ι) (Set.hasUnion.{u1} ι) s₁ s₂) t) (Union.union.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasUnion.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₁ t) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₂ t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s₁ : Set.{u2} ι} {s₂ : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Union.union.{u2} (Set.{u2} ι) (Set.instUnionSet.{u2} ι) s₁ s₂) t) (Union.union.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instUnionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₁ t) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₂ t))
Case conversion may be inaccurate. Consider using '#align set.union_sigma Set.union_sigmaₓ'. -/
@[simp]
theorem union_sigma : (s₁ ∪ s₂).Sigma t = s₁.Sigma t ∪ s₂.Sigma t :=
  ext fun _ => or_and_right
#align set.union_sigma Set.union_sigma

/- warning: set.sigma_union -> Set.sigma_union is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t₁ : forall (i : ι), Set.{u2} (α i)} {t₂ : forall (i : ι), Set.{u2} (α i)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s (fun (i : ι) => Union.union.{u2} (Set.{u2} (α i)) (Set.hasUnion.{u2} (α i)) (t₁ i) (t₂ i))) (Union.union.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasUnion.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t₁) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t₂))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t₁ : forall (i : ι), Set.{u1} (α i)} {t₂ : forall (i : ι), Set.{u1} (α i)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s (fun (i : ι) => Union.union.{u1} (Set.{u1} (α i)) (Set.instUnionSet.{u1} (α i)) (t₁ i) (t₂ i))) (Union.union.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instUnionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t₁) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t₂))
Case conversion may be inaccurate. Consider using '#align set.sigma_union Set.sigma_unionₓ'. -/
@[simp]
theorem sigma_union : (s.Sigma fun i => t₁ i ∪ t₂ i) = s.Sigma t₁ ∪ s.Sigma t₂ :=
  ext fun _ => and_or_left
#align set.sigma_union Set.sigma_union

/- warning: set.sigma_inter_sigma -> Set.sigma_inter_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s₁ : Set.{u1} ι} {s₂ : Set.{u1} ι} {t₁ : forall (i : ι), Set.{u2} (α i)} {t₂ : forall (i : ι), Set.{u2} (α i)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Inter.inter.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasInter.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₂ t₂)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (Inter.inter.{u1} (Set.{u1} ι) (Set.hasInter.{u1} ι) s₁ s₂) (fun (i : ι) => Inter.inter.{u2} (Set.{u2} (α i)) (Set.hasInter.{u2} (α i)) (t₁ i) (t₂ i)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s₁ : Set.{u2} ι} {s₂ : Set.{u2} ι} {t₁ : forall (i : ι), Set.{u1} (α i)} {t₂ : forall (i : ι), Set.{u1} (α i)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Inter.inter.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instInterSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₂ t₂)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Inter.inter.{u2} (Set.{u2} ι) (Set.instInterSet.{u2} ι) s₁ s₂) (fun (i : ι) => Inter.inter.{u1} (Set.{u1} (α i)) (Set.instInterSet.{u1} (α i)) (t₁ i) (t₂ i)))
Case conversion may be inaccurate. Consider using '#align set.sigma_inter_sigma Set.sigma_inter_sigmaₓ'. -/
theorem sigma_inter_sigma : s₁.Sigma t₁ ∩ s₂.Sigma t₂ = (s₁ ∩ s₂).Sigma fun i => t₁ i ∩ t₂ i :=
  by
  ext ⟨x, y⟩
  simp [and_assoc', and_left_comm]
#align set.sigma_inter_sigma Set.sigma_inter_sigma

/- warning: set.insert_sigma -> Set.insert_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (Insert.insert.{u1, u1} ι (Set.{u1} ι) (Set.hasInsert.{u1} ι) i s) t) (Union.union.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasUnion.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.image.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i) (t i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} {a : α i}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Insert.insert.{u2, u2} ι (Set.{u2} ι) (Set.instInsertSet.{u2} ι) i s) t) (Union.union.{max u2 u1} (Set.{max u2 u1} (Sigma.{u2, u1} ι α)) (Set.instUnionSet.{max u2 u1} (Sigma.{u2, u1} ι α)) (Set.image.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι α) (Sigma.mk.{u2, u1} ι α i) (t i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.insert_sigma Set.insert_sigmaₓ'. -/
theorem insert_sigma : (insert i s).Sigma t = Sigma.mk i '' t i ∪ s.Sigma t := by
  rw [insert_eq, union_sigma, singleton_sigma]
#align set.insert_sigma Set.insert_sigma

/- warning: set.sigma_insert -> Set.sigma_insert is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {a : forall (i : ι), α i}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s (fun (i : ι) => Insert.insert.{u2, u2} (α i) (Set.{u2} (α i)) (Set.hasInsert.{u2} (α i)) (a i) (t i))) (Union.union.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasUnion.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.image.{u1, max u1 u2} ι (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (fun (i : ι) => Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i (a i)) s) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {a : forall (i : ι), α i}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s (fun (i : ι) => Insert.insert.{u1, u1} (α i) (Set.{u1} (α i)) (Set.instInsertSet.{u1} (α i)) (a i) (t i))) (Union.union.{max u2 u1} (Set.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instUnionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.image.{u2, max u2 u1} ι (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (fun (i : ι) => Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i (a i)) s) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.sigma_insert Set.sigma_insertₓ'. -/
theorem sigma_insert {a : ∀ i, α i} :
    (s.Sigma fun i => insert (a i) (t i)) = (fun i => ⟨i, a i⟩) '' s ∪ s.Sigma t := by
  simp_rw [insert_eq, sigma_union, sigma_singleton]
#align set.sigma_insert Set.sigma_insert

/- warning: set.sigma_preimage_eq -> Set.sigma_preimage_eq is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {ι' : Type.{u2}} {α : ι -> Type.{u3}} {β : ι -> Type.{u4}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u3} (α i)} {f : ι' -> ι} {g : forall (i : ι), (β i) -> (α i)}, Eq.{succ (max u2 u4)} (Set.{max u2 u4} (Sigma.{u2, u4} ι' (fun (i : ι') => β (f i)))) (Set.Sigma.{u2, u4} ι' (fun (i : ι') => β (f i)) (Set.preimage.{u2, u1} ι' ι f s) (fun (i : ι') => Set.preimage.{u4, u3} (β (f i)) (α (f i)) (g (f i)) (t (f i)))) (Set.preimage.{max u2 u4, max u1 u3} (Sigma.{u2, u4} ι' (fun (i : ι') => β (f i))) (Sigma.{u1, u3} ι α) (fun (p : Sigma.{u2, u4} ι' (fun (i : ι') => β (f i))) => Sigma.mk.{u1, u3} ι α (f (Sigma.fst.{u2, u4} ι' (fun (i : ι') => β (f i)) p)) (g (f (Sigma.fst.{u2, u4} ι' (fun (i : ι') => β (f i)) p)) (Sigma.snd.{u2, u4} ι' (fun (i : ι') => β (f i)) p))) (Set.Sigma.{u1, u3} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {ι' : Type.{u4}} {α : ι -> Type.{u1}} {β : ι -> Type.{u3}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {f : ι' -> ι} {g : forall (i : ι), (β i) -> (α i)}, Eq.{max (succ u4) (succ u3)} (Set.{max u3 u4} (Sigma.{u4, u3} ι' (fun (i : ι') => β (f i)))) (Set.Sigma.{u4, u3} ι' (fun (i : ι') => β (f i)) (Set.preimage.{u4, u2} ι' ι f s) (fun (i : ι') => Set.preimage.{u3, u1} (β (f i)) (α (f i)) (g (f i)) (t (f i)))) (Set.preimage.{max u4 u3, max u1 u2} (Sigma.{u4, u3} ι' (fun (i : ι') => β (f i))) (Sigma.{u2, u1} ι α) (fun (p : Sigma.{u4, u3} ι' (fun (i : ι') => β (f i))) => Sigma.mk.{u2, u1} ι α (f (Sigma.fst.{u4, u3} ι' (fun (i : ι') => β (f i)) p)) (g (f (Sigma.fst.{u4, u3} ι' (fun (i : ι') => β (f i)) p)) (Sigma.snd.{u4, u3} ι' (fun (i : ι') => β (f i)) p))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.sigma_preimage_eq Set.sigma_preimage_eqₓ'. -/
theorem sigma_preimage_eq {f : ι' → ι} {g : ∀ i, β i → α i} :
    ((f ⁻¹' s).Sigma fun i => g (f i) ⁻¹' t (f i)) =
      (fun p : Σi, β (f i) => Sigma.mk _ (g _ p.2)) ⁻¹' s.Sigma t :=
  rfl
#align set.sigma_preimage_eq Set.sigma_preimage_eq

/- warning: set.sigma_preimage_left -> Set.sigma_preimage_left is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {ι' : Type.{u2}} {α : ι -> Type.{u3}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u3} (α i)} {f : ι' -> ι}, Eq.{succ (max u2 u3)} (Set.{max u2 u3} (Sigma.{u2, u3} ι' (fun (i : ι') => α (f i)))) (Set.Sigma.{u2, u3} ι' (fun (i : ι') => α (f i)) (Set.preimage.{u2, u1} ι' ι f s) (fun (i : ι') => t (f i))) (Set.preimage.{max u2 u3, max u1 u3} (Sigma.{u2, u3} ι' (fun (i : ι') => α (f i))) (Sigma.{u1, u3} ι α) (fun (p : Sigma.{u2, u3} ι' (fun (i : ι') => α (f i))) => Sigma.mk.{u1, u3} ι α (f (Sigma.fst.{u2, u3} ι' (fun (i : ι') => α (f i)) p)) (Sigma.snd.{u2, u3} ι' (fun (i : ι') => α (f i)) p)) (Set.Sigma.{u1, u3} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u1}} {ι' : Type.{u3}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {f : ι' -> ι}, Eq.{max (succ u3) (succ u2)} (Set.{max u2 u3} (Sigma.{u3, u2} ι' (fun (i : ι') => α (f i)))) (Set.Sigma.{u3, u2} ι' (fun (i : ι') => α (f i)) (Set.preimage.{u3, u1} ι' ι f s) (fun (i : ι') => t (f i))) (Set.preimage.{max u3 u2, max u2 u1} (Sigma.{u3, u2} ι' (fun (i : ι') => α (f i))) (Sigma.{u1, u2} ι α) (fun (p : Sigma.{u3, u2} ι' (fun (i : ι') => α (f i))) => Sigma.mk.{u1, u2} ι α (f (Sigma.fst.{u3, u2} ι' (fun (i : ι') => α (f i)) p)) (Sigma.snd.{u3, u2} ι' (fun (i : ι') => α (f i)) p)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.sigma_preimage_left Set.sigma_preimage_leftₓ'. -/
theorem sigma_preimage_left {f : ι' → ι} :
    ((f ⁻¹' s).Sigma fun i => t (f i)) = (fun p : Σi, α (f i) => Sigma.mk _ p.2) ⁻¹' s.Sigma t :=
  rfl
#align set.sigma_preimage_left Set.sigma_preimage_left

/- warning: set.sigma_preimage_right -> Set.sigma_preimage_right is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {β : ι -> Type.{u3}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {g : forall (i : ι), (β i) -> (α i)}, Eq.{succ (max u1 u3)} (Set.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => β i))) (Set.Sigma.{u1, u3} ι (fun (i : ι) => β i) s (fun (i : ι) => Set.preimage.{u3, u2} (β i) (α i) (g i) (t i))) (Set.preimage.{max u1 u3, max u1 u2} (Sigma.{u1, u3} ι (fun (i : ι) => β i)) (Sigma.{u1, u2} ι α) (fun (p : Sigma.{u1, u3} ι (fun (i : ι) => β i)) => Sigma.mk.{u1, u2} ι α (Sigma.fst.{u1, u3} ι (fun (i : ι) => β i) p) (g (Sigma.fst.{u1, u3} ι (fun (i : ι) => β i) p) (Sigma.snd.{u1, u3} ι (fun (i : ι) => β i) p))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u3}} {α : ι -> Type.{u1}} {β : ι -> Type.{u2}} {s : Set.{u3} ι} {t : forall (i : ι), Set.{u1} (α i)} {g : forall (i : ι), (β i) -> (α i)}, Eq.{max (succ u3) (succ u2)} (Set.{max u2 u3} (Sigma.{u3, u2} ι (fun (i : ι) => β i))) (Set.Sigma.{u3, u2} ι (fun (i : ι) => β i) s (fun (i : ι) => Set.preimage.{u2, u1} (β i) (α i) (g i) (t i))) (Set.preimage.{max u3 u2, max u1 u3} (Sigma.{u3, u2} ι (fun (i : ι) => β i)) (Sigma.{u3, u1} ι α) (fun (p : Sigma.{u3, u2} ι (fun (i : ι) => β i)) => Sigma.mk.{u3, u1} ι α (Sigma.fst.{u3, u2} ι (fun (i : ι) => β i) p) (g (Sigma.fst.{u3, u2} ι (fun (i : ι) => β i) p) (Sigma.snd.{u3, u2} ι (fun (i : ι) => β i) p))) (Set.Sigma.{u3, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.sigma_preimage_right Set.sigma_preimage_rightₓ'. -/
theorem sigma_preimage_right {g : ∀ i, β i → α i} :
    (s.Sigma fun i => g i ⁻¹' t i) = (fun p : Σi, β i => Sigma.mk p.1 (g _ p.2)) ⁻¹' s.Sigma t :=
  rfl
#align set.sigma_preimage_right Set.sigma_preimage_right

/- warning: set.preimage_sigma_map_sigma -> Set.preimage_sigmaMap_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {ι' : Type.{u2}} {α : ι -> Type.{u3}} {α' : ι' -> Type.{u4}} (f : ι -> ι') (g : forall (i : ι), (α i) -> (α' (f i))) (s : Set.{u2} ι') (t : forall (i : ι'), Set.{u4} (α' i)), Eq.{succ (max u1 u3)} (Set.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => α i))) (Set.preimage.{max u1 u3, max u2 u4} (Sigma.{u1, u3} ι (fun (i : ι) => α i)) (Sigma.{u2, u4} ι' α') (Sigma.map.{u1, u2, u3, u4} ι ι' (fun (i : ι) => α i) α' f g) (Set.Sigma.{u2, u4} ι' (fun (i : ι') => α' i) s t)) (Set.Sigma.{u1, u3} ι (fun (i : ι) => α i) (Set.preimage.{u1, u2} ι ι' f s) (fun (i : ι) => Set.preimage.{u3, u4} (α i) (α' (f i)) (g i) (t (f i))))
but is expected to have type
  forall {ι : Type.{u2}} {ι' : Type.{u3}} {α : ι -> Type.{u1}} {α' : ι' -> Type.{u4}} (f : ι -> ι') (g : forall (i : ι), (α i) -> (α' (f i))) (s : Set.{u3} ι') (t : forall (i : ι'), Set.{u4} (α' i)), Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.preimage.{max u1 u2, max u4 u3} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Sigma.{u3, u4} ι' α') (Sigma.map.{u2, u3, u1, u4} ι ι' (fun (i : ι) => α i) α' f g) (Set.Sigma.{u3, u4} ι' (fun (i : ι') => α' i) s t)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (Set.preimage.{u2, u3} ι ι' f s) (fun (i : ι) => Set.preimage.{u1, u4} (α i) (α' (f i)) (g i) (t (f i))))
Case conversion may be inaccurate. Consider using '#align set.preimage_sigma_map_sigma Set.preimage_sigmaMap_sigmaₓ'. -/
theorem preimage_sigmaMap_sigma {α' : ι' → Type _} (f : ι → ι') (g : ∀ i, α i → α' (f i))
    (s : Set ι') (t : ∀ i, Set (α' i)) :
    Sigma.map f g ⁻¹' s.Sigma t = (f ⁻¹' s).Sigma fun i => g i ⁻¹' t (f i) :=
  rfl
#align set.preimage_sigma_map_sigma Set.preimage_sigmaMap_sigma

/- warning: set.mk_preimage_sigma -> Set.mk_preimage_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι}, (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (Eq.{succ u2} (Set.{u2} (α i)) (Set.preimage.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (t i))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (Eq.{succ u1} (Set.{u1} (α i)) (Set.preimage.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (t i))
Case conversion may be inaccurate. Consider using '#align set.mk_preimage_sigma Set.mk_preimage_sigmaₓ'. -/
@[simp]
theorem mk_preimage_sigma (hi : i ∈ s) : Sigma.mk i ⁻¹' s.Sigma t = t i :=
  ext fun _ => and_iff_right hi
#align set.mk_preimage_sigma Set.mk_preimage_sigma

/- warning: set.mk_preimage_sigma_eq_empty -> Set.mk_preimage_sigma_eq_empty is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι}, (Not (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s)) -> (Eq.{succ u2} (Set.{u2} (α i)) (Set.preimage.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (EmptyCollection.emptyCollection.{u2} (Set.{u2} (α i)) (Set.hasEmptyc.{u2} (α i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι}, (Not (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s)) -> (Eq.{succ u1} (Set.{u1} (α i)) (Set.preimage.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (EmptyCollection.emptyCollection.{u1} (Set.{u1} (α i)) (Set.instEmptyCollectionSet.{u1} (α i))))
Case conversion may be inaccurate. Consider using '#align set.mk_preimage_sigma_eq_empty Set.mk_preimage_sigma_eq_emptyₓ'. -/
@[simp]
theorem mk_preimage_sigma_eq_empty (hi : i ∉ s) : Sigma.mk i ⁻¹' s.Sigma t = ∅ :=
  ext fun _ => iff_of_false (hi ∘ And.left) id
#align set.mk_preimage_sigma_eq_empty Set.mk_preimage_sigma_eq_empty

/- warning: set.mk_preimage_sigma_eq_if -> Set.mk_preimage_sigma_eq_if is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι} [_inst_1 : DecidablePred.{succ u1} ι (fun (_x : ι) => Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) _x s)], Eq.{succ u2} (Set.{u2} (α i)) (Set.preimage.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Sigma.mk.{u1, u2} ι (fun (i : ι) => α i) i) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (ite.{succ u2} (Set.{u2} (α i)) (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (_inst_1 i) (t i) (EmptyCollection.emptyCollection.{u2} (Set.{u2} (α i)) (Set.hasEmptyc.{u2} (α i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} [_inst_1 : DecidablePred.{succ u2} ι (fun (_x : ι) => Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) _x s)], Eq.{succ u1} (Set.{u1} (α i)) (Set.preimage.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Sigma.mk.{u2, u1} ι (fun (i : ι) => α i) i) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (ite.{succ u1} (Set.{u1} (α i)) (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (_inst_1 i) (t i) (EmptyCollection.emptyCollection.{u1} (Set.{u1} (α i)) (Set.instEmptyCollectionSet.{u1} (α i))))
Case conversion may be inaccurate. Consider using '#align set.mk_preimage_sigma_eq_if Set.mk_preimage_sigma_eq_ifₓ'. -/
theorem mk_preimage_sigma_eq_if [DecidablePred (· ∈ s)] :
    Sigma.mk i ⁻¹' s.Sigma t = if i ∈ s then t i else ∅ := by split_ifs <;> simp [h]
#align set.mk_preimage_sigma_eq_if Set.mk_preimage_sigma_eq_if

/- warning: set.mk_preimage_sigma_fn_eq_if -> Set.mk_preimage_sigma_fn_eq_if is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι} {β : Type.{u3}} [_inst_1 : DecidablePred.{succ u1} ι (fun (_x : ι) => Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) _x s)] (g : β -> (α i)), Eq.{succ u3} (Set.{u3} β) (Set.preimage.{u3, max u1 u2} β (Sigma.{u1, u2} ι (fun {i : ι} => α i)) (fun (b : β) => Sigma.mk.{u1, u2} ι (fun {i : ι} => α i) i (g b)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (ite.{succ u3} (Set.{u3} β) (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (_inst_1 i) (Set.preimage.{u3, u2} β (α i) g (t i)) (EmptyCollection.emptyCollection.{u3} (Set.{u3} β) (Set.hasEmptyc.{u3} β)))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι} {β : Type.{u3}} [_inst_1 : DecidablePred.{succ u2} ι (fun (_x : ι) => Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) _x s)] (g : β -> (α i)), Eq.{succ u3} (Set.{u3} β) (Set.preimage.{u3, max u1 u2} β (Sigma.{u2, u1} ι α) (fun (b : β) => Sigma.mk.{u2, u1} ι α i (g b)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (ite.{succ u3} (Set.{u3} β) (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (_inst_1 i) (Set.preimage.{u3, u1} β (α i) g (t i)) (EmptyCollection.emptyCollection.{u3} (Set.{u3} β) (Set.instEmptyCollectionSet.{u3} β)))
Case conversion may be inaccurate. Consider using '#align set.mk_preimage_sigma_fn_eq_if Set.mk_preimage_sigma_fn_eq_ifₓ'. -/
theorem mk_preimage_sigma_fn_eq_if {β : Type _} [DecidablePred (· ∈ s)] (g : β → α i) :
    (fun b => Sigma.mk i (g b)) ⁻¹' s.Sigma t = if i ∈ s then g ⁻¹' t i else ∅ :=
  ext fun _ => by split_ifs <;> simp [h]
#align set.mk_preimage_sigma_fn_eq_if Set.mk_preimage_sigma_fn_eq_if

/- warning: set.sigma_univ_range_eq -> Set.sigma_univ_range_eq is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {β : ι -> Type.{u3}} {f : forall (i : ι), (α i) -> (β i)}, Eq.{succ (max u1 u3)} (Set.{max u1 u3} (Sigma.{u1, u3} ι (fun (i : ι) => β i))) (Set.Sigma.{u1, u3} ι (fun (i : ι) => β i) (Set.univ.{u1} ι) (fun (i : ι) => Set.range.{u3, succ u2} (β i) (α i) (f i))) (Set.range.{max u1 u3, max (succ u1) (succ u2)} (Sigma.{u1, u3} ι (fun (i : ι) => β i)) (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (fun (x : Sigma.{u1, u2} ι (fun (i : ι) => α i)) => Sigma.mk.{u1, u3} ι (fun (i : ι) => β i) (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x) (f (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i) x) (Sigma.snd.{u1, u2} ι (fun (i : ι) => α i) x))))
but is expected to have type
  forall {ι : Type.{u3}} {α : ι -> Type.{u1}} {β : ι -> Type.{u2}} {f : forall (i : ι), (α i) -> (β i)}, Eq.{max (succ u3) (succ u2)} (Set.{max u2 u3} (Sigma.{u3, u2} ι (fun (i : ι) => β i))) (Set.Sigma.{u3, u2} ι (fun (i : ι) => β i) (Set.univ.{u3} ι) (fun (i : ι) => Set.range.{u2, succ u1} (β i) (α i) (f i))) (Set.range.{max u3 u2, max (succ u3) (succ u1)} (Sigma.{u3, u2} ι (fun (i : ι) => β i)) (Sigma.{u3, u1} ι (fun (i : ι) => α i)) (fun (x : Sigma.{u3, u1} ι (fun (i : ι) => α i)) => Sigma.mk.{u3, u2} ι (fun (i : ι) => β i) (Sigma.fst.{u3, u1} ι (fun (i : ι) => α i) x) (f (Sigma.fst.{u3, u1} ι (fun (i : ι) => α i) x) (Sigma.snd.{u3, u1} ι (fun (i : ι) => α i) x))))
Case conversion may be inaccurate. Consider using '#align set.sigma_univ_range_eq Set.sigma_univ_range_eqₓ'. -/
theorem sigma_univ_range_eq {f : ∀ i, α i → β i} :
    ((univ : Set ι).Sigma fun i => range (f i)) = range fun x : Σi, α i => ⟨x.1, f _ x.2⟩ :=
  ext <| by simp [range]
#align set.sigma_univ_range_eq Set.sigma_univ_range_eq

/- warning: set.nonempty.sigma -> Set.Nonempty.sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, (Set.Nonempty.{u1} ι s) -> (forall (i : ι), Set.Nonempty.{u2} (α i) (t i)) -> (Set.Nonempty.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, (Set.Nonempty.{u2} ι s) -> (forall (i : ι), Set.Nonempty.{u1} (α i) (t i)) -> (Set.Nonempty.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.nonempty.sigma Set.Nonempty.sigmaₓ'. -/
protected theorem Nonempty.sigma :
    s.Nonempty → (∀ i, (t i).Nonempty) → (s.Sigma t : Set _).Nonempty := fun ⟨i, hi⟩ h =>
  let ⟨a, ha⟩ := h i
  ⟨⟨i, a⟩, hi, ha⟩
#align set.nonempty.sigma Set.Nonempty.sigma

/- warning: set.nonempty.sigma_fst -> Set.Nonempty.sigma_fst is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, (Set.Nonempty.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) -> (Set.Nonempty.{u1} ι s)
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, (Set.Nonempty.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) -> (Set.Nonempty.{u2} ι s)
Case conversion may be inaccurate. Consider using '#align set.nonempty.sigma_fst Set.Nonempty.sigma_fstₓ'. -/
theorem Nonempty.sigma_fst : (s.Sigma t : Set _).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩
#align set.nonempty.sigma_fst Set.Nonempty.sigma_fst

/- warning: set.nonempty.sigma_snd -> Set.Nonempty.sigma_snd is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, (Set.Nonempty.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) -> (Exists.{succ u1} ι (fun (i : ι) => Exists.{0} (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (fun (H : Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) => Set.Nonempty.{u2} (α i) (t i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, (Set.Nonempty.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) -> (Exists.{succ u2} ι (fun (i : ι) => And (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (Set.Nonempty.{u1} (α i) (t i))))
Case conversion may be inaccurate. Consider using '#align set.nonempty.sigma_snd Set.Nonempty.sigma_sndₓ'. -/
theorem Nonempty.sigma_snd : (s.Sigma t : Set _).Nonempty → ∃ i ∈ s, (t i).Nonempty :=
  fun ⟨x, hx⟩ => ⟨x.1, hx.1, x.2, hx.2⟩
#align set.nonempty.sigma_snd Set.Nonempty.sigma_snd

/- warning: set.sigma_nonempty_iff -> Set.sigma_nonempty_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, Iff (Set.Nonempty.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) (Exists.{succ u1} ι (fun (i : ι) => Exists.{0} (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) (fun (H : Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) => Set.Nonempty.{u2} (α i) (t i))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, Iff (Set.Nonempty.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) (Exists.{succ u2} ι (fun (i : ι) => And (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) (Set.Nonempty.{u1} (α i) (t i))))
Case conversion may be inaccurate. Consider using '#align set.sigma_nonempty_iff Set.sigma_nonempty_iffₓ'. -/
theorem sigma_nonempty_iff : (s.Sigma t : Set _).Nonempty ↔ ∃ i ∈ s, (t i).Nonempty :=
  ⟨Nonempty.sigma_snd, fun ⟨i, hi, a, ha⟩ => ⟨⟨i, a⟩, hi, ha⟩⟩
#align set.sigma_nonempty_iff Set.sigma_nonempty_iff

/- warning: set.sigma_eq_empty_iff -> Set.sigma_eq_empty_iff is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)}, Iff (Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t) (EmptyCollection.emptyCollection.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasEmptyc.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))))) (forall (i : ι), (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (Eq.{succ u2} (Set.{u2} (α i)) (t i) (EmptyCollection.emptyCollection.{u2} (Set.{u2} (α i)) (Set.hasEmptyc.{u2} (α i)))))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)}, Iff (Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t) (EmptyCollection.emptyCollection.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instEmptyCollectionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))))) (forall (i : ι), (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (Eq.{succ u1} (Set.{u1} (α i)) (t i) (EmptyCollection.emptyCollection.{u1} (Set.{u1} (α i)) (Set.instEmptyCollectionSet.{u1} (α i)))))
Case conversion may be inaccurate. Consider using '#align set.sigma_eq_empty_iff Set.sigma_eq_empty_iffₓ'. -/
theorem sigma_eq_empty_iff : s.Sigma t = ∅ ↔ ∀ i ∈ s, t i = ∅ :=
  not_nonempty_iff_eq_empty.symm.trans <|
    sigma_nonempty_iff.Not.trans <| by simp only [not_nonempty_iff_eq_empty, not_exists]
#align set.sigma_eq_empty_iff Set.sigma_eq_empty_iff

#print Set.image_sigmaMk_subset_sigma_left /-
theorem image_sigmaMk_subset_sigma_left {a : ∀ i, α i} (ha : ∀ i, a i ∈ t i) :
    (fun i => Sigma.mk i (a i)) '' s ⊆ s.Sigma t :=
  image_subset_iff.2 fun i hi => ⟨hi, ha _⟩
#align set.image_sigma_mk_subset_sigma_left Set.image_sigmaMk_subset_sigma_left
-/

/- warning: set.image_sigma_mk_subset_sigma_right -> Set.image_sigmaMk_subset_sigma_right is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s : Set.{u1} ι} {t : forall (i : ι), Set.{u2} (α i)} {i : ι}, (Membership.Mem.{u1, u1} ι (Set.{u1} ι) (Set.hasMem.{u1} ι) i s) -> (HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun {i : ι} => α i))) (Set.hasSubset.{max u1 u2} (Sigma.{u1, u2} ι (fun {i : ι} => α i))) (Set.image.{u2, max u1 u2} (α i) (Sigma.{u1, u2} ι (fun {i : ι} => α i)) (Sigma.mk.{u1, u2} ι (fun {i : ι} => α i) i) (t i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s : Set.{u2} ι} {t : forall (i : ι), Set.{u1} (α i)} {i : ι}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (HasSubset.Subset.{max u2 u1} (Set.{max u2 u1} (Sigma.{u2, u1} ι α)) (Set.instHasSubsetSet.{max u2 u1} (Sigma.{u2, u1} ι α)) (Set.image.{u1, max u2 u1} (α i) (Sigma.{u2, u1} ι α) (Sigma.mk.{u2, u1} ι α i) (t i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t))
Case conversion may be inaccurate. Consider using '#align set.image_sigma_mk_subset_sigma_right Set.image_sigmaMk_subset_sigma_rightₓ'. -/
theorem image_sigmaMk_subset_sigma_right (hi : i ∈ s) : Sigma.mk i '' t i ⊆ s.Sigma t :=
  image_subset_iff.2 fun a => And.intro hi
#align set.image_sigma_mk_subset_sigma_right Set.image_sigmaMk_subset_sigma_right

/- warning: set.sigma_subset_preimage_fst -> Set.sigma_subset_preimage_fst is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} (s : Set.{u1} ι) (t : forall (i : ι), Set.{u2} (α i)), HasSubset.Subset.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasSubset.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t) (Set.preimage.{max u1 u2, u1} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i)) s)
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} (s : Set.{u2} ι) (t : forall (i : ι), Set.{u1} (α i)), HasSubset.Subset.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instHasSubsetSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t) (Set.preimage.{max u2 u1, u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i)) s)
Case conversion may be inaccurate. Consider using '#align set.sigma_subset_preimage_fst Set.sigma_subset_preimage_fstₓ'. -/
theorem sigma_subset_preimage_fst (s : Set ι) (t : ∀ i, Set (α i)) : s.Sigma t ⊆ Sigma.fst ⁻¹' s :=
  fun a => And.left
#align set.sigma_subset_preimage_fst Set.sigma_subset_preimage_fst

/- warning: set.fst_image_sigma_subset -> Set.fst_image_sigma_subset is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} (s : Set.{u1} ι) (t : forall (i : ι), Set.{u2} (α i)), HasSubset.Subset.{u1} (Set.{u1} ι) (Set.hasSubset.{u1} ι) (Set.image.{max u1 u2, u1} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) s
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} (s : Set.{u2} ι) (t : forall (i : ι), Set.{u1} (α i)), HasSubset.Subset.{u2} (Set.{u2} ι) (Set.instHasSubsetSet.{u2} ι) (Set.image.{max u1 u2, u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) s
Case conversion may be inaccurate. Consider using '#align set.fst_image_sigma_subset Set.fst_image_sigma_subsetₓ'. -/
theorem fst_image_sigma_subset (s : Set ι) (t : ∀ i, Set (α i)) : Sigma.fst '' s.Sigma t ⊆ s :=
  image_subset_iff.2 fun a => And.left
#align set.fst_image_sigma_subset Set.fst_image_sigma_subset

/- warning: set.fst_image_sigma -> Set.fst_image_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {t : forall (i : ι), Set.{u2} (α i)} (s : Set.{u1} ι), (forall (i : ι), Set.Nonempty.{u2} (α i) (t i)) -> (Eq.{succ u1} (Set.{u1} ι) (Set.image.{max u1 u2, u1} (Sigma.{u1, u2} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u1, u2} ι (fun (i : ι) => α i)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s t)) s)
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {t : forall (i : ι), Set.{u1} (α i)} (s : Set.{u2} ι), (forall (i : ι), Set.Nonempty.{u1} (α i) (t i)) -> (Eq.{succ u2} (Set.{u2} ι) (Set.image.{max u1 u2, u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i)) ι (Sigma.fst.{u2, u1} ι (fun (i : ι) => α i)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s t)) s)
Case conversion may be inaccurate. Consider using '#align set.fst_image_sigma Set.fst_image_sigmaₓ'. -/
theorem fst_image_sigma (s : Set ι) (ht : ∀ i, (t i).Nonempty) : Sigma.fst '' s.Sigma t = s :=
  (fst_image_sigma_subset _ _).antisymm fun i hi =>
    let ⟨a, ha⟩ := ht i
    ⟨⟨i, a⟩, ⟨hi, ha⟩, rfl⟩
#align set.fst_image_sigma Set.fst_image_sigma

/- warning: set.sigma_diff_sigma -> Set.sigma_diff_sigma is a dubious translation:
lean 3 declaration is
  forall {ι : Type.{u1}} {α : ι -> Type.{u2}} {s₁ : Set.{u1} ι} {s₂ : Set.{u1} ι} {t₁ : forall (i : ι), Set.{u2} (α i)} {t₂ : forall (i : ι), Set.{u2} (α i)}, Eq.{succ (max u1 u2)} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (SDiff.sdiff.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (BooleanAlgebra.toHasSdiff.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.booleanAlgebra.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i)))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₂ t₂)) (Union.union.{max u1 u2} (Set.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.hasUnion.{max u1 u2} (Sigma.{u1, u2} ι (fun (i : ι) => α i))) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) s₁ (SDiff.sdiff.{max u1 u2} (forall (i : ι), Set.{u2} (α i)) (Pi.sdiff.{u1, u2} ι (fun (i : ι) => Set.{u2} (α i)) (fun (i : ι) => BooleanAlgebra.toHasSdiff.{u2} (Set.{u2} (α i)) (Set.booleanAlgebra.{u2} (α i)))) t₁ t₂)) (Set.Sigma.{u1, u2} ι (fun (i : ι) => α i) (SDiff.sdiff.{u1} (Set.{u1} ι) (BooleanAlgebra.toHasSdiff.{u1} (Set.{u1} ι) (Set.booleanAlgebra.{u1} ι)) s₁ s₂) t₁))
but is expected to have type
  forall {ι : Type.{u2}} {α : ι -> Type.{u1}} {s₁ : Set.{u2} ι} {s₂ : Set.{u2} ι} {t₁ : forall (i : ι), Set.{u1} (α i)} {t₂ : forall (i : ι), Set.{u1} (α i)}, Eq.{max (succ u2) (succ u1)} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (SDiff.sdiff.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instSDiffSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₁ t₁) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₂ t₂)) (Union.union.{max u2 u1} (Set.{max u1 u2} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.instUnionSet.{max u2 u1} (Sigma.{u2, u1} ι (fun (i : ι) => α i))) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) s₁ (SDiff.sdiff.{max u2 u1} (forall (i : ι), Set.{u1} (α i)) (Pi.sdiff.{u2, u1} ι (fun (i : ι) => Set.{u1} (α i)) (fun (i : ι) => Set.instSDiffSet.{u1} (α i))) t₁ t₂)) (Set.Sigma.{u2, u1} ι (fun (i : ι) => α i) (SDiff.sdiff.{u2} (Set.{u2} ι) (Set.instSDiffSet.{u2} ι) s₁ s₂) t₁))
Case conversion may be inaccurate. Consider using '#align set.sigma_diff_sigma Set.sigma_diff_sigmaₓ'. -/
theorem sigma_diff_sigma : s₁.Sigma t₁ \ s₂.Sigma t₂ = s₁.Sigma (t₁ \ t₂) ∪ (s₁ \ s₂).Sigma t₁ :=
  ext fun x => by
    by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ x.1 <;> simp [*, ← imp_iff_or_not]
#align set.sigma_diff_sigma Set.sigma_diff_sigma

end Set


/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.instances.nnreal
import Mathlib.PostPort

universes u_1 u_2

namespace Mathlib

/-!
# Extended non-negative reals
-/

namespace ennreal

/-- Topology on `ennreal`.

Note: this is different from the `emetric_space` topology. The `emetric_space` topology has
`is_open {⊤}`, while this topology doesn't have singleton elements. -/
protected instance topological_space : topological_space ennreal :=
  preorder.topology ennreal

protected instance order_topology : order_topology ennreal :=
  order_topology.mk rfl

protected instance t2_space : t2_space ennreal :=
  regular_space.t2_space ennreal

protected instance topological_space.second_countable_topology : topological_space.second_countable_topology ennreal := sorry

theorem embedding_coe : embedding coe := sorry

theorem is_open_ne_top : is_open (set_of fun (a : ennreal) => a ≠ ⊤) :=
  is_open_ne

theorem is_open_Ico_zero {b : ennreal} : is_open (set.Ico 0 b) :=
  eq.mpr (id (Eq._oldrec (Eq.refl (is_open (set.Ico 0 b))) ennreal.Ico_eq_Iio)) is_open_Iio

theorem coe_range_mem_nhds {r : nnreal} : set.range coe ∈ nhds ↑r := sorry

theorem tendsto_coe {α : Type u_1} {f : filter α} {m : α → nnreal} {a : nnreal} : filter.tendsto (fun (a : α) => ↑(m a)) f (nhds ↑a) ↔ filter.tendsto m f (nhds a) :=
  iff.symm (embedding.tendsto_nhds_iff embedding_coe)

theorem continuous_coe : continuous coe :=
  embedding.continuous embedding_coe

theorem continuous_coe_iff {α : Type u_1} [topological_space α] {f : α → nnreal} : (continuous fun (a : α) => ↑(f a)) ↔ continuous f :=
  iff.symm (embedding.continuous_iff embedding_coe)

theorem nhds_coe {r : nnreal} : nhds ↑r = filter.map coe (nhds r) := sorry

theorem nhds_coe_coe {r : nnreal} {p : nnreal} : nhds (↑r, ↑p) = filter.map (fun (p : nnreal × nnreal) => (↑(prod.fst p), ↑(prod.snd p))) (nhds (r, p)) := sorry

theorem continuous_of_real : continuous ennreal.of_real :=
  continuous.comp (iff.mpr continuous_coe_iff continuous_id) nnreal.continuous_of_real

theorem tendsto_of_real {α : Type u_1} {f : filter α} {m : α → ℝ} {a : ℝ} (h : filter.tendsto m f (nhds a)) : filter.tendsto (fun (a : α) => ennreal.of_real (m a)) f (nhds (ennreal.of_real a)) :=
  filter.tendsto.comp (continuous.tendsto continuous_of_real a) h

theorem tendsto_to_nnreal {a : ennreal} : a ≠ ⊤ → filter.tendsto ennreal.to_nnreal (nhds a) (nhds (ennreal.to_nnreal a)) := sorry

theorem continuous_on_to_nnreal : continuous_on ennreal.to_nnreal (set_of fun (a : ennreal) => a ≠ ⊤) := sorry

theorem tendsto_to_real {a : ennreal} : a ≠ ⊤ → filter.tendsto ennreal.to_real (nhds a) (nhds (ennreal.to_real a)) :=
  fun (ha : a ≠ ⊤) => filter.tendsto.comp (iff.mpr nnreal.tendsto_coe filter.tendsto_id) (tendsto_to_nnreal ha)

/-- The set of finite `ennreal` numbers is homeomorphic to `ℝ≥0`. -/
def ne_top_homeomorph_nnreal : ↥(set_of fun (a : ennreal) => a ≠ ⊤) ≃ₜ nnreal :=
  homeomorph.mk (equiv.mk (equiv.to_fun ne_top_equiv_nnreal) (equiv.inv_fun ne_top_equiv_nnreal) sorry sorry)

/-- The set of finite `ennreal` numbers is homeomorphic to `ℝ≥0`. -/
def lt_top_homeomorph_nnreal : ↥(set_of fun (a : ennreal) => a < ⊤) ≃ₜ nnreal :=
  homeomorph.trans (homeomorph.set_congr sorry) ne_top_homeomorph_nnreal

theorem nhds_top : nhds ⊤ = infi fun (a : ennreal) => infi fun (H : a ≠ ⊤) => filter.principal (set.Ioi a) := sorry

theorem nhds_top' : nhds ⊤ = infi fun (r : nnreal) => filter.principal (set.Ioi ↑r) :=
  Eq.trans nhds_top (infi_ne_top fun (a : ennreal) => filter.principal (set.Ioi a))

theorem tendsto_nhds_top_iff_nnreal {α : Type u_1} {m : α → ennreal} {f : filter α} : filter.tendsto m f (nhds ⊤) ↔ ∀ (x : nnreal), filter.eventually (fun (a : α) => ↑x < m a) f := sorry

theorem tendsto_nhds_top_iff_nat {α : Type u_1} {m : α → ennreal} {f : filter α} : filter.tendsto m f (nhds ⊤) ↔ ∀ (n : ℕ), filter.eventually (fun (a : α) => ↑n < m a) f := sorry

theorem tendsto_nhds_top {α : Type u_1} {m : α → ennreal} {f : filter α} (h : ∀ (n : ℕ), filter.eventually (fun (a : α) => ↑n < m a) f) : filter.tendsto m f (nhds ⊤) :=
  iff.mpr tendsto_nhds_top_iff_nat h

theorem tendsto_nat_nhds_top : filter.tendsto (fun (n : ℕ) => ↑n) filter.at_top (nhds ⊤) := sorry

@[simp] theorem tendsto_coe_nhds_top {α : Type u_1} {f : α → nnreal} {l : filter α} : filter.tendsto (fun (x : α) => ↑(f x)) l (nhds ⊤) ↔ filter.tendsto f l filter.at_top := sorry

theorem nhds_zero : nhds 0 = infi fun (a : ennreal) => infi fun (H : a ≠ 0) => filter.principal (set.Iio a) := sorry

instance nhds_within_Ioi_coe_ne_bot {r : nnreal} : filter.ne_bot (nhds_within (↑r) (set.Ioi ↑r)) :=
  nhds_within_Ioi_self_ne_bot' coe_lt_top

instance nhds_within_Ioi_zero_ne_bot : filter.ne_bot (nhds_within 0 (set.Ioi 0)) :=
  nhds_within_Ioi_coe_ne_bot

-- using Icc because

-- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0

-- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not

theorem Icc_mem_nhds {x : ennreal} {ε : ennreal} : x ≠ ⊤ → 0 < ε → set.Icc (x - ε) (x + ε) ∈ nhds x := sorry

theorem nhds_of_ne_top {x : ennreal} : x ≠ ⊤ → nhds x = infi fun (ε : ennreal) => infi fun (H : ε > 0) => filter.principal (set.Icc (x - ε) (x + ε)) := sorry

/-- Characterization of neighborhoods for `ennreal` numbers. See also `tendsto_order`
for a version with strict inequalities. -/
protected theorem tendsto_nhds {α : Type u_1} {f : filter α} {u : α → ennreal} {a : ennreal} (ha : a ≠ ⊤) : filter.tendsto u f (nhds a) ↔
  ∀ (ε : ennreal), ε > 0 → filter.eventually (fun (x : α) => u x ∈ set.Icc (a - ε) (a + ε)) f := sorry

protected theorem tendsto_at_top {β : Type u_2} [Nonempty β] [semilattice_sup β] {f : β → ennreal} {a : ennreal} (ha : a ≠ ⊤) : filter.tendsto f filter.at_top (nhds a) ↔
  ∀ (ε : ennreal), ε > 0 → ∃ (N : β), ∀ (n : β), n ≥ N → f n ∈ set.Icc (a - ε) (a + ε) := sorry

protected instance has_continuous_add : has_continuous_add ennreal := sorry

protected theorem tendsto_mul {a : ennreal} {b : ennreal} (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) : filter.tendsto (fun (p : ennreal × ennreal) => prod.fst p * prod.snd p) (nhds (a, b)) (nhds (a * b)) := sorry

protected theorem tendsto.mul {α : Type u_1} {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a : ennreal} {b : ennreal} (hma : filter.tendsto ma f (nhds a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : filter.tendsto mb f (nhds b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : filter.tendsto (fun (a : α) => ma a * mb a) f (nhds (a * b)) := sorry

protected theorem tendsto.const_mul {α : Type u_1} {f : filter α} {m : α → ennreal} {a : ennreal} {b : ennreal} (hm : filter.tendsto m f (nhds b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : filter.tendsto (fun (b : α) => a * m b) f (nhds (a * b)) := sorry

protected theorem tendsto.mul_const {α : Type u_1} {f : filter α} {m : α → ennreal} {a : ennreal} {b : ennreal} (hm : filter.tendsto m f (nhds a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : filter.tendsto (fun (x : α) => m x * b) f (nhds (a * b)) := sorry

protected theorem continuous_at_const_mul {a : ennreal} {b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) : continuous_at (Mul.mul a) b :=
  tendsto.const_mul filter.tendsto_id (or.symm h)

protected theorem continuous_at_mul_const {a : ennreal} {b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) : continuous_at (fun (x : ennreal) => x * a) b :=
  tendsto.mul_const filter.tendsto_id (or.symm h)

protected theorem continuous_const_mul {a : ennreal} (ha : a ≠ ⊤) : continuous (Mul.mul a) :=
  iff.mpr continuous_iff_continuous_at fun (x : ennreal) => ennreal.continuous_at_const_mul (Or.inl ha)

protected theorem continuous_mul_const {a : ennreal} (ha : a ≠ ⊤) : continuous fun (x : ennreal) => x * a :=
  iff.mpr continuous_iff_continuous_at fun (x : ennreal) => ennreal.continuous_at_mul_const (Or.inl ha)

theorem le_of_forall_lt_one_mul_le {x : ennreal} {y : ennreal} (h : ∀ (a : ennreal), a < 1 → a * x ≤ y) : x ≤ y := sorry

theorem infi_mul_left {ι : Sort u_1} [Nonempty ι] {f : ι → ennreal} {a : ennreal} (h : a = ⊤ → (infi fun (i : ι) => f i) = 0 → ∃ (i : ι), f i = 0) : (infi fun (i : ι) => a * f i) = a * infi fun (i : ι) => f i := sorry

theorem infi_mul_right {ι : Sort u_1} [Nonempty ι] {f : ι → ennreal} {a : ennreal} (h : a = ⊤ → (infi fun (i : ι) => f i) = 0 → ∃ (i : ι), f i = 0) : (infi fun (i : ι) => f i * a) = (infi fun (i : ι) => f i) * a := sorry

protected theorem continuous_inv : continuous has_inv.inv := sorry

@[simp] protected theorem tendsto_inv_iff {α : Type u_1} {f : filter α} {m : α → ennreal} {a : ennreal} : filter.tendsto (fun (x : α) => m x⁻¹) f (nhds (a⁻¹)) ↔ filter.tendsto m f (nhds a) := sorry

protected theorem tendsto.div {α : Type u_1} {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a : ennreal} {b : ennreal} (hma : filter.tendsto ma f (nhds a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : filter.tendsto mb f (nhds b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : filter.tendsto (fun (a : α) => ma a / mb a) f (nhds (a / b)) := sorry

protected theorem tendsto.const_div {α : Type u_1} {f : filter α} {m : α → ennreal} {a : ennreal} {b : ennreal} (hm : filter.tendsto m f (nhds b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : filter.tendsto (fun (b : α) => a / m b) f (nhds (a / b)) := sorry

protected theorem tendsto.div_const {α : Type u_1} {f : filter α} {m : α → ennreal} {a : ennreal} {b : ennreal} (hm : filter.tendsto m f (nhds a)) (ha : a ≠ 0 ∨ b ≠ 0) : filter.tendsto (fun (x : α) => m x / b) f (nhds (a / b)) := sorry

protected theorem tendsto_inv_nat_nhds_zero : filter.tendsto (fun (n : ℕ) => ↑n⁻¹) filter.at_top (nhds 0) :=
  inv_top ▸ iff.mpr ennreal.tendsto_inv_iff tendsto_nat_nhds_top

theorem bsupr_add {a : ennreal} {ι : Type u_1} {s : set ι} (hs : set.nonempty s) {f : ι → ennreal} : (supr fun (i : ι) => supr fun (H : i ∈ s) => f i) + a = supr fun (i : ι) => supr fun (H : i ∈ s) => f i + a := sorry

theorem Sup_add {a : ennreal} {s : set ennreal} (hs : set.nonempty s) : Sup s + a = supr fun (b : ennreal) => supr fun (H : b ∈ s) => b + a := sorry

theorem supr_add {a : ennreal} {ι : Sort u_1} {s : ι → ennreal} [h : Nonempty ι] : supr s + a = supr fun (b : ι) => s b + a := sorry

theorem add_supr {a : ennreal} {ι : Sort u_1} {s : ι → ennreal} [h : Nonempty ι] : a + supr s = supr fun (b : ι) => a + s b := sorry

theorem supr_add_supr {ι : Sort u_1} {f : ι → ennreal} {g : ι → ennreal} (h : ∀ (i j : ι), ∃ (k : ι), f i + g j ≤ f k + g k) : supr f + supr g = supr fun (a : ι) => f a + g a := sorry

theorem supr_add_supr_of_monotone {ι : Type u_1} [semilattice_sup ι] {f : ι → ennreal} {g : ι → ennreal} (hf : monotone f) (hg : monotone g) : supr f + supr g = supr fun (a : ι) => f a + g a :=
  supr_add_supr fun (i j : ι) => Exists.intro (i ⊔ j) (add_le_add (hf le_sup_left) (hg le_sup_right))

theorem finset_sum_supr_nat {α : Type u_1} {ι : Type u_2} [semilattice_sup ι] {s : finset α} {f : α → ι → ennreal} (hf : ∀ (a : α), monotone (f a)) : (finset.sum s fun (a : α) => supr (f a)) = supr fun (n : ι) => finset.sum s fun (a : α) => f a n := sorry

theorem mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = supr fun (i : ennreal) => supr fun (H : i ∈ s) => a * i := sorry

theorem mul_supr {ι : Sort u_1} {f : ι → ennreal} {a : ennreal} : a * supr f = supr fun (i : ι) => a * f i := sorry

theorem supr_mul {ι : Sort u_1} {f : ι → ennreal} {a : ennreal} : supr f * a = supr fun (i : ι) => f i * a := sorry

protected theorem tendsto_coe_sub {r : nnreal} {b : ennreal} : filter.tendsto (fun (b : ennreal) => ↑r - b) (nhds b) (nhds (↑r - b)) := sorry

theorem sub_supr {a : ennreal} {ι : Sort u_1} [hι : Nonempty ι] {b : ι → ennreal} (hr : a < ⊤) : (a - supr fun (i : ι) => b i) = infi fun (i : ι) => a - b i := sorry

theorem supr_eq_zero {ι : Sort u_1} {f : ι → ennreal} : (supr fun (i : ι) => f i) = 0 ↔ ∀ (i : ι), f i = 0 := sorry

protected theorem has_sum_coe {α : Type u_1} {f : α → nnreal} {r : nnreal} : has_sum (fun (a : α) => ↑(f a)) ↑r ↔ has_sum f r := sorry

protected theorem tsum_coe_eq {α : Type u_1} {r : nnreal} {f : α → nnreal} (h : has_sum f r) : (tsum fun (a : α) => ↑(f a)) = ↑r :=
  has_sum.tsum_eq (iff.mpr ennreal.has_sum_coe h)

protected theorem coe_tsum {α : Type u_1} {f : α → nnreal} : summable f → ↑(tsum f) = tsum fun (a : α) => ↑(f a) := sorry

protected theorem has_sum {α : Type u_1} {f : α → ennreal} : has_sum f (supr fun (s : finset α) => finset.sum s fun (a : α) => f a) :=
  tendsto_at_top_supr fun (s t : finset α) => finset.sum_le_sum_of_subset

@[simp] protected theorem summable {α : Type u_1} {f : α → ennreal} : summable f :=
  Exists.intro (supr fun (s : finset α) => finset.sum s fun (a : α) => f a) ennreal.has_sum

theorem tsum_coe_ne_top_iff_summable {β : Type u_2} {f : β → nnreal} : (tsum fun (b : β) => ↑(f b)) ≠ ⊤ ↔ summable f := sorry

protected theorem tsum_eq_supr_sum {α : Type u_1} {f : α → ennreal} : (tsum fun (a : α) => f a) = supr fun (s : finset α) => finset.sum s fun (a : α) => f a :=
  has_sum.tsum_eq ennreal.has_sum

protected theorem tsum_eq_supr_sum' {α : Type u_1} {f : α → ennreal} {ι : Type u_2} (s : ι → finset α) (hs : ∀ (t : finset α), ∃ (i : ι), t ⊆ s i) : (tsum fun (a : α) => f a) = supr fun (i : ι) => finset.sum (s i) fun (a : α) => f a := sorry

protected theorem tsum_sigma {α : Type u_1} {β : α → Type u_2} (f : (a : α) → β a → ennreal) : (tsum fun (p : sigma fun (a : α) => β a) => f (sigma.fst p) (sigma.snd p)) =
  tsum fun (a : α) => tsum fun (b : β a) => f a b :=
  tsum_sigma' (fun (b : α) => ennreal.summable) ennreal.summable

protected theorem tsum_sigma' {α : Type u_1} {β : α → Type u_2} (f : (sigma fun (a : α) => β a) → ennreal) : (tsum fun (p : sigma fun (a : α) => β a) => f p) = tsum fun (a : α) => tsum fun (b : β a) => f (sigma.mk a b) :=
  tsum_sigma' (fun (b : α) => ennreal.summable) ennreal.summable

protected theorem tsum_prod {α : Type u_1} {β : Type u_2} {f : α → β → ennreal} : (tsum fun (p : α × β) => f (prod.fst p) (prod.snd p)) = tsum fun (a : α) => tsum fun (b : β) => f a b :=
  tsum_prod' ennreal.summable fun (_x : α) => ennreal.summable

protected theorem tsum_comm {α : Type u_1} {β : Type u_2} {f : α → β → ennreal} : (tsum fun (a : α) => tsum fun (b : β) => f a b) = tsum fun (b : β) => tsum fun (a : α) => f a b :=
  tsum_comm' ennreal.summable (fun (_x : β) => ennreal.summable) fun (_x : α) => ennreal.summable

protected theorem tsum_add {α : Type u_1} {f : α → ennreal} {g : α → ennreal} : (tsum fun (a : α) => f a + g a) = (tsum fun (a : α) => f a) + tsum fun (a : α) => g a :=
  tsum_add ennreal.summable ennreal.summable

protected theorem tsum_le_tsum {α : Type u_1} {f : α → ennreal} {g : α → ennreal} (h : ∀ (a : α), f a ≤ g a) : (tsum fun (a : α) => f a) ≤ tsum fun (a : α) => g a :=
  tsum_le_tsum h ennreal.summable ennreal.summable

protected theorem sum_le_tsum {α : Type u_1} {f : α → ennreal} (s : finset α) : (finset.sum s fun (x : α) => f x) ≤ tsum fun (x : α) => f x :=
  sum_le_tsum s (fun (x : α) (hx : ¬x ∈ s) => zero_le (f x)) ennreal.summable

protected theorem tsum_eq_supr_nat' {f : ℕ → ennreal} {N : ℕ → ℕ} (hN : filter.tendsto N filter.at_top filter.at_top) : (tsum fun (i : ℕ) => f i) = supr fun (i : ℕ) => finset.sum (finset.range (N i)) fun (i : ℕ) => f i := sorry

protected theorem tsum_eq_supr_nat {f : ℕ → ennreal} : (tsum fun (i : ℕ) => f i) = supr fun (i : ℕ) => finset.sum (finset.range i) fun (i : ℕ) => f i :=
  ennreal.tsum_eq_supr_sum' (fun (i : ℕ) => finset.range i) finset.exists_nat_subset_range

protected theorem le_tsum {α : Type u_1} {f : α → ennreal} (a : α) : f a ≤ tsum fun (a : α) => f a :=
  le_tsum' ennreal.summable a

protected theorem tsum_eq_top_of_eq_top {α : Type u_1} {f : α → ennreal} : (∃ (a : α), f a = ⊤) → (tsum fun (a : α) => f a) = ⊤ :=
  fun (ᾰ : ∃ (a : α), f a = ⊤) =>
    Exists.dcases_on ᾰ
      fun (ᾰ_w : α) (ᾰ_h : f ᾰ_w = ⊤) => idRhs ((tsum fun (a : α) => f a) = ⊤) (top_unique (ᾰ_h ▸ ennreal.le_tsum ᾰ_w))

protected theorem ne_top_of_tsum_ne_top {α : Type u_1} {f : α → ennreal} (h : (tsum fun (a : α) => f a) ≠ ⊤) (a : α) : f a ≠ ⊤ :=
  fun (ha : f a = ⊤) => h (ennreal.tsum_eq_top_of_eq_top (Exists.intro a ha))

protected theorem tsum_mul_left {α : Type u_1} {a : ennreal} {f : α → ennreal} : (tsum fun (i : α) => a * f i) = a * tsum fun (i : α) => f i := sorry

protected theorem tsum_mul_right {α : Type u_1} {a : ennreal} {f : α → ennreal} : (tsum fun (i : α) => f i * a) = (tsum fun (i : α) => f i) * a := sorry

@[simp] theorem tsum_supr_eq {α : Type u_1} (a : α) {f : α → ennreal} : (tsum fun (b : α) => supr fun (h : a = b) => f b) = f a := sorry

theorem has_sum_iff_tendsto_nat {f : ℕ → ennreal} (r : ennreal) : has_sum f r ↔ filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top (nhds r) := sorry

theorem to_nnreal_apply_of_tsum_ne_top {α : Type u_1} {f : α → ennreal} (hf : (tsum fun (i : α) => f i) ≠ ⊤) (x : α) : ↑(function.comp ennreal.to_nnreal f x) = f x :=
  coe_to_nnreal (ennreal.ne_top_of_tsum_ne_top hf x)

theorem summable_to_nnreal_of_tsum_ne_top {α : Type u_1} {f : α → ennreal} (hf : (tsum fun (i : α) => f i) ≠ ⊤) : summable (ennreal.to_nnreal ∘ f) := sorry

protected theorem tsum_apply {ι : Type u_1} {α : Type u_2} {f : ι → α → ennreal} {x : α} : tsum (fun (i : ι) => f i) x = tsum fun (i : ι) => f i x :=
  tsum_apply (iff.mpr pi.summable fun (_x : α) => ennreal.summable)

theorem tsum_sub {f : ℕ → ennreal} {g : ℕ → ennreal} (h₁ : (tsum fun (i : ℕ) => g i) < ⊤) (h₂ : g ≤ f) : (tsum fun (i : ℕ) => f i - g i) = (tsum fun (i : ℕ) => f i) - tsum fun (i : ℕ) => g i := sorry

end ennreal

namespace nnreal

/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
theorem exists_le_has_sum_of_le {β : Type u_2} {f : β → nnreal} {g : β → nnreal} {r : nnreal} (hgf : ∀ (b : β), g b ≤ f b) (hfr : has_sum f r) : ∃ (p : nnreal), ∃ (H : p ≤ r), has_sum g p := sorry

/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
theorem summable_of_le {β : Type u_2} {f : β → nnreal} {g : β → nnreal} (hgf : ∀ (b : β), g b ≤ f b) : summable f → summable g := sorry

/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
theorem has_sum_iff_tendsto_nat {f : ℕ → nnreal} {r : nnreal} : has_sum f r ↔ filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top (nhds r) := sorry

theorem not_summable_iff_tendsto_nat_at_top {f : ℕ → nnreal} : ¬summable f ↔ filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top filter.at_top := sorry

theorem summable_iff_not_tendsto_nat_at_top {f : ℕ → nnreal} : summable f ↔ ¬filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top filter.at_top := sorry

theorem summable_of_sum_range_le {f : ℕ → nnreal} {c : nnreal} (h : ∀ (n : ℕ), (finset.sum (finset.range n) fun (i : ℕ) => f i) ≤ c) : summable f := sorry

theorem tsum_le_of_sum_range_le {f : ℕ → nnreal} {c : nnreal} (h : ∀ (n : ℕ), (finset.sum (finset.range n) fun (i : ℕ) => f i) ≤ c) : (tsum fun (i : ℕ) => f i) ≤ c :=
  le_of_tendsto' (iff.mp has_sum_iff_tendsto_nat (summable.has_sum (summable_of_sum_range_le h))) h

theorem tsum_comp_le_tsum_of_inj {α : Type u_1} {β : Type u_2} {f : α → nnreal} (hf : summable f) {i : β → α} (hi : function.injective i) : (tsum fun (x : β) => f (i x)) ≤ tsum fun (x : α) => f x :=
  tsum_le_tsum_of_inj i hi (fun (c : α) (hc : ¬c ∈ set.range i) => zero_le (f c)) (fun (b : β) => le_refl (f (i b)))
    (summable_comp_injective hf hi) hf

theorem summable_sigma {α : Type u_1} {β : α → Type u_2} {f : (sigma fun (x : α) => β x) → nnreal} : summable f ↔
  (∀ (x : α), summable fun (y : β x) => f (sigma.mk x y)) ∧
    summable fun (x : α) => tsum fun (y : β x) => f (sigma.mk x y) := sorry

/-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability
assumption on `f`, as otherwise all sums are zero. -/
theorem tendsto_sum_nat_add (f : ℕ → nnreal) : filter.tendsto (fun (i : ℕ) => tsum fun (k : ℕ) => f (k + i)) filter.at_top (nhds 0) := sorry

end nnreal

namespace ennreal

theorem tendsto_sum_nat_add (f : ℕ → ennreal) (hf : (tsum fun (i : ℕ) => f i) ≠ ⊤) : filter.tendsto (fun (i : ℕ) => tsum fun (k : ℕ) => f (k + i)) filter.at_top (nhds 0) := sorry

end ennreal

theorem tsum_comp_le_tsum_of_inj {α : Type u_1} {β : Type u_2} {f : α → ℝ} (hf : summable f) (hn : ∀ (a : α), 0 ≤ f a) {i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f := sorry

/-- Comparison test of convergence of series of non-negative real numbers. -/
theorem summable_of_nonneg_of_le {β : Type u_2} {f : β → ℝ} {g : β → ℝ} (hg : ∀ (b : β), 0 ≤ g b) (hgf : ∀ (b : β), g b ≤ f b) (hf : summable f) : summable g := sorry

/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
theorem has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀ (i : ℕ), 0 ≤ f i) (r : ℝ) : has_sum f r ↔ filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top (nhds r) := sorry

theorem ennreal.of_real_tsum_of_nonneg {α : Type u_1} {f : α → ℝ} (hf_nonneg : ∀ (n : α), 0 ≤ f n) (hf : summable f) : ennreal.of_real (tsum fun (n : α) => f n) = tsum fun (n : α) => ennreal.of_real (f n) := sorry

theorem not_summable_iff_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ (n : ℕ), 0 ≤ f n) : ¬summable f ↔ filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top filter.at_top := sorry

theorem summable_iff_not_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ (n : ℕ), 0 ≤ f n) : summable f ↔ ¬filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i) filter.at_top filter.at_top := sorry

theorem summable_sigma_of_nonneg {α : Type u_1} {β : α → Type u_2} {f : (sigma fun (x : α) => β x) → ℝ} (hf : ∀ (x : sigma fun (x : α) => β x), 0 ≤ f x) : summable f ↔
  (∀ (x : α), summable fun (y : β x) => f (sigma.mk x y)) ∧
    summable fun (x : α) => tsum fun (y : β x) => f (sigma.mk x y) := sorry

theorem summable_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ (n : ℕ), 0 ≤ f n) (h : ∀ (n : ℕ), (finset.sum (finset.range n) fun (i : ℕ) => f i) ≤ c) : summable f := sorry

theorem tsum_le_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ (n : ℕ), 0 ≤ f n) (h : ∀ (n : ℕ), (finset.sum (finset.range n) fun (i : ℕ) => f i) ≤ c) : (tsum fun (i : ℕ) => f i) ≤ c := sorry

/-- In an emetric ball, the distance between points is everywhere finite -/
theorem edist_ne_top_of_mem_ball {β : Type u_2} [emetric_space β] {a : β} {r : ennreal} (x : ↥(emetric.ball a r)) (y : ↥(emetric.ball a r)) : edist (subtype.val x) (subtype.val y) ≠ ⊤ := sorry

/-- Each ball in an extended metric space gives us a metric space, as the edist
is everywhere finite. -/
def metric_space_emetric_ball {β : Type u_2} [emetric_space β] (a : β) (r : ennreal) : metric_space ↥(emetric.ball a r) :=
  emetric_space.to_metric_space edist_ne_top_of_mem_ball

theorem nhds_eq_nhds_emetric_ball {β : Type u_2} [emetric_space β] (a : β) (x : β) (r : ennreal) (h : x ∈ emetric.ball a r) : nhds x = filter.map coe (nhds { val := x, property := h }) :=
  Eq.symm (map_nhds_subtype_coe_eq h (mem_nhds_sets emetric.is_open_ball h))

theorem tendsto_iff_edist_tendsto_0 {α : Type u_1} {β : Type u_2} [emetric_space α] {l : filter β} {f : β → α} {y : α} : filter.tendsto f l (nhds y) ↔ filter.tendsto (fun (x : β) => edist (f x) y) l (nhds 0) := sorry

/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
theorem emetric.cauchy_seq_iff_le_tendsto_0 {α : Type u_1} {β : Type u_2} [emetric_space α] [Nonempty β] [semilattice_sup β] {s : β → α} : cauchy_seq s ↔
  ∃ (b : β → ennreal),
    (∀ (n m N : β), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N) ∧ filter.tendsto b filter.at_top (nhds 0) := sorry

theorem continuous_of_le_add_edist {α : Type u_1} [emetric_space α] {f : α → ennreal} (C : ennreal) (hC : C ≠ ⊤) (h : ∀ (x y : α), f x ≤ f y + C * edist x y) : continuous f := sorry

theorem continuous_edist {α : Type u_1} [emetric_space α] : continuous fun (p : α × α) => edist (prod.fst p) (prod.snd p) := sorry

theorem continuous.edist {α : Type u_1} {β : Type u_2} [emetric_space α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous fun (b : β) => edist (f b) (g b) :=
  continuous.comp continuous_edist (continuous.prod_mk hf hg)

theorem filter.tendsto.edist {α : Type u_1} {β : Type u_2} [emetric_space α] {f : β → α} {g : β → α} {x : filter β} {a : α} {b : α} (hf : filter.tendsto f x (nhds a)) (hg : filter.tendsto g x (nhds b)) : filter.tendsto (fun (x : β) => edist (f x) (g x)) x (nhds (edist a b)) :=
  filter.tendsto.comp (continuous.tendsto continuous_edist (a, b)) (filter.tendsto.prod_mk_nhds hf hg)

theorem cauchy_seq_of_edist_le_of_tsum_ne_top {α : Type u_1} [emetric_space α] {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ (n : ℕ), edist (f n) (f (Nat.succ n)) ≤ d n) (hd : tsum d ≠ ⊤) : cauchy_seq f := sorry

theorem emetric.is_closed_ball {α : Type u_1} [emetric_space α] {a : α} {r : ennreal} : is_closed (emetric.closed_ball a r) :=
  is_closed_le (continuous.edist continuous_id continuous_const) continuous_const

/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`,
then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/
theorem edist_le_tsum_of_edist_le_of_tendsto {α : Type u_1} [emetric_space α] {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ (n : ℕ), edist (f n) (f (Nat.succ n)) ≤ d n) {a : α} (ha : filter.tendsto f filter.at_top (nhds a)) (n : ℕ) : edist (f n) a ≤ tsum fun (m : ℕ) => d (n + m) := sorry

/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`,
then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/
theorem edist_le_tsum_of_edist_le_of_tendsto₀ {α : Type u_1} [emetric_space α] {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ (n : ℕ), edist (f n) (f (Nat.succ n)) ≤ d n) {a : α} (ha : filter.tendsto f filter.at_top (nhds a)) : edist (f 0) a ≤ tsum fun (m : ℕ) => d m := sorry