PartialOrder.agda 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module PartialOrder where
  2. open import Prelude
  3. record PartialOrder (A : Set) : Set1 where
  4. field
  5. _==_ : A -> A -> Set
  6. _≤_ : A -> A -> Set
  7. ==-def : forall {x y} -> (x == y) ⇐⇒ (x ≤ y) ∧ (y ≤ x)
  8. ≤-refl : forall {x} -> x ≤ x
  9. ≤-trans : forall {x y z} -> x ≤ y -> y ≤ z -> x ≤ z
  10. module POrder {A : Set}(ord : PartialOrder A) where
  11. private module POrd = PartialOrder ord
  12. open POrd public
  13. infix 60 _≤_ _==_
  14. Monotone : (A -> A) -> Set
  15. Monotone f = forall {x y} -> x ≤ y -> f x ≤ f y
  16. Antitone : (A -> A) -> Set
  17. Antitone f = forall {x y} -> x ≤ y -> f y ≤ f x
  18. ≤-antisym : forall {x y} -> x ≤ y -> y ≤ x -> x == y
  19. ≤-antisym p q = snd ==-def (p , q)
  20. ==≤-L : forall {x y} -> x == y -> x ≤ y
  21. ==≤-L x=y = fst (fst ==-def x=y)
  22. ==≤-R : forall {x y} -> x == y -> y ≤ x
  23. ==≤-R x=y = snd (fst ==-def x=y)
  24. ==-refl : forall {x} -> x == x
  25. ==-refl = ≤-antisym ≤-refl ≤-refl
  26. ==-sym : forall {x y} -> x == y -> y == x
  27. ==-sym xy = snd ==-def (swap (fst ==-def xy))
  28. ==-trans : forall {x y z} -> x == y -> y == z -> x == z
  29. ==-trans xy yz = ≤-antisym
  30. (≤-trans x≤y y≤z)
  31. (≤-trans z≤y y≤x)
  32. where
  33. x≤y = ==≤-L xy
  34. y≤z = ==≤-L yz
  35. y≤x = ==≤-R xy
  36. z≤y = ==≤-R yz
  37. Dual : PartialOrder A
  38. Dual = record
  39. { _==_ = _==_
  40. ; _≤_ = \x y -> y ≤ x
  41. ; ==-def = (swap ∘ fst ==-def , snd ==-def ∘ swap)
  42. ; ≤-refl = ≤-refl
  43. ; ≤-trans = \yx zy -> ≤-trans zy yx
  44. }