Module docstring
{"# Order homomorphisms and sets "}
{"# Order homomorphisms and sets "}
Set.sumEquiv
      definition
     : Set (α ⊕ β) ≃o Set α × Set β
        /-- Sets on sum types are order-equivalent to pairs of sets on each summand. -/
def sumEquiv : SetSet (α ⊕ β) ≃o Set α × Set β where
  toFun s := (Sum.inl ⁻¹' s, Sum.inr ⁻¹' s)
  invFun s := Sum.inlSum.inl '' s.1Sum.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]
        OrderIso.range_eq
      theorem
     (e : α ≃o β) : Set.range e = Set.univ
        
      OrderIso.symm_image_image
      theorem
     (e : α ≃o β) (s : Set α) : e.symm '' (e '' s) = s
        @[simp]
theorem symm_image_image (e : α ≃o β) (s : Set α) : e.symm '' (e '' s) = s :=
  e.toEquiv.symm_image_image s
        OrderIso.image_symm_image
      theorem
     (e : α ≃o β) (s : Set β) : e '' (e.symm '' s) = s
        @[simp]
theorem image_symm_image (e : α ≃o β) (s : Set β) : e '' (e.symm '' s) = s :=
  e.toEquiv.image_symm_image s
        OrderIso.image_eq_preimage
      theorem
     (e : α ≃o β) (s : Set α) : e '' s = e.symm ⁻¹' s
        theorem image_eq_preimage (e : α ≃o β) (s : Set α) : e '' s = e.symm ⁻¹' s :=
  e.toEquiv.image_eq_preimage s
        OrderIso.preimage_symm_preimage
      theorem
     (e : α ≃o β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s
        @[simp]
theorem preimage_symm_preimage (e : α ≃o β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s :=
  e.toEquiv.preimage_symm_preimage s
        OrderIso.symm_preimage_preimage
      theorem
     (e : α ≃o β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s
        @[simp]
theorem symm_preimage_preimage (e : α ≃o β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s :=
  e.toEquiv.symm_preimage_preimage s
        OrderIso.image_preimage
      theorem
     (e : α ≃o β) (s : Set β) : e '' (e ⁻¹' s) = s
        @[simp]
theorem image_preimage (e : α ≃o β) (s : Set β) : e '' (e ⁻¹' s) = s :=
  e.toEquiv.image_preimage s
        OrderIso.preimage_image
      theorem
     (e : α ≃o β) (s : Set α) : e ⁻¹' (e '' s) = s
        @[simp]
theorem preimage_image (e : α ≃o β) (s : Set α) : e ⁻¹' (e '' s) = s :=
  e.toEquiv.preimage_image s
        OrderIso.setCongr
      definition
     (s t : Set α) (h : s = t) : s ≃o t
        /-- Order isomorphism between two equal sets. -/
def setCongr (s t : Set α) (h : s = t) :
    s ≃o t where
  toEquiv := Equiv.setCongr h
  map_rel_iff' := Iff.rfl
        OrderIso.Set.univ
      definition
     : (Set.univ : Set α) ≃o α
        /-- Order isomorphism between `univ : Set α` and `α`. -/
def Set.univ : (Set.univ : Set α) ≃o α where
  toEquiv := Equiv.Set.univ α
  map_rel_iff' := Iff.rfl
        OrderEmbedding.orderIso
      definition
     [LE α] [LE β] {f : α ↪o β} : α ≃o Set.range f
        /-- 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 }
        StrictMonoOn.orderIso
      definition
     {α β} [LinearOrder α] [Preorder β] (f : α → β) (s : Set α) (hf : StrictMonoOn f s) : s ≃o f '' s
        /-- 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 _)
        StrictMono.orderIso
      definition
     : α ≃o Set.range 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
        StrictMono.orderIsoOfSurjective
      definition
     : α ≃o β
        /-- A strictly monotone surjective function from a linear order is an order isomorphism. -/
noncomputable def orderIsoOfSurjective : α ≃o β :=
  (h_mono.orderIso f).trans <|
    (OrderIso.setCongr _ _ h_surj.range_eq).trans OrderIso.Set.univ
        StrictMono.coe_orderIsoOfSurjective
      theorem
     : (orderIsoOfSurjective f h_mono h_surj : α → β) = f
        @[simp]
theorem coe_orderIsoOfSurjective : (orderIsoOfSurjective f h_mono h_surj : α → β) = f :=
  rfl
        StrictMono.orderIsoOfSurjective_symm_apply_self
      theorem
     (a : α) : (orderIsoOfSurjective f h_mono h_surj).symm (f a) = a
        @[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 _
        StrictMono.orderIsoOfSurjective_self_symm_apply
      theorem
     (b : β) : f ((orderIsoOfSurjective f h_mono h_surj).symm b) = b
        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 _
        OrderEmbedding.range_inj
      theorem
     [LinearOrder α] [WellFoundedLT α] [Preorder β] {f g : α ↪o β} : Set.range f = Set.range g ↔ f = g
        /-- Two order embeddings on a well-order are equal provided that their ranges are equal. -/
lemma OrderEmbedding.range_inj [LinearOrder α] [WellFoundedLT α] [Preorder β] {f g : α ↪o β} :
    Set.rangeSet.range f = Set.range g ↔ f = g := by
  rw [f.strictMono.range_inj g.strictMono, DFunLike.coe_fn_eq]
        OrderIso.subsingleton_of_wellFoundedLT
      instance
     [LinearOrder α] [WellFoundedLT α] [Preorder β] : Subsingleton (α ≃o β)
        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, coe_toOrderEmbedding, coe_toOrderEmbedding, range_eq, range_eq]
        OrderIso.subsingleton_of_wellFoundedLT'
      instance
     [LinearOrder β] [WellFoundedLT β] [Preorder α] : Subsingleton (α ≃o β)
        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]
        OrderIso.unique_of_wellFoundedLT
      instance
     [LinearOrder α] [WellFoundedLT α] : Unique (α ≃o α)
        instance unique_of_wellFoundedLT [LinearOrder α] [WellFoundedLT α] : Unique (α ≃o α) := Unique.mk' _
        OrderIso.subsingleton_of_wellFoundedGT
      instance
     [LinearOrder α] [WellFoundedGT α] [Preorder β] : Subsingleton (α ≃o β)
        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]
        OrderIso.subsingleton_of_wellFoundedGT'
      instance
     [LinearOrder β] [WellFoundedGT β] [Preorder α] : Subsingleton (α ≃o β)
        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]
        OrderIso.unique_of_wellFoundedGT
      instance
     [LinearOrder α] [WellFoundedGT α] : Unique (α ≃o α)
        instance unique_of_wellFoundedGT [LinearOrder α] [WellFoundedGT α] : Unique (α ≃o α) := Unique.mk' _
        OrderIso.Iic
      definition
     [Lattice α] [Lattice β] (e : α ≃o β) (x : α) : Iic x ≃o Iic (e x)
        /-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/
protected def Iic [Lattice α] [Lattice β] (e : α ≃o β) (x : α) :
    IicIic 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
        OrderIso.Ici
      definition
     [Lattice α] [Lattice β] (e : α ≃o β) (x : α) : Ici x ≃o Ici (e x)
        /-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/
protected def Ici [Lattice α] [Lattice β] (e : α ≃o β) (x : α) :
    IciIci 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
        OrderIso.Icc
      definition
     [Lattice α] [Lattice β] (e : α ≃o β) (x y : α) : Icc x y ≃o Icc (e x) (e y)
        /-- An order isomorphism between lattices induces an order isomorphism between corresponding
interval sublattices. -/
protected def Icc [Lattice α] [Lattice β] (e : α ≃o β) (x y : α) :
    IccIcc 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
        OrderIso.compl
      definition
     : α ≃o αᵒᵈ
        /-- Taking complements as an order isomorphism to the order dual. -/
@[simps!]
def OrderIso.compl : α ≃o αᵒᵈ where
  toFun := OrderDual.toDualOrderDual.toDual ∘ HasCompl.compl
  invFun := HasCompl.complHasCompl.compl ∘ OrderDual.ofDual
  left_inv := compl_compl
  right_inv := compl_compl (α := αᵒᵈ)
  map_rel_iff' := compl_le_compl_iff_le
        compl_strictAnti
      theorem
     : StrictAnti (compl : α → α)
        theorem compl_strictAnti : StrictAnti (compl : α → α) :=
  (OrderIso.compl α).strictMono
        compl_antitone
      theorem
     : Antitone (compl : α → α)
        theorem compl_antitone : Antitone (compl : α → α) :=
  (OrderIso.compl α).monotone