SemiLattice.agda 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. module SemiLattice where
  2. open import Prelude
  3. open import PartialOrder as PO
  4. import Chain
  5. private
  6. module IsSemiLat
  7. {A : Set}(po : PartialOrder A)(_⊓_ : A -> A -> A) where
  8. private open module PO = PartialOrder po
  9. record IsSemiLattice : Set where
  10. field
  11. ⊓-lbL : forall {x y} -> (x ⊓ y) ≤ x
  12. ⊓-lbR : forall {x y} -> (x ⊓ y) ≤ y
  13. ⊓-glb : forall {x y z} -> z ≤ x -> z ≤ y -> z ≤ (x ⊓ y)
  14. open IsSemiLat public
  15. record SemiLattice (A : Set) : Set1 where
  16. field
  17. po : PartialOrder A
  18. _⊓_ : A -> A -> A
  19. prf : IsSemiLattice po _⊓_
  20. module SemiLat {A : Set}(L : SemiLattice A) where
  21. private module SL = SemiLattice L
  22. private module SLPO = POrder SL.po
  23. private module IsSL = IsSemiLattice SL.po SL._⊓_ SL.prf
  24. open SLPO public
  25. open SL public hiding (prf)
  26. open IsSL public
  27. private open module C≤ = Chain _≤_ (\x -> ≤-refl) (\x y z -> ≤-trans)
  28. renaming (_===_ to _-≤-_; chain>_ to trans>_)
  29. ⊓-commute : forall {x y} -> (x ⊓ y) == (y ⊓ x)
  30. ⊓-commute = ≤-antisym lem lem
  31. where
  32. lem : forall {x y} -> (x ⊓ y) ≤ (y ⊓ x)
  33. lem = ⊓-glb ⊓-lbR ⊓-lbL
  34. ⊓-assoc : forall {x y z} -> (x ⊓ (y ⊓ z)) == ((x ⊓ y) ⊓ z)
  35. ⊓-assoc = ≤-antisym lem₁ lem₂
  36. where
  37. lem₁ : forall {x y z} -> (x ⊓ (y ⊓ z)) ≤ ((x ⊓ y) ⊓ z)
  38. lem₁ = ⊓-glb (⊓-glb ⊓-lbL (≤-trans ⊓-lbR ⊓-lbL))
  39. (≤-trans ⊓-lbR ⊓-lbR)
  40. lem₂ : forall {x y z} -> ((x ⊓ y) ⊓ z) ≤ (x ⊓ (y ⊓ z))
  41. lem₂ = ⊓-glb (≤-trans ⊓-lbL ⊓-lbL)
  42. (⊓-glb (≤-trans ⊓-lbL ⊓-lbR) ⊓-lbR)
  43. ⊓-idem : forall {x} -> (x ⊓ x) == x
  44. ⊓-idem = ≤-antisym ⊓-lbL (⊓-glb ≤-refl ≤-refl)
  45. ≤⊓-L : forall {x y} -> (x ≤ y) ⇐⇒ ((x ⊓ y) == x)
  46. ≤⊓-L = (fwd , bwd)
  47. where
  48. fwd = \x≤y -> ≤-antisym ⊓-lbL (⊓-glb ≤-refl x≤y)
  49. bwd = \x⊓y=x -> ≤-trans (==≤-R x⊓y=x) ⊓-lbR
  50. ≤⊓-R : forall {x y} -> (y ≤ x) ⇐⇒ ((x ⊓ y) == y)
  51. ≤⊓-R {x}{y} = (fwd , bwd)
  52. where
  53. lem : (y ≤ x) ⇐⇒ ((y ⊓ x) == y)
  54. lem = ≤⊓-L
  55. fwd = \y≤x -> ==-trans ⊓-commute (fst lem y≤x)
  56. bwd = \x⊓y=y -> snd lem (==-trans ⊓-commute x⊓y=y)
  57. ⊓-monotone-R : forall {a} -> Monotone (\x -> a ⊓ x)
  58. ⊓-monotone-R x≤y = ⊓-glb ⊓-lbL (≤-trans ⊓-lbR x≤y)
  59. ⊓-monotone-L : forall {a} -> Monotone (\x -> x ⊓ a)
  60. ⊓-monotone-L {a}{x}{y} x≤y =
  61. trans> x ⊓ a
  62. -≤- a ⊓ x by ==≤-L ⊓-commute
  63. -≤- a ⊓ y by ⊓-monotone-R x≤y
  64. -≤- y ⊓ a by ==≤-L ⊓-commute
  65. ≤⊓-compat : forall {w x y z} -> w ≤ y -> x ≤ z -> (w ⊓ x) ≤ (y ⊓ z)
  66. ≤⊓-compat {w}{x}{y}{z} w≤y x≤z =
  67. trans> w ⊓ x
  68. -≤- w ⊓ z by ⊓-monotone-R x≤z
  69. -≤- y ⊓ z by ⊓-monotone-L w≤y
  70. ⊓-cong : forall {w x y z} -> w == y -> x == z -> (w ⊓ x) == (y ⊓ z)
  71. ⊓-cong wy xz = ≤-antisym (≤⊓-compat (==≤-L wy) (==≤-L xz))
  72. (≤⊓-compat (==≤-R wy) (==≤-R xz))
  73. ⊓-cong-L : forall {x y z} -> x == y -> (x ⊓ z) == (y ⊓ z)
  74. ⊓-cong-L xy = ⊓-cong xy ==-refl
  75. ⊓-cong-R : forall {x y z} -> x == y -> (z ⊓ x) == (z ⊓ y)
  76. ⊓-cong-R xy = ⊓-cong ==-refl xy