Debian Codegraph @

src/Algebra/Lattice/Structures.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Some lattice-like structures defined by properties of _∧_ and _∨_
5 -- (not packed up with sets, operations, etc.)
6 --
7 -- For lattices defined via an order relation, see
8 -- Relation.Binary.Lattice.
9 ------------------------------------------------------------------------
10
11 -- The contents of this module should be accessed via `Algebra.Lattice`,
12 -- unless you want to parameterise it via the equality relation.
13
14 {-# OPTIONS --cubical-compatible --safe #-}
15
16 open import Algebra.Core using (Op₁; Op₂)
17 open import Data.Product.Base using (proj₁; proj₂)
18 open import Level using (_⊔_)
19 open import Relation.Binary.Core using (Rel)
20 open import Relation.Binary.Bundles using (Setoid)
21 open import Relation.Binary.Structures using (IsEquivalence)
22
23 module Algebra.Lattice.Structures
24 {a ℓ} {A : Set a} -- The underlying set
25 (_≈_ : Rel A ℓ) -- The underlying equality relation
26 where
27
28 open import Algebra.Definitions _≈_
29 open import Algebra.Structures _≈_
30
31 ------------------------------------------------------------------------
32 -- Structures with 1 binary operation
33
34 IsSemilattice = IsCommutativeBand
35 module IsSemilattice {∙} (L : IsSemilattice ∙) where
36 open IsCommutativeBand L public
37 using (isBand; comm)
38 open IsBand isBand public
39
40 -- Used to bring names appropriate for a meet semilattice into scope.
41 IsMeetSemilattice = IsSemilattice
42 module IsMeetSemilattice {∧} (L : IsMeetSemilattice ∧) where
43 open IsSemilattice L public
44 renaming
45 ( ∙-cong to ∧-cong
46 ; ∙-congˡ to ∧-congˡ
47 ; ∙-congʳ to ∧-congʳ
48 )
49
50 -- Used to bring names appropriate for a join semilattice into scope.
51 IsJoinSemilattice = IsSemilattice
52 module IsJoinSemilattice {∨} (L : IsJoinSemilattice ∨) where
53 open IsSemilattice L public
54 renaming
55 ( ∙-cong to ∨-cong
56 ; ∙-congˡ to ∨-congˡ
57 ; ∙-congʳ to ∨-congʳ
58 )
59
60 ------------------------------------------------------------------------
61 -- Structures with 1 binary operation & 1 element
62
63 -- A bounded semi-lattice is the same thing as an idempotent commutative
64 -- monoid.
65 IsBoundedSemilattice = IsIdempotentCommutativeMonoid
66 module IsBoundedSemilattice {∙ ε} (L : IsBoundedSemilattice ∙ ε) where
67
68 open IsIdempotentCommutativeMonoid L public
69 renaming (isCommutativeBand to isSemilattice)
70
71
72 -- Used to bring names appropriate for a bounded meet semilattice
73 -- into scope.
74 IsBoundedMeetSemilattice = IsBoundedSemilattice
75 module IsBoundedMeetSemilattice {∧ ⊤} (L : IsBoundedMeetSemilattice ∧ ⊤)
76 where
77
78 open IsBoundedSemilattice L public
79 using (identity; identityˡ; identityʳ)
80 renaming (isSemilattice to isMeetSemilattice)
81
82 open IsMeetSemilattice isMeetSemilattice public
83
84
85 -- Used to bring names appropriate for a bounded join semilattice
86 -- into scope.
87 IsBoundedJoinSemilattice = IsBoundedSemilattice
88 module IsBoundedJoinSemilattice {∨ ⊥} (L : IsBoundedJoinSemilattice ∨ ⊥)
89 where
90
91 open IsBoundedSemilattice L public
92 using (identity; identityˡ; identityʳ)
93 renaming (isSemilattice to isJoinSemilattice)
94
95 open IsJoinSemilattice isJoinSemilattice public
96
97 ------------------------------------------------------------------------
98 -- Structures with 2 binary operations
99
100 -- Note that `IsLattice` is not defined in terms of `IsMeetSemilattice`
101 -- and `IsJoinSemilattice` for two reasons:
102 -- 1) it would result in a structure with two *different* proofs that
103 -- the equality relation `≈` is an equivalence relation.
104 -- 2) the idempotence laws of ∨ and ∧ can be derived from the
105 -- absorption laws, which makes the corresponding "idem" fields
106 -- redundant.
107 --
108 -- It is possible to construct the `IsLattice` record from
109 -- `IsMeetSemilattice` and `IsJoinSemilattice` via the `IsLattice₂`
110 -- record found in `Algebra.Lattice.Structures.Biased`.
111 --
112 -- The derived idempotence laws are stated and proved in
113 -- `Algebra.Lattice.Properties.Lattice` along with the fact that every
114 -- lattice consists of two semilattices.
115
116 record IsLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
117 field
118 isEquivalence : IsEquivalence _≈_
119 ∨-comm : Commutative ∨
120 ∨-assoc : Associative ∨
121 ∨-cong : Congruent₂ ∨
122 ∧-comm : Commutative ∧
123 ∧-assoc : Associative ∧
124 ∧-cong : Congruent₂ ∧
125 absorptive : Absorptive ∨ ∧
126
127 open IsEquivalence isEquivalence public
128
129 ∨-absorbs-∧ : ∨ Absorbs ∧
130 ∨-absorbs-∧ = proj₁ absorptive
131
132 ∧-absorbs-∨ : ∧ Absorbs ∨
133 ∧-absorbs-∨ = proj₂ absorptive
134
135 ∧-congˡ : LeftCongruent ∧
136 ∧-congˡ y≈z = ∧-cong refl y≈z
137
138 ∧-congʳ : RightCongruent ∧
139 ∧-congʳ y≈z = ∧-cong y≈z refl
140
141 ∨-congˡ : LeftCongruent ∨
142 ∨-congˡ y≈z = ∨-cong refl y≈z
143
144 ∨-congʳ : RightCongruent ∨
145 ∨-congʳ y≈z = ∨-cong y≈z refl
146
147
148 record IsDistributiveLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
149 field
150 isLattice : IsLattice ∨ ∧
151 ∨-distrib-∧ : ∨ DistributesOver ∧
152 ∧-distrib-∨ : ∧ DistributesOver ∨
153
154 open IsLattice isLattice public
155
156 ∨-distribˡ-∧ : ∨ DistributesOverˡ ∧
157 ∨-distribˡ-∧ = proj₁ ∨-distrib-∧
158
159 ∨-distribʳ-∧ : ∨ DistributesOverʳ ∧
160 ∨-distribʳ-∧ = proj₂ ∨-distrib-∧
161
162 ∧-distribˡ-∨ : ∧ DistributesOverˡ ∨
163 ∧-distribˡ-∨ = proj₁ ∧-distrib-∨
164
165 ∧-distribʳ-∨ : ∧ DistributesOverʳ ∨
166 ∧-distribʳ-∨ = proj₂ ∧-distrib-∨
167
168 ------------------------------------------------------------------------
169 -- Structures with 2 binary ops, 1 unary op and 2 elements.
170
171 record IsBooleanAlgebra (∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ)
172 where
173
174 field
175 isDistributiveLattice : IsDistributiveLattice ∨ ∧
176 ∨-complement : Inverse ⊤ ¬ ∨
177 ∧-complement : Inverse ⊥ ¬ ∧
178 ¬-cong : Congruent₁ ¬
179
180 open IsDistributiveLattice isDistributiveLattice public
181
182 ∨-complementˡ : LeftInverse ⊤ ¬ ∨
183 ∨-complementˡ = proj₁ ∨-complement
184
185 ∨-complementʳ : RightInverse ⊤ ¬ ∨
186 ∨-complementʳ = proj₂ ∨-complement
187
188 ∧-complementˡ : LeftInverse ⊥ ¬ ∧
189 ∧-complementˡ = proj₁ ∧-complement
190
191 ∧-complementʳ : RightInverse ⊥ ¬ ∧
192 ∧-complementʳ = proj₂ ∧-complement