Lattice.agda 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module Lattice where
  2. open import Prelude
  3. open import PartialOrder as PO
  4. open import SemiLattice as SL
  5. import Chain
  6. open POrder using (Dual)
  7. record Lattice (A : Set) : Set1 where
  8. field
  9. sl : SemiLattice A
  10. _⊔_ : A -> A -> A
  11. prf : IsSemiLattice (Dual (SemiLat.po sl)) _⊔_
  12. module Lat {A : Set}(L : Lattice A) where
  13. private
  14. module LL = Lattice L
  15. module SLL = SemiLat LL.sl
  16. private
  17. sl' : SemiLattice A
  18. sl' = record { po = Dual SLL.po; _⊓_ = LL._⊔_; prf = LL.prf }
  19. module SLL' = SemiLat sl'
  20. hiding ( Monotone
  21. ; Antitone
  22. ; _==_; ==-refl; ==-sym; ==-trans
  23. ; po
  24. )
  25. renaming ( _≤_ to _≥_
  26. ; ≤-refl to ≥-refl
  27. ; ≤-trans to ≥-trans
  28. ; ≤-antisym to ≥-antisym
  29. ; ==≤-L to ==≥-R
  30. ; ==≤-R to ==≥-L
  31. ; _⊓_ to _⊔_
  32. ; ⊓-lbL to ⊔-ubL
  33. ; ⊓-lbR to ⊔-ubR
  34. ; ⊓-glb to ⊔-lub
  35. ; ⊓-commute to ⊔-commute
  36. ; ⊓-assoc to ⊔-assoc
  37. ; ⊓-idem to ⊔-idem
  38. ; ≤⊓-L to ≥⊔-L
  39. ; ≤⊓-R to ≥⊔-R
  40. ; ⊓-monotone-R to ⊔-monotone-R
  41. ; ⊓-monotone-L to ⊔-monotone-L
  42. ; ≤⊓-compat to ≥⊔-compat
  43. ; ⊓-cong to ⊔-cong
  44. ; ⊓-cong-L to ⊔-cong-L
  45. ; ⊓-cong-R to ⊔-cong-R
  46. )
  47. open SLL public
  48. open SLL' public
  49. DualLattice : Lattice A
  50. DualLattice = record { sl = sl'; _⊔_ = _⊓_; prf = SemiLattice.prf LL.sl }
  51. module MeetJoin {A : Set}(L : Lattice A) where
  52. private module L = Lat L
  53. open L
  54. open module C== = Chain _==_ (\x -> ==-refl) (\x y z -> ==-trans)
  55. -- Experiment with very explicit proof
  56. ⊓⊔-absorb-LL = \{x y} ->
  57. (x ⊓ (x ⊔ y)) == x from
  58. ≤-antisym
  59. ((x ⊓ (x ⊔ y)) ≤ x from ⊓-lbL)
  60. (x ≤ (x ⊓ (x ⊔ y)) from
  61. ⊓-glb (x ≤ x from ≤-refl)
  62. (x ≤ (x ⊔ y) from ⊔-ubL)
  63. )
  64. ⊓⊔-eq : forall {x y} -> (x ⊓ y) == (x ⊔ y) -> x == y
  65. ⊓⊔-eq {x}{y} p =
  66. chain> x
  67. === x ⊓ (x ⊔ y) by ==-sym ⊓⊔-absorb-LL
  68. === x ⊓ (x ⊓ y) by ==-sym (⊓-cong-R p)
  69. === (x ⊓ x) ⊓ y by {!!} -- ⊓-assoc
  70. === x ⊓ y by ⊓-cong-L ⊓-idem
  71. === y ⊓ x by ⊓-commute
  72. === (y ⊓ y) ⊓ x by ⊓-cong-L (==-sym ⊓-idem)
  73. === y ⊓ (y ⊓ x) by ==-sym ⊓-assoc
  74. === y ⊓ (x ⊓ y) by ⊓-cong-R ⊓-commute
  75. === y ⊓ (x ⊔ y) by {! !} -- ⊓-cong-R p
  76. === y ⊓ (y ⊔ x) by ⊓-cong-R ⊔-commute
  77. === y by ⊓⊔-absorb-LL
  78. module JoinMeet {A : Set}(L : Lattice A) =
  79. MeetJoin (Lat.DualLattice L)
  80. hiding (⊓⊔-eq)
  81. renaming (⊓⊔-absorb-LL to ⊔⊓-absorb-LL)