Debian Codegraph @

src/Relation/Binary/Lattice/Properties/JoinSemilattice.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties satisfied by join semilattices
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Lattice
10
11 module Relation.Binary.Lattice.Properties.JoinSemilattice
12 {c ℓ₁ ℓ₂} (J : JoinSemilattice c ℓ₁ ℓ₂) where
13
14 import Algebra.Lattice as Alg
15 using (IsMeetSemilattice; MeetSemilattice; IsSemilattice; Semilattice)
16 open import Data.Product.Base using (_,_)
17 open import Function.Base using (_∘_; flip)
18 open import Relation.Binary.Core using (_Preserves₂_⟶_⟶_)
19 open import Relation.Binary.Structures using (IsDecPartialOrder)
20 open import Relation.Binary.Definitions using (Decidable)
21 open import Relation.Nullary.Decidable.Core using (yes; no)
22 open import Relation.Nullary.Negation.Core using (¬_; contraposition)
23
24 open JoinSemilattice J
25
26 open import Algebra.Definitions _≈_
27 open import Relation.Binary.Properties.Poset poset using (≥-isPartialOrder)
28 import Relation.Binary.Reasoning.PartialOrder as PoR
29
30 ------------------------------------------------------------------------
31 -- Algebraic properties
32
33 -- The join operation is monotonic.
34
35 ∨-monotonic : _∨_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
36 ∨-monotonic {x} {y} {u} {v} x≤y u≤v =
37 let _ , _ , least = supremum x u
38 y≤y∨v , v≤y∨v , _ = supremum y v
39 in least (y ∨ v) (trans x≤y y≤y∨v) (trans u≤v v≤y∨v)
40
41 ∨-cong : _∨_ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
42 ∨-cong x≈y u≈v = antisym (∨-monotonic (reflexive x≈y) (reflexive u≈v))
43 (∨-monotonic (reflexive (Eq.sym x≈y))
44 (reflexive (Eq.sym u≈v)))
45
46 -- The join operation is commutative, associative and idempotent.
47
48 ∨-comm : Commutative _∨_
49 ∨-comm x y =
50 let x≤x∨y , y≤x∨y , least = supremum x y
51 y≤y∨x , x≤y∨x , least′ = supremum y x
52 in antisym (least (y ∨ x) x≤y∨x y≤y∨x) (least′ (x ∨ y) y≤x∨y x≤x∨y)
53
54 ∨-assoc : Associative _∨_
55 ∨-assoc x y z =
56 let x∨y≤[x∨y]∨z , z≤[x∨y]∨z , least = supremum (x ∨ y) z
57 x≤x∨[y∨z] , y∨z≤x∨[y∨z] , least′ = supremum x (y ∨ z)
58 y≤y∨z , z≤y∨z , _ = supremum y z
59 x≤x∨y , y≤x∨y , _ = supremum x y
60 in antisym (least (x ∨ (y ∨ z)) (∨-monotonic refl y≤y∨z)
61 (trans z≤y∨z y∨z≤x∨[y∨z]))
62 (least′ ((x ∨ y) ∨ z) (trans x≤x∨y x∨y≤[x∨y]∨z)
63 (∨-monotonic y≤x∨y refl))
64
65 ∨-idempotent : Idempotent _∨_
66 ∨-idempotent x =
67 let x≤x∨x , _ , least = supremum x x
68 in antisym (least x refl refl) x≤x∨x
69
70 x≤y⇒x∨y≈y : ∀ {x y} → x ≤ y → x ∨ y ≈ y
71 x≤y⇒x∨y≈y {x} {y} x≤y = antisym
72 (begin x ∨ y ≤⟨ ∨-monotonic x≤y refl ⟩
73 y ∨ y ≈⟨ ∨-idempotent _ ⟩
74 y ∎)
75 (y≤x∨y _ _)
76 where open PoR poset
77
78 -- Every order-theoretic semilattice can be turned into an algebraic one.
79
80 isAlgSemilattice : Alg.IsSemilattice _≈_ _∨_
81 isAlgSemilattice = record
82 { isBand = record
83 { isSemigroup = record
84 { isMagma = record
85 { isEquivalence = isEquivalence
86 ; ∙-cong = ∨-cong
87 }
88 ; assoc = ∨-assoc
89 }
90 ; idem = ∨-idempotent
91 }
92 ; comm = ∨-comm
93 }
94
95 algSemilattice : Alg.Semilattice c ℓ₁
96 algSemilattice = record { isSemilattice = isAlgSemilattice }
97
98 ------------------------------------------------------------------------
99 -- The dual construction is a meet semilattice.
100
101 dualIsMeetSemilattice : IsMeetSemilattice _≈_ (flip _≤_) _∨_
102 dualIsMeetSemilattice = record
103 { isPartialOrder = ≥-isPartialOrder
104 ; infimum = supremum
105 }
106
107 dualMeetSemilattice : MeetSemilattice c ℓ₁ ℓ₂
108 dualMeetSemilattice = record
109 { _∧_ = _∨_
110 ; isMeetSemilattice = dualIsMeetSemilattice
111 }
112
113 ------------------------------------------------------------------------
114 -- If ≈ is decidable then so is ≤
115
116 ≈-dec⇒≤-dec : Decidable _≈_ → Decidable _≤_
117 ≈-dec⇒≤-dec _≟_ x y with (x ∨ y) ≟ y
118 ... | yes x∨y≈y = yes (trans (x≤x∨y x y) (reflexive x∨y≈y))
119 ... | no x∨y≉y = no (contraposition x≤y⇒x∨y≈y x∨y≉y)
120
121 ≈-dec⇒isDecPartialOrder : Decidable _≈_ → IsDecPartialOrder _≈_ _≤_
122 ≈-dec⇒isDecPartialOrder _≟_ = record
123 { isPartialOrder = isPartialOrder
124 ; _≟_ = _≟_
125 ; _≤?_ = ≈-dec⇒≤-dec _≟_
126 }