Zulip Chat Archive

Stream: Is there code for X?

Topic: Sorting `Sym2`


Eric Wieser (Jun 28 2024 at 19:53):

Do we have anything along the lines of

import Mathlib.Data.Finset.Sym

namespace Sym2
variable {α}

def sup [SemilatticeSup α] (x : Sym2 α) : α := Sym2.lift (·  ·), sup_comm x

@[simp] theorem sup_mk [SemilatticeSup α] (a b : α) : s(a, b).sup = a  b := rfl

def inf [SemilatticeInf α] (x : Sym2 α) : α := Sym2.lift (·  ·), inf_comm x

@[simp] theorem inf_mk [SemilatticeInf α] (a b : α) : s(a, b).inf = a  b := rfl

theorem inf_le_sup [Lattice α] (s : Sym2 α) : s.inf  s.sup := by
  cases s using Sym2.ind; simp [_root_.inf_le_sup]

def sortEquiv [LinearOrder α] : Sym2 α  { p : α × α // p.1  p.2 } where
  toFun s := (s.inf, s.sup), inf_le_sup _⟩
  invFun p := Sym2.mk p
  left_inv := Sym2.ind fun a b => mk_eq_mk_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])

end Sym2

Last updated: May 02 2025 at 03:31 UTC