| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Algebraic properties of constructions over unary relations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Relation.Unary.Algebra where |
| 10 |
|
| 11 |
open import Algebra.Bundles |
| 12 |
using (Magma; Semigroup; Band |
| 13 |
; Monoid; CommutativeMonoid; IdempotentCommutativeMonoid |
| 14 |
; SemiringWithoutAnnihilatingZero; Semiring; CommutativeSemiring) |
| 15 |
import Algebra.Definitions as AlgebraicDefinitions |
| 16 |
open import Algebra.Lattice.Bundles |
| 17 |
using (Semilattice; Lattice; DistributiveLattice) |
| 18 |
import Algebra.Lattice.Structures as AlgebraicLatticeStructures |
| 19 |
using (IsLattice; IsDistributiveLattice; IsSemilattice) |
| 20 |
import Algebra.Structures as AlgebraicStructures |
| 21 |
using (IsMagma; IsSemigroup; IsBand; IsMonoid; IsCommutativeMonoid |
| 22 |
; IsIdempotentCommutativeMonoid; IsSemiringWithoutAnnihilatingZero |
| 23 |
; IsSemiring; IsCommutativeSemiring) |
| 24 |
open import Data.Empty.Polymorphic using (⊥-elim) |
| 25 |
open import Data.Product.Base as Product |
| 26 |
using (_,_; proj₁; proj₂; <_,_>; curry; uncurry) |
| 27 |
open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]) |
| 28 |
open import Data.Unit.Polymorphic using (tt) |
| 29 |
open import Function.Base using (id; const; _∘_) |
| 30 |
open import Level using (Level; _⊔_) |
| 31 |
open import Relation.Unary hiding (∅; U) |
| 32 |
open import Relation.Unary.Polymorphic using (∅; U) |
| 33 |
open import Relation.Unary.Relation.Binary.Equality using (≐-isEquivalence) |
| 34 |
|
| 35 |
module _ {a ℓ : Level} {A : Set a} where |
| 36 |
|
| 37 |
open AlgebraicDefinitions {A = Pred A ℓ} _≐_ |
| 38 |
|
| 39 |
------------------------------------------------------------------------ |
| 40 |
-- Properties of _∩_ |
| 41 |
|
| 42 |
∩-cong : Congruent₂ _∩_ |
| 43 |
∩-cong (P⊆Q , Q⊆P) (R⊆S , S⊆R) = Product.map P⊆Q R⊆S , Product.map Q⊆P S⊆R |
| 44 |
|
| 45 |
∩-comm : Commutative _∩_ |
| 46 |
∩-comm _ _ = Product.swap , Product.swap |
| 47 |
|
| 48 |
∩-assoc : Associative _∩_ |
| 49 |
∩-assoc _ _ _ = Product.assocʳ′ , Product.assocˡ′ |
| 50 |
|
| 51 |
∩-idem : Idempotent _∩_ |
| 52 |
∩-idem _ = proj₁ , < id , id > |
| 53 |
|
| 54 |
∩-identityˡ : LeftIdentity U _∩_ |
| 55 |
∩-identityˡ _ = proj₂ , < const tt , id > |
| 56 |
|
| 57 |
∩-identityʳ : RightIdentity U _∩_ |
| 58 |
∩-identityʳ _ = proj₁ , < id , const tt > |
| 59 |
|
| 60 |
∩-identity : Identity U _∩_ |
| 61 |
∩-identity = ∩-identityˡ , ∩-identityʳ |
| 62 |
|
| 63 |
∩-zeroˡ : LeftZero ∅ _∩_ |
| 64 |
∩-zeroˡ _ = proj₁ , ⊥-elim |
| 65 |
|
| 66 |
∩-zeroʳ : RightZero ∅ _∩_ |
| 67 |
∩-zeroʳ _ = proj₂ , ⊥-elim |
| 68 |
|
| 69 |
∩-zero : Zero ∅ _∩_ |
| 70 |
∩-zero = ∩-zeroˡ , ∩-zeroʳ |
| 71 |
|
| 72 |
------------------------------------------------------------------------ |
| 73 |
-- Properties of _∪_ |
| 74 |
|
| 75 |
∪-cong : Congruent₂ _∪_ |
| 76 |
∪-cong (P⊆Q , Q⊆P) (R⊆S , S⊆R) = Sum.map P⊆Q R⊆S , Sum.map Q⊆P S⊆R |
| 77 |
|
| 78 |
∪-comm : Commutative _∪_ |
| 79 |
∪-comm _ _ = Sum.swap , Sum.swap |
| 80 |
|
| 81 |
∪-assoc : Associative _∪_ |
| 82 |
∪-assoc _ _ _ = Sum.assocʳ , Sum.assocˡ |
| 83 |
|
| 84 |
∪-idem : Idempotent _∪_ |
| 85 |
∪-idem _ = [ id , id ] , inj₁ |
| 86 |
|
| 87 |
∪-identityˡ : LeftIdentity ∅ _∪_ |
| 88 |
∪-identityˡ _ = [ ⊥-elim , id ] , inj₂ |
| 89 |
|
| 90 |
∪-identityʳ : RightIdentity ∅ _∪_ |
| 91 |
∪-identityʳ _ = [ id , ⊥-elim ] , inj₁ |
| 92 |
|
| 93 |
∪-identity : Identity ∅ _∪_ |
| 94 |
∪-identity = ∪-identityˡ , ∪-identityʳ |
| 95 |
|
| 96 |
------------------------------------------------------------------------ |
| 97 |
-- Properties of _∩_ and _∪_ |
| 98 |
|
| 99 |
∩-distribˡ-∪ : _∩_ DistributesOverˡ _∪_ |
| 100 |
∩-distribˡ-∪ _ _ _ = |
| 101 |
( uncurry (λ x∈P → [ inj₁ ∘ (x∈P ,_) , inj₂ ∘ (x∈P ,_) ]) |
| 102 |
, [ Product.map₂ inj₁ , Product.map₂ inj₂ ] |
| 103 |
) |
| 104 |
|
| 105 |
∩-distribʳ-∪ : _∩_ DistributesOverʳ _∪_ |
| 106 |
∩-distribʳ-∪ _ _ _ = |
| 107 |
( uncurry [ curry inj₁ , curry inj₂ ] |
| 108 |
, [ Product.map₁ inj₁ , Product.map₁ inj₂ ] |
| 109 |
) |
| 110 |
|
| 111 |
∩-distrib-∪ : _∩_ DistributesOver _∪_ |
| 112 |
∩-distrib-∪ = ∩-distribˡ-∪ , ∩-distribʳ-∪ |
| 113 |
|
| 114 |
∪-distribˡ-∩ : _∪_ DistributesOverˡ _∩_ |
| 115 |
∪-distribˡ-∩ _ _ _ = |
| 116 |
( [ < inj₁ , inj₁ > , Product.map inj₂ inj₂ ] |
| 117 |
, uncurry [ const ∘ inj₁ , (λ x∈Q → [ inj₁ , inj₂ ∘ (x∈Q ,_) ]) ] |
| 118 |
) |
| 119 |
|
| 120 |
∪-distribʳ-∩ : _∪_ DistributesOverʳ _∩_ |
| 121 |
∪-distribʳ-∩ _ _ _ = |
| 122 |
( [ Product.map inj₁ inj₁ , < inj₂ , inj₂ > ] |
| 123 |
, uncurry [ (λ x∈Q → [ inj₁ ∘ (x∈Q ,_) , inj₂ ]) , const ∘ inj₂ ] |
| 124 |
) |
| 125 |
|
| 126 |
∪-distrib-∩ : _∪_ DistributesOver _∩_ |
| 127 |
∪-distrib-∩ = ∪-distribˡ-∩ , ∪-distribʳ-∩ |
| 128 |
|
| 129 |
∩-abs-∪ : _∩_ Absorbs _∪_ |
| 130 |
∩-abs-∪ _ _ = proj₁ , < id , inj₁ > |
| 131 |
|
| 132 |
∪-abs-∩ : _∪_ Absorbs _∩_ |
| 133 |
∪-abs-∩ _ _ = [ id , proj₁ ] , inj₁ |
| 134 |
|
| 135 |
∪-∩-absorptive : Absorptive _∪_ _∩_ |
| 136 |
∪-∩-absorptive = ∪-abs-∩ , ∩-abs-∪ |
| 137 |
|
| 138 |
∩-∪-absorptive : Absorptive _∩_ _∪_ |
| 139 |
∩-∪-absorptive = ∩-abs-∪ , ∪-abs-∩ |
| 140 |
|
| 141 |
module _ {a : Level} (A : Set a) (ℓ : Level) where |
| 142 |
|
| 143 |
open AlgebraicStructures {A = Pred A ℓ} _≐_ |
| 144 |
open AlgebraicLatticeStructures {A = Pred A ℓ} _≐_ |
| 145 |
|
| 146 |
------------------------------------------------------------------------ |
| 147 |
-- Algebraic structures of _∩_ |
| 148 |
|
| 149 |
∩-isMagma : IsMagma _∩_ |
| 150 |
∩-isMagma = record |
| 151 |
{ isEquivalence = ≐-isEquivalence |
| 152 |
; ∙-cong = ∩-cong |
| 153 |
} |
| 154 |
|
| 155 |
∩-isSemigroup : IsSemigroup _∩_ |
| 156 |
∩-isSemigroup = record |
| 157 |
{ isMagma = ∩-isMagma |
| 158 |
; assoc = ∩-assoc |
| 159 |
} |
| 160 |
|
| 161 |
∩-isBand : IsBand _∩_ |
| 162 |
∩-isBand = record |
| 163 |
{ isSemigroup = ∩-isSemigroup |
| 164 |
; idem = ∩-idem |
| 165 |
} |
| 166 |
|
| 167 |
∩-isSemilattice : IsSemilattice _∩_ |
| 168 |
∩-isSemilattice = record |
| 169 |
{ isBand = ∩-isBand |
| 170 |
; comm = ∩-comm |
| 171 |
} |
| 172 |
|
| 173 |
∩-isMonoid : IsMonoid _∩_ U |
| 174 |
∩-isMonoid = record |
| 175 |
{ isSemigroup = ∩-isSemigroup |
| 176 |
; identity = ∩-identity |
| 177 |
} |
| 178 |
|
| 179 |
∩-isCommutativeMonoid : IsCommutativeMonoid _∩_ U |
| 180 |
∩-isCommutativeMonoid = record |
| 181 |
{ isMonoid = ∩-isMonoid |
| 182 |
; comm = ∩-comm |
| 183 |
} |
| 184 |
|
| 185 |
∩-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∩_ U |
| 186 |
∩-isIdempotentCommutativeMonoid = record |
| 187 |
{ isCommutativeMonoid = ∩-isCommutativeMonoid |
| 188 |
; idem = ∩-idem |
| 189 |
} |
| 190 |
|
| 191 |
------------------------------------------------------------------------ |
| 192 |
-- Algebraic structures of _∪_ |
| 193 |
|
| 194 |
∪-isMagma : IsMagma _∪_ |
| 195 |
∪-isMagma = record |
| 196 |
{ isEquivalence = ≐-isEquivalence |
| 197 |
; ∙-cong = ∪-cong |
| 198 |
} |
| 199 |
|
| 200 |
∪-isSemigroup : IsSemigroup _∪_ |
| 201 |
∪-isSemigroup = record |
| 202 |
{ isMagma = ∪-isMagma |
| 203 |
; assoc = ∪-assoc |
| 204 |
} |
| 205 |
|
| 206 |
∪-isBand : IsBand _∪_ |
| 207 |
∪-isBand = record |
| 208 |
{ isSemigroup = ∪-isSemigroup |
| 209 |
; idem = ∪-idem |
| 210 |
} |
| 211 |
|
| 212 |
∪-isSemilattice : IsSemilattice _∪_ |
| 213 |
∪-isSemilattice = record |
| 214 |
{ isBand = ∪-isBand |
| 215 |
; comm = ∪-comm |
| 216 |
} |
| 217 |
|
| 218 |
∪-isMonoid : IsMonoid _∪_ ∅ |
| 219 |
∪-isMonoid = record |
| 220 |
{ isSemigroup = ∪-isSemigroup |
| 221 |
; identity = ∪-identity |
| 222 |
} |
| 223 |
|
| 224 |
∪-isCommutativeMonoid : IsCommutativeMonoid _∪_ ∅ |
| 225 |
∪-isCommutativeMonoid = record |
| 226 |
{ isMonoid = ∪-isMonoid |
| 227 |
; comm = ∪-comm |
| 228 |
} |
| 229 |
|
| 230 |
∪-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∪_ ∅ |
| 231 |
∪-isIdempotentCommutativeMonoid = record |
| 232 |
{ isCommutativeMonoid = ∪-isCommutativeMonoid |
| 233 |
; idem = ∪-idem |
| 234 |
} |
| 235 |
|
| 236 |
------------------------------------------------------------------------ |
| 237 |
-- Algebraic structures of _∩_ and _∪_ |
| 238 |
|
| 239 |
∪-∩-isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _∪_ _∩_ ∅ U |
| 240 |
∪-∩-isSemiringWithoutAnnihilatingZero = record |
| 241 |
{ +-isCommutativeMonoid = ∪-isCommutativeMonoid |
| 242 |
; *-cong = ∩-cong |
| 243 |
; *-assoc = ∩-assoc |
| 244 |
; *-identity = ∩-identity |
| 245 |
; distrib = ∩-distrib-∪ |
| 246 |
} |
| 247 |
|
| 248 |
∪-∩-isSemiring : IsSemiring _∪_ _∩_ ∅ U |
| 249 |
∪-∩-isSemiring = record |
| 250 |
{ isSemiringWithoutAnnihilatingZero = ∪-∩-isSemiringWithoutAnnihilatingZero |
| 251 |
; zero = ∩-zero |
| 252 |
} |
| 253 |
|
| 254 |
∪-∩-isCommutativeSemiring : IsCommutativeSemiring _∪_ _∩_ ∅ U |
| 255 |
∪-∩-isCommutativeSemiring = record |
| 256 |
{ isSemiring = ∪-∩-isSemiring |
| 257 |
; *-comm = ∩-comm |
| 258 |
} |
| 259 |
|
| 260 |
∪-∩-isLattice : IsLattice _∪_ _∩_ |
| 261 |
∪-∩-isLattice = record |
| 262 |
{ isEquivalence = ≐-isEquivalence |
| 263 |
; ∨-comm = ∪-comm |
| 264 |
; ∨-assoc = ∪-assoc |
| 265 |
; ∨-cong = ∪-cong |
| 266 |
; ∧-comm = ∩-comm |
| 267 |
; ∧-assoc = ∩-assoc |
| 268 |
; ∧-cong = ∩-cong |
| 269 |
; absorptive = ∪-∩-absorptive |
| 270 |
} |
| 271 |
|
| 272 |
∪-∩-isDistributiveLattice : IsDistributiveLattice _∪_ _∩_ |
| 273 |
∪-∩-isDistributiveLattice = record |
| 274 |
{ isLattice = ∪-∩-isLattice |
| 275 |
; ∨-distrib-∧ = ∪-distrib-∩ |
| 276 |
; ∧-distrib-∨ = ∩-distrib-∪ |
| 277 |
} |
| 278 |
|
| 279 |
∩-∪-isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _∩_ _∪_ U ∅ |
| 280 |
∩-∪-isSemiringWithoutAnnihilatingZero = record |
| 281 |
{ +-isCommutativeMonoid = ∩-isCommutativeMonoid |
| 282 |
; *-cong = ∪-cong |
| 283 |
; *-assoc = ∪-assoc |
| 284 |
; *-identity = ∪-identity |
| 285 |
; distrib = ∪-distrib-∩ |
| 286 |
} |
| 287 |
|
| 288 |
------------------------------------------------------------------------ |
| 289 |
-- Algebraic bundles of _∩_ |
| 290 |
|
| 291 |
∩-magma : Magma _ _ |
| 292 |
∩-magma = record |
| 293 |
{ isMagma = ∩-isMagma |
| 294 |
} |
| 295 |
|
| 296 |
∩-semigroup : Semigroup _ _ |
| 297 |
∩-semigroup = record |
| 298 |
{ isSemigroup = ∩-isSemigroup |
| 299 |
} |
| 300 |
|
| 301 |
∩-band : Band _ _ |
| 302 |
∩-band = record |
| 303 |
{ isBand = ∩-isBand |
| 304 |
} |
| 305 |
|
| 306 |
∩-semilattice : Semilattice _ _ |
| 307 |
∩-semilattice = record |
| 308 |
{ isSemilattice = ∩-isSemilattice |
| 309 |
} |
| 310 |
|
| 311 |
∩-monoid : Monoid _ _ |
| 312 |
∩-monoid = record |
| 313 |
{ isMonoid = ∩-isMonoid |
| 314 |
} |
| 315 |
|
| 316 |
∩-commutativeMonoid : CommutativeMonoid _ _ |
| 317 |
∩-commutativeMonoid = record |
| 318 |
{ isCommutativeMonoid = ∩-isCommutativeMonoid |
| 319 |
} |
| 320 |
|
| 321 |
∩-idempotentCommutativeMonoid : IdempotentCommutativeMonoid _ _ |
| 322 |
∩-idempotentCommutativeMonoid = record |
| 323 |
{ isIdempotentCommutativeMonoid = ∩-isIdempotentCommutativeMonoid |
| 324 |
} |
| 325 |
|
| 326 |
------------------------------------------------------------------------ |
| 327 |
-- Algebraic bundles of _∪_ |
| 328 |
|
| 329 |
∪-magma : Magma _ _ |
| 330 |
∪-magma = record |
| 331 |
{ isMagma = ∪-isMagma |
| 332 |
} |
| 333 |
|
| 334 |
∪-semigroup : Semigroup _ _ |
| 335 |
∪-semigroup = record |
| 336 |
{ isSemigroup = ∪-isSemigroup |
| 337 |
} |
| 338 |
|
| 339 |
∪-band : Band _ _ |
| 340 |
∪-band = record |
| 341 |
{ isBand = ∪-isBand |
| 342 |
} |
| 343 |
|
| 344 |
∪-semilattice : Semilattice _ _ |
| 345 |
∪-semilattice = record |
| 346 |
{ isSemilattice = ∪-isSemilattice |
| 347 |
} |
| 348 |
|
| 349 |
∪-monoid : Monoid _ _ |
| 350 |
∪-monoid = record |
| 351 |
{ isMonoid = ∪-isMonoid |
| 352 |
} |
| 353 |
|
| 354 |
∪-commutativeMonoid : CommutativeMonoid _ _ |
| 355 |
∪-commutativeMonoid = record |
| 356 |
{ isCommutativeMonoid = ∪-isCommutativeMonoid |
| 357 |
} |
| 358 |
|
| 359 |
∪-idempotentCommutativeMonoid : IdempotentCommutativeMonoid _ _ |
| 360 |
∪-idempotentCommutativeMonoid = record |
| 361 |
{ isIdempotentCommutativeMonoid = ∪-isIdempotentCommutativeMonoid |
| 362 |
} |
| 363 |
|
| 364 |
------------------------------------------------------------------------ |
| 365 |
-- Algebraic bundles of _∩_ and _∪_ |
| 366 |
|
| 367 |
∪-∩-semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero _ _ |
| 368 |
∪-∩-semiringWithoutAnnihilatingZero = record |
| 369 |
{ isSemiringWithoutAnnihilatingZero = ∪-∩-isSemiringWithoutAnnihilatingZero |
| 370 |
} |
| 371 |
|
| 372 |
∪-∩-semiring : Semiring _ _ |
| 373 |
∪-∩-semiring = record |
| 374 |
{ isSemiring = ∪-∩-isSemiring |
| 375 |
} |
| 376 |
|
| 377 |
∪-∩-commutativeSemiring : CommutativeSemiring _ _ |
| 378 |
∪-∩-commutativeSemiring = record |
| 379 |
{ isCommutativeSemiring = ∪-∩-isCommutativeSemiring |
| 380 |
} |
| 381 |
|
| 382 |
∪-∩-lattice : Lattice _ _ |
| 383 |
∪-∩-lattice = record |
| 384 |
{ isLattice = ∪-∩-isLattice |
| 385 |
} |
| 386 |
|
| 387 |
∪-∩-distributiveLattice : DistributiveLattice _ _ |
| 388 |
∪-∩-distributiveLattice = record |
| 389 |
{ isDistributiveLattice = ∪-∩-isDistributiveLattice |
| 390 |
} |
| 391 |
|
| 392 |
∩-∪-semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero _ _ |
| 393 |
∩-∪-semiringWithoutAnnihilatingZero = record |
| 394 |
{ isSemiringWithoutAnnihilatingZero = ∩-∪-isSemiringWithoutAnnihilatingZero |
| 395 |
} |