diff --git a/Mathlib/Data/Sum/Order.lean b/Mathlib/Data/Sum/Order.lean index 97959964a3dfc1..b87733b9e21cae 100644 --- a/Mathlib/Data/Sum/Order.lean +++ b/Mathlib/Data/Sum/Order.lean @@ -717,6 +717,22 @@ theorem sumLexDualAntidistrib_symm_inr : (sumLexDualAntidistrib α β).symm (inr (toDual a)) = toDual (inl a) := rfl +/-- `Equiv.sumEmpty` as an `OrderIso` with the lexicographic sum. -/ +def sumLexEmpty [IsEmpty β] : + Lex (α ⊕ β) ≃o α := RelIso.sumLexEmpty .. + +/-- `Equiv.emptySum` as an `OrderIso` with the lexicographic sum. -/ +def emptySumLex [IsEmpty β] : + Lex (β ⊕ α) ≃o α := RelIso.emptySumLex .. + +@[simp] +lemma sumLexEmpty_apply_inl [IsEmpty β] (x : α) : + sumLexEmpty (β := β) (toLex <| .inl x) = x := rfl + +@[simp] +lemma emptySumLex_apply_inr [IsEmpty β] (x : α) : + emptySumLex (β := β) (toLex <| .inr x) = x := rfl + end OrderIso variable [LE α] diff --git a/Mathlib/Order/Hom/Basic.lean b/Mathlib/Order/Hom/Basic.lean index f22f138e25411b..d5ec41f174a683 100644 --- a/Mathlib/Order/Hom/Basic.lean +++ b/Mathlib/Order/Hom/Basic.lean @@ -884,6 +884,13 @@ def prodComm : α × β ≃o β × α where toEquiv := Equiv.prodComm α β map_rel_iff' := Prod.swap_le_swap +/-- `Equiv.prodAssoc` promoted to an order isomorphism. -/ +@[simps! (attr := grind =)] +def prodAssoc (α β γ : Type*) [LE α] [LE β] [LE γ] : + (α × β) × γ ≃o α × (β × γ) where + toEquiv := .prodAssoc α β γ + map_rel_iff' := @fun ⟨⟨_, _⟩, _⟩ ⟨⟨_, _⟩, _⟩ ↦ by simp [Equiv.prodAssoc, and_assoc] + @[simp] theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap := rfl @@ -1069,6 +1076,10 @@ noncomputable def ofUnique toEquiv := Equiv.ofUnique α β map_rel_iff' := by simp +/-- `Equiv.equivOfIsEmpty` promoted to an `OrderIso`. -/ +def ofIsEmpty (α β : Type*) [Preorder α] [Preorder β] [IsEmpty α] [IsEmpty β] : α ≃o β := + ⟨Equiv.equivOfIsEmpty α β, @isEmptyElim _ _ _⟩ + end OrderIso namespace Equiv diff --git a/Mathlib/Order/Hom/Lex.lean b/Mathlib/Order/Hom/Lex.lean index 46bbd436d776f7..2f8886bebdbd7f 100644 --- a/Mathlib/Order/Hom/Lex.lean +++ b/Mathlib/Order/Hom/Lex.lean @@ -179,4 +179,33 @@ variable {α β} in theorem uniqueProd_apply [Preorder α] [Unique α] [LE β] (x : α ×ₗ β) : uniqueProd α β x = (ofLex x).2 := rfl +/-- `Equiv.prodAssoc` promoted to an order isomorphism of lexicographic products. -/ +@[simps!] +def prodLexAssoc (α β γ : Type*) + [Preorder α] [Preorder β] [Preorder γ] : (α ×ₗ β) ×ₗ γ ≃o α ×ₗ β ×ₗ γ where + toEquiv := .trans ofLex <| .trans (.prodCongr ofLex <| .refl _) <| + .trans (.prodAssoc α β γ) <| .trans (.prodCongr (.refl _) toLex) <| toLex + map_rel_iff' := by + simp only [Prod.Lex.le_iff, Prod.Lex.lt_iff, Equiv.trans_apply, Equiv.prodCongr_apply, + Equiv.prodAssoc_apply] + grind [EmbeddingLike.apply_eq_iff_eq, ofLex_toLex] + +/-- `Equiv.sumProdDistrib` promoted to an order isomorphism of lexicographic products. + +Right distributivity doesn't hold. A counterexample is `ℕ ×ₗ (Unit ⊕ₗ Unit) ≃o ℕ` +which is not isomorphic to `ℕ ×ₗ Unit ⊕ₗ ℕ ×ₗ Unit ≃o ℕ ⊕ₗ ℕ`. -/ +@[simps!] +def sumLexProdLexDistrib (α β γ : Type*) + [Preorder α] [Preorder β] [Preorder γ] : (α ⊕ₗ β) ×ₗ γ ≃o α ×ₗ γ ⊕ₗ β ×ₗ γ where + toEquiv := .trans ofLex <| .trans (.prodCongr ofLex <| .refl _) <| + .trans (.sumProdDistrib α β γ) <| .trans (.sumCongr toLex toLex) toLex + map_rel_iff' := by simp [Prod.Lex.le_iff] + +/-- `Equiv.prodCongr` promoted to an order isomorphism between lexicographic products. -/ +@[simps! apply] +def prodLexCongr {α β γ δ : Type*} [Preorder α] [Preorder β] + [Preorder γ] [Preorder δ] (ea : α ≃o β) (eb : γ ≃o δ) : α ×ₗ γ ≃o β ×ₗ δ where + toEquiv := ofLex.trans ((Equiv.prodCongr ea eb).trans toLex) + map_rel_iff' := by simp [Prod.Lex.le_iff] + end Prod.Lex