Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Algebra/Field/     Datei vom 15.10.2026 mit Größe 1 kB image not shown  

Quelle  Set.lean   Sprache: Lean

 

/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/

module

public import Mathlib.Logic.Equiv.Set
public import Mathlib.Order.Hom.Basic
public import Mathlib.Order.Interval.Set.Defs
public import Mathlib.Order.WellFounded

/-!
# Order homomorphisms and sets
-/


@[expose] public section


open OrderDual Set

variable {α β γ : Type*}

namespace Set

/-- Membership as an order isomorphism between sets and predicates. -/
@[simps!]
def memOrderIso : Set α ≃o (α → Prop) where
  toEquiv := memEquiv
  map_rel_iff' := .rfl

/-- Sets on sum types are order-equivalent to pairs of sets on each summand. -/
@[simps apply]
def sumEquiv : Set (α ⊕ β) ≃o Set α × Set β where
  toFun s := (Sum.inl ⁻¹' s, Sum.inr ⁻¹' s)
  invFun s := Sum.inl '' s.1 ∪ Sum.inr '' s.2
  left_inv s := image_preimage_inl_union_image_preimage_inr s
  right_inv s := by
    simp [preimage_image_eq _ Sum.inl_injective, preimage_image_eq _ Sum.inr_injective]
  map_rel_iff' := by simp [subset_def]

@[simp]
theorem sumEquiv_symm_apply {s : Set α × Set β} :
    sumEquiv.symm s = Sum.inl '' s.1 ∪ Sum.inr '' s.2 := rfl

theorem MapsTo.sumElim {f : α → γ} {g : β → γ} {s : Set α × Set β} {t : Set γ}
    (hf : Set.MapsTo f s.1 t) (hg : Set.MapsTo g s.2 t) :
    Set.MapsTo (Sum.elim f g) (Set.sumEquiv.symm s) t := by
  rintro (a | b) <;> aesop

theorem InjOn.sumElim {f : α → γ} {g : β → γ} {s : Set α × Set β}
    (hf : Set.InjOn f s.1) (hg : Set.InjOn g s.2) (hfg : ∀ a ∈ s.1, ∀ b ∈ s.2, f a ≠ g b) :
    Set.InjOn (Sum.elim f g) (Set.sumEquiv.symm s) := by
  rintro (a₁ | b₁) h₁ (a₂ | b₂) h₂ heq <;> aesop

section Preorder
variable [Preorder α]

/-- Order isomorphism between two equal sets. -/
@[simps! apply symm_apply]
def orderIsoOfEq (s t : Set α) (h : s = t) : s ≃o t where
  toEquiv := equivOfEq h
  map_rel_iff' := Iff.rfl

@[deprecated (since := "2026-08-29")] alias _root_.OrderIso.Set.congr := orderIsoOfEq
@[deprecated (since := "2026-08-29")] alias _root_.OrderIso.Set.congr_apply := orderIsoOfEq_apply
@[deprecated (since := "2026-08-29")]
alias _root_.OrderIso.Set.congr_symm_apply := orderIsoOfEq_symm_apply

end Preorder

end Set

namespace OrderIso

section LE

variable [LE α] [LE β]

theorem range_eq (e : α ≃o β) : Set.range e = Set.univ :=
  e.surjective.range_eq

@[simp]
theorem symm_image_image (e : α ≃o β) (s : Set α) : e.symm '' e '' s = s :=
  e.toEquiv.symm_image_image s

@[simp]
theorem image_symm_image (e : α ≃o β) (s : Set β) : e '' e.symm '' s = s :=
  e.toEquiv.image_symm_image s

theorem image_eq_preimage_symm (e : α ≃o β) (s : Set α) : e '' s = e.symm ⁻¹' s :=
  e.toEquiv.image_eq_preimage_symm s

@[simp]
theorem preimage_symm_preimage (e : α ≃o β) (s : Set α) : e ⁻¹' e.symm ⁻¹' s = s :=
  e.toEquiv.preimage_symm_preimage s

@[simp]
theorem symm_preimage_preimage (e : α ≃o β) (s : Set β) : e.symm ⁻¹' e ⁻¹' s = s :=
  e.toEquiv.symm_preimage_preimage s

@[simp]
theorem image_preimage (e : α ≃o β) (s : Set β) : e '' e ⁻¹' s = s :=
  e.toEquiv.image_preimage s

@[simp]
theorem preimage_image (e : α ≃o β) (s : Set α) : e ⁻¹' e '' s = s :=
  e.toEquiv.preimage_image s

end LE

open Set

variable [Preorder α]

@[deprecated (since := "2026-08-21")] alias setCongr := _root_.Set.orderIsoOfEq
@[deprecated (since := "2026-08-21")] alias setCongr_apply := _root_.Set.orderIsoOfEq_apply
@[deprecated (since := "2026-08-21")]
alias setCongr_symm_apply := _root_.Set.orderIsoOfEq_symm_apply

/-- Order isomorphism between `univ : Set α` and `α`. -/
def Set.univ : (Set.univ : Set α) ≃o α where
  toEquiv := Equiv.Set.univ α
  map_rel_iff' := Iff.rfl

end OrderIso

/-- We can regard an order embedding as an order isomorphism to its range. -/
@[simps! apply]
noncomputable def OrderEmbedding.orderIso [LE α] [LE β] {f : α ↪o β} :
    α ≃o Set.range f :=
  { Equiv.ofInjective _ f.injective with
    map_rel_iff' := f.map_rel_iff }

/-- If a function `f` is strictly monotone on a set `s`, then it defines an order isomorphism
between `s` and its image. -/

protected noncomputable def StrictMonoOn.orderIso {α β} [LinearOrder α] [Preorder β] (f : α → β)
    (s : Set α) (hf : StrictMonoOn f s) :
    s ≃o f '' s where
  toEquiv := hf.injOn.bijOn_image.equiv _
  map_rel_iff' := hf.le_iff_le (Subtype.property _) (Subtype.property _)

namespace StrictMono

variable [LinearOrder α] [Preorder β]
variable (f : α → β) (h_mono : StrictMono f) (h_surj : Function.Surjective f)

/-- A strictly monotone function from a linear order is an order isomorphism between its domain and
its range. -/

@[simps! apply]
protected noncomputable def orderIso :
    α ≃o Set.range f where
  toEquiv := Equiv.ofInjective f h_mono.injective
  map_rel_iff' := h_mono.le_iff_le

/-- A strictly monotone surjective function from a linear order is an order isomorphism. -/
noncomputable def orderIsoOfSurjective : α ≃o β :=
  (h_mono.orderIso f).trans <|
    (Set.orderIsoOfEq _ _ h_surj.range_eq).trans OrderIso.Set.univ

@[simp]
theorem coe_orderIsoOfSurjective : (orderIsoOfSurjective f h_mono h_surj : α → β) = f :=
  rfl

@[simp]
theorem orderIsoOfSurjective_symm_apply_self (a : α) :
    (orderIsoOfSurjective f h_mono h_surj).symm (f a) = a :=
  (orderIsoOfSurjective f h_mono h_surj).symm_apply_apply _

theorem orderIsoOfSurjective_self_symm_apply (b : β) :
    f ((orderIsoOfSurjective f h_mono h_surj).symm b) = b :=
  (orderIsoOfSurjective f h_mono h_surj).apply_symm_apply _

end StrictMono

/-- Two order embeddings with the same range are equal if their domain has no nontrivial order
automorphisms. -/

lemma OrderEmbedding.eq_of_range_eq [Preorder α] [Preorder β] [Subsingleton (α ≃o α)]
    {f g : α ↪o β} (h : Set.range f = Set.range g) : f = g := by
  let e : α ≃o α := f.orderIso.trans ((Set.orderIsoOfEq _ _ h).trans g.orderIso.symm)
  have he : e = OrderIso.refl α := Subsingleton.elim _ _
  ext x
  have : g (e x) = f x := congrArg Subtype.val <|
    g.orderIso.apply_symm_apply (Set.orderIsoOfEq _ _ h (f.orderIso x))
  simp_all

/-- Two strictly monotone functions are equal provided that their ranges are equal, assuming the
type of order automorphisms of the domain is a subsingleton. -/

lemma StrictMono.eq_of_range_eq [LinearOrder α] [Preorder β]
    [Subsingleton (α ≃o α)] {f g : α → β} (hf : StrictMono f) (hg : StrictMono g)
    (h : Set.range f = Set.range g) : f = g := by
  have : Set.range (OrderEmbedding.ofStrictMono f hf) = Set.range f := by simp
  have : Set.range (OrderEmbedding.ofStrictMono g hg) = Set.range g := by simp
  grind [OrderEmbedding.eq_of_range_eq]

/-- Two order embeddings on a well-order are equal provided that their ranges are equal. -/
@[to_dual
/-- Two order embeddings on a well-order are equal provided that their ranges are equal. -/]
lemma OrderEmbedding.range_inj_of_wellFoundedLT [LinearOrder α] [WellFoundedLT α] [Preorder β]
    {f g : α ↪o β} : Set.range f = Set.range g ↔ f = g := by
  rw [f.strictMono.range_inj_of_wellFoundedLT g.strictMono, DFunLike.coe_fn_eq]

@[deprecated (since := "2026-08-13")]
alias OrderEmbedding.range_inj := OrderEmbedding.range_inj_of_wellFoundedLT

namespace OrderIso

-- These results are also true whenever β is well-founded instead of α.
-- You can use `RelEmbedding.isWellFounded` to transfer the instance over.

instance subsingleton_of_wellFoundedLT [LinearOrder α] [WellFoundedLT α] [Preorder β] :
    Subsingleton (α ≃o β) := by
  refine ⟨fun f g ↦ ?_⟩
  rw [OrderIso.ext_iff, ← coe_toOrderEmbedding, ← coe_toOrderEmbedding, DFunLike.coe_fn_eq,
    ← OrderEmbedding.range_inj_of_wellFoundedLT, coe_toOrderEmbedding, coe_toOrderEmbedding,
    range_eq, range_eq]

instance subsingleton_of_wellFoundedLT' [LinearOrder β] [WellFoundedLT β] [Preorder α] :
    Subsingleton (α ≃o β) := by
  refine ⟨fun f g ↦ ?_⟩
  change f.symm.symm = g.symm.symm
  rw [Subsingleton.elim f.symm]

instance unique_of_wellFoundedLT [LinearOrder α] [WellFoundedLT α] : Unique (α ≃o α) := Unique.mk' _

instance subsingleton_of_wellFoundedGT [LinearOrder α] [WellFoundedGT α] [Preorder β] :
    Subsingleton (α ≃o β) := by
  refine ⟨fun f g ↦ ?_⟩
  change f.dual.dual = g.dual.dual
  rw [Subsingleton.elim f.dual]

instance subsingleton_of_wellFoundedGT' [LinearOrder β] [WellFoundedGT β] [Preorder α] :
    Subsingleton (α ≃o β) := by
  refine ⟨fun f g ↦ ?_⟩
  change f.dual.dual = g.dual.dual
  rw [Subsingleton.elim f.dual]

instance unique_of_wellFoundedGT [LinearOrder α] [WellFoundedGT α] : Unique (α ≃o α) := Unique.mk' _

set_option backward.isDefEq.respectTransparency false in
/-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/

protected def Iic [Lattice α] [Lattice β] (e : α ≃o β) (x : α) :
    Iic x ≃o Iic (e x) where
  toFun y := ⟨e y, (map_le_map_iff _).mpr y.property⟩
  invFun y := ⟨e.symm y, e.symm_apply_le.mpr y.property⟩
  left_inv y := by simp
  right_inv y := by simp
  map_rel_iff' := by simp

set_option backward.isDefEq.respectTransparency false in
/-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/

protected def Ici [Lattice α] [Lattice β] (e : α ≃o β) (x : α) :
    Ici x ≃o Ici (e x) where
  toFun y := ⟨e y, (map_le_map_iff _).mpr y.property⟩
  invFun y := ⟨e.symm y, e.le_symm_apply.mpr y.property⟩
  left_inv y := by simp
  right_inv y := by simp
  map_rel_iff' := by simp

/-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/

protected def Icc [Lattice α] [Lattice β] (e : α ≃o β) (x y : α) :
    Icc x y ≃o Icc (e x) (e y) where
  toFun z := ⟨e z, by simp only [mem_Icc, map_le_map_iff]; exact z.property⟩
  invFun z := ⟨e.symm z, by simp only [mem_Icc, e.le_symm_apply, e.symm_apply_le]; exact z.property⟩
  left_inv y := by simp
  right_inv y := by simp
  map_rel_iff' := by simp

end OrderIso

section BooleanAlgebra

variable (α) [BooleanAlgebra α]

/-- Taking complements as an order isomorphism to the order dual. -/
@[simps!]
def OrderIso.compl : α ≃o αᵒᵈ where
  toFun := OrderDual.toDual ∘ Compl.compl
  invFun := Compl.compl ∘ OrderDual.ofDual
  left_inv := compl_compl
  right_inv := compl_compl (α := αᵒᵈ)
  map_rel_iff' := compl_le_compl_iff_le

theorem compl_strictAnti : StrictAnti (compl : α → α) :=
  (OrderIso.compl α).strictMono

theorem compl_antitone : Antitone (compl : α → α) :=
  (OrderIso.compl α).monotone

end BooleanAlgebra

Messung
CHZG
9310010097

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-11-24) ¤

*© Formatika GbR, Deutschland