| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Structures for order-theoretic lattices |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- The contents of this module should be accessed via |
| 8 |
-- `Relation.Binary.Lattice`. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
open import Relation.Binary.Core using (Rel) |
| 13 |
|
| 14 |
module Relation.Binary.Lattice.Structures |
| 15 |
{a ℓ₁ ℓ₂} {A : Set a} |
| 16 |
(_≈_ : Rel A ℓ₁) -- The underlying equality. |
| 17 |
(_≤_ : Rel A ℓ₂) -- The partial order. |
| 18 |
where |
| 19 |
|
| 20 |
open import Algebra.Core using (Op₁; Op₂) |
| 21 |
open import Algebra.Definitions using (_DistributesOverˡ_) |
| 22 |
open import Data.Product.Base using (_×_; _,_) |
| 23 |
open import Level using (suc; _⊔_) |
| 24 |
open import Relation.Binary.Definitions using (Minimum; Maximum) |
| 25 |
open import Relation.Binary.Lattice.Definitions |
| 26 |
using (Supremum; Infimum; Exponential) |
| 27 |
open import Relation.Binary.Structures using (IsPartialOrder) |
| 28 |
|
| 29 |
------------------------------------------------------------------------ |
| 30 |
-- Join semilattices |
| 31 |
|
| 32 |
record IsJoinSemilattice (_∨_ : Op₂ A) -- The join operation. |
| 33 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 34 |
field |
| 35 |
isPartialOrder : IsPartialOrder _≈_ _≤_ |
| 36 |
supremum : Supremum _≤_ _∨_ |
| 37 |
|
| 38 |
x≤x∨y : ∀ x y → x ≤ (x ∨ y) |
| 39 |
x≤x∨y x y = let pf , _ , _ = supremum x y in pf |
| 40 |
|
| 41 |
y≤x∨y : ∀ x y → y ≤ (x ∨ y) |
| 42 |
y≤x∨y x y = let _ , pf , _ = supremum x y in pf |
| 43 |
|
| 44 |
∨-least : ∀ {x y z} → x ≤ z → y ≤ z → (x ∨ y) ≤ z |
| 45 |
∨-least {x} {y} {z} = let _ , _ , pf = supremum x y in pf z |
| 46 |
|
| 47 |
open IsPartialOrder isPartialOrder public |
| 48 |
|
| 49 |
record IsBoundedJoinSemilattice (_∨_ : Op₂ A) -- The join operation. |
| 50 |
(⊥ : A) -- The minimum. |
| 51 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 52 |
field |
| 53 |
isJoinSemilattice : IsJoinSemilattice _∨_ |
| 54 |
minimum : Minimum _≤_ ⊥ |
| 55 |
|
| 56 |
open IsJoinSemilattice isJoinSemilattice public |
| 57 |
|
| 58 |
------------------------------------------------------------------------ |
| 59 |
-- Meet semilattices |
| 60 |
|
| 61 |
record IsMeetSemilattice (_∧_ : Op₂ A) -- The meet operation. |
| 62 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 63 |
field |
| 64 |
isPartialOrder : IsPartialOrder _≈_ _≤_ |
| 65 |
infimum : Infimum _≤_ _∧_ |
| 66 |
|
| 67 |
x∧y≤x : ∀ x y → (x ∧ y) ≤ x |
| 68 |
x∧y≤x x y = let pf , _ , _ = infimum x y in pf |
| 69 |
|
| 70 |
x∧y≤y : ∀ x y → (x ∧ y) ≤ y |
| 71 |
x∧y≤y x y = let _ , pf , _ = infimum x y in pf |
| 72 |
|
| 73 |
∧-greatest : ∀ {x y z} → x ≤ y → x ≤ z → x ≤ (y ∧ z) |
| 74 |
∧-greatest {x} {y} {z} = let _ , _ , pf = infimum y z in pf x |
| 75 |
|
| 76 |
open IsPartialOrder isPartialOrder public |
| 77 |
|
| 78 |
record IsBoundedMeetSemilattice (_∧_ : Op₂ A) -- The join operation. |
| 79 |
(⊤ : A) -- The maximum. |
| 80 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 81 |
field |
| 82 |
isMeetSemilattice : IsMeetSemilattice _∧_ |
| 83 |
maximum : Maximum _≤_ ⊤ |
| 84 |
|
| 85 |
open IsMeetSemilattice isMeetSemilattice public |
| 86 |
|
| 87 |
------------------------------------------------------------------------ |
| 88 |
-- Lattices |
| 89 |
|
| 90 |
record IsLattice (_∨_ : Op₂ A) -- The join operation. |
| 91 |
(_∧_ : Op₂ A) -- The meet operation. |
| 92 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 93 |
field |
| 94 |
isPartialOrder : IsPartialOrder _≈_ _≤_ |
| 95 |
supremum : Supremum _≤_ _∨_ |
| 96 |
infimum : Infimum _≤_ _∧_ |
| 97 |
|
| 98 |
isJoinSemilattice : IsJoinSemilattice _∨_ |
| 99 |
isJoinSemilattice = record |
| 100 |
{ isPartialOrder = isPartialOrder |
| 101 |
; supremum = supremum |
| 102 |
} |
| 103 |
|
| 104 |
isMeetSemilattice : IsMeetSemilattice _∧_ |
| 105 |
isMeetSemilattice = record |
| 106 |
{ isPartialOrder = isPartialOrder |
| 107 |
; infimum = infimum |
| 108 |
} |
| 109 |
|
| 110 |
open IsJoinSemilattice isJoinSemilattice public |
| 111 |
using (x≤x∨y; y≤x∨y; ∨-least) |
| 112 |
open IsMeetSemilattice isMeetSemilattice public |
| 113 |
using (x∧y≤x; x∧y≤y; ∧-greatest) |
| 114 |
open IsPartialOrder isPartialOrder public |
| 115 |
|
| 116 |
record IsDistributiveLattice (_∨_ : Op₂ A) -- The join operation. |
| 117 |
(_∧_ : Op₂ A) -- The meet operation. |
| 118 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 119 |
field |
| 120 |
isLattice : IsLattice _∨_ _∧_ |
| 121 |
∧-distribˡ-∨ : _DistributesOverˡ_ _≈_ _∧_ _∨_ |
| 122 |
|
| 123 |
open IsLattice isLattice public |
| 124 |
|
| 125 |
record IsBoundedLattice (_∨_ : Op₂ A) -- The join operation. |
| 126 |
(_∧_ : Op₂ A) -- The meet operation. |
| 127 |
(⊤ : A) -- The maximum. |
| 128 |
(⊥ : A) -- The minimum. |
| 129 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 130 |
field |
| 131 |
isLattice : IsLattice _∨_ _∧_ |
| 132 |
maximum : Maximum _≤_ ⊤ |
| 133 |
minimum : Minimum _≤_ ⊥ |
| 134 |
|
| 135 |
open IsLattice isLattice public |
| 136 |
|
| 137 |
isBoundedJoinSemilattice : IsBoundedJoinSemilattice _∨_ ⊥ |
| 138 |
isBoundedJoinSemilattice = record |
| 139 |
{ isJoinSemilattice = isJoinSemilattice |
| 140 |
; minimum = minimum |
| 141 |
} |
| 142 |
|
| 143 |
isBoundedMeetSemilattice : IsBoundedMeetSemilattice _∧_ ⊤ |
| 144 |
isBoundedMeetSemilattice = record |
| 145 |
{ isMeetSemilattice = isMeetSemilattice |
| 146 |
; maximum = maximum |
| 147 |
} |
| 148 |
|
| 149 |
------------------------------------------------------------------------ |
| 150 |
-- Heyting algebras (a bounded lattice with exponential operator) |
| 151 |
|
| 152 |
record IsHeytingAlgebra (_∨_ : Op₂ A) -- The join operation. |
| 153 |
(_∧_ : Op₂ A) -- The meet operation. |
| 154 |
(_⇨_ : Op₂ A) -- The exponential operation. |
| 155 |
(⊤ : A) -- The maximum. |
| 156 |
(⊥ : A) -- The minimum. |
| 157 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 158 |
field |
| 159 |
isBoundedLattice : IsBoundedLattice _∨_ _∧_ ⊤ ⊥ |
| 160 |
exponential : Exponential _≤_ _∧_ _⇨_ |
| 161 |
|
| 162 |
transpose-⇨ : ∀ {w x y} → (w ∧ x) ≤ y → w ≤ (x ⇨ y) |
| 163 |
transpose-⇨ {w} {x} {y} = let pf , _ = exponential w x y in pf |
| 164 |
|
| 165 |
transpose-∧ : ∀ {w x y} → w ≤ (x ⇨ y) → (w ∧ x) ≤ y |
| 166 |
transpose-∧ {w} {x} {y} = let _ , pf = exponential w x y in pf |
| 167 |
|
| 168 |
open IsBoundedLattice isBoundedLattice public |
| 169 |
|
| 170 |
------------------------------------------------------------------------ |
| 171 |
-- Boolean algebras (a specialized Heyting algebra) |
| 172 |
|
| 173 |
record IsBooleanAlgebra (_∨_ : Op₂ A) -- The join operation. |
| 174 |
(_∧_ : Op₂ A) -- The meet operation. |
| 175 |
(¬_ : Op₁ A) -- The negation operation. |
| 176 |
(⊤ : A) -- The maximum. |
| 177 |
(⊥ : A) -- The minimum. |
| 178 |
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 179 |
infixr 5 _⇨_ |
| 180 |
_⇨_ : Op₂ A |
| 181 |
x ⇨ y = (¬ x) ∨ y |
| 182 |
|
| 183 |
field |
| 184 |
isHeytingAlgebra : IsHeytingAlgebra _∨_ _∧_ _⇨_ ⊤ ⊥ |
| 185 |
|
| 186 |
open IsHeytingAlgebra isHeytingAlgebra public |