source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Order/Irreducible.lean
import Mathlib.Data.Finset.Lattice.Fold /-! # Irreducible and prime elements in an order This file defines irreducible and prime elements in an order and shows that in a well-founded lattice every element decomposes as a supremum of irreducible elements. An element is sup-irreducible (resp. inf-irreducible) if it isn't `⊥` and can't be written as the supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `⊥` and is greater than the supremum of any two elements less than it. Primality implies irreducibility in general. The converse only holds in distributive lattices. Both hold for all (non-minimal) elements in a linear order. ## Main declarations * `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b ⊔ c → a = b ∨ a = c` * `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b ⊓ c → a = b ∨ a = c` * `SupPrime a`: Sup-primality, `a` isn't minimal and `a ≤ b ⊔ c → a ≤ b ∨ a ≤ c` * `InfIrred a`: Inf-primality, `a` isn't maximal and `a ≥ b ⊓ c → a ≥ b ∨ a ≥ c` * `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles in a well-founded semilattice. -/ open Finset OrderDual variable {ι α : Type*} /-! ### Irreducible and prime elements -/ section SemilatticeSup variable [SemilatticeSup α] {a b c : α} /-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller. -/ def SupIrred (a : α) : Prop := ¬IsMin a ∧ ∀ ⦃b c⦄, b ⊔ c = a → b = a ∨ c = a /-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything smaller. -/ def SupPrime (a : α) : Prop := ¬IsMin a ∧ ∀ ⦃b c⦄, a ≤ b ⊔ c → a ≤ b ∨ a ≤ c theorem SupIrred.not_isMin (ha : SupIrred a) : ¬IsMin a := ha.1 theorem SupPrime.not_isMin (ha : SupPrime a) : ¬IsMin a := ha.1 theorem IsMin.not_supIrred (ha : IsMin a) : ¬SupIrred a := fun h => h.1 ha theorem IsMin.not_supPrime (ha : IsMin a) : ¬SupPrime a := fun h => h.1 ha @[simp] theorem not_supIrred : ¬SupIrred a ↔ IsMin a ∨ ∃ b c, b ⊔ c = a ∧ b < a ∧ c < a := by rw [SupIrred, not_and_or] push_neg rw [exists₂_congr] simp +contextual [@eq_comm _ _ a] @[simp] theorem not_supPrime : ¬SupPrime a ↔ IsMin a ∨ ∃ b c, a ≤ b ⊔ c ∧ ¬a ≤ b ∧ ¬a ≤ c := by rw [SupPrime, not_and_or]; push_neg; rfl protected theorem SupPrime.supIrred : SupPrime a → SupIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.ge theorem SupPrime.le_sup (ha : SupPrime a) : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := ⟨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩ variable [OrderBot α] {s : Finset ι} {f : ι → α} @[simp] theorem not_supIrred_bot : ¬SupIrred (⊥ : α) := isMin_bot.not_supIrred @[simp] theorem not_supPrime_bot : ¬SupPrime (⊥ : α) := isMin_bot.not_supPrime theorem SupIrred.ne_bot (ha : SupIrred a) : a ≠ ⊥ := by rintro rfl; exact not_supIrred_bot ha theorem SupPrime.ne_bot (ha : SupPrime a) : a ≠ ⊥ := by rintro rfl; exact not_supPrime_bot ha theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : ∃ i ∈ s, f i = a := by classical induction s using Finset.induction with | empty => simpa [ha.ne_bot] using h.symm | insert i s _ ih => simp only [exists_mem_insert] at ih ⊢ rw [sup_insert] at h exact (ha.2 h).imp_right ih theorem SupPrime.le_finset_sup (ha : SupPrime a) : a ≤ s.sup f ↔ ∃ i ∈ s, a ≤ f i := by classical induction s using Finset.induction with | empty => simp [ha.ne_bot] | insert i s _ ih => simp only [exists_mem_insert, sup_insert, ha.le_sup, ih] variable [WellFoundedLT α] /-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible elements. This is the order-theoretic analogue of prime factorisation. -/ theorem exists_supIrred_decomposition (a : α) : ∃ s : Finset α, s.sup id = a ∧ ∀ ⦃b⦄, b ∈ s → SupIrred b := by classical apply WellFoundedLT.induction a _ clear a rintro a ih by_cases ha : SupIrred a · exact ⟨{a}, by simp [ha]⟩ rw [not_supIrred] at ha obtain ha | ⟨b, c, rfl, hb, hc⟩ := ha · exact ⟨∅, by simp [ha.eq_bot]⟩ obtain ⟨s, rfl, hs⟩ := ih _ hb obtain ⟨t, rfl, ht⟩ := ih _ hc exact ⟨s ∪ t, sup_union, forall_mem_union.2 ⟨hs, ht⟩⟩ end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] {a b c : α} /-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/ def InfIrred (a : α) : Prop := ¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c = a → b = a ∨ c = a /-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything bigger. -/ def InfPrime (a : α) : Prop := ¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c ≤ a → b ≤ a ∨ c ≤ a @[simp] theorem IsMax.not_infIrred (ha : IsMax a) : ¬InfIrred a := fun h => h.1 ha @[simp] theorem IsMax.not_infPrime (ha : IsMax a) : ¬InfPrime a := fun h => h.1 ha @[simp] theorem not_infIrred : ¬InfIrred a ↔ IsMax a ∨ ∃ b c, b ⊓ c = a ∧ a < b ∧ a < c := @not_supIrred αᵒᵈ _ _ @[simp] theorem not_infPrime : ¬InfPrime a ↔ IsMax a ∨ ∃ b c, b ⊓ c ≤ a ∧ ¬b ≤ a ∧ ¬c ≤ a := @not_supPrime αᵒᵈ _ _ protected theorem InfPrime.infIrred : InfPrime a → InfIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.le theorem InfPrime.inf_le (ha : InfPrime a) : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a := ⟨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_le⟩ variable [OrderTop α] {s : Finset ι} {f : ι → α} theorem not_infIrred_top : ¬InfIrred (⊤ : α) := isMax_top.not_infIrred theorem not_infPrime_top : ¬InfPrime (⊤ : α) := isMax_top.not_infPrime theorem InfIrred.ne_top (ha : InfIrred a) : a ≠ ⊤ := by rintro rfl; exact not_infIrred_top ha theorem InfPrime.ne_top (ha : InfPrime a) : a ≠ ⊤ := by rintro rfl; exact not_infPrime_top ha theorem InfIrred.finset_inf_eq : InfIrred a → s.inf f = a → ∃ i ∈ s, f i = a := @SupIrred.finset_sup_eq _ αᵒᵈ _ _ _ _ _ theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f ≤ a ↔ ∃ i ∈ s, f i ≤ a := @SupPrime.le_finset_sup _ αᵒᵈ _ _ _ _ _ ha variable [WellFoundedGT α] /-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible elements. This is the order-theoretic analogue of prime factorisation. -/ theorem exists_infIrred_decomposition (a : α) : ∃ s : Finset α, s.inf id = a ∧ ∀ ⦃b⦄, b ∈ s → InfIrred b := exists_supIrred_decomposition (α := αᵒᵈ) _ end SemilatticeInf section SemilatticeSup variable [SemilatticeSup α] @[simp] theorem infIrred_toDual {a : α} : InfIrred (toDual a) ↔ SupIrred a := Iff.rfl @[simp] theorem infPrime_toDual {a : α} : InfPrime (toDual a) ↔ SupPrime a := Iff.rfl @[simp] theorem supIrred_ofDual {a : αᵒᵈ} : SupIrred (ofDual a) ↔ InfIrred a := Iff.rfl @[simp] theorem supPrime_ofDual {a : αᵒᵈ} : SupPrime (ofDual a) ↔ InfPrime a := Iff.rfl alias ⟨_, SupIrred.dual⟩ := infIrred_toDual alias ⟨_, SupPrime.dual⟩ := infPrime_toDual alias ⟨_, InfIrred.ofDual⟩ := supIrred_ofDual alias ⟨_, InfPrime.ofDual⟩ := supPrime_ofDual end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] @[simp] theorem supIrred_toDual {a : α} : SupIrred (toDual a) ↔ InfIrred a := Iff.rfl @[simp] theorem supPrime_toDual {a : α} : SupPrime (toDual a) ↔ InfPrime a := Iff.rfl @[simp] theorem infIrred_ofDual {a : αᵒᵈ} : InfIrred (ofDual a) ↔ SupIrred a := Iff.rfl @[simp] theorem infPrime_ofDual {a : αᵒᵈ} : InfPrime (ofDual a) ↔ SupPrime a := Iff.rfl alias ⟨_, InfIrred.dual⟩ := supIrred_toDual alias ⟨_, InfPrime.dual⟩ := supPrime_toDual alias ⟨_, SupIrred.ofDual⟩ := infIrred_ofDual alias ⟨_, SupPrime.ofDual⟩ := infPrime_ofDual end SemilatticeInf section DistribLattice variable [DistribLattice α] {a : α} @[simp] theorem supPrime_iff_supIrred : SupPrime a ↔ SupIrred a := ⟨SupPrime.supIrred, And.imp_right fun h b c => by simp_rw [← inf_eq_left, inf_sup_left]; exact @h _ _⟩ @[simp] theorem infPrime_iff_infIrred : InfPrime a ↔ InfIrred a := ⟨InfPrime.infIrred, And.imp_right fun h b c => by simp_rw [← sup_eq_left, sup_inf_left]; exact @h _ _⟩ protected alias ⟨_, SupIrred.supPrime⟩ := supPrime_iff_supIrred protected alias ⟨_, InfIrred.infPrime⟩ := infPrime_iff_infIrred end DistribLattice section LinearOrder variable [LinearOrder α] {a : α} theorem supPrime_iff_not_isMin : SupPrime a ↔ ¬IsMin a := and_iff_left <| by simp theorem infPrime_iff_not_isMax : InfPrime a ↔ ¬IsMax a := and_iff_left <| by simp @[simp] theorem supIrred_iff_not_isMin : SupIrred a ↔ ¬IsMin a := and_iff_left fun _ _ => by simpa only [max_eq_iff] using Or.imp And.left And.left @[simp] theorem infIrred_iff_not_isMax : InfIrred a ↔ ¬IsMax a := and_iff_left fun _ _ => by simpa only [min_eq_iff] using Or.imp And.left And.left end LinearOrder
.lake/packages/mathlib/Mathlib/Order/SemiconjSup.lean
import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.Order.Group.End import Mathlib.Logic.Function.Conjugate import Mathlib.Order.Bounds.OrderIso import Mathlib.Order.OrdContinuous /-! # Semiconjugate by `sSup` In this file we prove two facts about semiconjugate (families of) functions. First, if an order isomorphism `fa : α → α` is semiconjugate to an order embedding `fb : β → β` by `g : α → β`, then `fb` is semiconjugate to `fa` by `y ↦ sSup {x | g x ≤ y}`, see `Semiconj.symm_adjoint`. Second, consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`, see `Function.sSup_div_semiconj`. In the case of a conditionally complete lattice, a similar statement holds true under an additional assumption that each set `{(f₁ g)⁻¹ (f₂ g x) | g : G}` is bounded above, see `Function.csSup_div_semiconj`. The lemmas come from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie bornée][ghys87:groupes], Proposition 2.1 and 5.4 respectively. In the paper they are formulated for homeomorphisms of the circle, so in order to apply results from this file one has to lift these homeomorphisms to the real line first. -/ -- Guard against import creep assert_not_exists Finset variable {α β γ : Type*} open Set /-- We say that `g : β → α` is an order right adjoint function for `f : α → β` if it sends each `y` to a least upper bound for `{x | f x ≤ y}`. If `α` is a partial order, and `f : α → β` has a right adjoint, then this right adjoint is unique. -/ def IsOrderRightAdjoint [Preorder α] [Preorder β] (f : α → β) (g : β → α) := ∀ y, IsLUB { x | f x ≤ y } (g y) theorem isOrderRightAdjoint_sSup [CompleteSemilatticeSup α] [Preorder β] (f : α → β) : IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun _ => isLUB_sSup _ theorem isOrderRightAdjoint_csSup [ConditionallyCompleteLattice α] [Preorder β] (f : α → β) (hne : ∀ y, ∃ x, f x ≤ y) (hbdd : ∀ y, BddAbove { x | f x ≤ y }) : IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun y => isLUB_csSup (hne y) (hbdd y) namespace IsOrderRightAdjoint protected theorem unique [PartialOrder α] [Preorder β] {f : α → β} {g₁ g₂ : β → α} (h₁ : IsOrderRightAdjoint f g₁) (h₂ : IsOrderRightAdjoint f g₂) : g₁ = g₂ := funext fun y => (h₁ y).unique (h₂ y) theorem right_mono [Preorder α] [Preorder β] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) : Monotone g := fun y₁ y₂ hy => ((h y₁).mono (h y₂)) fun _ hx => le_trans hx hy theorem orderIso_comp [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) (e : β ≃o γ) : IsOrderRightAdjoint (e ∘ f) (g ∘ e.symm) := fun y => by simpa [e.le_symm_apply] using h (e.symm y) theorem comp_orderIso [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) (e : γ ≃o α) : IsOrderRightAdjoint (f ∘ e) (e.symm ∘ g) := by intro y change IsLUB (e ⁻¹' { x | f x ≤ y }) (e.symm (g y)) rw [e.isLUB_preimage, e.apply_symm_apply] exact h y end IsOrderRightAdjoint namespace Function /-- If an order automorphism `fa` is semiconjugate to an order embedding `fb` by a function `g` and `g'` is an order right adjoint of `g` (i.e. `g' y = sSup {x | f x ≤ y}`), then `fb` is semiconjugate to `fa` by `g'`. This is a version of Proposition 2.1 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie bornée][ghys87:groupes]. -/ theorem Semiconj.symm_adjoint [PartialOrder α] [Preorder β] {fa : α ≃o α} {fb : β ↪o β} {g : α → β} (h : Function.Semiconj g fa fb) {g' : β → α} (hg' : IsOrderRightAdjoint g g') : Function.Semiconj g' fb fa := by refine fun y => (hg' _).unique ?_ rw [← fa.surjective.image_preimage { x | g x ≤ fb y }, preimage_setOf_eq] simp only [h.eq, fb.le_iff_le, fa.leftOrdContinuous (hg' _)] variable {G : Type*} theorem semiconj_of_isLUB [PartialOrder α] [Group G] (f₁ f₂ : G →* α ≃o α) {h : α → α} (H : ∀ x, IsLUB (range fun g' => (f₁ g')⁻¹ (f₂ g' x)) (h x)) (g : G) : Function.Semiconj h (f₂ g) (f₁ g) := by refine fun y => (H _).unique ?_ have := (f₁ g).leftOrdContinuous (H y) rw [← range_comp, ← (Equiv.mulRight g).surjective.range_comp _] at this simpa [comp_def] using this /-- Consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie bornée][ghys87:groupes]. -/ theorem sSup_div_semiconj [CompleteLattice α] [Group G] (f₁ f₂ : G →* α ≃o α) (g : G) : Function.Semiconj (fun x => ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) := semiconj_of_isLUB f₁ f₂ (fun _ => isLUB_iSup) _ /-- Consider two actions `f₁ f₂ : G → α → α` of a group on a conditionally complete lattice by order isomorphisms. Suppose that each set $s(x)=\{f_1(g)^{-1} (f_2(g)(x)) | g \in G\}$ is bounded above. Then the map `x ↦ sSup s(x)` semiconjugates each `f₁ g'` to `f₂ g'`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie bornée][ghys87:groupes]. -/ theorem csSup_div_semiconj [ConditionallyCompleteLattice α] [Group G] (f₁ f₂ : G →* α ≃o α) (hbdd : ∀ x, BddAbove (range fun g => (f₁ g)⁻¹ (f₂ g x))) (g : G) : Function.Semiconj (fun x => ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) := semiconj_of_isLUB f₁ f₂ (fun x => isLUB_csSup (range_nonempty _) (hbdd x)) _ end Function
.lake/packages/mathlib/Mathlib/Order/Nucleus.lean
import Mathlib.Order.Closure import Mathlib.Order.Hom.CompleteLattice /-! # Nucleus Locales are the dual concept to frames. Locale theory is a branch of point-free topology, where intuitively locales are like topological spaces which may or may not have enough points. Sublocales of a locale generalize the concept of subspaces in topology to the point-free setting. A nucleus is an endomorphism of a frame which corresponds to a sublocale. ## References https://ncatlab.org/nlab/show/sublocale https://ncatlab.org/nlab/show/nucleus -/ open Order InfHom Set variable {X : Type*} /-- A nucleus is an inflationary idempotent `inf`-preserving endomorphism of a semilattice. In a frame, nuclei correspond to sublocales. See `nucleusIsoSublocale`. -/ structure Nucleus (X : Type*) [SemilatticeInf X] extends InfHom X X where /-- A nucleus is idempotent. Do not use this directly. Instead use `NucleusClass.idempotent`. -/ idempotent' (x : X) : toFun (toFun x) ≤ toFun x /-- A nucleus is increasing. Do not use this directly. Instead use `NucleusClass.le_apply`. -/ le_apply' (x : X) : x ≤ toFun x /-- `NucleusClass F X` states that F is a type of nuclei. -/ class NucleusClass (F X : Type*) [SemilatticeInf X] [FunLike F X X] : Prop extends InfHomClass F X X where /-- A nucleus is idempotent. -/ idempotent (x : X) (f : F) : f (f x) ≤ f x /-- A nucleus is inflationary. -/ le_apply (x : X) (f : F) : x ≤ f x namespace Nucleus section SemilatticeInf variable [SemilatticeInf X] {n m : Nucleus X} {x y : X} instance : FunLike (Nucleus X) X X where coe x := x.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; congr! /-- See Note [custom simps projection] -/ def Simps.apply (n : Nucleus X) : X → X := n @[simp] lemma toFun_eq_coe (n : Nucleus X) : n.toFun = n := rfl @[simp] lemma coe_toInfHom (n : Nucleus X) : ⇑n.toInfHom = n := rfl @[simp] lemma coe_mk (f : InfHom X X) (h1 h2) : ⇑(mk f h1 h2) = f := rfl initialize_simps_projections Nucleus (toFun → apply) instance : NucleusClass (Nucleus X) X where idempotent _ _ := idempotent' .. le_apply _ _ := le_apply' .. map_inf _ _ _ := map_inf' .. /-- Every nucleus is a `ClosureOperator`. -/ def toClosureOperator (n : Nucleus X) : ClosureOperator X := ClosureOperator.mk' n (OrderHomClass.mono n) n.le_apply' n.idempotent' @[simp] lemma idempotent (x : X) : n (n x) = n x := n.toClosureOperator.idempotent x lemma le_apply : x ≤ n x := n.toClosureOperator.le_closure x lemma monotone : Monotone n := n.toClosureOperator.monotone lemma map_inf : n (x ⊓ y) = n x ⊓ n y := InfHomClass.map_inf n x y @[ext] lemma ext {m n : Nucleus X} (h : ∀ a, m a = n a) : m = n := DFunLike.ext m n h instance : PartialOrder (Nucleus X) := .lift (⇑) DFunLike.coe_injective @[simp, norm_cast] lemma coe_le_coe : ⇑m ≤ n ↔ m ≤ n := .rfl @[simp, norm_cast] lemma coe_lt_coe : ⇑m < n ↔ m < n := .rfl @[simp] lemma mk_le_mk (toInfHom₁ toInfHom₂ : InfHom X X) (le_apply₁ le_apply₂ idempotent₁ idempotent₂) : mk toInfHom₁ le_apply₁ idempotent₁ ≤ mk toInfHom₂ le_apply₂ idempotent₂ ↔ toInfHom₁ ≤ toInfHom₂ := .rfl @[gcongr] alias ⟨_, _root_.GCongr.Nucleus.mk_le_mk⟩ := mk_le_mk instance : Min (Nucleus X) where min m n := { toFun := m ⊓ n map_inf' x y := by simp [inf_inf_inf_comm] idempotent' x := by simp only [Pi.inf_apply, map_inf, idempotent] exact inf_le_inf inf_le_left inf_le_right le_apply' x := le_inf m.le_apply n.le_apply } @[simp, norm_cast] lemma coe_inf (m n : Nucleus X) : ⇑(m ⊓ n) = ⇑m ⊓ ⇑n := rfl @[simp] lemma inf_apply (m n : Nucleus X) (x : X) : (m ⊓ n) x = m x ⊓ n x := rfl instance : SemilatticeInf (Nucleus X) := DFunLike.coe_injective.semilatticeInf _ coe_inf /-- The smallest nucleus is the identity. -/ instance instBot : OrderBot (Nucleus X) where bot.toFun x := x bot.idempotent' := by simp bot.le_apply' := by simp bot.map_inf' := by simp bot_le n _ := n.le_apply @[simp, norm_cast] lemma coe_bot : ⇑(⊥ : Nucleus X) = id := rfl @[simp] lemma bot_apply (x : X) : (⊥ : Nucleus X) x = x := rfl variable [OrderTop X] /-- A nucleus preserves `⊤`. -/ instance : TopHomClass (Nucleus X) X X where map_top _ := eq_top_iff.mpr le_apply /-- The largest nucleus sends everything to `⊤`. -/ instance instTop : Top (Nucleus X) where top.toFun := ⊤ top.idempotent' := by simp top.le_apply' := by simp top.map_inf' := by simp @[simp, norm_cast] lemma coe_top : ⇑(⊤ : Nucleus X) = ⊤ := rfl @[simp] lemma top_apply (x : X) : (⊤ : Nucleus X) x = ⊤ := rfl instance : BoundedOrder (Nucleus X) where bot_le _ _ := le_apply le_top _ _ := by simp end SemilatticeInf section CompleteLattice variable [CompleteLattice X] instance : InfSet (Nucleus X) where sInf s := { toFun x := ⨅ f ∈ s, f x, map_inf' x y := by simp only [InfHomClass.map_inf, le_antisymm_iff, le_inf_iff, le_iInf_iff] refine ⟨⟨?_, ?_⟩, ?_⟩ <;> rintro f hf · exact iInf₂_le_of_le f hf inf_le_left · exact iInf₂_le_of_le f hf inf_le_right · exact ⟨inf_le_of_left_le <| iInf₂_le f hf, inf_le_of_right_le <| iInf₂_le f hf⟩ idempotent' x := iInf₂_mono fun f hf ↦ (f.monotone <| iInf₂_le f hf).trans_eq (f.idempotent _) le_apply' x := by simp [le_apply] } @[simp] lemma sInf_apply (s : Set (Nucleus X)) (x : X) : sInf s x = ⨅ j ∈ s, j x := rfl @[simp] lemma iInf_apply {ι : Type*} (f : ι → (Nucleus X)) (x : X) : iInf f x = ⨅ j, f j x := by rw [iInf, sInf_apply, iInf_range] instance : CompleteSemilatticeInf (Nucleus X) where sInf_le := by simp +contextual [← coe_le_coe, Pi.le_def, iInf_le_iff] le_sInf := by simp +contextual [← coe_le_coe, Pi.le_def] instance : CompleteLattice (Nucleus X) where __ : SemilatticeInf (Nucleus X) := inferInstance __ : OrderBot (Nucleus X) := inferInstance __ : OrderTop (Nucleus X) := inferInstance __ := completeLatticeOfCompleteSemilatticeInf (Nucleus X) end CompleteLattice section Frame variable [Order.Frame X] {n m : Nucleus X} {x y : X} lemma map_himp_le : n (x ⇨ y) ≤ x ⇨ n y := by rw [le_himp_iff] calc n (x ⇨ y) ⊓ x _ ≤ n (x ⇨ y) ⊓ n x := by gcongr; exact n.le_apply _ = n (y ⊓ x) := by rw [← map_inf, himp_inf_self] _ ≤ n y := by gcongr; exact inf_le_left lemma map_himp_apply (n : Nucleus X) (x y : X) : n (x ⇨ n y) = x ⇨ n y := le_antisymm (map_himp_le.trans_eq <| by rw [n.idempotent]) n.le_apply instance : HImp (Nucleus X) where himp m n := { toFun x := ⨅ y ≥ x, m y ⇨ n y idempotent' x := le_iInf₂ fun y hy ↦ calc ⨅ z ≥ ⨅ w ≥ x, m w ⇨ n w, m z ⇨ n z _ ≤ m (m y ⇨ n y) ⇨ n (m y ⇨ n y) := iInf₂_le _ <| biInf_le _ hy _ = m y ⇨ n y := by rw [map_himp_apply, himp_himp, ← map_inf, inf_of_le_right (le_trans n.le_apply le_himp)] map_inf' x y := by simp only [and_assoc, le_antisymm_iff, le_inf_iff, le_iInf_iff] refine ⟨fun z hxz ↦ iInf₂_le _ <| inf_le_of_left_le hxz, fun z hyz ↦ iInf₂_le _ <| inf_le_of_right_le hyz, ?_⟩ have : Nonempty X := ⟨x⟩ simp only [iInf_inf, le_iInf_iff, le_himp_iff, iInf_le_iff, le_inf_iff, forall_and, forall_const, and_imp] intro k hxyk l hlx hly hlk calc l = (l ⊓ m (x ⊔ k)) ⊓ (l ⊓ m (y ⊔ k)) := by rw [← inf_inf_distrib_left, ← map_inf, ← sup_inf_right, sup_eq_right.2 hxyk, inf_eq_left.2 hlk] _ ≤ n (x ⊔ k) ⊓ n (y ⊔ k) := by gcongr; exacts [hlx (x ⊔ k) le_sup_left, hly (y ⊔ k) le_sup_left] _ = n k := by rw [← map_inf, ← sup_inf_right, sup_eq_right.2 hxyk] le_apply' := by simpa using fun _ _ h ↦ inf_le_of_left_le <| h.trans n.le_apply } @[simp] lemma himp_apply (m n : Nucleus X) (x : X) : (m ⇨ n) x = ⨅ y ≥ x, m y ⇨ n y := rfl instance : HeytingAlgebra (Nucleus X) where compl m := m ⇨ ⊥ le_himp_iff _ n _ := by simpa [← coe_le_coe, Pi.le_def] using ⟨fun h i ↦ h i i le_rfl, fun h i j _ ↦ (h j).trans' <| by gcongr⟩ himp_bot m := rfl instance : Order.Frame (Nucleus X) where __ := Nucleus.instHeytingAlgebra __ := Nucleus.instCompleteLattice lemma mem_range : x ∈ range n ↔ n x = x where mp := by rintro ⟨x, rfl⟩; exact idempotent _ mpr h := ⟨x, h⟩ /-- See `Nucleus.giRestrict` for the public-facing version. -/ private def giAux (n : Nucleus X) : GaloisInsertion (rangeFactorization n) Subtype.val where choice x hx := ⟨x, mem_range.2 <| hx.antisymm n.le_apply⟩ gc x y := ClosureOperator.IsClosed.closure_le_iff (c := n.toClosureOperator) <| mem_range.1 y.2 le_l_u x := le_apply choice_eq x hx := by ext; exact le_apply.antisymm hx instance : CompleteLattice (range n) := n.giAux.liftCompleteLattice instance range.instFrameMinimalAxioms : Frame.MinimalAxioms (range n) where inf_sSup_le_iSup_inf a s := by simp_rw [← Subtype.coe_le_coe, iSup_subtype', iSup, sSup, n.giAux.gc.u_inf] rw [rangeFactorization_coe, ← mem_range.1 a.prop, ← map_inf] apply n.monotone simp_rw [inf_sSup_eq, sSup_image, iSup_range, iSup_image, iSup_subtype', n.giAux.gc.u_inf, le_rfl] instance : Frame (range n) := .ofMinimalAxioms range.instFrameMinimalAxioms /-- Restrict a nucleus to its range. -/ @[simps] def restrict (n : Nucleus X) : FrameHom X (range n) where toFun := rangeFactorization n map_inf' a b := by ext; exact map_inf map_top' := by ext; exact map_top n map_sSup' s := by rw [n.giAux.gc.l_sSup, sSup_image] /-- The restriction of a nucleus to its range forms a Galois insertion with the forgetful map from the range to the original frame. -/ def giRestrict (n : Nucleus X) : GaloisInsertion n.restrict Subtype.val := n.giAux lemma comp_eq_right_iff_le : n ∘ m = m ↔ n ≤ m where mpr h := funext_iff.mpr <| fun _ ↦ le_antisymm (le_trans (h (m _)) (m.idempotent' _)) le_apply mp h := by rw [← coe_le_coe, ← h] exact fun _ ↦ monotone le_apply @[simp] lemma range_subset_range : range m ⊆ range n ↔ n ≤ m where mp h x := by rw [← mem_range.mp (Set.range_subset_iff.mp h x)] exact n.monotone m.le_apply mpr h := range_subset_range_iff_exists_comp.mpr ⟨m, (comp_eq_right_iff_le.mpr h).symm⟩ end Frame end Nucleus
.lake/packages/mathlib/Mathlib/Order/Antisymmetrization.lean
import Mathlib.Logic.Relation import Mathlib.Order.Hom.Basic import Mathlib.Tactic.Tauto /-! # Turning a preorder into a partial order This file allows to make a preorder into a partial order by quotienting out the elements `a`, `b` such that `a ≤ b` and `b ≤ a`. `Antisymmetrization` is a functor from `Preorder` to `PartialOrder`. See `Preorder_to_PartialOrder`. ## Main declarations * `AntisymmRel`: The antisymmetrization relation. `AntisymmRel r a b` means that `a` and `b` are related both ways by `r`. * `Antisymmetrization α r`: The quotient of `α` by `AntisymmRel r`. Even when `r` is just a preorder, `Antisymmetrization α` is a partial order. -/ open Function OrderDual variable {α β : Type*} {a b c d : α} section Relation variable (r : α → α → Prop) /-- The antisymmetrization relation `AntisymmRel r` is defined so that `AntisymmRel r a b ↔ r a b ∧ r b a`. -/ def AntisymmRel (a b : α) : Prop := r a b ∧ r b a theorem antisymmRel_swap : AntisymmRel (swap r) = AntisymmRel r := funext₂ fun _ _ ↦ propext and_comm theorem antisymmRel_swap_apply : AntisymmRel (swap r) a b ↔ AntisymmRel r a b := and_comm @[simp, refl] theorem AntisymmRel.refl [IsRefl α r] (a : α) : AntisymmRel r a a := ⟨_root_.refl _, _root_.refl _⟩ variable {r} in lemma AntisymmRel.rfl [IsRefl α r] {a : α} : AntisymmRel r a a := .refl .. instance [IsRefl α r] : IsRefl α (AntisymmRel r) where refl := .refl r variable {r} theorem AntisymmRel.of_eq [IsRefl α r] {a b : α} (h : a = b) : AntisymmRel r a b := h ▸ .rfl alias Eq.antisymmRel := AntisymmRel.of_eq @[symm] theorem AntisymmRel.symm : AntisymmRel r a b → AntisymmRel r b a := And.symm instance : IsSymm α (AntisymmRel r) where symm _ _ := AntisymmRel.symm theorem antisymmRel_comm : AntisymmRel r a b ↔ AntisymmRel r b a := And.comm @[trans] theorem AntisymmRel.trans [IsTrans α r] (hab : AntisymmRel r a b) (hbc : AntisymmRel r b c) : AntisymmRel r a c := ⟨_root_.trans hab.1 hbc.1, _root_.trans hbc.2 hab.2⟩ instance [IsTrans α r] : IsTrans α (AntisymmRel r) where trans _ _ _ := .trans instance AntisymmRel.decidableRel [DecidableRel r] : DecidableRel (AntisymmRel r) := fun _ _ ↦ instDecidableAnd @[simp] theorem antisymmRel_iff_eq [IsRefl α r] [IsAntisymm α r] : AntisymmRel r a b ↔ a = b := antisymm_iff alias ⟨AntisymmRel.eq, _⟩ := antisymmRel_iff_eq namespace Mathlib.Tactic.GCongr variable {α : Type*} {a b : α} {r : α → α → Prop} lemma AntisymmRel.left (h : AntisymmRel r a b) : r a b := h.1 lemma AntisymmRel.right (h : AntisymmRel r a b) : r b a := h.2 /-- See if the term is `AntisymmRel r a b` and the goal is `r a b`. -/ @[gcongr_forward] def exactAntisymmRelLeft : ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``AntisymmRel.left #[h]) /-- See if the term is `AntisymmRel r a b` and the goal is `r b a`. -/ @[gcongr_forward] def exactAntisymmRelRight : ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``AntisymmRel.right #[h]) end Mathlib.Tactic.GCongr end Relation section LE variable [LE α] theorem AntisymmRel.le (h : AntisymmRel (· ≤ ·) a b) : a ≤ b := h.1 theorem AntisymmRel.ge (h : AntisymmRel (· ≤ ·) a b) : b ≤ a := h.2 end LE section IsPreorder variable (α) (r : α → α → Prop) [IsPreorder α r] /-- The antisymmetrization relation as an equivalence relation. -/ @[simps] def AntisymmRel.setoid : Setoid α := ⟨AntisymmRel r, .refl r, .symm, .trans⟩ /-- The partial order derived from a preorder by making pairwise comparable elements equal. This is the quotient by `fun a b => a ≤ b ∧ b ≤ a`. -/ def Antisymmetrization : Type _ := Quotient <| AntisymmRel.setoid α r variable {α} /-- Turn an element into its antisymmetrization. -/ def toAntisymmetrization : α → Antisymmetrization α r := Quotient.mk _ /-- Get a representative from the antisymmetrization. -/ noncomputable def ofAntisymmetrization : Antisymmetrization α r → α := Quotient.out instance [Inhabited α] : Inhabited (Antisymmetrization α r) := by unfold Antisymmetrization; infer_instance instance [Subsingleton α] : Subsingleton (Antisymmetrization α r) := by unfold Antisymmetrization; infer_instance @[elab_as_elim] protected theorem Antisymmetrization.ind {p : Antisymmetrization α r → Prop} : (∀ a, p <| toAntisymmetrization r a) → ∀ q, p q := Quot.ind @[elab_as_elim] protected theorem Antisymmetrization.induction_on {p : Antisymmetrization α r → Prop} (a : Antisymmetrization α r) (h : ∀ a, p <| toAntisymmetrization r a) : p a := Quotient.inductionOn' a h @[simp] theorem toAntisymmetrization_ofAntisymmetrization (a : Antisymmetrization α r) : toAntisymmetrization r (ofAntisymmetrization r a) = a := Quotient.out_eq' _ end IsPreorder section Preorder variable [Preorder α] [Preorder β] theorem le_iff_lt_or_antisymmRel : a ≤ b ↔ a < b ∨ AntisymmRel (· ≤ ·) a b := by rw [lt_iff_le_not_ge, AntisymmRel] tauto alias ⟨LE.le.lt_or_antisymmRel, _⟩ := le_iff_lt_or_antisymmRel theorem le_of_le_of_antisymmRel (h₁ : a ≤ b) (h₂ : AntisymmRel (· ≤ ·) b c) : a ≤ c := h₁.trans h₂.le theorem le_of_antisymmRel_of_le (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : b ≤ c) : a ≤ c := h₁.le.trans h₂ alias LE.le.trans_antisymmRel := le_of_le_of_antisymmRel alias AntisymmRel.trans_le := le_of_antisymmRel_of_le theorem lt_of_lt_of_antisymmRel (h₁ : a < b) (h₂ : AntisymmRel (· ≤ ·) b c) : a < c := h₁.trans_le h₂.le theorem lt_of_antisymmRel_of_lt (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : b < c) : a < c := h₁.le.trans_lt h₂ alias LT.lt.trans_antisymmRel := lt_of_lt_of_antisymmRel alias AntisymmRel.trans_lt := lt_of_antisymmRel_of_lt theorem not_lt_of_antisymmRel (h : AntisymmRel (· ≤ ·) a b) : ¬ a < b := h.ge.not_gt theorem not_gt_of_antisymmRel (h : AntisymmRel (· ≤ ·) a b) : ¬ b < a := h.le.not_gt alias AntisymmRel.not_lt := not_lt_of_antisymmRel alias AntisymmRel.not_gt := not_gt_of_antisymmRel theorem not_antisymmRel_of_lt : a < b → ¬ AntisymmRel (· ≤ ·) a b := imp_not_comm.1 not_lt_of_antisymmRel theorem not_antisymmRel_of_gt : b < a → ¬ AntisymmRel (· ≤ ·) a b := imp_not_comm.1 not_gt_of_antisymmRel alias LT.lt.not_antisymmRel := not_antisymmRel_of_lt alias LT.lt.not_antisymmRel_symm := not_antisymmRel_of_gt instance : @Trans α α α (· ≤ ·) (AntisymmRel (· ≤ ·)) (· ≤ ·) where trans := le_of_le_of_antisymmRel instance : @Trans α α α (AntisymmRel (· ≤ ·)) (· ≤ ·) (· ≤ ·) where trans := le_of_antisymmRel_of_le instance : @Trans α α α (· < ·) (AntisymmRel (· ≤ ·)) (· < ·) where trans := lt_of_lt_of_antisymmRel instance : @Trans α α α (AntisymmRel (· ≤ ·)) (· < ·) (· < ·) where trans := lt_of_antisymmRel_of_lt theorem AntisymmRel.le_congr (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) : a ≤ c ↔ b ≤ d where mp h := (h₁.symm.trans_le h).trans_antisymmRel h₂ mpr h := (h₁.trans_le h).trans_antisymmRel h₂.symm theorem AntisymmRel.le_congr_left (h : AntisymmRel (· ≤ ·) a b) : a ≤ c ↔ b ≤ c := h.le_congr .rfl theorem AntisymmRel.le_congr_right (h : AntisymmRel (· ≤ ·) b c) : a ≤ b ↔ a ≤ c := AntisymmRel.rfl.le_congr h theorem AntisymmRel.lt_congr (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) : a < c ↔ b < d where mp h := (h₁.symm.trans_lt h).trans_antisymmRel h₂ mpr h := (h₁.trans_lt h).trans_antisymmRel h₂.symm theorem AntisymmRel.lt_congr_left (h : AntisymmRel (· ≤ ·) a b) : a < c ↔ b < c := h.lt_congr .rfl theorem AntisymmRel.lt_congr_right (h : AntisymmRel (· ≤ ·) b c) : a < b ↔ a < c := AntisymmRel.rfl.lt_congr h theorem AntisymmRel.antisymmRel_congr (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) : AntisymmRel (· ≤ ·) a c ↔ AntisymmRel (· ≤ ·) b d := rel_congr h₁ h₂ theorem AntisymmRel.antisymmRel_congr_left (h : AntisymmRel (· ≤ ·) a b) : AntisymmRel (· ≤ ·) a c ↔ AntisymmRel (· ≤ ·) b c := rel_congr_left h theorem AntisymmRel.antisymmRel_congr_right (h : AntisymmRel (· ≤ ·) b c) : AntisymmRel (· ≤ ·) a b ↔ AntisymmRel (· ≤ ·) a c := rel_congr_right h theorem AntisymmRel.image (h : AntisymmRel (· ≤ ·) a b) {f : α → β} (hf : Monotone f) : AntisymmRel (· ≤ ·) (f a) (f b) := ⟨hf h.1, hf h.2⟩ instance instPartialOrderAntisymmetrization : PartialOrder (Antisymmetrization α (· ≤ ·)) where le := Quotient.lift₂ (· ≤ ·) fun (_ _ _ _ : α) h₁ h₂ => propext ⟨fun h => h₁.2.trans <| h.trans h₂.1, fun h => h₁.1.trans <| h.trans h₂.2⟩ lt := Quotient.lift₂ (· < ·) fun (_ _ _ _ : α) h₁ h₂ => propext ⟨fun h => h₁.2.trans_lt <| h.trans_le h₂.1, fun h => h₁.1.trans_lt <| h.trans_le h₂.2⟩ le_refl a := Quotient.inductionOn' a le_refl le_trans a b c := Quotient.inductionOn₃' a b c fun _ _ _ => le_trans lt_iff_le_not_ge a b := Quotient.inductionOn₂' a b fun _ _ => lt_iff_le_not_ge le_antisymm a b := Quotient.inductionOn₂' a b fun _ _ hab hba => Quotient.sound' ⟨hab, hba⟩ theorem antisymmetrization_fibration : Relation.Fibration (· < ·) (· < ·) (toAntisymmetrization (α := α) (· ≤ ·)) := by rintro a ⟨b⟩ h exact ⟨b, h, rfl⟩ theorem acc_antisymmetrization_iff : Acc (· < ·) (toAntisymmetrization (α := α) (· ≤ ·) a) ↔ Acc (· < ·) a := acc_lift₂_iff theorem wellFounded_antisymmetrization_iff : WellFounded (@LT.lt (Antisymmetrization α (· ≤ ·)) _) ↔ WellFounded (@LT.lt α _) := wellFounded_lift₂_iff theorem wellFoundedLT_antisymmetrization_iff : WellFoundedLT (Antisymmetrization α (· ≤ ·)) ↔ WellFoundedLT α := by simp_rw [isWellFounded_iff, wellFounded_antisymmetrization_iff] theorem wellFoundedGT_antisymmetrization_iff : WellFoundedGT (Antisymmetrization α (· ≤ ·)) ↔ WellFoundedGT α := by simp_rw [isWellFounded_iff] convert wellFounded_liftOn₂'_iff with ⟨_⟩ ⟨_⟩ exact fun _ _ _ _ h₁ h₂ ↦ propext ⟨fun h ↦ (h₂.2.trans_lt h).trans_le h₁.1, fun h ↦ (h₂.1.trans_lt h).trans_le h₁.2⟩ instance [WellFoundedLT α] : WellFoundedLT (Antisymmetrization α (· ≤ ·)) := wellFoundedLT_antisymmetrization_iff.mpr ‹_› instance [WellFoundedGT α] : WellFoundedGT (Antisymmetrization α (· ≤ ·)) := wellFoundedGT_antisymmetrization_iff.mpr ‹_› instance [DecidableLE α] [DecidableLT α] [IsTotal α (· ≤ ·)] : LinearOrder (Antisymmetrization α (· ≤ ·)) := { instPartialOrderAntisymmetrization with le_total := fun a b => Quotient.inductionOn₂' a b <| total_of (· ≤ ·), toDecidableLE := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance, toDecidableLT := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance } @[simp] theorem toAntisymmetrization_le_toAntisymmetrization_iff : toAntisymmetrization (α := α) (· ≤ ·) a ≤ toAntisymmetrization (α := α) (· ≤ ·) b ↔ a ≤ b := Iff.rfl @[simp] theorem toAntisymmetrization_lt_toAntisymmetrization_iff : toAntisymmetrization (α := α) (· ≤ ·) a < toAntisymmetrization (α := α) (· ≤ ·) b ↔ a < b := Iff.rfl @[simp] theorem ofAntisymmetrization_le_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} : ofAntisymmetrization (· ≤ ·) a ≤ ofAntisymmetrization (· ≤ ·) b ↔ a ≤ b := (Quotient.outRelEmbedding _).map_rel_iff @[simp] theorem ofAntisymmetrization_lt_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} : ofAntisymmetrization (· ≤ ·) a < ofAntisymmetrization (· ≤ ·) b ↔ a < b := (Quotient.outRelEmbedding _).map_rel_iff @[mono] theorem toAntisymmetrization_mono : Monotone (toAntisymmetrization (α := α) (· ≤ ·)) := fun _ _ => id open scoped Relator in private theorem liftFun_antisymmRel (f : α →o β) : ((AntisymmRel.setoid α (· ≤ ·)).r ⇒ (AntisymmRel.setoid β (· ≤ ·)).r) f f := fun _ _ h => ⟨f.mono h.1, f.mono h.2⟩ /-- Turns an order homomorphism from `α` to `β` into one from `Antisymmetrization α` to `Antisymmetrization β`. `Antisymmetrization` is actually a functor. See `Preorder_to_PartialOrder`. -/ protected def OrderHom.antisymmetrization (f : α →o β) : Antisymmetrization α (· ≤ ·) →o Antisymmetrization β (· ≤ ·) := ⟨Quotient.map' f <| liftFun_antisymmRel f, fun a b => Quotient.inductionOn₂' a b <| f.mono⟩ @[simp] theorem OrderHom.coe_antisymmetrization (f : α →o β) : ⇑f.antisymmetrization = Quotient.map' f (liftFun_antisymmRel f) := rfl theorem OrderHom.antisymmetrization_apply (f : α →o β) (a : Antisymmetrization α (· ≤ ·)) : f.antisymmetrization a = Quotient.map' f (liftFun_antisymmRel f) a := rfl @[simp] theorem OrderHom.antisymmetrization_apply_mk (f : α →o β) (a : α) : f.antisymmetrization (toAntisymmetrization _ a) = toAntisymmetrization _ (f a) := @Quotient.map_mk _ _ (_root_.id _) (_root_.id _) f (liftFun_antisymmRel f) _ variable (α) /-- `ofAntisymmetrization` as an order embedding. -/ @[simps] noncomputable def OrderEmbedding.ofAntisymmetrization : Antisymmetrization α (· ≤ ·) ↪o α := { Quotient.outRelEmbedding _ with toFun := _root_.ofAntisymmetrization _ } /-- `Antisymmetrization` and `orderDual` commute. -/ def OrderIso.dualAntisymmetrization : (Antisymmetrization α (· ≤ ·))ᵒᵈ ≃o Antisymmetrization αᵒᵈ (· ≤ ·) where toFun := (Quotient.map' id) fun _ _ => And.symm invFun := (Quotient.map' id) fun _ _ => And.symm left_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id] right_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id] map_rel_iff' := @fun a b => Quotient.inductionOn₂' a b fun _ _ => Iff.rfl @[simp] theorem OrderIso.dualAntisymmetrization_apply (a : α) : OrderIso.dualAntisymmetrization _ (toDual <| toAntisymmetrization _ a) = toAntisymmetrization _ (toDual a) := rfl @[simp] theorem OrderIso.dualAntisymmetrization_symm_apply (a : α) : (OrderIso.dualAntisymmetrization _).symm (toAntisymmetrization _ <| toDual a) = toDual (toAntisymmetrization _ a) := rfl end Preorder section Prod variable (α β) [Preorder α] [Preorder β] namespace Antisymmetrization /-- The antisymmetrization of a product preorder is order isomorphic to the product of antisymmetrizations. -/ def prodEquiv : Antisymmetrization (α × β) (· ≤ ·) ≃o Antisymmetrization α (· ≤ ·) × Antisymmetrization β (· ≤ ·) where toFun := Quotient.lift (fun ab ↦ (⟦ab.1⟧, ⟦ab.2⟧)) fun ab₁ ab₂ h ↦ Prod.ext (Quotient.sound ⟨h.1.1, h.2.1⟩) (Quotient.sound ⟨h.1.2, h.2.2⟩) invFun := Function.uncurry <| Quotient.lift₂ (fun a b ↦ ⟦(a, b)⟧) fun a₁ b₁ a₂ b₂ h₁ h₂ ↦ Quotient.sound ⟨⟨h₁.1, h₂.1⟩, h₁.2, h₂.2⟩ left_inv := by rintro ⟨_⟩; rfl right_inv := by rintro ⟨⟨_⟩, ⟨_⟩⟩; rfl map_rel_iff' := by rintro ⟨_⟩ ⟨_⟩; rfl @[simp] lemma prodEquiv_apply_mk {ab} : prodEquiv α β ⟦ab⟧ = (⟦ab.1⟧, ⟦ab.2⟧) := rfl @[simp] lemma prodEquiv_symm_apply_mk {a b} : (prodEquiv α β).symm (⟦a⟧, ⟦b⟧) = ⟦(a, b)⟧ := rfl end Antisymmetrization attribute [local instance] Prod.wellFoundedLT' Prod.wellFoundedGT' instance Prod.wellFoundedLT [WellFoundedLT α] [WellFoundedLT β] : WellFoundedLT (α × β) := wellFoundedLT_antisymmetrization_iff.mp <| (Antisymmetrization.prodEquiv α β).strictMono.wellFoundedLT instance Prod.wellFoundedGT [WellFoundedGT α] [WellFoundedGT β] : WellFoundedGT (α × β) := wellFoundedGT_antisymmetrization_iff.mp <| (Antisymmetrization.prodEquiv α β).strictMono.wellFoundedGT end Prod
.lake/packages/mathlib/Mathlib/Order/BooleanSubalgebra.lean
import Mathlib.Order.Sublattice /-! # Boolean subalgebras This file defines Boolean subalgebras. -/ open Function Set variable {ι : Sort*} {α β γ : Type*} variable (α) in /-- A Boolean subalgebra of a Boolean algebra is a set containing the bottom and top elements, and closed under suprema, infima and complements. -/ structure BooleanSubalgebra [BooleanAlgebra α] extends Sublattice α where compl_mem' {a} : a ∈ carrier → aᶜ ∈ carrier bot_mem' : ⊥ ∈ carrier namespace BooleanSubalgebra section BooleanAlgebra variable [BooleanAlgebra α] [BooleanAlgebra β] [BooleanAlgebra γ] {L M : BooleanSubalgebra α} {f : BoundedLatticeHom α β} {s t : Set α} {a b : α} initialize_simps_projections BooleanSubalgebra (carrier → coe, as_prefix coe) instance instSetLike : SetLike (BooleanSubalgebra α) α where coe L := L.carrier coe_injective' L M h := by obtain ⟨⟨_, _⟩, _⟩ := L; congr lemma coe_inj : (L : Set α) = M ↔ L = M := SetLike.coe_set_eq @[simp] lemma supClosed (L : BooleanSubalgebra α) : SupClosed (L : Set α) := L.supClosed' @[simp] lemma infClosed (L : BooleanSubalgebra α) : InfClosed (L : Set α) := L.infClosed' lemma compl_mem (ha : a ∈ L) : aᶜ ∈ L := L.compl_mem' ha @[simp] lemma compl_mem_iff : aᶜ ∈ L ↔ a ∈ L := ⟨fun ha ↦ by simpa using compl_mem ha, compl_mem⟩ @[simp] lemma bot_mem : ⊥ ∈ L := L.bot_mem' @[simp] lemma top_mem : ⊤ ∈ L := by simpa using compl_mem L.bot_mem lemma sup_mem (ha : a ∈ L) (hb : b ∈ L) : a ⊔ b ∈ L := L.supClosed ha hb lemma inf_mem (ha : a ∈ L) (hb : b ∈ L) : a ⊓ b ∈ L := L.infClosed ha hb lemma sdiff_mem (ha : a ∈ L) (hb : b ∈ L) : a \ b ∈ L := by simpa [sdiff_eq] using L.infClosed ha (compl_mem hb) lemma himp_mem (ha : a ∈ L) (hb : b ∈ L) : a ⇨ b ∈ L := by simpa [himp_eq] using L.supClosed hb (compl_mem ha) lemma mem_carrier : a ∈ L.carrier ↔ a ∈ L := .rfl @[simp] lemma mem_toSublattice : a ∈ L.toSublattice ↔ a ∈ L := .rfl @[simp] lemma mem_mk {L : Sublattice α} (h_compl h_bot) : a ∈ mk L h_compl h_bot ↔ a ∈ L := .rfl @[simp] lemma coe_mk (L : Sublattice α) (h_compl h_bot) : (mk L h_compl h_bot : Set α) = L := rfl @[simp] lemma mk_le_mk {L M : Sublattice α} (hL_compl hL_bot hM_compl hM_bot) : mk L hL_compl hL_bot ≤ mk M hM_compl hM_bot ↔ L ≤ M := .rfl @[simp] lemma mk_lt_mk {L M : Sublattice α} (hL_compl hL_bot hM_compl hM_bot) : mk L hL_compl hL_bot < mk M hM_compl hM_bot ↔ L < M := .rfl /-- Copy of a Boolean subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (L : BooleanSubalgebra α) (s : Set α) (hs : s = L) : BooleanSubalgebra α where toSublattice := L.toSublattice.copy s <| by subst hs; rfl compl_mem' := by subst hs; exact L.compl_mem' bot_mem' := by subst hs; exact L.bot_mem' @[simp, norm_cast] lemma coe_copy (L : BooleanSubalgebra α) (s : Set α) (hs) : L.copy s hs = s := rfl lemma copy_eq (L : BooleanSubalgebra α) (s : Set α) (hs) : L.copy s hs = L := SetLike.coe_injective hs /-- Two Boolean subalgebras are equal if they have the same elements. -/ lemma ext : (∀ a, a ∈ L ↔ a ∈ M) → L = M := SetLike.ext /-- A Boolean subalgebra of a lattice inherits a bottom element. -/ instance instBotCoe : Bot L where bot := ⟨⊥, bot_mem⟩ /-- A Boolean subalgebra of a lattice inherits a top element. -/ instance instTopCoe : Top L where top := ⟨⊤, top_mem⟩ /-- A Boolean subalgebra of a lattice inherits a supremum. -/ instance instSupCoe : Max L where max a b := ⟨a ⊔ b, L.supClosed a.2 b.2⟩ /-- A Boolean subalgebra of a lattice inherits an infimum. -/ instance instInfCoe : Min L where min a b := ⟨a ⊓ b, L.infClosed a.2 b.2⟩ /-- A Boolean subalgebra of a lattice inherits a complement. -/ instance instHasComplCoe : HasCompl L where compl a := ⟨aᶜ, compl_mem a.2⟩ /-- A Boolean subalgebra of a lattice inherits a difference. -/ instance instSDiffCoe : SDiff L where sdiff a b := ⟨a \ b, sdiff_mem a.2 b.2⟩ /-- A Boolean subalgebra of a lattice inherits a Heyting implication. -/ instance instHImpCoe : HImp L where himp a b := ⟨a ⇨ b, himp_mem a.2 b.2⟩ @[simp, norm_cast] lemma val_bot : (⊥ : L) = (⊥ : α) := rfl @[simp, norm_cast] lemma val_top : (⊤ : L) = (⊤ : α) := rfl @[simp, norm_cast] lemma val_sup (a b : L) : a ⊔ b = (a : α) ⊔ b := rfl @[simp, norm_cast] lemma val_inf (a b : L) : a ⊓ b = (a : α) ⊓ b := rfl @[simp, norm_cast] lemma val_compl (a : L) : aᶜ = (a : α)ᶜ := rfl @[simp, norm_cast] lemma val_sdiff (a b : L) : a \ b = (a : α) \ b := rfl @[simp, norm_cast] lemma val_himp (a b : L) : a ⇨ b = (a : α) ⇨ b := rfl @[simp] lemma mk_bot : (⟨⊥, bot_mem⟩ : L) = ⊥ := rfl @[simp] lemma mk_top : (⟨⊤, top_mem⟩ : L) = ⊤ := rfl @[simp] lemma mk_sup_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊔ ⟨b, hb⟩ : L) = ⟨a ⊔ b, L.supClosed ha hb⟩ := rfl @[simp] lemma mk_inf_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊓ ⟨b, hb⟩ : L) = ⟨a ⊓ b, L.infClosed ha hb⟩ := rfl @[simp] lemma compl_mk (a : α) (ha) : (⟨a, ha⟩ : L)ᶜ = ⟨aᶜ, compl_mem ha⟩ := rfl @[simp] lemma mk_sdiff_mk (a b : α) (ha hb) : (⟨a, ha⟩ \ ⟨b, hb⟩ : L) = ⟨a \ b, sdiff_mem ha hb⟩ := rfl @[simp] lemma mk_himp_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⇨ ⟨b, hb⟩ : L) = ⟨a ⇨ b, himp_mem ha hb⟩ := rfl /-- A Boolean subalgebra of a lattice inherits a Boolean algebra structure. -/ instance instBooleanAlgebraCoe (L : BooleanSubalgebra α) : BooleanAlgebra L := Subtype.coe_injective.booleanAlgebra _ val_sup val_inf val_top val_bot val_compl val_sdiff val_himp /-- The natural lattice hom from a Boolean subalgebra to the original lattice. -/ def subtype (L : BooleanSubalgebra α) : BoundedLatticeHom L α where toFun := ((↑) : L → α) map_bot' := L.val_bot map_top' := L.val_top map_sup' := val_sup map_inf' := val_inf @[simp, norm_cast] lemma coe_subtype (L : BooleanSubalgebra α) : L.subtype = ((↑) : L → α) := rfl lemma subtype_apply (L : BooleanSubalgebra α) (a : L) : L.subtype a = a := rfl lemma subtype_injective (L : BooleanSubalgebra α) : Injective <| subtype L := Subtype.coe_injective /-- The inclusion homomorphism from a Boolean subalgebra `L` to a bigger Boolean subalgebra `M`. -/ def inclusion (h : L ≤ M) : BoundedLatticeHom L M where toFun := Set.inclusion h map_bot' := rfl map_top' := rfl map_sup' _ _ := rfl map_inf' _ _ := rfl @[simp] lemma coe_inclusion (h : L ≤ M) : inclusion h = Set.inclusion h := rfl lemma inclusion_apply (h : L ≤ M) (a : L) : inclusion h a = Set.inclusion h a := rfl lemma inclusion_injective (h : L ≤ M) : Injective <| inclusion h := Set.inclusion_injective h @[simp] lemma inclusion_rfl (L : BooleanSubalgebra α) : inclusion le_rfl = .id L := rfl @[simp] lemma subtype_comp_inclusion (h : L ≤ M) : M.subtype.comp (inclusion h) = L.subtype := rfl /-- The maximum Boolean subalgebra of a lattice. -/ instance instTop : Top (BooleanSubalgebra α) where top.carrier := univ top.bot_mem' := mem_univ _ top.compl_mem' _ := mem_univ _ top.supClosed' := supClosed_univ top.infClosed' := infClosed_univ /-- The trivial Boolean subalgebra of a lattice. -/ instance instBot : Bot (BooleanSubalgebra α) where bot.carrier := {⊥, ⊤} bot.bot_mem' := by simp bot.compl_mem' := by simp bot.supClosed' _ := by simp bot.infClosed' _ := by simp /-- The inf of two Boolean subalgebras is their intersection. -/ instance instInf : Min (BooleanSubalgebra α) where min L M := { carrier := L ∩ M bot_mem' := ⟨bot_mem, bot_mem⟩ compl_mem' := fun ha ↦ ⟨compl_mem ha.1, compl_mem ha.2⟩ supClosed' := L.supClosed.inter M.supClosed infClosed' := L.infClosed.inter M.infClosed } /-- The inf of Boolean subalgebras is their intersection. -/ instance instInfSet : InfSet (BooleanSubalgebra α) where sInf S := { carrier := ⋂ L ∈ S, L bot_mem' := mem_iInter₂.2 fun _ _ ↦ bot_mem compl_mem' := fun ha ↦ mem_iInter₂.2 fun L hL ↦ compl_mem <| mem_iInter₂.1 ha L hL supClosed' := supClosed_sInter <| forall_mem_range.2 fun L ↦ supClosed_sInter <| forall_mem_range.2 fun _ ↦ L.supClosed infClosed' := infClosed_sInter <| forall_mem_range.2 fun L ↦ infClosed_sInter <| forall_mem_range.2 fun _ ↦ L.infClosed } instance instInhabited : Inhabited (BooleanSubalgebra α) := ⟨⊥⟩ /-- The top Boolean subalgebra is isomorphic to the original Boolean algebra. This is the Boolean subalgebra version of `Equiv.Set.univ α`. -/ def topEquiv : (⊤ : BooleanSubalgebra α) ≃o α where toEquiv := Equiv.Set.univ _ map_rel_iff' := .rfl @[simp, norm_cast] lemma coe_top : (⊤ : BooleanSubalgebra α) = (univ : Set α) := rfl @[simp, norm_cast] lemma coe_bot : (⊥ : BooleanSubalgebra α) = ({⊥, ⊤} : Set α) := rfl @[simp, norm_cast] lemma coe_inf (L M : BooleanSubalgebra α) : L ⊓ M = (L : Set α) ∩ M := rfl @[simp, norm_cast] lemma coe_sInf (S : Set (BooleanSubalgebra α)) : sInf S = ⋂ L ∈ S, (L : Set α) := rfl @[simp, norm_cast] lemma coe_iInf (f : ι → BooleanSubalgebra α) : ⨅ i, f i = ⋂ i, (f i : Set α) := by simp [iInf] @[simp, norm_cast] lemma coe_eq_univ : L = (univ : Set α) ↔ L = ⊤ := by rw [← coe_top, coe_inj] @[simp] lemma mem_bot : a ∈ (⊥ : BooleanSubalgebra α) ↔ a = ⊥ ∨ a = ⊤ := .rfl @[simp] lemma mem_top : a ∈ (⊤ : BooleanSubalgebra α) := mem_univ _ @[simp] lemma mem_inf : a ∈ L ⊓ M ↔ a ∈ L ∧ a ∈ M := .rfl @[simp] lemma mem_sInf {S : Set (BooleanSubalgebra α)} : a ∈ sInf S ↔ ∀ L ∈ S, a ∈ L := by rw [← SetLike.mem_coe]; simp @[simp] lemma mem_iInf {f : ι → BooleanSubalgebra α} : a ∈ ⨅ i, f i ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe]; simp /-- BooleanSubalgebras of a lattice form a complete lattice. -/ instance instCompleteLattice : CompleteLattice (BooleanSubalgebra α) where bot := ⊥ bot_le _S _a := by aesop top := ⊤ le_top _S a _ha := mem_top inf := (· ⊓ ·) le_inf _L _M _N hM hN _a ha := ⟨hM ha, hN ha⟩ inf_le_left _L _M _a := And.left inf_le_right _L _M _a := And.right __ := completeLatticeOfInf (BooleanSubalgebra α) fun _s ↦ IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf instance [IsEmpty α] : Subsingleton (BooleanSubalgebra α) := SetLike.coe_injective.subsingleton instance [IsEmpty α] : Unique (BooleanSubalgebra α) := uniqueOfSubsingleton ⊤ /-- The preimage of a Boolean subalgebra along a bounded lattice homomorphism. -/ def comap (f : BoundedLatticeHom α β) (L : BooleanSubalgebra β) : BooleanSubalgebra α where carrier := f ⁻¹' L bot_mem' := by simp compl_mem' := by simp [map_compl'] supClosed' := L.supClosed.preimage _ infClosed' := L.infClosed.preimage _ @[simp, norm_cast] lemma coe_comap (L : BooleanSubalgebra β) (f : BoundedLatticeHom α β) : L.comap f = f ⁻¹' L := rfl @[simp] lemma mem_comap {L : BooleanSubalgebra β} : a ∈ L.comap f ↔ f a ∈ L := .rfl lemma comap_mono : Monotone (comap f) := fun _ _ ↦ preimage_mono @[simp] lemma comap_id (L : BooleanSubalgebra α) : L.comap (BoundedLatticeHom.id _) = L := rfl @[simp] lemma comap_comap (L : BooleanSubalgebra γ) (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) : (L.comap g).comap f = L.comap (g.comp f) := rfl /-- The image of a Boolean subalgebra along a monoid homomorphism is a Boolean subalgebra. -/ def map (f : BoundedLatticeHom α β) (L : BooleanSubalgebra α) : BooleanSubalgebra β where carrier := f '' L bot_mem' := ⟨⊥, by simp⟩ compl_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨aᶜ, by simpa [map_compl']⟩ supClosed' := L.supClosed.image f infClosed' := L.infClosed.image f @[simp] lemma coe_map (f : BoundedLatticeHom α β) (L : BooleanSubalgebra α) : (L.map f : Set β) = f '' L := rfl @[simp] lemma mem_map {b : β} : b ∈ L.map f ↔ ∃ a ∈ L, f a = b := .rfl lemma mem_map_of_mem (f : BoundedLatticeHom α β) {a : α} : a ∈ L → f a ∈ L.map f := mem_image_of_mem f lemma apply_coe_mem_map (f : BoundedLatticeHom α β) (a : L) : f a ∈ L.map f := mem_map_of_mem f a.prop lemma map_mono : Monotone (map f) := fun _ _ ↦ image_mono @[simp] lemma map_id : L.map (.id α) = L := SetLike.coe_injective <| image_id _ @[simp] lemma map_map (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) : (L.map f).map g = L.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ lemma mem_map_equiv {f : α ≃o β} {a : β} : a ∈ L.map f ↔ f.symm a ∈ L := Set.mem_image_equiv lemma apply_mem_map_iff (hf : Injective f) : f a ∈ L.map f ↔ a ∈ L := hf.mem_set_image lemma map_equiv_eq_comap_symm (f : α ≃o β) (L : BooleanSubalgebra α) : L.map f = L.comap (f.symm : BoundedLatticeHom β α) := SetLike.coe_injective <| f.toEquiv.image_eq_preimage_symm L lemma comap_equiv_eq_map_symm (f : β ≃o α) (L : BooleanSubalgebra α) : L.comap f = L.map (f.symm : BoundedLatticeHom α β) := (map_equiv_eq_comap_symm f.symm L).symm lemma map_symm_eq_iff_eq_map {M : BooleanSubalgebra β} {e : β ≃o α} : L.map ↑e.symm = M ↔ L = M.map ↑e := by simp_rw [← coe_inj]; exact (Equiv.eq_image_iff_symm_image_eq _ _ _).symm lemma map_le_iff_le_comap {f : BoundedLatticeHom α β} {M : BooleanSubalgebra β} : L.map f ≤ M ↔ L ≤ M.comap f := image_subset_iff lemma gc_map_comap (f : BoundedLatticeHom α β) : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap @[simp] lemma map_bot (f : BoundedLatticeHom α β) : (⊥ : BooleanSubalgebra α).map f = ⊥ := (gc_map_comap f).l_bot lemma map_sup (f : BoundedLatticeHom α β) (L M : BooleanSubalgebra α) : (L ⊔ M).map f = L.map f ⊔ M.map f := (gc_map_comap f).l_sup lemma map_iSup (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra α) : (⨆ i, L i).map f = ⨆ i, (L i).map f := (gc_map_comap f).l_iSup @[simp] lemma comap_top (f : BoundedLatticeHom α β) : (⊤ : BooleanSubalgebra β).comap f = ⊤ := (gc_map_comap f).u_top lemma comap_inf (L M : BooleanSubalgebra β) (f : BoundedLatticeHom α β) : (L ⊓ M).comap f = L.comap f ⊓ M.comap f := (gc_map_comap f).u_inf lemma comap_iInf (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra β) : (⨅ i, L i).comap f = ⨅ i, (L i).comap f := (gc_map_comap f).u_iInf lemma map_inf_le (L M : BooleanSubalgebra α) (f : BoundedLatticeHom α β) : map f (L ⊓ M) ≤ map f L ⊓ map f M := map_mono.map_inf_le _ _ lemma le_comap_sup (L M : BooleanSubalgebra β) (f : BoundedLatticeHom α β) : comap f L ⊔ comap f M ≤ comap f (L ⊔ M) := comap_mono.le_map_sup _ _ lemma le_comap_iSup (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra β) : ⨆ i, (L i).comap f ≤ (⨆ i, L i).comap f := comap_mono.le_map_iSup lemma map_inf (L M : BooleanSubalgebra α) (f : BoundedLatticeHom α β) (hf : Injective f) : map f (L ⊓ M) = map f L ⊓ map f M := by rw [← SetLike.coe_set_eq] simp [Set.image_inter hf] lemma map_top (f : BoundedLatticeHom α β) (h : Surjective f) : BooleanSubalgebra.map f ⊤ = ⊤ := SetLike.coe_injective <| by simp [h.range_eq] /-- The minimum Boolean subalgebra containing a given set. -/ def closure (s : Set α) : BooleanSubalgebra α := sInf {L | s ⊆ L} variable {s : Set α} lemma mem_closure {x : α} : x ∈ closure s ↔ ∀ ⦃L : BooleanSubalgebra α⦄, s ⊆ L → x ∈ L := mem_sInf @[simp, aesop safe 20 (rule_sets := [SetLike])] lemma subset_closure : s ⊆ closure s := fun _ hx ↦ mem_closure.2 fun _ hK ↦ hK hx @[aesop 80% (rule_sets := [SetLike])] theorem mem_closure_of_mem {s : Set α} {x : α} (hx : x ∈ s) : x ∈ closure s := subset_closure hx @[simp] lemma closure_le : closure s ≤ L ↔ s ⊆ L := ⟨subset_closure.trans, fun h ↦ sInf_le h⟩ lemma closure_mono (hst : s ⊆ t) : closure s ≤ closure t := sInf_le_sInf fun _L ↦ hst.trans lemma latticeClosure_subset_closure : latticeClosure s ⊆ closure s := latticeClosure_min subset_closure (closure s).isSublattice @[simp] lemma closure_latticeClosure (s : Set α) : closure (latticeClosure s) = closure s := le_antisymm (closure_le.2 latticeClosure_subset_closure) (closure_mono subset_latticeClosure) /-- An induction principle for closure membership. If `p` holds for `⊥` and all elements of `s`, and is preserved under suprema and complement, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] lemma closure_bot_sup_induction {p : ∀ g ∈ closure s, Prop} (mem : ∀ x hx, p x (subset_closure hx)) (bot : p ⊥ bot_mem) (sup : ∀ x hx y hy, p x hx → p y hy → p (x ⊔ y) (supClosed _ hx hy)) (compl : ∀ x hx, p x hx → p xᶜ (compl_mem hx)) {x} (hx : x ∈ closure s) : p x hx := have inf ⦃x hx y hy⦄ (hx' : p x hx) (hy' : p y hy) : p (x ⊓ y) (infClosed _ hx hy) := by simpa using compl _ _ <| sup _ _ _ _ (compl _ _ hx') (compl _ _ hy') let L : BooleanSubalgebra α := { carrier := { x | ∃ hx, p x hx } supClosed' := fun _a ⟨_, ha⟩ _b ⟨_, hb⟩ ↦ ⟨_, sup _ _ _ _ ha hb⟩ infClosed' := fun _a ⟨_, ha⟩ _b ⟨_, hb⟩ ↦ ⟨_, inf ha hb⟩ bot_mem' := ⟨_, bot⟩ compl_mem' := fun ⟨_, hb⟩ ↦ ⟨_, compl _ _ hb⟩ } closure_le (L := L).mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id section sdiff_sup variable (isSublattice : IsSublattice s) (bot_mem : ⊥ ∈ s) (top_mem : ⊤ ∈ s) include isSublattice bot_mem top_mem theorem mem_closure_iff_sup_sdiff {a : α} : a ∈ closure s ↔ ∃ t : Finset (s × s), a = t.sup fun x ↦ x.1.1 \ x.2.1 := by classical refine ⟨closure_bot_sup_induction (fun x h ↦ ⟨{(⟨x, h⟩, ⟨⊥, bot_mem⟩)}, by simp⟩) ⟨∅, by simp⟩ ?_ ?_, ?_⟩ · rintro ⟨t, rfl⟩ exact t.sup_mem _ (subset_closure bot_mem) (fun _ h _ ↦ sup_mem h) _ fun x hx ↦ sdiff_mem (subset_closure x.1.2) (subset_closure x.2.2) · rintro _ - _ - ⟨t₁, rfl⟩ ⟨t₂, rfl⟩ exact ⟨t₁ ∪ t₂, by rw [Finset.sup_union]⟩ rintro x - ⟨t, rfl⟩ refine t.induction ⟨{(⟨⊤, top_mem⟩, ⟨⊥, bot_mem⟩)}, by simp⟩ fun ⟨x, y⟩ t _ ⟨tc, eq⟩ ↦ ?_ simp_rw [Finset.sup_insert, compl_sup, eq] refine tc.induction ⟨∅, by simp⟩ fun ⟨z, w⟩ tc _ ⟨t, eq⟩ ↦ ?_ simp_rw [Finset.sup_insert, inf_sup_left, eq] use {(z, ⟨_, isSublattice.supClosed x.2 w.2⟩), (⟨_, isSublattice.infClosed y.2 z.2⟩, w)} ∪ t simp_rw [Finset.sup_union, Finset.sup_insert, Finset.sup_singleton, sdiff_eq, compl_sup, inf_left_comm z.1, compl_inf, compl_compl, inf_sup_right, inf_assoc] @[elab_as_elim] theorem closure_sdiff_sup_induction {p : ∀ g ∈ closure s, Prop} (sdiff : ∀ x hx y hy, p (x \ y) (sdiff_mem (subset_closure hx) (subset_closure hy))) (sup : ∀ x hx y hy, p x hx → p y hy → p (x ⊔ y) (sup_mem hx hy)) (x) (hx : x ∈ closure s) : p x hx := by obtain ⟨t, rfl⟩ := (mem_closure_iff_sup_sdiff isSublattice bot_mem top_mem).mp hx revert hx classical refine t.induction (by simpa using sdiff _ bot_mem _ bot_mem) fun x t _ ih hxt ↦ ?_ simp only [Finset.sup_insert] at hxt ⊢ exact sup _ _ _ ((mem_closure_iff_sup_sdiff isSublattice bot_mem top_mem).mpr ⟨_, rfl⟩) (sdiff _ x.1.2 _ x.2.2) (ih _) end sdiff_sup end BooleanAlgebra section CompleteBooleanAlgebra variable [CompleteBooleanAlgebra α] {L : BooleanSubalgebra α} {f : ι → α} {s : Set α} lemma iSup_mem [Finite ι] (hf : ∀ i, f i ∈ L) : ⨆ i, f i ∈ L := L.supClosed.iSup_mem bot_mem hf lemma iInf_mem [Finite ι] (hf : ∀ i, f i ∈ L) : ⨅ i, f i ∈ L := L.infClosed.iInf_mem top_mem hf lemma sSup_mem (hs : s.Finite) (hsL : s ⊆ L) : sSup s ∈ L := L.supClosed.sSup_mem hs bot_mem hsL lemma sInf_mem (hs : s.Finite) (hsL : s ⊆ L) : sInf s ∈ L := L.infClosed.sInf_mem hs top_mem hsL lemma biSup_mem {ι : Type*} {t : Set ι} {f : ι → α} (ht : t.Finite) (hf : ∀ i ∈ t, f i ∈ L) : ⨆ i ∈ t, f i ∈ L := L.supClosed.biSup_mem ht bot_mem hf lemma biInf_mem {ι : Type*} {t : Set ι} {f : ι → α} (ht : t.Finite) (hf : ∀ i ∈ t, f i ∈ L) : ⨅ i ∈ t, f i ∈ L := L.infClosed.biInf_mem ht top_mem hf end CompleteBooleanAlgebra end BooleanSubalgebra
.lake/packages/mathlib/Mathlib/Order/Lattice.lean
import Mathlib.Data.Bool.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift /-! # (Semi-)lattices Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `SemilatticeSup`: a type class for join semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is commutative, associative and idempotent. * `SemilatticeInf`: a type class for meet semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is commutative, associative and idempotent. * `Lattice`: a type class for lattices * `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `DistribLattice`: a type class for distributive lattices. ## Notation * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ universe u v w variable {α : Type u} {β : Type v} /-! ### Join-semilattices -/ -- TODO: automatic construction of dual definitions / theorems /-- A `SemilatticeSup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class SemilatticeSup (α : Type u) extends PartialOrder α where /-- The binary supremum, used to derive `Max α` -/ sup : α → α → α /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ sup a b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ sup a b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) : SemilatticeSup α where sup := (· ⊔ ·) le a b := a ⊔ b = b le_refl := sup_idem le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by rw [← sup_assoc, sup_idem] le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by rwa [sup_assoc, hbc] section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias ⟨_, sup_of_le_left⟩ := sup_eq_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a := le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := h.not_le_or_not_ge.symm.imp left_lt_sup.2 right_lt_sup.2 theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by constructor · intro h exact ⟨b, (sup_eq_right.mpr h).symm⟩ · rintro ⟨c, rfl : _ = _ ⊔ _⟩ exact le_sup_left @[gcongr] theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂) theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup le_rfl h₁ theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ le_rfl theorem sup_idem (a : α) : a ⊔ a = a := by simp instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩ theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩ theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc] instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩ theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by rw [sup_comm, sup_comm a, sup_assoc] theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by rw [sup_assoc, sup_assoc, sup_comm b] theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by rw [sup_assoc, sup_left_comm b, ← sup_assoc] theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c := (sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c := (sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b := ⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩ theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := ⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩ theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := hab.symm.not_le_or_not_ge.imp left_lt_sup.2 right_lt_sup.2 /-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/ theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f) (hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n := calc f m ≤ f (m ⊔ n) := hf le_sup_left _ ≤ g (m ⊔ n) := h _ _ ≤ g n := hg le_sup_right theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) (x y : α) : (haveI := A; x ⊔ y) = x ⊔ y := eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases PartialOrder.ext H congr ext; apply SemilatticeSup.ext_sup H theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' := if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right end SemilatticeSup /-! ### Meet-semilattices -/ /-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class SemilatticeInf (α : Type u) extends PartialOrder α where /-- The binary infimum, used to derive `Min α` -/ inf : α → α → α /-- The infimum is a lower bound on the first argument -/ protected inf_le_left : ∀ a b : α, inf a b ≤ a /-- The infimum is a lower bound on the second argument -/ protected inf_le_right : ∀ a b : α, inf a b ≤ b /-- The infimum is the *greatest* lower bound -/ protected le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ inf b c instance SemilatticeInf.toMin [SemilatticeInf α] : Min α where min a b := SemilatticeInf.inf a b instance OrderDual.instSemilatticeSup (α) [SemilatticeInf α] : SemilatticeSup αᵒᵈ where sup := @SemilatticeInf.inf α _ le_sup_left := @SemilatticeInf.inf_le_left α _ le_sup_right := @SemilatticeInf.inf_le_right α _ sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf α _ _ _ _ hca hcb instance OrderDual.instSemilatticeInf (α) [SemilatticeSup α] : SemilatticeInf αᵒᵈ where inf := @SemilatticeSup.sup α _ inf_le_left := @le_sup_left α _ inf_le_right := @le_sup_right α _ le_inf := fun _ _ _ hca hcb => @sup_le α _ _ _ _ hca hcb theorem SemilatticeSup.dual_dual (α : Type*) [H : SemilatticeSup α] : OrderDual.instSemilatticeSup αᵒᵈ = H := SemilatticeSup.ext fun _ _ => Iff.rfl section SemilatticeInf variable [SemilatticeInf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := SemilatticeInf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := SemilatticeInf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := SemilatticeInf.le_inf a b c theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_left h theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := @sup_le_iff αᵒᵈ _ _ _ _ @[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans <| by simp @[simp] theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans <| by simp @[simp] theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right alias ⟨le_of_inf_eq, inf_of_le_left⟩ := inf_eq_left alias ⟨_, inf_of_le_right⟩ := inf_eq_right attribute [simp] inf_of_le_left inf_of_le_right @[simp] theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b := @left_lt_sup αᵒᵈ _ _ _ @[simp] theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a := @right_lt_sup αᵒᵈ _ _ _ theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b := @left_or_right_lt_sup αᵒᵈ _ _ _ h @[gcongr] theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := @sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂ theorem inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h le_rfl theorem inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf le_rfl h theorem inf_idem (a : α) : a ⊓ a = a := by simp instance : Std.IdempotentOp (α := α) (· ⊓ ·) := ⟨inf_idem⟩ theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _ instance : Std.Commutative (α := α) (· ⊓ ·) := ⟨inf_comm⟩ theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ _ _ _ instance : Std.Associative (α := α) (· ⊓ ·) := ⟨inf_assoc⟩ theorem inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a := @sup_left_right_swap αᵒᵈ _ _ _ _ theorem inf_left_idem (a b : α) : a ⊓ (a ⊓ b) = a ⊓ b := by simp theorem inf_right_idem (a b : α) : a ⊓ b ⊓ b = a ⊓ b := by simp theorem inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := @sup_left_comm αᵒᵈ _ a b c theorem inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b := @sup_right_comm αᵒᵈ _ a b c theorem inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) := @sup_sup_sup_comm αᵒᵈ _ _ _ _ _ theorem inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = a ⊓ b ⊓ (a ⊓ c) := @sup_sup_distrib_left αᵒᵈ _ _ _ _ theorem inf_inf_distrib_right (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ (b ⊓ c) := @sup_sup_distrib_right αᵒᵈ _ _ _ _ theorem inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c := @sup_congr_left αᵒᵈ _ _ _ _ hb hc theorem inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c := @sup_congr_right αᵒᵈ _ _ _ _ h1 h2 theorem inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c := @sup_eq_sup_iff_left αᵒᵈ _ _ _ _ theorem inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b := @sup_eq_sup_iff_right αᵒᵈ _ _ _ _ theorem Ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b := @Ne.lt_sup_or_lt_sup αᵒᵈ _ _ _ theorem SemilatticeInf.ext_inf {α} {A B : SemilatticeInf α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) (x y : α) : (haveI := A; x ⊓ y) = x ⊓ y := eq_of_forall_le_iff fun c => by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem SemilatticeInf.ext {α} {A B : SemilatticeInf α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases PartialOrder.ext H congr ext; apply SemilatticeInf.ext_inf H theorem SemilatticeInf.dual_dual (α : Type*) [H : SemilatticeInf α] : OrderDual.instSemilatticeInf αᵒᵈ = H := SemilatticeInf.ext fun _ _ => Iff.rfl theorem inf_le_ite (s s' : α) (P : Prop) [Decidable P] : s ⊓ s' ≤ ite P s s' := @ite_le_sup αᵒᵈ _ _ _ _ _ end SemilatticeInf /-- A type with a commutative, associative and idempotent binary `inf` operation has the structure of a meet-semilattice. The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`. -/ def SemilatticeInf.mk' {α : Type*} [Min α] (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a) (inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) : SemilatticeInf α := by haveI : SemilatticeSup αᵒᵈ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem haveI i := OrderDual.instSemilatticeInf αᵒᵈ exact i /-! ### Lattices -/ /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ class Lattice (α : Type u) extends SemilatticeSup α, SemilatticeInf α instance OrderDual.instLattice (α) [Lattice α] : Lattice αᵒᵈ where /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`) and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/ theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder {α : Type*} [Max α] [Min α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a) (inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) (sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a) (inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) : @SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) = @SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) := PartialOrder.ext fun a b => show a ⊔ b = b ↔ b ⊓ a = a from ⟨fun h => by rw [← h, inf_comm, inf_sup_self], fun h => by rw [← h, sup_comm, sup_inf_self]⟩ /-- A type with a pair of commutative and associative binary operations which satisfy two absorption laws relating the two operations has the structure of a lattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def Lattice.mk' {α : Type*} [Max α] [Min α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a) (inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a) (inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) : Lattice α := have sup_idem : ∀ b : α, b ⊔ b = b := fun b => calc b ⊔ b = b ⊔ b ⊓ (b ⊔ b) := by rw [inf_sup_self] _ = b := by rw [sup_inf_self] have inf_idem : ∀ b : α, b ⊓ b = b := fun b => calc b ⊓ b = b ⊓ (b ⊔ b ⊓ b) := by rw [sup_inf_self] _ = b := by rw [inf_sup_self] let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst = @SemilatticeInf.toPartialOrder _ semilatt_inf_inst := semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _ sup_inf_self inf_sup_self { semilatt_sup_inst, semilatt_inf_inst with inf_le_left := fun a b => by rw [partial_order_eq] apply inf_le_left, inf_le_right := fun a b => by rw [partial_order_eq] apply inf_le_right, le_inf := fun a b c => by rw [partial_order_eq] apply le_inf } section Lattice variable [Lattice α] {a b c : α} theorem inf_le_sup : a ⊓ b ≤ a ⊔ b := inf_le_left.trans le_sup_left theorem sup_le_inf : a ⊔ b ≤ a ⊓ b ↔ a = b := by simp [le_antisymm_iff, and_comm] @[simp] lemma inf_eq_sup : a ⊓ b = a ⊔ b ↔ a = b := by rw [← inf_le_sup.ge_iff_eq, sup_le_inf] @[simp] lemma sup_eq_inf : a ⊔ b = a ⊓ b ↔ a = b := eq_comm.trans inf_eq_sup @[simp] lemma inf_lt_sup : a ⊓ b < a ⊔ b ↔ a ≠ b := by rw [inf_le_sup.lt_iff_ne, Ne, inf_eq_sup] @[simp] lemma inf_left_le_sup_right : (a ⊓ b) ≤ (b ⊔ c) := le_trans inf_le_right le_sup_left @[simp] lemma inf_right_le_sup_right : (b ⊓ a) ≤ (b ⊔ c) := le_trans inf_le_left le_sup_left @[simp] lemma inf_left_le_sup_left : (a ⊓ b) ≤ (c ⊔ b) := le_trans inf_le_right le_sup_right @[simp] lemma inf_right_le_sup_left : (b ⊓ a) ≤ (c ⊔ b) := le_trans inf_le_left le_sup_right lemma inf_eq_and_sup_eq_iff : a ⊓ b = c ∧ a ⊔ b = c ↔ a = c ∧ b = c := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm) simpa using h · rintro ⟨rfl, rfl⟩ exact ⟨inf_idem _, sup_idem _⟩ /-! #### Distributivity laws -/ -- TODO: better names? theorem sup_inf_le : a ⊔ b ⊓ c ≤ (a ⊔ b) ⊓ (a ⊔ c) := le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _) theorem le_inf_sup : a ⊓ b ⊔ a ⊓ c ≤ a ⊓ (b ⊔ c) := sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right) theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp theorem sup_inf_self : a ⊔ a ⊓ b = a := by simp theorem sup_eq_iff_inf_eq : a ⊔ b = b ↔ a ⊓ b = a := by rw [sup_eq_right, ← inf_eq_left] theorem Lattice.ext {α} {A B : Lattice α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases SemilatticeSup.ext H cases SemilatticeInf.ext H congr end Lattice /-! ### Distributive lattices -/ /-- A distributive lattice is a lattice that satisfies any of four equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`, on the left or right). The definition here chooses `le_sup_inf`: `(x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)`. To prove distributivity from the dual law, use `DistribLattice.of_inf_sup_le`. A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ class DistribLattice (α) extends Lattice α where /-- The infimum distributes over the supremum -/ protected le_sup_inf : ∀ x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z section DistribLattice variable [DistribLattice α] {x y z : α} theorem le_sup_inf : ∀ {x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z := fun {x y z} => DistribLattice.le_sup_inf x y z theorem sup_inf_left (a b c : α) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right (a b c : α) : a ⊓ b ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) := by simp only [sup_inf_left, sup_comm _ c] theorem inf_sup_left (a b c : α) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c := calc a ⊓ (b ⊔ c) = a ⊓ (a ⊔ c) ⊓ (b ⊔ c) := by rw [inf_sup_self] _ = a ⊓ (a ⊓ b ⊔ c) := by simp only [inf_assoc, sup_inf_right] _ = (a ⊔ a ⊓ b) ⊓ (a ⊓ b ⊔ c) := by rw [sup_inf_self] _ = (a ⊓ b ⊔ a) ⊓ (a ⊓ b ⊔ c) := by rw [sup_comm] _ = a ⊓ b ⊔ a ⊓ c := by rw [sup_inf_left] instance OrderDual.instDistribLattice (α : Type*) [DistribLattice α] : DistribLattice αᵒᵈ where le_sup_inf _ _ _ := (inf_sup_left _ _ _).le theorem inf_sup_right (a b c : α) : (a ⊔ b) ⊓ c = a ⊓ c ⊔ b ⊓ c := by simp only [inf_sup_left, inf_comm _ c] theorem le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y := calc x ≤ y ⊓ z ⊔ x := le_sup_right _ = (y ⊔ x) ⊓ (x ⊔ z) := by rw [sup_inf_right, sup_comm x] _ ≤ (y ⊔ x) ⊓ (y ⊔ z) := inf_le_inf_left _ h₂ _ = y ⊔ x ⊓ z := by rw [← sup_inf_left] _ ≤ y ⊔ y ⊓ z := sup_le_sup_left h₁ _ _ ≤ _ := sup_le (le_refl y) inf_le_left theorem eq_of_inf_eq_sup_eq {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂)) (le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm)) end DistribLattice -- See note [reducible non-instances] /-- Prove distributivity of an existing lattice from the dual distributive law. -/ abbrev DistribLattice.ofInfSupLe [Lattice α] (inf_sup_le : ∀ a b c : α, a ⊓ (b ⊔ c) ≤ a ⊓ b ⊔ a ⊓ c) : DistribLattice α where le_sup_inf := (@OrderDual.instDistribLattice αᵒᵈ {inferInstanceAs (Lattice αᵒᵈ) with le_sup_inf := inf_sup_le}).le_sup_inf /-! ### Lattices derived from linear orders -/ -- see Note [lower instance priority] instance (priority := 100) LinearOrder.toLattice {α : Type u} [LinearOrder α] : Lattice α where sup := max inf := min le_sup_left := le_max_left; le_sup_right := le_max_right; sup_le _ _ _ := max_le inf_le_left := min_le_left; inf_le_right := min_le_right; le_inf _ _ _ := le_min section LinearOrder variable [LinearOrder α] {a b c d : α} theorem sup_ind (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) := (IsTotal.total a b).elim (fun h : a ≤ b => by rwa [sup_eq_right.2 h]) fun h => by rwa [sup_eq_left.2 h] @[simp] theorem le_sup_iff : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := by grind @[simp] theorem lt_sup_iff : a < b ⊔ c ↔ a < b ∨ a < c := by grind @[simp] theorem sup_lt_iff : b ⊔ c < a ↔ b < a ∧ c < a := ⟨fun h => ⟨le_sup_left.trans_lt h, le_sup_right.trans_lt h⟩, fun h => sup_ind (p := (· < a)) b c h.1 h.2⟩ theorem inf_ind (a b : α) {p : α → Prop} : p a → p b → p (a ⊓ b) := @sup_ind αᵒᵈ _ _ _ _ @[simp] theorem inf_le_iff : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a := @le_sup_iff αᵒᵈ _ _ _ _ @[simp] theorem inf_lt_iff : b ⊓ c < a ↔ b < a ∨ c < a := @lt_sup_iff αᵒᵈ _ _ _ _ @[simp] theorem lt_inf_iff : a < b ⊓ c ↔ a < b ∧ a < c := @sup_lt_iff αᵒᵈ _ _ _ _ variable (a b c d) theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) := sup_sup_sup_comm _ _ _ _ theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) := inf_inf_inf_comm _ _ _ _ end LinearOrder theorem sup_eq_maxDefault [SemilatticeSup α] [DecidableLE α] [IsTotal α (· ≤ ·)] : (· ⊔ ·) = (maxDefault : α → α → α) := by ext x y unfold maxDefault split_ifs with h' exacts [sup_of_le_right h', sup_of_le_left <| (total_of (· ≤ ·) x y).resolve_left h'] theorem inf_eq_minDefault [SemilatticeInf α] [DecidableLE α] [IsTotal α (· ≤ ·)] : (· ⊓ ·) = (minDefault : α → α → α) := by ext x y unfold minDefault split_ifs with h' exacts [inf_of_le_left h', inf_of_le_right <| (total_of (· ≤ ·) x y).resolve_left h'] /-- A lattice with total order is a linear order. See note [reducible non-instances]. -/ abbrev Lattice.toLinearOrder (α : Type u) [Lattice α] [DecidableEq α] [DecidableLE α] [DecidableLT α] [IsTotal α (· ≤ ·)] : LinearOrder α where toDecidableLE := ‹_› toDecidableEq := ‹_› toDecidableLT := ‹_› le_total := total_of (· ≤ ·) max_def := by exact congr_fun₂ sup_eq_maxDefault min_def := by exact congr_fun₂ inf_eq_minDefault -- see Note [lower instance priority] instance (priority := 100) {α : Type u} [LinearOrder α] : DistribLattice α where le_sup_inf _ b c := match le_total b c with | Or.inl h => inf_le_of_left_le <| sup_le_sup_left (le_inf (le_refl b) h) _ | Or.inr h => inf_le_of_right_le <| sup_le_sup_left (le_inf h (le_refl c)) _ instance : DistribLattice ℕ := inferInstance instance : Lattice ℤ := inferInstance /-! ### Dual order -/ open OrderDual @[simp] theorem ofDual_inf [Max α] (a b : αᵒᵈ) : ofDual (a ⊓ b) = ofDual a ⊔ ofDual b := rfl @[simp] theorem ofDual_sup [Min α] (a b : αᵒᵈ) : ofDual (a ⊔ b) = ofDual a ⊓ ofDual b := rfl @[simp] theorem toDual_inf [Min α] (a b : α) : toDual (a ⊓ b) = toDual a ⊔ toDual b := rfl @[simp] theorem toDual_sup [Max α] (a b : α) : toDual (a ⊔ b) = toDual a ⊓ toDual b := rfl section LinearOrder variable [LinearOrder α] @[simp] theorem ofDual_min (a b : αᵒᵈ) : ofDual (min a b) = max (ofDual a) (ofDual b) := rfl @[simp] theorem ofDual_max (a b : αᵒᵈ) : ofDual (max a b) = min (ofDual a) (ofDual b) := rfl @[simp] theorem toDual_min (a b : α) : toDual (min a b) = max (toDual a) (toDual b) := rfl @[simp] theorem toDual_max (a b : α) : toDual (max a b) = min (toDual a) (toDual b) := rfl end LinearOrder /-! ### Function lattices -/ namespace Pi variable {ι : Type*} {α' : ι → Type*} instance [∀ i, Max (α' i)] : Max (∀ i, α' i) := ⟨fun f g i => f i ⊔ g i⟩ @[simp] theorem sup_apply [∀ i, Max (α' i)] (f g : ∀ i, α' i) (i : ι) : (f ⊔ g) i = f i ⊔ g i := rfl @[push ←] theorem sup_def [∀ i, Max (α' i)] (f g : ∀ i, α' i) : f ⊔ g = fun i => f i ⊔ g i := rfl instance [∀ i, Min (α' i)] : Min (∀ i, α' i) := ⟨fun f g i => f i ⊓ g i⟩ @[simp] theorem inf_apply [∀ i, Min (α' i)] (f g : ∀ i, α' i) (i : ι) : (f ⊓ g) i = f i ⊓ g i := rfl @[push ←] theorem inf_def [∀ i, Min (α' i)] (f g : ∀ i, α' i) : f ⊓ g = fun i => f i ⊓ g i := rfl instance instSemilatticeSup [∀ i, SemilatticeSup (α' i)] : SemilatticeSup (∀ i, α' i) where sup x y i := x i ⊔ y i le_sup_left _ _ _ := le_sup_left le_sup_right _ _ _ := le_sup_right sup_le _ _ _ ac bc i := sup_le (ac i) (bc i) instance instSemilatticeInf [∀ i, SemilatticeInf (α' i)] : SemilatticeInf (∀ i, α' i) where inf x y i := x i ⊓ y i inf_le_left _ _ _ := inf_le_left inf_le_right _ _ _ := inf_le_right le_inf _ _ _ ac bc i := le_inf (ac i) (bc i) instance instLattice [∀ i, Lattice (α' i)] : Lattice (∀ i, α' i) where instance instDistribLattice [∀ i, DistribLattice (α' i)] : DistribLattice (∀ i, α' i) where le_sup_inf _ _ _ _ := le_sup_inf end Pi namespace Function variable {ι : Type*} {π : ι → Type*} [DecidableEq ι] -- Porting note: Dot notation on `Function.update` broke theorem update_sup [∀ i, SemilatticeSup (π i)] (f : ∀ i, π i) (i : ι) (a b : π i) : update f i (a ⊔ b) = update f i a ⊔ update f i b := funext fun j => by obtain rfl | hji := eq_or_ne j i <;> simp [update_of_ne, *] theorem update_inf [∀ i, SemilatticeInf (π i)] (f : ∀ i, π i) (i : ι) (a b : π i) : update f i (a ⊓ b) = update f i a ⊓ update f i b := funext fun j => by obtain rfl | hji := eq_or_ne j i <;> simp [update_of_ne, *] end Function /-! ### Monotone functions and lattices -/ namespace Monotone /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} (hf : Monotone f) (hg : Monotone g) : Monotone (f ⊔ g) := fun _ _ h => sup_le_sup (hf h) (hg h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} (hf : Monotone f) (hg : Monotone g) : Monotone (f ⊓ g) := fun _ _ h => inf_le_inf (hf h) (hg h) /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => max (f x) (g x) := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => min (f x) (g x) := hf.inf hg theorem le_map_sup [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (h : Monotone f) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := sup_le (h le_sup_left) (h le_sup_right) theorem map_inf_le [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (h : Monotone f) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := le_inf (h inf_le_left) (h inf_le_right) theorem of_map_inf_le_left [SemilatticeInf α] [Preorder β] {f : α → β} (h : ∀ x y, f (x ⊓ y) ≤ f x) : Monotone f := by intro x y hxy rw [← inf_eq_right.2 hxy] apply h theorem of_map_inf_le [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (h : ∀ x y, f (x ⊓ y) ≤ f x ⊓ f y) : Monotone f := of_map_inf_le_left fun x y ↦ (h x y).trans inf_le_left theorem of_map_inf [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (h : ∀ x y, f (x ⊓ y) = f x ⊓ f y) : Monotone f := of_map_inf_le fun x y ↦ (h x y).le theorem of_left_le_map_sup [SemilatticeSup α] [Preorder β] {f : α → β} (h : ∀ x y, f x ≤ f (x ⊔ y)) : Monotone f := monotone_dual_iff.1 <| of_map_inf_le_left h theorem of_le_map_sup [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (h : ∀ x y, f x ⊔ f y ≤ f (x ⊔ y)) : Monotone f := monotone_dual_iff.mp <| of_map_inf_le h theorem of_map_sup [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (h : ∀ x y, f (x ⊔ y) = f x ⊔ f y) : Monotone f := (@of_map_inf (OrderDual α) (OrderDual β) _ _ _ h).dual variable [LinearOrder α] theorem map_sup [SemilatticeSup β] {f : α → β} (hf : Monotone f) (x y : α) : f (x ⊔ y) = f x ⊔ f y := (IsTotal.total x y).elim (fun h : x ≤ y => by simp only [h, hf h, sup_of_le_right]) fun h => by simp only [h, hf h, sup_of_le_left] theorem map_inf [SemilatticeInf β] {f : α → β} (hf : Monotone f) (x y : α) : f (x ⊓ y) = f x ⊓ f y := hf.dual.map_sup _ _ end Monotone namespace MonotoneOn variable {f : α → β} {s : Set α} {x y : α} /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (f ⊔ g) s := fun _ hx _ hy h => sup_le_sup (hf hx hy h) (hg hx hy h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (f ⊓ g) s := (hf.dual.sup hg.dual).dual /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => max (f x) (g x)) s := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => min (f x) (g x)) s := hf.inf hg theorem of_map_inf [SemilatticeInf α] [SemilatticeInf β] (h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊓ y) = f x ⊓ f y) : MonotoneOn f s := fun x hx y hy hxy => inf_eq_left.1 <| by rw [← h _ hx _ hy, inf_eq_left.2 hxy] theorem of_map_sup [SemilatticeSup α] [SemilatticeSup β] (h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊔ y) = f x ⊔ f y) : MonotoneOn f s := (@of_map_inf αᵒᵈ βᵒᵈ _ _ _ _ h).dual variable [LinearOrder α] theorem map_sup [SemilatticeSup β] (hf : MonotoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : f (x ⊔ y) = f x ⊔ f y := by cases le_total x y <;> have := hf ?_ ?_ ‹_› <;> first | assumption | simp only [*, sup_of_le_left, sup_of_le_right] theorem map_inf [SemilatticeInf β] (hf : MonotoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : f (x ⊓ y) = f x ⊓ f y := hf.dual.map_sup hx hy end MonotoneOn namespace Antitone /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} (hf : Antitone f) (hg : Antitone g) : Antitone (f ⊔ g) := fun _ _ h => sup_le_sup (hf h) (hg h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} (hf : Antitone f) (hg : Antitone g) : Antitone (f ⊓ g) := fun _ _ h => inf_le_inf (hf h) (hg h) /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} (hf : Antitone f) (hg : Antitone g) : Antitone fun x => max (f x) (g x) := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} (hf : Antitone f) (hg : Antitone g) : Antitone fun x => min (f x) (g x) := hf.inf hg theorem map_sup_le [SemilatticeSup α] [SemilatticeInf β] {f : α → β} (h : Antitone f) (x y : α) : f (x ⊔ y) ≤ f x ⊓ f y := h.dual_right.le_map_sup x y theorem le_map_inf [SemilatticeInf α] [SemilatticeSup β] {f : α → β} (h : Antitone f) (x y : α) : f x ⊔ f y ≤ f (x ⊓ y) := h.dual_right.map_inf_le x y variable [LinearOrder α] theorem map_sup [SemilatticeInf β] {f : α → β} (hf : Antitone f) (x y : α) : f (x ⊔ y) = f x ⊓ f y := hf.dual_right.map_sup x y theorem map_inf [SemilatticeSup β] {f : α → β} (hf : Antitone f) (x y : α) : f (x ⊓ y) = f x ⊔ f y := hf.dual_right.map_inf x y end Antitone namespace AntitoneOn variable {f : α → β} {s : Set α} {x y : α} /-- Pointwise supremum of two antitone functions is an antitone function. -/ protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (f ⊔ g) s := fun _ hx _ hy h => sup_le_sup (hf hx hy h) (hg hx hy h) /-- Pointwise infimum of two antitone functions is an antitone function. -/ protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (f ⊓ g) s := (hf.dual.sup hg.dual).dual /-- Pointwise maximum of two antitone functions is an antitone function. -/ protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => max (f x) (g x)) s := hf.sup hg /-- Pointwise minimum of two antitone functions is an antitone function. -/ protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => min (f x) (g x)) s := hf.inf hg theorem of_map_inf [SemilatticeInf α] [SemilatticeSup β] (h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊓ y) = f x ⊔ f y) : AntitoneOn f s := fun x hx y hy hxy => sup_eq_left.1 <| by rw [← h _ hx _ hy, inf_eq_left.2 hxy] theorem of_map_sup [SemilatticeSup α] [SemilatticeInf β] (h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊔ y) = f x ⊓ f y) : AntitoneOn f s := (@of_map_inf αᵒᵈ βᵒᵈ _ _ _ _ h).dual variable [LinearOrder α] theorem map_sup [SemilatticeInf β] (hf : AntitoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : f (x ⊔ y) = f x ⊓ f y := by cases le_total x y <;> have := hf ?_ ?_ ‹_› <;> first | assumption | simp only [*, sup_of_le_left, sup_of_le_right, inf_of_le_left, inf_of_le_right] theorem map_inf [SemilatticeSup β] (hf : AntitoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : f (x ⊓ y) = f x ⊔ f y := hf.dual.map_sup hx hy end AntitoneOn /-! ### Products of (semi-)lattices -/ namespace Prod variable (α β) instance [Max α] [Max β] : Max (α × β) := ⟨fun p q => ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [Min α] [Min β] : Min (α × β) := ⟨fun p q => ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ @[simp] theorem mk_sup_mk [Max α] [Max β] (a₁ a₂ : α) (b₁ b₂ : β) : (a₁, b₁) ⊔ (a₂, b₂) = (a₁ ⊔ a₂, b₁ ⊔ b₂) := rfl @[simp] theorem mk_inf_mk [Min α] [Min β] (a₁ a₂ : α) (b₁ b₂ : β) : (a₁, b₁) ⊓ (a₂, b₂) = (a₁ ⊓ a₂, b₁ ⊓ b₂) := rfl @[simp] theorem fst_sup [Max α] [Max β] (p q : α × β) : (p ⊔ q).fst = p.fst ⊔ q.fst := rfl @[simp] theorem fst_inf [Min α] [Min β] (p q : α × β) : (p ⊓ q).fst = p.fst ⊓ q.fst := rfl @[simp] theorem snd_sup [Max α] [Max β] (p q : α × β) : (p ⊔ q).snd = p.snd ⊔ q.snd := rfl @[simp] theorem snd_inf [Min α] [Min β] (p q : α × β) : (p ⊓ q).snd = p.snd ⊓ q.snd := rfl @[simp] theorem swap_sup [Max α] [Max β] (p q : α × β) : (p ⊔ q).swap = p.swap ⊔ q.swap := rfl @[simp] theorem swap_inf [Min α] [Min β] (p q : α × β) : (p ⊓ q).swap = p.swap ⊓ q.swap := rfl theorem sup_def [Max α] [Max β] (p q : α × β) : p ⊔ q = (p.fst ⊔ q.fst, p.snd ⊔ q.snd) := rfl theorem inf_def [Min α] [Min β] (p q : α × β) : p ⊓ q = (p.fst ⊓ q.fst, p.snd ⊓ q.snd) := rfl instance instSemilatticeSup [SemilatticeSup α] [SemilatticeSup β] : SemilatticeSup (α × β) where sup a b := ⟨a.1 ⊔ b.1, a.2 ⊔ b.2⟩ sup_le _ _ _ h₁ h₂ := ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩ le_sup_left _ _ := ⟨le_sup_left, le_sup_left⟩ le_sup_right _ _ := ⟨le_sup_right, le_sup_right⟩ instance instSemilatticeInf [SemilatticeInf α] [SemilatticeInf β] : SemilatticeInf (α × β) where inf a b := ⟨a.1 ⊓ b.1, a.2 ⊓ b.2⟩ le_inf _ _ _ h₁ h₂ := ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩ inf_le_left _ _ := ⟨inf_le_left, inf_le_left⟩ inf_le_right _ _ := ⟨inf_le_right, inf_le_right⟩ instance instLattice [Lattice α] [Lattice β] : Lattice (α × β) where instance instDistribLattice [DistribLattice α] [DistribLattice β] : DistribLattice (α × β) where le_sup_inf _ _ _ := ⟨le_sup_inf, le_sup_inf⟩ end Prod /-! ### Subtypes of (semi-)lattices -/ namespace Subtype /-- A subtype forms a `⊔`-semilattice if `⊔` preserves the property. See note [reducible non-instances]. -/ protected abbrev semilatticeSup [SemilatticeSup α] {P : α → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) : SemilatticeSup { x : α // P x } where sup x y := ⟨x.1 ⊔ y.1, Psup x.2 y.2⟩ le_sup_left _ _ := le_sup_left le_sup_right _ _ := le_sup_right sup_le _ _ _ h1 h2 := sup_le h1 h2 /-- A subtype forms a `⊓`-semilattice if `⊓` preserves the property. See note [reducible non-instances]. -/ protected abbrev semilatticeInf [SemilatticeInf α] {P : α → Prop} (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : SemilatticeInf { x : α // P x } where inf x y := ⟨x.1 ⊓ y.1, Pinf x.2 y.2⟩ inf_le_left _ _ := inf_le_left inf_le_right _ _ := inf_le_right le_inf _ _ _ h1 h2 := le_inf h1 h2 /-- A subtype forms a lattice if `⊔` and `⊓` preserve the property. See note [reducible non-instances]. -/ protected abbrev lattice [Lattice α] {P : α → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : Lattice { x : α // P x } where __ := Subtype.semilatticeInf Pinf __ := Subtype.semilatticeSup Psup @[simp, norm_cast] theorem coe_sup [SemilatticeSup α] {P : α → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (x y : Subtype P) : (haveI := Subtype.semilatticeSup Psup; (x ⊔ y : Subtype P) : α) = (x ⊔ y : α) := rfl @[simp, norm_cast] theorem coe_inf [SemilatticeInf α] {P : α → Prop} (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) (x y : Subtype P) : (haveI := Subtype.semilatticeInf Pinf; (x ⊓ y : Subtype P) : α) = (x ⊓ y : α) := rfl @[simp] theorem mk_sup_mk [SemilatticeSup α] {P : α → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) {x y : α} (hx : P x) (hy : P y) : (haveI := Subtype.semilatticeSup Psup; (⟨x, hx⟩ ⊔ ⟨y, hy⟩ : Subtype P)) = ⟨x ⊔ y, Psup hx hy⟩ := rfl @[simp] theorem mk_inf_mk [SemilatticeInf α] {P : α → Prop} (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) {x y : α} (hx : P x) (hy : P y) : (haveI := Subtype.semilatticeInf Pinf; (⟨x, hx⟩ ⊓ ⟨y, hy⟩ : Subtype P)) = ⟨x ⊓ y, Pinf hx hy⟩ := rfl end Subtype section lift /-- A type endowed with `⊔` is a `SemilatticeSup`, if it admits an injective map that preserves `⊔` to a `SemilatticeSup`. See note [reducible non-instances]. -/ protected abbrev Function.Injective.semilatticeSup [Max α] [SemilatticeSup β] (f : α → β) (hf_inj : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) : SemilatticeSup α where __ := PartialOrder.lift f hf_inj sup a b := max a b le_sup_left a b := by change f a ≤ f (a ⊔ b) rw [map_sup] exact le_sup_left le_sup_right a b := by change f b ≤ f (a ⊔ b) rw [map_sup] exact le_sup_right sup_le a b c ha hb := by change f (a ⊔ b) ≤ f c rw [map_sup] exact sup_le ha hb /-- A type endowed with `⊓` is a `SemilatticeInf`, if it admits an injective map that preserves `⊓` to a `SemilatticeInf`. See note [reducible non-instances]. -/ protected abbrev Function.Injective.semilatticeInf [Min α] [SemilatticeInf β] (f : α → β) (hf_inj : Function.Injective f) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : SemilatticeInf α where __ := PartialOrder.lift f hf_inj inf a b := min a b inf_le_left a b := by change f (a ⊓ b) ≤ f a rw [map_inf] exact inf_le_left inf_le_right a b := by change f (a ⊓ b) ≤ f b rw [map_inf] exact inf_le_right le_inf a b c ha hb := by change f a ≤ f (b ⊓ c) rw [map_inf] exact le_inf ha hb /-- A type endowed with `⊔` and `⊓` is a `Lattice`, if it admits an injective map that preserves `⊔` and `⊓` to a `Lattice`. See note [reducible non-instances]. -/ protected abbrev Function.Injective.lattice [Max α] [Min α] [Lattice β] (f : α → β) (hf_inj : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : Lattice α where __ := hf_inj.semilatticeSup f map_sup __ := hf_inj.semilatticeInf f map_inf /-- A type endowed with `⊔` and `⊓` is a `DistribLattice`, if it admits an injective map that preserves `⊔` and `⊓` to a `DistribLattice`. See note [reducible non-instances]. -/ protected abbrev Function.Injective.distribLattice [Max α] [Min α] [DistribLattice β] (f : α → β) (hf_inj : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : DistribLattice α where __ := hf_inj.lattice f map_sup map_inf le_sup_inf a b c := by change f ((a ⊔ b) ⊓ (a ⊔ c)) ≤ f (a ⊔ b ⊓ c) rw [map_inf, map_sup, map_sup, map_sup, map_inf] exact le_sup_inf end lift namespace ULift instance [SemilatticeSup α] : SemilatticeSup (ULift.{v} α) := ULift.down_injective.semilatticeSup _ down_sup instance [SemilatticeInf α] : SemilatticeInf (ULift.{v} α) := ULift.down_injective.semilatticeInf _ down_inf instance [Lattice α] : Lattice (ULift.{v} α) := ULift.down_injective.lattice _ down_sup down_inf instance [DistribLattice α] : DistribLattice (ULift.{v} α) := ULift.down_injective.distribLattice _ down_sup down_inf instance [LinearOrder α] : LinearOrder (ULift.{v} α) := ULift.down_injective.linearOrder _ down_le down_lt down_inf down_sup down_compare end ULift --To avoid noncomputability poisoning from `Bool.completeBooleanAlgebra` instance Bool.instPartialOrder : PartialOrder Bool := inferInstance instance Bool.instDistribLattice : DistribLattice Bool := inferInstance
.lake/packages/mathlib/Mathlib/Order/FixedPoints.lean
import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.Order.Hom.Order import Mathlib.Order.OmegaCompletePartialOrder /-! # Fixed point construction on complete lattices This file sets up the basic theory of fixed points of a monotone function in a complete lattice. ## Main definitions * `OrderHom.lfp`: The least fixed point of a bundled monotone function. * `OrderHom.gfp`: The greatest fixed point of a bundled monotone function. * `OrderHom.prevFixed`: The greatest fixed point of a bundled monotone function smaller than or equal to a given element. * `OrderHom.nextFixed`: The least fixed point of a bundled monotone function greater than or equal to a given element. * `fixedPoints.completeLattice`: The Knaster-Tarski theorem: fixed points of a monotone self-map of a complete lattice form themselves a complete lattice. ## Tags fixed point, complete lattice, monotone function -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Function (fixedPoints IsFixedPt) namespace OrderHom section Basic variable [CompleteLattice α] (f : α →o α) /-- Least fixed point of a monotone function -/ def lfp : (α →o α) →o α where toFun f := sInf { a | f a ≤ a } monotone' _ _ hle := sInf_le_sInf fun a ha => (hle a).trans ha /-- Greatest fixed point of a monotone function -/ def gfp : (α →o α) →o α where toFun f := sSup { a | a ≤ f a } monotone' _ _ hle := sSup_le_sSup fun a ha => le_trans ha (hle a) theorem lfp_le {a : α} (h : f a ≤ a) : f.lfp ≤ a := sInf_le h theorem lfp_le_fixed {a : α} (h : f a = a) : f.lfp ≤ a := f.lfp_le h.le theorem le_lfp {a : α} (h : ∀ b, f b ≤ b → a ≤ b) : a ≤ f.lfp := le_sInf h theorem map_le_lfp {a : α} (ha : a ≤ f.lfp) : f a ≤ f.lfp := f.le_lfp fun _ hb => (f.mono <| le_sInf_iff.1 ha _ hb).trans hb @[simp] theorem map_lfp : f f.lfp = f.lfp := have h : f f.lfp ≤ f.lfp := f.map_le_lfp le_rfl h.antisymm <| f.lfp_le <| f.mono h theorem isFixedPt_lfp : IsFixedPt f f.lfp := f.map_lfp theorem lfp_le_map {a : α} (ha : f.lfp ≤ a) : f.lfp ≤ f a := calc f.lfp = f f.lfp := f.map_lfp.symm _ ≤ f a := f.mono ha theorem isLeast_lfp_le : IsLeast { a | f a ≤ a } f.lfp := ⟨f.map_lfp.le, fun _ => f.lfp_le⟩ theorem isLeast_lfp : IsLeast (fixedPoints f) f.lfp := ⟨f.isFixedPt_lfp, fun _ => f.lfp_le_fixed⟩ theorem lfp_induction {p : α → Prop} (step : ∀ a, p a → a ≤ f.lfp → p (f a)) (hSup : ∀ s, (∀ a ∈ s, p a) → p (sSup s)) : p f.lfp := by set s := { a | a ≤ f.lfp ∧ p a } specialize hSup s fun a => And.right suffices sSup s = f.lfp from this ▸ hSup have h : sSup s ≤ f.lfp := sSup_le fun b => And.left have hmem : f (sSup s) ∈ s := ⟨f.map_le_lfp h, step _ hSup h⟩ exact h.antisymm (f.lfp_le <| le_sSup hmem) theorem le_gfp {a : α} (h : a ≤ f a) : a ≤ f.gfp := le_sSup h theorem gfp_le {a : α} (h : ∀ b, b ≤ f b → b ≤ a) : f.gfp ≤ a := sSup_le h theorem isFixedPt_gfp : IsFixedPt f f.gfp := f.dual.isFixedPt_lfp @[simp] theorem map_gfp : f f.gfp = f.gfp := f.dual.map_lfp theorem map_le_gfp {a : α} (ha : a ≤ f.gfp) : f a ≤ f.gfp := f.dual.lfp_le_map ha theorem gfp_le_map {a : α} (ha : f.gfp ≤ a) : f.gfp ≤ f a := f.dual.map_le_lfp ha theorem isGreatest_gfp_le : IsGreatest { a | a ≤ f a } f.gfp := f.dual.isLeast_lfp_le theorem isGreatest_gfp : IsGreatest (fixedPoints f) f.gfp := f.dual.isLeast_lfp theorem gfp_induction {p : α → Prop} (step : ∀ a, p a → f.gfp ≤ a → p (f a)) (hInf : ∀ s, (∀ a ∈ s, p a) → p (sInf s)) : p f.gfp := f.dual.lfp_induction step hInf end Basic section Eqn variable [CompleteLattice α] [CompleteLattice β] (f : β →o α) (g : α →o β) -- Rolling rule theorem map_lfp_comp : f (g.comp f).lfp = (f.comp g).lfp := le_antisymm ((f.comp g).map_lfp ▸ f.mono (lfp_le_fixed _ <| congr_arg g (f.comp g).map_lfp)) <| lfp_le _ (congr_arg f (g.comp f).map_lfp).le theorem map_gfp_comp : f (g.comp f).gfp = (f.comp g).gfp := f.dual.map_lfp_comp g.dual -- Diagonal rule theorem lfp_lfp (h : α →o α →o α) : (lfp.comp h).lfp = h.onDiag.lfp := by let a := (lfp.comp h).lfp refine (lfp_le _ ?_).antisymm (lfp_le _ (Eq.le ?_)) · exact lfp_le _ h.onDiag.map_lfp.le have ha : (lfp ∘ h) a = a := (lfp.comp h).map_lfp calc h a a = h a (h a).lfp := congr_arg (h a) ha.symm _ = (h a).lfp := (h a).map_lfp _ = a := ha theorem gfp_gfp (h : α →o α →o α) : (gfp.comp h).gfp = h.onDiag.gfp := @lfp_lfp αᵒᵈ _ <| (OrderHom.dualIso αᵒᵈ αᵒᵈ).symm.toOrderEmbedding.toOrderHom.comp h.dual end Eqn section PrevNext variable [CompleteLattice α] (f : α →o α) theorem gfp_const_inf_le (x : α) : (const α x ⊓ f).gfp ≤ x := (gfp_le _) fun _ hb => hb.trans inf_le_left /-- Previous fixed point of a monotone map. If `f` is a monotone self-map of a complete lattice and `x` is a point such that `f x ≤ x`, then `f.prevFixed x hx` is the greatest fixed point of `f` that is less than or equal to `x`. -/ def prevFixed (x : α) (hx : f x ≤ x) : fixedPoints f := ⟨(const α x ⊓ f).gfp, calc f (const α x ⊓ f).gfp = x ⊓ f (const α x ⊓ f).gfp := Eq.symm <| inf_of_le_right <| (f.mono <| f.gfp_const_inf_le x).trans hx _ = (const α x ⊓ f).gfp := (const α x ⊓ f).map_gfp ⟩ /-- Next fixed point of a monotone map. If `f` is a monotone self-map of a complete lattice and `x` is a point such that `x ≤ f x`, then `f.nextFixed x hx` is the least fixed point of `f` that is greater than or equal to `x`. -/ def nextFixed (x : α) (hx : x ≤ f x) : fixedPoints f := { f.dual.prevFixed x hx with val := (const α x ⊔ f).lfp } theorem prevFixed_le {x : α} (hx : f x ≤ x) : ↑(f.prevFixed x hx) ≤ x := f.gfp_const_inf_le x theorem le_nextFixed {x : α} (hx : x ≤ f x) : x ≤ f.nextFixed x hx := f.dual.prevFixed_le hx theorem nextFixed_le {x : α} (hx : x ≤ f x) {y : fixedPoints f} (h : x ≤ y) : f.nextFixed x hx ≤ y := Subtype.coe_le_coe.1 <| lfp_le _ <| sup_le h y.2.le @[simp] theorem nextFixed_le_iff {x : α} (hx : x ≤ f x) {y : fixedPoints f} : f.nextFixed x hx ≤ y ↔ x ≤ y := ⟨fun h => (f.le_nextFixed hx).trans h, f.nextFixed_le hx⟩ @[simp] theorem le_prevFixed_iff {x : α} (hx : f x ≤ x) {y : fixedPoints f} : y ≤ f.prevFixed x hx ↔ ↑y ≤ x := f.dual.nextFixed_le_iff hx theorem le_prevFixed {x : α} (hx : f x ≤ x) {y : fixedPoints f} (h : ↑y ≤ x) : y ≤ f.prevFixed x hx := (f.le_prevFixed_iff hx).2 h theorem le_map_sup_fixedPoints (x y : fixedPoints f) : (x ⊔ y : α) ≤ f (x ⊔ y) := calc (x ⊔ y : α) = f x ⊔ f y := congr_arg₂ (· ⊔ ·) x.2.symm y.2.symm _ ≤ f (x ⊔ y) := f.mono.le_map_sup x y -- Porting note: `x ⊓ y` without the `.val`s fails to synthesize `Inf` instance theorem map_inf_fixedPoints_le (x y : fixedPoints f) : f (x ⊓ y) ≤ x.val ⊓ y.val := f.dual.le_map_sup_fixedPoints x y theorem le_map_sSup_subset_fixedPoints (A : Set α) (hA : A ⊆ fixedPoints f) : sSup A ≤ f (sSup A) := sSup_le fun _ hx => hA hx ▸ (f.mono <| le_sSup hx) theorem map_sInf_subset_fixedPoints_le (A : Set α) (hA : A ⊆ fixedPoints f) : f (sInf A) ≤ sInf A := le_sInf fun _ hx => hA hx ▸ (f.mono <| sInf_le hx) end PrevNext end OrderHom namespace fixedPoints open OrderHom variable [CompleteLattice α] (f : α →o α) instance : SemilatticeSup (fixedPoints f) := { Subtype.partialOrder _ with sup := fun x y => f.nextFixed (x ⊔ y) (f.le_map_sup_fixedPoints x y) le_sup_left := fun _ _ => Subtype.coe_le_coe.1 <| le_sup_left.trans (f.le_nextFixed _) le_sup_right := fun _ _ => Subtype.coe_le_coe.1 <| le_sup_right.trans (f.le_nextFixed _) sup_le := fun _ _ _ hxz hyz => f.nextFixed_le _ <| sup_le hxz hyz } instance : SemilatticeInf (fixedPoints f) := { OrderDual.instSemilatticeInf (fixedPoints f.dual) with inf := fun x y => f.prevFixed (x ⊓ y) (f.map_inf_fixedPoints_le x y) } instance : CompleteSemilatticeSup (fixedPoints f) := { Subtype.partialOrder _ with sSup := fun s => f.nextFixed (sSup (Subtype.val '' s)) (f.le_map_sSup_subset_fixedPoints (Subtype.val '' s) fun _ ⟨x, hx⟩ => hx.2 ▸ x.2) le_sSup := fun _ _ hx => Subtype.coe_le_coe.1 <| le_trans (le_sSup <| Set.mem_image_of_mem _ hx) (f.le_nextFixed _) sSup_le := fun _ _ hx => f.nextFixed_le _ <| sSup_le <| Set.forall_mem_image.2 hx } instance : CompleteSemilatticeInf (fixedPoints f) := { Subtype.partialOrder _ with sInf := fun s => f.prevFixed (sInf (Subtype.val '' s)) (f.map_sInf_subset_fixedPoints_le (Subtype.val '' s) fun _ ⟨x, hx⟩ => hx.2 ▸ x.2) le_sInf := fun _ _ hx => f.le_prevFixed _ <| le_sInf <| Set.forall_mem_image.2 hx sInf_le := fun _ _ hx => Subtype.coe_le_coe.1 <| le_trans (f.prevFixed_le _) (sInf_le <| Set.mem_image_of_mem _ hx) } /-- **Knaster-Tarski Theorem**: The fixed points of `f` form a complete lattice. -/ instance completeLattice : CompleteLattice (fixedPoints f) where __ := inferInstanceAs (SemilatticeInf (fixedPoints f)) __ := inferInstanceAs (SemilatticeSup (fixedPoints f)) __ := inferInstanceAs (CompleteSemilatticeInf (fixedPoints f)) __ := inferInstanceAs (CompleteSemilatticeSup (fixedPoints f)) top := ⟨f.gfp, f.isFixedPt_gfp⟩ bot := ⟨f.lfp, f.isFixedPt_lfp⟩ le_top x := f.le_gfp x.2.ge bot_le x := f.lfp_le x.2.le open OmegaCompletePartialOrder fixedPoints /-- **Kleene's fixed point Theorem**: The least fixed point in a complete lattice is the supremum of iterating a function on bottom arbitrary often. -/ theorem lfp_eq_sSup_iterate (h : ωScottContinuous f) : f.lfp = ⨆ n, f^[n] ⊥ := by apply le_antisymm · apply lfp_le_fixed exact Function.mem_fixedPoints.mp (ωSup_iterate_mem_fixedPoint ⟨f, h.map_ωSup_of_orderHom⟩ ⊥ bot_le) · apply le_lfp intro a h_a exact ωSup_iterate_le_prefixedPoint ⟨f, h.map_ωSup_of_orderHom⟩ ⊥ bot_le h_a bot_le theorem gfp_eq_sInf_iterate (h : ωScottContinuous f.dual) : f.gfp = ⨅ n, f^[n] ⊤ := lfp_eq_sSup_iterate f.dual h end fixedPoints
.lake/packages/mathlib/Mathlib/Order/Height.lean
import Mathlib.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ assert_not_exists Field open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.IsChain (· < ·) ∧ ∀ i ∈ l, i ∈ s } @[simp] theorem nil_mem_subchain : [] ∈ s.subchain := ⟨.nil, fun _ ↦ nofun⟩ variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, isChain_cons, and_left_comm, and_comm, and_assoc] @[simp] theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2 := s.exists_chain_of_le_chainHeight tfae_have 2 → 3 := fun ⟨l, hls, he⟩ ↦ ⟨l, hls, he.ge⟩ tfae_have 3 → 1 := fun ⟨l, hs, hn⟩ ↦ le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one_iff, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] @[simp] theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl @[simp] theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 := chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _) theorem le_chainHeight_add_nat_iff {n m : ℕ} : ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2] theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) : s.chainHeight + n ≤ t.chainHeight + m ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m where mp e l h := le_chainHeight_add_nat_iff.1 <| by push_cast; grw [length_le_chainHeight_of_mem_subchain h, e] mpr H := by by_cases h : s.chainHeight = ⊤ · suffices t.chainHeight = ⊤ by rw [this, top_add] exact le_top rw [chainHeight_eq_top_iff] at h ⊢ intro k have := (le_chainHeight_TFAE t k).out 1 2 rw [this] obtain ⟨l, hs, hl⟩ := h (k + m) obtain ⟨l', ht, hl'⟩ := H l hs exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩ · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le rw [← hk, ← hl] exact le_chainHeight_add_nat_iff.2 (H l hs) theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) : TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l', ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by tfae_have 1 ↔ 3 := by convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero tfae_have 2 ↔ 3 := by refine forall₂_congr fun l _ ↦ ?_ simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm] tfae_finish theorem chainHeight_le_chainHeight_iff {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 1 theorem chainHeight_le_chainHeight_iff_le {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 2 theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight := chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩ theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) : (f '' s).chainHeight = s.chainHeight := by apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff] · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by intro l hl obtain ⟨l', h₁, rfl⟩ := this l hl exact ⟨l', h₁, length_map _⟩ intro l induction l with | nil => exact fun _ ↦ ⟨nil, ⟨.nil, fun x h ↦ (not_mem_nil h).elim⟩, rfl⟩ | cons x xs hx => intro h rw [cons_mem_subchain_iff] at h obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h obtain ⟨l', h₃, rfl⟩ := hx h₁ refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩ cases l' · simp · simpa [← hf] using h₂ · intro l hl refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩ · simp_rw [isChain_map, ← hf] exact hl.1 · intro _ e obtain ⟨a, ha, rfl⟩ := mem_map.mp e exact Set.mem_image_of_mem _ (hl.2 _ ha) · rw [length_map] variable (s) @[simp] theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by apply le_antisymm <;> · rw [chainHeight_le_chainHeight_iff] rintro l ⟨h₁, h₂⟩ exact ⟨l.reverse, ⟨isChain_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩, length_reverse.symm⟩ end LT section Preorder variable (s t : Set α) [Preorder α] theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by apply le_antisymm · refine iSup₂_le ?_ rintro (_ | ⟨x, xs⟩) h · exact zero_le _ · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1) apply length_le_chainHeight_of_mem_subchain refine ⟨h.1, fun i hi ↦ ⟨h.2 i hi, ?_⟩⟩ cases hi · exact left_mem_Ici rename_i hi obtain - | h' := isChain_iff_pairwise.mp h.1 exact (h' _ hi).le · exact iSup₂_le fun i _ ↦ chainHeight_mono Set.inter_subset_left theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by simp_rw [← chainHeight_dual (_ ∩ _)] rw [← chainHeight_dual, chainHeight_eq_iSup_Ici] rfl variable {s t} theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← add_zero (insert a s).chainHeight] change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ) apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add] · rintro (_ | ⟨y, ys⟩) h · exact ⟨[], nil_mem_subchain _, zero_le _⟩ · have h' := cons_mem_subchain_iff.mp h refine ⟨ys, ⟨h'.2.1.1, fun i hi ↦ ?_⟩, by simp⟩ apply (h'.2.1.2 i hi).resolve_left rintro rfl obtain - | hy := isChain_iff_pairwise.mp h.1 rcases h'.1 with h' | h' exacts [(hy _ hi).ne h', not_le_of_gt (hy _ hi) (hx _ h').le] · intro l hl refine ⟨a::l, ⟨?_, ?_⟩, by simp⟩ · rw [isChain_cons] exact ⟨fun y hy ↦ hx _ (hl.2 _ (mem_of_mem_head? hy)), hl.1⟩ · rintro x (_ | _) exacts [Or.inl (Set.mem_singleton a), Or.inr (hl.2 x ‹x ∈ l›)] theorem chainHeight_insert_of_forall_lt (a : α) (ha : ∀ b ∈ s, b < a) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← chainHeight_dual, ← chainHeight_dual s] exact chainHeight_insert_of_forall_gt _ ha theorem chainHeight_union_le : (s ∪ t).chainHeight ≤ s.chainHeight + t.chainHeight := by classical refine iSup₂_le fun l hl ↦ ?_ let l₁ := l.filter (· ∈ s) let l₂ := l.filter (· ∈ t) have hl₁ : ↑l₁.length ≤ s.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist filter_sublist, fun i h ↦ by simpa using (of_mem_filter h :)⟩ have hl₂ : ↑l₂.length ≤ t.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist filter_sublist, fun i h ↦ by simpa using (of_mem_filter h :)⟩ grw [← hl₁, ← hl₂] simp_rw [l₁, l₂, ← Nat.cast_add, ← Multiset.coe_card, ← Multiset.card_add, ← Multiset.filter_coe] rw [Multiset.filter_add_filter, Multiset.filter_eq_self.mpr, Multiset.card_add, Nat.cast_add] exacts [le_add_right rfl.le, hl.2] theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) : (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by cases h : t.chainHeight · rw [add_top, eq_top_iff, ← h] exact Set.chainHeight_mono subset_union_right apply le_antisymm · rw [← h] exact chainHeight_union_le rw [← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero, ENat.some_eq_coe, chainHeight_add_le_chainHeight_add] intro l hl obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le refine ⟨l ++ l', ⟨IsChain.append hl.1 hl'.1 fun x hx y hy ↦ ?_, fun i hi ↦ ?_⟩, by simp⟩ · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy) · rw [mem_append] at hi rcases hi with hi | hi exacts [Or.inl (hl.2 _ hi), Or.inr (hl'.2 _ hi)] theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) : WellFoundedGT s := by haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs refine ⟨RelEmbedding.wellFounded_iff_isEmpty.2 ⟨fun f ↦ ?_⟩⟩ refine n.lt_succ_self.not_ge (WithTop.coe_le_coe.1 <| hn.symm ▸ ?_) refine le_iSup₂_of_le ((ofFn (n := n.succ) fun i ↦ f i).map Subtype.val) ⟨isChain_map_of_isChain ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id) (isChain_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2), fun i h ↦ ?_⟩ ?_ · obtain ⟨a, -, rfl⟩ := mem_map.1 h exact a.prop · rw [length_map, length_ofFn] exact le_rfl theorem wellFoundedLT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) : WellFoundedLT s := wellFoundedGT_of_chainHeight_ne_top (ofDual ⁻¹' s) <| by rwa [chainHeight_dual] end Preorder end Set
.lake/packages/mathlib/Mathlib/Order/SupClosed.lean
import Mathlib.Data.Finset.Lattice.Prod import Mathlib.Data.Finset.Powerset import Mathlib.Data.Set.Finite.Basic import Mathlib.Order.Closure import Mathlib.Order.ConditionallyCompleteLattice.Finset /-! # Sets closed under join/meet This file defines predicates for sets closed under `⊔` and shows that each set in a join-semilattice generates a join-closed set and that a semilattice where every directed set has a least upper bound is automatically complete. All dually for `⊓`. ## Main declarations * `SupClosed`: Predicate for a set to be closed under join (`a ∈ s` and `b ∈ s` imply `a ⊔ b ∈ s`). * `InfClosed`: Predicate for a set to be closed under meet (`a ∈ s` and `b ∈ s` imply `a ⊓ b ∈ s`). * `IsSublattice`: Predicate for a set to be closed under meet and join. * `supClosure`: Sup-closure. Smallest sup-closed set containing a given set. * `infClosure`: Inf-closure. Smallest inf-closed set containing a given set. * `latticeClosure`: Smallest sublattice containing a given set. * `SemilatticeSup.toCompleteSemilatticeSup`: A join-semilattice where every sup-closed set has a least upper bound is automatically complete. * `SemilatticeInf.toCompleteSemilatticeInf`: A meet-semilattice where every inf-closed set has a greatest lower bound is automatically complete. -/ variable {ι : Sort*} {F α β : Type*} section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] section Set variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is *sup-closed* if `a ⊔ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/ def SupClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊔ b ∈ s @[simp] lemma supClosed_empty : SupClosed (∅ : Set α) := by simp [SupClosed] @[simp] lemma supClosed_singleton : SupClosed ({a} : Set α) := by simp [SupClosed] @[simp] lemma supClosed_univ : SupClosed (univ : Set α) := by simp [SupClosed] lemma SupClosed.inter (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ∩ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma supClosed_sInter (hS : ∀ s ∈ S, SupClosed s) : SupClosed (⋂₀ S) := fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs) lemma supClosed_iInter (hf : ∀ i, SupClosed (f i)) : SupClosed (⋂ i, f i) := supClosed_sInter <| forall_mem_range.2 hf lemma SupClosed.directedOn (hs : SupClosed s) : DirectedOn (· ≤ ·) s := fun _a ha _b hb ↦ ⟨_, hs ha hb, le_sup_left, le_sup_right⟩ lemma IsUpperSet.supClosed (hs : IsUpperSet s) : SupClosed s := fun _a _ _b ↦ hs le_sup_right lemma SupClosed.preimage [FunLike F β α] [SupHomClass F β α] (hs : SupClosed s) (f : F) : SupClosed (f ⁻¹' s) := fun a ha b hb ↦ by simpa [map_sup] using hs ha hb lemma SupClosed.image [FunLike F α β] [SupHomClass F α β] (hs : SupClosed s) (f : F) : SupClosed (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ rw [← map_sup] exact Set.mem_image_of_mem _ <| hs ha hb lemma supClosed_range [FunLike F α β] [SupHomClass F α β] (f : F) : SupClosed (Set.range f) := by simpa using supClosed_univ.image f lemma SupClosed.prod {t : Set β} (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ×ˢ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma supClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeSup (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, SupClosed (t i)) : SupClosed (s.pi t) := fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi) lemma SupClosed.insert_upperBounds {s : Set α} {a : α} (hs : SupClosed s) (ha : a ∈ upperBounds s) : SupClosed (insert a s) := by rw [SupClosed] aesop lemma SupClosed.insert_lowerBounds {s : Set α} {a : α} (h : SupClosed s) (ha : a ∈ lowerBounds s) : SupClosed (insert a s) := by rw [SupClosed] have ha' : ∀ b ∈ s, a ≤ b := fun _ a ↦ ha a aesop end Set section Finset variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α} open Finset lemma SupClosed.finsetSup'_mem (hs : SupClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.sup' ht f ∈ s := sup'_induction _ _ hs lemma SupClosed.finsetSup_mem [OrderBot α] (hs : SupClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.sup f ∈ s := sup'_eq_sup ht f ▸ hs.finsetSup'_mem ht end Finset end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [SemilatticeInf β] section Set variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is *inf-closed* if `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/ def InfClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊓ b ∈ s @[simp] lemma infClosed_empty : InfClosed (∅ : Set α) := by simp [InfClosed] @[simp] lemma infClosed_singleton : InfClosed ({a} : Set α) := by simp [InfClosed] @[simp] lemma infClosed_univ : InfClosed (univ : Set α) := by simp [InfClosed] lemma InfClosed.inter (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ∩ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma infClosed_sInter (hS : ∀ s ∈ S, InfClosed s) : InfClosed (⋂₀ S) := fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs) lemma infClosed_iInter (hf : ∀ i, InfClosed (f i)) : InfClosed (⋂ i, f i) := infClosed_sInter <| forall_mem_range.2 hf lemma InfClosed.codirectedOn (hs : InfClosed s) : DirectedOn (· ≥ ·) s := fun _a ha _b hb ↦ ⟨_, hs ha hb, inf_le_left, inf_le_right⟩ lemma IsLowerSet.infClosed (hs : IsLowerSet s) : InfClosed s := fun _a _ _b ↦ hs inf_le_right lemma InfClosed.preimage [FunLike F β α] [InfHomClass F β α] (hs : InfClosed s) (f : F) : InfClosed (f ⁻¹' s) := fun a ha b hb ↦ by simpa [map_inf] using hs ha hb lemma InfClosed.image [FunLike F α β] [InfHomClass F α β] (hs : InfClosed s) (f : F) : InfClosed (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ rw [← map_inf] exact Set.mem_image_of_mem _ <| hs ha hb lemma infClosed_range [FunLike F α β] [InfHomClass F α β] (f : F) : InfClosed (Set.range f) := by simpa using infClosed_univ.image f lemma InfClosed.prod {t : Set β} (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ×ˢ t) := fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩ lemma infClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeInf (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, InfClosed (t i)) : InfClosed (s.pi t) := fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi) lemma InfClosed.insert_upperBounds {s : Set α} {a : α} (hs : InfClosed s) (ha : a ∈ upperBounds s) : InfClosed (insert a s) := by rw [InfClosed] have ha' : ∀ b ∈ s, b ≤ a := fun _ a ↦ ha a aesop lemma InfClosed.insert_lowerBounds {s : Set α} {a : α} (h : InfClosed s) (ha : a ∈ lowerBounds s) : InfClosed (insert a s) := by rw [InfClosed] aesop end Set section Finset variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α} open Finset lemma InfClosed.finsetInf'_mem (hs : InfClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.inf' ht f ∈ s := inf'_induction _ _ hs lemma InfClosed.finsetInf_mem [OrderTop α] (hs : InfClosed s) (ht : t.Nonempty) : (∀ i ∈ t, f i ∈ s) → t.inf f ∈ s := inf'_eq_inf ht f ▸ hs.finsetInf'_mem ht end Finset end SemilatticeInf open Finset OrderDual section Lattice variable {ι : Sort*} [Lattice α] [Lattice β] {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α} open Set /-- A set `s` is a *sublattice* if `a ⊔ b ∈ s` and `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. Note: This is not the preferred way to declare a sublattice. One should instead use `Sublattice`. TODO: Define `Sublattice`. -/ structure IsSublattice (s : Set α) : Prop where supClosed : SupClosed s infClosed : InfClosed s @[simp] lemma isSublattice_empty : IsSublattice (∅ : Set α) := ⟨supClosed_empty, infClosed_empty⟩ @[simp] lemma isSublattice_singleton : IsSublattice ({a} : Set α) := ⟨supClosed_singleton, infClosed_singleton⟩ @[simp] lemma isSublattice_univ : IsSublattice (Set.univ : Set α) := ⟨supClosed_univ, infClosed_univ⟩ lemma IsSublattice.inter (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ∩ t) := ⟨hs.1.inter ht.1, hs.2.inter ht.2⟩ lemma isSublattice_sInter (hS : ∀ s ∈ S, IsSublattice s) : IsSublattice (⋂₀ S) := ⟨supClosed_sInter fun _s hs ↦ (hS _ hs).1, infClosed_sInter fun _s hs ↦ (hS _ hs).2⟩ lemma isSublattice_iInter (hf : ∀ i, IsSublattice (f i)) : IsSublattice (⋂ i, f i) := ⟨supClosed_iInter fun _i ↦ (hf _).1, infClosed_iInter fun _i ↦ (hf _).2⟩ lemma IsSublattice.preimage [FunLike F β α] [LatticeHomClass F β α] (hs : IsSublattice s) (f : F) : IsSublattice (f ⁻¹' s) := ⟨hs.1.preimage _, hs.2.preimage _⟩ lemma IsSublattice.image [FunLike F α β] [LatticeHomClass F α β] (hs : IsSublattice s) (f : F) : IsSublattice (f '' s) := ⟨hs.1.image _, hs.2.image _⟩ lemma IsSublattice_range [FunLike F α β] [LatticeHomClass F α β] (f : F) : IsSublattice (Set.range f) := ⟨supClosed_range _, infClosed_range _⟩ lemma IsSublattice.prod {t : Set β} (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ lemma isSublattice_pi {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, IsSublattice (t i)) : IsSublattice (s.pi t) := ⟨supClosed_pi fun _i hi ↦ (ht _ hi).1, infClosed_pi fun _i hi ↦ (ht _ hi).2⟩ @[simp] lemma supClosed_preimage_toDual {s : Set αᵒᵈ} : SupClosed (toDual ⁻¹' s) ↔ InfClosed s := Iff.rfl @[simp] lemma infClosed_preimage_toDual {s : Set αᵒᵈ} : InfClosed (toDual ⁻¹' s) ↔ SupClosed s := Iff.rfl @[simp] lemma supClosed_preimage_ofDual {s : Set α} : SupClosed (ofDual ⁻¹' s) ↔ InfClosed s := Iff.rfl @[simp] lemma infClosed_preimage_ofDual {s : Set α} : InfClosed (ofDual ⁻¹' s) ↔ SupClosed s := Iff.rfl @[simp] lemma isSublattice_preimage_toDual {s : Set αᵒᵈ} : IsSublattice (toDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩ @[simp] lemma isSublattice_preimage_ofDual : IsSublattice (ofDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩ alias ⟨_, InfClosed.dual⟩ := supClosed_preimage_ofDual alias ⟨_, SupClosed.dual⟩ := infClosed_preimage_ofDual alias ⟨_, IsSublattice.dual⟩ := isSublattice_preimage_ofDual alias ⟨_, IsSublattice.of_dual⟩ := isSublattice_preimage_toDual end Lattice section LinearOrder variable [LinearOrder α] @[simp] protected lemma LinearOrder.supClosed (s : Set α) : SupClosed s := fun a ha b hb ↦ by cases le_total a b <;> simp [*] @[simp] protected lemma LinearOrder.infClosed (s : Set α) : InfClosed s := fun a ha b hb ↦ by cases le_total a b <;> simp [*] @[simp] protected lemma LinearOrder.isSublattice (s : Set α) : IsSublattice s := ⟨LinearOrder.supClosed _, LinearOrder.infClosed _⟩ end LinearOrder /-! ## Closure -/ section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] {s t : Set α} {a b : α} /-- Every set in a join-semilattice generates a set closed under join. -/ @[simps! isClosed] def supClosure : ClosureOperator (Set α) := .ofPred (fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.sup' ht id = a}) SupClosed (fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩) (by classical rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩ refine ⟨_, ht.mono subset_union_left, ?_, sup'_union ht hu _⟩ rw [coe_union] exact Set.union_subset hts hus) (by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetSup'_mem ht fun i hi ↦ hs <| hts hi) @[simp] lemma subset_supClosure {s : Set α} : s ⊆ supClosure s := supClosure.le_closure _ @[simp] lemma supClosed_supClosure : SupClosed (supClosure s) := supClosure.isClosed_closure _ lemma supClosure_mono : Monotone (supClosure : Set α → Set α) := supClosure.monotone @[simp] lemma supClosure_eq_self : supClosure s = s ↔ SupClosed s := supClosure.isClosed_iff.symm alias ⟨_, SupClosed.supClosure_eq⟩ := supClosure_eq_self lemma supClosure_idem (s : Set α) : supClosure (supClosure s) = supClosure s := supClosure.idempotent _ @[simp] lemma supClosure_empty : supClosure (∅ : Set α) = ∅ := by simp @[simp] lemma supClosure_singleton : supClosure {a} = {a} := by simp @[simp] lemma supClosure_univ : supClosure (Set.univ : Set α) = Set.univ := by simp @[simp] lemma upperBounds_supClosure (s : Set α) : upperBounds (supClosure s) = upperBounds s := (upperBounds_mono_set subset_supClosure).antisymm <| by rintro a ha _ ⟨t, ht, hts, rfl⟩ exact sup'_le _ _ fun b hb ↦ ha <| hts hb @[simp] lemma isLUB_supClosure : IsLUB (supClosure s) a ↔ IsLUB s a := by simp [IsLUB] lemma sup_mem_supClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊔ b ∈ supClosure s := supClosed_supClosure (subset_supClosure ha) (subset_supClosure hb) lemma finsetSup'_mem_supClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α} (hf : ∀ i ∈ t, f i ∈ s) : t.sup' ht f ∈ supClosure s := supClosed_supClosure.finsetSup'_mem _ fun _i hi ↦ subset_supClosure <| hf _ hi lemma supClosure_min : s ⊆ t → SupClosed t → supClosure s ⊆ t := supClosure.closure_min /-- The semilattice generated by a finite set is finite. -/ protected lemma Set.Finite.supClosure (hs : s.Finite) : (supClosure s).Finite := by lift s to Finset α using hs classical refine ({t ∈ s.powerset | t.Nonempty}.attach.image fun t ↦ t.1.sup' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_ rintro _ ⟨t, ht, hts, rfl⟩ simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists, Finset.mem_powerset, mem_filter] exact ⟨t, ⟨hts, ht⟩, rfl⟩ @[simp] lemma supClosure_prod (s : Set α) (t : Set β) : supClosure (s ×ˢ t) = supClosure s ×ˢ supClosure t := le_antisymm (supClosure_min (Set.prod_mono subset_supClosure subset_supClosure) <| supClosed_supClosure.prod supClosed_supClosure) <| by rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩ refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩ · simpa only [coe_product] using Set.prod_mono hus hvt · simp [prodMk_sup'_sup'] end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [SemilatticeInf β] {s t : Set α} {a b : α} /-- Every set in a join-semilattice generates a set closed under join. -/ @[simps! isClosed] def infClosure : ClosureOperator (Set α) := ClosureOperator.ofPred (fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.inf' ht id = a}) InfClosed (fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩) (by classical rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩ refine ⟨_, ht.mono subset_union_left, ?_, inf'_union ht hu _⟩ rw [coe_union] exact Set.union_subset hts hus) (by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetInf'_mem ht fun i hi ↦ hs <| hts hi) @[simp] lemma subset_infClosure {s : Set α} : s ⊆ infClosure s := infClosure.le_closure _ @[simp] lemma infClosed_infClosure : InfClosed (infClosure s) := infClosure.isClosed_closure _ lemma infClosure_mono : Monotone (infClosure : Set α → Set α) := infClosure.monotone @[simp] lemma infClosure_eq_self : infClosure s = s ↔ InfClosed s := infClosure.isClosed_iff.symm alias ⟨_, InfClosed.infClosure_eq⟩ := infClosure_eq_self lemma infClosure_idem (s : Set α) : infClosure (infClosure s) = infClosure s := infClosure.idempotent _ @[simp] lemma infClosure_empty : infClosure (∅ : Set α) = ∅ := by simp @[simp] lemma infClosure_singleton : infClosure {a} = {a} := by simp @[simp] lemma infClosure_univ : infClosure (Set.univ : Set α) = Set.univ := by simp @[simp] lemma lowerBounds_infClosure (s : Set α) : lowerBounds (infClosure s) = lowerBounds s := (lowerBounds_mono_set subset_infClosure).antisymm <| by rintro a ha _ ⟨t, ht, hts, rfl⟩ exact le_inf' _ _ fun b hb ↦ ha <| hts hb @[simp] lemma isGLB_infClosure : IsGLB (infClosure s) a ↔ IsGLB s a := by simp [IsGLB] lemma inf_mem_infClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊓ b ∈ infClosure s := infClosed_infClosure (subset_infClosure ha) (subset_infClosure hb) lemma finsetInf'_mem_infClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α} (hf : ∀ i ∈ t, f i ∈ s) : t.inf' ht f ∈ infClosure s := infClosed_infClosure.finsetInf'_mem _ fun _i hi ↦ subset_infClosure <| hf _ hi lemma infClosure_min : s ⊆ t → InfClosed t → infClosure s ⊆ t := infClosure.closure_min /-- The semilattice generated by a finite set is finite. -/ protected lemma Set.Finite.infClosure (hs : s.Finite) : (infClosure s).Finite := by lift s to Finset α using hs classical refine ({t ∈ s.powerset | t.Nonempty}.attach.image fun t ↦ t.1.inf' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_ rintro _ ⟨t, ht, hts, rfl⟩ simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists, Finset.mem_powerset, mem_filter] exact ⟨t, ⟨hts, ht⟩, rfl⟩ @[simp] lemma infClosure_prod (s : Set α) (t : Set β) : infClosure (s ×ˢ t) = infClosure s ×ˢ infClosure t := le_antisymm (infClosure_min (Set.prod_mono subset_infClosure subset_infClosure) <| infClosed_infClosure.prod infClosed_infClosure) <| by rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩ refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩ · simpa only [coe_product] using Set.prod_mono hus hvt · simp [prodMk_inf'_inf'] end SemilatticeInf section Lattice variable [Lattice α] [Lattice β] {s t : Set α} /-- Every set in a join-semilattice generates a set closed under join. -/ @[simps! isClosed] def latticeClosure : ClosureOperator (Set α) := .ofCompletePred IsSublattice fun _ ↦ isSublattice_sInter @[simp] lemma subset_latticeClosure : s ⊆ latticeClosure s := latticeClosure.le_closure _ @[simp] lemma isSublattice_latticeClosure : IsSublattice (latticeClosure s) := latticeClosure.isClosed_closure _ lemma latticeClosure_min : s ⊆ t → IsSublattice t → latticeClosure s ⊆ t := latticeClosure.closure_min lemma latticeClosure_sup_inf_induction (p : (a : α) → a ∈ latticeClosure s → Prop) (mem : ∀ (a : α) (has : a ∈ s), p a (subset_latticeClosure has)) (sup : ∀ (a : α) (has : a ∈ latticeClosure s) (b : α) (hbs : b ∈ latticeClosure s), p a has → p b hbs → p (a ⊔ b) (isSublattice_latticeClosure.supClosed has hbs)) (inf : ∀ (a : α) (has : a ∈ latticeClosure s) (b : α) (hbs : b ∈ latticeClosure s), p a has → p b hbs → p (a ⊓ b) (isSublattice_latticeClosure.infClosed has hbs)) {a : α} (has : a ∈ latticeClosure s) : p a has := by have h : IsSublattice { a : α | ∃ has : a ∈ latticeClosure s, p a has } := { supClosed := fun a ⟨has, hpa⟩ b ⟨hbs, hpb⟩ => ⟨isSublattice_latticeClosure.supClosed has hbs, sup a has b hbs hpa hpb⟩ infClosed := fun a ⟨has, hpa⟩ b ⟨hbs, hpb⟩ => ⟨isSublattice_latticeClosure.infClosed has hbs, inf a has b hbs hpa hpb⟩ } refine (latticeClosure_min (fun a ha ↦ ?_) h has).choose_spec exact ⟨subset_latticeClosure ha, mem a ha⟩ lemma latticeClosure_mono : Monotone (latticeClosure : Set α → Set α) := latticeClosure.monotone @[simp] lemma latticeClosure_eq_self : latticeClosure s = s ↔ IsSublattice s := latticeClosure.isClosed_iff.symm alias ⟨_, IsSublattice.latticeClosure_eq⟩ := latticeClosure_eq_self lemma latticeClosure_idem (s : Set α) : latticeClosure (latticeClosure s) = latticeClosure s := latticeClosure.idempotent _ @[simp] lemma latticeClosure_empty : latticeClosure (∅ : Set α) = ∅ := by simp @[simp] lemma latticeClosure_singleton (a : α) : latticeClosure {a} = {a} := by simp @[simp] lemma latticeClosure_univ : latticeClosure (Set.univ : Set α) = Set.univ := by simp lemma image_latticeClosure (s : Set α) (f : α → β) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : f '' latticeClosure s = latticeClosure (f '' s) := by simp only [subset_antisymm_iff, Set.image_subset_iff] constructor <;> apply latticeClosure_sup_inf_induction · exact fun a ha ↦ subset_latticeClosure <| Set.mem_image_of_mem _ ha · rintro a - b - ha hb simpa [map_sup] using isSublattice_latticeClosure.supClosed ha hb · rintro a - b - ha hb simpa [map_inf] using isSublattice_latticeClosure.infClosed ha hb · exact Set.image_mono subset_latticeClosure · rintro _ - _ - ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩ exact ⟨a ⊔ b, isSublattice_latticeClosure.supClosed ha hb, map_sup ..⟩ · rintro _ - _ - ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩ exact ⟨a ⊓ b, isSublattice_latticeClosure.infClosed ha hb, map_inf ..⟩ lemma ofDual_preimage_latticeClosure (s : Set α) : ofDual ⁻¹' latticeClosure s = latticeClosure (ofDual ⁻¹' s) := by change ClosureOperator.ofCompletePred _ _ _ = ClosureOperator.ofCompletePred _ _ _ congr 2 ext exact ⟨fun h => ⟨h.2, h.1⟩, fun h => ⟨h.2, h.1⟩⟩ lemma image_latticeClosure' (s : Set α) (f : α → β) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊓ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊔ f b) : f '' latticeClosure s = latticeClosure (f '' s) := by simpa only [Set.image_comp, Equiv.image_symm_eq_preimage, ← ofDual_preimage_latticeClosure] using image_latticeClosure s (ofDual.symm ∘ f) map_sup map_inf end Lattice section DistribLattice variable [DistribLattice α] [DistribLattice β] {s : Set α} protected lemma SupClosed.infClosure (hs : SupClosed s) : SupClosed (infClosure s) := by rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩ rw [inf'_sup_inf'] exact finsetInf'_mem_infClosure _ fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2) protected lemma InfClosed.supClosure (hs : InfClosed s) : InfClosed (supClosure s) := by rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩ rw [sup'_inf_sup'] exact finsetSup'_mem_supClosure _ fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2) @[simp] lemma supClosure_infClosure (s : Set α) : supClosure (infClosure s) = latticeClosure s := le_antisymm (supClosure_min (infClosure_min subset_latticeClosure isSublattice_latticeClosure.2) isSublattice_latticeClosure.1) <| latticeClosure_min (subset_infClosure.trans subset_supClosure) ⟨supClosed_supClosure, infClosed_infClosure.supClosure⟩ @[simp] lemma infClosure_supClosure (s : Set α) : infClosure (supClosure s) = latticeClosure s := le_antisymm (infClosure_min (supClosure_min subset_latticeClosure isSublattice_latticeClosure.1) isSublattice_latticeClosure.2) <| latticeClosure_min (subset_supClosure.trans subset_infClosure) ⟨supClosed_supClosure.infClosure, infClosed_infClosure⟩ lemma Set.Finite.latticeClosure (hs : s.Finite) : (latticeClosure s).Finite := by rw [← supClosure_infClosure]; exact hs.infClosure.supClosure @[simp] lemma latticeClosure_prod (s : Set α) (t : Set β) : latticeClosure (s ×ˢ t) = latticeClosure s ×ˢ latticeClosure t := by simp_rw [← supClosure_infClosure]; simp end DistribLattice /-- A join-semilattice where every sup-closed set has a least upper bound is automatically complete. -/ def SemilatticeSup.toCompleteSemilatticeSup [SemilatticeSup α] (sSup : Set α → α) (h : ∀ s, SupClosed s → IsLUB s (sSup s)) : CompleteSemilatticeSup α where sSup := fun s => sSup (supClosure s) le_sSup _ _ ha := (h _ supClosed_supClosure).1 <| subset_supClosure ha sSup_le s a ha := (isLUB_le_iff <| h _ supClosed_supClosure).2 <| by rwa [upperBounds_supClosure] /-- A meet-semilattice where every inf-closed set has a greatest lower bound is automatically complete. -/ def SemilatticeInf.toCompleteSemilatticeInf [SemilatticeInf α] (sInf : Set α → α) (h : ∀ s, InfClosed s → IsGLB s (sInf s)) : CompleteSemilatticeInf α where sInf := fun s => sInf (infClosure s) sInf_le _ _ ha := (h _ infClosed_infClosure).1 <| subset_infClosure ha le_sInf s a ha := (le_isGLB_iff <| h _ infClosed_infClosure).2 <| by rwa [lowerBounds_infClosure] section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {f : ι → α} {s t : Set α} lemma SupClosed.iSup_mem_of_nonempty [Finite ι] [Nonempty ι] (hs : SupClosed s) (hf : ∀ i, f i ∈ s) : ⨆ i, f i ∈ s := by cases nonempty_fintype (PLift ι) rw [← iSup_plift_down, ← Finset.sup'_univ_eq_ciSup] exact hs.finsetSup'_mem Finset.univ_nonempty fun _ _ ↦ hf _ lemma InfClosed.iInf_mem_of_nonempty [Finite ι] [Nonempty ι] (hs : InfClosed s) (hf : ∀ i, f i ∈ s) : ⨅ i, f i ∈ s := hs.dual.iSup_mem_of_nonempty hf lemma SupClosed.sSup_mem_of_nonempty (hs : SupClosed s) (ht : t.Finite) (ht' : t.Nonempty) (hts : t ⊆ s) : sSup t ∈ s := by have := ht.to_subtype have := ht'.to_subtype rw [sSup_eq_iSup'] exact hs.iSup_mem_of_nonempty (by simpa) lemma InfClosed.sInf_mem_of_nonempty (hs : InfClosed s) (ht : t.Finite) (ht' : t.Nonempty) (hts : t ⊆ s) : sInf t ∈ s := hs.dual.sSup_mem_of_nonempty ht ht' hts end ConditionallyCompleteLattice section BooleanAlgebra variable [BooleanAlgebra α] {s : Set α} lemma compl_image_latticeClosure (s : Set α) : compl '' latticeClosure s = latticeClosure (compl '' s) := image_latticeClosure' s _ compl_sup_distrib (fun _ _ => compl_inf) lemma compl_image_latticeClosure_eq_of_compl_image_eq_self (hs : compl '' s = s) : compl '' latticeClosure s = latticeClosure s := compl_image_latticeClosure s ▸ hs.symm ▸ rfl end BooleanAlgebra variable [CompleteLattice α] {f : ι → α} {s t : Set α} lemma SupClosed.biSup_mem_of_nonempty {ι : Type*} {t : Set ι} {f : ι → α} (hs : SupClosed s) (ht : t.Finite) (ht' : t.Nonempty) (hf : ∀ i ∈ t, f i ∈ s) : ⨆ i ∈ t, f i ∈ s := by rw [← sSup_image] exact hs.sSup_mem_of_nonempty (ht.image _) (by simpa) (by simpa) lemma InfClosed.biInf_mem_of_nonempty {ι : Type*} {t : Set ι} {f : ι → α} (hs : InfClosed s) (ht : t.Finite) (ht' : t.Nonempty) (hf : ∀ i ∈ t, f i ∈ s) : ⨅ i ∈ t, f i ∈ s := hs.dual.biSup_mem_of_nonempty ht ht' hf lemma SupClosed.iSup_mem [Finite ι] (hs : SupClosed s) (hbot : ⊥ ∈ s) (hf : ∀ i, f i ∈ s) : ⨆ i, f i ∈ s := by cases isEmpty_or_nonempty ι · simpa [iSup_of_empty] · exact hs.iSup_mem_of_nonempty hf lemma InfClosed.iInf_mem [Finite ι] (hs : InfClosed s) (htop : ⊤ ∈ s) (hf : ∀ i, f i ∈ s) : ⨅ i, f i ∈ s := hs.dual.iSup_mem htop hf lemma SupClosed.sSup_mem (hs : SupClosed s) (ht : t.Finite) (hbot : ⊥ ∈ s) (hts : t ⊆ s) : sSup t ∈ s := by have := ht.to_subtype rw [sSup_eq_iSup'] exact hs.iSup_mem hbot (by simpa) lemma InfClosed.sInf_mem (hs : InfClosed s) (ht : t.Finite) (htop : ⊤ ∈ s) (hts : t ⊆ s) : sInf t ∈ s := hs.dual.sSup_mem ht htop hts lemma SupClosed.biSup_mem {ι : Type*} {t : Set ι} {f : ι → α} (hs : SupClosed s) (ht : t.Finite) (hbot : ⊥ ∈ s) (hf : ∀ i ∈ t, f i ∈ s) : ⨆ i ∈ t, f i ∈ s := by rw [← sSup_image] exact hs.sSup_mem (ht.image _) hbot (by simpa) lemma InfClosed.biInf_mem {ι : Type*} {t : Set ι} {f : ι → α} (hs : InfClosed s) (ht : t.Finite) (htop : ⊤ ∈ s) (hf : ∀ i ∈ t, f i ∈ s) : ⨅ i ∈ t, f i ∈ s := hs.dual.biSup_mem ht htop hf
.lake/packages/mathlib/Mathlib/Order/Max.lean
import Mathlib.Order.Synonym /-! # Minimal/maximal and bottom/top elements This file defines predicates for elements to be minimal/maximal or bottom/top and typeclasses saying that there are no such elements. ## Predicates * `IsBot`: An element is *bottom* if all elements are greater than it. * `IsTop`: An element is *top* if all elements are less than it. * `IsMin`: An element is *minimal* if no element is strictly less than it. * `IsMax`: An element is *maximal* if no element is strictly greater than it. See also `isBot_iff_isMin` and `isTop_iff_isMax` for the equivalences in a (co)directed order. ## Typeclasses * `NoBotOrder`: An order without bottom elements. * `NoTopOrder`: An order without top elements. * `NoMinOrder`: An order without minimal elements. * `NoMaxOrder`: An order without maximal elements. -/ open OrderDual universe u v variable {α β : Type*} /-- Order without bottom elements. -/ class NoBotOrder (α : Type*) [LE α] : Prop where /-- For each term `a`, there is some `b` which is either incomparable or strictly smaller. -/ exists_not_ge (a : α) : ∃ b, ¬a ≤ b /-- Order without top elements. -/ class NoTopOrder (α : Type*) [LE α] : Prop where /-- For each term `a`, there is some `b` which is either incomparable or strictly larger. -/ exists_not_le (a : α) : ∃ b, ¬b ≤ a /-- Order without minimal elements. Sometimes called coinitial or dense. -/ class NoMinOrder (α : Type*) [LT α] : Prop where /-- For each term `a`, there is some strictly smaller `b`. -/ exists_lt (a : α) : ∃ b, b < a /-- Order without maximal elements. Sometimes called cofinal. -/ class NoMaxOrder (α : Type*) [LT α] : Prop where /-- For each term `a`, there is some strictly greater `b`. -/ exists_gt (a : α) : ∃ b, a < b export NoBotOrder (exists_not_ge) export NoTopOrder (exists_not_le) export NoMinOrder (exists_lt) export NoMaxOrder (exists_gt) instance nonempty_lt [LT α] [NoMinOrder α] (a : α) : Nonempty { x // x < a } := nonempty_subtype.2 (exists_lt a) instance nonempty_gt [LT α] [NoMaxOrder α] (a : α) : Nonempty { x // a < x } := nonempty_subtype.2 (exists_gt a) instance IsEmpty.toNoMaxOrder [LT α] [IsEmpty α] : NoMaxOrder α := ⟨isEmptyElim⟩ instance IsEmpty.toNoMinOrder [LT α] [IsEmpty α] : NoMinOrder α := ⟨isEmptyElim⟩ instance OrderDual.noBotOrder [LE α] [NoTopOrder α] : NoBotOrder αᵒᵈ := ⟨fun a => exists_not_le (α := α) a⟩ instance OrderDual.noTopOrder [LE α] [NoBotOrder α] : NoTopOrder αᵒᵈ := ⟨fun a => exists_not_ge (α := α) a⟩ instance OrderDual.noMinOrder [LT α] [NoMaxOrder α] : NoMinOrder αᵒᵈ := ⟨fun a => exists_gt (α := α) a⟩ instance OrderDual.noMaxOrder [LT α] [NoMinOrder α] : NoMaxOrder αᵒᵈ := ⟨fun a => exists_lt (α := α) a⟩ -- See note [lower instance priority] instance (priority := 100) [Preorder α] [NoMinOrder α] : NoBotOrder α := ⟨fun a => (exists_lt a).imp fun _ => not_le_of_gt⟩ -- See note [lower instance priority] instance (priority := 100) [Preorder α] [NoMaxOrder α] : NoTopOrder α := ⟨fun a => (exists_gt a).imp fun _ => not_le_of_gt⟩ instance noMaxOrder_of_left [Preorder α] [Preorder β] [NoMaxOrder α] : NoMaxOrder (α × β) := ⟨fun ⟨a, b⟩ => by obtain ⟨c, h⟩ := exists_gt a exact ⟨(c, b), Prod.mk_lt_mk_iff_left.2 h⟩⟩ instance noMaxOrder_of_right [Preorder α] [Preorder β] [NoMaxOrder β] : NoMaxOrder (α × β) := ⟨fun ⟨a, b⟩ => by obtain ⟨c, h⟩ := exists_gt b exact ⟨(a, c), Prod.mk_lt_mk_iff_right.2 h⟩⟩ instance noMinOrder_of_left [Preorder α] [Preorder β] [NoMinOrder α] : NoMinOrder (α × β) := ⟨fun ⟨a, b⟩ => by obtain ⟨c, h⟩ := exists_lt a exact ⟨(c, b), Prod.mk_lt_mk_iff_left.2 h⟩⟩ instance noMinOrder_of_right [Preorder α] [Preorder β] [NoMinOrder β] : NoMinOrder (α × β) := ⟨fun ⟨a, b⟩ => by obtain ⟨c, h⟩ := exists_lt b exact ⟨(a, c), Prod.mk_lt_mk_iff_right.2 h⟩⟩ instance {ι : Type u} {π : ι → Type*} [Nonempty ι] [∀ i, Preorder (π i)] [∀ i, NoMaxOrder (π i)] : NoMaxOrder (∀ i, π i) := ⟨fun a => by classical obtain ⟨b, hb⟩ := exists_gt (a <| Classical.arbitrary _) exact ⟨_, lt_update_self_iff.2 hb⟩⟩ instance {ι : Type u} {π : ι → Type*} [Nonempty ι] [∀ i, Preorder (π i)] [∀ i, NoMinOrder (π i)] : NoMinOrder (∀ i, π i) := ⟨fun a => by classical obtain ⟨b, hb⟩ := exists_lt (a <| Classical.arbitrary _) exact ⟨_, update_lt_self_iff.2 hb⟩⟩ theorem NoBotOrder.to_noMinOrder (α : Type*) [LinearOrder α] [NoBotOrder α] : NoMinOrder α := { exists_lt := fun a => by simpa [not_le] using exists_not_ge a } theorem NoTopOrder.to_noMaxOrder (α : Type*) [LinearOrder α] [NoTopOrder α] : NoMaxOrder α := { exists_gt := fun a => by simpa [not_le] using exists_not_le a } theorem noBotOrder_iff_noMinOrder (α : Type*) [LinearOrder α] : NoBotOrder α ↔ NoMinOrder α := ⟨fun _ => NoBotOrder.to_noMinOrder α, fun _ => inferInstance⟩ theorem noTopOrder_iff_noMaxOrder (α : Type*) [LinearOrder α] : NoTopOrder α ↔ NoMaxOrder α := ⟨fun _ => NoTopOrder.to_noMaxOrder α, fun _ => inferInstance⟩ theorem NoMinOrder.not_acc [LT α] [NoMinOrder α] (a : α) : ¬Acc (· < ·) a := fun h => Acc.recOn h fun x _ => (exists_lt x).recOn theorem NoMaxOrder.not_acc [LT α] [NoMaxOrder α] (a : α) : ¬Acc (· > ·) a := fun h => Acc.recOn h fun x _ => (exists_gt x).recOn section LE variable [LE α] {a : α} /-- `a : α` is a bottom element of `α` if it is less than or equal to any other element of `α`. This predicate is roughly an unbundled version of `OrderBot`, except that a preorder may have several bottom elements. When `α` is linear, this is useful to make a case disjunction on `NoMinOrder α` within a proof. -/ def IsBot (a : α) : Prop := ∀ b, a ≤ b /-- `a : α` is a top element of `α` if it is greater than or equal to any other element of `α`. This predicate is roughly an unbundled version of `OrderBot`, except that a preorder may have several top elements. When `α` is linear, this is useful to make a case disjunction on `NoMaxOrder α` within a proof. -/ def IsTop (a : α) : Prop := ∀ b, b ≤ a /-- `a` is a minimal element of `α` if no element is strictly less than it. We spell it without `<` to avoid having to convert between `≤` and `<`. Instead, `isMin_iff_forall_not_lt` does the conversion. -/ def IsMin (a : α) : Prop := ∀ ⦃b⦄, b ≤ a → a ≤ b /-- `a` is a maximal element of `α` if no element is strictly greater than it. We spell it without `<` to avoid having to convert between `≤` and `<`. Instead, `isMax_iff_forall_not_lt` does the conversion. -/ def IsMax (a : α) : Prop := ∀ ⦃b⦄, a ≤ b → b ≤ a @[simp] theorem not_isBot [NoBotOrder α] (a : α) : ¬IsBot a := fun h => let ⟨_, hb⟩ := exists_not_ge a hb <| h _ @[simp] theorem not_isTop [NoTopOrder α] (a : α) : ¬IsTop a := fun h => let ⟨_, hb⟩ := exists_not_le a hb <| h _ protected theorem IsBot.isMin (h : IsBot a) : IsMin a := fun b _ => h b protected theorem IsTop.isMax (h : IsTop a) : IsMax a := fun b _ => h b theorem IsTop.isMax_iff {α} [PartialOrder α] {i j : α} (h : IsTop i) : IsMax j ↔ j = i := by simp_rw [le_antisymm_iff, h j, true_and] exact ⟨(· (h j)), Function.swap (fun _ ↦ h · |>.trans ·)⟩ theorem IsBot.isMin_iff {α} [PartialOrder α] {i j : α} (h : IsBot i) : IsMin j ↔ j = i := by simp_rw [le_antisymm_iff, h j, and_true] exact ⟨fun a ↦ a (h j), fun a h' ↦ fun _ ↦ Preorder.le_trans j i h' a (h h')⟩ @[simp] theorem isBot_toDual_iff : IsBot (toDual a) ↔ IsTop a := Iff.rfl @[simp] theorem isTop_toDual_iff : IsTop (toDual a) ↔ IsBot a := Iff.rfl @[simp] theorem isMin_toDual_iff : IsMin (toDual a) ↔ IsMax a := Iff.rfl @[simp] theorem isMax_toDual_iff : IsMax (toDual a) ↔ IsMin a := Iff.rfl @[simp] theorem isBot_ofDual_iff {a : αᵒᵈ} : IsBot (ofDual a) ↔ IsTop a := Iff.rfl @[simp] theorem isTop_ofDual_iff {a : αᵒᵈ} : IsTop (ofDual a) ↔ IsBot a := Iff.rfl @[simp] theorem isMin_ofDual_iff {a : αᵒᵈ} : IsMin (ofDual a) ↔ IsMax a := Iff.rfl @[simp] theorem isMax_ofDual_iff {a : αᵒᵈ} : IsMax (ofDual a) ↔ IsMin a := Iff.rfl alias ⟨_, IsTop.toDual⟩ := isBot_toDual_iff alias ⟨_, IsBot.toDual⟩ := isTop_toDual_iff alias ⟨_, IsMax.toDual⟩ := isMin_toDual_iff alias ⟨_, IsMin.toDual⟩ := isMax_toDual_iff alias ⟨_, IsTop.ofDual⟩ := isBot_ofDual_iff alias ⟨_, IsBot.ofDual⟩ := isTop_ofDual_iff alias ⟨_, IsMax.ofDual⟩ := isMin_ofDual_iff alias ⟨_, IsMin.ofDual⟩ := isMax_ofDual_iff end LE section Preorder variable [Preorder α] {a b : α} theorem IsBot.mono (ha : IsBot a) (h : b ≤ a) : IsBot b := fun _ => h.trans <| ha _ theorem IsTop.mono (ha : IsTop a) (h : a ≤ b) : IsTop b := fun _ => (ha _).trans h theorem IsMin.mono (ha : IsMin a) (h : b ≤ a) : IsMin b := fun _ hc => h.trans <| ha <| hc.trans h theorem IsMax.mono (ha : IsMax a) (h : a ≤ b) : IsMax b := fun _ hc => (ha <| h.trans hc).trans h theorem IsMin.not_lt (h : IsMin a) : ¬b < a := fun hb => hb.not_ge <| h hb.le theorem IsMax.not_lt (h : IsMax a) : ¬a < b := fun hb => hb.not_ge <| h hb.le theorem not_isMin_of_lt (h : b < a) : ¬IsMin a := fun ha => ha.not_lt h theorem not_isMax_of_lt (h : a < b) : ¬IsMax a := fun ha => ha.not_lt h alias LT.lt.not_isMin := not_isMin_of_lt alias LT.lt.not_isMax := not_isMax_of_lt theorem isMin_iff_forall_not_lt : IsMin a ↔ ∀ b, ¬b < a := ⟨fun h _ => h.not_lt, fun h _ hba => of_not_not fun hab => h _ <| hba.lt_of_not_ge hab⟩ theorem isMax_iff_forall_not_lt : IsMax a ↔ ∀ b, ¬a < b := ⟨fun h _ => h.not_lt, fun h _ hba => of_not_not fun hab => h _ <| hba.lt_of_not_ge hab⟩ @[simp] theorem not_isMin_iff : ¬IsMin a ↔ ∃ b, b < a := by simp [lt_iff_le_not_ge, IsMin, not_forall] @[simp] theorem not_isMax_iff : ¬IsMax a ↔ ∃ b, a < b := by simp [lt_iff_le_not_ge, IsMax, not_forall] @[simp] theorem not_isMin [NoMinOrder α] (a : α) : ¬IsMin a := not_isMin_iff.2 <| exists_lt a @[simp] theorem not_isMax [NoMaxOrder α] (a : α) : ¬IsMax a := not_isMax_iff.2 <| exists_gt a namespace Subsingleton variable [Subsingleton α] protected theorem isBot (a : α) : IsBot a := fun _ => (Subsingleton.elim _ _).le protected theorem isTop (a : α) : IsTop a := fun _ => (Subsingleton.elim _ _).le protected theorem isMin (a : α) : IsMin a := (Subsingleton.isBot _).isMin protected theorem isMax (a : α) : IsMax a := (Subsingleton.isTop _).isMax end Subsingleton end Preorder section PartialOrder variable [PartialOrder α] {a b : α} protected theorem IsMin.eq_of_le (ha : IsMin a) (h : b ≤ a) : b = a := h.antisymm <| ha h protected theorem IsMin.eq_of_ge (ha : IsMin a) (h : b ≤ a) : a = b := h.antisymm' <| ha h protected theorem IsMax.eq_of_le (ha : IsMax a) (h : a ≤ b) : a = b := h.antisymm <| ha h protected theorem IsMax.eq_of_ge (ha : IsMax a) (h : a ≤ b) : b = a := h.antisymm' <| ha h protected theorem IsBot.lt_of_ne (ha : IsBot a) (h : a ≠ b) : a < b := (ha b).lt_of_ne h protected theorem IsTop.lt_of_ne (ha : IsTop a) (h : b ≠ a) : b < a := (ha b).lt_of_ne h protected theorem IsBot.not_isMax [Nontrivial α] (ha : IsBot a) : ¬ IsMax a := by intro ha' obtain ⟨b, hb⟩ := exists_ne a exact hb <| ha'.eq_of_ge (ha.lt_of_ne hb.symm).le protected theorem IsTop.not_isMin [Nontrivial α] (ha : IsTop a) : ¬ IsMin a := ha.toDual.not_isMax protected theorem IsBot.not_isTop [Nontrivial α] (ha : IsBot a) : ¬ IsTop a := mt IsTop.isMax ha.not_isMax protected theorem IsTop.not_isBot [Nontrivial α] (ha : IsTop a) : ¬ IsBot a := ha.toDual.not_isTop end PartialOrder section Prod variable [Preorder α] [Preorder β] {a : α} {b : β} {x : α × β} theorem IsBot.prodMk (ha : IsBot a) (hb : IsBot b) : IsBot (a, b) := fun _ => ⟨ha _, hb _⟩ theorem IsTop.prodMk (ha : IsTop a) (hb : IsTop b) : IsTop (a, b) := fun _ => ⟨ha _, hb _⟩ theorem IsMin.prodMk (ha : IsMin a) (hb : IsMin b) : IsMin (a, b) := fun _ hc => ⟨ha hc.1, hb hc.2⟩ theorem IsMax.prodMk (ha : IsMax a) (hb : IsMax b) : IsMax (a, b) := fun _ hc => ⟨ha hc.1, hb hc.2⟩ theorem IsBot.fst (hx : IsBot x) : IsBot x.1 := fun c => (hx (c, x.2)).1 theorem IsBot.snd (hx : IsBot x) : IsBot x.2 := fun c => (hx (x.1, c)).2 theorem IsTop.fst (hx : IsTop x) : IsTop x.1 := fun c => (hx (c, x.2)).1 theorem IsTop.snd (hx : IsTop x) : IsTop x.2 := fun c => (hx (x.1, c)).2 theorem IsMin.fst (hx : IsMin x) : IsMin x.1 := fun c hc => (hx <| show (c, x.2) ≤ x from (and_iff_left le_rfl).2 hc).1 theorem IsMin.snd (hx : IsMin x) : IsMin x.2 := fun c hc => (hx <| show (x.1, c) ≤ x from (and_iff_right le_rfl).2 hc).2 theorem IsMax.fst (hx : IsMax x) : IsMax x.1 := fun c hc => (hx <| show x ≤ (c, x.2) from (and_iff_left le_rfl).2 hc).1 theorem IsMax.snd (hx : IsMax x) : IsMax x.2 := fun c hc => (hx <| show x ≤ (x.1, c) from (and_iff_right le_rfl).2 hc).2 theorem Prod.isBot_iff : IsBot x ↔ IsBot x.1 ∧ IsBot x.2 := ⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prodMk h.2⟩ theorem Prod.isTop_iff : IsTop x ↔ IsTop x.1 ∧ IsTop x.2 := ⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prodMk h.2⟩ theorem Prod.isMin_iff : IsMin x ↔ IsMin x.1 ∧ IsMin x.2 := ⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prodMk h.2⟩ theorem Prod.isMax_iff : IsMax x ↔ IsMax x.1 ∧ IsMax x.2 := ⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prodMk h.2⟩ end Prod
.lake/packages/mathlib/Mathlib/Order/LatticeIntervals.lean
import Mathlib.Order.Bounds.Basic /-! # Intervals in Lattices In this file, we provide instances of lattice structures on intervals within lattices. Some of them depend on the order of the endpoints of the interval, and thus are not made global instances. These are probably not all of the lattice instances that could be placed on these intervals, but more can be added easily along the same lines when needed. ## Main definitions In the following, `*` can represent either `c`, `o`, or `i`. * `Set.Ic*.orderBot` * `Set.Ii*.semilatticeInf` * `Set.I*c.orderTop` * `Set.I*c.semilatticeInf` * `Set.I**.lattice` * `Set.Iic.boundedOrder`, within an `OrderBot` * `Set.Ici.boundedOrder`, within an `OrderTop` -/ variable {α : Type*} namespace Set namespace Ico instance semilatticeInf [SemilatticeInf α] {a b : α} : SemilatticeInf (Ico a b) := Subtype.semilatticeInf fun _ _ hx hy => ⟨le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2⟩ @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {a b : α} {x y : Ico a b} : ↑(x ⊓ y) = (↑x ⊓ ↑y : α) := rfl /-- `Ico a b` has a bottom element whenever `a < b`. -/ instance orderBot [PartialOrder α] {a b : α} [Fact (a < b)] : OrderBot (Ico a b) := (isLeast_Ico Fact.out).orderBot @[simp, norm_cast] protected lemma coe_bot [PartialOrder α] (a b : α) [Fact (a < b)] : ↑(⊥ : Ico a b) = a := rfl protected lemma disjoint_iff [SemilatticeInf α] {a b : α} [Fact (a < b)] {x y : Ico a b} : Disjoint x y ↔ ↑x ⊓ ↑y = a := by simp [_root_.disjoint_iff, Subtype.ext_iff] end Ico namespace Iio instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf (Iio a) := Subtype.semilatticeInf fun _ _ hx _ => lt_of_le_of_lt inf_le_left hx @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {a : α} {x y : Iio a} : ↑(x ⊓ y) = (↑x ⊓ ↑y : α) := rfl end Iio namespace Ioc instance semilatticeSup [SemilatticeSup α] {a b : α} : SemilatticeSup (Ioc a b) := Subtype.semilatticeSup fun _ _ hx hy => ⟨lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2⟩ @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {a b : α} {x y : Ioc a b} : ↑(x ⊔ y) = (↑x ⊔ ↑y : α) := rfl /-- `Ioc a b` has a top element whenever `a < b`. -/ instance orderTop [PartialOrder α] {a b : α} [Fact (a < b)] : OrderTop (Ioc a b) := (isGreatest_Ioc Fact.out).orderTop @[simp, norm_cast] protected lemma coe_top [PartialOrder α] (a b : α) [Fact (a < b)] : ↑(⊤ : Ioc a b) = b := rfl protected lemma codisjoint_iff [SemilatticeSup α] {a b : α} [Fact (a < b)] {x y : Ioc a b} : Codisjoint x y ↔ ↑x ⊔ ↑y = b := by simp [_root_.codisjoint_iff, Subtype.ext_iff] end Ioc namespace Ioi instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup (Ioi a) := Subtype.semilatticeSup fun _ _ hx _ => lt_of_lt_of_le hx le_sup_left @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {a : α} {x y : Ioi a} : ↑(x ⊔ y) = (↑x ⊔ ↑y : α) := rfl end Ioi namespace Iic variable {a : α} instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (Iic a) := Subtype.semilatticeInf fun _ _ hx _ => le_trans inf_le_left hx @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {x y : Iic a} : ↑(x ⊓ y) = (↑x ⊓ ↑y : α) := rfl instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (Iic a) := Subtype.semilatticeSup fun _ _ hx hy => sup_le hx hy @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {x y : Iic a} : ↑(x ⊔ y) = (↑x ⊔ ↑y : α) := rfl instance [Lattice α] : Lattice (Iic a) := { Iic.semilatticeInf, Iic.semilatticeSup with } instance orderTop [Preorder α] : OrderTop (Iic a) where top := ⟨a, le_refl a⟩ le_top x := x.prop @[simp, norm_cast] protected lemma coe_top [Preorder α] (a : α) : (⊤ : Iic a) = a := rfl protected lemma eq_top_iff [Preorder α] {x : Iic a} : x = ⊤ ↔ (x : α) = a := by simp [Subtype.ext_iff] instance orderBot [Preorder α] [OrderBot α] : OrderBot (Iic a) where bot := ⟨⊥, bot_le⟩ bot_le := fun ⟨_, _⟩ => Subtype.mk_le_mk.2 bot_le @[simp, norm_cast] protected lemma coe_bot [Preorder α] [OrderBot α] (a : α) : (⊥ : Iic a) = (⊥ : α) := rfl instance [Preorder α] [OrderBot α] : BoundedOrder (Iic a) := { Iic.orderTop, Iic.orderBot with } protected lemma disjoint_iff [SemilatticeInf α] [OrderBot α] {x y : Iic a} : Disjoint x y ↔ Disjoint (x : α) (y : α) := by simp [_root_.disjoint_iff, Subtype.ext_iff] protected lemma codisjoint_iff [SemilatticeSup α] {x y : Iic a} : Codisjoint x y ↔ ↑x ⊔ ↑y = a := by simpa only [_root_.codisjoint_iff] using Iic.eq_top_iff protected lemma isCompl_iff [Lattice α] [OrderBot α] {x y : Iic a} : IsCompl x y ↔ Disjoint (x : α) (y : α) ∧ ↑x ⊔ ↑y = a := by rw [_root_.isCompl_iff, Iic.disjoint_iff, Iic.codisjoint_iff] protected lemma complementedLattice_iff [Lattice α] [OrderBot α] : ComplementedLattice (Iic a) ↔ ∀ b, b ≤ a → ∃ c ≤ a, b ⊓ c = ⊥ ∧ b ⊔ c = a := by simp_rw [complementedLattice_iff, Iic.isCompl_iff, Subtype.forall, Subtype.exists, disjoint_iff, exists_prop, Set.mem_Iic] end Iic namespace Ici instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf (Ici a) := Subtype.semilatticeInf fun _ _ hx hy => le_inf hx hy @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {a : α} {x y : Ici a} : ↑(x ⊓ y) = (↑x ⊓ ↑y : α) := rfl instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup (Ici a) := Subtype.semilatticeSup fun _ _ hx _ => le_trans hx le_sup_left @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {a : α} {x y : Ici a} : ↑(x ⊔ y) = (↑x ⊔ ↑y : α) := rfl instance lattice [Lattice α] {a : α} : Lattice (Ici a) := { Ici.semilatticeInf, Ici.semilatticeSup with } instance distribLattice [DistribLattice α] {a : α} : DistribLattice (Ici a) := { Ici.lattice with le_sup_inf := fun _ _ _ => le_sup_inf } instance orderBot [Preorder α] {a : α} : OrderBot (Ici a) where bot := ⟨a, le_refl a⟩ bot_le x := x.prop @[simp, norm_cast] protected lemma coe_bot [Preorder α] (a : α) : ↑(⊥ : Ici a) = a := rfl instance orderTop [Preorder α] [OrderTop α] {a : α} : OrderTop (Ici a) where top := ⟨⊤, le_top⟩ le_top := fun ⟨_, _⟩ => Subtype.mk_le_mk.2 le_top @[simp, norm_cast] protected lemma coe_top [Preorder α] [OrderTop α] (a : α) : ↑(⊤ : Ici a) = (⊤ : α) := rfl instance boundedOrder [Preorder α] [OrderTop α] {a : α} : BoundedOrder (Ici a) := { Ici.orderTop, Ici.orderBot with } protected lemma disjoint_iff [SemilatticeInf α] {a : α} {x y : Ici a} : Disjoint x y ↔ ↑x ⊓ ↑y = a := by simp [_root_.disjoint_iff, Subtype.ext_iff] protected lemma codisjoint_iff [SemilatticeSup α] [OrderTop α] {a : α} {x y : Ici a} : Codisjoint x y ↔ Codisjoint (x : α) (y : α) := by simp [_root_.codisjoint_iff, Subtype.ext_iff] protected lemma isCompl_iff [Lattice α] [OrderTop α] {a : α} {x y : Ici a} : IsCompl x y ↔ ↑x ⊓ ↑y = a ∧ Codisjoint (x : α) (y : α) := by rw [_root_.isCompl_iff, Ici.disjoint_iff, Ici.codisjoint_iff] end Ici namespace Icc variable {a b : α} instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (Icc a b) := Subtype.semilatticeInf fun _ _ hx hy => ⟨le_inf hx.1 hy.1, le_trans inf_le_left hx.2⟩ @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {x y : Icc a b} : ↑(x ⊓ y) = (↑x ⊓ ↑y : α) := rfl instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (Icc a b) := Subtype.semilatticeSup fun _ _ hx hy => ⟨le_trans hx.1 le_sup_left, sup_le hx.2 hy.2⟩ @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {x y : Icc a b} : ↑(x ⊔ y) = (↑x ⊔ ↑y : α) := rfl instance lattice [Lattice α] : Lattice (Icc a b) := { Icc.semilatticeInf, Icc.semilatticeSup with } /-- `Icc a b` has a bottom element whenever `a ≤ b`. -/ instance [Preorder α] [Fact (a ≤ b)] : OrderBot (Icc a b) := (isLeast_Icc Fact.out).orderBot @[simp, norm_cast] protected lemma coe_bot [Preorder α] (a b : α) [Fact (a ≤ b)] : ↑(⊥ : Icc a b) = a := rfl /-- `Icc a b` has a top element whenever `a ≤ b`. -/ instance [Preorder α] [Fact (a ≤ b)] : OrderTop (Icc a b) := (isGreatest_Icc Fact.out).orderTop @[simp, norm_cast] protected lemma coe_top [Preorder α] (a b : α) [Fact (a ≤ b)] : ↑(⊤ : Icc a b) = b := rfl /-- `Icc a b` is a `BoundedOrder` whenever `a ≤ b`. -/ instance [Preorder α] [Fact (a ≤ b)] : BoundedOrder (Icc a b) where protected lemma disjoint_iff [SemilatticeInf α] [Fact (a ≤ b)] {x y : Icc a b} : Disjoint x y ↔ ↑x ⊓ ↑y = a := by simp [_root_.disjoint_iff, Subtype.ext_iff] protected lemma codisjoint_iff [SemilatticeSup α] [Fact (a ≤ b)] {x y : Icc a b} : Codisjoint x y ↔ ↑x ⊔ (y : α) = b := by simp [_root_.codisjoint_iff, Subtype.ext_iff] protected lemma isCompl_iff [Lattice α] [Fact (a ≤ b)] {x y : Icc a b} : IsCompl x y ↔ ↑x ⊓ ↑y = a ∧ ↑x ⊔ ↑y = b := by rw [_root_.isCompl_iff, Icc.disjoint_iff, Icc.codisjoint_iff] end Icc end Set
.lake/packages/mathlib/Mathlib/Order/BourbakiWitt.lean
import Mathlib.Order.Preorder.Chain import Mathlib.Data.Set.Lattice import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.Order.OmegaCompletePartialOrder /-! # Bourbaki-Witt Theorem This file proves the Bourbaki-Witt Theorem. ## Main definitions - class `ChainCompletePartialOrder` : A nonempty partial order is a chain complete partial order such that every nonempty chain has a supremum ## Main statements - `nonempty_fixedPoints_of_inflationary` : The Bourbaki-Witt Theorem : If $X$ is a chain complete partial order and $f : X → X$ is inflationary (i.e. ∀ x, x ≤ f x), then $f$ has a fixed point ## References The proof used can be found in [serge_lang_algebra] -/ variable {α : Type*} /-- The type of nonempty chains of an order -/ @[ext] structure NonemptyChain (α : Type*) [LE α] where /-- The underlying set of a nonempty chain -/ carrier : Set α Nonempty' : carrier.Nonempty isChain' : IsChain (· ≤ ·) carrier instance {α : Type*} [LE α] : SetLike (NonemptyChain α) α where coe := NonemptyChain.carrier coe_injective' _ _ := NonemptyChain.ext /-- A chain complete partial order (CCPO) is a nonempty partial order such that every nonempty chain has a supremum (which we call `cSup`) -/ class ChainCompletePartialOrder (α : Type*) extends PartialOrder α where /-- The supremum of a nonempty chain -/ cSup : NonemptyChain α → α /-- `cSup` is an upper bound of the nonempty chain -/ le_cSup (c : NonemptyChain α) (x : α) : x ∈ c.carrier → x ≤ cSup c /-- `cSup` is a lower bound of the set of upper bounds of the nonempty chain -/ cSup_le (c : NonemptyChain α) (x : α) : (∀ y ∈ c.carrier, y ≤ x) → cSup c ≤ x open ChainCompletePartialOrder Set OmegaCompletePartialOrder.Chain namespace ChainCompletePartialOrder instance [ChainCompletePartialOrder α] : OmegaCompletePartialOrder α where ωSup c := cSup (NonemptyChain.mk (range c) (range_nonempty c) (isChain_range c)) le_ωSup _ i := le_cSup _ _ (mem_range_self i) ωSup_le _ _ hx := cSup_le _ _ (fun _ ⟨i, hi⟩ ↦ hi ▸ hx i) instance [CompleteLattice α] : ChainCompletePartialOrder α where cSup c := sSup c le_cSup _ _ hx := le_sSup hx cSup_le _ _ h := sSup_le h variable [ChainCompletePartialOrder α] {x : α} {f : α → α} /-- An admissible set for given `x : α` and `f : α → α` has `x`, the base point, as a least element and is closed under applying `f` and `cSup`. -/ structure IsAdmissible (x : α) (f : α → α) (s : Set α) : Prop where /-- The base point is the least element of an admissible set -/ base_isLeast : IsLeast s x /-- The image of an admissible set under `f` is a subset of itself -/ image_self_subset_self : f '' s ⊆ s /-- If a chain is a subset of an admissible set, its `cSup` is a member of the admissible set -/ cSup_mem : ∀ (c : NonemptyChain α), ↑c ⊆ s → cSup c ∈ s lemma ici_isAdmissible (le_map : ∀ x, x ≤ f x) : IsAdmissible x f (Ici x) where base_isLeast := ⟨le_refl x, fun _ h ↦ h⟩ image_self_subset_self := by rintro _ ⟨y, hy, rfl⟩ exact le_trans hy (le_map _) cSup_mem := by intro c hc have ⟨y, hy⟩ := c.Nonempty' exact le_trans (hc hy) (le_cSup _ _ hy) /-- The bottom admissible set with base point `x` and inflationary function `f` -/ abbrev bot (x : α) (f : α → α) : Set α := ⋂₀ {s | IsAdmissible x f s} lemma bot_isAdmissible (le_map : ∀ x, x ≤ f x) : IsAdmissible x f (bot x f) where base_isLeast := by constructor · exact fun _ h ↦ h.base_isLeast.1 · intro y hy exact hy (Ici x) (ici_isAdmissible le_map) image_self_subset_self := by rintro _ ⟨y, hy, rfl⟩ s hs exact hs.image_self_subset_self ⟨y, ⟨mem_sInter.1 hy _ hs, rfl⟩⟩ cSup_mem := by intro c hc s hs exact hs.cSup_mem c (subset_trans hc (sInter_subset_of_mem hs)) lemma subset_bot_iff {s : Set α} (h : IsAdmissible x f s) : s ⊆ bot x f ↔ s = bot x f where mp h' := subset_antisymm h' (sInter_subset_of_mem h) mpr h' := h' ▸ subset_refl (bot x f) lemma map_mem_bot {y : α} (le_map : ∀ x, x ≤ f x) (h : y ∈ bot x f) : f y ∈ bot x f := by apply (bot_isAdmissible (le_map)).image_self_subset_self use y /-- `y` is an extreme point for `x : α` and `f : α → α` if it is in the bottom admissible set and `y` is larger than `f z` for any `z < y` in the bottom admissible set. This definition comes from [serge_lang_algebra] -/ structure IsExtremePt (x : α) (f : α → α) (y : α) : Prop where mem_bot : y ∈ bot x f map_le_of_mem_of_lt {z : α} (h : z ∈ bot x f) (h' : z < y) : f z ≤ y namespace IsExtremePt /-- If `y` is an extreme point and `f` is inflationary, then there are no element between `y` and `f y`. -/ lemma bot_eq_of_le_or_map_le {y : α} (le_map : ∀ x, x ≤ f x) (hy : IsExtremePt x f y) : {z ∈ bot x f | z ≤ y ∨ f y ≤ z} = bot x f := by rw [← subset_bot_iff] · apply sep_subset · apply IsAdmissible.mk · constructor · constructor · exact (bot_isAdmissible le_map).base_isLeast.1 · exact Or.inl ((bot_isAdmissible le_map).base_isLeast.2 hy.mem_bot) · exact fun y h ↦ (bot_isAdmissible le_map).base_isLeast.2 h.1 · rintro _ ⟨z, ⟨hz, (hzy | hyz)⟩, rfl⟩ <;> refine ⟨map_mem_bot le_map hz, ?_⟩ · rcases le_iff_lt_or_eq.1 hzy with (hzy | rfl) · left; exact hy.map_le_of_mem_of_lt hz hzy · right; exact le_refl _ · right; exact le_trans hyz (le_map z) · intro c hc refine ⟨(bot_isAdmissible le_map).cSup_mem _ (subset_trans hc (sep_subset _ _)), ?_⟩ · by_cases h : ∀ z ∈ c, z ≤ y · left; apply cSup_le c y h · push_neg at h rcases h with ⟨z, hz, hzy⟩ obtain h' := Or.resolve_left (hc hz).2 hzy right apply le_trans h' (le_cSup _ _ hz) lemma setOf_isExtremePt_isAdmissible (le_map : ∀ x, x ≤ f x) : IsAdmissible x f {y | IsExtremePt x f y} := by apply IsAdmissible.mk · constructor · refine ⟨(bot_isAdmissible le_map).base_isLeast.1, ?_⟩ intro y hy hyx exfalso exact lt_irrefl x (lt_of_le_of_lt ((bot_isAdmissible le_map).base_isLeast.2 hy) hyx) · exact fun y h ↦ (bot_isAdmissible le_map).base_isLeast.2 h.1 · rintro _ ⟨y, hy, rfl⟩ refine ⟨map_mem_bot le_map hy.mem_bot, ?_⟩ intro z hz hzy have hz' := hz rw [← bot_eq_of_le_or_map_le le_map hy] at hz' rcases hz' with ⟨_, (hz' | hz')⟩ · rcases le_iff_lt_or_eq.1 hz' with (hz' | rfl) · exact le_trans (hy.map_le_of_mem_of_lt hz hz') (le_map y) · exact le_refl (f z) · exfalso exact lt_irrefl z (lt_of_lt_of_le hzy hz') · intro c hc refine ⟨(bot_isAdmissible le_map).cSup_mem _ (subset_trans hc (fun _ h ↦ h.mem_bot)), ?_⟩ intro y hy hy' obtain ⟨z, hz, hzy⟩ : ∃ z ∈ c, ¬ (f z ≤ y) := by by_contra! h apply lt_irrefl y (lt_of_lt_of_le hy' ?_) apply cSup_le intro z hz exact le_trans (le_map z) (h z hz) have h : y ≤ z := by rw [← bot_eq_of_le_or_map_le le_map (hc hz)] at hy exact Or.resolve_right hy.2 hzy obtain hyz | rfl := le_iff_lt_or_eq.1 h · exact le_trans ((hc hz).map_le_of_mem_of_lt hy hyz) (le_cSup _ _ hz) · have hc' := (bot_isAdmissible le_map).cSup_mem _ (subset_trans hc fun _ h ↦ h.mem_bot) rw [← bot_eq_of_le_or_map_le le_map (hc hz)] at hc' apply hc'.2.resolve_left intro hc' exact lt_irrefl y (lt_of_lt_of_le hy' hc') lemma setOf_isExtremePt_eq_bot (le_map : ∀ x, x ≤ f x) : {y | IsExtremePt x f y} = bot x f := by rw [← subset_bot_iff] · exact fun _ h ↦ h.mem_bot · exact setOf_isExtremePt_isAdmissible le_map lemma mem_bot_iff_isExtremePt {y : α} (le_map : ∀ x, x ≤ f x) : y ∈ bot x f ↔ IsExtremePt x f y := by rw [← setOf_isExtremePt_eq_bot le_map] rfl lemma bot_isChain (le_map : ∀ x, x ≤ f x) : IsChain (· ≤ ·) (bot x f) := by intro y hy z hz _ rw [mem_bot_iff_isExtremePt le_map] at hy rw [← bot_eq_of_le_or_map_le le_map hy] at hz obtain ⟨_, (hz | hz)⟩ := hz · right; exact hz · left; exact le_trans (le_map y) hz end IsExtremePt open Function IsExtremePt /- **The Bourbaki-Witt Theorem**: If `α` is a chain complete partial order and `f : α → α` is inflationary, then `f` has a fixed point -/ theorem nonempty_fixedPoints_of_inflationary [Nonempty α] (le_map : ∀ x, x ≤ f x) : (fixedPoints f).Nonempty := by let x : α := Classical.ofNonempty let y := cSup (NonemptyChain.mk (bot x f) ⟨x, (bot_isAdmissible le_map).base_isLeast.1⟩ (bot_isChain le_map)) use y apply le_antisymm (le_cSup _ _ (_ : f y ∈ bot x f)) (le_map y) apply (bot_isAdmissible le_map).image_self_subset_self use y exact ⟨(bot_isAdmissible le_map).cSup_mem _ (subset_refl _), rfl⟩ end ChainCompletePartialOrder
.lake/packages/mathlib/Mathlib/Order/Radical.lean
import Mathlib.Order.Atoms /-! # The radical of a lattice This file contains results on the order radical of a lattice: the infimum of the coatoms. -/ /-- The infimum of all coatoms. This notion specializes, e.g. in the subgroup lattice of a group to the Frattini subgroup, or in the lattices of ideals in a ring `R` to the Jacobson ideal. -/ def Order.radical (α : Type*) [Preorder α] [OrderTop α] [InfSet α] : α := ⨅ a ∈ {H | IsCoatom H}, a variable {α : Type*} [CompleteLattice α] lemma Order.radical_le_coatom {a : α} (h : IsCoatom a) : radical α ≤ a := biInf_le _ h variable {β : Type*} [CompleteLattice β] theorem OrderIso.map_radical (f : α ≃o β) : f (Order.radical α) = Order.radical β := by unfold Order.radical simp only [OrderIso.map_iInf] fapply Equiv.iInf_congr · exact f.toEquiv · simp theorem Order.radical_nongenerating [IsCoatomic α] {a : α} (h : a ⊔ radical α = ⊤) : a = ⊤ := by -- Since the lattice is coatomic, either `a` is already the top element, -- or there is a coatom above it. obtain (rfl | w) := eq_top_or_exists_le_coatom a · -- In the first case, we're done, this was already the goal. rfl · obtain ⟨m, c, le⟩ := w have q : a ⊔ radical α ≤ m := sup_le le (radical_le_coatom c) -- Now note that `a ⊔ radical α ≤ m` since both `a ≤ m` and `radical α ≤ m`. rw [h, top_le_iff] at q simpa using c.1 q
.lake/packages/mathlib/Mathlib/Order/PiLex.lean
import Mathlib.Order.WellFounded import Mathlib.Tactic.Common /-! # Lexicographic order on Pi types This file defines the lexicographic and colexicographic orders for Pi types. * In the lexicographic order, `a` is less than `b` if `a i = b i` for all `i` up to some point `k`, and `a k < b k`. * In the colexicographic order, `a` is less than `b` if `a i = b i` for all `i` above some point `k`, and `a k < b k`. ## Notation * `Πₗ i, α i`: Pi type equipped with the lexicographic order. Type synonym of `Π i, α i`. ## See also Related files are: * `Data.Finset.Colex`: Colexicographic order on finite sets. * `Data.List.Lex`: Lexicographic order on lists. * `Data.Sigma.Order`: Lexicographic order on `Σₗ i, α i`. * `Data.PSigma.Order`: Lexicographic order on `Σₗ' i, α i`. * `Data.Prod.Lex`: Lexicographic order on `α × β`. -/ assert_not_exists Monoid variable {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop) (s : ∀ {i}, β i → β i → Prop) namespace Pi /-- The lexicographic relation on `Π i : ι, β i`, where `ι` is ordered by `r`, and each `β i` is ordered by `s`. The `<` relation on `Lex (∀ i, β i)` is `Pi.Lex (· < ·) (· < ·)`, while the `<` relation on `Colex (∀ i, β i)` is `Pi.Lex (· > ·) (· < ·)`. -/ protected def Lex (x y : ∀ i, β i) : Prop := ∃ i, (∀ j, r j i → x j = y j) ∧ s (x i) (y i) /- This unfortunately results in a type that isn't delta-reduced, so we keep the notation out of the basic API, just in case -/ /-- The notation `Πₗ i, α i` refers to a pi type equipped with the lexicographic order. -/ notation3 (prettyPrint := false) "Πₗ " (...) ", " r:(scoped p => Lex (∀ i, p i)) => r theorem lex_lt_of_lt_of_preorder [∀ i, Preorder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i} (hlt : x < y) : ∃ i, (∀ j, r j i → x j ≤ y j ∧ y j ≤ x j) ∧ x i < y i := let h' := Pi.lt_def.1 hlt let ⟨i, hi, hl⟩ := hwf.has_min _ h'.2 ⟨i, fun j hj => ⟨h'.1 j, not_not.1 fun h => hl j (lt_of_le_not_ge (h'.1 j) h) hj⟩, hi⟩ theorem lex_lt_of_lt [∀ i, PartialOrder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i} (hlt : x < y) : Pi.Lex r (· < ·) x y := by simp_rw [Pi.Lex, le_antisymm_iff] exact lex_lt_of_lt_of_preorder hwf hlt theorem isTrichotomous_lex [∀ i, IsTrichotomous (β i) s] (wf : WellFounded r) : IsTrichotomous (∀ i, β i) (Pi.Lex r @s) := { trichotomous := fun a b => by rcases eq_or_ne a b with hab | hab · exact Or.inr (Or.inl hab) · rw [Function.ne_iff] at hab let i := wf.min _ hab have hri : ∀ j, r j i → a j = b j := by intro j rw [← not_imp_not] exact fun h' => wf.not_lt_min _ _ h' have hne : a i ≠ b i := wf.min_mem _ hab rcases trichotomous_of s (a i) (b i) with hi | hi exacts [Or.inl ⟨i, hri, hi⟩, Or.inr <| Or.inr <| ⟨i, fun j hj => (hri j hj).symm, hi.resolve_left hne⟩] } instance [LT ι] [∀ a, LT (β a)] : LT (Lex (∀ i, β i)) := ⟨Pi.Lex (· < ·) (· < ·)⟩ instance [LT ι] [∀ a, LT (β a)] : LT (Colex (∀ i, β i)) := ⟨Pi.Lex (· > ·) (· < ·)⟩ -- If `Lex` and `Colex` are ever made into one-field structures, we need a `CoeFun` instance. -- This will make `x i` syntactically equal to `ofLex x i` for `x : Πₗ i, α i`, thus making -- the following theorems redundant. @[simp] theorem toLex_apply (x : ∀ i, β i) (i : ι) : toLex x i = x i := rfl @[simp] theorem ofLex_apply (x : Lex (∀ i, β i)) (i : ι) : ofLex x i = x i := rfl @[simp] theorem toColex_apply (x : ∀ i, β i) (i : ι) : toColex x i = x i := rfl @[simp] theorem ofColex_apply (x : Colex (∀ i, β i)) (i : ι) : ofColex x i = x i := rfl instance Lex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] : IsStrictOrder (Lex (∀ i, β i)) (· < ·) where irrefl := fun a ⟨k, _, hk₂⟩ => lt_irrefl (a k) hk₂ trans := by rintro a b c ⟨N₁, lt_N₁, a_lt_b⟩ ⟨N₂, lt_N₂, b_lt_c⟩ rcases lt_trichotomy N₁ N₂ with (H | rfl | H) exacts [⟨N₁, fun j hj => (lt_N₁ _ hj).trans (lt_N₂ _ <| hj.trans H), lt_N₂ _ H ▸ a_lt_b⟩, ⟨N₁, fun j hj => (lt_N₁ _ hj).trans (lt_N₂ _ hj), a_lt_b.trans b_lt_c⟩, ⟨N₂, fun j hj => (lt_N₁ _ (hj.trans H)).trans (lt_N₂ _ hj), (lt_N₁ _ H).symm ▸ b_lt_c⟩] instance Colex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] : IsStrictOrder (Colex (∀ i, β i)) (· < ·) := Lex.isStrictOrder (ι := ιᵒᵈ) instance [LinearOrder ι] [∀ a, PartialOrder (β a)] : PartialOrder (Lex (∀ i, β i)) := partialOrderOfSO (· < ·) instance [LinearOrder ι] [∀ a, PartialOrder (β a)] : PartialOrder (Colex (∀ i, β i)) := partialOrderOfSO (· < ·) /-- `Lex (∀ i, α i)` is a linear order if the original order has well-founded `<`. -/ noncomputable instance Lex.linearOrder [LinearOrder ι] [WellFoundedLT ι] [∀ a, LinearOrder (β a)] : LinearOrder (Lex (∀ i, β i)) := @linearOrderOfSTO (Πₗ i, β i) (· < ·) { trichotomous := (isTrichotomous_lex _ _ IsWellFounded.wf).1 } (Classical.decRel _) /-- `Colex (∀ i, α i)` is a linear order if the original order has well-founded `>`. -/ noncomputable instance Colex.linearOrder [LinearOrder ι] [WellFoundedGT ι] [∀ a, LinearOrder (β a)] : LinearOrder (Colex (∀ i, β i)) := Lex.linearOrder (ι := ιᵒᵈ) section Lex variable [LinearOrder ι] [WellFoundedLT ι] [∀ i, PartialOrder (β i)] {x : ∀ i, β i} {i : ι} {a : β i} open Function theorem toLex_monotone : Monotone (@toLex (∀ i, β i)) := fun a b h => or_iff_not_imp_left.2 fun hne => let ⟨i, hi, hl⟩ := IsWellFounded.wf.has_min (r := (· < ·)) { i | a i ≠ b i } (Function.ne_iff.1 hne) ⟨i, fun j hj => by contrapose! hl exact ⟨j, hl, hj⟩, (h i).lt_of_ne hi⟩ theorem toLex_strictMono : StrictMono (@toLex (∀ i, β i)) := fun a b h => let ⟨i, hi, hl⟩ := IsWellFounded.wf.has_min (r := (· < ·)) { i | a i ≠ b i } (Function.ne_iff.1 h.ne) ⟨i, fun j hj => by contrapose! hl exact ⟨j, hl, hj⟩, (h.le i).lt_of_ne hi⟩ @[simp] theorem lt_toLex_update_self_iff : toLex x < toLex (update x i a) ↔ x i < a := by refine ⟨?_, fun h => toLex_strictMono <| lt_update_self_iff.2 h⟩ rintro ⟨j, hj, h⟩ dsimp at h obtain rfl : j = i := by by_contra H rw [update_of_ne H] at h exact h.false rwa [update_self] at h @[simp] theorem toLex_update_lt_self_iff : toLex (update x i a) < toLex x ↔ a < x i := by refine ⟨?_, fun h => toLex_strictMono <| update_lt_self_iff.2 h⟩ rintro ⟨j, hj, h⟩ dsimp at h obtain rfl : j = i := by by_contra H rw [update_of_ne H] at h exact h.false rwa [update_self] at h @[simp] theorem le_toLex_update_self_iff : toLex x ≤ toLex (update x i a) ↔ x i ≤ a := by simp_rw [le_iff_lt_or_eq, lt_toLex_update_self_iff, toLex_inj, eq_update_self_iff] @[simp] theorem toLex_update_le_self_iff : toLex (update x i a) ≤ toLex x ↔ a ≤ x i := by simp_rw [le_iff_lt_or_eq, toLex_update_lt_self_iff, toLex_inj, update_eq_self_iff] end Lex section Colex variable [LinearOrder ι] [WellFoundedGT ι] [∀ i, PartialOrder (β i)] {x : ∀ i, β i} {i : ι} {a : β i} open Function theorem toColex_monotone : Monotone (@toColex (∀ i, β i)) := toLex_monotone (ι := ιᵒᵈ) theorem toColex_strictMono : StrictMono (@toColex (∀ i, β i)) := toLex_strictMono (ι := ιᵒᵈ) @[simp] theorem lt_toColex_update_self_iff : toColex x < toColex (update x i a) ↔ x i < a := lt_toLex_update_self_iff (ι := ιᵒᵈ) @[simp] theorem toColex_update_lt_self_iff : toColex (update x i a) < toColex x ↔ a < x i := toLex_update_lt_self_iff (ι := ιᵒᵈ) @[simp] theorem le_toColex_update_self_iff : toColex x ≤ toColex (update x i a) ↔ x i ≤ a := le_toLex_update_self_iff (ι := ιᵒᵈ) @[simp] theorem toColex_update_le_self_iff : toColex (update x i a) ≤ toColex x ↔ a ≤ x i := toLex_update_le_self_iff (ι := ιᵒᵈ) end Colex instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderBot (β a)] : OrderBot (Lex (∀ a, β a)) where bot := toLex ⊥ bot_le _ := toLex_monotone bot_le instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderBot (β a)] : OrderBot (Colex (∀ a, β a)) where bot := toColex ⊥ bot_le _ := toColex_monotone bot_le instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderTop (β a)] : OrderTop (Lex (∀ a, β a)) where top := toLex ⊤ le_top _ := toLex_monotone le_top instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderTop (β a)] : OrderTop (Colex (∀ a, β a)) where top := toColex ⊤ le_top _ := toColex_monotone le_top instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)] [∀ a, BoundedOrder (β a)] : BoundedOrder (Lex (∀ a, β a)) where instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)] [∀ a, BoundedOrder (β a)] : BoundedOrder (Colex (∀ a, β a)) where instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] : DenselyOrdered (Lex (∀ i, β i)) := ⟨by rintro _ a₂ ⟨i, h, hi⟩ obtain ⟨a, ha₁, ha₂⟩ := exists_between hi classical refine ⟨Function.update a₂ _ a, ⟨i, fun j hj => ?_, ?_⟩, i, fun j hj => ?_, ?_⟩ · rw [h j hj] dsimp only at hj rw [Function.update_of_ne hj.ne a] · rwa [Function.update_self i a] · rw [Function.update_of_ne hj.ne a] · rwa [Function.update_self i a]⟩ instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] : DenselyOrdered (Colex (∀ i, β i)) := inferInstanceAs (DenselyOrdered (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i)))) theorem Lex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (β i)] : NoMaxOrder (Lex (∀ i, β i)) := ⟨fun a => by let ⟨b, hb⟩ := exists_gt (a i) classical exact ⟨Function.update a i b, i, fun j hj => (Function.update_of_ne hj.ne b a).symm, by rwa [Function.update_self i b]⟩⟩ theorem Colex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (β i)] : NoMaxOrder (Colex (∀ i, β i)) := Lex.noMaxOrder' (ι := ιᵒᵈ) i instance [LinearOrder ι] [WellFoundedLT ι] [Nonempty ι] [∀ i, PartialOrder (β i)] [∀ i, NoMaxOrder (β i)] : NoMaxOrder (Lex (∀ i, β i)) := ⟨fun a => let ⟨_, hb⟩ := exists_gt (ofLex a) ⟨_, toLex_strictMono hb⟩⟩ instance [LinearOrder ι] [WellFoundedGT ι] [Nonempty ι] [∀ i, PartialOrder (β i)] [∀ i, NoMaxOrder (β i)] : NoMaxOrder (Colex (∀ i, β i)) := inferInstanceAs (NoMaxOrder (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i)))) instance [LinearOrder ι] [WellFoundedLT ι] [Nonempty ι] [∀ i, PartialOrder (β i)] [∀ i, NoMinOrder (β i)] : NoMinOrder (Lex (∀ i, β i)) := ⟨fun a => let ⟨_, hb⟩ := exists_lt (ofLex a) ⟨_, toLex_strictMono hb⟩⟩ instance [LinearOrder ι] [WellFoundedGT ι] [Nonempty ι] [∀ i, PartialOrder (β i)] [∀ i, NoMinOrder (β i)] : NoMinOrder (Colex (∀ i, β i)) := inferInstanceAs (NoMinOrder (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i)))) /-- If we swap two strictly decreasing values in a function, then the result is lexicographically smaller than the original function. -/ theorem lex_desc {α} [Preorder ι] [DecidableEq ι] [LT α] {f : ι → α} {i j : ι} (h₁ : i ≤ j) (h₂ : f j < f i) : toLex (f ∘ Equiv.swap i j) < toLex f := ⟨i, fun _ hik => congr_arg f (Equiv.swap_apply_of_ne_of_ne hik.ne (hik.trans_le h₁).ne), by simpa only [Pi.toLex_apply, Function.comp_apply, Equiv.swap_apply_left] using h₂⟩ /-- If we swap two strictly increasing values in a function, then the result is colexicographically smaller than the original function. -/ theorem colex_asc {α} [Preorder ι] [DecidableEq ι] [LT α] {f : ι → α} {i j : ι} (h₁ : i ≤ j) (h₂ : f i < f j) : toColex (f ∘ Equiv.swap i j) < toColex f := by rw [Equiv.swap_comm] exact lex_desc (ι := ιᵒᵈ) h₁ h₂ end Pi
.lake/packages/mathlib/Mathlib/Order/Prod/Lex/Hom.lean
import Mathlib.Data.Prod.Lex import Mathlib.Order.Hom.Basic /-! # Order homomorphism for `Prod.Lex` -/ /-- `toLex` as an `OrderHom`. -/ @[simps] def Prod.Lex.toLexOrderHom {α β : Type*} [PartialOrder α] [Preorder β] : α × β →o α ×ₗ β where toFun := toLex monotone' := Prod.Lex.toLex_mono
.lake/packages/mathlib/Mathlib/Order/Bounds/OrderIso.lean
import Mathlib.Order.Bounds.Image import Mathlib.Order.Hom.Set /-! # Order isomorphisms and bounds. -/ open Set namespace OrderIso variable {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) theorem upperBounds_image {s : Set α} : upperBounds (f '' s) = f '' upperBounds s := Subset.antisymm (fun x hx => ⟨f.symm x, fun _ hy => f.le_symm_apply.2 (hx <| mem_image_of_mem _ hy), f.apply_symm_apply x⟩) f.monotone.image_upperBounds_subset_upperBounds_image theorem lowerBounds_image {s : Set α} : lowerBounds (f '' s) = f '' lowerBounds s := @upperBounds_image αᵒᵈ βᵒᵈ _ _ f.dual _ @[simp] theorem isLUB_image {s : Set α} {x : β} : IsLUB (f '' s) x ↔ IsLUB s (f.symm x) := ⟨fun h => IsLUB.of_image (by simp) ((f.apply_symm_apply x).symm ▸ h), fun h => (IsLUB.of_image (by simp)) <| (f.symm_image_image s).symm ▸ h⟩ theorem isLUB_image' {s : Set α} {x : α} : IsLUB (f '' s) (f x) ↔ IsLUB s x := by rw [isLUB_image, f.symm_apply_apply] @[simp] theorem isGLB_image {s : Set α} {x : β} : IsGLB (f '' s) x ↔ IsGLB s (f.symm x) := f.dual.isLUB_image theorem isGLB_image' {s : Set α} {x : α} : IsGLB (f '' s) (f x) ↔ IsGLB s x := f.dual.isLUB_image' @[simp] theorem isLUB_preimage {s : Set β} {x : α} : IsLUB (f ⁻¹' s) x ↔ IsLUB s (f x) := by rw [← f.symm_symm, ← image_eq_preimage_symm, isLUB_image] theorem isLUB_preimage' {s : Set β} {x : β} : IsLUB (f ⁻¹' s) (f.symm x) ↔ IsLUB s x := by rw [isLUB_preimage, f.apply_symm_apply] @[simp] theorem isGLB_preimage {s : Set β} {x : α} : IsGLB (f ⁻¹' s) x ↔ IsGLB s (f x) := f.dual.isLUB_preimage theorem isGLB_preimage' {s : Set β} {x : β} : IsGLB (f ⁻¹' s) (f.symm x) ↔ IsGLB s x := f.dual.isLUB_preimage' end OrderIso
.lake/packages/mathlib/Mathlib/Order/Bounds/Image.lean
import Mathlib.Data.Set.NAry import Mathlib.Order.Bounds.Basic /-! # Images of upper/lower bounds under monotone functions In this file we prove various results about the behaviour of bounds under monotone/antitone maps. -/ open Function Set open OrderDual (toDual ofDual) universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace MonotoneOn variable [Preorder α] [Preorder β] {f : α → β} {s t : Set α} {a : α} theorem mem_upperBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) (Has : a ∈ upperBounds s) (Hat : a ∈ t) : f a ∈ upperBounds (f '' s) := forall_mem_image.2 fun _ H => Hf (Hst H) Hat (Has H) theorem mem_upperBounds_image_self (Hf : MonotoneOn f t) : a ∈ upperBounds t → a ∈ t → f a ∈ upperBounds (f '' t) := Hf.mem_upperBounds_image subset_rfl theorem mem_lowerBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s) (Hat : a ∈ t) : f a ∈ lowerBounds (f '' s) := forall_mem_image.2 fun _ H => Hf Hat (Hst H) (Has H) theorem mem_lowerBounds_image_self (Hf : MonotoneOn f t) : a ∈ lowerBounds t → a ∈ t → f a ∈ lowerBounds (f '' t) := Hf.mem_lowerBounds_image subset_rfl theorem image_upperBounds_subset_upperBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) : f '' (upperBounds s ∩ t) ⊆ upperBounds (f '' s) := by rintro _ ⟨a, ha, rfl⟩ exact Hf.mem_upperBounds_image Hst ha.1 ha.2 theorem image_lowerBounds_subset_lowerBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) : f '' (lowerBounds s ∩ t) ⊆ lowerBounds (f '' s) := Hf.dual.image_upperBounds_subset_upperBounds_image Hst /-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t` is bounded above. -/ theorem map_bddAbove (Hf : MonotoneOn f t) (Hst : s ⊆ t) : (upperBounds s ∩ t).Nonempty → BddAbove (f '' s) := fun ⟨C, hs, ht⟩ => ⟨f C, Hf.mem_upperBounds_image Hst hs ht⟩ /-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t` is bounded below. -/ theorem map_bddBelow (Hf : MonotoneOn f t) (Hst : s ⊆ t) : (lowerBounds s ∩ t).Nonempty → BddBelow (f '' s) := fun ⟨C, hs, ht⟩ => ⟨f C, Hf.mem_lowerBounds_image Hst hs ht⟩ /-- A monotone map sends a least element of a set to a least element of its image. -/ theorem map_isLeast (Hf : MonotoneOn f t) (Ha : IsLeast t a) : IsLeast (f '' t) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image_self Ha.2 Ha.1⟩ /-- A monotone map sends a greatest element of a set to a greatest element of its image. -/ theorem map_isGreatest (Hf : MonotoneOn f t) (Ha : IsGreatest t a) : IsGreatest (f '' t) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image_self Ha.2 Ha.1⟩ end MonotoneOn namespace AntitoneOn variable [Preorder α] [Preorder β] {f : α → β} {s t : Set α} {a : α} theorem mem_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s) : a ∈ t → f a ∈ upperBounds (f '' s) := Hf.dual_right.mem_lowerBounds_image Hst Has theorem mem_upperBounds_image_self (Hf : AntitoneOn f t) : a ∈ lowerBounds t → a ∈ t → f a ∈ upperBounds (f '' t) := Hf.dual_right.mem_lowerBounds_image_self theorem mem_lowerBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) : a ∈ upperBounds s → a ∈ t → f a ∈ lowerBounds (f '' s) := Hf.dual_right.mem_upperBounds_image Hst theorem mem_lowerBounds_image_self (Hf : AntitoneOn f t) : a ∈ upperBounds t → a ∈ t → f a ∈ lowerBounds (f '' t) := Hf.dual_right.mem_upperBounds_image_self theorem image_lowerBounds_subset_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) : f '' (lowerBounds s ∩ t) ⊆ upperBounds (f '' s) := Hf.dual_right.image_lowerBounds_subset_lowerBounds_image Hst theorem image_upperBounds_subset_lowerBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) : f '' (upperBounds s ∩ t) ⊆ lowerBounds (f '' s) := Hf.dual_right.image_upperBounds_subset_upperBounds_image Hst /-- The image under an antitone function of a set which is bounded above is bounded below. -/ theorem map_bddAbove (Hf : AntitoneOn f t) (Hst : s ⊆ t) : (upperBounds s ∩ t).Nonempty → BddBelow (f '' s) := Hf.dual_right.map_bddAbove Hst /-- The image under an antitone function of a set which is bounded below is bounded above. -/ theorem map_bddBelow (Hf : AntitoneOn f t) (Hst : s ⊆ t) : (lowerBounds s ∩ t).Nonempty → BddAbove (f '' s) := Hf.dual_right.map_bddBelow Hst /-- An antitone map sends a greatest element of a set to a least element of its image. -/ theorem map_isGreatest (Hf : AntitoneOn f t) : IsGreatest t a → IsLeast (f '' t) (f a) := Hf.dual_right.map_isGreatest /-- An antitone map sends a least element of a set to a greatest element of its image. -/ theorem map_isLeast (Hf : AntitoneOn f t) : IsLeast t a → IsGreatest (f '' t) (f a) := Hf.dual_right.map_isLeast end AntitoneOn namespace Monotone variable [Preorder α] [Preorder β] {f : α → β} (Hf : Monotone f) {a : α} {s : Set α} include Hf theorem mem_upperBounds_image (Ha : a ∈ upperBounds s) : f a ∈ upperBounds (f '' s) := forall_mem_image.2 fun _ H => Hf (Ha H) theorem mem_lowerBounds_image (Ha : a ∈ lowerBounds s) : f a ∈ lowerBounds (f '' s) := forall_mem_image.2 fun _ H => Hf (Ha H) theorem image_upperBounds_subset_upperBounds_image : f '' upperBounds s ⊆ upperBounds (f '' s) := by rintro _ ⟨a, ha, rfl⟩ exact Hf.mem_upperBounds_image ha theorem image_lowerBounds_subset_lowerBounds_image : f '' lowerBounds s ⊆ lowerBounds (f '' s) := Hf.dual.image_upperBounds_subset_upperBounds_image /-- The image under a monotone function of a set which is bounded above is bounded above. See also `BddAbove.image2`. -/ theorem map_bddAbove : BddAbove s → BddAbove (f '' s) | ⟨C, hC⟩ => ⟨f C, Hf.mem_upperBounds_image hC⟩ /-- The image under a monotone function of a set which is bounded below is bounded below. See also `BddBelow.image2`. -/ theorem map_bddBelow : BddBelow s → BddBelow (f '' s) | ⟨C, hC⟩ => ⟨f C, Hf.mem_lowerBounds_image hC⟩ /-- A monotone map sends a least element of a set to a least element of its image. -/ theorem map_isLeast (Ha : IsLeast s a) : IsLeast (f '' s) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image Ha.2⟩ /-- A monotone map sends a greatest element of a set to a greatest element of its image. -/ theorem map_isGreatest (Ha : IsGreatest s a) : IsGreatest (f '' s) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image Ha.2⟩ end Monotone namespace Antitone variable [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f) {a : α} {s : Set α} include hf theorem mem_upperBounds_image : a ∈ lowerBounds s → f a ∈ upperBounds (f '' s) := hf.dual_right.mem_lowerBounds_image theorem mem_lowerBounds_image : a ∈ upperBounds s → f a ∈ lowerBounds (f '' s) := hf.dual_right.mem_upperBounds_image theorem image_lowerBounds_subset_upperBounds_image : f '' lowerBounds s ⊆ upperBounds (f '' s) := hf.dual_right.image_lowerBounds_subset_lowerBounds_image theorem image_upperBounds_subset_lowerBounds_image : f '' upperBounds s ⊆ lowerBounds (f '' s) := hf.dual_right.image_upperBounds_subset_upperBounds_image /-- The image under an antitone function of a set which is bounded above is bounded below. -/ theorem map_bddAbove : BddAbove s → BddBelow (f '' s) := hf.dual_right.map_bddAbove /-- The image under an antitone function of a set which is bounded below is bounded above. -/ theorem map_bddBelow : BddBelow s → BddAbove (f '' s) := hf.dual_right.map_bddBelow /-- An antitone map sends a greatest element of a set to a least element of its image. -/ theorem map_isGreatest : IsGreatest s a → IsLeast (f '' s) (f a) := hf.dual_right.map_isGreatest /-- An antitone map sends a least element of a set to a greatest element of its image. -/ theorem map_isLeast : IsLeast s a → IsGreatest (f '' s) (f a) := hf.dual_right.map_isLeast end Antitone section StrictMono variable [LinearOrder α] [Preorder β] {f : α → β} {a : α} {s : Set α} lemma StrictMono.mem_upperBounds_image (hf : StrictMono f) : f a ∈ upperBounds (f '' s) ↔ a ∈ upperBounds s := by simp [upperBounds, hf.le_iff_le] lemma StrictMono.mem_lowerBounds_image (hf : StrictMono f) : f a ∈ lowerBounds (f '' s) ↔ a ∈ lowerBounds s := by simp [lowerBounds, hf.le_iff_le] lemma StrictMono.map_isLeast (hf : StrictMono f) : IsLeast (f '' s) (f a) ↔ IsLeast s a := by simp [IsLeast, hf.injective.eq_iff, hf.mem_lowerBounds_image] lemma StrictMono.map_isGreatest (hf : StrictMono f) : IsGreatest (f '' s) (f a) ↔ IsGreatest s a := by simp [IsGreatest, hf.injective.eq_iff, hf.mem_upperBounds_image] end StrictMono section StrictAnti variable [LinearOrder α] [Preorder β] {f : α → β} {a : α} {s : Set α} lemma StrictAnti.mem_upperBounds_image (hf : StrictAnti f) : f a ∈ upperBounds (f '' s) ↔ a ∈ lowerBounds s := by simp [upperBounds, lowerBounds, hf.le_iff_ge] lemma StrictAnti.mem_lowerBounds_image (hf : StrictAnti f) : f a ∈ lowerBounds (f '' s) ↔ a ∈ upperBounds s := by simp [upperBounds, lowerBounds, hf.le_iff_ge] lemma StrictAnti.map_isLeast (hf : StrictAnti f) : IsLeast (f '' s) (f a) ↔ IsGreatest s a := by simp [IsLeast, IsGreatest, hf.injective.eq_iff, hf.mem_lowerBounds_image] lemma StrictAnti.map_isGreatest (hf : StrictAnti f) : IsGreatest (f '' s) (f a) ↔ IsLeast s a := by simp [IsLeast, IsGreatest, hf.injective.eq_iff, hf.mem_upperBounds_image] end StrictAnti section Image2 variable [Preorder α] [Preorder β] [Preorder γ] {f : α → β → γ} {s : Set α} {t : Set β} {a : α} {b : β} section MonotoneMonotone variable (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Monotone (f a)) include h₀ h₁ theorem mem_upperBounds_image2 (ha : a ∈ upperBounds s) (hb : b ∈ upperBounds t) : f a b ∈ upperBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem mem_lowerBounds_image2 (ha : a ∈ lowerBounds s) (hb : b ∈ lowerBounds t) : f a b ∈ lowerBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem image2_upperBounds_upperBounds_subset : image2 f (upperBounds s) (upperBounds t) ⊆ upperBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_upperBounds_image2 h₀ h₁ ha hb theorem image2_lowerBounds_lowerBounds_subset : image2 f (lowerBounds s) (lowerBounds t) ⊆ lowerBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_lowerBounds_image2 h₀ h₁ ha hb /-- See also `Monotone.map_bddAbove`. -/ protected theorem BddAbove.image2 : BddAbove s → BddAbove t → BddAbove (image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_upperBounds_image2 h₀ h₁ ha hb⟩ /-- See also `Monotone.map_bddBelow`. -/ protected theorem BddBelow.image2 : BddBelow s → BddBelow t → BddBelow (image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_lowerBounds_image2 h₀ h₁ ha hb⟩ protected theorem IsGreatest.image2 (ha : IsGreatest s a) (hb : IsGreatest t b) : IsGreatest (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2 h₀ h₁ ha.2 hb.2⟩ protected theorem IsLeast.image2 (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2 h₀ h₁ ha.2 hb.2⟩ end MonotoneMonotone section MonotoneAntitone variable (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Antitone (f a)) include h₀ h₁ theorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds (ha : a ∈ upperBounds s) (hb : b ∈ lowerBounds t) : f a b ∈ upperBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds t) : f a b ∈ lowerBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem image2_upperBounds_lowerBounds_subset_upperBounds_image2 : image2 f (upperBounds s) (lowerBounds t) ⊆ upperBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha hb theorem image2_lowerBounds_upperBounds_subset_lowerBounds_image2 : image2 f (lowerBounds s) (upperBounds t) ⊆ lowerBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha hb theorem BddAbove.bddAbove_image2_of_bddBelow : BddAbove s → BddBelow t → BddAbove (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha hb⟩ theorem BddBelow.bddBelow_image2_of_bddAbove : BddBelow s → BddAbove t → BddBelow (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha hb⟩ theorem IsGreatest.isGreatest_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) : IsGreatest (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩ theorem IsLeast.isLeast_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) : IsLeast (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩ end MonotoneAntitone section AntitoneAntitone variable (h₀ : ∀ b, Antitone (swap f b)) (h₁ : ∀ a, Antitone (f a)) include h₀ h₁ theorem mem_upperBounds_image2_of_mem_lowerBounds (ha : a ∈ lowerBounds s) (hb : b ∈ lowerBounds t) : f a b ∈ upperBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem mem_lowerBounds_image2_of_mem_upperBounds (ha : a ∈ upperBounds s) (hb : b ∈ upperBounds t) : f a b ∈ lowerBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem image2_upperBounds_upperBounds_subset_upperBounds_image2 : image2 f (lowerBounds s) (lowerBounds t) ⊆ upperBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha hb theorem image2_lowerBounds_lowerBounds_subset_lowerBounds_image2 : image2 f (upperBounds s) (upperBounds t) ⊆ lowerBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha hb theorem BddBelow.image2_bddAbove : BddBelow s → BddBelow t → BddAbove (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha hb⟩ theorem BddAbove.image2_bddBelow : BddAbove s → BddAbove t → BddBelow (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha hb⟩ theorem IsLeast.isGreatest_image2 (ha : IsLeast s a) (hb : IsLeast t b) : IsGreatest (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩ theorem IsGreatest.isLeast_image2 (ha : IsGreatest s a) (hb : IsGreatest t b) : IsLeast (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩ end AntitoneAntitone section AntitoneMonotone variable (h₀ : ∀ b, Antitone (swap f b)) (h₁ : ∀ a, Monotone (f a)) include h₀ h₁ theorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds t) : f a b ∈ upperBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds (ha : a ∈ upperBounds s) (hb : b ∈ lowerBounds t) : f a b ∈ lowerBounds (image2 f s t) := forall_mem_image2.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy theorem image2_lowerBounds_upperBounds_subset_upperBounds_image2 : image2 f (lowerBounds s) (upperBounds t) ⊆ upperBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha hb theorem image2_upperBounds_lowerBounds_subset_lowerBounds_image2 : image2 f (upperBounds s) (lowerBounds t) ⊆ lowerBounds (image2 f s t) := image2_subset_iff.2 fun _ ha _ hb ↦ mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha hb theorem BddBelow.bddAbove_image2_of_bddAbove : BddBelow s → BddAbove t → BddAbove (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha hb⟩ theorem BddAbove.bddBelow_image2_of_bddAbove : BddAbove s → BddBelow t → BddBelow (Set.image2 f s t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ exact ⟨f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha hb⟩ theorem IsLeast.isGreatest_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) : IsGreatest (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩ theorem IsGreatest.isLeast_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) : IsLeast (Set.image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩ end AntitoneMonotone end Image2 section IsCofinalFor variable {α β : Type*} [Preorder α] [Preorder β] {s t : Set α} {f : α → β} lemma IsCofinalFor.image_of_monotone (hst : IsCofinalFor s t) (hf : Monotone f) : IsCofinalFor (f '' s) (f '' t) := by simp only [IsCofinalFor, forall_mem_image, exists_mem_image] rintro a ha obtain ⟨b, hb, hab⟩ := hst ha exact ⟨b, hb, hf hab⟩ lemma IsCofinalFor.image_of_antitone (hst : IsCofinalFor s t) (hf : Antitone f) : IsCoinitialFor (f '' s) (f '' t) := by simp only [IsCoinitialFor, forall_mem_image, exists_mem_image] rintro a ha obtain ⟨b, hb, hab⟩ := hst ha exact ⟨b, hb, hf hab⟩ lemma IsCoinitialFor.image_of_monotone (hst : IsCoinitialFor s t) (hf : Monotone f) : IsCoinitialFor (f '' s) (f '' t) := by simp only [IsCoinitialFor, forall_mem_image, exists_mem_image] rintro a ha obtain ⟨b, hb, hba⟩ := hst ha exact ⟨b, hb, hf hba⟩ lemma IsCoinitialFor.image_of_antitone (hst : IsCoinitialFor s t) (hf : Antitone f) : IsCofinalFor (f '' s) (f '' t) := by simp only [IsCofinalFor, forall_mem_image, exists_mem_image] rintro a ha obtain ⟨b, hb, hba⟩ := hst ha exact ⟨b, hb, hf hba⟩ end IsCofinalFor section Prod variable {α β : Type*} [Preorder α] [Preorder β] lemma bddAbove_prod {s : Set (α × β)} : BddAbove s ↔ BddAbove (Prod.fst '' s) ∧ BddAbove (Prod.snd '' s) := ⟨fun ⟨p, hp⟩ ↦ ⟨⟨p.1, forall_mem_image.2 fun _q hq ↦ (hp hq).1⟩, ⟨p.2, forall_mem_image.2 fun _q hq ↦ (hp hq).2⟩⟩, fun ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ ↦ ⟨⟨x, y⟩, fun _p hp ↦ ⟨hx <| mem_image_of_mem _ hp, hy <| mem_image_of_mem _ hp⟩⟩⟩ lemma bddBelow_prod {s : Set (α × β)} : BddBelow s ↔ BddBelow (Prod.fst '' s) ∧ BddBelow (Prod.snd '' s) := bddAbove_prod (α := αᵒᵈ) (β := βᵒᵈ) lemma bddAbove_range_prod {F : ι → α × β} : BddAbove (range F) ↔ BddAbove (range <| Prod.fst ∘ F) ∧ BddAbove (range <| Prod.snd ∘ F) := by simp only [bddAbove_prod, ← range_comp] lemma bddBelow_range_prod {F : ι → α × β} : BddBelow (range F) ↔ BddBelow (range <| Prod.fst ∘ F) ∧ BddBelow (range <| Prod.snd ∘ F) := bddAbove_range_prod (α := αᵒᵈ) (β := βᵒᵈ) theorem isLUB_prod {s : Set (α × β)} (p : α × β) : IsLUB s p ↔ IsLUB (Prod.fst '' s) p.1 ∧ IsLUB (Prod.snd '' s) p.2 := by refine ⟨fun H => ⟨⟨monotone_fst.mem_upperBounds_image H.1, fun a ha => ?_⟩, ⟨monotone_snd.mem_upperBounds_image H.1, fun a ha => ?_⟩⟩, fun H => ⟨?_, ?_⟩⟩ · suffices h : (a, p.2) ∈ upperBounds s from (H.2 h).1 exact fun q hq => ⟨ha <| mem_image_of_mem _ hq, (H.1 hq).2⟩ · suffices h : (p.1, a) ∈ upperBounds s from (H.2 h).2 exact fun q hq => ⟨(H.1 hq).1, ha <| mem_image_of_mem _ hq⟩ · exact fun q hq => ⟨H.1.1 <| mem_image_of_mem _ hq, H.2.1 <| mem_image_of_mem _ hq⟩ · exact fun q hq => ⟨H.1.2 <| monotone_fst.mem_upperBounds_image hq, H.2.2 <| monotone_snd.mem_upperBounds_image hq⟩ theorem isGLB_prod {s : Set (α × β)} (p : α × β) : IsGLB s p ↔ IsGLB (Prod.fst '' s) p.1 ∧ IsGLB (Prod.snd '' s) p.2 := @isLUB_prod αᵒᵈ βᵒᵈ _ _ _ _ lemma Monotone.upperBounds_image_of_directedOn_prod {γ : Type*} [Preorder γ] {g : α × β → γ} (hg : Monotone g) {d : Set (α × β)} (hd : DirectedOn (· ≤ ·) d) : upperBounds (g '' d) = upperBounds (g '' (Prod.fst '' d) ×ˢ (Prod.snd '' d)) := le_antisymm (upperBounds_mono_of_isCofinalFor (hd.isCofinalFor_fst_image_prod_snd_image.image_of_monotone hg)) (upperBounds_mono_set (image_mono subset_fst_image_prod_snd_image)) end Prod section Pi variable {π : α → Type*} [∀ a, Preorder (π a)] lemma bddAbove_pi {s : Set (∀ a, π a)} : BddAbove s ↔ ∀ a, BddAbove (Function.eval a '' s) := ⟨fun ⟨f, hf⟩ a ↦ ⟨f a, forall_mem_image.2 fun _ hg ↦ hf hg a⟩, fun h ↦ ⟨fun a ↦ (h a).some, fun _ hg a ↦ (h a).some_mem <| mem_image_of_mem _ hg⟩⟩ lemma bddBelow_pi {s : Set (∀ a, π a)} : BddBelow s ↔ ∀ a, BddBelow (Function.eval a '' s) := bddAbove_pi (π := fun a ↦ (π a)ᵒᵈ) lemma bddAbove_range_pi {F : ι → ∀ a, π a} : BddAbove (range F) ↔ ∀ a, BddAbove (range fun i ↦ F i a) := by simp only [bddAbove_pi, ← range_comp] rfl lemma bddBelow_range_pi {F : ι → ∀ a, π a} : BddBelow (range F) ↔ ∀ a, BddBelow (range fun i ↦ F i a) := bddAbove_range_pi (π := fun a ↦ (π a)ᵒᵈ) theorem isLUB_pi {s : Set (∀ a, π a)} {f : ∀ a, π a} : IsLUB s f ↔ ∀ a, IsLUB (Function.eval a '' s) (f a) := by classical refine ⟨fun H a => ⟨(Function.monotone_eval a).mem_upperBounds_image H.1, fun b hb => ?_⟩, fun H => ⟨?_, ?_⟩⟩ · suffices h : Function.update f a b ∈ upperBounds s from Function.update_self a b f ▸ H.2 h a exact fun g hg => le_update_iff.2 ⟨hb <| mem_image_of_mem _ hg, fun i _ => H.1 hg i⟩ · exact fun g hg a => (H a).1 (mem_image_of_mem _ hg) · exact fun g hg a => (H a).2 ((Function.monotone_eval a).mem_upperBounds_image hg) theorem isGLB_pi {s : Set (∀ a, π a)} {f : ∀ a, π a} : IsGLB s f ↔ ∀ a, IsGLB (Function.eval a '' s) (f a) := @isLUB_pi α (fun a => (π a)ᵒᵈ) _ s f end Pi theorem IsGLB.of_image [Preorder α] [Preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y) {s : Set α} {x : α} (hx : IsGLB (f '' s) (f x)) : IsGLB s x := ⟨fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy => hf.1 <| hx.2 <| Monotone.mem_lowerBounds_image (fun _ _ => hf.2) hy⟩ theorem IsLUB.of_image [Preorder α] [Preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y) {s : Set α} {x : α} (hx : IsLUB (f '' s) (f x)) : IsLUB s x := ⟨fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy => hf.1 <| hx.2 <| Monotone.mem_upperBounds_image (fun _ _ => hf.2) hy⟩ lemma BddAbove.range_mono [Preorder β] {f : α → β} (g : α → β) (h : ∀ a, f a ≤ g a) (hbdd : BddAbove (range g)) : BddAbove (range f) := by obtain ⟨C, hC⟩ := hbdd use C rintro - ⟨x, rfl⟩ exact (h x).trans (hC <| mem_range_self x) lemma BddBelow.range_mono [Preorder β] (f : α → β) {g : α → β} (h : ∀ a, f a ≤ g a) (hbdd : BddBelow (range f)) : BddBelow (range g) := BddAbove.range_mono (β := βᵒᵈ) f h hbdd lemma BddAbove.range_comp {γ : Type*} [Preorder β] [Preorder γ] {f : α → β} {g : β → γ} (hf : BddAbove (range f)) (hg : Monotone g) : BddAbove (range (fun x => g (f x))) := by change BddAbove (range (g ∘ f)) simpa only [Set.range_comp] using hg.map_bddAbove hf lemma BddBelow.range_comp {γ : Type*} [Preorder β] [Preorder γ] {f : α → β} {g : β → γ} (hf : BddBelow (range f)) (hg : Monotone g) : BddBelow (range (fun x => g (f x))) := by change BddBelow (range (g ∘ f)) simpa only [Set.range_comp] using hg.map_bddBelow hf
.lake/packages/mathlib/Mathlib/Order/Bounds/Basic.lean
import Mathlib.Order.Bounds.Defs import Mathlib.Order.Directed import Mathlib.Order.BoundedOrder.Monotone import Mathlib.Order.Interval.Set.Basic /-! # Upper / lower bounds In this file we prove various lemmas about upper/lower bounds of a set: monotonicity, behaviour under `∪`, `∩`, `insert`, and provide formulas for `∅`, `univ`, and intervals. -/ open Function Set open OrderDual (toDual ofDual) variable {α β γ : Type*} section variable [Preorder α] {s t u : Set α} {a b : α} theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a := Iff.rfl theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x := Iff.rfl lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x := Iff.rfl theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y := Iff.rfl theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top @[simp] theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s := and_iff_left <| bot_mem_lowerBounds _ @[simp] theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s := and_iff_left <| top_mem_upperBounds _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x` is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/ theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by simp [BddAbove, upperBounds, Set.Nonempty] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x` is not less than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/ theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y := @not_bddAbove_iff' αᵒᵈ _ _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater than `x`. A version for preorders is called `not_bddAbove_iff'`. -/ theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by simp only [not_bddAbove_iff', not_le] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less than `x`. A version for preorders is called `not_bddBelow_iff'`. -/ theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x := @not_bddAbove_iff αᵒᵈ _ _ @[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl @[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} : BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} : BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) := h theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) := h theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) := h theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) := h theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) := h theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) := h /-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/ abbrev IsLeast.orderBot (h : IsLeast s a) : OrderBot s where bot := ⟨a, h.1⟩ bot_le := Subtype.forall.2 h.2 /-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/ abbrev IsGreatest.orderTop (h : IsGreatest s a) : OrderTop s where top := ⟨a, h.1⟩ le_top := Subtype.forall.2 h.2 theorem isLUB_congr (h : upperBounds s = upperBounds t) : IsLUB s a ↔ IsLUB t a := by rw [IsLUB, IsLUB, h] theorem isGLB_congr (h : lowerBounds s = lowerBounds t) : IsGLB s a ↔ IsGLB t a := by rw [IsGLB, IsGLB, h] @[simp] lemma IsCofinalFor.of_subset (hst : s ⊆ t) : IsCofinalFor s t := fun a ha ↦ ⟨a, hst ha, le_rfl⟩ @[simp] lemma IsCoinitialFor.of_subset (hst : s ⊆ t) : IsCoinitialFor s t := fun a ha ↦ ⟨a, hst ha, le_rfl⟩ alias HasSubset.Subset.iscofinalfor := IsCofinalFor.of_subset alias HasSubset.Subset.iscoinitialfor := IsCoinitialFor.of_subset @[refl] protected lemma IsCofinalFor.rfl : IsCofinalFor s s := .of_subset .rfl @[refl] protected lemma IsCoinitialFor.rfl : IsCoinitialFor s s := .of_subset .rfl protected lemma IsCofinalFor.trans (hst : IsCofinalFor s t) (htu : IsCofinalFor t u) : IsCofinalFor s u := fun _a ha ↦ let ⟨_b, hb, hab⟩ := hst ha; let ⟨c, hc, hbc⟩ := htu hb; ⟨c, hc, hab.trans hbc⟩ protected lemma IsCoinitialFor.trans (hst : IsCoinitialFor s t) (htu : IsCoinitialFor t u) : IsCoinitialFor s u := fun _a ha ↦ let ⟨_b, hb, hba⟩ := hst ha; let ⟨c, hc, hcb⟩ := htu hb; ⟨c, hc, hcb.trans hba⟩ protected lemma IsCofinalFor.mono_left (hst : s ⊆ t) (htu : IsCofinalFor t u) : IsCofinalFor s u := hst.iscofinalfor.trans htu protected lemma IsCoinitialFor.mono_left (hst : s ⊆ t) (htu : IsCoinitialFor t u) : IsCoinitialFor s u := hst.iscoinitialfor.trans htu protected lemma IsCofinalFor.mono_right (htu : t ⊆ u) (hst : IsCofinalFor s t) : IsCofinalFor s u := hst.trans htu.iscofinalfor protected lemma IsCoinitialFor.mono_right (htu : t ⊆ u) (hst : IsCoinitialFor s t) : IsCoinitialFor s u := hst.trans htu.iscoinitialfor lemma DirectedOn.isCofinalFor_fst_image_prod_snd_image {β : Type*} [Preorder β] {s : Set (α × β)} (hs : DirectedOn (· ≤ ·) s) : IsCofinalFor ((Prod.fst '' s) ×ˢ (Prod.snd '' s)) s := by rintro ⟨_, _⟩ ⟨⟨x, hx, rfl⟩, y, hy, rfl⟩ obtain ⟨z, hz, hxz, hyz⟩ := hs _ hx _ hy exact ⟨z, hz, hxz.1, hyz.2⟩ /-! ### Monotonicity -/ theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s := fun _ hb _ h => hb <| hst h theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s := fun _ hb _ h => hb <| hst h @[gcongr] lemma upperBounds_mono_of_isCofinalFor (hst : IsCofinalFor s t) : upperBounds t ⊆ upperBounds s := fun _a ha _b hb ↦ let ⟨_c, hc, hbc⟩ := hst hb; hbc.trans (ha hc) @[gcongr] lemma lowerBounds_mono_of_isCoinitialFor (hst : IsCoinitialFor s t) : lowerBounds t ⊆ lowerBounds s := fun _a ha _b hb ↦ let ⟨_c, hc, hcb⟩ := hst hb; hcb.trans' (ha hc) theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s := fun ha _ h => le_trans (ha h) hab theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s := fun hb _ h => le_trans hab (hb h) theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds t → b ∈ upperBounds s := fun ha => upperBounds_mono_set hst <| upperBounds_mono_mem hab ha theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb => lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb /-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/ @[gcongr] theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s := Nonempty.mono <| upperBounds_mono_set h /-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/ @[gcongr] theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s := Nonempty.mono <| lowerBounds_mono_set h /-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsLUB t a := ⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩ /-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsGLB t a := hs.dual.of_subset_of_superset hp hst htp theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a := hb.2 (hst ha.1) theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b := hb.2 (hst ha.1) theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b := IsLeast.mono hb ha <| upperBounds_mono_set hst theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a := IsGreatest.mono hb ha <| lowerBounds_mono_set hst theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) := fun _ hx _ hy => hy hx theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) := fun _ hx _ hy => hy hx theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) := hs.mono (subset_upperBounds_lowerBounds s) theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) := hs.mono (subset_lowerBounds_upperBounds s) /-! ### Conversions -/ theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a := ⟨h.2, fun _ hb => hb h.1⟩ theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a := ⟨h.2, fun _ hb => hb h.1⟩ theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a := Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩ theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a := h.dual.upperBounds_eq theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a := h.isGLB.lowerBounds_eq theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a := h.isLUB.upperBounds_eq theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b := ⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩ theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x := h.dual.lt_iff theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by rw [h.upperBounds_eq] rfl theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by rw [h.lowerBounds_eq] rfl theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s := ⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩ theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s := @isLUB_iff_le_iff αᵒᵈ _ _ _ /-- If `s` has a least upper bound, then it is bounded above. -/ theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s := ⟨a, h.1⟩ /-- If `s` has a greatest lower bound, then it is bounded below. -/ theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s := ⟨a, h.1⟩ /-- If `s` has a greatest element, then it is bounded above. -/ theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s := ⟨a, h.2⟩ /-- If `s` has a least element, then it is bounded below. -/ theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s := ⟨a, h.2⟩ theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty := ⟨a, h.1⟩ theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty := ⟨a, h.1⟩ /-! ### Union and intersection -/ @[simp] theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t := Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩) fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht @[simp] theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t := @upperBounds_union αᵒᵈ _ s t theorem union_upperBounds_subset_upperBounds_inter : upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) := union_subset (upperBounds_mono_set inter_subset_left) (upperBounds_mono_set inter_subset_right) theorem union_lowerBounds_subset_lowerBounds_inter : lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) := @union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t theorem isLeast_union_iff {a : α} {s t : Set α} : IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc] theorem isGreatest_union_iff : IsGreatest (s ∪ t) a ↔ IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a := @isLeast_union_iff αᵒᵈ _ a s t /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) := h.mono inter_subset_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) := h.mono inter_subset_right /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) := h.mono inter_subset_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) := h.mono inter_subset_right /-- In a directed order, the union of bounded above sets is bounded above. -/ theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove s → BddAbove t → BddAbove (s ∪ t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b rw [BddAbove, upperBounds_union] exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩ /-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/ theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t := ⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h => h.1.union h.2⟩ /-- In a codirected order, the union of bounded below sets is bounded below. -/ theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow s → BddBelow t → BddBelow (s ∪ t) := @BddAbove.union αᵒᵈ _ _ _ _ /-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/ theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t := @bddAbove_union αᵒᵈ _ _ _ _ /-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`, then `a ⊔ b` is the least upper bound of `s ∪ t`. -/ theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) : IsLUB (s ∪ t) (a ⊔ b) := ⟨fun _ h => h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h, fun _ hc => sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩ /-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`, then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/ theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁) (ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) := hs.dual.union ht /-- If `a` is the least element of `s` and `b` is the least element of `t`, then `min a b` is the least element of `s ∪ t`. -/ theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩ /-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`, then `max a b` is the greatest element of `s ∪ t`. -/ theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a) (hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩ theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) : IsLUB (s ∩ Ici b) a := ⟨fun _ hx => ha.1 hx.1, fun c hc => have hbc : b ≤ c := hc ⟨hb, le_rfl⟩ ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩ theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) : IsGLB (s ∩ Iic b) a := ha.dual.inter_Ici_of_mem hb theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) : BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by rw [bddAbove_def, exists_ge_and_iff_exists] exact Monotone.ball fun x _ => monotone_le theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) : BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := bddAbove_iff_exists_ge (toDual x₀) theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) : ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := (bddAbove_iff_exists_ge x₀).mp hs theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) : ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := (bddBelow_iff_exists_le x₀).mp hs /-! ### Specific sets #### Unbounded intervals -/ theorem isLeast_Ici : IsLeast (Ici a) a := ⟨left_mem_Ici, fun _ => id⟩ theorem isGreatest_Iic : IsGreatest (Iic a) a := ⟨right_mem_Iic, fun _ => id⟩ theorem isLUB_Iic : IsLUB (Iic a) a := isGreatest_Iic.isLUB theorem isGLB_Ici : IsGLB (Ici a) a := isLeast_Ici.isGLB theorem upperBounds_Iic : upperBounds (Iic a) = Ici a := isLUB_Iic.upperBounds_eq theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a := isGLB_Ici.lowerBounds_eq theorem bddAbove_Iic : BddAbove (Iic a) := isLUB_Iic.bddAbove theorem bddBelow_Ici : BddBelow (Ici a) := isGLB_Ici.bddBelow theorem bddAbove_Iio : BddAbove (Iio a) := ⟨a, fun _ hx => le_of_lt hx⟩ theorem bddBelow_Ioi : BddBelow (Ioi a) := ⟨a, fun _ hx => le_of_lt hx⟩ theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a := (isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b := @lub_Iio_le αᵒᵈ _ _ a hb theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) : j = i ∨ Iio i = Iic j := by rcases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i | hj_lt_i · exact Or.inl hj_eq_i · right exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩ theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) : j = i ∨ Ioi i = Ici j := @lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj section variable [LinearOrder γ] theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by by_cases! h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i · obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩ · refine ⟨i, fun j hj => le_of_lt hj, ?_⟩ rw [mem_lowerBounds] exact h_exists_lt theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j := @exists_lub_Iio γᵒᵈ _ i variable [DenselyOrdered γ] theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a := ⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_lt_imp_le_of_dense hy⟩ theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a := @isLUB_Iio γᵒᵈ _ _ a theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a := isLUB_Iio.upperBounds_eq theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a := isGLB_Ioi.lowerBounds_eq end /-! #### Singleton -/ @[simp] theorem isGreatest_singleton : IsGreatest {a} a := ⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩ @[simp] theorem isLeast_singleton : IsLeast {a} a := @isGreatest_singleton αᵒᵈ _ a @[simp] theorem isLUB_singleton : IsLUB {a} a := isGreatest_singleton.isLUB @[simp] theorem isGLB_singleton : IsGLB {a} a := isLeast_singleton.isGLB @[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove @[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow @[simp] theorem upperBounds_singleton : upperBounds {a} = Ici a := isLUB_singleton.upperBounds_eq @[simp] theorem lowerBounds_singleton : lowerBounds {a} = Iic a := isGLB_singleton.lowerBounds_eq /-! #### Bounded intervals -/ @[simp] lemma bddAbove_Icc : BddAbove (Icc a b) := ⟨b, fun _ => And.right⟩ @[simp] lemma bddBelow_Icc : BddBelow (Icc a b) := ⟨a, fun _ => And.left⟩ @[simp] lemma bddAbove_Ico : BddAbove (Ico a b) := bddAbove_Icc.mono Ico_subset_Icc_self @[simp] lemma bddBelow_Ico : BddBelow (Ico a b) := bddBelow_Icc.mono Ico_subset_Icc_self @[simp] lemma bddAbove_Ioc : BddAbove (Ioc a b) := bddAbove_Icc.mono Ioc_subset_Icc_self @[simp] lemma bddBelow_Ioc : BddBelow (Ioc a b) := bddBelow_Icc.mono Ioc_subset_Icc_self @[simp] lemma bddAbove_Ioo : BddAbove (Ioo a b) := bddAbove_Icc.mono Ioo_subset_Icc_self @[simp] lemma bddBelow_Ioo : BddBelow (Ioo a b) := bddBelow_Icc.mono Ioo_subset_Icc_self theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b := ⟨right_mem_Icc.2 h, fun _ => And.right⟩ theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b := (isGreatest_Icc h).isLUB theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b := (isLUB_Icc h).upperBounds_eq theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a := ⟨left_mem_Icc.2 h, fun _ => And.left⟩ theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a := (isLeast_Icc h).isGLB theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a := (isGLB_Icc h).lowerBounds_eq theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b := ⟨right_mem_Ioc.2 h, fun _ => And.right⟩ theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b := (isGreatest_Ioc h).isLUB theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b := (isLUB_Ioc h).upperBounds_eq theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a := ⟨left_mem_Ico.2 h, fun _ => And.left⟩ theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a := (isLeast_Ico h).isGLB theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a := (isGLB_Ico h).lowerBounds_eq section variable [SemilatticeSup γ] [DenselyOrdered γ] theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a := ⟨fun _ hx => hx.1.le, fun x hx => by rcases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ | h₂ · exact h₁.symm ▸ le_sup_left obtain ⟨y, lty, ylt⟩ := exists_between h₂ apply (not_lt_of_ge (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim obtain ⟨u, au, ub⟩ := exists_between h apply (hx ⟨au, ub⟩).trans ub.le⟩ theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a := (isGLB_Ioo hab).lowerBounds_eq theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a := (isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a := (isGLB_Ioc hab).lowerBounds_eq end section variable [SemilatticeInf γ] [DenselyOrdered γ] theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by simpa only [Ioo_toDual] using isGLB_Ioo hab.dual theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b := (isLUB_Ioo hab).upperBounds_eq theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by simpa only [Ioc_toDual] using isGLB_Ioc hab.dual theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b := (isLUB_Ico hab).upperBounds_eq end theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a := Iff.rfl theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a := Iff.rfl theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici, bddAbove_iff_subset_Iic, exists_and_left, exists_and_right] /-! #### Univ -/ @[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by simp [IsGreatest, mem_upperBounds, IsTop] theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ := isGreatest_univ_iff.2 isTop_top @[simp] theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] : upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top] theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ := isGreatest_univ.isLUB @[simp] theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] : lowerBounds (univ : Set γ) = {⊥} := @OrderTop.upperBounds_univ γᵒᵈ _ _ @[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a := @isGreatest_univ_iff αᵒᵈ _ _ theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ := @isGreatest_univ αᵒᵈ _ _ theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ := isLeast_univ.isGLB @[simp] theorem NoTopOrder.upperBounds_univ [NoTopOrder α] : upperBounds (univ : Set α) = ∅ := eq_empty_of_subset_empty fun b hb => not_isTop b fun x => hb (mem_univ x) @[simp] theorem NoBotOrder.lowerBounds_univ [NoBotOrder α] : lowerBounds (univ : Set α) = ∅ := @NoTopOrder.upperBounds_univ αᵒᵈ _ _ @[simp] theorem not_bddAbove_univ [NoTopOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove] @[simp] theorem not_bddBelow_univ [NoBotOrder α] : ¬BddBelow (univ : Set α) := @not_bddAbove_univ αᵒᵈ _ _ /-! #### Empty set -/ @[simp] theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff] @[simp] theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ := @upperBounds_empty αᵒᵈ _ @[simp] theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by simp only [BddAbove, upperBounds_empty, univ_nonempty] @[simp] theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by simp only [BddBelow, lowerBounds_empty, univ_nonempty] @[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by simp [IsGLB] @[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a := @isGLB_empty_iff αᵒᵈ _ _ theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) := isGLB_empty_iff.2 isTop_top theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) := @isGLB_empty αᵒᵈ _ _ theorem IsLUB.nonempty [NoBotOrder α] (hs : IsLUB s a) : s.Nonempty := nonempty_iff_ne_empty.2 fun h => not_isBot a fun _ => hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _ theorem IsGLB.nonempty [NoTopOrder α] (hs : IsGLB s a) : s.Nonempty := hs.dual.nonempty theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty := (Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1 theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty := @nonempty_of_not_bddAbove αᵒᵈ _ _ _ h /-! #### insert -/ /-- Adding a point to a set preserves its boundedness above. -/ @[simp] theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} : BddAbove (insert a s) ↔ BddAbove s := by simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and] protected theorem BddAbove.insert [IsDirected α (· ≤ ·)] {s : Set α} (a : α) : BddAbove s → BddAbove (insert a s) := bddAbove_insert.2 /-- Adding a point to a set preserves its boundedness below. -/ @[simp] theorem bddBelow_insert [IsDirected α (· ≥ ·)] {s : Set α} {a : α} : BddBelow (insert a s) ↔ BddBelow s := by simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and] protected theorem BddBelow.insert [IsDirected α (· ≥ ·)] {s : Set α} (a : α) : BddBelow s → BddBelow (insert a s) := bddBelow_insert.2 protected theorem IsLUB.insert [SemilatticeSup γ] (a) {b} {s : Set γ} (hs : IsLUB s b) : IsLUB (insert a s) (a ⊔ b) := by rw [insert_eq] exact isLUB_singleton.union hs protected theorem IsGLB.insert [SemilatticeInf γ] (a) {b} {s : Set γ} (hs : IsGLB s b) : IsGLB (insert a s) (a ⊓ b) := by rw [insert_eq] exact isGLB_singleton.union hs protected theorem IsGreatest.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsGreatest s b) : IsGreatest (insert a s) (max a b) := by rw [insert_eq] exact isGreatest_singleton.union hs protected theorem IsLeast.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsLeast s b) : IsLeast (insert a s) (min a b) := by rw [insert_eq] exact isLeast_singleton.union hs @[simp] theorem upperBounds_insert (a : α) (s : Set α) : upperBounds (insert a s) = Ici a ∩ upperBounds s := by rw [insert_eq, upperBounds_union, upperBounds_singleton] @[simp] theorem lowerBounds_insert (a : α) (s : Set α) : lowerBounds (insert a s) = Iic a ∩ lowerBounds s := by rw [insert_eq, lowerBounds_union, lowerBounds_singleton] /-- When there is a global maximum, every set is bounded above. -/ @[simp] protected theorem OrderTop.bddAbove [OrderTop α] (s : Set α) : BddAbove s := ⟨⊤, fun a _ => OrderTop.le_top a⟩ /-- When there is a global minimum, every set is bounded below. -/ @[simp] protected theorem OrderBot.bddBelow [OrderBot α] (s : Set α) : BddBelow s := ⟨⊥, fun a _ => OrderBot.bot_le a⟩ /-- Sets are automatically bounded or cobounded in complete lattices. To use the same statements in complete and conditionally complete lattices but let automation fill automatically the boundedness proofs in complete lattices, we use the tactic `bddDefault` in the statements, in the form `(hA : BddAbove A := by bddDefault)`. -/ macro "bddDefault" : tactic => `(tactic| first | apply OrderTop.bddAbove | apply OrderBot.bddBelow) /-! #### Pair -/ theorem isLUB_pair [SemilatticeSup γ] {a b : γ} : IsLUB {a, b} (a ⊔ b) := isLUB_singleton.insert _ theorem isGLB_pair [SemilatticeInf γ] {a b : γ} : IsGLB {a, b} (a ⊓ b) := isGLB_singleton.insert _ theorem isLeast_pair [LinearOrder γ] {a b : γ} : IsLeast {a, b} (min a b) := isLeast_singleton.insert _ theorem isGreatest_pair [LinearOrder γ] {a b : γ} : IsGreatest {a, b} (max a b) := isGreatest_singleton.insert _ /-! #### Lower/upper bounds -/ @[simp] theorem isLUB_lowerBounds : IsLUB (lowerBounds s) a ↔ IsGLB s a := ⟨fun H => ⟨fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1⟩, IsGreatest.isLUB⟩ @[simp] theorem isGLB_upperBounds : IsGLB (upperBounds s) a ↔ IsLUB s a := @isLUB_lowerBounds αᵒᵈ _ _ _ end /-! ### (In)equalities with the least upper bound and the greatest lower bound -/ section Preorder variable [Preorder α] [Preorder β] {s : Set α} {t : Set β} {a b : α} theorem lowerBounds_le_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : s.Nonempty → a ≤ b | ⟨_, hc⟩ => le_trans (ha hc) (hb hc) theorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a ≤ b := lowerBounds_le_upperBounds ha.1 hb.1 hs theorem isLUB_lt_iff (ha : IsLUB s a) : a < b ↔ ∃ c ∈ upperBounds s, c < b := ⟨fun hb => ⟨a, ha.1, hb⟩, fun ⟨_, hcs, hcb⟩ => lt_of_le_of_lt (ha.2 hcs) hcb⟩ theorem lt_isGLB_iff (ha : IsGLB s a) : b < a ↔ ∃ c ∈ lowerBounds s, b < c := isLUB_lt_iff ha.dual theorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b ≤ a) (hx : x ∈ s) (hy : y ∈ s) : x ≤ y := calc x ≤ b := hb.1 hx _ ≤ a := hab _ ≤ y := ha.1 hy @[simp] lemma upperBounds_prod (hs : s.Nonempty) (ht : t.Nonempty) : upperBounds (s ×ˢ t) = upperBounds s ×ˢ upperBounds t := by ext; rw [← nonempty_coe_sort] at hs ht; aesop (add simp [upperBounds, Prod.le_def, forall_and]) @[simp] lemma lowerBounds_prod (hs : s.Nonempty) (ht : t.Nonempty) : lowerBounds (s ×ˢ t) = lowerBounds s ×ˢ lowerBounds t := by ext; rw [← nonempty_coe_sort] at hs ht; aesop (add simp [lowerBounds, Prod.le_def, forall_and]) lemma IsLUB.prod {b : β} (hs : s.Nonempty) (ht : t.Nonempty) (ha : IsLUB s a) (hb : IsLUB t b) : IsLUB (s ×ˢ t) (a, b) := by simp_all +contextual [IsLUB, IsLeast, lowerBounds] lemma IsGLB.prod {b : β} (hs : s.Nonempty) (ht : t.Nonempty) (ha : IsGLB s a) (hb : IsGLB t b) : IsGLB (s ×ˢ t) (a, b) := by simp_all +contextual [IsGLB, IsGreatest, upperBounds] end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} {a b : α} theorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b := le_antisymm (Ha.right Hb.left) (Hb.right Ha.left) theorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b ↔ a = b := Iff.intro Ha.unique fun h => h ▸ Ha theorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b := le_antisymm (Hb.right Ha.left) (Ha.right Hb.left) theorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b ↔ a = b := Iff.intro Ha.unique fun h => h ▸ Ha theorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b := IsLeast.unique Ha Hb theorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b := IsGreatest.unique Ha Hb theorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b ≤ a) : s.Subsingleton := fun _ hx _ hy => le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx) theorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x ∈ s) (Hy : y ∈ s) (Hxy : x ≠ y) : a < b := lt_iff_le_not_ge.2 ⟨lowerBounds_le_upperBounds Ha.1 Hb.1 ⟨x, Hx⟩, fun hab => Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy⟩ end PartialOrder section LinearOrder variable [LinearOrder α] {s : Set α} {a b : α} theorem lt_isLUB_iff (h : IsLUB s a) : b < a ↔ ∃ c ∈ s, b < c := by simp_rw [← not_le, isLUB_le_iff h, mem_upperBounds, not_forall, not_le, exists_prop] theorem isGLB_lt_iff (h : IsGLB s a) : a < b ↔ ∃ c ∈ s, c < b := lt_isLUB_iff h.dual theorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : ∃ c ∈ s, b < c ∧ c ≤ a := let ⟨c, hcs, hbc⟩ := (lt_isLUB_iff h).1 hb ⟨c, hcs, hbc, h.1 hcs⟩ theorem IsLUB.exists_between' (h : IsLUB s a) (h' : a ∉ s) (hb : b < a) : ∃ c ∈ s, b < c ∧ c < a := let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb ⟨c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac ▸ hcs⟩ theorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : ∃ c ∈ s, a ≤ c ∧ c < b := let ⟨c, hcs, hbc⟩ := (isGLB_lt_iff h).1 hb ⟨c, hcs, h.1 hcs, hbc⟩ theorem IsGLB.exists_between' (h : IsGLB s a) (h' : a ∉ s) (hb : a < b) : ∃ c ∈ s, a < c ∧ c < b := let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb ⟨c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm ▸ hcs, hcb⟩ end LinearOrder theorem isGreatest_himp [GeneralizedHeytingAlgebra α] (a b : α) : IsGreatest {w | w ⊓ a ≤ b} (a ⇨ b) := by simp [IsGreatest, mem_upperBounds] theorem isLeast_sdiff [GeneralizedCoheytingAlgebra α] (a b : α) : IsLeast {w | a ≤ b ⊔ w} (a \ b) := by simp [IsLeast, mem_lowerBounds] theorem isGreatest_compl [HeytingAlgebra α] (a : α) : IsGreatest {w | Disjoint w a} (aᶜ) := by simpa only [himp_bot, disjoint_iff_inf_le] using isGreatest_himp a ⊥ theorem isLeast_hnot [CoheytingAlgebra α] (a : α) : IsLeast {w | Codisjoint a w} (¬a) := by simpa only [CoheytingAlgebra.top_sdiff, codisjoint_iff_le_sup] using isLeast_sdiff ⊤ a instance Nat.instDecidableIsLeast (p : ℕ → Prop) (n : ℕ) [DecidablePred p] : Decidable (IsLeast { n : ℕ | p n } n) := decidable_of_iff (p n ∧ ∀ k < n, ¬p k) <| .and .rfl <| by simp [mem_lowerBounds, @imp_not_comm _ (p _)]
.lake/packages/mathlib/Mathlib/Order/Bounds/Defs.lean
import Mathlib.Data.Set.Defs import Mathlib.Tactic.TypeStar /-! # Definitions about upper/lower bounds In this file we define: * `upperBounds`, `lowerBounds` : the set of upper bounds (resp., lower bounds) of a set; * `BddAbove s`, `BddBelow s` : the set `s` is bounded above (resp., below), i.e., the set of upper (resp., lower) bounds of `s` is nonempty; * `IsLeast s a`, `IsGreatest s a` : `a` is a least (resp., greatest) element of `s`; for a partial order, it is unique if exists; * `IsLUB s a`, `IsGLB s a` : `a` is a least upper bound (resp., a greatest lower bound) of `s`; for a partial order, it is unique if exists. * `IsCofinal s`: for every `a`, there exists a member of `s` greater or equal to it. * `IsCofinalFor s t` : for all `a ∈ s` there exists `b ∈ t` such that `a ≤ b` * `IsCoinitialFor s t` : for all `a ∈ s` there exists `b ∈ t` such that `b ≤ a` -/ variable {α : Type*} [LE α] /-- The set of upper bounds of a set. -/ def upperBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → a ≤ x } /-- The set of lower bounds of a set. -/ def lowerBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → x ≤ a } /-- A set is bounded above if there exists an upper bound. -/ def BddAbove (s : Set α) := (upperBounds s).Nonempty /-- A set is bounded below if there exists a lower bound. -/ def BddBelow (s : Set α) := (lowerBounds s).Nonempty /-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/ def IsLeast (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ lowerBounds s /-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists. -/ def IsGreatest (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ upperBounds s /-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/ def IsLUB (s : Set α) : α → Prop := IsLeast (upperBounds s) /-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/ def IsGLB (s : Set α) : α → Prop := IsGreatest (lowerBounds s) /-- A set `s` is said to be cofinal for a set `t` if, for all `a ∈ s` there exists `b ∈ t` such that `a ≤ b`. -/ def IsCofinalFor (s t : Set α) := ∀ ⦃a⦄, a ∈ s → ∃ b ∈ t, a ≤ b /-- A set `s` is said to be coinitial for a set `t` if, for all `a ∈ s` there exists `b ∈ t` such that `b ≤ a`. -/ def IsCoinitialFor (s t : Set α) := ∀ ⦃a⦄, a ∈ s → ∃ b ∈ t, b ≤ a /-- A set is cofinal when for every `x : α` there exists `y ∈ s` with `x ≤ y`. -/ def IsCofinal (s : Set α) : Prop := ∀ x, ∃ y ∈ s, x ≤ y
.lake/packages/mathlib/Mathlib/Order/Bounds/Lattice.lean
import Mathlib.Data.Set.Lattice.Image /-! # Unions and intersections of bounds Some results about upper and lower bounds over collections of sets. ## Implementation notes In a separate file as we need to import `Mathlib/Data/Set/Lattice.lean`. -/ variable {α : Type*} [Preorder α] {ι : Sort*} {s : ι → Set α} open Set theorem gc_upperBounds_lowerBounds : GaloisConnection (OrderDual.toDual ∘ upperBounds : Set α → (Set α)ᵒᵈ) (lowerBounds ∘ OrderDual.ofDual : (Set α)ᵒᵈ → Set α) := by simpa [GaloisConnection, subset_def, mem_upperBounds, mem_lowerBounds] using fun S T ↦ forall₂_swap @[simp] theorem upperBounds_iUnion : upperBounds (⋃ i, s i) = ⋂ i, upperBounds (s i) := gc_upperBounds_lowerBounds.l_iSup @[simp] theorem lowerBounds_iUnion : lowerBounds (⋃ i, s i) = ⋂ i, lowerBounds (s i) := gc_upperBounds_lowerBounds.u_iInf theorem isLUB_iUnion_iff_of_isLUB {u : ι → α} (hs : ∀ i, IsLUB (s i) (u i)) (c : α) : IsLUB (Set.range u) c ↔ IsLUB (⋃ i, s i) c := by refine isLUB_congr ?_ simp_rw [range_eq_iUnion, upperBounds_iUnion, upperBounds_singleton, (hs _).upperBounds_eq] theorem isGLB_iUnion_iff_of_isLUB {u : ι → α} (hs : ∀ i, IsGLB (s i) (u i)) (c : α) : IsGLB (Set.range u) c ↔ IsGLB (⋃ i, s i) c := by refine isGLB_congr ?_ simp_rw [range_eq_iUnion, lowerBounds_iUnion, lowerBounds_singleton, (hs _).lowerBounds_eq]
.lake/packages/mathlib/Mathlib/Order/Atoms/Finite.lean
import Mathlib.Data.Set.Finite.Lattice import Mathlib.Order.Atoms import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.Preorder.Finite /-! # Atoms, Coatoms, Simple Lattices, and Finiteness This module contains some results on atoms and simple lattices in the finite context. ## Main results * `Finite.to_isAtomic`, `Finite.to_isCoatomic`: Finite partial orders with bottom resp. top are atomic resp. coatomic. -/ variable {α β : Type*} namespace IsSimpleOrder variable [LE α] [BoundedOrder α] [IsSimpleOrder α] section DecidableEq /-- It is important that `IsSimpleOrder` is the last type-class argument of this instance, so that type-class inference fails quickly if it doesn't apply. Note that as of 2025-08-13, this is false. Could someone investigate? -/ scoped instance (priority := 200) [DecidableEq α] : Fintype α := Fintype.ofEquiv Bool equivBool.symm end DecidableEq scoped instance (priority := 200) : Finite α := by classical infer_instance end IsSimpleOrder namespace Fintype namespace IsSimpleOrder open scoped _root_.IsSimpleOrder variable [LE α] [BoundedOrder α] [IsSimpleOrder α] [DecidableEq α] theorem univ : (Finset.univ : Finset α) = {⊤, ⊥} := by change Finset.map _ (Finset.univ : Finset Bool) = _ rw [Fintype.univ_bool] simp only [Finset.map_insert, Function.Embedding.coeFn_mk, Finset.map_singleton] rfl theorem card : Fintype.card α = 2 := (Fintype.ofEquiv_card _).trans Fintype.card_bool end IsSimpleOrder end Fintype namespace Bool instance : IsSimpleOrder Bool := ⟨fun a => by rw [← Finset.mem_singleton, Or.comm, ← Finset.mem_insert, top_eq_true, bot_eq_false, ← Fintype.univ_bool] apply Finset.mem_univ⟩ end Bool section Fintype open Finset -- see Note [lower instance priority] instance (priority := 100) Finite.to_isCoatomic [PartialOrder α] [OrderTop α] [Finite α] : IsCoatomic α := IsStronglyCoatomic.toIsCoatomic α -- see Note [lower instance priority] instance (priority := 100) Finite.to_isAtomic [PartialOrder α] [OrderBot α] [Finite α] : IsAtomic α := isCoatomic_dual_iff_isAtomic.mp Finite.to_isCoatomic end Fintype section LocallyFinite variable [Preorder α] [LocallyFiniteOrder α] instance : IsStronglyAtomic α where exists_covBy_le_of_lt a b hab := by obtain ⟨x, hx, hxmin⟩ := (LocallyFiniteOrder.finsetIoc a b).exists_minimal ⟨b, by simpa [LocallyFiniteOrder.finset_mem_Ioc]⟩ simp only [LocallyFiniteOrder.finset_mem_Ioc] at hx hxmin exact ⟨x, ⟨hx.1, fun c hac hcx ↦ hcx.not_ge <| hxmin ⟨hac, hcx.le.trans hx.2⟩ hcx.le⟩, hx.2⟩ instance : IsStronglyCoatomic α := by rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; infer_instance end LocallyFinite section IsStronglyAtomic variable [PartialOrder α] {a : α} theorem exists_covby_infinite_Ici_of_infinite_Ici [IsStronglyAtomic α] (ha : (Set.Ici a).Infinite) (hfin : {x | a ⋖ x}.Finite) : ∃ b, a ⋖ b ∧ (Set.Ici b).Infinite := by by_contra! h refine ((hfin.biUnion (t := Set.Ici) (by simpa using h)).subset (fun b hb ↦ ?_)).not_infinite (ha.diff (Set.finite_singleton a)) obtain ⟨x, hax, hxb⟩ := ((show a ≤ b from hb.1).lt_of_ne (Ne.symm hb.2)).exists_covby_le exact Set.mem_biUnion hax hxb theorem exists_covby_infinite_Iic_of_infinite_Iic [IsStronglyCoatomic α] (ha : (Set.Iic a).Infinite) (hfin : {x | x ⋖ a}.Finite) : ∃ b, b ⋖ a ∧ (Set.Iic b).Infinite := by simp_rw [← toDual_covBy_toDual_iff (α := α)] at hfin ⊢ exact exists_covby_infinite_Ici_of_infinite_Ici (α := αᵒᵈ) ha hfin end IsStronglyAtomic
.lake/packages/mathlib/Mathlib/Order/Preorder/Finite.lean
import Mathlib.Data.Set.Finite.Basic import Mathlib.Order.Minimal /-! # Finite preorders and finite sets in a preorder This file shows that non-empty finite sets in a preorder have minimal/maximal elements, and contrapositively that non-empty sets without minimal or maximal elements are infinite. -/ variable {ι α β : Type*} namespace Finset section IsTrans variable [LE α] [IsTrans α LE.le] {s : Finset α} {a : α} lemma exists_maximalFor (f : ι → α) (s : Finset ι) (hs : s.Nonempty) : ∃ i, MaximalFor (· ∈ s) f i := by induction hs using Finset.Nonempty.cons_induction with | singleton i => exact ⟨i, by simp⟩ | @cons i s hi hs ih => obtain ⟨j, hj⟩ := ih by_cases hji : f j ≤ f i · refine ⟨i, mem_cons_self .., ?_⟩ simp only [mem_cons, forall_eq_or_imp, imp_self, true_and] exact fun k hk hik ↦ _root_.trans (hj.2 hk <| _root_.trans hji hik) hji · exact ⟨j, mem_cons_of_mem hj.1, by simpa [hji] using hj.2⟩ lemma exists_minimalFor (f : ι → α) (s : Finset ι) (hs : s.Nonempty) : ∃ i, MinimalFor (· ∈ s) f i := exists_maximalFor (α := αᵒᵈ) f s hs lemma exists_maximal (hs : s.Nonempty) : ∃ i, Maximal (· ∈ s) i := s.exists_maximalFor id hs lemma exists_minimal (hs : s.Nonempty) : ∃ i, Minimal (· ∈ s) i := s.exists_minimalFor id hs end IsTrans section Preorder variable [Preorder α] {s : Finset α} {a : α} lemma exists_le_maximal (s : Finset α) (ha : a ∈ s) : ∃ b, a ≤ b ∧ Maximal (· ∈ s) b := by classical obtain ⟨b, hb, hab, hbmin⟩ : ∃ b ∈ s, a ≤ b ∧ _ := by simpa [Maximal, and_assoc] using {x ∈ s | a ≤ x}.exists_maximal ⟨a, mem_filter.2 ⟨ha, le_rfl⟩⟩ exact ⟨b, hab, hb, fun c hc hbc ↦ hbmin hc (hab.trans hbc) hbc⟩ lemma exists_le_minimal (s : Finset α) (ha : a ∈ s) : ∃ b ≤ a, Minimal (· ∈ s) b := exists_le_maximal (α := αᵒᵈ) s ha @[deprecated (since := "2025-05-04")] alias exists_minimal_le := exists_le_minimal end Preorder end Finset namespace Set section IsTrans variable [LE α] [IsTrans α LE.le] {s : Set α} {a : α} lemma Finite.exists_maximalFor (f : ι → α) (s : Set ι) (h : s.Finite) (hs : s.Nonempty) : ∃ i, MaximalFor (· ∈ s) f i := by lift s to Finset ι using h; exact s.exists_maximalFor f hs lemma Finite.exists_minimalFor (f : ι → α) (s : Set ι) (h : s.Finite) (hs : s.Nonempty) : ∃ i, MinimalFor (· ∈ s) f i := Finite.exists_maximalFor (α := αᵒᵈ) f s h hs lemma Finite.exists_maximal (h : s.Finite) (hs : s.Nonempty) : ∃ i, Maximal (· ∈ s) i := h.exists_maximalFor id _ hs lemma Finite.exists_minimal (h : s.Finite) (hs : s.Nonempty) : ∃ i, Minimal (· ∈ s) i := h.exists_minimalFor id _ hs /-- A version of `Finite.exists_maximalFor` with the (weaker) hypothesis that the image of `s` is finite rather than `s` itself. -/ lemma Finite.exists_maximalFor' (f : ι → α) (s : Set ι) (h : (f '' s).Finite) (hs : s.Nonempty) : ∃ i, MaximalFor (· ∈ s) f i := by obtain ⟨_, ⟨a, ha, rfl⟩, hmax⟩ := Finite.exists_maximalFor id (f '' s) h (hs.image f) exact ⟨a, ha, fun a' ha' hf ↦ hmax (mem_image_of_mem f ha') hf⟩ /-- A version of `Finite.exists_minimalFor` with the (weaker) hypothesis that the image of `s` is finite rather than `s` itself. -/ lemma Finite.exists_minimalFor' (f : ι → α) (s : Set ι) (h : (f '' s).Finite) (hs : s.Nonempty) : ∃ i, MinimalFor (· ∈ s) f i := h.exists_maximalFor' (α := αᵒᵈ) f s hs @[deprecated (since := "2025-05-04")] alias Finite.exists_maximal_wrt := Finite.exists_maximalFor @[deprecated (since := "2025-05-04")] alias Finite.exists_minimal_wrt := Finite.exists_minimalFor @[deprecated (since := "2025-05-04")] alias Finite.exists_maximal_wrt' := Finite.exists_maximalFor' @[deprecated (since := "2025-05-04")] alias Finite.exists_minimal_wrt' := Finite.exists_minimalFor' end IsTrans section Preorder variable [Preorder α] {s : Set α} {a : α} lemma Finite.exists_le_maximal (hs : s.Finite) (ha : a ∈ s) : ∃ b, a ≤ b ∧ Maximal (· ∈ s) b := by lift s to Finset α using hs; exact s.exists_le_maximal ha lemma Finite.exists_le_minimal (hs : s.Finite) (ha : a ∈ s) : ∃ b, b ≤ a ∧ Minimal (· ∈ s) b := by lift s to Finset α using hs; exact s.exists_le_minimal ha variable [Nonempty α] lemma infinite_of_forall_exists_gt (h : ∀ a, ∃ b ∈ s, a < b) : s.Infinite := by inhabit α let f (n : ℕ) : α := Nat.recOn n (h default).choose fun _ a ↦ (h a).choose have hf : ∀ n, f n ∈ s := by rintro (_ | _) <;> exact (h _).choose_spec.1 exact infinite_of_injective_forall_mem (strictMono_nat_of_lt_succ fun n => (h _).choose_spec.2).injective hf lemma infinite_of_forall_exists_lt (h : ∀ a, ∃ b ∈ s, b < a) : s.Infinite := infinite_of_forall_exists_gt (α := αᵒᵈ) h end Preorder section PartialOrder variable (α) [PartialOrder α] lemma finite_isTop : {a : α | IsTop a}.Finite := (subsingleton_isTop α).finite lemma finite_isBot : {a : α | IsBot a}.Finite := (subsingleton_isBot α).finite end PartialOrder section LinearOrder variable [LinearOrder α] {s : Set α} {t : Set β} {f : α → β} lemma Infinite.exists_lt_map_eq_of_mapsTo (hs : s.Infinite) (hf : MapsTo f s t) (ht : t.Finite) : ∃ x ∈ s, ∃ y ∈ s, x < y ∧ f x = f y := let ⟨x, hx, y, hy, hxy, hf⟩ := hs.exists_ne_map_eq_of_mapsTo hf ht hxy.lt_or_gt.elim (fun hxy => ⟨x, hx, y, hy, hxy, hf⟩) fun hyx => ⟨y, hy, x, hx, hyx, hf.symm⟩ lemma Finite.exists_lt_map_eq_of_forall_mem [Infinite α] (hf : ∀ a, f a ∈ t) (ht : t.Finite) : ∃ a b, a < b ∧ f a = f b := by rw [← mapsTo_univ_iff] at hf obtain ⟨a, -, b, -, h⟩ := infinite_univ.exists_lt_map_eq_of_mapsTo hf ht exact ⟨a, b, h⟩ end LinearOrder end Set section Preorder variable [Preorder α] [Finite α] {p : α → Prop} {a : α} lemma Finite.exists_le_maximal (h : p a) : ∃ b, a ≤ b ∧ Maximal p b := {x | p x}.toFinite.exists_le_maximal h lemma Finite.exists_le_minimal (h : p a) : ∃ b ≤ a, Minimal p b := {x | p x}.toFinite.exists_le_minimal h end Preorder
.lake/packages/mathlib/Mathlib/Order/Preorder/Chain.lean
import Mathlib.Data.Set.Pairwise.Basic import Mathlib.Data.SetLike.Basic import Mathlib.Order.Directed import Mathlib.Order.Hom.Set /-! # Chains and flags This file defines chains for an arbitrary relation and flags for an order. ## Main declarations * `IsChain s`: A chain `s` is a set of comparable elements. * `Flag`: The type of flags, aka maximal chains, of an order. ## Notes Originally ported from Isabelle/HOL. The [original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D. Fleuriot, Tobias Nipkow, Christian Sternagel. -/ assert_not_exists CompleteLattice open Set variable {α β : Type*} /-! ### Chains -/ section Chain variable (r : α → α → Prop) /-- In this file, we use `≺` as a local notation for any relation `r`. -/ local infixl:50 " ≺ " => r /-- A chain is a set `s` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ s`. -/ def IsChain (s : Set α) : Prop := s.Pairwise fun x y => x ≺ y ∨ y ≺ x /-- `SuperChain s t` means that `t` is a chain that strictly includes `s`. -/ def SuperChain (s t : Set α) : Prop := IsChain r t ∧ s ⊂ t /-- A chain `s` is a maximal chain if there does not exists a chain strictly including `s`. -/ def IsMaxChain (s : Set α) : Prop := IsChain r s ∧ ∀ ⦃t⦄, IsChain r t → s ⊆ t → s = t variable {r} {c c₁ c₂ s t : Set α} {a b x y : α} @[simp] lemma IsChain.empty : IsChain r ∅ := pairwise_empty _ @[simp] lemma IsChain.singleton : IsChain r {a} := pairwise_singleton .. theorem Set.Subsingleton.isChain (hs : s.Subsingleton) : IsChain r s := hs.pairwise _ theorem IsChain.mono : s ⊆ t → IsChain r t → IsChain r s := Set.Pairwise.mono theorem IsChain.mono_rel {r' : α → α → Prop} (h : IsChain r s) (h_imp : ∀ x y, r x y → r' x y) : IsChain r' s := h.mono' fun x y => Or.imp (h_imp x y) (h_imp y x) /-- This can be used to turn `IsChain (≥)` into `IsChain (≤)` and vice-versa. -/ theorem IsChain.symm (h : IsChain r s) : IsChain (flip r) s := h.mono' fun _ _ => Or.symm theorem isChain_of_trichotomous [IsTrichotomous α r] (s : Set α) : IsChain r s := fun a _ b _ hab => (trichotomous_of r a b).imp_right fun h => h.resolve_left hab protected theorem IsChain.insert (hs : IsChain r s) (ha : ∀ b ∈ s, a ≠ b → a ≺ b ∨ b ≺ a) : IsChain r (insert a s) := hs.insert_of_symmetric (fun _ _ => Or.symm) ha lemma IsChain.pair (h : r a b) : IsChain r {a, b} := IsChain.singleton.insert fun _ hb _ ↦ .inl <| (eq_of_mem_singleton hb).symm.recOn ‹_› theorem isChain_univ_iff : IsChain r (univ : Set α) ↔ IsTrichotomous α r := by refine ⟨fun h => ⟨fun a b => ?_⟩, fun h => @isChain_of_trichotomous _ _ h univ⟩ rw [or_left_comm, or_iff_not_imp_left] exact h trivial trivial theorem IsChain.image (r : α → α → Prop) (s : β → β → Prop) (f : α → β) (h : ∀ x y, r x y → s (f x) (f y)) {c : Set α} (hrc : IsChain r c) : IsChain s (f '' c) := fun _ ⟨_, ha₁, ha₂⟩ _ ⟨_, hb₁, hb₂⟩ => ha₂ ▸ hb₂ ▸ fun hxy => (hrc ha₁ hb₁ <| ne_of_apply_ne f hxy).imp (h _ _) (h _ _) theorem IsChain.preimage (r : α → α → Prop) (s : β → β → Prop) (f : α → β) (hf : Function.Injective f) (h : ∀ x y, s (f x) (f y) → r x y) {c : Set β} (hrc : IsChain s c) : IsChain r (f ⁻¹' c) := by intro _ ha _ hb hne have := hrc ha hb (fun h ↦ hne (hf h)) grind lemma isChain_union {s t : Set α} : IsChain r (s ∪ t) ↔ IsChain r s ∧ IsChain r t ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b ∨ r b a := by rw [IsChain, IsChain, IsChain, pairwise_union_of_symmetric fun _ _ ↦ Or.symm] lemma Monotone.isChain_image [Preorder α] [Preorder β] {s : Set α} {f : α → β} (hf : Monotone f) (hs : IsChain (· ≤ ·) s) : IsChain (· ≤ ·) (f '' s) := hs.image _ _ _ (fun _ _ a ↦ hf a) theorem Monotone.isChain_range [LinearOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : IsChain (· ≤ ·) (range f) := by rw [← image_univ] exact hf.isChain_image (isChain_of_trichotomous _) theorem IsChain.lt_of_le [PartialOrder α] {s : Set α} (h : IsChain (· ≤ ·) s) : IsChain (· < ·) s := fun _a ha _b hb hne ↦ (h ha hb hne).imp hne.lt_of_le hne.lt_of_le' section Rel variable {r : α → α → Prop} {r' : β → β → Prop} {s : Set α} theorem IsChain.image_relEmbedding (hs : IsChain r s) (φ : r ↪r r') : IsChain r' (φ '' s) := by intro b hb b' hb' h rw [Set.mem_image] at hb hb' obtain ⟨⟨a, has, rfl⟩, ⟨a', has', rfl⟩⟩ := hb, hb' have := hs has has' (fun haa' => h (by rw [haa'])) grind [RelEmbedding.map_rel_iff] theorem IsChain.preimage_relEmbedding {t : Set β} (ht : IsChain r' t) (φ : r ↪r r') : IsChain r (φ ⁻¹' t) := fun _ ha _s ha' hne => by have := ht ha ha' (fun h => hne (φ.injective h)) grind [RelEmbedding.map_rel_iff] theorem IsChain.image_relIso (hs : IsChain r s) (φ : r ≃r r') : IsChain r' (φ '' s) := hs.image_relEmbedding φ.toRelEmbedding theorem IsChain.preimage_relIso {t : Set β} (hs : IsChain r' t) (φ : r ≃r r') : IsChain r (φ ⁻¹' t) := hs.preimage_relEmbedding φ.toRelEmbedding theorem IsChain.image_relEmbedding_iff {φ : r ↪r r'} : IsChain r' (φ '' s) ↔ IsChain r s := ⟨fun h => (φ.injective.preimage_image s).subst (h.preimage_relEmbedding φ), fun h => h.image_relEmbedding φ⟩ theorem IsChain.image_relIso_iff {φ : r ≃r r'} : IsChain r' (φ '' s) ↔ IsChain r s := @image_relEmbedding_iff _ _ _ _ _ (φ : r ↪r r') theorem IsChain.image_embedding [LE α] [LE β] (hs : IsChain (· ≤ ·) s) (φ : α ↪o β) : IsChain (· ≤ ·) (φ '' s) := image_relEmbedding hs _ theorem IsChain.preimage_embedding [LE α] [LE β] {t : Set β} (ht : IsChain (· ≤ ·) t) (φ : α ↪o β) : IsChain (· ≤ ·) (φ ⁻¹' t) := preimage_relEmbedding ht _ theorem IsChain.image_embedding_iff [LE α] [LE β] {φ : α ↪o β} : IsChain (· ≤ ·) (φ '' s) ↔ IsChain (· ≤ ·) s := image_relEmbedding_iff theorem IsChain.image_iso [LE α] [LE β] (hs : IsChain (· ≤ ·) s) (φ : α ≃o β) : IsChain (· ≤ ·) (φ '' s) := image_relEmbedding hs _ theorem IsChain.image_iso_iff [LE α] [LE β] {φ : α ≃o β} : IsChain (· ≤ ·) (φ '' s) ↔ IsChain (· ≤ ·) s := image_relEmbedding_iff theorem IsChain.preimage_iso [LE α] [LE β] {t : Set β} (ht : IsChain (· ≤ ·) t) (φ : α ≃o β) : IsChain (· ≤ ·) (φ ⁻¹' t) := preimage_relEmbedding ht _ theorem IsChain.preimage_iso_iff [LE α] [LE β] {t : Set β} {φ : α ≃o β} : IsChain (· ≤ ·) (φ ⁻¹' t) ↔ IsChain (· ≤ ·) t := ⟨fun h => (φ.image_preimage t).subst (h.image_iso φ), fun h => h.preimage_iso _⟩ end Rel section Total variable [IsRefl α r] theorem IsChain.total (h : IsChain r s) (hx : x ∈ s) (hy : y ∈ s) : x ≺ y ∨ y ≺ x := (eq_or_ne x y).elim (fun e => Or.inl <| e ▸ refl _) (h hx hy) theorem IsChain.directedOn (H : IsChain r s) : DirectedOn r s := fun x hx y hy => ((H.total hx hy).elim fun h => ⟨y, hy, h, refl _⟩) fun h => ⟨x, hx, refl _, h⟩ protected theorem IsChain.directed {f : β → α} {c : Set β} (h : IsChain (f ⁻¹'o r) c) : Directed r fun x : { a : β // a ∈ c } => f x := fun ⟨a, ha⟩ ⟨b, hb⟩ => (by_cases fun hab : a = b => by simp only [hab, exists_prop, and_self_iff, Subtype.exists] exact ⟨b, hb, refl _⟩) fun hab => ((h ha hb hab).elim fun h => ⟨⟨b, hb⟩, h, refl _⟩) fun h => ⟨⟨a, ha⟩, refl _, h⟩ theorem IsChain.exists3 (hchain : IsChain r s) [IsTrans α r] {a b c} (mem1 : a ∈ s) (mem2 : b ∈ s) (mem3 : c ∈ s) : ∃ (z : _) (_ : z ∈ s), r a z ∧ r b z ∧ r c z := by rcases directedOn_iff_directed.mpr (IsChain.directed hchain) a mem1 b mem2 with ⟨z, mem4, H1, H2⟩ rcases directedOn_iff_directed.mpr (IsChain.directed hchain) z mem4 c mem3 with ⟨z', mem5, H3, H4⟩ exact ⟨z', mem5, _root_.trans H1 H3, _root_.trans H2 H3, H4⟩ end Total lemma IsChain.le_of_not_gt [Preorder α] (hs : IsChain (· ≤ ·) s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) (h : ¬ x < y) : y ≤ x := by cases hs.total hx hy with | inr h' => exact h' | inl h' => simpa [lt_iff_le_not_ge, h'] using h @[deprecated (since := "2025-05-11")] alias IsChain.le_of_not_lt := IsChain.le_of_not_gt lemma IsChain.not_lt [Preorder α] (hs : IsChain (· ≤ ·) s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : ¬ x < y ↔ y ≤ x := ⟨(hs.le_of_not_gt hx hy ·), fun h h' ↦ h'.not_ge h⟩ lemma IsChain.lt_of_not_ge [Preorder α] (hs : IsChain (· ≤ ·) s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) (h : ¬ x ≤ y) : y < x := (hs.total hx hy).elim (h · |>.elim) (lt_of_le_not_ge · h) @[deprecated (since := "2025-05-11")] alias IsChain.lt_of_not_le := IsChain.lt_of_not_ge lemma IsChain.not_le [Preorder α] (hs : IsChain (· ≤ ·) s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : ¬ x ≤ y ↔ y < x := ⟨(hs.lt_of_not_ge hx hy ·), fun h h' ↦ h'.not_gt h⟩ theorem IsMaxChain.isChain (h : IsMaxChain r s) : IsChain r s := h.1 theorem IsMaxChain.not_superChain (h : IsMaxChain r s) : ¬SuperChain r s t := fun ht => ht.2.ne <| h.2 ht.1 ht.2.1 theorem IsMaxChain.bot_mem [LE α] [OrderBot α] (h : IsMaxChain (· ≤ ·) s) : ⊥ ∈ s := (h.2 (h.1.insert fun _ _ _ => Or.inl bot_le) <| subset_insert _ _).symm ▸ mem_insert _ _ theorem IsMaxChain.top_mem [LE α] [OrderTop α] (h : IsMaxChain (· ≤ ·) s) : ⊤ ∈ s := (h.2 (h.1.insert fun _ _ _ => Or.inr le_top) <| subset_insert _ _).symm ▸ mem_insert _ _ lemma IsMaxChain.image {s : β → β → Prop} (e : r ≃r s) {c : Set α} (hc : IsMaxChain r c) : IsMaxChain s (e '' c) where left := hc.isChain.image _ _ _ fun _ _ ↦ by exact e.map_rel_iff.2 right t ht hf := by rw [← e.coe_fn_toEquiv, ← e.toEquiv.eq_preimage_iff_image_eq, ← Equiv.image_symm_eq_preimage] exact hc.2 (ht.image _ _ _ fun _ _ ↦ by exact e.symm.map_rel_iff.2) ((e.toEquiv.subset_symm_image _ _).2 hf) protected theorem IsMaxChain.isEmpty_iff (h : IsMaxChain r s) : IsEmpty α ↔ s = ∅ := by refine ⟨fun _ ↦ s.eq_empty_of_isEmpty, fun h' ↦ ?_⟩ constructor intro x simp only [IsMaxChain, h', IsChain.empty, empty_subset, forall_const, true_and] at h exact singleton_ne_empty x (h IsChain.singleton).symm protected theorem IsMaxChain.nonempty_iff (h : IsMaxChain r s) : Nonempty α ↔ s ≠ ∅ := by grind [not_nonempty_iff, IsMaxChain.isEmpty_iff] theorem IsMaxChain.symm (h : IsMaxChain r s) : IsMaxChain (flip r) s := ⟨h.isChain.symm, fun _ ht₁ ht₂ ↦ h.2 ht₁.symm ht₂⟩ open Classical in /-- Given a set `s`, if there exists a chain `t` strictly including `s`, then `SuccChain s` is one of these chains. Otherwise it is `s`. -/ def SuccChain (r : α → α → Prop) (s : Set α) : Set α := if h : ∃ t, IsChain r s ∧ SuperChain r s t then h.choose else s theorem succChain_spec (h : ∃ t, IsChain r s ∧ SuperChain r s t) : SuperChain r s (SuccChain r s) := by have : IsChain r s ∧ SuperChain r s h.choose := h.choose_spec simpa [SuccChain, dif_pos, exists_and_left.mp h] using this.2 open Classical in theorem IsChain.succ (hs : IsChain r s) : IsChain r (SuccChain r s) := if h : ∃ t, IsChain r s ∧ SuperChain r s t then (succChain_spec h).1 else by rw [exists_and_left] at h simpa [SuccChain, dif_neg, h] using hs theorem IsChain.superChain_succChain (hs₁ : IsChain r s) (hs₂ : ¬IsMaxChain r s) : SuperChain r s (SuccChain r s) := by simp only [IsMaxChain, _root_.not_and, not_forall, exists_prop] at hs₂ obtain ⟨t, ht, hst⟩ := hs₂ hs₁ exact succChain_spec ⟨t, hs₁, ht, ssubset_iff_subset_ne.2 hst⟩ open Classical in theorem subset_succChain : s ⊆ SuccChain r s := if h : ∃ t, IsChain r s ∧ SuperChain r s t then (succChain_spec h).2.1 else by simp [SuccChain, h] end Chain /-! ### Flags -/ /-- The type of flags, aka maximal chains, of an order. -/ structure Flag (α : Type*) [LE α] where /-- The `carrier` of a flag is the underlying set. -/ carrier : Set α /-- By definition, a flag is a chain -/ Chain' : IsChain (· ≤ ·) carrier /-- By definition, a flag is a maximal chain -/ max_chain' : ∀ ⦃s⦄, IsChain (· ≤ ·) s → carrier ⊆ s → carrier = s namespace Flag section LE variable [LE α] {s t : Flag α} {a : α} instance : SetLike (Flag α) α where coe := carrier coe_injective' s t h := by cases s cases t congr @[ext] theorem ext : (s : Set α) = t → s = t := SetLike.ext' theorem mem_coe_iff : a ∈ (s : Set α) ↔ a ∈ s := Iff.rfl @[simp] theorem coe_mk (s : Set α) (h₁ h₂) : (mk s h₁ h₂ : Set α) = s := rfl @[simp] theorem mk_coe (s : Flag α) : mk (s : Set α) s.Chain' s.max_chain' = s := ext rfl theorem chain_le (s : Flag α) : IsChain (· ≤ ·) (s : Set α) := s.Chain' protected theorem maxChain (s : Flag α) : IsMaxChain (· ≤ ·) (s : Set α) := ⟨s.chain_le, s.max_chain'⟩ theorem top_mem [OrderTop α] (s : Flag α) : (⊤ : α) ∈ s := s.maxChain.top_mem theorem bot_mem [OrderBot α] (s : Flag α) : (⊥ : α) ∈ s := s.maxChain.bot_mem /-- Reinterpret a maximal chain as a flag. -/ def ofIsMaxChain (c : Set α) (hc : IsMaxChain (· ≤ ·) c) : Flag α := ⟨c, hc.isChain, hc.2⟩ @[simp, norm_cast] lemma coe_ofIsMaxChain (c : Set α) (hc) : ofIsMaxChain c hc = c := rfl end LE section Preorder variable [Preorder α] [Preorder β] {a b : α} {s : Flag α} protected theorem le_or_le (s : Flag α) (ha : a ∈ s) (hb : b ∈ s) : a ≤ b ∨ b ≤ a := s.chain_le.total ha hb instance [OrderTop α] (s : Flag α) : OrderTop s := Subtype.orderTop s.top_mem instance [OrderBot α] (s : Flag α) : OrderBot s := Subtype.orderBot s.bot_mem instance [BoundedOrder α] (s : Flag α) : BoundedOrder s := Subtype.boundedOrder s.bot_mem s.top_mem lemma mem_iff_forall_le_or_ge : a ∈ s ↔ ∀ ⦃b⦄, b ∈ s → a ≤ b ∨ b ≤ a := ⟨fun ha b => s.le_or_le ha, fun hb => of_not_not fun ha => Set.ne_insert_of_notMem _ ‹_› <| s.maxChain.2 (s.chain_le.insert fun c hc _ => hb hc) <| Set.subset_insert _ _⟩ /-- Flags are preserved under order isomorphisms. -/ def map (e : α ≃o β) : Flag α ≃ Flag β where toFun s := ofIsMaxChain _ (s.maxChain.image e) invFun s := ofIsMaxChain _ (s.maxChain.image e.symm) left_inv s := ext <| e.symm_image_image s right_inv s := ext <| e.image_symm_image s @[simp, norm_cast] lemma coe_map (e : α ≃o β) (s : Flag α) : ↑(map e s) = e '' s := rfl @[simp] lemma symm_map (e : α ≃o β) : (map e).symm = map e.symm := rfl end Preorder section PartialOrder variable [PartialOrder α] theorem chain_lt (s : Flag α) : IsChain (· < ·) (s : Set α) := s.chain_le.lt_of_le instance [DecidableLE α] [DecidableLT α] [DecidableEq α] (s : Flag α) : LinearOrder s := { Subtype.partialOrder _ with le_total := fun a b => s.le_or_le a.2 b.2 toDecidableLE := Subtype.decidableLE toDecidableLT := Subtype.decidableLT toDecidableEq := Subtype.instDecidableEq } end PartialOrder instance [LinearOrder α] : Unique (Flag α) where default := ⟨univ, isChain_of_trichotomous _, fun s _ => s.subset_univ.antisymm'⟩ uniq s := SetLike.coe_injective <| s.3 (isChain_of_trichotomous _) <| subset_univ _ end Flag
.lake/packages/mathlib/Mathlib/Order/Preorder/Finsupp.lean
import Mathlib.Data.Finsupp.Defs /-! # Pointwise order on finitely supported functions This file lifts order structures on `M` to `ι →₀ M`. -/ assert_not_exists CompleteLattice noncomputable section open Finset namespace Finsupp variable {ι M : Type*} [Zero M] section LE variable [LE M] {f g : ι →₀ M} instance instLE : LE (ι →₀ M) where le f g := ∀ i, f i ≤ g i lemma le_def : f ≤ g ↔ ∀ i, f i ≤ g i := .rfl @[simp, norm_cast] lemma coe_le_coe : ⇑f ≤ g ↔ f ≤ g := .rfl /-- The order on `Finsupp`s over a partial order embeds into the order on functions -/ @[simps] def orderEmbeddingToFun : (ι →₀ M) ↪o (ι → M) where toFun f := f inj' := DFunLike.coe_injective map_rel_iff' := coe_le_coe end LE section Preorder variable [Preorder M] {f g : ι →₀ M} {i : ι} {a b : M} instance preorder : Preorder (ι →₀ M) where le_refl _ _ := le_rfl le_trans _ _ _ hfg hgh i := (hfg i).trans (hgh i) lemma lt_def : f < g ↔ f ≤ g ∧ ∃ i, f i < g i := Pi.lt_def @[simp, norm_cast] lemma coe_lt_coe : ⇑f < g ↔ f < g := .rfl lemma coe_mono : Monotone (Finsupp.toFun : (ι →₀ M) → ι → M) := fun _ _ ↦ id lemma coe_strictMono : Monotone (Finsupp.toFun : (ι →₀ M) → ι → M) := fun _ _ ↦ id end Preorder instance partialorder [PartialOrder M] : PartialOrder (ι →₀ M) where le_antisymm _f _g hfg hgf := ext fun i ↦ (hfg i).antisymm (hgf i) section SemilatticeInf variable [SemilatticeInf M] instance semilatticeInf : SemilatticeInf (ι →₀ M) where inf := zipWith (· ⊓ ·) (inf_idem _) inf_le_left _f _g _i := inf_le_left inf_le_right _f _g _i := inf_le_right le_inf _f _g _i h1 h2 s := le_inf (h1 s) (h2 s) @[simp] lemma inf_apply (f g : ι →₀ M) (i : ι) : (f ⊓ g) i = f i ⊓ g i := rfl end SemilatticeInf section SemilatticeSup variable [SemilatticeSup M] instance semilatticeSup : SemilatticeSup (ι →₀ M) where sup := zipWith (· ⊔ ·) (sup_idem _) le_sup_left _f _g _i := le_sup_left le_sup_right _f _g _i := le_sup_right sup_le _f _g _h hf hg i := sup_le (hf i) (hg i) @[simp] lemma sup_apply (f g : ι →₀ M) (i : ι) : (f ⊔ g) i = f i ⊔ g i := rfl end SemilatticeSup section Lattice variable [Lattice M] (f g : ι →₀ M) instance lattice : Lattice (ι →₀ M) where __ := Finsupp.semilatticeInf __ := Finsupp.semilatticeSup variable [DecidableEq ι] lemma support_inf_union_support_sup : (f ⊓ g).support ∪ (f ⊔ g).support = f.support ∪ g.support := coe_injective <| compl_injective <| by ext; simp [inf_eq_and_sup_eq_iff] lemma support_sup_union_support_inf : (f ⊔ g).support ∪ (f ⊓ g).support = f.support ∪ g.support := (union_comm _ _).trans <| support_inf_union_support_sup _ _ end Lattice end Finsupp
.lake/packages/mathlib/Mathlib/Order/Heyting/Regular.lean
import Mathlib.Order.GaloisConnection.Basic /-! # Heyting regular elements This file defines Heyting regular elements, elements of a Heyting algebra that are their own double complement, and proves that they form a Boolean algebra. From a logic standpoint, this means that we can perform classical logic within intuitionistic logic by simply double-negating all propositions. This is practical for synthetic computability theory. ## Main declarations * `IsRegular`: `a` is Heyting-regular if `aᶜᶜ = a`. * `Regular`: The subtype of Heyting-regular elements. * `Regular.BooleanAlgebra`: Heyting-regular elements form a Boolean algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] -/ open Function variable {α : Type*} namespace Heyting section HasCompl variable [HasCompl α] {a : α} /-- An element of a Heyting algebra is regular if its double complement is itself. -/ def IsRegular (a : α) : Prop := aᶜᶜ = a protected theorem IsRegular.eq : IsRegular a → aᶜᶜ = a := id instance IsRegular.decidablePred [DecidableEq α] : @DecidablePred α IsRegular := fun _ => ‹DecidableEq α› _ _ end HasCompl section HeytingAlgebra variable [HeytingAlgebra α] {a b : α} theorem isRegular_bot : IsRegular (⊥ : α) := by rw [IsRegular, compl_bot, compl_top] theorem isRegular_top : IsRegular (⊤ : α) := by rw [IsRegular, compl_top, compl_bot] theorem IsRegular.inf (ha : IsRegular a) (hb : IsRegular b) : IsRegular (a ⊓ b) := by rw [IsRegular, compl_compl_inf_distrib, ha.eq, hb.eq] theorem IsRegular.himp (ha : IsRegular a) (hb : IsRegular b) : IsRegular (a ⇨ b) := by rw [IsRegular, compl_compl_himp_distrib, ha.eq, hb.eq] theorem isRegular_compl (a : α) : IsRegular aᶜ := compl_compl_compl _ protected theorem IsRegular.disjoint_compl_left_iff (ha : IsRegular a) : Disjoint aᶜ b ↔ b ≤ a := by rw [← le_compl_iff_disjoint_left, ha.eq] protected theorem IsRegular.disjoint_compl_right_iff (hb : IsRegular b) : Disjoint a bᶜ ↔ a ≤ b := by rw [← le_compl_iff_disjoint_right, hb.eq] -- See note [reducible non-instances] /-- A Heyting algebra with regular excluded middle is a Boolean algebra. -/ abbrev _root_.BooleanAlgebra.ofRegular (h : ∀ a : α, IsRegular (a ⊔ aᶜ)) : BooleanAlgebra α := have : ∀ a : α, IsCompl a aᶜ := fun a => ⟨disjoint_compl_right, codisjoint_iff.2 <| by rw [← (h a), compl_sup, inf_compl_eq_bot, compl_bot]⟩ { ‹HeytingAlgebra α›, GeneralizedHeytingAlgebra.toDistribLattice with himp_eq := fun _ _ => eq_of_forall_le_iff fun _ => le_himp_iff.trans (this _).le_sup_right_iff_inf_left_le.symm inf_compl_le_bot := fun _ => (this _).1.le_bot top_le_sup_compl := fun _ => (this _).2.top_le } variable (α) /-- The Boolean algebra of Heyting regular elements. -/ def Regular : Type _ := { a : α // IsRegular a } variable {α} namespace Regular /-- The coercion `Regular α → α` -/ @[coe] def val : Regular α → α := Subtype.val theorem prop : ∀ a : Regular α, IsRegular a.val := Subtype.prop instance : CoeOut (Regular α) α := ⟨Regular.val⟩ theorem coe_injective : Injective ((↑) : Regular α → α) := Subtype.coe_injective @[simp] theorem coe_inj {a b : Regular α} : (a : α) = b ↔ a = b := Subtype.coe_inj instance top : Top (Regular α) := ⟨⟨⊤, isRegular_top⟩⟩ instance bot : Bot (Regular α) := ⟨⟨⊥, isRegular_bot⟩⟩ instance inf : Min (Regular α) := ⟨fun a b => ⟨a ⊓ b, a.2.inf b.2⟩⟩ instance himp : HImp (Regular α) := ⟨fun a b => ⟨a ⇨ b, a.2.himp b.2⟩⟩ instance hasCompl : HasCompl (Regular α) := ⟨fun a => ⟨aᶜ, isRegular_compl _⟩⟩ @[simp, norm_cast] theorem coe_top : ((⊤ : Regular α) : α) = ⊤ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : Regular α) : α) = ⊥ := rfl @[simp, norm_cast] theorem coe_inf (a b : Regular α) : (↑(a ⊓ b) : α) = (a : α) ⊓ b := rfl @[simp, norm_cast] theorem coe_himp (a b : Regular α) : (↑(a ⇨ b) : α) = (a : α) ⇨ b := rfl @[simp, norm_cast] theorem coe_compl (a : Regular α) : (↑aᶜ : α) = (a : α)ᶜ := rfl instance : Inhabited (Regular α) := ⟨⊥⟩ instance : SemilatticeInf (Regular α) := coe_injective.semilatticeInf _ coe_inf instance boundedOrder : BoundedOrder (Regular α) := BoundedOrder.lift ((↑) : Regular α → α) (fun _ _ => id) coe_top coe_bot @[simp, norm_cast] theorem coe_le_coe {a b : Regular α} : (a : α) ≤ b ↔ a ≤ b := Iff.rfl @[simp, norm_cast] theorem coe_lt_coe {a b : Regular α} : (a : α) < b ↔ a < b := Iff.rfl /-- **Regularization** of `a`. The smallest regular element greater than `a`. -/ def toRegular : α →o Regular α := ⟨fun a => ⟨aᶜᶜ, isRegular_compl _⟩, fun _ _ h => coe_le_coe.1 <| compl_le_compl <| compl_le_compl h⟩ @[simp, norm_cast] theorem coe_toRegular (a : α) : (toRegular a : α) = aᶜᶜ := rfl @[simp] theorem toRegular_coe (a : Regular α) : toRegular (a : α) = a := coe_injective a.2 /-- The Galois insertion between `Regular.toRegular` and `coe`. -/ def gi : GaloisInsertion toRegular ((↑) : Regular α → α) where choice a ha := ⟨a, ha.antisymm le_compl_compl⟩ gc _ b := coe_le_coe.symm.trans <| ⟨le_compl_compl.trans, fun h => (compl_anti <| compl_anti h).trans_eq b.2⟩ le_l_u _ := le_compl_compl choice_eq _ ha := coe_injective <| le_compl_compl.antisymm ha instance lattice : Lattice (Regular α) := gi.liftLattice @[simp, norm_cast] theorem coe_sup (a b : Regular α) : (↑(a ⊔ b) : α) = ((a : α) ⊔ b)ᶜᶜ := rfl instance : BooleanAlgebra (Regular α) := { Regular.lattice, Regular.boundedOrder, Regular.himp, Regular.hasCompl with le_sup_inf := fun a b c => coe_le_coe.1 <| by dsimp rw [sup_inf_left, compl_compl_inf_distrib] inf_compl_le_bot := fun _ => coe_le_coe.1 <| disjoint_iff_inf_le.1 disjoint_compl_right top_le_sup_compl := fun a => coe_le_coe.1 <| by dsimp rw [compl_sup, inf_compl_eq_bot, compl_bot] himp_eq := fun a b => coe_injective (by dsimp rw [compl_sup, a.prop.eq] refine eq_of_forall_le_iff fun c => le_himp_iff.trans ?_ rw [le_compl_iff_disjoint_right, disjoint_left_comm] rw [b.prop.disjoint_compl_left_iff]) } @[simp, norm_cast] theorem coe_sdiff (a b : Regular α) : (↑(a \ b) : α) = (a : α) ⊓ bᶜ := rfl end Regular end HeytingAlgebra variable [BooleanAlgebra α] theorem isRegular_of_boolean : ∀ a : α, IsRegular a := compl_compl /-- A decidable proposition is intuitionistically Heyting-regular. -/ theorem isRegular_of_decidable (p : Prop) [Decidable p] : IsRegular p := propext <| Decidable.not_not end Heyting
.lake/packages/mathlib/Mathlib/Order/Heyting/Boundary.lean
import Mathlib.Order.BooleanAlgebra.Basic import Mathlib.Tactic.Common /-! # Co-Heyting boundary The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation with itself. The boundary in the co-Heyting algebra of closed sets coincides with the topological boundary. ## Main declarations * `Coheyting.boundary`: Co-Heyting boundary. `Coheyting.boundary a = a ⊓ ¬a` ## Notation `∂ a` is notation for `Coheyting.boundary a` in scope `Heyting`. -/ assert_not_exists RelIso variable {α : Type*} namespace Coheyting variable [CoheytingAlgebra α] {a b : α} /-- The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation with itself. Note that this is always `⊥` for a Boolean algebra. -/ def boundary (a : α) : α := a ⊓ ¬a /-- The boundary of an element of a co-Heyting algebra. -/ scoped[Heyting] prefix:120 "∂ " => Coheyting.boundary open Heyting -- TODO: Should hnot be named hNot? theorem inf_hnot_self (a : α) : a ⊓ ¬a = ∂ a := rfl theorem boundary_le : ∂ a ≤ a := inf_le_left theorem boundary_le_hnot : ∂ a ≤ ¬a := inf_le_right @[simp] theorem boundary_bot : ∂ (⊥ : α) = ⊥ := bot_inf_eq _ @[simp] theorem boundary_top : ∂ (⊤ : α) = ⊥ := by rw [boundary, hnot_top, inf_bot_eq] theorem boundary_hnot_le (a : α) : ∂ (¬a) ≤ ∂ a := (inf_comm _ _).trans_le <| inf_le_inf_right _ hnot_hnot_le @[simp] theorem boundary_hnot_hnot (a : α) : ∂ (¬¬a) = ∂ (¬a) := by simp_rw [boundary, hnot_hnot_hnot, inf_comm] @[simp] theorem hnot_boundary (a : α) : ¬∂ a = ⊤ := by rw [boundary, hnot_inf_distrib, sup_hnot_self] /-- **Leibniz rule** for the co-Heyting boundary. -/ theorem boundary_inf (a b : α) : ∂ (a ⊓ b) = ∂ a ⊓ b ⊔ a ⊓ ∂ b := by unfold boundary rw [hnot_inf_distrib, inf_sup_left, inf_right_comm, ← inf_assoc] theorem boundary_inf_le : ∂ (a ⊓ b) ≤ ∂ a ⊔ ∂ b := (boundary_inf _ _).trans_le <| sup_le_sup inf_le_left inf_le_right theorem boundary_sup_le : ∂ (a ⊔ b) ≤ ∂ a ⊔ ∂ b := by rw [boundary, inf_sup_right] exact sup_le_sup (inf_le_inf_left _ <| hnot_anti le_sup_left) (inf_le_inf_left _ <| hnot_anti le_sup_right) /- The intuitionistic version of `Coheyting.boundary_le_boundary_sup_sup_boundary_inf_left`. Either proof can be obtained from the other using the equivalence of Heyting algebras and intuitionistic logic and duality between Heyting and co-Heyting algebras. It is crucial that the following proof be intuitionistic. -/ example (a b : Prop) : (a ∧ b ∨ ¬(a ∧ b)) ∧ ((a ∨ b) ∨ ¬(a ∨ b)) → a ∨ ¬a := by rintro ⟨⟨ha, _⟩ | hnab, (ha | hb) | hnab⟩ <;> try exact Or.inl ha · exact Or.inr fun ha => hnab ⟨ha, hb⟩ · exact Or.inr fun ha => hnab <| Or.inl ha theorem boundary_le_boundary_sup_sup_boundary_inf_left : ∂ a ≤ ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) := by simp only [boundary, sup_inf_left, sup_inf_right, sup_right_idem, le_inf_iff, sup_assoc, sup_comm _ a] refine ⟨⟨⟨?_, ?_⟩, ⟨?_, ?_⟩⟩, ?_, ?_⟩ <;> try { exact le_sup_of_le_left inf_le_left } <;> refine inf_le_of_right_le ?_ · rw [hnot_le_iff_codisjoint_right, codisjoint_left_comm] exact codisjoint_hnot_left · refine le_sup_of_le_right ?_ rw [hnot_le_iff_codisjoint_right] exact codisjoint_hnot_right.mono_right (hnot_anti inf_le_left) theorem boundary_le_boundary_sup_sup_boundary_inf_right : ∂ b ≤ ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) := by rw [sup_comm a, inf_comm] exact boundary_le_boundary_sup_sup_boundary_inf_left theorem boundary_sup_sup_boundary_inf (a b : α) : ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) = ∂ a ⊔ ∂ b := le_antisymm (sup_le boundary_sup_le boundary_inf_le) <| sup_le boundary_le_boundary_sup_sup_boundary_inf_left boundary_le_boundary_sup_sup_boundary_inf_right @[simp] theorem boundary_idem (a : α) : ∂ ∂ a = ∂ a := by rw [boundary, hnot_boundary, inf_top_eq] theorem hnot_hnot_sup_boundary (a : α) : ¬¬a ⊔ ∂ a = a := by rw [boundary, sup_inf_left, hnot_sup_self, inf_top_eq, sup_eq_right] exact hnot_hnot_le theorem hnot_eq_top_iff_exists_boundary : ¬a = ⊤ ↔ ∃ b, ∂ b = a := ⟨fun h => ⟨a, by rw [boundary, h, inf_top_eq]⟩, by rintro ⟨b, rfl⟩ exact hnot_boundary _⟩ end Coheyting open Heyting section BooleanAlgebra variable [BooleanAlgebra α] @[simp] theorem Coheyting.boundary_eq_bot (a : α) : ∂ a = ⊥ := inf_compl_eq_bot end BooleanAlgebra
.lake/packages/mathlib/Mathlib/Order/Heyting/Basic.lean
import Mathlib.Order.PropInstances import Mathlib.Order.GaloisConnection.Defs /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas Boolean algebras model classical logic. Heyting algebras are the order-theoretic equivalent of Cartesian closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: Bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ assert_not_exists RelIso open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ @[push ←] theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl @[push ←] theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `aᶜ` is defined as `a ⇨ ⊥` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd @[simp] theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by rw [sup_himp_distrib, himp_self, top_inf_eq] @[simp] theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by rw [sup_himp_distrib, himp_self, inf_top_eq] theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by conv_rhs => rw [← @top_himp _ _ a] rw [← h.eq_top, sup_himp_self_left] theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b := h.symm.himp_eq_right theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left] theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right] /-- See `himp_le` for a stronger version in Boolean algebras. -/ theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a := (himp_le_himp_left hba).trans_eq hac.himp_eq_right theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b := le_himp_iff.2 inf_himp_le @[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff] lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by rw [le_himp_iff, inf_right_comm, ← le_himp_iff] exact himp_inf_le.trans le_himp_himp theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c := (himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba) theorem gc_inf_himp : GaloisConnection (a ⊓ ·) (a ⇨ ·) := fun _ _ ↦ Iff.symm le_himp_iff' -- See note [lower instance priority] instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α := DistribLattice.ofInfSupLe fun a b c => by simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] : GeneralizedHeytingAlgebra (α × β) where le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] : GeneralizedHeytingAlgebra (∀ i, α i) where le_himp_iff i := by simp [le_def] end GeneralizedHeytingAlgebra section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] {a b c d : α} @[simp] theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c := GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _ theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm] theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff'] theorem sdiff_le : a \ b ≤ a := sdiff_le_iff.2 le_sup_right theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b := h.mono_left sdiff_le theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) := h.mono_right sdiff_le theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem] @[simp] theorem sdiff_self : a \ a = ⊥ := le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left theorem le_sup_sdiff : a ≤ b ⊔ a \ b := sdiff_le_iff.1 le_rfl theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff] theorem sup_sdiff_left : a ⊔ a \ b = a := sup_of_le_left sdiff_le theorem sup_sdiff_right : a \ b ⊔ a = a := sup_of_le_right sdiff_le theorem inf_sdiff_left : a \ b ⊓ a = a \ b := inf_of_le_left sdiff_le theorem inf_sdiff_right : a ⊓ a \ b = a \ b := inf_of_le_right sdiff_le @[simp] theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b := le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff) @[simp] theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm] alias sup_sdiff_self_left := sdiff_sup_self alias sup_sdiff_self_right := sup_sdiff_self theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b := sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _ -- cf. `Set.union_diff_cancel'` theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc] theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b := sup_sdiff_cancel' le_rfl h theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h] theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c := sup_le hac <| h.trans sdiff_le theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c := sup_le (h.trans sdiff_le) hbc @[simp] theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq] @[simp] theorem sdiff_bot : a \ ⊥ = a := eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq] @[simp] theorem bot_sdiff : ⊥ \ a = ⊥ := sdiff_eq_bot_iff.2 bot_le theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self, sup_left_comm] exact le_sup_left @[simp] theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by simpa using @sdiff_sdiff_sdiff_le_sdiff theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc] theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) := sdiff_sdiff _ _ _ theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by simp_rw [sdiff_sdiff, sup_comm] theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b := sdiff_right_comm _ _ _ @[simp] theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem] @[simp] theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff] theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff] theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c := eq_of_forall_ge_iff fun d => by rw [sup_le_iff, sdiff_le_comm, le_inf_iff] simp_rw [sdiff_le_comm] theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c := sup_sdiff_distrib _ _ _ @[simp] theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by rw [sup_sdiff, sdiff_self, sup_bot_eq] @[simp] theorem sup_sdiff_left_self : (a ⊔ b) \ a = b \ a := by rw [sup_comm, sup_sdiff_right_self] theorem sdiff_le_sdiff_right (h : a ≤ b) : a \ c ≤ b \ c := sdiff_le_iff.2 <| h.trans <| le_sup_sdiff theorem sdiff_le_sdiff_left (h : a ≤ b) : c \ b ≤ c \ a := sdiff_le_iff.2 <| le_sup_sdiff.trans <| sup_le_sup_right h _ @[gcongr] theorem sdiff_le_sdiff (hab : a ≤ b) (hcd : c ≤ d) : a \ d ≤ b \ c := (sdiff_le_sdiff_right hab).trans <| sdiff_le_sdiff_left hcd -- cf. `IsCompl.inf_sup` theorem sdiff_inf : a \ (b ⊓ c) = a \ b ⊔ a \ c := sdiff_inf_distrib _ _ _ @[simp] theorem sdiff_inf_self_left (a b : α) : a \ (a ⊓ b) = a \ b := by rw [sdiff_inf, sdiff_self, bot_sup_eq] @[simp] theorem sdiff_inf_self_right (a b : α) : b \ (a ⊓ b) = b \ a := by rw [sdiff_inf, sdiff_self, sup_bot_eq] theorem Disjoint.sdiff_eq_left (h : Disjoint a b) : a \ b = a := by conv_rhs => rw [← @sdiff_bot _ _ a] rw [← h.eq_bot, sdiff_inf_self_left] theorem Disjoint.sdiff_eq_right (h : Disjoint a b) : b \ a = b := h.symm.sdiff_eq_left theorem Disjoint.sup_sdiff_cancel_left (h : Disjoint a b) : (a ⊔ b) \ a = b := by rw [sup_sdiff, sdiff_self, bot_sup_eq, h.sdiff_eq_right] theorem Disjoint.sup_sdiff_cancel_right (h : Disjoint a b) : (a ⊔ b) \ b = a := by rw [sup_sdiff, sdiff_self, sup_bot_eq, h.sdiff_eq_left] /-- See `le_sdiff` for a stronger version in generalised Boolean algebras. -/ theorem Disjoint.le_sdiff_of_le_left (hac : Disjoint a c) (hab : a ≤ b) : a ≤ b \ c := hac.sdiff_eq_left.ge.trans <| sdiff_le_sdiff_right hab theorem sdiff_sdiff_le : a \ (a \ b) ≤ b := sdiff_le_iff.2 le_sdiff_sup @[simp] lemma sdiff_eq_sdiff_iff : a \ b = b \ a ↔ a = b := by simp [le_antisymm_iff] lemma sdiff_ne_sdiff_iff : a \ b ≠ b \ a ↔ a ≠ b := sdiff_eq_sdiff_iff.not theorem sdiff_triangle (a b c : α) : a \ c ≤ a \ b ⊔ b \ c := by rw [sdiff_le_iff, sup_left_comm, ← sdiff_le_iff] exact sdiff_sdiff_le.trans le_sup_sdiff theorem sdiff_sup_sdiff_cancel (hba : b ≤ a) (hcb : c ≤ b) : a \ b ⊔ b \ c = a \ c := (sdiff_triangle _ _ _).antisymm' <| sup_le (sdiff_le_sdiff_left hcb) (sdiff_le_sdiff_right hba) /-- a version of `sdiff_sup_sdiff_cancel` with more general hypotheses. -/ theorem sdiff_sup_sdiff_cancel' (hinf : a ⊓ c ≤ b) (hsup : b ≤ a ⊔ c) : a \ b ⊔ b \ c = a \ c := by refine (sdiff_triangle ..).antisymm' <| sup_le ?_ <| by simpa [sup_comm] rw [← sdiff_inf_self_left (b := c)] exact sdiff_le_sdiff_left hinf theorem sdiff_le_sdiff_of_sup_le_sup_left (h : c ⊔ a ≤ c ⊔ b) : a \ c ≤ b \ c := by rw [← sup_sdiff_left_self, ← @sup_sdiff_left_self _ _ _ b] exact sdiff_le_sdiff_right h theorem sdiff_le_sdiff_of_sup_le_sup_right (h : a ⊔ c ≤ b ⊔ c) : a \ c ≤ b \ c := by rw [← sup_sdiff_right_self, ← @sup_sdiff_right_self _ _ b] exact sdiff_le_sdiff_right h @[simp] theorem inf_sdiff_sup_left : a \ c ⊓ (a ⊔ b) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_left @[simp] theorem inf_sdiff_sup_right : a \ c ⊓ (b ⊔ a) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_right theorem gc_sdiff_sup : GaloisConnection (· \ a) (a ⊔ ·) := fun _ _ ↦ sdiff_le_iff -- See note [lower instance priority] instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : DistribLattice α := { ‹GeneralizedCoheytingAlgebra α› with le_sup_inf := fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl } instance OrderDual.instGeneralizedHeytingAlgebra : GeneralizedHeytingAlgebra αᵒᵈ where himp := fun a b => toDual (ofDual b \ ofDual a) le_himp_iff := fun a b c => by rw [inf_comm]; exact sdiff_le_iff instance Prod.instGeneralizedCoheytingAlgebra [GeneralizedCoheytingAlgebra β] : GeneralizedCoheytingAlgebra (α × β) where sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff instance Pi.instGeneralizedCoheytingAlgebra {α : ι → Type*} [∀ i, GeneralizedCoheytingAlgebra (α i)] : GeneralizedCoheytingAlgebra (∀ i, α i) where sdiff_le_iff i := by simp [le_def] end GeneralizedCoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] {a b : α} @[simp] theorem himp_bot (a : α) : a ⇨ ⊥ = aᶜ := HeytingAlgebra.himp_bot _ @[simp] theorem bot_himp (a : α) : ⊥ ⇨ a = ⊤ := himp_eq_top_iff.2 bot_le theorem compl_sup_distrib (a b : α) : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := by simp_rw [← himp_bot, sup_himp_distrib] @[simp] theorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := compl_sup_distrib _ _ theorem compl_le_himp : aᶜ ≤ a ⇨ b := (himp_bot _).ge.trans <| himp_le_himp_left bot_le theorem compl_sup_le_himp : aᶜ ⊔ b ≤ a ⇨ b := sup_le compl_le_himp le_himp theorem sup_compl_le_himp : b ⊔ aᶜ ≤ a ⇨ b := sup_le le_himp compl_le_himp -- `p → ¬ p ↔ ¬ p` @[simp] theorem himp_compl (a : α) : a ⇨ aᶜ = aᶜ := by rw [← himp_bot, himp_himp, inf_idem] -- `p → ¬ q ↔ q → ¬ p` theorem himp_compl_comm (a b : α) : a ⇨ bᶜ = b ⇨ aᶜ := by simp_rw [← himp_bot, himp_left_comm] theorem le_compl_iff_disjoint_right : a ≤ bᶜ ↔ Disjoint a b := by rw [← himp_bot, le_himp_iff, disjoint_iff_inf_le] theorem le_compl_iff_disjoint_left : a ≤ bᶜ ↔ Disjoint b a := le_compl_iff_disjoint_right.trans disjoint_comm theorem le_compl_comm : a ≤ bᶜ ↔ b ≤ aᶜ := by rw [le_compl_iff_disjoint_right, le_compl_iff_disjoint_left] alias ⟨_, Disjoint.le_compl_right⟩ := le_compl_iff_disjoint_right alias ⟨_, Disjoint.le_compl_left⟩ := le_compl_iff_disjoint_left alias le_compl_iff_le_compl := le_compl_comm alias ⟨le_compl_of_le_compl, _⟩ := le_compl_comm theorem disjoint_compl_left : Disjoint aᶜ a := disjoint_iff_inf_le.mpr <| le_himp_iff.1 (himp_bot _).ge theorem disjoint_compl_right : Disjoint a aᶜ := disjoint_compl_left.symm theorem LE.le.disjoint_compl_left (h : b ≤ a) : Disjoint aᶜ b := _root_.disjoint_compl_left.mono_right h theorem LE.le.disjoint_compl_right (h : a ≤ b) : Disjoint a bᶜ := _root_.disjoint_compl_right.mono_left h theorem IsCompl.compl_eq (h : IsCompl a b) : aᶜ = b := h.1.le_compl_left.antisymm' <| Disjoint.le_of_codisjoint disjoint_compl_left h.2 theorem IsCompl.eq_compl (h : IsCompl a b) : a = bᶜ := h.1.le_compl_right.antisymm <| Disjoint.le_of_codisjoint disjoint_compl_left h.2.symm theorem compl_unique (h₀ : a ⊓ b = ⊥) (h₁ : a ⊔ b = ⊤) : aᶜ = b := (IsCompl.of_eq h₀ h₁).compl_eq @[simp] theorem inf_compl_self (a : α) : a ⊓ aᶜ = ⊥ := disjoint_compl_right.eq_bot @[simp] theorem compl_inf_self (a : α) : aᶜ ⊓ a = ⊥ := disjoint_compl_left.eq_bot theorem inf_compl_eq_bot : a ⊓ aᶜ = ⊥ := inf_compl_self _ theorem compl_inf_eq_bot : aᶜ ⊓ a = ⊥ := compl_inf_self _ @[simp] theorem compl_top : (⊤ : α)ᶜ = ⊥ := eq_of_forall_le_iff fun a => by rw [le_compl_iff_disjoint_right, disjoint_top, le_bot_iff] @[simp] theorem compl_bot : (⊥ : α)ᶜ = ⊤ := by rw [← himp_bot, himp_self] @[simp] theorem le_compl_self : a ≤ aᶜ ↔ a = ⊥ := by rw [le_compl_iff_disjoint_left, disjoint_self] @[simp] theorem ne_compl_self [Nontrivial α] : a ≠ aᶜ := by intro h cases le_compl_self.1 (le_of_eq h) simp at h @[simp] theorem compl_ne_self [Nontrivial α] : aᶜ ≠ a := ne_comm.1 ne_compl_self @[simp] theorem lt_compl_self [Nontrivial α] : a < aᶜ ↔ a = ⊥ := by rw [lt_iff_le_and_ne]; simp theorem le_compl_compl : a ≤ aᶜᶜ := disjoint_compl_right.le_compl_right theorem compl_anti : Antitone (compl : α → α) := fun _ _ h => le_compl_comm.1 <| h.trans le_compl_compl @[gcongr] theorem compl_le_compl (h : a ≤ b) : bᶜ ≤ aᶜ := compl_anti h @[simp] theorem compl_compl_compl (a : α) : aᶜᶜᶜ = aᶜ := (compl_anti le_compl_compl).antisymm le_compl_compl @[simp] theorem disjoint_compl_compl_left_iff : Disjoint aᶜᶜ b ↔ Disjoint a b := by simp_rw [← le_compl_iff_disjoint_left, compl_compl_compl] @[simp] theorem disjoint_compl_compl_right_iff : Disjoint a bᶜᶜ ↔ Disjoint a b := by simp_rw [← le_compl_iff_disjoint_right, compl_compl_compl] theorem compl_sup_compl_le : aᶜ ⊔ bᶜ ≤ (a ⊓ b)ᶜ := sup_le (compl_anti inf_le_left) <| compl_anti inf_le_right theorem compl_compl_inf_distrib (a b : α) : (a ⊓ b)ᶜᶜ = aᶜᶜ ⊓ bᶜᶜ := by refine ((compl_anti compl_sup_compl_le).trans (compl_sup_distrib _ _).le).antisymm ?_ rw [le_compl_iff_disjoint_right, disjoint_assoc, disjoint_compl_compl_left_iff, disjoint_left_comm, disjoint_compl_compl_left_iff, ← disjoint_assoc, inf_comm] exact disjoint_compl_right theorem compl_compl_himp_distrib (a b : α) : (a ⇨ b)ᶜᶜ = aᶜᶜ ⇨ bᶜᶜ := by apply le_antisymm · rw [le_himp_iff, ← compl_compl_inf_distrib] exact compl_anti (compl_anti himp_inf_le) · refine le_compl_comm.1 ((compl_anti compl_sup_le_himp).trans ?_) rw [compl_sup_distrib, le_compl_iff_disjoint_right, disjoint_right_comm, ← le_compl_iff_disjoint_right] exact inf_himp_le instance OrderDual.instCoheytingAlgebra : CoheytingAlgebra αᵒᵈ where hnot := toDual ∘ compl ∘ ofDual sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff top_sdiff := @himp_bot α _ @[simp] theorem ofDual_hnot (a : αᵒᵈ) : ofDual (¬a) = (ofDual a)ᶜ := rfl @[simp] theorem toDual_compl (a : α) : toDual aᶜ = ¬toDual a := rfl instance Prod.instHeytingAlgebra [HeytingAlgebra β] : HeytingAlgebra (α × β) where himp_bot a := Prod.ext_iff.2 ⟨himp_bot a.1, himp_bot a.2⟩ instance Pi.instHeytingAlgebra {α : ι → Type*} [∀ i, HeytingAlgebra (α i)] : HeytingAlgebra (∀ i, α i) where himp_bot f := funext fun i ↦ himp_bot (f i) end HeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] {a b : α} @[simp] theorem top_sdiff' (a : α) : ⊤ \ a = ¬a := CoheytingAlgebra.top_sdiff _ @[simp] theorem sdiff_top (a : α) : a \ ⊤ = ⊥ := sdiff_eq_bot_iff.2 le_top theorem hnot_inf_distrib (a b : α) : ¬(a ⊓ b) = ¬a ⊔ ¬b := by simp_rw [← top_sdiff', sdiff_inf_distrib] theorem sdiff_le_hnot : a \ b ≤ ¬b := (sdiff_le_sdiff_right le_top).trans_eq <| top_sdiff' _ theorem sdiff_le_inf_hnot : a \ b ≤ a ⊓ ¬b := le_inf sdiff_le sdiff_le_hnot -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toDistribLattice : DistribLattice α := { ‹CoheytingAlgebra α› with le_sup_inf := fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl } @[simp] theorem hnot_sdiff (a : α) : ¬a \ a = ¬a := by rw [← top_sdiff', sdiff_sdiff, sup_idem] theorem hnot_sdiff_comm (a b : α) : ¬a \ b = ¬b \ a := by simp_rw [← top_sdiff', sdiff_right_comm] theorem hnot_le_iff_codisjoint_right : ¬a ≤ b ↔ Codisjoint a b := by rw [← top_sdiff', sdiff_le_iff, codisjoint_iff_le_sup] theorem hnot_le_iff_codisjoint_left : ¬a ≤ b ↔ Codisjoint b a := hnot_le_iff_codisjoint_right.trans codisjoint_comm theorem hnot_le_comm : ¬a ≤ b ↔ ¬b ≤ a := by rw [hnot_le_iff_codisjoint_right, hnot_le_iff_codisjoint_left] alias ⟨_, Codisjoint.hnot_le_right⟩ := hnot_le_iff_codisjoint_right alias ⟨_, Codisjoint.hnot_le_left⟩ := hnot_le_iff_codisjoint_left theorem codisjoint_hnot_right : Codisjoint a (¬a) := codisjoint_iff_le_sup.2 <| sdiff_le_iff.1 (top_sdiff' _).le theorem codisjoint_hnot_left : Codisjoint (¬a) a := codisjoint_hnot_right.symm theorem LE.le.codisjoint_hnot_left (h : a ≤ b) : Codisjoint (¬a) b := _root_.codisjoint_hnot_left.mono_right h theorem LE.le.codisjoint_hnot_right (h : b ≤ a) : Codisjoint a (¬b) := _root_.codisjoint_hnot_right.mono_left h theorem IsCompl.hnot_eq (h : IsCompl a b) : ¬a = b := h.2.hnot_le_right.antisymm <| Disjoint.le_of_codisjoint h.1.symm codisjoint_hnot_right theorem IsCompl.eq_hnot (h : IsCompl a b) : a = ¬b := h.2.hnot_le_left.antisymm' <| Disjoint.le_of_codisjoint h.1 codisjoint_hnot_right @[simp] theorem sup_hnot_self (a : α) : a ⊔ ¬a = ⊤ := Codisjoint.eq_top codisjoint_hnot_right @[simp] theorem hnot_sup_self (a : α) : ¬a ⊔ a = ⊤ := Codisjoint.eq_top codisjoint_hnot_left @[simp] theorem hnot_bot : ¬(⊥ : α) = ⊤ := eq_of_forall_ge_iff fun a => by rw [hnot_le_iff_codisjoint_left, codisjoint_bot, top_le_iff] @[simp] theorem hnot_top : ¬(⊤ : α) = ⊥ := by rw [← top_sdiff', sdiff_self] theorem hnot_hnot_le : ¬¬a ≤ a := codisjoint_hnot_right.hnot_le_left theorem hnot_anti : Antitone (hnot : α → α) := fun _ _ h => hnot_le_comm.1 <| hnot_hnot_le.trans h theorem hnot_le_hnot (h : a ≤ b) : ¬b ≤ ¬a := hnot_anti h @[simp] theorem hnot_hnot_hnot (a : α) : ¬¬¬a = ¬a := hnot_hnot_le.antisymm <| hnot_anti hnot_hnot_le @[simp] theorem codisjoint_hnot_hnot_left_iff : Codisjoint (¬¬a) b ↔ Codisjoint a b := by simp_rw [← hnot_le_iff_codisjoint_right, hnot_hnot_hnot] @[simp] theorem codisjoint_hnot_hnot_right_iff : Codisjoint a (¬¬b) ↔ Codisjoint a b := by simp_rw [← hnot_le_iff_codisjoint_left, hnot_hnot_hnot] theorem le_hnot_inf_hnot : ¬(a ⊔ b) ≤ ¬a ⊓ ¬b := le_inf (hnot_anti le_sup_left) <| hnot_anti le_sup_right theorem hnot_hnot_sup_distrib (a b : α) : ¬¬(a ⊔ b) = ¬¬a ⊔ ¬¬b := by refine ((hnot_inf_distrib _ _).ge.trans <| hnot_anti le_hnot_inf_hnot).antisymm' ?_ rw [hnot_le_iff_codisjoint_left, codisjoint_assoc, codisjoint_hnot_hnot_left_iff, codisjoint_left_comm, codisjoint_hnot_hnot_left_iff, ← codisjoint_assoc, sup_comm] exact codisjoint_hnot_right theorem hnot_hnot_sdiff_distrib (a b : α) : ¬¬(a \ b) = ¬¬a \ ¬¬b := by apply le_antisymm · refine hnot_le_comm.1 ((hnot_anti sdiff_le_inf_hnot).trans' ?_) rw [hnot_inf_distrib, hnot_le_iff_codisjoint_right, codisjoint_left_comm, ← hnot_le_iff_codisjoint_right] exact le_sdiff_sup · rw [sdiff_le_iff, ← hnot_hnot_sup_distrib] exact hnot_anti (hnot_anti le_sup_sdiff) instance OrderDual.instHeytingAlgebra : HeytingAlgebra αᵒᵈ where compl := toDual ∘ hnot ∘ ofDual himp a b := toDual (ofDual b \ ofDual a) le_himp_iff a b c := by rw [inf_comm]; exact sdiff_le_iff himp_bot := @top_sdiff' α _ @[simp] theorem ofDual_compl (a : αᵒᵈ) : ofDual aᶜ = ¬ofDual a := rfl @[simp] theorem ofDual_himp (a b : αᵒᵈ) : ofDual (a ⇨ b) = ofDual b \ ofDual a := rfl @[simp] theorem toDual_hnot (a : α) : toDual (¬a) = (toDual a)ᶜ := rfl @[simp] theorem toDual_sdiff (a b : α) : toDual (a \ b) = toDual b ⇨ toDual a := rfl instance Prod.instCoheytingAlgebra [CoheytingAlgebra β] : CoheytingAlgebra (α × β) where sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff top_sdiff a := Prod.ext_iff.2 ⟨top_sdiff' a.1, top_sdiff' a.2⟩ instance Pi.instCoheytingAlgebra {α : ι → Type*} [∀ i, CoheytingAlgebra (α i)] : CoheytingAlgebra (∀ i, α i) where top_sdiff f := funext fun i ↦ top_sdiff' (f i) end CoheytingAlgebra section BiheytingAlgebra variable [BiheytingAlgebra α] {a : α} theorem compl_le_hnot : aᶜ ≤ ¬a := (disjoint_compl_left : Disjoint _ a).le_of_codisjoint codisjoint_hnot_right end BiheytingAlgebra /-- Propositions form a Heyting algebra with implication as Heyting implication and negation as complement. -/ instance Prop.instHeytingAlgebra : HeytingAlgebra Prop := { Prop.instDistribLattice, Prop.instBoundedOrder with himp := (· → ·), le_himp_iff := fun _ _ _ => and_imp.symm, himp_bot := fun _ => rfl } @[simp] theorem himp_iff_imp (p q : Prop) : p ⇨ q ↔ p → q := Iff.rfl @[simp] theorem compl_iff_not (p : Prop) : pᶜ ↔ ¬p := Iff.rfl variable (α) in -- See note [reducible non-instances] /-- A bounded linear order is a bi-Heyting algebra by setting * `a ⇨ b = ⊤` if `a ≤ b` and `a ⇨ b = b` otherwise. * `a \ b = ⊥` if `a ≤ b` and `a \ b = a` otherwise. -/ abbrev LinearOrder.toBiheytingAlgebra [LinearOrder α] [BoundedOrder α] : BiheytingAlgebra α := { LinearOrder.toLattice, ‹BoundedOrder α› with himp := fun a b => if a ≤ b then ⊤ else b, compl := fun a => if a = ⊥ then ⊤ else ⊥, le_himp_iff := fun a b c => by split_ifs with h · exact iff_of_true le_top (inf_le_of_right_le h) · rw [inf_le_iff, or_iff_left h], himp_bot := fun _ => if_congr le_bot_iff rfl rfl, sdiff := fun a b => if a ≤ b then ⊥ else a, hnot := fun a => if a = ⊤ then ⊥ else ⊤, sdiff_le_iff := fun a b c => by split_ifs with h · exact iff_of_true bot_le (le_sup_of_le_left h) · rw [le_sup_iff, or_iff_right h], top_sdiff := fun _ => if_congr top_le_iff rfl rfl } instance OrderDual.instBiheytingAlgebra [BiheytingAlgebra α] : BiheytingAlgebra αᵒᵈ where __ := instHeytingAlgebra __ := instCoheytingAlgebra instance Prod.instBiheytingAlgebra [BiheytingAlgebra α] [BiheytingAlgebra β] : BiheytingAlgebra (α × β) where __ := instHeytingAlgebra __ := instCoheytingAlgebra instance Pi.instBiheytingAlgebra {α : ι → Type*} [∀ i, BiheytingAlgebra (α i)] : BiheytingAlgebra (∀ i, α i) where __ := instHeytingAlgebra __ := instCoheytingAlgebra section lift -- See note [reducible non-instances] /-- Pullback a `GeneralizedHeytingAlgebra` along an injection. -/ protected abbrev Function.Injective.generalizedHeytingAlgebra [Max α] [Min α] [Top α] [HImp α] [GeneralizedHeytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : GeneralizedHeytingAlgebra α := { __ := hf.lattice f map_sup map_inf __ := ‹Top α› __ := ‹HImp α› le_top := fun a => by change f _ ≤ _ rw [map_top] exact le_top, le_himp_iff := fun a b c => by change f _ ≤ _ ↔ f _ ≤ _ rw [map_himp, map_inf, le_himp_iff] } -- See note [reducible non-instances] /-- Pullback a `GeneralizedCoheytingAlgebra` along an injection. -/ protected abbrev Function.Injective.generalizedCoheytingAlgebra [Max α] [Min α] [Bot α] [SDiff α] [GeneralizedCoheytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_bot : f ⊥ = ⊥) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : GeneralizedCoheytingAlgebra α := { __ := hf.lattice f map_sup map_inf __ := ‹Bot α› __ := ‹SDiff α› bot_le := fun a => by change f _ ≤ _ rw [map_bot] exact bot_le, sdiff_le_iff := fun a b c => by change f _ ≤ _ ↔ f _ ≤ _ rw [map_sdiff, map_sup, sdiff_le_iff] } -- See note [reducible non-instances] /-- Pullback a `HeytingAlgebra` along an injection. -/ protected abbrev Function.Injective.heytingAlgebra [Max α] [Min α] [Top α] [Bot α] [HasCompl α] [HImp α] [HeytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : HeytingAlgebra α := { __ := hf.generalizedHeytingAlgebra f map_sup map_inf map_top map_himp __ := ‹Bot α› __ := ‹HasCompl α› bot_le := fun a => by change f _ ≤ _ rw [map_bot] exact bot_le, himp_bot := fun a => hf <| by rw [map_himp, map_compl, map_bot, himp_bot] } -- See note [reducible non-instances] /-- Pullback a `CoheytingAlgebra` along an injection. -/ protected abbrev Function.Injective.coheytingAlgebra [Max α] [Min α] [Top α] [Bot α] [HNot α] [SDiff α] [CoheytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_hnot : ∀ a, f (¬a) = ¬f a) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : CoheytingAlgebra α := { __ := hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff __ := ‹Top α› __ := ‹HNot α› le_top := fun a => by change f _ ≤ _ rw [map_top] exact le_top, top_sdiff := fun a => hf <| by rw [map_sdiff, map_hnot, map_top, top_sdiff'] } -- See note [reducible non-instances] /-- Pullback a `BiheytingAlgebra` along an injection. -/ protected abbrev Function.Injective.biheytingAlgebra [Max α] [Min α] [Top α] [Bot α] [HasCompl α] [HNot α] [HImp α] [SDiff α] [BiheytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_hnot : ∀ a, f (¬a) = ¬f a) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : BiheytingAlgebra α := { hf.heytingAlgebra f map_sup map_inf map_top map_bot map_compl map_himp, hf.coheytingAlgebra f map_sup map_inf map_top map_bot map_hnot map_sdiff with } end lift namespace PUnit variable (a b : PUnit.{u + 1}) instance instBiheytingAlgebra : BiheytingAlgebra PUnit.{u + 1} := { PUnit.instLinearOrder.{u} with top := unit, bot := unit, sup := fun _ _ => unit, inf := fun _ _ => unit, compl := fun _ => unit, sdiff := fun _ _ => unit, hnot := fun _ => unit, himp := fun _ _ => unit, le_top := fun _ => trivial, le_sup_left := fun _ _ => trivial, le_sup_right := fun _ _ => trivial, sup_le := fun _ _ _ _ _ => trivial, inf_le_left := fun _ _ => trivial, inf_le_right := fun _ _ => trivial, le_inf := fun _ _ _ _ _ => trivial, bot_le := fun _ => trivial, le_himp_iff := fun _ _ _ => Iff.rfl, himp_bot := fun _ => rfl, top_sdiff := fun _ => rfl, sdiff_le_iff := fun _ _ _ => Iff.rfl } @[simp] theorem top_eq : (⊤ : PUnit) = unit := rfl @[simp] theorem bot_eq : (⊥ : PUnit) = unit := rfl @[simp] theorem sup_eq : a ⊔ b = unit := rfl @[simp] theorem inf_eq : a ⊓ b = unit := rfl @[simp] theorem compl_eq : aᶜ = unit := rfl @[simp] theorem sdiff_eq : a \ b = unit := rfl @[simp] theorem hnot_eq : ¬a = unit := rfl @[simp] theorem himp_eq : a ⇨ b = unit := rfl end PUnit
.lake/packages/mathlib/Mathlib/Order/Heyting/Hom.lean
import Mathlib.Order.Hom.BoundedLattice /-! # Heyting algebra morphisms A Heyting homomorphism between two Heyting algebras is a bounded lattice homomorphism that preserves Heyting implication. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `HeytingHom`: Heyting homomorphisms. * `CoheytingHom`: Co-Heyting homomorphisms. * `BiheytingHom`: Bi-Heyting homomorphisms. ## Typeclasses * `HeytingHomClass` * `CoheytingHomClass` * `BiheytingHomClass` -/ open Function variable {F α β γ δ : Type*} /-- The type of Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that preserve Heyting implication. -/ structure HeytingHom (α β : Type*) [HeytingAlgebra α] [HeytingAlgebra β] extends LatticeHom α β where /-- The proposition that a Heyting homomorphism preserves the bottom element. -/ protected map_bot' : toFun ⊥ = ⊥ /-- The proposition that a Heyting homomorphism preserves the Heyting implication. -/ protected map_himp' : ∀ a b, toFun (a ⇨ b) = toFun a ⇨ toFun b /-- The type of co-Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that preserve difference. -/ structure CoheytingHom (α β : Type*) [CoheytingAlgebra α] [CoheytingAlgebra β] extends LatticeHom α β where /-- The proposition that a co-Heyting homomorphism preserves the top element. -/ protected map_top' : toFun ⊤ = ⊤ /-- The proposition that a co-Heyting homomorphism preserves the difference operation. -/ protected map_sdiff' : ∀ a b, toFun (a \ b) = toFun a \ toFun b /-- The type of bi-Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that preserve Heyting implication and difference. -/ structure BiheytingHom (α β : Type*) [BiheytingAlgebra α] [BiheytingAlgebra β] extends LatticeHom α β where /-- The proposition that a bi-Heyting homomorphism preserves the Heyting implication. -/ protected map_himp' : ∀ a b, toFun (a ⇨ b) = toFun a ⇨ toFun b /-- The proposition that a bi-Heyting homomorphism preserves the difference operation. -/ protected map_sdiff' : ∀ a b, toFun (a \ b) = toFun a \ toFun b /-- `HeytingHomClass F α β` states that `F` is a type of Heyting homomorphisms. You should extend this class when you extend `HeytingHom`. -/ class HeytingHomClass (F α β : Type*) [HeytingAlgebra α] [HeytingAlgebra β] [FunLike F α β] : Prop extends LatticeHomClass F α β where /-- The proposition that a Heyting homomorphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ /-- The proposition that a Heyting homomorphism preserves the Heyting implication. -/ map_himp (f : F) : ∀ a b, f (a ⇨ b) = f a ⇨ f b /-- `CoheytingHomClass F α β` states that `F` is a type of co-Heyting homomorphisms. You should extend this class when you extend `CoheytingHom`. -/ class CoheytingHomClass (F α β : Type*) [CoheytingAlgebra α] [CoheytingAlgebra β] [FunLike F α β] : Prop extends LatticeHomClass F α β where /-- The proposition that a co-Heyting homomorphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- The proposition that a co-Heyting homomorphism preserves the difference operation. -/ map_sdiff (f : F) : ∀ a b, f (a \ b) = f a \ f b /-- `BiheytingHomClass F α β` states that `F` is a type of bi-Heyting homomorphisms. You should extend this class when you extend `BiheytingHom`. -/ class BiheytingHomClass (F α β : Type*) [BiheytingAlgebra α] [BiheytingAlgebra β] [FunLike F α β] : Prop extends LatticeHomClass F α β where /-- The proposition that a bi-Heyting homomorphism preserves the Heyting implication. -/ map_himp (f : F) : ∀ a b, f (a ⇨ b) = f a ⇨ f b /-- The proposition that a bi-Heyting homomorphism preserves the difference operation. -/ map_sdiff (f : F) : ∀ a b, f (a \ b) = f a \ f b export HeytingHomClass (map_himp) export CoheytingHomClass (map_sdiff) attribute [simp] map_himp map_sdiff section Hom variable [FunLike F α β] /-! This section passes in some instances implicitly. See note [implicit instance arguments] -/ -- See note [lower instance priority] instance (priority := 100) HeytingHomClass.toBoundedLatticeHomClass [HeytingAlgebra α] {_ : HeytingAlgebra β} [HeytingHomClass F α β] : BoundedLatticeHomClass F α β := { ‹HeytingHomClass F α β› with map_top := fun f => by rw [← @himp_self α _ ⊥, ← himp_self, map_himp] } -- See note [lower instance priority] instance (priority := 100) CoheytingHomClass.toBoundedLatticeHomClass [CoheytingAlgebra α] {_ : CoheytingAlgebra β} [CoheytingHomClass F α β] : BoundedLatticeHomClass F α β := { ‹CoheytingHomClass F α β› with map_bot := fun f => by rw [← @sdiff_self α _ ⊤, ← sdiff_self, map_sdiff] } -- See note [lower instance priority] instance (priority := 100) BiheytingHomClass.toHeytingHomClass [BiheytingAlgebra α] {_ : BiheytingAlgebra β} [BiheytingHomClass F α β] : HeytingHomClass F α β := { ‹BiheytingHomClass F α β› with map_bot := fun f => by rw [← @sdiff_self α _ ⊤, ← sdiff_self, BiheytingHomClass.map_sdiff] } -- See note [lower instance priority] instance (priority := 100) BiheytingHomClass.toCoheytingHomClass [BiheytingAlgebra α] {_ : BiheytingAlgebra β} [BiheytingHomClass F α β] : CoheytingHomClass F α β := { ‹BiheytingHomClass F α β› with map_top := fun f => by rw [← @himp_self α _ ⊥, ← himp_self, map_himp] } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toHeytingHomClass [HeytingAlgebra α] {_ : HeytingAlgebra β} [OrderIsoClass F α β] : HeytingHomClass F α β := { OrderIsoClass.toBoundedLatticeHomClass with map_himp := fun f a b => eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_himp_iff] rw [← OrderIsoClass.map_le_map_iff f] simp } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toCoheytingHomClass [CoheytingAlgebra α] {_ : CoheytingAlgebra β} [OrderIsoClass F α β] : CoheytingHomClass F α β := { OrderIsoClass.toBoundedLatticeHomClass with map_sdiff := fun f a b => eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sdiff_le_iff] rw [← OrderIsoClass.map_le_map_iff f] simp } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBiheytingHomClass [BiheytingAlgebra α] {_ : BiheytingAlgebra β} [OrderIsoClass F α β] : BiheytingHomClass F α β := { OrderIsoClass.toLatticeHomClass with map_himp := fun f a b => eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_himp_iff] rw [← OrderIsoClass.map_le_map_iff f] simp map_sdiff := fun f a b => eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sdiff_le_iff] rw [← OrderIsoClass.map_le_map_iff f] simp } end Equiv variable [FunLike F α β] instance BoundedLatticeHomClass.toBiheytingHomClass [BooleanAlgebra α] [BooleanAlgebra β] [BoundedLatticeHomClass F α β] : BiheytingHomClass F α β := { ‹BoundedLatticeHomClass F α β› with map_himp := fun f a b => by rw [himp_eq, himp_eq, map_sup, (isCompl_compl.map _).compl_eq] map_sdiff := fun f a b => by rw [sdiff_eq, sdiff_eq, map_inf, (isCompl_compl.map _).compl_eq] } section HeytingAlgebra open scoped symmDiff variable [HeytingAlgebra α] [HeytingAlgebra β] [HeytingHomClass F α β] (f : F) @[simp] theorem map_compl (a : α) : f aᶜ = (f a)ᶜ := by rw [← himp_bot, ← himp_bot, map_himp, map_bot] @[simp] theorem map_bihimp (a b : α) : f (a ⇔ b) = f a ⇔ f b := by simp_rw [bihimp, map_inf, map_himp] end HeytingAlgebra section CoheytingAlgebra open scoped symmDiff variable [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingHomClass F α β] (f : F) @[simp] theorem map_hnot (a : α) : f (¬a) = ¬f a := by rw [← top_sdiff', ← top_sdiff', map_sdiff, map_top] @[simp] theorem map_symmDiff (a b : α) : f (a ∆ b) = f a ∆ f b := by simp_rw [symmDiff, map_sup, map_sdiff] end CoheytingAlgebra instance [HeytingAlgebra α] [HeytingAlgebra β] [HeytingHomClass F α β] : CoeTC F (HeytingHom α β) := ⟨fun f => { toFun := f map_sup' := map_sup f map_inf' := map_inf f map_bot' := map_bot f map_himp' := map_himp f }⟩ instance [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingHomClass F α β] : CoeTC F (CoheytingHom α β) := ⟨fun f => { toFun := f map_sup' := map_sup f map_inf' := map_inf f map_top' := map_top f map_sdiff' := map_sdiff f }⟩ instance [BiheytingAlgebra α] [BiheytingAlgebra β] [BiheytingHomClass F α β] : CoeTC F (BiheytingHom α β) := ⟨fun f => { toFun := f map_sup' := map_sup f map_inf' := map_inf f map_himp' := map_himp f map_sdiff' := map_sdiff f }⟩ namespace HeytingHom variable [HeytingAlgebra α] [HeytingAlgebra β] [HeytingAlgebra γ] [HeytingAlgebra δ] instance instFunLike : FunLike (HeytingHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr instance instHeytingHomClass : HeytingHomClass (HeytingHom α β) α β where map_sup f := f.map_sup' map_inf f := f.map_inf' map_bot f := f.map_bot' map_himp := HeytingHom.map_himp' theorem toFun_eq_coe {f : HeytingHom α β} : f.toFun = ⇑f := rfl @[simp] theorem toFun_eq_coe_aux {f : HeytingHom α β} : (↑f.toLatticeHom) = ⇑f := rfl @[ext] theorem ext {f g : HeytingHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `HeytingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : HeytingHom α β) (f' : α → β) (h : f' = f) : HeytingHom α β where toFun := f' map_sup' := by simpa only [h] using map_sup f map_inf' := by simpa only [h] using map_inf f map_bot' := by simpa only [h] using map_bot f map_himp' := by simpa only [h] using map_himp f @[simp] theorem coe_copy (f : HeytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : HeytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `HeytingHom`. -/ protected def id : HeytingHom α α := { BotHom.id _ with toLatticeHom := LatticeHom.id _ map_himp' := fun _ _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(HeytingHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : HeytingHom.id α a = a := rfl instance : Inhabited (HeytingHom α α) := ⟨HeytingHom.id _⟩ instance : PartialOrder (HeytingHom α β) := PartialOrder.lift _ DFunLike.coe_injective /-- Composition of `HeytingHom`s as a `HeytingHom`. -/ def comp (f : HeytingHom β γ) (g : HeytingHom α β) : HeytingHom α γ := { f.toLatticeHom.comp g.toLatticeHom with toFun := f ∘ g map_bot' := by simp map_himp' := fun a b => by simp } variable {f f₁ f₂ : HeytingHom α β} {g g₁ g₂ : HeytingHom β γ} @[simp] theorem coe_comp (f : HeytingHom β γ) (g : HeytingHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : HeytingHom β γ) (g : HeytingHom α β) (a : α) : f.comp g a = f (g a) := rfl @[simp] theorem comp_assoc (f : HeytingHom γ δ) (g : HeytingHom β γ) (h : HeytingHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : HeytingHom α β) : f.comp (HeytingHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : HeytingHom α β) : (HeytingHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => HeytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end HeytingHom namespace CoheytingHom variable [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingAlgebra γ] [CoheytingAlgebra δ] instance : FunLike (CoheytingHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr instance : CoheytingHomClass (CoheytingHom α β) α β where map_sup f := f.map_sup' map_inf f := f.map_inf' map_top f := f.map_top' map_sdiff := CoheytingHom.map_sdiff' theorem toFun_eq_coe {f : CoheytingHom α β} : f.toFun = (f : α → β) := rfl @[simp] theorem toFun_eq_coe_aux {f : CoheytingHom α β} : (↑f.toLatticeHom) = ⇑f := rfl @[ext] theorem ext {f g : CoheytingHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `CoheytingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : CoheytingHom α β where toFun := f' map_sup' := by simpa only [h] using map_sup f map_inf' := by simpa only [h] using map_inf f map_top' := by simpa only [h] using map_top f map_sdiff' := by simpa only [h] using map_sdiff f @[simp] theorem coe_copy (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `CoheytingHom`. -/ protected def id : CoheytingHom α α := { TopHom.id _ with toLatticeHom := LatticeHom.id _ map_sdiff' := fun _ _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(CoheytingHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : CoheytingHom.id α a = a := rfl instance : Inhabited (CoheytingHom α α) := ⟨CoheytingHom.id _⟩ instance : PartialOrder (CoheytingHom α β) := PartialOrder.lift _ DFunLike.coe_injective /-- Composition of `CoheytingHom`s as a `CoheytingHom`. -/ def comp (f : CoheytingHom β γ) (g : CoheytingHom α β) : CoheytingHom α γ := { f.toLatticeHom.comp g.toLatticeHom with toFun := f ∘ g map_top' := by simp map_sdiff' := fun a b => by simp } variable {f f₁ f₂ : CoheytingHom α β} {g g₁ g₂ : CoheytingHom β γ} @[simp] theorem coe_comp (f : CoheytingHom β γ) (g : CoheytingHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : CoheytingHom β γ) (g : CoheytingHom α β) (a : α) : f.comp g a = f (g a) := rfl @[simp] theorem comp_assoc (f : CoheytingHom γ δ) (g : CoheytingHom β γ) (h : CoheytingHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : CoheytingHom α β) : f.comp (CoheytingHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : CoheytingHom α β) : (CoheytingHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => CoheytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end CoheytingHom namespace BiheytingHom variable [BiheytingAlgebra α] [BiheytingAlgebra β] [BiheytingAlgebra γ] [BiheytingAlgebra δ] instance : FunLike (BiheytingHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr instance : BiheytingHomClass (BiheytingHom α β) α β where map_sup f := f.map_sup' map_inf f := f.map_inf' map_himp f := f.map_himp' map_sdiff f := f.map_sdiff' theorem toFun_eq_coe {f : BiheytingHom α β} : f.toFun = (f : α → β) := rfl @[simp] theorem toFun_eq_coe_aux {f : BiheytingHom α β} : (↑f.toLatticeHom) = ⇑f := rfl @[ext] theorem ext {f g : BiheytingHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `BiheytingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : BiheytingHom α β where toFun := f' map_sup' := by simpa only [h] using map_sup f map_inf' := by simpa only [h] using map_inf f map_himp' := by simpa only [h] using map_himp f map_sdiff' := by simpa only [h] using map_sdiff f @[simp] theorem coe_copy (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `BiheytingHom`. -/ protected def id : BiheytingHom α α := { HeytingHom.id _, CoheytingHom.id _ with toLatticeHom := LatticeHom.id _ } @[simp, norm_cast] theorem coe_id : ⇑(BiheytingHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : BiheytingHom.id α a = a := rfl instance : Inhabited (BiheytingHom α α) := ⟨BiheytingHom.id _⟩ instance : PartialOrder (BiheytingHom α β) := PartialOrder.lift _ DFunLike.coe_injective /-- Composition of `BiheytingHom`s as a `BiheytingHom`. -/ def comp (f : BiheytingHom β γ) (g : BiheytingHom α β) : BiheytingHom α γ := { f.toLatticeHom.comp g.toLatticeHom with toFun := f ∘ g map_himp' := fun a b => by simp map_sdiff' := fun a b => by simp } variable {f f₁ f₂ : BiheytingHom α β} {g g₁ g₂ : BiheytingHom β γ} @[simp] theorem coe_comp (f : BiheytingHom β γ) (g : BiheytingHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : BiheytingHom β γ) (g : BiheytingHom α β) (a : α) : f.comp g a = f (g a) := rfl @[simp] theorem comp_assoc (f : BiheytingHom γ δ) (g : BiheytingHom β γ) (h : BiheytingHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : BiheytingHom α β) : f.comp (BiheytingHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : BiheytingHom α β) : (BiheytingHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => BiheytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end BiheytingHom
.lake/packages/mathlib/Mathlib/Order/Extension/Linear.lean
import Mathlib.Order.Zorn /-! # Extend a partial order to a linear order This file constructs a linear order which is an extension of the given partial order, using Zorn's lemma. -/ universe u open Set /-- **Szpilrajn extension theorem**: any partial order can be extended to a linear order. -/ theorem extend_partialOrder {α : Type u} (r : α → α → Prop) [IsPartialOrder α r] : ∃ s : α → α → Prop, IsLinearOrder α s ∧ r ≤ s := by let S := { s | IsPartialOrder α s } have hS : ∀ c, c ⊆ S → IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ S, ∀ z ∈ c, z ≤ ub := by rintro c hc₁ hc₂ s hs haveI := (hc₁ hs).1 refine ⟨sSup c, ?_, fun z hz => le_sSup hz⟩ refine { refl := ?_ trans := ?_ antisymm := ?_ } <;> simp_rw [binary_relation_sSup_iff] · intro x exact ⟨s, hs, refl x⟩ · rintro x y z ⟨s₁, h₁s₁, h₂s₁⟩ ⟨s₂, h₁s₂, h₂s₂⟩ haveI : IsPartialOrder _ _ := hc₁ h₁s₁ haveI : IsPartialOrder _ _ := hc₁ h₁s₂ rcases hc₂.total h₁s₁ h₁s₂ with h | h · exact ⟨s₂, h₁s₂, _root_.trans (h _ _ h₂s₁) h₂s₂⟩ · exact ⟨s₁, h₁s₁, _root_.trans h₂s₁ (h _ _ h₂s₂)⟩ · rintro x y ⟨s₁, h₁s₁, h₂s₁⟩ ⟨s₂, h₁s₂, h₂s₂⟩ haveI : IsPartialOrder _ _ := hc₁ h₁s₁ haveI : IsPartialOrder _ _ := hc₁ h₁s₂ rcases hc₂.total h₁s₁ h₁s₂ with h | h · exact antisymm (h _ _ h₂s₁) h₂s₂ · apply antisymm h₂s₁ (h _ _ h₂s₂) obtain ⟨s, hrs, hs⟩ := zorn_le_nonempty₀ S hS r ‹_› haveI : IsPartialOrder α s := hs.prop refine ⟨s, { total := ?_, refl := hs.1.refl, trans := hs.1.trans, antisymm := hs.1.antisymm }, hrs⟩ intro x y by_contra! h let s' x' y' := s x' y' ∨ s x' x ∧ s y y' rw [hs.eq_of_le (y := s') ?_ fun _ _ ↦ Or.inl] at h · apply h.1 (Or.inr ⟨refl _, refl _⟩) · refine { refl := fun x ↦ Or.inl (refl _) trans := ?_ antisymm := ?_ } · rintro a b c (ab | ⟨ax : s a x, yb : s y b⟩) (bc | ⟨bx : s b x, yc : s y c⟩) · exact Or.inl (_root_.trans ab bc) · exact Or.inr ⟨_root_.trans ab bx, yc⟩ · exact Or.inr ⟨ax, _root_.trans yb bc⟩ · exact Or.inr ⟨ax, yc⟩ rintro a b (ab | ⟨ax : s a x, yb : s y b⟩) (ba | ⟨bx : s b x, ya : s y a⟩) · exact antisymm ab ba · exact (h.2 (_root_.trans ya (_root_.trans ab bx))).elim · exact (h.2 (_root_.trans yb (_root_.trans ba ax))).elim · exact (h.2 (_root_.trans yb bx)).elim /-- A type alias for `α`, intended to extend a partial order on `α` to a linear order. -/ def LinearExtension (α : Type u) : Type u := α noncomputable instance {α : Type u} [PartialOrder α] : LinearOrder (LinearExtension α) where le := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose le_refl := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.1.1.1 le_trans := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.1.2.1 le_antisymm := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.2.1 le_total := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.2.1 toDecidableLE := Classical.decRel _ /-- The embedding of `α` into `LinearExtension α` as an order homomorphism. -/ noncomputable def toLinearExtension {α : Type u} [PartialOrder α] : α →o LinearExtension α where toFun x := x monotone' := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.2 instance {α : Type u} [Inhabited α] : Inhabited (LinearExtension α) := ⟨(default : α)⟩
.lake/packages/mathlib/Mathlib/Order/Extension/Well.lean
import Mathlib.Data.Prod.Lex import Mathlib.SetTheory.Ordinal.Rank /-! # Extend a well-founded order to a well-order This file constructs a well-order (linear well-founded order) which is an extension of a given well-founded order. ## Proof idea We can map our order into two well-orders: * the first map respects the order but isn't necessarily injective. Namely, this is the *rank* function `IsWellFounded.rank : α → Ordinal`. * the second map is injective but doesn't necessarily respect the order. This is an arbitrary embedding into `Cardinal` given by `embeddingToCardinal`. Then their lexicographic product is a well-founded linear order which our original order injects in. ## Implementation note The definition in `mathlib` 3 used an auxiliary well-founded order on `α` lifted from `Cardinal`, instead of using `Cardinal` directly. The new definition is definitionally equal to the `mathlib` 3 version but avoids non-standard instances. ## Tags well-founded relation, well order, extension -/ universe u variable {α : Type u} {r : α → α → Prop} namespace IsWellFounded variable {α : Type u} (r : α → α → Prop) [IsWellFounded α r] /-- An arbitrary well order on `α` that extends `r`. The construction maps `r` into two well-orders: the first map is `IsWellFounded.rank`, which is not necessarily injective but respects the order `r`; the other map is the identity (with an arbitrarily chosen well-order on `α`), which is injective but doesn't respect `r`. By taking the lexicographic product of the two, we get both properties, so we can pull it back and get a well-order that extend our original order `r`. Another way to view this is that we choose an arbitrary well-order to serve as a tiebreak between two elements of same rank. -/ noncomputable def wellOrderExtension : LinearOrder α := @LinearOrder.lift' α (Ordinal ×ₗ Cardinal) _ (fun a : α => (rank r a, embeddingToCardinal a)) fun _ _ h => embeddingToCardinal.injective <| congr_arg Prod.snd h instance wellOrderExtension.isWellFounded_lt : IsWellFounded α (wellOrderExtension r).lt := ⟨InvImage.wf (fun a : α => (rank r a, embeddingToCardinal a)) <| Ordinal.lt_wf.prod_lex Cardinal.lt_wf⟩ instance wellOrderExtension.isWellOrder_lt : IsWellOrder α (wellOrderExtension r).lt where /-- Any well-founded relation can be extended to a well-ordering on that type. -/ theorem exists_well_order_ge : ∃ s, r ≤ s ∧ IsWellOrder α s := ⟨(wellOrderExtension r).lt, fun _ _ h => Prod.Lex.left _ _ (rank_lt_of_rel h), ⟨⟩⟩ end IsWellFounded /-- A type alias for `α`, intended to extend a well-founded order on `α` to a well-order. -/ def WellOrderExtension (α : Type*) : Type _ := α instance [Inhabited α] : Inhabited (WellOrderExtension α) := ‹_› /-- "Identity" equivalence between a well-founded order and its well-order extension. -/ def toWellOrderExtension : α ≃ WellOrderExtension α := Equiv.refl _ noncomputable instance [LT α] [h : WellFoundedLT α] : LinearOrder (WellOrderExtension α) := h.wellOrderExtension instance WellOrderExtension.wellFoundedLT [LT α] [WellFoundedLT α] : WellFoundedLT (WellOrderExtension α) := IsWellFounded.wellOrderExtension.isWellFounded_lt (α := α) (· < ·) theorem toWellOrderExtension_strictMono [Preorder α] [WellFoundedLT α] : StrictMono (toWellOrderExtension : α → WellOrderExtension α) := fun _ _ h => Prod.Lex.left _ _ <| IsWellFounded.rank_lt_of_rel h
.lake/packages/mathlib/Mathlib/Order/Fin/Tuple.lean
import Mathlib.Data.Fin.VecNotation import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Order.Fin.Basic import Mathlib.Order.PiLex import Mathlib.Order.Interval.Set.Defs /-! # Order properties on tuples -/ assert_not_exists Monoid open Function Set namespace Fin variable {m n : ℕ} {α : Fin (n + 1) → Type*} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ) (i : Fin n) (y : α i.succ) (z : α 0) lemma pi_lex_lt_cons_cons {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} (s : ∀ {i : Fin n.succ}, α i → α i → Prop) : Pi.Lex (· < ·) (@s) (Fin.cons x₀ x) (Fin.cons y₀ y) ↔ s x₀ y₀ ∨ x₀ = y₀ ∧ Pi.Lex (· < ·) (@fun i : Fin n ↦ @s i.succ) x y := by simp_rw [Pi.Lex, Fin.exists_fin_succ, Fin.cons_succ, Fin.cons_zero, Fin.forall_iff_succ] simp [and_assoc, exists_and_left] variable [∀ i, Preorder (α i)] lemma insertNth_mem_Icc {i : Fin (n + 1)} {x : α i} {p : ∀ j, α (i.succAbove j)} {q₁ q₂ : ∀ j, α j} : i.insertNth x p ∈ Icc q₁ q₂ ↔ x ∈ Icc (q₁ i) (q₂ i) ∧ p ∈ Icc (fun j ↦ q₁ (i.succAbove j)) fun j ↦ q₂ (i.succAbove j) := by simp only [mem_Icc, insertNth_le_iff, le_insertNth_iff, and_assoc, @and_left_comm (x ≤ q₂ i)] lemma preimage_insertNth_Icc_of_mem {i : Fin (n + 1)} {x : α i} {q₁ q₂ : ∀ j, α j} (hx : x ∈ Icc (q₁ i) (q₂ i)) : i.insertNth x ⁻¹' Icc q₁ q₂ = Icc (fun j ↦ q₁ (i.succAbove j)) fun j ↦ q₂ (i.succAbove j) := Set.ext fun p ↦ by simp only [mem_preimage, insertNth_mem_Icc, hx, true_and] lemma preimage_insertNth_Icc_of_notMem {i : Fin (n + 1)} {x : α i} {q₁ q₂ : ∀ j, α j} (hx : x ∉ Icc (q₁ i) (q₂ i)) : i.insertNth x ⁻¹' Icc q₁ q₂ = ∅ := Set.ext fun p ↦ by simp only [mem_preimage, insertNth_mem_Icc, hx, false_and, mem_empty_iff_false] @[deprecated (since := "2025-05-23")] alias preimage_insertNth_Icc_of_not_mem := preimage_insertNth_Icc_of_notMem end Fin open Fin Matrix variable {α : Type*} open scoped Relator in lemma liftFun_vecCons {n : ℕ} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} {a : α} : ((· < ·) ⇒ r) (vecCons a f) (vecCons a f) ↔ r a (f 0) ∧ ((· < ·) ⇒ r) f f := by simp only [liftFun_iff_succ r, forall_iff_succ, cons_val_succ, cons_val_zero, ← succ_castSucc, castSucc_zero] variable [Preorder α] {n : ℕ} {f : Fin (n + 1) → α} {a : α} @[simp] lemma strictMono_vecCons : StrictMono (vecCons a f) ↔ a < f 0 ∧ StrictMono f := liftFun_vecCons (· < ·) @[simp] lemma monotone_vecCons : Monotone (vecCons a f) ↔ a ≤ f 0 ∧ Monotone f := by simpa only [monotone_iff_forall_lt] using @liftFun_vecCons α n (· ≤ ·) _ f a @[simp] lemma monotone_vecEmpty : Monotone ![a] | ⟨0, _⟩, ⟨0, _⟩, _ => le_refl _ @[simp] lemma strictMono_vecEmpty : StrictMono ![a] | ⟨0, _⟩, ⟨0, _⟩, h => (irrefl _ h).elim @[simp] lemma strictAnti_vecCons : StrictAnti (vecCons a f) ↔ f 0 < a ∧ StrictAnti f := liftFun_vecCons (· > ·) @[simp] lemma antitone_vecCons : Antitone (vecCons a f) ↔ f 0 ≤ a ∧ Antitone f := monotone_vecCons (α := αᵒᵈ) @[simp] lemma antitone_vecEmpty : Antitone (vecCons a vecEmpty) | ⟨0, _⟩, ⟨0, _⟩, _ => le_rfl @[simp] lemma strictAnti_vecEmpty : StrictAnti (vecCons a vecEmpty) | ⟨0, _⟩, ⟨0, _⟩, h => (irrefl _ h).elim lemma StrictMono.vecCons (hf : StrictMono f) (ha : a < f 0) : StrictMono (vecCons a f) := strictMono_vecCons.2 ⟨ha, hf⟩ lemma StrictAnti.vecCons (hf : StrictAnti f) (ha : f 0 < a) : StrictAnti (vecCons a f) := strictAnti_vecCons.2 ⟨ha, hf⟩ lemma Monotone.vecCons (hf : Monotone f) (ha : a ≤ f 0) : Monotone (vecCons a f) := monotone_vecCons.2 ⟨ha, hf⟩ lemma Antitone.vecCons (hf : Antitone f) (ha : f 0 ≤ a) : Antitone (vecCons a f) := antitone_vecCons.2 ⟨ha, hf⟩ example : Monotone ![1, 2, 2, 3] := by decide variable {n : ℕ} /-- `Π i : Fin 2, α i` is order equivalent to `α 0 × α 1`. See also `OrderIso.finTwoArrowEquiv` for a non-dependent version. -/ def OrderIso.piFinTwoIso (α : Fin 2 → Type*) [∀ i, Preorder (α i)] : (∀ i, α i) ≃o α 0 × α 1 where toEquiv := piFinTwoEquiv α map_rel_iff' := Iff.symm Fin.forall_fin_two /-- The space of functions `Fin 2 → α` is order equivalent to `α × α`. See also `OrderIso.piFinTwoIso`. -/ def OrderIso.finTwoArrowIso (α : Type*) [Preorder α] : (Fin 2 → α) ≃o α × α := { OrderIso.piFinTwoIso fun _ => α with toEquiv := finTwoArrowEquiv α } namespace Fin /-- Order isomorphism between tuples of length `n + 1` and pairs of an element and a tuple of length `n` given by separating out the first element of the tuple. This is `Fin.cons` as an `OrderIso`. -/ @[simps!, simps toEquiv] def consOrderIso (α : Fin (n + 1) → Type*) [∀ i, LE (α i)] : α 0 × (∀ i, α (succ i)) ≃o ∀ i, α i where toEquiv := consEquiv α map_rel_iff' := forall_iff_succ /-- Order isomorphism between tuples of length `n + 1` and pairs of an element and a tuple of length `n` given by separating out the last element of the tuple. This is `Fin.snoc` as an `OrderIso`. -/ @[simps!, simps toEquiv] def snocOrderIso (α : Fin (n + 1) → Type*) [∀ i, LE (α i)] : α (last n) × (∀ i, α (castSucc i)) ≃o ∀ i, α i where toEquiv := snocEquiv α map_rel_iff' := by simp [Pi.le_def, Prod.le_def, forall_iff_castSucc] /-- Order isomorphism between tuples of length `n + 1` and pairs of an element and a tuple of length `n` given by separating out the `p`-th element of the tuple. This is `Fin.insertNth` as an `OrderIso`. -/ @[simps!, simps toEquiv] def insertNthOrderIso (α : Fin (n + 1) → Type*) [∀ i, LE (α i)] (p : Fin (n + 1)) : α p × (∀ i, α (p.succAbove i)) ≃o ∀ i, α i where toEquiv := insertNthEquiv α p map_rel_iff' := by simp [Pi.le_def, Prod.le_def, p.forall_iff_succAbove] @[simp] lemma insertNthOrderIso_zero (α : Fin (n + 1) → Type*) [∀ i, LE (α i)] : insertNthOrderIso α 0 = consOrderIso α := by ext; simp [insertNthOrderIso] /-- Note this lemma can only be written about non-dependent tuples as `insertNth (last n) = snoc` is not a definitional equality. -/ @[simp] lemma insertNthOrderIso_last (n : ℕ) (α : Type*) [LE α] : insertNthOrderIso (fun _ ↦ α) (last n) = snocOrderIso (fun _ ↦ α) := by ext; simp end Fin /-- `Fin.succAbove` as an order isomorphism between `Fin n` and `{x : Fin (n + 1) // x ≠ p}`. -/ def finSuccAboveOrderIso (p : Fin (n + 1)) : Fin n ≃o { x : Fin (n + 1) // x ≠ p } where __ := finSuccAboveEquiv p map_rel_iff' := p.succAboveOrderEmb.map_rel_iff' lemma finSuccAboveOrderIso_apply (p : Fin (n + 1)) (i : Fin n) : finSuccAboveOrderIso p i = ⟨p.succAbove i, p.succAbove_ne i⟩ := rfl lemma finSuccAboveOrderIso_symm_apply_last (x : { x : Fin (n + 1) // x ≠ Fin.last n }) : (finSuccAboveOrderIso (Fin.last n)).symm x = Fin.castLT x.1 (Fin.val_lt_last x.2) := by rw [← Option.some_inj] simp [finSuccAboveOrderIso, finSuccAboveEquiv, OrderIso.symm] lemma finSuccAboveOrderIso_symm_apply_ne_last {p : Fin (n + 1)} (h : p ≠ Fin.last n) (x : { x : Fin (n + 1) // x ≠ p }) : (finSuccAboveEquiv p).symm x = (p.castLT (Fin.val_lt_last h)).predAbove x := by rw [← Option.some_inj] simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_ne_last_apply h x.property /-- Promote a `Fin n` into a larger `Fin m`, as a subtype where the underlying values are retained. This is the `OrderIso` version of `Fin.castLE`. -/ @[simps apply symm_apply] def Fin.castLEOrderIso {n m : ℕ} (h : n ≤ m) : Fin n ≃o { i : Fin m // (i : ℕ) < n } where toFun i := ⟨Fin.castLE h i, by simp⟩ invFun i := ⟨i, i.prop⟩ left_inv _ := by simp right_inv _ := by simp map_rel_iff' := by simp [(strictMono_castLE h).le_iff_le]
.lake/packages/mathlib/Mathlib/Order/Fin/Finset.lean
import Mathlib.Order.Fin.Tuple import Mathlib.Order.Hom.Set import Mathlib.Data.Finset.Insert /-! # Order isomorphisms from Fin to finsets We define order isomorphisms like `Fin.orderIsoTriple` from `Fin 3` to the finset `{a, b, c}` when `a < b` and `b < c`. ## Future works * Do the same for `Set` without too much duplication of code (TODO) * Provide a definition which would take as an input an order isomorphism `e : Fin (n + 1) ≃o s` (with `s : Set α` (or `Finset α`)) and extend it to an order isomorphism `Fin (n + 2) ≃o Finset.insert i s` when `i < e 0` (TODO). -/ namespace Fin variable {α : Type*} [Preorder α] /-- This is the order isomorphism from `Fin 1` to a finset `{a}`. -/ noncomputable def orderIsoSingleton (a : α) : Fin 1 ≃o ({a} : Finset α) := OrderIso.ofUnique _ _ @[simp] lemma orderIsoSingleton_apply (a : α) (i : Fin 1) : orderIsoSingleton a i = a := rfl variable [DecidableEq α] section variable (a b : α) (hab : a < b) /-- This is the order isomorphism from `Fin 2` to a finset `{a, b}` when `a < b`. -/ noncomputable def orderIsoPair : Fin 2 ≃o ({a, b} : Finset α) := StrictMono.orderIsoOfSurjective ![⟨a, by simp⟩, ⟨b, by simp⟩] (strictMono_vecEmpty.vecCons hab) (fun ⟨x, hx⟩ ↦ by simp only [Finset.mem_insert, Finset.mem_singleton] at hx obtain rfl | rfl := hx · exact ⟨0, rfl⟩ · exact ⟨1, rfl⟩) @[simp] lemma orderIsoPair_zero : orderIsoPair a b hab 0 = a := rfl @[simp] lemma orderIsoPair_one : orderIsoPair a b hab 1 = b := rfl end section variable (a b c : α) (hab : a < b) (hbc : b < c) /-- This is the order isomorphism from `Fin 3` to a finset `{a, b, c}` when `a < b` and `b < c`. -/ noncomputable def orderIsoTriple : Fin 3 ≃o ({a, b, c} : Finset α) := StrictMono.orderIsoOfSurjective ![⟨a, by simp⟩, ⟨b, by simp⟩, ⟨c, by simp⟩] (StrictMono.vecCons (strictMono_vecEmpty.vecCons hbc) hab) (fun ⟨x, hx⟩ ↦ by simp only [Finset.mem_insert, Finset.mem_singleton] at hx obtain rfl | rfl | rfl := hx · exact ⟨0, rfl⟩ · exact ⟨1, rfl⟩ · exact ⟨2, rfl⟩) @[simp] lemma orderIsoTriple_zero : orderIsoTriple a b c hab hbc 0 = a := rfl @[simp] lemma orderIsoTriple_one : orderIsoTriple a b c hab hbc 1 = b := rfl @[simp] lemma orderIsoTriple_two : orderIsoTriple a b c hab hbc 2 = c := rfl end end Fin
.lake/packages/mathlib/Mathlib/Order/Fin/Basic.lean
import Mathlib.Data.Fin.Embedding import Mathlib.Data.Fin.Rev import Mathlib.Order.Hom.Basic /-! # `Fin n` forms a bounded linear order This file contains the linear ordered instance on `Fin n`. `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions * `Fin.orderIsoSubtype` : coercion to `{i // i < n}` as an `OrderIso`; * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.valOrderEmb` : coercion to natural numbers as an `OrderEmbedding`; * `Fin.succOrderEmb` : `Fin.succ` as an `OrderEmbedding`; * `Fin.castLEOrderEmb h` : `Fin.castLE` as an `OrderEmbedding`, embed `Fin n` into `Fin m` when `h : n ≤ m`; * `Fin.castOrderIso` : `Fin.cast` as an `OrderIso`, order isomorphism between `Fin n` and `Fin m` provided that `n = m`, see also `Equiv.finCongr`; * `Fin.castAddOrderEmb m` : `Fin.castAdd` as an `OrderEmbedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccOrderEmb` : `Fin.castSucc` as an `OrderEmbedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatOrderEmb m i` : `Fin.addNat` as an `OrderEmbedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddOrderEmb n i` : `Fin.natAdd` as an `OrderEmbedding`, adds `n` on `i` on the left; * `Fin.revOrderIso`: `Fin.rev` as an `OrderIso`, the antitone involution given by `i ↦ n-(i+1)` -/ assert_not_exists Monoid open Function Nat Set namespace Fin variable {m n : ℕ} /-! ### Instances -/ instance : Max (Fin n) where max x y := ⟨max x y, max_rec' (· < n) x.2 y.2⟩ instance : Min (Fin n) where min x y := ⟨min x y, min_rec' (· < n) x.2 y.2⟩ @[simp, norm_cast] theorem coe_max (a b : Fin n) : ↑(max a b) = (max a b : ℕ) := rfl @[simp, norm_cast] theorem coe_min (a b : Fin n) : ↑(min a b) = (min a b : ℕ) := rfl theorem compare_eq_compare_val (a b : Fin n) : compare a b = compare a.val b.val := rfl instance instLinearOrder : LinearOrder (Fin n) := Fin.val_injective.linearOrder _ Fin.le_iff_val_le_val Fin.lt_iff_val_lt_val coe_min coe_max compare_eq_compare_val instance instBoundedOrder [NeZero n] : BoundedOrder (Fin n) where top := rev 0 le_top i := Nat.le_pred_of_lt i.is_lt bot := 0 bot_le := Fin.zero_le instance instBiheytingAlgebra [NeZero n] : BiheytingAlgebra (Fin n) := LinearOrder.toBiheytingAlgebra (Fin n) /- There is a slight asymmetry here, in the sense that `0` is of type `Fin n` when we have `[NeZero n]` whereas `last n` is of type `Fin (n + 1)`. To address this properly would require a change to std4, defining `NeZero n` and thus re-defining `last n` (and possibly make its argument implicit) as `rev 0`, of type `Fin n`. As we can see from these lemmas, this would be equivalent to the existing definition. -/ /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance instPartialOrder : PartialOrder (Fin n) := inferInstance instance instLattice : Lattice (Fin n) := inferInstance instance instHeytingAlgebra [NeZero n] : HeytingAlgebra (Fin n) := inferInstance instance instCoheytingAlgebra [NeZero n] : CoheytingAlgebra (Fin n) := inferInstance /-! ### Miscellaneous lemmas -/ lemma top_eq_last (n : ℕ) : ⊤ = Fin.last n := rfl lemma bot_eq_zero (n : ℕ) [NeZero n] : ⊥ = (0 : Fin n) := rfl @[simp] theorem rev_bot [NeZero n] : rev (⊥ : Fin n) = ⊤ := rfl @[simp] theorem rev_top [NeZero n] : rev (⊤ : Fin n) = ⊥ := rev_rev _ theorem rev_zero_eq_top (n : ℕ) [NeZero n] : rev (0 : Fin n) = ⊤ := rfl theorem rev_last_eq_bot (n : ℕ) : rev (last n) = ⊥ := by rw [rev_last, bot_eq_zero] @[simp] theorem succ_top (n : ℕ) [NeZero n] : (⊤ : Fin n).succ = ⊤ := by rw [← rev_zero_eq_top, ← rev_zero_eq_top, ← rev_castSucc, castSucc_zero'] @[simp] theorem val_top (n : ℕ) [NeZero n] : ((⊤ : Fin n) : ℕ) = n - 1 := rfl @[simp] theorem zero_eq_top {n : ℕ} [NeZero n] : (0 : Fin n) = ⊤ ↔ n = 1 := by rw [← bot_eq_zero, subsingleton_iff_bot_eq_top, subsingleton_iff_le_one, le_one_iff_eq_zero_or_eq_one, or_iff_right (NeZero.ne n)] @[simp] theorem top_eq_zero {n : ℕ} [NeZero n] : (⊤ : Fin n) = 0 ↔ n = 1 := eq_comm.trans zero_eq_top @[simp] theorem cast_top {m n : ℕ} [NeZero m] [NeZero n] (h : m = n) : (⊤ : Fin m).cast h = ⊤ := by simp [← val_inj, h] section ToFin variable {α : Type*} [Preorder α] {f : α → Fin (n + 1)} lemma strictMono_pred_comp (hf : ∀ a, f a ≠ 0) (hf₂ : StrictMono f) : StrictMono (fun a => pred (f a) (hf a)) := fun _ _ h => pred_lt_pred_iff.2 (hf₂ h) lemma monotone_pred_comp (hf : ∀ a, f a ≠ 0) (hf₂ : Monotone f) : Monotone (fun a => pred (f a) (hf a)) := fun _ _ h => pred_le_pred_iff.2 (hf₂ h) lemma strictMono_castPred_comp (hf : ∀ a, f a ≠ last n) (hf₂ : StrictMono f) : StrictMono (fun a => castPred (f a) (hf a)) := fun _ _ h => castPred_lt_castPred_iff.2 (hf₂ h) lemma monotone_castPred_comp (hf : ∀ a, f a ≠ last n) (hf₂ : Monotone f) : Monotone (fun a => castPred (f a) (hf a)) := fun _ _ h => castPred_le_castPred_iff.2 (hf₂ h) end ToFin section FromFin variable {α : Type*} [Preorder α] {f : Fin (n + 1) → α} /-- A function `f` on `Fin (n + 1)` is strictly monotone if and only if `f i < f (i + 1)` for all `i`. -/ lemma strictMono_iff_lt_succ : StrictMono f ↔ ∀ i : Fin n, f (castSucc i) < f i.succ := liftFun_iff_succ (· < ·) /-- A function `f` on `Fin (n + 1)` is monotone if and only if `f i ≤ f (i + 1)` for all `i`. -/ lemma monotone_iff_le_succ : Monotone f ↔ ∀ i : Fin n, f (castSucc i) ≤ f i.succ := monotone_iff_forall_lt.trans <| liftFun_iff_succ (· ≤ ·) /-- A function `f` on `Fin (n + 1)` is strictly antitone if and only if `f (i + 1) < f i` for all `i`. -/ lemma strictAnti_iff_succ_lt : StrictAnti f ↔ ∀ i : Fin n, f i.succ < f (castSucc i) := liftFun_iff_succ (· > ·) /-- A function `f` on `Fin (n + 1)` is antitone if and only if `f (i + 1) ≤ f i` for all `i`. -/ lemma antitone_iff_succ_le : Antitone f ↔ ∀ i : Fin n, f i.succ ≤ f (castSucc i) := antitone_iff_forall_lt.trans <| liftFun_iff_succ (· ≥ ·) lemma orderHom_injective_iff {α : Type*} [PartialOrder α] {n : ℕ} (f : Fin (n + 1) →o α) : Function.Injective f ↔ ∀ (i : Fin n), f i.castSucc ≠ f i.succ := by constructor · intro hf i hi have := hf hi simp [Fin.ext_iff] at this · intro hf refine (strictMono_iff_lt_succ (f := f).2 fun i ↦ ?_).injective exact lt_of_le_of_ne (f.monotone (Fin.castSucc_le_succ i)) (hf i) end FromFin /-! #### Monotonicity -/ lemma val_strictMono : StrictMono (val : Fin n → ℕ) := fun _ _ ↦ id lemma cast_strictMono {k l : ℕ} (h : k = l) : StrictMono (Fin.cast h) := fun {_ _} h ↦ h lemma strictMono_succ : StrictMono (succ : Fin n → Fin (n + 1)) := fun _ _ ↦ succ_lt_succ lemma strictMono_castLE (h : n ≤ m) : StrictMono (castLE h : Fin n → Fin m) := fun _ _ ↦ id lemma strictMono_castAdd (m) : StrictMono (castAdd m : Fin n → Fin (n + m)) := strictMono_castLE _ lemma strictMono_castSucc : StrictMono (castSucc : Fin n → Fin (n + 1)) := strictMono_castAdd _ lemma strictMono_natAdd (n) : StrictMono (natAdd n : Fin m → Fin (n + m)) := fun i j h ↦ Nat.add_lt_add_left (show i.val < j.val from h) _ lemma strictMono_addNat (m) : StrictMono ((addNat · m) : Fin n → Fin (n + m)) := fun i j h ↦ Nat.add_lt_add_right (show i.val < j.val from h) _ lemma strictMono_succAbove (p : Fin (n + 1)) : StrictMono (succAbove p) := strictMono_castSucc.ite strictMono_succ (fun _ _ hij hj => (castSucc_lt_castSucc_iff.mpr hij).trans hj) fun i => (castSucc_lt_succ i).le variable {p : Fin (n + 1)} {i j : Fin n} @[simp] lemma succAbove_inj : succAbove p i = succAbove p j ↔ i = j := (strictMono_succAbove p).injective.eq_iff @[simp] lemma succAbove_le_succAbove_iff : succAbove p i ≤ succAbove p j ↔ i ≤ j := (strictMono_succAbove p).le_iff_le @[gcongr] alias ⟨_, _root_.GCongr.Fin.succAbove_le_succAbove⟩ := succAbove_le_succAbove_iff @[simp] lemma succAbove_lt_succAbove_iff : succAbove p i < succAbove p j ↔ i < j := (strictMono_succAbove p).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.Fin.succAbove_lt_succAbove⟩ := succAbove_lt_succAbove_iff @[simp] theorem natAdd_inj (m) {i j : Fin n} : natAdd m i = natAdd m j ↔ i = j := (strictMono_natAdd _).injective.eq_iff theorem natAdd_injective (m n : ℕ) : Function.Injective (Fin.natAdd n : Fin m → _) := (strictMono_natAdd _).injective @[simp] theorem natAdd_le_natAdd_iff (m) {i j : Fin n} : natAdd m i ≤ natAdd m j ↔ i ≤ j := (strictMono_natAdd _).le_iff_le @[gcongr] alias ⟨_, _root_.GCongr.Fin.natAdd_le_natAdd⟩ := natAdd_le_natAdd_iff @[simp] theorem natAdd_lt_natAdd_iff (m) {i j : Fin n} : natAdd m i < natAdd m j ↔ i < j := (strictMono_natAdd _).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.Fin.natAdd_lt_natAdd⟩ := natAdd_lt_natAdd_iff @[simp] theorem addNat_inj (m) {i j : Fin n} : i.addNat m = j.addNat m ↔ i = j := (strictMono_addNat _).injective.eq_iff @[simp] theorem addNat_le_addNat_iff (m) {i j : Fin n} : i.addNat m ≤ j.addNat m ↔ i ≤ j := (strictMono_addNat _).le_iff_le @[gcongr] alias ⟨_, _root_.GCongr.Fin.addNat_le_addNat⟩ := addNat_le_addNat_iff @[simp] theorem addNat_lt_addNat_iff (m) {i j : Fin n} : i.addNat m < j.addNat m ↔ i < j := (strictMono_addNat _).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.Fin.addNat_lt_addNat⟩ := addNat_lt_addNat_iff @[simp] theorem castLE_le_castLE_iff {i j : Fin n} (h : n ≤ m) : i.castLE h ≤ j.castLE h ↔ i ≤ j := .rfl @[gcongr] alias ⟨_, _root_.GCongr.Fin.castLE_le_castLE⟩ := castLE_le_castLE_iff @[simp] theorem castLE_lt_castLE_iff {i j : Fin n} (h : n ≤ m) : i.castLE h < j.castLE h ↔ i < j := .rfl @[gcongr] alias ⟨_, _root_.GCongr.Fin.castLE_lt_castLE⟩ := castLE_lt_castLE_iff lemma predAbove_right_monotone (p : Fin n) : Monotone p.predAbove := fun a b H => by dsimp [predAbove] split_ifs with ha hb hb all_goals simp only [le_iff_val_le_val, coe_pred] · exact pred_le_pred H · calc _ ≤ _ := Nat.pred_le _ _ ≤ _ := H · exact le_pred_of_lt ((not_lt.mp ha).trans_lt hb) · exact H lemma predAbove_left_monotone (i : Fin (n + 1)) : Monotone fun p ↦ predAbove p i := fun a b H ↦ by dsimp [predAbove] split_ifs with ha hb hb · rfl · exact pred_le _ · have : b < a := castSucc_lt_castSucc_iff.mpr (hb.trans_le (le_of_not_gt ha)) exact absurd H this.not_ge · rfl @[gcongr] lemma predAbove_le_predAbove {p q : Fin n} (hpq : p ≤ q) {i j : Fin (n + 1)} (hij : i ≤ j) : p.predAbove i ≤ q.predAbove j := (predAbove_right_monotone p hij).trans (predAbove_left_monotone j hpq) /-- `Fin.predAbove p` as an `OrderHom`. -/ @[simps!] def predAboveOrderHom (p : Fin n) : Fin (n + 1) →o Fin n := ⟨p.predAbove, p.predAbove_right_monotone⟩ /-- `predAbove` is injective at the pivot -/ lemma predAbove_left_injective : Injective (@predAbove n) := by intro i j hij obtain ⟨n, rfl⟩ := Nat.exists_add_one_eq.2 i.size_positive wlog h : i < j generalizing i j · simp only [not_lt] at h obtain h | rfl := h.lt_or_eq · exact (this hij.symm h).symm · rfl replace hij := congr_fun hij i.succ rw [predAbove_succ_self, Fin.predAbove_of_le_castSucc _ _ (by simpa), ← Fin.castSucc_inj, castSucc_castPred] at hij exact (i.castSucc_lt_succ.ne hij).elim /-- `predAbove` is injective at the pivot -/ @[simp] lemma predAbove_left_inj {x y : Fin n} : x.predAbove = y.predAbove ↔ x = y := predAbove_left_injective.eq_iff /-! #### Order isomorphisms -/ /-- The equivalence `Fin n ≃ {i // i < n}` is an order isomorphism. -/ @[simps! apply symm_apply] def orderIsoSubtype : Fin n ≃o {i // i < n} := equivSubtype.toOrderIso (by simp [Monotone]) (by simp [Monotone]) /-- `Fin.cast` as an `OrderIso`. `castOrderIso eq i` embeds `i` into an equal `Fin` type. -/ @[simps] def castOrderIso (eq : n = m) : Fin n ≃o Fin m where toEquiv := ⟨Fin.cast eq, Fin.cast eq.symm, leftInverse_cast eq, rightInverse_cast eq⟩ map_rel_iff' := cast_le_cast eq @[simp] lemma symm_castOrderIso (h : n = m) : (castOrderIso h).symm = castOrderIso h.symm := by subst h; rfl @[simp] lemma castOrderIso_refl (h : n = n := rfl) : castOrderIso h = OrderIso.refl (Fin n) := by ext; simp /-- While in many cases `Fin.castOrderIso` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic lemma about `cast`. -/ lemma castOrderIso_toEquiv (h : n = m) : (castOrderIso h).toEquiv = Equiv.cast (h ▸ rfl) := by subst h; rfl /-- `Fin.rev n` as an order-reversing isomorphism. -/ @[simps! apply toEquiv] def revOrderIso : (Fin n)ᵒᵈ ≃o Fin n := ⟨OrderDual.ofDual.trans revPerm, rev_le_rev⟩ @[simp] lemma revOrderIso_symm_apply (i : Fin n) : revOrderIso.symm i = OrderDual.toDual (rev i) := rfl lemma rev_strictAnti : StrictAnti (@rev n) := fun _ _ ↦ rev_lt_rev.mpr lemma rev_anti : Antitone (@rev n) := rev_strictAnti.antitone /-! #### Order embeddings -/ /-- The inclusion map `Fin n → ℕ` is an order embedding. -/ @[simps! apply] def valOrderEmb (n) : Fin n ↪o ℕ := ⟨valEmbedding, Iff.rfl⟩ namespace OrderEmbedding @[simps] instance : Inhabited (Fin n ↪o ℕ) where default := Fin.valOrderEmb n end OrderEmbedding /-- The ordering on `Fin n` is a well order. -/ instance Lt.isWellOrder (n) : IsWellOrder (Fin n) (· < ·) := (valOrderEmb n).isWellOrder /-- `Fin.succ` as an `OrderEmbedding` -/ def succOrderEmb (n : ℕ) : Fin n ↪o Fin (n + 1) := .ofStrictMono succ strictMono_succ @[simp, norm_cast] lemma coe_succOrderEmb : ⇑(succOrderEmb n) = Fin.succ := rfl @[simp] lemma succOrderEmb_toEmbedding : (succOrderEmb n).toEmbedding = succEmb n := rfl /-- `Fin.castLE` as an `OrderEmbedding`. `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps! apply toEmbedding] def castLEOrderEmb (h : n ≤ m) : Fin n ↪o Fin m := .ofStrictMono (castLE h) (strictMono_castLE h) /-- `Fin.castAdd` as an `OrderEmbedding`. `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ @[simps! apply toEmbedding] def castAddOrderEmb (m) : Fin n ↪o Fin (n + m) := .ofStrictMono (castAdd m) (strictMono_castAdd m) /-- `Fin.castSucc` as an `OrderEmbedding`. `castSuccOrderEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ @[simps! apply toEmbedding] def castSuccOrderEmb : Fin n ↪o Fin (n + 1) := .ofStrictMono castSucc strictMono_castSucc /-- `Fin.addNat` as an `OrderEmbedding`. `addNatOrderEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/ @[simps! apply toEmbedding] def addNatOrderEmb (m) : Fin n ↪o Fin (n + m) := .ofStrictMono (addNat · m) (strictMono_addNat m) /-- `Fin.natAdd` as an `OrderEmbedding`. `natAddOrderEmb n i` adds `n` to `i` "on the left". -/ @[simps! apply toEmbedding] def natAddOrderEmb (n) : Fin m ↪o Fin (n + m) := .ofStrictMono (natAdd n) (strictMono_natAdd n) /-- `Fin.succAbove p` as an `OrderEmbedding`. -/ @[simps! apply toEmbedding] def succAboveOrderEmb (p : Fin (n + 1)) : Fin n ↪o Fin (n + 1) := OrderEmbedding.ofStrictMono (succAbove p) (strictMono_succAbove p) /-! ### Uniqueness of order isomorphisms -/ variable {α : Type*} [Preorder α] /-- If `e` is an `orderIso` between `Fin n` and `Fin m`, then `n = m` and `e` is the identity map. In this lemma we state that for each `i : Fin n` we have `(e i : ℕ) = (i : ℕ)`. -/ @[simp] lemma coe_orderIso_apply (e : Fin n ≃o Fin m) (i : Fin n) : (e i : ℕ) = i := by rcases i with ⟨i, hi⟩ dsimp only induction i using Nat.strong_induction_on with | _ i h refine le_antisymm (forall_lt_iff_le.1 fun j hj => ?_) (forall_lt_iff_le.1 fun j hj => ?_) · have := e.symm.lt_symm_apply.1 (mk_lt_of_lt_val hj) specialize h _ this (e.symm _).is_lt simp only [Fin.eta, OrderIso.apply_symm_apply] at h rwa [h] · rwa [← h j hj (hj.trans hi), ← lt_iff_val_lt_val, e.lt_iff_lt] end Fin
.lake/packages/mathlib/Mathlib/Order/Fin/SuccAboveOrderIso.lean
import Mathlib.Order.Fin.Basic import Mathlib.Data.Fintype.Basic import Mathlib.Tactic.FinCases /-! # The order isomorphism `Fin (n + 1) ≃o {i}ᶜ` Given `i : Fin (n + 2)`, we show that `Fin.succAboveOrderEmb` induces an order isomorphism `Fin (n + 1) ≃o ({i}ᶜ : Finset (Fin (n + 2)))`. -/ open Finset /-- Given `i : Fin (n + 2)`, this is the order isomorphism between `Fin (n + 1)` and the finite set `{i}ᶜ`. -/ noncomputable def Fin.succAboveOrderIso {n : ℕ} (i : Fin (n + 2)) : Fin (n + 1) ≃o ({i}ᶜ : Finset (Fin (n + 2))) where toEquiv := Equiv.ofBijective (f := fun a ↦ ⟨Fin.succAboveOrderEmb i a, by simp⟩) (by constructor · intro a b h exact (Fin.succAboveOrderEmb i).injective (by simpa using h) · rintro ⟨j, hj⟩ simp only [mem_compl, mem_singleton] at hj obtain rfl | ⟨i, rfl⟩ := Fin.eq_zero_or_eq_succ i · exact ⟨j.pred hj, by simp⟩ · exact ⟨i.predAbove j, by aesop⟩) map_rel_iff' {a b} := by simp only [Equiv.ofBijective_apply, Subtype.mk_le_mk, OrderEmbedding.le_iff_le]
.lake/packages/mathlib/Mathlib/Order/Hom/BoundedLattice.lean
import Mathlib.Order.Hom.Bounded import Mathlib.Order.Hom.Lattice import Mathlib.Order.SymmDiff /-! # Bounded lattice homomorphisms This file defines bounded lattice homomorphisms. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `SupBotHom`: Finitary supremum homomorphisms. Maps which preserve `⊔` and `⊥`. * `InfTopHom`: Finitary infimum homomorphisms. Maps which preserve `⊓` and `⊤`. * `BoundedLatticeHom`: Bounded lattice homomorphisms. Maps which preserve `⊤`, `⊥`, `⊔` and `⊓`. ## Typeclasses * `SupBotHomClass` * `InfTopHomClass` * `BoundedLatticeHomClass` ## TODO Do we need more intersections between `BotHom`, `TopHom` and lattice homomorphisms? -/ open Function variable {F α β γ δ : Type*} /-- The type of finitary supremum-preserving homomorphisms from `α` to `β`. -/ structure SupBotHom (α β : Type*) [Max α] [Max β] [Bot α] [Bot β] extends SupHom α β where /-- A `SupBotHom` preserves the bottom element. Do not use this directly. Use `map_bot` instead. -/ map_bot' : toFun ⊥ = ⊥ /-- The type of finitary infimum-preserving homomorphisms from `α` to `β`. -/ structure InfTopHom (α β : Type*) [Min α] [Min β] [Top α] [Top β] extends InfHom α β where /-- An `InfTopHom` preserves the top element. Do not use this directly. Use `map_top` instead. -/ map_top' : toFun ⊤ = ⊤ /-- The type of bounded lattice homomorphisms from `α` to `β`. -/ structure BoundedLatticeHom (α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] extends LatticeHom α β where /-- A `BoundedLatticeHom` preserves the top element. Do not use this directly. Use `map_top` instead. -/ map_top' : toFun ⊤ = ⊤ /-- A `BoundedLatticeHom` preserves the bottom element. Do not use this directly. Use `map_bot` instead. -/ map_bot' : toFun ⊥ = ⊥ -- TODO: remove this configuration and use the default configuration. initialize_simps_projections SupBotHom (+toSupHom, -toFun) initialize_simps_projections InfTopHom (+toInfHom, -toFun) initialize_simps_projections BoundedLatticeHom (+toLatticeHom, -toFun) section /-- `SupBotHomClass F α β` states that `F` is a type of finitary supremum-preserving morphisms. You should extend this class when you extend `SupBotHom`. -/ class SupBotHomClass (F α β : Type*) [Max α] [Max β] [Bot α] [Bot β] [FunLike F α β] : Prop extends SupHomClass F α β where /-- A `SupBotHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ /-- `InfTopHomClass F α β` states that `F` is a type of finitary infimum-preserving morphisms. You should extend this class when you extend `SupBotHom`. -/ class InfTopHomClass (F α β : Type*) [Min α] [Min β] [Top α] [Top β] [FunLike F α β] : Prop extends InfHomClass F α β where /-- An `InfTopHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- `BoundedLatticeHomClass F α β` states that `F` is a type of bounded lattice morphisms. You should extend this class when you extend `BoundedLatticeHom`. -/ class BoundedLatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [FunLike F α β] : Prop extends LatticeHomClass F α β where /-- A `BoundedLatticeHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- A `BoundedLatticeHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ end section Hom variable [FunLike F α β] -- See note [lower instance priority] instance (priority := 100) SupBotHomClass.toBotHomClass [Max α] [Max β] [Bot α] [Bot β] [SupBotHomClass F α β] : BotHomClass F α β := { ‹SupBotHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) InfTopHomClass.toTopHomClass [Min α] [Min β] [Top α] [Top β] [InfTopHomClass F α β] : TopHomClass F α β := { ‹InfTopHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toSupBotHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : SupBotHomClass F α β := { ‹BoundedLatticeHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toInfTopHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : InfTopHomClass F α β := { ‹BoundedLatticeHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toBoundedOrderHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : BoundedOrderHomClass F α β := { show OrderHomClass F α β from inferInstance, ‹BoundedLatticeHomClass F α β› with } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toSupBotHomClass [SemilatticeSup α] [OrderBot α] [SemilatticeSup β] [OrderBot β] [OrderIsoClass F α β] : SupBotHomClass F α β := { OrderIsoClass.toSupHomClass, OrderIsoClass.toBotHomClass with } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toInfTopHomClass [SemilatticeInf α] [OrderTop α] [SemilatticeInf β] [OrderTop β] [OrderIsoClass F α β] : InfTopHomClass F α β := { OrderIsoClass.toInfHomClass, OrderIsoClass.toTopHomClass with } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBoundedLatticeHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [OrderIsoClass F α β] : BoundedLatticeHomClass F α β := { OrderIsoClass.toLatticeHomClass, OrderIsoClass.toBoundedOrderHomClass with } end Equiv section BoundedLattice variable [Lattice α] [Lattice β] [FunLike F α β] theorem Disjoint.map [OrderBot α] [OrderBot β] [BotHomClass F α β] [InfHomClass F α β] {a b : α} (f : F) (h : Disjoint a b) : Disjoint (f a) (f b) := by rw [disjoint_iff, ← map_inf, h.eq_bot, map_bot] theorem Codisjoint.map [OrderTop α] [OrderTop β] [TopHomClass F α β] [SupHomClass F α β] {a b : α} (f : F) (h : Codisjoint a b) : Codisjoint (f a) (f b) := by rw [codisjoint_iff, ← map_sup, h.eq_top, map_top] theorem IsCompl.map [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] {a b : α} (f : F) (h : IsCompl a b) : IsCompl (f a) (f b) := ⟨h.1.map _, h.2.map _⟩ end BoundedLattice section BooleanAlgebra variable [BooleanAlgebra α] [BooleanAlgebra β] [FunLike F α β] [BoundedLatticeHomClass F α β] variable (f : F) /-- Special case of `map_compl` for Boolean algebras. -/ theorem map_compl' (a : α) : f aᶜ = (f a)ᶜ := (isCompl_compl.map _).compl_eq.symm /-- Special case of `map_sdiff` for Boolean algebras. -/ theorem map_sdiff' (a b : α) : f (a \ b) = f a \ f b := by rw [sdiff_eq, sdiff_eq, map_inf, map_compl'] open scoped symmDiff in /-- Special case of `map_symmDiff` for Boolean algebras. -/ theorem map_symmDiff' (a b : α) : f (a ∆ b) = f a ∆ f b := by rw [symmDiff, symmDiff, map_sup, map_sdiff', map_sdiff'] end BooleanAlgebra variable [FunLike F α β] instance [Max α] [Max β] [Bot α] [Bot β] [SupBotHomClass F α β] : CoeTC F (SupBotHom α β) := ⟨fun f => ⟨f, map_bot f⟩⟩ instance [Min α] [Min β] [Top α] [Top β] [InfTopHomClass F α β] : CoeTC F (InfTopHom α β) := ⟨fun f => ⟨f, map_top f⟩⟩ instance [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : CoeTC F (BoundedLatticeHom α β) := ⟨fun f => { (f : LatticeHom α β) with toFun := f map_top' := map_top f map_bot' := map_bot f }⟩ /-! ### Finitary supremum homomorphisms -/ namespace SupBotHom variable [Max α] [Bot α] section Sup variable [Max β] [Bot β] [Max γ] [Bot γ] [Max δ] [Bot δ] /-- Reinterpret a `SupBotHom` as a `BotHom`. -/ def toBotHom (f : SupBotHom α β) : BotHom α β := { f with } instance : FunLike (SupBotHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : SupBotHomClass (SupBotHom α β) α β where map_sup f := f.map_sup' map_bot f := f.map_bot' lemma toFun_eq_coe (f : SupBotHom α β) : f.toFun = f := rfl @[simp] lemma coe_toSupHom (f : SupBotHom α β) : ⇑f.toSupHom = f := rfl @[simp] lemma coe_toBotHom (f : SupBotHom α β) : ⇑f.toBotHom = f := rfl @[simp] lemma coe_mk (f : SupHom α β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : SupBotHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `SupBotHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : SupBotHom α β) (f' : α → β) (h : f' = f) : SupBotHom α β := { f.toBotHom.copy f' h with toSupHom := f.toSupHom.copy f' h } @[simp] theorem coe_copy (f : SupBotHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : SupBotHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `SupBotHom`. -/ @[simps] protected def id : SupBotHom α α := ⟨SupHom.id α, rfl⟩ instance : Inhabited (SupBotHom α α) := ⟨SupBotHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(SupBotHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : SupBotHom.id α a = a := rfl /-- Composition of `SupBotHom`s as a `SupBotHom`. -/ def comp (f : SupBotHom β γ) (g : SupBotHom α β) : SupBotHom α γ := { f.toSupHom.comp g.toSupHom, f.toBotHom.comp g.toBotHom with } @[simp] theorem coe_comp (f : SupBotHom β γ) (g : SupBotHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : SupBotHom β γ) (g : SupBotHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : SupBotHom γ δ) (g : SupBotHom β γ) (h : SupBotHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : SupBotHom α β) : f.comp (SupBotHom.id α) = f := rfl @[simp] theorem id_comp (f : SupBotHom α β) : (SupBotHom.id β).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ : SupBotHom β γ} {f : SupBotHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : SupBotHom β γ} {f₁ f₂ : SupBotHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => SupBotHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end Sup variable [SemilatticeSup β] [OrderBot β] instance : Max (SupBotHom α β) := ⟨fun f g => { f.toBotHom ⊔ g.toBotHom with toSupHom := f.toSupHom ⊔ g.toSupHom }⟩ instance : SemilatticeSup (SupBotHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl instance : OrderBot (SupBotHom α β) where bot := ⟨⊥, rfl⟩ bot_le _ _ := bot_le @[simp] theorem coe_sup (f g : SupBotHom α β) : DFunLike.coe (f ⊔ g) = f ⊔ g := rfl @[simp] theorem coe_bot : ⇑(⊥ : SupBotHom α β) = ⊥ := rfl @[simp] theorem sup_apply (f g : SupBotHom α β) (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl @[simp] theorem bot_apply (a : α) : (⊥ : SupBotHom α β) a = ⊥ := rfl /-- `Subtype.val` as a `SupBotHom`. -/ def subtypeVal {P : β → Prop} (Pbot : P ⊥) (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) : letI := Subtype.orderBot Pbot letI := Subtype.semilatticeSup Psup SupBotHom {x : β // P x} β := letI := Subtype.orderBot Pbot letI := Subtype.semilatticeSup Psup .mk (SupHom.subtypeVal Psup) (by simp [Subtype.coe_bot Pbot]) @[simp] lemma subtypeVal_apply {P : β → Prop} (Pbot : P ⊥) (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) (x : {x : β // P x}) : subtypeVal Pbot Psup x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Pbot : P ⊥) (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) : ⇑(subtypeVal Pbot Psup) = Subtype.val := rfl end SupBotHom /-! ### Finitary infimum homomorphisms -/ namespace InfTopHom variable [Min α] [Top α] section Inf variable [Min β] [Top β] [Min γ] [Top γ] [Min δ] [Top δ] /-- Reinterpret an `InfTopHom` as a `TopHom`. -/ def toTopHom (f : InfTopHom α β) : TopHom α β := { f with } instance : FunLike (InfTopHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : InfTopHomClass (InfTopHom α β) α β where map_inf f := f.map_inf' map_top f := f.map_top' theorem toFun_eq_coe (f : InfTopHom α β) : f.toFun = f := rfl @[simp] lemma coe_toInfHom (f : InfTopHom α β) : ⇑f.toInfHom = f := rfl @[simp] lemma coe_toTopHom (f : InfTopHom α β) : ⇑f.toTopHom = f := rfl @[simp] lemma coe_mk (f : InfHom α β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : InfTopHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of an `InfTopHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : InfTopHom α β) (f' : α → β) (h : f' = f) : InfTopHom α β := { f.toTopHom.copy f' h with toInfHom := f.toInfHom.copy f' h } @[simp] theorem coe_copy (f : InfTopHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : InfTopHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as an `InfTopHom`. -/ @[simps] protected def id : InfTopHom α α := ⟨InfHom.id α, rfl⟩ instance : Inhabited (InfTopHom α α) := ⟨InfTopHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(InfTopHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : InfTopHom.id α a = a := rfl /-- Composition of `InfTopHom`s as an `InfTopHom`. -/ def comp (f : InfTopHom β γ) (g : InfTopHom α β) : InfTopHom α γ := { f.toInfHom.comp g.toInfHom, f.toTopHom.comp g.toTopHom with } @[simp] theorem coe_comp (f : InfTopHom β γ) (g : InfTopHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : InfTopHom β γ) (g : InfTopHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : InfTopHom γ δ) (g : InfTopHom β γ) (h : InfTopHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : InfTopHom α β) : f.comp (InfTopHom.id α) = f := rfl @[simp] theorem id_comp (f : InfTopHom α β) : (InfTopHom.id β).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ : InfTopHom β γ} {f : InfTopHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : InfTopHom β γ} {f₁ f₂ : InfTopHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => InfTopHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end Inf variable [SemilatticeInf β] [OrderTop β] instance : Min (InfTopHom α β) := ⟨fun f g => { f.toTopHom ⊓ g.toTopHom with toInfHom := f.toInfHom ⊓ g.toInfHom }⟩ instance : SemilatticeInf (InfTopHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl instance : OrderTop (InfTopHom α β) where top := ⟨⊤, rfl⟩ le_top _ _ := le_top @[simp] theorem coe_inf (f g : InfTopHom α β) : DFunLike.coe (f ⊓ g) = f ⊓ g := rfl @[simp] theorem coe_top : ⇑(⊤ : InfTopHom α β) = ⊤ := rfl @[simp] theorem inf_apply (f g : InfTopHom α β) (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl @[simp] theorem top_apply (a : α) : (⊤ : InfTopHom α β) a = ⊤ := rfl /-- `Subtype.val` as an `InfTopHom`. -/ def subtypeVal {P : β → Prop} (Ptop : P ⊤) (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) : letI := Subtype.orderTop Ptop letI := Subtype.semilatticeInf Pinf InfTopHom {x : β // P x} β := letI := Subtype.orderTop Ptop letI := Subtype.semilatticeInf Pinf .mk (InfHom.subtypeVal Pinf) (by simp [Subtype.coe_top Ptop]) @[simp] lemma subtypeVal_apply {P : β → Prop} (Ptop : P ⊤) (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) (x : {x : β // P x}) : subtypeVal Ptop Pinf x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Ptop : P ⊤) (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) : ⇑(subtypeVal Ptop Pinf) = Subtype.val := rfl end InfTopHom /-! ### Bounded lattice homomorphisms -/ namespace BoundedLatticeHom variable [Lattice α] [Lattice β] [Lattice γ] [Lattice δ] [BoundedOrder α] [BoundedOrder β] [BoundedOrder γ] [BoundedOrder δ] /-- Reinterpret a `BoundedLatticeHom` as a `SupBotHom`. -/ def toSupBotHom (f : BoundedLatticeHom α β) : SupBotHom α β := { f with } /-- Reinterpret a `BoundedLatticeHom` as an `InfTopHom`. -/ def toInfTopHom (f : BoundedLatticeHom α β) : InfTopHom α β := { f with } /-- Reinterpret a `BoundedLatticeHom` as a `BoundedOrderHom`. -/ def toBoundedOrderHom (f : BoundedLatticeHom α β) : BoundedOrderHom α β := { f, (f.toLatticeHom : α →o β) with } instance instFunLike : FunLike (BoundedLatticeHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr instance instBoundedLatticeHomClass : BoundedLatticeHomClass (BoundedLatticeHom α β) α β where map_sup f := f.map_sup' map_inf f := f.map_inf' map_top f := f.map_top' map_bot f := f.map_bot' @[simp] lemma toFun_eq_coe (f : BoundedLatticeHom α β) : f.toFun = f := rfl @[simp] lemma coe_toLatticeHom (f : BoundedLatticeHom α β) : ⇑f.toLatticeHom = f := rfl @[simp] lemma coe_toSupBotHom (f : BoundedLatticeHom α β) : ⇑f.toSupBotHom = f := rfl @[simp] lemma coe_toInfTopHom (f : BoundedLatticeHom α β) : ⇑f.toInfTopHom = f := rfl @[simp] lemma coe_toBoundedOrderHom (f : BoundedLatticeHom α β) : ⇑f.toBoundedOrderHom = f := rfl @[simp] lemma coe_mk (f : LatticeHom α β) (hf hf') : ⇑(mk f hf hf') = f := rfl @[ext] theorem ext {f g : BoundedLatticeHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `BoundedLatticeHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : BoundedLatticeHom α β := { f.toLatticeHom.copy f' h, f.toBoundedOrderHom.copy f' h with } @[simp] theorem coe_copy (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `BoundedLatticeHom`. -/ protected def id : BoundedLatticeHom α α := { LatticeHom.id α, BoundedOrderHom.id α with } instance : Inhabited (BoundedLatticeHom α α) := ⟨BoundedLatticeHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(BoundedLatticeHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : BoundedLatticeHom.id α a = a := rfl /-- Composition of `BoundedLatticeHom`s as a `BoundedLatticeHom`. -/ def comp (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : BoundedLatticeHom α γ := { f.toLatticeHom.comp g.toLatticeHom, f.toBoundedOrderHom.comp g.toBoundedOrderHom with } @[simp] theorem coe_comp (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] -- `simp`-normal form of `coe_comp_lattice_hom` theorem coe_comp_lattice_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : (⟨(f : SupHom β γ).comp g, map_inf (f.comp g)⟩ : LatticeHom α γ) = (f : LatticeHom β γ).comp g := rfl theorem coe_comp_lattice_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : (f.comp g : LatticeHom α γ) = (f : LatticeHom β γ).comp g := rfl @[simp] -- `simp`-normal form of `coe_comp_sup_hom` theorem coe_comp_sup_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : ⟨f ∘ g, map_sup (f.comp g)⟩ = (f : SupHom β γ).comp g := rfl theorem coe_comp_sup_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : (f.comp g : SupHom α γ) = (f : SupHom β γ).comp g := rfl @[simp] -- `simp`-normal form of `coe_comp_inf_hom` theorem coe_comp_inf_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : ⟨f ∘ g, map_inf (f.comp g)⟩ = (f : InfHom β γ).comp g := rfl theorem coe_comp_inf_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : (f.comp g : InfHom α γ) = (f : InfHom β γ).comp g := rfl @[simp] theorem comp_assoc (f : BoundedLatticeHom γ δ) (g : BoundedLatticeHom β γ) (h : BoundedLatticeHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : BoundedLatticeHom α β) : f.comp (BoundedLatticeHom.id α) = f := rfl @[simp] theorem id_comp (f : BoundedLatticeHom α β) : (BoundedLatticeHom.id β).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ : BoundedLatticeHom β γ} {f : BoundedLatticeHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => BoundedLatticeHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : BoundedLatticeHom β γ} {f₁ f₂ : BoundedLatticeHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ /-- `Subtype.val` as a `BoundedLatticeHom`. -/ def subtypeVal {P : β → Prop} (Pbot : P ⊥) (Ptop : P ⊤) (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : letI := Subtype.lattice Psup Pinf letI := Subtype.boundedOrder Pbot Ptop BoundedLatticeHom {x : β // P x} β := letI := Subtype.lattice Psup Pinf letI := Subtype.boundedOrder Pbot Ptop .mk (.subtypeVal Psup Pinf) (by simp [Subtype.coe_top Ptop]) (by simp [Subtype.coe_bot Pbot]) @[simp] lemma subtypeVal_apply {P : β → Prop} (Pbot : P ⊥) (Ptop : P ⊤) (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) (x : {x : β // P x}) : subtypeVal Pbot Ptop Psup Pinf x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Pbot : P ⊥) (Ptop : P ⊤) (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : ⇑(subtypeVal Pbot Ptop Psup Pinf) = Subtype.val := rfl end BoundedLatticeHom /-! ### Dual homs -/ namespace SupBotHom variable [Max α] [Bot α] [Max β] [Bot β] [Max γ] [Bot γ] /-- Reinterpret a finitary supremum homomorphism as a finitary infimum homomorphism between the dual lattices. -/ def dual : SupBotHom α β ≃ InfTopHom αᵒᵈ βᵒᵈ where toFun f := ⟨SupHom.dual f.toSupHom, f.map_bot'⟩ invFun f := ⟨SupHom.dual.symm f.toInfHom, f.map_top'⟩ @[simp] theorem dual_id : SupBotHom.dual (SupBotHom.id α) = InfTopHom.id _ := rfl @[simp] theorem dual_comp (g : SupBotHom β γ) (f : SupBotHom α β) : SupBotHom.dual (g.comp f) = (SupBotHom.dual g).comp (SupBotHom.dual f) := rfl @[simp] theorem symm_dual_id : SupBotHom.dual.symm (InfTopHom.id _) = SupBotHom.id α := rfl @[simp] theorem symm_dual_comp (g : InfTopHom βᵒᵈ γᵒᵈ) (f : InfTopHom αᵒᵈ βᵒᵈ) : SupBotHom.dual.symm (g.comp f) = (SupBotHom.dual.symm g).comp (SupBotHom.dual.symm f) := rfl end SupBotHom namespace InfTopHom variable [Min α] [Top α] [Min β] [Top β] [Min γ] [Top γ] /-- Reinterpret a finitary infimum homomorphism as a finitary supremum homomorphism between the dual lattices. -/ @[simps] protected def dual : InfTopHom α β ≃ SupBotHom αᵒᵈ βᵒᵈ where toFun f := ⟨InfHom.dual f.toInfHom, f.map_top'⟩ invFun f := ⟨InfHom.dual.symm f.toSupHom, f.map_bot'⟩ @[simp] theorem dual_id : InfTopHom.dual (InfTopHom.id α) = SupBotHom.id _ := rfl @[simp] theorem dual_comp (g : InfTopHom β γ) (f : InfTopHom α β) : InfTopHom.dual (g.comp f) = (InfTopHom.dual g).comp (InfTopHom.dual f) := rfl @[simp] theorem symm_dual_id : InfTopHom.dual.symm (SupBotHom.id _) = InfTopHom.id α := rfl @[simp] theorem symm_dual_comp (g : SupBotHom βᵒᵈ γᵒᵈ) (f : SupBotHom αᵒᵈ βᵒᵈ) : InfTopHom.dual.symm (g.comp f) = (InfTopHom.dual.symm g).comp (InfTopHom.dual.symm f) := rfl end InfTopHom namespace BoundedLatticeHom variable [Lattice α] [BoundedOrder α] [Lattice β] [BoundedOrder β] [Lattice γ] [BoundedOrder γ] /-- Reinterpret a bounded lattice homomorphism as a bounded lattice homomorphism between the dual bounded lattices. -/ @[simps] protected def dual : BoundedLatticeHom α β ≃ BoundedLatticeHom αᵒᵈ βᵒᵈ where toFun f := ⟨LatticeHom.dual f.toLatticeHom, f.map_bot', f.map_top'⟩ invFun f := ⟨LatticeHom.dual.symm f.toLatticeHom, f.map_bot', f.map_top'⟩ @[simp] theorem dual_id : BoundedLatticeHom.dual (BoundedLatticeHom.id α) = BoundedLatticeHom.id _ := rfl @[simp] theorem dual_comp (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) : BoundedLatticeHom.dual (g.comp f) = (BoundedLatticeHom.dual g).comp (BoundedLatticeHom.dual f) := rfl @[simp] theorem symm_dual_id : BoundedLatticeHom.dual.symm (BoundedLatticeHom.id _) = BoundedLatticeHom.id α := rfl @[simp] theorem symm_dual_comp (g : BoundedLatticeHom βᵒᵈ γᵒᵈ) (f : BoundedLatticeHom αᵒᵈ βᵒᵈ) : BoundedLatticeHom.dual.symm (g.comp f) = (BoundedLatticeHom.dual.symm g).comp (BoundedLatticeHom.dual.symm f) := rfl end BoundedLatticeHom
.lake/packages/mathlib/Mathlib/Order/Hom/Lex.lean
import Mathlib.Data.Prod.Lex import Mathlib.Data.Sum.Order import Mathlib.Order.Hom.Set import Mathlib.Order.RelIso.Set /-! # Lexicographic order and order isomorphisms ## Main declarations * `OrderIso.sumLexIioIci` and `OrderIso.sumLexIicIoi`: if `α` is a linear order and `x : α`, then `α` is order isomorphic to both `Iio x ⊕ₗ Ici x` and `Iic x ⊕ₗ Ioi x`. * `Prod.Lex.prodUnique` and `Prod.Lex.uniqueProd`: `α ×ₗ β` is order isomorphic to one side if the other side is `Unique`. -/ open Set variable {α : Type*} /-! ### Relation isomorphism -/ namespace RelIso variable {r : α → α → Prop} {x y : α} [IsTrans α r] [IsTrichotomous α r] [DecidableRel r] variable (r x) in /-- A relation is isomorphic to the lexicographic sum of elements less than `x` and elements not less than `x`. -/ def sumLexComplLeft : Sum.Lex (Subrel r (r · x)) (Subrel r (¬ r · x)) ≃r r where toEquiv := .sumCompl (r · x) map_rel_iff' := by rintro (⟨a, ha⟩ | ⟨a, ha⟩) (⟨b, hb⟩ | ⟨b, hb⟩) · simp · simpa using trans_trichotomous_right ha hb · simpa using fun h ↦ ha <| trans h hb · simp @[simp] theorem sumLexComplLeft_apply (a) : sumLexComplLeft r x a = Equiv.sumCompl (r · x) a := rfl @[simp] theorem sumLexComplLeft_symm_apply (a) : sumLexComplLeft r x a = Equiv.sumCompl (r · x) a := rfl variable (r x) in /-- A relation is isomorphic to the lexicographic sum of elements not greater than `x` and elements greater than `x`. -/ def sumLexComplRight : Sum.Lex (Subrel r (¬ r x ·)) (Subrel r (r x)) ≃r r where toEquiv := (Equiv.sumComm _ _).trans <| .sumCompl (r x) map_rel_iff' := by rintro (⟨a, ha⟩ | ⟨a, ha⟩) (⟨b, hb⟩ | ⟨b, hb⟩) · simp · simpa using trans_trichotomous_left ha hb · simpa using fun h ↦ hb <| trans ha h · simp @[simp] theorem sumLexComplRight_apply (a) : sumLexComplRight r x a = Equiv.sumCompl (r x) a.swap := rfl @[simp] theorem sumLexComplRight_symm_apply (a) : sumLexComplRight r x a = Equiv.sumCompl (r x) a.swap := rfl end RelIso /-! ### Order isomorphism -/ namespace OrderIso variable [LinearOrder α] {x y : α} variable (x) in /-- A linear order is isomorphic to the lexicographic sum of elements less than `x` and elements greater or equal to `x`. -/ def sumLexIioIci : Iio x ⊕ₗ Ici x ≃o α := (sumLexCongr (refl _) (setCongr (Ici x) {y | ¬ y < x} (by ext; simp))).trans <| ofRelIsoLT (RelIso.sumLexComplLeft (· < ·) x) @[simp] theorem sumLexIioIci_apply_inl (a : Iio x) : sumLexIioIci x (toLex <| Sum.inl a) = a := rfl @[simp] theorem sumLexIioIci_apply_inr (a : Ici x) : sumLexIioIci x (toLex <| Sum.inr a) = a := rfl theorem sumLexIioIci_symm_apply_of_lt (h : y < x) : (sumLexIioIci x).symm y = toLex (Sum.inl ⟨y, h⟩) := by rw [symm_apply_eq, sumLexIioIci_apply_inl] theorem sumLexIioIci_symm_apply_of_ge {y : α} (h : x ≤ y) : (sumLexIioIci x).symm y = toLex (Sum.inr ⟨y, h⟩) := by rw [symm_apply_eq, sumLexIioIci_apply_inr] @[simp] theorem sumLexIioIci_symm_apply_Iio (a : Iio x) : (sumLexIioIci x).symm a = toLex (Sum.inl a) := sumLexIioIci_symm_apply_of_lt a.2 @[simp] theorem sumLexIioIci_symm_apply_Ici (a : Ici x) : (sumLexIioIci x).symm a = toLex (Sum.inr a) := sumLexIioIci_symm_apply_of_ge a.2 variable (x) in /-- A linear order is isomorphic to the lexicographic sum of elements less or equal to `x` and elements greater than `x`. -/ def sumLexIicIoi : Iic x ⊕ₗ Ioi x ≃o α := (sumLexCongr (setCongr (Iic x) {y | ¬ x < y} (by ext; simp)) (refl _)).trans <| ofRelIsoLT (RelIso.sumLexComplRight (· < ·) x) @[simp] theorem sumLexIicIoi_apply_inl (a : Iic x) : sumLexIicIoi x (toLex <| Sum.inl a) = a := rfl @[simp] theorem sumLexIicIoi_apply_inr (a : Ioi x) : sumLexIicIoi x (toLex <| Sum.inr a) = a := rfl theorem sumLexIicIoi_symm_apply_of_le (h : y ≤ x) : (sumLexIicIoi x).symm y = toLex (Sum.inl ⟨y, h⟩) := by rw [symm_apply_eq, sumLexIicIoi_apply_inl] theorem sumLexIicIoi_symm_apply_of_lt {y : α} (h : x < y) : (sumLexIicIoi x).symm y = toLex (Sum.inr ⟨y, h⟩) := by rw [symm_apply_eq, sumLexIicIoi_apply_inr] @[simp] theorem sumLexIicIoi_symm_apply_Iic (a : Iic x) : (sumLexIicIoi x).symm a = Sum.inl a := sumLexIicIoi_symm_apply_of_le a.2 @[simp] theorem sumLexIicIoi_symm_apply_Ioi (a : Ioi x) : (sumLexIicIoi x).symm a = Sum.inr a := sumLexIicIoi_symm_apply_of_lt a.2 end OrderIso /-! ### Degenerate products -/ namespace Prod.Lex variable (α β : Type*) /-- Lexicographic product type with `Unique` type on the right is `OrderIso` to the left. -/ def prodUnique [PartialOrder α] [Preorder β] [Unique β] : α ×ₗ β ≃o α where toFun x := (ofLex x).1 invFun x := toLex (x, default) left_inv x := x.rec fun (a, b) ↦ by simpa using Unique.default_eq b right_inv x := by simp map_rel_iff' {a b} := a.rec fun a ↦ b.rec fun b ↦ by simpa [Prod.Lex.toLex_le_toLex] using le_iff_lt_or_eq variable {α β} in @[simp] theorem prodUnique_apply [PartialOrder α] [Preorder β] [Unique β] (x : α ×ₗ β) : prodUnique α β x = (ofLex x).1 := rfl /-- Lexicographic product type with `Unique` type on the left is `OrderIso` to the right. -/ def uniqueProd [Preorder α] [Unique α] [LE β] : α ×ₗ β ≃o β where toFun x := (ofLex x).2 invFun x := toLex (default, x) left_inv x := x.rec fun (a, b) ↦ by simpa using Unique.default_eq a right_inv x := by simp map_rel_iff' {a b} := a.rec fun a ↦ b.rec fun b ↦ by have heq : a.1 = b.1 := Subsingleton.allEq _ _ simp [Prod.Lex.toLex_le_toLex, heq] variable {α β} in @[simp] theorem uniqueProd_apply [Preorder α] [Unique α] [LE β] (x : α ×ₗ β) : uniqueProd α β x = (ofLex x).2 := rfl end Prod.Lex
.lake/packages/mathlib/Mathlib/Order/Hom/Order.lean
import Mathlib.Logic.Function.Iterate import Mathlib.Order.GaloisConnection.Basic import Mathlib.Order.Hom.Basic /-! # Lattice structure on order homomorphisms This file defines the lattice structure on order homomorphisms, which are bundled monotone functions. ## Main definitions * `OrderHom.instCompleteLattice`: if `β` is a complete lattice, so is `α →o β` ## Tags monotone map, bundled morphism -/ namespace OrderHom variable {α β : Type*} section Preorder variable [Preorder α] instance [SemilatticeSup β] : Max (α →o β) where max f g := ⟨fun a => f a ⊔ g a, f.mono.sup g.mono⟩ @[simp] lemma coe_sup [SemilatticeSup β] (f g : α →o β) : ((f ⊔ g : α →o β) : α → β) = (f : α → β) ⊔ g := rfl instance [SemilatticeSup β] : SemilatticeSup (α →o β) := { (_ : PartialOrder (α →o β)) with sup := Max.max le_sup_left := fun _ _ _ => le_sup_left le_sup_right := fun _ _ _ => le_sup_right sup_le := fun _ _ _ h₀ h₁ x => sup_le (h₀ x) (h₁ x) } instance [SemilatticeInf β] : Min (α →o β) where min f g := ⟨fun a => f a ⊓ g a, f.mono.inf g.mono⟩ @[simp] lemma coe_inf [SemilatticeInf β] (f g : α →o β) : ((f ⊓ g : α →o β) : α → β) = (f : α → β) ⊓ g := rfl instance [SemilatticeInf β] : SemilatticeInf (α →o β) := { (_ : PartialOrder (α →o β)), (dualIso α β).symm.toGaloisInsertion.liftSemilatticeInf with inf := (· ⊓ ·) } instance lattice [Lattice β] : Lattice (α →o β) := { (_ : SemilatticeSup (α →o β)), (_ : SemilatticeInf (α →o β)) with } @[simps] instance [Preorder β] [OrderBot β] : Bot (α →o β) where bot := const α ⊥ instance orderBot [Preorder β] [OrderBot β] : OrderBot (α →o β) where bot_le _ _ := bot_le @[simps] instance instTopOrderHom [Preorder β] [OrderTop β] : Top (α →o β) where top := const α ⊤ instance orderTop [Preorder β] [OrderTop β] : OrderTop (α →o β) where le_top _ _ := le_top instance [CompleteLattice β] : InfSet (α →o β) where sInf s := ⟨fun x => ⨅ f ∈ s, (f :) x, fun _ _ h => iInf₂_mono fun f _ => f.mono h⟩ @[simp] theorem sInf_apply [CompleteLattice β] (s : Set (α →o β)) (x : α) : sInf s x = ⨅ f ∈ s, (f :) x := rfl theorem iInf_apply {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) (x : α) : (⨅ i, f i) x = ⨅ i, f i x := (sInf_apply _ _).trans iInf_range @[simp, norm_cast] theorem coe_iInf {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) : ((⨅ i, f i : α →o β) : α → β) = ⨅ i, (f i : α → β) := by funext x; simp [iInf_apply] instance [CompleteLattice β] : SupSet (α →o β) where sSup s := ⟨fun x => ⨆ f ∈ s, (f :) x, fun _ _ h => iSup₂_mono fun f _ => f.mono h⟩ @[simp] theorem sSup_apply [CompleteLattice β] (s : Set (α →o β)) (x : α) : sSup s x = ⨆ f ∈ s, (f :) x := rfl theorem iSup_apply {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) (x : α) : (⨆ i, f i) x = ⨆ i, f i x := (sSup_apply _ _).trans iSup_range @[simp, norm_cast] theorem coe_iSup {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) : ((⨆ i, f i : α →o β) : α → β) = ⨆ i, (f i : α → β) := by funext x; simp [iSup_apply] instance [CompleteLattice β] : CompleteLattice (α →o β) := { (_ : Lattice (α →o β)), OrderHom.orderTop, OrderHom.orderBot with -- Porting note: Added `by apply`, was `fun s f hf x => le_iSup_of_le f (le_iSup _ hf)` le_sSup := fun s f hf x => le_iSup_of_le f (by apply le_iSup _ hf) sSup_le := fun _ _ hf x => iSup₂_le fun g hg => hf g hg x le_sInf := fun _ _ hf x => le_iInf₂ fun g hg => hf g hg x sInf_le := fun _ f hf _ => iInf_le_of_le f (iInf_le _ hf) } theorem iterate_sup_le_sup_iff {α : Type*} [SemilatticeSup α] (f : α →o α) : (∀ n₁ n₂ a₁ a₂, f^[n₁ + n₂] (a₁ ⊔ a₂) ≤ f^[n₁] a₁ ⊔ f^[n₂] a₂) ↔ ∀ a₁ a₂, f (a₁ ⊔ a₂) ≤ f a₁ ⊔ a₂ := by constructor <;> intro h · exact h 1 0 · intro n₁ n₂ a₁ a₂ have h' : ∀ n a₁ a₂, f^[n] (a₁ ⊔ a₂) ≤ f^[n] a₁ ⊔ a₂ := by intro n induction n with | zero => intro a₁ a₂; rfl | succ n ih => intro a₁ a₂ calc f^[n + 1] (a₁ ⊔ a₂) = f^[n] (f (a₁ ⊔ a₂)) := Function.iterate_succ_apply f n _ _ ≤ f^[n] (f a₁ ⊔ a₂) := f.mono.iterate n (h a₁ a₂) _ ≤ f^[n] (f a₁) ⊔ a₂ := ih _ _ _ = f^[n + 1] a₁ ⊔ a₂ := by rw [← Function.iterate_succ_apply] calc f^[n₁ + n₂] (a₁ ⊔ a₂) = f^[n₁] (f^[n₂] (a₁ ⊔ a₂)) := Function.iterate_add_apply f n₁ n₂ _ _ = f^[n₁] (f^[n₂] (a₂ ⊔ a₁)) := by rw [sup_comm] _ ≤ f^[n₁] (f^[n₂] a₂ ⊔ a₁) := f.mono.iterate n₁ (h' n₂ _ _) _ = f^[n₁] (a₁ ⊔ f^[n₂] a₂) := by rw [sup_comm] _ ≤ f^[n₁] a₁ ⊔ f^[n₂] a₂ := h' n₁ a₁ _ end Preorder end OrderHom
.lake/packages/mathlib/Mathlib/Order/Hom/Basic.lean
import Mathlib.Order.Disjoint import Mathlib.Order.RelIso.Basic import Mathlib.Tactic.Monotonicity.Attr /-! # Order homomorphisms This file defines order homomorphisms, which are bundled monotone functions. A preorder homomorphism `f : α →o β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`. ## Main definitions In this file we define the following bundled monotone maps: * `OrderHom α β` a.k.a. `α →o β`: Preorder homomorphism. An `OrderHom α β` is a function `f : α → β` such that `a₁ ≤ a₂ → f a₁ ≤ f a₂` * `OrderEmbedding α β` a.k.a. `α ↪o β`: Relation embedding. An `OrderEmbedding α β` is an embedding `f : α ↪ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelEmbedding α β (≤) (≤)`. * `OrderIso`: Relation isomorphism. An `OrderIso α β` is an equivalence `f : α ≃ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelIso α β (≤) (≤)`. We also define many `OrderHom`s. In some cases we define two versions, one with `ₘ` suffix and one without it (e.g., `OrderHom.compₘ` and `OrderHom.comp`). This means that the former function is a "more bundled" version of the latter. We can't just drop the "less bundled" version because the more bundled version usually does not work with dot notation. * `OrderHom.id`: identity map as `α →o α`; * `OrderHom.curry`: an order isomorphism between `α × β →o γ` and `α →o β →o γ`; * `OrderHom.comp`: composition of two bundled monotone maps; * `OrderHom.compₘ`: composition of bundled monotone maps as a bundled monotone map; * `OrderHom.const`: constant function as a bundled monotone map; * `OrderHom.prod`: combine `α →o β` and `α →o γ` into `α →o β × γ`; * `OrderHom.prodₘ`: a more bundled version of `OrderHom.prod`; * `OrderHom.prodIso`: order isomorphism between `α →o β × γ` and `(α →o β) × (α →o γ)`; * `OrderHom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map; * `OrderHom.onDiag`: restrict a monotone map `α →o α →o β` to the diagonal; * `OrderHom.fst`: projection `Prod.fst : α × β → α` as a bundled monotone map; * `OrderHom.snd`: projection `Prod.snd : α × β → β` as a bundled monotone map; * `OrderHom.prodMap`: `Prod.map f g` as a bundled monotone map; * `Pi.evalOrderHom`: evaluation of a function at a point `Function.eval i` as a bundled monotone map; * `OrderHom.coeFnHom`: coercion to function as a bundled monotone map; * `OrderHom.apply`: application of an `OrderHom` at a point as a bundled monotone map; * `OrderHom.pi`: combine a family of monotone maps `f i : α →o π i` into a monotone map `α →o Π i, π i`; * `OrderHom.piIso`: order isomorphism between `α →o Π i, π i` and `Π i, α →o π i`; * `OrderHom.subtype.val`: embedding `Subtype.val : Subtype p → α` as a bundled monotone map; * `OrderHom.dual`: reinterpret a monotone map `α →o β` as a monotone map `αᵒᵈ →o βᵒᵈ`; * `OrderHom.dualIso`: order isomorphism between `α →o β` and `(αᵒᵈ →o βᵒᵈ)ᵒᵈ`; * `OrderHom.compl`: order isomorphism `α ≃o αᵒᵈ` given by taking complements in a Boolean algebra; We also define two functions to convert other bundled maps to `α →o β`: * `OrderEmbedding.toOrderHom`: convert `α ↪o β` to `α →o β`; * `RelHom.toOrderHom`: convert a `RelHom` between strict orders to an `OrderHom`. ## Tags monotone map, bundled morphism -/ -- Developments relating order homs and sets belong in `Order.Hom.Set` or later. assert_not_imported Mathlib.Data.Set.Basic open OrderDual variable {F α β γ δ : Type*} /-- Bundled monotone (aka, increasing) function -/ structure OrderHom (α β : Type*) [Preorder α] [Preorder β] where /-- The underlying function of an `OrderHom`. -/ toFun : α → β /-- The underlying function of an `OrderHom` is monotone. -/ monotone' : Monotone toFun /-- Notation for an `OrderHom`. -/ infixr:25 " →o " => OrderHom /-- An order embedding is an embedding `f : α ↪ β` such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelEmbedding (≤) (≤)`. -/ abbrev OrderEmbedding (α β : Type*) [LE α] [LE β] := @RelEmbedding α β (· ≤ ·) (· ≤ ·) /-- Notation for an `OrderEmbedding`. -/ infixl:25 " ↪o " => OrderEmbedding /-- An order isomorphism is an equivalence such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelIso (≤) (≤)`. -/ abbrev OrderIso (α β : Type*) [LE α] [LE β] := @RelIso α β (· ≤ ·) (· ≤ ·) /-- Notation for an `OrderIso`. -/ infixl:25 " ≃o " => OrderIso section /-- `OrderHomClass F α b` asserts that `F` is a type of `≤`-preserving morphisms. -/ abbrev OrderHomClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [FunLike F α β] := RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) /-- `OrderIsoClass F α β` states that `F` is a type of order isomorphisms. You should extend this class when you extend `OrderIso`. -/ class OrderIsoClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [EquivLike F α β] : Prop where /-- An order isomorphism respects `≤`. -/ map_le_map_iff (f : F) {a b : α} : f a ≤ f b ↔ a ≤ b end export OrderIsoClass (map_le_map_iff) attribute [simp] map_le_map_iff /-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` into an actual `OrderIso`. This is declared as the default coercion from `F` to `α ≃o β`. -/ @[coe] def OrderIsoClass.toOrderIso [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] (f : F) : α ≃o β := { EquivLike.toEquiv f with map_rel_iff' := map_le_map_iff f } /-- Any type satisfying `OrderIsoClass` can be cast into `OrderIso` via `OrderIsoClass.toOrderIso`. -/ instance [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : CoeTC F (α ≃o β) := ⟨OrderIsoClass.toOrderIso⟩ -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toOrderHomClass [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderHomClass F α β := { EquivLike.toEmbeddingLike (E := F) with map_rel := fun f _ _ => (map_le_map_iff f).2 } namespace OrderHomClass variable [Preorder α] [Preorder β] [FunLike F α β] [OrderHomClass F α β] protected theorem monotone (f : F) : Monotone f := fun _ _ => map_rel f @[gcongr] protected theorem mono (f : F) : Monotone f := fun _ _ => map_rel f /-- Turn an element of a type `F` satisfying `OrderHomClass F α β` into an actual `OrderHom`. This is declared as the default coercion from `F` to `α →o β`. -/ @[coe] def toOrderHom (f : F) : α →o β where toFun := f monotone' := OrderHomClass.monotone f /-- Any type satisfying `OrderHomClass` can be cast into `OrderHom` via `OrderHomClass.toOrderHom`. -/ instance : CoeTC F (α →o β) := ⟨toOrderHom⟩ end OrderHomClass section OrderIsoClass section LE variable [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] @[simp] theorem map_inv_le_iff (f : F) {a : α} {b : β} : EquivLike.inv f b ≤ a ↔ b ≤ f a := by convert (map_le_map_iff f).symm exact (EquivLike.right_inv f _).symm theorem map_inv_le_map_inv_iff (f : F) {a b : β} : EquivLike.inv f b ≤ EquivLike.inv f a ↔ b ≤ a := by simp @[simp] theorem le_map_inv_iff (f : F) {a : α} {b : β} : a ≤ EquivLike.inv f b ↔ f a ≤ b := by convert (map_le_map_iff f).symm exact (EquivLike.right_inv _ _).symm end LE variable [Preorder α] [Preorder β] [EquivLike F α β] [OrderIsoClass F α β] theorem map_lt_map_iff (f : F) {a b : α} : f a < f b ↔ a < b := lt_iff_lt_of_le_iff_le' (map_le_map_iff f) (map_le_map_iff f) @[simp] theorem map_inv_lt_iff (f : F) {a : α} {b : β} : EquivLike.inv f b < a ↔ b < f a := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] theorem map_inv_lt_map_inv_iff (f : F) {a b : β} : EquivLike.inv f b < EquivLike.inv f a ↔ b < a := by simp @[simp] theorem lt_map_inv_iff (f : F) {a : α} {b : β} : a < EquivLike.inv f b ↔ f a < b := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] end OrderIsoClass namespace OrderHom variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] instance : FunLike (α →o β) α β where coe := toFun coe_injective' f g h := by cases f; cases g; congr instance : OrderHomClass (α →o β) α β where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f : α → β) (hf : Monotone f) : ⇑(mk f hf) = f := rfl protected theorem monotone (f : α →o β) : Monotone f := f.monotone' protected theorem mono (f : α →o β) : Monotone f := f.monotone /-- See Note [custom simps projection]. We give this manually so that we use `toFun` as the projection directly instead. -/ def Simps.coe (f : α →o β) : α → β := f /- TODO: all other DFunLike classes use `apply` instead of `coe` for the projection names. Maybe we should change this. -/ initialize_simps_projections OrderHom (toFun → coe) @[simp] theorem toFun_eq_coe (f : α →o β) : f.toFun = f := rfl -- See library note [partially-applied ext lemmas] @[ext] theorem ext (f g : α →o β) (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h @[simp] theorem coe_eq (f : α →o β) : OrderHomClass.toOrderHom f = f := rfl @[simp] theorem _root_.OrderHomClass.coe_coe {F} [FunLike F α β] [OrderHomClass F α β] (f : F) : ⇑(f : α →o β) = f := rfl /-- One can lift an unbundled monotone function to a bundled one. -/ protected instance canLift : CanLift (α → β) (α →o β) (↑) Monotone where prf f h := ⟨⟨f, h⟩, rfl⟩ /-- Copy of an `OrderHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →o β) (f' : α → β) (h : f' = f) : α →o β := ⟨f', h.symm.subst f.monotone'⟩ @[simp] theorem coe_copy (f : α →o β) (f' : α → β) (h : f' = f) : (f.copy f' h) = f' := rfl theorem copy_eq (f : α →o β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h instance {α : Type*} (β : Type*) [PartialOrder α] [PartialOrder β] [DecidableEq (α → β)] : DecidableEq (α →o β) := fun a b => decidable_of_iff (a.toFun = b.toFun) OrderHom.ext_iff.symm /-- The identity function as bundled monotone function. -/ @[simps -fullyApplied] def id : α →o α := ⟨_root_.id, monotone_id⟩ instance : Inhabited (α →o α) := ⟨id⟩ /-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/ instance : Preorder (α →o β) := @Preorder.lift (α →o β) (α → β) _ toFun instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) := @PartialOrder.lift (α →o β) (α → β) _ toFun ext theorem le_def {f g : α →o β} : f ≤ g ↔ ∀ x, f x ≤ g x := Iff.rfl @[simp, norm_cast] theorem coe_le_coe {f g : α →o β} : (f : α → β) ≤ g ↔ f ≤ g := Iff.rfl @[simp] theorem mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g := Iff.rfl @[mono] theorem apply_mono {f g : α →o β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y := (h₁ x).trans <| g.mono h₂ /-- Curry/uncurry as an order isomorphism between `α × β →o γ` and `α →o β →o γ`. -/ def curry : (α × β →o γ) ≃o (α →o β →o γ) where toFun f := ⟨fun x ↦ ⟨Function.curry f x, fun _ _ h ↦ f.mono ⟨le_rfl, h⟩⟩, fun _ _ h _ => f.mono ⟨h, le_rfl⟩⟩ invFun f := ⟨Function.uncurry fun x ↦ f x, fun x y h ↦ (f.mono h.1 x.2).trans ((f y.1).mono h.2)⟩ map_rel_iff' := by simp [le_def] @[simp] theorem curry_apply (f : α × β →o γ) (x : α) (y : β) : curry f x y = f (x, y) := rfl @[simp] theorem curry_symm_apply (f : α →o β →o γ) (x : α × β) : curry.symm f x = f x.1 x.2 := rfl /-- The composition of two bundled monotone functions. -/ @[simps -fullyApplied] def comp (g : β →o γ) (f : α →o β) : α →o γ := ⟨g ∘ f, g.mono.comp f.mono⟩ @[mono] theorem comp_mono ⦃g₁ g₂ : β →o γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →o β⦄ (hf : f₁ ≤ f₂) : g₁.comp f₁ ≤ g₂.comp f₂ := fun _ => (hg _).trans (g₂.mono <| hf _) @[simp] lemma mk_comp_mk (g : β → γ) (f : α → β) (hg hf) : comp ⟨g, hg⟩ ⟨f, hf⟩ = ⟨g ∘ f, hg.comp hf⟩ := rfl /-- The composition of two bundled monotone functions, a fully bundled version. -/ @[simps! -fullyApplied] def compₘ : (β →o γ) →o (α →o β) →o α →o γ := curry ⟨fun f : (β →o γ) × (α →o β) => f.1.comp f.2, fun _ _ h => comp_mono h.1 h.2⟩ @[simp] theorem comp_id (f : α →o β) : comp f id = f := by ext rfl @[simp] theorem id_comp (f : α →o β) : comp id f = f := by ext rfl /-- Constant function bundled as an `OrderHom`. -/ @[simps -fullyApplied] def const (α : Type*) [Preorder α] {β : Type*} [Preorder β] : β →o α →o β where toFun b := ⟨Function.const α b, fun _ _ _ => le_rfl⟩ monotone' _ _ h _ := h @[simp] theorem const_comp (f : α →o β) (c : γ) : (const β c).comp f = const α c := rfl @[simp] theorem comp_const (γ : Type*) [Preorder γ] (f : α →o β) (c : α) : f.comp (const γ c) = const γ (f c) := rfl /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. -/ @[simps] protected def prod (f : α →o β) (g : α →o γ) : α →o β × γ := ⟨fun x => (f x, g x), fun _ _ h => ⟨f.mono h, g.mono h⟩⟩ @[mono] theorem prod_mono {f₁ f₂ : α →o β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →o γ} (hg : g₁ ≤ g₂) : f₁.prod g₁ ≤ f₂.prod g₂ := fun _ => Prod.le_def.2 ⟨hf _, hg _⟩ theorem comp_prod_comp_same (f₁ f₂ : β →o γ) (g : α →o β) : (f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g := rfl /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. This is a fully bundled version. -/ @[simps!] def prodₘ : (α →o β) →o (α →o γ) →o α →o β × γ := curry ⟨fun f : (α →o β) × (α →o γ) => f.1.prod f.2, fun _ _ h => prod_mono h.1 h.2⟩ /-- Diagonal embedding of `α` into `α × α` as an `OrderHom`. -/ @[simps!] def diag : α →o α × α := id.prod id /-- Restriction of `f : α →o α →o β` to the diagonal. -/ @[simps! +simpRhs] def onDiag (f : α →o α →o β) : α →o β := (curry.symm f).comp diag /-- `Prod.fst` as an `OrderHom`. -/ @[simps] def fst : α × β →o α := ⟨Prod.fst, fun _ _ h => h.1⟩ /-- `Prod.snd` as an `OrderHom`. -/ @[simps] def snd : α × β →o β := ⟨Prod.snd, fun _ _ h => h.2⟩ @[simp] theorem fst_prod_snd : (fst : α × β →o α).prod snd = id := by ext ⟨x, y⟩ : 2 rfl @[simp] theorem fst_comp_prod (f : α →o β) (g : α →o γ) : fst.comp (f.prod g) = f := ext _ _ rfl @[simp] theorem snd_comp_prod (f : α →o β) (g : α →o γ) : snd.comp (f.prod g) = g := ext _ _ rfl /-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces of monotone maps to `β` and `γ`. -/ @[simps] def prodIso : (α →o β × γ) ≃o (α →o β) × (α →o γ) where toFun f := (fst.comp f, snd.comp f) invFun f := f.1.prod f.2 map_rel_iff' := forall_and.symm /-- `Prod.map` of two `OrderHom`s as an `OrderHom` -/ @[simps] def prodMap (f : α →o β) (g : γ →o δ) : α × γ →o β × δ := ⟨Prod.map f g, fun _ _ h => ⟨f.mono h.1, g.mono h.2⟩⟩ variable {ι : Type*} {π : ι → Type*} [∀ i, Preorder (π i)] /-- Evaluation of an unbundled function at a point (`Function.eval`) as an `OrderHom`. -/ @[simps -fullyApplied] def _root_.Pi.evalOrderHom (i : ι) : (∀ j, π j) →o π i := ⟨Function.eval i, Function.monotone_eval i⟩ /-- The "forgetful functor" from `α →o β` to `α → β` that takes the underlying function, is monotone. -/ @[simps -fullyApplied] def coeFnHom : (α →o β) →o α → β where toFun f := f monotone' _ _ h := h /-- Function application `fun f => f a` (for fixed `a`) is a monotone function from the monotone function space `α →o β` to `β`. See also `Pi.evalOrderHom`. -/ @[simps! -fullyApplied] def apply (x : α) : (α →o β) →o β := (Pi.evalOrderHom x).comp coeFnHom /-- Construct a bundled monotone map `α →o Π i, π i` from a family of monotone maps `f i : α →o π i`. -/ @[simps] def pi (f : ∀ i, α →o π i) : α →o ∀ i, π i := ⟨fun x i => f i x, fun _ _ h i => (f i).mono h⟩ /-- Order isomorphism between bundled monotone maps `α →o Π i, π i` and families of bundled monotone maps `Π i, α →o π i`. -/ @[simps] def piIso : (α →o ∀ i, π i) ≃o ∀ i, α →o π i where toFun f i := (Pi.evalOrderHom i).comp f invFun := pi map_rel_iff' := forall_swap /-- `Subtype.val` as a bundled monotone function. -/ @[simps -fullyApplied] def Subtype.val (p : α → Prop) : Subtype p →o α := ⟨_root_.Subtype.val, fun _ _ h => h⟩ /-- `Subtype.impEmbedding` as an order embedding. -/ @[simps!] def _root_.Subtype.orderEmbedding {p q : α → Prop} (h : ∀ a, p a → q a) : {x // p x} ↪o {x // q x} := { Subtype.impEmbedding _ _ h with map_rel_iff' := by aesop } /-- There is a unique monotone map from a subsingleton to itself. -/ instance unique [Subsingleton α] : Unique (α →o α) where default := OrderHom.id uniq _ := ext _ _ (Subsingleton.elim _ _) theorem orderHom_eq_id [Subsingleton α] (g : α →o α) : g = OrderHom.id := Subsingleton.elim _ _ /-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/ @[simps] protected def dual : (α →o β) ≃ (αᵒᵈ →o βᵒᵈ) where toFun f := ⟨(OrderDual.toDual : β → βᵒᵈ) ∘ (f : α → β) ∘ (OrderDual.ofDual : αᵒᵈ → α), f.mono.dual⟩ invFun f := ⟨OrderDual.ofDual ∘ f ∘ OrderDual.toDual, f.mono.dual⟩ @[simp] theorem dual_id : (OrderHom.id : α →o α).dual = OrderHom.id := rfl @[simp] theorem dual_comp (g : β →o γ) (f : α →o β) : (g.comp f).dual = g.dual.comp f.dual := rfl @[simp] theorem symm_dual_id : OrderHom.dual.symm OrderHom.id = (OrderHom.id : α →o α) := rfl @[simp] theorem symm_dual_comp (g : βᵒᵈ →o γᵒᵈ) (f : αᵒᵈ →o βᵒᵈ) : OrderHom.dual.symm (g.comp f) = (OrderHom.dual.symm g).comp (OrderHom.dual.symm f) := rfl /-- `OrderHom.dual` as an order isomorphism. -/ def dualIso (α β : Type*) [Preorder α] [Preorder β] : (α →o β) ≃o (αᵒᵈ →o βᵒᵈ)ᵒᵈ where toEquiv := OrderHom.dual.trans OrderDual.toDual map_rel_iff' := Iff.rfl /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `ULift α →o ULift β` in a higher universe. -/ @[simps!] def uliftMap (f : α →o β) : ULift α →o ULift β := ⟨fun i => ⟨f i.down⟩, fun _ _ h ↦ f.monotone h⟩ /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `α →o ULift β` in a higher universe. -/ @[simps!] def uliftRightMap (f : α →o β) : α →o ULift β := ⟨fun i => ⟨f i⟩, fun _ _ h ↦ f.monotone h⟩ /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `ULift α →o β` in a higher universe. -/ @[simps!] def uliftLeftMap (f : α →o β) : ULift α →o β := ⟨fun i => f i.down, fun _ _ h ↦ f.monotone h⟩ @[simp] theorem uliftLeftMap_uliftRightMap_eq (f : α →o β) : f.uliftLeftMap.uliftRightMap = f.uliftMap := rfl @[simp] theorem uliftRightMap_uliftLeftMap_eq (f : α →o β) : f.uliftRightMap.uliftLeftMap = f.uliftMap := rfl end OrderHom -- See note [lower instance priority] instance (priority := 90) OrderHomClass.toOrderHomClassOrderDual [LE α] [LE β] [FunLike F α β] [OrderHomClass F α β] : OrderHomClass F αᵒᵈ βᵒᵈ where map_rel f := map_rel f /-- Embeddings of partial orders that preserve `<` also preserve `≤`. -/ def RelEmbedding.orderEmbeddingOfLTEmbedding [PartialOrder α] [PartialOrder β] (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : α ↪o β := { f with map_rel_iff' := by simp [le_iff_lt_or_eq, f.map_rel_iff, f.injective.eq_iff] } @[simp] theorem RelEmbedding.orderEmbeddingOfLTEmbedding_apply [PartialOrder α] [PartialOrder β] {f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)} {x : α} : RelEmbedding.orderEmbeddingOfLTEmbedding f x = f x := rfl namespace OrderEmbedding variable [Preorder α] [Preorder β] (f : α ↪o β) /-- `<` is preserved by order embeddings of preorders. -/ def ltEmbedding : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop) := { f with map_rel_iff' := by simp [lt_iff_le_not_ge, f.map_rel_iff] } @[simp] theorem ltEmbedding_apply (x : α) : f.ltEmbedding x = f x := rfl @[simp] theorem le_iff_le {a b} : f a ≤ f b ↔ a ≤ b := f.map_rel_iff @[simp] theorem lt_iff_lt {a b} : f a < f b ↔ a < b := f.ltEmbedding.map_rel_iff theorem eq_iff_eq {a b} : f a = f b ↔ a = b := f.injective.eq_iff protected theorem monotone : Monotone f := OrderHomClass.monotone f protected theorem strictMono : StrictMono f := fun _ _ => f.lt_iff_lt.2 protected theorem acc (a : α) : Acc (· < ·) (f a) → Acc (· < ·) a := f.ltEmbedding.acc a protected theorem wellFounded (f : α ↪o β) : WellFounded ((· < ·) : β → β → Prop) → WellFounded ((· < ·) : α → α → Prop) := f.ltEmbedding.wellFounded protected theorem isWellOrder [IsWellOrder β (· < ·)] (f : α ↪o β) : IsWellOrder α (· < ·) := f.ltEmbedding.isWellOrder /-- An order embedding is also an order embedding between dual orders. -/ protected def dual : αᵒᵈ ↪o βᵒᵈ := ⟨f.toEmbedding, f.map_rel_iff⟩ /-- A preorder which embeds into a well-founded preorder is itself well-founded. -/ protected theorem wellFoundedLT [WellFoundedLT β] (f : α ↪o β) : WellFoundedLT α where wf := f.wellFounded IsWellFounded.wf /-- A preorder which embeds into a preorder in which `(· > ·)` is well-founded also has `(· > ·)` well-founded. -/ protected theorem wellFoundedGT [WellFoundedGT β] (f : α ↪o β) : WellFoundedGT α := @OrderEmbedding.wellFoundedLT αᵒᵈ _ _ _ _ f.dual /-- To define an order embedding from a partial order to a preorder it suffices to give a function together with a proof that it satisfies `f a ≤ f b ↔ a ≤ b`. -/ def ofMapLEIff {α β} [PartialOrder α] [Preorder β] (f : α → β) (hf : ∀ a b, f a ≤ f b ↔ a ≤ b) : α ↪o β := RelEmbedding.ofMapRelIff f hf @[simp] theorem coe_ofMapLEIff {α β} [PartialOrder α] [Preorder β] {f : α → β} (h) : ⇑(ofMapLEIff f h) = f := rfl /-- A strictly monotone map from a linear order is an order embedding. -/ def ofStrictMono {α β} [LinearOrder α] [Preorder β] (f : α → β) (h : StrictMono f) : α ↪o β := ofMapLEIff f fun _ _ => h.le_iff_le @[simp] theorem coe_ofStrictMono {α β} [LinearOrder α] [Preorder β] {f : α → β} (h : StrictMono f) : ⇑(ofStrictMono f h) = f := rfl /-- Embedding of a subtype into the ambient type as an `OrderEmbedding`. -/ def subtype (p : α → Prop) : Subtype p ↪o α := ⟨Function.Embedding.subtype p, Iff.rfl⟩ @[simp] theorem subtype_apply {p : α → Prop} (x : Subtype p) : subtype p x = x := rfl theorem subtype_injective (p : α → Prop) : Function.Injective (subtype p) := Subtype.coe_injective @[simp] theorem coe_subtype (p : α → Prop) : ⇑(subtype p) = Subtype.val := rfl /-- Convert an `OrderEmbedding` to an `OrderHom`. -/ @[simps -fullyApplied] def toOrderHom {X Y : Type*} [Preorder X] [Preorder Y] (f : X ↪o Y) : X →o Y where toFun := f monotone' := f.monotone /-- The trivial embedding from an empty preorder to another preorder -/ @[simps] def ofIsEmpty [IsEmpty α] : α ↪o β where toFun := isEmptyElim inj' := isEmptyElim map_rel_iff' {a} := isEmptyElim a @[simp, norm_cast] lemma coe_ofIsEmpty [IsEmpty α] : (ofIsEmpty : α ↪o β) = (isEmptyElim : α → β) := rfl end OrderEmbedding section Disjoint variable [PartialOrder α] [PartialOrder β] (f : OrderEmbedding α β) /-- If the images by an order embedding of two elements are disjoint, then they are themselves disjoint. -/ lemma Disjoint.of_orderEmbedding [OrderBot α] [OrderBot β] {a₁ a₂ : α} : Disjoint (f a₁) (f a₂) → Disjoint a₁ a₂ := by intro h x h₁ h₂ rw [← f.le_iff_le] at h₁ h₂ ⊢ calc f x ≤ ⊥ := h h₁ h₂ _ ≤ f ⊥ := bot_le /-- If the images by an order embedding of two elements are codisjoint, then they are themselves codisjoint. -/ lemma Codisjoint.of_orderEmbedding [OrderTop α] [OrderTop β] {a₁ a₂ : α} : Codisjoint (f a₁) (f a₂) → Codisjoint a₁ a₂ := Disjoint.of_orderEmbedding (α := αᵒᵈ) (β := βᵒᵈ) f.dual /-- If the images by an order embedding of two elements are complements, then they are themselves complements. -/ lemma IsCompl.of_orderEmbedding [BoundedOrder α] [BoundedOrder β] {a₁ a₂ : α} : IsCompl (f a₁) (f a₂) → IsCompl a₁ a₂ := fun ⟨hd, hcd⟩ ↦ ⟨Disjoint.of_orderEmbedding f hd, Codisjoint.of_orderEmbedding f hcd⟩ end Disjoint section RelHom variable [PartialOrder α] [Preorder β] namespace RelHom variable (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)) /-- A bundled expression of the fact that a map between partial orders that is strictly monotone is weakly monotone. -/ @[simps -fullyApplied] def toOrderHom : α →o β where toFun := f monotone' := StrictMono.monotone fun _ _ => f.map_rel end RelHom theorem RelEmbedding.toOrderHom_injective (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : Function.Injective (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)).toOrderHom := fun _ _ h => f.injective h end RelHom namespace OrderIso section LE variable [LE α] [LE β] [LE γ] instance : EquivLike (α ≃o β) α β where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : OrderIsoClass (α ≃o β) α β where map_le_map_iff f _ _ := f.map_rel_iff' @[simp] theorem toFun_eq_coe {f : α ≃o β} : f.toFun = f := rfl -- See note [partially-applied ext lemmas] @[ext] theorem ext {f g : α ≃o β} (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h /-- Reinterpret an order isomorphism as an order embedding. -/ def toOrderEmbedding (e : α ≃o β) : α ↪o β := e.toRelEmbedding @[simp] theorem coe_toOrderEmbedding (e : α ≃o β) : ⇑e.toOrderEmbedding = e := rfl protected theorem bijective (e : α ≃o β) : Function.Bijective e := e.toEquiv.bijective protected theorem injective (e : α ≃o β) : Function.Injective e := e.toEquiv.injective protected theorem surjective (e : α ≃o β) : Function.Surjective e := e.toEquiv.surjective theorem apply_eq_iff_eq (e : α ≃o β) {x y : α} : e x = e y ↔ x = y := e.toEquiv.apply_eq_iff_eq /-- Identity order isomorphism. -/ def refl (α : Type*) [LE α] : α ≃o α := RelIso.refl (· ≤ ·) @[simp] theorem coe_refl : ⇑(refl α) = id := rfl @[simp] theorem refl_apply (x : α) : refl α x = x := rfl @[simp] theorem refl_toEquiv : (refl α).toEquiv = Equiv.refl α := rfl /-- Inverse of an order isomorphism. -/ def symm (e : α ≃o β) : β ≃o α := RelIso.symm e @[simp] lemma symm_mk (e : α ≃ β) (map_rel_iff') : symm (.mk e map_rel_iff') = .mk e.symm (by simp [← map_rel_iff']) := rfl @[simp] theorem apply_symm_apply (e : α ≃o β) (x : β) : e (e.symm x) = x := e.toEquiv.apply_symm_apply x @[simp] theorem symm_apply_apply (e : α ≃o β) (x : α) : e.symm (e x) = x := e.toEquiv.symm_apply_apply x @[simp] theorem symm_refl (α : Type*) [LE α] : (refl α).symm = refl α := rfl theorem apply_eq_iff_eq_symm_apply (e : α ≃o β) (x : α) (y : β) : e x = y ↔ x = e.symm y := e.toEquiv.apply_eq_iff_eq_symm_apply theorem symm_apply_eq (e : α ≃o β) {x : α} {y : β} : e.symm y = x ↔ y = e x := e.toEquiv.symm_apply_eq @[simp] theorem symm_symm (e : α ≃o β) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (OrderIso.symm : (α ≃o β) → β ≃o α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (symm : α ≃o β → β ≃o α) := symm_bijective.injective @[simp] theorem toEquiv_symm (e : α ≃o β) : e.symm.toEquiv = e.toEquiv.symm := rfl @[simp] theorem coe_toEquiv (e : α ≃o β) : ⇑e.toEquiv = e := rfl @[simp] theorem coe_symm_toEquiv (e : α ≃o β) : ⇑e.toEquiv.symm = e.symm := rfl /-- Composition of two order isomorphisms is an order isomorphism. -/ @[trans] def trans (e : α ≃o β) (e' : β ≃o γ) : α ≃o γ := RelIso.trans e e' @[simp] theorem coe_trans (e : α ≃o β) (e' : β ≃o γ) : ⇑(e.trans e') = e' ∘ e := rfl @[simp] theorem trans_apply (e : α ≃o β) (e' : β ≃o γ) (x : α) : e.trans e' x = e' (e x) := rfl @[simp] theorem refl_trans (e : α ≃o β) : (refl α).trans e = e := by ext x rfl @[simp] theorem trans_refl (e : α ≃o β) : e.trans (refl β) = e := by ext x rfl @[simp] theorem symm_trans_apply (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : γ) : (e₁.trans e₂).symm c = e₁.symm (e₂.symm c) := rfl theorem symm_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl @[simp] theorem self_trans_symm (e : α ≃o β) : e.trans e.symm = OrderIso.refl α := RelIso.self_trans_symm e @[simp] theorem symm_trans_self (e : α ≃o β) : e.symm.trans e = OrderIso.refl β := RelIso.symm_trans_self e /-- An order isomorphism between the domains and codomains of two prosets of order homomorphisms gives an order isomorphism between the two function prosets. -/ @[simps apply symm_apply] def arrowCongr {α β γ δ} [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] (f : α ≃o γ) (g : β ≃o δ) : (α →o β) ≃o (γ →o δ) where toFun p := .comp g <| .comp p f.symm invFun p := .comp g.symm <| .comp p f left_inv p := DFunLike.coe_injective <| by change (g.symm ∘ g) ∘ p ∘ (f.symm ∘ f) = p simp only [← OrderIso.coe_trans, Function.id_comp, OrderIso.self_trans_symm, OrderIso.coe_refl, Function.comp_id] right_inv p := DFunLike.coe_injective <| by change (g ∘ g.symm) ∘ p ∘ (f ∘ f.symm) = p simp only [← OrderIso.coe_trans, Function.id_comp, OrderIso.symm_trans_self, OrderIso.coe_refl, Function.comp_id] map_rel_iff' {p q} := by simp only [Equiv.coe_fn_mk, OrderHom.le_def, OrderHom.comp_coe, OrderHomClass.coe_coe, Function.comp_apply, map_le_map_iff] exact Iff.symm f.forall_congr_left /-- If `α` and `β` are order-isomorphic then the two orders of order-homomorphisms from `α` and `β` to themselves are order-isomorphic. -/ @[simps! apply symm_apply] def conj {α β} [Preorder α] [Preorder β] (f : α ≃o β) : (α →o α) ≃ (β →o β) := arrowCongr f f /-- `Prod.swap` as an `OrderIso`. -/ def prodComm : α × β ≃o β × α where toEquiv := Equiv.prodComm α β map_rel_iff' := Prod.swap_le_swap @[simp] theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap := rfl @[simp] theorem prodComm_symm : (prodComm : α × β ≃o β × α).symm = prodComm := rfl variable (α) /-- The order isomorphism between a type and its double dual. -/ def dualDual : α ≃o αᵒᵈᵒᵈ := refl α @[simp] theorem coe_dualDual : ⇑(dualDual α) = toDual ∘ toDual := rfl @[simp] theorem coe_dualDual_symm : ⇑(dualDual α).symm = ofDual ∘ ofDual := rfl variable {α} @[simp] theorem dualDual_apply (a : α) : dualDual α a = toDual (toDual a) := rfl @[simp] theorem dualDual_symm_apply (a : αᵒᵈᵒᵈ) : (dualDual α).symm a = ofDual (ofDual a) := rfl end LE open Set section LE variable [LE α] [LE β] theorem le_iff_le (e : α ≃o β) {x y : α} : e x ≤ e y ↔ x ≤ y := e.map_rel_iff @[gcongr] protected alias ⟨_, GCongr.orderIso_apply_le_apply⟩ := le_iff_le theorem le_symm_apply (e : α ≃o β) {x : α} {y : β} : x ≤ e.symm y ↔ e x ≤ y := e.rel_symm_apply theorem symm_apply_le (e : α ≃o β) {x : α} {y : β} : e.symm y ≤ x ↔ y ≤ e x := e.symm_apply_rel end LE variable [Preorder α] [Preorder β] protected theorem monotone (e : α ≃o β) : Monotone e := e.toOrderEmbedding.monotone protected theorem strictMono (e : α ≃o β) : StrictMono e := e.toOrderEmbedding.strictMono @[simp] theorem lt_iff_lt (e : α ≃o β) {x y : α} : e x < e y ↔ x < y := e.toOrderEmbedding.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.orderIso_apply_lt_apply⟩ := lt_iff_lt theorem lt_symm_apply (e : α ≃o β) {x : α} {y : β} : x < e.symm y ↔ e x < y := by rw [← e.lt_iff_lt, e.apply_symm_apply] theorem symm_apply_lt (e : α ≃o β) {x : α} {y : β} : e.symm y < x ↔ y < e x := by rw [← e.lt_iff_lt, e.apply_symm_apply] /-- Converts an `OrderIso` into a `RelIso (<) (<)`. -/ def toRelIsoLT (e : α ≃o β) : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop) := ⟨e.toEquiv, lt_iff_lt e⟩ @[simp] theorem toRelIsoLT_apply (e : α ≃o β) (x : α) : e.toRelIsoLT x = e x := rfl @[simp] theorem toRelIsoLT_symm (e : α ≃o β) : e.symm.toRelIsoLT = e.toRelIsoLT.symm := rfl @[simp] theorem coe_toRelIsoLT (e : α ≃o β) : ⇑e.toRelIsoLT = e := rfl @[simp] theorem coe_symm_toRelIsoLT (e : α ≃o β) : ⇑e.toRelIsoLT.symm = e.symm := rfl /-- Converts a `RelIso (<) (<)` into an `OrderIso`. -/ def ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : α ≃o β := ⟨e.toEquiv, by simp [le_iff_eq_or_lt, e.map_rel_iff, e.injective.eq_iff]⟩ @[simp] theorem ofRelIsoLT_apply {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) (x : α) : ofRelIsoLT e x = e x := rfl @[simp] theorem ofRelIsoLT_symm {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : (ofRelIsoLT e).symm = ofRelIsoLT e.symm := rfl @[simp] theorem ofRelIsoLT_toRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : α ≃o β) : ofRelIsoLT (toRelIsoLT e) = e := by ext simp @[simp] theorem toRelIsoLT_ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : toRelIsoLT (ofRelIsoLT e) = e := by ext simp /-- To show that `f : α → β`, `g : β → α` make up an order isomorphism of linear orders, it suffices to prove `cmp a (g b) = cmp (f a) b`. -/ def ofCmpEqCmp {α β} [LinearOrder α] [LinearOrder β] (f : α → β) (g : β → α) (h : ∀ (a : α) (b : β), cmp a (g b) = cmp (f a) b) : α ≃o β := have gf : ∀ a : α, a = g (f a) := by intro rw [← cmp_eq_eq_iff, h, cmp_self_eq_eq] { toFun := f, invFun := g, left_inv := fun a => (gf a).symm, right_inv := by intro rw [← cmp_eq_eq_iff, ← h, cmp_self_eq_eq], map_rel_iff' := by intro a b apply le_iff_le_of_cmp_eq_cmp convert (h a (f b)).symm apply gf } /-- To show that `f : α →o β` and `g : β →o α` make up an order isomorphism it is enough to show that `g` is the inverse of `f`. -/ @[simps! apply] def ofHomInv {F G : Type*} [FunLike F α β] [OrderHomClass F α β] [FunLike G β α] [OrderHomClass G β α] (f : F) (g : G) (h₁ : (f : α →o β).comp (g : β →o α) = OrderHom.id) (h₂ : (g : β →o α).comp (f : α →o β) = OrderHom.id) : α ≃o β where toFun := f invFun := g left_inv := DFunLike.congr_fun h₂ right_inv := DFunLike.congr_fun h₁ map_rel_iff' := @fun a b => ⟨fun h => by replace h := map_rel g h rwa [Equiv.coe_fn_mk, show g (f a) = (g : β →o α).comp (f : α →o β) a from rfl, show g (f b) = (g : β →o α).comp (f : α →o β) b from rfl, h₂] at h, fun h => (f : α →o β).monotone h⟩ @[simp] theorem ofHomInv_symm_apply {F G : Type*} [FunLike F α β] [OrderHomClass F α β] [FunLike G β α] [OrderHomClass G β α] (f : F) (g : G) (h₁ : (f : α →o β).comp (g : β →o α) = OrderHom.id) (h₂ : (g : β →o α).comp (f : α →o β) = OrderHom.id) (a : β) : (ofHomInv f g h₁ h₂).symm a = g a := rfl /-- Order isomorphism between `α → β` and `β`, where `α` has a unique element. -/ @[simps! toEquiv apply] def funUnique (α β : Type*) [Unique α] [Preorder β] : (α → β) ≃o β where toEquiv := Equiv.funUnique α β map_rel_iff' := by simp [Pi.le_def, Unique.forall_iff] @[simp] theorem funUnique_symm_apply {α β : Type*} [Unique α] [Preorder β] : ((funUnique α β).symm : β → α → β) = Function.const α := rfl /-- The order isomorphism `α ≃o β` when `α` and `β` are preordered types containing unique elements. -/ @[simps!] noncomputable def ofUnique (α β : Type*) [Unique α] [Unique β] [Preorder α] [Preorder β] : α ≃o β where toEquiv := Equiv.ofUnique α β map_rel_iff' := by simp end OrderIso namespace Equiv variable [Preorder α] [Preorder β] /-- If `e` is an equivalence with monotone forward and inverse maps, then `e` is an order isomorphism. -/ def toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : α ≃o β := ⟨e, ⟨fun h => by simpa only [e.symm_apply_apply] using h₂ h, fun h => h₁ h⟩⟩ @[simp] theorem coe_toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : ⇑(e.toOrderIso h₁ h₂) = e := rfl @[simp] theorem toOrderIso_toEquiv (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : (e.toOrderIso h₁ h₂).toEquiv = e := rfl end Equiv namespace StrictMono variable [LinearOrder α] [Preorder β] variable (f : α → β) (h_mono : StrictMono f) /-- A strictly monotone function with a right inverse is an order isomorphism. -/ @[simps -fullyApplied] def orderIsoOfRightInverse (g : β → α) (hg : Function.RightInverse g f) : α ≃o β := { OrderEmbedding.ofStrictMono f h_mono with toFun := f, invFun := g, left_inv := fun _ => h_mono.injective <| hg _, right_inv := hg } end StrictMono /-- An order isomorphism is also an order isomorphism between dual orders. -/ protected def OrderIso.dual [LE α] [LE β] (f : α ≃o β) : αᵒᵈ ≃o βᵒᵈ := ⟨f.toEquiv, f.map_rel_iff⟩ section LatticeIsos theorem OrderIso.map_bot' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x ≤ x') (hy : ∀ y', y ≤ y') : f x = y := by refine le_antisymm ?_ (hy _) rw [← f.apply_symm_apply y, f.map_rel_iff] apply hx theorem OrderIso.map_bot [LE α] [PartialOrder β] [OrderBot α] [OrderBot β] (f : α ≃o β) : f ⊥ = ⊥ := f.map_bot' (fun _ => bot_le) fun _ => bot_le theorem OrderIso.map_top' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x' ≤ x) (hy : ∀ y', y' ≤ y) : f x = y := f.dual.map_bot' hx hy theorem OrderIso.map_top [LE α] [PartialOrder β] [OrderTop α] [OrderTop β] (f : α ≃o β) : f ⊤ = ⊤ := f.dual.map_bot theorem OrderEmbedding.map_inf_le [SemilatticeInf α] [SemilatticeInf β] (f : α ↪o β) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := f.monotone.map_inf_le x y theorem OrderEmbedding.le_map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ↪o β) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := f.monotone.le_map_sup x y theorem OrderIso.map_inf [SemilatticeInf α] [SemilatticeInf β] (f : α ≃o β) (x y : α) : f (x ⊓ y) = f x ⊓ f y := by refine (f.toOrderEmbedding.map_inf_le x y).antisymm ?_ apply f.symm.le_iff_le.1 simpa using f.symm.toOrderEmbedding.map_inf_le (f x) (f y) theorem OrderIso.map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ≃o β) (x y : α) : f (x ⊔ y) = f x ⊔ f y := f.dual.map_inf x y theorem OrderIso.isMax_apply {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) {x : α} : IsMax (f x) ↔ IsMax x := by refine ⟨f.strictMono.isMax_of_apply, ?_⟩ conv_lhs => rw [← f.symm_apply_apply x] exact f.symm.strictMono.isMax_of_apply theorem OrderIso.isMin_apply {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) {x : α} : IsMin (f x) ↔ IsMin x := by refine ⟨f.strictMono.isMin_of_apply, ?_⟩ conv_lhs => rw [← f.symm_apply_apply x] exact f.symm.strictMono.isMin_of_apply /-- Note that this goal could also be stated `(Disjoint on f) a b` -/ theorem Disjoint.map_orderIso [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β] {a b : α} (f : α ≃o β) (ha : Disjoint a b) : Disjoint (f a) (f b) := by rw [disjoint_iff_inf_le, ← f.map_inf, ← f.map_bot] exact f.monotone ha.le_bot /-- Note that this goal could also be stated `(Codisjoint on f) a b` -/ theorem Codisjoint.map_orderIso [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β] {a b : α} (f : α ≃o β) (ha : Codisjoint a b) : Codisjoint (f a) (f b) := by rw [codisjoint_iff_le_sup, ← f.map_sup, ← f.map_top] exact f.monotone ha.top_le @[simp] theorem disjoint_map_orderIso_iff [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β] {a b : α} (f : α ≃o β) : Disjoint (f a) (f b) ↔ Disjoint a b := ⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm, fun h => h.map_orderIso f⟩ @[simp] theorem codisjoint_map_orderIso_iff [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β] {a b : α} (f : α ≃o β) : Codisjoint (f a) (f b) ↔ Codisjoint a b := ⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm, fun h => h.map_orderIso f⟩ section BoundedOrder variable [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] (f : α ≃o β) theorem OrderIso.isCompl {x y : α} (h : IsCompl x y) : IsCompl (f x) (f y) := ⟨h.1.map_orderIso _, h.2.map_orderIso _⟩ theorem OrderIso.isCompl_iff {x y : α} : IsCompl x y ↔ IsCompl (f x) (f y) := ⟨f.isCompl, fun h => f.symm_apply_apply x ▸ f.symm_apply_apply y ▸ f.symm.isCompl h⟩ theorem OrderIso.complementedLattice [ComplementedLattice α] (f : α ≃o β) : ComplementedLattice β := ⟨fun x => by obtain ⟨y, hy⟩ := exists_isCompl (f.symm x) rw [← f.symm_apply_apply y] at hy exact ⟨f y, f.symm.isCompl_iff.2 hy⟩⟩ theorem OrderIso.complementedLattice_iff (f : α ≃o β) : ComplementedLattice α ↔ ComplementedLattice β := ⟨by intro; exact f.complementedLattice, by intro; exact f.symm.complementedLattice⟩ end BoundedOrder end LatticeIsos -- See note [lower instance priority] instance (priority := 90) OrderIsoClass.toOrderIsoClassOrderDual [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderIsoClass F αᵒᵈ βᵒᵈ where map_le_map_iff f := map_le_map_iff f section DenselyOrdered -- could live in a more upstream file, but hard to find a good place lemma StrictMono.denselyOrdered_range {X Y : Type*} [LinearOrder X] [DenselyOrdered X] [Preorder Y] {f : X → Y} (hf : StrictMono f) : DenselyOrdered (Set.range f) := by constructor simpa [← exists_and_left, ← exists_and_right, exists_comm, hf.lt_iff_lt] using fun _ _ ↦ exists_between lemma denselyOrdered_iff_of_orderIsoClass {X Y F : Type*} [Preorder X] [Preorder Y] [EquivLike F X Y] [OrderIsoClass F X Y] (f : F) : DenselyOrdered X ↔ DenselyOrdered Y := by constructor · intro H refine ⟨fun a b h ↦ ?_⟩ obtain ⟨c, hc⟩ := exists_between ((map_inv_lt_map_inv_iff f).mpr h) exact ⟨f c, by simpa using hc⟩ · intro H refine ⟨fun a b h ↦ ?_⟩ obtain ⟨c, hc⟩ := exists_between ((map_lt_map_iff f).mpr h) exact ⟨EquivLike.inv f c, by simpa using hc⟩ lemma denselyOrdered_iff_of_strictAnti {X Y F : Type*} [LinearOrder X] [Preorder Y] [EquivLike F X Y] (f : F) (hf : StrictAnti f) : DenselyOrdered X ↔ DenselyOrdered Y := by rw [← denselyOrdered_orderDual] let e : Xᵒᵈ ≃o Y := ⟨OrderDual.ofDual.trans (f : X ≃ Y), ?_⟩ · exact denselyOrdered_iff_of_orderIsoClass e · simp only [Equiv.trans_apply, EquivLike.coe_coe, OrderDual.forall, OrderDual.ofDual_toDual, OrderDual.toDual_le_toDual] intro a b rw [hf.le_iff_ge] end DenselyOrdered universe v u in /-- The bijection `ULift.{v} α ≃ α` as an isomorphism of orders. -/ @[pp_with_univ, simps!] def ULift.orderIso {α : Type u} [Preorder α] : ULift.{v} α ≃o α := Equiv.ulift.toOrderIso (fun _ _ ↦ id) (fun _ _ ↦ id)
.lake/packages/mathlib/Mathlib/Order/Hom/Set.lean
import Mathlib.Logic.Equiv.Set import Mathlib.Order.Hom.Basic import Mathlib.Order.Interval.Set.Defs import Mathlib.Order.WellFounded import Mathlib.Tactic.MinImports /-! # Order homomorphisms and sets -/ open OrderDual Set variable {α β : Type*} namespace Set /-- Sets on sum types are order-equivalent to pairs of sets on each summand. -/ 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] 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 α] /-- Order isomorphism between two equal sets. -/ @[simps! apply symm_apply] def setCongr (s t : Set α) (h : s = t) : s ≃o t where toEquiv := Equiv.setCongr h map_rel_iff' := Iff.rfl /-- 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 <| (OrderIso.setCongr _ _ 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 on a well-order are equal provided that their ranges are equal. -/ lemma OrderEmbedding.range_inj [LinearOrder α] [WellFoundedLT α] [Preorder β] {f g : α ↪o β} : Set.range f = Set.range g ↔ f = g := by rw [f.strictMono.range_inj g.strictMono, DFunLike.coe_fn_eq] 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, 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' _ /-- 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 /-- 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 ∘ HasCompl.compl invFun := HasCompl.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
.lake/packages/mathlib/Mathlib/Order/Hom/Bounded.lean
import Mathlib.Order.Hom.Basic /-! # Bounded order homomorphisms This file defines (bounded) order homomorphisms. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `TopHom`: Maps which preserve `⊤`. * `BotHom`: Maps which preserve `⊥`. * `BoundedOrderHom`: Bounded order homomorphisms. Monotone maps which preserve `⊤` and `⊥`. ## Typeclasses * `TopHomClass` * `BotHomClass` * `BoundedOrderHomClass` -/ open Function OrderDual variable {F α β γ δ : Type*} /-- The type of `⊤`-preserving functions from `α` to `β`. -/ structure TopHom (α β : Type*) [Top α] [Top β] where /-- The underlying function. The preferred spelling is `DFunLike.coe`. -/ toFun : α → β /-- The function preserves the top element. The preferred spelling is `map_top`. -/ map_top' : toFun ⊤ = ⊤ /-- The type of `⊥`-preserving functions from `α` to `β`. -/ structure BotHom (α β : Type*) [Bot α] [Bot β] where /-- The underlying function. The preferred spelling is `DFunLike.coe`. -/ toFun : α → β /-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/ map_bot' : toFun ⊥ = ⊥ /-- The type of bounded order homomorphisms from `α` to `β`. -/ structure BoundedOrderHom (α β : Type*) [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] extends OrderHom α β where /-- The function preserves the top element. The preferred spelling is `map_top`. -/ map_top' : toFun ⊤ = ⊤ /-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/ map_bot' : toFun ⊥ = ⊥ section /-- `TopHomClass F α β` states that `F` is a type of `⊤`-preserving morphisms. You should extend this class when you extend `TopHom`. -/ class TopHomClass (F : Type*) (α β : outParam Type*) [Top α] [Top β] [FunLike F α β] : Prop where /-- A `TopHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- `BotHomClass F α β` states that `F` is a type of `⊥`-preserving morphisms. You should extend this class when you extend `BotHom`. -/ class BotHomClass (F : Type*) (α β : outParam Type*) [Bot α] [Bot β] [FunLike F α β] : Prop where /-- A `BotHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ /-- `BoundedOrderHomClass F α β` states that `F` is a type of bounded order morphisms. You should extend this class when you extend `BoundedOrderHom`. -/ class BoundedOrderHomClass (F α β : Type*) [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [FunLike F α β] : Prop extends RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) where /-- Morphisms preserve the top element. The preferred spelling is `_root_.map_top`. -/ map_top (f : F) : f ⊤ = ⊤ /-- Morphisms preserve the bottom element. The preferred spelling is `_root_.map_bot`. -/ map_bot (f : F) : f ⊥ = ⊥ end export TopHomClass (map_top) export BotHomClass (map_bot) attribute [simp] map_top map_bot section Hom variable [FunLike F α β] -- See note [lower instance priority] instance (priority := 100) BoundedOrderHomClass.toTopHomClass [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : TopHomClass F α β := { ‹BoundedOrderHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) BoundedOrderHomClass.toBotHomClass [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : BotHomClass F α β := { ‹BoundedOrderHomClass F α β› with } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toTopHomClass [LE α] [OrderTop α] [PartialOrder β] [OrderTop β] [OrderIsoClass F α β] : TopHomClass F α β := { show OrderHomClass F α β from inferInstance with map_top := fun f => top_le_iff.1 <| (map_inv_le_iff f).1 le_top } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBotHomClass [LE α] [OrderBot α] [PartialOrder β] [OrderBot β] [OrderIsoClass F α β] : BotHomClass F α β := { map_bot := fun f => le_bot_iff.1 <| (le_map_inv_iff f).1 bot_le } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBoundedOrderHomClass [LE α] [BoundedOrder α] [PartialOrder β] [BoundedOrder β] [OrderIsoClass F α β] : BoundedOrderHomClass F α β := { show OrderHomClass F α β from inferInstance, OrderIsoClass.toTopHomClass, OrderIsoClass.toBotHomClass with } @[simp] theorem map_eq_top_iff [LE α] [OrderTop α] [PartialOrder β] [OrderTop β] [OrderIsoClass F α β] (f : F) {a : α} : f a = ⊤ ↔ a = ⊤ := by rw [← map_top f, (EquivLike.injective f).eq_iff] @[simp] theorem map_eq_bot_iff [LE α] [OrderBot α] [PartialOrder β] [OrderBot β] [OrderIsoClass F α β] (f : F) {a : α} : f a = ⊥ ↔ a = ⊥ := by rw [← map_bot f, (EquivLike.injective f).eq_iff] end Equiv variable [FunLike F α β] /-- Turn an element of a type `F` satisfying `TopHomClass F α β` into an actual `TopHom`. This is declared as the default coercion from `F` to `TopHom α β`. -/ @[coe] def TopHomClass.toTopHom [Top α] [Top β] [TopHomClass F α β] (f : F) : TopHom α β := ⟨f, map_top f⟩ instance [Top α] [Top β] [TopHomClass F α β] : CoeTC F (TopHom α β) := ⟨TopHomClass.toTopHom⟩ /-- Turn an element of a type `F` satisfying `BotHomClass F α β` into an actual `BotHom`. This is declared as the default coercion from `F` to `BotHom α β`. -/ @[coe] def BotHomClass.toBotHom [Bot α] [Bot β] [BotHomClass F α β] (f : F) : BotHom α β := ⟨f, map_bot f⟩ instance [Bot α] [Bot β] [BotHomClass F α β] : CoeTC F (BotHom α β) := ⟨BotHomClass.toBotHom⟩ /-- Turn an element of a type `F` satisfying `BoundedOrderHomClass F α β` into an actual `BoundedOrderHom`. This is declared as the default coercion from `F` to `BoundedOrderHom α β`. -/ @[coe] def BoundedOrderHomClass.toBoundedOrderHom [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] (f : F) : BoundedOrderHom α β := { (f : α →o β) with toFun := f, map_top' := map_top f, map_bot' := map_bot f } instance [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : CoeTC F (BoundedOrderHom α β) := ⟨BoundedOrderHomClass.toBoundedOrderHom⟩ /-! ### Top homomorphisms -/ namespace TopHom variable [Top α] section Top variable [Top β] [Top γ] [Top δ] instance : FunLike (TopHom α β) α β where coe := TopHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : TopHomClass (TopHom α β) α β where map_top := TopHom.map_top' -- this must come after the coe_to_fun definition initialize_simps_projections TopHom (toFun → apply) @[ext] theorem ext {f g : TopHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `TopHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : TopHom α β) (f' : α → β) (h : f' = f) : TopHom α β where toFun := f' map_top' := h.symm ▸ f.map_top' @[simp] theorem coe_copy (f : TopHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : TopHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h instance : Inhabited (TopHom α β) := ⟨⟨fun _ => ⊤, rfl⟩⟩ variable (α) /-- `id` as a `TopHom`. -/ protected def id : TopHom α α := ⟨id, rfl⟩ @[simp, norm_cast] theorem coe_id : ⇑(TopHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : TopHom.id α a = a := rfl /-- Composition of `TopHom`s as a `TopHom`. -/ def comp (f : TopHom β γ) (g : TopHom α β) : TopHom α γ where toFun := f ∘ g map_top' := by rw [comp_apply, map_top, map_top] @[simp] theorem coe_comp (f : TopHom β γ) (g : TopHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : TopHom β γ) (g : TopHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : TopHom γ δ) (g : TopHom β γ) (h : TopHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : TopHom α β) : f.comp (TopHom.id α) = f := TopHom.ext fun _ => rfl @[simp] theorem id_comp (f : TopHom α β) : (TopHom.id β).comp f = f := TopHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : TopHom β γ} {f : TopHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => TopHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun g => comp g f)⟩ @[simp] theorem cancel_left {g : TopHom β γ} {f₁ f₂ : TopHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => TopHom.ext fun a => hg <| by rw [← TopHom.comp_apply, h, TopHom.comp_apply], congr_arg _⟩ end Top instance instLE [LE β] [Top β] : LE (TopHom α β) where le f g := (f : α → β) ≤ g instance [Preorder β] [Top β] : Preorder (TopHom α β) := Preorder.lift (DFunLike.coe : TopHom α β → α → β) instance [PartialOrder β] [Top β] : PartialOrder (TopHom α β) := PartialOrder.lift _ DFunLike.coe_injective section OrderTop variable [LE β] [OrderTop β] instance : OrderTop (TopHom α β) where top := ⟨⊤, rfl⟩ le_top := fun _ => @le_top (α → β) _ _ _ @[simp] theorem coe_top : ⇑(⊤ : TopHom α β) = ⊤ := rfl @[simp] theorem top_apply (a : α) : (⊤ : TopHom α β) a = ⊤ := rfl end OrderTop section SemilatticeInf variable [SemilatticeInf β] [OrderTop β] (f g : TopHom α β) instance : Min (TopHom α β) := ⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_top, map_top, inf_top_eq]⟩⟩ instance : SemilatticeInf (TopHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl @[simp] theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl @[simp] theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl end SemilatticeInf section SemilatticeSup variable [SemilatticeSup β] [OrderTop β] (f g : TopHom α β) instance : Max (TopHom α β) := ⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_top, map_top, sup_top_eq]⟩⟩ instance : SemilatticeSup (TopHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl @[simp] theorem coe_sup : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl @[simp] theorem sup_apply (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl end SemilatticeSup instance [Lattice β] [OrderTop β] : Lattice (TopHom α β) := DFunLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl instance [DistribLattice β] [OrderTop β] : DistribLattice (TopHom α β) := DFunLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl end TopHom /-! ### Bot homomorphisms -/ namespace BotHom variable [Bot α] section Bot variable [Bot β] [Bot γ] [Bot δ] instance : FunLike (BotHom α β) α β where coe := BotHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : BotHomClass (BotHom α β) α β where map_bot := BotHom.map_bot' -- this must come after the coe_to_fun definition initialize_simps_projections BotHom (toFun → apply) @[ext] theorem ext {f g : BotHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `BotHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : BotHom α β) (f' : α → β) (h : f' = f) : BotHom α β where toFun := f' map_bot' := h.symm ▸ f.map_bot' @[simp] theorem coe_copy (f : BotHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : BotHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h instance : Inhabited (BotHom α β) := ⟨⟨fun _ => ⊥, rfl⟩⟩ variable (α) /-- `id` as a `BotHom`. -/ protected def id : BotHom α α := ⟨id, rfl⟩ @[simp, norm_cast] theorem coe_id : ⇑(BotHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : BotHom.id α a = a := rfl /-- Composition of `BotHom`s as a `BotHom`. -/ def comp (f : BotHom β γ) (g : BotHom α β) : BotHom α γ where toFun := f ∘ g map_bot' := by rw [comp_apply, map_bot, map_bot] @[simp] theorem coe_comp (f : BotHom β γ) (g : BotHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : BotHom β γ) (g : BotHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : BotHom γ δ) (g : BotHom β γ) (h : BotHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : BotHom α β) : f.comp (BotHom.id α) = f := BotHom.ext fun _ => rfl @[simp] theorem id_comp (f : BotHom α β) : (BotHom.id β).comp f = f := BotHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : BotHom β γ} {f : BotHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => BotHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (comp · f)⟩ @[simp] theorem cancel_left {g : BotHom β γ} {f₁ f₂ : BotHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => BotHom.ext fun a => hg <| by rw [← BotHom.comp_apply, h, BotHom.comp_apply], congr_arg _⟩ end Bot instance instLE [LE β] [Bot β] : LE (BotHom α β) where le f g := (f : α → β) ≤ g instance [Preorder β] [Bot β] : Preorder (BotHom α β) := Preorder.lift (DFunLike.coe : BotHom α β → α → β) instance [PartialOrder β] [Bot β] : PartialOrder (BotHom α β) := PartialOrder.lift _ DFunLike.coe_injective section OrderBot variable [LE β] [OrderBot β] instance : OrderBot (BotHom α β) where bot := ⟨⊥, rfl⟩ bot_le := fun _ => @bot_le (α → β) _ _ _ @[simp] theorem coe_bot : ⇑(⊥ : BotHom α β) = ⊥ := rfl @[simp] theorem bot_apply (a : α) : (⊥ : BotHom α β) a = ⊥ := rfl end OrderBot section SemilatticeInf variable [SemilatticeInf β] [OrderBot β] (f g : BotHom α β) instance : Min (BotHom α β) := ⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_bot, map_bot, inf_bot_eq]⟩⟩ instance : SemilatticeInf (BotHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl @[simp] theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl @[simp] theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl end SemilatticeInf section SemilatticeSup variable [SemilatticeSup β] [OrderBot β] (f g : BotHom α β) instance : Max (BotHom α β) := ⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_bot, map_bot, sup_bot_eq]⟩⟩ instance : SemilatticeSup (BotHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl @[simp] theorem coe_sup : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl @[simp] theorem sup_apply (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl end SemilatticeSup instance [Lattice β] [OrderBot β] : Lattice (BotHom α β) := DFunLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl instance [DistribLattice β] [OrderBot β] : DistribLattice (BotHom α β) := DFunLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl end BotHom /-! ### Bounded order homomorphisms -/ -- TODO: remove this configuration and use the default configuration. initialize_simps_projections BoundedOrderHom (+toOrderHom, -toFun) namespace BoundedOrderHom variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] [BoundedOrder α] [BoundedOrder β] [BoundedOrder γ] [BoundedOrder δ] /-- Reinterpret a `BoundedOrderHom` as a `TopHom`. -/ def toTopHom (f : BoundedOrderHom α β) : TopHom α β := { f with } /-- Reinterpret a `BoundedOrderHom` as a `BotHom`. -/ def toBotHom (f : BoundedOrderHom α β) : BotHom α β := { f with } instance : FunLike (BoundedOrderHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr instance : BoundedOrderHomClass (BoundedOrderHom α β) α β where map_rel f := @(f.monotone') map_top f := f.map_top' map_bot f := f.map_bot' @[ext] theorem ext {f g : BoundedOrderHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `BoundedOrderHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : BoundedOrderHom α β := { f.toOrderHom.copy f' h, f.toTopHom.copy f' h, f.toBotHom.copy f' h with } @[simp] theorem coe_copy (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `BoundedOrderHom`. -/ protected def id : BoundedOrderHom α α := { OrderHom.id, TopHom.id α, BotHom.id α with } instance : Inhabited (BoundedOrderHom α α) := ⟨BoundedOrderHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(BoundedOrderHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : BoundedOrderHom.id α a = a := rfl /-- Composition of `BoundedOrderHom`s as a `BoundedOrderHom`. -/ def comp (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : BoundedOrderHom α γ := { f.toOrderHom.comp g.toOrderHom, f.toTopHom.comp g.toTopHom, f.toBotHom.comp g.toBotHom with } @[simp] theorem coe_comp (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem coe_comp_orderHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : (f.comp g : OrderHom α γ) = (f : OrderHom β γ).comp g := rfl @[simp] theorem coe_comp_topHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : (f.comp g : TopHom α γ) = (f : TopHom β γ).comp g := rfl @[simp] theorem coe_comp_botHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : (f.comp g : BotHom α γ) = (f : BotHom β γ).comp g := rfl @[simp] theorem comp_assoc (f : BoundedOrderHom γ δ) (g : BoundedOrderHom β γ) (h : BoundedOrderHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : BoundedOrderHom α β) : f.comp (BoundedOrderHom.id α) = f := BoundedOrderHom.ext fun _ => rfl @[simp] theorem id_comp (f : BoundedOrderHom α β) : (BoundedOrderHom.id β).comp f = f := BoundedOrderHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : BoundedOrderHom β γ} {f : BoundedOrderHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => BoundedOrderHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun g => comp g f)⟩ @[simp] theorem cancel_left {g : BoundedOrderHom β γ} {f₁ f₂ : BoundedOrderHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => BoundedOrderHom.ext fun a => hg <| by rw [← BoundedOrderHom.comp_apply, h, BoundedOrderHom.comp_apply], congr_arg _⟩ end BoundedOrderHom /-! ### Dual homs -/ namespace TopHom variable [LE α] [OrderTop α] [LE β] [OrderTop β] [LE γ] [OrderTop γ] /-- Reinterpret a top homomorphism as a bot homomorphism between the dual lattices. -/ @[simps] protected def dual : TopHom α β ≃ BotHom αᵒᵈ βᵒᵈ where toFun f := ⟨f, f.map_top'⟩ invFun f := ⟨f, f.map_bot'⟩ @[simp] theorem dual_id : TopHom.dual (TopHom.id α) = BotHom.id _ := rfl @[simp] theorem dual_comp (g : TopHom β γ) (f : TopHom α β) : TopHom.dual (g.comp f) = g.dual.comp (TopHom.dual f) := rfl @[simp] theorem symm_dual_id : TopHom.dual.symm (BotHom.id _) = TopHom.id α := rfl @[simp] theorem symm_dual_comp (g : BotHom βᵒᵈ γᵒᵈ) (f : BotHom αᵒᵈ βᵒᵈ) : TopHom.dual.symm (g.comp f) = (TopHom.dual.symm g).comp (TopHom.dual.symm f) := rfl end TopHom namespace BotHom variable [LE α] [OrderBot α] [LE β] [OrderBot β] [LE γ] [OrderBot γ] /-- Reinterpret a bot homomorphism as a top homomorphism between the dual lattices. -/ @[simps] protected def dual : BotHom α β ≃ TopHom αᵒᵈ βᵒᵈ where toFun f := ⟨f, f.map_bot'⟩ invFun f := ⟨f, f.map_top'⟩ @[simp] theorem dual_id : BotHom.dual (BotHom.id α) = TopHom.id _ := rfl @[simp] theorem dual_comp (g : BotHom β γ) (f : BotHom α β) : BotHom.dual (g.comp f) = g.dual.comp (BotHom.dual f) := rfl @[simp] theorem symm_dual_id : BotHom.dual.symm (TopHom.id _) = BotHom.id α := rfl @[simp] theorem symm_dual_comp (g : TopHom βᵒᵈ γᵒᵈ) (f : TopHom αᵒᵈ βᵒᵈ) : BotHom.dual.symm (g.comp f) = (BotHom.dual.symm g).comp (BotHom.dual.symm f) := rfl end BotHom namespace BoundedOrderHom variable [Preorder α] [BoundedOrder α] [Preorder β] [BoundedOrder β] [Preorder γ] [BoundedOrder γ] /-- Reinterpret a bounded order homomorphism as a bounded order homomorphism between the dual orders. -/ @[simps] protected def dual : BoundedOrderHom α β ≃ BoundedOrderHom αᵒᵈ βᵒᵈ where toFun f := ⟨f.toOrderHom.dual, f.map_bot', f.map_top'⟩ invFun f := ⟨OrderHom.dual.symm f.toOrderHom, f.map_bot', f.map_top'⟩ @[simp] theorem dual_id : (BoundedOrderHom.id α).dual = BoundedOrderHom.id _ := rfl @[simp] theorem dual_comp (g : BoundedOrderHom β γ) (f : BoundedOrderHom α β) : (g.comp f).dual = g.dual.comp f.dual := rfl @[simp] theorem symm_dual_id : BoundedOrderHom.dual.symm (BoundedOrderHom.id _) = BoundedOrderHom.id α := rfl @[simp] theorem symm_dual_comp (g : BoundedOrderHom βᵒᵈ γᵒᵈ) (f : BoundedOrderHom αᵒᵈ βᵒᵈ) : BoundedOrderHom.dual.symm (g.comp f) = (BoundedOrderHom.dual.symm g).comp (BoundedOrderHom.dual.symm f) := rfl end BoundedOrderHom
.lake/packages/mathlib/Mathlib/Order/Hom/WithTopBot.lean
import Mathlib.Order.Hom.BoundedLattice import Mathlib.Order.WithBot /-! # Adjoining `⊤` and `⊥` to order maps and lattice homomorphisms This file defines ways to adjoin `⊤` or `⊥` or both to order maps (homomorphisms, embeddings and isomorphisms) and lattice homomorphisms, and properties about the results. Some definitions cause a possibly unbounded lattice homomorphism to become bounded, so they change the type of the homomorphism. -/ variable {α β γ : Type*} namespace WithTop open OrderDual /-- Taking the dual then adding `⊤` is the same as adding `⊥` then taking the dual. This is the order iso form of `WithTop.ofDual`, as proven by `coe_toDualBotEquiv`. -/ protected def toDualBotEquiv [LE α] : WithTop αᵒᵈ ≃o (WithBot α)ᵒᵈ := OrderIso.refl _ @[simp] theorem toDualBotEquiv_coe [LE α] (a : α) : WithTop.toDualBotEquiv ↑(toDual a) = toDual (a : WithBot α) := rfl @[simp] theorem toDualBotEquiv_symm_coe [LE α] (a : α) : WithTop.toDualBotEquiv.symm (toDual (a : WithBot α)) = ↑(toDual a) := rfl @[simp] theorem toDualBotEquiv_top [LE α] : WithTop.toDualBotEquiv (⊤ : WithTop αᵒᵈ) = ⊤ := rfl @[simp] theorem toDualBotEquiv_symm_top [LE α] : WithTop.toDualBotEquiv.symm (⊤ : (WithBot α)ᵒᵈ) = ⊤ := rfl theorem coe_toDualBotEquiv [LE α] : (WithTop.toDualBotEquiv : WithTop αᵒᵈ → (WithBot α)ᵒᵈ) = toDual ∘ WithTop.ofDual := funext fun _ => rfl /-- Embedding into `WithTop α`. -/ @[simps] def _root_.Function.Embedding.coeWithTop : α ↪ WithTop α where toFun := (↑) inj' := WithTop.coe_injective /-- The coercion `α → WithTop α` bundled as monotone map. -/ @[simps -fullyApplied] def coeOrderHom {α : Type*} [Preorder α] : α ↪o WithTop α where toFun := (↑) inj' := WithTop.coe_injective map_rel_iff' := WithTop.coe_le_coe /-- Any `OrderTop` is equivalent to `WithTop` of the subtype excluding `⊤`. See also `Equiv.optionSubtypeNe`. -/ def subtypeOrderIso [PartialOrder α] [OrderTop α] [DecidablePred (· = (⊤ : α))] : WithTop {a : α // a ≠ ⊤} ≃o α where toFun a := (a.map (↑)).untopD ⊤ invFun a := if h : a = ⊤ then ⊤ else .some ⟨a, h⟩ left_inv | .some ⟨a, h⟩ => by simp [h] | ⊤ => by simp right_inv a := by dsimp only; split_ifs <;> simp [*] map_rel_iff' {a b} := match a, b with | .some a, .some b => by simp | ⊤, .some ⟨b, h⟩ => by simp [h] | a, ⊤ => by simp @[simp] theorem subtypeOrderIso_apply_coe [PartialOrder α] [OrderTop α] [DecidablePred (· = (⊤ : α))] (a : {a : α // a ≠ ⊤}) : subtypeOrderIso (a : WithTop {a : α // a ≠ ⊤}) = a := rfl theorem subtypeOrderIso_symm_apply [PartialOrder α] [OrderTop α] [DecidablePred (· = (⊤ : α))] {a : α} (h : a ≠ ⊤) : (subtypeOrderIso).symm a = (⟨a, h⟩ : {a : α // a ≠ ⊤}) := by rw [OrderIso.symm_apply_eq] rfl end WithTop namespace WithBot open OrderDual /-- Taking the dual then adding `⊥` is the same as adding `⊤` then taking the dual. This is the order iso form of `WithBot.ofDual`, as proven by `coe_toDualTopEquiv`. -/ protected def toDualTopEquiv [LE α] : WithBot αᵒᵈ ≃o (WithTop α)ᵒᵈ := OrderIso.refl _ @[simp] theorem toDualTopEquiv_coe [LE α] (a : α) : WithBot.toDualTopEquiv ↑(toDual a) = toDual (a : WithTop α) := rfl @[simp] theorem toDualTopEquiv_symm_coe [LE α] (a : α) : WithBot.toDualTopEquiv.symm (toDual (a : WithTop α)) = ↑(toDual a) := rfl @[simp] theorem toDualTopEquiv_bot [LE α] : WithBot.toDualTopEquiv (⊥ : WithBot αᵒᵈ) = ⊥ := rfl @[simp] theorem toDualTopEquiv_symm_bot [LE α] : WithBot.toDualTopEquiv.symm (⊥ : (WithTop α)ᵒᵈ) = ⊥ := rfl theorem coe_toDualTopEquiv_eq [LE α] : (WithBot.toDualTopEquiv : WithBot αᵒᵈ → (WithTop α)ᵒᵈ) = toDual ∘ WithBot.ofDual := funext fun _ => rfl /-- Embedding into `WithBot α`. -/ @[simps] def _root_.Function.Embedding.coeWithBot : α ↪ WithBot α where toFun := (↑) inj' := WithBot.coe_injective /-- The coercion `α → WithBot α` bundled as monotone map. -/ @[simps -fullyApplied] def coeOrderHom {α : Type*} [Preorder α] : α ↪o WithBot α where toFun := (↑) inj' := WithBot.coe_injective map_rel_iff' := WithBot.coe_le_coe /-- Any `OrderBot` is equivalent to `WithBot` of the subtype excluding `⊥`. See also `Equiv.optionSubtypeNe`. -/ def subtypeOrderIso [PartialOrder α] [OrderBot α] [DecidablePred (· = (⊥ : α))] : WithBot {a : α // a ≠ ⊥} ≃o α := (WithTop.subtypeOrderIso (α := αᵒᵈ)).dual @[simp] theorem subtypeOrderIso_apply_coe [PartialOrder α] [OrderBot α] [DecidablePred (· = (⊥ : α))] (a : {a : α // a ≠ ⊥}) : subtypeOrderIso (a : WithTop {a : α // a ≠ ⊥}) = a := rfl theorem subtypeOrderIso_symm_apply [PartialOrder α] [OrderBot α] [DecidablePred (· = (⊥ : α))] {a : α} (h : a ≠ ⊥) : (subtypeOrderIso).symm a = (⟨a, h⟩ : {a : α // a ≠ ⊥}) := by rw [OrderIso.symm_apply_eq] rfl end WithBot namespace OrderHom variable [Preorder α] [Preorder β] /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithBot α →o WithBot β`. -/ @[simps -fullyApplied] protected def withBotMap (f : α →o β) : WithBot α →o WithBot β := ⟨WithBot.map f, f.mono.withBot_map⟩ /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithTop α →o WithTop β`. -/ @[simps -fullyApplied] protected def withTopMap (f : α →o β) : WithTop α →o WithTop β := ⟨WithTop.map f, f.mono.withTop_map⟩ end OrderHom namespace OrderEmbedding variable [Preorder α] [Preorder β] /-- A version of `WithBot.map` for order embeddings. -/ @[simps -fullyApplied] protected def withBotMap (f : α ↪o β) : WithBot α ↪o WithBot β where toFun := WithBot.map f inj' := WithBot.map_injective f.injective map_rel_iff' := WithBot.map_le_iff f f.map_rel_iff /-- A version of `WithTop.map` for order embeddings. -/ @[simps -fullyApplied] protected def withTopMap (f : α ↪o β) : WithTop α ↪o WithTop β := { f.dual.withBotMap.dual with toFun := WithTop.map f } @[deprecated (since := "2025-08-21")] protected alias withBotCoe := WithBot.coeOrderHom @[deprecated (since := "2025-08-21")] alias withBotCoe_apply := WithBot.coeOrderHom_apply @[deprecated (since := "2025-08-21")] protected alias withTopCoe := WithTop.coeOrderHom @[deprecated (since := "2025-08-21")] alias withTopCoe_apply := WithTop.coeOrderHom_apply end OrderEmbedding namespace OrderIso variable [PartialOrder α] [PartialOrder β] [PartialOrder γ] /-- A version of `Equiv.optionCongr` for `WithTop`. -/ @[simps -fullyApplied] def withTopCongr (e : α ≃o β) : WithTop α ≃o WithTop β where toFun := WithTop.map e __ := e.toOrderEmbedding.withTopMap __ := e.toEquiv.withTopCongr @[simp] theorem withTopCongr_refl : (OrderIso.refl α).withTopCongr = OrderIso.refl _ := RelIso.toEquiv_injective Equiv.withTopCongr_refl @[simp] theorem withTopCongr_symm (e : α ≃o β) : e.symm.withTopCongr = e.withTopCongr.symm := RelIso.toEquiv_injective e.toEquiv.withTopCongr_symm @[simp] theorem withTopCongr_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).withTopCongr = e₁.withTopCongr.trans e₂.withTopCongr := RelIso.toEquiv_injective <| e₁.toEquiv.withTopCongr_trans e₂.toEquiv /-- A version of `Equiv.optionCongr` for `WithBot`. -/ @[simps -fullyApplied] def withBotCongr (e : α ≃o β) : WithBot α ≃o WithBot β where toFun := WithBot.map e __ := e.toOrderEmbedding.withBotMap __ := e.toEquiv.withBotCongr @[simp] theorem withBotCongr_refl : (OrderIso.refl α).withBotCongr = OrderIso.refl _ := RelIso.toEquiv_injective Equiv.withBotCongr_refl @[simp] theorem withBotCongr_symm (e : α ≃o β) : e.symm.withBotCongr = e.withBotCongr.symm := RelIso.toEquiv_injective e.toEquiv.withBotCongr_symm @[simp] theorem withBotCongr_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).withBotCongr = e₁.withBotCongr.trans e₂.withBotCongr := RelIso.toEquiv_injective <| e₁.toEquiv.withBotCongr_trans e₂.toEquiv end OrderIso namespace SupHom variable [SemilatticeSup α] [SemilatticeSup β] [SemilatticeSup γ] /-- Adjoins a `⊤` to the domain and codomain of a `SupHom`. -/ @[simps] protected def withTop (f : SupHom α β) : SupHom (WithTop α) (WithTop β) where toFun := WithTop.map f map_sup' a b := match a, b with | ⊤, ⊤ => rfl | ⊤, (b : α) => rfl | (a : α), ⊤ => rfl | (a : α), (b : α) => congr_arg _ (f.map_sup' _ _) @[simp] theorem withTop_id : (SupHom.id α).withTop = SupHom.id _ := DFunLike.coe_injective WithTop.map_id @[simp] theorem withTop_comp (f : SupHom β γ) (g : SupHom α β) : (f.comp g).withTop = f.withTop.comp g.withTop := DFunLike.coe_injective <| Eq.symm <| WithTop.map_comp_map _ _ /-- Adjoins a `⊥` to the domain and codomain of a `SupHom`. -/ @[simps] protected def withBot (f : SupHom α β) : SupBotHom (WithBot α) (WithBot β) where toFun := WithBot.map f map_sup' a b := match a, b with | ⊥, ⊥ => rfl | ⊥, (b : α) => rfl | (a : α), ⊥ => rfl | (a : α), (b : α) => congr_arg _ (f.map_sup' _ _) map_bot' := rfl @[simp] theorem withBot_id : (SupHom.id α).withBot = SupBotHom.id _ := DFunLike.coe_injective WithBot.map_id @[simp] theorem withBot_comp (f : SupHom β γ) (g : SupHom α β) : (f.comp g).withBot = f.withBot.comp g.withBot := DFunLike.coe_injective <| Eq.symm <| WithBot.map_comp_map _ _ /-- Adjoins a `⊤` to the codomain of a `SupHom`. -/ @[simps] def withTop' [OrderTop β] (f : SupHom α β) : SupHom (WithTop α) β where toFun a := a.elim ⊤ f map_sup' a b := match a, b with | ⊤, ⊤ => (top_sup_eq _).symm | ⊤, (b : α) => (top_sup_eq _).symm | (a : α), ⊤ => (sup_top_eq _).symm | (a : α), (b : α) => f.map_sup' _ _ /-- Adjoins a `⊥` to the domain of a `SupHom`. -/ @[simps] def withBot' [OrderBot β] (f : SupHom α β) : SupBotHom (WithBot α) β where toFun a := a.elim ⊥ f map_sup' a b := match a, b with | ⊥, ⊥ => (bot_sup_eq _).symm | ⊥, (b : α) => (bot_sup_eq _).symm | (a : α), ⊥ => (sup_bot_eq _).symm | (a : α), (b : α) => f.map_sup' _ _ map_bot' := rfl end SupHom namespace InfHom variable [SemilatticeInf α] [SemilatticeInf β] [SemilatticeInf γ] /-- Adjoins a `⊤` to the domain and codomain of an `InfHom`. -/ @[simps] protected def withTop (f : InfHom α β) : InfTopHom (WithTop α) (WithTop β) where toFun := WithTop.map f map_inf' a b := match a, b with | ⊤, ⊤ => rfl | ⊤, (b : α) => rfl | (a : α), ⊤ => rfl | (a : α), (b : α) => congr_arg _ (f.map_inf' _ _) map_top' := rfl @[simp] theorem withTop_id : (InfHom.id α).withTop = InfTopHom.id _ := DFunLike.coe_injective WithTop.map_id @[simp] theorem withTop_comp (f : InfHom β γ) (g : InfHom α β) : (f.comp g).withTop = f.withTop.comp g.withTop := DFunLike.coe_injective <| Eq.symm <| WithTop.map_comp_map _ _ /-- Adjoins a `⊥` to the domain and codomain of an `InfHom`. -/ @[simps] protected def withBot (f : InfHom α β) : InfHom (WithBot α) (WithBot β) where toFun := WithBot.map f map_inf' a b := match a, b with | ⊥, ⊥ => rfl | ⊥, (b : α) => rfl | (a : α), ⊥ => rfl | (a : α), (b : α) => congr_arg _ (f.map_inf' _ _) @[simp] theorem withBot_id : (InfHom.id α).withBot = InfHom.id _ := DFunLike.coe_injective WithBot.map_id @[simp] theorem withBot_comp (f : InfHom β γ) (g : InfHom α β) : (f.comp g).withBot = f.withBot.comp g.withBot := DFunLike.coe_injective <| Eq.symm <| WithBot.map_comp_map _ _ /-- Adjoins a `⊤` to the codomain of an `InfHom`. -/ @[simps] def withTop' [OrderTop β] (f : InfHom α β) : InfTopHom (WithTop α) β where toFun a := a.elim ⊤ f map_inf' a b := match a, b with | ⊤, ⊤ => (top_inf_eq _).symm | ⊤, (b : α) => (top_inf_eq _).symm | (a : α), ⊤ => (inf_top_eq _).symm | (a : α), (b : α) => f.map_inf' _ _ map_top' := rfl /-- Adjoins a `⊥` to the codomain of an `InfHom`. -/ @[simps] def withBot' [OrderBot β] (f : InfHom α β) : InfHom (WithBot α) β where toFun a := a.elim ⊥ f map_inf' a b := match a, b with | ⊥, ⊥ => (bot_inf_eq _).symm | ⊥, (b : α) => (bot_inf_eq _).symm | (a : α), ⊥ => (inf_bot_eq _).symm | (a : α), (b : α) => f.map_inf' _ _ end InfHom namespace LatticeHom variable [Lattice α] [Lattice β] [Lattice γ] /-- Adjoins a `⊤` to the domain and codomain of a `LatticeHom`. -/ @[simps] protected def withTop (f : LatticeHom α β) : LatticeHom (WithTop α) (WithTop β) := { f.toInfHom.withTop with toSupHom := f.toSupHom.withTop } -- Porting note: `simps` doesn't generate those @[simp, norm_cast] lemma coe_withTop (f : LatticeHom α β) : ⇑f.withTop = WithTop.map f := rfl lemma withTop_apply (f : LatticeHom α β) (a : WithTop α) : f.withTop a = a.map f := rfl @[simp] theorem withTop_id : (LatticeHom.id α).withTop = LatticeHom.id _ := DFunLike.coe_injective WithTop.map_id @[simp] theorem withTop_comp (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g).withTop = f.withTop.comp g.withTop := DFunLike.coe_injective <| Eq.symm <| WithTop.map_comp_map _ _ /-- Adjoins a `⊥` to the domain and codomain of a `LatticeHom`. -/ @[simps] protected def withBot (f : LatticeHom α β) : LatticeHom (WithBot α) (WithBot β) := { f.toInfHom.withBot with toSupHom := f.toSupHom.withBot } -- Porting note: `simps` doesn't generate those @[simp, norm_cast] lemma coe_withBot (f : LatticeHom α β) : ⇑f.withBot = WithBot.map f := rfl lemma withBot_apply (f : LatticeHom α β) (a : WithBot α) : f.withBot a = a.map f := rfl @[simp] theorem withBot_id : (LatticeHom.id α).withBot = LatticeHom.id _ := DFunLike.coe_injective WithBot.map_id @[simp] theorem withBot_comp (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g).withBot = f.withBot.comp g.withBot := DFunLike.coe_injective <| Eq.symm <| WithBot.map_comp_map _ _ /-- Adjoins a `⊤` and `⊥` to the domain and codomain of a `LatticeHom`. -/ @[simps] def withTopWithBot (f : LatticeHom α β) : BoundedLatticeHom (WithTop <| WithBot α) (WithTop <| WithBot β) := ⟨f.withBot.withTop, rfl, rfl⟩ -- Porting note: `simps` doesn't generate those @[simp, norm_cast] lemma coe_withTopWithBot (f : LatticeHom α β) : ⇑f.withTopWithBot = WithTop.map (WithBot.map f) := rfl lemma withTopWithBot_apply (f : LatticeHom α β) (a : WithTop <| WithBot α) : f.withTopWithBot a = a.map (WithBot.map f) := rfl @[simp] theorem withTopWithBot_id : (LatticeHom.id α).withTopWithBot = BoundedLatticeHom.id _ := DFunLike.coe_injective <| by simp [WithTop.map_id, WithBot.map_id] @[simp] theorem withTopWithBot_comp (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g).withTopWithBot = f.withTopWithBot.comp g.withTopWithBot := by ext; simp /-- Adjoins a `⊥` to the codomain of a `LatticeHom`. -/ @[simps] def withTop' [OrderTop β] (f : LatticeHom α β) : LatticeHom (WithTop α) β := { f.toSupHom.withTop', f.toInfHom.withTop' with } /-- Adjoins a `⊥` to the domain and codomain of a `LatticeHom`. -/ @[simps] def withBot' [OrderBot β] (f : LatticeHom α β) : LatticeHom (WithBot α) β := { f.toSupHom.withBot', f.toInfHom.withBot' with } /-- Adjoins a `⊤` and `⊥` to the codomain of a `LatticeHom`. -/ @[simps] def withTopWithBot' [BoundedOrder β] (f : LatticeHom α β) : BoundedLatticeHom (WithTop <| WithBot α) β where toLatticeHom := f.withBot'.withTop' map_top' := rfl map_bot' := rfl end LatticeHom
.lake/packages/mathlib/Mathlib/Order/Hom/CompleteLattice.lean
import Mathlib.Data.Set.Lattice.Image import Mathlib.Order.Hom.BoundedLattice /-! # Complete lattice homomorphisms This file defines frame homomorphisms and complete lattice homomorphisms. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `sSupHom`: Maps which preserve `⨆`. * `sInfHom`: Maps which preserve `⨅`. * `FrameHom`: Frame homomorphisms. Maps which preserve `⨆`, `⊓` and `⊤`. * `CompleteLatticeHom`: Complete lattice homomorphisms. Maps which preserve `⨆` and `⨅`. ## Typeclasses * `sSupHomClass` * `sInfHomClass` * `FrameHomClass` * `CompleteLatticeHomClass` ## Concrete homs * `CompleteLatticeHom.setPreimage`: `Set.preimage` as a complete lattice homomorphism. ## TODO Frame homs are Heyting homs. -/ assert_not_exists Monoid open Function OrderDual Set variable {F α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*} /-- The type of `⨆`-preserving functions from `α` to `β`. -/ structure sSupHom (α β : Type*) [SupSet α] [SupSet β] where /-- The underlying function of a sSupHom. -/ toFun : α → β /-- The proposition that a `sSupHom` commutes with arbitrary suprema/joins. -/ map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s) /-- The type of `⨅`-preserving functions from `α` to `β`. -/ structure sInfHom (α β : Type*) [InfSet α] [InfSet β] where /-- The underlying function of an `sInfHom`. -/ toFun : α → β /-- The proposition that a `sInfHom` commutes with arbitrary infima/meets -/ map_sInf' (s : Set α) : toFun (sInf s) = sInf (toFun '' s) /-- The type of frame homomorphisms from `α` to `β`. They preserve finite meets and arbitrary joins. -/ structure FrameHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends InfTopHom α β where /-- The proposition that frame homomorphisms commute with arbitrary suprema/joins. -/ map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s) /-- The type of complete lattice homomorphisms from `α` to `β`. -/ structure CompleteLatticeHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends sInfHom α β where /-- The proposition that complete lattice homomorphism commutes with arbitrary suprema/joins. -/ map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s) section /-- `sSupHomClass F α β` states that `F` is a type of `⨆`-preserving morphisms. You should extend this class when you extend `sSupHom`. -/ class sSupHomClass (F α β : Type*) [SupSet α] [SupSet β] [FunLike F α β] : Prop where /-- The proposition that members of `sSupHomClass`s commute with arbitrary suprema/joins. -/ map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s) /-- `sInfHomClass F α β` states that `F` is a type of `⨅`-preserving morphisms. You should extend this class when you extend `sInfHom`. -/ class sInfHomClass (F α β : Type*) [InfSet α] [InfSet β] [FunLike F α β] : Prop where /-- The proposition that members of `sInfHomClass`s commute with arbitrary infima/meets. -/ map_sInf (f : F) (s : Set α) : f (sInf s) = sInf (f '' s) /-- `FrameHomClass F α β` states that `F` is a type of frame morphisms. They preserve `⊓` and `⨆`. You should extend this class when you extend `FrameHom`. -/ class FrameHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β] [FunLike F α β] : Prop extends InfTopHomClass F α β where /-- The proposition that members of `FrameHomClass` commute with arbitrary suprema/joins. -/ map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s) /-- `CompleteLatticeHomClass F α β` states that `F` is a type of complete lattice morphisms. You should extend this class when you extend `CompleteLatticeHom`. -/ class CompleteLatticeHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β] [FunLike F α β] : Prop extends sInfHomClass F α β where /-- The proposition that members of `CompleteLatticeHomClass` commute with arbitrary suprema/joins. -/ map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s) end export sSupHomClass (map_sSup) export sInfHomClass (map_sInf) attribute [simp] map_sSup map_sInf section Hom variable [FunLike F α β] @[simp] theorem map_iSup [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ι → α) : f (⨆ i, g i) = ⨆ i, f (g i) := by simp [iSup, ← Set.range_comp, Function.comp_def] theorem map_iSup₂ [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ∀ i, κ i → α) : f (⨆ (i) (j), g i j) = ⨆ (i) (j), f (g i j) := by simp_rw [map_iSup] @[simp] theorem map_iInf [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ι → α) : f (⨅ i, g i) = ⨅ i, f (g i) := by simp [iInf, ← Set.range_comp, Function.comp_def] theorem map_iInf₂ [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ∀ i, κ i → α) : f (⨅ (i) (j), g i j) = ⨅ (i) (j), f (g i j) := by simp_rw [map_iInf] -- See note [lower instance priority] instance (priority := 100) sSupHomClass.toSupBotHomClass [CompleteLattice α] [CompleteLattice β] [sSupHomClass F α β] : SupBotHomClass F α β := { ‹sSupHomClass F α β› with map_sup := fun f a b => by rw [← sSup_pair, map_sSup] simp only [Set.image_pair, sSup_insert, sSup_singleton] map_bot := fun f => by rw [← sSup_empty, map_sSup, Set.image_empty, sSup_empty] } -- See note [lower instance priority] instance (priority := 100) sInfHomClass.toInfTopHomClass [CompleteLattice α] [CompleteLattice β] [sInfHomClass F α β] : InfTopHomClass F α β := { ‹sInfHomClass F α β› with map_inf := fun f a b => by rw [← sInf_pair, map_sInf, Set.image_pair] simp only [sInf_insert, sInf_singleton] map_top := fun f => by rw [← sInf_empty, map_sInf, Set.image_empty, sInf_empty] } -- See note [lower instance priority] instance (priority := 100) FrameHomClass.tosSupHomClass [CompleteLattice α] [CompleteLattice β] [FrameHomClass F α β] : sSupHomClass F α β := { ‹FrameHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) FrameHomClass.toBoundedLatticeHomClass [CompleteLattice α] [CompleteLattice β] [FrameHomClass F α β] : BoundedLatticeHomClass F α β := { ‹FrameHomClass F α β›, sSupHomClass.toSupBotHomClass with } -- See note [lower instance priority] instance (priority := 100) CompleteLatticeHomClass.toFrameHomClass [CompleteLattice α] [CompleteLattice β] [CompleteLatticeHomClass F α β] : FrameHomClass F α β := { ‹CompleteLatticeHomClass F α β›, sInfHomClass.toInfTopHomClass with } -- See note [lower instance priority] instance (priority := 100) CompleteLatticeHomClass.toBoundedLatticeHomClass [CompleteLattice α] [CompleteLattice β] [CompleteLatticeHomClass F α β] : BoundedLatticeHomClass F α β := { sSupHomClass.toSupBotHomClass, sInfHomClass.toInfTopHomClass with } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.tosSupHomClass [CompleteLattice α] [CompleteLattice β] [OrderIsoClass F α β] : sSupHomClass F α β := { show OrderHomClass F α β from inferInstance with map_sSup := fun f s => eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sSup_le_iff, Set.forall_mem_image] } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.tosInfHomClass [CompleteLattice α] [CompleteLattice β] [OrderIsoClass F α β] : sInfHomClass F α β := { show OrderHomClass F α β from inferInstance with map_sInf := fun f s => eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_sInf_iff, Set.forall_mem_image] } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toCompleteLatticeHomClass [CompleteLattice α] [CompleteLattice β] [OrderIsoClass F α β] : CompleteLatticeHomClass F α β := { OrderIsoClass.tosSupHomClass, OrderIsoClass.tosInfHomClass with } end Equiv variable [FunLike F α β] /-- Reinterpret an order isomorphism as a morphism of complete lattices. -/ @[simps] def OrderIso.toCompleteLatticeHom [CompleteLattice α] [CompleteLattice β] (f : OrderIso α β) : CompleteLatticeHom α β where toFun := f map_sInf' := sInfHomClass.map_sInf f map_sSup' := sSupHomClass.map_sSup f instance [SupSet α] [SupSet β] [sSupHomClass F α β] : CoeTC F (sSupHom α β) := ⟨fun f => ⟨f, map_sSup f⟩⟩ instance [InfSet α] [InfSet β] [sInfHomClass F α β] : CoeTC F (sInfHom α β) := ⟨fun f => ⟨f, map_sInf f⟩⟩ instance [CompleteLattice α] [CompleteLattice β] [FrameHomClass F α β] : CoeTC F (FrameHom α β) := ⟨fun f => ⟨f, map_sSup f⟩⟩ instance [CompleteLattice α] [CompleteLattice β] [CompleteLatticeHomClass F α β] : CoeTC F (CompleteLatticeHom α β) := ⟨fun f => ⟨f, map_sSup f⟩⟩ /-! ### Supremum homomorphisms -/ namespace sSupHom variable [SupSet α] section SupSet variable [SupSet β] [SupSet γ] [SupSet δ] instance : FunLike (sSupHom α β) α β where coe := sSupHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : sSupHomClass (sSupHom α β) α β where map_sSup := sSupHom.map_sSup' @[simp] lemma toFun_eq_coe (f : sSupHom α β) : f.toFun = f := rfl @[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : sSupHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `sSupHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : sSupHom α β) (f' : α → β) (h : f' = f) : sSupHom α β where toFun := f' map_sSup' := h.symm ▸ f.map_sSup' @[simp] theorem coe_copy (f : sSupHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : sSupHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `sSupHom`. -/ protected def id : sSupHom α α := ⟨id, fun s => by rw [id, Set.image_id]⟩ instance : Inhabited (sSupHom α α) := ⟨sSupHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(sSupHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : sSupHom.id α a = a := rfl /-- Composition of `sSupHom`s as a `sSupHom`. -/ def comp (f : sSupHom β γ) (g : sSupHom α β) : sSupHom α γ where toFun := f ∘ g map_sSup' s := by rw [comp_apply, map_sSup, map_sSup, Set.image_image]; simp only [Function.comp] @[simp] theorem coe_comp (f : sSupHom β γ) (g : sSupHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : sSupHom β γ) (g : sSupHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : sSupHom γ δ) (g : sSupHom β γ) (h : sSupHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : sSupHom α β) : f.comp (sSupHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : sSupHom α β) : (sSupHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : sSupHom β γ} {f : sSupHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left {g : sSupHom β γ} {f₁ f₂ : sSupHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end SupSet variable {_ : CompleteLattice β} instance : PartialOrder (sSupHom α β) := PartialOrder.lift _ DFunLike.coe_injective instance : Bot (sSupHom α β) := ⟨⟨fun _ => ⊥, fun s => by obtain rfl | hs := s.eq_empty_or_nonempty · rw [Set.image_empty, sSup_empty] · rw [hs.image_const, sSup_singleton]⟩⟩ instance : OrderBot (sSupHom α β) where bot_le := fun _ _ ↦ OrderBot.bot_le _ @[simp] theorem coe_bot : ⇑(⊥ : sSupHom α β) = ⊥ := rfl @[simp] theorem bot_apply (a : α) : (⊥ : sSupHom α β) a = ⊥ := rfl end sSupHom /-! ### Infimum homomorphisms -/ namespace sInfHom variable [InfSet α] section InfSet variable [InfSet β] [InfSet γ] [InfSet δ] instance : FunLike (sInfHom α β) α β where coe := sInfHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : sInfHomClass (sInfHom α β) α β where map_sInf := sInfHom.map_sInf' @[simp] lemma toFun_eq_coe (f : sInfHom α β) : f.toFun = f := rfl @[simp] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : sInfHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `sInfHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : sInfHom α β) (f' : α → β) (h : f' = f) : sInfHom α β where toFun := f' map_sInf' := h.symm ▸ f.map_sInf' @[simp] theorem coe_copy (f : sInfHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : sInfHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as an `sInfHom`. -/ protected def id : sInfHom α α := ⟨id, fun s => by rw [id, Set.image_id]⟩ instance : Inhabited (sInfHom α α) := ⟨sInfHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(sInfHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : sInfHom.id α a = a := rfl /-- Composition of `sInfHom`s as a `sInfHom`. -/ def comp (f : sInfHom β γ) (g : sInfHom α β) : sInfHom α γ where toFun := f ∘ g map_sInf' s := by rw [comp_apply, map_sInf, map_sInf, Set.image_image]; simp only [Function.comp] @[simp] theorem coe_comp (f : sInfHom β γ) (g : sInfHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : sInfHom β γ) (g : sInfHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : sInfHom γ δ) (g : sInfHom β γ) (h : sInfHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : sInfHom α β) : f.comp (sInfHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : sInfHom α β) : (sInfHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : sInfHom β γ} {f : sInfHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left {g : sInfHom β γ} {f₁ f₂ : sInfHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end InfSet variable [CompleteLattice β] instance : PartialOrder (sInfHom α β) := PartialOrder.lift _ DFunLike.coe_injective instance : Top (sInfHom α β) := ⟨⟨fun _ => ⊤, fun s => by obtain rfl | hs := s.eq_empty_or_nonempty · rw [Set.image_empty, sInf_empty] · rw [hs.image_const, sInf_singleton]⟩⟩ instance : OrderTop (sInfHom α β) where le_top := fun _ _ => OrderTop.le_top _ @[simp] theorem coe_top : ⇑(⊤ : sInfHom α β) = ⊤ := rfl @[simp] theorem top_apply (a : α) : (⊤ : sInfHom α β) a = ⊤ := rfl end sInfHom /-! ### Frame homomorphisms -/ namespace FrameHom variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] [CompleteLattice δ] instance : FunLike (FrameHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g congr instance : FrameHomClass (FrameHom α β) α β where map_sSup f := f.map_sSup' map_inf f := f.map_inf' map_top f := f.map_top' /-- Reinterpret a `FrameHom` as a `LatticeHom`. -/ def toLatticeHom (f : FrameHom α β) : LatticeHom α β := f lemma toFun_eq_coe (f : FrameHom α β) : f.toFun = f := rfl @[simp] lemma coe_toInfTopHom (f : FrameHom α β) : ⇑f.toInfTopHom = f := rfl @[simp] lemma coe_toLatticeHom (f : FrameHom α β) : ⇑f.toLatticeHom = f := rfl @[simp] lemma coe_mk (f : InfTopHom α β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : FrameHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `FrameHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : FrameHom α β) (f' : α → β) (h : f' = f) : FrameHom α β := { (f : sSupHom α β).copy f' h with toInfTopHom := f.toInfTopHom.copy f' h } @[simp] theorem coe_copy (f : FrameHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : FrameHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `FrameHom`. -/ protected def id : FrameHom α α := { sSupHom.id α with toInfTopHom := InfTopHom.id α } instance : Inhabited (FrameHom α α) := ⟨FrameHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(FrameHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : FrameHom.id α a = a := rfl /-- Composition of `FrameHom`s as a `FrameHom`. -/ def comp (f : FrameHom β γ) (g : FrameHom α β) : FrameHom α γ := { (f : sSupHom β γ).comp (g : sSupHom α β) with toInfTopHom := f.toInfTopHom.comp g.toInfTopHom } @[simp] theorem coe_comp (f : FrameHom β γ) (g : FrameHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : FrameHom β γ) (g : FrameHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : FrameHom γ δ) (g : FrameHom β γ) (h : FrameHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : FrameHom α β) : f.comp (FrameHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : FrameHom α β) : (FrameHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : FrameHom β γ} {f : FrameHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left {g : FrameHom β γ} {f₁ f₂ : FrameHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ instance : PartialOrder (FrameHom α β) := PartialOrder.lift _ DFunLike.coe_injective end FrameHom /-! ### Complete lattice homomorphisms -/ namespace CompleteLatticeHom variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] [CompleteLattice δ] instance : FunLike (CompleteLatticeHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr instance : CompleteLatticeHomClass (CompleteLatticeHom α β) α β where map_sSup f := f.map_sSup' map_sInf f := f.map_sInf' /-- Reinterpret a `CompleteLatticeHom` as a `sSupHom`. -/ def tosSupHom (f : CompleteLatticeHom α β) : sSupHom α β := f /-- Reinterpret a `CompleteLatticeHom` as a `BoundedLatticeHom`. -/ def toBoundedLatticeHom (f : CompleteLatticeHom α β) : BoundedLatticeHom α β := f lemma toFun_eq_coe (f : CompleteLatticeHom α β) : f.toFun = f := rfl @[simp] lemma coe_tosInfHom (f : CompleteLatticeHom α β) : ⇑f.tosInfHom = f := rfl @[simp] lemma coe_tosSupHom (f : CompleteLatticeHom α β) : ⇑f.tosSupHom = f := rfl @[simp] lemma coe_toBoundedLatticeHom (f : CompleteLatticeHom α β) : ⇑f.toBoundedLatticeHom = f := rfl @[simp] lemma coe_mk (f : sInfHom α β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : CompleteLatticeHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `CompleteLatticeHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) : CompleteLatticeHom α β := { f.tosSupHom.copy f' h with tosInfHom := f.tosInfHom.copy f' h } @[simp] theorem coe_copy (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `CompleteLatticeHom`. -/ protected def id : CompleteLatticeHom α α := { sSupHom.id α, sInfHom.id α with toFun := id } instance : Inhabited (CompleteLatticeHom α α) := ⟨CompleteLatticeHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(CompleteLatticeHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : CompleteLatticeHom.id α a = a := rfl /-- Composition of `CompleteLatticeHom`s as a `CompleteLatticeHom`. -/ def comp (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) : CompleteLatticeHom α γ := { f.tosSupHom.comp g.tosSupHom with tosInfHom := f.tosInfHom.comp g.tosInfHom } @[simp] theorem coe_comp (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] theorem comp_apply (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : CompleteLatticeHom γ δ) (g : CompleteLatticeHom β γ) (h : CompleteLatticeHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : CompleteLatticeHom α β) : f.comp (CompleteLatticeHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : CompleteLatticeHom α β) : (CompleteLatticeHom.id β).comp f = f := ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : CompleteLatticeHom β γ} {f : CompleteLatticeHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩ @[simp] theorem cancel_left {g : CompleteLatticeHom β γ} {f₁ f₂ : CompleteLatticeHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ end CompleteLatticeHom /-! ### Dual homs -/ namespace sSupHom variable [SupSet α] [SupSet β] [SupSet γ] /-- Reinterpret a `⨆`-homomorphism as an `⨅`-homomorphism between the dual orders. -/ @[simps] protected def dual : sSupHom α β ≃ sInfHom αᵒᵈ βᵒᵈ where toFun f := ⟨toDual ∘ f ∘ ofDual, f.map_sSup'⟩ invFun f := ⟨ofDual ∘ f ∘ toDual, f.map_sInf'⟩ @[simp] theorem dual_id : sSupHom.dual (sSupHom.id α) = sInfHom.id _ := rfl @[simp] theorem dual_comp (g : sSupHom β γ) (f : sSupHom α β) : sSupHom.dual (g.comp f) = (sSupHom.dual g).comp (sSupHom.dual f) := rfl @[simp] theorem symm_dual_id : sSupHom.dual.symm (sInfHom.id _) = sSupHom.id α := rfl @[simp] theorem symm_dual_comp (g : sInfHom βᵒᵈ γᵒᵈ) (f : sInfHom αᵒᵈ βᵒᵈ) : sSupHom.dual.symm (g.comp f) = (sSupHom.dual.symm g).comp (sSupHom.dual.symm f) := rfl end sSupHom namespace sInfHom variable [InfSet α] [InfSet β] [InfSet γ] /-- Reinterpret an `⨅`-homomorphism as a `⨆`-homomorphism between the dual orders. -/ @[simps] protected def dual : sInfHom α β ≃ sSupHom αᵒᵈ βᵒᵈ where toFun f := { toFun := toDual ∘ f ∘ ofDual map_sSup' := fun _ => congr_arg toDual (map_sInf f _) } invFun f := { toFun := ofDual ∘ f ∘ toDual map_sInf' := fun _ => congr_arg ofDual (map_sSup f _) } @[simp] theorem dual_id : sInfHom.dual (sInfHom.id α) = sSupHom.id _ := rfl @[simp] theorem dual_comp (g : sInfHom β γ) (f : sInfHom α β) : sInfHom.dual (g.comp f) = (sInfHom.dual g).comp (sInfHom.dual f) := rfl @[simp] theorem symm_dual_id : sInfHom.dual.symm (sSupHom.id _) = sInfHom.id α := rfl @[simp] theorem symm_dual_comp (g : sSupHom βᵒᵈ γᵒᵈ) (f : sSupHom αᵒᵈ βᵒᵈ) : sInfHom.dual.symm (g.comp f) = (sInfHom.dual.symm g).comp (sInfHom.dual.symm f) := rfl end sInfHom namespace CompleteLatticeHom variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] /-- Reinterpret a complete lattice homomorphism as a complete lattice homomorphism between the dual lattices. -/ @[simps!] protected def dual : CompleteLatticeHom α β ≃ CompleteLatticeHom αᵒᵈ βᵒᵈ where toFun f := ⟨sSupHom.dual f.tosSupHom, fun s ↦ f.map_sInf' s⟩ invFun f := ⟨sSupHom.dual f.tosSupHom, fun s ↦ f.map_sInf' s⟩ @[simp] theorem dual_id : CompleteLatticeHom.dual (CompleteLatticeHom.id α) = CompleteLatticeHom.id _ := rfl @[simp] theorem dual_comp (g : CompleteLatticeHom β γ) (f : CompleteLatticeHom α β) : CompleteLatticeHom.dual (g.comp f) = (CompleteLatticeHom.dual g).comp (CompleteLatticeHom.dual f) := rfl @[simp] theorem symm_dual_id : CompleteLatticeHom.dual.symm (CompleteLatticeHom.id _) = CompleteLatticeHom.id α := rfl @[simp] theorem symm_dual_comp (g : CompleteLatticeHom βᵒᵈ γᵒᵈ) (f : CompleteLatticeHom αᵒᵈ βᵒᵈ) : CompleteLatticeHom.dual.symm (g.comp f) = (CompleteLatticeHom.dual.symm g).comp (CompleteLatticeHom.dual.symm f) := rfl end CompleteLatticeHom /-! ### Concrete homs -/ namespace CompleteLatticeHom /-- `Set.preimage` as a complete lattice homomorphism. See also `sSupHom.setImage`. -/ def setPreimage (f : α → β) : CompleteLatticeHom (Set β) (Set α) where toFun := preimage f map_sSup' s := preimage_sUnion.trans <| by simp only [Set.sSup_eq_sUnion, Set.sUnion_image] map_sInf' s := preimage_sInter.trans <| by simp only [Set.sInf_eq_sInter, Set.sInter_image] @[simp] theorem coe_setPreimage (f : α → β) : ⇑(setPreimage f) = preimage f := rfl @[simp] theorem setPreimage_apply (f : α → β) (s : Set β) : setPreimage f s = s.preimage f := rfl @[simp] theorem setPreimage_id : setPreimage (id : α → α) = CompleteLatticeHom.id _ := rfl -- This lemma can't be `simp` because `g ∘ f` matches anything (`id ∘ f = f` syntactically) theorem setPreimage_comp (g : β → γ) (f : α → β) : setPreimage (g ∘ f) = (setPreimage f).comp (setPreimage g) := rfl end CompleteLatticeHom theorem Set.image_sSup {f : α → β} (s : Set (Set α)) : f '' sSup s = sSup (image f '' s) := Set.image_sUnion /-- Using `Set.image`, a function between types yields a `sSupHom` between their lattices of subsets. See also `CompleteLatticeHom.setPreimage`. -/ @[simps] def sSupHom.setImage (f : α → β) : sSupHom (Set α) (Set β) where toFun := image f map_sSup' := Set.image_sSup /-- An equivalence of types yields an order isomorphism between their lattices of subsets. -/ @[simps] def Equiv.toOrderIsoSet (e : α ≃ β) : Set α ≃o Set β where toFun s := e '' s invFun s := e.symm '' s left_inv s := by simp only [← image_comp, Equiv.symm_comp_self, id, image_id'] right_inv s := by simp only [← image_comp, Equiv.self_comp_symm, id, image_id'] map_rel_iff' := ⟨fun h => by simpa using @monotone_image _ _ e.symm _ _ h, fun h => monotone_image h⟩ variable [CompleteLattice α] (x : α × α) /-- The map `(a, b) ↦ a ⊔ b` as a `sSupHom`. -/ def supsSupHom : sSupHom (α × α) α where toFun x := x.1 ⊔ x.2 map_sSup' s := by simp_rw [Prod.fst_sSup, Prod.snd_sSup, sSup_image, iSup_sup_eq] /-- The map `(a, b) ↦ a ⊓ b` as an `sInfHom`. -/ def infsInfHom : sInfHom (α × α) α where toFun x := x.1 ⊓ x.2 map_sInf' s := by simp_rw [Prod.fst_sInf, Prod.snd_sInf, sInf_image, iInf_inf_eq] @[simp, norm_cast] theorem supsSupHom_apply : supsSupHom x = x.1 ⊔ x.2 := rfl @[simp, norm_cast] theorem infsInfHom_apply : infsInfHom x = x.1 ⊓ x.2 := rfl
.lake/packages/mathlib/Mathlib/Order/Hom/Lattice.lean
import Mathlib.Order.Hom.Basic /-! # Unbounded lattice homomorphisms This file defines unbounded lattice homomorphisms. _Bounded_ lattice homomorphisms are defined in `Mathlib/Order/Hom/BoundedLattice.lean`. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `SupHom`: Maps which preserve `⊔`. * `InfHom`: Maps which preserve `⊓`. * `LatticeHom`: Lattice homomorphisms. Maps which preserve `⊔` and `⊓`. ## Typeclasses * `SupHomClass` * `InfHomClass` * `LatticeHomClass` -/ open Function variable {F α β γ δ : Type*} /-- The type of `⊔`-preserving functions from `α` to `β`. -/ structure SupHom (α β : Type*) [Max α] [Max β] where /-- The underlying function of a `SupHom`. Do not use this function directly. Instead use the coercion coming from the `FunLike` instance. -/ toFun : α → β /-- A `SupHom` preserves suprema. Do not use this directly. Use `map_sup` instead. -/ map_sup' (a b : α) : toFun (a ⊔ b) = toFun a ⊔ toFun b /-- The type of `⊓`-preserving functions from `α` to `β`. -/ structure InfHom (α β : Type*) [Min α] [Min β] where /-- The underlying function of an `InfHom`. Do not use this function directly. Instead use the coercion coming from the `FunLike` instance. -/ toFun : α → β /-- An `InfHom` preserves infima. Do not use this directly. Use `map_inf` instead. -/ map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b /-- The type of lattice homomorphisms from `α` to `β`. -/ structure LatticeHom (α β : Type*) [Lattice α] [Lattice β] extends SupHom α β where /-- A `LatticeHom` preserves infima. Do not use this directly. Use `map_inf` instead. -/ map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b -- TODO: remove this configuration and use the default configuration. initialize_simps_projections LatticeHom (+toSupHom, -toFun) section /-- `SupHomClass F α β` states that `F` is a type of `⊔`-preserving morphisms. You should extend this class when you extend `SupHom`. -/ class SupHomClass (F α β : Type*) [Max α] [Max β] [FunLike F α β] : Prop where /-- A `SupHomClass` morphism preserves suprema. -/ map_sup (f : F) (a b : α) : f (a ⊔ b) = f a ⊔ f b /-- `InfHomClass F α β` states that `F` is a type of `⊓`-preserving morphisms. You should extend this class when you extend `InfHom`. -/ class InfHomClass (F α β : Type*) [Min α] [Min β] [FunLike F α β] : Prop where /-- An `InfHomClass` morphism preserves infima. -/ map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b /-- `LatticeHomClass F α β` states that `F` is a type of lattice morphisms. You should extend this class when you extend `LatticeHom`. -/ class LatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [FunLike F α β] : Prop extends SupHomClass F α β where /-- A `LatticeHomClass` morphism preserves infima. -/ map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b end export SupHomClass (map_sup) export InfHomClass (map_inf) attribute [simp] map_sup map_inf section Hom variable [FunLike F α β] -- See note [lower instance priority] instance (priority := 100) SupHomClass.toOrderHomClass [SemilatticeSup α] [SemilatticeSup β] [SupHomClass F α β] : OrderHomClass F α β := { ‹SupHomClass F α β› with map_rel := fun f a b h => by rw [← sup_eq_right, ← map_sup, sup_eq_right.2 h] } -- See note [lower instance priority] instance (priority := 100) InfHomClass.toOrderHomClass [SemilatticeInf α] [SemilatticeInf β] [InfHomClass F α β] : OrderHomClass F α β := { ‹InfHomClass F α β› with map_rel := fun f a b h => by rw [← inf_eq_left, ← map_inf, inf_eq_left.2 h] } -- See note [lower instance priority] instance (priority := 100) LatticeHomClass.toInfHomClass [Lattice α] [Lattice β] [LatticeHomClass F α β] : InfHomClass F α β := { ‹LatticeHomClass F α β› with } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toSupHomClass [SemilatticeSup α] [SemilatticeSup β] [OrderIsoClass F α β] : SupHomClass F α β := { show OrderHomClass F α β from inferInstance with map_sup := fun f a b => eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sup_le_iff] } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toInfHomClass [SemilatticeInf α] [SemilatticeInf β] [OrderIsoClass F α β] : InfHomClass F α β := { show OrderHomClass F α β from inferInstance with map_inf := fun f a b => eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_inf_iff] } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toLatticeHomClass [Lattice α] [Lattice β] [OrderIsoClass F α β] : LatticeHomClass F α β := { OrderIsoClass.toSupHomClass, OrderIsoClass.toInfHomClass with } end Equiv section OrderEmbedding variable [FunLike F α β] /-- We can regard an injective map preserving binary infima as an order embedding. -/ @[simps! apply] def orderEmbeddingOfInjective [SemilatticeInf α] [SemilatticeInf β] (f : F) [InfHomClass F α β] (hf : Injective f) : α ↪o β := OrderEmbedding.ofMapLEIff f (fun x y ↦ by refine ⟨fun h ↦ ?_, fun h ↦ OrderHomClass.mono f h⟩ rwa [← inf_eq_left, ← hf.eq_iff, map_inf, inf_eq_left]) end OrderEmbedding variable [FunLike F α β] instance [Max α] [Max β] [SupHomClass F α β] : CoeTC F (SupHom α β) := ⟨fun f => ⟨f, map_sup f⟩⟩ instance [Min α] [Min β] [InfHomClass F α β] : CoeTC F (InfHom α β) := ⟨fun f => ⟨f, map_inf f⟩⟩ instance [Lattice α] [Lattice β] [LatticeHomClass F α β] : CoeTC F (LatticeHom α β) := ⟨fun f => { toFun := f map_sup' := map_sup f map_inf' := map_inf f }⟩ /-! ### Supremum homomorphisms -/ namespace SupHom variable [Max α] section Sup variable [Max β] [Max γ] [Max δ] instance : FunLike (SupHom α β) α β where coe := SupHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : SupHomClass (SupHom α β) α β where map_sup := SupHom.map_sup' @[simp] lemma toFun_eq_coe (f : SupHom α β) : f.toFun = f := rfl @[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : SupHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `SupHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : SupHom α β) (f' : α → β) (h : f' = f) : SupHom α β where toFun := f' map_sup' := h.symm ▸ f.map_sup' @[simp] theorem coe_copy (f : SupHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : SupHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `SupHom`. -/ protected def id : SupHom α α := ⟨id, fun _ _ => rfl⟩ instance : Inhabited (SupHom α α) := ⟨SupHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(SupHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : SupHom.id α a = a := rfl /-- Composition of `SupHom`s as a `SupHom`. -/ def comp (f : SupHom β γ) (g : SupHom α β) : SupHom α γ where toFun := f ∘ g map_sup' a b := by rw [comp_apply, map_sup, map_sup]; rfl @[simp] theorem coe_comp (f : SupHom β γ) (g : SupHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : SupHom β γ) (g : SupHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : SupHom γ δ) (g : SupHom β γ) (h : SupHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : SupHom α β) : f.comp (SupHom.id α) = f := rfl @[simp] theorem id_comp (f : SupHom α β) : (SupHom.id β).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ : SupHom β γ} {f : SupHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => SupHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : SupHom β γ} {f₁ f₂ : SupHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => SupHom.ext fun a => hg <| by rw [← SupHom.comp_apply, h, SupHom.comp_apply], congr_arg _⟩ end Sup variable (α) [SemilatticeSup β] /-- The constant function as a `SupHom`. -/ def const (b : β) : SupHom α β := ⟨fun _ ↦ b, fun _ _ ↦ (sup_idem _).symm⟩ @[simp] theorem coe_const (b : β) : ⇑(const α b) = Function.const α b := rfl @[simp] theorem const_apply (b : β) (a : α) : const α b a = b := rfl variable {α} instance : Max (SupHom α β) := ⟨fun f g => ⟨f ⊔ g, fun a b => by rw [Pi.sup_apply, map_sup, map_sup] exact sup_sup_sup_comm _ _ _ _⟩⟩ instance : SemilatticeSup (SupHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl instance [Bot β] : Bot (SupHom α β) := ⟨SupHom.const α ⊥⟩ instance [Top β] : Top (SupHom α β) := ⟨SupHom.const α ⊤⟩ instance [OrderBot β] : OrderBot (SupHom α β) := OrderBot.lift ((↑) : _ → α → β) (fun _ _ => id) rfl instance [OrderTop β] : OrderTop (SupHom α β) := OrderTop.lift ((↑) : _ → α → β) (fun _ _ => id) rfl instance [BoundedOrder β] : BoundedOrder (SupHom α β) := BoundedOrder.lift ((↑) : _ → α → β) (fun _ _ => id) rfl rfl @[simp] theorem coe_sup (f g : SupHom α β) : DFunLike.coe (f ⊔ g) = f ⊔ g := rfl @[simp] theorem coe_bot [Bot β] : ⇑(⊥ : SupHom α β) = ⊥ := rfl @[simp] theorem coe_top [Top β] : ⇑(⊤ : SupHom α β) = ⊤ := rfl @[simp] theorem sup_apply (f g : SupHom α β) (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl @[simp] theorem bot_apply [Bot β] (a : α) : (⊥ : SupHom α β) a = ⊥ := rfl @[simp] theorem top_apply [Top β] (a : α) : (⊤ : SupHom α β) a = ⊤ := rfl @[simp] lemma mk_le_mk (toFun₁ toFun₂ : α → β) (map_sup₁ map_sup₂) : mk toFun₁ map_sup₁ ≤ mk toFun₂ map_sup₂ ↔ toFun₁ ≤ toFun₂ := .rfl @[gcongr] alias ⟨_, _root_.GCongr.SupHom.mk_le_mk⟩ := mk_le_mk /-- `Subtype.val` as a `SupHom`. -/ def subtypeVal {P : β → Prop} (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) : letI := Subtype.semilatticeSup Psup SupHom {x : β // P x} β := letI := Subtype.semilatticeSup Psup .mk Subtype.val (by simp) @[simp] lemma subtypeVal_apply {P : β → Prop} (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) (x : {x : β // P x}) : subtypeVal Psup x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Psup : ∀ ⦃x y : β⦄, P x → P y → P (x ⊔ y)) : ⇑(subtypeVal Psup) = Subtype.val := rfl end SupHom /-! ### Infimum homomorphisms -/ namespace InfHom variable [Min α] section Inf variable [Min β] [Min γ] [Min δ] instance : FunLike (InfHom α β) α β where coe := InfHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : InfHomClass (InfHom α β) α β where map_inf := InfHom.map_inf' @[simp] lemma toFun_eq_coe (f : InfHom α β) : f.toFun = (f : α → β) := rfl @[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : InfHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of an `InfHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : InfHom α β) (f' : α → β) (h : f' = f) : InfHom α β where toFun := f' map_inf' := h.symm ▸ f.map_inf' @[simp] theorem coe_copy (f : InfHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : InfHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as an `InfHom`. -/ protected def id : InfHom α α := ⟨id, fun _ _ => rfl⟩ instance : Inhabited (InfHom α α) := ⟨InfHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(InfHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : InfHom.id α a = a := rfl /-- Composition of `InfHom`s as an `InfHom`. -/ def comp (f : InfHom β γ) (g : InfHom α β) : InfHom α γ where toFun := f ∘ g map_inf' a b := by rw [comp_apply, map_inf, map_inf]; rfl @[simp] theorem coe_comp (f : InfHom β γ) (g : InfHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : InfHom β γ) (g : InfHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : InfHom γ δ) (g : InfHom β γ) (h : InfHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : InfHom α β) : f.comp (InfHom.id α) = f := rfl @[simp] theorem id_comp (f : InfHom α β) : (InfHom.id β).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ : InfHom β γ} {f : InfHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => InfHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : InfHom β γ} {f₁ f₂ : InfHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => InfHom.ext fun a => hg <| by rw [← InfHom.comp_apply, h, InfHom.comp_apply], congr_arg _⟩ end Inf variable (α) [SemilatticeInf β] /-- The constant function as an `InfHom`. -/ def const (b : β) : InfHom α β := ⟨fun _ ↦ b, fun _ _ ↦ (inf_idem _).symm⟩ @[simp] theorem coe_const (b : β) : ⇑(const α b) = Function.const α b := rfl @[simp] theorem const_apply (b : β) (a : α) : const α b a = b := rfl variable {α} instance : Min (InfHom α β) := ⟨fun f g => ⟨f ⊓ g, fun a b => by rw [Pi.inf_apply, map_inf, map_inf] exact inf_inf_inf_comm _ _ _ _⟩⟩ instance : SemilatticeInf (InfHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl instance [Bot β] : Bot (InfHom α β) := ⟨InfHom.const α ⊥⟩ instance [Top β] : Top (InfHom α β) := ⟨InfHom.const α ⊤⟩ instance [OrderBot β] : OrderBot (InfHom α β) := OrderBot.lift ((↑) : _ → α → β) (fun _ _ => id) rfl instance [OrderTop β] : OrderTop (InfHom α β) := OrderTop.lift ((↑) : _ → α → β) (fun _ _ => id) rfl instance [BoundedOrder β] : BoundedOrder (InfHom α β) := BoundedOrder.lift ((↑) : _ → α → β) (fun _ _ => id) rfl rfl @[simp] theorem coe_inf (f g : InfHom α β) : DFunLike.coe (f ⊓ g) = f ⊓ g := rfl @[simp] theorem coe_bot [Bot β] : ⇑(⊥ : InfHom α β) = ⊥ := rfl @[simp] theorem coe_top [Top β] : ⇑(⊤ : InfHom α β) = ⊤ := rfl @[simp] theorem inf_apply (f g : InfHom α β) (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl @[simp] theorem bot_apply [Bot β] (a : α) : (⊥ : InfHom α β) a = ⊥ := rfl @[simp] theorem top_apply [Top β] (a : α) : (⊤ : InfHom α β) a = ⊤ := rfl @[simp] lemma mk_le_mk (toFun₁ toFun₂ : α → β) (map_inf₁ map_inf₂) : mk toFun₁ map_inf₁ ≤ mk toFun₂ map_inf₂ ↔ toFun₁ ≤ toFun₂ := .rfl @[gcongr] alias ⟨_, _root_.GCongr.InfHom.mk_le_mk⟩ := mk_le_mk /-- `Subtype.val` as an `InfHom`. -/ def subtypeVal {P : β → Prop} (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) : letI := Subtype.semilatticeInf Pinf InfHom {x : β // P x} β := letI := Subtype.semilatticeInf Pinf .mk Subtype.val (by simp) @[simp] lemma subtypeVal_apply {P : β → Prop} (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) (x : {x : β // P x}) : subtypeVal Pinf x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Pinf : ∀ ⦃x y : β⦄, P x → P y → P (x ⊓ y)) : ⇑(subtypeVal Pinf) = Subtype.val := rfl end InfHom /-! ### Lattice homomorphisms -/ namespace LatticeHom variable [Lattice α] [Lattice β] [Lattice γ] [Lattice δ] /-- Reinterpret a `LatticeHom` as an `InfHom`. -/ def toInfHom (f : LatticeHom α β) : InfHom α β := { f with } instance : FunLike (LatticeHom α β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr instance : LatticeHomClass (LatticeHom α β) α β where map_sup f := f.map_sup' map_inf f := f.map_inf' lemma toFun_eq_coe (f : LatticeHom α β) : f.toFun = f := rfl @[simp] lemma coe_toSupHom (f : LatticeHom α β) : ⇑f.toSupHom = f := rfl @[simp] lemma coe_toInfHom (f : LatticeHom α β) : ⇑f.toInfHom = f := rfl @[simp] lemma coe_mk (f : SupHom α β) (hf) : ⇑(mk f hf) = f := rfl @[ext] theorem ext {f g : LatticeHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `LatticeHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : LatticeHom α β) (f' : α → β) (h : f' = f) : LatticeHom α β := { f.toSupHom.copy f' h, f.toInfHom.copy f' h with } @[simp] theorem coe_copy (f : LatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : LatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `LatticeHom`. -/ protected def id : LatticeHom α α where toFun := id map_sup' _ _ := rfl map_inf' _ _ := rfl instance : Inhabited (LatticeHom α α) := ⟨LatticeHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(LatticeHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : LatticeHom.id α a = a := rfl /-- Composition of `LatticeHom`s as a `LatticeHom`. -/ def comp (f : LatticeHom β γ) (g : LatticeHom α β) : LatticeHom α γ := { f.toSupHom.comp g.toSupHom, f.toInfHom.comp g.toInfHom with } @[simp] theorem coe_comp (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : LatticeHom β γ) (g : LatticeHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] -- `simp`-normal form of `coe_comp_sup_hom` theorem coe_comp_sup_hom' (f : LatticeHom β γ) (g : LatticeHom α β) : ⟨f ∘ g, map_sup (f.comp g)⟩ = (f : SupHom β γ).comp g := rfl theorem coe_comp_sup_hom (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g : SupHom α γ) = (f : SupHom β γ).comp g := rfl @[simp] -- `simp`-normal form of `coe_comp_inf_hom` theorem coe_comp_inf_hom' (f : LatticeHom β γ) (g : LatticeHom α β) : ⟨f ∘ g, map_inf (f.comp g)⟩ = (f : InfHom β γ).comp g := rfl theorem coe_comp_inf_hom (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g : InfHom α γ) = (f : InfHom β γ).comp g := rfl @[simp] theorem comp_assoc (f : LatticeHom γ δ) (g : LatticeHom β γ) (h : LatticeHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : LatticeHom α β) : f.comp (LatticeHom.id α) = f := LatticeHom.ext fun _ => rfl @[simp] theorem id_comp (f : LatticeHom α β) : (LatticeHom.id β).comp f = f := LatticeHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : LatticeHom β γ} {f : LatticeHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => LatticeHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩ @[simp] theorem cancel_left {g : LatticeHom β γ} {f₁ f₂ : LatticeHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => LatticeHom.ext fun a => hg <| by rw [← LatticeHom.comp_apply, h, LatticeHom.comp_apply], congr_arg _⟩ /-- `Subtype.val` as a `LatticeHom`. -/ def subtypeVal {P : β → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : letI := Subtype.lattice Psup Pinf LatticeHom {x : β // P x} β := letI := Subtype.lattice Psup Pinf .mk (SupHom.subtypeVal Psup) (by simp [Subtype.coe_inf Pinf]) @[simp] lemma subtypeVal_apply {P : β → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) (x : {x : β // P x}) : subtypeVal Psup Pinf x = x := rfl @[simp] lemma subtypeVal_coe {P : β → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : ⇑(subtypeVal Psup Pinf) = Subtype.val := rfl end LatticeHom namespace OrderHomClass variable (α β) variable [LinearOrder α] [Lattice β] [OrderHomClass F α β] /-- An order homomorphism from a linear order is a lattice homomorphism. -/ instance (priority := 100) toLatticeHomClass : LatticeHomClass F α β := { ‹OrderHomClass F α β› with map_sup := fun f a b => by obtain h | h := le_total a b · rw [sup_eq_right.2 h, sup_eq_right.2 (OrderHomClass.mono f h : f a ≤ f b)] · rw [sup_eq_left.2 h, sup_eq_left.2 (OrderHomClass.mono f h : f b ≤ f a)] map_inf := fun f a b => by obtain h | h := le_total a b · rw [inf_eq_left.2 h, inf_eq_left.2 (OrderHomClass.mono f h : f a ≤ f b)] · rw [inf_eq_right.2 h, inf_eq_right.2 (OrderHomClass.mono f h : f b ≤ f a)] } /-- Reinterpret an order homomorphism to a linear order as a `LatticeHom`. -/ def toLatticeHom (f : F) : LatticeHom α β := f @[simp] theorem coe_to_lattice_hom (f : F) : ⇑(toLatticeHom α β f) = f := rfl @[simp] theorem to_lattice_hom_apply (f : F) (a : α) : toLatticeHom α β f a = f a := rfl end OrderHomClass /-! ### Dual homs -/ namespace SupHom variable [Max α] [Max β] [Max γ] /-- Reinterpret a supremum homomorphism as an infimum homomorphism between the dual lattices. -/ @[simps] protected def dual : SupHom α β ≃ InfHom αᵒᵈ βᵒᵈ where toFun f := ⟨f, f.map_sup'⟩ invFun f := ⟨f, f.map_inf'⟩ @[simp] theorem dual_id : SupHom.dual (SupHom.id α) = InfHom.id _ := rfl @[simp] theorem dual_comp (g : SupHom β γ) (f : SupHom α β) : SupHom.dual (g.comp f) = (SupHom.dual g).comp (SupHom.dual f) := rfl @[simp] theorem symm_dual_id : SupHom.dual.symm (InfHom.id _) = SupHom.id α := rfl @[simp] theorem symm_dual_comp (g : InfHom βᵒᵈ γᵒᵈ) (f : InfHom αᵒᵈ βᵒᵈ) : SupHom.dual.symm (g.comp f) = (SupHom.dual.symm g).comp (SupHom.dual.symm f) := rfl end SupHom namespace InfHom variable [Min α] [Min β] [Min γ] /-- Reinterpret an infimum homomorphism as a supremum homomorphism between the dual lattices. -/ @[simps] protected def dual : InfHom α β ≃ SupHom αᵒᵈ βᵒᵈ where toFun f := ⟨f, f.map_inf'⟩ invFun f := ⟨f, f.map_sup'⟩ @[simp] theorem dual_id : InfHom.dual (InfHom.id α) = SupHom.id _ := rfl @[simp] theorem dual_comp (g : InfHom β γ) (f : InfHom α β) : InfHom.dual (g.comp f) = (InfHom.dual g).comp (InfHom.dual f) := rfl @[simp] theorem symm_dual_id : InfHom.dual.symm (SupHom.id _) = InfHom.id α := rfl @[simp] theorem symm_dual_comp (g : SupHom βᵒᵈ γᵒᵈ) (f : SupHom αᵒᵈ βᵒᵈ) : InfHom.dual.symm (g.comp f) = (InfHom.dual.symm g).comp (InfHom.dual.symm f) := rfl end InfHom namespace LatticeHom variable [Lattice α] [Lattice β] [Lattice γ] /-- Reinterpret a lattice homomorphism as a lattice homomorphism between the dual lattices. -/ @[simps] protected def dual : LatticeHom α β ≃ LatticeHom αᵒᵈ βᵒᵈ where toFun f := ⟨InfHom.dual f.toInfHom, f.map_sup'⟩ invFun f := ⟨SupHom.dual.symm f.toInfHom, f.map_sup'⟩ @[simp] theorem dual_id : LatticeHom.dual (LatticeHom.id α) = LatticeHom.id _ := rfl @[simp] theorem dual_comp (g : LatticeHom β γ) (f : LatticeHom α β) : LatticeHom.dual (g.comp f) = (LatticeHom.dual g).comp (LatticeHom.dual f) := rfl @[simp] theorem symm_dual_id : LatticeHom.dual.symm (LatticeHom.id _) = LatticeHom.id α := rfl @[simp] theorem symm_dual_comp (g : LatticeHom βᵒᵈ γᵒᵈ) (f : LatticeHom αᵒᵈ βᵒᵈ) : LatticeHom.dual.symm (g.comp f) = (LatticeHom.dual.symm g).comp (LatticeHom.dual.symm f) := rfl end LatticeHom /-! ### Prod -/ namespace LatticeHom variable [Lattice α] [Lattice β] /-- Natural projection homomorphism from `α × β` to `α`. -/ def fst : LatticeHom (α × β) α where toFun := Prod.fst map_sup' _ _ := rfl map_inf' _ _ := rfl /-- Natural projection homomorphism from `α × β` to `β`. -/ def snd : LatticeHom (α × β) β where toFun := Prod.snd map_sup' _ _ := rfl map_inf' _ _ := rfl @[simp, norm_cast] lemma coe_fst : ⇑(fst (α := α) (β := β)) = Prod.fst := rfl @[simp, norm_cast] lemma coe_snd : ⇑(snd (α := α) (β := β)) = Prod.snd := rfl lemma fst_apply (x : α × β) : fst x = x.fst := rfl lemma snd_apply (x : α × β) : snd x = x.snd := rfl end LatticeHom /-! ### Pi -/ namespace Pi variable {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] /-- Evaluation as a lattice homomorphism. -/ def evalLatticeHom (i : ι) : LatticeHom (∀ i, α i) (α i) where toFun := Function.eval i map_sup' _a _b := rfl map_inf' _a _b := rfl @[simp, norm_cast] lemma coe_evalLatticeHom (i : ι) : ⇑(evalLatticeHom (α := α) i) = Function.eval i := rfl lemma evalLatticeHom_apply (i : ι) (f : ∀ i, α i) : evalLatticeHom i f = f i := rfl end Pi
.lake/packages/mathlib/Mathlib/Order/Category/DistLat.lean
import Mathlib.Order.Category.Lat /-! # The category of distributive lattices This file defines `DistLat`, the category of distributive lattices. Note that [`DistLat`](https://ncatlab.org/nlab/show/DistLat) in the literature doesn't always correspond to `DistLat` as we don't require bottom or top elements. Instead, this `DistLat` corresponds to `BddDistLat`. -/ universe u open CategoryTheory /-- The category of distributive lattices. -/ structure DistLat where /-- The underlying distributive lattice. -/ carrier : Type* [str : DistribLattice carrier] attribute [instance] DistLat.str initialize_simps_projections DistLat (carrier → coe, -str) namespace DistLat instance : CoeSort DistLat.{u} (Type u) := ⟨DistLat.carrier⟩ attribute [coe] DistLat.carrier /-- Construct a bundled `DistLat` from the underlying type and typeclass. -/ abbrev of (X : Type*) [DistribLattice X] : DistLat := ⟨X⟩ /-- The type of morphisms in `DistLat R`. -/ @[ext] structure Hom (X Y : DistLat.{u}) where private mk :: /-- The underlying `LatticeHom`. -/ hom' : LatticeHom X Y instance : Category DistLat.{u} where Hom X Y := Hom X Y id X := ⟨LatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory DistLat (LatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `DistLat` back into a `LatticeHom`. -/ abbrev Hom.hom {X Y : DistLat.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := DistLat) f /-- Typecheck a `LatticeHom` as a morphism in `DistLat`. -/ abbrev ofHom {X Y : Type u} [DistribLattice X] [DistribLattice Y] (f : LatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := DistLat) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : DistLat.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : DistLat} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : DistLat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : DistLat} (f : X ⟶ Y) : (forget DistLat).map f = f := rfl @[ext] lemma ext {X Y : DistLat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [DistribLattice X] : (DistLat.of X : Type u) = X := rfl @[simp] lemma hom_id {X : DistLat} : (𝟙 X : X ⟶ X).hom = LatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : DistLat) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : DistLat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : DistLat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : DistLat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [DistribLattice X] [DistribLattice Y] (f : LatticeHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : DistLat} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [DistribLattice X] : ofHom (LatticeHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [DistribLattice X] [DistribLattice Y] [DistribLattice Z] (f : LatticeHom X Y) (g : LatticeHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [DistribLattice X] [DistribLattice Y] (f : LatticeHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : DistLat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : DistLat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance hasForgetToLat : HasForget₂ DistLat Lat where forget₂.obj X := .of X forget₂.map f := Lat.ofHom f.hom /-- Constructs an equivalence between distributive lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : DistLat.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : DistLat ⥤ DistLat where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `DistLat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : DistLat ≌ DistLat where functor := dual inverse := dual unitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X) fun _ => rfl counitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X) fun _ => rfl end DistLat theorem distLat_dual_comp_forget_to_Lat : DistLat.dual ⋙ forget₂ DistLat Lat = forget₂ DistLat Lat ⋙ Lat.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/BddLat.lean
import Mathlib.CategoryTheory.Adjunction.Unique import Mathlib.Order.Category.BddOrd import Mathlib.Order.Category.Lat import Mathlib.Order.Category.Semilat import Mathlib.Order.Hom.WithTopBot /-! # The category of bounded lattices This file defines `BddLat`, the category of bounded lattices. In literature, this is sometimes called `Lat`, the category of lattices, because being a lattice is understood to entail having a bottom and a top element. -/ universe u open CategoryTheory /-- The category of bounded lattices with bounded lattice morphisms. -/ structure BddLat extends Lat where [isBoundedOrder : BoundedOrder toLat] /-- The underlying lattice of a bounded lattice. -/ add_decl_doc BddLat.toLat namespace BddLat instance : CoeSort BddLat Type* := ⟨fun X => X.toLat⟩ attribute [instance] BddLat.isBoundedOrder /-- Construct a bundled `BddLat` from `Lattice` + `BoundedOrder`. -/ abbrev of (α : Type*) [Lattice α] [BoundedOrder α] : BddLat where carrier := α theorem coe_of (α : Type*) [Lattice α] [BoundedOrder α] : ↥(of α) = α := rfl /-- The type of morphisms in `BddLat`. -/ @[ext] structure Hom (X Y : BddLat.{u}) where private mk :: /-- The underlying `BoundedLatticeHom`. -/ hom' : BoundedLatticeHom X Y instance : Inhabited BddLat := ⟨of PUnit⟩ instance : LargeCategory.{u} BddLat where Hom := Hom id X := ⟨BoundedLatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory BddLat (BoundedLatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `BddLat` back into a `BoundedLatticeHom`. -/ abbrev Hom.hom {X Y : BddLat.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := BddLat) f /-- Typecheck a `BoundedLatticeHom` as a morphism in `BddLat`. -/ abbrev ofHom {X Y : Type u} [Lattice X] [BoundedOrder X] [Lattice Y] [BoundedOrder Y] (f : BoundedLatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := BddLat) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : BddLat.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) @[simp] lemma hom_id {X : Lat} : (𝟙 X : X ⟶ X).hom = LatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : Lat) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : Lat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : Lat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma ext {X Y : BddLat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w @[ext] lemma hom_ext {X Y : BddLat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf instance hasForgetToBddOrd : HasForget₂ BddLat BddOrd where forget₂.obj X := .of X forget₂.map f := BddOrd.ofHom f.hom.toBoundedOrderHom instance hasForgetToLat : HasForget₂ BddLat Lat where forget₂.obj X := .of X forget₂.map f := Lat.ofHom f.hom.toLatticeHom instance hasForgetToSemilatSup : HasForget₂ BddLat SemilatSupCat where forget₂.obj X := .of X forget₂.map f := f.hom.toSupBotHom instance hasForgetToSemilatInf : HasForget₂ BddLat SemilatInfCat where forget₂.obj X := .of X forget₂.map f := f.hom.toInfTopHom @[simp] theorem coe_forget_to_bddOrd (X : BddLat) : ↥((forget₂ BddLat BddOrd).obj X) = ↥X := rfl @[simp] theorem coe_forget_to_lat (X : BddLat) : ↥((forget₂ BddLat Lat).obj X) = ↥X := rfl @[simp] theorem coe_forget_to_semilatSup (X : BddLat) : ↥((forget₂ BddLat SemilatSupCat).obj X) = ↥X := rfl @[simp] theorem coe_forget_to_semilatInf (X : BddLat) : ↥((forget₂ BddLat SemilatInfCat).obj X) = ↥X := rfl theorem forget_lat_partOrd_eq_forget_bddOrd_partOrd : forget₂ BddLat Lat ⋙ forget₂ Lat PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl theorem forget_semilatSup_partOrd_eq_forget_bddOrd_partOrd : forget₂ BddLat SemilatSupCat ⋙ forget₂ SemilatSupCat PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl theorem forget_semilatInf_partOrd_eq_forget_bddOrd_partOrd : forget₂ BddLat SemilatInfCat ⋙ forget₂ SemilatInfCat PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl /-- Constructs an equivalence between bounded lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : BddLat.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps map] def dual : BddLat ⥤ BddLat where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `BddLat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : BddLat ≌ BddLat where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end BddLat theorem bddLat_dual_comp_forget_to_bddOrd : BddLat.dual ⋙ forget₂ BddLat BddOrd = forget₂ BddLat BddOrd ⋙ BddOrd.dual := rfl theorem bddLat_dual_comp_forget_to_lat : BddLat.dual ⋙ forget₂ BddLat Lat = forget₂ BddLat Lat ⋙ Lat.dual := rfl theorem bddLat_dual_comp_forget_to_semilatSupCat : BddLat.dual ⋙ forget₂ BddLat SemilatSupCat = forget₂ BddLat SemilatInfCat ⋙ SemilatInfCat.dual := rfl theorem bddLat_dual_comp_forget_to_semilatInfCat : BddLat.dual ⋙ forget₂ BddLat SemilatInfCat = forget₂ BddLat SemilatSupCat ⋙ SemilatSupCat.dual := rfl /-- The functor that adds a bottom and a top element to a lattice. This is the free functor. -/ def latToBddLat : Lat.{u} ⥤ BddLat where obj X := .of <| WithTop <| WithBot X map f := BddLat.ofHom <| LatticeHom.withTopWithBot f.hom /-- `latToBddLat` is left adjoint to the forgetful functor, meaning it is the free functor from `Lat` to `BddLat`. -/ def latToBddLatForgetAdjunction : latToBddLat.{u} ⊣ forget₂ BddLat Lat := Adjunction.mkOfHomEquiv { homEquiv X _ := { toFun f := Lat.ofHom { toFun := f ∘ some ∘ some map_sup' := fun a b => (congr_arg f <| by rfl).trans (f.hom.map_sup' _ _) map_inf' := fun a b => (congr_arg f <| by rfl).trans (f.hom.map_inf' _ _) } invFun f := BddLat.ofHom <| LatticeHom.withTopWithBot' f.hom left_inv := fun f => BddLat.ext fun a => match a with | none => f.hom.map_top'.symm | some none => f.hom.map_bot'.symm | some (some _) => rfl } homEquiv_naturality_left_symm := fun _ _ => BddLat.ext fun a => match a with | none => rfl | some none => rfl | some (some _) => rfl homEquiv_naturality_right := fun _ _ => Lat.ext fun _ => rfl } /-- `latToBddLat` and `OrderDual` commute. -/ def latToBddLatCompDualIsoDualCompLatToBddLat : latToBddLat.{u} ⋙ BddLat.dual ≅ Lat.dual ⋙ latToBddLat := Adjunction.leftAdjointUniq (latToBddLatForgetAdjunction.comp BddLat.dualEquiv.toAdjunction) (Lat.dualEquiv.toAdjunction.comp latToBddLatForgetAdjunction)
.lake/packages/mathlib/Mathlib/Order/Category/Preord.lean
import Mathlib.CategoryTheory.Category.Cat import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Elementwise import Mathlib.Order.Hom.Basic import Mathlib.Order.CompleteBooleanAlgebra /-! # Category of preorders This defines `Preord`, the category of preorders with monotone maps. -/ universe u open CategoryTheory /-- The category of preorders. -/ structure Preord where /-- Construct a bundled `Preord` from the underlying type and typeclass. -/ of :: /-- The underlying preordered type. -/ (carrier : Type*) [str : Preorder carrier] attribute [instance] Preord.str initialize_simps_projections Preord (carrier → coe, -str) namespace Preord instance : CoeSort Preord (Type u) := ⟨Preord.carrier⟩ attribute [coe] Preord.carrier /-- The type of morphisms in `Preord R`. -/ @[ext] structure Hom (X Y : Preord.{u}) where private mk :: /-- The underlying `OrderHom`. -/ hom' : X →o Y instance : Category Preord.{u} where Hom X Y := Hom X Y id _ := ⟨OrderHom.id⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory Preord (· →o ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `Preord` back into a `OrderHom`. -/ abbrev Hom.hom {X Y : Preord.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := Preord) f /-- Typecheck a `OrderHom` as a morphism in `Preord`. -/ abbrev ofHom {X Y : Type u} [Preorder X] [Preorder Y] (f : X →o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := Preord) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : Preord.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : Preord} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : Preord} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : Preord} (f : X ⟶ Y) : (forget Preord).map f = f := rfl @[ext] lemma ext {X Y : Preord} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [Preorder X] : (Preord.of X : Type u) = X := rfl @[simp] lemma hom_id {X : Preord} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl /- Provided for rewriting. -/ lemma id_apply (X : Preord) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : Preord} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : Preord} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : Preord} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [Preorder X] [Preorder Y] (f : X →o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : Preord} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [Preorder X] : ofHom OrderHom.id = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [Preorder X] [Preorder Y] [Preorder Z] (f : X →o Y) (g : Y →o Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [Preorder X] [Preorder Y] (f : X →o Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : Preord} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : Preord} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited Preord := ⟨of PUnit⟩ /-- Constructs an equivalence between preorders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : Preord.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : Preord ⥤ Preord where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `Preord` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : Preord ≌ Preord where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end Preord /-- The embedding of `Preord` into `Cat`. -/ @[simps] def preordToCat : Preord.{u} ⥤ Cat where obj X := .of X.1 map f := f.hom.monotone.functor instance : preordToCat.{u}.Faithful where map_injective h := by ext x; exact Functor.congr_obj h x instance : preordToCat.{u}.Full where map_surjective {X Y} f := ⟨⟨f.obj, @CategoryTheory.Functor.monotone X Y _ _ f⟩, rfl⟩
.lake/packages/mathlib/Mathlib/Order/Category/PartOrdEmb.lean
import Mathlib.Order.Category.PartOrd import Mathlib.CategoryTheory.Limits.Filtered import Mathlib.CategoryTheory.Limits.Preserves.Filtered import Mathlib.CategoryTheory.Limits.Types.Filtered /-! # Category of partial orders, with order embeddings as morphisms This defines `PartOrdEmb`, the category of partial orders with order embeddings as morphisms. We also show that `PartOrdEmb` has filtered colimits. -/ open CategoryTheory Limits universe u /-- The category of partial orders. -/ structure PartOrdEmb where /-- Construct a bundled `PartOrdEmb` from the underlying type and typeclass. -/ of :: /-- The underlying partially ordered type. -/ (carrier : Type*) [str : PartialOrder carrier] attribute [instance] PartOrdEmb.str initialize_simps_projections PartOrdEmb (carrier → coe, -str) namespace PartOrdEmb instance : CoeSort PartOrdEmb (Type _) := ⟨PartOrdEmb.carrier⟩ attribute [coe] PartOrdEmb.carrier /-- The type of morphisms in `PartOrdEmb R`. -/ @[ext] structure Hom (X Y : PartOrdEmb.{u}) where private mk :: /-- The underlying `OrderEmbedding`. -/ hom' : X ↪o Y instance : Category PartOrdEmb.{u} where Hom X Y := Hom X Y id _ := ⟨RelEmbedding.refl _⟩ comp f g := ⟨f.hom'.trans g.hom'⟩ instance : ConcreteCategory PartOrdEmb (· ↪o ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `PartOrdEmb` back into a `OrderEmbedding`. -/ abbrev Hom.hom {X Y : PartOrdEmb.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := PartOrdEmb) f /-- Typecheck a `OrderEmbedding` as a morphism in `PartOrdEmb`. -/ abbrev ofHom {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X ↪o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := PartOrdEmb) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : PartOrdEmb.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : PartOrdEmb} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : PartOrdEmb} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : PartOrdEmb} (f : X ⟶ Y) : (forget PartOrdEmb).map f = f := rfl @[ext] lemma ext {X Y : PartOrdEmb} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [PartialOrder X] : (PartOrdEmb.of X : Type u) = X := rfl lemma hom_id {X : PartOrdEmb} : (𝟙 X : X ⟶ X).hom = RelEmbedding.refl _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : PartOrdEmb) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : PartOrdEmb} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = f.hom.trans g.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : PartOrdEmb} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp lemma Hom.injective {X Y : PartOrdEmb.{u}} (f : X ⟶ Y) : Function.Injective f := f.hom'.injective lemma Hom.le_iff_le {X Y : PartOrdEmb.{u}} (f : X ⟶ Y) (x₁ x₂ : X) : f x₁ ≤ f x₂ ↔ x₁ ≤ x₂ := f.hom'.le_iff_le @[ext] lemma hom_ext {X Y : PartOrdEmb} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X ↪o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : PartOrdEmb} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [PartialOrder X] : ofHom (RelEmbedding.refl _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [PartialOrder X] [PartialOrder Y] [PartialOrder Z] (f : X ↪o Y) (g : Y ↪o Z) : ofHom (f.trans g) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X ↪o Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : PartOrdEmb} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : PartOrdEmb} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance hasForgetToPartOrd : HasForget₂ PartOrdEmb PartOrd where forget₂.obj X := .of X forget₂.map f := PartOrd.ofHom f.hom /-- Constructs an equivalence between partial orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : PartOrdEmb.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : PartOrdEmb ⥤ PartOrdEmb where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `PartOrdEmb` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : PartOrdEmb ≌ PartOrdEmb where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end PartOrdEmb theorem partOrdEmb_dual_comp_forget_to_pardOrd : PartOrdEmb.dual ⋙ forget₂ PartOrdEmb PartOrd = forget₂ PartOrdEmb PartOrd ⋙ PartOrd.dual := rfl namespace PartOrdEmb variable {J : Type u} [SmallCategory J] [IsFiltered J] {F : J ⥤ PartOrdEmb.{u}} namespace Limits variable {c : Cocone (F ⋙ forget _)} (hc : IsColimit c) /-- Given a functor `F : J ⥤ PartOrdEmb` and a colimit cocone `c` for `F ⋙ forget _`, this is the type `c.pt` on which we define a partial order which makes it the colimit of `F`. -/ @[nolint unusedArguments] def CoconePt (_ : IsColimit c) : Type u := c.pt open IsFiltered instance : PartialOrder (CoconePt hc) where le x y := ∃ (j : J) (x' y' : F.obj j) (hx : c.ι.app j x' = x) (hy : c.ι.app j y' = y), x' ≤ y' le_refl x := by obtain ⟨j, x', hx⟩ := Types.jointly_surjective_of_isColimit hc x exact ⟨j, x', x', hx, hx, le_rfl⟩ le_trans := by rintro x y z ⟨j, x₁, y₁, hx₁, hy₁, hxy⟩ ⟨k, y₂, z₁, hy₂, hz₁, hyz⟩ obtain ⟨l, a, b, h⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc (xi := y₁) (xj := y₂)).1 (hy₁.trans hy₂.symm) exact ⟨l, F.map a x₁, F.map b z₁, (ConcreteCategory.congr_hom (c.w a) x₁).trans hx₁, (ConcreteCategory.congr_hom (c.w b) z₁).trans hz₁, ((F.map a).hom.monotone hxy).trans (le_of_eq_of_le h ((F.map b).hom.monotone hyz))⟩ le_antisymm := by rintro x y ⟨j, x₁, y₁, hx₁, hy₁, h₁⟩ ⟨k, y₂, x₂, hy₂, hx₂, h₂⟩ obtain ⟨l, a, b, x₃, y₃, h₃, h₄, h₅, h₆⟩ : ∃ (l : J) (a : j ⟶ l) (b : k ⟶ l) (x₃ y₃ : _), x₃ = F.map a x₁ ∧ x₃ = F.map b x₂ ∧ y₃ = F.map a y₁ ∧ y₃ = F.map b y₂ := by obtain ⟨l₁, a, b, h₃⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc (xi := x₁) (xj := x₂)).1 (hx₁.trans hx₂.symm) obtain ⟨l₂, a', b', h₄⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc (xi := y₁) (xj := y₂)).1 (hy₁.trans hy₂.symm) obtain ⟨l, d, d', h₅, h₆⟩ := IsFiltered.bowtie a a' b b' exact ⟨l, a ≫ d, b ≫ d, F.map (a ≫ d) x₁, F.map (a' ≫ d') y₁, rfl, by simpa, by rw [h₅], by simpa [h₆]⟩ have h₇ : x₃ = y₃ := le_antisymm (by simpa only [h₃, h₅] using (F.map a).hom.monotone h₁) (by simpa only [h₄, h₆] using (F.map b).hom.monotone h₂) exact hx₁.symm.trans ((ConcreteCategory.congr_hom (c.w a) x₁).symm.trans ((congr_arg (c.ι.app l) (h₃.symm.trans (h₇.trans h₅))).trans ((ConcreteCategory.congr_hom (c.w a) y₁).trans hy₁))) /-- The colimit cocone for a functor `F : J ⥤ PartOrdEmb` from a filtered category that is constructed from a colimit cocone for `F ⋙ forget _`. -/ @[simps] def cocone : Cocone F where pt := .of (CoconePt hc) ι.app j := ofHom { toFun := c.ι.app j inj' x y h := by obtain ⟨k, a, ha⟩ := (Types.FilteredColimit.isColimit_eq_iff' hc x y).1 h exact (F.map a).injective ha map_rel_iff' {x y} := by refine ⟨?_, fun h ↦ ⟨j, x, y, rfl, rfl, h⟩⟩ rintro ⟨k, x', y', hx, hy, h⟩ obtain ⟨l₁, a₁, b₁, hl₁⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc).1 hx obtain ⟨l₂, a₂, b₂, hl₂⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc).1 hy dsimp at hx hy hl₁ hl₂ obtain ⟨m, d, d', h₁, h₂⟩ := bowtie a₁ a₂ b₁ b₂ rw [← (F.map (a₁ ≫ d)).le_iff_le] at h rw [← (F.map (b₁ ≫ d)).le_iff_le] conv_rhs => rw [h₂] conv_rhs at h => rw [h₁] simpa [← hl₁, ← hl₂] using h } ι.naturality _ _ f := by ext x; exact ConcreteCategory.congr_hom (c.w f) x /-- Auxiliary definition for `isColimitCocone`. -/ def CoconePt.desc (s : Cocone F) : CoconePt hc ↪o s.pt where toFun := hc.desc ((forget _).mapCocone s) inj' x y h := by obtain ⟨j, x', y', rfl, rfl⟩ := Types.FilteredColimit.jointly_surjective_of_isColimit₂ hc x y obtain rfl := (s.ι.app j).injective (((congr_fun (hc.fac ((forget _).mapCocone s) j) x').symm.trans h).trans (congr_fun (hc.fac ((forget _).mapCocone s) j) y')) rfl map_rel_iff' {x y} := by obtain ⟨j, x', y', rfl, rfl⟩ := Types.FilteredColimit.jointly_surjective_of_isColimit₂ hc x y have hx := (congr_fun (hc.fac ((forget _).mapCocone s) j) x') have hy := (congr_fun (hc.fac ((forget _).mapCocone s) j) y') dsimp at hx hy ⊢ rw [hx, hy, OrderEmbedding.le_iff_le] refine ⟨fun h ↦ ⟨j, _, _, rfl, rfl, h⟩, fun ⟨k, x, y, hx', hy', h⟩ ↦ ?_⟩ obtain ⟨l, f, g, hl⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc).1 hx' obtain ⟨l', f', g', hl'⟩ := (Types.FilteredColimit.isColimit_eq_iff _ hc).1 hy' obtain ⟨m, a, b, h₁, h₂⟩ := bowtie f f' g g' dsimp at hl hl' rw [← (F.map (f ≫ a)).le_iff_le] at h rw [← (F.map (g ≫ a)).le_iff_le] exact le_of_eq_of_le (by simp [hl]) (le_of_le_of_eq h (by simp [h₁, h₂, hl'])) @[simp] lemma CoconePt.fac_apply (s : Cocone F) (j : J) (x : F.obj j) : CoconePt.desc hc s (c.ι.app j x) = s.ι.app j x := congr_fun (hc.fac ((forget _).mapCocone s) j) x /-- A colimit cocone for `F : J ⥤ PartOrdEmb` (with `J` filtered) can be obtained from a colimit cocone for `F ⋙ forget _`. -/ def isColimitCocone : IsColimit (cocone hc) where desc s := ofHom (CoconePt.desc hc s) uniq s m hm := by ext x obtain ⟨j, x, rfl⟩ := Types.jointly_surjective_of_isColimit hc x exact ((ConcreteCategory.congr_hom (hm j)) x).trans (CoconePt.fac_apply hc s j x).symm instance : HasColimit F where exists_colimit := ⟨_, isColimitCocone (colimit.isColimit (F ⋙ forget _))⟩ instance : PreservesColimit F (forget _) := preservesColimit_of_preserves_colimit_cocone (isColimitCocone (colimit.isColimit (F ⋙ forget _))) (colimit.isColimit (F ⋙ forget _)) instance : HasColimitsOfShape J PartOrdEmb.{u} where instance : PreservesColimitsOfShape J (forget PartOrdEmb.{u}) where instance : HasFilteredColimitsOfSize.{u, u} PartOrdEmb.{u} where HasColimitsOfShape _ := inferInstance instance : PreservesFilteredColimitsOfSize.{u, u} (forget PartOrdEmb.{u}) where preserves_filtered_colimits _ := inferInstance end Limits end PartOrdEmb
.lake/packages/mathlib/Mathlib/Order/Category/BddDistLat.lean
import Mathlib.Order.Category.BddLat import Mathlib.Order.Category.DistLat /-! # The category of bounded distributive lattices This defines `BddDistLat`, the category of bounded distributive lattices. Note that this category is sometimes called [`DistLat`](https://ncatlab.org/nlab/show/DistLat) when being a lattice is understood to entail having a bottom and a top element. -/ universe u open CategoryTheory /-- The category of bounded distributive lattices with bounded lattice morphisms. -/ structure BddDistLat extends DistLat where [isBoundedOrder : BoundedOrder toDistLat] /-- The underlying distrib lattice of a bounded distributive lattice. -/ add_decl_doc BddDistLat.toDistLat namespace BddDistLat instance : CoeSort BddDistLat Type* := ⟨fun X => X.toDistLat⟩ instance (X : BddDistLat) : DistribLattice X := X.toDistLat.str attribute [instance] BddDistLat.isBoundedOrder /-- Construct a bundled `BddDistLat` from a `BoundedOrder` `DistribLattice`. -/ abbrev of (α : Type*) [DistribLattice α] [BoundedOrder α] : BddDistLat where carrier := α theorem coe_of (α : Type*) [DistribLattice α] [BoundedOrder α] : ↥(of α) = α := rfl /-- The type of morphisms in `BddDistLat R`. -/ @[ext] structure Hom (X Y : BddDistLat.{u}) where private mk :: /-- The underlying `BoundedLatticeHom`. -/ hom' : BoundedLatticeHom X Y instance : Category BddDistLat.{u} where Hom X Y := Hom X Y id X := ⟨BoundedLatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory BddDistLat (BoundedLatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `BddDistLat` back into a `BoundedLatticeHom`. -/ abbrev Hom.hom {X Y : BddDistLat.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := BddDistLat) f /-- Typecheck a `BoundedLatticeHom` as a morphism in `BddDistLat`. -/ abbrev ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [DistribLattice Y] [BoundedOrder Y] (f : BoundedLatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := BddDistLat) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : BddDistLat.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : BddDistLat} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : BddDistLat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : BddDistLat} (f : X ⟶ Y) : (forget BddDistLat).map f = f := rfl @[ext] lemma ext {X Y : BddDistLat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w @[simp] lemma hom_id {X : BddDistLat} : (𝟙 X : X ⟶ X).hom = BoundedLatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : BddDistLat) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : BddDistLat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : BddDistLat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : BddDistLat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [DistribLattice Y] [BoundedOrder Y] (f : BoundedLatticeHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : BddDistLat} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [DistribLattice X] [BoundedOrder X] : ofHom (BoundedLatticeHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [DistribLattice X] [BoundedOrder X] [DistribLattice Y] [BoundedOrder Y] [DistribLattice Z] [BoundedOrder Z] (f : BoundedLatticeHom X Y) (g : BoundedLatticeHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [DistribLattice X] [BoundedOrder X] [DistribLattice Y] [BoundedOrder Y] (f : BoundedLatticeHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : BddDistLat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : BddDistLat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited BddDistLat := ⟨of PUnit⟩ /-- Turn a `BddDistLat` into a `BddLat` by forgetting it is distributive. -/ def toBddLat (X : BddDistLat) : BddLat := .of X @[simp] theorem coe_toBddLat (X : BddDistLat) : ↥X.toBddLat = ↥X := rfl instance hasForgetToDistLat : HasForget₂ BddDistLat DistLat where forget₂.obj X := .of X forget₂.map f := DistLat.ofHom f.hom.toLatticeHom instance hasForgetToBddLat : HasForget₂ BddDistLat BddLat where forget₂.obj X := .of X forget₂.map f := BddLat.ofHom f.hom theorem forget_bddLat_lat_eq_forget_distLat_lat : forget₂ BddDistLat BddLat ⋙ forget₂ BddLat Lat = forget₂ BddDistLat DistLat ⋙ forget₂ DistLat Lat := rfl /-- Constructs an equivalence between bounded distributive lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : BddDistLat.{u}} (e : α ≃o β) : α ≅ β where hom := BddDistLat.ofHom e inv := BddDistLat.ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : BddDistLat ⥤ BddDistLat where obj X := of Xᵒᵈ map f := BddDistLat.ofHom f.hom.dual /-- The equivalence between `BddDistLat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : BddDistLat ≌ BddDistLat where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end BddDistLat theorem bddDistLat_dual_comp_forget_to_distLat : BddDistLat.dual ⋙ forget₂ BddDistLat DistLat = forget₂ BddDistLat DistLat ⋙ DistLat.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/FinBddDistLat.lean
import Mathlib.Data.Fintype.Order import Mathlib.Order.Category.BddDistLat import Mathlib.Order.Category.FinPartOrd /-! # The category of finite bounded distributive lattices This file defines `FinBddDistLat`, the category of finite distributive lattices with bounded lattice homomorphisms. -/ universe u open CategoryTheory /-- The category of finite distributive lattices with bounded lattice morphisms. -/ structure FinBddDistLat extends BddDistLat where [isFintype : Fintype carrier] namespace FinBddDistLat instance : CoeSort FinBddDistLat Type* := ⟨fun X => X.carrier⟩ instance (X : FinBddDistLat) : DistribLattice X := X.str instance (X : FinBddDistLat) : BoundedOrder X := X.isBoundedOrder attribute [instance] FinBddDistLat.isFintype /-- Construct a bundled `FinBddDistLat` from a `Fintype` `BoundedOrder` `DistribLattice`. -/ abbrev of (α : Type*) [DistribLattice α] [BoundedOrder α] [Fintype α] : FinBddDistLat where carrier := α /-- Construct a bundled `FinBddDistLat` from a `Nonempty` `Fintype` `DistribLattice`. -/ abbrev of' (α : Type*) [DistribLattice α] [Fintype α] [Nonempty α] : FinBddDistLat where carrier := α isBoundedOrder := Fintype.toBoundedOrder α /-- The type of morphisms in `FinBddDistLat R`. -/ @[ext] structure Hom (X Y : FinBddDistLat.{u}) where private mk :: /-- The underlying `BoundedLatticeHom`. -/ hom' : BoundedLatticeHom X Y instance : Category FinBddDistLat.{u} where Hom X Y := Hom X Y id X := ⟨BoundedLatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory FinBddDistLat (BoundedLatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `FinBddDistLat` back into a `BoundedLatticeHom`. -/ abbrev Hom.hom {X Y : FinBddDistLat.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := FinBddDistLat) f /-- Typecheck a `BoundedLatticeHom` as a morphism in `FinBddDistLat`. -/ abbrev ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y] [BoundedOrder Y] [Fintype Y] (f : BoundedLatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := FinBddDistLat) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : FinBddDistLat.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : FinBddDistLat} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : FinBddDistLat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : FinBddDistLat} (f : X ⟶ Y) : (forget FinBddDistLat).map f = f := rfl @[ext] lemma ext {X Y : FinBddDistLat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w @[simp] lemma hom_id {X : FinBddDistLat} : (𝟙 X : X ⟶ X).hom = BoundedLatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : FinBddDistLat) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : FinBddDistLat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : FinBddDistLat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : FinBddDistLat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y] [BoundedOrder Y] [Fintype Y] (f : BoundedLatticeHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : FinBddDistLat} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] : ofHom (BoundedLatticeHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y] [BoundedOrder Y] [Fintype Y] [DistribLattice Z] [BoundedOrder Z] [Fintype Z] (f : BoundedLatticeHom X Y) (g : BoundedLatticeHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y] [BoundedOrder Y] [Fintype Y] (f : BoundedLatticeHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : FinBddDistLat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : FinBddDistLat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited FinBddDistLat := ⟨of PUnit⟩ instance hasForgetToBddDistLat : HasForget₂ FinBddDistLat BddDistLat where forget₂.obj X := .of X forget₂.map f := BddDistLat.ofHom f.hom instance hasForgetToFinPartOrd : HasForget₂ FinBddDistLat FinPartOrd where forget₂.obj X := .of X forget₂.map f := PartOrd.ofHom (OrderHomClass.toOrderHom f.hom) /-- Constructs an equivalence between finite distributive lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : FinBddDistLat.{u}} (e : α.carrier ≃o β.carrier) : α ≅ β where hom := ofHom e inv := ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps map] def dual : FinBddDistLat ⥤ FinBddDistLat where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `FinBddDistLat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : FinBddDistLat ≌ FinBddDistLat where functor := dual inverse := dual unitIso := NatIso.ofComponents (fun X => Iso.mk (α := X) <| OrderIso.dualDual X) counitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X) end FinBddDistLat theorem finBddDistLat_dual_comp_forget_to_bddDistLat : FinBddDistLat.dual ⋙ forget₂ FinBddDistLat BddDistLat = forget₂ FinBddDistLat BddDistLat ⋙ BddDistLat.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/LinOrd.lean
import Mathlib.Order.Category.Lat /-! # Category of linear orders This defines `LinOrd`, the category of linear orders with monotone maps. -/ open CategoryTheory universe u /-- The category of linear orders. -/ structure LinOrd where /-- Construct a bundled `LinOrd` from the underlying type and typeclass. -/ of :: /-- The underlying linearly ordered type. -/ (carrier : Type*) [str : LinearOrder carrier] attribute [instance] LinOrd.str initialize_simps_projections LinOrd (carrier → coe, -str) namespace LinOrd instance : CoeSort LinOrd (Type _) := ⟨LinOrd.carrier⟩ attribute [coe] LinOrd.carrier /-- The type of morphisms in `LinOrd R`. -/ @[ext] structure Hom (X Y : LinOrd.{u}) where private mk :: /-- The underlying `OrderHom`. -/ hom' : X →o Y instance : Category LinOrd.{u} where Hom X Y := Hom X Y id _ := ⟨OrderHom.id⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory LinOrd (· →o ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `LinOrd` back into a `OrderHom`. -/ abbrev Hom.hom {X Y : LinOrd.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := LinOrd) f /-- Typecheck a `OrderHom` as a morphism in `LinOrd`. -/ abbrev ofHom {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := LinOrd) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : LinOrd.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : LinOrd} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : LinOrd} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : LinOrd} (f : X ⟶ Y) : (forget LinOrd).map f = f := rfl @[ext] lemma ext {X Y : LinOrd} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [LinearOrder X] : (LinOrd.of X : Type u) = X := rfl @[simp] lemma hom_id {X : LinOrd} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl /- Provided for rewriting. -/ lemma id_apply (X : LinOrd) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : LinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : LinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : LinOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : LinOrd} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [LinearOrder X] : ofHom OrderHom.id = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [LinearOrder X] [LinearOrder Y] [LinearOrder Z] (f : X →o Y) (g : Y →o Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : LinOrd} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : LinOrd} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited LinOrd := ⟨of PUnit⟩ instance hasForgetToLat : HasForget₂ LinOrd Lat where forget₂.obj X := .of X forget₂.map f := Lat.ofHom (OrderHomClass.toLatticeHom _ _ f.hom) /-- Constructs an equivalence between linear orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : LinOrd.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : LinOrd ⥤ LinOrd where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `LinOrd` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : LinOrd ≌ LinOrd where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end LinOrd theorem linOrd_dual_comp_forget_to_Lat : LinOrd.dual ⋙ forget₂ LinOrd Lat = forget₂ LinOrd Lat ⋙ Lat.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/PartOrd.lean
import Mathlib.Order.Antisymmetrization import Mathlib.Order.Category.Preord import Mathlib.CategoryTheory.Adjunction.Basic /-! # Category of partial orders This defines `PartOrd`, the category of partial orders with monotone maps. -/ open CategoryTheory universe u /-- The category of partial orders. -/ structure PartOrd where /-- Construct a bundled `PartOrd` from the underlying type and typeclass. -/ of :: /-- The underlying partially ordered type. -/ (carrier : Type*) [str : PartialOrder carrier] attribute [instance] PartOrd.str initialize_simps_projections PartOrd (carrier → coe, -str) namespace PartOrd instance : CoeSort PartOrd (Type _) := ⟨PartOrd.carrier⟩ attribute [coe] PartOrd.carrier /-- The type of morphisms in `PartOrd R`. -/ @[ext] structure Hom (X Y : PartOrd.{u}) where private mk :: /-- The underlying `OrderHom`. -/ hom' : X →o Y instance : Category PartOrd.{u} where Hom X Y := Hom X Y id _ := ⟨OrderHom.id⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory PartOrd (· →o ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `PartOrd` back into a `OrderHom`. -/ abbrev Hom.hom {X Y : PartOrd.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := PartOrd) f /-- Typecheck a `OrderHom` as a morphism in `PartOrd`. -/ abbrev ofHom {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X →o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := PartOrd) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : PartOrd.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : PartOrd} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : PartOrd} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : PartOrd} (f : X ⟶ Y) : (forget PartOrd).map f = f := rfl @[ext] lemma ext {X Y : PartOrd} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [PartialOrder X] : (PartOrd.of X : Type u) = X := rfl @[simp] lemma hom_id {X : PartOrd} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl /- Provided for rewriting. -/ lemma id_apply (X : PartOrd) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : PartOrd} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : PartOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : PartOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X →o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : PartOrd} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [PartialOrder X] : ofHom OrderHom.id = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [PartialOrder X] [PartialOrder Y] [PartialOrder Z] (f : X →o Y) (g : Y →o Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [PartialOrder X] [PartialOrder Y] (f : X →o Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : PartOrd} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : PartOrd} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance hasForgetToPreord : HasForget₂ PartOrd Preord where forget₂.obj X := .of X forget₂.map f := Preord.ofHom f.hom /-- Constructs an equivalence between partial orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : PartOrd.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : PartOrd ⥤ PartOrd where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `PartOrd` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : PartOrd ≌ PartOrd where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end PartOrd theorem partOrd_dual_comp_forget_to_preord : PartOrd.dual ⋙ forget₂ PartOrd Preord = forget₂ PartOrd Preord ⋙ Preord.dual := rfl /-- `Antisymmetrization` as a functor. It is the free functor. -/ def preordToPartOrd : Preord.{u} ⥤ PartOrd where obj X := .of (Antisymmetrization X (· ≤ ·)) map f := PartOrd.ofHom f.hom.antisymmetrization map_id X := by ext x exact Quotient.inductionOn' x fun x => Quotient.map'_mk'' _ (fun a b => id) _ map_comp f g := by ext x exact Quotient.inductionOn' x fun x => OrderHom.antisymmetrization_apply_mk _ _ /-- `preordToPartOrd` is left adjoint to the forgetful functor, meaning it is the free functor from `Preord` to `PartOrd`. -/ def preordToPartOrdForgetAdjunction : preordToPartOrd.{u} ⊣ forget₂ PartOrd Preord := Adjunction.mkOfHomEquiv { homEquiv _ _ := { toFun f := Preord.ofHom ⟨f ∘ toAntisymmetrization (· ≤ ·), f.hom.mono.comp toAntisymmetrization_mono⟩ invFun f := PartOrd.ofHom ⟨fun a => Quotient.liftOn' a f (fun _ _ h => (AntisymmRel.image h f.hom.mono).eq), fun a b => Quotient.inductionOn₂' a b fun _ _ h => f.hom.mono h⟩ left_inv _ := PartOrd.ext fun x => Quotient.inductionOn' x fun _ => rfl } homEquiv_naturality_left_symm _ _ := PartOrd.ext fun x => Quotient.inductionOn' x fun _ => rfl } -- The `simpNF` linter would complain as `Functor.comp_obj`, `Preord.dual_obj` both apply to LHS -- of `preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd_hom_app_coe` /-- `PreordToPartOrd` and `OrderDual` commute. -/ @[simps! -isSimp hom_app_hom_coe inv_app_hom_coe] def preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd : preordToPartOrd.{u} ⋙ PartOrd.dual ≅ Preord.dual ⋙ preordToPartOrd := NatIso.ofComponents (fun _ => PartOrd.Iso.mk <| OrderIso.dualAntisymmetrization _) (fun _ => PartOrd.ext fun x => Quotient.inductionOn' x fun _ => rfl) -- `simp`-normal form for `preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd_inv_app_hom_coe` @[simp] lemma preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd_inv_app_hom_coe' (X) (a : preordToPartOrd.obj (Preord.dual.obj X)) : (PartOrd.Hom.hom (X := preordToPartOrd.obj (Preord.dual.obj X)) (Y := PartOrd.dual.obj (preordToPartOrd.obj X)) (preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd.inv.app X)) a = (OrderIso.dualAntisymmetrization ↑X).symm a := rfl
.lake/packages/mathlib/Mathlib/Order/Category/FinPartOrd.lean
import Mathlib.CategoryTheory.FintypeCat import Mathlib.Order.Category.PartOrd /-! # The category of finite partial orders This defines `FinPartOrd`, the category of finite partial orders. Note: `FinPartOrd` is *not* a subcategory of `BddOrd` because finite orders are not necessarily bounded. ## TODO `FinPartOrd` is equivalent to a small category. -/ universe u v open CategoryTheory /-- The category of finite partial orders with monotone functions. -/ structure FinPartOrd extends PartOrd where [isFintype : Fintype toPartOrd] namespace FinPartOrd instance : CoeSort FinPartOrd Type* := ⟨fun X => X.toPartOrd⟩ instance (X : FinPartOrd) : PartialOrder X := X.toPartOrd.str attribute [instance] FinPartOrd.isFintype /-- Construct a bundled `FinPartOrd` from `PartialOrder` + `Fintype`. -/ abbrev of (α : Type*) [PartialOrder α] [Fintype α] : FinPartOrd where carrier := α instance : Inhabited FinPartOrd := ⟨of PUnit⟩ instance largeCategory : LargeCategory FinPartOrd := InducedCategory.category FinPartOrd.toPartOrd instance concreteCategory : ConcreteCategory FinPartOrd (· →o ·) := InducedCategory.concreteCategory FinPartOrd.toPartOrd instance hasForgetToPartOrd : HasForget₂ FinPartOrd PartOrd := InducedCategory.hasForget₂ FinPartOrd.toPartOrd instance hasForgetToFintype : HasForget₂ FinPartOrd FintypeCat where forget₂.obj X := .of X forget₂.map f := f.hom /-- Typecheck a `OrderHom` as a morphism in `FinPartOrd`. -/ abbrev ofHom {X Y : Type u} [PartialOrder X] [Fintype X] [PartialOrder Y] [Fintype Y] (f : X →o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := FinPartOrd) f @[simp] lemma hom_id {X : FinPartOrd} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl /- Provided for rewriting. -/ lemma id_apply (X : FinPartOrd) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : FinPartOrd} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : FinPartOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : FinPartOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := ConcreteCategory.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [PartialOrder X] [Fintype X] [PartialOrder Y] [Fintype Y] (f : X →o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : FinPartOrd} (f : X ⟶ Y) : ofHom f.hom = f := rfl /-- Constructs an isomorphism of finite partial orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : FinPartOrd.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : FinPartOrd ⥤ FinPartOrd where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `FinPartOrd` and itself induced by `OrderDual` both ways. -/ @[simps] def dualEquiv : FinPartOrd ≌ FinPartOrd where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end FinPartOrd theorem FinPartOrd_dual_comp_forget_to_partOrd : FinPartOrd.dual ⋙ forget₂ FinPartOrd PartOrd = forget₂ FinPartOrd PartOrd ⋙ PartOrd.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/Lat.lean
import Mathlib.Order.Category.PartOrd import Mathlib.Order.Hom.Lattice /-! # The category of lattices This defines `Lat`, the category of lattices. Note that `Lat` doesn't correspond to the literature definition of [`Lat`] (https://ncatlab.org/nlab/show/Lat) as we don't require bottom or top elements. Instead, `Lat` corresponds to `BddLat`. ## TODO The free functor from `Lat` to `BddLat` is `X → WithTop (WithBot X)`. -/ universe u open CategoryTheory /-- The category of lattices. -/ structure Lat where /-- The underlying lattices. -/ (carrier : Type*) [str : Lattice carrier] attribute [instance] Lat.str initialize_simps_projections Lat (carrier → coe, -str) namespace Lat instance : CoeSort Lat (Type _) := ⟨Lat.carrier⟩ attribute [coe] Lat.carrier /-- Construct a bundled `Lat` from the underlying type and typeclass. -/ abbrev of (X : Type*) [Lattice X] : Lat := ⟨X⟩ /-- The type of morphisms in `Lat R`. -/ @[ext] structure Hom (X Y : Lat.{u}) where private mk :: /-- The underlying `LatticeHom`. -/ hom' : LatticeHom X Y instance : Category Lat.{u} where Hom X Y := Hom X Y id X := ⟨LatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory Lat (LatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `Lat` back into a `LatticeHom`. -/ abbrev Hom.hom {X Y : Lat.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := Lat) f /-- Typecheck a `LatticeHom` as a morphism in `Lat`. -/ abbrev ofHom {X Y : Type u} [Lattice X] [Lattice Y] (f : LatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := Lat) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : Lat.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : Lat} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : Lat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : Lat} (f : X ⟶ Y) : (forget Lat).map f = f := rfl @[ext] lemma ext {X Y : Lat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [Lattice X] : (Lat.of X : Type u) = X := rfl @[simp] lemma hom_id {X : Lat} : (𝟙 X : X ⟶ X).hom = LatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : Lat) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : Lat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : Lat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : Lat} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [Lattice X] [Lattice Y] (f : LatticeHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : Lat} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [Lattice X] : ofHom (LatticeHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [Lattice X] [Lattice Y] [Lattice Z] (f : LatticeHom X Y) (g : LatticeHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [Lattice X] [Lattice Y] (f : LatticeHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : Lat} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : Lat} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance hasForgetToPartOrd : HasForget₂ Lat PartOrd where forget₂.obj X := .of X forget₂.map f := PartOrd.ofHom f.hom /-- Constructs an isomorphism of lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : Lat.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : Lat ⥤ Lat where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `Lat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : Lat ≌ Lat where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end Lat theorem Lat_dual_comp_forget_to_partOrd : Lat.dual ⋙ forget₂ Lat PartOrd = forget₂ Lat PartOrd ⋙ PartOrd.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/HeytAlg.lean
import Mathlib.Order.Category.BddDistLat import Mathlib.Order.Heyting.Hom /-! # The category of Heyting algebras This file defines `HeytAlg`, the category of Heyting algebras. -/ universe u open CategoryTheory Opposite Order /-- The category of Heyting algebras. -/ structure HeytAlg where /-- The underlying Heyting algebra. -/ carrier : Type* [str : HeytingAlgebra carrier] attribute [instance] HeytAlg.str initialize_simps_projections HeytAlg (carrier → coe, -str) namespace HeytAlg instance : CoeSort HeytAlg (Type _) := ⟨HeytAlg.carrier⟩ attribute [coe] HeytAlg.carrier /-- Construct a bundled `HeytAlg` from the underlying type and typeclass. -/ abbrev of (X : Type*) [HeytingAlgebra X] : HeytAlg := ⟨X⟩ /-- The type of morphisms in `HeytAlg R`. -/ @[ext] structure Hom (X Y : HeytAlg.{u}) where private mk :: /-- The underlying `HeytingHom`. -/ hom' : HeytingHom X Y instance : Category HeytAlg.{u} where Hom X Y := Hom X Y id X := ⟨HeytingHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory HeytAlg (HeytingHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `HeytAlg` back into a `HeytingHom`. -/ abbrev Hom.hom {X Y : HeytAlg.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := HeytAlg) f /-- Typecheck a `HeytingHom` as a morphism in `HeytAlg`. -/ abbrev ofHom {X Y : Type u} [HeytingAlgebra X] [HeytingAlgebra Y] (f : HeytingHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := HeytAlg) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : HeytAlg.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : HeytAlg} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : HeytAlg} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : HeytAlg} (f : X ⟶ Y) : (forget HeytAlg).map f = f := rfl @[ext] lemma ext {X Y : HeytAlg} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [HeytingAlgebra X] : (HeytAlg.of X : Type u) = X := rfl @[simp] lemma hom_id {X : HeytAlg} : (𝟙 X : X ⟶ X).hom = HeytingHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : HeytAlg) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : HeytAlg} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : HeytAlg} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : HeytAlg} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [HeytingAlgebra X] [HeytingAlgebra Y] (f : HeytingHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : HeytAlg} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [HeytingAlgebra X] : ofHom (HeytingHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [HeytingAlgebra X] [HeytingAlgebra Y] [HeytingAlgebra Z] (f : HeytingHom X Y) (g : HeytingHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [HeytingAlgebra X] [HeytingAlgebra Y] (f : HeytingHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : HeytAlg} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : HeytAlg} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited HeytAlg := ⟨of PUnit⟩ @[simps] instance hasForgetToLat : HasForget₂ HeytAlg BddDistLat where forget₂.obj X := .of X forget₂.map f := BddDistLat.ofHom f.hom /-- Constructs an isomorphism of Heyting algebras from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : HeytAlg.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ end HeytAlg
.lake/packages/mathlib/Mathlib/Order/Category/NonemptyFinLinOrd.lean
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.Data.Fintype.Order import Mathlib.Data.Set.Subsingleton import Mathlib.Order.Category.FinPartOrd import Mathlib.Order.Category.LinOrd /-! # Nonempty finite linear orders This defines `NonemptyFinLinOrd`, the category of nonempty finite linear orders with monotone maps. This is the index category for simplicial objects. Note: `NonemptyFinLinOrd` is *not* a subcategory of `FinBddDistLat` because its morphisms do not preserve `⊥` and `⊤`. -/ universe u v open CategoryTheory CategoryTheory.Limits /-- The category of nonempty finite linear orders. -/ structure NonemptyFinLinOrd extends LinOrd where [nonempty : Nonempty carrier] [fintype : Fintype carrier] attribute [instance] NonemptyFinLinOrd.nonempty NonemptyFinLinOrd.fintype namespace NonemptyFinLinOrd instance : CoeSort NonemptyFinLinOrd (Type _) where coe X := X.carrier instance : LargeCategory NonemptyFinLinOrd := InducedCategory.category NonemptyFinLinOrd.toLinOrd instance : ConcreteCategory NonemptyFinLinOrd (· →o ·) := InducedCategory.concreteCategory NonemptyFinLinOrd.toLinOrd instance (X : NonemptyFinLinOrd) : BoundedOrder X := Fintype.toBoundedOrder X /-- Construct a bundled `NonemptyFinLinOrd` from the underlying type and typeclass. -/ abbrev of (α : Type*) [Nonempty α] [Fintype α] [LinearOrder α] : NonemptyFinLinOrd where carrier := α theorem coe_of (α : Type*) [Nonempty α] [Fintype α] [LinearOrder α] : ↥(of α) = α := rfl /-- Typecheck a `OrderHom` as a morphism in `NonemptyFinLinOrd`. -/ abbrev ofHom {X Y : Type u} [Nonempty X] [LinearOrder X] [Fintype X] [Nonempty Y] [LinearOrder Y] [Fintype Y] (f : X →o Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := NonemptyFinLinOrd) f @[simp] lemma hom_id {X : NonemptyFinLinOrd} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl /- Provided for rewriting. -/ lemma id_apply (X : NonemptyFinLinOrd) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : NonemptyFinLinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : NonemptyFinLinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : NonemptyFinLinOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := ConcreteCategory.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [Nonempty X] [LinearOrder X] [Fintype X] [Nonempty Y] [LinearOrder Y] [Fintype Y] (f : X →o Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : NonemptyFinLinOrd} (f : X ⟶ Y) : ofHom f.hom = f := rfl instance : Inhabited NonemptyFinLinOrd := ⟨of PUnit⟩ instance hasForgetToLinOrd : HasForget₂ NonemptyFinLinOrd LinOrd := InducedCategory.hasForget₂ _ instance hasForgetToFinPartOrd : HasForget₂ NonemptyFinLinOrd FinPartOrd where forget₂.obj X := .of X forget₂.map f := FinPartOrd.ofHom f.hom /-- Constructs an equivalence between nonempty finite linear orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : NonemptyFinLinOrd.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : NonemptyFinLinOrd ⥤ NonemptyFinLinOrd where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `NonemptyFinLinOrd` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : NonemptyFinLinOrd ≌ NonemptyFinLinOrd where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X theorem mono_iff_injective {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) : Mono f ↔ Function.Injective f := by refine ⟨?_, ConcreteCategory.mono_of_injective f⟩ intro _ a₁ a₂ h let X := of (ULift (Fin 1)) let g₁ : X ⟶ A := ofHom ⟨fun _ => a₁, fun _ _ _ => by rfl⟩ let g₂ : X ⟶ A := ofHom ⟨fun _ => a₂, fun _ _ _ => by rfl⟩ change g₁ (ULift.up (0 : Fin 1)) = g₂ (ULift.up (0 : Fin 1)) have eq : g₁ ≫ f = g₂ ≫ f := by ext exact h rw [cancel_mono] at eq rw [eq] theorem epi_iff_surjective {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) : Epi f ↔ Function.Surjective f := by constructor · intro dsimp only [Function.Surjective] by_contra! hf' rcases hf' with ⟨m, hm⟩ let Y := of (ULift (Fin 2)) let p₁ : B ⟶ Y := ofHom ⟨fun b => if b < m then ULift.up 0 else ULift.up 1, fun x₁ x₂ h => by simp only split_ifs with h₁ h₂ h₂ any_goals apply Fin.zero_le · exfalso exact h₁ (lt_of_le_of_lt h h₂) · rfl⟩ let p₂ : B ⟶ Y := ofHom ⟨fun b => if b ≤ m then ULift.up 0 else ULift.up 1, fun x₁ x₂ h => by simp only split_ifs with h₁ h₂ h₂ any_goals apply Fin.zero_le · exfalso exact h₁ (h.trans h₂) · rfl⟩ have h : p₁ m = p₂ m := by congr rw [← cancel_epi f] ext a : 3 simp only [p₁, p₂, hom_comp, OrderHom.comp_coe, Function.comp_apply, hom_ofHom] change ite _ _ _ = ite _ _ _ split_ifs with h₁ h₂ h₂ any_goals rfl · exfalso exact h₂ (le_of_lt h₁) · exfalso exact hm a (eq_of_le_of_not_lt h₂ h₁) simp [Y, p₁, p₂, ConcreteCategory.hom_ofHom] at h · intro h exact ConcreteCategory.epi_of_surjective f h instance : SplitEpiCategory NonemptyFinLinOrd.{u} := ⟨fun {X Y} f hf => by have H : ∀ y : Y, Nonempty (f ⁻¹' {y}) := by rw [epi_iff_surjective] at hf intro y exact Nonempty.intro ⟨(hf y).choose, (hf y).choose_spec⟩ let φ : Y → X := fun y => (H y).some.1 have hφ : ∀ y : Y, f (φ y) = y := fun y => (H y).some.2 refine IsSplitEpi.mk' ⟨ofHom ⟨φ, ?_⟩, ?_⟩ swap · ext b apply hφ · intro a b contrapose intro h simp only [not_le] at h ⊢ suffices b ≤ a by apply lt_of_le_of_ne this rintro rfl exfalso simp at h have H : f (φ b) ≤ f (φ a) := f.hom.monotone (le_of_lt h) simpa only [hφ] using H⟩ instance : HasStrongEpiMonoFactorisations NonemptyFinLinOrd.{u} := ⟨fun {X Y} f => by let I := of (Set.image f ⊤) let e : X ⟶ I := ofHom ⟨fun x => ⟨f x, ⟨x, by tauto⟩⟩, fun x₁ x₂ h => f.hom.monotone h⟩ let m : I ⟶ Y := ofHom ⟨fun y => y.1, by tauto⟩ haveI : Epi e := by rw [epi_iff_surjective] rintro ⟨_, y, h, rfl⟩ exact ⟨y, rfl⟩ haveI : StrongEpi e := strongEpi_of_epi e haveI : Mono m := ConcreteCategory.mono_of_injective _ (fun x y h => Subtype.ext h) exact ⟨⟨I, m, e, rfl⟩⟩⟩ end NonemptyFinLinOrd theorem nonemptyFinLinOrd_dual_comp_forget_to_linOrd : NonemptyFinLinOrd.dual ⋙ forget₂ NonemptyFinLinOrd LinOrd = forget₂ NonemptyFinLinOrd LinOrd ⋙ LinOrd.dual := rfl /-- The forgetful functor `NonemptyFinLinOrd ⥤ FinPartOrd` and `OrderDual` commute. -/ def nonemptyFinLinOrdDualCompForgetToFinPartOrd : NonemptyFinLinOrd.dual ⋙ forget₂ NonemptyFinLinOrd FinPartOrd ≅ forget₂ NonemptyFinLinOrd FinPartOrd ⋙ FinPartOrd.dual where hom.app X := FinPartOrd.ofHom OrderHom.id inv.app X := FinPartOrd.ofHom OrderHom.id /-- The generating arrow `i ⟶ i+1` in the category `Fin n` -/ def Fin.hom_succ {n} (i : Fin n) : i.castSucc ⟶ i.succ := homOfLE (Fin.castSucc_le_succ i)
.lake/packages/mathlib/Mathlib/Order/Category/OmegaCompletePartialOrder.lean
import Mathlib.Order.OmegaCompletePartialOrder import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.ConcreteCategory.Basic /-! # Category of types with an omega complete partial order In this file, we bundle the class `OmegaCompletePartialOrder` into a concrete category and prove that continuous functions also form an `OmegaCompletePartialOrder`. ## Main definitions * `ωCPO` * an instance of `Category` and `ConcreteCategory` -/ open CategoryTheory universe u v /-- The category of types with an omega complete partial order. -/ structure ωCPO : Type (u + 1) where /-- Construct a bundled ωCPO from the underlying type and typeclass. -/ of :: /-- The underlying type. -/ carrier : Type u [str : OmegaCompletePartialOrder carrier] attribute [instance] ωCPO.str namespace ωCPO open OmegaCompletePartialOrder instance : CoeSort ωCPO Type* := ⟨carrier⟩ theorem coe_of (α : Type*) [OmegaCompletePartialOrder α] : ↥(of α) = α := rfl instance : LargeCategory.{u} ωCPO where Hom X Y := ContinuousHom X Y id X := ContinuousHom.id comp f g := g.comp f instance : ConcreteCategory ωCPO (ContinuousHom · ·) where hom f := f ofHom f := f instance : Inhabited ωCPO := ⟨of PUnit⟩ section open CategoryTheory.Limits namespace HasProducts /-- The pi-type gives a cone for a product. -/ def product {J : Type v} (f : J → ωCPO.{v}) : Fan f := Fan.mk (of (∀ j, f j)) fun j => .mk (Pi.evalOrderHom j) fun _ => rfl /-- The pi-type is a limit cone for the product. -/ def isProduct (J : Type v) (f : J → ωCPO) : IsLimit (product f) where lift s := ⟨⟨fun t j => (s.π.app ⟨j⟩) t, fun _ _ h j => (s.π.app ⟨j⟩).monotone h⟩, fun x => funext fun j => (s.π.app ⟨j⟩).continuous x⟩ uniq s m w := by ext t; funext j -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): Originally `ext t j` change m t j = (s.π.app ⟨j⟩) t rw [← w ⟨j⟩] rfl fac _ _ := rfl instance (J : Type v) (f : J → ωCPO.{v}) : HasProduct f := HasLimit.mk ⟨_, isProduct _ f⟩ end HasProducts instance omegaCompletePartialOrderEqualizer {α β : Type*} [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β] (f g : α →𝒄 β) : OmegaCompletePartialOrder { a : α // f a = g a } := OmegaCompletePartialOrder.subtype _ fun c hc => by rw [f.continuous, g.continuous] congr 1 ext x apply hc _ ⟨_, rfl⟩ namespace HasEqualizers /-- The equalizer inclusion function as a `ContinuousHom`. -/ def equalizerι {α β : Type*} [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β] (f g : α →𝒄 β) : { a : α // f a = g a } →𝒄 α := .mk (OrderHom.Subtype.val _) fun _ => rfl /-- A construction of the equalizer fork. -/ def equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : Fork f g := Fork.ofι (P := ωCPO.of { a // f a = g a }) (equalizerι f g) (ContinuousHom.ext _ _ fun x => x.2) /-- The equalizer fork is a limit. -/ def isEqualizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : IsLimit (equalizer f g) := Fork.IsLimit.mk' _ fun s => ⟨{ toFun := fun x => ⟨s.ι x, by apply ContinuousHom.congr_fun s.condition⟩ monotone' := fun _ _ h => s.ι.monotone h map_ωSup' := fun x => Subtype.ext (s.ι.continuous x) }, by ext; rfl, fun hm => by ext x : 2; apply Subtype.ext ?_ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): Originally `ext` apply ContinuousHom.congr_fun hm⟩ end HasEqualizers instance : HasProducts.{v} ωCPO.{v} := fun _ => { has_limit := fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm } instance {X Y : ωCPO.{v}} (f g : X ⟶ Y) : HasLimit (parallelPair f g) := HasLimit.mk ⟨_, HasEqualizers.isEqualizer f g⟩ instance : HasEqualizers ωCPO.{v} := hasEqualizers_of_hasLimit_parallelPair _ instance : HasLimits ωCPO.{v} := has_limits_of_hasEqualizers_and_products end end ωCPO
.lake/packages/mathlib/Mathlib/Order/Category/CompleteLat.lean
import Mathlib.Order.Category.BddLat import Mathlib.Order.Hom.CompleteLattice /-! # The category of complete lattices This file defines `CompleteLat`, the category of complete lattices. -/ universe u open CategoryTheory /-- The category of complete lattices. -/ structure CompleteLat where /-- Construct a bundled `CompleteLat` from the underlying type and typeclass. -/ of :: /-- The underlying lattice. -/ (carrier : Type*) [str : CompleteLattice carrier] attribute [instance] CompleteLat.str initialize_simps_projections CompleteLat (carrier → coe, -str) namespace CompleteLat instance : CoeSort CompleteLat (Type _) := ⟨CompleteLat.carrier⟩ attribute [coe] CompleteLat.carrier theorem coe_of (α : Type*) [CompleteLattice α] : ↥(of α) = α := rfl instance : Inhabited CompleteLat := ⟨of PUnit⟩ instance : LargeCategory.{u} CompleteLat where Hom X Y := CompleteLatticeHom X Y id X := CompleteLatticeHom.id X comp f g := g.comp f instance : ConcreteCategory CompleteLat (CompleteLatticeHom · ·) where hom f := f ofHom f := f instance hasForgetToBddLat : HasForget₂ CompleteLat BddLat where forget₂.obj X := .of X forget₂.map f := BddLat.ofHom (CompleteLatticeHom.toBoundedLatticeHom f) /-- Constructs an isomorphism of complete lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : CompleteLat.{u}} (e : α ≃o β) : α ≅ β where hom := ConcreteCategory.ofHom e inv := ConcreteCategory.ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps map] def dual : CompleteLat ⥤ CompleteLat where obj X := of Xᵒᵈ map {_ _} := CompleteLatticeHom.dual /-- The equivalence between `CompleteLat` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : CompleteLat ≌ CompleteLat where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end CompleteLat theorem completeLat_dual_comp_forget_to_bddLat : CompleteLat.dual ⋙ forget₂ CompleteLat BddLat = forget₂ CompleteLat BddLat ⋙ BddLat.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/Semilat.lean
import Mathlib.Order.Category.PartOrd import Mathlib.Order.Hom.BoundedLattice /-! # The categories of semilattices This defines `SemilatSupCat` and `SemilatInfCat`, the categories of sup-semilattices with a bottom element and inf-semilattices with a top element. ## References * [nLab, *semilattice*](https://ncatlab.org/nlab/show/semilattice) -/ universe u open CategoryTheory /-- The category of sup-semilattices with a bottom element. -/ structure SemilatSupCat : Type (u + 1) where /-- Construct a bundled `SemilatSupCat` from a `SemilatticeSup`. -/ of :: /-- The underlying type of a sup-semilattice with a bottom element. -/ protected X : Type u [isSemilatticeSup : SemilatticeSup X] [isOrderBot : OrderBot.{u} X] /-- The category of inf-semilattices with a top element. -/ structure SemilatInfCat : Type (u + 1) where /-- Construct a bundled `SemilatInfCat` from a `SemilatticeInf`. -/ of :: /-- The underlying type of an inf-semilattice with a top element. -/ protected X : Type u [isSemilatticeInf : SemilatticeInf X] [isOrderTop : OrderTop.{u} X] namespace SemilatSupCat instance : CoeSort SemilatSupCat Type* := ⟨SemilatSupCat.X⟩ attribute [instance] isSemilatticeSup isOrderBot theorem coe_of (α : Type*) [SemilatticeSup α] [OrderBot α] : ↥(of α) = α := rfl instance : Inhabited SemilatSupCat := ⟨of PUnit⟩ instance : LargeCategory.{u} SemilatSupCat where Hom X Y := SupBotHom X Y id X := SupBotHom.id X comp f g := g.comp f id_comp := SupBotHom.comp_id comp_id := SupBotHom.id_comp assoc _ _ _ := SupBotHom.comp_assoc _ _ _ instance : ConcreteCategory SemilatSupCat (SupBotHom · ·) where hom f := f ofHom f := f instance hasForgetToPartOrd : HasForget₂ SemilatSupCat PartOrd where forget₂.obj X := .of X forget₂.map f := PartOrd.ofHom ⟨f.toSupHom, OrderHomClass.mono f.toSupHom⟩ @[simp] theorem coe_forget_to_partOrd (X : SemilatSupCat) : ↥((forget₂ SemilatSupCat PartOrd).obj X) = ↥X := rfl end SemilatSupCat namespace SemilatInfCat instance : CoeSort SemilatInfCat Type* := ⟨SemilatInfCat.X⟩ attribute [instance] isSemilatticeInf isOrderTop theorem coe_of (α : Type*) [SemilatticeInf α] [OrderTop α] : ↥(of α) = α := rfl instance : Inhabited SemilatInfCat := ⟨of PUnit⟩ instance : LargeCategory.{u} SemilatInfCat where Hom X Y := InfTopHom X Y id X := InfTopHom.id X comp f g := g.comp f id_comp := InfTopHom.comp_id comp_id := InfTopHom.id_comp assoc _ _ _ := InfTopHom.comp_assoc _ _ _ instance : ConcreteCategory SemilatInfCat (InfTopHom · ·) where hom f := f ofHom f := f instance hasForgetToPartOrd : HasForget₂ SemilatInfCat PartOrd where forget₂.obj X := .of X forget₂.map f := PartOrd.ofHom ⟨f.toInfHom, OrderHomClass.mono f.toInfHom⟩ @[simp] theorem coe_forget_to_partOrd (X : SemilatInfCat) : ↥((forget₂ SemilatInfCat PartOrd).obj X) = ↥X := rfl end SemilatInfCat /-! ### Order dual -/ namespace SemilatSupCat /-- Constructs an isomorphism of lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : SemilatSupCat.{u}} (e : α ≃o β) : α ≅ β where hom := (e : SupBotHom _ _) inv := (e.symm : SupBotHom _ _) hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps map] def dual : SemilatSupCat ⥤ SemilatInfCat where obj X := .of Xᵒᵈ map {_ _} := SupBotHom.dual end SemilatSupCat namespace SemilatInfCat /-- Constructs an isomorphism of lattices from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : SemilatInfCat.{u}} (e : α ≃o β) : α ≅ β where hom := (e : InfTopHom _ _) inv := (e.symm : InfTopHom _ _) hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps] def dual : SemilatInfCat ⥤ SemilatSupCat where obj X := .of Xᵒᵈ map {_ _} := InfTopHom.dual end SemilatInfCat /-- The equivalence between `SemilatSupCat` and `SemilatInfCat` induced by `OrderDual` both ways. -/ @[simps functor inverse] def SemilatSupCatEquivSemilatInfCat : SemilatSupCat ≌ SemilatInfCat where functor := SemilatSupCat.dual inverse := SemilatInfCat.dual unitIso := NatIso.ofComponents fun X => SemilatSupCat.Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => SemilatInfCat.Iso.mk <| OrderIso.dualDual X theorem SemilatSupCat_dual_comp_forget_to_partOrd : SemilatSupCat.dual ⋙ forget₂ SemilatInfCat PartOrd = forget₂ SemilatSupCat PartOrd ⋙ PartOrd.dual := rfl theorem SemilatInfCat_dual_comp_forget_to_partOrd : SemilatInfCat.dual ⋙ forget₂ SemilatSupCat PartOrd = forget₂ SemilatInfCat PartOrd ⋙ PartOrd.dual := rfl
.lake/packages/mathlib/Mathlib/Order/Category/BddOrd.lean
import Mathlib.CategoryTheory.Category.Bipointed import Mathlib.Order.Category.PartOrd import Mathlib.Order.Hom.Bounded /-! # The category of bounded orders This defines `BddOrd`, the category of bounded orders. -/ universe u v open CategoryTheory /-- The category of bounded orders with monotone functions. -/ structure BddOrd extends PartOrd where [isBoundedOrder : BoundedOrder toPartOrd] /-- The underlying object in the category of partial orders. -/ add_decl_doc BddOrd.toPartOrd attribute [instance] BddOrd.isBoundedOrder initialize_simps_projections BddOrd (carrier → coe, -str) namespace BddOrd instance : CoeSort BddOrd Type* := InducedCategory.hasCoeToSort toPartOrd /-- Construct a bundled `BddOrd` from the underlying type and typeclass. -/ abbrev of (X : Type*) [PartialOrder X] [BoundedOrder X] : BddOrd where carrier := X /-- The type of morphisms in `BddOrd R`. -/ @[ext] structure Hom (X Y : BddOrd.{u}) where private mk :: /-- The underlying `BoundedOrderHom`. -/ hom' : BoundedOrderHom X Y instance : Category BddOrd.{u} where Hom X Y := Hom X Y id _ := ⟨BoundedOrderHom.id _⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory BddOrd (BoundedOrderHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `BddOrd` back into a `BoundedOrderHom`. -/ abbrev Hom.hom {X Y : BddOrd.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := BddOrd) f /-- Typecheck a `BoundedOrderHom` as a morphism in `BddOrd`. -/ abbrev ofHom {X Y : Type u} [PartialOrder X] [BoundedOrder X] [PartialOrder Y] [BoundedOrder Y] (f : BoundedOrderHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := BddOrd) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : BddOrd.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : BddOrd} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : BddOrd} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : BddOrd} (f : X ⟶ Y) : (forget BddOrd).map f = f := rfl @[ext] lemma ext {X Y : BddOrd} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [PartialOrder X] [BoundedOrder X] : (BddOrd.of X : Type u) = X := rfl @[simp] lemma hom_id {X : BddOrd} : (𝟙 X : X ⟶ X).hom = BoundedOrderHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : BddOrd) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : BddOrd} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : BddOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : BddOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [PartialOrder X] [BoundedOrder X] [PartialOrder Y] [BoundedOrder Y] (f : BoundedOrderHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : BddOrd} (f : X ⟶ Y) : ofHom f.hom = f := rfl @[simp] lemma ofHom_id {X : Type u} [PartialOrder X] [BoundedOrder X] : ofHom (BoundedOrderHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [PartialOrder X] [BoundedOrder X] [PartialOrder Y] [BoundedOrder Y] [PartialOrder Z] [BoundedOrder Z] (f : BoundedOrderHom X Y) (g : BoundedOrderHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [PartialOrder X] [BoundedOrder X] [PartialOrder Y] [BoundedOrder Y] (f : BoundedOrderHom X Y) (x : X) : ofHom f x = f x := rfl lemma inv_hom_apply {X Y : BddOrd} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : BddOrd} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited BddOrd := ⟨of PUnit⟩ instance hasForgetToPartOrd : HasForget₂ BddOrd PartOrd where forget₂.obj X := X.toPartOrd forget₂.map f := PartOrd.ofHom f.hom.toOrderHom instance hasForgetToBipointed : HasForget₂ BddOrd Bipointed where forget₂ := { obj := fun X => ⟨X, ⊥, ⊤⟩ map := fun f => ⟨f, f.hom.map_bot', f.hom.map_top'⟩ } forget_comp := rfl /-- `OrderDual` as a functor. -/ @[simps map] def dual : BddOrd ⥤ BddOrd where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- Constructs an equivalence between bounded orders from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : BddOrd.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- The equivalence between `BddOrd` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : BddOrd ≌ BddOrd where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end BddOrd theorem bddOrd_dual_comp_forget_to_partOrd : BddOrd.dual ⋙ forget₂ BddOrd PartOrd = forget₂ BddOrd PartOrd ⋙ PartOrd.dual := rfl theorem bddOrd_dual_comp_forget_to_bipointed : BddOrd.dual ⋙ forget₂ BddOrd Bipointed = forget₂ BddOrd Bipointed ⋙ Bipointed.swap := rfl
.lake/packages/mathlib/Mathlib/Order/Category/BoolAlg.lean
import Mathlib.Order.Category.HeytAlg import Mathlib.Order.Hom.CompleteLattice /-! # The category of Boolean algebras This defines `BoolAlg`, the category of Boolean algebras. -/ open OrderDual Opposite Set universe u open CategoryTheory /-- The category of Boolean algebras. -/ structure BoolAlg where /-- Construct a bundled `BoolAlg` from the underlying type and typeclass. -/ of :: /-- The underlying Boolean algebra. -/ carrier : Type* [str : BooleanAlgebra carrier] attribute [instance] BoolAlg.str initialize_simps_projections BoolAlg (carrier → coe, -str) namespace BoolAlg instance : CoeSort BoolAlg (Type _) := ⟨BoolAlg.carrier⟩ attribute [coe] BoolAlg.carrier /-- The type of morphisms in `BoolAlg R`. -/ @[ext] structure Hom (X Y : BoolAlg.{u}) where private mk :: /-- The underlying `BoundedLatticeHom`. -/ hom' : BoundedLatticeHom X Y instance : Category BoolAlg.{u} where Hom X Y := Hom X Y id X := ⟨BoundedLatticeHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory BoolAlg (BoundedLatticeHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `BoolAlg` back into a `BoundedLatticeHom`. -/ abbrev Hom.hom {X Y : BoolAlg.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := BoolAlg) f /-- Typecheck a `BoundedLatticeHom` as a morphism in `BoolAlg`. -/ abbrev ofHom {X Y : Type u} [BooleanAlgebra X] [BooleanAlgebra Y] (f : BoundedLatticeHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := BoolAlg) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : BoolAlg.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : BoolAlg} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : BoolAlg} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : BoolAlg} (f : X ⟶ Y) : (forget BoolAlg).map f = f := rfl @[ext] lemma ext {X Y : BoolAlg} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [BooleanAlgebra X] : (BoolAlg.of X : Type u) = X := rfl @[simp] lemma hom_id {X : BoolAlg} : (𝟙 X : X ⟶ X).hom = BoundedLatticeHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : BoolAlg) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : BoolAlg} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : BoolAlg} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : BoolAlg} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [BooleanAlgebra X] [BooleanAlgebra Y] (f : BoundedLatticeHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : BoolAlg} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [BooleanAlgebra X] : ofHom (BoundedLatticeHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [BooleanAlgebra X] [BooleanAlgebra Y] [BooleanAlgebra Z] (f : BoundedLatticeHom X Y) (g : BoundedLatticeHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [BooleanAlgebra X] [BooleanAlgebra Y] (f : BoundedLatticeHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : BoolAlg} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : BoolAlg} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited BoolAlg := ⟨of PUnit⟩ /-- Turn a `BoolAlg` into a `BddDistLat` by forgetting its complement operation. -/ def toBddDistLat (X : BoolAlg) : BddDistLat := .of X @[simp] theorem coe_toBddDistLat (X : BoolAlg) : ↥X.toBddDistLat = ↥X := rfl instance hasForgetToBddDistLat : HasForget₂ BoolAlg BddDistLat where forget₂.obj X := .of X forget₂.map f := BddDistLat.ofHom f.hom section attribute [local instance] BoundedLatticeHomClass.toBiheytingHomClass @[simps] instance hasForgetToHeytAlg : HasForget₂ BoolAlg HeytAlg where forget₂.obj X := .of X forget₂.map {X Y} f := HeytAlg.ofHom f.hom end /-- Constructs an equivalence between Boolean algebras from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : BoolAlg.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm /-- `OrderDual` as a functor. -/ @[simps map] def dual : BoolAlg ⥤ BoolAlg where obj X := of Xᵒᵈ map f := ofHom f.hom.dual /-- The equivalence between `BoolAlg` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : BoolAlg ≌ BoolAlg where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end BoolAlg theorem boolAlg_dual_comp_forget_to_bddDistLat : BoolAlg.dual ⋙ forget₂ BoolAlg BddDistLat = forget₂ BoolAlg BddDistLat ⋙ BddDistLat.dual := rfl /-- The powerset functor. `Set` as a contravariant functor. -/ @[simps] def typeToBoolAlgOp : Type u ⥤ BoolAlgᵒᵖ where obj X := op <| .of (Set X) map {X Y} f := Quiver.Hom.op (BoolAlg.ofHom (CompleteLatticeHom.setPreimage f))
.lake/packages/mathlib/Mathlib/Order/Category/Frm.lean
import Mathlib.Order.Category.Lat import Mathlib.Order.Hom.CompleteLattice import Mathlib.CategoryTheory.ConcreteCategory.Bundled /-! # The category of frames This file defines `Frm`, the category of frames. ## References * [nLab, *Frm*](https://ncatlab.org/nlab/show/Frm) -/ universe u open CategoryTheory Order /-- The category of frames. -/ structure Frm where /-- Construct a bundled `Frm` from the underlying type and typeclass. -/ of :: /-- The underlying frame. -/ (carrier : Type*) [str : Frame carrier] attribute [instance] Frm.str initialize_simps_projections Frm (carrier → coe, -str) namespace Frm instance : CoeSort Frm (Type _) := ⟨Frm.carrier⟩ attribute [coe] Frm.carrier /-- The type of morphisms in `Frm R`. -/ @[ext] structure Hom (X Y : Frm.{u}) where private mk :: /-- The underlying `FrameHom`. -/ hom' : FrameHom X Y instance : Category Frm.{u} where Hom X Y := Hom X Y id X := ⟨FrameHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory Frm (FrameHom · ·) where hom := Hom.hom' ofHom := Hom.mk /-- Turn a morphism in `Frm` back into a `FrameHom`. -/ abbrev Hom.hom {X Y : Frm.{u}} (f : Hom X Y) := ConcreteCategory.hom (C := Frm) f /-- Typecheck a `FrameHom` as a morphism in `Frm`. -/ abbrev ofHom {X Y : Type u} [Frame X] [Frame Y] (f : FrameHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom (C := Frm) f variable {R} in /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (X Y : Frm.{u}) (f : Hom X Y) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[simp] lemma coe_id {X : Frm} : (𝟙 X : X → X) = id := rfl @[simp] lemma coe_comp {X Y Z : Frm} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : Frm} (f : X ⟶ Y) : (forget Frm).map f = f := rfl @[ext] lemma ext {X Y : Frm} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g := ConcreteCategory.hom_ext _ _ w -- This is not `simp` to avoid rewriting in types of terms. theorem coe_of (X : Type u) [Frame X] : (Frm.of X : Type u) = X := rfl @[simp] lemma hom_id {X : Frm} : (𝟙 X : X ⟶ X).hom = FrameHom.id _ := rfl /- Provided for rewriting. -/ lemma id_apply (X : Frm) (x : X) : (𝟙 X : X ⟶ X) x = x := by simp @[simp] lemma hom_comp {X Y Z : Frm} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {X Y Z : Frm} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp @[ext] lemma hom_ext {X Y : Frm} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {X Y : Type u} [Frame X] [Frame Y] (f : FrameHom X Y) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {X Y : Frm} (f : X ⟶ Y) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {X : Type u} [Frame X] : ofHom (FrameHom.id _) = 𝟙 (of X) := rfl @[simp] lemma ofHom_comp {X Y Z : Type u} [Frame X] [Frame Y] [Frame Z] (f : FrameHom X Y) (g : FrameHom Y Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {X Y : Type u} [Frame X] [Frame Y] (f : FrameHom X Y) (x : X) : (ofHom f) x = f x := rfl lemma inv_hom_apply {X Y : Frm} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp lemma hom_inv_apply {X Y : Frm} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by simp instance : Inhabited Frm := ⟨of PUnit⟩ instance hasForgetToLat : HasForget₂ Frm Lat where forget₂.obj X := .of X forget₂.map f := Lat.ofHom f.hom /-- Constructs an isomorphism of frames from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : Frm.{u}} (e : α ≃o β) : α ≅ β where hom := ofHom e inv := ofHom e.symm end Frm
.lake/packages/mathlib/Mathlib/Order/Category/FinBoolAlg.lean
import Mathlib.Data.Fintype.Powerset import Mathlib.Order.Category.BoolAlg import Mathlib.Order.Category.FinBddDistLat import Mathlib.Order.Hom.CompleteLattice import Mathlib.Tactic.ApplyFun import Mathlib.Data.Set.Subsingleton /-! # The category of finite Boolean algebras This file defines `FinBoolAlg`, the category of finite Boolean algebras. ## TODO Birkhoff's representation for finite Boolean algebras. ``` FintypeCat_to_FinBoolAlg_op.left_op ⋙ FinBoolAlg.dual ≅ FintypeCat_to_FinBoolAlg_op.left_op ``` `FinBoolAlg` is essentially small. -/ universe u open CategoryTheory OrderDual Opposite /-- The category of finite Boolean algebras with bounded lattice morphisms. -/ structure FinBoolAlg extends BoolAlg where [isFintype : Fintype toBoolAlg] attribute [instance] FinBoolAlg.isFintype namespace FinBoolAlg instance : CoeSort FinBoolAlg Type* := ⟨fun X => X.carrier⟩ /-- Construct a bundled `FinBoolAlg` from `BooleanAlgebra` + `Fintype`. -/ abbrev of (α : Type*) [BooleanAlgebra α] [Fintype α] : FinBoolAlg where carrier := α theorem coe_of (α : Type*) [BooleanAlgebra α] [Fintype α] : ↥(of α) = α := rfl instance : Inhabited FinBoolAlg := ⟨of PUnit⟩ instance largeCategory : LargeCategory FinBoolAlg := InducedCategory.category FinBoolAlg.toBoolAlg instance concreteCategory : ConcreteCategory FinBoolAlg (BoundedLatticeHom · ·) := InducedCategory.concreteCategory FinBoolAlg.toBoolAlg instance hasForgetToBoolAlg : HasForget₂ FinBoolAlg BoolAlg := InducedCategory.hasForget₂ FinBoolAlg.toBoolAlg instance hasForgetToFinBddDistLat : HasForget₂ FinBoolAlg FinBddDistLat where forget₂.obj X := .of X forget₂.map f := FinBddDistLat.ofHom f.hom instance forgetToBoolAlg_full : (forget₂ FinBoolAlg BoolAlg).Full := InducedCategory.full _ instance forgetToBoolAlgFaithful : (forget₂ FinBoolAlg BoolAlg).Faithful := InducedCategory.faithful _ @[simps] instance hasForgetToFinPartOrd : HasForget₂ FinBoolAlg FinPartOrd where forget₂.obj X := .of X forget₂.map {X Y} f := PartOrd.ofHom f.hom instance forgetToFinPartOrdFaithful : (forget₂ FinBoolAlg FinPartOrd).Faithful where map_injective h := by ext x exact CategoryTheory.congr_fun h x /-- Constructs an equivalence between finite Boolean algebras from an order isomorphism between them. -/ @[simps] def Iso.mk {α β : FinBoolAlg.{u}} (e : α ≃o β) : α ≅ β where hom := BoolAlg.ofHom e inv := BoolAlg.ofHom e.symm hom_inv_id := by ext; exact e.symm_apply_apply _ inv_hom_id := by ext; exact e.apply_symm_apply _ /-- `OrderDual` as a functor. -/ @[simps map] def dual : FinBoolAlg ⥤ FinBoolAlg where obj X := of Xᵒᵈ map f := BoolAlg.ofHom f.hom.dual /-- The equivalence between `FinBoolAlg` and itself induced by `OrderDual` both ways. -/ @[simps functor inverse] def dualEquiv : FinBoolAlg ≌ FinBoolAlg where functor := dual inverse := dual unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X end FinBoolAlg theorem finBoolAlg_dual_comp_forget_to_finBddDistLat : FinBoolAlg.dual ⋙ forget₂ FinBoolAlg FinBddDistLat = forget₂ FinBoolAlg FinBddDistLat ⋙ FinBddDistLat.dual := rfl /-- The powerset functor. `Set` as a functor. -/ @[simps] def fintypeToFinBoolAlgOp : FintypeCat ⥤ FinBoolAlgᵒᵖ where obj X := op <| .of (Set X) map {X Y} f := Quiver.Hom.op <| BoolAlg.ofHom <| CompleteLatticeHom.setPreimage f
.lake/packages/mathlib/Mathlib/Order/SuccPred/Limit.lean
import Mathlib.Order.SuccPred.Archimedean import Mathlib.Order.BoundedOrder.Lattice /-! # Successor and predecessor limits We define the predicate `Order.IsSuccPrelimit` for "successor pre-limits", values that don't cover any others. They are so named since they can't be the successors of anything smaller. We define `Order.IsPredPrelimit` analogously, and prove basic results. For some applications, it is desirable to exclude minimal elements from being successor limits, or maximal elements from being predecessor limits. As such, we also provide `Order.IsSuccLimit` and `Order.IsPredLimit`, which exclude these cases. -/ variable {α : Type*} {a b : α} namespace Order open Function Set OrderDual /-! ### Successor limits -/ section LT variable [LT α] /-- A successor pre-limit is a value that doesn't cover any other. It's so named because in a successor order, a successor pre-limit can't be the successor of anything smaller. Use `IsSuccLimit` if you want to exclude the case of a minimal element. -/ def IsSuccPrelimit (a : α) : Prop := ∀ b, ¬b ⋖ a theorem not_isSuccPrelimit_iff_exists_covBy (a : α) : ¬IsSuccPrelimit a ↔ ∃ b, b ⋖ a := by simp [IsSuccPrelimit] @[simp] theorem IsSuccPrelimit.of_dense [DenselyOrdered α] (a : α) : IsSuccPrelimit a := fun _ => not_covBy end LT section Preorder variable [Preorder α] /-- A successor limit is a value that isn't minimal and doesn't cover any other. It's so named because in a successor order, a successor limit can't be the successor of anything smaller. This previously allowed the element to be minimal. This usage is now covered by `IsSuccPrelimit`. -/ def IsSuccLimit (a : α) : Prop := ¬ IsMin a ∧ IsSuccPrelimit a protected theorem IsSuccLimit.not_isMin (h : IsSuccLimit a) : ¬ IsMin a := h.1 protected theorem IsSuccLimit.isSuccPrelimit (h : IsSuccLimit a) : IsSuccPrelimit a := h.2 theorem IsSuccPrelimit.isSuccLimit_of_not_isMin (h : IsSuccPrelimit a) (ha : ¬ IsMin a) : IsSuccLimit a := ⟨ha, h⟩ theorem IsSuccPrelimit.isSuccLimit [NoMinOrder α] (h : IsSuccPrelimit a) : IsSuccLimit a := h.isSuccLimit_of_not_isMin (not_isMin a) theorem isSuccPrelimit_iff_isSuccLimit_of_not_isMin (h : ¬ IsMin a) : IsSuccPrelimit a ↔ IsSuccLimit a := ⟨fun ha ↦ ha.isSuccLimit_of_not_isMin h, IsSuccLimit.isSuccPrelimit⟩ theorem isSuccPrelimit_iff_isSuccLimit [NoMinOrder α] : IsSuccPrelimit a ↔ IsSuccLimit a := isSuccPrelimit_iff_isSuccLimit_of_not_isMin (not_isMin a) protected theorem _root_.IsMin.not_isSuccLimit (h : IsMin a) : ¬ IsSuccLimit a := fun ha ↦ ha.not_isMin h protected theorem _root_.IsMin.isSuccPrelimit : IsMin a → IsSuccPrelimit a := fun h _ hab => not_isMin_of_lt hab.lt h theorem IsSuccLimit.nonempty_Iio (h : IsSuccLimit a) : (Set.Iio a).Nonempty := not_isMin_iff.1 h.1 theorem isSuccPrelimit_bot [OrderBot α] : IsSuccPrelimit (⊥ : α) := isMin_bot.isSuccPrelimit theorem not_isSuccLimit_bot [OrderBot α] : ¬ IsSuccLimit (⊥ : α) := isMin_bot.not_isSuccLimit theorem IsSuccLimit.ne_bot [OrderBot α] (h : IsSuccLimit a) : a ≠ ⊥ := by rintro rfl exact not_isSuccLimit_bot h theorem not_isSuccLimit_iff : ¬ IsSuccLimit a ↔ IsMin a ∨ ¬ IsSuccPrelimit a := by rw [IsSuccLimit, not_and_or, not_not] variable [SuccOrder α] protected theorem IsSuccPrelimit.isMax (h : IsSuccPrelimit (succ a)) : IsMax a := by by_contra H exact h a (covBy_succ_of_not_isMax H) protected theorem IsSuccLimit.isMax (h : IsSuccLimit (succ a)) : IsMax a := h.isSuccPrelimit.isMax theorem not_isSuccPrelimit_succ_of_not_isMax (ha : ¬ IsMax a) : ¬ IsSuccPrelimit (succ a) := mt IsSuccPrelimit.isMax ha theorem not_isSuccLimit_succ_of_not_isMax (ha : ¬ IsMax a) : ¬ IsSuccLimit (succ a) := mt IsSuccLimit.isMax ha /-- Given `j < i` with `i` a prelimit, `IsSuccPrelimit.mid` picks an arbitrary element strictly between `j` and `i`. -/ noncomputable def IsSuccPrelimit.mid {i j : α} (hi : IsSuccPrelimit i) (hj : j < i) : Ioo j i := Classical.indefiniteDescription _ ((not_covBy_iff hj).mp <| hi j) section NoMaxOrder variable [NoMaxOrder α] theorem IsSuccPrelimit.succ_ne (h : IsSuccPrelimit a) (b : α) : succ b ≠ a := by rintro rfl exact not_isMax _ h.isMax theorem IsSuccLimit.succ_ne (h : IsSuccLimit a) (b : α) : succ b ≠ a := h.isSuccPrelimit.succ_ne b @[simp] theorem not_isSuccPrelimit_succ (a : α) : ¬IsSuccPrelimit (succ a) := fun h => h.succ_ne _ rfl @[simp] theorem not_isSuccLimit_succ (a : α) : ¬IsSuccLimit (succ a) := fun h => h.succ_ne _ rfl end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] [NoMaxOrder α] theorem IsSuccPrelimit.isMin_of_noMax (h : IsSuccPrelimit a) : IsMin a := by intro b hb rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩ · exact le_rfl · rw [iterate_succ_apply'] at h exact (not_isSuccPrelimit_succ _ h).elim @[simp] theorem isSuccPrelimit_iff_of_noMax : IsSuccPrelimit a ↔ IsMin a := ⟨IsSuccPrelimit.isMin_of_noMax, IsMin.isSuccPrelimit⟩ @[simp] theorem not_isSuccLimit_of_noMax : ¬ IsSuccLimit a := fun h ↦ h.not_isMin h.isSuccPrelimit.isMin_of_noMax theorem not_isSuccPrelimit_of_noMax [NoMinOrder α] : ¬ IsSuccPrelimit a := by simp end IsSuccArchimedean end Preorder section PartialOrder variable [PartialOrder α] theorem isSuccLimit_iff [OrderBot α] : IsSuccLimit a ↔ a ≠ ⊥ ∧ IsSuccPrelimit a := by rw [IsSuccLimit, isMin_iff_eq_bot] theorem IsSuccLimit.bot_lt [OrderBot α] (h : IsSuccLimit a) : ⊥ < a := h.ne_bot.bot_lt variable [SuccOrder α] theorem isSuccPrelimit_of_succ_ne (h : ∀ b, succ b ≠ a) : IsSuccPrelimit a := fun b hba => h b (CovBy.succ_eq hba) theorem not_isSuccPrelimit_iff : ¬ IsSuccPrelimit a ↔ ∃ b, ¬ IsMax b ∧ succ b = a := by rw [not_isSuccPrelimit_iff_exists_covBy] refine exists_congr fun b => ⟨fun hba => ⟨hba.lt.not_isMax, (CovBy.succ_eq hba)⟩, ?_⟩ rintro ⟨h, rfl⟩ exact covBy_succ_of_not_isMax h /-- See `not_isSuccPrelimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_succ_of_not_isSuccPrelimit (h : ¬ IsSuccPrelimit a) : a ∈ range (succ : α → α) := by obtain ⟨b, hb⟩ := not_isSuccPrelimit_iff.1 h exact ⟨b, hb.2⟩ theorem mem_range_succ_or_isSuccPrelimit (a) : a ∈ range (succ : α → α) ∨ IsSuccPrelimit a := or_iff_not_imp_right.2 <| mem_range_succ_of_not_isSuccPrelimit theorem isMin_or_mem_range_succ_or_isSuccLimit (a) : IsMin a ∨ a ∈ range (succ : α → α) ∨ IsSuccLimit a := by rw [IsSuccLimit] have := mem_range_succ_or_isSuccPrelimit a tauto theorem isSuccPrelimit_of_succ_lt (H : ∀ a < b, succ a < b) : IsSuccPrelimit b := fun a hab => (H a hab.lt).ne (CovBy.succ_eq hab) theorem IsSuccPrelimit.succ_lt (hb : IsSuccPrelimit b) (ha : a < b) : succ a < b := by by_cases h : IsMax a · rwa [h.succ_eq] · rw [lt_iff_le_and_ne, succ_le_iff_of_not_isMax h] refine ⟨ha, fun hab => ?_⟩ subst hab exact (h hb.isMax).elim theorem IsSuccLimit.succ_lt (hb : IsSuccLimit b) (ha : a < b) : succ a < b := hb.isSuccPrelimit.succ_lt ha theorem IsSuccPrelimit.succ_lt_iff (hb : IsSuccPrelimit b) : succ a < b ↔ a < b := ⟨fun h => (le_succ a).trans_lt h, hb.succ_lt⟩ theorem IsSuccLimit.succ_lt_iff (hb : IsSuccLimit b) : succ a < b ↔ a < b := hb.isSuccPrelimit.succ_lt_iff theorem isSuccPrelimit_iff_succ_lt : IsSuccPrelimit b ↔ ∀ a < b, succ a < b := ⟨fun hb _ => hb.succ_lt, isSuccPrelimit_of_succ_lt⟩ section NoMaxOrder variable [NoMaxOrder α] theorem isSuccPrelimit_iff_succ_ne : IsSuccPrelimit a ↔ ∀ b, succ b ≠ a := ⟨IsSuccPrelimit.succ_ne, isSuccPrelimit_of_succ_ne⟩ theorem not_isSuccPrelimit_iff' : ¬ IsSuccPrelimit a ↔ a ∈ range (succ : α → α) := by simp_rw [isSuccPrelimit_iff_succ_ne, not_forall, not_ne_iff, mem_range] end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] protected theorem IsSuccPrelimit.isMin (h : IsSuccPrelimit a) : IsMin a := fun b hb => by revert h refine Succ.rec (fun _ => le_rfl) (fun c _ H hc => ?_) hb have := hc.isMax.succ_eq rw [this] at hc ⊢ exact H hc @[simp] theorem isSuccPrelimit_iff : IsSuccPrelimit a ↔ IsMin a := ⟨IsSuccPrelimit.isMin, IsMin.isSuccPrelimit⟩ @[simp] theorem not_isSuccLimit : ¬ IsSuccLimit a := fun h ↦ h.not_isMin <| h.isSuccPrelimit.isMin theorem not_isSuccPrelimit [NoMinOrder α] : ¬ IsSuccPrelimit a := by simp end IsSuccArchimedean end PartialOrder section LinearOrder variable [LinearOrder α] theorem IsSuccPrelimit.le_iff_forall_le (h : IsSuccPrelimit a) : a ≤ b ↔ ∀ c < a, c ≤ b := by use fun ha c hc ↦ hc.le.trans ha intro H by_contra! ha exact h b ⟨ha, fun c hb hc ↦ (H c hc).not_gt hb⟩ theorem IsSuccLimit.le_iff_forall_le (h : IsSuccLimit a) : a ≤ b ↔ ∀ c < a, c ≤ b := h.isSuccPrelimit.le_iff_forall_le theorem IsSuccPrelimit.lt_iff_exists_lt (h : IsSuccPrelimit b) : a < b ↔ ∃ c < b, a < c := by rw [← not_iff_not] simp [h.le_iff_forall_le] theorem IsSuccLimit.lt_iff_exists_lt (h : IsSuccLimit b) : a < b ↔ ∃ c < b, a < c := h.isSuccPrelimit.lt_iff_exists_lt lemma _root_.IsLUB.isSuccPrelimit_of_notMem {s : Set α} (hs : IsLUB s a) (ha : a ∉ s) : IsSuccPrelimit a := by intro b hb obtain ⟨c, hc, hbc, hca⟩ := hs.exists_between hb.lt obtain rfl := (hb.ge_of_gt hbc).antisymm hca contradiction @[deprecated (since := "2025-05-23")] alias _root_.IsLUB.isSuccPrelimit_of_not_mem := _root_.IsLUB.isSuccPrelimit_of_notMem lemma _root_.IsLUB.mem_of_not_isSuccPrelimit {s : Set α} (hs : IsLUB s a) (ha : ¬IsSuccPrelimit a) : a ∈ s := ha.imp_symm hs.isSuccPrelimit_of_notMem lemma _root_.IsLUB.isSuccLimit_of_notMem {s : Set α} (hs : IsLUB s a) (hs' : s.Nonempty) (ha : a ∉ s) : IsSuccLimit a := by refine ⟨?_, hs.isSuccPrelimit_of_notMem ha⟩ obtain ⟨b, hb⟩ := hs' obtain rfl | hb := (hs.1 hb).eq_or_lt · contradiction · exact hb.not_isMin @[deprecated (since := "2025-05-23")] alias _root_.IsLUB.isSuccLimit_of_not_mem := _root_.IsLUB.isSuccLimit_of_notMem lemma _root_.IsLUB.mem_of_not_isSuccLimit {s : Set α} (hs : IsLUB s a) (hs' : s.Nonempty) (ha : ¬IsSuccLimit a) : a ∈ s := ha.imp_symm <| hs.isSuccLimit_of_notMem hs' theorem IsSuccPrelimit.isLUB_Iio (ha : IsSuccPrelimit a) : IsLUB (Iio a) a := by refine ⟨fun _ ↦ le_of_lt, fun b hb ↦ le_of_forall_lt fun c hc ↦ ?_⟩ obtain ⟨d, hd, hd'⟩ := ha.lt_iff_exists_lt.1 hc exact hd'.trans_le (hb hd) theorem IsSuccLimit.isLUB_Iio (ha : IsSuccLimit a) : IsLUB (Iio a) a := ha.isSuccPrelimit.isLUB_Iio theorem isLUB_Iio_iff_isSuccPrelimit : IsLUB (Iio a) a ↔ IsSuccPrelimit a := by refine ⟨fun ha b hb ↦ ?_, IsSuccPrelimit.isLUB_Iio⟩ rw [hb.Iio_eq] at ha obtain rfl := isLUB_Iic.unique ha cases hb.lt.false variable [SuccOrder α] theorem IsSuccPrelimit.le_succ_iff (hb : IsSuccPrelimit b) : b ≤ succ a ↔ b ≤ a := le_iff_le_iff_lt_iff_lt.2 hb.succ_lt_iff theorem IsSuccLimit.le_succ_iff (hb : IsSuccLimit b) : b ≤ succ a ↔ b ≤ a := hb.isSuccPrelimit.le_succ_iff end LinearOrder /-! ### Predecessor limits -/ section LT variable [LT α] /-- A predecessor pre-limit is a value that isn't covered by any other. It's so named because in a predecessor order, a predecessor pre-limit can't be the predecessor of anything smaller. Use `IsPredLimit` to exclude the case of a maximal element. -/ def IsPredPrelimit (a : α) : Prop := ∀ b, ¬ a ⋖ b theorem not_isPredPrelimit_iff_exists_covBy (a : α) : ¬IsPredPrelimit a ↔ ∃ b, a ⋖ b := by simp [IsPredPrelimit] @[simp] theorem IsPredPrelimit.of_dense [DenselyOrdered α] (a : α) : IsPredPrelimit a := fun _ => not_covBy @[simp] theorem isSuccPrelimit_toDual_iff : IsSuccPrelimit (toDual a) ↔ IsPredPrelimit a := by simp [IsSuccPrelimit, IsPredPrelimit] @[simp] theorem isPredPrelimit_toDual_iff : IsPredPrelimit (toDual a) ↔ IsSuccPrelimit a := by simp [IsSuccPrelimit, IsPredPrelimit] alias ⟨_, IsPredPrelimit.dual⟩ := isSuccPrelimit_toDual_iff alias ⟨_, IsSuccPrelimit.dual⟩ := isPredPrelimit_toDual_iff end LT section Preorder variable [Preorder α] /-- A predecessor limit is a value that isn't maximal and doesn't cover any other. It's so named because in a predecessor order, a predecessor limit can't be the predecessor of anything larger. This previously allowed the element to be maximal. This usage is now covered by `IsPredPreLimit`. -/ def IsPredLimit (a : α) : Prop := ¬ IsMax a ∧ IsPredPrelimit a protected theorem IsPredLimit.not_isMax (h : IsPredLimit a) : ¬ IsMax a := h.1 protected theorem IsPredLimit.isPredPrelimit (h : IsPredLimit a) : IsPredPrelimit a := h.2 @[simp] theorem isSuccLimit_toDual_iff : IsSuccLimit (toDual a) ↔ IsPredLimit a := by simp [IsSuccLimit, IsPredLimit] @[simp] theorem isPredLimit_toDual_iff : IsPredLimit (toDual a) ↔ IsSuccLimit a := by simp [IsSuccLimit, IsPredLimit] alias ⟨_, IsPredLimit.dual⟩ := isSuccLimit_toDual_iff alias ⟨_, IsSuccLimit.dual⟩ := isPredLimit_toDual_iff theorem IsPredPrelimit.isPredLimit_of_not_isMax (h : IsPredPrelimit a) (ha : ¬ IsMax a) : IsPredLimit a := ⟨ha, h⟩ theorem IsPredPrelimit.isPredLimit [NoMaxOrder α] (h : IsPredPrelimit a) : IsPredLimit a := h.isPredLimit_of_not_isMax (not_isMax a) theorem isPredPrelimit_iff_isPredLimit_of_not_isMax (h : ¬ IsMax a) : IsPredPrelimit a ↔ IsPredLimit a := ⟨fun ha ↦ ha.isPredLimit_of_not_isMax h, IsPredLimit.isPredPrelimit⟩ theorem isPredPrelimit_iff_isPredLimit [NoMaxOrder α] : IsPredPrelimit a ↔ IsPredLimit a := isPredPrelimit_iff_isPredLimit_of_not_isMax (not_isMax a) protected theorem _root_.IsMax.not_isPredLimit (h : IsMax a) : ¬ IsPredLimit a := fun ha ↦ ha.not_isMax h protected theorem _root_.IsMax.isPredPrelimit : IsMax a → IsPredPrelimit a := fun h _ hab => not_isMax_of_lt hab.lt h theorem IsPredLimit.nonempty_Ioi (h : IsPredLimit a) : (Set.Ioi a).Nonempty := not_isMax_iff.1 h.1 theorem isPredPrelimit_top [OrderTop α] : IsPredPrelimit (⊤ : α) := isMax_top.isPredPrelimit theorem not_isPredLimit_top [OrderTop α] : ¬ IsPredLimit (⊤ : α) := isMax_top.not_isPredLimit theorem IsPredLimit.ne_top [OrderTop α] (h : IsPredLimit a) : a ≠ ⊤ := h.dual.ne_bot theorem not_isPredLimit_iff : ¬ IsPredLimit a ↔ IsMax a ∨ ¬ IsPredPrelimit a := by rw [IsPredLimit, not_and_or, not_not] theorem not_isPredLimit_of_not_isPredPrelimit (h : ¬ IsPredPrelimit a) : ¬ IsPredLimit a := not_isPredLimit_iff.2 (Or.inr h) variable [PredOrder α] protected theorem IsPredPrelimit.isMin (h : IsPredPrelimit (pred a)) : IsMin a := h.dual.isMax protected theorem IsPredLimit.isMin (h : IsPredLimit (pred a)) : IsMin a := h.dual.isMax theorem not_isPredPrelimit_pred_of_not_isMin (ha : ¬ IsMin a) : ¬ IsPredPrelimit (pred a) := mt IsPredPrelimit.isMin ha theorem not_isPredLimit_pred_of_not_isMin (ha : ¬ IsMin a) : ¬ IsPredLimit (pred a) := mt IsPredLimit.isMin ha section NoMinOrder variable [NoMinOrder α] theorem IsPredPrelimit.pred_ne (h : IsPredPrelimit a) (b : α) : pred b ≠ a := h.dual.succ_ne b theorem IsPredLimit.pred_ne (h : IsPredLimit a) (b : α) : pred b ≠ a := h.isPredPrelimit.pred_ne b @[simp] theorem not_isPredPrelimit_pred (a : α) : ¬ IsPredPrelimit (pred a) := fun h => h.pred_ne _ rfl @[simp] theorem not_isPredLimit_pred (a : α) : ¬ IsPredLimit (pred a) := fun h => h.pred_ne _ rfl end NoMinOrder section IsPredArchimedean variable [IsPredArchimedean α] [NoMinOrder α] theorem IsPredPrelimit.isMax_of_noMin (h : IsPredPrelimit a) : IsMax a := h.dual.isMin_of_noMax @[simp] theorem isPredPrelimit_iff_of_noMin : IsPredPrelimit a ↔ IsMax a := ⟨IsPredPrelimit.isMax_of_noMin, IsMax.isPredPrelimit⟩ theorem not_isPredPrelimit_of_noMin [NoMaxOrder α] : ¬ IsPredPrelimit a := by simp @[simp] theorem not_isPredLimit_of_noMin : ¬ IsPredLimit a := fun h ↦ h.not_isMax h.isPredPrelimit.isMax_of_noMin end IsPredArchimedean end Preorder section PartialOrder variable [PartialOrder α] theorem isPredLimit_iff [OrderTop α] : IsPredLimit a ↔ a ≠ ⊤ ∧ IsPredPrelimit a := by rw [IsPredLimit, isMax_iff_eq_top] theorem IsPredLimit.lt_top [OrderTop α] (h : IsPredLimit a) : a < ⊤ := h.ne_top.lt_top variable [PredOrder α] theorem isPredPrelimit_of_pred_ne (h : ∀ b, pred b ≠ a) : IsPredPrelimit a := fun b hba => h b (CovBy.pred_eq hba) theorem not_isPredPrelimit_iff : ¬ IsPredPrelimit a ↔ ∃ b, ¬ IsMin b ∧ pred b = a := by rw [← isSuccPrelimit_toDual_iff] exact not_isSuccPrelimit_iff /-- See `not_isPredPrelimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_pred_of_not_isPredPrelimit (h : ¬ IsPredPrelimit a) : a ∈ range (pred : α → α) := by obtain ⟨b, hb⟩ := not_isPredPrelimit_iff.1 h exact ⟨b, hb.2⟩ theorem mem_range_pred_or_isPredPrelimit (a) : a ∈ range (pred : α → α) ∨ IsPredPrelimit a := or_iff_not_imp_right.2 <| mem_range_pred_of_not_isPredPrelimit theorem isPredPrelimit_of_pred_lt (H : ∀ b > a, a < pred b) : IsPredPrelimit a := fun a hab => (H a hab.lt).ne (CovBy.pred_eq hab).symm theorem IsPredPrelimit.lt_pred (ha : IsPredPrelimit a) (hb : a < b) : a < pred b := ha.dual.succ_lt hb theorem IsPredLimit.lt_pred (ha : IsPredLimit a) (hb : a < b) : a < pred b := ha.isPredPrelimit.lt_pred hb theorem IsPredPrelimit.lt_pred_iff (ha : IsPredPrelimit a) : a < pred b ↔ a < b := ha.dual.succ_lt_iff theorem IsPredLimit.lt_pred_iff (ha : IsPredLimit a) : a < pred b ↔ a < b := ha.dual.succ_lt_iff theorem isPredPrelimit_iff_lt_pred : IsPredPrelimit a ↔ ∀ b > a, a < pred b := ⟨fun hb _ => hb.lt_pred, isPredPrelimit_of_pred_lt⟩ section NoMinOrder variable [NoMinOrder α] theorem isPredPrelimit_iff_pred_ne : IsPredPrelimit a ↔ ∀ b, pred b ≠ a := ⟨IsPredPrelimit.pred_ne, isPredPrelimit_of_pred_ne⟩ theorem not_isPredPrelimit_iff' : ¬ IsPredPrelimit a ↔ a ∈ range (pred : α → α) := by simp_rw [isPredPrelimit_iff_pred_ne, not_forall, not_ne_iff, mem_range] end NoMinOrder section IsPredArchimedean variable [IsPredArchimedean α] protected theorem IsPredPrelimit.isMax (h : IsPredPrelimit a) : IsMax a := h.dual.isMin @[simp] theorem isPredPrelimit_iff : IsPredPrelimit a ↔ IsMax a := ⟨IsPredPrelimit.isMax, IsMax.isPredPrelimit⟩ @[simp] theorem not_isPredLimit : ¬ IsPredLimit a := fun h ↦ h.not_isMax <| h.isPredPrelimit.isMax theorem not_isPredPrelimit [NoMaxOrder α] : ¬ IsPredPrelimit a := by simp end IsPredArchimedean end PartialOrder section LinearOrder variable [LinearOrder α] theorem IsPredPrelimit.le_iff_forall_le (h : IsPredPrelimit a) : b ≤ a ↔ ∀ ⦃c⦄, a < c → b ≤ c := h.dual.le_iff_forall_le theorem IsPredLimit.le_iff_forall_le (h : IsPredLimit a) : b ≤ a ↔ ∀ ⦃c⦄, a < c → b ≤ c := h.dual.le_iff_forall_le theorem IsPredPrelimit.lt_iff_exists_lt (h : IsPredPrelimit b) : b < a ↔ ∃ c, b < c ∧ c < a := h.dual.lt_iff_exists_lt theorem IsPredLimit.lt_iff_exists_lt (h : IsPredLimit b) : b < a ↔ ∃ c, b < c ∧ c < a := h.dual.lt_iff_exists_lt lemma _root_.IsGLB.isPredPrelimit_of_notMem {s : Set α} (hs : IsGLB s a) (ha : a ∉ s) : IsPredPrelimit a := by simpa using (IsGLB.dual hs).isSuccPrelimit_of_notMem ha @[deprecated (since := "2025-05-23")] alias _root_.IsGLB.isPredPrelimit_of_not_mem := _root_.IsGLB.isPredPrelimit_of_notMem lemma _root_.IsGLB.mem_of_not_isPredPrelimit {s : Set α} (hs : IsGLB s a) (ha : ¬IsPredPrelimit a) : a ∈ s := ha.imp_symm hs.isPredPrelimit_of_notMem lemma _root_.IsGLB.isPredLimit_of_notMem {s : Set α} (hs : IsGLB s a) (hs' : s.Nonempty) (ha : a ∉ s) : IsPredLimit a := by simpa using (IsGLB.dual hs).isSuccLimit_of_notMem hs' ha @[deprecated (since := "2025-05-23")] alias _root_.IsGLB.isPredLimit_of_not_mem := _root_.IsGLB.isPredLimit_of_notMem lemma _root_.IsGLB.mem_of_not_isPredLimit {s : Set α} (hs : IsGLB s a) (hs' : s.Nonempty) (ha : ¬IsPredLimit a) : a ∈ s := ha.imp_symm <| hs.isPredLimit_of_notMem hs' theorem IsPredPrelimit.isGLB_Ioi (ha : IsPredPrelimit a) : IsGLB (Ioi a) a := ha.dual.isLUB_Iio theorem IsPredLimit.isGLB_Ioi (ha : IsPredLimit a) : IsGLB (Ioi a) a := ha.dual.isLUB_Iio theorem isGLB_Ioi_iff_isPredPrelimit : IsGLB (Ioi a) a ↔ IsPredPrelimit a := by simpa using isLUB_Iio_iff_isSuccPrelimit (a := toDual a) variable [PredOrder α] theorem IsPredPrelimit.pred_le_iff (hb : IsPredPrelimit b) : pred a ≤ b ↔ a ≤ b := hb.dual.le_succ_iff theorem IsPredLimit.pred_le_iff (hb : IsPredLimit b) : pred a ≤ b ↔ a ≤ b := hb.dual.le_succ_iff end LinearOrder end Order /-! ### Induction principles -/ variable {motive : α → Sort*} namespace Order section isSuccPrelimitRecOn section PartialOrder variable [PartialOrder α] [SuccOrder α] (succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → motive a) variable (b) in open Classical in /-- A value can be built by building it on successors and successor pre-limits. -/ @[elab_as_elim] noncomputable def isSuccPrelimitRecOn : motive b := if hb : IsSuccPrelimit b then isSuccPrelimit b hb else haveI H := Classical.choose_spec (not_isSuccPrelimit_iff.1 hb) cast (congr_arg motive H.2) (succ _ H.1) theorem isSuccPrelimitRecOn_of_isSuccPrelimit (hb : IsSuccPrelimit b) : isSuccPrelimitRecOn b succ isSuccPrelimit = isSuccPrelimit b hb := dif_pos hb end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] (succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → motive a) theorem isSuccPrelimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) : isSuccPrelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b hb := by have hb' := not_isSuccPrelimit_succ_of_not_isMax hb have H := Classical.choose_spec (not_isSuccPrelimit_iff.1 hb') rw [isSuccPrelimitRecOn, dif_neg hb', cast_eq_iff_heq] congr exacts [(succ_eq_succ_iff_of_not_isMax H.1 hb).1 H.2, proof_irrel_heq _ _] @[simp] theorem isSuccPrelimitRecOn_succ [NoMaxOrder α] (b : α) : isSuccPrelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b (not_isMax b) := isSuccPrelimitRecOn_succ_of_not_isMax _ _ _ end LinearOrder end isSuccPrelimitRecOn section isPredPrelimitRecOn section PartialOrder variable [PartialOrder α] [PredOrder α] (pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → motive a) variable (b) in /-- A value can be built by building it on predecessors and predecessor pre-limits. -/ @[elab_as_elim] noncomputable def isPredPrelimitRecOn : motive b := isSuccPrelimitRecOn (α := αᵒᵈ) b pred (fun a ha ↦ isPredPrelimit a ha.dual) theorem isPredPrelimitRecOn_of_isPredPrelimit (hb : IsPredPrelimit b) : isPredPrelimitRecOn b pred isPredPrelimit = isPredPrelimit b hb := isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.dual end PartialOrder section LinearOrder variable [LinearOrder α] [PredOrder α] (pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → motive a) theorem isPredPrelimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) : isPredPrelimitRecOn (Order.pred b) pred isPredPrelimit = pred b hb := isSuccPrelimitRecOn_succ_of_not_isMax (α := αᵒᵈ) _ _ _ @[simp] theorem isPredPrelimitRecOn_pred [NoMinOrder α] (b : α) : isPredPrelimitRecOn (Order.pred b) pred isPredPrelimit = pred b (not_isMin b) := isPredPrelimitRecOn_pred_of_not_isMin _ _ _ end LinearOrder end isPredPrelimitRecOn section isSuccLimitRecOn section PartialOrder variable [PartialOrder α] [SuccOrder α] (isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccLimit : ∀ a, IsSuccLimit a → motive a) variable (b) in open Classical in /-- A value can be built by building it on minimal elements, successors, and successor limits. -/ @[elab_as_elim] noncomputable def isSuccLimitRecOn : motive b := isSuccPrelimitRecOn b succ fun a ha ↦ if h : IsMin a then isMin a h else isSuccLimit a (ha.isSuccLimit_of_not_isMin h) @[simp] theorem isSuccLimitRecOn_of_isSuccLimit (hb : IsSuccLimit b) : isSuccLimitRecOn b isMin succ isSuccLimit = isSuccLimit b hb := by rw [isSuccLimitRecOn, isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_neg hb.not_isMin] end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] (isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccLimit : ∀ a, IsSuccLimit a → motive a) theorem isSuccLimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) : isSuccLimitRecOn (Order.succ b) isMin succ isSuccLimit = succ b hb := by rw [isSuccLimitRecOn, isSuccPrelimitRecOn_succ_of_not_isMax] @[simp] theorem isSuccLimitRecOn_succ [NoMaxOrder α] (b : α) : isSuccLimitRecOn (Order.succ b) isMin succ isSuccLimit = succ b (not_isMax b) := isSuccLimitRecOn_succ_of_not_isMax isMin succ isSuccLimit _ theorem isSuccLimitRecOn_of_isMin (hb : IsMin b) : isSuccLimitRecOn b isMin succ isSuccLimit = isMin b hb := by rw [isSuccLimitRecOn, isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_pos hb] end LinearOrder end isSuccLimitRecOn section isPredLimitRecOn section PartialOrder variable [PartialOrder α] [PredOrder α] (isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredLimit : ∀ a, IsPredLimit a → motive a) variable (b) in /-- A value can be built by building it on maximal elements, predecessors, and predecessor limits. -/ @[elab_as_elim] noncomputable def isPredLimitRecOn : motive b := isSuccLimitRecOn (α := αᵒᵈ) b isMax pred (fun a ha => isPredLimit a ha.dual) @[simp] theorem isPredLimitRecOn_of_isPredLimit (hb : IsPredLimit b) : isPredLimitRecOn b isMax pred isPredLimit = isPredLimit b hb := isSuccLimitRecOn_of_isSuccLimit (α := αᵒᵈ) isMax pred _ hb.dual end PartialOrder section LinearOrder variable [LinearOrder α] [PredOrder α] (isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredLimit : ∀ a, IsPredLimit a → motive a) theorem isPredLimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) : isPredLimitRecOn (Order.pred b) isMax pred isPredLimit = pred b hb := isSuccLimitRecOn_succ_of_not_isMax (α := αᵒᵈ) isMax pred _ hb @[simp] theorem isPredLimitRecOn_pred [NoMinOrder α] : isPredLimitRecOn (Order.pred b) isMax pred isPredLimit = pred b (not_isMin b) := isSuccLimitRecOn_succ (α := αᵒᵈ) isMax pred _ b theorem isPredLimitRecOn_of_isMax (hb : IsMax b) : isPredLimitRecOn b isMax pred isPredLimit = isMax b hb := isSuccLimitRecOn_of_isMin (α := αᵒᵈ) isMax pred _ hb end LinearOrder end isPredLimitRecOn end Order open Order namespace SuccOrder section prelimitRecOn section PartialOrder variable [PartialOrder α] [SuccOrder α] [WellFoundedLT α] (succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → (∀ b < a, motive b) → motive a) variable (b) in open Classical in /-- Recursion principle on a well-founded partial `SuccOrder`. -/ @[elab_as_elim] noncomputable def prelimitRecOn : motive b := wellFounded_lt.fix (fun a IH ↦ if h : IsSuccPrelimit a then isSuccPrelimit a h IH else haveI H := Classical.choose_spec (not_isSuccPrelimit_iff.1 h) cast (congr_arg motive H.2) (succ _ H.1 <| IH _ <| H.2.subst <| lt_succ_of_not_isMax H.1)) b @[simp] theorem prelimitRecOn_of_isSuccPrelimit (hb : IsSuccPrelimit b) : prelimitRecOn b succ isSuccPrelimit = isSuccPrelimit b hb fun x _ ↦ SuccOrder.prelimitRecOn x succ isSuccPrelimit := by rw [prelimitRecOn, WellFounded.fix_eq, dif_pos hb]; rfl end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] [WellFoundedLT α] (succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → (∀ b < a, motive b) → motive a) theorem prelimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) : prelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b hb (prelimitRecOn b succ isSuccPrelimit) := by have h := not_isSuccPrelimit_succ_of_not_isMax hb have H := Classical.choose_spec (not_isSuccPrelimit_iff.1 h) rw [prelimitRecOn, WellFounded.fix_eq, dif_neg h] have {a c : α} {ha hc} {x : ∀ a, motive a} (h : a = c) : cast (congr_arg (motive ∘ Order.succ) h) (succ a ha (x a)) = succ c hc (x c) := by subst h; rfl exact this <| (succ_eq_succ_iff_of_not_isMax H.1 hb).1 H.2 @[simp] theorem prelimitRecOn_succ [NoMaxOrder α] (b : α) : prelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b (not_isMax b) (prelimitRecOn b succ isSuccPrelimit) := prelimitRecOn_succ_of_not_isMax _ _ _ end LinearOrder end prelimitRecOn section limitRecOn section PartialOrder variable [PartialOrder α] [SuccOrder α] [WellFoundedLT α] (isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a)) (isSuccLimit : ∀ a, IsSuccLimit a → (∀ b < a, motive b) → motive a) variable (b) in open Classical in /-- Recursion principle on a well-founded partial `SuccOrder`, separating out the case of a minimal element. -/ @[elab_as_elim] noncomputable def limitRecOn : motive b := prelimitRecOn b succ fun a ha IH ↦ if h : IsMin a then isMin a h else isSuccLimit a (ha.isSuccLimit_of_not_isMin h) IH @[simp] theorem limitRecOn_isMin (hb : IsMin b) : limitRecOn b isMin succ isSuccLimit = isMin b hb := by rw [limitRecOn, prelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_pos hb] @[simp] theorem limitRecOn_of_isSuccLimit (hb : IsSuccLimit b) : limitRecOn b isMin succ isSuccLimit = isSuccLimit b hb fun x _ ↦ limitRecOn x isMin succ isSuccLimit := by rw [limitRecOn, prelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_neg hb.not_isMin]; rfl end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] [WellFoundedLT α] (isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a)) (isSuccLimit : ∀ a, IsSuccLimit a → (∀ b < a, motive b) → motive a) theorem limitRecOn_succ_of_not_isMax (hb : ¬IsMax b) : limitRecOn (Order.succ b) isMin succ isSuccLimit = succ b hb (limitRecOn b isMin succ isSuccLimit) := by rw [limitRecOn, prelimitRecOn_succ_of_not_isMax]; rfl @[simp] theorem limitRecOn_succ [NoMaxOrder α] (b : α) : limitRecOn (Order.succ b) isMin succ isSuccLimit = succ b (not_isMax b) (limitRecOn b isMin succ isSuccLimit) := limitRecOn_succ_of_not_isMax isMin succ isSuccLimit _ end LinearOrder end limitRecOn end SuccOrder namespace PredOrder section prelimitRecOn section PartialOrder variable [PartialOrder α] [PredOrder α] [WellFoundedGT α] (pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → (∀ b > a, motive b) → motive a) variable (b) in /-- Recursion principle on a well-founded partial `PredOrder`. -/ @[elab_as_elim] noncomputable def prelimitRecOn : motive b := SuccOrder.prelimitRecOn (α := αᵒᵈ) b pred (fun a ha => isPredPrelimit a ha.dual) @[simp] theorem prelimitRecOn_of_isPredPrelimit (hb : IsPredPrelimit b) : prelimitRecOn b pred isPredPrelimit = isPredPrelimit b hb fun x _ ↦ prelimitRecOn x pred isPredPrelimit := SuccOrder.prelimitRecOn_of_isSuccPrelimit _ _ hb.dual end PartialOrder section LinearOrder variable [LinearOrder α] [PredOrder α] [WellFoundedGT α] (pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → (∀ b > a, motive b) → motive a) theorem prelimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) : prelimitRecOn (Order.pred b) pred isPredPrelimit = pred b hb (prelimitRecOn b pred isPredPrelimit) := SuccOrder.prelimitRecOn_succ_of_not_isMax _ _ _ @[simp] theorem prelimitRecOn_pred [NoMinOrder α] (b : α) : prelimitRecOn (Order.pred b) pred isPredPrelimit = pred b (not_isMin b) (prelimitRecOn b pred isPredPrelimit) := prelimitRecOn_pred_of_not_isMin _ _ _ end LinearOrder end prelimitRecOn section limitRecOn section PartialOrder variable [PartialOrder α] [PredOrder α] [WellFoundedGT α] (isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a)) (isPredLimit : ∀ a, IsPredLimit a → (∀ b > a, motive b) → motive a) variable (b) in open Classical in /-- Recursion principle on a well-founded partial `PredOrder`, separating out the case of a maximal element. -/ @[elab_as_elim] noncomputable def limitRecOn : motive b := SuccOrder.limitRecOn (α := αᵒᵈ) b isMax pred (fun a ha => isPredLimit a ha.dual) @[simp] theorem limitRecOn_isMax (hb : IsMax b) : limitRecOn b isMax pred isPredLimit = isMax b hb := SuccOrder.limitRecOn_isMin (α := αᵒᵈ) isMax pred _ hb @[simp] theorem limitRecOn_of_isPredLimit (hb : IsPredLimit b) : limitRecOn b isMax pred isPredLimit = isPredLimit b hb fun x _ ↦ limitRecOn x isMax pred isPredLimit := SuccOrder.limitRecOn_of_isSuccLimit (α := αᵒᵈ) isMax pred _ hb.dual end PartialOrder section LinearOrder variable [LinearOrder α] [PredOrder α] [WellFoundedGT α] (isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a)) (isPredLimit : ∀ a, IsPredLimit a → (∀ b > a, motive b) → motive a) theorem limitRecOn_pred_of_not_isMin (hb : ¬IsMin b) : limitRecOn (Order.pred b) isMax pred isPredLimit = pred b hb (limitRecOn b isMax pred isPredLimit) := SuccOrder.limitRecOn_succ_of_not_isMax (α := αᵒᵈ) isMax pred _ hb @[simp] theorem limitRecOn_pred [NoMinOrder α] (b : α) : limitRecOn (Order.pred b) isMax pred isPredLimit = pred b (not_isMin b) (limitRecOn b isMax pred isPredLimit) := SuccOrder.limitRecOn_succ (α := αᵒᵈ) isMax pred _ b end LinearOrder end limitRecOn end PredOrder
.lake/packages/mathlib/Mathlib/Order/SuccPred/Archimedean.lean
import Mathlib.Order.SuccPred.Basic /-! # Archimedean successor and predecessor * `IsSuccArchimedean`: `SuccOrder` where `succ` iterated to an element gives all the greater ones. * `IsPredArchimedean`: `PredOrder` where `pred` iterated to an element gives all the smaller ones. -/ variable {α β : Type*} open Order Function /-- A `SuccOrder` is succ-archimedean if one can go from any two comparable elements by iterating `succ` -/ class IsSuccArchimedean (α : Type*) [Preorder α] [SuccOrder α] : Prop where /-- If `a ≤ b` then one can get to `a` from `b` by iterating `succ` -/ exists_succ_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, succ^[n] a = b /-- A `PredOrder` is pred-archimedean if one can go from any two comparable elements by iterating `pred` -/ class IsPredArchimedean (α : Type*) [Preorder α] [PredOrder α] : Prop where /-- If `a ≤ b` then one can get to `b` from `a` by iterating `pred` -/ exists_pred_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, pred^[n] b = a export IsSuccArchimedean (exists_succ_iterate_of_le) export IsPredArchimedean (exists_pred_iterate_of_le) section Preorder variable [Preorder α] section SuccOrder variable [SuccOrder α] [IsSuccArchimedean α] {a b : α} instance : IsPredArchimedean αᵒᵈ := ⟨fun {a b} h => by convert exists_succ_iterate_of_le h.ofDual⟩ theorem LE.le.exists_succ_iterate (h : a ≤ b) : ∃ n, succ^[n] a = b := exists_succ_iterate_of_le h theorem exists_succ_iterate_iff_le : (∃ n, succ^[n] a = b) ↔ a ≤ b := by refine ⟨?_, exists_succ_iterate_of_le⟩ rintro ⟨n, rfl⟩ exact id_le_iterate_of_id_le le_succ n a /-- Induction principle on a type with a `SuccOrder` for all elements above a given element `m`. -/ @[elab_as_elim] theorem Succ.rec {m : α} {P : ∀ n, m ≤ n → Prop} (rfl : P m le_rfl) (succ : ∀ n (hmn : m ≤ n), P n hmn → P (succ n) (hmn.trans <| le_succ _)) ⦃n : α⦄ (hmn : m ≤ n) : P n hmn := by obtain ⟨n, rfl⟩ := hmn.exists_succ_iterate induction n with | zero => exact rfl | succ n ih => simp_rw [Function.iterate_succ_apply'] exact succ _ (id_le_iterate_of_id_le le_succ n m) (ih _) theorem Succ.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) {a b : α} (h : a ≤ b) : p a ↔ p b := by obtain ⟨n, rfl⟩ := h.exists_succ_iterate exact Iterate.rec (fun b => p a ↔ p b) Iff.rfl (fun c hc => hc.trans (hsucc _)) n lemma le_total_of_codirected {r v₁ v₂ : α} (h₁ : r ≤ v₁) (h₂ : r ≤ v₂) : v₁ ≤ v₂ ∨ v₂ ≤ v₁ := by obtain ⟨n, rfl⟩ := h₁.exists_succ_iterate obtain ⟨m, rfl⟩ := h₂.exists_succ_iterate clear h₁ h₂ wlog h : n ≤ m · rw [Or.comm] apply this exact Nat.le_of_not_ge h left obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h rw [Nat.add_comm, Function.iterate_add, Function.comp_apply] apply Order.le_succ_iterate end SuccOrder section PredOrder variable [PredOrder α] [IsPredArchimedean α] {a b : α} instance : IsSuccArchimedean αᵒᵈ := ⟨fun {a b} h => by convert exists_pred_iterate_of_le h.ofDual⟩ theorem LE.le.exists_pred_iterate (h : a ≤ b) : ∃ n, pred^[n] b = a := exists_pred_iterate_of_le h theorem exists_pred_iterate_iff_le : (∃ n, pred^[n] b = a) ↔ a ≤ b := exists_succ_iterate_iff_le (α := αᵒᵈ) /-- Induction principle on a type with a `PredOrder` for all elements below a given element `m`. -/ @[elab_as_elim] theorem Pred.rec {m : α} {P : ∀ n, n ≤ m → Prop} (rfl : P m le_rfl) (pred : ∀ n (hnm : n ≤ m), P n hnm → P (pred n) ((pred_le _).trans hnm)) ⦃n : α⦄ (hnm : n ≤ m) : P n hnm := Succ.rec (α := αᵒᵈ) (P := P) rfl pred hnm theorem Pred.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) {a b : α} (h : a ≤ b) : p a ↔ p b := (Succ.rec_iff (α := αᵒᵈ) hsucc h).symm lemma le_total_of_directed {r v₁ v₂ : α} (h₁ : v₁ ≤ r) (h₂ : v₂ ≤ r) : v₁ ≤ v₂ ∨ v₂ ≤ v₁ := Or.symm (le_total_of_codirected (α := αᵒᵈ) h₁ h₂) end PredOrder end Preorder section PartialOrder variable [PartialOrder α] lemma lt_or_le_of_codirected [SuccOrder α] [IsSuccArchimedean α] {r v₁ v₂ : α} (h₁ : r ≤ v₁) (h₂ : r ≤ v₂) : v₁ < v₂ ∨ v₂ ≤ v₁ := by rw [Classical.or_iff_not_imp_right] intro nh rcases le_total_of_codirected h₁ h₂ with h | h · apply lt_of_le_of_ne h (ne_of_not_le nh).symm · contradiction /-- This isn't an instance due to a loop with `LinearOrder`. -/ -- See note [reducible non-instances] abbrev IsSuccArchimedean.linearOrder [SuccOrder α] [IsSuccArchimedean α] [DecidableEq α] [DecidableLE α] [DecidableLT α] [IsDirected α (· ≥ ·)] : LinearOrder α where le_total a b := have ⟨c, ha, hb⟩ := directed_of (· ≥ ·) a b le_total_of_codirected ha hb toDecidableEq := inferInstance toDecidableLE := inferInstance toDecidableLT := inferInstance lemma lt_or_le_of_directed [PredOrder α] [IsPredArchimedean α] {r v₁ v₂ : α} (h₁ : v₁ ≤ r) (h₂ : v₂ ≤ r) : v₁ < v₂ ∨ v₂ ≤ v₁ := by rw [Classical.or_iff_not_imp_right] intro nh rcases le_total_of_directed h₁ h₂ with h | h · apply lt_of_le_of_ne h (ne_of_not_le nh).symm · contradiction /-- This isn't an instance due to a loop with `LinearOrder`. -/ -- See note [reducible non-instances] abbrev IsPredArchimedean.linearOrder [PredOrder α] [IsPredArchimedean α] [DecidableEq α] [DecidableLE α] [DecidableLT α] [IsDirected α (· ≤ ·)] : LinearOrder α := letI : LinearOrder αᵒᵈ := IsSuccArchimedean.linearOrder inferInstanceAs (LinearOrder αᵒᵈᵒᵈ) end PartialOrder section LinearOrder variable [LinearOrder α] section SuccOrder variable [SuccOrder α] lemma succ_max (a b : α) : succ (max a b) = max (succ a) (succ b) := succ_mono.map_max lemma succ_min (a b : α) : succ (min a b) = min (succ a) (succ b) := succ_mono.map_min variable [IsSuccArchimedean α] {a b : α} theorem exists_succ_iterate_or : (∃ n, succ^[n] a = b) ∨ ∃ n, succ^[n] b = a := (le_total a b).imp exists_succ_iterate_of_le exists_succ_iterate_of_le theorem Succ.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) (a b : α) : p a ↔ p b := (le_total a b).elim (Succ.rec_iff hsucc) fun h => (Succ.rec_iff hsucc h).symm end SuccOrder section PredOrder variable [PredOrder α] lemma pred_max (a b : α) : pred (max a b) = max (pred a) (pred b) := pred_mono.map_max lemma pred_min (a b : α) : pred (min a b) = min (pred a) (pred b) := pred_mono.map_min variable [IsPredArchimedean α] {a b : α} theorem exists_pred_iterate_or : (∃ n, pred^[n] b = a) ∨ ∃ n, pred^[n] a = b := (le_total a b).imp exists_pred_iterate_of_le exists_pred_iterate_of_le theorem Pred.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) (a b : α) : p a ↔ p b := (le_total a b).elim (Pred.rec_iff hsucc) fun h => (Pred.rec_iff hsucc h).symm end PredOrder end LinearOrder section bdd_range variable [Preorder α] [Nonempty α] [Preorder β] {f : α → β} lemma StrictMono.not_bddAbove_range_of_isSuccArchimedean [NoMaxOrder α] [SuccOrder β] [IsSuccArchimedean β] (hf : StrictMono f) : ¬ BddAbove (Set.range f) := by rintro ⟨m, hm⟩ have hm' : ∀ a, f a ≤ m := fun a ↦ hm <| Set.mem_range_self _ obtain ⟨a₀⟩ := ‹Nonempty α› suffices ∀ b, f a₀ ≤ b → ∃ a, b < f a by obtain ⟨a, ha⟩ : ∃ a, m < f a := this m (hm' a₀) exact ha.not_ge (hm' a) have h : ∀ a, ∃ a', f a < f a' := fun a ↦ (exists_gt a).imp (fun a' h ↦ hf h) apply Succ.rec · exact h a₀ rintro b _ ⟨a, hba⟩ exact (h a).imp (fun a' ↦ (succ_le_of_lt hba).trans_lt) lemma StrictMono.not_bddBelow_range_of_isPredArchimedean [NoMinOrder α] [PredOrder β] [IsPredArchimedean β] (hf : StrictMono f) : ¬ BddBelow (Set.range f) := hf.dual.not_bddAbove_range_of_isSuccArchimedean lemma StrictAnti.not_bddBelow_range_of_isSuccArchimedean [NoMinOrder α] [SuccOrder β] [IsSuccArchimedean β] (hf : StrictAnti f) : ¬ BddAbove (Set.range f) := hf.dual_right.not_bddBelow_range_of_isPredArchimedean lemma StrictAnti.not_bddBelow_range_of_isPredArchimedean [NoMaxOrder α] [PredOrder β] [IsPredArchimedean β] (hf : StrictAnti f) : ¬ BddBelow (Set.range f) := hf.dual_right.not_bddAbove_range_of_isSuccArchimedean end bdd_range section IsWellFounded variable [PartialOrder α] instance (priority := 100) WellFoundedLT.toIsPredArchimedean [h : WellFoundedLT α] [PredOrder α] : IsPredArchimedean α := ⟨fun {a b} => by refine WellFounded.fix (C := fun b => a ≤ b → ∃ n, Nat.iterate pred n b = a) h.wf ?_ b intro b ih hab replace hab := eq_or_lt_of_le hab rcases hab with (rfl | hab) · exact ⟨0, rfl⟩ rcases eq_or_lt_of_le (pred_le b) with hb | hb · cases (min_of_le_pred hb.ge).not_lt hab dsimp at ih obtain ⟨k, hk⟩ := ih (pred b) hb (le_pred_of_lt hab) refine ⟨k + 1, ?_⟩ rw [iterate_add_apply, iterate_one, hk]⟩ instance (priority := 100) WellFoundedGT.toIsSuccArchimedean [h : WellFoundedGT α] [SuccOrder α] : IsSuccArchimedean α := let h : IsPredArchimedean αᵒᵈ := by infer_instance ⟨h.1⟩ end IsWellFounded section OrderBot variable [Preorder α] [OrderBot α] [SuccOrder α] [IsSuccArchimedean α] theorem Succ.rec_bot (p : α → Prop) (hbot : p ⊥) (hsucc : ∀ a, p a → p (succ a)) (a : α) : p a := Succ.rec hbot (fun x _ h => hsucc x h) (bot_le : ⊥ ≤ a) end OrderBot section OrderTop variable [Preorder α] [OrderTop α] [PredOrder α] [IsPredArchimedean α] theorem Pred.rec_top (p : α → Prop) (htop : p ⊤) (hpred : ∀ a, p a → p (pred a)) (a : α) : p a := Pred.rec htop (fun x _ h => hpred x h) (le_top : a ≤ ⊤) end OrderTop lemma SuccOrder.forall_ne_bot_iff [Nontrivial α] [PartialOrder α] [OrderBot α] [SuccOrder α] [IsSuccArchimedean α] (P : α → Prop) : (∀ i, i ≠ ⊥ → P i) ↔ (∀ i, P (SuccOrder.succ i)) := by refine ⟨fun h i ↦ h _ (Order.succ_ne_bot i), fun h i hi ↦ ?_⟩ obtain ⟨j, rfl⟩ := exists_succ_iterate_of_le (bot_le : ⊥ ≤ i) have hj : 0 < j := by apply Nat.pos_of_ne_zero; contrapose! hi; simp [hi] rw [← Nat.succ_pred_eq_of_pos hj] simp only [Function.iterate_succ', Function.comp_apply] apply h section IsLeast -- TODO: generalize to PartialOrder and `DirectedOn` after https://github.com/leanprover-community/mathlib4/pull/16272 lemma BddAbove.exists_isGreatest_of_nonempty {X : Type*} [LinearOrder X] [SuccOrder X] [IsSuccArchimedean X] {S : Set X} (hS : BddAbove S) (hS' : S.Nonempty) : ∃ x, IsGreatest S x := by obtain ⟨m, hm⟩ := hS obtain ⟨n, hn⟩ := hS' by_cases hm' : m ∈ S · exact ⟨_, hm', hm⟩ have hn' := hm hn revert hn hm hm' refine Succ.rec ?_ ?_ hn' · simp +contextual intro m _ IH hm hn hm' rw [mem_upperBounds] at IH hm simp_rw [Order.le_succ_iff_eq_or_le] at hm replace hm : ∀ x ∈ S, x ≤ m := by intro x hx refine (hm x hx).resolve_left ?_ rintro rfl exact hm' hx by_cases hmS : m ∈ S · exact ⟨m, hmS, hm⟩ · exact IH hm hn hmS lemma BddBelow.exists_isLeast_of_nonempty {X : Type*} [LinearOrder X] [PredOrder X] [IsPredArchimedean X] {S : Set X} (hS : BddBelow S) (hS' : S.Nonempty) : ∃ x, IsLeast S x := hS.dual.exists_isGreatest_of_nonempty hS' end IsLeast section OrderIso variable {X Y : Type*} [PartialOrder X] [PartialOrder Y] /-- `IsSuccArchimedean` transfers across equivalences between `SuccOrder`s. -/ protected lemma IsSuccArchimedean.of_orderIso [SuccOrder X] [IsSuccArchimedean X] [SuccOrder Y] (f : X ≃o Y) : IsSuccArchimedean Y where exists_succ_iterate_of_le {a b} h := by refine (exists_succ_iterate_of_le ((map_inv_le_map_inv_iff f).mpr h)).imp ?_ intro n rw [← f.apply_eq_iff_eq, EquivLike.apply_inv_apply] rintro rfl clear h induction n generalizing a with | zero => simp | succ n IH => simp only [Function.iterate_succ', Function.comp_apply, IH, f.map_succ] /-- `IsPredArchimedean` transfers across equivalences between `PredOrder`s. -/ protected lemma IsPredArchimedean.of_orderIso [PredOrder X] [IsPredArchimedean X] [PredOrder Y] (f : X ≃o Y) : IsPredArchimedean Y where exists_pred_iterate_of_le {a b} h := by refine (exists_pred_iterate_of_le ((map_inv_le_map_inv_iff f).mpr h)).imp ?_ intro n rw [← f.apply_eq_iff_eq, EquivLike.apply_inv_apply] rintro rfl clear h induction n generalizing b with | zero => simp | succ n IH => simp only [Function.iterate_succ', Function.comp_apply, IH, f.map_pred] end OrderIso section OrdConnected variable [PartialOrder α] instance Set.OrdConnected.isPredArchimedean [PredOrder α] [IsPredArchimedean α] (s : Set α) [s.OrdConnected] : IsPredArchimedean s where exists_pred_iterate_of_le := @fun ⟨b, hb⟩ ⟨c, hc⟩ hbc ↦ by classical simp only [Subtype.mk_le_mk] at hbc obtain ⟨n, hn⟩ := hbc.exists_pred_iterate use n induction n generalizing c with | zero => simp_all | succ n hi => simp_all only [Function.iterate_succ, Function.comp_apply] change Order.pred^[n] (dite ..) = _ split_ifs with h · dsimp only at h ⊢ apply hi _ _ _ hn · rw [← hn] apply Order.pred_iterate_le · have : Order.pred (⟨c, hc⟩ : s) = ⟨c, hc⟩ := by change dite .. = _ simp [h] rw [Function.iterate_fixed] · simp only [Order.pred_eq_iff_isMin] at this apply (this.eq_of_le _).symm exact hbc · exact this instance Set.OrdConnected.isSuccArchimedean [SuccOrder α] [IsSuccArchimedean α] (s : Set α) [s.OrdConnected] : IsSuccArchimedean s := letI : IsPredArchimedean sᵒᵈ := inferInstanceAs (IsPredArchimedean (OrderDual.ofDual ⁻¹' s)) inferInstanceAs (IsSuccArchimedean sᵒᵈᵒᵈ) end OrdConnected section Monotone variable {α β : Type*} [PartialOrder α] [Preorder β] section SuccOrder variable [SuccOrder α] [IsSuccArchimedean α] {s : Set α} {f : α → β} lemma monotoneOn_of_le_succ (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMax a → a ∈ s → succ a ∈ s → f a ≤ f (succ a)) : MonotoneOn f s := by rintro a ha b hb hab obtain ⟨n, rfl⟩ := exists_succ_iterate_of_le hab clear hab induction n with | zero => simp | succ n hn => rw [Function.iterate_succ_apply'] at hb ⊢ have : succ^[n] a ∈ s := hs.1 ha hb ⟨le_succ_iterate .., le_succ _⟩ by_cases hb' : IsMax (succ^[n] a) · rw [succ_eq_iff_isMax.2 hb'] exact hn this · exact (hn this).trans (hf _ hb' this hb) lemma antitoneOn_of_succ_le (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMax a → a ∈ s → succ a ∈ s → f (succ a) ≤ f a) : AntitoneOn f s := monotoneOn_of_le_succ (β := βᵒᵈ) hs hf lemma strictMonoOn_of_lt_succ (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMax a → a ∈ s → succ a ∈ s → f a < f (succ a)) : StrictMonoOn f s := by rintro a ha b hb hab obtain ⟨n, rfl⟩ := exists_succ_iterate_of_le hab.le obtain _ | n := n · simp at hab apply not_isMax_of_lt at hab induction n with | zero => simpa using hf _ hab ha hb | succ n hn => rw [Function.iterate_succ_apply'] at hb ⊢ have : succ^[n + 1] a ∈ s := hs.1 ha hb ⟨le_succ_iterate .., le_succ _⟩ by_cases hb' : IsMax (succ^[n + 1] a) · rw [succ_eq_iff_isMax.2 hb'] exact hn this · exact (hn this).trans (hf _ hb' this hb) lemma strictAntiOn_of_succ_lt (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMax a → a ∈ s → succ a ∈ s → f (succ a) < f a) : StrictAntiOn f s := strictMonoOn_of_lt_succ (β := βᵒᵈ) hs hf lemma monotone_of_le_succ (hf : ∀ a, ¬ IsMax a → f a ≤ f (succ a)) : Monotone f := by simpa using monotoneOn_of_le_succ Set.ordConnected_univ (by simpa using hf) lemma antitone_of_succ_le (hf : ∀ a, ¬ IsMax a → f (succ a) ≤ f a) : Antitone f := by simpa using antitoneOn_of_succ_le Set.ordConnected_univ (by simpa using hf) lemma strictMono_of_lt_succ (hf : ∀ a, ¬ IsMax a → f a < f (succ a)) : StrictMono f := by simpa using strictMonoOn_of_lt_succ Set.ordConnected_univ (by simpa using hf) lemma strictAnti_of_succ_lt (hf : ∀ a, ¬ IsMax a → f (succ a) < f a) : StrictAnti f := by simpa using strictAntiOn_of_succ_lt Set.ordConnected_univ (by simpa using hf) end SuccOrder section PredOrder variable [PredOrder α] [IsPredArchimedean α] {s : Set α} {f : α → β} lemma monotoneOn_of_pred_le (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMin a → a ∈ s → pred a ∈ s → f (pred a) ≤ f a) : MonotoneOn f s := by rintro a ha b hb hab obtain ⟨n, rfl⟩ := exists_pred_iterate_of_le hab clear hab induction n with | zero => simp | succ n hn => rw [Function.iterate_succ_apply'] at ha ⊢ have : pred^[n] b ∈ s := hs.1 ha hb ⟨pred_le _, pred_iterate_le ..⟩ by_cases ha' : IsMin (pred^[n] b) · rw [pred_eq_iff_isMin.2 ha'] exact hn this · exact (hn this).trans' (hf _ ha' this ha) lemma antitoneOn_of_le_pred (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMin a → a ∈ s → pred a ∈ s → f a ≤ f (pred a)) : AntitoneOn f s := monotoneOn_of_pred_le (β := βᵒᵈ) hs hf lemma strictMonoOn_of_pred_lt (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMin a → a ∈ s → pred a ∈ s → f (pred a) < f a) : StrictMonoOn f s := by rintro a ha b hb hab obtain ⟨n, rfl⟩ := exists_pred_iterate_of_le hab.le obtain _ | n := n · simp at hab apply not_isMin_of_lt at hab induction n with | zero => simpa using hf _ hab hb ha | succ n hn => rw [Function.iterate_succ_apply'] at ha ⊢ have : pred^[n + 1] b ∈ s := hs.1 ha hb ⟨pred_le _, pred_iterate_le ..⟩ by_cases ha' : IsMin (pred^[n + 1] b) · rw [pred_eq_iff_isMin.2 ha'] exact hn this · exact (hn this).trans' (hf _ ha' this ha) lemma strictAntiOn_of_lt_pred (hs : s.OrdConnected) (hf : ∀ a, ¬ IsMin a → a ∈ s → pred a ∈ s → f a < f (pred a)) : StrictAntiOn f s := strictMonoOn_of_pred_lt (β := βᵒᵈ) hs hf lemma monotone_of_pred_le (hf : ∀ a, ¬ IsMin a → f (pred a) ≤ f a) : Monotone f := by simpa using monotoneOn_of_pred_le Set.ordConnected_univ (by simpa using hf) lemma antitone_of_le_pred (hf : ∀ a, ¬ IsMin a → f a ≤ f (pred a)) : Antitone f := by simpa using antitoneOn_of_le_pred Set.ordConnected_univ (by simpa using hf) lemma strictMono_of_pred_lt (hf : ∀ a, ¬ IsMin a → f (pred a) < f a) : StrictMono f := by simpa using strictMonoOn_of_pred_lt Set.ordConnected_univ (by simpa using hf) lemma strictAnti_of_lt_pred (hf : ∀ a, ¬ IsMin a → f a < f (pred a)) : StrictAnti f := by simpa using strictAntiOn_of_lt_pred Set.ordConnected_univ (by simpa using hf) end PredOrder end Monotone
.lake/packages/mathlib/Mathlib/Order/SuccPred/CompleteLinearOrder.lean
import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.SuccPred.Limit /-! # Relation between `IsSuccPrelimit` and `iSup` in (conditionally) complete linear orders. -/ open Order Set variable {ι : Sort*} {α : Type*} section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [Nonempty ι] {f : ι → α} {s : Set α} {x : α} lemma csSup_mem_of_not_isSuccPrelimit (hne : s.Nonempty) (hbdd : BddAbove s) (hlim : ¬ IsSuccPrelimit (sSup s)) : sSup s ∈ s := by obtain ⟨y, hy⟩ := not_forall_not.mp hlim obtain ⟨i, his, hi⟩ := exists_lt_of_lt_csSup hne hy.lt exact eq_of_le_of_not_lt (le_csSup hbdd his) (hy.2 hi) ▸ his lemma csInf_mem_of_not_isPredPrelimit (hne : s.Nonempty) (hbdd : BddBelow s) (hlim : ¬ IsPredPrelimit (sInf s)) : sInf s ∈ s := by obtain ⟨y, hy⟩ := not_forall_not.mp hlim obtain ⟨i, his, hi⟩ := exists_lt_of_csInf_lt hne hy.lt exact eq_of_le_of_not_lt (csInf_le hbdd his) (hy.2 · hi) ▸ his lemma exists_eq_ciSup_of_not_isSuccPrelimit (hf : BddAbove (range f)) (hf' : ¬ IsSuccPrelimit (⨆ i, f i)) : ∃ i, f i = ⨆ i, f i := csSup_mem_of_not_isSuccPrelimit (range_nonempty f) hf hf' lemma exists_eq_ciInf_of_not_isPredPrelimit (hf : BddBelow (range f)) (hf' : ¬ IsPredPrelimit (⨅ i, f i)) : ∃ i, f i = ⨅ i, f i := csInf_mem_of_not_isPredPrelimit (range_nonempty f) hf hf' lemma IsLUB.mem_of_nonempty_of_not_isSuccPrelimit (hs : IsLUB s x) (hne : s.Nonempty) (hx : ¬ IsSuccPrelimit x) : x ∈ s := hs.csSup_eq hne ▸ csSup_mem_of_not_isSuccPrelimit hne hs.bddAbove (hs.csSup_eq hne ▸ hx) lemma IsGLB.mem_of_nonempty_of_not_isPredPrelimit (hs : IsGLB s x) (hne : s.Nonempty) (hx : ¬ IsPredPrelimit x) : x ∈ s := hs.csInf_eq hne ▸ csInf_mem_of_not_isPredPrelimit hne hs.bddBelow (hs.csInf_eq hne ▸ hx) lemma IsLUB.exists_of_nonempty_of_not_isSuccPrelimit (hf : IsLUB (range f) x) (hx : ¬ IsSuccPrelimit x) : ∃ i, f i = x := hf.mem_of_nonempty_of_not_isSuccPrelimit (range_nonempty f) hx lemma IsGLB.exists_of_nonempty_of_not_isPredPrelimit (hf : IsGLB (range f) x) (hx : ¬ IsPredPrelimit x) : ∃ i, f i = x := hf.mem_of_nonempty_of_not_isPredPrelimit (range_nonempty f) hx open Classical in /-- Every conditionally complete linear order with well-founded `<` is a successor order, by setting the successor of an element to be the infimum of all larger elements. -/ noncomputable def ConditionallyCompleteLinearOrder.toSuccOrder [WellFoundedLT α] : SuccOrder α where succ a := if IsMax a then a else sInf {b | a < b} le_succ a := by by_cases h : IsMax a · simp [h] · simp only [h, ↓reduceIte] rw [not_isMax_iff] at h exact le_csInf h (fun b => le_of_lt) max_of_succ_le hs := by by_contra h simp [h] at hs rw [not_isMax_iff] at h exact hs.not_gt (csInf_mem h) succ_le_of_lt {a b} ha := by simp only [ha.not_isMax, ↓reduceIte] exact csInf_le ⟨a, fun _ hc => hc.le⟩ ha end ConditionallyCompleteLinearOrder section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α} {s : Set α} {x : α} /-- See `csSup_mem_of_not_isSuccPrelimit` for the `ConditionallyCompleteLinearOrder` version. -/ lemma csSup_mem_of_not_isSuccPrelimit' (hbdd : BddAbove s) (hlim : ¬ IsSuccPrelimit (sSup s)) : sSup s ∈ s := by obtain rfl | hs := s.eq_empty_or_nonempty · simp [isSuccPrelimit_bot] at hlim · exact csSup_mem_of_not_isSuccPrelimit hs hbdd hlim /-- See `exists_eq_ciSup_of_not_isSuccPrelimit` for the `ConditionallyCompleteLinearOrder` version. -/ lemma exists_eq_ciSup_of_not_isSuccPrelimit' (hf : BddAbove (range f)) (hf' : ¬ IsSuccPrelimit (⨆ i, f i)) : ∃ i, f i = ⨆ i, f i := csSup_mem_of_not_isSuccPrelimit' hf hf' theorem Order.IsSuccPrelimit.sSup_Iio (h : IsSuccPrelimit x) : sSup (Iio x) = x := by obtain rfl | hx := eq_bot_or_bot_lt x · simp · exact h.isLUB_Iio.csSup_eq ⟨⊥, hx⟩ theorem Order.IsSuccPrelimit.iSup_Iio (h : IsSuccPrelimit x) : ⨆ a : Iio x, a.1 = x := by rw [← sSup_eq_iSup', h.sSup_Iio] theorem Order.IsSuccLimit.sSup_Iio (h : IsSuccLimit x) : sSup (Iio x) = x := h.isSuccPrelimit.sSup_Iio theorem Order.IsSuccLimit.iSup_Iio (h : IsSuccLimit x) : ⨆ a : Iio x, a.1 = x := h.isSuccPrelimit.iSup_Iio theorem sSup_Iio_eq_self_iff_isSuccPrelimit : sSup (Iio x) = x ↔ IsSuccPrelimit x := by refine ⟨fun h ↦ ?_, IsSuccPrelimit.sSup_Iio⟩ by_contra hx rw [← h] at hx simpa [h] using csSup_mem_of_not_isSuccPrelimit' bddAbove_Iio hx theorem iSup_Iio_eq_self_iff_isSuccPrelimit : ⨆ a : Iio x, a.1 = x ↔ IsSuccPrelimit x := by rw [← sSup_eq_iSup', sSup_Iio_eq_self_iff_isSuccPrelimit] theorem iSup_succ [SuccOrder α] (x : α) : ⨆ a : Iio x, succ a.1 = x := by have H : BddAbove (range fun a : Iio x ↦ succ a.1) := ⟨succ x, by simp +contextual [upperBounds, succ_le_succ, le_of_lt]⟩ apply le_antisymm _ (le_of_forall_lt fun y hy ↦ ?_) · rw [ciSup_le_iff' H] exact fun a ↦ succ_le_of_lt a.2 · rw [lt_ciSup_iff' H] exact ⟨⟨y, hy⟩, lt_succ_of_not_isMax hy.not_isMax⟩ end ConditionallyCompleteLinearOrderBot section CompleteLinearOrder variable [CompleteLinearOrder α] {s : Set α} {f : ι → α} {x : α} lemma sSup_mem_of_not_isSuccPrelimit (hlim : ¬ IsSuccPrelimit (sSup s)) : sSup s ∈ s := by obtain ⟨y, hy⟩ := not_forall_not.mp hlim obtain ⟨i, his, hi⟩ := lt_sSup_iff.mp hy.lt exact eq_of_le_of_not_lt (le_sSup his) (hy.2 hi) ▸ his lemma sInf_mem_of_not_isPredPrelimit (hlim : ¬ IsPredPrelimit (sInf s)) : sInf s ∈ s := by obtain ⟨y, hy⟩ := not_forall_not.mp hlim obtain ⟨i, his, hi⟩ := sInf_lt_iff.mp hy.lt exact eq_of_le_of_not_lt (sInf_le his) (hy.2 · hi) ▸ his lemma exists_eq_iSup_of_not_isSuccPrelimit (hf : ¬ IsSuccPrelimit (⨆ i, f i)) : ∃ i, f i = ⨆ i, f i := sSup_mem_of_not_isSuccPrelimit hf lemma exists_eq_iInf_of_not_isPredPrelimit (hf : ¬ IsPredPrelimit (⨅ i, f i)) : ∃ i, f i = ⨅ i, f i := sInf_mem_of_not_isPredPrelimit hf end CompleteLinearOrder
.lake/packages/mathlib/Mathlib/Order/SuccPred/LinearLocallyFinite.lean
import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.Countable.Basic import Mathlib.Data.Finset.Max import Mathlib.Data.Fintype.Pigeonhole import Mathlib.Logic.Encodable.Basic import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.SuccPred.Archimedean /-! # Linear locally finite orders We prove that a `LinearOrder` which is a `LocallyFiniteOrder` also verifies * `SuccOrder` * `PredOrder` * `IsSuccArchimedean` * `IsPredArchimedean` * `Countable` Furthermore, we show that there is an `OrderIso` between such an order and a subset of `ℤ`. ## Main definitions * `toZ i0 i`: in a linear order on which we can define predecessors and successors and which is succ-archimedean, we can assign a unique integer `toZ i0 i` to each element `i : ι` while respecting the order, starting from `toZ i0 i0 = 0`. ## Main results Results about linear locally finite orders: * `LinearLocallyFiniteOrder.SuccOrder`: a linear locally finite order has a successor function. * `LinearLocallyFiniteOrder.PredOrder`: a linear locally finite order has a predecessor function. * `LinearLocallyFiniteOrder.isSuccArchimedean`: a linear locally finite order is succ-archimedean. * `LinearOrder.pred_archimedean_of_succ_archimedean`: a succ-archimedean linear order is also pred-archimedean. * `countable_of_linear_succ_pred_arch` : a succ-archimedean linear order is countable. About `toZ`: * `orderIsoRangeToZOfLinearSuccPredArch`: `toZ` defines an `OrderIso` between `ι` and its range. * `orderIsoNatOfLinearSuccPredArch`: if the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. * `orderIsoIntOfLinearSuccPredArch`: if the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. * `orderIsoRangeOfLinearSuccPredArch`: if the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range ((toZ ⊥ ⊤).toNat + 1)`. -/ open Order variable {ι : Type*} [LinearOrder ι] namespace LinearOrder variable [SuccOrder ι] [PredOrder ι] instance (priority := 100) isPredArchimedean_of_isSuccArchimedean [IsSuccArchimedean ι] : IsPredArchimedean ι where exists_pred_iterate_of_le {i j} hij := by have h_exists := exists_succ_iterate_of_le hij obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j := ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩ refine ⟨n, ?_⟩ rw [← hn_eq] cases n with | zero => simp only [Function.iterate_zero, id] | succ n => rw [pred_succ_iterate_of_not_isMax] rw [Nat.succ_sub_succ_eq_sub, tsub_zero] suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this refine lt_of_le_of_ne ?_ ?_ · rw [Function.iterate_succ_apply'] exact le_succ _ · rw [hn_eq] exact hn_lt_ne _ (Nat.lt_succ_self n) instance isSuccArchimedean_of_isPredArchimedean [IsPredArchimedean ι] : IsSuccArchimedean ι := inferInstanceAs (IsSuccArchimedean ιᵒᵈᵒᵈ) /-- In a linear `SuccOrder` that's also a `PredOrder`, `IsSuccArchimedean` and `IsPredArchimedean` are equivalent. -/ theorem isSuccArchimedean_iff_isPredArchimedean : IsSuccArchimedean ι ↔ IsPredArchimedean ι where mp _ := isPredArchimedean_of_isSuccArchimedean mpr _ := isSuccArchimedean_of_isPredArchimedean end LinearOrder namespace LinearLocallyFiniteOrder /-- Successor in a linear order. This defines a true successor only when `i` is isolated from above, i.e. when `i` is not the greatest lower bound of `(i, ∞)`. -/ noncomputable def succFn (i : ι) : ι := (exists_glb_Ioi i).choose theorem succFn_spec (i : ι) : IsGLB (Set.Ioi i) (succFn i) := (exists_glb_Ioi i).choose_spec theorem le_succFn (i : ι) : i ≤ succFn i := by rw [le_isGLB_iff (succFn_spec i), mem_lowerBounds] exact fun x hx ↦ le_of_lt hx theorem isGLB_Ioc_of_isGLB_Ioi {i j k : ι} (hij_lt : i < j) (h : IsGLB (Set.Ioi i) k) : IsGLB (Set.Ioc i j) k := by simp_rw [IsGLB, IsGreatest, mem_upperBounds, mem_lowerBounds] at h ⊢ refine ⟨fun x hx ↦ h.1 x hx.1, fun x hx ↦ h.2 x ?_⟩ intro y hy rcases le_or_gt y j with h_le | h_lt · exact hx y ⟨hy, h_le⟩ · exact le_trans (hx j ⟨hij_lt, le_rfl⟩) h_lt.le theorem isMax_of_succFn_le [LocallyFiniteOrder ι] (i : ι) (hi : succFn i ≤ i) : IsMax i := by refine fun j _ ↦ not_lt.mp fun hij_lt ↦ ?_ have h_succFn_eq : succFn i = i := le_antisymm hi (le_succFn i) have h_glb : IsGLB (Finset.Ioc i j : Set ι) i := by rw [Finset.coe_Ioc] have h := succFn_spec i rw [h_succFn_eq] at h exact isGLB_Ioc_of_isGLB_Ioi hij_lt h have hi_mem : i ∈ Finset.Ioc i j := by refine Finset.isGLB_mem _ h_glb ?_ exact ⟨_, Finset.mem_Ioc.mpr ⟨hij_lt, le_rfl⟩⟩ rw [Finset.mem_Ioc] at hi_mem exact lt_irrefl i hi_mem.1 theorem succFn_le_of_lt (i j : ι) (hij : i < j) : succFn i ≤ j := by have h := succFn_spec i rw [IsGLB, IsGreatest, mem_lowerBounds] at h exact h.1 j hij theorem le_of_lt_succFn (j i : ι) (hij : j < succFn i) : j ≤ i := by rw [lt_isGLB_iff (succFn_spec i)] at hij obtain ⟨k, hk_lb, hk⟩ := hij rw [mem_lowerBounds] at hk_lb exact not_lt.mp fun hi_lt_j ↦ not_le.mpr hk (hk_lb j hi_lt_j) variable (ι) in /-- A locally finite order is a `SuccOrder`. This is not an instance, because its `succ` field conflicts with computable `SuccOrder` structures on `ℕ` and `ℤ`. -/ noncomputable def succOrder [LocallyFiniteOrder ι] : SuccOrder ι where succ := succFn le_succ := le_succFn max_of_succ_le h := isMax_of_succFn_le _ h succ_le_of_lt h := succFn_le_of_lt _ _ h variable (ι) in /-- A locally finite order is a `PredOrder`. This is not an instance, because its `succ` field conflicts with computable `PredOrder` structures on `ℕ` and `ℤ`. -/ noncomputable def predOrder [LocallyFiniteOrder ι] : PredOrder ι := letI := succOrder (ι := ιᵒᵈ) inferInstanceAs (PredOrder ιᵒᵈᵒᵈ) instance (priority := 100) [LocallyFiniteOrder ι] [SuccOrder ι] : IsSuccArchimedean ι where exists_succ_iterate_of_le := by intro i j hij rw [le_iff_lt_or_eq] at hij rcases hij with hij | hij swap · refine ⟨0, ?_⟩ simpa only [Function.iterate_zero, id] using hij by_contra! h have h_lt : ∀ n, succ^[n] i < j := fun n ↦ by induction n with | zero => simpa only [Function.iterate_zero, id] using hij | succ n hn => refine lt_of_le_of_ne ?_ (h _) rw [Function.iterate_succ', Function.comp_apply] exact succ_le_of_lt hn have h_mem : ∀ n, succ^[n] i ∈ Finset.Icc i j := fun n ↦ Finset.mem_Icc.mpr ⟨le_succ_iterate n i, (h_lt n).le⟩ obtain ⟨n, m, hnm, h_eq⟩ : ∃ n m, n < m ∧ succ^[n] i = succ^[m] i := by let f : ℕ → Finset.Icc i j := fun n ↦ ⟨succ^[n] i, h_mem n⟩ obtain ⟨n, m, hnm_ne, hfnm⟩ : ∃ n m, n ≠ m ∧ f n = f m := Finite.exists_ne_map_eq_of_infinite f have hnm_eq : succ^[n] i = succ^[m] i := by simpa only [f, Subtype.mk_eq_mk] using hfnm rcases le_total n m with h_le | h_le · exact ⟨n, m, lt_of_le_of_ne h_le hnm_ne, hnm_eq⟩ · exact ⟨m, n, lt_of_le_of_ne h_le hnm_ne.symm, hnm_eq.symm⟩ have h_max : IsMax (succ^[n] i) := isMax_iterate_succ_of_eq_of_ne h_eq hnm.ne exact not_le.mpr (h_lt n) (h_max (h_lt n).le) instance (priority := 100) [LocallyFiniteOrder ι] [PredOrder ι] : IsPredArchimedean ι := inferInstanceAs (IsPredArchimedean ιᵒᵈᵒᵈ) end LinearLocallyFiniteOrder section toZ -- Requiring either of `IsSuccArchimedean` or `IsPredArchimedean` is equivalent. variable [SuccOrder ι] [IsSuccArchimedean ι] [PredOrder ι] {i0 i : ι} -- For "to_Z" /-- `toZ` numbers elements of `ι` according to their order, starting from `i0`. We prove in `orderIsoRangeToZOfLinearSuccPredArch` that this defines an `OrderIso` between `ι` and the range of `toZ`. -/ def toZ (i0 i : ι) : ℤ := dite (i0 ≤ i) (fun hi ↦ Nat.find (exists_succ_iterate_of_le hi)) fun hi ↦ -Nat.find (exists_pred_iterate_of_le (α := ι) (not_le.mp hi).le) theorem toZ_of_ge (hi : i0 ≤ i) : toZ i0 i = Nat.find (exists_succ_iterate_of_le hi) := dif_pos hi theorem toZ_of_lt (hi : i < i0) : toZ i0 i = -Nat.find (exists_pred_iterate_of_le (α := ι) hi.le) := dif_neg (not_le.mpr hi) @[simp] theorem toZ_of_eq : toZ i0 i0 = 0 := by rw [toZ_of_ge le_rfl] norm_cast refine le_antisymm (Nat.find_le ?_) (zero_le _) rw [Function.iterate_zero, id] theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by rw [toZ_of_ge hi, Int.toNat_natCast] exact Nat.find_spec (exists_succ_iterate_of_le hi) theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by rw [toZ_of_lt hi, neg_neg, Int.toNat_natCast] exact Nat.find_spec (exists_pred_iterate_of_le hi.le) lemma toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by rw [toZ_of_ge hi]; exact Int.natCast_nonneg _ theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by refine lt_of_le_of_ne ?_ ?_ · rw [toZ_of_lt hi] cutsat · by_contra h have h_eq := iterate_pred_toZ i hi rw [← h_eq, h] at hi simp only [neg_zero, Int.toNat_zero, Function.iterate_zero, id, lt_self_iff_false] at hi theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by rw [toZ_of_ge (le_succ_iterate _ _)] norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by rcases le_or_gt i0 (pred^[n] i0) with h | h · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h rw [h_eq, toZ_of_eq] cutsat · rw [toZ_of_lt h] refine Int.neg_le_neg ?_ norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_succ_of_not_isMax (n : ℕ) (hn : ¬IsMax (succ^[n] i0)) : toZ i0 (succ^[n] i0) = n := by let m := (toZ i0 (succ^[n] i0)).toNat have h_eq : succ^[m] i0 = succ^[n] i0 := iterate_succ_toZ _ (le_succ_iterate _ _) by_cases hmn : m = n · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_ge (le_succ_iterate _ _), max_eq_left] exact Int.natCast_nonneg _ suffices IsMax (succ^[n] i0) from absurd this hn exact isMax_iterate_succ_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem toZ_iterate_pred_of_not_isMin (n : ℕ) (hn : ¬IsMin (pred^[n] i0)) : toZ i0 (pred^[n] i0) = -n := by rcases n with - | n · simp have : pred^[n.succ] i0 < i0 := by refine lt_of_le_of_ne (pred_iterate_le _ _) fun h_pred_iterate_eq ↦ hn ?_ have h_pred_eq_pred : pred^[n.succ] i0 = pred^[0] i0 := by rwa [Function.iterate_zero, id] exact isMin_iterate_pred_of_eq_of_ne h_pred_eq_pred (Nat.succ_ne_zero n) let m := (-toZ i0 (pred^[n.succ] i0)).toNat have h_eq : pred^[m] i0 = pred^[n.succ] i0 := iterate_pred_toZ _ this by_cases hmn : m = n + 1 · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_lt this, max_eq_left, neg_neg] rw [neg_neg] exact Int.natCast_nonneg _ · suffices IsMin (pred^[n.succ] i0) from absurd this hn exact isMin_iterate_pred_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem le_of_toZ_le {j : ι} (h_le : toZ i0 i ≤ toZ i0 j) : i ≤ j := by rcases le_or_gt i0 i with hi | hi <;> rcases le_or_gt i0 j with hj | hj · rw [← iterate_succ_toZ i hi, ← iterate_succ_toZ j hj] exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ _) (Int.toNat_le_toNat h_le) · exact absurd ((toZ_neg hj).trans_le (toZ_nonneg hi)) (not_lt.mpr h_le) · exact hi.le.trans hj · rw [← iterate_pred_toZ i hi, ← iterate_pred_toZ j hj] refine Monotone.antitone_iterate_of_map_le pred_mono (pred_le _) (Int.toNat_le_toNat ?_) exact Int.neg_le_neg h_le theorem toZ_mono {i j : ι} (h_le : i ≤ j) : toZ i0 i ≤ toZ i0 j := by by_cases hi_max : IsMax i · rw [le_antisymm h_le (hi_max h_le)] by_cases hj_min : IsMin j · rw [le_antisymm h_le (hj_min h_le)] rcases le_or_gt i0 i with hi | hi <;> rcases le_or_gt i0 j with hj | hj · let m := Nat.find (exists_succ_iterate_of_le h_le) have hm : succ^[m] i = j := Nat.find_spec (exists_succ_iterate_of_le h_le) have hj_eq : j = succ^[(toZ i0 i).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_succ_toZ i hi] rw [Function.iterate_add] rfl by_contra h obtain hm0 | hm0 : m = 0 ∨ 1 ≤ m := by cutsat · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hi_max (max_of_succ_le (le_trans ?_ (@le_of_toZ_le _ _ _ _ _ i0 j i ?_))) · have h_succ_le : succ^[(toZ i0 i).toNat + 1] i0 ≤ j := by rw [hj_eq] exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ i0) (by gcongr) rwa [Function.iterate_succ', Function.comp_apply, iterate_succ_toZ i hi] at h_succ_le · exact le_of_not_ge h · exact absurd h_le (not_le.mpr (hj.trans_le hi)) · exact (toZ_neg hi).le.trans (toZ_nonneg hj) · let m := Nat.find (exists_pred_iterate_of_le (α := ι) h_le) have hm : pred^[m] j = i := Nat.find_spec (exists_pred_iterate_of_le (α := ι) h_le) have hj_eq : i = pred^[(-toZ i0 j).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_pred_toZ j hj] rw [Function.iterate_add] rfl by_contra h obtain hm0 | hm0 : m = 0 ∨ 1 ≤ m := by cutsat · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hj_min (min_of_le_pred ?_) refine (@le_of_toZ_le _ _ _ _ _ i0 j i ?_).trans ?_ · exact le_of_not_ge h · have h_le_pred : i ≤ pred^[(-toZ i0 j).toNat + 1] i0 := by rw [hj_eq] exact Monotone.antitone_iterate_of_map_le pred_mono (pred_le i0) (by gcongr) rwa [Function.iterate_succ', Function.comp_apply, iterate_pred_toZ j hj] at h_le_pred theorem toZ_le_iff (i j : ι) : toZ i0 i ≤ toZ i0 j ↔ i ≤ j := ⟨le_of_toZ_le, toZ_mono⟩ theorem toZ_iterate_succ [NoMaxOrder ι] (n : ℕ) : toZ i0 (succ^[n] i0) = n := toZ_iterate_succ_of_not_isMax n (not_isMax _) theorem toZ_iterate_pred [NoMinOrder ι] (n : ℕ) : toZ i0 (pred^[n] i0) = -n := toZ_iterate_pred_of_not_isMin n (not_isMin _) theorem injective_toZ : Function.Injective (toZ i0) := fun _ _ h ↦ le_antisymm (le_of_toZ_le h.le) (le_of_toZ_le h.symm.le) end toZ section OrderIso variable [SuccOrder ι] [PredOrder ι] [IsSuccArchimedean ι] /-- `toZ` defines an `OrderIso` between `ι` and its range. -/ noncomputable def orderIsoRangeToZOfLinearSuccPredArch [hι : Nonempty ι] : ι ≃o Set.range (toZ hι.some) where toEquiv := Equiv.ofInjective _ injective_toZ map_rel_iff' := by intro i j; exact toZ_le_iff i j instance (priority := 100) countable_of_linear_succ_pred_arch : Countable ι := by rcases isEmpty_or_nonempty ι with _ | hι · infer_instance · exact Countable.of_equiv _ orderIsoRangeToZOfLinearSuccPredArch.symm.toEquiv /-- If the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. -/ noncomputable def orderIsoIntOfLinearSuccPredArch [NoMaxOrder ι] [NoMinOrder ι] [hι : Nonempty ι] : ι ≃o ℤ where toFun := toZ hι.some invFun n := if 0 ≤ n then succ^[n.toNat] hι.some else pred^[(-n).toNat] hι.some left_inv i := by rcases le_or_gt hι.some i with hi | hi · have h_nonneg : 0 ≤ toZ hι.some i := toZ_nonneg hi simp_rw [if_pos h_nonneg] exact iterate_succ_toZ i hi · have h_neg : toZ hι.some i < 0 := toZ_neg hi simp_rw [if_neg (not_le.mpr h_neg)] exact iterate_pred_toZ i hi right_inv n := by rcases le_or_gt 0 n with hn | hn · simp_rw [if_pos hn] rw [toZ_iterate_succ] exact Int.toNat_of_nonneg hn · simp_rw [if_neg (not_le.mpr hn)] rw [toZ_iterate_pred] simp only [hn.le, Int.toNat_of_nonneg, Int.neg_nonneg_of_nonpos, Int.neg_neg] map_rel_iff' := by intro i j; exact toZ_le_iff i j /-- If the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. -/ def orderIsoNatOfLinearSuccPredArch [NoMaxOrder ι] [OrderBot ι] : ι ≃o ℕ where toFun i := (toZ ⊥ i).toNat invFun n := succ^[n] ⊥ left_inv i := by dsimp only exact iterate_succ_toZ i bot_le right_inv n := by dsimp only rw [toZ_iterate_succ] exact Int.toNat_natCast n map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] /-- If the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range n` for some `n`. -/ def orderIsoRangeOfLinearSuccPredArch [OrderBot ι] [OrderTop ι] : ι ≃o Finset.range ((toZ ⊥ (⊤ : ι)).toNat + 1) where toFun i := ⟨(toZ ⊥ i).toNat, Finset.mem_range_succ_iff.mpr (Int.toNat_le_toNat ((toZ_le_iff _ _).mpr le_top))⟩ invFun n := succ^[n] ⊥ left_inv i := iterate_succ_toZ i bot_le right_inv n := by ext1 simp only refine le_antisymm ?_ ?_ · rw [Int.toNat_le] exact toZ_iterate_succ_le _ by_cases hn_max : IsMax (succ^[↑n] (⊥ : ι)) · rw [← isTop_iff_isMax, isTop_iff_eq_top] at hn_max rw [hn_max] exact Nat.lt_succ_iff.mp (Finset.mem_range.mp n.prop) · rw [toZ_iterate_succ_of_not_isMax _ hn_max] simp only [Int.toNat_natCast, le_refl] map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] end OrderIso instance (priority := 100) Countable.of_linearOrder_locallyFiniteOrder [LocallyFiniteOrder ι] : Countable ι := have := LinearLocallyFiniteOrder.succOrder ι have := LinearLocallyFiniteOrder.predOrder ι countable_of_linear_succ_pred_arch
.lake/packages/mathlib/Mathlib/Order/SuccPred/Basic.lean
import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] where (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non-maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function -/ succ : α → α /-- Proof of basic ordering with respect to `succ` -/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function -/ pred : α → α /-- Proof of basic ordering with respect to `pred` -/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b → a ≤ pred b instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (α) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_ge fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_gt⟩ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_ge hba).trans_le <| le_succ b) · rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_ge hba · exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax · ha) theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≤ b → a < succ b := (lt_succ_of_le_of_not_isMax · <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by by_cases ha : IsMax a · simpa [ha.succ_eq] using le_of_eq · rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) : f (succ a) = succ (f a) := by by_cases h : IsMax a · rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] · exact ((apply_covBy_apply_iff f).2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder α] theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] {a b : α} theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by obtain ha | ha := (le_succ a).eq_or_lt · exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin · exact not_isMin_of_lt ha theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext fun _ => le_succ_iff_eq_or_le theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) := ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)] theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_isMax <| not_isMax b theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff alias ⟨lt_of_succ_lt_succ, _⟩ := succ_lt_succ_iff -- TODO: prove for a succ-archimedean non-linear order with bottom @[simp] theorem Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_isMax <| not_isMax _ -- TODO: prove for a succ-archimedean non-linear order @[simp] theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b) theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1 theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_isMax <| not_isMax a theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b @[simp] theorem Ioo_eq_empty_iff_le_succ : Ioo a b = ∅ ↔ b ≤ succ a := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · contrapose! h exact ⟨succ a, lt_succ_iff_not_isMax.mpr (not_isMax a), h⟩ · ext x suffices a < x → b ≤ x by simpa exact fun hx ↦ le_of_lt_succ <| lt_of_le_of_lt h <| succ_strictMono hx end NoMaxOrder section OrderBot variable [OrderBot α] theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] end OrderBot end LinearOrder /-- There is at most one way to define the successors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (SuccOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMax a · exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm · exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩ theorem succ_eq_sInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_sInf fun b => succ_le_of_lt).antisymm obtain rfl | ha := eq_or_ne a ⊤ · rw [succ_top] exact le_top · exact sInf_le (lt_succ_iff_ne_top.2 ha) theorem succ_eq_iInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = ⨅ b > a, b := by rw [succ_eq_sInf, iInf_subtype', iInf, Subtype.range_coe_subtype, Ioi] theorem succ_eq_csInf [ConditionallyCompleteLattice α] [SuccOrder α] [NoMaxOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_csInf nonempty_Ioi fun b => succ_le_of_lt).antisymm exact csInf_le ⟨a, fun b => le_of_lt⟩ <| lt_succ a /-! ### Predecessor order -/ section Preorder variable [Preorder α] [PredOrder α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := PredOrder.pred theorem pred_le : ∀ a : α, pred a ≤ a := PredOrder.pred_le theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a := PredOrder.min_of_le_pred theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b := PredOrder.le_pred_of_lt alias _root_.LT.lt.le_pred := le_pred_of_lt @[simp] theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a := ⟨min_of_le_pred, fun h => h <| pred_le _⟩ alias ⟨_root_.IsMin.of_le_pred, _root_.IsMin.le_pred⟩ := le_pred_iff_isMin @[simp] theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a := ⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_ge fun h => ha <| min_of_le_pred h⟩ alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin theorem pred_wcovBy (a : α) : pred a ⩿ a := ⟨pred_le a, fun _ hb nh => (le_pred_of_lt nh).not_gt hb⟩ theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a := (pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h theorem pred_lt_of_not_isMin_of_le (ha : ¬IsMin a) : a ≤ b → pred a < b := (pred_lt_of_not_isMin ha).trans_le theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a := ⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩ lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b := pred_lt_of_not_isMin_of_le ha <| le_pred_of_lt h theorem pred_le_pred_of_not_isMin_of_le (ha : ¬IsMin a) (hb : ¬IsMin b) : a ≤ b → pred a ≤ pred b := by rw [le_pred_iff_of_not_isMin hb] apply pred_lt_of_not_isMin_of_le ha @[simp, mono, gcongr] theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred /-- See also `Order.pred_eq_of_covBy`. -/ lemma pred_le_of_wcovBy (h : a ⩿ b) : pred b ≤ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (hab.lt.le_pred.lt_of_not_ge hba) (pred_lt_of_not_isMin hab.lt.not_isMin) · exact (pred_le _).trans hba alias _root_.WCovBy.pred_le := pred_le_of_wcovBy theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.iterate_le_of_le pred_mono pred_le k x theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_lt : n < m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_ne : n ≠ m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne theorem Ici_subset_Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ici a ⊆ Ioi (pred a) := fun _ ↦ pred_lt_of_not_isMin_of_le ha theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a := Set.ext fun _ => le_pred_iff_of_not_isMin ha theorem Icc_subset_Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Icc a b ⊆ Ioc (pred a) b := by rw [← Ioi_inter_Iic, ← Ici_inter_Iic] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Ico_subset_Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ico a b ⊆ Ioo (pred a) b := by rw [← Ioi_inter_Iio, ← Ici_inter_Iio] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio] theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio] section NoMinOrder variable [NoMinOrder α] theorem pred_lt (a : α) : pred a < a := pred_lt_of_not_isMin <| not_isMin a @[simp] theorem pred_lt_of_le : a ≤ b → pred a < b := pred_lt_of_not_isMin_of_le <| not_isMin a @[simp] theorem le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_isMin <| not_isMin b theorem pred_le_pred_of_le : a ≤ b → pred a ≤ pred b := by intro; simp_all theorem pred_lt_pred : a < b → pred a < pred b := by intro; simp_all theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred theorem pred_covBy (a : α) : pred a ⋖ a := pred_covBy_of_not_isMin <| not_isMin a theorem Ici_subset_Ioi_pred (a : α) : Ici a ⊆ Ioi (pred a) := by simp @[simp] theorem Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_isMin <| not_isMin a @[simp] theorem Icc_subset_Ioc_pred_left (a b : α) : Icc a b ⊆ Ioc (pred a) b := Icc_subset_Ioc_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Ico_subset_Ioo_pred_left (a b : α) : Ico a b ⊆ Ioo (pred a) b := Ico_subset_Ioo_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_of_not_isMin <| not_isMin _ @[simp] theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b := Ioc_pred_right_of_not_isMin <| not_isMin _ end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} @[simp] theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a := ⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩ alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin lemma le_iff_eq_or_le_pred : a ≤ b ↔ a = b ∨ a ≤ pred b := by by_cases hb : IsMin b · simpa [hb.pred_eq] using le_of_eq · rw [le_pred_iff_of_not_isMin hb, le_iff_eq_or_lt] theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩ rintro (rfl | rfl) · exact ⟨pred_le b, le_rfl⟩ · exact ⟨le_rfl, pred_le a⟩ /-- See also `Order.pred_le_of_wcovBy`. -/ lemma pred_eq_of_covBy (h : a ⋖ b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt) alias _root_.CovBy.pred_eq := pred_eq_of_covBy theorem _root_.OrderIso.map_pred {β : Type*} [PartialOrder β] [PredOrder β] (f : α ≃o β) (a : α) : f (pred a) = pred (f a) := f.dual.map_succ a section NoMinOrder variable [NoMinOrder α] theorem pred_eq_iff_covBy : pred b = a ↔ a ⋖ b := ⟨by rintro rfl exact pred_covBy _, CovBy.pred_eq⟩ end NoMinOrder section OrderBot variable [OrderBot α] @[simp] theorem pred_bot : pred (⊥ : α) = ⊥ := isMin_bot.pred_eq theorem le_pred_iff_eq_bot : a ≤ pred a ↔ a = ⊥ := @succ_le_iff_eq_top αᵒᵈ _ _ _ _ theorem pred_lt_iff_ne_bot : pred a < a ↔ a ≠ ⊥ := @lt_succ_iff_ne_top αᵒᵈ _ _ _ _ end OrderBot section OrderTop variable [OrderTop α] [Nontrivial α] theorem pred_lt_top (a : α) : pred a < ⊤ := (pred_mono le_top).trans_lt <| pred_lt_of_not_isMin not_isMin_top theorem pred_ne_top (a : α) : pred a ≠ ⊤ := (pred_lt_top a).ne end OrderTop end PartialOrder section LinearOrder variable [LinearOrder α] [PredOrder α] {a b : α} theorem le_of_pred_lt {a b : α} : pred a < b → a ≤ b := fun h ↦ by by_contra! nh exact le_pred_of_lt nh |>.trans_lt h |>.false theorem pred_lt_iff_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a ≤ b := ⟨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_le⟩ theorem pred_lt_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a < pred b ↔ a < b := by rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb] theorem pred_le_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a ≤ pred b ↔ a ≤ b := by rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha] theorem Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = Ici a := Set.ext fun _ => pred_lt_iff_of_not_isMin ha theorem Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioc (pred a) b = Icc a b := by rw [← Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic] theorem Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioo (pred a) b = Ico a b := by rw [← Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio] theorem pred_eq_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a = pred b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, pred_le_pred_iff_of_not_isMin ha hb, pred_lt_pred_iff_of_not_isMin ha hb] theorem pred_le_iff_eq_or_le : pred a ≤ b ↔ b = pred a ∨ a ≤ b := by by_cases ha : IsMin a · rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq] · rw [← pred_lt_iff_of_not_isMin ha, le_iff_eq_or_lt, eq_comm] theorem pred_lt_iff_eq_or_lt_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a = b ∨ a < b := (pred_lt_iff_of_not_isMin ha).trans le_iff_eq_or_lt theorem not_isMax_pred [Nontrivial α] (a : α) : ¬ IsMax (pred a) := not_isMin_succ (α := αᵒᵈ) a theorem Ici_pred (a : α) : Ici (pred a) = insert (pred a) (Ici a) := ext fun _ => pred_le_iff_eq_or_le theorem Ioi_pred_eq_insert_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = insert a (Ioi a) := by ext x; simp only [insert, mem_setOf, @eq_comm _ x a, mem_Ioi, Set.insert] exact pred_lt_iff_eq_or_lt_of_not_isMin ha theorem Icc_pred_left (h : pred a ≤ b) : Icc (pred a) b = insert (pred a) (Icc a b) := by simp_rw [← Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)] theorem Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) := by simp_rw [← Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)] section NoMinOrder variable [NoMinOrder α] @[simp] theorem pred_lt_iff : pred a < b ↔ a ≤ b := pred_lt_iff_of_not_isMin <| not_isMin a theorem pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by simp theorem pred_lt_pred_iff : pred a < pred b ↔ a < b := by simp alias ⟨le_of_pred_le_pred, _⟩ := pred_le_pred_iff alias ⟨lt_of_pred_lt_pred, _⟩ := pred_lt_pred_iff -- TODO: prove for a pred-archimedean non-linear order with top @[simp] theorem Ioi_pred (a : α) : Ioi (pred a) = Ici a := Ioi_pred_of_not_isMin <| not_isMin a @[simp] theorem Ioc_pred_left (a b : α) : Ioc (pred a) b = Icc a b := Ioc_pred_left_of_not_isMin <| not_isMin _ -- TODO: prove for a pred-archimedean non-linear order @[simp] theorem Ioo_pred_left (a b : α) : Ioo (pred a) b = Ico a b := Ioo_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem pred_eq_pred_iff : pred a = pred b ↔ a = b := by simp_rw [eq_iff_le_not_lt, pred_le_pred_iff, pred_lt_pred_iff] theorem pred_injective : Injective (pred : α → α) := fun _ _ => pred_eq_pred_iff.1 theorem pred_ne_pred_iff : pred a ≠ pred b ↔ a ≠ b := pred_injective.ne_iff alias ⟨_, pred_ne_pred⟩ := pred_ne_pred_iff theorem pred_lt_iff_eq_or_lt : pred a < b ↔ a = b ∨ a < b := pred_lt_iff.trans le_iff_eq_or_lt theorem Ioi_pred_eq_insert (a : α) : Ioi (pred a) = insert a (Ioi a) := ext fun _ => pred_lt_iff_eq_or_lt.trans <| or_congr_left eq_comm theorem Ico_pred_right_eq_insert (h : a ≤ b) : Ioc (pred a) b = insert a (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iic.2 h)] theorem Ioo_pred_right_eq_insert (h : a < b) : Ioo (pred a) b = insert a (Ioo a b) := by simp_rw [← Ioi_inter_Iio, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iio.2 h)] @[simp] theorem Ioo_eq_empty_iff_pred_le : Ioo a b = ∅ ↔ pred b ≤ a := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · contrapose! h exact ⟨pred b, h, pred_lt_iff_not_isMin.mpr (not_isMin b)⟩ · ext x suffices a < x → b ≤ x by simpa exact fun hx ↦ le_of_pred_lt <| lt_of_le_of_lt h hx end NoMinOrder section OrderTop variable [OrderTop α] theorem pred_top_lt_iff [NoMinOrder α] : pred ⊤ < a ↔ a = ⊤ := @lt_succ_bot_iff αᵒᵈ _ _ _ _ _ theorem pred_top_le_iff : pred ⊤ ≤ a ↔ a = ⊤ ∨ a = pred ⊤ := @le_succ_bot_iff αᵒᵈ _ _ _ _ end OrderTop end LinearOrder /-- There is at most one way to define the predecessors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (PredOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMin a · exact (@IsMin.pred_eq _ _ h₀ _ ha).trans ha.pred_eq.symm · exact @CovBy.pred_eq _ _ h₀ _ _ (pred_covBy_of_not_isMin ha)⟩ theorem pred_eq_sSup [CompleteLattice α] [PredOrder α] : ∀ a : α, pred a = sSup (Set.Iio a) := succ_eq_sInf (α := αᵒᵈ) theorem pred_eq_iSup [CompleteLattice α] [PredOrder α] (a : α) : pred a = ⨆ b < a, b := succ_eq_iInf (α := αᵒᵈ) a theorem pred_eq_csSup [ConditionallyCompleteLattice α] [PredOrder α] [NoMinOrder α] (a : α) : pred a = sSup (Set.Iio a) := succ_eq_csInf (α := αᵒᵈ) a /-! ### Successor-predecessor orders -/ section SuccPredOrder section Preorder variable [Preorder α] [SuccOrder α] [PredOrder α] {a b : α} lemma le_succ_pred (a : α) : a ≤ succ (pred a) := (pred_wcovBy _).le_succ lemma pred_succ_le (a : α) : pred (succ a) ≤ a := (wcovBy_succ _).pred_le lemma pred_le_iff_le_succ : pred a ≤ b ↔ a ≤ succ b where mp hab := (le_succ_pred _).trans (succ_mono hab) mpr hab := (pred_mono hab).trans (pred_succ_le _) lemma gc_pred_succ : GaloisConnection (pred : α → α) succ := fun _ _ ↦ pred_le_iff_le_succ end Preorder variable [PartialOrder α] [SuccOrder α] [PredOrder α] {a : α} @[simp] theorem succ_pred_of_not_isMin (h : ¬IsMin a) : succ (pred a) = a := CovBy.succ_eq (pred_covBy_of_not_isMin h) @[simp] theorem pred_succ_of_not_isMax (h : ¬IsMax a) : pred (succ a) = a := CovBy.pred_eq (covBy_succ_of_not_isMax h) theorem succ_pred [NoMinOrder α] (a : α) : succ (pred a) = a := CovBy.succ_eq (pred_covBy _) theorem pred_succ [NoMaxOrder α] (a : α) : pred (succ a) = a := CovBy.pred_eq (covBy_succ _) theorem pred_succ_iterate_of_not_isMax (i : α) (n : ℕ) (hin : ¬IsMax (succ^[n - 1] i)) : pred^[n] (succ^[n] i) = i := by induction n with | zero => simp only [Function.iterate_zero, id] | succ n hn => rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hin have h_not_max : ¬IsMax (succ^[n - 1] i) := by rcases n with - | n · simpa using hin rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hn ⊢ have h_sub_le : succ^[n] i ≤ succ^[n.succ] i := by rw [Function.iterate_succ'] exact le_succ _ refine fun h_max => hin fun j hj => ?_ have hj_le : j ≤ succ^[n] i := h_max (h_sub_le.trans hj) exact hj_le.trans h_sub_le rw [Function.iterate_succ, Function.iterate_succ'] simp only [Function.comp_apply] rw [pred_succ_of_not_isMax hin] exact hn h_not_max theorem succ_pred_iterate_of_not_isMin (i : α) (n : ℕ) (hin : ¬IsMin (pred^[n - 1] i)) : succ^[n] (pred^[n] i) = i := @pred_succ_iterate_of_not_isMax αᵒᵈ _ _ _ i n hin end SuccPredOrder end Order open Order /-! ### `WithBot`, `WithTop` Adding a greatest/least element to a `SuccOrder` or to a `PredOrder`. As far as successors and predecessors are concerned, there are four ways to add a bottom or top element to an order: * Adding a `⊤` to an `OrderTop`: Preserves `succ` and `pred`. * Adding a `⊤` to a `NoMaxOrder`: Preserves `succ`. Never preserves `pred`. * Adding a `⊥` to an `OrderBot`: Preserves `succ` and `pred`. * Adding a `⊥` to a `NoMinOrder`: Preserves `pred`. Never preserves `succ`. where "preserves `(succ/pred)`" means `(Succ/Pred)Order α → (Succ/Pred)Order ((WithTop/WithBot) α)`. -/ namespace WithTop /-! #### Adding a `⊤` to an `OrderTop` -/ section Succ variable [PartialOrder α] [SuccOrder α] [∀ a : α, Decidable (succ a = a)] instance : SuccOrder (WithTop α) where succ a := match a with | ⊤ => ⊤ | Option.some a => ite (succ a = a) ⊤ (some (succ a)) le_succ a := by obtain - | a := a · exact le_top change _ ≤ ite _ _ _ split_ifs · exact le_top · exact coe_le_coe.2 (le_succ a) max_of_succ_le {a} ha := by cases a · exact isMax_top dsimp only at ha split_ifs at ha with ha' · exact (not_top_le_coe _ ha).elim · rw [coe_le_coe, succ_le_iff_isMax, ← succ_eq_iff_isMax] at ha exact (ha' ha).elim succ_le_of_lt {a b} h := by cases b · exact le_top cases a · exact (not_top_lt h).elim rw [coe_lt_coe] at h change ite _ _ _ ≤ _ split_ifs with ha · rw [succ_eq_iff_isMax] at ha exact (ha.not_lt h).elim · exact coe_le_coe.2 (succ_le_of_lt h) @[simp] theorem succ_coe_of_isMax {a : α} (h : IsMax a) : succ ↑a = (⊤ : WithTop α) := dif_pos (succ_eq_iff_isMax.2 h) theorem succ_coe_of_not_isMax {a : α} (h : ¬ IsMax a) : succ (↑a : WithTop α) = ↑(succ a) := dif_neg (succ_eq_iff_isMax.not.2 h) @[simp] theorem succ_coe [NoMaxOrder α] {a : α} : succ (↑a : WithTop α) = ↑(succ a) := succ_coe_of_not_isMax <| not_isMax a end Succ section Pred variable [Preorder α] [OrderTop α] [PredOrder α] instance : PredOrder (WithTop α) where pred a := match a with | ⊤ => some ⊤ | Option.some a => some (pred a) pred_le a := match a with | ⊤ => le_top | Option.some a => coe_le_coe.2 (pred_le a) min_of_le_pred {a} ha := by cases a · exact ((coe_lt_top (⊤ : α)).not_ge ha).elim · exact (min_of_le_pred <| coe_le_coe.1 ha).withTop le_pred_of_lt {a b} h := by cases a · exact (le_top.not_gt h).elim cases b · exact coe_le_coe.2 le_top exact coe_le_coe.2 (le_pred_of_lt <| coe_lt_coe.1 h) /-- Not to be confused with `WithTop.pred_bot`, which is about `WithTop.pred`. -/ @[simp] lemma orderPred_top : pred (⊤ : WithTop α) = ↑(⊤ : α) := rfl /-- Not to be confused with `WithTop.pred_coe`, which is about `WithTop.pred`. -/ @[simp] lemma orderPred_coe (a : α) : pred (↑a : WithTop α) = ↑(pred a) := rfl @[simp] theorem pred_untop : ∀ (a : WithTop α) (ha : a ≠ ⊤), pred (a.untop ha) = (pred a).untop (by induction a <;> simp) | ⊤, ha => (ha rfl).elim | (a : α), _ => rfl end Pred section Pred variable [Preorder α] [NoMaxOrder α] instance [hα : Nonempty α] : IsEmpty (PredOrder (WithTop α)) := ⟨by intro cases h : pred (⊤ : WithTop α) with | top => exact hα.elim fun a => (min_of_le_pred h.ge).not_lt <| coe_lt_top a | coe a => obtain ⟨c, hc⟩ := exists_gt a rw [← coe_lt_coe, ← h] at hc exact (le_pred_of_lt (coe_lt_top c)).not_gt hc⟩ end Pred end WithTop namespace WithBot /-! #### Adding a `⊥` to an `OrderBot` -/ section Succ variable [Preorder α] [OrderBot α] [SuccOrder α] instance : SuccOrder (WithBot α) where succ a := match a with | ⊥ => some ⊥ | Option.some a => some (succ a) le_succ a := match a with | ⊥ => bot_le | Option.some a => coe_le_coe.2 (le_succ a) max_of_succ_le {a} ha := by cases a · exact ((bot_lt_coe (⊥ : α)).not_ge ha).elim · exact (max_of_succ_le <| coe_le_coe.1 ha).withBot succ_le_of_lt {a b} h := by cases b · exact (not_lt_bot h).elim cases a · exact coe_le_coe.2 bot_le · exact coe_le_coe.2 (succ_le_of_lt <| coe_lt_coe.1 h) /-- Not to be confused with `WithBot.succ_bot`, which is about `WithBot.succ`. -/ @[simp] lemma orderSucc_bot : succ (⊥ : WithBot α) = ↑(⊥ : α) := rfl /-- Not to be confused with `WithBot.succ_coe`, which is about `WithBot.succ`. -/ @[simp] lemma orderSucc_coe (a : α) : succ (↑a : WithBot α) = ↑(succ a) := rfl @[simp] theorem succ_unbot : ∀ (a : WithBot α) (ha : a ≠ ⊥), succ (a.unbot ha) = (succ a).unbot (by induction a <;> simp) | ⊥, ha => (ha rfl).elim | (a : α), _ => rfl end Succ section Pred variable [PartialOrder α] [PredOrder α] [∀ a : α, Decidable (pred a = a)] instance : PredOrder (WithBot α) where pred a := match a with | ⊥ => ⊥ | Option.some a => ite (pred a = a) ⊥ (some (pred a)) pred_le a := by obtain - | a := a · exact bot_le change ite _ _ _ ≤ _ split_ifs · exact bot_le · exact coe_le_coe.2 (pred_le a) min_of_le_pred {a} ha := by cases a with | bot => exact isMin_bot | coe a => dsimp only at ha split_ifs at ha with ha' · exact (not_coe_le_bot _ ha).elim · rw [coe_le_coe, le_pred_iff_isMin, ← pred_eq_iff_isMin] at ha exact (ha' ha).elim le_pred_of_lt {a b} h := by cases a · exact bot_le cases b · exact (not_lt_bot h).elim rw [coe_lt_coe] at h change _ ≤ ite _ _ _ split_ifs with hb · rw [pred_eq_iff_isMin] at hb exact (hb.not_lt h).elim · exact coe_le_coe.2 (le_pred_of_lt h) @[simp] theorem pred_coe_of_isMin {a : α} (h : IsMin a) : pred ↑a = (⊥ : WithBot α) := dif_pos (pred_eq_iff_isMin.2 h) theorem pred_coe_of_not_isMin {a : α} (h : ¬ IsMin a) : pred (↑a : WithBot α) = ↑(pred a) := dif_neg (pred_eq_iff_isMin.not.2 h) theorem pred_coe [NoMinOrder α] {a : α} : pred (↑a : WithBot α) = ↑(pred a) := pred_coe_of_not_isMin <| not_isMin a end Pred /-! #### Adding a `⊥` to a `NoMinOrder` -/ section Succ variable [Preorder α] [NoMinOrder α] instance [hα : Nonempty α] : IsEmpty (SuccOrder (WithBot α)) := ⟨by intro cases h : succ (⊥ : WithBot α) with | bot => exact hα.elim fun a => (max_of_succ_le h.le).not_lt <| bot_lt_coe a | coe a => obtain ⟨c, hc⟩ := exists_lt a rw [← coe_lt_coe, ← h] at hc exact (succ_le_of_lt (bot_lt_coe _)).not_gt hc⟩ end Succ end WithBot section OrderIso variable {X Y : Type*} [Preorder X] [Preorder Y] -- See note [reducible non-instances] /-- `SuccOrder` transfers across equivalences between orders. -/ protected abbrev SuccOrder.ofOrderIso [SuccOrder X] (f : X ≃o Y) : SuccOrder Y where succ y := f (succ (f.symm y)) le_succ y := by rw [← map_inv_le_iff f]; exact le_succ (f.symm y) max_of_succ_le h := by rw [← f.symm.isMax_apply] refine max_of_succ_le ?_ simp [f.le_symm_apply, h] succ_le_of_lt h := by rw [← le_map_inv_iff]; exact succ_le_of_lt (by simp [h]) -- See note [reducible non-instances] /-- `PredOrder` transfers across equivalences between orders. -/ protected abbrev PredOrder.ofOrderIso [PredOrder X] (f : X ≃o Y) : PredOrder Y where pred y := f (pred (f.symm y)) pred_le y := by rw [← le_map_inv_iff f]; exact pred_le (f.symm y) min_of_le_pred h := by rw [← f.symm.isMin_apply] refine min_of_le_pred ?_ simp [f.symm_apply_le, h] le_pred_of_lt h := by rw [← map_inv_le_iff]; exact le_pred_of_lt (by simp [h]) end OrderIso section OrdConnected variable {α : Type*} [PartialOrder α] {s : Set α} [s.OrdConnected] open scoped Classical in noncomputable instance Set.OrdConnected.predOrder [PredOrder α] : PredOrder s where pred x := if h : Order.pred x.1 ∈ s then ⟨Order.pred x.1, h⟩ else x pred_le := fun ⟨x, hx⟩ ↦ by dsimp; split <;> simp_all [Order.pred_le] min_of_le_pred := @fun ⟨x, hx⟩ h ↦ by dsimp at h split_ifs at h with h' · simp only [Subtype.mk_le_mk, Order.le_pred_iff_isMin] at h rintro ⟨y, _⟩ hy simp [h hy] · rintro ⟨y, hy⟩ h rcases h.lt_or_eq with h | h · simp only [Subtype.mk_lt_mk] at h have := h.le_pred absurd h' apply out' hy hx simp [this, Order.pred_le] · simp [h] le_pred_of_lt := @fun ⟨b, hb⟩ ⟨c, hc⟩ h ↦ by rw [Subtype.mk_lt_mk] at h dsimp only split · exact h.le_pred · exact h.le @[simp, norm_cast] lemma coe_pred_of_mem [PredOrder α] {a : s} (h : pred a.1 ∈ s) : (pred a).1 = pred ↑a := by classical change Subtype.val (dite ..) = _ simp [h] lemma isMin_of_pred_notMem [PredOrder α] {a : s} (h : pred ↑a ∉ s) : IsMin a := by classical rw [← pred_eq_iff_isMin] change dite .. = _ simp [h] @[deprecated (since := "2025-05-23")] alias isMin_of_not_pred_mem := isMin_of_pred_notMem lemma pred_notMem_iff_isMin [PredOrder α] [NoMinOrder α] {a : s} : pred ↑a ∉ s ↔ IsMin a where mp := isMin_of_pred_notMem mpr h nh := by replace h := congr($h.pred_eq.1) rw [coe_pred_of_mem nh] at h simp at h @[deprecated (since := "2025-05-23")] alias not_pred_mem_iff_isMin := pred_notMem_iff_isMin noncomputable instance Set.OrdConnected.succOrder [SuccOrder α] : SuccOrder s := letI : PredOrder sᵒᵈ := inferInstanceAs (PredOrder (OrderDual.ofDual ⁻¹' s)) inferInstanceAs (SuccOrder sᵒᵈᵒᵈ) @[simp, norm_cast] lemma coe_succ_of_mem [SuccOrder α] {a : s} (h : succ ↑a ∈ s) : (succ a).1 = succ ↑a := by classical change Subtype.val (dite ..) = _ split_ifs <;> trivial lemma isMax_of_succ_notMem [SuccOrder α] {a : s} (h : succ ↑a ∉ s) : IsMax a := by classical rw [← succ_eq_iff_isMax] change dite .. = _ split_ifs <;> trivial @[deprecated (since := "2025-05-23")] alias isMax_of_not_succ_mem := isMax_of_succ_notMem lemma succ_notMem_iff_isMax [SuccOrder α] [NoMaxOrder α] {a : s} : succ ↑a ∉ s ↔ IsMax a where mp := isMax_of_succ_notMem mpr h nh := by replace h := congr($h.succ_eq.1) rw [coe_succ_of_mem nh] at h simp at h @[deprecated (since := "2025-05-23")] alias not_succ_mem_iff_isMax := succ_notMem_iff_isMax end OrdConnected
.lake/packages/mathlib/Mathlib/Order/SuccPred/Tree.lean
import Mathlib.Order.SuccPred.Archimedean import Mathlib.Data.Nat.Find import Mathlib.Order.Atoms import Mathlib.Data.SetLike.Basic /-! # Rooted trees This file proves basic results about rooted trees, represented using the ancestorship order. This is a `PartialOrder`, with `PredOrder` with the immediate parent as a predecessor, and an `OrderBot` which is the root. We also have an `IsPredArchimedean` assumption to prevent infinite dangling chains. -/ variable {α : Type*} [PartialOrder α] [PredOrder α] [IsPredArchimedean α] namespace IsPredArchimedean variable [OrderBot α] section DecidableEq variable [DecidableEq α] /-- The unique atom less than an element in an `OrderBot` with archimedean predecessor. -/ def findAtom (r : α) : α := Order.pred^[Nat.find (bot_le (a := r)).exists_pred_iterate - 1] r @[simp] lemma findAtom_le (r : α) : findAtom r ≤ r := Order.pred_iterate_le _ _ @[simp] lemma findAtom_bot : findAtom (⊥ : α) = ⊥ := by apply Function.iterate_fixed simp @[simp] lemma pred_findAtom (r : α) : Order.pred (findAtom r) = ⊥ := by unfold findAtom generalize h : Nat.find (bot_le (a := r)).exists_pred_iterate = n cases n · have : Order.pred^[0] r = ⊥ := by rw [← h] apply Nat.find_spec (bot_le (a := r)).exists_pred_iterate simp only [Function.iterate_zero, id_eq] at this simp [this] · simp only [Nat.add_sub_cancel_right, ← Function.iterate_succ_apply', Nat.succ_eq_add_one] rw [← h] apply Nat.find_spec (bot_le (a := r)).exists_pred_iterate @[simp] lemma findAtom_eq_bot {r : α} : findAtom r = ⊥ ↔ r = ⊥ where mp h := by unfold findAtom at h have := Nat.find_min' (bot_le (a := r)).exists_pred_iterate h replace : Nat.find (bot_le (a := r)).exists_pred_iterate = 0 := by omega simpa [this] using h mpr h := by simp [h] lemma findAtom_ne_bot {r : α} : findAtom r ≠ ⊥ ↔ r ≠ ⊥ := findAtom_eq_bot.not lemma isAtom_findAtom {r : α} (hr : r ≠ ⊥) : IsAtom (findAtom r) := by constructor · simp [hr] · intro b hb apply Order.le_pred_of_lt at hb simpa using hb @[simp] lemma isAtom_findAtom_iff {r : α} : IsAtom (findAtom r) ↔ r ≠ ⊥ where mpr := isAtom_findAtom mp h nh := by simp only [nh, findAtom_bot] at h; exact h.1 rfl end DecidableEq instance instIsAtomic : IsAtomic α where eq_bot_or_exists_atom_le b := by classical rw [or_iff_not_imp_left] intro hb use findAtom b, isAtom_findAtom hb, findAtom_le b end IsPredArchimedean /-- The type of rooted trees. -/ structure RootedTree where /-- The type representing the elements in the tree. -/ α : Type* /-- The type should be a `SemilatticeInf`, where `inf` is the least common ancestor in the tree. -/ [semilatticeInf : SemilatticeInf α] /-- The type should have a bottom, the root. -/ [orderBot : OrderBot α] /-- The type should have a predecessor for every element, its parent. -/ [predOrder : PredOrder α] /-- The predecessor relationship should be archimedean. -/ [isPredArchimedean : IsPredArchimedean α] attribute [coe] RootedTree.α instance : CoeSort RootedTree Type* := ⟨RootedTree.α⟩ attribute [instance] RootedTree.semilatticeInf RootedTree.predOrder RootedTree.orderBot RootedTree.isPredArchimedean /-- A subtree is represented by its root, therefore this is a type synonym. -/ def SubRootedTree (t : RootedTree) : Type* := t /-- The root of a `SubRootedTree`. -/ def SubRootedTree.root {t : RootedTree} (v : SubRootedTree t) : t := v /-- The `SubRootedTree` rooted at a given node. -/ def RootedTree.subtree (t : RootedTree) (r : t) : SubRootedTree t := r @[simp] lemma RootedTree.root_subtree (t : RootedTree) (r : t) : (t.subtree r).root = r := rfl @[simp] lemma RootedTree.subtree_root (t : RootedTree) (v : SubRootedTree t) : t.subtree v.root = v := rfl @[ext] lemma SubRootedTree.ext {t : RootedTree} {v₁ v₂ : SubRootedTree t} (h : v₁.root = v₂.root) : v₁ = v₂ := h instance (t : RootedTree) : SetLike (SubRootedTree t) t where coe v := Set.Ici v.root coe_injective' a₁ a₂ h := by simpa only [Set.Ici_inj, ← SubRootedTree.ext_iff] using h lemma SubRootedTree.mem_iff {t : RootedTree} {r : SubRootedTree t} {v : t} : v ∈ r ↔ r.root ≤ v := Iff.rfl /-- The coercion from a `SubRootedTree` to a `RootedTree`. -/ @[coe, reducible] noncomputable def SubRootedTree.coeTree {t : RootedTree} (r : SubRootedTree t) : RootedTree where α := Set.Ici r.root noncomputable instance (t : RootedTree) : CoeOut (SubRootedTree t) RootedTree := ⟨SubRootedTree.coeTree⟩ @[simp] lemma SubRootedTree.bot_mem_iff {t : RootedTree} (r : SubRootedTree t) : ⊥ ∈ r ↔ r.root = ⊥ := by simp [mem_iff] /-- All of the immediate subtrees of a given rooted tree, that is subtrees which are rooted at a direct child of the root (or, order-theoretically, at an atom). -/ def RootedTree.subtrees (t : RootedTree) : Set (SubRootedTree t) := {x | IsAtom x.root} variable {t : RootedTree} lemma SubRootedTree.root_ne_bot_of_mem_subtrees (r : SubRootedTree t) (hr : r ∈ t.subtrees) : r.root ≠ ⊥ := by simp only [RootedTree.subtrees, Set.mem_setOf_eq] at hr exact hr.1 lemma RootedTree.mem_subtrees_disjoint_iff {t₁ t₂ : SubRootedTree t} (ht₁ : t₁ ∈ t.subtrees) (ht₂ : t₂ ∈ t.subtrees) (v₁ v₂ : t) (h₁ : v₁ ∈ t₁) (h₂ : v₂ ∈ t₂) : Disjoint v₁ v₂ ↔ t₁ ≠ t₂ where mp h := by intro nh have : t₁.root ≤ (v₁ : t) ⊓ (v₂ : t) := by simp only [le_inf_iff] exact ⟨h₁, nh ▸ h₂⟩ rw [h.eq_bot] at this simp only [le_bot_iff] at this exact t₁.root_ne_bot_of_mem_subtrees ht₁ this mpr h := by rw [SubRootedTree.mem_iff] at h₁ h₂ contrapose! h rw [disjoint_iff, ← ne_eq, ← bot_lt_iff_ne_bot] at h rcases lt_or_le_of_directed (by simp : v₁ ⊓ v₂ ≤ v₁) h₁ with oh | oh · simp_all [RootedTree.subtrees, IsAtom.lt_iff] rw [le_inf_iff] at oh ext simpa only [ht₂.le_iff_eq ht₁.1, ht₁.le_iff_eq ht₂.1, eq_comm, or_self] using le_total_of_directed oh.2 h₂ lemma RootedTree.subtrees_disjoint : t.subtrees.PairwiseDisjoint ((↑) : _ → Set t) := by intro t₁ ht₁ t₂ ht₂ h rw [Function.onFun_apply, Set.disjoint_left] intro a ha hb rw [← mem_subtrees_disjoint_iff ht₁ ht₂ a a ha hb, disjoint_self] at h subst h simp only [SetLike.mem_coe, SubRootedTree.bot_mem_iff] at ha exact t₁.root_ne_bot_of_mem_subtrees ht₁ ha /-- The immediate subtree of `t` containing `v`, or all of `t` if `v` is the root. -/ def RootedTree.subtreeOf (t : RootedTree) [DecidableEq t] (v : t) : SubRootedTree t := t.subtree (IsPredArchimedean.findAtom v) @[simp] lemma RootedTree.mem_subtreeOf [DecidableEq t] {v : t} : v ∈ t.subtreeOf v := by simp [SubRootedTree.mem_iff, RootedTree.subtreeOf] lemma RootedTree.subtreeOf_mem_subtrees [DecidableEq t] {v : t} (hr : v ≠ ⊥) : t.subtreeOf v ∈ t.subtrees := by simpa [RootedTree.subtrees, RootedTree.subtreeOf]
.lake/packages/mathlib/Mathlib/Order/SuccPred/Relation.lean
import Mathlib.Order.SuccPred.Archimedean /-! # Relations on types with a `SuccOrder` This file contains properties about relations on types with a `SuccOrder` and their closure operations (like the transitive closure). -/ open Function Order Relation Set section PartialSucc variable {α : Type*} [PartialOrder α] [SuccOrder α] [IsSuccArchimedean α] /-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ_of_le (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n ≤ m) : ReflTransGen r n m := by revert h; refine Succ.rec ?_ ?_ hnm · intro _ exact ReflTransGen.refl · intro m hnm ih h have : ReflTransGen r n m := ih fun i hi => h i ⟨hi.1, hi.2.trans_le <| le_succ m⟩ rcases (le_succ m).eq_or_lt with hm | hm · rwa [← hm] exact this.tail (h m ⟨hnm, hm⟩) /-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `succ i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ_of_ge (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m ≤ n) : ReflTransGen r n m := by rw [← reflTransGen_swap] exact reflTransGen_of_succ_of_le (swap r) h hmn /-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_lt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n < m) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp <| reflTransGen_of_succ_of_le r h hnm.le).resolve_left hnm.ne' /-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` if `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_gt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m < n) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp <| reflTransGen_of_succ_of_ge r h hmn.le).resolve_left hmn.ne end PartialSucc section LinearSucc variable {α : Type*} [LinearOrder α] [SuccOrder α] [IsSuccArchimedean α] /-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : ReflTransGen r n m := (le_total n m).elim (reflTransGen_of_succ_of_le r h1) <| reflTransGen_of_succ_of_ge r h2 /-- For `n ≠ m`,`(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_ne (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) (hnm : n ≠ m) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp (reflTransGen_of_succ r h1 h2)).resolve_left hnm.symm /-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_reflexive (r : α → α → Prop) {n m : α} (hr : Reflexive r) (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : TransGen r n m := by rcases eq_or_ne m n with (rfl | hmn); · exact TransGen.single (hr m) exact transGen_of_succ_of_ne r h1 h2 hmn.symm end LinearSucc section PartialPred variable {α : Type*} [PartialOrder α] [PredOrder α] [IsPredArchimedean α] /-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred_of_ge (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m ≤ n) : ReflTransGen r n m := reflTransGen_of_succ_of_le (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hnm /-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `pred i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred_of_le (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n ≤ m) : ReflTransGen r n m := reflTransGen_of_succ_of_ge (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hmn /-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `i ~ pred i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_gt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m < n) : TransGen r n m := transGen_of_succ_of_lt (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hnm /-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_lt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n < m) : TransGen r n m := transGen_of_succ_of_gt (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hmn end PartialPred section LinearPred variable {α : Type*} [LinearOrder α] [PredOrder α] [IsPredArchimedean α] /-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : ReflTransGen r n m := reflTransGen_of_succ (α := αᵒᵈ) r (fun x hx => h1 x ⟨hx.2, hx.1⟩) fun x hx => h2 x ⟨hx.2, hx.1⟩ /-- For `n ≠ m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_ne (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) (hnm : n ≠ m) : TransGen r n m := transGen_of_succ_of_ne (α := αᵒᵈ) r (fun x hx => h1 x ⟨hx.2, hx.1⟩) (fun x hx => h2 x ⟨hx.2, hx.1⟩) hnm /-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_reflexive (r : α → α → Prop) {n m : α} (hr : Reflexive r) (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : TransGen r n m := transGen_of_succ_of_reflexive (α := αᵒᵈ) r hr (fun x hx => h1 x ⟨hx.2, hx.1⟩) fun x hx => h2 x ⟨hx.2, hx.1⟩ end LinearPred
.lake/packages/mathlib/Mathlib/Order/SuccPred/InitialSeg.lean
import Mathlib.Order.InitialSeg import Mathlib.Order.SuccPred.Limit /-! # Initial segments and successors We establish some connections between initial segment embeddings and successors and predecessors. -/ variable {α β : Type*} {a b : α} [PartialOrder α] [PartialOrder β] open Order namespace InitialSeg @[simp] theorem apply_covBy_apply_iff (f : α ≤i β) : f a ⋖ f b ↔ a ⋖ b := (isLowerSet_range f).ordConnected.apply_covBy_apply_iff f.toOrderEmbedding @[simp] theorem apply_wCovBy_apply_iff (f : α ≤i β) : f a ⩿ f b ↔ a ⩿ b := by simp [wcovBy_iff_eq_or_covBy] theorem map_succ [SuccOrder α] [NoMaxOrder α] [SuccOrder β] (f : α ≤i β) (a : α) : f (succ a) = succ (f a) := (f.apply_covBy_apply_iff.2 (covBy_succ a)).succ_eq.symm theorem map_pred [PredOrder α] [NoMinOrder α] [PredOrder β] (f : α ≤i β) (a : α) : f (pred a) = pred (f a) := (f.apply_covBy_apply_iff.2 (pred_covBy a)).pred_eq.symm @[simp] theorem isSuccPrelimit_apply_iff (f : α ≤i β) : IsSuccPrelimit (f a) ↔ IsSuccPrelimit a := by constructor <;> intro h b hb · rw [← f.apply_covBy_apply_iff] at hb exact h _ hb · obtain ⟨c, rfl⟩ := f.mem_range_of_rel hb.lt rw [f.apply_covBy_apply_iff] at hb exact h _ hb @[simp] theorem isSuccLimit_apply_iff (f : α ≤i β) : IsSuccLimit (f a) ↔ IsSuccLimit a := by simp [IsSuccLimit] alias ⟨_, map_isSuccPrelimit⟩ := isSuccPrelimit_apply_iff alias ⟨_, map_isSuccLimit⟩ := isSuccLimit_apply_iff end InitialSeg namespace PrincipalSeg @[simp] theorem apply_covBy_apply_iff (f : α <i β) : f a ⋖ f b ↔ a ⋖ b := (f : α ≤i β).apply_covBy_apply_iff @[simp] theorem apply_wCovBy_apply_iff (f : α <i β) : f a ⩿ f b ↔ a ⩿ b := (f : α ≤i β).apply_wCovBy_apply_iff theorem map_succ [SuccOrder α] [NoMaxOrder α] [SuccOrder β] (f : α <i β) (a : α) : f (succ a) = succ (f a) := (f : α ≤i β).map_succ a theorem map_pred [PredOrder α] [NoMinOrder α] [PredOrder β] (f : α ≤i β) (a : α) : f (pred a) = pred (f a) := (f : α ≤i β).map_pred a @[simp] theorem isSuccPrelimit_apply_iff (f : α <i β) : IsSuccPrelimit (f a) ↔ IsSuccPrelimit a := (f : α ≤i β).isSuccPrelimit_apply_iff @[simp] theorem isSuccLimit_apply_iff (f : α <i β) : IsSuccLimit (f a) ↔ IsSuccLimit a := (f : α ≤i β).isSuccLimit_apply_iff alias ⟨_, map_isSuccPrelimit⟩ := isSuccPrelimit_apply_iff alias ⟨_, map_isSuccLimit⟩ := isSuccLimit_apply_iff end PrincipalSeg
.lake/packages/mathlib/Mathlib/Order/SuccPred/WithBot.lean
import Mathlib.Order.SuccPred.Basic /-! # Successor function on `WithBot` This file defines the successor of `a : WithBot α` as an element of `α`, and dually for `WithTop`. -/ namespace WithBot variable {α : Type*} [Preorder α] [OrderBot α] [SuccOrder α] {x y : WithBot α} /-- The successor of `a : WithBot α` as an element of `α`. -/ def succ (a : WithBot α) : α := a.recBotCoe ⊥ Order.succ /-- Not to be confused with `WithBot.orderSucc_bot`, which is about `Order.succ`. -/ @[simp] lemma succ_bot : succ (⊥ : WithBot α) = ⊥ := rfl /-- Not to be confused with `WithBot.orderSucc_coe`, which is about `Order.succ`. -/ @[simp] lemma succ_coe (a : α) : succ (a : WithBot α) = Order.succ a := rfl lemma succ_eq_succ : ∀ a : WithBot α, succ a = Order.succ a | ⊥ => rfl | (a : α) => rfl lemma lt_succ [NoMaxOrder α] (x : WithBot α) : x < x.succ := succ_eq_succ x ▸ Order.lt_succ x lemma succ_mono : Monotone (succ : WithBot α → α) | ⊥, _, _ => by simp | (a : α), ⊥, hab => by simp at hab | (a : α), (b : α), hab => Order.succ_le_succ (by simpa using hab) lemma succ_strictMono [NoMaxOrder α] : StrictMono (succ : WithBot α → α) | ⊥, (b : α), hab => by simp | (a : α), (b : α), hab => Order.succ_lt_succ (by simpa using hab) @[gcongr] lemma succ_le_succ (hxy : x ≤ y) : x.succ ≤ y.succ := succ_mono hxy @[gcongr] lemma succ_lt_succ [NoMaxOrder α] (hxy : x < y) : x.succ < y.succ := succ_strictMono hxy section LinearOrder variable {α : Type*} [Nontrivial α] [LinearOrder α] [OrderBot α] [SuccOrder α] @[simp] theorem succ_eq_bot (a : WithBot α) : WithBot.succ a = ⊥ ↔ a = ⊥ := by cases a · simp · simp only [WithBot.succ_coe, WithBot.coe_ne_bot, iff_false] apply ne_of_gt by_contra! h have h₂ : _ = ⊥ := le_bot_iff.mp ((Order.le_succ _).trans h) exact not_isMax_bot (h₂ ▸ Order.max_of_succ_le (h.trans bot_le)) end LinearOrder end WithBot namespace WithTop variable {α : Type*} [Preorder α] [OrderTop α] [PredOrder α] {x y : WithTop α} /-- The predecessor of `a : WithTop α` as an element of `α`. -/ def pred (a : WithTop α) : α := a.recTopCoe ⊤ Order.pred /-- Not to be confused with `WithTop.orderPred_top`, which is about `Order.pred`. -/ @[simp] lemma pred_top : pred (⊤ : WithTop α) = ⊤ := rfl /-- Not to be confused with `WithTop.orderPred_coe`, which is about `Order.pred`. -/ @[simp] lemma pred_coe (a : α) : pred (a : WithTop α) = Order.pred a := rfl lemma pred_eq_pred : ∀ a : WithTop α, pred a = Order.pred a | ⊤ => rfl | (a : α) => rfl lemma pred_mono : Monotone (pred : WithTop α → α) | _, ⊤, _ => by simp | ⊤, (a : α), hab => by simp at hab | (a : α), (b : α), hab => Order.pred_le_pred (by simpa using hab) lemma pred_strictMono [NoMinOrder α] : StrictMono (pred : WithTop α → α) | (b : α), ⊤, hab => by simp | (a : α), (b : α), hab => Order.pred_lt_pred (by simpa using hab) @[gcongr] lemma pred_le_pred (hxy : x ≤ y) : x.pred ≤ y.pred := pred_mono hxy @[gcongr] lemma pred_lt_pred [NoMinOrder α] (hxy : x < y) : x.pred < y.pred := pred_strictMono hxy section LinearOrder variable {α : Type*} [Nontrivial α] [LinearOrder α] [OrderTop α] [PredOrder α] @[simp] theorem pred_eq_top (a : WithTop α) : WithTop.pred a = ⊤ ↔ a = ⊤ := by cases a · simp · simp only [WithTop.pred_coe, WithTop.coe_ne_top, iff_false] apply ne_of_lt by_contra! h have h₂ : _ = ⊤ := top_le_iff.mp (h.trans (Order.pred_le _)) exact not_isMin_top (h₂ ▸ Order.min_of_le_pred (le_top.trans h)) end LinearOrder end WithTop
.lake/packages/mathlib/Mathlib/Order/SuccPred/IntervalSucc.lean
import Mathlib.Data.Set.Pairwise.Basic import Mathlib.Data.Set.Lattice import Mathlib.Order.SuccPred.Archimedean /-! # Intervals `Ixx (f x) (f (Order.succ x))` In this file we prove * `Monotone.biUnion_Ico_Ioc_map_succ`: if `α` is a linear archimedean succ order and `β` is a linear order, then for any monotone function `f` and `m n : α`, the union of intervals `Set.Ioc (f i) (f (Order.succ i))`, `m ≤ i < n`, is equal to `Set.Ioc (f m) (f n)`; * `Monotone.pairwise_disjoint_on_Ioc_succ`: if `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f n) (f (Order.succ n))` are pairwise disjoint. For the latter lemma, we also prove various order dual versions. -/ open Set Order variable {α β : Type*} [LinearOrder α] theorem biUnion_Ici_Ico_map_succ [SuccOrder α] [IsSuccArchimedean α] [LinearOrder β] {f : α → β} {a : α} (hf : ∀ i ∈ Ici a, f a ≤ f i) (h2f : ¬BddAbove (f '' Ici a)) : ⋃ i ∈ Ici a, Ico (f i) (f (succ i)) = Ici (f a) := by apply subset_antisymm <| iUnion₂_subset fun i hi ↦ Ico_subset_Ico_left (hf i hi) |>.trans Ico_subset_Ici_self intro b hb contrapose! h2f use b simp only [upperBounds, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] exact Succ.rec (P := fun i _ ↦ f i ≤ b) hb (by aesop) theorem biUnion_Ici_Ioc_map_succ [SuccOrder α] [IsSuccArchimedean α] [LinearOrder β] {f : α → β} {a : α} (hf : ∀ i ∈ Ici a, f a ≤ f i) (h2f : ¬BddAbove (f '' Ici a)) : ⋃ i ∈ Ici a, Ioc (f i) (f (succ i)) = Ioi (f a) := by apply subset_antisymm <| iUnion₂_subset fun i hi ↦ Ioc_subset_Ioc_left (hf i hi) |>.trans Ioc_subset_Ioi_self intro b hb contrapose! h2f suffices ∀ i, a ≤ i → f i < b from ⟨b, by aesop (add simp [upperBounds, le_of_lt])⟩ exact Succ.rec (P := fun i _ ↦ f i < b) hb (by aesop) namespace Monotone /-- If `α` is a linear archimedean succ order and `β` is a linear order, then for any monotone function `f` and `m n : α`, the union of intervals `Set.Ioc (f i) (f (Order.succ i))`, `m ≤ i < n`, is equal to `Set.Ioc (f m) (f n)` -/ theorem biUnion_Ico_Ioc_map_succ [SuccOrder α] [IsSuccArchimedean α] [LinearOrder β] {f : α → β} (hf : Monotone f) (m n : α) : ⋃ i ∈ Ico m n, Ioc (f i) (f (succ i)) = Ioc (f m) (f n) := by rcases le_total n m with hnm | hmn · rw [Ico_eq_empty_of_le hnm, Ioc_eq_empty_of_le (hf hnm), biUnion_empty] · refine Succ.rec ?_ ?_ hmn · simp only [Ioc_self, Ico_self, biUnion_empty] · intro k hmk ihk rw [← Ioc_union_Ioc_eq_Ioc (hf hmk) (hf <| le_succ _), union_comm, ← ihk] by_cases hk : IsMax k · rw [hk.succ_eq, Ioc_self, empty_union] · rw [Ico_succ_right_eq_insert_of_not_isMax hmk hk, biUnion_insert] open scoped Function -- required for scoped `on` notation /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioc (f n) (f (succ n))) := (pairwise_disjoint_on _).2 fun _ _ hmn => disjoint_iff_inf_le.mpr fun _ ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩ => h₂.not_ge <| h₁.trans <| hf <| succ_le_of_lt hmn /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ico (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ico (f n) (f (succ n))) := (pairwise_disjoint_on _).2 fun _ _ hmn => disjoint_iff_inf_le.mpr fun _ ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩ => h₁.not_ge <| (hf <| succ_le_of_lt hmn).trans h₂ /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioo (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioo (f n) (f (succ n))) := hf.pairwise_disjoint_on_Ico_succ.mono fun _ _ h => h.mono Ioo_subset_Ico_self Ioo_subset_Ico_self /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioc (f (pred n)) (f n)) := by simpa using hf.dual.pairwise_disjoint_on_Ico_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ico (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ico (f (pred n)) (f n)) := by simpa using hf.dual.pairwise_disjoint_on_Ioc_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioo (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioo (f (pred n)) (f n)) := by simpa using hf.dual.pairwise_disjoint_on_Ioo_succ end Monotone namespace Antitone open scoped Function -- required for scoped `on` notation /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioc (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioc (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ioc_pred /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ico (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ico (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ico_pred /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioo (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioo (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ioo_pred /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioc (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioc (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ioc_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ico (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ico (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ico_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioo (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioo (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ioo_succ end Antitone
.lake/packages/mathlib/Mathlib/Order/UpperLower/Prod.lean
import Mathlib.Order.UpperLower.Closure /-! # Upper and lower set product The Cartesian product of sets carries over to upper and lower sets in a natural way. This file defines said product over the types `UpperSet` and `LowerSet` and proves some of its properties. ## Notation * `×ˢ` is notation for `UpperSet.prod` / `LowerSet.prod`. -/ open Set variable {α β : Type*} section Preorder variable [Preorder α] [Preorder β] section variable {s : Set α} {t : Set β} theorem IsUpperSet.prod (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ×ˢ t) := fun _ _ h ha => ⟨hs h.1 ha.1, ht h.2 ha.2⟩ theorem IsLowerSet.prod (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ×ˢ t) := fun _ _ h ha => ⟨hs h.1 ha.1, ht h.2 ha.2⟩ end namespace UpperSet variable (s s₁ s₂ : UpperSet α) (t t₁ t₂ : UpperSet β) {x : α × β} /-- The product of two upper sets as an upper set. -/ def prod : UpperSet (α × β) := ⟨s ×ˢ t, s.2.prod t.2⟩ instance instSProd : SProd (UpperSet α) (UpperSet β) (UpperSet (α × β)) where sprod := UpperSet.prod @[simp, norm_cast] theorem coe_prod : ((s ×ˢ t : UpperSet (α × β)) : Set (α × β)) = (s : Set α) ×ˢ t := rfl @[simp] theorem mem_prod {s : UpperSet α} {t : UpperSet β} : x ∈ s ×ˢ t ↔ x.1 ∈ s ∧ x.2 ∈ t := Iff.rfl theorem Ici_prod (x : α × β) : Ici x = Ici x.1 ×ˢ Ici x.2 := rfl @[simp] theorem Ici_prod_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl @[simp] theorem prod_top : s ×ˢ (⊤ : UpperSet β) = ⊤ := ext prod_empty @[simp] theorem top_prod : (⊤ : UpperSet α) ×ˢ t = ⊤ := ext empty_prod @[simp] theorem bot_prod_bot : (⊥ : UpperSet α) ×ˢ (⊥ : UpperSet β) = ⊥ := ext univ_prod_univ @[simp] theorem sup_prod : (s₁ ⊔ s₂) ×ˢ t = s₁ ×ˢ t ⊔ s₂ ×ˢ t := ext inter_prod @[simp] theorem prod_sup : s ×ˢ (t₁ ⊔ t₂) = s ×ˢ t₁ ⊔ s ×ˢ t₂ := ext prod_inter @[simp] theorem inf_prod : (s₁ ⊓ s₂) ×ˢ t = s₁ ×ˢ t ⊓ s₂ ×ˢ t := ext union_prod @[simp] theorem prod_inf : s ×ˢ (t₁ ⊓ t₂) = s ×ˢ t₁ ⊓ s ×ˢ t₂ := ext prod_union theorem prod_sup_prod : s₁ ×ˢ t₁ ⊔ s₂ ×ˢ t₂ = (s₁ ⊔ s₂) ×ˢ (t₁ ⊔ t₂) := ext prod_inter_prod variable {s s₁ s₂ t t₁ t₂} @[mono] theorem prod_mono : s₁ ≤ s₂ → t₁ ≤ t₂ → s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ := Set.prod_mono theorem prod_mono_left : s₁ ≤ s₂ → s₁ ×ˢ t ≤ s₂ ×ˢ t := Set.prod_mono_left theorem prod_mono_right : t₁ ≤ t₂ → s ×ˢ t₁ ≤ s ×ˢ t₂ := Set.prod_mono_right @[simp] theorem prod_self_le_prod_self : s₁ ×ˢ s₁ ≤ s₂ ×ˢ s₂ ↔ s₁ ≤ s₂ := prod_self_subset_prod_self @[simp] theorem prod_self_lt_prod_self : s₁ ×ˢ s₁ < s₂ ×ˢ s₂ ↔ s₁ < s₂ := prod_self_ssubset_prod_self theorem prod_le_prod_iff : s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ ↔ s₁ ≤ s₂ ∧ t₁ ≤ t₂ ∨ s₂ = ⊤ ∨ t₂ = ⊤ := prod_subset_prod_iff.trans <| by simp @[simp] theorem prod_eq_top : s ×ˢ t = ⊤ ↔ s = ⊤ ∨ t = ⊤ := by simp_rw [SetLike.ext'_iff] exact prod_eq_empty_iff @[simp] theorem codisjoint_prod : Codisjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Codisjoint s₁ s₂ ∨ Codisjoint t₁ t₂ := by simp_rw [codisjoint_iff, prod_sup_prod, prod_eq_top] end UpperSet namespace LowerSet variable (s s₁ s₂ : LowerSet α) (t t₁ t₂ : LowerSet β) {x : α × β} /-- The product of two lower sets as a lower set. -/ def prod : LowerSet (α × β) := ⟨s ×ˢ t, s.2.prod t.2⟩ instance instSProd : SProd (LowerSet α) (LowerSet β) (LowerSet (α × β)) where sprod := LowerSet.prod @[simp, norm_cast] theorem coe_prod : ((s ×ˢ t : LowerSet (α × β)) : Set (α × β)) = (s : Set α) ×ˢ t := rfl @[simp] theorem mem_prod {s : LowerSet α} {t : LowerSet β} : x ∈ s ×ˢ t ↔ x.1 ∈ s ∧ x.2 ∈ t := Iff.rfl theorem Iic_prod (x : α × β) : Iic x = Iic x.1 ×ˢ Iic x.2 := rfl @[simp] theorem Ici_prod_Ici (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl @[simp] theorem prod_bot : s ×ˢ (⊥ : LowerSet β) = ⊥ := ext prod_empty @[simp] theorem bot_prod : (⊥ : LowerSet α) ×ˢ t = ⊥ := ext empty_prod @[simp] theorem top_prod_top : (⊤ : LowerSet α) ×ˢ (⊤ : LowerSet β) = ⊤ := ext univ_prod_univ @[simp] theorem inf_prod : (s₁ ⊓ s₂) ×ˢ t = s₁ ×ˢ t ⊓ s₂ ×ˢ t := ext inter_prod @[simp] theorem prod_inf : s ×ˢ (t₁ ⊓ t₂) = s ×ˢ t₁ ⊓ s ×ˢ t₂ := ext prod_inter @[simp] theorem sup_prod : (s₁ ⊔ s₂) ×ˢ t = s₁ ×ˢ t ⊔ s₂ ×ˢ t := ext union_prod @[simp] theorem prod_sup : s ×ˢ (t₁ ⊔ t₂) = s ×ˢ t₁ ⊔ s ×ˢ t₂ := ext prod_union theorem prod_inf_prod : s₁ ×ˢ t₁ ⊓ s₂ ×ˢ t₂ = (s₁ ⊓ s₂) ×ˢ (t₁ ⊓ t₂) := ext prod_inter_prod variable {s s₁ s₂ t t₁ t₂} theorem prod_mono : s₁ ≤ s₂ → t₁ ≤ t₂ → s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ := Set.prod_mono theorem prod_mono_left : s₁ ≤ s₂ → s₁ ×ˢ t ≤ s₂ ×ˢ t := Set.prod_mono_left theorem prod_mono_right : t₁ ≤ t₂ → s ×ˢ t₁ ≤ s ×ˢ t₂ := Set.prod_mono_right @[simp] theorem prod_self_le_prod_self : s₁ ×ˢ s₁ ≤ s₂ ×ˢ s₂ ↔ s₁ ≤ s₂ := prod_self_subset_prod_self @[simp] theorem prod_self_lt_prod_self : s₁ ×ˢ s₁ < s₂ ×ˢ s₂ ↔ s₁ < s₂ := prod_self_ssubset_prod_self theorem prod_le_prod_iff : s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ ↔ s₁ ≤ s₂ ∧ t₁ ≤ t₂ ∨ s₁ = ⊥ ∨ t₁ = ⊥ := prod_subset_prod_iff.trans <| by simp @[simp] theorem prod_eq_bot : s ×ˢ t = ⊥ ↔ s = ⊥ ∨ t = ⊥ := by simp_rw [SetLike.ext'_iff] exact prod_eq_empty_iff @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_iff, prod_inf_prod, prod_eq_bot] end LowerSet @[simp] theorem upperClosure_prod (s : Set α) (t : Set β) : upperClosure (s ×ˢ t) = upperClosure s ×ˢ upperClosure t := by ext simp [Prod.le_def, @and_and_and_comm _ (_ ∈ t)] @[simp] theorem lowerClosure_prod (s : Set α) (t : Set β) : lowerClosure (s ×ˢ t) = lowerClosure s ×ˢ lowerClosure t := by ext simp [Prod.le_def, @and_and_and_comm _ (_ ∈ t)] end Preorder
.lake/packages/mathlib/Mathlib/Order/UpperLower/Closure.lean
import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Minimal import Mathlib.Order.UpperLower.Principal /-! # Upper and lower closures Upper (lower) closures generalise principal upper (lower) sets to arbitrary included sets. Indeed, they are equivalent to a union over principal upper (lower) sets, as shown in `coe_upperClosure` (`coe_lowerClosure`). ## Main declarations * `upperClosure`: The greatest upper set containing a set. * `lowerClosure`: The least lower set containing a set. -/ open OrderDual Set variable {α β : Type*} {ι : Sort*} section Preorder variable [Preorder α] [Preorder β] {s t : Set α} {x : α} /-- The greatest upper set containing a given set. -/ def upperClosure (s : Set α) : UpperSet α := ⟨{ x | ∃ a ∈ s, a ≤ x }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hx.2.trans hle⟩⟩ /-- The least lower set containing a given set. -/ def lowerClosure (s : Set α) : LowerSet α := ⟨{ x | ∃ a ∈ s, x ≤ a }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hle.trans hx.2⟩⟩ -- TODO: move `GaloisInsertion`s up, use them to prove lemmas @[simp] theorem mem_upperClosure : x ∈ upperClosure s ↔ ∃ a ∈ s, a ≤ x := Iff.rfl @[simp] theorem mem_lowerClosure : x ∈ lowerClosure s ↔ ∃ a ∈ s, x ≤ a := Iff.rfl -- We do not tag those two as `simp` to respect the abstraction. @[norm_cast] theorem coe_upperClosure (s : Set α) : ↑(upperClosure s) = ⋃ a ∈ s, Ici a := by ext simp @[norm_cast] theorem coe_lowerClosure (s : Set α) : ↑(lowerClosure s) = ⋃ a ∈ s, Iic a := by ext simp instance instDecidablePredMemUpperClosure [DecidablePred (∃ a ∈ s, a ≤ ·)] : DecidablePred (· ∈ upperClosure s) := ‹DecidablePred _› instance instDecidablePredMemLowerClosure [DecidablePred (∃ a ∈ s, · ≤ a)] : DecidablePred (· ∈ lowerClosure s) := ‹DecidablePred _› theorem subset_upperClosure : s ⊆ upperClosure s := fun x hx => ⟨x, hx, le_rfl⟩ theorem subset_lowerClosure : s ⊆ lowerClosure s := fun x hx => ⟨x, hx, le_rfl⟩ theorem upperClosure_min (h : s ⊆ t) (ht : IsUpperSet t) : ↑(upperClosure s) ⊆ t := fun _a ⟨_b, hb, hba⟩ => ht hba <| h hb theorem lowerClosure_min (h : s ⊆ t) (ht : IsLowerSet t) : ↑(lowerClosure s) ⊆ t := fun _a ⟨_b, hb, hab⟩ => ht hab <| h hb protected theorem IsUpperSet.upperClosure (hs : IsUpperSet s) : ↑(upperClosure s) = s := (upperClosure_min Subset.rfl hs).antisymm subset_upperClosure protected theorem IsLowerSet.lowerClosure (hs : IsLowerSet s) : ↑(lowerClosure s) = s := (lowerClosure_min Subset.rfl hs).antisymm subset_lowerClosure @[simp] protected theorem UpperSet.upperClosure (s : UpperSet α) : upperClosure (s : Set α) = s := SetLike.coe_injective s.2.upperClosure @[simp] protected theorem LowerSet.lowerClosure (s : LowerSet α) : lowerClosure (s : Set α) = s := SetLike.coe_injective s.2.lowerClosure @[simp] theorem upperClosure_image (f : α ≃o β) : upperClosure (f '' s) = UpperSet.map f (upperClosure s) := by rw [← f.symm_symm, ← UpperSet.symm_map, f.symm_symm] ext simp [-UpperSet.symm_map, UpperSet.map, OrderIso.symm, ← f.le_symm_apply] @[simp] theorem lowerClosure_image (f : α ≃o β) : lowerClosure (f '' s) = LowerSet.map f (lowerClosure s) := by rw [← f.symm_symm, ← LowerSet.symm_map, f.symm_symm] ext simp [-LowerSet.symm_map, LowerSet.map, OrderIso.symm, ← f.symm_apply_le] @[simp] theorem UpperSet.iInf_Ici (s : Set α) : ⨅ a ∈ s, UpperSet.Ici a = upperClosure s := by ext simp @[simp] theorem LowerSet.iSup_Iic (s : Set α) : ⨆ a ∈ s, LowerSet.Iic a = lowerClosure s := by ext simp @[simp] lemma lowerClosure_le {t : LowerSet α} : lowerClosure s ≤ t ↔ s ⊆ t := ⟨fun h ↦ subset_lowerClosure.trans <| LowerSet.coe_subset_coe.2 h, fun h ↦ lowerClosure_min h t.lower⟩ @[simp] lemma le_upperClosure {s : UpperSet α} : s ≤ upperClosure t ↔ t ⊆ s := ⟨fun h ↦ subset_upperClosure.trans <| UpperSet.coe_subset_coe.2 h, fun h ↦ upperClosure_min h s.upper⟩ theorem gc_upperClosure_coe : GaloisConnection (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) := fun _s _t ↦ le_upperClosure theorem gc_lowerClosure_coe : GaloisConnection (lowerClosure : Set α → LowerSet α) (↑) := fun _s _t ↦ lowerClosure_le /-- `upperClosure` forms a reversed Galois insertion with the coercion from upper sets to sets. -/ def giUpperClosureCoe : GaloisInsertion (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) where choice s hs := toDual (⟨s, fun a _b hab ha => hs ⟨a, ha, hab⟩⟩ : UpperSet α) gc := gc_upperClosure_coe le_l_u _ := subset_upperClosure choice_eq _s hs := ofDual.injective <| SetLike.coe_injective <| subset_upperClosure.antisymm hs /-- `lowerClosure` forms a Galois insertion with the coercion from lower sets to sets. -/ def giLowerClosureCoe : GaloisInsertion (lowerClosure : Set α → LowerSet α) (↑) where choice s hs := ⟨s, fun a _b hba ha => hs ⟨a, ha, hba⟩⟩ gc := gc_lowerClosure_coe le_l_u _ := subset_lowerClosure choice_eq _s hs := SetLike.coe_injective <| subset_lowerClosure.antisymm hs theorem upperClosure_anti : Antitone (upperClosure : Set α → UpperSet α) := gc_upperClosure_coe.monotone_l theorem lowerClosure_mono : Monotone (lowerClosure : Set α → LowerSet α) := gc_lowerClosure_coe.monotone_l @[simp] theorem upperClosure_empty : upperClosure (∅ : Set α) = ⊤ := (@gc_upperClosure_coe α).l_bot @[simp] theorem lowerClosure_empty : lowerClosure (∅ : Set α) = ⊥ := (@gc_lowerClosure_coe α).l_bot @[simp] theorem upperClosure_singleton (a : α) : upperClosure ({a} : Set α) = UpperSet.Ici a := by ext simp @[simp] theorem lowerClosure_singleton (a : α) : lowerClosure ({a} : Set α) = LowerSet.Iic a := by ext simp @[simp] theorem upperClosure_univ : upperClosure (univ : Set α) = ⊥ := bot_unique subset_upperClosure @[simp] theorem lowerClosure_univ : lowerClosure (univ : Set α) = ⊤ := top_unique subset_lowerClosure @[simp] theorem upperClosure_eq_top_iff : upperClosure s = ⊤ ↔ s = ∅ := (@gc_upperClosure_coe α _).l_eq_bot.trans subset_empty_iff @[simp] theorem lowerClosure_eq_bot_iff : lowerClosure s = ⊥ ↔ s = ∅ := (@gc_lowerClosure_coe α _).l_eq_bot.trans subset_empty_iff @[simp] theorem upperClosure_union (s t : Set α) : upperClosure (s ∪ t) = upperClosure s ⊓ upperClosure t := (@gc_upperClosure_coe α _).l_sup @[simp] theorem lowerClosure_union (s t : Set α) : lowerClosure (s ∪ t) = lowerClosure s ⊔ lowerClosure t := (@gc_lowerClosure_coe α _).l_sup @[simp] theorem upperClosure_iUnion (f : ι → Set α) : upperClosure (⋃ i, f i) = ⨅ i, upperClosure (f i) := (@gc_upperClosure_coe α _).l_iSup @[simp] theorem lowerClosure_iUnion (f : ι → Set α) : lowerClosure (⋃ i, f i) = ⨆ i, lowerClosure (f i) := (@gc_lowerClosure_coe α _).l_iSup @[simp] theorem upperClosure_sUnion (S : Set (Set α)) : upperClosure (⋃₀ S) = ⨅ s ∈ S, upperClosure s := by simp_rw [sUnion_eq_biUnion, upperClosure_iUnion] @[simp] theorem lowerClosure_sUnion (S : Set (Set α)) : lowerClosure (⋃₀ S) = ⨆ s ∈ S, lowerClosure s := by simp_rw [sUnion_eq_biUnion, lowerClosure_iUnion] theorem Set.OrdConnected.upperClosure_inter_lowerClosure (h : s.OrdConnected) : ↑(upperClosure s) ∩ ↑(lowerClosure s) = s := (subset_inter subset_upperClosure subset_lowerClosure).antisymm' fun _a ⟨⟨_b, hb, hba⟩, _c, hc, hac⟩ => h.out hb hc ⟨hba, hac⟩ theorem ordConnected_iff_upperClosure_inter_lowerClosure : s.OrdConnected ↔ ↑(upperClosure s) ∩ ↑(lowerClosure s) = s := by refine ⟨Set.OrdConnected.upperClosure_inter_lowerClosure, fun h => ?_⟩ rw [← h] exact (UpperSet.upper _).ordConnected.inter (LowerSet.lower _).ordConnected @[simp] theorem upperBounds_lowerClosure : upperBounds (lowerClosure s : Set α) = upperBounds s := (upperBounds_mono_set subset_lowerClosure).antisymm fun _a ha _b ⟨_c, hc, hcb⟩ ↦ hcb.trans <| ha hc @[simp] theorem lowerBounds_upperClosure : lowerBounds (upperClosure s : Set α) = lowerBounds s := (lowerBounds_mono_set subset_upperClosure).antisymm fun _a ha _b ⟨_c, hc, hcb⟩ ↦ (ha hc).trans hcb @[simp] theorem bddAbove_lowerClosure : BddAbove (lowerClosure s : Set α) ↔ BddAbove s := by simp_rw [BddAbove, upperBounds_lowerClosure] @[simp] theorem bddBelow_upperClosure : BddBelow (upperClosure s : Set α) ↔ BddBelow s := by simp_rw [BddBelow, lowerBounds_upperClosure] protected alias ⟨BddAbove.of_lowerClosure, BddAbove.lowerClosure⟩ := bddAbove_lowerClosure protected alias ⟨BddBelow.of_upperClosure, BddBelow.upperClosure⟩ := bddBelow_upperClosure @[simp] lemma IsLowerSet.disjoint_upperClosure_left (ht : IsLowerSet t) : Disjoint ↑(upperClosure s) t ↔ Disjoint s t := by refine ⟨Disjoint.mono_left subset_upperClosure, ?_⟩ simp only [disjoint_left, SetLike.mem_coe, mem_upperClosure, forall_exists_index, and_imp] exact fun h a b hb hba ha ↦ h hb <| ht hba ha @[simp] lemma IsLowerSet.disjoint_upperClosure_right (hs : IsLowerSet s) : Disjoint s (upperClosure t) ↔ Disjoint s t := by simpa only [disjoint_comm] using hs.disjoint_upperClosure_left @[simp] lemma IsUpperSet.disjoint_lowerClosure_left (ht : IsUpperSet t) : Disjoint ↑(lowerClosure s) t ↔ Disjoint s t := ht.toDual.disjoint_upperClosure_left @[simp] lemma IsUpperSet.disjoint_lowerClosure_right (hs : IsUpperSet s) : Disjoint s (lowerClosure t) ↔ Disjoint s t := hs.toDual.disjoint_upperClosure_right @[simp] lemma upperClosure_eq : ↑(upperClosure s) = s ↔ IsUpperSet s := ⟨(· ▸ UpperSet.upper _), IsUpperSet.upperClosure⟩ @[simp] lemma lowerClosure_eq : ↑(lowerClosure s) = s ↔ IsLowerSet s := @upperClosure_eq αᵒᵈ _ _ end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} {x : α} lemma IsAntichain.minimal_mem_upperClosure_iff_mem (hs : IsAntichain (· ≤ ·) s) : Minimal (· ∈ upperClosure s) x ↔ x ∈ s := by simp only [upperClosure, UpperSet.mem_mk, mem_setOf_eq] refine ⟨fun h ↦ ?_, fun h ↦ ⟨⟨x, h, rfl.le⟩, fun b ⟨a, has, hab⟩ hbx ↦ ?_⟩⟩ · obtain ⟨a, has, hax⟩ := h.prop rwa [h.eq_of_ge ⟨a, has, rfl.le⟩ hax] rwa [← hs.eq has h (hab.trans hbx)] lemma IsAntichain.maximal_mem_lowerClosure_iff_mem (hs : IsAntichain (· ≤ ·) s) : Maximal (· ∈ lowerClosure s) x ↔ x ∈ s := hs.to_dual.minimal_mem_upperClosure_iff_mem end PartialOrder /-! ### Set Difference -/ namespace LowerSet variable [Preorder α] {s : LowerSet α} {t : Set α} {a : α} /-- The biggest lower subset of a lower set `s` disjoint from a set `t`. -/ def sdiff (s : LowerSet α) (t : Set α) : LowerSet α where carrier := s \ upperClosure t lower' := s.lower.sdiff_of_isUpperSet (upperClosure t).upper /-- The biggest lower subset of a lower set `s` not containing an element `a`. -/ def erase (s : LowerSet α) (a : α) : LowerSet α where carrier := s \ UpperSet.Ici a lower' := s.lower.sdiff_of_isUpperSet (UpperSet.Ici a).upper @[simp, norm_cast] lemma coe_sdiff (s : LowerSet α) (t : Set α) : s.sdiff t = (s : Set α) \ upperClosure t := rfl @[simp, norm_cast] lemma coe_erase (s : LowerSet α) (a : α) : s.erase a = (s : Set α) \ UpperSet.Ici a := rfl @[simp] lemma sdiff_singleton (s : LowerSet α) (a : α) : s.sdiff {a} = s.erase a := by simp [sdiff, erase] lemma sdiff_le_left : s.sdiff t ≤ s := diff_subset lemma erase_le : s.erase a ≤ s := diff_subset @[simp] protected lemma sdiff_eq_left : s.sdiff t = s ↔ Disjoint ↑s t := by simp [← SetLike.coe_set_eq] @[simp] lemma erase_eq : s.erase a = s ↔ a ∉ s := by rw [← sdiff_singleton]; simp [-sdiff_singleton] @[simp] lemma sdiff_lt_left : s.sdiff t < s ↔ ¬ Disjoint ↑s t := sdiff_le_left.lt_iff_ne.trans LowerSet.sdiff_eq_left.not @[simp] lemma erase_lt : s.erase a < s ↔ a ∈ s := erase_le.lt_iff_ne.trans erase_eq.not_left @[simp] protected lemma sdiff_idem (s : LowerSet α) (t : Set α) : (s.sdiff t).sdiff t = s.sdiff t := SetLike.coe_injective sdiff_idem @[simp] lemma erase_idem (s : LowerSet α) (a : α) : (s.erase a).erase a = s.erase a := SetLike.coe_injective sdiff_idem lemma sdiff_sup_lowerClosure (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : s.sdiff t ⊔ lowerClosure t = s := by refine le_antisymm (sup_le sdiff_le_left <| lowerClosure_le.2 hts) fun a ha ↦ ?_ obtain hat | hat := em (a ∈ t) · exact subset_union_right (subset_lowerClosure hat) · refine subset_union_left ⟨ha, ?_⟩ rintro ⟨b, hb, hba⟩ exact hat <| hst _ ha _ hb hba lemma lowerClosure_sup_sdiff (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : lowerClosure t ⊔ s.sdiff t = s := by rw [sup_comm, sdiff_sup_lowerClosure hts hst] lemma erase_sup_Iic (ha : a ∈ s) (has : ∀ b ∈ s, a ≤ b → b = a) : s.erase a ⊔ Iic a = s := by rw [← lowerClosure_singleton, ← sdiff_singleton, sdiff_sup_lowerClosure] <;> simpa lemma Iic_sup_erase (ha : a ∈ s) (has : ∀ b ∈ s, a ≤ b → b = a) : Iic a ⊔ s.erase a = s := by rw [sup_comm, erase_sup_Iic ha has] end LowerSet namespace UpperSet variable [Preorder α] {s : UpperSet α} {t : Set α} {a : α} /-- The biggest upper subset of a upper set `s` disjoint from a set `t`. -/ def sdiff (s : UpperSet α) (t : Set α) : UpperSet α where carrier := s \ lowerClosure t upper' := s.upper.sdiff_of_isLowerSet (lowerClosure t).lower /-- The biggest upper subset of a upper set `s` not containing an element `a`. -/ def erase (s : UpperSet α) (a : α) : UpperSet α where carrier := s \ LowerSet.Iic a upper' := s.upper.sdiff_of_isLowerSet (LowerSet.Iic a).lower @[simp, norm_cast] lemma coe_sdiff (s : UpperSet α) (t : Set α) : s.sdiff t = (s : Set α) \ lowerClosure t := rfl @[simp, norm_cast] lemma coe_erase (s : UpperSet α) (a : α) : s.erase a = (s : Set α) \ LowerSet.Iic a := rfl @[simp] lemma sdiff_singleton (s : UpperSet α) (a : α) : s.sdiff {a} = s.erase a := by simp [sdiff, erase] lemma le_sdiff_left : s ≤ s.sdiff t := diff_subset lemma le_erase : s ≤ s.erase a := diff_subset @[simp] protected lemma sdiff_eq_left : s.sdiff t = s ↔ Disjoint ↑s t := by simp [← SetLike.coe_set_eq] @[simp] lemma erase_eq : s.erase a = s ↔ a ∉ s := by rw [← sdiff_singleton]; simp [-sdiff_singleton] @[simp] lemma lt_sdiff_left : s < s.sdiff t ↔ ¬ Disjoint ↑s t := le_sdiff_left.lt_iff_ne'.trans UpperSet.sdiff_eq_left.not @[simp] lemma lt_erase : s < s.erase a ↔ a ∈ s := le_erase.lt_iff_ne'.trans erase_eq.not_left @[simp] protected lemma sdiff_idem (s : UpperSet α) (t : Set α) : (s.sdiff t).sdiff t = s.sdiff t := SetLike.coe_injective sdiff_idem @[simp] lemma erase_idem (s : UpperSet α) (a : α) : (s.erase a).erase a = s.erase a := SetLike.coe_injective sdiff_idem lemma sdiff_inf_upperClosure (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : s.sdiff t ⊓ upperClosure t = s := by refine ge_antisymm (le_inf le_sdiff_left <| le_upperClosure.2 hts) fun a ha ↦ ?_ obtain hat | hat := em (a ∈ t) · exact subset_union_right (subset_upperClosure hat) · refine subset_union_left ⟨ha, ?_⟩ rintro ⟨b, hb, hab⟩ exact hat <| hst _ ha _ hb hab lemma upperClosure_inf_sdiff (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : upperClosure t ⊓ s.sdiff t = s := by rw [inf_comm, sdiff_inf_upperClosure hts hst] lemma erase_inf_Ici (ha : a ∈ s) (has : ∀ b ∈ s, b ≤ a → b = a) : s.erase a ⊓ Ici a = s := by rw [← upperClosure_singleton, ← sdiff_singleton, sdiff_inf_upperClosure] <;> simpa lemma Ici_inf_erase (ha : a ∈ s) (has : ∀ b ∈ s, b ≤ a → b = a) : Ici a ⊓ s.erase a = s := by rw [inf_comm, erase_inf_Ici ha has] end UpperSet
.lake/packages/mathlib/Mathlib/Order/UpperLower/Basic.lean
import Mathlib.Logic.Equiv.Set import Mathlib.Order.Interval.Set.OrderEmbedding import Mathlib.Order.SetNotation import Mathlib.Order.WellFounded /-! # Properties of unbundled upper/lower sets This file proves results on `IsUpperSet` and `IsLowerSet`, including their interactions with set operations, images, preimages and order duals, and properties that reflect stronger assumptions on the underlying order (such as `PartialOrder` and `LinearOrder`). ## TODO * Lattice structure on antichains. * Order equivalence between upper/lower sets and antichains. -/ open OrderDual Set variable {α β : Type*} {ι : Sort*} {κ : ι → Sort*} attribute [aesop norm unfold] IsUpperSet IsLowerSet section LE variable [LE α] {s t : Set α} {a : α} theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha @[simp] theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsLowerSet.compl⟩ @[simp] theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsUpperSet.compl⟩ theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) := isUpperSet_sUnion <| forall_mem_range.2 hf theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) := isLowerSet_sUnion <| forall_mem_range.2 hf theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋃ (i) (j), f i j) := isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋃ (i) (j), f i j) := isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) := isUpperSet_sInter <| forall_mem_range.2 hf theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) := isLowerSet_sInter <| forall_mem_range.2 hf theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋂ (i) (j), f i j) := isUpperSet_iInter fun i => isUpperSet_iInter <| hf i theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋂ (i) (j), f i j) := isLowerSet_iInter fun i => isLowerSet_iInter <| hf i @[simp] theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl @[simp] theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) : IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) : IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : IsUpperSet (s \ t) := fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩ lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : IsLowerSet (s \ t) := fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩ lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) := hs.sdiff <| by aesop lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) := hs.sdiff <| by aesop lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) := hs.sdiff <| by simpa using has lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) := hs.sdiff <| by simpa using has end LE section Preorder variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α) theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)] alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s := Ioi_subset_Ici_self.trans <| h.Ici_subset ha theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s := h.toDual.Ioi_subset ha theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected := ⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩ theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected := ⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩ theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) : IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) : IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by change IsUpperSet ((f : α ≃ β) '' s) rw [Equiv.image_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by change IsLowerSet ((f : α ≃ β) '' s) rw [Equiv.image_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ici a = Ici (e a) := by rw [← e.preimage_Ici, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ici_subset (mem_range_self _)] theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iic a = Iic (e a) := e.dual.image_Ici he a theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ioi a = Ioi (e a) := by rw [← e.preimage_Ioi, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)] theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iio a = Iio (e a) := e.dual.image_Ioi he a @[simp] theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s := forall_swap @[simp] theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p := Iff.rfl @[simp] theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p := forall_swap lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha section OrderTop variable [OrderTop α] theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩ theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩ theorem IsUpperSet.top_notMem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ := hs.top_mem.not.trans not_nonempty_iff_eq_empty @[deprecated (since := "2025-05-24")] alias IsUpperSet.not_top_mem := IsUpperSet.top_notMem end OrderTop section OrderBot variable [OrderBot α] theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩ theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩ theorem IsLowerSet.bot_notMem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ := hs.bot_mem.not.trans not_nonempty_iff_eq_empty @[deprecated (since := "2025-05-24")] alias IsLowerSet.not_bot_mem := IsLowerSet.bot_notMem end OrderBot section NoMaxOrder variable [NoMaxOrder α] theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_gt b exact hc.not_ge (hb <| hs ((hb ha).trans hc.le) ha) theorem not_bddAbove_Ici : ¬BddAbove (Ici a) := (isUpperSet_Ici _).not_bddAbove nonempty_Ici theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) := (isUpperSet_Ioi _).not_bddAbove nonempty_Ioi end NoMaxOrder section NoMinOrder variable [NoMinOrder α] theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_lt b exact hc.not_ge (hb <| hs (hc.le.trans <| hb ha) ha) theorem not_bddBelow_Iic : ¬BddBelow (Iic a) := (isLowerSet_Iic _).not_bddBelow nonempty_Iic theorem not_bddBelow_Iio : ¬BddBelow (Iio a) := (isLowerSet_Iio _).not_bddBelow nonempty_Iio end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] end PartialOrder section LinearOrder variable [LinearOrder α] {s t : Set α} theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by by_contra! h simp_rw [Set.not_subset] at h obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h obtain hab | hba := le_total a b · exact hbs (hs hab has) · exact hat (ht hba hbt) theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s := hs.toDual.total ht.toDual theorem IsUpperSet.eq_empty_or_Ici [WellFoundedLT α] (h : IsUpperSet s) : s = ∅ ∨ (∃ a, s = Set.Ici a) := by refine or_iff_not_imp_left.2 fun ha ↦ ?_ obtain ⟨a, ha⟩ := Set.nonempty_iff_ne_empty.2 ha exact ⟨_, Set.ext fun b ↦ ⟨wellFounded_lt.min_le, (h · <| wellFounded_lt.min_mem _ ⟨a, ha⟩)⟩⟩ theorem IsLowerSet.eq_empty_or_Iic [WellFoundedGT α] (h : IsLowerSet s) : s = ∅ ∨ (∃ a, s = Set.Iic a) := IsUpperSet.eq_empty_or_Ici (α := αᵒᵈ) h theorem IsLowerSet.eq_univ_or_Iio [WellFoundedLT α] (h : IsLowerSet s) : s = .univ ∨ (∃ a, s = Set.Iio a) := by simp_rw [← @compl_inj_iff _ s] simpa using h.compl.eq_empty_or_Ici theorem IsUpperSet.eq_univ_or_Ioi [WellFoundedGT α] (h : IsUpperSet s) : s = .univ ∨ (∃ a, s = Set.Ioi a) := IsLowerSet.eq_univ_or_Iio (α := αᵒᵈ) h end LinearOrder
.lake/packages/mathlib/Mathlib/Order/UpperLower/Fibration.lean
import Mathlib.Order.UpperLower.Basic /-! # Upper/lower sets and fibrations -/ open Set namespace Relation variable {α β : Type*} {f : α → β} lemma Fibration.isLowerSet_image [LE α] [LE β] (hf : Fibration (· ≤ ·) (· ≤ ·) f) {s : Set α} (hs : IsLowerSet s) : IsLowerSet (f '' s) := by rintro _ y' e ⟨x, hx, rfl⟩; obtain ⟨y, e', rfl⟩ := hf e; exact ⟨_, hs e' hx, rfl⟩ alias _root_.IsLowerSet.image_fibration := Fibration.isLowerSet_image lemma fibration_iff_isLowerSet_image_Iic [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, IsLowerSet (f '' Iic x) := ⟨fun h x ↦ (isLowerSet_Iic x).image_fibration h, fun H x _ e ↦ H x e ⟨x, le_rfl, rfl⟩⟩ lemma fibration_iff_isLowerSet_image [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ s, IsLowerSet s → IsLowerSet (f '' s) := ⟨Fibration.isLowerSet_image, fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (H _ <| isLowerSet_Iic ·)⟩ lemma fibration_iff_image_Iic [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, f '' Iic x = Iic (f x) := ⟨fun H x ↦ le_antisymm (fun _ ⟨_, hy, e⟩ ↦ e ▸ hf hy) ((H.isLowerSet_image (isLowerSet_Iic x)).Iic_subset ⟨x, le_rfl, rfl⟩), fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (fun x ↦ (H x).symm ▸ isLowerSet_Iic (f x))⟩ lemma Fibration.isUpperSet_image [LE α] [LE β] (hf : Fibration (· ≥ ·) (· ≥ ·) f) {s : Set α} (hs : IsUpperSet s) : IsUpperSet (f '' s) := @Fibration.isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ hf s hs alias _root_.IsUpperSet.image_fibration := Fibration.isUpperSet_image lemma fibration_iff_isUpperSet_image_Ici [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, IsUpperSet (f '' Ici x) := @fibration_iff_isLowerSet_image_Iic αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_isUpperSet_image [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ s, IsUpperSet s → IsUpperSet (f '' s) := @fibration_iff_isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_image_Ici [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, f '' Ici x = Ici (f x) := fibration_iff_image_Iic hf.dual end Relation
.lake/packages/mathlib/Mathlib/Order/UpperLower/Principal.lean
import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Order.UpperLower.CompleteLattice /-! # Principal upper/lower sets The results in this file all assume that the underlying type is equipped with at least a preorder. ## Main declarations * `UpperSet.Ici`: Principal upper set. `Set.Ici` as an upper set. * `UpperSet.Ioi`: Strict principal upper set. `Set.Ioi` as an upper set. * `LowerSet.Iic`: Principal lower set. `Set.Iic` as a lower set. * `LowerSet.Iio`: Strict principal lower set. `Set.Iio` as a lower set. -/ open Function Set variable {α β : Type*} {ι : Sort*} {κ : ι → Sort*} namespace UpperSet section Preorder variable [Preorder α] [Preorder β] {s : UpperSet α} {a b : α} /-- Principal upper set. `Set.Ici` as an upper set. The smallest upper set containing a given element. -/ nonrec def Ici (a : α) : UpperSet α := ⟨Ici a, isUpperSet_Ici a⟩ /-- Strict principal upper set. `Set.Ioi` as an upper set. -/ nonrec def Ioi (a : α) : UpperSet α := ⟨Ioi a, isUpperSet_Ioi a⟩ @[simp] theorem coe_Ici (a : α) : ↑(Ici a) = Set.Ici a := rfl @[simp] theorem coe_Ioi (a : α) : ↑(Ioi a) = Set.Ioi a := rfl @[simp] theorem mem_Ici_iff : b ∈ Ici a ↔ a ≤ b := Iff.rfl @[simp] theorem mem_Ioi_iff : b ∈ Ioi a ↔ a < b := Iff.rfl @[simp] theorem map_Ici (f : α ≃o β) (a : α) : map f (Ici a) = Ici (f a) := by ext simp @[simp] theorem map_Ioi (f : α ≃o β) (a : α) : map f (Ioi a) = Ioi (f a) := by ext simp theorem Ici_le_Ioi (a : α) : Ici a ≤ Ioi a := Ioi_subset_Ici_self @[simp] nonrec theorem Ici_bot [OrderBot α] : Ici (⊥ : α) = ⊥ := SetLike.coe_injective Ici_bot @[simp] nonrec theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ⊤ := SetLike.coe_injective Ioi_top @[simp] lemma Ici_ne_top : Ici a ≠ ⊤ := SetLike.coe_ne_coe.1 nonempty_Ici.ne_empty @[simp] lemma Ici_lt_top : Ici a < ⊤ := lt_top_iff_ne_top.2 Ici_ne_top @[simp] lemma le_Ici : s ≤ Ici a ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.upper.Ici_subset ha⟩ variable (α) in theorem Ici_strictMono : StrictMono (Ici (α := α)) := fun _ _ h ↦ (Set.Ici_ssubset_Ici).mpr h variable (α) in theorem Ioi_strictMono : StrictMono (Ioi (α := α)) := fun _ _ h ↦ Set.Ioi_ssubset_Ioi h end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Ici_injective : Injective (Ici : α → UpperSet α) := fun _a _b hab ↦ Ici_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff lemma Ici_ne_Ici : Ici a ≠ Ici b ↔ a ≠ b := Ici_inj.not @[simp] theorem Ioi_eq_top [OrderTop α] {a : α} : Ioi a = ⊤ ↔ a = ⊤ := by simp [UpperSet.ext_iff] end PartialOrder @[simp] theorem Ici_sup [SemilatticeSup α] (a b : α) : Ici (a ⊔ b) = Ici a ⊔ Ici b := ext Ici_inter_Ici.symm section CompleteLattice variable [CompleteLattice α] @[simp] theorem Ici_sSup (S : Set α) : Ici (sSup S) = ⨆ a ∈ S, Ici a := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, sSup_le_iff] @[simp] theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⨆ i, Ici (f i) := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, iSup_le_iff] theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⨆ (i) (j), Ici (f i j) := by simp end CompleteLattice end UpperSet namespace LowerSet section Preorder variable [Preorder α] [Preorder β] {s : LowerSet α} {a b : α} /-- Principal lower set. `Set.Iic` as a lower set. The smallest lower set containing a given element. -/ nonrec def Iic (a : α) : LowerSet α := ⟨Iic a, isLowerSet_Iic a⟩ /-- Strict principal lower set. `Set.Iio` as a lower set. -/ nonrec def Iio (a : α) : LowerSet α := ⟨Iio a, isLowerSet_Iio a⟩ @[simp] theorem coe_Iic (a : α) : ↑(Iic a) = Set.Iic a := rfl @[simp] theorem coe_Iio (a : α) : ↑(Iio a) = Set.Iio a := rfl @[simp] theorem mem_Iic_iff : b ∈ Iic a ↔ b ≤ a := Iff.rfl @[simp] theorem mem_Iio_iff : b ∈ Iio a ↔ b < a := Iff.rfl @[simp] theorem map_Iic (f : α ≃o β) (a : α) : map f (Iic a) = Iic (f a) := by ext simp @[simp] theorem map_Iio (f : α ≃o β) (a : α) : map f (Iio a) = Iio (f a) := by ext simp theorem Ioi_le_Ici (a : α) : Ioi a ≤ Ici a := Ioi_subset_Ici_self @[simp] nonrec theorem Iic_top [OrderTop α] : Iic (⊤ : α) = ⊤ := SetLike.coe_injective Iic_top @[simp] nonrec theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ⊥ := SetLike.coe_injective Iio_bot @[simp] lemma Iic_ne_bot : Iic a ≠ ⊥ := SetLike.coe_ne_coe.1 nonempty_Iic.ne_empty @[simp] lemma bot_lt_Iic : ⊥ < Iic a := bot_lt_iff_ne_bot.2 Iic_ne_bot @[simp] lemma Iic_le : Iic a ≤ s ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.lower.Iic_subset ha⟩ variable (α) in theorem Iic_strictMono : StrictMono (Iic (α := α)) := fun _ _ h ↦ (Set.Iic_ssubset_Iic).mpr h variable (α) in theorem Iio_strictMono : StrictMono (Iio (α := α)) := fun _ _ h ↦ Set.Iio_ssubset_Iio h end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Iic_injective : Injective (Iic : α → LowerSet α) := fun _a _b hab ↦ Iic_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff lemma Iic_ne_Iic : Iic a ≠ Iic b ↔ a ≠ b := Iic_inj.not @[simp] theorem Iio_eq_bot [OrderBot α] {a : α} : Iio a = ⊥ ↔ a = ⊥ := by simp [LowerSet.ext_iff] end PartialOrder @[simp] theorem Iic_inf [SemilatticeInf α] (a b : α) : Iic (a ⊓ b) = Iic a ⊓ Iic b := SetLike.coe_injective Iic_inter_Iic.symm section CompleteLattice variable [CompleteLattice α] @[simp] theorem Iic_sInf (S : Set α) : Iic (sInf S) = ⨅ a ∈ S, Iic a := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf₂_iff, le_sInf_iff] @[simp] theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⨅ i, Iic (f i) := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf_iff, le_iInf_iff] theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⨅ (i) (j), Iic (f i j) := by simp end CompleteLattice end LowerSet
.lake/packages/mathlib/Mathlib/Order/UpperLower/CompleteLattice.lean
import Mathlib.Data.Set.Lattice.Image import Mathlib.Data.SetLike.Basic import Mathlib.Order.UpperLower.Basic /-! # The complete lattice structure on `UpperSet`/`LowerSet` This file defines a completely distributive lattice structure on `UpperSet` and `LowerSet`, pulled back across the canonical injection (`UpperSet.carrier`, `LowerSet.carrier`) into `Set α`. ## Notes Upper sets are ordered by **reverse** inclusion. This convention is motivated by the fact that this makes them order-isomorphic to lower sets and antichains, and matches the convention on `Filter`. -/ open OrderDual Set variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*} section LE variable [LE α] namespace UpperSet instance : SetLike (UpperSet α) α where coe := UpperSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : UpperSet α) : Set α := s initialize_simps_projections UpperSet (carrier → coe, as_prefix coe) @[ext] theorem ext {s t : UpperSet α} : (s : Set α) = t → s = t := SetLike.ext' @[simp] theorem carrier_eq_coe (s : UpperSet α) : s.carrier = s := rfl @[simp] protected lemma upper (s : UpperSet α) : IsUpperSet (s : Set α) := s.upper' @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl end UpperSet namespace LowerSet instance : SetLike (LowerSet α) α where coe := LowerSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : LowerSet α) : Set α := s initialize_simps_projections LowerSet (carrier → coe, as_prefix coe) @[ext] theorem ext {s t : LowerSet α} : (s : Set α) = t → s = t := SetLike.ext' @[simp] theorem carrier_eq_coe (s : LowerSet α) : s.carrier = s := rfl @[simp] protected lemma lower (s : LowerSet α) : IsLowerSet (s : Set α) := s.lower' @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl end LowerSet namespace UpperSet variable {S : Set (UpperSet α)} {s t : UpperSet α} {a : α} instance : Max (UpperSet α) := ⟨fun s t => ⟨s ∩ t, s.upper.inter t.upper⟩⟩ instance : Min (UpperSet α) := ⟨fun s t => ⟨s ∪ t, s.upper.union t.upper⟩⟩ instance : Top (UpperSet α) := ⟨⟨∅, isUpperSet_empty⟩⟩ instance : Bot (UpperSet α) := ⟨⟨univ, isUpperSet_univ⟩⟩ instance : SupSet (UpperSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isUpperSet_iInter₂ fun s _ => s.upper⟩⟩ instance : InfSet (UpperSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isUpperSet_iUnion₂ fun s _ => s.upper⟩⟩ instance completeLattice : CompleteLattice (UpperSet α) := (toDual.injective.comp SetLike.coe_injective).completeLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance completelyDistribLattice : CompletelyDistribLattice (UpperSet α) := .ofMinimalAxioms <| (toDual.injective.comp SetLike.coe_injective).completelyDistribLatticeMinimalAxioms .of _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (UpperSet α) := ⟨⊥⟩ @[simp 1100, norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ t ≤ s := Iff.rfl @[simp 1100, norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ t < s := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : UpperSet α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : UpperSet α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊥ := by simp [SetLike.ext'_iff] @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊤ := by simp [SetLike.ext'_iff] @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊤ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : UpperSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∩ t := rfl @[simp, norm_cast] theorem coe_inf (s t : UpperSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∪ t := rfl @[simp, norm_cast] theorem coe_sSup (S : Set (UpperSet α)) : (↑(sSup S) : Set α) = ⋂ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_sInf (S : Set (UpperSet α)) : (↑(sInf S) : Set α) = ⋃ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_iSup (f : ι → UpperSet α) : (↑(⨆ i, f i) : Set α) = ⋂ i, f i := by simp [iSup] @[simp, norm_cast] theorem coe_iInf (f : ι → UpperSet α) : (↑(⨅ i, f i) : Set α) = ⋃ i, f i := by simp [iInf] @[norm_cast] theorem coe_iSup₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp @[norm_cast] theorem coe_iInf₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp @[simp] theorem notMem_top : a ∉ (⊤ : UpperSet α) := id @[deprecated (since := "2025-05-23")] alias not_mem_top := notMem_top @[simp] theorem mem_bot : a ∈ (⊥ : UpperSet α) := trivial @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] @[simp] theorem mem_iSup_iff {f : ι → UpperSet α} : (a ∈ ⨆ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iInter @[simp] theorem mem_iInf_iff {f : ι → UpperSet α} : (a ∈ ⨅ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iUnion theorem mem_iSup₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp theorem mem_iInf₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, codisjoint_iff, SetLike.ext'_iff] end UpperSet namespace LowerSet variable {S : Set (LowerSet α)} {s t : LowerSet α} {a : α} instance : Max (LowerSet α) := ⟨fun s t => ⟨s ∪ t, fun _ _ h => Or.imp (s.lower h) (t.lower h)⟩⟩ instance : Min (LowerSet α) := ⟨fun s t => ⟨s ∩ t, fun _ _ h => And.imp (s.lower h) (t.lower h)⟩⟩ instance : Top (LowerSet α) := ⟨⟨univ, fun _ _ _ => id⟩⟩ instance : Bot (LowerSet α) := ⟨⟨∅, fun _ _ _ => id⟩⟩ instance : SupSet (LowerSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isLowerSet_iUnion₂ fun s _ => s.lower⟩⟩ instance : InfSet (LowerSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isLowerSet_iInter₂ fun s _ => s.lower⟩⟩ instance completeLattice : CompleteLattice (LowerSet α) := SetLike.coe_injective.completeLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance completelyDistribLattice : CompletelyDistribLattice (LowerSet α) := .ofMinimalAxioms <| SetLike.coe_injective.completelyDistribLatticeMinimalAxioms .of _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (LowerSet α) := ⟨⊥⟩ @[norm_cast] lemma coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := Iff.rfl @[norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : LowerSet α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : LowerSet α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊤ := by simp [SetLike.ext'_iff] @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊥ := by simp [SetLike.ext'_iff] @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : LowerSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∪ t := rfl @[simp, norm_cast] theorem coe_inf (s t : LowerSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∩ t := rfl @[simp, norm_cast] theorem coe_sSup (S : Set (LowerSet α)) : (↑(sSup S) : Set α) = ⋃ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_sInf (S : Set (LowerSet α)) : (↑(sInf S) : Set α) = ⋂ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_iSup (f : ι → LowerSet α) : (↑(⨆ i, f i) : Set α) = ⋃ i, f i := by simp_rw [iSup, coe_sSup, mem_range, iUnion_exists, iUnion_iUnion_eq'] @[simp, norm_cast] theorem coe_iInf (f : ι → LowerSet α) : (↑(⨅ i, f i) : Set α) = ⋂ i, f i := by simp_rw [iInf, coe_sInf, mem_range, iInter_exists, iInter_iInter_eq'] @[norm_cast] theorem coe_iSup₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp @[norm_cast] theorem coe_iInf₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp @[simp] theorem mem_top : a ∈ (⊤ : LowerSet α) := trivial @[simp] theorem notMem_bot : a ∉ (⊥ : LowerSet α) := id @[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ @[simp] theorem mem_iSup_iff {f : ι → LowerSet α} : (a ∈ ⨆ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iUnion @[simp] theorem mem_iInf_iff {f : ι → LowerSet α} : (a ∈ ⨅ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iInter theorem mem_iSup₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp theorem mem_iInf₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, SetLike.ext'_iff] end LowerSet /-! ### Complement -/ /-- The complement of a lower set as an upper set. -/ def UpperSet.compl (s : UpperSet α) : LowerSet α := ⟨sᶜ, s.upper.compl⟩ /-- The complement of a lower set as an upper set. -/ def LowerSet.compl (s : LowerSet α) : UpperSet α := ⟨sᶜ, s.lower.compl⟩ namespace UpperSet variable {s t : UpperSet α} {a : α} @[simp] theorem coe_compl (s : UpperSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl @[simp] nonrec theorem compl_compl (s : UpperSet α) : s.compl.compl = s := UpperSet.ext <| compl_compl _ @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl @[simp] protected theorem compl_sup (s t : UpperSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := LowerSet.ext compl_inf @[simp] protected theorem compl_inf (s t : UpperSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := LowerSet.ext compl_sup @[simp] protected theorem compl_top : (⊤ : UpperSet α).compl = ⊤ := LowerSet.ext compl_empty @[simp] protected theorem compl_bot : (⊥ : UpperSet α).compl = ⊥ := LowerSet.ext compl_univ @[simp] protected theorem compl_sSup (S : Set (UpperSet α)) : (sSup S).compl = ⨆ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sSup, compl_iInter₂, LowerSet.coe_iSup₂] @[simp] protected theorem compl_sInf (S : Set (UpperSet α)) : (sInf S).compl = ⨅ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sInf, compl_iUnion₂, LowerSet.coe_iInf₂] @[simp] protected theorem compl_iSup (f : ι → UpperSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iSup, compl_iInter, LowerSet.coe_iSup] @[simp] protected theorem compl_iInf (f : ι → UpperSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iInf, compl_iUnion, LowerSet.coe_iInf] theorem compl_iSup₂ (f : ∀ i, κ i → UpperSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp theorem compl_iInf₂ (f : ∀ i, κ i → UpperSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp end UpperSet namespace LowerSet variable {s t : LowerSet α} {a : α} @[simp] theorem coe_compl (s : LowerSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl @[simp] nonrec theorem compl_compl (s : LowerSet α) : s.compl.compl = s := LowerSet.ext <| compl_compl _ @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl protected theorem compl_sup (s t : LowerSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := UpperSet.ext compl_sup protected theorem compl_inf (s t : LowerSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := UpperSet.ext compl_inf protected theorem compl_top : (⊤ : LowerSet α).compl = ⊤ := UpperSet.ext compl_univ protected theorem compl_bot : (⊥ : LowerSet α).compl = ⊥ := UpperSet.ext compl_empty protected theorem compl_sSup (S : Set (LowerSet α)) : (sSup S).compl = ⨆ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sSup, compl_iUnion₂, UpperSet.coe_iSup₂] protected theorem compl_sInf (S : Set (LowerSet α)) : (sInf S).compl = ⨅ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sInf, compl_iInter₂, UpperSet.coe_iInf₂] protected theorem compl_iSup (f : ι → LowerSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iSup, compl_iUnion, UpperSet.coe_iSup] protected theorem compl_iInf (f : ι → LowerSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iInf, compl_iInter, UpperSet.coe_iInf] @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → LowerSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iSup] @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → LowerSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iInf] end LowerSet /-- Upper sets are order-isomorphic to lower sets under complementation. -/ @[simps] def upperSetIsoLowerSet : UpperSet α ≃o LowerSet α where toFun := UpperSet.compl invFun := LowerSet.compl left_inv := UpperSet.compl_compl right_inv := LowerSet.compl_compl map_rel_iff' := UpperSet.compl_le_compl end LE section LinearOrder variable [LinearOrder α] instance UpperSet.isTotal_le : IsTotal (UpperSet α) (· ≤ ·) := ⟨fun s t => t.upper.total s.upper⟩ instance LowerSet.isTotal_le : IsTotal (LowerSet α) (· ≤ ·) := ⟨fun s t => s.lower.total t.lower⟩ noncomputable instance UpperSet.instLinearOrder : LinearOrder (UpperSet α) := by classical exact Lattice.toLinearOrder _ noncomputable instance LowerSet.instLinearOrder : LinearOrder (LowerSet α) := by classical exact Lattice.toLinearOrder _ noncomputable instance UpperSet.instCompleteLinearOrder : CompleteLinearOrder (UpperSet α) := { completelyDistribLattice, instLinearOrder with } noncomputable instance LowerSet.instCompleteLinearOrder : CompleteLinearOrder (LowerSet α) := { completelyDistribLattice, instLinearOrder with } end LinearOrder section Map variable [Preorder α] [Preorder β] [Preorder γ] namespace UpperSet variable {f : α ≃o β} {s t : UpperSet α} {a : α} {b : β} /-- An order isomorphism of Preorders induces an order isomorphism of their upper sets. -/ def map (f : α ≃o β) : UpperSet α ≃o UpperSet β where toFun s := ⟨f '' s, s.upper.image f⟩ invFun t := ⟨f ⁻¹' t, t.upper.preimage f.monotone⟩ left_inv _ := ext <| f.preimage_image _ right_inv _ := ext <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := by ext; simp [map, OrderIso.symm_apply_eq] @[simp] theorem mem_map : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl end UpperSet namespace LowerSet variable {f : α ≃o β} {s t : LowerSet α} {a : α} /-- An order isomorphism of Preorders induces an order isomorphism of their lower sets. -/ def map (f : α ≃o β) : LowerSet α ≃o LowerSet β where toFun s := ⟨f '' s, s.lower.image f⟩ invFun t := ⟨f ⁻¹' t, t.lower.preimage f.monotone⟩ left_inv _ := SetLike.coe_injective <| f.preimage_image _ right_inv _ := SetLike.coe_injective <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := by ext; simp [map, OrderIso.symm_apply_eq] @[simp] theorem mem_map {f : α ≃o β} {b : β} : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl end LowerSet namespace UpperSet @[simp] theorem compl_map (f : α ≃o β) (s : UpperSet α) : (map f s).compl = LowerSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm end UpperSet namespace LowerSet @[simp] theorem compl_map (f : α ≃o β) (s : LowerSet α) : (map f s).compl = UpperSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm end LowerSet end Map
.lake/packages/mathlib/Mathlib/Order/UpperLower/Relative.lean
import Mathlib.Data.Set.Image import Mathlib.Data.SetLike.Basic import Mathlib.Order.Interval.Set.Defs import Mathlib.Order.SetNotation /-! # Properties of relative upper/lower sets This file proves results on `IsRelUpperSet` and `IsRelLowerSet`. -/ open Set variable {α : Type*} {ι : Sort*} {κ : ι → Sort*} {s t : Set α} {a : α} {P : α → Prop} section LE variable [LE α] lemma IsRelUpperSet.prop_of_mem (hs : IsRelUpperSet s P) (h : a ∈ s) : P a := (hs h).1 lemma IsRelLowerSet.prop_of_mem (hs : IsRelLowerSet s P) (h : a ∈ s) : P a := (hs h).1 @[simp] lemma isRelUpperSet_empty : IsRelUpperSet (∅ : Set α) P := fun _ ↦ False.elim @[simp] lemma isRelLowerSet_empty : IsRelLowerSet (∅ : Set α) P := fun _ ↦ False.elim @[simp] lemma isRelUpperSet_self : IsRelUpperSet s (· ∈ s) := fun _ b ↦ ⟨b, fun _ _ ↦ id⟩ @[simp] lemma isRelLowerSet_self : IsRelLowerSet s (· ∈ s) := fun _ b ↦ ⟨b, fun _ _ ↦ id⟩ lemma IsRelUpperSet.union (hs : IsRelUpperSet s P) (ht : IsRelUpperSet t P) : IsRelUpperSet (s ∪ t) P := fun b mb ↦ by cases mb with | inl h => exact ⟨(hs h).1, fun _ x y ↦ .inl ((hs h).2 x y)⟩ | inr h => exact ⟨(ht h).1, fun _ x y ↦ .inr ((ht h).2 x y)⟩ lemma IsRelLowerSet.union (hs : IsRelLowerSet s P) (ht : IsRelLowerSet t P) : IsRelLowerSet (s ∪ t) P := fun b mb ↦ by cases mb with | inl h => exact ⟨(hs h).1, fun _ x y ↦ .inl ((hs h).2 x y)⟩ | inr h => exact ⟨(ht h).1, fun _ x y ↦ .inr ((ht h).2 x y)⟩ lemma IsRelUpperSet.inter (hs : IsRelUpperSet s P) (ht : IsRelUpperSet t P) : IsRelUpperSet (s ∩ t) P := fun b ⟨bs, bt⟩ ↦ by simp_all only [IsRelUpperSet, true_and] exact fun _ x y ↦ ⟨(hs bs).2 x y, (ht bt).2 x y⟩ lemma IsRelLowerSet.inter (hs : IsRelLowerSet s P) (ht : IsRelLowerSet t P) : IsRelLowerSet (s ∩ t) P := fun b ⟨bs, bt⟩ ↦ by simp_all only [IsRelLowerSet, true_and] exact fun _ x y ↦ ⟨(hs bs).2 x y, (ht bt).2 x y⟩ protected lemma IsRelUpperSet.sUnion {S : Set (Set α)} (hS : ∀ s ∈ S, IsRelUpperSet s P) : IsRelUpperSet (⋃₀ S) P := fun _ ⟨s, ms, mb⟩ ↦ ⟨(hS s ms mb).1, fun _ x y ↦ ⟨s, ms, (hS s ms mb).2 x y⟩⟩ protected lemma IsRelLowerSet.sUnion {S : Set (Set α)} (hS : ∀ s ∈ S, IsRelLowerSet s P) : IsRelLowerSet (⋃₀ S) P := fun _ ⟨s, ms, mb⟩ ↦ ⟨(hS s ms mb).1, fun _ x y ↦ ⟨s, ms, (hS s ms mb).2 x y⟩⟩ protected lemma IsRelUpperSet.iUnion {f : ι → Set α} (hf : ∀ i, IsRelUpperSet (f i) P) : IsRelUpperSet (⋃ i, f i) P := .sUnion (forall_mem_range.2 hf) protected lemma IsRelLowerSet.iUnion {f : ι → Set α} (hf : ∀ i, IsRelLowerSet (f i) P) : IsRelLowerSet (⋃ i, f i) P := .sUnion (forall_mem_range.2 hf) protected lemma IsRelUpperSet.iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelUpperSet (f i j) P) : IsRelUpperSet (⋃ (i) (j), f i j) P := .iUnion fun i ↦ .iUnion (hf i) protected lemma IsRelLowerSet.iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelLowerSet (f i j) P) : IsRelLowerSet (⋃ (i) (j), f i j) P := .iUnion fun i ↦ .iUnion (hf i) protected lemma IsRelUpperSet.sInter {S : Set (Set α)} (hS : S.Nonempty) (hf : ∀ s ∈ S, IsRelUpperSet s P) : IsRelUpperSet (⋂₀ S) P := fun b mb ↦ by obtain ⟨s₀, ms₀⟩ := hS refine ⟨(hf s₀ ms₀ (mb s₀ ms₀)).1, fun _ x y s ms ↦ (hf s ms (mb s ms)).2 x y⟩ protected lemma IsRelLowerSet.sInter {S : Set (Set α)} (hS : S.Nonempty) (hf : ∀ s ∈ S, IsRelLowerSet s P) : IsRelLowerSet (⋂₀ S) P := fun b mb ↦ by obtain ⟨s₀, ms₀⟩ := hS refine ⟨(hf s₀ ms₀ (mb s₀ ms₀)).1, fun _ x y s ms ↦ (hf s ms (mb s ms)).2 x y⟩ protected lemma IsRelUpperSet.iInter [Nonempty ι] {f : ι → Set α} (hf : ∀ i, IsRelUpperSet (f i) P) : IsRelUpperSet (⋂ i, f i) P := .sInter (range_nonempty f) (forall_mem_range.2 hf) protected lemma IsRelLowerSet.iInter [Nonempty ι] {f : ι → Set α} (hf : ∀ i, IsRelLowerSet (f i) P) : IsRelLowerSet (⋂ i, f i) P := .sInter (range_nonempty f) (forall_mem_range.2 hf) protected lemma IsRelUpperSet.iInter₂ [Nonempty ι] [∀ i, Nonempty (κ i)] {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelUpperSet (f i j) P) : IsRelUpperSet (⋂ (i) (j), f i j) P := .iInter fun i ↦ .iInter (hf i) protected lemma IsRelLowerSet.iInter₂ [Nonempty ι] [∀ i, Nonempty (κ i)] {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsRelLowerSet (f i j) P) : IsRelLowerSet (⋂ (i) (j), f i j) P := .iInter fun i ↦ .iInter (hf i) lemma isUpperSet_subtype_iff_isRelUpperSet {s : Set { x // P x }} : IsUpperSet s ↔ IsRelUpperSet (Subtype.val '' s) P := by refine ⟨fun h a x ↦ ?_, fun h a b x y ↦ ?_⟩ · obtain ⟨a, ma, rfl⟩ := x exact ⟨a.2, fun b x y ↦ by simpa [h (show a ≤ ⟨b, y⟩ by exact x) ma]⟩ · have ma : a.1 ∈ Subtype.val '' s := by simp [a.2, y] simpa only [mem_image, SetCoe.ext_iff, exists_eq_right] using (h ma).2 x b.2 lemma isLowerSet_subtype_iff_isRelLowerSet {s : Set { x // P x }} : IsLowerSet s ↔ IsRelLowerSet (Subtype.val '' s) P := by refine ⟨fun h a x ↦ ?_, fun h a b x y ↦ ?_⟩ · obtain ⟨a, ma, rfl⟩ := x exact ⟨a.2, fun b x y ↦ by simpa [h (show ⟨b, y⟩ ≤ a by exact x) ma]⟩ · have ma : a.1 ∈ Subtype.val '' s := by simp [a.2, y] simpa only [mem_image, SetCoe.ext_iff, exists_eq_right] using (h ma).2 x b.2 instance : SetLike (RelUpperSet P) α where coe := RelUpperSet.carrier coe_injective' s t h := by cases s; cases t; congr instance : SetLike (RelLowerSet P) α where coe := RelLowerSet.carrier coe_injective' s t h := by cases s; cases t; congr lemma RelUpperSet.isRelUpperSet (u : RelUpperSet P) : IsRelUpperSet u P := u.isRelUpperSet' lemma RelLowerSet.isRelLowerSet (l : RelLowerSet P) : IsRelLowerSet l P := l.isRelLowerSet' end LE section Preorder variable [Preorder α] {c : α} lemma isRelUpperSet_Icc_le : IsRelUpperSet (Icc a c) (· ≤ c) := fun _ b ↦ by simp_all only [mem_Icc, and_true, true_and] exact fun _ x _ ↦ b.1.trans x lemma isRelLowerSet_Icc_ge : IsRelLowerSet (Icc c a) (c ≤ ·) := fun _ b ↦ by simp_all only [mem_Icc, true_and] exact fun _ x _ ↦ x.trans b.2 end Preorder
.lake/packages/mathlib/Mathlib/Order/UpperLower/Hom.lean
import Mathlib.Order.Hom.CompleteLattice import Mathlib.Order.UpperLower.Principal /-! # `UpperSet.Ici` etc. as `Sup`/`sSup`/`Inf`/`sInf`-homomorphisms In this file we define `UpperSet.iciSupHom` etc. These functions are `UpperSet.Ici` and `LowerSet.Iic` bundled as `SupHom`s, `InfHom`s, `sSupHom`s, or `sInfHom`s. -/ variable {α : Type*} open OrderDual namespace UpperSet section SemilatticeSup variable [SemilatticeSup α] /-- `UpperSet.Ici` as a `SupHom`. -/ def iciSupHom : SupHom α (UpperSet α) := ⟨Ici, Ici_sup⟩ @[simp] theorem coe_iciSupHom : (iciSupHom : α → UpperSet α) = Ici := rfl @[simp] theorem iciSupHom_apply (a : α) : iciSupHom a = Ici a := rfl end SemilatticeSup variable [CompleteLattice α] /-- `UpperSet.Ici` as a `sSupHom`. -/ def icisSupHom : sSupHom α (UpperSet α) := ⟨Ici, fun s => (Ici_sSup s).trans sSup_image.symm⟩ @[simp] theorem coe_icisSupHom : (icisSupHom : α → UpperSet α) = Ici := rfl @[simp] theorem icisSupHom_apply (a : α) : icisSupHom a = Ici a := rfl end UpperSet namespace LowerSet section SemilatticeInf variable [SemilatticeInf α] /-- `LowerSet.Iic` as an `InfHom`. -/ def iicInfHom : InfHom α (LowerSet α) := ⟨Iic, Iic_inf⟩ @[simp] theorem coe_iicInfHom : (iicInfHom : α → LowerSet α) = Iic := rfl @[simp] theorem iicInfHom_apply (a : α) : iicInfHom a = Iic a := rfl end SemilatticeInf variable [CompleteLattice α] /-- `LowerSet.Iic` as an `sInfHom`. -/ def iicsInfHom : sInfHom α (LowerSet α) := ⟨Iic, fun s => (Iic_sInf s).trans sInf_image.symm⟩ @[simp] theorem coe_iicsInfHom : (iicsInfHom : α → LowerSet α) = Iic := rfl @[simp] theorem iicsInfHom_apply (a : α) : iicsInfHom a = Iic a := rfl end LowerSet
.lake/packages/mathlib/Mathlib/Order/UpperLower/LocallyFinite.lean
import Mathlib.Data.Set.Finite.Lattice import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.UpperLower.Closure /-! # Upper and lower sets in a locally finite order In this file we characterise the interaction of `UpperSet`/`LowerSet` and `LocallyFiniteOrder`. -/ namespace Set variable {α : Type*} [Preorder α] {s : Set α} protected theorem Finite.upperClosure [LocallyFiniteOrderTop α] (hs : s.Finite) : (upperClosure s : Set α).Finite := by rw [coe_upperClosure] exact hs.biUnion fun _ _ => finite_Ici _ protected theorem Finite.lowerClosure [LocallyFiniteOrderBot α] (hs : s.Finite) : (lowerClosure s : Set α).Finite := by rw [coe_lowerClosure] exact hs.biUnion fun _ _ => finite_Iic _ end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Lex.lean
import Mathlib.Order.Interval.Basic import Mathlib.Data.Prod.Lex import Mathlib.Tactic.FastInstance /-! # The lexicographic order on intervals This order is compatible with the inclusion ordering, but is total. Under this ordering, `[(3, 3), (2, 2), (2, 3), (1, 1), (1, 2), (1, 3)]` is sorted. -/ namespace NonemptyInterval variable {α} section LELT variable [LT α] [LE α] instance : LE (Lex (NonemptyInterval α)) where le x y := toLex (ofLex x).toDualProd ≤ toLex (ofLex y).toDualProd instance : LT (Lex (NonemptyInterval α)) where lt x y := toLex (ofLex x).toDualProd < toLex (ofLex y).toDualProd theorem toLex_le_toLex {x y : NonemptyInterval α} : toLex x ≤ toLex y ↔ y.fst < x.fst ∨ x.fst = y.fst ∧ x.snd ≤ y.snd := Prod.lex_def theorem toLex_lt_toLex {x y : NonemptyInterval α} : toLex x < toLex y ↔ y.fst < x.fst ∨ x.fst = y.fst ∧ x.snd < y.snd := Prod.lex_def instance [DecidableEq α] [DecidableLT α] [DecidableLE α] : DecidableLE (Lex (NonemptyInterval α)) := fun _ _ => decidable_of_iff' _ toLex_le_toLex instance [DecidableEq α] [DecidableLT α] : DecidableLT (Lex (NonemptyInterval α)) := fun _ _ => decidable_of_iff' _ toLex_lt_toLex -- Sanity check on the ordering. /-- info: [(3, 3), (2, 2), (2, 3), (1, 1), (1, 2), (1, 3)] -/ #guard_msgs in #eval [ NonemptyInterval.mk (1, 1) (by grind), NonemptyInterval.mk (1, 2) (by grind), NonemptyInterval.mk (1, 3) (by grind), NonemptyInterval.mk (2, 2) (by grind), NonemptyInterval.mk (2, 3) (by grind), NonemptyInterval.mk (3, 3) (by grind)].map toLex |>.mergeSort.map (·.toProd) end LELT instance [Preorder α] : Preorder (Lex (NonemptyInterval α)) := fast_instance% Preorder.lift fun x => toLex (ofLex x).toDualProd theorem toLex_mono [PartialOrder α] : Monotone (toLex : NonemptyInterval α → _) := Prod.Lex.toLex_mono.comp toDualProd_mono theorem toLex_strictMono [PartialOrder α] : StrictMono (toLex : NonemptyInterval α → _) := Prod.Lex.toLex_strictMono.comp toDualProd_strictMono instance [PartialOrder α] : PartialOrder (Lex (NonemptyInterval α)) := fast_instance% PartialOrder.lift (fun x => toLex (ofLex x).toDualProd) <| toLex.injective.comp <| toDualProd_injective.comp ofLex.injective instance [LinearOrder α] : LinearOrder (Lex (NonemptyInterval α)) := fast_instance% { LinearOrder.lift' (fun x : Lex (NonemptyInterval α) => toLex (ofLex x).toDualProd) <| toLex.injective.comp <| toDualProd_injective.comp ofLex.injective with toDecidableEq := inferInstance toDecidableLT := inferInstance toDecidableLE := inferInstance } end NonemptyInterval
.lake/packages/mathlib/Mathlib/Order/Interval/Basic.lean
import Mathlib.Order.Interval.Set.Basic import Mathlib.Data.Set.Lattice.Image import Mathlib.Data.SetLike.Basic /-! # Order intervals This file defines (nonempty) closed intervals in an order (see `Set.Icc`). This is a prototype for interval arithmetic. ## Main declarations * `NonemptyInterval`: Nonempty intervals. Pairs where the second element is greater than the first. * `Interval`: Intervals. Either `∅` or a nonempty interval. -/ open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*} /-- The nonempty closed intervals in an order. We define intervals by the pair of endpoints `fst`, `snd`. To convert intervals to the set of elements between these endpoints, use the coercion `NonemptyInterval α → Set α`. -/ @[ext (flat := false)] structure NonemptyInterval (α : Type*) [LE α] extends Prod α α where /-- The starting point of an interval is smaller than the endpoint. -/ fst_le_snd : fst ≤ snd namespace NonemptyInterval section LE variable [LE α] {s t : NonemptyInterval α} theorem toProd_injective : Injective (toProd : NonemptyInterval α → α × α) := fun s t h => by cases s; cases t; congr /-- Allow lifting a pair `(a, b)` with `a ≤ b` to `NonemptyInterval` in the `lift` tactic. -/ instance instCanLift : CanLift (α × α) (NonemptyInterval α) NonemptyInterval.toProd (fun x ↦ x.1 ≤ x.2) where prf x hx := ⟨⟨x, hx⟩, rfl⟩ /-- The injection that induces the order on intervals. -/ def toDualProd : NonemptyInterval α → αᵒᵈ × α := toProd @[simp] theorem toDualProd_apply (s : NonemptyInterval α) : s.toDualProd = (toDual s.fst, s.snd) := rfl theorem toDualProd_injective : Injective (toDualProd : NonemptyInterval α → αᵒᵈ × α) := toProd_injective instance [IsEmpty α] : IsEmpty (NonemptyInterval α) := ⟨fun s => isEmptyElim s.fst⟩ instance [Subsingleton α] : Subsingleton (NonemptyInterval α) := toDualProd_injective.subsingleton instance [DecidableEq α] : DecidableEq (NonemptyInterval α) := toDualProd_injective.decidableEq instance le : LE (NonemptyInterval α) := ⟨fun s t => t.fst ≤ s.fst ∧ s.snd ≤ t.snd⟩ theorem le_def : s ≤ t ↔ t.fst ≤ s.fst ∧ s.snd ≤ t.snd := Iff.rfl instance [DecidableLE α] : DecidableLE (NonemptyInterval α) := fun _ _ => decidable_of_iff' _ le_def /-- `toDualProd` as an order embedding. -/ @[simps] def toDualProdHom : NonemptyInterval α ↪o αᵒᵈ × α where toFun := toDualProd inj' := toDualProd_injective map_rel_iff' := Iff.rfl /-- Turn an interval into an interval in the dual order. -/ def dual : NonemptyInterval α ≃ NonemptyInterval αᵒᵈ where toFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ invFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ @[simp] theorem fst_dual (s : NonemptyInterval α) : s.dual.fst = toDual s.snd := rfl @[simp] theorem snd_dual (s : NonemptyInterval α) : s.dual.snd = toDual s.fst := rfl end LE section Preorder variable [Preorder α] [Preorder β] [Preorder γ] {s : NonemptyInterval α} {x : α × α} {a : α} instance : Preorder (NonemptyInterval α) := Preorder.lift toDualProd theorem toDualProd_mono : Monotone (toDualProd : _ → αᵒᵈ × α) := fun _ _ => id theorem toDualProd_strictMono : StrictMono (toDualProd : _ → αᵒᵈ × α) := fun _ _ => id instance : Coe (NonemptyInterval α) (Set α) := ⟨fun s => Icc s.fst s.snd⟩ instance (priority := 100) : Membership α (NonemptyInterval α) := ⟨fun s a => a ∈ (s : Set α)⟩ @[simp] theorem mem_mk {hx : x.1 ≤ x.2} : a ∈ mk x hx ↔ x.1 ≤ a ∧ a ≤ x.2 := Iff.rfl theorem mem_def : a ∈ s ↔ s.fst ≤ a ∧ a ≤ s.snd := Iff.rfl theorem coe_nonempty (s : NonemptyInterval α) : (s : Set α).Nonempty := nonempty_Icc.2 s.fst_le_snd /-- `{a}` as an interval. -/ @[simps] def pure (a : α) : NonemptyInterval α := ⟨⟨a, a⟩, le_rfl⟩ theorem mem_pure_self (a : α) : a ∈ pure a := ⟨le_rfl, le_rfl⟩ theorem pure_injective : Injective (pure : α → NonemptyInterval α) := fun _ _ => congr_arg <| Prod.fst ∘ toProd @[simp] theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) := rfl instance [Inhabited α] : Inhabited (NonemptyInterval α) := ⟨pure default⟩ instance [Nonempty α] : Nonempty (NonemptyInterval α) := Nonempty.map pure (by infer_instance) instance [Nontrivial α] : Nontrivial (NonemptyInterval α) := pure_injective.nontrivial /-- Pushforward of nonempty intervals. -/ @[simps!] def map (f : α →o β) (a : NonemptyInterval α) : NonemptyInterval β := ⟨a.toProd.map f f, f.mono a.fst_le_snd⟩ @[simp] theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) := rfl @[simp] theorem map_map (g : β →o γ) (f : α →o β) (a : NonemptyInterval α) : (a.map f).map g = a.map (g.comp f) := rfl @[simp] theorem dual_map (f : α →o β) (a : NonemptyInterval α) : dual (a.map f) = a.dual.map f.dual := rfl /-- Binary pushforward of nonempty intervals. -/ @[simps] def map₂ (f : α → β → γ) (h₀ : ∀ b, Monotone fun a => f a b) (h₁ : ∀ a, Monotone (f a)) : NonemptyInterval α → NonemptyInterval β → NonemptyInterval γ := fun s t => ⟨(f s.fst t.fst, f s.snd t.snd), (h₀ _ s.fst_le_snd).trans <| h₁ _ t.fst_le_snd⟩ @[simp] theorem map₂_pure (f : α → β → γ) (h₀ h₁) (a : α) (b : β) : map₂ f h₀ h₁ (pure a) (pure b) = pure (f a b) := rfl @[simp] theorem dual_map₂ (f : α → β → γ) (h₀ h₁ s t) : dual (map₂ f h₀ h₁ s t) = map₂ (fun a b => toDual <| f (ofDual a) <| ofDual b) (fun _ => (h₀ _).dual) (fun _ => (h₁ _).dual) (dual s) (dual t) := rfl variable [BoundedOrder α] instance : OrderTop (NonemptyInterval α) where top := ⟨⟨⊥, ⊤⟩, bot_le⟩ le_top _ := ⟨bot_le, le_top⟩ @[simp] theorem dual_top : dual (⊤ : NonemptyInterval α) = ⊤ := rfl end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {s t : NonemptyInterval α} {a b : α} instance : PartialOrder (NonemptyInterval α) := PartialOrder.lift _ toDualProd_injective instance [DecidableLE α] : DecidableLE (NonemptyInterval α) := fun _ _ => decidable_of_iff' _ le_def /-- Consider a nonempty interval `[a, b]` as the set `[a, b]`. -/ def coeHom : NonemptyInterval α ↪o Set α := OrderEmbedding.ofMapLEIff (fun s => Icc s.fst s.snd) fun s _ => Icc_subset_Icc_iff s.fst_le_snd instance setLike : SetLike (NonemptyInterval α) α where coe s := Icc s.fst s.snd coe_injective' := coeHom.injective @[norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ (s : NonemptyInterval α) ≤ t := (@coeHom α _).le_iff_le @[norm_cast] theorem coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := (@coeHom α _).lt_iff_lt @[simp] theorem coe_coeHom : (coeHom : NonemptyInterval α → Set α) = ((↑) : NonemptyInterval α → Set α) := rfl theorem coe_def (s : NonemptyInterval α) : (s : Set α) = Set.Icc s.toProd.1 s.toProd.2 := rfl @[simp, norm_cast] theorem coe_pure (a : α) : (pure a : Set α) = {a} := Icc_self _ @[simp] theorem mem_pure : b ∈ pure a ↔ b = a := by rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff] @[simp, norm_cast] theorem coe_top [BoundedOrder α] : ((⊤ : NonemptyInterval α) : Set α) = univ := Icc_bot_top @[simp, norm_cast] theorem coe_dual (s : NonemptyInterval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s := Icc_toDual theorem subset_coe_map (f : α →o β) (s : NonemptyInterval α) : f '' s ⊆ s.map f := image_subset_iff.2 fun _ ha => ⟨f.mono ha.1, f.mono ha.2⟩ end PartialOrder section Lattice variable [Lattice α] instance : Max (NonemptyInterval α) := ⟨fun s t => ⟨⟨s.fst ⊓ t.fst, s.snd ⊔ t.snd⟩, inf_le_left.trans <| s.fst_le_snd.trans le_sup_left⟩⟩ instance : SemilatticeSup (NonemptyInterval α) := toDualProd_injective.semilatticeSup _ fun _ _ => rfl @[simp] theorem fst_sup (s t : NonemptyInterval α) : (s ⊔ t).fst = s.fst ⊓ t.fst := rfl @[simp] theorem snd_sup (s t : NonemptyInterval α) : (s ⊔ t).snd = s.snd ⊔ t.snd := rfl end Lattice end NonemptyInterval /-- The closed intervals in an order. We represent intervals either as `⊥` or a nonempty interval given by its endpoints `fst`, `snd`. To convert intervals to the set of elements between these endpoints, use the coercion `Interval α → Set α`. -/ abbrev Interval (α : Type*) [LE α] := WithBot (NonemptyInterval α) namespace Interval section LE variable [LE α] -- The `Inhabited, LE, OrderBot` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 -- Note(kmill): `Interval` is an `abbrev`, so none of these `instance`s are needed. instance : Inhabited (Interval α) := WithBot.inhabited instance : LE (Interval α) := WithBot.instLE instance : OrderBot (Interval α) := WithBot.instOrderBot instance : Coe (NonemptyInterval α) (Interval α) := WithBot.coe instance canLift : CanLift (Interval α) (NonemptyInterval α) (↑) fun r => r ≠ ⊥ := WithBot.canLift /-- Recursor for `Interval` using the preferred forms `⊥` and `↑a`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recBotCoe {C : Interval α → Sort*} (bot : C ⊥) (coe : ∀ a : NonemptyInterval α, C a) : ∀ n : Interval α, C n := WithBot.recBotCoe bot coe theorem coe_injective : Injective ((↑) : NonemptyInterval α → Interval α) := WithBot.coe_injective @[norm_cast] theorem coe_inj {s t : NonemptyInterval α} : (s : Interval α) = t ↔ s = t := WithBot.coe_inj protected theorem «forall» {p : Interval α → Prop} : (∀ s, p s) ↔ p ⊥ ∧ ∀ s : NonemptyInterval α, p s := Option.forall protected theorem «exists» {p : Interval α → Prop} : (∃ s, p s) ↔ p ⊥ ∨ ∃ s : NonemptyInterval α, p s := Option.exists instance [IsEmpty α] : Unique (Interval α) := inferInstanceAs <| Unique (Option _) /-- Turn an interval into an interval in the dual order. -/ def dual : Interval α ≃ Interval αᵒᵈ := NonemptyInterval.dual.withBotCongr end LE section Preorder variable [Preorder α] [Preorder β] [Preorder γ] instance : Preorder (Interval α) := WithBot.instPreorder /-- `{a}` as an interval. -/ def pure (a : α) : Interval α := NonemptyInterval.pure a theorem pure_injective : Injective (pure : α → Interval α) := coe_injective.comp NonemptyInterval.pure_injective @[simp] theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) := rfl @[simp] theorem dual_bot : dual (⊥ : Interval α) = ⊥ := rfl @[simp] theorem pure_ne_bot {a : α} : pure a ≠ ⊥ := WithBot.coe_ne_bot @[simp] theorem bot_ne_pure {a : α} : ⊥ ≠ pure a := WithBot.bot_ne_coe instance [Nonempty α] : Nontrivial (Interval α) := Option.nontrivial /-- Pushforward of intervals. -/ def map (f : α →o β) : Interval α → Interval β := WithBot.map (NonemptyInterval.map f) @[simp] theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) := rfl @[simp] theorem map_map (g : β →o γ) (f : α →o β) (s : Interval α) : (s.map f).map g = s.map (g.comp f) := Option.map_map _ _ _ @[simp] theorem dual_map (f : α →o β) (s : Interval α) : dual (s.map f) = s.dual.map f.dual := by cases s · rfl · exact WithBot.map_comm rfl _ variable [BoundedOrder α] instance boundedOrder : BoundedOrder (Interval α) := WithBot.instBoundedOrder @[simp] theorem dual_top : dual (⊤ : Interval α) = ⊤ := rfl end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {s t : Interval α} {a b : α} instance partialOrder : PartialOrder (Interval α) := WithBot.instPartialOrder /-- Consider an interval `[a, b]` as the set `[a, b]`. -/ def coeHom : Interval α ↪o Set α := OrderEmbedding.ofMapLEIff (fun s => match s with | ⊥ => ∅ | some s => s) fun s t => match s, t with | ⊥, _ => iff_of_true bot_le bot_le | some s, ⊥ => iff_of_false (fun h => s.coe_nonempty.ne_empty <| le_bot_iff.1 h) (WithBot.not_coe_le_bot _) | some _, some _ => (@NonemptyInterval.coeHom α _).le_iff_le.trans WithBot.coe_le_coe.symm instance setLike : SetLike (Interval α) α where coe := coeHom coe_injective' := coeHom.injective @[norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := (@coeHom α _).le_iff_le @[norm_cast] theorem coe_sSubset_coe : (s : Set α) ⊂ t ↔ s < t := (@coeHom α _).lt_iff_lt @[simp, norm_cast] theorem coe_pure (a : α) : (pure a : Set α) = {a} := Icc_self _ @[simp, norm_cast] theorem coe_coe (s : NonemptyInterval α) : ((s : Interval α) : Set α) = s := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : Interval α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_top [BoundedOrder α] : ((⊤ : Interval α) : Set α) = univ := Icc_bot_top @[simp, norm_cast] theorem coe_dual (s : Interval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s := by cases s with | bot => rfl | coe s₀ => exact NonemptyInterval.coe_dual s₀ theorem subset_coe_map (f : α →o β) : ∀ s : Interval α, f '' s ⊆ s.map f | ⊥ => by simp | (s : NonemptyInterval α) => s.subset_coe_map _ @[simp] theorem mem_pure : b ∈ pure a ↔ b = a := by rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff] theorem mem_pure_self (a : α) : a ∈ pure a := mem_pure.2 rfl end PartialOrder section Lattice variable [Lattice α] instance semilatticeSup : SemilatticeSup (Interval α) := WithBot.semilatticeSup section Decidable variable [DecidableLE α] instance lattice : Lattice (Interval α) := { Interval.semilatticeSup with inf := fun s t => match s, t with | ⊥, _ => ⊥ | _, ⊥ => ⊥ | some s, some t => if h : s.fst ≤ t.snd ∧ t.fst ≤ s.snd then WithBot.some ⟨⟨s.fst ⊔ t.fst, s.snd ⊓ t.snd⟩, sup_le (le_inf s.fst_le_snd h.1) <| le_inf h.2 t.fst_le_snd⟩ else ⊥ inf_le_left := fun s t => match s, t with | ⊥, ⊥ => bot_le | ⊥, some _ => bot_le | some _, ⊥ => bot_le | some s, some t => by change dite _ _ _ ≤ _ split_ifs · exact WithBot.coe_le_coe.2 ⟨le_sup_left, inf_le_left⟩ · exact bot_le inf_le_right := fun s t => match s, t with | ⊥, ⊥ => bot_le | ⊥, some _ => bot_le | some _, ⊥ => bot_le | some s, some t => by change dite _ _ _ ≤ _ split_ifs · exact WithBot.coe_le_coe.2 ⟨le_sup_right, inf_le_right⟩ · exact bot_le le_inf := fun s t c => match s, t, c with | ⊥, _, _ => fun _ _ => bot_le | (s : NonemptyInterval α), t, c => fun hb hc => by lift t to NonemptyInterval α using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hb lift c to NonemptyInterval α using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hc change _ ≤ dite _ _ _ simp only [WithBot.coe_le_coe] at hb hc ⊢ rw [dif_pos, WithBot.coe_le_coe] · exact ⟨sup_le hb.1 hc.1, le_inf hb.2 hc.2⟩ -- Porting note: had to add the next 6 lines including the changes because -- it seems that lean cannot automatically turn `NonemptyInterval.toDualProd s` -- into `s.toProd` anymore. rcases hb with ⟨hb₁, hb₂⟩ rcases hc with ⟨hc₁, hc₂⟩ change t.toProd.fst ≤ s.toProd.fst at hb₁ change s.toProd.snd ≤ t.toProd.snd at hb₂ change c.toProd.fst ≤ s.toProd.fst at hc₁ change s.toProd.snd ≤ c.toProd.snd at hc₂ -- Porting note: originally it just had `hb.1` etc. in this next line exact ⟨hb₁.trans <| s.fst_le_snd.trans hc₂, hc₁.trans <| s.fst_le_snd.trans hb₂⟩ } @[simp, norm_cast] theorem coe_inf : ∀ s t : Interval α, (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t | ⊥, _ => by rw [bot_inf_eq] exact (empty_inter _).symm | (s : NonemptyInterval α), ⊥ => by rw [inf_bot_eq] exact (inter_empty _).symm | (s : NonemptyInterval α), (t : NonemptyInterval α) => by simp only [Min.min, coe_coe, NonemptyInterval.coe_def, Icc_inter_Icc, SemilatticeInf.inf, Lattice.inf] split_ifs with h · simp only [coe_coe, NonemptyInterval.coe_def] · refine (Icc_eq_empty <| mt ?_ h).symm exact fun h ↦ ⟨le_sup_left.trans <| h.trans inf_le_right, le_sup_right.trans <| h.trans inf_le_left⟩ end Decidable @[simp, norm_cast] theorem disjoint_coe (s t : Interval α) : Disjoint (s : Set α) t ↔ Disjoint s t := by classical rw [disjoint_iff_inf_le, disjoint_iff_inf_le, ← coe_subset_coe, coe_inf] rfl end Lattice end Interval namespace NonemptyInterval section Preorder variable [Preorder α] {s : NonemptyInterval α} {a : α} @[simp, norm_cast] theorem coe_pure_interval (a : α) : (pure a : Interval α) = Interval.pure a := rfl @[simp, norm_cast] theorem coe_eq_pure : (s : Interval α) = Interval.pure a ↔ s = pure a := by rw [← Interval.coe_inj, coe_pure_interval] @[simp, norm_cast] theorem coe_top_interval [BoundedOrder α] : ((⊤ : NonemptyInterval α) : Interval α) = ⊤ := rfl end Preorder @[simp, norm_cast] theorem mem_coe_interval [PartialOrder α] {s : NonemptyInterval α} {x : α} : x ∈ (s : Interval α) ↔ x ∈ s := Iff.rfl @[simp, norm_cast] theorem coe_sup_interval [Lattice α] (s t : NonemptyInterval α) : (↑(s ⊔ t) : Interval α) = ↑s ⊔ ↑t := rfl end NonemptyInterval namespace Interval section CompleteLattice variable [CompleteLattice α] noncomputable instance completeLattice [DecidableLE α] : CompleteLattice (Interval α) := by classical exact { Interval.lattice, Interval.boundedOrder with sSup := fun S => if h : S ⊆ {⊥} then ⊥ else WithBot.some ⟨⟨⨅ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.fst, ⨆ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.snd⟩, by obtain ⟨s, hs, ha⟩ := not_subset.1 h lift s to NonemptyInterval α using ha exact iInf₂_le_of_le s hs (le_iSup₂_of_le s hs s.fst_le_snd)⟩ le_sSup := fun s s ha => by split_ifs with h · exact (h ha).le cases s · exact bot_le · -- Porting note: This case was -- `exact WithBot.some_le_some.2 ⟨iInf₂_le _ ha, le_iSup₂_of_le _ ha le_rfl⟩` -- but there seems to be a defEq-problem at `iInf₂_le` that lean cannot resolve yet. apply WithBot.coe_le_coe.2 constructor · apply iInf₂_le exact ha · exact le_iSup₂_of_le _ ha le_rfl sSup_le := fun s s ha => by split_ifs with h · exact bot_le obtain ⟨b, hs, hb⟩ := not_subset.1 h lift s to NonemptyInterval α using ne_bot_of_le_ne_bot hb (ha _ hs) exact WithBot.coe_le_coe.2 ⟨le_iInf₂ fun c hc => (WithBot.coe_le_coe.1 <| ha _ hc).1, iSup₂_le fun c hc => (WithBot.coe_le_coe.1 <| ha _ hc).2⟩ sInf := fun S => if h : ⊥ ∉ S ∧ ∀ ⦃s : NonemptyInterval α⦄, ↑s ∈ S → ∀ ⦃t : NonemptyInterval α⦄, ↑t ∈ S → s.fst ≤ t.snd then WithBot.some ⟨⟨⨆ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.fst, ⨅ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.snd⟩, iSup₂_le fun s hs => le_iInf₂ <| h.2 hs⟩ else ⊥ sInf_le := fun s₁ s ha => by split_ifs with h · lift s to NonemptyInterval α using ne_of_mem_of_not_mem ha h.1 -- Porting note: Lean failed to figure out the function `f` by itself, -- so I added it through manually let f := fun (s : NonemptyInterval α) (_ : ↑s ∈ s₁) => s.toProd.fst exact WithBot.coe_le_coe.2 ⟨le_iSup₂ (f := f) s ha, iInf₂_le s ha⟩ · exact bot_le le_sInf := by intro S s ha cases s with | bot => exact bot_le | coe s => split_ifs with h · exact WithBot.coe_le_coe.2 ⟨iSup₂_le fun t hb => (WithBot.coe_le_coe.1 <| ha _ hb).1, le_iInf₂ fun t hb => (WithBot.coe_le_coe.1 <| ha _ hb).2⟩ · rw [not_and_or, not_not] at h rcases h with h | h · exact ha _ h · -- Porting note: ungolfed, due to identification problems -- between `toProd` and `toDualProd`. Original mathport output: -- cases h fun t hb c hc => -- (WithBot.coe_le_coe.1 <| ha _ hb).1.trans <| -- s.fst_le_snd.trans (WithBot.coe_le_coe.1 <| ha _ hc).2 } exfalso apply h intro b hb c hc have h₁ := (WithBot.coe_le_coe.1 <| ha _ hb).1 repeat rw [NonemptyInterval.toDualProd_apply] at h₁ rw [OrderDual.toDual_le_toDual] at h₁ exact h₁.trans (s.fst_le_snd.trans (WithBot.coe_le_coe.1 <| ha _ hc).2) } @[simp, norm_cast] theorem coe_sInf [DecidableLE α] (S : Set (Interval α)) : ↑(sInf S) = ⋂ s ∈ S, (s : Set α) := by classical change ((dite _ _ _ : Interval α) : Set α) = ⋂ (s : Interval α) (_ : s ∈ S), (s : Set α) split_ifs with h · ext simp [Interval.forall, h.1, ← forall_and, ← NonemptyInterval.mem_def] simp_rw [not_and_or, Classical.not_not] at h rcases h with h | h · refine (eq_empty_of_subset_empty ?_).symm exact iInter₂_subset_of_subset _ h Subset.rfl · refine (not_nonempty_iff_eq_empty.1 ?_).symm rintro ⟨x, hx⟩ rw [mem_iInter₂] at hx exact h fun s ha t hb => (hx _ ha).1.trans (hx _ hb).2 @[simp, norm_cast] theorem coe_iInf [DecidableLE α] (f : ι → Interval α) : ↑(⨅ i, f i) = ⋂ i, (f i : Set α) := by simp [iInf] @[norm_cast] theorem coe_iInf₂ [DecidableLE α] (f : ∀ i, κ i → Interval α) : ↑(⨅ (i) (j), f i j) = ⋂ (i) (j), (f i j : Set α) := by simp_rw [coe_iInf] end CompleteLattice end Interval
.lake/packages/mathlib/Mathlib/Order/Interval/Multiset.lean
import Mathlib.Order.Interval.Finset.Basic /-! # Intervals as multisets This file defines intervals as multisets. ## Main declarations In a `LocallyFiniteOrder`, * `Multiset.Icc`: Closed-closed interval as a multiset. * `Multiset.Ico`: Closed-open interval as a multiset. * `Multiset.Ioc`: Open-closed interval as a multiset. * `Multiset.Ioo`: Open-open interval as a multiset. In a `LocallyFiniteOrderTop`, * `Multiset.Ici`: Closed-infinite interval as a multiset. * `Multiset.Ioi`: Open-infinite interval as a multiset. In a `LocallyFiniteOrderBot`, * `Multiset.Iic`: Infinite-open interval as a multiset. * `Multiset.Iio`: Infinite-closed interval as a multiset. ## TODO Do we really need this file at all? (March 2024) -/ variable {α : Type*} namespace Multiset section LocallyFiniteOrder variable [Preorder α] [LocallyFiniteOrder α] {a b x : α} /-- The multiset of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a multiset. -/ def Icc (a b : α) : Multiset α := (Finset.Icc a b).val /-- The multiset of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a multiset. -/ def Ico (a b : α) : Multiset α := (Finset.Ico a b).val /-- The multiset of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a multiset. -/ def Ioc (a b : α) : Multiset α := (Finset.Ioc a b).val /-- The multiset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a multiset. -/ def Ioo (a b : α) : Multiset α := (Finset.Ioo a b).val @[simp] lemma mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := by rw [Icc, ← Finset.mem_def, Finset.mem_Icc] @[simp] lemma mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := by rw [Ico, ← Finset.mem_def, Finset.mem_Ico] @[simp] lemma mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := by rw [Ioc, ← Finset.mem_def, Finset.mem_Ioc] @[simp] lemma mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := by rw [Ioo, ← Finset.mem_def, Finset.mem_Ioo] end LocallyFiniteOrder section LocallyFiniteOrderTop variable [Preorder α] [LocallyFiniteOrderTop α] {a x : α} /-- The multiset of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a multiset. -/ def Ici (a : α) : Multiset α := (Finset.Ici a).val /-- The multiset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a multiset. -/ def Ioi (a : α) : Multiset α := (Finset.Ioi a).val @[simp] lemma mem_Ici : x ∈ Ici a ↔ a ≤ x := by rw [Ici, ← Finset.mem_def, Finset.mem_Ici] @[simp] lemma mem_Ioi : x ∈ Ioi a ↔ a < x := by rw [Ioi, ← Finset.mem_def, Finset.mem_Ioi] end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [Preorder α] [LocallyFiniteOrderBot α] {b x : α} /-- The multiset of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a multiset. -/ def Iic (b : α) : Multiset α := (Finset.Iic b).val /-- The multiset of elements `x` such that `x < b`. Basically `Set.Iio b` as a multiset. -/ def Iio (b : α) : Multiset α := (Finset.Iio b).val @[simp] lemma mem_Iic : x ∈ Iic b ↔ x ≤ b := by rw [Iic, ← Finset.mem_def, Finset.mem_Iic] @[simp] lemma mem_Iio : x ∈ Iio b ↔ x < b := by rw [Iio, ← Finset.mem_def, Finset.mem_Iio] end LocallyFiniteOrderBot section Preorder variable [Preorder α] [LocallyFiniteOrder α] {a b c : α} theorem nodup_Icc : (Icc a b).Nodup := Finset.nodup _ theorem nodup_Ico : (Ico a b).Nodup := Finset.nodup _ theorem nodup_Ioc : (Ioc a b).Nodup := Finset.nodup _ theorem nodup_Ioo : (Ioo a b).Nodup := Finset.nodup _ @[simp] theorem Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b := by rw [Icc, Finset.val_eq_zero, Finset.Icc_eq_empty_iff] @[simp] theorem Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b := by rw [Ico, Finset.val_eq_zero, Finset.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b := by rw [Ioc, Finset.val_eq_zero, Finset.Ioc_eq_empty_iff] @[simp] theorem Ioo_eq_zero_iff [DenselyOrdered α] : Ioo a b = 0 ↔ ¬a < b := by rw [Ioo, Finset.val_eq_zero, Finset.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_zero⟩ := Icc_eq_zero_iff alias ⟨_, Ico_eq_zero⟩ := Ico_eq_zero_iff alias ⟨_, Ioc_eq_zero⟩ := Ioc_eq_zero_iff @[simp] theorem Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 := eq_zero_iff_forall_notMem.2 fun _x hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 := Icc_eq_zero h.not_ge @[simp] theorem Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 := Ico_eq_zero h.not_gt @[simp] theorem Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 := Ioc_eq_zero h.not_gt @[simp] theorem Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 := Ioo_eq_zero h.not_gt variable (a) theorem Ico_self : Ico a a = 0 := by rw [Ico, Finset.Ico_self, Finset.empty_val] theorem Ioc_self : Ioc a a = 0 := by rw [Ioc, Finset.Ioc_self, Finset.empty_val] theorem Ioo_self : Ioo a a = 0 := by rw [Ioo, Finset.Ioo_self, Finset.empty_val] variable {a} theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := Finset.left_mem_Icc theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := Finset.left_mem_Ico theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := Finset.right_mem_Icc theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := Finset.right_mem_Ioc theorem left_notMem_Ioc : a ∉ Ioc a b := Finset.left_notMem_Ioc @[deprecated (since := "2025-05-23")] alias left_not_mem_Ioc := left_notMem_Ioc theorem left_notMem_Ioo : a ∉ Ioo a b := Finset.left_notMem_Ioo @[deprecated (since := "2025-05-23")] alias left_not_mem_Ioo := left_notMem_Ioo theorem right_notMem_Ico : b ∉ Ico a b := Finset.right_notMem_Ico @[deprecated (since := "2025-05-23")] alias right_not_mem_Ico := right_notMem_Ico theorem right_notMem_Ioo : b ∉ Ioo a b := Finset.right_notMem_Ioo @[deprecated (since := "2025-05-23")] alias right_not_mem_Ioo := right_notMem_Ioo theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : ((Ico a b).filter fun x => x < c) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_left hca] rfl theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : ((Ico a b).filter fun x => x < c) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_right_le hbc] theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : ((Ico a b).filter fun x => x < c) = Ico a c := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_right hcb] rfl theorem Ico_filter_le_of_le_left [DecidablePred (c ≤ ·)] (hca : c ≤ a) : ((Ico a b).filter fun x => c ≤ x) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_le_left hca] theorem Ico_filter_le_of_right_le [DecidablePred (b ≤ ·)] : ((Ico a b).filter fun x => b ≤ x) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_right_le] rfl theorem Ico_filter_le_of_left_le [DecidablePred (c ≤ ·)] (hac : a ≤ c) : ((Ico a b).filter fun x => c ≤ x) = Ico c b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_left_le hac] rfl end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [Icc, Finset.Icc_self, Finset.singleton_val] theorem Ico_cons_right (h : a ≤ b) : b ::ₘ Ico a b = Icc a b := by classical rw [Ico, ← Finset.insert_val_of_notMem right_notMem_Ico, Finset.Ico_insert_right h] rfl theorem Ioo_cons_left (h : a < b) : a ::ₘ Ioo a b = Ico a b := by classical rw [Ioo, ← Finset.insert_val_of_notMem left_notMem_Ioo, Finset.Ioo_insert_left h] rfl theorem Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : Disjoint (Ico a b) (Ico c d) := disjoint_left.mpr fun hab hbc => by rw [mem_Ico] at hab hbc exact hab.2.not_ge (h.trans hbc.1) @[simp] theorem Ico_inter_Ico_of_le [DecidableEq α] {a b c d : α} (h : b ≤ c) : Ico a b ∩ Ico c d = 0 := Multiset.inter_eq_zero_iff_disjoint.2 <| Ico_disjoint_Ico h theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : ((Ico a b).filter fun x => x ≤ a) = {a} := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_left hab] rfl theorem card_Ico_eq_card_Icc_sub_one (a b : α) : card (Ico a b) = card (Icc a b) - 1 := Finset.card_Ico_eq_card_Icc_sub_one _ _ theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : card (Ioc a b) = card (Icc a b) - 1 := Finset.card_Ioc_eq_card_Icc_sub_one _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : card (Ioo a b) = card (Ico a b) - 1 := Finset.card_Ioo_eq_card_Ico_sub_one _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : card (Ioo a b) = card (Icc a b) - 2 := Finset.card_Ioo_eq_card_Icc_sub_two _ _ end PartialOrder section LinearOrder variable [LinearOrder α] [LocallyFiniteOrder α] {a b c d : α} theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := Finset.Ico_subset_Ico_iff h theorem Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b + Ico b c = Ico a c := by rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ← Finset.union_val, Finset.Ico_union_Ico_eq_Ico hab hbc] theorem Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [Ico, Ico, Ico, ← Finset.inter_val, Finset.Ico_inter_Ico] @[simp] theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_lt] @[simp] theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_le] @[simp] theorem Ico_sub_Ico_left (a b c : α) : Ico a b - Ico a c = Ico (max a c) b := by rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_left] @[simp] theorem Ico_sub_Ico_right (a b c : α) : Ico a b - Ico c b = Ico a (min b c) := by rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_right] end LinearOrder end Multiset
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/DenselyOrdered.lean
import Mathlib.Order.Interval.Finset.Basic /-! # Linear locally finite orders are densely ordered iff they are trivial ## Main results * `LocallyFiniteOrder.denselyOrdered_iff_subsingleton`: A linear locally finite order is densely ordered if and only if it is a subsingleton. -/ variable {X : Type*} [LinearOrder X] [LocallyFiniteOrder X] lemma LocallyFiniteOrder.denselyOrdered_iff_subsingleton : DenselyOrdered X ↔ Subsingleton X := by refine ⟨fun H ↦ ?_, fun h ↦ h.instDenselyOrdered⟩ rw [← not_nontrivial_iff_subsingleton, nontrivial_iff_lt] rintro ⟨a, b, hab⟩ exact not_lt_of_denselyOrdered_of_locallyFinite a b hab lemma denselyOrdered_set_iff_subsingleton {s : Set X} : DenselyOrdered s ↔ s.Subsingleton := by classical simp [LocallyFiniteOrder.denselyOrdered_iff_subsingleton] lemma WithBot.denselyOrdered_set_iff_subsingleton {s : Set (WithBot X)} : DenselyOrdered s ↔ s.Subsingleton := by refine ⟨fun H ↦ ?_, fun h ↦ h.denselyOrdered⟩ rw [← Set.subsingleton_coe, ← not_nontrivial_iff_subsingleton, nontrivial_iff_lt] suffices DenselyOrdered (WithBot.some ⁻¹' s) by rintro ⟨x, y, H⟩ rw [_root_.denselyOrdered_set_iff_subsingleton] at this obtain ⟨z, hz, hz'⟩ := exists_between H have hz0 : (⊥ : WithBot X) < z := by simp [(Subtype.coe_lt_coe.mpr hz).trans_le'] replace hz' : WithBot.unbot z.val hz0.ne' < WithBot.unbot y (hz0.trans hz').ne' := by rwa [← WithBot.coe_lt_coe, WithBot.coe_unbot, WithBot.coe_unbot] refine absurd (this ?_ ?_) hz'.ne <;> simp constructor simp only [Subtype.exists, Set.mem_preimage, Subtype.forall, Subtype.mk_lt_mk, exists_and_right, exists_prop] intro x hx y hy hxy have : (⟨_, hx⟩ : s) < ⟨_, hy⟩ := by simp [hxy] obtain ⟨z, hz, hz'⟩ := exists_between this simp only [← Subtype.coe_lt_coe] at hz hz' refine ⟨WithBot.unbot z (hz.trans_le' (by simp)).ne', ⟨?_, ?_⟩, ?_⟩ · simp · rw [← WithBot.coe_lt_coe] simp [hz.trans_le] · rw [← WithBot.coe_lt_coe] simp [hz'.trans_le'] lemma WithTop.denselyOrdered_set_iff_subsingleton {s : Set (WithTop X)} : DenselyOrdered s ↔ s.Subsingleton := by have he : StrictAnti (WithTop.toDual.image s) := WithTop.toDual.image_strictAnti _ (fun ⦃a b⦄ a ↦ a) rw [denselyOrdered_iff_of_strictAnti _ he, WithBot.denselyOrdered_set_iff_subsingleton, WithTop.toDual.injective.subsingleton_image_iff]
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/Fin.lean
import Mathlib.Data.Finset.Fin import Mathlib.Order.Interval.Finset.Nat import Mathlib.Order.Interval.Set.Fin /-! # Finite intervals in `Fin n` This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as Finsets and Fintypes. -/ assert_not_exists MonoidWithZero open Finset Function namespace Fin variable (n : ℕ) /-! ### Locally finite order etc. instances -/ instance instLocallyFiniteOrder (n : ℕ) : LocallyFiniteOrder (Fin n) where finsetIcc a b := attachFin (Icc a b) fun x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2 finsetIco a b := attachFin (Ico a b) fun x hx ↦ (mem_Ico.mp hx).2.trans b.2 finsetIoc a b := attachFin (Ioc a b) fun x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2 finsetIoo a b := attachFin (Ioo a b) fun x hx ↦ (mem_Ioo.mp hx).2.trans b.2 finset_mem_Icc a b := by simp finset_mem_Ico a b := by simp finset_mem_Ioc a b := by simp finset_mem_Ioo a b := by simp instance instLocallyFiniteOrderBot : ∀ n, LocallyFiniteOrderBot (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderBot | _ + 1 => inferInstance instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderTop | _ + 1 => inferInstance variable {n} variable {m : ℕ} (a b : Fin n) @[simp] theorem attachFin_Icc : attachFin (Icc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2) = Icc a b := rfl @[simp] theorem attachFin_Ico : attachFin (Ico a b) (fun _x hx ↦ (mem_Ico.mp hx).2.trans b.2) = Ico a b := rfl @[simp] theorem attachFin_Ioc : attachFin (Ioc a b) (fun _x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2) = Ioc a b := rfl @[simp] theorem attachFin_Ioo : attachFin (Ioo a b) (fun _x hx ↦ (mem_Ioo.mp hx).2.trans b.2) = Ioo a b := rfl @[simp] theorem attachFin_uIcc : attachFin (uIcc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt (max a b).2) = uIcc a b := rfl @[simp] theorem attachFin_Ico_eq_Ici : attachFin (Ico a n) (fun _x hx ↦ (mem_Ico.mp hx).2) = Ici a := by ext; simp @[simp] theorem attachFin_Ioo_eq_Ioi : attachFin (Ioo a n) (fun _x hx ↦ (mem_Ioo.mp hx).2) = Ioi a := by ext; simp @[simp] theorem attachFin_Iic : attachFin (Iic a) (fun _x hx ↦ (mem_Iic.mp hx).trans_lt a.2) = Iic a := by ext; simp @[simp] theorem attachFin_Iio : attachFin (Iio a) (fun _x hx ↦ (mem_Iio.mp hx).trans a.2) = Iio a := by ext; simp section deprecated end deprecated section val /-! ### Images under `Fin.val` -/ @[simp] theorem finsetImage_val_Icc : (Icc a b).image val = Icc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ico : (Ico a b).image val = Ico (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioc : (Ioc a b).image val = Ioc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioo : (Ioo a b).image val = Ioo (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_uIcc : (uIcc a b).image val = uIcc (a : ℕ) b := finsetImage_val_Icc _ _ @[simp] theorem finsetImage_val_Ici : (Ici a).image val = Ico (a : ℕ) n := by simp [← coe_inj] @[simp] theorem finsetImage_val_Ioi : (Ioi a).image val = Ioo (a : ℕ) n := by simp [← coe_inj] @[simp] theorem finsetImage_val_Iic : (Iic a).image val = Iic (a : ℕ) := by simp [← coe_inj] @[simp] theorem finsetImage_val_Iio : (Iio b).image val = Iio (b : ℕ) := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.valEmbedding` -/ @[simp] theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_uIcc : (uIcc a b).map valEmbedding = uIcc (a : ℕ) b := map_valEmbedding_Icc _ _ @[simp] theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Ico (a : ℕ) n := by rw [← attachFin_Ico_eq_Ici, map_valEmbedding_attachFin] @[simp] theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioo (a : ℕ) n := by rw [← attachFin_Ioo_eq_Ioi, map_valEmbedding_attachFin] @[simp] theorem map_valEmbedding_Iic : (Iic a).map Fin.valEmbedding = Iic (a : ℕ) := by rw [← attachFin_Iic, map_valEmbedding_attachFin] @[simp] theorem map_valEmbedding_Iio : (Iio a).map Fin.valEmbedding = Iio (a : ℕ) := by rw [← attachFin_Iio, map_valEmbedding_attachFin] end val section castLE /-! ### Image under `Fin.castLE` -/ @[simp] theorem finsetImage_castLE_Icc (h : n ≤ m) : (Icc a b).image (castLE h) = Icc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_Ico (h : n ≤ m) : (Ico a b).image (castLE h) = Ico (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_Ioc (h : n ≤ m) : (Ioc a b).image (castLE h) = Ioc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_Ioo (h : n ≤ m) : (Ioo a b).image (castLE h) = Ioo (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_uIcc (h : n ≤ m) : (uIcc a b).image (castLE h) = uIcc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_Iic (h : n ≤ m) : (Iic a).image (castLE h) = Iic (castLE h a) := by simp [← coe_inj] @[simp] theorem finsetImage_castLE_Iio (h : n ≤ m) : (Iio a).image (castLE h) = Iio (castLE h a) := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.castLEEmb` -/ @[simp] theorem map_castLEEmb_Icc (h : n ≤ m) : (Icc a b).map (castLEEmb h) = Icc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_Ico (h : n ≤ m) : (Ico a b).map (castLEEmb h) = Ico (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_Ioc (h : n ≤ m) : (Ioc a b).map (castLEEmb h) = Ioc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_Ioo (h : n ≤ m) : (Ioo a b).map (castLEEmb h) = Ioo (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_uIcc (h : n ≤ m) : (uIcc a b).map (castLEEmb h) = uIcc (castLE h a) (castLE h b) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_Iic (h : n ≤ m) : (Iic a).map (castLEEmb h) = Iic (castLE h a) := by simp [← coe_inj] @[simp] theorem map_castLEEmb_Iio (h : n ≤ m) : (Iio a).map (castLEEmb h) = Iio (castLE h a) := by simp [← coe_inj] end castLE section castAdd /-! ### Images under `Fin.castAdd` -/ @[simp] theorem finsetImage_castAdd_Icc (m) (i j : Fin n) : (Icc i j).image (castAdd m) = Icc (castAdd m i) (castAdd m j) := finsetImage_castLE_Icc .. @[simp] theorem finsetImage_castAdd_Ico (m) (i j : Fin n) : (Ico i j).image (castAdd m) = Ico (castAdd m i) (castAdd m j) := finsetImage_castLE_Ico .. @[simp] theorem finsetImage_castAdd_Ioc (m) (i j : Fin n) : (Ioc i j).image (castAdd m) = Ioc (castAdd m i) (castAdd m j) := finsetImage_castLE_Ioc .. @[simp] theorem finsetImage_castAdd_Ioo (m) (i j : Fin n) : (Ioo i j).image (castAdd m) = Ioo (castAdd m i) (castAdd m j) := finsetImage_castLE_Ioo .. @[simp] theorem finsetImage_castAdd_uIcc (m) (i j : Fin n) : (uIcc i j).image (castAdd m) = uIcc (castAdd m i) (castAdd m j) := finsetImage_castLE_uIcc .. @[simp] theorem finsetImage_castAdd_Ici (m) [NeZero m] (i : Fin n) : (Ici i).image (castAdd m) = Ico (castAdd m i) (natAdd n 0) := by simp [← coe_inj] @[simp] theorem finsetImage_castAdd_Ioi (m) [NeZero m] (i : Fin n) : (Ioi i).image (castAdd m) = Ioo (castAdd m i) (natAdd n 0) := by simp [← coe_inj] @[simp] theorem finsetImage_castAdd_Iic (m) (i : Fin n) : (Iic i).image (castAdd m) = Iic (castAdd m i) := finsetImage_castLE_Iic i _ @[simp] theorem finsetImage_castAdd_Iio (m) (i : Fin n) : (Iio i).image (castAdd m) = Iio (castAdd m i) := finsetImage_castLE_Iio .. /-! ### `Finset.map` along `Fin.castAddEmb` -/ @[simp] theorem map_castAddEmb_Icc (m) (i j : Fin n) : (Icc i j).map (castAddEmb m) = Icc (castAdd m i) (castAdd m j) := map_castLEEmb_Icc .. @[simp] theorem map_castAddEmb_Ico (m) (i j : Fin n) : (Ico i j).map (castAddEmb m) = Ico (castAdd m i) (castAdd m j) := map_castLEEmb_Ico .. @[simp] theorem map_castAddEmb_Ioc (m) (i j : Fin n) : (Ioc i j).map (castAddEmb m) = Ioc (castAdd m i) (castAdd m j) := map_castLEEmb_Ioc .. @[simp] theorem map_castAddEmb_Ioo (m) (i j : Fin n) : (Ioo i j).map (castAddEmb m) = Ioo (castAdd m i) (castAdd m j) := map_castLEEmb_Ioo .. @[simp] theorem map_castAddEmb_uIcc (m) (i j : Fin n) : (uIcc i j).map (castAddEmb m) = uIcc (castAdd m i) (castAdd m j) := map_castLEEmb_uIcc .. @[simp] theorem map_castAddEmb_Ici (m) [NeZero m] (i : Fin n) : (Ici i).map (castAddEmb m) = Ico (castAdd m i) (natAdd n 0) := by simp [map_eq_image] @[simp] theorem map_castAddEmb_Ioi (m) [NeZero m] (i : Fin n) : (Ioi i).map (castAddEmb m) = Ioo (castAdd m i) (natAdd n 0) := by simp [← coe_inj] @[simp] theorem map_castAddEmb_Iic (m) (i : Fin n) : (Iic i).map (castAddEmb m) = Iic (castAdd m i) := map_castLEEmb_Iic i _ @[simp] theorem map_castAddEmb_Iio (m) (i : Fin n) : (Iio i).map (castAddEmb m) = Iio (castAdd m i) := map_castLEEmb_Iio .. end castAdd section cast /-! ### Images under `Fin.cast` -/ @[simp] theorem finsetImage_cast_Icc (h : n = m) (i j : Fin n) : (Icc i j).image (.cast h) = Icc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Ico (h : n = m) (i j : Fin n) : (Ico i j).image (.cast h) = Ico (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Ioc (h : n = m) (i j : Fin n) : (Ioc i j).image (.cast h) = Ioc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Ioo (h : n = m) (i j : Fin n) : (Ioo i j).image (.cast h) = Ioo (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_uIcc (h : n = m) (i j : Fin n) : (uIcc i j).image (.cast h) = uIcc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Ici (h : n = m) (i : Fin n) : (Ici i).image (.cast h) = Ici (i.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Ioi (h : n = m) (i : Fin n) : (Ioi i).image (.cast h) = Ioi (i.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Iic (h : n = m) (i : Fin n) : (Iic i).image (.cast h) = Iic (i.cast h) := by simp [← coe_inj] @[simp] theorem finsetImage_cast_Iio (h : n = m) (i : Fin n) : (Iio i).image (.cast h) = Iio (i.cast h) := by simp [← coe_inj] /-! ### `Finset.map` along `finCongr` -/ @[simp] theorem map_finCongr_Icc (h : n = m) (i j : Fin n) : (Icc i j).map (finCongr h).toEmbedding = Icc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Ico (h : n = m) (i j : Fin n) : (Ico i j).map (finCongr h).toEmbedding = Ico (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Ioc (h : n = m) (i j : Fin n) : (Ioc i j).map (finCongr h).toEmbedding = Ioc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Ioo (h : n = m) (i j : Fin n) : (Ioo i j).map (finCongr h).toEmbedding = Ioo (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_uIcc (h : n = m) (i j : Fin n) : (uIcc i j).map (finCongr h).toEmbedding = uIcc (i.cast h) (j.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Ici (h : n = m) (i : Fin n) : (Ici i).map (finCongr h).toEmbedding = Ici (i.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Ioi (h : n = m) (i : Fin n) : (Ioi i).map (finCongr h).toEmbedding = Ioi (i.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Iic (h : n = m) (i : Fin n) : (Iic i).map (finCongr h).toEmbedding = Iic (i.cast h) := by simp [← coe_inj] @[simp] theorem map_finCongr_Iio (h : n = m) (i : Fin n) : (Iio i).map (finCongr h).toEmbedding = Iio (i.cast h) := by simp [← coe_inj] end cast section castSucc /-! ### Images under `Fin.castSucc` -/ @[simp] theorem finsetImage_castSucc_Icc (i j : Fin n) : (Icc i j).image castSucc = Icc i.castSucc j.castSucc := finsetImage_castAdd_Icc .. @[simp] theorem finsetImage_castSucc_Ico (i j : Fin n) : (Ico i j).image castSucc = Ico i.castSucc j.castSucc := finsetImage_castAdd_Ico .. @[simp] theorem finsetImage_castSucc_Ioc (i j : Fin n) : (Ioc i j).image castSucc = Ioc i.castSucc j.castSucc := finsetImage_castAdd_Ioc .. @[simp] theorem finsetImage_castSucc_Ioo (i j : Fin n) : (Ioo i j).image castSucc = Ioo i.castSucc j.castSucc := finsetImage_castAdd_Ioo .. @[simp] theorem finsetImage_castSucc_uIcc (i j : Fin n) : (uIcc i j).image castSucc = uIcc i.castSucc j.castSucc := finsetImage_castAdd_uIcc .. @[simp] theorem finsetImage_castSucc_Ici (i : Fin n) : (Ici i).image castSucc = Ico i.castSucc (.last n) := finsetImage_castAdd_Ici .. @[simp] theorem finsetImage_castSucc_Ioi (i : Fin n) : (Ioi i).image castSucc = Ioo i.castSucc (.last n) := finsetImage_castAdd_Ioi .. @[simp] theorem finsetImage_castSucc_Iic (i : Fin n) : (Iic i).image castSucc = Iic i.castSucc := finsetImage_castAdd_Iic .. @[simp] theorem finsetImage_castSucc_Iio (i : Fin n) : (Iio i).image castSucc = Iio i.castSucc := finsetImage_castAdd_Iio .. /-! ### `Finset.map` along `Fin.castSuccEmb` -/ @[simp] theorem map_castSuccEmb_Icc (i j : Fin n) : (Icc i j).map castSuccEmb = Icc i.castSucc j.castSucc := map_castAddEmb_Icc .. @[simp] theorem map_castSuccEmb_Ico (i j : Fin n) : (Ico i j).map castSuccEmb = Ico i.castSucc j.castSucc := map_castAddEmb_Ico .. @[simp] theorem map_castSuccEmb_Ioc (i j : Fin n) : (Ioc i j).map castSuccEmb = Ioc i.castSucc j.castSucc := map_castAddEmb_Ioc .. @[simp] theorem map_castSuccEmb_Ioo (i j : Fin n) : (Ioo i j).map castSuccEmb = Ioo i.castSucc j.castSucc := map_castAddEmb_Ioo .. @[simp] theorem map_castSuccEmb_uIcc (i j : Fin n) : (uIcc i j).map castSuccEmb = uIcc i.castSucc j.castSucc := map_castAddEmb_uIcc .. @[simp] theorem map_castSuccEmb_Ici (i : Fin n) : (Ici i).map castSuccEmb = Ico i.castSucc (.last n) := map_castAddEmb_Ici .. @[simp] theorem map_castSuccEmb_Ioi (i : Fin n) : (Ioi i).map castSuccEmb = Ioo i.castSucc (.last n) := map_castAddEmb_Ioi .. @[simp] theorem map_castSuccEmb_Iic (i : Fin n) : (Iic i).map castSuccEmb = Iic i.castSucc := map_castAddEmb_Iic .. @[simp] theorem map_castSuccEmb_Iio (i : Fin n) : (Iio i).map castSuccEmb = Iio i.castSucc := map_castAddEmb_Iio .. end castSucc section natAdd /-! ### Images under `Fin.natAdd` -/ @[simp] theorem finsetImage_natAdd_Icc (m) (i j : Fin n) : (Icc i j).image (natAdd m) = Icc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_Ico (m) (i j : Fin n) : (Ico i j).image (natAdd m) = Ico (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_Ioc (m) (i j : Fin n) : (Ioc i j).image (natAdd m) = Ioc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_Ioo (m) (i j : Fin n) : (Ioo i j).image (natAdd m) = Ioo (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_uIcc (m) (i j : Fin n) : (uIcc i j).image (natAdd m) = uIcc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_Ici (m) (i : Fin n) : (Ici i).image (natAdd m) = Ici (natAdd m i) := by simp [← coe_inj] @[simp] theorem finsetImage_natAdd_Ioi (m) (i : Fin n) : (Ioi i).image (natAdd m) = Ioi (natAdd m i) := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.natAddEmb` -/ @[simp] theorem map_natAddEmb_Icc (m) (i j : Fin n) : (Icc i j).map (natAddEmb m) = Icc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_Ico (m) (i j : Fin n) : (Ico i j).map (natAddEmb m) = Ico (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_Ioc (m) (i j : Fin n) : (Ioc i j).map (natAddEmb m) = Ioc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_Ioo (m) (i j : Fin n) : (Ioo i j).map (natAddEmb m) = Ioo (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_uIcc (m) (i j : Fin n) : (uIcc i j).map (natAddEmb m) = uIcc (natAdd m i) (natAdd m j) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_Ici (m) (i : Fin n) : (Ici i).map (natAddEmb m) = Ici (natAdd m i) := by simp [← coe_inj] @[simp] theorem map_natAddEmb_Ioi (m) (i : Fin n) : (Ioi i).map (natAddEmb m) = Ioi (natAdd m i) := by simp [← coe_inj] end natAdd section addNat /-! ### Images under `Fin.addNat` -/ @[simp] theorem finsetImage_addNat_Icc (m) (i j : Fin n) : (Icc i j).image (addNat · m) = Icc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_Ico (m) (i j : Fin n) : (Ico i j).image (addNat · m) = Ico (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_Ioc (m) (i j : Fin n) : (Ioc i j).image (addNat · m) = Ioc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_Ioo (m) (i j : Fin n) : (Ioo i j).image (addNat · m) = Ioo (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_uIcc (m) (i j : Fin n) : (uIcc i j).image (addNat · m) = uIcc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_Ici (m) (i : Fin n) : (Ici i).image (addNat · m) = Ici (i.addNat m) := by simp [← coe_inj] @[simp] theorem finsetImage_addNat_Ioi (m) (i : Fin n) : (Ioi i).image (addNat · m) = Ioi (i.addNat m) := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.addNatEmb` -/ @[simp] theorem map_addNatEmb_Icc (m) (i j : Fin n) : (Icc i j).map (addNatEmb m) = Icc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_Ico (m) (i j : Fin n) : (Ico i j).map (addNatEmb m) = Ico (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_Ioc (m) (i j : Fin n) : (Ioc i j).map (addNatEmb m) = Ioc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_Ioo (m) (i j : Fin n) : (Ioo i j).map (addNatEmb m) = Ioo (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_uIcc (m) (i j : Fin n) : (uIcc i j).map (addNatEmb m) = uIcc (i.addNat m) (j.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_Ici (m) (i : Fin n) : (Ici i).map (addNatEmb m) = Ici (i.addNat m) := by simp [← coe_inj] @[simp] theorem map_addNatEmb_Ioi (m) (i : Fin n) : (Ioi i).map (addNatEmb m) = Ioi (i.addNat m) := by simp [← coe_inj] end addNat section succ /-! ### Images under `Fin.succ` -/ @[simp] theorem finsetImage_succ_Icc (i j : Fin n) : (Icc i j).image succ = Icc i.succ j.succ := finsetImage_addNat_Icc .. @[simp] theorem finsetImage_succ_Ico (i j : Fin n) : (Ico i j).image succ = Ico i.succ j.succ := finsetImage_addNat_Ico .. @[simp] theorem finsetImage_succ_Ioc (i j : Fin n) : (Ioc i j).image succ = Ioc i.succ j.succ := finsetImage_addNat_Ioc .. @[simp] theorem finsetImage_succ_Ioo (i j : Fin n) : (Ioo i j).image succ = Ioo i.succ j.succ := finsetImage_addNat_Ioo .. @[simp] theorem finsetImage_succ_uIcc (i j : Fin n) : (uIcc i j).image succ = uIcc i.succ j.succ := finsetImage_addNat_uIcc .. @[simp] theorem finsetImage_succ_Ici (i : Fin n) : (Ici i).image succ = Ici i.succ := finsetImage_addNat_Ici .. @[simp] theorem finsetImage_succ_Ioi (i : Fin n) : (Ioi i).image succ = Ioi i.succ := finsetImage_addNat_Ioi .. @[simp] theorem finsetImage_succ_Iic (i : Fin n) : (Iic i).image succ = Ioc 0 i.succ := by simp [← coe_inj] @[simp] theorem finsetImage_succ_Iio (i : Fin n) : (Iio i).image succ = Ioo 0 i.succ := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.succEmb` -/ @[simp] theorem map_succEmb_Icc (i j : Fin n) : (Icc i j).map (succEmb n) = Icc i.succ j.succ := map_addNatEmb_Icc .. @[simp] theorem map_succEmb_Ico (i j : Fin n) : (Ico i j).map (succEmb n) = Ico i.succ j.succ := map_addNatEmb_Ico .. @[simp] theorem map_succEmb_Ioc (i j : Fin n) : (Ioc i j).map (succEmb n) = Ioc i.succ j.succ := map_addNatEmb_Ioc .. @[simp] theorem map_succEmb_Ioo (i j : Fin n) : (Ioo i j).map (succEmb n) = Ioo i.succ j.succ := map_addNatEmb_Ioo .. @[simp] theorem map_succEmb_uIcc (i j : Fin n) : (uIcc i j).map (succEmb n) = uIcc i.succ j.succ := map_addNatEmb_uIcc .. @[simp] theorem map_succEmb_Ici (i : Fin n) : (Ici i).map (succEmb n) = Ici i.succ := map_addNatEmb_Ici .. @[simp] theorem map_succEmb_Ioi (i : Fin n) : (Ioi i).map (succEmb n) = Ioi i.succ := map_addNatEmb_Ioi .. @[simp] theorem map_succEmb_Iic (i : Fin n) : (Iic i).map (succEmb n) = Ioc 0 i.succ := by simp [← coe_inj] @[simp] theorem map_succEmb_Iio (i : Fin n) : (Iio i).map (succEmb n) = Ioo 0 i.succ := by simp [← coe_inj] end succ section rev /-! ### Images under `Fin.rev` -/ @[simp] theorem finsetImage_rev_Icc (i j : Fin n) : (Icc i j).image rev = Icc j.rev i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Ico (i j : Fin n) : (Ico i j).image rev = Ioc j.rev i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Ioc (i j : Fin n) : (Ioc i j).image rev = Ico j.rev i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Ioo (i j : Fin n) : (Ioo i j).image rev = Ioo j.rev i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_uIcc (i j : Fin n) : (uIcc i j).image rev = uIcc i.rev j.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Ici (i : Fin n) : (Ici i).image rev = Iic i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Ioi (i : Fin n) : (Ioi i).image rev = Iio i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Iic (i : Fin n) : (Iic i).image rev = Ici i.rev := by simp [← coe_inj] @[simp] theorem finsetImage_rev_Iio (i : Fin n) : (Iio i).image rev = Ioi i.rev := by simp [← coe_inj] /-! ### `Finset.map` along `revPerm` -/ @[simp] theorem map_revPerm_Icc (i j : Fin n) : (Icc i j).map revPerm.toEmbedding = Icc j.rev i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Ico (i j : Fin n) : (Ico i j).map revPerm.toEmbedding = Ioc j.rev i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Ioc (i j : Fin n) : (Ioc i j).map revPerm.toEmbedding = Ico j.rev i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Ioo (i j : Fin n) : (Ioo i j).map revPerm.toEmbedding = Ioo j.rev i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_uIcc (i j : Fin n) : (uIcc i j).map revPerm.toEmbedding = uIcc i.rev j.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Ici (i : Fin n) : (Ici i).map revPerm.toEmbedding = Iic i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Ioi (i : Fin n) : (Ioi i).map revPerm.toEmbedding = Iio i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Iic (i : Fin n) : (Iic i).map revPerm.toEmbedding = Ici i.rev := by simp [← coe_inj] @[simp] theorem map_revPerm_Iio (i : Fin n) : (Iio i).map revPerm.toEmbedding = Ioi i.rev := by simp [← coe_inj] end rev /-! ### Cardinalities of the intervals -/ section card @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := by rw [← Nat.card_Icc, ← map_valEmbedding_Icc, card_map] @[simp] lemma card_Ico : #(Ico a b) = b - a := by rw [← Nat.card_Ico, ← map_valEmbedding_Ico, card_map] @[simp] lemma card_Ioc : #(Ioc a b) = b - a := by rw [← Nat.card_Ioc, ← map_valEmbedding_Ioc, card_map] @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := by rw [← Nat.card_Ioo, ← map_valEmbedding_Ioo, card_map] @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := by rw [← Nat.card_uIcc, ← map_valEmbedding_uIcc, card_map] @[simp] theorem card_Ici : #(Ici a) = n - a := by rw [← attachFin_Ico_eq_Ici, card_attachFin, Nat.card_Ico] @[simp] theorem card_Ioi : #(Ioi a) = n - 1 - a := by rw [← card_map, map_valEmbedding_Ioi, Nat.card_Ioo, Nat.sub_right_comm] @[simp] theorem card_Iic : #(Iic b) = b + 1 := by rw [← Nat.card_Iic b, ← map_valEmbedding_Iic, card_map] @[simp] theorem card_Iio : #(Iio b) = b := by rw [← Nat.card_Iio b, ← map_valEmbedding_Iio, card_map] end card end Fin
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/SuccPred.lean
import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.Interval.Set.SuccPred /-! # Finset intervals in a successor-predecessor order This file proves relations between the various finset intervals in a successor/predecessor order. ## Notes Please keep in sync with: * `Mathlib/Algebra/Order/Interval/Finset/SuccPred.lean` * `Mathlib/Algebra/Order/Interval/Set/SuccPred.lean` * `Mathlib/Order/Interval/Set/SuccPred.lean` ## TODO Copy over `insert` lemmas from `Mathlib/Order/Interval/Finset/Nat.lean`. -/ assert_not_exists MonoidWithZero open Order namespace Finset variable {α : Type*} [LinearOrder α] /-! ### Two-sided intervals -/ section LocallyFiniteOrder variable [LocallyFiniteOrder α] section SuccOrder variable [SuccOrder α] {a b : α} /-! #### Orders possibly with maximal elements ##### Equalities of intervals -/ lemma Ico_succ_left_eq_Ioo (a b : α) : Ico (succ a) b = Ioo a b := coe_injective <| by simpa using Set.Ico_succ_left_eq_Ioo _ _ lemma Icc_succ_left_eq_Ioc_of_not_isMax (ha : ¬ IsMax a) (b : α) : Icc (succ a) b = Ioc a b := coe_injective <| by simpa using Set.Icc_succ_left_eq_Ioc_of_not_isMax ha _ lemma Ico_succ_right_eq_Icc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico a (succ b) = Icc a b := coe_injective <| by simpa using Set.Ico_succ_right_eq_Icc_of_not_isMax hb _ lemma Ioo_succ_right_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ioo a (succ b) = Ioc a b := coe_injective <| by simpa using Set.Ioo_succ_right_eq_Ioc_of_not_isMax hb _ lemma Ico_succ_succ_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico (succ a) (succ b) = Ioc a b := coe_injective <| by simpa using Set.Ico_succ_succ_eq_Ioc_of_not_isMax hb _ /-! ##### Inserting into intervals -/ lemma insert_Icc_succ_left_eq_Icc (h : a ≤ b) : insert a (Icc (succ a) b) = Icc a b := coe_injective <| by simpa using Set.insert_Icc_succ_left_eq_Icc h lemma insert_Icc_right_eq_Icc_succ (h : a ≤ succ b) : insert (succ b) (Icc a b) = Icc a (succ b) := coe_injective <| by simpa using Set.insert_Icc_right_eq_Icc_succ h lemma insert_Ico_right_eq_Ico_succ_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert b (Ico a b) = Ico a (succ b) := coe_injective <| by simpa using Set.insert_Ico_right_eq_Ico_succ_of_not_isMax h hb lemma insert_Ico_succ_left_eq_Ico (h : a < b) : insert a (Ico (succ a) b) = Ico a b := coe_injective <| by simpa using Set.insert_Ico_succ_left_eq_Ico h lemma insert_Ioc_right_eq_Ioc_succ_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert (succ b) (Ioc a b) = Ioc a (succ b) := coe_injective <| by simpa using Set.insert_Ioc_right_eq_Ioc_succ_of_not_isMax h hb lemma insert_Ioc_succ_left_eq_Ioc (h : a < b) : insert (succ a) (Ioc (succ a) b) = Ioc a b := coe_injective <| by simpa using Set.insert_Ioc_succ_left_eq_Ioc h /-! #### Orders with no maximal elements ##### Equalities of intervals -/ variable [NoMaxOrder α] lemma Icc_succ_left_eq_Ioc (a b : α) : Icc (succ a) b = Ioc a b := coe_injective <| by simp lemma Ico_succ_right_eq_Icc (a b : α) : Ico a (succ b) = Icc a b := coe_injective <| by simp lemma Ioo_succ_right_eq_Ioc (a b : α) : Ioo a (succ b) = Ioc a b := coe_injective <| by simp lemma Ico_succ_succ_eq_Ioc (a b : α) : Ico (succ a) (succ b) = Ioc a b := coe_injective <| by simp /-! ##### Inserting into intervals -/ lemma insert_Ico_right_eq_Ico_succ (h : a ≤ b) : insert b (Ico a b) = Ico a (succ b) := coe_injective <| by simpa using Set.insert_Ico_right_eq_Ico_succ h lemma insert_Ioc_right_eq_Ioc_succ (h : a ≤ b) : insert (succ b) (Ioc a b) = Ioc a (succ b) := coe_injective <| by simpa using Set.insert_Ioc_right_eq_Ioc_succ h end SuccOrder section PredOrder variable [PredOrder α] {a b : α} /-! #### Orders possibly with minimal elements ##### Equalities of intervals -/ lemma Ioc_pred_right_eq_Ioo (a b : α) : Ioc a (pred b) = Ioo a b := coe_injective <| by simpa using Set.Ioc_pred_right_eq_Ioo _ _ lemma Icc_pred_right_eq_Ico_of_not_isMin (hb : ¬ IsMin b) (a : α) : Icc a (pred b) = Ico a b := coe_injective <| by simpa using Set.Icc_pred_right_eq_Ico_of_not_isMin hb _ lemma Ioc_pred_left_eq_Icc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (pred a) b = Icc a b := coe_injective <| by simpa using Set.Ioc_pred_left_eq_Icc_of_not_isMin ha _ lemma Ioo_pred_left_eq_Ioc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioo (pred a) b = Ico a b := coe_injective <| by simpa using Set.Ioo_pred_left_eq_Ioc_of_not_isMin ha _ lemma Ioc_pred_pred_eq_Ico_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (pred a) (pred b) = Ico a b := coe_injective <| by simpa using Set.Ioc_pred_pred_eq_Ico_of_not_isMin ha _ /-! ##### Inserting into intervals -/ lemma insert_Icc_pred_right_eq_Icc (h : a ≤ b) : insert b (Icc a (pred b)) = Icc a b := coe_injective <| by simpa using Set.insert_Icc_pred_right_eq_Icc h lemma insert_Icc_left_eq_Icc_pred (h : pred a ≤ b) : insert (pred a) (Icc a b) = Icc (pred a) b := coe_injective <| by simpa using Set.insert_Icc_left_eq_Icc_pred h lemma insert_Ioc_left_eq_Ioc_pred_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert a (Ioc a b) = Ioc (pred a) b := coe_injective <| by simpa using Set.insert_Ioc_left_eq_Ioc_pred_of_not_isMin h ha lemma insert_Ioc_pred_right_eq_Ioc (h : a < b) : insert b (Ioc a (pred b)) = Ioc a b := coe_injective <| by simpa using Set.insert_Ioc_pred_right_eq_Ioc h lemma insert_Ico_left_eq_Ico_pred_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert (pred a) (Ico a b) = Ico (pred a) b := coe_injective <| by simpa using Set.insert_Ico_left_eq_Ico_pred_of_not_isMin h ha lemma insert_Ico_pred_right_eq_Ico (h : a < b) : insert (pred b) (Ico a (pred b)) = Ico a b := coe_injective <| by simpa using Set.insert_Ico_pred_right_eq_Ico h /-! #### Orders with no minimal elements ##### Equalities of intervals -/ variable [NoMinOrder α] lemma Icc_pred_right_eq_Ico (a b : α) : Icc a (pred b) = Ico a b := coe_injective <| by simp lemma Ioc_pred_left_eq_Icc (a b : α) : Ioc (pred a) b = Icc a b := coe_injective <| by simp lemma Ioo_pred_left_eq_Ioc (a b : α) : Ioo (pred a) b = Ico a b := coe_injective <| by simp lemma Ioc_pred_pred_eq_Ico (a b : α) : Ioc (pred a) (pred b) = Ico a b := coe_injective <| by simp /-! ##### Inserting into intervals -/ lemma insert_Ioc_left_eq_Ioc_pred (h : a ≤ b) : insert a (Ioc a b) = Ioc (pred a) b := coe_injective <| by simpa using Set.insert_Ioc_left_eq_Ioc_pred h lemma insert_Ico_left_eq_Ico_pred (h : a ≤ b) : insert (pred a) (Ico a b) = Ico (pred a) b := insert_Ico_left_eq_Ico_pred_of_not_isMin h (not_isMin _) end PredOrder section SuccPredOrder variable [SuccOrder α] [PredOrder α] [Nontrivial α] lemma Icc_succ_pred_eq_Ioo (a b : α) : Icc (succ a) (pred b) = Ioo a b := coe_injective <| by simpa using Set.Icc_succ_pred_eq_Ioo _ _ end SuccPredOrder end LocallyFiniteOrder /-! ### One-sided interval towards `⊥` -/ section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] section SuccOrder variable [SuccOrder α] {b : α} lemma Iio_succ_eq_Iic_of_not_isMax (hb : ¬ IsMax b) : Iio (succ b) = Iic b := coe_injective <| by simpa using Set.Iio_succ_eq_Iic_of_not_isMax hb variable [NoMaxOrder α] lemma Iio_succ_eq_Iic (b : α) : Iio (succ b) = Iic b := coe_injective <| by simp end SuccOrder section PredOrder variable [PredOrder α] {a b : α} lemma Iic_pred_eq_Iio_of_not_isMin (hb : ¬ IsMin b) : Iic (pred b) = Iio b := coe_injective <| by simpa using Set.Iic_pred_eq_Iio_of_not_isMin hb variable [NoMinOrder α] lemma Iic_pred_eq_Iio (b : α) : Iic (pred b) = Iio b := coe_injective <| by simp end PredOrder end LocallyFiniteOrderBot /-! ### One-sided interval towards `⊤` -/ section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] section SuccOrder variable [SuccOrder α] {a : α} lemma Ici_succ_eq_Ioi_of_not_isMax (ha : ¬ IsMax a) : Ici (succ a) = Ioi a := coe_injective <| by simpa using Set.Ici_succ_eq_Ioi_of_not_isMax ha variable [NoMaxOrder α] lemma Ici_succ_eq_Ioi (a : α) : Ici (succ a) = Ioi a := coe_injective <| by simp end SuccOrder section PredOrder variable [PredOrder α] {a a : α} lemma Ioi_pred_eq_Ici_of_not_isMin (ha : ¬ IsMin a) : Ioi (pred a) = Ici a := coe_injective <| by simpa using Set.Ioi_pred_eq_Ici_of_not_isMin ha variable [NoMinOrder α] lemma Ioi_pred_eq_Ici (a : α) : Ioi (pred a) = Ici a := coe_injective <| by simp end PredOrder end LocallyFiniteOrderTop end Finset
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/Nat.lean
import Mathlib.Algebra.Group.Embedding import Mathlib.Order.Interval.Finset.SuccPred import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : ℕ) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm theorem range_succ_eq_Icc_zero (n : ℕ) : range (n + 1) = Icc 0 n := by rw [range_eq_Icc_zero_sub_one _ (Nat.add_one_ne_zero _), Nat.add_sub_cancel_right] @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := List.length_range' .. @[simp] lemma card_Ico : #(Ico a b) = b - a := List.length_range' .. @[simp] lemma card_Ioc : #(Ioc a b) = b - a := List.length_range' .. @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := List.length_range' .. @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := (card_Icc _ _).trans <| by rw [← Int.natCast_inj, Int.ofNat_sub] <;> omega @[simp] lemma card_Iic : #(Iic b) = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero] @[simp] theorem card_Iio : #(Iio b) = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero] @[deprecated Finset.Icc_succ_left_eq_Ioc (since := "2025-04-24")] theorem Icc_succ_left : Icc a.succ b = Ioc a b := by ext x rw [mem_Icc, mem_Ioc, succ_le_iff] @[deprecated Finset.Ico_succ_right_eq_Icc (since := "2025-04-24")] theorem Ico_succ_right : Ico a b.succ = Icc a b := by ext x rw [mem_Ico, mem_Icc, Nat.lt_succ_iff] @[deprecated Finset.Ico_succ_left_eq_Ioo (since := "2025-04-24")] theorem Ico_succ_left : Ico a.succ b = Ioo a b := by ext x rw [mem_Ico, mem_Ioo, succ_le_iff] @[deprecated Finset.Icc_pred_right_eq_Ico (since := "2025-04-24")] theorem Icc_pred_right {b : ℕ} (h : 0 < b) : Icc a (b - 1) = Ico a b := by ext x rw [mem_Icc, mem_Ico, lt_iff_le_pred h] @[deprecated Finset.Ico_succ_succ_eq_Ioc (since := "2025-04-24")] theorem Ico_succ_succ : Ico a.succ b.succ = Ioc a b := by ext x rw [mem_Ico, mem_Ioc, succ_le_iff, Nat.lt_succ_iff] -- TODO: Generalise the following series of lemmas. set_option linter.deprecated false in @[simp] theorem Ico_succ_singleton : Ico a (a + 1) = {a} := by rw [Ico_succ_right, Icc_self] set_option linter.deprecated false in @[simp] theorem Ico_pred_singleton {a : ℕ} (h : 0 < a) : Ico (a - 1) a = {a - 1} := by rw [← Icc_pred_right _ h, Icc_self] set_option linter.deprecated false in @[simp] theorem Ioc_succ_singleton : Ioc b (b + 1) = {b + 1} := by rw [← Nat.Icc_succ_left, Icc_self] variable {a b c} lemma mem_Ioc_succ : a ∈ Ioc b (b + 1) ↔ a = b + 1 := by simp lemma mem_Ioc_succ' (a : Ioc b (b + 1)) : a = ⟨b + 1, mem_Ioc.2 (by omega)⟩ := Subtype.val_inj.1 (mem_Ioc_succ.1 a.2) set_option linter.deprecated false in @[deprecated Finset.insert_Ico_right_eq_Ico_succ (since := "2025-04-24")] theorem Ico_succ_right_eq_insert_Ico (h : a ≤ b) : Ico a (b + 1) = insert b (Ico a b) := by rw [Ico_succ_right, ← Ico_insert_right h] set_option linter.deprecated false in @[deprecated Finset.insert_Ico_succ_left_eq_Ico (since := "2025-04-24")] theorem Ico_insert_succ_left (h : a < b) : insert a (Ico a.succ b) = Ico a b := by rw [Ico_succ_left, ← Ioo_insert_left h] @[deprecated Finset.insert_Icc_succ_left_eq_Icc (since := "2025-04-24")] lemma Icc_insert_succ_left (h : a ≤ b) : insert a (Icc (a + 1) b) = Icc a b := by ext x simp only [mem_insert, mem_Icc] cutsat @[deprecated Finset.insert_Icc_right_eq_Icc_succ (since := "2025-04-24")] lemma Icc_insert_succ_right (h : a ≤ b + 1) : insert (b + 1) (Icc a b) = Icc a (b + 1) := by ext x simp only [mem_insert, mem_Icc] cutsat theorem image_sub_const_Ico (h : c ≤ a) : ((Ico a b).image fun x => x - c) = Ico (a - c) (b - c) := by ext x simp_rw [mem_image, mem_Ico] refine ⟨?_, fun h ↦ ⟨x + c, by cutsat⟩⟩ rintro ⟨x, hx, rfl⟩ cutsat theorem Ico_image_const_sub_eq_Ico (hac : a ≤ c) : ((Ico a b).image fun x => c - x) = Ico (c + 1 - b) (c + 1 - a) := by ext x simp_rw [mem_image, mem_Ico] refine ⟨?_, fun h ↦ ⟨c - x, by cutsat⟩⟩ rintro ⟨x, hx, rfl⟩ cutsat set_option linter.deprecated false in theorem Ico_succ_left_eq_erase_Ico : Ico a.succ b = erase (Ico a b) a := by ext x rw [Ico_succ_left, mem_erase, mem_Ico, mem_Ioo, ← and_assoc, ne_comm, and_comm (a := a ≠ x), lt_iff_le_and_ne] set_option linter.deprecated false in theorem mod_injOn_Ico (n a : ℕ) : Set.InjOn (· % a) (Finset.Ico n (n + a)) := by induction n with | zero => simp only [zero_add, Ico_zero_eq_range] rintro k hk l hl (hkl : k % a = l % a) simp only [Finset.mem_range, Finset.mem_coe] at hk hl rwa [mod_eq_of_lt hk, mod_eq_of_lt hl] at hkl | succ n ih => rw [Ico_succ_left_eq_erase_Ico, succ_add, succ_eq_add_one, Ico_succ_right_eq_insert_Ico (by omega)] rintro k hk l hl (hkl : k % a = l % a) have ha : 0 < a := Nat.pos_iff_ne_zero.2 <| by rintro rfl; simp at hk simp only [Finset.mem_coe, Finset.mem_insert, Finset.mem_erase] at hk hl rcases hk with ⟨hkn, rfl | hk⟩ <;> rcases hl with ⟨hln, rfl | hl⟩ · rfl · rw [add_mod_right] at hkl refine (hln <| ih hl ?_ hkl.symm).elim simpa using Nat.lt_add_of_pos_right (n := n) ha · rw [add_mod_right] at hkl suffices k = n by contradiction refine ih hk ?_ hkl simpa using Nat.lt_add_of_pos_right (n := n) ha · refine ih ?_ ?_ hkl <;> simp only [Finset.mem_coe, hk, hl] /-- Note that while this lemma cannot be easily generalized to a type class, it holds for ℤ as well. See `Int.image_Ico_emod` for the ℤ version. -/ theorem image_Ico_mod (n a : ℕ) : (Ico n (n + a)).image (· % a) = range a := by obtain rfl | ha := eq_or_ne a 0 · rw [range_zero, add_zero, Ico_self, image_empty] ext i simp only [mem_image, mem_range, mem_Ico] constructor · rintro ⟨i, _, rfl⟩ exact mod_lt i ha.bot_lt intro hia have hn := Nat.mod_add_div n a obtain hi | hi := lt_or_ge i (n % a) · refine ⟨i + a * (n / a + 1), ⟨?_, ?_⟩, ?_⟩ · rw [add_comm (n / a), Nat.mul_add, mul_one, ← add_assoc] refine hn.symm.le.trans (Nat.add_le_add_right ?_ _) simpa only [zero_add] using add_le_add (zero_le i) (Nat.mod_lt n ha.bot_lt).le · refine lt_of_lt_of_le (Nat.add_lt_add_right hi (a * (n / a + 1))) ?_ rw [Nat.mul_add, mul_one, ← add_assoc, hn] · rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia] · refine ⟨i + a * (n / a), ⟨?_, ?_⟩, ?_⟩ · cutsat · cutsat · rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia] section Multiset open Multiset theorem multiset_Ico_map_mod (n a : ℕ) : (Multiset.Ico n (n + a)).map (· % a) = Multiset.range a := by convert congr_arg Finset.val (image_Ico_mod n a) refine ((nodup_map_iff_inj_on (Finset.Ico _ _).nodup).2 <| ?_).dedup.symm exact mod_injOn_Ico _ _ end Multiset end Nat namespace List lemma toFinset_range'_1 (a b : ℕ) : (List.range' a b).toFinset = Ico a (a + b) := by ext x rw [List.mem_toFinset, List.mem_range'_1, Finset.mem_Ico] lemma toFinset_range'_1_1 (a : ℕ) : (List.range' 1 a).toFinset = Icc 1 a := by ext x rw [List.mem_toFinset, List.mem_range'_1, add_comm, Nat.lt_succ_iff, Finset.mem_Icc] lemma toFinset_range (a : ℕ) : (List.range a).toFinset = Finset.range a := by ext x rw [List.mem_toFinset, List.mem_range, Finset.mem_range] end List namespace Finset theorem range_image_pred_top_sub (n : ℕ) : ((Finset.range n).image fun j => n - 1 - j) = Finset.range n := by cases n · rw [range_zero, image_empty] · rw [Finset.range_eq_Ico, Nat.Ico_image_const_sub_eq_Ico (Nat.zero_le _)] simp_rw [succ_sub_succ, Nat.sub_zero, Nat.sub_self] theorem range_add_eq_union : range (a + b) = range a ∪ (range b).map (addLeftEmbedding a) := by rw [Finset.range_eq_Ico, map_eq_image] convert (Ico_union_Ico_eq_Ico a.zero_le (a.le_add_right b)).symm ext x simp only [Ico_zero_eq_range, mem_image, mem_range, addLeftEmbedding_apply, mem_Ico] constructor · cutsat · rintro h exact ⟨x - a, by cutsat⟩ end Finset section Induction variable {P : ℕ → Prop} theorem Nat.decreasing_induction_of_not_bddAbove (h : ∀ n, P (n + 1) → P n) (hP : ¬BddAbove { x | P x }) (n : ℕ) : P n := let ⟨_, hm, hl⟩ := not_bddAbove_iff.1 hP n decreasingInduction (fun _ _ => h _) hm hl.le @[elab_as_elim] lemma Nat.strong_decreasing_induction (base : ∃ n, ∀ m > n, P m) (step : ∀ n, (∀ m > n, P m) → P n) (n : ℕ) : P n := by apply Nat.decreasing_induction_of_not_bddAbove (P := fun n ↦ ∀ m ≥ n, P m) _ _ n n le_rfl · intro n ih m hm rcases hm.eq_or_lt with rfl | hm · exact step n ih · exact ih m hm · rintro ⟨b, hb⟩ rcases base with ⟨n, hn⟩ specialize @hb (n + b + 1) (fun m hm ↦ hn _ _) all_goals cutsat theorem Nat.decreasing_induction_of_infinite (h : ∀ n, P (n + 1) → P n) (hP : { x | P x }.Infinite) (n : ℕ) : P n := Nat.decreasing_induction_of_not_bddAbove h (mt BddAbove.finite hP) n theorem Nat.cauchy_induction' (seed : ℕ) (h : ∀ n, P (n + 1) → P n) (hs : P seed) (hi : ∀ x, seed ≤ x → P x → ∃ y, x < y ∧ P y) (n : ℕ) : P n := by apply Nat.decreasing_induction_of_infinite h fun hf => _ intro hf obtain ⟨m, hP, hm⟩ := hf.exists_maximal ⟨seed, hs⟩ obtain ⟨y, hl, hy⟩ := hi m (le_of_not_gt <| not_lt_iff_le_imp_ge.2 <| hm hs) hP exact hl.not_ge (hm hy hl.le) theorem Nat.cauchy_induction (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed) (f : ℕ → ℕ) (hf : ∀ x, seed ≤ x → P x → x < f x ∧ P (f x)) (n : ℕ) : P n := seed.cauchy_induction' h hs (fun x hl hx => ⟨f x, hf x hl hx⟩) n theorem Nat.cauchy_induction_mul (h : ∀ (n : ℕ), P (n + 1) → P n) (k seed : ℕ) (hk : 1 < k) (hs : P seed.succ) (hm : ∀ x, seed < x → P x → P (k * x)) (n : ℕ) : P n := by apply Nat.cauchy_induction h _ hs (k * ·) fun x hl hP => ⟨_, hm x hl hP⟩ intro _ hl _ convert (Nat.mul_lt_mul_right <| seed.succ_pos.trans_le hl).2 hk rw [one_mul] theorem Nat.cauchy_induction_two_mul (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed.succ) (hm : ∀ x, seed < x → P x → P (2 * x)) (n : ℕ) : P n := Nat.cauchy_induction_mul h 2 seed Nat.one_lt_two hs hm n theorem Nat.pow_imp_self_of_one_lt {M} [Monoid M] (k : ℕ) (hk : 1 < k) (P : M → Prop) (hmul : ∀ x y, P x → P (x * y) ∨ P (y * x)) (hpow : ∀ x, P (x ^ k) → P x) : ∀ n x, P (x ^ n) → P x := k.cauchy_induction_mul (fun n ih x hx ↦ ih x <| (hmul _ x hx).elim (fun h ↦ by rwa [_root_.pow_succ]) fun h ↦ by rwa [_root_.pow_succ']) 0 hk (fun x hx ↦ pow_one x ▸ hx) fun n _ hn x hx ↦ hpow x <| hn _ <| (pow_mul x k n).subst hx end Induction
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/Basic.lean
import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.Preorder.Finite /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered; -- See `not_lt_of_denselyOrdered_of_locallyFinite` @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered -- See `not_lt_of_denselyOrdered_of_locallyFinite` @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_notMem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_ge @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_gt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_gt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_gt theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_notMem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 @[deprecated (since := "2025-05-23")] alias left_not_mem_Ioc := left_notMem_Ioc theorem left_notMem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 @[deprecated (since := "2025-05-23")] alias left_not_mem_Ioo := left_notMem_Ioo theorem right_notMem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 @[deprecated (since := "2025-05-23")] alias right_not_mem_Ico := right_notMem_Ico theorem right_notMem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[deprecated (since := "2025-05-23")] alias right_not_mem_Ioo := right_notMem_Ioo @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_gt (mem_Ioc.1 h2) lemma _root_.not_lt_of_denselyOrdered_of_locallyFinite [DenselyOrdered α] (a b : α) : ¬ a < b := by intro h induction hs : Finset.Icc a b using Finset.strongInduction generalizing b with | H i ih subst hs obtain ⟨c, hac, hcb⟩ := exists_between h refine ih _ ?_ c hac rfl exact Finset.Icc_ssubset_Icc_right (hac.trans hcb).le le_rfl hcb variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_gt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_ge theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop α] [Fintype α] : Iic (⊤ : α) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder α] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_gt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : α) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a ▸ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : ({x | a ≤ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : ({x | x ≤ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem Icc_bot [OrderBot α] : Icc (⊥ : α) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop α] : Icc a (⊤ : α) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot α] : Ico (⊥ : α) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop α] : Ioc a (⊤ : α) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder α] [Fintype α] : Icc (⊥ : α) (⊤ : α) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_gt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_ge (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop α] : Ici (⊤ : α) = {⊤} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot α] : Iic (⊥ : α) = {⊥} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] @[simp] theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] @[simp] theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] @[simp] theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] @[simp] theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_notMem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_notMem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_notMem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_notMem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : {x ∈ Ico a b | x ≤ a} = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab theorem card_Ico_eq_card_Icc_sub_one (a b : α) : #(Ico a b) = #(Icc a b) - 1 := by classical by_cases h : a ≤ b · rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : #(Ioc a b) = #(Icc a b) - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : #(Ioo a b) = #(Ico a b) - 1 := by classical by_cases h : a < b · rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : #(Ioo a b) = #(Ioc a b) - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : #(Ioo a b) = #(Icc a b) - 2 := by rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl end PartialOrder section Prod variable {β : Type*} section sectL lemma uIcc_map_sectL [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) : (uIcc a b).map (.sectL _ c) = uIcc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) variable [Preorder α] [PartialOrder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) lemma Icc_map_sectL : (Icc a b).map (.sectL _ c) = Icc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectL : (Ioc a b).map (.sectL _ c) = Ioc (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectL : (Ico a b).map (.sectL _ c) = Ico (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectL : (Ioo a b).map (.sectL _ c) = Ioo (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectL section sectR lemma uIcc_map_sectR [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) : (uIcc a b).map (.sectR c _) = uIcc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) variable [PartialOrder α] [Preorder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) lemma Icc_map_sectR : (Icc a b).map (.sectR c _) = Icc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectR : (Ioc a b).map (.sectR c _) = Ioc (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectR : (Ico a b).map (.sectR c _) = Ico (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectR : (Ioo a b).map (.sectR c _) = Ioo (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectR end Prod section BoundedPartialOrder variable [PartialOrder α] section OrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ici_erase [DecidableEq α] (a : α) : (Ici a).erase a = Ioi a := by ext simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm] @[simp] theorem Ioi_insert [DecidableEq α] (a : α) : insert a (Ioi a) = Ici a := by ext simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] theorem notMem_Ioi_self {b : α} : b ∉ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h) @[deprecated (since := "2025-05-23")] alias not_mem_Ioi_self := notMem_Ioi_self -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Ioi_insert`. -/ theorem Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a notMem_Ioi_self := by classical rw [cons_eq_insert, Ioi_insert] theorem card_Ioi_eq_card_Ici_sub_one (a : α) : #(Ioi a) = #(Ici a) - 1 := by rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right] end OrderTop section OrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iic_erase [DecidableEq α] (b : α) : (Iic b).erase b = Iio b := by ext simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] @[simp] theorem Iio_insert [DecidableEq α] (b : α) : insert b (Iio b) = Iic b := by ext simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] theorem notMem_Iio_self {b : α} : b ∉ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h) @[deprecated (since := "2025-05-23")] alias not_mem_Iio_self := notMem_Iio_self -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Iio_insert`. -/ theorem Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b notMem_Iio_self := by classical rw [cons_eq_insert, Iio_insert] theorem card_Iio_eq_card_Iic_sub_one (a : α) : #(Iio a) = #(Iic a) - 1 := by rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right] end OrderBot end BoundedPartialOrder section SemilatticeSup variable [SemilatticeSup α] [LocallyFiniteOrderBot α] -- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`? lemma sup'_Iic (a : α) : (Iic a).sup' nonempty_Iic id = a := le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a @[simp] lemma sup_Iic [OrderBot α] (a : α) : (Iic a).sup id = a := le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a lemma image_subset_Iic_sup [OrderBot α] [DecidableEq α] (f : ι → α) (s : Finset ι) : s.image f ⊆ Iic (s.sup f) := by refine fun i hi ↦ mem_Iic.2 ?_ obtain ⟨j, hj, rfl⟩ := mem_image.1 hi exact le_sup hj lemma subset_Iic_sup_id [OrderBot α] (s : Finset α) : s ⊆ Iic (s.sup id) := fun _ h ↦ mem_Iic.2 <| le_sup (f := id) h end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [LocallyFiniteOrderTop α] lemma inf'_Ici (a : α) : (Ici a).inf' nonempty_Ici id = a := ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a @[simp] lemma inf_Ici [OrderTop α] (a : α) : (Ici a).inf id = a := le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1 end SemilatticeInf section LinearOrder variable [LinearOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h] theorem Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc] @[simp] theorem Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := by rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ h₂] theorem Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico] exact Set.Ico_subset_Ico_union_Ico theorem Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had] theorem Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ h₂] theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, Set.Ico_inter_Ico] theorem Ioc_inter_Ioc {a b c d : α} : Ioc a b ∩ Ioc c d = Ioc (max a c) (min b d) := by rw [← coe_inj] push_cast exact Set.Ioc_inter_Ioc @[simp] theorem Ico_filter_lt (a b c : α) : {x ∈ Ico a b | x < c} = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_filter_lt_of_right_le h, min_eq_left h] | inr h => rw [Ico_filter_lt_of_le_right h, min_eq_right h] @[simp] theorem Ico_filter_le (a b c : α) : {x ∈ Ico a b | c ≤ x} = Ico (max a c) b := by cases le_total a c with | inl h => rw [Ico_filter_le_of_left_le h, max_eq_right h] | inr h => rw [Ico_filter_le_of_le_left h, max_eq_left h] @[simp] theorem Ioo_filter_lt (a b c : α) : {x ∈ Ioo a b | x < c} = Ioo a (min b c) := by ext simp [and_assoc] @[simp] theorem Iio_filter_lt {α} [LinearOrder α] [LocallyFiniteOrderBot α] (a b : α) : {x ∈ Iio a | x < b} = Iio (min a b) := by ext simp @[simp] theorem Ico_diff_Ico_left (a b c : α) : Ico a b \ Ico a c = Ico (max a c) b := by cases le_total a c with | inl h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and_right_comm, not_and, not_lt] exact and_congr_left' ⟨fun hx => hx.2 hx.1, fun hx => ⟨h.trans hx, fun _ => hx⟩⟩ | inr h => rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h] @[simp] theorem Ico_diff_Ico_right (a b c : α) : Ico a b \ Ico c b = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h] | inr h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le] exact and_congr_right' ⟨fun hx => hx.2 hx.1, fun hx => ⟨hx.trans_le h, fun _ => hx⟩⟩ @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [disjoint_iff_inter_eq_empty, Ioc_inter_Ioc, Ioc_eq_empty_iff, not_lt] section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] theorem Iic_diff_Ioc : Iic b \ Ioc a b = Iic (a ⊓ b) := by rw [← coe_inj] push_cast exact Set.Iic_diff_Ioc theorem Iic_diff_Ioc_self_of_le (hab : a ≤ b) : Iic b \ Ioc a b = Iic a := by rw [Iic_diff_Ioc, min_eq_left hab] theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b := by rw [← coe_inj] push_cast exact Set.Iic_union_Ioc_eq_Iic h end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {s : Set α} theorem _root_.Set.Infinite.exists_gt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, a < b := not_bddAbove_iff.1 hs.not_bddAbove theorem _root_.Set.infinite_iff_exists_gt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, a < b := ⟨Set.Infinite.exists_gt, Set.infinite_of_forall_exists_gt⟩ end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {s : Set α} theorem _root_.Set.Infinite.exists_lt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, b < a := not_bddBelow_iff.1 hs.not_bddBelow theorem _root_.Set.infinite_iff_exists_lt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, b < a := ⟨Set.Infinite.exists_lt, Set.infinite_of_forall_exists_lt⟩ end LocallyFiniteOrderTop variable [Fintype α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem Ioi_disjUnion_Iio (a : α) : (Ioi a).disjUnion (Iio a) (disjoint_Ioi_Iio a) = ({a} : Finset α)ᶜ := by ext simp [eq_comm] end LinearOrder section Lattice variable [Lattice α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ x : α} theorem uIcc_toDual (a b : α) : [[toDual a, toDual b]] = [[a, b]].map toDual.toEmbedding := Icc_toDual (a ⊔ b) (a ⊓ b) @[simp] theorem uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] @[simp] theorem uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h] theorem uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by rw [uIcc, uIcc, inf_comm, sup_comm] theorem uIcc_self : [[a, a]] = {a} := by simp [uIcc] @[simp] theorem nonempty_uIcc : Finset.Nonempty [[a, b]] := nonempty_Icc.2 inf_le_sup theorem Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right theorem Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left theorem left_mem_uIcc : a ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_left, le_sup_left⟩ theorem right_mem_uIcc : b ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_right, le_sup_right⟩ theorem mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc <| mem_Icc.2 ⟨ha, hb⟩ theorem mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' <| mem_Icc.2 ⟨hb, ha⟩ theorem uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) : [[a₁, b₁]] ⊆ [[a₂, b₂]] := by rw [mem_uIcc] at h₁ h₂ exact Icc_subset_Icc (_root_.le_inf h₁.1 h₂.1) (_root_.sup_le h₁.2 h₂.2) theorem uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := by rw [mem_Icc] at ha hb exact Icc_subset_Icc (_root_.le_inf ha.1 hb.1) (_root_.sup_le ha.2 hb.2) theorem uIcc_subset_uIcc_iff_mem : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] := ⟨fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩, fun h => uIcc_subset_uIcc h.1 h.2⟩ theorem uIcc_subset_uIcc_iff_le' : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ := Icc_subset_Icc_iff inf_le_sup theorem uIcc_subset_uIcc_right (h : x ∈ [[a, b]]) : [[x, b]] ⊆ [[a, b]] := uIcc_subset_uIcc h right_mem_uIcc theorem uIcc_subset_uIcc_left (h : x ∈ [[a, b]]) : [[a, x]] ⊆ [[a, b]] := uIcc_subset_uIcc left_mem_uIcc h end Lattice section DistribLattice variable [DistribLattice α] [LocallyFiniteOrder α] {a b c : α} theorem eq_of_mem_uIcc_of_mem_uIcc : a ∈ [[b, c]] → b ∈ [[a, c]] → a = b := by simp_rw [mem_uIcc] exact Set.eq_of_mem_uIcc_of_mem_uIcc theorem eq_of_mem_uIcc_of_mem_uIcc' : b ∈ [[a, c]] → c ∈ [[a, b]] → b = c := by simp_rw [mem_uIcc] exact Set.eq_of_mem_uIcc_of_mem_uIcc' theorem uIcc_injective_right (a : α) : Injective fun b => [[b, a]] := fun b c h => by rw [Finset.ext_iff] at h exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc) theorem uIcc_injective_left (a : α) : Injective (uIcc a) := by simpa only [uIcc_comm] using uIcc_injective_right a end DistribLattice section LinearOrder variable [LinearOrder α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c : α} theorem Icc_min_max : Icc (min a b) (max a b) = [[a, b]] := rfl theorem uIcc_of_not_le (h : ¬a ≤ b) : [[a, b]] = Icc b a := uIcc_of_ge <| le_of_not_ge h theorem uIcc_of_not_ge (h : ¬b ≤ a) : [[a, b]] = Icc a b := uIcc_of_le <| le_of_not_ge h theorem uIcc_eq_union : [[a, b]] = Icc a b ∪ Icc b a := coe_injective <| by push_cast exact Set.uIcc_eq_union theorem mem_uIcc' : a ∈ [[b, c]] ↔ b ≤ a ∧ a ≤ c ∨ c ≤ a ∧ a ≤ b := by simp [uIcc_eq_union] theorem notMem_uIcc_of_lt : c < a → c < b → c ∉ [[a, b]] := by rw [mem_uIcc] exact Set.notMem_uIcc_of_lt @[deprecated (since := "2025-05-23")] alias not_mem_uIcc_of_lt := notMem_uIcc_of_lt theorem notMem_uIcc_of_gt : a < c → b < c → c ∉ [[a, b]] := by rw [mem_uIcc] exact Set.notMem_uIcc_of_gt @[deprecated (since := "2025-05-23")] alias not_mem_uIcc_of_gt := notMem_uIcc_of_gt theorem uIcc_subset_uIcc_iff_le : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ := uIcc_subset_uIcc_iff_le' /-- A sort of triangle inequality. -/ theorem uIcc_subset_uIcc_union_uIcc : [[a, c]] ⊆ [[a, b]] ∪ [[b, c]] := coe_subset.1 <| by push_cast exact Set.uIcc_subset_uIcc_union_uIcc end LinearOrder end Finset /-! ### `⩿`, `⋖` and monotonicity -/ section Cover open Finset Relation lemma transGen_wcovBy_of_le [Preorder α] [LocallyFiniteOrder α] {x y : α} (hxy : x ≤ y) : TransGen (· ⩿ ·) x y := by -- We proceed by well-founded induction on the cardinality of `Icc x y`. -- It's impossible for the cardinality to be zero since `x ≤ y` have : #(Ico x y) < #(Icc x y) := card_lt_card <| ⟨Ico_subset_Icc_self, not_subset.mpr ⟨y, ⟨right_mem_Icc.mpr hxy, right_notMem_Ico⟩⟩⟩ by_cases hxy' : y ≤ x -- If `y ≤ x`, then `x ⩿ y` · exact .single <| wcovBy_of_le_of_le hxy hxy' /- and if `¬ y ≤ x`, then `x < y`, not because it is a linear order, but because `x ≤ y` already. In that case, since `z` is maximal in `Ico x y`, then `z ⩿ y` and we can use the induction hypothesis to show that `Relation.TransGen (· ⩿ ·) x z`. -/ · obtain ⟨z, hxz, hz⟩ := (Set.finite_Ico x y).exists_le_maximal <| Set.left_mem_Ico.2 <| hxy.lt_of_not_ge hxy' have z_card := calc #(Icc x z) ≤ #(Ico x y) := card_le_card <| Icc_subset_Ico_right hz.1.2 _ < #(Icc x y) := this have h₁ := transGen_wcovBy_of_le hz.1.1 have h₂ : z ⩿ y := ⟨hz.1.2.le, fun c hzc hcy ↦ hzc.not_ge <| hz.2 ⟨hz.1.1.trans hzc.le, hcy⟩ hzc.le⟩ exact .tail h₁ h₂ termination_by #(Icc x y) /-- In a locally finite preorder, `≤` is the transitive closure of `⩿`. -/ lemma le_iff_transGen_wcovBy [Preorder α] [LocallyFiniteOrder α] {x y : α} : x ≤ y ↔ TransGen (· ⩿ ·) x y := by refine ⟨transGen_wcovBy_of_le, fun h ↦ ?_⟩ induction h with | single h => exact h.le | tail _ h₁ h₂ => exact h₂.trans h₁.le /-- In a locally finite partial order, `≤` is the reflexive transitive closure of `⋖`. -/ lemma le_iff_reflTransGen_covBy [PartialOrder α] [LocallyFiniteOrder α] {x y : α} : x ≤ y ↔ ReflTransGen (· ⋖ ·) x y := by rw [le_iff_transGen_wcovBy, wcovBy_eq_reflGen_covBy, transGen_reflGen] lemma transGen_covBy_of_lt [Preorder α] [LocallyFiniteOrder α] {x y : α} (hxy : x < y) : TransGen (· ⋖ ·) x y := by -- We proceed by well-founded induction on the cardinality of `Ico x y`. -- It's impossible for the cardinality to be zero since `x < y` -- `Ico x y` is a nonempty finset and so contains a maximal element `z` and -- `Ico x z` has cardinality strictly less than the cardinality of `Ico x y` obtain ⟨z, hxz, hz⟩ := (Set.finite_Ico x y).exists_le_maximal <| Set.left_mem_Ico.2 hxy have z_card : #(Ico x z) < #(Ico x y) := card_lt_card <| ssubset_iff_of_subset (Ico_subset_Ico_right hz.1.2.le) |>.mpr ⟨z, mem_Ico.2 hz.1, right_notMem_Ico⟩ /- Since `z` is maximal in `Ico x y`, `z ⋖ y`. -/ have hzy : z ⋖ y := ⟨hz.1.2, fun c hc hcy ↦ hc.not_ge <| hz.2 (⟨(hz.1.1.trans_lt hc).le, hcy⟩) hc.le⟩ by_cases hxz : x < z /- when `x < z`, then we may use the induction hypothesis to get a chain `Relation.TransGen (· ⋖ ·) x z`, which we can extend with `Relation.TransGen.tail`. -/ · exact .tail (transGen_covBy_of_lt hxz) hzy /- when `¬ x < z`, then actually `z ≤ x` (not because it's a linear order, but because `x ≤ z`), and since `z ⋖ y` we conclude that `x ⋖ y`, then `Relation.TransGen.single`. -/ · simp only [lt_iff_le_not_ge, not_and, not_not] at hxz exact .single (hzy.of_le_of_lt (hxz hz.1.1) hxy) termination_by #(Ico x y) /-- In a locally finite preorder, `<` is the transitive closure of `⋖`. -/ lemma lt_iff_transGen_covBy [Preorder α] [LocallyFiniteOrder α] {x y : α} : x < y ↔ TransGen (· ⋖ ·) x y := by refine ⟨transGen_covBy_of_lt, fun h ↦ ?_⟩ induction h with | single hx => exact hx.1 | tail _ hb ih => exact ih.trans hb.1 variable {β : Type*} /-- A function from a locally finite preorder is monotone if and only if it is monotone when restricted to pairs satisfying `a ⩿ b`. -/ lemma monotone_iff_forall_wcovBy [Preorder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : Monotone f ↔ ∀ a b : α, a ⩿ b → f a ≤ f b := by refine ⟨fun hf _ _ h ↦ hf h.le, fun h a b hab ↦ ?_⟩ simpa [transGen_eq_self (r := (· ≤ · : β → β → Prop)) transitive_le] using TransGen.lift f h <| le_iff_transGen_wcovBy.mp hab /-- A function from a locally finite partial order is monotone if and only if it is monotone when restricted to pairs satisfying `a ⋖ b`. -/ lemma monotone_iff_forall_covBy [PartialOrder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : Monotone f ↔ ∀ a b : α, a ⋖ b → f a ≤ f b := by refine ⟨fun hf _ _ h ↦ hf h.le, fun h a b hab ↦ ?_⟩ simpa [reflTransGen_eq_self (r := (· ≤ · : β → β → Prop)) IsRefl.reflexive transitive_le] using ReflTransGen.lift f h <| le_iff_reflTransGen_covBy.mp hab /-- A function from a locally finite preorder is strictly monotone if and only if it is strictly monotone when restricted to pairs satisfying `a ⋖ b`. -/ lemma strictMono_iff_forall_covBy [Preorder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : StrictMono f ↔ ∀ a b : α, a ⋖ b → f a < f b := by refine ⟨fun hf _ _ h ↦ hf h.lt, fun h a b hab ↦ ?_⟩ have := Relation.TransGen.lift f h (a := a) (b := b) rw [← lt_iff_transGen_covBy, transGen_eq_self (@lt_trans β _)] at this exact this hab /-- A function from a locally finite preorder is antitone if and only if it is antitone when restricted to pairs satisfying `a ⩿ b`. -/ lemma antitone_iff_forall_wcovBy [Preorder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : Antitone f ↔ ∀ a b : α, a ⩿ b → f b ≤ f a := monotone_iff_forall_wcovBy (β := βᵒᵈ) f /-- A function from a locally finite partial order is antitone if and only if it is antitone when restricted to pairs satisfying `a ⋖ b`. -/ lemma antitone_iff_forall_covBy [PartialOrder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : Antitone f ↔ ∀ a b : α, a ⋖ b → f b ≤ f a := monotone_iff_forall_covBy (β := βᵒᵈ) f /-- A function from a locally finite preorder is strictly antitone if and only if it is strictly antitone when restricted to pairs satisfying `a ⋖ b`. -/ lemma strictAnti_iff_forall_covBy [Preorder α] [LocallyFiniteOrder α] [Preorder β] (f : α → β) : StrictAnti f ↔ ∀ a b : α, a ⋖ b → f b < f a := strictMono_iff_forall_covBy (β := βᵒᵈ) f end Cover
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/Defs.lean
import Mathlib.Data.Finset.Preimage import Mathlib.Data.Finset.Prod import Mathlib.Order.Hom.WithTopBot import Mathlib.Order.Interval.Set.UnorderedInterval /-! # Locally finite orders This file defines locally finite orders. A locally finite order is an order for which all bounded intervals are finite. This allows to make sense of `Icc`/`Ico`/`Ioc`/`Ioo` as lists, multisets, or finsets. Further, if the order is bounded above (resp. below), then we can also make sense of the "unbounded" intervals `Ici`/`Ioi` (resp. `Iic`/`Iio`). Many theorems about these intervals can be found in `Mathlib/Order/Interval/Finset/Basic.lean`. ## Examples Naturally occurring locally finite orders are `ℕ`, `ℤ`, `ℕ+`, `Fin n`, `α × β` the product of two locally finite orders, `α →₀ β` the finitely supported functions to a locally finite order `β`... ## Main declarations In a `LocallyFiniteOrder`, * `Finset.Icc`: Closed-closed interval as a finset. * `Finset.Ico`: Closed-open interval as a finset. * `Finset.Ioc`: Open-closed interval as a finset. * `Finset.Ioo`: Open-open interval as a finset. * `Finset.uIcc`: Unordered closed interval as a finset. In a `LocallyFiniteOrderTop`, * `Finset.Ici`: Closed-infinite interval as a finset. * `Finset.Ioi`: Open-infinite interval as a finset. In a `LocallyFiniteOrderBot`, * `Finset.Iic`: Infinite-open interval as a finset. * `Finset.Iio`: Infinite-closed interval as a finset. ## Instances A `LocallyFiniteOrder` instance can be built * for a subtype of a locally finite order. See `Subtype.locallyFiniteOrder`. * for the product of two locally finite orders. See `Prod.locallyFiniteOrder`. * for any fintype (but not as an instance). See `Fintype.toLocallyFiniteOrder`. * from a definition of `Finset.Icc` alone. See `LocallyFiniteOrder.ofIcc`. * by pulling back `LocallyFiniteOrder β` through an order embedding `f : α →o β`. See `OrderEmbedding.locallyFiniteOrder`. Instances for concrete types are proved in their respective files: * `ℕ` is in `Order.Interval.Finset.Nat` * `ℤ` is in `Data.Int.Interval` * `ℕ+` is in `Data.PNat.Interval` * `Fin n` is in `Order.Interval.Finset.Fin` * `Finset α` is in `Data.Finset.Interval` * `Σ i, α i` is in `Data.Sigma.Interval` Along, you will find lemmas about the cardinality of those finite intervals. ## TODO Provide the `LocallyFiniteOrder` instance for `α ×ₗ β` where `LocallyFiniteOrder α` and `Fintype β`. Provide the `LocallyFiniteOrder` instance for `α →₀ β` where `β` is locally finite. Provide the `LocallyFiniteOrder` instance for `Π₀ i, β i` where all the `β i` are locally finite. From `LinearOrder α`, `NoMaxOrder α`, `LocallyFiniteOrder α`, we can also define an order isomorphism `α ≃ ℕ` or `α ≃ ℤ`, depending on whether we have `OrderBot α` or `NoMinOrder α` and `Nonempty α`. When `OrderBot α`, we can match `a : α` to `#(Iio a)`. We can provide `SuccOrder α` from `LinearOrder α` and `LocallyFiniteOrder α` using ```lean lemma exists_min_greater [LinearOrder α] [LocallyFiniteOrder α] {x ub : α} (hx : x < ub) : ∃ lub, x < lub ∧ ∀ y, x < y → lub ≤ y := by -- very non-golfed have h : (Finset.Ioc x ub).Nonempty := ⟨ub, Finset.mem_Ioc.2 ⟨hx, le_rfl⟩⟩ use Finset.min' (Finset.Ioc x ub) h constructor · exact (Finset.mem_Ioc.mp <| Finset.min'_mem _ h).1 rintro y hxy obtain hy | hy := le_total y ub · refine Finset.min'_le (Ioc x ub) y ?_ simp [*] at * · exact (Finset.min'_le _ _ (Finset.mem_Ioc.2 ⟨hx, le_rfl⟩)).trans hy ``` Note that the converse is not true. Consider `{-2^z | z : ℤ} ∪ {2^z | z : ℤ}`. Any element has a successor (and actually a predecessor as well), so it is a `SuccOrder`, but it's not locally finite as `Icc (-1) 1` is infinite. -/ open Finset Function /-- This is a mixin class describing a locally finite order, that is, is an order where bounded intervals are finite. When you don't care too much about definitional equality, you can use `LocallyFiniteOrder.ofIcc` or `LocallyFiniteOrder.ofFiniteIcc` to build a locally finite order from just `Finset.Icc`. -/ class LocallyFiniteOrder (α : Type*) [Preorder α] where /-- Left-closed right-closed interval -/ finsetIcc : α → α → Finset α /-- Left-closed right-open interval -/ finsetIco : α → α → Finset α /-- Left-open right-closed interval -/ finsetIoc : α → α → Finset α /-- Left-open right-open interval -/ finsetIoo : α → α → Finset α /-- `x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b` -/ finset_mem_Icc : ∀ a b x : α, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b /-- `x ∈ finsetIco a b ↔ a ≤ x ∧ x < b` -/ finset_mem_Ico : ∀ a b x : α, x ∈ finsetIco a b ↔ a ≤ x ∧ x < b /-- `x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b` -/ finset_mem_Ioc : ∀ a b x : α, x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b /-- `x ∈ finsetIoo a b ↔ a < x ∧ x < b` -/ finset_mem_Ioo : ∀ a b x : α, x ∈ finsetIoo a b ↔ a < x ∧ x < b /-- This mixin class describes an order where all intervals bounded below are finite. This is slightly weaker than `LocallyFiniteOrder` + `OrderTop` as it allows empty types. -/ class LocallyFiniteOrderTop (α : Type*) [Preorder α] where /-- Left-open right-infinite interval -/ finsetIoi : α → Finset α /-- Left-closed right-infinite interval -/ finsetIci : α → Finset α /-- `x ∈ finsetIci a ↔ a ≤ x` -/ finset_mem_Ici : ∀ a x : α, x ∈ finsetIci a ↔ a ≤ x /-- `x ∈ finsetIoi a ↔ a < x` -/ finset_mem_Ioi : ∀ a x : α, x ∈ finsetIoi a ↔ a < x /-- This mixin class describes an order where all intervals bounded above are finite. This is slightly weaker than `LocallyFiniteOrder` + `OrderBot` as it allows empty types. -/ class LocallyFiniteOrderBot (α : Type*) [Preorder α] where /-- Left-infinite right-open interval -/ finsetIio : α → Finset α /-- Left-infinite right-closed interval -/ finsetIic : α → Finset α /-- `x ∈ finsetIic a ↔ x ≤ a` -/ finset_mem_Iic : ∀ a x : α, x ∈ finsetIic a ↔ x ≤ a /-- `x ∈ finsetIio a ↔ x < a` -/ finset_mem_Iio : ∀ a x : α, x ∈ finsetIio a ↔ x < a /-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableLE` but only `Preorder`. -/ def LocallyFiniteOrder.ofIcc' (α : Type*) [Preorder α] [DecidableLE α] (finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) : LocallyFiniteOrder α where finsetIcc := finsetIcc finsetIco a b := {x ∈ finsetIcc a b | ¬b ≤ x} finsetIoc a b := {x ∈ finsetIcc a b | ¬x ≤ a} finsetIoo a b := {x ∈ finsetIcc a b | ¬x ≤ a ∧ ¬b ≤ x} finset_mem_Icc := mem_Icc finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_not_ge] finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_not_ge] finset_mem_Ioo a b x := by rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_not_ge, lt_iff_le_not_ge] /-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrder.ofIcc'`, this one requires `PartialOrder` but only `DecidableEq`. -/ def LocallyFiniteOrder.ofIcc (α : Type*) [PartialOrder α] [DecidableEq α] (finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) : LocallyFiniteOrder α where finsetIcc := finsetIcc finsetIco a b := {x ∈ finsetIcc a b | x ≠ b} finsetIoc a b := {x ∈ finsetIcc a b | a ≠ x} finsetIoo a b := {x ∈ finsetIcc a b | a ≠ x ∧ x ≠ b} finset_mem_Icc := mem_Icc finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_and_ne] finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_and_ne] finset_mem_Ioo a b x := by rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_and_ne, lt_iff_le_and_ne] /-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrderTop.ofIci`, this one requires `DecidableLE` but only `Preorder`. -/ def LocallyFiniteOrderTop.ofIci' (α : Type*) [Preorder α] [DecidableLE α] (finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) : LocallyFiniteOrderTop α where finsetIci := finsetIci finsetIoi a := {x ∈ finsetIci a | ¬x ≤ a} finset_mem_Ici := mem_Ici finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_not_ge] /-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but only `DecidableEq`. -/ def LocallyFiniteOrderTop.ofIci (α : Type*) [PartialOrder α] [DecidableEq α] (finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) : LocallyFiniteOrderTop α where finsetIci := finsetIci finsetIoi a := {x ∈ finsetIci a | a ≠ x} finset_mem_Ici := mem_Ici finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_and_ne] /-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrderBot.ofIic`, this one requires `DecidableLE` but only `Preorder`. -/ def LocallyFiniteOrderBot.ofIic' (α : Type*) [Preorder α] [DecidableLE α] (finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) : LocallyFiniteOrderBot α where finsetIic := finsetIic finsetIio a := {x ∈ finsetIic a | ¬a ≤ x} finset_mem_Iic := mem_Iic finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_not_ge] /-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing the ends. As opposed to `LocallyFiniteOrderBot.ofIic'`, this one requires `PartialOrder` but only `DecidableEq`. -/ def LocallyFiniteOrderBot.ofIic (α : Type*) [PartialOrder α] [DecidableEq α] (finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) : LocallyFiniteOrderBot α where finsetIic := finsetIic finsetIio a := {x ∈ finsetIic a | x ≠ a} finset_mem_Iic := mem_Iic finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_and_ne] variable {α β : Type*} -- See note [reducible non-instances] /-- An empty type is locally finite. This is not an instance as it would not be defeq to more specific instances. -/ protected abbrev IsEmpty.toLocallyFiniteOrder [Preorder α] [IsEmpty α] : LocallyFiniteOrder α where finsetIcc := isEmptyElim finsetIco := isEmptyElim finsetIoc := isEmptyElim finsetIoo := isEmptyElim finset_mem_Icc := isEmptyElim finset_mem_Ico := isEmptyElim finset_mem_Ioc := isEmptyElim finset_mem_Ioo := isEmptyElim -- See note [reducible non-instances] /-- An empty type is locally finite. This is not an instance as it would not be defeq to more specific instances. -/ protected abbrev IsEmpty.toLocallyFiniteOrderTop [Preorder α] [IsEmpty α] : LocallyFiniteOrderTop α where finsetIci := isEmptyElim finsetIoi := isEmptyElim finset_mem_Ici := isEmptyElim finset_mem_Ioi := isEmptyElim -- See note [reducible non-instances] /-- An empty type is locally finite. This is not an instance as it would not be defeq to more specific instances. -/ protected abbrev IsEmpty.toLocallyFiniteOrderBot [Preorder α] [IsEmpty α] : LocallyFiniteOrderBot α where finsetIic := isEmptyElim finsetIio := isEmptyElim finset_mem_Iic := isEmptyElim finset_mem_Iio := isEmptyElim /-! ### Intervals as finsets -/ namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a b x : α} /-- The finset $[a, b]$ of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a finset. -/ def Icc (a b : α) : Finset α := LocallyFiniteOrder.finsetIcc a b /-- The finset $[a, b)$ of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a finset. -/ def Ico (a b : α) : Finset α := LocallyFiniteOrder.finsetIco a b /-- The finset $(a, b]$ of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a finset. -/ def Ioc (a b : α) : Finset α := LocallyFiniteOrder.finsetIoc a b /-- The finset $(a, b)$ of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a finset. -/ def Ioo (a b : α) : Finset α := LocallyFiniteOrder.finsetIoo a b @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := LocallyFiniteOrder.finset_mem_Icc a b x @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := LocallyFiniteOrder.finset_mem_Ico a b x @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := LocallyFiniteOrder.finset_mem_Ioc a b x @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := LocallyFiniteOrder.finset_mem_Ioo a b x @[simp, norm_cast] theorem coe_Icc (a b : α) : (Icc a b : Set α) = Set.Icc a b := Set.ext fun _ => mem_Icc @[simp, norm_cast] theorem coe_Ico (a b : α) : (Ico a b : Set α) = Set.Ico a b := Set.ext fun _ => mem_Ico @[simp, norm_cast] theorem coe_Ioc (a b : α) : (Ioc a b : Set α) = Set.Ioc a b := Set.ext fun _ => mem_Ioc @[simp, norm_cast] theorem coe_Ioo (a b : α) : (Ioo a b : Set α) = Set.Ioo a b := Set.ext fun _ => mem_Ioo @[simp] theorem _root_.Fintype.card_Icc (a b : α) [Fintype (Set.Icc a b)] : Fintype.card (Set.Icc a b) = #(Icc a b) := Fintype.card_of_finset' _ fun _ ↦ by simp @[simp] theorem _root_.Fintype.card_Ico (a b : α) [Fintype (Set.Ico a b)] : Fintype.card (Set.Ico a b) = #(Ico a b) := Fintype.card_of_finset' _ fun _ ↦ by simp @[simp] theorem _root_.Fintype.card_Ioc (a b : α) [Fintype (Set.Ioc a b)] : Fintype.card (Set.Ioc a b) = #(Ioc a b) := Fintype.card_of_finset' _ fun _ ↦ by simp @[simp] theorem _root_.Fintype.card_Ioo (a b : α) [Fintype (Set.Ioo a b)] : Fintype.card (Set.Ioo a b) = #(Ioo a b) := Fintype.card_of_finset' _ fun _ ↦ by simp end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a x : α} /-- The finset $[a, ∞)$ of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a finset. -/ def Ici (a : α) : Finset α := LocallyFiniteOrderTop.finsetIci a /-- The finset $(a, ∞)$ of elements `x` such that `a < x`. Basically `Set.Ioi a` as a finset. -/ def Ioi (a : α) : Finset α := LocallyFiniteOrderTop.finsetIoi a @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := LocallyFiniteOrderTop.finset_mem_Ici _ _ @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := LocallyFiniteOrderTop.finset_mem_Ioi _ _ @[simp, norm_cast] theorem coe_Ici (a : α) : (Ici a : Set α) = Set.Ici a := Set.ext fun _ => mem_Ici @[simp, norm_cast] theorem coe_Ioi (a : α) : (Ioi a : Set α) = Set.Ioi a := Set.ext fun _ => mem_Ioi @[simp] theorem _root_.Fintype.card_Ici (a : α) [Fintype (Set.Ici a)] : Fintype.card (Set.Ici a) = #(Ici a) := Fintype.card_of_finset' _ fun _ ↦ by simp @[simp] theorem _root_.Fintype.card_Ioi (a : α) [Fintype (Set.Ioi a)] : Fintype.card (Set.Ioi a) = #(Ioi a) := Fintype.card_of_finset' _ fun _ ↦ by simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a x : α} /-- The finset $(-∞, b]$ of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a finset. -/ def Iic (b : α) : Finset α := LocallyFiniteOrderBot.finsetIic b /-- The finset $(-∞, b)$ of elements `x` such that `x < b`. Basically `Set.Iio b` as a finset. -/ def Iio (b : α) : Finset α := LocallyFiniteOrderBot.finsetIio b @[simp] theorem mem_Iic : x ∈ Iic a ↔ x ≤ a := LocallyFiniteOrderBot.finset_mem_Iic _ _ @[simp] theorem mem_Iio : x ∈ Iio a ↔ x < a := LocallyFiniteOrderBot.finset_mem_Iio _ _ @[simp, norm_cast] theorem coe_Iic (a : α) : (Iic a : Set α) = Set.Iic a := Set.ext fun _ => mem_Iic @[simp, norm_cast] theorem coe_Iio (a : α) : (Iio a : Set α) = Set.Iio a := Set.ext fun _ => mem_Iio @[simp] theorem _root_.Fintype.card_Iic (a : α) [Fintype (Set.Iic a)] : Fintype.card (Set.Iic a) = #(Iic a) := Fintype.card_of_finset' _ fun _ ↦ by simp @[simp] theorem _root_.Fintype.card_Iio (a : α) [Fintype (Set.Iio a)] : Fintype.card (Set.Iio a) = #(Iio a) := Fintype.card_of_finset' _ fun _ ↦ by simp end LocallyFiniteOrderBot section OrderTop variable [LocallyFiniteOrder α] [OrderTop α] {a x : α} -- See note [lower priority instance] instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderTop : LocallyFiniteOrderTop α where finsetIci b := Icc b ⊤ finsetIoi b := Ioc b ⊤ finset_mem_Ici a x := by rw [mem_Icc, and_iff_left le_top] finset_mem_Ioi a x := by rw [mem_Ioc, and_iff_left le_top] theorem Ici_eq_Icc (a : α) : Ici a = Icc a ⊤ := rfl theorem Ioi_eq_Ioc (a : α) : Ioi a = Ioc a ⊤ := rfl end OrderTop section OrderBot variable [OrderBot α] [LocallyFiniteOrder α] {b x : α} -- See note [lower priority instance] instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderBot : LocallyFiniteOrderBot α where finsetIic := Icc ⊥ finsetIio := Ico ⊥ finset_mem_Iic a x := by rw [mem_Icc, and_iff_right bot_le] finset_mem_Iio a x := by rw [mem_Ico, and_iff_right bot_le] theorem Iic_eq_Icc : Iic = Icc (⊥ : α) := rfl theorem Iio_eq_Ico : Iio = Ico (⊥ : α) := rfl end OrderBot end Preorder section Lattice variable [Lattice α] [LocallyFiniteOrder α] {a b x : α} /-- `Finset.uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. Note that we define it more generally in a lattice as `Finset.Icc (a ⊓ b) (a ⊔ b)`. In a product type, `Finset.uIcc` corresponds to the bounding box of the two elements. -/ def uIcc (a b : α) : Finset α := Icc (a ⊓ b) (a ⊔ b) @[inherit_doc] scoped[FinsetInterval] notation "[[" a ", " b "]]" => Finset.uIcc a b @[simp] theorem mem_uIcc : x ∈ uIcc a b ↔ a ⊓ b ≤ x ∧ x ≤ a ⊔ b := mem_Icc @[simp, norm_cast] theorem coe_uIcc (a b : α) : (Finset.uIcc a b : Set α) = Set.uIcc a b := coe_Icc _ _ @[simp] theorem _root_.Fintype.card_uIcc (a b : α) [Fintype (Set.uIcc a b)] : Fintype.card (Set.uIcc a b) = #(uIcc a b) := Fintype.card_of_finset' _ fun _ ↦ by simp [Set.uIcc] end Lattice end Finset namespace Mathlib.Meta open Lean Elab Term Meta Batteries.ExtendedBinder /-- Elaborate set builder notation for `Finset`. * `{x ≤ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iic a)` if the expected type is `Finset ?α`. * `{x ≥ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ici a)` if the expected type is `Finset ?α`. * `{x < a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iio a)` if the expected type is `Finset ?α`. * `{x > a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ioi a)` if the expected type is `Finset ?α`. See also * `Data.Set.Defs` for the `Set` builder notation elaborator that this elaborator partly overrides. * `Data.Finset.Basic` for the `Finset` builder notation elaborator partly overriding this one for syntax of the form `{x ∈ s | p x}`. * `Data.Fintype.Basic` for the `Finset` builder notation elaborator handling syntax of the form `{x | p x}`, `{x : α | p x}`, `{x ∉ s | p x}`, `{x ≠ a | p x}`. TODO: Write a delaborator -/ @[term_elab setBuilder] def elabFinsetBuilderIxx : TermElab | `({ $x:ident ≤ $a | $p }), expectedType? => do -- If the expected type is not known to be `Finset ?α`, give up. unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iic $a))) expectedType? | `({ $x:ident ≥ $a | $p }), expectedType? => do -- If the expected type is not known to be `Finset ?α`, give up. unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ici $a))) expectedType? | `({ $x:ident < $a | $p }), expectedType? => do -- If the expected type is not known to be `Finset ?α`, give up. unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iio $a))) expectedType? | `({ $x:ident > $a | $p }), expectedType? => do -- If the expected type is not known to be `Finset ?α`, give up. unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ioi $a))) expectedType? | _, _ => throwUnsupportedSyntax end Mathlib.Meta /-! ### Finiteness of `Set` intervals -/ namespace Set section Preorder variable [Preorder α] [LocallyFiniteOrder α] (a b : α) instance instFintypeIcc : Fintype (Icc a b) := .ofFinset (Finset.Icc a b) fun _ => Finset.mem_Icc instance instFintypeIco : Fintype (Ico a b) := .ofFinset (Finset.Ico a b) fun _ => Finset.mem_Ico instance instFintypeIoc : Fintype (Ioc a b) := .ofFinset (Finset.Ioc a b) fun _ => Finset.mem_Ioc instance instFintypeIoo : Fintype (Ioo a b) := .ofFinset (Finset.Ioo a b) fun _ => Finset.mem_Ioo theorem finite_Icc : (Icc a b).Finite := (Icc a b).toFinite theorem finite_Ico : (Ico a b).Finite := (Ico a b).toFinite theorem finite_Ioc : (Ioc a b).Finite := (Ioc a b).toFinite theorem finite_Ioo : (Ioo a b).Finite := (Ioo a b).toFinite end Preorder section OrderTop variable [Preorder α] [LocallyFiniteOrderTop α] (a : α) instance instFintypeIci : Fintype (Ici a) := .ofFinset (Finset.Ici a) fun _ => Finset.mem_Ici instance instFintypeIoi : Fintype (Ioi a) := .ofFinset (Finset.Ioi a) fun _ => Finset.mem_Ioi theorem finite_Ici : (Ici a).Finite := (Ici a).toFinite theorem finite_Ioi : (Ioi a).Finite := (Ioi a).toFinite end OrderTop section OrderBot variable [Preorder α] [LocallyFiniteOrderBot α] (b : α) instance instFintypeIic : Fintype (Iic b) := .ofFinset (Finset.Iic b) fun _ => Finset.mem_Iic instance instFintypeIio : Fintype (Iio b) := .ofFinset (Finset.Iio b) fun _ => Finset.mem_Iio theorem finite_Iic : (Iic b).Finite := (Iic b).toFinite theorem finite_Iio : (Iio b).Finite := (Iio b).toFinite end OrderBot section Lattice variable [Lattice α] [LocallyFiniteOrder α] (a b : α) instance fintypeUIcc : Fintype (uIcc a b) := Fintype.ofFinset (Finset.uIcc a b) fun _ => Finset.mem_uIcc @[simp] theorem finite_interval : (uIcc a b).Finite := (uIcc _ _).toFinite end Lattice end Set /-! ### Instances -/ section Preorder variable [Preorder α] [Preorder β] /-- A noncomputable constructor from the finiteness of all closed intervals. -/ noncomputable def LocallyFiniteOrder.ofFiniteIcc (h : ∀ a b : α, (Set.Icc a b).Finite) : LocallyFiniteOrder α := @LocallyFiniteOrder.ofIcc' α _ (Classical.decRel _) (fun a b => (h a b).toFinset) fun a b x => by rw [Set.Finite.mem_toFinset, Set.mem_Icc] /-- A fintype is a locally finite order. This is not an instance as it would not be defeq to better instances such as `Fin.locallyFiniteOrder`. -/ abbrev Fintype.toLocallyFiniteOrder [Fintype α] [DecidableLT α] [DecidableLE α] : LocallyFiniteOrder α where finsetIcc a b := (Set.Icc a b).toFinset finsetIco a b := (Set.Ico a b).toFinset finsetIoc a b := (Set.Ioc a b).toFinset finsetIoo a b := (Set.Ioo a b).toFinset finset_mem_Icc a b x := by simp only [Set.mem_toFinset, Set.mem_Icc] finset_mem_Ico a b x := by simp only [Set.mem_toFinset, Set.mem_Ico] finset_mem_Ioc a b x := by simp only [Set.mem_toFinset, Set.mem_Ioc] finset_mem_Ioo a b x := by simp only [Set.mem_toFinset, Set.mem_Ioo] instance : Subsingleton (LocallyFiniteOrder α) := Subsingleton.intro fun h₀ h₁ => by obtain ⟨h₀_finset_Icc, h₀_finset_Ico, h₀_finset_Ioc, h₀_finset_Ioo, h₀_finset_mem_Icc, h₀_finset_mem_Ico, h₀_finset_mem_Ioc, h₀_finset_mem_Ioo⟩ := h₀ obtain ⟨h₁_finset_Icc, h₁_finset_Ico, h₁_finset_Ioc, h₁_finset_Ioo, h₁_finset_mem_Icc, h₁_finset_mem_Ico, h₁_finset_mem_Ioc, h₁_finset_mem_Ioo⟩ := h₁ have hIcc : h₀_finset_Icc = h₁_finset_Icc := by ext a b x rw [h₀_finset_mem_Icc, h₁_finset_mem_Icc] have hIco : h₀_finset_Ico = h₁_finset_Ico := by ext a b x rw [h₀_finset_mem_Ico, h₁_finset_mem_Ico] have hIoc : h₀_finset_Ioc = h₁_finset_Ioc := by ext a b x rw [h₀_finset_mem_Ioc, h₁_finset_mem_Ioc] have hIoo : h₀_finset_Ioo = h₁_finset_Ioo := by ext a b x rw [h₀_finset_mem_Ioo, h₁_finset_mem_Ioo] simp_rw [hIcc, hIco, hIoc, hIoo] instance : Subsingleton (LocallyFiniteOrderTop α) := Subsingleton.intro fun h₀ h₁ => by obtain ⟨h₀_finset_Ioi, h₀_finset_Ici, h₀_finset_mem_Ici, h₀_finset_mem_Ioi⟩ := h₀ obtain ⟨h₁_finset_Ioi, h₁_finset_Ici, h₁_finset_mem_Ici, h₁_finset_mem_Ioi⟩ := h₁ have hIci : h₀_finset_Ici = h₁_finset_Ici := by ext a b rw [h₀_finset_mem_Ici, h₁_finset_mem_Ici] have hIoi : h₀_finset_Ioi = h₁_finset_Ioi := by ext a b rw [h₀_finset_mem_Ioi, h₁_finset_mem_Ioi] simp_rw [hIci, hIoi] instance : Subsingleton (LocallyFiniteOrderBot α) := Subsingleton.intro fun h₀ h₁ => by obtain ⟨h₀_finset_Iio, h₀_finset_Iic, h₀_finset_mem_Iic, h₀_finset_mem_Iio⟩ := h₀ obtain ⟨h₁_finset_Iio, h₁_finset_Iic, h₁_finset_mem_Iic, h₁_finset_mem_Iio⟩ := h₁ have hIic : h₀_finset_Iic = h₁_finset_Iic := by ext a b rw [h₀_finset_mem_Iic, h₁_finset_mem_Iic] have hIio : h₀_finset_Iio = h₁_finset_Iio := by ext a b rw [h₀_finset_mem_Iio, h₁_finset_mem_Iio] simp_rw [hIic, hIio] -- Should this be called `LocallyFiniteOrder.lift`? /-- Given an order embedding `α ↪o β`, pulls back the `LocallyFiniteOrder` on `β` to `α`. -/ protected noncomputable def OrderEmbedding.locallyFiniteOrder [LocallyFiniteOrder β] (f : α ↪o β) : LocallyFiniteOrder α where finsetIcc a b := (Icc (f a) (f b)).preimage f f.toEmbedding.injective.injOn finsetIco a b := (Ico (f a) (f b)).preimage f f.toEmbedding.injective.injOn finsetIoc a b := (Ioc (f a) (f b)).preimage f f.toEmbedding.injective.injOn finsetIoo a b := (Ioo (f a) (f b)).preimage f f.toEmbedding.injective.injOn finset_mem_Icc a b x := by rw [mem_preimage, mem_Icc, f.le_iff_le, f.le_iff_le] finset_mem_Ico a b x := by rw [mem_preimage, mem_Ico, f.le_iff_le, f.lt_iff_lt] finset_mem_Ioc a b x := by rw [mem_preimage, mem_Ioc, f.lt_iff_lt, f.le_iff_le] finset_mem_Ioo a b x := by rw [mem_preimage, mem_Ioo, f.lt_iff_lt, f.lt_iff_lt] /-! ### `OrderDual` -/ open OrderDual section LocallyFiniteOrder variable [LocallyFiniteOrder α] (a b : α) /-- Note we define `Icc (toDual a) (toDual b)` as `Icc α _ _ b a` (which has type `Finset α` not `Finset αᵒᵈ`!) instead of `(Icc b a).map toDual.toEmbedding` as this means the following is defeq: ``` lemma this : (Icc (toDual (toDual a)) (toDual (toDual b)) :) = (Icc a b :) := rfl ``` -/ instance OrderDual.instLocallyFiniteOrder : LocallyFiniteOrder αᵒᵈ where finsetIcc a b := @Icc α _ _ (ofDual b) (ofDual a) finsetIco a b := @Ioc α _ _ (ofDual b) (ofDual a) finsetIoc a b := @Ico α _ _ (ofDual b) (ofDual a) finsetIoo a b := @Ioo α _ _ (ofDual b) (ofDual a) finset_mem_Icc _ _ _ := (mem_Icc (α := α)).trans and_comm finset_mem_Ico _ _ _ := (mem_Ioc (α := α)).trans and_comm finset_mem_Ioc _ _ _ := (mem_Ico (α := α)).trans and_comm finset_mem_Ioo _ _ _ := (mem_Ioo (α := α)).trans and_comm lemma Finset.Icc_orderDual_def (a b : αᵒᵈ) : Icc a b = (Icc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Ico_orderDual_def (a b : αᵒᵈ) : Ico a b = (Ioc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Ioc_orderDual_def (a b : αᵒᵈ) : Ioc a b = (Ico (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Ioo_orderDual_def (a b : αᵒᵈ) : Ioo a b = (Ioo (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Icc_toDual : Icc (toDual a) (toDual b) = (Icc b a).map toDual.toEmbedding := map_refl.symm lemma Finset.Ico_toDual : Ico (toDual a) (toDual b) = (Ioc b a).map toDual.toEmbedding := map_refl.symm lemma Finset.Ioc_toDual : Ioc (toDual a) (toDual b) = (Ico b a).map toDual.toEmbedding := map_refl.symm lemma Finset.Ioo_toDual : Ioo (toDual a) (toDual b) = (Ioo b a).map toDual.toEmbedding := map_refl.symm lemma Finset.Icc_ofDual (a b : αᵒᵈ) : Icc (ofDual a) (ofDual b) = (Icc b a).map ofDual.toEmbedding := map_refl.symm lemma Finset.Ico_ofDual (a b : αᵒᵈ) : Ico (ofDual a) (ofDual b) = (Ioc b a).map ofDual.toEmbedding := map_refl.symm lemma Finset.Ioc_ofDual (a b : αᵒᵈ) : Ioc (ofDual a) (ofDual b) = (Ico b a).map ofDual.toEmbedding := map_refl.symm lemma Finset.Ioo_ofDual (a b : αᵒᵈ) : Ioo (ofDual a) (ofDual b) = (Ioo b a).map ofDual.toEmbedding := map_refl.symm end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] /-- Note we define `Iic (toDual a)` as `Ici a` (which has type `Finset α` not `Finset αᵒᵈ`!) instead of `(Ici a).map toDual.toEmbedding` as this means the following is defeq: ``` lemma this : (Iic (toDual (toDual a)) :) = (Iic a :) := rfl ``` -/ instance OrderDual.instLocallyFiniteOrderBot : LocallyFiniteOrderBot αᵒᵈ where finsetIic a := @Ici α _ _ (ofDual a) finsetIio a := @Ioi α _ _ (ofDual a) finset_mem_Iic _ _ := mem_Ici (α := α) finset_mem_Iio _ _ := mem_Ioi (α := α) lemma Iic_orderDual_def (a : αᵒᵈ) : Iic a = (Ici (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Iio_orderDual_def (a : αᵒᵈ) : Iio a = (Ioi (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Iic_toDual (a : α) : Iic (toDual a) = (Ici a).map toDual.toEmbedding := map_refl.symm lemma Finset.Iio_toDual (a : α) : Iio (toDual a) = (Ioi a).map toDual.toEmbedding := map_refl.symm lemma Finset.Ici_ofDual (a : αᵒᵈ) : Ici (ofDual a) = (Iic a).map ofDual.toEmbedding := map_refl.symm lemma Finset.Ioi_ofDual (a : αᵒᵈ) : Ioi (ofDual a) = (Iio a).map ofDual.toEmbedding := map_refl.symm end LocallyFiniteOrderTop section LocallyFiniteOrderTop variable [LocallyFiniteOrderBot α] /-- Note we define `Ici (toDual a)` as `Iic a` (which has type `Finset α` not `Finset αᵒᵈ`!) instead of `(Iic a).map toDual.toEmbedding` as this means the following is defeq: ``` lemma this : (Ici (toDual (toDual a)) :) = (Ici a :) := rfl ``` -/ instance OrderDual.instLocallyFiniteOrderTop : LocallyFiniteOrderTop αᵒᵈ where finsetIci a := @Iic α _ _ (ofDual a) finsetIoi a := @Iio α _ _ (ofDual a) finset_mem_Ici _ _ := mem_Iic (α := α) finset_mem_Ioi _ _ := mem_Iio (α := α) lemma Ici_orderDual_def (a : αᵒᵈ) : Ici a = (Iic (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Ioi_orderDual_def (a : αᵒᵈ) : Ioi a = (Iio (ofDual a)).map toDual.toEmbedding := map_refl.symm lemma Finset.Ici_toDual (a : α) : Ici (toDual a) = (Iic a).map toDual.toEmbedding := map_refl.symm lemma Finset.Ioi_toDual (a : α) : Ioi (toDual a) = (Iio a).map toDual.toEmbedding := map_refl.symm lemma Finset.Iic_ofDual (a : αᵒᵈ) : Iic (ofDual a) = (Ici a).map ofDual.toEmbedding := map_refl.symm lemma Finset.Iio_ofDual (a : αᵒᵈ) : Iio (ofDual a) = (Ioi a).map ofDual.toEmbedding := map_refl.symm end LocallyFiniteOrderTop /-! ### `Prod` -/ section LocallyFiniteOrder variable [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] instance Prod.instLocallyFiniteOrder : LocallyFiniteOrder (α × β) := LocallyFiniteOrder.ofIcc' (α × β) (fun x y ↦ Icc x.1 y.1 ×ˢ Icc x.2 y.2) fun a b x => by rw [mem_product, mem_Icc, mem_Icc, and_and_and_comm, le_def, le_def] lemma Finset.Icc_prod_def (x y : α × β) : Icc x y = Icc x.1 y.1 ×ˢ Icc x.2 y.2 := rfl lemma Finset.Icc_product_Icc (a₁ a₂ : α) (b₁ b₂ : β) : Icc a₁ a₂ ×ˢ Icc b₁ b₂ = Icc (a₁, b₁) (a₂, b₂) := rfl lemma Finset.card_Icc_prod (x y : α × β) : #(Icc x y) = #(Icc x.1 y.1) * #(Icc x.2 y.2) := card_product .. end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderTop β] [DecidableLE (α × β)] instance Prod.instLocallyFiniteOrderTop : LocallyFiniteOrderTop (α × β) := LocallyFiniteOrderTop.ofIci' (α × β) (fun x => Ici x.1 ×ˢ Ici x.2) fun a x => by rw [mem_product, mem_Ici, mem_Ici, le_def] lemma Finset.Ici_prod_def (x : α × β) : Ici x = Ici x.1 ×ˢ Ici x.2 := rfl lemma Finset.Ici_product_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl lemma Finset.card_Ici_prod (x : α × β) : #(Ici x) = #(Ici x.1) * #(Ici x.2) := card_product _ _ end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] [LocallyFiniteOrderBot β] [DecidableLE (α × β)] instance Prod.instLocallyFiniteOrderBot : LocallyFiniteOrderBot (α × β) := LocallyFiniteOrderBot.ofIic' (α × β) (fun x ↦ Iic x.1 ×ˢ Iic x.2) fun a x ↦ by rw [mem_product, mem_Iic, mem_Iic, le_def] lemma Finset.Iic_prod_def (x : α × β) : Iic x = Iic x.1 ×ˢ Iic x.2 := rfl lemma Finset.Iic_product_Iic (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl lemma Finset.card_Iic_prod (x : α × β) : #(Iic x) = #(Iic x.1) * #(Iic x.2) := card_product .. end LocallyFiniteOrderBot end Preorder section Lattice variable [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] lemma Finset.uIcc_prod_def (x y : α × β) : uIcc x y = uIcc x.1 y.1 ×ˢ uIcc x.2 y.2 := rfl lemma Finset.uIcc_product_uIcc (a₁ a₂ : α) (b₁ b₂ : β) : uIcc a₁ a₂ ×ˢ uIcc b₁ b₂ = uIcc (a₁, b₁) (a₂, b₂) := rfl lemma Finset.card_uIcc_prod (x y : α × β) : #(uIcc x y) = #(uIcc x.1 y.1) * #(uIcc x.2 y.2) := card_product .. end Lattice /-! #### `WithTop`, `WithBot` Adding a `⊤` to a locally finite `OrderTop` keeps it locally finite. Adding a `⊥` to a locally finite `OrderBot` keeps it locally finite. -/ namespace WithTop /-- Given a finset on `α`, lift it to being a finset on `WithTop α` using `WithTop.some` and then insert `⊤`. -/ def insertTop : Finset α ↪o Finset (WithTop α) := OrderEmbedding.ofMapLEIff (fun s => cons ⊤ (s.map Embedding.coeWithTop) <| by simp) (fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset]) @[simp] theorem some_mem_insertTop {s : Finset α} {a : α} : ↑a ∈ insertTop s ↔ a ∈ s := by simp [insertTop] @[simp] theorem top_mem_insertTop {s : Finset α} : ⊤ ∈ insertTop s := by simp [insertTop] variable (α) [PartialOrder α] [OrderTop α] [LocallyFiniteOrder α] instance locallyFiniteOrder : LocallyFiniteOrder (WithTop α) where finsetIcc a b := match a, b with | ⊤, ⊤ => {⊤} | ⊤, (b : α) => ∅ | (a : α), ⊤ => insertTop (Ici a) | (a : α), (b : α) => (Icc a b).map Embedding.coeWithTop finsetIco a b := match a, b with | ⊤, _ => ∅ | (a : α), ⊤ => (Ici a).map Embedding.coeWithTop | (a : α), (b : α) => (Ico a b).map Embedding.coeWithTop finsetIoc a b := match a, b with | ⊤, _ => ∅ | (a : α), ⊤ => insertTop (Ioi a) | (a : α), (b : α) => (Ioc a b).map Embedding.coeWithTop finsetIoo a b := match a, b with | ⊤, _ => ∅ | (a : α), ⊤ => (Ioi a).map Embedding.coeWithTop | (a : α), (b : α) => (Ioo a b).map Embedding.coeWithTop finset_mem_Icc a b x := by cases a <;> cases b <;> cases x <;> simp finset_mem_Ico a b x := by cases a <;> cases b <;> cases x <;> simp finset_mem_Ioc a b x := by cases a <;> cases b <;> cases x <;> simp finset_mem_Ioo a b x := by cases a <;> cases b <;> cases x <;> simp variable (a b : α) theorem Icc_coe_top : Icc (a : WithTop α) ⊤ = insertNone (Ici a) := rfl theorem Icc_coe_coe : Icc (a : WithTop α) b = (Icc a b).map Embedding.some := rfl theorem Ico_coe_top : Ico (a : WithTop α) ⊤ = (Ici a).map Embedding.some := rfl theorem Ico_coe_coe : Ico (a : WithTop α) b = (Ico a b).map Embedding.some := rfl theorem Ioc_coe_top : Ioc (a : WithTop α) ⊤ = insertNone (Ioi a) := rfl theorem Ioc_coe_coe : Ioc (a : WithTop α) b = (Ioc a b).map Embedding.some := rfl theorem Ioo_coe_top : Ioo (a : WithTop α) ⊤ = (Ioi a).map Embedding.some := rfl theorem Ioo_coe_coe : Ioo (a : WithTop α) b = (Ioo a b).map Embedding.some := rfl end WithTop namespace WithBot /-- Given a finset on `α`, lift it to being a finset on `WithBot α` using `WithBot.some` and then insert `⊥`. -/ def insertBot : Finset α ↪o Finset (WithBot α) := OrderEmbedding.ofMapLEIff (fun s => cons ⊥ (s.map Embedding.coeWithBot) <| by simp) (fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset]) @[simp] theorem some_mem_insertBot {s : Finset α} {a : α} : ↑a ∈ insertBot s ↔ a ∈ s := by simp [insertBot] @[simp] theorem bot_mem_insertBot {s : Finset α} : ⊥ ∈ insertBot s := by simp [insertBot] variable (α) [PartialOrder α] [OrderBot α] [LocallyFiniteOrder α] instance instLocallyFiniteOrder : LocallyFiniteOrder (WithBot α) := OrderDual.instLocallyFiniteOrder (α := WithTop αᵒᵈ) variable (a b : α) theorem Icc_bot_coe : Icc (⊥ : WithBot α) b = insertNone (Iic b) := rfl theorem Icc_coe_coe : Icc (a : WithBot α) b = (Icc a b).map Embedding.some := rfl theorem Ico_bot_coe : Ico (⊥ : WithBot α) b = insertNone (Iio b) := rfl theorem Ico_coe_coe : Ico (a : WithBot α) b = (Ico a b).map Embedding.some := rfl theorem Ioc_bot_coe : Ioc (⊥ : WithBot α) b = (Iic b).map Embedding.some := rfl theorem Ioc_coe_coe : Ioc (a : WithBot α) b = (Ioc a b).map Embedding.some := rfl theorem Ioo_bot_coe : Ioo (⊥ : WithBot α) b = (Iio b).map Embedding.some := rfl theorem Ioo_coe_coe : Ioo (a : WithBot α) b = (Ioo a b).map Embedding.some := rfl end WithBot namespace OrderIso variable [Preorder α] [Preorder β] /-! #### Transfer locally finite orders across order isomorphisms -/ -- See note [reducible non-instances] /-- Transfer `LocallyFiniteOrder` across an `OrderIso`. -/ abbrev locallyFiniteOrder [LocallyFiniteOrder β] (f : α ≃o β) : LocallyFiniteOrder α where finsetIcc a b := (Icc (f a) (f b)).map f.symm.toEquiv.toEmbedding finsetIco a b := (Ico (f a) (f b)).map f.symm.toEquiv.toEmbedding finsetIoc a b := (Ioc (f a) (f b)).map f.symm.toEquiv.toEmbedding finsetIoo a b := (Ioo (f a) (f b)).map f.symm.toEquiv.toEmbedding finset_mem_Icc := by simp finset_mem_Ico := by simp finset_mem_Ioc := by simp finset_mem_Ioo := by simp -- See note [reducible non-instances] /-- Transfer `LocallyFiniteOrderTop` across an `OrderIso`. -/ abbrev locallyFiniteOrderTop [LocallyFiniteOrderTop β] (f : α ≃o β) : LocallyFiniteOrderTop α where finsetIci a := (Ici (f a)).map f.symm.toEquiv.toEmbedding finsetIoi a := (Ioi (f a)).map f.symm.toEquiv.toEmbedding finset_mem_Ici := by simp finset_mem_Ioi := by simp -- See note [reducible non-instances] /-- Transfer `LocallyFiniteOrderBot` across an `OrderIso`. -/ abbrev locallyFiniteOrderBot [LocallyFiniteOrderBot β] (f : α ≃o β) : LocallyFiniteOrderBot α where finsetIic a := (Iic (f a)).map f.symm.toEquiv.toEmbedding finsetIio a := (Iio (f a)).map f.symm.toEquiv.toEmbedding finset_mem_Iic := by simp finset_mem_Iio := by simp end OrderIso /-! #### Subtype of a locally finite order -/ variable [Preorder α] (p : α → Prop) [DecidablePred p] instance Subtype.instLocallyFiniteOrder [LocallyFiniteOrder α] : LocallyFiniteOrder (Subtype p) where finsetIcc a b := (Icc (a : α) b).subtype p finsetIco a b := (Ico (a : α) b).subtype p finsetIoc a b := (Ioc (a : α) b).subtype p finsetIoo a b := (Ioo (a : α) b).subtype p finset_mem_Icc a b x := by simp_rw [Finset.mem_subtype, mem_Icc, Subtype.coe_le_coe] finset_mem_Ico a b x := by simp_rw [Finset.mem_subtype, mem_Ico, Subtype.coe_le_coe, Subtype.coe_lt_coe] finset_mem_Ioc a b x := by simp_rw [Finset.mem_subtype, mem_Ioc, Subtype.coe_le_coe, Subtype.coe_lt_coe] finset_mem_Ioo a b x := by simp_rw [Finset.mem_subtype, mem_Ioo, Subtype.coe_lt_coe] instance Subtype.instLocallyFiniteOrderTop [LocallyFiniteOrderTop α] : LocallyFiniteOrderTop (Subtype p) where finsetIci a := (Ici (a : α)).subtype p finsetIoi a := (Ioi (a : α)).subtype p finset_mem_Ici a x := by simp_rw [Finset.mem_subtype, mem_Ici, Subtype.coe_le_coe] finset_mem_Ioi a x := by simp_rw [Finset.mem_subtype, mem_Ioi, Subtype.coe_lt_coe] instance Subtype.instLocallyFiniteOrderBot [LocallyFiniteOrderBot α] : LocallyFiniteOrderBot (Subtype p) where finsetIic a := (Iic (a : α)).subtype p finsetIio a := (Iio (a : α)).subtype p finset_mem_Iic a x := by simp_rw [Finset.mem_subtype, mem_Iic, Subtype.coe_le_coe] finset_mem_Iio a x := by simp_rw [Finset.mem_subtype, mem_Iio, Subtype.coe_lt_coe] namespace Finset section LocallyFiniteOrder variable [LocallyFiniteOrder α] (a b : Subtype p) theorem subtype_Icc_eq : Icc a b = (Icc (a : α) b).subtype p := rfl theorem subtype_Ico_eq : Ico a b = (Ico (a : α) b).subtype p := rfl theorem subtype_Ioc_eq : Ioc a b = (Ioc (a : α) b).subtype p := rfl theorem subtype_Ioo_eq : Ioo a b = (Ioo (a : α) b).subtype p := rfl theorem map_subtype_embedding_Icc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) : (Icc a b).map (Embedding.subtype p) = (Icc a b : Finset α) := by rw [subtype_Icc_eq] refine Finset.subtype_map_of_mem fun x hx => ?_ rw [mem_Icc] at hx exact hp hx.1 hx.2 a.prop b.prop theorem map_subtype_embedding_Ico (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) : (Ico a b).map (Embedding.subtype p) = (Ico a b : Finset α) := by rw [subtype_Ico_eq] refine Finset.subtype_map_of_mem fun x hx => ?_ rw [mem_Ico] at hx exact hp hx.1 hx.2.le a.prop b.prop theorem map_subtype_embedding_Ioc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) : (Ioc a b).map (Embedding.subtype p) = (Ioc a b : Finset α) := by rw [subtype_Ioc_eq] refine Finset.subtype_map_of_mem fun x hx => ?_ rw [mem_Ioc] at hx exact hp hx.1.le hx.2 a.prop b.prop theorem map_subtype_embedding_Ioo (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) : (Ioo a b).map (Embedding.subtype p) = (Ioo a b : Finset α) := by rw [subtype_Ioo_eq] refine Finset.subtype_map_of_mem fun x hx => ?_ rw [mem_Ioo] at hx exact hp hx.1.le hx.2.le a.prop b.prop end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] (a : Subtype p) theorem subtype_Ici_eq : Ici a = (Ici (a : α)).subtype p := rfl theorem subtype_Ioi_eq : Ioi a = (Ioi (a : α)).subtype p := rfl theorem map_subtype_embedding_Ici (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) : (Ici a).map (Embedding.subtype p) = (Ici a : Finset α) := by rw [subtype_Ici_eq] exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ici.1 hx) a.prop theorem map_subtype_embedding_Ioi (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) : (Ioi a).map (Embedding.subtype p) = (Ioi a : Finset α) := by rw [subtype_Ioi_eq] exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ioi.1 hx).le a.prop end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] (a : Subtype p) theorem subtype_Iic_eq : Iic a = (Iic (a : α)).subtype p := rfl theorem subtype_Iio_eq : Iio a = (Iio (a : α)).subtype p := rfl theorem map_subtype_embedding_Iic (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) : (Iic a).map (Embedding.subtype p) = (Iic a : Finset α) := by rw [subtype_Iic_eq] exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iic.1 hx) a.prop theorem map_subtype_embedding_Iio (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) : (Iio a).map (Embedding.subtype p) = (Iio a : Finset α) := by rw [subtype_Iio_eq] exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iio.1 hx).le a.prop end LocallyFiniteOrderBot end Finset section Finite variable {α : Type*} {s : Set α} theorem BddBelow.finite_of_bddAbove [Preorder α] [LocallyFiniteOrder α] {s : Set α} (h₀ : BddBelow s) (h₁ : BddAbove s) : s.Finite := let ⟨a, ha⟩ := h₀ let ⟨b, hb⟩ := h₁ (Set.finite_Icc a b).subset fun _x hx ↦ ⟨ha hx, hb hx⟩ theorem Set.finite_iff_bddAbove [SemilatticeSup α] [LocallyFiniteOrder α] [OrderBot α] : s.Finite ↔ BddAbove s := ⟨fun h ↦ ⟨h.toFinset.sup id, fun _ hx ↦ Finset.le_sup (f := id) ((Finite.mem_toFinset h).mpr hx)⟩, fun ⟨m, hm⟩ ↦ (Set.finite_Icc ⊥ m).subset (fun _ hx ↦ ⟨bot_le, hm hx⟩)⟩ theorem Set.finite_iff_bddBelow [SemilatticeInf α] [LocallyFiniteOrder α] [OrderTop α] : s.Finite ↔ BddBelow s := finite_iff_bddAbove (α := αᵒᵈ) theorem Set.finite_iff_bddBelow_bddAbove [Nonempty α] [Lattice α] [LocallyFiniteOrder α] : s.Finite ↔ BddBelow s ∧ BddAbove s := by obtain (rfl | hs) := s.eq_empty_or_nonempty · simp only [Set.finite_empty, bddBelow_empty, bddAbove_empty, and_self] exact ⟨fun h ↦ ⟨⟨h.toFinset.inf' ((Finite.toFinset_nonempty h).mpr hs) id, fun x hx ↦ Finset.inf'_le id ((Finite.mem_toFinset h).mpr hx)⟩, ⟨h.toFinset.sup' ((Finite.toFinset_nonempty h).mpr hs) id, fun x hx ↦ Finset.le_sup' id ((Finite.mem_toFinset h).mpr hx)⟩⟩, fun ⟨h₀, h₁⟩ ↦ BddBelow.finite_of_bddAbove h₀ h₁⟩ end Finite /-! We make the instances below low priority so when alternative constructions are available they are preferred. -/ variable {y : α} instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] : LocallyFiniteOrderTop { x : α // x ≤ y } where finsetIoi a := Finset.Ioc a ⟨y, by rfl⟩ finsetIci a := Finset.Icc a ⟨y, by rfl⟩ finset_mem_Ici a b := by simp only [Finset.mem_Icc, and_iff_left_iff_imp] exact fun _ => b.property finset_mem_Ioi a b := by simp only [Finset.mem_Ioc, and_iff_left_iff_imp] exact fun _ => b.property instance (priority := low) [Preorder α] [DecidableLT α] [LocallyFiniteOrder α] : LocallyFiniteOrderTop { x : α // x < y } where finsetIoi a := (Finset.Ioo ↑a y).subtype _ finsetIci a := (Finset.Ico ↑a y).subtype _ finset_mem_Ici a b := by simp only [Finset.mem_subtype, Finset.mem_Ico, Subtype.coe_le_coe, and_iff_left_iff_imp] exact fun _ => b.property finset_mem_Ioi a b := by simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_left_iff_imp] exact fun _ => b.property instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] : LocallyFiniteOrderBot { x : α // y ≤ x } where finsetIio a := Finset.Ico ⟨y, by rfl⟩ a finsetIic a := Finset.Icc ⟨y, by rfl⟩ a finset_mem_Iic a b := by simp only [Finset.mem_Icc, and_iff_right_iff_imp] exact fun _ => b.property finset_mem_Iio a b := by simp only [Finset.mem_Ico, and_iff_right_iff_imp] exact fun _ => b.property instance (priority := low) [Preorder α] [DecidableLT α] [LocallyFiniteOrder α] : LocallyFiniteOrderBot { x : α // y < x } where finsetIio a := (Finset.Ioo y ↑a).subtype _ finsetIic a := (Finset.Ioc y ↑a).subtype _ finset_mem_Iic a b := by simp only [Finset.mem_subtype, Finset.mem_Ioc, Subtype.coe_le_coe, and_iff_right_iff_imp] exact fun _ => b.property finset_mem_Iio a b := by simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_right_iff_imp] exact fun _ => b.property instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x ≤ y } := by simpa only [coe_Iic] using (Finset.Iic y).finite_toSet instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x < y } := by simpa only [coe_Iio] using (Finset.Iio y).finite_toSet instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y ≤ x } := by simpa only [coe_Ici] using (Finset.Ici y).finite_toSet instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y < x } := by simpa only [coe_Ioi] using (Finset.Ioi y).finite_toSet namespace Set variable {α : Type*} [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] lemma toFinset_Icc (a b : α) [Fintype (Icc a b)] : (Icc a b).toFinset = Finset.Icc a b := by ext; simp @[simp] lemma toFinset_Ico (a b : α) [Fintype (Ico a b)] : (Ico a b).toFinset = Finset.Ico a b := by ext; simp @[simp] lemma toFinset_Ioc (a b : α) [Fintype (Ioc a b)] : (Ioc a b).toFinset = Finset.Ioc a b := by ext; simp @[simp] lemma toFinset_Ioo (a b : α) [Fintype (Ioo a b)] : (Ioo a b).toFinset = Finset.Ioo a b := by ext; simp end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] lemma toFinset_Ici (a : α) [Fintype (Ici a)] : (Ici a).toFinset = Finset.Ici a := by ext; simp @[simp] lemma toFinset_Ioi (a : α) [Fintype (Ioi a)] : (Ioi a).toFinset = Finset.Ioi a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] lemma toFinset_Iic (a : α) [Fintype (Iic a)] : (Iic a).toFinset = Finset.Iic a := by ext; simp @[simp] lemma toFinset_Iio (a : α) [Fintype (Iio a)] : (Iio a).toFinset = Finset.Iio a := by ext; simp end LocallyFiniteOrderBot end Set /-- A `LocallyFiniteOrder` can be transferred across an order isomorphism. -/ -- See note [reducible non-instances] abbrev LocallyFiniteOrder.ofOrderIsoClass {F M N : Type*} [Preorder M] [Preorder N] [EquivLike F M N] [OrderIsoClass F M N] (f : F) [LocallyFiniteOrder N] : LocallyFiniteOrder M where finsetIcc x y := (finsetIcc (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩ finsetIco x y := (finsetIco (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩ finsetIoc x y := (finsetIoc (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩ finsetIoo x y := (finsetIoo (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩ finset_mem_Icc := by simp [finset_mem_Icc, EquivLike.inv_apply_eq] finset_mem_Ico := by simp [finset_mem_Ico, EquivLike.inv_apply_eq, map_lt_map_iff] finset_mem_Ioc := by simp [finset_mem_Ioc, EquivLike.inv_apply_eq, map_lt_map_iff] finset_mem_Ioo := by simp [finset_mem_Ioo, EquivLike.inv_apply_eq, map_lt_map_iff]
.lake/packages/mathlib/Mathlib/Order/Interval/Finset/Box.lean
import Mathlib.Algebra.Order.Disjointed import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.Order.Ring.Prod import Mathlib.Data.Int.Interval import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify /-! # Decomposing a locally finite ordered ring into boxes This file proves that any locally finite ordered ring can be decomposed into "boxes", namely differences of consecutive intervals. ## Implementation notes We don't need the full ring structure, only that there is an order embedding `ℤ → ` -/ /-! ### General locally finite ordered ring -/ namespace Finset variable {α : Type*} [Ring α] [PartialOrder α] [IsOrderedRing α] [LocallyFiniteOrder α] {n : ℕ} private lemma Icc_neg_mono : Monotone fun n : ℕ ↦ Icc (-n : α) n := by refine fun m n hmn ↦ by apply Icc_subset_Icc <;> simpa using Nat.mono_cast hmn variable [DecidableEq α] /-- Hollow box centered at `0 : α` going from `-n` to `n`. -/ def box : ℕ → Finset α := disjointed fun n ↦ Icc (-n : α) n omit [IsOrderedRing α] in @[simp] lemma box_zero : (box 0 : Finset α) = {0} := by simp [box] lemma box_succ_eq_sdiff (n : ℕ) : box (n + 1) = Icc (-n.succ : α) n.succ \ Icc (-n) n := by rw [box, Icc_neg_mono.disjointed_add_one] simp only [Nat.cast_add_one, Nat.succ_eq_add_one] lemma disjoint_box_succ_prod (n : ℕ) : Disjoint (box (n + 1)) (Icc (-n : α) n) := by rw [box_succ_eq_sdiff]; exact disjoint_sdiff_self_left @[simp] lemma box_succ_union_prod (n : ℕ) : box (n + 1) ∪ Icc (-n : α) n = Icc (-n.succ : α) n.succ := Icc_neg_mono.disjointed_add_one_sup _ lemma box_succ_disjUnion (n : ℕ) : (box (n + 1)).disjUnion (Icc (-n : α) n) (disjoint_box_succ_prod _) = Icc (-n.succ : α) n.succ := by rw [disjUnion_eq_union, box_succ_union_prod] @[simp] lemma zero_mem_box : (0 : α) ∈ box n ↔ n = 0 := by cases n <;> simp [box_succ_eq_sdiff] lemma eq_zero_iff_eq_zero_of_mem_box {x : α} (hx : x ∈ box n) : x = 0 ↔ n = 0 := ⟨zero_mem_box.mp ∘ (· ▸ hx), fun hn ↦ by rwa [hn, box_zero, mem_singleton] at hx⟩ end Finset open Finset /-! ### Product of locally finite ordered rings -/ namespace Prod variable {α β : Type*} [Ring α] [PartialOrder α] [IsOrderedRing α] [Ring β] [PartialOrder β] [IsOrderedRing β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableEq α] [DecidableEq β] [DecidableLE (α × β)] @[simp] lemma card_box_succ (n : ℕ) : #(box (n + 1) : Finset (α × β)) = #(Icc (-n.succ : α) n.succ) * #(Icc (-n.succ : β) n.succ) - #(Icc (-n : α) n) * #(Icc (-n : β) n) := by rw [box_succ_eq_sdiff, card_sdiff_of_subset (Icc_neg_mono n.le_succ), Finset.card_Icc_prod, Finset.card_Icc_prod] simp_rw [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one, neg_add_rev, fst_add, fst_neg, fst_one, fst_natCast, snd_add, snd_neg, snd_one, snd_natCast] end Prod /-! ### `ℤ × ℤ` -/ namespace Int variable {x : ℤ × ℤ} attribute [norm_cast] toNat_ofNat lemma card_box : ∀ {n}, n ≠ 0 → #(box n : Finset (ℤ × ℤ)) = 8 * n | n + 1, _ => by simp_rw [Prod.card_box_succ, card_Icc, sub_neg_eq_add] norm_cast refine tsub_eq_of_eq_add ?_ zify ring @[simp] lemma mem_box : ∀ {n}, x ∈ box n ↔ max x.1.natAbs x.2.natAbs = n | 0 => by simp [Prod.ext_iff] | n + 1 => by simp [box_succ_eq_sdiff, Prod.le_def] omega -- TODO: Can this be generalised to locally finite archimedean ordered rings? lemma existsUnique_mem_box (x : ℤ × ℤ) : ∃! n : ℕ, x ∈ box n := by use max x.1.natAbs x.2.natAbs; simp only [mem_box, and_self_iff, forall_eq'] end Int
.lake/packages/mathlib/Mathlib/Order/Interval/Set/IsoIoo.lean
import Mathlib.Order.Monotone.Odd import Mathlib.Algebra.Order.Field.Basic import Mathlib.Tactic.FieldSimp /-! # Order isomorphism between a linear ordered field and `(-1, 1)` In this file we provide an order isomorphism `orderIsoIooNegOneOne` between the open interval `(-1, 1)` in a linear ordered field and the whole field. -/ open Set /-- In a linear ordered field, the whole field is order isomorphic to the open interval `(-1, 1)`. We consider the actual implementation to be a "black box", so it is irreducible. -/ @[irreducible] def orderIsoIooNegOneOne (k : Type*) [Field k] [LinearOrder k] [IsStrictOrderedRing k] : k ≃o Ioo (-1 : k) 1 := by refine StrictMono.orderIsoOfRightInverse ?_ ?_ (fun x ↦ x / (1 - |↑x|)) ?_ · refine codRestrict (fun x ↦ x / (1 + |x|)) _ fun x ↦ abs_lt.1 ?_ have H : 0 < 1 + |x| := (abs_nonneg x).trans_lt (lt_one_add _) calc |x / (1 + |x|)| = |x| / (1 + |x|) := by rw [abs_div, abs_of_pos H] _ < 1 := (div_lt_one H).2 (lt_one_add _) · refine (strictMono_of_odd_strictMonoOn_nonneg ?_ ?_).codRestrict _ · intro x simp only [abs_neg, neg_div] · rintro x (hx : 0 ≤ x) y (hy : 0 ≤ y) hxy simp [abs_of_nonneg, mul_add, mul_comm x y, div_lt_div_iff₀, hx.trans_lt (lt_one_add _), hy.trans_lt (lt_one_add _), *] · refine fun x ↦ Subtype.ext ?_ have : 0 < 1 - |(x : k)| := sub_pos.2 (abs_lt.2 x.2) simp [field, abs_div, abs_of_pos this]
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Limit.lean
import Mathlib.Order.SetIsMax import Mathlib.Order.SuccPred.Limit /-! # Limit elements in Set.Ici If `J` is a linearly ordered type, `j : J`, and `m : Set.Ici j` is successor limit, then `↑m : J` is also successor limit. -/ universe u namespace Set.Ici lemma isSuccLimit_coe {J : Type u} [LinearOrder J] {j : J} (m : Set.Ici j) (hm : Order.IsSuccLimit m) : Order.IsSuccLimit m.1 := ⟨Set.not_isMin_coe _ hm.1, fun b ↦ by simp only [CovBy, not_lt, not_and, not_forall, not_le] intro hb by_cases hb' : j ≤ b · have := hm.2 ⟨b, hb'⟩ rw [not_covBy_iff (by exact hb)] at this obtain ⟨⟨x, h₁⟩, h₂, h₃⟩ := this refine ⟨x, h₂, h₃⟩ · simp only [not_le] at hb' refine ⟨j, hb', ?_⟩ by_contra! apply hm.1 rintro ⟨k, hk⟩ _ exact this.trans (by simpa using hk)⟩ end Set.Ici
.lake/packages/mathlib/Mathlib/Order/Interval/Set/UnorderedInterval.lean
import Mathlib.Data.Set.Order import Mathlib.Order.Bounds.Basic import Mathlib.Order.Interval.Set.Image import Mathlib.Order.Interval.Set.LinearOrder import Mathlib.Tactic.Common import Mathlib.Order.MinMax /-! # Intervals without endpoints ordering In any lattice `α`, we define `uIcc a b` to be `Icc (a ⊓ b) (a ⊔ b)`, which in a linear order is the set of elements lying between `a` and `b`. `Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The interval as defined in this file is always the set of things lying between `a` and `b`, regardless of the relative order of `a` and `b`. For real numbers, `uIcc a b` is the same as `segment ℝ a b`. In a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example, `uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`, `(-1, 1)`, `(1, 1)`. In `Finset α` (seen as a hypercube of dimension `Fintype.card α`), `uIcc a b` is the smallest subcube containing both `a` and `b`. ## Notation We use the localized notation `[[a, b]]` for `uIcc a b`. One can open the scope `Interval` to make the notation available. -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Lattice variable [Lattice α] [Lattice β] {a a₁ a₂ b b₁ b₂ x : α} /-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. Note that we define it more generally in a lattice as `Set.Icc (a ⊓ b) (a ⊔ b)`. In a product type, `uIcc` corresponds to the bounding box of the two elements. -/ def uIcc (a b : α) : Set α := Icc (a ⊓ b) (a ⊔ b) /-- `[[a, b]]` denotes the set of elements lying between `a` and `b`, inclusive. -/ scoped[Interval] notation "[[" a ", " b "]]" => Set.uIcc a b open Interval @[simp] lemma uIcc_toDual (a b : α) : [[toDual a, toDual b]] = ofDual ⁻¹' [[a, b]] := -- Note: needed to hint `(α := α)` after https://github.com/leanprover-community/mathlib4/pull/8386 (elaboration order?) Icc_toDual (α := α) @[simp] theorem uIcc_ofDual (a b : αᵒᵈ) : [[ofDual a, ofDual b]] = toDual ⁻¹' [[a, b]] := Icc_ofDual @[simp] lemma uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] @[simp] lemma uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h] lemma uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by simp_rw [uIcc, inf_comm, sup_comm] lemma uIcc_of_lt (h : a < b) : [[a, b]] = Icc a b := uIcc_of_le h.le lemma uIcc_of_gt (h : b < a) : [[a, b]] = Icc b a := uIcc_of_ge h.le lemma uIcc_self : [[a, a]] = {a} := by simp [uIcc] @[simp] lemma nonempty_uIcc : [[a, b]].Nonempty := nonempty_Icc.2 inf_le_sup lemma Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right lemma Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left @[simp] lemma left_mem_uIcc : a ∈ [[a, b]] := ⟨inf_le_left, le_sup_left⟩ @[simp] lemma right_mem_uIcc : b ∈ [[a, b]] := ⟨inf_le_right, le_sup_right⟩ lemma mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc ⟨ha, hb⟩ lemma mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' ⟨hb, ha⟩ lemma uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) : [[a₁, b₁]] ⊆ [[a₂, b₂]] := Icc_subset_Icc (le_inf h₁.1 h₂.1) (sup_le h₁.2 h₂.2) lemma uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := Icc_subset_Icc (le_inf ha.1 hb.1) (sup_le ha.2 hb.2) lemma uIcc_subset_uIcc_iff_mem : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] := Iff.intro (fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩) fun h => uIcc_subset_uIcc h.1 h.2 lemma uIcc_subset_uIcc_iff_le' : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ := Icc_subset_Icc_iff inf_le_sup lemma uIcc_subset_uIcc_right (h : x ∈ [[a, b]]) : [[x, b]] ⊆ [[a, b]] := uIcc_subset_uIcc h right_mem_uIcc lemma uIcc_subset_uIcc_left (h : x ∈ [[a, b]]) : [[a, x]] ⊆ [[a, b]] := uIcc_subset_uIcc left_mem_uIcc h lemma bdd_below_bdd_above_iff_subset_uIcc (s : Set α) : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ [[a, b]] := bddBelow_bddAbove_iff_subset_Icc.trans ⟨fun ⟨a, b, h⟩ => ⟨a, b, fun _ hx => Icc_subset_uIcc (h hx)⟩, fun ⟨_, _, h⟩ => ⟨_, _, h⟩⟩ section Prod @[simp] theorem uIcc_prod_uIcc (a₁ a₂ : α) (b₁ b₂ : β) : [[a₁, a₂]] ×ˢ [[b₁, b₂]] = [[(a₁, b₁), (a₂, b₂)]] := Icc_prod_Icc _ _ _ _ theorem uIcc_prod_eq (a b : α × β) : [[a, b]] = [[a.1, b.1]] ×ˢ [[a.2, b.2]] := by simp end Prod end Lattice open Interval section DistribLattice variable [DistribLattice α] {a b c : α} lemma eq_of_mem_uIcc_of_mem_uIcc (ha : a ∈ [[b, c]]) (hb : b ∈ [[a, c]]) : a = b := eq_of_inf_eq_sup_eq (inf_congr_right ha.1 hb.1) <| sup_congr_right ha.2 hb.2 lemma eq_of_mem_uIcc_of_mem_uIcc' : b ∈ [[a, c]] → c ∈ [[a, b]] → b = c := by simpa only [uIcc_comm a] using eq_of_mem_uIcc_of_mem_uIcc lemma uIcc_injective_right (a : α) : Injective fun b => uIcc b a := fun b c h => by rw [Set.ext_iff] at h exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc) lemma uIcc_injective_left (a : α) : Injective (uIcc a) := by simpa only [uIcc_comm] using uIcc_injective_right a end DistribLattice section LinearOrder variable [LinearOrder α] section Lattice variable [Lattice β] {f : α → β} {a b : α} lemma _root_.MonotoneOn.mapsTo_uIcc (hf : MonotoneOn f (uIcc a b)) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) := by rw [uIcc, uIcc, ← hf.map_sup, ← hf.map_inf] <;> apply_rules [left_mem_uIcc, right_mem_uIcc, hf.mapsTo_Icc] lemma _root_.AntitoneOn.mapsTo_uIcc (hf : AntitoneOn f (uIcc a b)) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) := by rw [uIcc, uIcc, ← hf.map_sup, ← hf.map_inf] <;> apply_rules [left_mem_uIcc, right_mem_uIcc, hf.mapsTo_Icc] lemma _root_.Monotone.mapsTo_uIcc (hf : Monotone f) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) := (hf.monotoneOn _).mapsTo_uIcc lemma _root_.Antitone.mapsTo_uIcc (hf : Antitone f) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) := (hf.antitoneOn _).mapsTo_uIcc lemma _root_.MonotoneOn.image_uIcc_subset (hf : MonotoneOn f (uIcc a b)) : f '' uIcc a b ⊆ uIcc (f a) (f b) := hf.mapsTo_uIcc.image_subset lemma _root_.AntitoneOn.image_uIcc_subset (hf : AntitoneOn f (uIcc a b)) : f '' uIcc a b ⊆ uIcc (f a) (f b) := hf.mapsTo_uIcc.image_subset lemma _root_.Monotone.image_uIcc_subset (hf : Monotone f) : f '' uIcc a b ⊆ uIcc (f a) (f b) := (hf.monotoneOn _).image_uIcc_subset lemma _root_.Antitone.image_uIcc_subset (hf : Antitone f) : f '' uIcc a b ⊆ uIcc (f a) (f b) := (hf.antitoneOn _).image_uIcc_subset end Lattice variable [LinearOrder β] {f : α → β} {s : Set α} {a a₁ a₂ b b₁ b₂ c : α} theorem Icc_min_max : Icc (min a b) (max a b) = [[a, b]] := rfl lemma uIcc_of_not_le (h : ¬a ≤ b) : [[a, b]] = Icc b a := uIcc_of_gt <| lt_of_not_ge h lemma uIcc_of_not_ge (h : ¬b ≤ a) : [[a, b]] = Icc a b := uIcc_of_lt <| lt_of_not_ge h lemma uIcc_eq_union : [[a, b]] = Icc a b ∪ Icc b a := by rw [Icc_union_Icc', max_comm] <;> rfl lemma mem_uIcc : a ∈ [[b, c]] ↔ b ≤ a ∧ a ≤ c ∨ c ≤ a ∧ a ≤ b := by simp [uIcc_eq_union] lemma notMem_uIcc_of_lt (ha : c < a) (hb : c < b) : c ∉ [[a, b]] := notMem_Icc_of_lt <| lt_min_iff.mpr ⟨ha, hb⟩ @[deprecated (since := "2025-05-23")] alias not_mem_uIcc_of_lt := notMem_uIcc_of_lt lemma notMem_uIcc_of_gt (ha : a < c) (hb : b < c) : c ∉ [[a, b]] := notMem_Icc_of_gt <| max_lt_iff.mpr ⟨ha, hb⟩ @[deprecated (since := "2025-05-23")] alias not_mem_uIcc_of_gt := notMem_uIcc_of_gt lemma uIcc_subset_uIcc_iff_le : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ := uIcc_subset_uIcc_iff_le' /-- A sort of triangle inequality. -/ lemma uIcc_subset_uIcc_union_uIcc : [[a, c]] ⊆ [[a, b]] ∪ [[b, c]] := fun x => by simp only [mem_uIcc, mem_union] rcases le_total x b with h2 | h2 <;> tauto lemma monotone_or_antitone_iff_uIcc : Monotone f ∨ Antitone f ↔ ∀ a b c, c ∈ [[a, b]] → f c ∈ [[f a, f b]] := by constructor · rintro (hf | hf) a b c <;> simp_rw [← Icc_min_max, ← hf.map_min, ← hf.map_max] exacts [fun hc => ⟨hf hc.1, hf hc.2⟩, fun hc => ⟨hf hc.2, hf hc.1⟩] contrapose! rw [not_monotone_not_antitone_iff_exists_le_le] rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩ · exact ⟨a, c, b, Icc_subset_uIcc ⟨hab, hbc⟩, fun h => h.2.not_gt <| max_lt hfab hfcb⟩ · exact ⟨a, c, b, Icc_subset_uIcc ⟨hab, hbc⟩, fun h => h.1.not_gt <| lt_min hfba hfbc⟩ lemma monotoneOn_or_antitoneOn_iff_uIcc : MonotoneOn f s ∨ AntitoneOn f s ↔ ∀ᵉ (a ∈ s) (b ∈ s) (c ∈ s), c ∈ [[a, b]] → f c ∈ [[f a, f b]] := by simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, monotone_or_antitone_iff_uIcc, mem_uIcc] /-- The open-closed uIcc with unordered bounds. -/ def uIoc : α → α → Set α := fun a b => Ioc (min a b) (max a b) -- Below is a capital iota /-- `Ι a b` denotes the open-closed interval with unordered bounds. Here, `Ι` is a capital iota, distinguished from a capital `i`. -/ scoped[Interval] notation "Ι" => Set.uIoc open scoped Interval @[simp] lemma uIoc_of_le (h : a ≤ b) : Ι a b = Ioc a b := by simp [uIoc, h] @[simp] lemma uIoc_of_ge (h : b ≤ a) : Ι a b = Ioc b a := by simp [uIoc, h] lemma uIoc_eq_union : Ι a b = Ioc a b ∪ Ioc b a := by cases le_total a b <;> simp [uIoc, *] lemma mem_uIoc : a ∈ Ι b c ↔ b < a ∧ a ≤ c ∨ c < a ∧ a ≤ b := by rw [uIoc_eq_union, mem_union, mem_Ioc, mem_Ioc] lemma notMem_uIoc : a ∉ Ι b c ↔ a ≤ b ∧ a ≤ c ∨ c < a ∧ b < a := by simp only [uIoc_eq_union, mem_union, mem_Ioc, ← not_le] tauto @[deprecated (since := "2025-05-23")] alias not_mem_uIoc := notMem_uIoc @[simp] lemma left_mem_uIoc : a ∈ Ι a b ↔ b < a := by simp [mem_uIoc] @[simp] lemma right_mem_uIoc : b ∈ Ι a b ↔ a < b := by simp [mem_uIoc] lemma forall_uIoc_iff {P : α → Prop} : (∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ ∀ x ∈ Ioc b a, P x := by simp only [uIoc_eq_union, mem_union, or_imp, forall_and] lemma uIoc_subset_uIoc_of_uIcc_subset_uIcc {a b c d : α} (h : [[a, b]] ⊆ [[c, d]]) : Ι a b ⊆ Ι c d := Ioc_subset_Ioc (uIcc_subset_uIcc_iff_le.1 h).1 (uIcc_subset_uIcc_iff_le.1 h).2 lemma uIoc_comm (a b : α) : Ι a b = Ι b a := by simp only [uIoc, min_comm a b, max_comm a b] lemma Ioc_subset_uIoc : Ioc a b ⊆ Ι a b := Ioc_subset_Ioc (min_le_left _ _) (le_max_right _ _) lemma Ioc_subset_uIoc' : Ioc a b ⊆ Ι b a := Ioc_subset_Ioc (min_le_right _ _) (le_max_left _ _) lemma uIoc_subset_uIcc : Ι a b ⊆ uIcc a b := Ioc_subset_Icc_self lemma eq_of_mem_uIoc_of_mem_uIoc : a ∈ Ι b c → b ∈ Ι a c → a = b := by simp_rw [mem_uIoc]; rintro (⟨_, _⟩ | ⟨_, _⟩) (⟨_, _⟩ | ⟨_, _⟩) <;> apply le_antisymm <;> first | assumption | exact le_of_lt ‹_› | exact le_trans ‹_› (le_of_lt ‹_›) lemma eq_of_mem_uIoc_of_mem_uIoc' : b ∈ Ι a c → c ∈ Ι a b → b = c := by simpa only [uIoc_comm a] using eq_of_mem_uIoc_of_mem_uIoc lemma eq_of_notMem_uIoc_of_notMem_uIoc (ha : a ≤ c) (hb : b ≤ c) : a ∉ Ι b c → b ∉ Ι a c → a = b := by simp_rw [notMem_uIoc] rintro (⟨_, _⟩ | ⟨_, _⟩) (⟨_, _⟩ | ⟨_, _⟩) <;> apply le_antisymm <;> first | assumption | exact le_of_lt ‹_› | exact absurd hb (not_le_of_gt ‹c < b›) | exact absurd ha (not_le_of_gt ‹c < a›) @[deprecated (since := "2025-05-23")] alias eq_of_not_mem_uIoc_of_not_mem_uIoc := eq_of_notMem_uIoc_of_notMem_uIoc lemma uIoc_injective_right (a : α) : Injective fun b => Ι b a := by rintro b c h rw [Set.ext_iff] at h obtain ha | ha := le_or_gt b a · have hb := (h b).not simp only [ha, left_mem_uIoc, true_iff, notMem_uIoc, ← not_le, and_true, not_true, false_and, not_false_iff, or_false] at hb refine hb.eq_of_not_lt fun hc => ?_ simpa [ha, and_iff_right hc, ← @not_le _ _ _ a, iff_not_self, -not_le] using h c · refine eq_of_mem_uIoc_of_mem_uIoc ((h _).1 <| left_mem_uIoc.2 ha) ((h _).2 <| left_mem_uIoc.2 <| ha.trans_le ?_) simpa [ha, ha.not_ge, mem_uIoc] using h b lemma uIoc_injective_left (a : α) : Injective (Ι a) := by simpa only [uIoc_comm] using uIoc_injective_right a lemma uIoc_union_uIoc (h : b ∈ [[a, c]]) : Ι a b ∪ Ι b c = Ι a c := by wlog hac : a ≤ c generalizing a c · rw [uIoc_comm, union_comm, uIoc_comm, this _ (le_of_not_ge hac), uIoc_comm] rwa [uIcc_comm] rw [uIcc_of_le hac] at h rw [uIoc_of_le h.1, uIoc_of_le h.2, uIoc_of_le hac, Ioc_union_Ioc_eq_Ioc h.1 h.2] section uIoo /-- `uIoo a b` is the set of elements lying between `a` and `b`, with `a` and `b` not included. Note that we define it more generally in a lattice as `Set.Ioo (a ⊓ b) (a ⊔ b)`. In a product type, `uIoo` corresponds to the bounding box of the two elements. -/ def uIoo (a b : α) : Set α := Ioo (a ⊓ b) (a ⊔ b) @[simp] lemma uIoo_toDual (a b : α) : uIoo (toDual a) (toDual b) = ofDual ⁻¹' uIoo a b := Ioo_toDual (α := α) @[simp] theorem uIoo_ofDual (a b : αᵒᵈ) : uIoo (ofDual a) (ofDual b) = toDual ⁻¹' uIoo a b := Ioo_ofDual @[simp] lemma uIoo_of_le (h : a ≤ b) : uIoo a b = Ioo a b := by rw [uIoo, inf_eq_left.2 h, sup_eq_right.2 h] @[simp] lemma uIoo_of_ge (h : b ≤ a) : uIoo a b = Ioo b a := by rw [uIoo, inf_eq_right.2 h, sup_eq_left.2 h] lemma uIoo_comm (a b : α) : uIoo a b = uIoo b a := by simp_rw [uIoo, inf_comm, sup_comm] lemma uIoo_of_lt (h : a < b) : uIoo a b = Ioo a b := uIoo_of_le h.le lemma uIoo_of_gt (h : b < a) : uIoo a b = Ioo b a := uIoo_of_ge h.le lemma uIoo_self : uIoo a a = ∅ := by simp [uIoo] @[simp] lemma left_notMem_uIoo : a ∉ uIoo a b := by simp +contextual [uIoo, le_of_lt] @[simp] lemma right_notMem_uIoo : b ∉ uIoo a b := by simp +contextual [uIoo, le_of_lt] lemma Ioo_subset_uIoo : Ioo a b ⊆ uIoo a b := Ioo_subset_Ioo inf_le_left le_sup_right /-- Same as `Ioo_subset_uIoo` but with `Ioo a b` replaced by `Ioo b a`. -/ lemma Ioo_subset_uIoo' : Ioo b a ⊆ uIoo a b := Ioo_subset_Ioo inf_le_right le_sup_left variable {x : α} lemma mem_uIoo_of_lt (ha : a < x) (hb : x < b) : x ∈ uIoo a b := Ioo_subset_uIoo ⟨ha, hb⟩ lemma mem_uIoo_of_gt (hb : b < x) (ha : x < a) : x ∈ uIoo a b := Ioo_subset_uIoo' ⟨hb, ha⟩ variable {a b : α} theorem Ioo_min_max : Ioo (min a b) (max a b) = uIoo a b := rfl lemma uIoo_of_not_le (h : ¬a ≤ b) : uIoo a b = Ioo b a := uIoo_of_gt <| lt_of_not_ge h lemma uIoo_of_not_ge (h : ¬b ≤ a) : uIoo a b = Ioo a b := uIoo_of_lt <| lt_of_not_ge h lemma uIoo_subset_uIcc_self : uIoo a b ⊆ uIcc a b := by simp [uIoo, uIcc, Ioo_subset_Icc_self] @[deprecated uIoo_subset_uIcc_self (since := "2025-11-09")] lemma uIoo_subset_uIcc (a b : α) : uIoo a b ⊆ uIcc a b := uIoo_subset_uIcc_self lemma uIoo_subset_Ioo (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : uIoo a₁ b₁ ⊆ Ioo a₂ b₂ := Ioo_subset_Ioo (le_inf ha.1 hb.1) (sup_le ha.2 hb.2) @[simp] lemma nonempty_uIoo [DenselyOrdered α] : (uIoo a b).Nonempty ↔ a ≠ b := by simp [uIoo, eq_comm] lemma uIoo_eq_union : uIoo a b = Ioo a b ∪ Ioo b a := by rcases lt_or_ge a b with h | h · simp [uIoo_of_lt, h, Ioo_eq_empty_of_le h.le] · simp [uIoo_of_ge, h] end uIoo end LinearOrder end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/OrderIso.lean
import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.Hom.Set /-! # Lemmas about images of intervals under order isomorphisms. -/ open Set namespace OrderIso section Preorder variable {α β : Type*} [Preorder α] [Preorder β] @[simp] theorem preimage_Iic (e : α ≃o β) (b : β) : e ⁻¹' Iic b = Iic (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Ici (e : α ≃o β) (b : β) : e ⁻¹' Ici b = Ici (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Iio (e : α ≃o β) (b : β) : e ⁻¹' Iio b = Iio (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Ioi (e : α ≃o β) (b : β) : e ⁻¹' Ioi b = Ioi (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Icc (e : α ≃o β) (a b : β) : e ⁻¹' Icc a b = Icc (e.symm a) (e.symm b) := by simp [← Ici_inter_Iic] @[simp] theorem preimage_Ico (e : α ≃o β) (a b : β) : e ⁻¹' Ico a b = Ico (e.symm a) (e.symm b) := by simp [← Ici_inter_Iio] @[simp] theorem preimage_Ioc (e : α ≃o β) (a b : β) : e ⁻¹' Ioc a b = Ioc (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_Ioo (e : α ≃o β) (a b : β) : e ⁻¹' Ioo a b = Ioo (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iio] @[simp] theorem image_Iic (e : α ≃o β) (a : α) : e '' Iic a = Iic (e a) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Iic, e.symm_symm] @[simp] theorem image_Ici (e : α ≃o β) (a : α) : e '' Ici a = Ici (e a) := e.dual.image_Iic a @[simp] theorem image_Iio (e : α ≃o β) (a : α) : e '' Iio a = Iio (e a) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Iio, e.symm_symm] @[simp] theorem image_Ioi (e : α ≃o β) (a : α) : e '' Ioi a = Ioi (e a) := e.dual.image_Iio a @[simp] theorem image_Ioo (e : α ≃o β) (a b : α) : e '' Ioo a b = Ioo (e a) (e b) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Ioo, e.symm_symm] @[simp] theorem image_Ioc (e : α ≃o β) (a b : α) : e '' Ioc a b = Ioc (e a) (e b) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Ioc, e.symm_symm] @[simp] theorem image_Ico (e : α ≃o β) (a b : α) : e '' Ico a b = Ico (e a) (e b) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Ico, e.symm_symm] @[simp] theorem image_Icc (e : α ≃o β) (a b : α) : e '' Icc a b = Icc (e a) (e b) := by rw [e.image_eq_preimage_symm, e.symm.preimage_Icc, e.symm_symm] end Preorder /-- Order isomorphism between `Iic (⊤ : α)` and `α` when `α` has a top element -/ def IicTop {α : Type*} [Preorder α] [OrderTop α] : Iic (⊤ : α) ≃o α := { @Equiv.subtypeUnivEquiv α (Iic (⊤ : α)) fun _ => le_top with map_rel_iff' := @fun x y => by rfl } /-- Order isomorphism between `Ici (⊥ : α)` and `α` when `α` has a bottom element -/ def IciBot {α : Type*} [Preorder α] [OrderBot α] : Ici (⊥ : α) ≃o α := { @Equiv.subtypeUnivEquiv α (Ici (⊥ : α)) fun _ => bot_le with map_rel_iff' := @fun x y => by rfl } end OrderIso
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Fin.lean
import Mathlib.Order.Fin.Basic import Mathlib.Order.Interval.Set.UnorderedInterval /-! # (Pre)images of set intervals under `Fin` operations In this file we prove basic lemmas about preimages and images of the intervals under the following operations: - `Fin.val`, - `Fin.castLE` (preimages only), - `Fin.castAdd`, - `Fin.cast`, - `Fin.castSucc`, - `Fin.natAdd`, - `Fin.addNat`, - `Fin.succ`, - `Fin.rev`. -/ open Function Set namespace Fin variable {m n : ℕ} /-! ### (Pre)images under `Fin.val` -/ @[simp] theorem range_val : range ((↑) : Fin n → ℕ) = Set.Iio n := by ext; simp [Fin.exists_iff] @[simp] theorem preimage_val_Ici_val (i : Fin n) : (↑) ⁻¹' Ici (i : ℕ) = Ici i := rfl @[simp] theorem preimage_val_Ioi_val (i : Fin n) : (↑) ⁻¹' Ioi (i : ℕ) = Ioi i := rfl @[simp] theorem preimage_val_Iic_val (i : Fin n) : (↑) ⁻¹' Iic (i : ℕ) = Iic i := rfl @[simp] theorem preimage_val_Iio_val (i : Fin n) : (↑) ⁻¹' Iio (i : ℕ) = Iio i := rfl @[simp] theorem preimage_val_Icc_val (i j : Fin n) : (↑) ⁻¹' Icc (i : ℕ) j = Icc i j := rfl @[simp] theorem preimage_val_Ico_val (i j : Fin n) : (↑) ⁻¹' Ico (i : ℕ) j = Ico i j := rfl @[simp] theorem preimage_val_Ioc_val (i j : Fin n) : (↑) ⁻¹' Ioc (i : ℕ) j = Ioc i j := rfl @[simp] theorem preimage_val_Ioo_val (i j : Fin n) : (↑) ⁻¹' Ioo (i : ℕ) j = Ioo i j := rfl @[simp] theorem preimage_val_uIcc_val (i j : Fin n) : (↑) ⁻¹' uIcc (i : ℕ) j = uIcc i j := rfl @[simp] theorem preimage_val_uIoc_val (i j : Fin n) : (↑) ⁻¹' uIoc (i : ℕ) j = uIoc i j := rfl @[simp] theorem preimage_val_uIoo_val (i j : Fin n) : (↑) ⁻¹' uIoo (i : ℕ) j = uIoo i j := rfl @[simp] theorem image_val_Ici (i : Fin n) : (↑) '' Ici i = Ico (i : ℕ) n := by rw [← preimage_val_Ici_val, image_preimage_eq_inter_range, range_val, Ici_inter_Iio] @[simp] theorem image_val_Iic (i : Fin n) : (↑) '' Iic i = Iic (i : ℕ) := by rw [← preimage_val_Iic_val, image_preimage_eq_of_subset] simp [range_val] @[simp] theorem image_val_Ioi (i : Fin n) : (↑) '' Ioi i = Ioo (i : ℕ) n := by rw [← preimage_val_Ioi_val, image_preimage_eq_inter_range, range_val, Ioi_inter_Iio] @[simp] theorem image_val_Iio (i : Fin n) : (↑) '' Iio i = Iio (i : ℕ) := by rw [← preimage_val_Iio_val, image_preimage_eq_inter_range, range_val, inter_eq_left] exact Iio_subset_Iio i.is_lt.le @[simp] theorem image_val_Icc (i j : Fin n) : (↑) '' Icc i j = Icc (i : ℕ) j := by rw [← preimage_val_Icc_val, image_preimage_eq_inter_range, range_val, inter_eq_left] exact fun k hk ↦ hk.2.trans_lt j.is_lt @[simp] theorem image_val_Ico (i j : Fin n) : (↑) '' Ico i j = Ico (i : ℕ) j := by rw [← preimage_val_Ico_val, image_preimage_eq_inter_range, range_val, inter_eq_left] exact fun k hk ↦ hk.2.trans j.is_lt @[simp] theorem image_val_Ioc (i j : Fin n) : (↑) '' Ioc i j = Ioc (i : ℕ) j := by rw [← preimage_val_Ioc_val, image_preimage_eq_inter_range, range_val, inter_eq_left] exact fun k hk ↦ hk.2.trans_lt j.is_lt @[simp] theorem image_val_Ioo (i j : Fin n) : (↑) '' Ioo i j = Ioo (i : ℕ) j := by rw [← preimage_val_Ioo_val, image_preimage_eq_inter_range, range_val, inter_eq_left] exact fun k hk ↦ hk.2.trans j.is_lt @[simp] theorem image_val_uIcc (i j : Fin n) : (↑) '' uIcc i j = uIcc (i : ℕ) j := by simp [uIcc] @[simp] theorem image_val_uIoc (i j : Fin n) : (↑) '' uIoc i j = uIoc (i : ℕ) j := by simp [uIoc] @[simp] theorem image_val_uIoo (i j : Fin n) : (↑) '' uIoo i j = uIoo (i : ℕ) j := by simp [uIoo] /-! ### Preimages under `Fin.castLE` -/ @[simp] theorem preimage_castLE_Ici_castLE (i : Fin m) (h : m ≤ n) : castLE h ⁻¹' Ici (castLE h i) = Ici i := rfl @[simp] theorem preimage_castLE_Ioi_castLE (i : Fin m) (h : m ≤ n) : castLE h ⁻¹' Ioi (castLE h i) = Ioi i := rfl @[simp] theorem preimage_castLE_Iic_castLE (i : Fin m) (h : m ≤ n) : castLE h ⁻¹' Iic (castLE h i) = Iic i := rfl @[simp] theorem preimage_castLE_Iio_castLE (i : Fin m) (h : m ≤ n) : castLE h ⁻¹' Iio (castLE h i) = Iio i := rfl @[simp] theorem preimage_castLE_Icc_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' Icc (castLE h i) (castLE h j) = Icc i j := rfl @[simp] theorem preimage_castLE_Ico_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' Ico (castLE h i) (castLE h j) = Ico i j := rfl @[simp] theorem preimage_castLE_Ioc_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' Ioc (castLE h i) (castLE h j) = Ioc i j := rfl @[simp] theorem preimage_castLE_Ioo_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' Ioo (castLE h i) (castLE h j) = Ioo i j := rfl @[simp] theorem preimage_castLE_uIcc_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' uIcc (castLE h i) (castLE h j) = uIcc i j := rfl @[simp] theorem preimage_castLE_uIoc_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' uIoc (castLE h i) (castLE h j) = uIoc i j := rfl @[simp] theorem preimage_castLE_uIoo_castLE (i j : Fin m) (h : m ≤ n) : castLE h ⁻¹' uIoo (castLE h i) (castLE h j) = uIoo i j := rfl @[simp] theorem image_castLE_Iic (i : Fin m) (h : m ≤ n) : castLE h '' Iic i = Iic (castLE h i) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_Iio (i : Fin m) (h : m ≤ n) : castLE h '' Iio i = Iio (castLE h i) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_Icc (i j : Fin m) (h : m ≤ n) : castLE h '' Icc i j = Icc (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_Ico (i j : Fin m) (h : m ≤ n) : castLE h '' Ico i j = Ico (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_Ioc (i j : Fin m) (h : m ≤ n) : castLE h '' Ioc i j = Ioc (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_Ioo (i j : Fin m) (h : m ≤ n) : castLE h '' Ioo i j = Ioo (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_uIcc (i j : Fin m) (h : m ≤ n) : castLE h '' uIcc i j = uIcc (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_uIoc (i j : Fin m) (h : m ≤ n) : castLE h '' uIoc i j = uIoc (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] @[simp] theorem image_castLE_uIoo (i j : Fin m) (h : m ≤ n) : castLE h '' uIoo i j = uIoo (castLE h i) (castLE h j) := val_injective.image_injective <| by simp [image_image] /-! ### (Pre)images under `Fin.castAdd` -/ @[simp] theorem range_castAdd [NeZero m] : range (castAdd m : Fin n → Fin (n + m)) = Iio (natAdd n 0) := val_injective.image_injective <| by simp [← range_comp, comp_def] @[simp] theorem preimage_castAdd_Ici_castAdd (m) (i : Fin n) : castAdd m ⁻¹' Ici (castAdd m i) = Ici i := rfl @[simp] theorem preimage_castAdd_Ioi_castAdd (m) (i : Fin n) : castAdd m ⁻¹' Ioi (castAdd m i) = Ioi i := rfl @[simp] theorem preimage_castAdd_Iic_castAdd (m) (i : Fin n) : castAdd m ⁻¹' Iic (castAdd m i) = Iic i := rfl @[simp] theorem preimage_castAdd_Iio_castAdd (m) (i : Fin n) : castAdd m ⁻¹' Iio (castAdd m i) = Iio i := rfl @[simp] theorem preimage_castAdd_Icc_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' Icc (castAdd m i) (castAdd m j) = Icc i j := rfl @[simp] theorem preimage_castAdd_Ico_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' Ico (castAdd m i) (castAdd m j) = Ico i j := rfl @[simp] theorem preimage_castAdd_Ioc_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' Ioc (castAdd m i) (castAdd m j) = Ioc i j := rfl @[simp] theorem preimage_castAdd_Ioo_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' Ioo (castAdd m i) (castAdd m j) = Ioo i j := rfl @[simp] theorem preimage_castAdd_uIcc_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' uIcc (castAdd m i) (castAdd m j) = uIcc i j := rfl @[simp] theorem preimage_castAdd_uIoc_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' uIoc (castAdd m i) (castAdd m j) = uIoc i j := rfl @[simp] theorem preimage_castAdd_uIoo_castAdd (m) (i j : Fin n) : castAdd m ⁻¹' uIoo (castAdd m i) (castAdd m j) = uIoo i j := rfl @[simp] theorem image_castAdd_Ici (m) [NeZero m] (i : Fin n) : castAdd m '' Ici i = Ico (castAdd m i) (natAdd n 0) := val_injective.image_injective <| by simp [← image_comp] @[simp] theorem image_castAdd_Ioi (m) [NeZero m] (i : Fin n) : castAdd m '' Ioi i = Ioo (castAdd m i) (natAdd n 0) := val_injective.image_injective <| by simp [← image_comp] @[simp] theorem image_castAdd_Iic (m) (i : Fin n) : castAdd m '' Iic i = Iic (castAdd m i) := image_castLE_Iic i _ @[simp] theorem image_castAdd_Iio (m) (i : Fin n) : castAdd m '' Iio i = Iio (castAdd m i) := image_castLE_Iio .. @[simp] theorem image_castAdd_Icc (m) (i j : Fin n) : castAdd m '' Icc i j = Icc (castAdd m i) (castAdd m j) := image_castLE_Icc .. @[simp] theorem image_castAdd_Ico (m) (i j : Fin n) : castAdd m '' Ico i j = Ico (castAdd m i) (castAdd m j) := image_castLE_Ico .. @[simp] theorem image_castAdd_Ioc (m) (i j : Fin n) : castAdd m '' Ioc i j = Ioc (castAdd m i) (castAdd m j) := image_castLE_Ioc .. @[simp] theorem image_castAdd_Ioo (m) (i j : Fin n) : castAdd m '' Ioo i j = Ioo (castAdd m i) (castAdd m j) := image_castLE_Ioo .. @[simp] theorem image_castAdd_uIcc (m) (i j : Fin n) : castAdd m '' uIcc i j = uIcc (castAdd m i) (castAdd m j) := image_castLE_uIcc .. @[simp] theorem image_castAdd_uIoc (m) (i j : Fin n) : castAdd m '' uIoc i j = uIoc (castAdd m i) (castAdd m j) := image_castLE_uIoc .. @[simp] theorem image_castAdd_uIoo (m) (i j : Fin n) : castAdd m '' uIoo i j = uIoo (castAdd m i) (castAdd m j) := image_castLE_uIoo .. /-! ### (Pre)images under `Fin.cast` -/ theorem image_cast (h : m = n) (s : Set (Fin m)) : Fin.cast h '' s = Fin.cast h.symm ⁻¹' s := (finCongr h).image_eq_preimage_symm _ @[simp] theorem image_cast_fun (h : m = n) : image (Fin.cast h) = preimage (Fin.cast h.symm) := funext <| image_cast h @[simp] theorem preimage_cast_Ici (h : m = n) (i : Fin n) : .cast h ⁻¹' Ici i = Ici (i.cast h.symm) := rfl @[simp] theorem preimage_cast_Ioi (h : m = n) (i : Fin n) : .cast h ⁻¹' Ioi i = Ioi (i.cast h.symm) := rfl @[simp] theorem preimage_cast_Iic (h : m = n) (i : Fin n) : .cast h ⁻¹' Iic i = Iic (i.cast h.symm) := rfl @[simp] theorem preimage_cast_Iio (h : m = n) (i : Fin n) : .cast h ⁻¹' Iio i = Iio (i.cast h.symm) := rfl @[simp] theorem preimage_cast_Icc (h : m = n) (i j : Fin n) : .cast h ⁻¹' Icc i j = Icc (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_Ico (h : m = n) (i j : Fin n) : .cast h ⁻¹' Ico i j = Ico (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_Ioc (h : m = n) (i j : Fin n) : .cast h ⁻¹' Ioc i j = Ioc (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_Ioo (h : m = n) (i j : Fin n) : .cast h ⁻¹' Ioo i j = Ioo (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_uIcc (h : m = n) (i j : Fin n) : .cast h ⁻¹' uIcc i j = uIcc (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_uIoc (h : m = n) (i j : Fin n) : .cast h ⁻¹' uIoc i j = uIoc (i.cast h.symm) (j.cast h.symm) := rfl @[simp] theorem preimage_cast_uIoo (h : m = n) (i j : Fin n) : .cast h ⁻¹' uIoo i j = uIoo (i.cast h.symm) (j.cast h.symm) := rfl /-! ### `Fin.castSucc` -/ @[simp] theorem preimage_castSucc_Ici_castSucc (i : Fin n) : castSucc ⁻¹' Ici i.castSucc = Ici i := rfl @[simp] theorem preimage_castSucc_Ioi_castSucc (i : Fin n) : castSucc ⁻¹' Ioi i.castSucc = Ioi i := rfl @[simp] theorem preimage_castSucc_Iic_castSucc (i : Fin n) : castSucc ⁻¹' Iic i.castSucc = Iic i := rfl @[simp] theorem preimage_castSucc_Iio_castSucc (i : Fin n) : castSucc ⁻¹' Iio i.castSucc = Iio i := rfl @[simp] theorem preimage_castSucc_Icc_castSucc (i j : Fin n) : castSucc ⁻¹' Icc i.castSucc j.castSucc = Icc i j := rfl @[simp] theorem preimage_castSucc_Ico_castSucc (i j : Fin n) : castSucc ⁻¹' Ico i.castSucc j.castSucc = Ico i j := rfl @[simp] theorem preimage_castSucc_Ioc_castSucc (i j : Fin n) : castSucc ⁻¹' Ioc i.castSucc j.castSucc = Ioc i j := rfl @[simp] theorem preimage_castSucc_Ioo_castSucc (i j : Fin n) : castSucc ⁻¹' Ioo i.castSucc j.castSucc = Ioo i j := rfl @[simp] theorem preimage_castSucc_uIcc_castSucc (i j : Fin n) : castSucc ⁻¹' uIcc i.castSucc j.castSucc = uIcc i j := rfl @[simp] theorem preimage_castSucc_uIoc_castSucc (i j : Fin n) : castSucc ⁻¹' uIoc i.castSucc j.castSucc = uIoc i j := rfl @[simp] theorem preimage_castSucc_uIoo_castSucc (i j : Fin n) : castSucc ⁻¹' uIoo i.castSucc j.castSucc = uIoo i j := rfl @[simp] theorem image_castSucc_Ici (i : Fin n) : castSucc '' Ici i = Ico i.castSucc (.last n) := image_castAdd_Ici .. @[simp] theorem image_castSucc_Ioi (i : Fin n) : castSucc '' Ioi i = Ioo i.castSucc (.last n) := image_castAdd_Ioi .. @[simp] theorem image_castSucc_Iic (i : Fin n) : castSucc '' Iic i = Iic i.castSucc := image_castAdd_Iic .. @[simp] theorem image_castSucc_Iio (i : Fin n) : castSucc '' Iio i = Iio i.castSucc := image_castAdd_Iio .. @[simp] theorem image_castSucc_Icc (i j : Fin n) : castSucc '' Icc i j = Icc i.castSucc j.castSucc := image_castAdd_Icc .. @[simp] theorem image_castSucc_Ico (i j : Fin n) : castSucc '' Ico i j = Ico i.castSucc j.castSucc := image_castAdd_Ico .. @[simp] theorem image_castSucc_Ioc (i j : Fin n) : castSucc '' Ioc i j = Ioc i.castSucc j.castSucc := image_castAdd_Ioc .. @[simp] theorem image_castSucc_Ioo (i j : Fin n) : castSucc '' Ioo i j = Ioo i.castSucc j.castSucc := image_castAdd_Ioo .. @[simp] theorem image_castSucc_uIcc (i j : Fin n) : castSucc '' uIcc i j = uIcc i.castSucc j.castSucc := image_castAdd_uIcc .. @[simp] theorem image_castSucc_uIoc (i j : Fin n) : castSucc '' uIoc i j = uIoc i.castSucc j.castSucc := image_castAdd_uIoc .. @[simp] theorem image_castSucc_uIoo (i j : Fin n) : castSucc '' uIoo i j = uIoo i.castSucc j.castSucc := image_castAdd_uIoo .. /-! ### `Fin.natAdd` -/ theorem range_natAdd (m n : ℕ) : range (natAdd m : Fin n → Fin (m + n)) = {i | m ≤ i.1} := by ext i constructor · rintro ⟨i, rfl⟩ apply le_coe_natAdd · refine fun (hi : m ≤ i) ↦ ⟨⟨i - m, by cutsat⟩, ?_⟩ ext simp [hi] theorem range_natAdd_eq_Ici (m n : ℕ) [NeZero n] : range (natAdd m : Fin n → Fin (m + n)) = Ici (natAdd m 0) := range_natAdd m n theorem range_natAdd_eq_Ioi (m n : ℕ) [NeZero m] : range (natAdd m : Fin n → Fin (m + n)) = Ioi (castAdd n ⊤) := by ext ⟨_, _⟩ simp [range_natAdd, lt_def, ← Nat.succ_le_iff, Nat.one_le_iff_ne_zero.mpr (NeZero.ne m)] @[simp] theorem preimage_natAdd_Ici_natAdd (m) (i : Fin n) : natAdd m ⁻¹' Ici (natAdd m i) = Ici i := by ext; simp @[simp] theorem preimage_natAdd_Ioi_natAdd (m) (i : Fin n) : natAdd m ⁻¹' Ioi (natAdd m i) = Ioi i := by ext; simp @[simp] theorem preimage_natAdd_Iic_natAdd (m) (i : Fin n) : natAdd m ⁻¹' Iic (natAdd m i) = Iic i := by ext; simp @[simp] theorem preimage_natAdd_Iio_natAdd (m) (i : Fin n) : natAdd m ⁻¹' Iio (natAdd m i) = Iio i := by ext; simp @[simp] theorem preimage_natAdd_Icc_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' Icc (natAdd m i) (natAdd m j) = Icc i j := by ext; simp @[simp] theorem preimage_natAdd_Ico_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' Ico (natAdd m i) (natAdd m j) = Ico i j := by ext; simp @[simp] theorem preimage_natAdd_Ioc_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' Ioc (natAdd m i) (natAdd m j) = Ioc i j := by ext; simp @[simp] theorem preimage_natAdd_Ioo_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' Ioo (natAdd m i) (natAdd m j) = Ioo i j := by ext; simp @[simp] theorem preimage_natAdd_uIcc_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' uIcc (natAdd m i) (natAdd m j) = uIcc i j := by simp [uIcc, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] @[simp] theorem preimage_natAdd_uIoc_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' uIoc (natAdd m i) (natAdd m j) = uIoc i j := by simp [uIoc, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] @[simp] theorem preimage_natAdd_uIoo_natAdd (m) (i j : Fin n) : natAdd m ⁻¹' uIoo (natAdd m i) (natAdd m j) = uIoo i j := by simp [uIoo, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] @[simp] theorem image_natAdd_Ici (m) (i : Fin n) : natAdd m '' Ici i = Ici (natAdd m i) := by rw [← preimage_natAdd_Ici_natAdd, image_preimage_eq_of_subset] rw [range_natAdd] exact fun j hj ↦ Nat.le_trans (le_coe_natAdd ..) hj @[simp] theorem image_natAdd_Ioi (m) (i : Fin n) : natAdd m '' Ioi i = Ioi (natAdd m i) := by rw [← preimage_natAdd_Ioi_natAdd, image_preimage_eq_of_subset] exact Ioi_subset_Ici_self.trans <| image_natAdd_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_natAdd_Icc (m) (i j : Fin n) : natAdd m '' Icc i j = Icc (natAdd m i) (natAdd m j) := by rw [← preimage_natAdd_Icc_natAdd, image_preimage_eq_of_subset] exact Icc_subset_Ici_self.trans <| image_natAdd_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_natAdd_Ico (m) (i j : Fin n) : natAdd m '' Ico i j = Ico (natAdd m i) (natAdd m j) := by rw [← preimage_natAdd_Ico_natAdd, image_preimage_eq_of_subset] exact Ico_subset_Ici_self.trans <| image_natAdd_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_natAdd_Ioc (m) (i j : Fin n) : natAdd m '' Ioc i j = Ioc (natAdd m i) (natAdd m j) := by rw [← preimage_natAdd_Ioc_natAdd, image_preimage_eq_of_subset] exact Ioc_subset_Ioi_self.trans <| image_natAdd_Ioi m i ▸ image_subset_range _ _ @[simp] theorem image_natAdd_Ioo (m) (i j : Fin n) : natAdd m '' Ioo i j = Ioo (natAdd m i) (natAdd m j) := by rw [← preimage_natAdd_Ioo_natAdd, image_preimage_eq_of_subset] exact Ioo_subset_Ioi_self.trans <| image_natAdd_Ioi m i ▸ image_subset_range _ _ @[simp] theorem image_natAdd_uIcc (m) (i j : Fin n) : natAdd m '' uIcc i j = uIcc (natAdd m i) (natAdd m j) := by simp [uIcc, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] @[simp] theorem image_natAdd_uIoc (m) (i j : Fin n) : natAdd m '' uIoc i j = uIoc (natAdd m i) (natAdd m j) := by simp [uIoc, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] @[simp] theorem image_natAdd_uIoo (m) (i j : Fin n) : natAdd m '' uIoo i j = uIoo (natAdd m i) (natAdd m j) := by simp [uIoo, ← (strictMono_natAdd m).monotone.map_max, ← (strictMono_natAdd m).monotone.map_min] /-! ### `Fin.addNat` -/ @[simp] theorem preimage_addNat_Ici_addNat (m) (i : Fin n) : (addNat · m) ⁻¹' Ici (i.addNat m) = Ici i := by ext; simp @[simp] theorem preimage_addNat_Ioi_addNat (m) (i : Fin n) : (addNat · m) ⁻¹' Ioi (i.addNat m) = Ioi i := by ext; simp @[simp] theorem preimage_addNat_Iic_addNat (m) (i : Fin n) : (addNat · m) ⁻¹' Iic (i.addNat m) = Iic i := by ext; simp @[simp] theorem preimage_addNat_Iio_addNat (m) (i : Fin n) : (addNat · m) ⁻¹' Iio (i.addNat m) = Iio i := by ext; simp @[simp] theorem preimage_addNat_Icc_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' Icc (i.addNat m) (j.addNat m) = Icc i j := by ext; simp @[simp] theorem preimage_addNat_Ico_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' Ico (i.addNat m) (j.addNat m) = Ico i j := by ext; simp @[simp] theorem preimage_addNat_Ioc_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' Ioc (i.addNat m) (j.addNat m) = Ioc i j := by ext; simp @[simp] theorem preimage_addNat_Ioo_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' Ioo (i.addNat m) (j.addNat m) = Ioo i j := by ext; simp @[simp] theorem preimage_addNat_uIcc_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' uIcc (i.addNat m) (j.addNat m) = uIcc i j := by simp [uIcc, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] @[simp] theorem preimage_addNat_uIoc_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' uIoc (i.addNat m) (j.addNat m) = uIoc i j := by simp [uIoc, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] @[simp] theorem preimage_addNat_uIoo_addNat (m) (i j : Fin n) : (addNat · m) ⁻¹' uIoo (i.addNat m) (j.addNat m) = uIoo i j := by simp [uIoo, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] @[simp] theorem image_addNat_Ici (m) (i : Fin n) : (addNat · m) '' Ici i = Ici (i.addNat m) := by rw [← preimage_addNat_Ici_addNat, image_preimage_eq_of_subset] intro j hj have : (i : ℕ) + m ≤ j := hj refine ⟨⟨j - m, by cutsat⟩, ?_⟩ simp (disch := omega) @[simp] theorem image_addNat_Ioi (m) (i : Fin n) : (addNat · m) '' Ioi i = Ioi (i.addNat m) := by rw [← preimage_addNat_Ioi_addNat, image_preimage_eq_of_subset] exact Ioi_subset_Ici_self.trans <| image_addNat_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_addNat_Icc (m) (i j : Fin n) : (addNat · m) '' Icc i j = Icc (i.addNat m) (j.addNat m) := by rw [← preimage_addNat_Icc_addNat, image_preimage_eq_of_subset] exact Icc_subset_Ici_self.trans <| image_addNat_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_addNat_Ico (m) (i j : Fin n) : (addNat · m) '' Ico i j = Ico (i.addNat m) (j.addNat m) := by rw [← preimage_addNat_Ico_addNat, image_preimage_eq_of_subset] exact Ico_subset_Ici_self.trans <| image_addNat_Ici m i ▸ image_subset_range _ _ @[simp] theorem image_addNat_Ioc (m) (i j : Fin n) : (addNat · m) '' Ioc i j = Ioc (i.addNat m) (j.addNat m) := by rw [← preimage_addNat_Ioc_addNat, image_preimage_eq_of_subset] exact Ioc_subset_Ioi_self.trans <| image_addNat_Ioi m i ▸ image_subset_range _ _ @[simp] theorem image_addNat_Ioo (m) (i j : Fin n) : (addNat · m) '' Ioo i j = Ioo (i.addNat m) (j.addNat m) := by rw [← preimage_addNat_Ioo_addNat, image_preimage_eq_of_subset] exact Ioo_subset_Ioi_self.trans <| image_addNat_Ioi m i ▸ image_subset_range _ _ @[simp] theorem image_addNat_uIcc (m) (i j : Fin n) : (addNat · m) '' uIcc i j = uIcc (i.addNat m) (j.addNat m) := by simp [uIcc, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] @[simp] theorem image_addNat_uIoc (m) (i j : Fin n) : (addNat · m) '' uIoc i j = uIoc (i.addNat m) (j.addNat m) := by simp [uIoc, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] @[simp] theorem image_addNat_uIoo (m) (i j : Fin n) : (addNat · m) '' uIoo i j = uIoo (i.addNat m) (j.addNat m) := by simp [uIoo, ← (strictMono_addNat m).monotone.map_max, ← (strictMono_addNat m).monotone.map_min] /-! ### `Fin.succ` -/ @[simp] theorem preimage_succ_Ici_succ (i : Fin n) : succ ⁻¹' Ici i.succ = Ici i := preimage_addNat_Ici_addNat .. @[simp] theorem preimage_succ_Ioi_succ (i : Fin n) : succ ⁻¹' Ioi i.succ = Ioi i := preimage_addNat_Ioi_addNat .. @[simp] theorem preimage_succ_Iic_succ (i : Fin n) : succ ⁻¹' Iic i.succ = Iic i := preimage_addNat_Iic_addNat .. @[simp] theorem preimage_succ_Iio_succ (i : Fin n) : succ ⁻¹' Iio i.succ = Iio i := preimage_addNat_Iio_addNat .. @[simp] theorem preimage_succ_Icc_succ (i j : Fin n) : succ ⁻¹' Icc i.succ j.succ = Icc i j := preimage_addNat_Icc_addNat .. @[simp] theorem preimage_succ_Ico_succ (i j : Fin n) : succ ⁻¹' Ico i.succ j.succ = Ico i j := preimage_addNat_Ico_addNat .. @[simp] theorem preimage_succ_Ioc_succ (i j : Fin n) : succ ⁻¹' Ioc i.succ j.succ = Ioc i j := preimage_addNat_Ioc_addNat .. @[simp] theorem preimage_succ_Ioo_succ (i j : Fin n) : succ ⁻¹' Ioo i.succ j.succ = Ioo i j := preimage_addNat_Ioo_addNat .. @[simp] theorem preimage_succ_uIcc_succ (i j : Fin n) : succ ⁻¹' uIcc i.succ j.succ = uIcc i j := preimage_addNat_uIcc_addNat .. @[simp] theorem preimage_succ_uIoc_succ (i j : Fin n) : succ ⁻¹' uIoc i.succ j.succ = uIoc i j := preimage_addNat_uIoc_addNat .. @[simp] theorem preimage_succ_uIoo_succ (i j : Fin n) : succ ⁻¹' uIoo i.succ j.succ = uIoo i j := preimage_addNat_uIoo_addNat .. @[simp] theorem image_succ_Ici (i : Fin n) : succ '' Ici i = Ici i.succ := image_addNat_Ici .. @[simp] theorem image_succ_Ioi (i : Fin n) : succ '' Ioi i = Ioi i.succ := image_addNat_Ioi .. @[simp] theorem image_succ_Iic (i : Fin n) : succ '' Iic i = Ioc 0 i.succ := by refine Subset.antisymm (image_subset_iff.mpr fun j hj ↦ ⟨j.succ_pos, succ_le_succ_iff.2 hj⟩) ?_ rintro j ⟨hj₀, hj⟩ rcases exists_succ_eq_of_ne_zero hj₀.ne' with ⟨j, rfl⟩ exact mem_image_of_mem _ <| succ_le_succ_iff.mp hj @[simp] theorem image_succ_Iio (i : Fin n) : succ '' Iio i = Ioo 0 i.succ := by refine Subset.antisymm (image_subset_iff.mpr fun j hj ↦ ⟨j.succ_pos, succ_lt_succ_iff.2 hj⟩) ?_ rintro j ⟨hj₀, hj⟩ rcases exists_succ_eq_of_ne_zero hj₀.ne' with ⟨j, rfl⟩ exact mem_image_of_mem _ <| succ_lt_succ_iff.mp hj @[simp] theorem image_succ_Icc (i j : Fin n) : succ '' Icc i j = Icc i.succ j.succ := image_addNat_Icc .. @[simp] theorem image_succ_Ico (i j : Fin n) : succ '' Ico i j = Ico i.succ j.succ := image_addNat_Ico .. @[simp] theorem image_succ_Ioc (i j : Fin n) : succ '' Ioc i j = Ioc i.succ j.succ := image_addNat_Ioc .. @[simp] theorem image_succ_Ioo (i j : Fin n) : succ '' Ioo i j = Ioo i.succ j.succ := image_addNat_Ioo .. @[simp] theorem image_succ_uIcc (i j : Fin n) : succ '' uIcc i j = uIcc i.succ j.succ := image_addNat_uIcc .. @[simp] theorem image_succ_uIoc (i j : Fin n) : succ '' uIoc i j = uIoc i.succ j.succ := image_addNat_uIoc .. @[simp] theorem image_succ_uIoo (i j : Fin n) : succ '' uIoo i j = uIoo i.succ j.succ := image_addNat_uIoo .. /-! ### `Fin.rev` -/ @[simp] theorem range_rev : range (rev : Fin n → Fin n) = univ := rev_surjective.range_eq theorem image_rev (s : Set (Fin n)) : rev '' s = rev ⁻¹' s := revPerm.image_eq_preimage_symm s @[simp] theorem image_rev_fun : image (@rev n) = preimage rev := funext image_rev @[simp] theorem preimage_rev_Ici (i : Fin n) : rev ⁻¹' Ici i = Iic i.rev := by ext; simp [le_rev_iff] @[simp] theorem preimage_rev_Ioi (i : Fin n) : rev ⁻¹' Ioi i = Iio i.rev := by ext; simp [lt_rev_iff] @[simp] theorem preimage_rev_Iic (i : Fin n) : rev ⁻¹' Iic i = Ici i.rev := by ext; simp [rev_le_iff] @[simp] theorem preimage_rev_Iio (i : Fin n) : rev ⁻¹' Iio i = Ioi i.rev := by ext; simp [rev_lt_iff] @[simp] theorem preimage_rev_Icc (i j : Fin n) : rev ⁻¹' Icc i j = Icc j.rev i.rev := by ext; simp [le_rev_iff, rev_le_iff, and_comm] @[simp] theorem preimage_rev_Ico (i j : Fin n) : rev ⁻¹' Ico i j = Ioc j.rev i.rev := by ext; simp [le_rev_iff, rev_lt_iff, and_comm] @[simp] theorem preimage_rev_Ioc (i j : Fin n) : rev ⁻¹' Ioc i j = Ico j.rev i.rev := by ext; simp [lt_rev_iff, rev_le_iff, and_comm] @[simp] theorem preimage_rev_Ioo (i j : Fin n) : rev ⁻¹' Ioo i j = Ioo j.rev i.rev := by ext; simp [lt_rev_iff, rev_lt_iff, and_comm] @[simp] theorem preimage_rev_uIcc (i j : Fin n) : rev ⁻¹' uIcc i j = uIcc i.rev j.rev := by simp [uIcc, ← rev_anti.map_min, ← rev_anti.map_max] @[simp] theorem preimage_rev_uIoo (i j : Fin n) : rev ⁻¹' uIoo i j = uIoo i.rev j.rev := by simp [uIoo, ← rev_anti.map_min, ← rev_anti.map_max] end Fin
.lake/packages/mathlib/Mathlib/Order/Interval/Set/SuccPred.lean
import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.SuccPred.Basic /-! # Set intervals in a successor-predecessor order This file proves relations between the various set intervals in a successor/predecessor order. ## Notes Please keep in sync with: * `Mathlib/Algebra/Order/Interval/Finset/SuccPred.lean` * `Mathlib/Algebra/Order/Interval/Set/SuccPred.lean` * `Mathlib/Order/Interval/Finset/SuccPred.lean` ## TODO Copy over `insert` lemmas from `Mathlib/Order/Interval/Finset/Nat.lean`. -/ assert_not_exists MonoidWithZero open Order namespace Set variable {α : Type*} [LinearOrder α] /-! ### Two-sided intervals -/ section SuccOrder variable [SuccOrder α] {a b : α} /-! #### Orders possibly with maximal elements ##### Equalities of intervals -/ lemma Ico_succ_left_eq_Ioo (a b : α) : Ico (succ a) b = Ioo a b := by by_cases ha : IsMax a · rw [Ico_eq_empty (ha.mono <| le_succ _).not_lt, Ioo_eq_empty ha.not_lt] · ext x rw [mem_Ico, mem_Ioo, succ_le_iff_of_not_isMax ha] lemma Icc_succ_left_eq_Ioc_of_not_isMax (ha : ¬ IsMax a) (b : α) : Icc (succ a) b = Ioc a b := by ext x; rw [mem_Icc, mem_Ioc, succ_le_iff_of_not_isMax ha] lemma Ico_succ_right_eq_Icc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico a (succ b) = Icc a b := by ext x; rw [mem_Ico, mem_Icc, lt_succ_iff_of_not_isMax hb] lemma Ioo_succ_right_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ioo a (succ b) = Ioc a b := by ext x; rw [mem_Ioo, mem_Ioc, lt_succ_iff_of_not_isMax hb] lemma Ico_succ_succ_eq_Ioc_of_not_isMax (hb : ¬ IsMax b) (a : α) : Ico (succ a) (succ b) = Ioc a b := by rw [Ico_succ_left_eq_Ioo, Ioo_succ_right_eq_Ioc_of_not_isMax hb] /-! ##### Inserting into intervals -/ lemma insert_Icc_succ_left_eq_Icc (h : a ≤ b) : insert a (Icc (succ a) b) = Icc a b := by ext x; simp [or_and_left, eq_comm, ← le_iff_eq_or_succ_le]; aesop lemma insert_Icc_right_eq_Icc_succ (h : a ≤ succ b) : insert (succ b) (Icc a b) = Icc a (succ b) := by ext x; simp [or_and_left, le_succ_iff_eq_or_le]; simp_all lemma insert_Ico_right_eq_Ico_succ_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert b (Ico a b) = Ico a (succ b) := by rw [Ico_succ_right_of_not_isMax hb, ← Ico_insert_right h] lemma insert_Ico_succ_left_eq_Ico (h : a < b) : insert a (Ico (succ a) b) = Ico a b := by rw [Ico_succ_left_of_not_isMax h.not_isMax, ← Ioo_insert_left h] lemma insert_Ioc_right_eq_Ioc_succ_of_not_isMax (h : a ≤ b) (hb : ¬ IsMax b) : insert (succ b) (Ioc a b) = Ioc a (succ b) := by ext x; simp +contextual [or_and_left, le_succ_iff_eq_or_le, lt_succ_of_le_of_not_isMax h hb] lemma insert_Ioc_succ_left_eq_Ioc (h : a < b) : insert (succ a) (Ioc (succ a) b) = Ioc a b := by rw [Ioc_insert_left (succ_le_of_lt h), Icc_succ_left_of_not_isMax h.not_isMax] /-! #### Orders with no maximal elements ##### Equalities of intervals -/ variable [NoMaxOrder α] lemma Icc_succ_left_eq_Ioc (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_eq_Ioc_of_not_isMax (not_isMax _) _ lemma Ico_succ_right_eq_Icc (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_eq_Icc_of_not_isMax (not_isMax _) _ lemma Ioo_succ_right_eq_Ioc (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_eq_Ioc_of_not_isMax (not_isMax _) _ lemma Ico_succ_succ_eq_Ioc (a b : α) : Ico (succ a) (succ b) = Ioc a b := Ico_succ_succ_eq_Ioc_of_not_isMax (not_isMax _) _ /-! ##### Inserting into intervals -/ lemma insert_Ico_right_eq_Ico_succ (h : a ≤ b) : insert b (Ico a b) = Ico a (succ b) := insert_Ico_right_eq_Ico_succ_of_not_isMax h (not_isMax _) lemma insert_Ioc_right_eq_Ioc_succ (h : a ≤ b) : insert (succ b) (Ioc a b) = Ioc a (succ b) := insert_Ioc_right_eq_Ioc_succ_of_not_isMax h (not_isMax _) end SuccOrder section PredOrder variable [PredOrder α] {a b : α} /-! #### Orders possibly with minimal elements ##### Equalities of intervals -/ lemma Ioc_pred_right_eq_Ioo (a b : α) : Ioc a (pred b) = Ioo a b := by by_cases hb : IsMin b · rw [Ioc_eq_empty (hb.mono <| pred_le _).not_lt, Ioo_eq_empty hb.not_lt] · ext x rw [mem_Ioc, mem_Ioo, le_pred_iff_of_not_isMin hb] lemma Icc_pred_right_eq_Ico_of_not_isMin (hb : ¬ IsMin b) (a : α) : Icc a (pred b) = Ico a b := by ext x; rw [mem_Icc, mem_Ico, le_pred_iff_of_not_isMin hb] lemma Ioc_pred_left_eq_Icc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (pred a) b = Icc a b := by ext x; rw [mem_Ioc, mem_Icc, pred_lt_iff_of_not_isMin ha] lemma Ioo_pred_left_eq_Ioc_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioo (pred a) b = Ico a b := by ext x; rw [mem_Ioo, mem_Ico, pred_lt_iff_of_not_isMin ha] lemma Ioc_pred_pred_eq_Ico_of_not_isMin (ha : ¬ IsMin a) (b : α) : Ioc (pred a) (pred b) = Ico a b := by rw [Ioc_pred_right_eq_Ioo, Ioo_pred_left_eq_Ioc_of_not_isMin ha] /-! ##### Inserting into intervals -/ lemma insert_Icc_pred_right_eq_Icc (h : a ≤ b) : insert b (Icc a (pred b)) = Icc a b := by ext x; simp [or_and_left, ← le_iff_eq_or_le_pred]; simp_all lemma insert_Icc_left_eq_Icc_pred (h : pred a ≤ b) : insert (pred a) (Icc a b) = Icc (pred a) b := by ext x; simp [or_and_left, pred_le_iff_eq_or_le]; simp_all lemma insert_Ioc_left_eq_Ioc_pred_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert a (Ioc a b) = Ioc (pred a) b := by rw [Ioc_pred_left_of_not_isMin ha, Ioc_insert_left h] lemma insert_Ioc_pred_right_eq_Ioc (h : a < b) : insert b (Ioc a (pred b)) = Ioc a b := by rw [Ioc_pred_right_of_not_isMin h.not_isMin, Ioo_insert_right h] lemma insert_Ico_left_eq_Ico_pred_of_not_isMin (h : a ≤ b) (ha : ¬ IsMin a) : insert (pred a) (Ico a b) = Ico (pred a) b := by ext x; simp +contextual [or_and_left, pred_le_iff_eq_or_le, pred_lt_of_not_isMin_of_le ha h] lemma insert_Ico_pred_right_eq_Ico (h : a < b) : insert (pred b) (Ico a (pred b)) = Ico a b := by rw [Ico_insert_right (le_pred_of_lt h), Icc_pred_right_of_not_isMin h.not_isMin] /-! #### Orders with no minimal elements ##### Equalities of intervals -/ variable [NoMinOrder α] lemma Icc_pred_right_eq_Ico (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_eq_Ico_of_not_isMin (not_isMin _) _ lemma Ioc_pred_left_eq_Icc (a b : α) : Ioc (pred a) b = Icc a b := Ioc_pred_left_eq_Icc_of_not_isMin (not_isMin _) _ lemma Ioo_pred_left_eq_Ioc (a b : α) : Ioo (pred a) b = Ico a b := Ioo_pred_left_eq_Ioc_of_not_isMin (not_isMin _) _ lemma Ioc_pred_pred_eq_Ico (a b : α) : Ioc (pred a) (pred b) = Ico a b := Ioc_pred_pred_eq_Ico_of_not_isMin (not_isMin _) _ /-! ##### Inserting into intervals -/ lemma insert_Ioc_left_eq_Ioc_pred (h : a ≤ b) : insert a (Ioc a b) = Ioc (pred a) b := insert_Ioc_left_eq_Ioc_pred_of_not_isMin h (not_isMin _) lemma insert_Ico_left_eq_Ico_pred (h : a ≤ b) : insert (pred a) (Ico a b) = Ico (pred a) b := insert_Ico_left_eq_Ico_pred_of_not_isMin h (not_isMin _) end PredOrder section SuccPredOrder variable [SuccOrder α] [PredOrder α] [Nontrivial α] lemma Icc_succ_pred_eq_Ioo (a b : α) : Icc (succ a) (pred b) = Ioo a b := by by_cases hb : IsMin b · rw [Icc_eq_empty, Ioo_eq_empty hb.not_lt] exact fun h ↦ not_isMin_succ _ <| hb.mono <| h.trans <| pred_le _ · rw [Icc_pred_right_eq_Ico_of_not_isMin hb, Ico_succ_left_eq_Ioo] end SuccPredOrder /-! ### One-sided interval towards `⊥` -/ section SuccOrder variable [SuccOrder α] {b : α} lemma Iio_succ_eq_Iic_of_not_isMax (hb : ¬ IsMax b) : Iio (succ b) = Iic b := by ext x; rw [mem_Iio, mem_Iic, lt_succ_iff_of_not_isMax hb] variable [NoMaxOrder α] lemma Iio_succ_eq_Iic (b : α) : Iio (succ b) = Iic b := Iio_succ_eq_Iic_of_not_isMax (not_isMax _) end SuccOrder section PredOrder variable [PredOrder α] {a b : α} lemma Iic_pred_eq_Iio_of_not_isMin (hb : ¬ IsMin b) : Iic (pred b) = Iio b := by ext x; rw [mem_Iic, mem_Iio, le_pred_iff_of_not_isMin hb] variable [NoMinOrder α] lemma Iic_pred_eq_Iio (b : α) : Iic (pred b) = Iio b := Iic_pred_eq_Iio_of_not_isMin (not_isMin _) end PredOrder /-! ### One-sided interval towards `⊤` -/ section SuccOrder variable [SuccOrder α] {a : α} lemma Ici_succ_eq_Ioi_of_not_isMax (ha : ¬ IsMax a) : Ici (succ a) = Ioi a := by ext x; rw [mem_Ici, mem_Ioi, succ_le_iff_of_not_isMax ha] variable [NoMaxOrder α] lemma Ici_succ_eq_Ioi (a : α) : Ici (succ a) = Ioi a := Ici_succ_eq_Ioi_of_not_isMax (not_isMax _) end SuccOrder section PredOrder variable [PredOrder α] {a a : α} lemma Ioi_pred_eq_Ici_of_not_isMin (ha : ¬ IsMin a) : Ioi (pred a) = Ici a := by ext x; rw [mem_Ioi, mem_Ici, pred_lt_iff_of_not_isMin ha] variable [NoMinOrder α] lemma Ioi_pred_eq_Ici (a : α) : Ioi (pred a) = Ici a := Ioi_pred_eq_Ici_of_not_isMin (not_isMin _) end PredOrder end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/SuccOrder.lean
import Mathlib.Order.LatticeIntervals import Mathlib.Order.SuccPred.Basic /-! # Successors in intervals If `j` is an element of a partially ordered set equipped with a successor function, then for any element `i : Set.Iic j` which is not the maximum, we have `↑(Order.succ i) = Order.succ ↑i`. -/ namespace Set variable {J : Type*} [PartialOrder J] lemma Iic.coe_succ_of_not_isMax [SuccOrder J] {j : J} {i : Set.Iic j} (hi : ¬ IsMax i) : (Order.succ i).1 = Order.succ i.1 := by rw [coe_succ_of_mem] apply Order.succ_le_of_lt exact lt_of_le_of_ne (α := Set.Iic j) le_top (by simpa using hi) lemma Iic.succ_eq_of_not_isMax [SuccOrder J] {j : J} {i : Set.Iic j} (hi : ¬ IsMax i) : Order.succ i = ⟨Order.succ i.1, by rw [← coe_succ_of_not_isMax hi] apply Subtype.coe_prop⟩ := by ext simp only [coe_succ_of_not_isMax hi] lemma Ici.coe_pred_of_not_isMin [PredOrder J] {j : J} {i : Set.Ici j} (hi : ¬ IsMin i) : (Order.pred i).1 = Order.pred i.1 := by rw [coe_pred_of_mem] apply Order.le_pred_of_lt exact lt_of_le_of_ne (α := Set.Ici j) bot_le (Ne.symm (by simpa using hi)) lemma Ici.pred_eq_of_not_isMin [PredOrder J] {j : J} {i : Set.Ici j} (hi : ¬ IsMin i) : Order.pred i = ⟨Order.pred i.1, by rw [← coe_pred_of_not_isMin hi] apply Subtype.coe_prop⟩ := by ext simp only [coe_pred_of_not_isMin hi] end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/SurjOn.lean
import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.LinearOrder /-! # Monotone surjective functions are surjective on intervals A monotone surjective function sends any interval in the domain onto the interval with corresponding endpoints in the range. This is expressed in this file using `Set.surjOn`, and provided for all permutations of interval endpoints. -/ variable {α : Type*} {β : Type*} [LinearOrder α] [PartialOrder β] {f : α → β} open Set Function open OrderDual (toDual) theorem surjOn_Ioo_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ioo a b) (Ioo (f a) (f b)) := by intro p hp rcases h_surj p with ⟨x, rfl⟩ refine ⟨x, mem_Ioo.2 ?_, rfl⟩ contrapose! hp exact fun h => h.2.not_ge (h_mono <| hp <| h_mono.reflect_lt h.1) theorem surjOn_Ico_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ico a b) (Ico (f a) (f b)) := by obtain hab | hab := lt_or_ge a b · intro p hp rcases eq_left_or_mem_Ioo_of_mem_Ico hp with (rfl | hp') · exact mem_image_of_mem f (left_mem_Ico.mpr hab) · exact image_mono Ioo_subset_Ico_self <| surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp' · rw [Ico_eq_empty (h_mono hab).not_gt] exact surjOn_empty f _ theorem surjOn_Ioc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a b : α) : SurjOn f (Ioc a b) (Ioc (f a) (f b)) := by simpa using surjOn_Ico_of_monotone_surjective h_mono.dual h_surj (toDual b) (toDual a) -- to see that the hypothesis `a ≤ b` is necessary, consider a constant function theorem surjOn_Icc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) {a b : α} (hab : a ≤ b) : SurjOn f (Icc a b) (Icc (f a) (f b)) := by intro p hp rcases eq_endpoints_or_mem_Ioo_of_mem_Icc hp with (rfl | rfl | hp') · exact ⟨a, left_mem_Icc.mpr hab, rfl⟩ · exact ⟨b, right_mem_Icc.mpr hab, rfl⟩ · exact image_mono Ioo_subset_Icc_self <| surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp' theorem surjOn_Ioi_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Ioi a) (Ioi (f a)) := by rw [← compl_Iic, ← compl_compl (Ioi (f a))] refine MapsTo.surjOn_compl ?_ h_surj exact fun x hx => (h_mono hx).not_gt theorem surjOn_Iio_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Iio a) (Iio (f a)) := @surjOn_Ioi_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a theorem surjOn_Ici_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Ici a) (Ici (f a)) := by rw [← Ioi_union_left, ← Ioi_union_left] exact (surjOn_Ioi_of_monotone_surjective h_mono h_surj a).union_union (@image_singleton _ _ f a ▸ surjOn_image _ _) theorem surjOn_Iic_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f) (a : α) : SurjOn f (Iic a) (Iic (f a)) := @surjOn_Ici_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Final.lean
import Mathlib.CategoryTheory.Filtered.Final /-! # Final functors between intervals -/ universe u instance Set.Ici.subtype_functor_final {J : Type u} [LinearOrder J] (j : J) : (Subtype.mono_coe (Set.Ici j)).functor.Final := by rw [Monotone.final_functor_iff] intro k exact ⟨⟨max j k, le_max_left _ _⟩, le_max_right _ _⟩