Debian Codegraph @

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

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties satisfied by lattices
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Lattice using (Lattice; IsLattice)
10
11 module Relation.Binary.Lattice.Properties.Lattice
12 {c ℓ₁ ℓ₂} (L : Lattice c ℓ₁ ℓ₂) where
13
14 import Algebra.Lattice as Alg using (IsLattice; Lattice)
15 open import Data.Product.Base using (_,_)
16 open import Function.Base using (flip)
17 import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
18 import Relation.Binary.Reasoning.PartialOrder as ≤-Reasoning
19
20 open Lattice L
21
22 open import Algebra.Definitions _≈_
23 open import Relation.Binary.Properties.Poset poset using (≥-isPartialOrder)
24 import Relation.Binary.Lattice.Properties.JoinSemilattice joinSemilattice as J
25 import Relation.Binary.Lattice.Properties.MeetSemilattice meetSemilattice as M
26
27
28 ∨-absorbs-∧ : _∨_ Absorbs _∧_
29 ∨-absorbs-∧ x y =
30 let x≤x∨[x∧y] , _ , least = supremum x (x ∧ y)
31 x∧y≤x , _ , _ = infimum x y
32 in antisym (least x refl x∧y≤x) x≤x∨[x∧y]
33
34 ∧-absorbs-∨ : _∧_ Absorbs _∨_
35 ∧-absorbs-∨ x y =
36 let x∧[x∨y]≤x , _ , greatest = infimum x (x ∨ y)
37 x≤x∨y , _ , _ = supremum x y
38 in antisym x∧[x∨y]≤x (greatest x refl x≤x∨y)
39
40 absorptive : Absorptive _∨_ _∧_
41 absorptive = ∨-absorbs-∧ , ∧-absorbs-∨
42
43 ∧≤∨ : ∀ {x y} → x ∧ y ≤ x ∨ y
44 ∧≤∨ {x} {y} = begin
45 x ∧ y ≤⟨ x∧y≤x x y ⟩
46 x ≤⟨ x≤x∨y x y ⟩
47 x ∨ y ∎
48 where open ≤-Reasoning poset
49
50 -- two quadrilateral arguments
51
52 quadrilateral₁ : ∀ {x y} → x ∨ y ≈ x → x ∧ y ≈ y
53 quadrilateral₁ {x} {y} x∨y≈x = begin
54 x ∧ y ≈⟨ M.∧-cong (Eq.sym x∨y≈x) Eq.refl ⟩
55 (x ∨ y) ∧ y ≈⟨ M.∧-comm _ _ ⟩
56 y ∧ (x ∨ y) ≈⟨ M.∧-cong Eq.refl (J.∨-comm _ _) ⟩
57 y ∧ (y ∨ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩
58 y ∎
59 where open ≈-Reasoning setoid
60
61 quadrilateral₂ : ∀ {x y} → x ∧ y ≈ y → x ∨ y ≈ x
62 quadrilateral₂ {x} {y} x∧y≈y = begin
63 x ∨ y ≈⟨ J.∨-cong Eq.refl (Eq.sym x∧y≈y) ⟩
64 x ∨ (x ∧ y) ≈⟨ ∨-absorbs-∧ _ _ ⟩
65 x ∎
66 where open ≈-Reasoning setoid
67
68 -- collapsing sublattice
69
70 collapse₁ : ∀ {x y} → x ≈ y → x ∧ y ≈ x ∨ y
71 collapse₁ {x} {y} x≈y = begin
72 x ∧ y ≈⟨ M.y≤x⇒x∧y≈y y≤x ⟩
73 y ≈⟨ Eq.sym x≈y ⟩
74 x ≈⟨ Eq.sym (J.x≤y⇒x∨y≈y y≤x) ⟩
75 y ∨ x ≈⟨ J.∨-comm _ _ ⟩
76 x ∨ y ∎
77 where
78 y≤x = reflexive (Eq.sym x≈y)
79 open ≈-Reasoning setoid
80
81 -- this can also be proved by quadrilateral argument, but it's much less symmetric.
82 collapse₂ : ∀ {x y} → x ∨ y ≤ x ∧ y → x ≈ y
83 collapse₂ {x} {y} ∨≤∧ = antisym
84 (begin x ≤⟨ x≤x∨y _ _ ⟩
85 x ∨ y ≤⟨ ∨≤∧ ⟩
86 x ∧ y ≤⟨ x∧y≤y _ _ ⟩
87 y ∎)
88 (begin y ≤⟨ y≤x∨y _ _ ⟩
89 x ∨ y ≤⟨ ∨≤∧ ⟩
90 x ∧ y ≤⟨ x∧y≤x _ _ ⟩
91 x ∎)
92 where open ≤-Reasoning poset
93
94 ------------------------------------------------------------------------
95 -- The dual construction is also a lattice.
96
97 ∧-∨-isLattice : IsLattice _≈_ (flip _≤_) _∧_ _∨_
98 ∧-∨-isLattice = record
99 { isPartialOrder = ≥-isPartialOrder
100 ; supremum = infimum
101 ; infimum = supremum
102 }
103
104 ∧-∨-lattice : Lattice c ℓ₁ ℓ₂
105 ∧-∨-lattice = record
106 { _∧_ = _∨_
107 ; _∨_ = _∧_
108 ; isLattice = ∧-∨-isLattice
109 }
110
111 ------------------------------------------------------------------------
112 -- Every order-theoretic lattice can be turned into an algebraic one.
113
114 isAlgLattice : Alg.IsLattice _≈_ _∨_ _∧_
115 isAlgLattice = record
116 { isEquivalence = isEquivalence
117 ; ∨-comm = J.∨-comm
118 ; ∨-assoc = J.∨-assoc
119 ; ∨-cong = J.∨-cong
120 ; ∧-comm = M.∧-comm
121 ; ∧-assoc = M.∧-assoc
122 ; ∧-cong = M.∧-cong
123 ; absorptive = absorptive
124 }
125
126 algLattice : Alg.Lattice c ℓ₁
127 algLattice = record { isLattice = isAlgLattice }