| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some biased records for lattice-like structures. Such records are |
| 5 |
-- often easier to construct, but are suboptimal to use more widely and |
| 6 |
-- should be converted to the standard record definitions immediately |
| 7 |
-- using the provided conversion functions. |
| 8 |
------------------------------------------------------------------------ |
| 9 |
|
| 10 |
-- The contents of this module should be accessed via `Algebra.Lattice`, |
| 11 |
-- unless you want to parameterise it via the equality relation. |
| 12 |
|
| 13 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 14 |
|
| 15 |
open import Relation.Binary.Core using (Rel) |
| 16 |
|
| 17 |
module Algebra.Lattice.Structures.Biased |
| 18 |
{a ℓ} {A : Set a} -- The underlying set |
| 19 |
(_≈_ : Rel A ℓ) -- The underlying equality relation |
| 20 |
where |
| 21 |
|
| 22 |
open import Algebra.Core using (Op₁; Op₂) |
| 23 |
open import Algebra.Consequences.Setoid |
| 24 |
using (comm∧distrʳ⇒distr; distrib∧absorbs⇒distribˡ; comm∧distrˡ⇒distr; |
| 25 |
comm∧invʳ⇒inv) |
| 26 |
open import Data.Product.Base using (proj₁; proj₂) |
| 27 |
open import Level using (_⊔_) |
| 28 |
open import Relation.Binary.Bundles using (Setoid) |
| 29 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 30 |
open import Algebra.Definitions _≈_ |
| 31 |
using (Associative; Commutative; Congruent₁; RightInverse; |
| 32 |
_DistributesOverʳ_; Absorptive) |
| 33 |
open import Algebra.Lattice.Structures _≈_ |
| 34 |
using (IsJoinSemilattice; IsMeetSemilattice; IsLattice; |
| 35 |
IsDistributiveLattice; IsBooleanAlgebra) |
| 36 |
|
| 37 |
private |
| 38 |
variable |
| 39 |
∧ ∨ : Op₂ A |
| 40 |
¬ : Op₁ A |
| 41 |
⊤ ⊥ : A |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- Lattice |
| 45 |
|
| 46 |
-- An alternative form of `IsLattice` defined in terms of |
| 47 |
-- `IsJoinSemilattice` and `IsMeetLattice`. This form may be desirable |
| 48 |
-- to use when constructing a lattice object as it requires fewer |
| 49 |
-- arguments, but is often a mistake to use as an argument as it |
| 50 |
-- contains two, *potentially different*, proofs that the equality |
| 51 |
-- relation _≈_ is an equivalence. |
| 52 |
|
| 53 |
record IsLattice₂ (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where |
| 54 |
field |
| 55 |
isJoinSemilattice : IsJoinSemilattice ∨ |
| 56 |
isMeetSemilattice : IsMeetSemilattice ∧ |
| 57 |
absorptive : Absorptive ∨ ∧ |
| 58 |
|
| 59 |
module ML = IsMeetSemilattice isMeetSemilattice |
| 60 |
module JL = IsJoinSemilattice isJoinSemilattice |
| 61 |
|
| 62 |
isLattice₂ : IsLattice ∨ ∧ |
| 63 |
isLattice₂ = record |
| 64 |
{ isEquivalence = ML.isEquivalence |
| 65 |
; ∨-comm = JL.comm |
| 66 |
; ∨-assoc = JL.assoc |
| 67 |
; ∨-cong = JL.∨-cong |
| 68 |
; ∧-comm = ML.comm |
| 69 |
; ∧-assoc = ML.assoc |
| 70 |
; ∧-cong = ML.∧-cong |
| 71 |
; absorptive = absorptive |
| 72 |
} |
| 73 |
|
| 74 |
open IsLattice₂ public using (isLattice₂) |
| 75 |
|
| 76 |
------------------------------------------------------------------------ |
| 77 |
-- DistributiveLattice |
| 78 |
|
| 79 |
-- A version of distributive lattice that is biased towards the (r)ight |
| 80 |
-- distributivity law for (j)oin and (m)eet. |
| 81 |
record IsDistributiveLatticeʳʲᵐ (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where |
| 82 |
field |
| 83 |
isLattice : IsLattice ∨ ∧ |
| 84 |
∨-distribʳ-∧ : ∨ DistributesOverʳ ∧ |
| 85 |
|
| 86 |
open IsLattice isLattice public |
| 87 |
|
| 88 |
setoid : Setoid a ℓ |
| 89 |
setoid = record { isEquivalence = isEquivalence } |
| 90 |
|
| 91 |
∨-distrib-∧ = comm∧distrʳ⇒distr setoid ∧-cong ∨-comm ∨-distribʳ-∧ |
| 92 |
∧-distribˡ-∨ = distrib∧absorbs⇒distribˡ setoid ∧-cong ∧-assoc ∨-comm ∧-absorbs-∨ ∨-absorbs-∧ ∨-distrib-∧ |
| 93 |
∧-distrib-∨ = comm∧distrˡ⇒distr setoid ∨-cong ∧-comm ∧-distribˡ-∨ |
| 94 |
|
| 95 |
isDistributiveLatticeʳʲᵐ : IsDistributiveLattice ∨ ∧ |
| 96 |
isDistributiveLatticeʳʲᵐ = record |
| 97 |
{ isLattice = isLattice |
| 98 |
; ∨-distrib-∧ = ∨-distrib-∧ |
| 99 |
; ∧-distrib-∨ = ∧-distrib-∨ |
| 100 |
} |
| 101 |
|
| 102 |
open IsDistributiveLatticeʳʲᵐ public using (isDistributiveLatticeʳʲᵐ) |
| 103 |
|
| 104 |
------------------------------------------------------------------------ |
| 105 |
-- BooleanAlgebra |
| 106 |
|
| 107 |
-- A (r)ight biased version of a boolean algebra. |
| 108 |
record IsBooleanAlgebraʳ |
| 109 |
(∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where |
| 110 |
field |
| 111 |
isDistributiveLattice : IsDistributiveLattice ∨ ∧ |
| 112 |
∨-complementʳ : RightInverse ⊤ ¬ ∨ |
| 113 |
∧-complementʳ : RightInverse ⊥ ¬ ∧ |
| 114 |
¬-cong : Congruent₁ ¬ |
| 115 |
|
| 116 |
open IsDistributiveLattice isDistributiveLattice public |
| 117 |
|
| 118 |
setoid : Setoid a ℓ |
| 119 |
setoid = record { isEquivalence = isEquivalence } |
| 120 |
|
| 121 |
isBooleanAlgebraʳ : IsBooleanAlgebra ∨ ∧ ¬ ⊤ ⊥ |
| 122 |
isBooleanAlgebraʳ = record |
| 123 |
{ isDistributiveLattice = isDistributiveLattice |
| 124 |
; ∨-complement = comm∧invʳ⇒inv setoid ∨-comm ∨-complementʳ |
| 125 |
; ∧-complement = comm∧invʳ⇒inv setoid ∧-comm ∧-complementʳ |
| 126 |
; ¬-cong = ¬-cong |
| 127 |
} |
| 128 |
|
| 129 |
open IsBooleanAlgebraʳ public using (isBooleanAlgebraʳ) |