/-
Copyright (c) 2024 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
module
public import Mathlib.Data.Sym.Sym2
set_option doc.verso true
set_option doc.verso.suggestions false
/-!
# Sorting the elements of `Sym2`
This file provides `Sym2.sortEquiv`, the forward direction of which is somewhat analogous to
`Multiset.sort`.
-/
@[expose] public section
namespace Sym2
variable {α}
/-- The supremum of the two elements. -/
def sup [SemilatticeSup α] (x : Sym2 α) : α := Sym2.lift ⟨(· ⊔ ·), sup_comm⟩ x
@[simp] theorem sup_mk [SemilatticeSup α] (a b : α) : s(a, b).sup = a ⊔ b := rfl
/-- The infimum of the two elements. -/
def inf [SemilatticeInf α] (x : Sym2 α) : α := Sym2.lift ⟨(· ⊓ ·), inf_comm⟩ x
@[simp] theorem inf_mk [SemilatticeInf α] (a b : α) : s(a, b).inf = a ⊓ b := rfl
protected theorem inf_le_sup [Lattice α] (s : Sym2 α) : s.inf ≤ s.sup := by
cases s using Sym2.ind; simp
/-- In a linear order, symmetric squares are canonically identified with ordered pairs. -/
@[simps!]
def sortEquiv [LinearOrder α] : Sym2 α ≃ { p : α × α // p.1 ≤ p.2 } where
toFun s := ⟨(s.inf, s.sup), Sym2.inf_le_sup _⟩
invFun p := s(p.1.1, p.1.2)
left_inv := Sym2.ind fun a b => eq_iff.mpr <| by
cases le_total a b with
| inl h => simp [h]
| inr h => simp [h]
right_inv := Subtype.rec <| Prod.rec fun x y hxy =>
Subtype.ext <| Prod.ext (by simp [hxy]) (by simp [hxy])
/-- In a linear order, two symmetric squares are equal if and only if
they have the same infimum and supremum. -/
theorem inf_eq_inf_and_sup_eq_sup [LinearOrder α] {s t : Sym2 α} :
s.inf = t.inf ∧ s.sup = t.sup ↔ s = t := by
induction s with | _ a b
induction t with | _ c d
obtain hab | hba := le_total a b <;> obtain hcd | hdc := le_total c d <;>
aesop (add unsafe le_antisymm)
end Sym2
¤ Dauer der Verarbeitung: 0.4 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland