2023-04-04 21:08:31 -07:00
|
|
|
|
module Lattice where
|
|
|
|
|
|
2023-04-06 23:08:49 -07:00
|
|
|
|
import Data.Nat.Properties as NatProps
|
2023-07-23 00:51:34 -07:00
|
|
|
|
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; sym)
|
2023-04-04 21:08:31 -07:00
|
|
|
|
open import Relation.Binary.Definitions
|
2023-04-06 23:08:49 -07:00
|
|
|
|
open import Data.Nat as Nat using (ℕ; _≤_)
|
|
|
|
|
open import Data.Product using (_×_; _,_)
|
2023-07-13 21:50:27 -07:00
|
|
|
|
open import Data.Sum using (_⊎_; inj₁; inj₂)
|
|
|
|
|
open import Agda.Primitive using (lsuc; Level)
|
2023-04-04 21:08:31 -07:00
|
|
|
|
|
2023-04-06 23:08:49 -07:00
|
|
|
|
open import NatMap using (NatMap)
|
2023-04-04 21:08:31 -07:00
|
|
|
|
|
2023-07-15 15:16:51 -07:00
|
|
|
|
record IsEquivalence {a} (A : Set a) (_≈_ : A → A → Set a) : Set a where
|
|
|
|
|
field
|
|
|
|
|
≈-refl : {a : A} → a ≈ a
|
|
|
|
|
≈-sym : {a b : A} → a ≈ b → b ≈ a
|
|
|
|
|
≈-trans : {a b c : A} → a ≈ b → b ≈ c → a ≈ c
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
record IsSemilattice {a} (A : Set a)
|
|
|
|
|
(_≈_ : A → A → Set a)
|
|
|
|
|
(_⊔_ : A → A → A) : Set a where
|
|
|
|
|
|
2023-04-06 23:08:49 -07:00
|
|
|
|
field
|
2023-07-15 15:16:51 -07:00
|
|
|
|
≈-equiv : IsEquivalence A _≈_
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
⊔-assoc : (x y z : A) → ((x ⊔ y) ⊔ z) ≈ (x ⊔ (y ⊔ z))
|
|
|
|
|
⊔-comm : (x y : A) → (x ⊔ y) ≈ (y ⊔ x)
|
|
|
|
|
⊔-idemp : (x : A) → (x ⊔ x) ≈ x
|
|
|
|
|
|
2023-07-15 15:16:51 -07:00
|
|
|
|
open IsEquivalence ≈-equiv public
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
record IsLattice {a} (A : Set a)
|
|
|
|
|
(_≈_ : A → A → Set a)
|
|
|
|
|
(_⊔_ : A → A → A)
|
|
|
|
|
(_⊓_ : A → A → A) : Set a where
|
2023-04-04 21:08:31 -07:00
|
|
|
|
|
|
|
|
|
field
|
2023-07-15 14:40:11 -07:00
|
|
|
|
joinSemilattice : IsSemilattice A _≈_ _⊔_
|
|
|
|
|
meetSemilattice : IsSemilattice A _≈_ _⊓_
|
2023-04-06 23:08:49 -07:00
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
absorb-⊔-⊓ : (x y : A) → (x ⊔ (x ⊓ y)) ≈ x
|
|
|
|
|
absorb-⊓-⊔ : (x y : A) → (x ⊓ (x ⊔ y)) ≈ x
|
2023-04-04 21:08:31 -07:00
|
|
|
|
|
2023-04-06 23:08:49 -07:00
|
|
|
|
open IsSemilattice joinSemilattice public
|
|
|
|
|
open IsSemilattice meetSemilattice public renaming
|
|
|
|
|
( ⊔-assoc to ⊓-assoc
|
|
|
|
|
; ⊔-comm to ⊓-comm
|
|
|
|
|
; ⊔-idemp to ⊓-idemp
|
|
|
|
|
)
|
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
record Semilattice {a} (A : Set a) : Set (lsuc a) where
|
|
|
|
|
field
|
2023-07-15 14:40:11 -07:00
|
|
|
|
_≈_ : A → A → Set a
|
2023-07-15 13:12:21 -07:00
|
|
|
|
_⊔_ : A → A → A
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
isSemilattice : IsSemilattice A _≈_ _⊔_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
|
|
|
|
|
open IsSemilattice isSemilattice public
|
|
|
|
|
|
2023-04-06 23:08:49 -07:00
|
|
|
|
|
|
|
|
|
record Lattice {a} (A : Set a) : Set (lsuc a) where
|
|
|
|
|
field
|
2023-07-15 14:40:11 -07:00
|
|
|
|
_≈_ : A → A → Set a
|
2023-04-06 23:08:49 -07:00
|
|
|
|
_⊔_ : A → A → A
|
|
|
|
|
_⊓_ : A → A → A
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
isLattice : IsLattice A _≈_ _⊔_ _⊓_
|
2023-04-06 23:08:49 -07:00
|
|
|
|
|
|
|
|
|
open IsLattice isLattice public
|
|
|
|
|
|
2023-07-23 00:51:34 -07:00
|
|
|
|
module IsEquivalenceInstances where
|
|
|
|
|
module ForMap {a b} (A : Set a) (B : Set b)
|
|
|
|
|
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
|
|
|
|
(_≈₂_ : B → B → Set b)
|
|
|
|
|
(eB : IsEquivalence B _≈₂_) where
|
|
|
|
|
|
2023-08-03 23:46:26 -07:00
|
|
|
|
open import Map A B ≡-dec-A using (Map; lift; subset)
|
2023-07-23 00:51:34 -07:00
|
|
|
|
open import Data.List using (_∷_; []) -- TODO: re-export these with nicer names from map
|
|
|
|
|
|
|
|
|
|
open IsEquivalence eB renaming
|
|
|
|
|
( ≈-refl to ≈₂-refl
|
|
|
|
|
; ≈-sym to ≈₂-sym
|
|
|
|
|
; ≈-trans to ≈₂-trans
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
_≈_ : Map → Map → Set (Agda.Primitive._⊔_ a b)
|
|
|
|
|
_≈_ = lift _≈₂_
|
|
|
|
|
|
|
|
|
|
_⊆_ : Map → Map → Set (Agda.Primitive._⊔_ a b)
|
|
|
|
|
_⊆_ = subset _≈₂_
|
|
|
|
|
|
2023-07-24 23:58:14 -07:00
|
|
|
|
⊆-refl : (m : Map) → m ⊆ m
|
|
|
|
|
⊆-refl _ k v k,v∈m = (v , (≈₂-refl , k,v∈m))
|
2023-07-23 00:51:34 -07:00
|
|
|
|
|
2023-07-24 23:58:14 -07:00
|
|
|
|
⊆-trans : (m₁ m₂ m₃ : Map) → m₁ ⊆ m₂ → m₂ ⊆ m₃ → m₁ ⊆ m₃
|
|
|
|
|
⊆-trans _ _ _ m₁⊆m₂ m₂⊆m₃ k v k,v∈m₁ =
|
2023-07-23 00:51:34 -07:00
|
|
|
|
let
|
|
|
|
|
(v' , (v≈v' , k,v'∈m₂)) = m₁⊆m₂ k v k,v∈m₁
|
|
|
|
|
(v'' , (v'≈v'' , k,v''∈m₃)) = m₂⊆m₃ k v' k,v'∈m₂
|
|
|
|
|
in (v'' , (≈₂-trans v≈v' v'≈v'' , k,v''∈m₃))
|
|
|
|
|
|
2023-07-24 23:58:14 -07:00
|
|
|
|
≈-refl : (m : Map) → m ≈ m
|
|
|
|
|
≈-refl m = (⊆-refl m , ⊆-refl m)
|
2023-07-23 00:51:34 -07:00
|
|
|
|
|
2023-07-24 23:58:14 -07:00
|
|
|
|
≈-sym : (m₁ m₂ : Map) → m₁ ≈ m₂ → m₂ ≈ m₁
|
|
|
|
|
≈-sym _ _ (m₁⊆m₂ , m₂⊆m₁) = (m₂⊆m₁ , m₁⊆m₂)
|
2023-07-23 00:51:34 -07:00
|
|
|
|
|
2023-07-24 23:58:14 -07:00
|
|
|
|
≈-trans : (m₁ m₂ m₃ : Map) → m₁ ≈ m₂ → m₂ ≈ m₃ → m₁ ≈ m₃
|
|
|
|
|
≈-trans m₁ m₂ m₃ (m₁⊆m₂ , m₂⊆m₁) (m₂⊆m₃ , m₃⊆m₂) =
|
|
|
|
|
( ⊆-trans m₁ m₂ m₃ m₁⊆m₂ m₂⊆m₃
|
|
|
|
|
, ⊆-trans m₃ m₂ m₁ m₃⊆m₂ m₂⊆m₁
|
2023-07-24 23:55:09 -07:00
|
|
|
|
)
|
2023-07-23 00:51:34 -07:00
|
|
|
|
|
2023-07-30 20:36:19 -07:00
|
|
|
|
LiftEquivalence : IsEquivalence Map _≈_
|
|
|
|
|
LiftEquivalence = record
|
|
|
|
|
{ ≈-refl = λ {m₁} → ≈-refl m₁
|
|
|
|
|
; ≈-sym = λ {m₁} {m₂} → ≈-sym m₁ m₂
|
|
|
|
|
; ≈-trans = λ {m₁} {m₂} {m₃} → ≈-trans m₁ m₂ m₃
|
|
|
|
|
}
|
2023-07-23 00:51:34 -07:00
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
module IsSemilatticeInstances where
|
2023-07-14 19:59:07 -07:00
|
|
|
|
module ForNat where
|
|
|
|
|
open Nat
|
|
|
|
|
open NatProps
|
|
|
|
|
open Eq
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
NatIsMaxSemilattice : IsSemilattice ℕ _≡_ _⊔_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
NatIsMaxSemilattice = record
|
2023-07-15 15:16:51 -07:00
|
|
|
|
{ ≈-equiv = record
|
|
|
|
|
{ ≈-refl = refl
|
|
|
|
|
; ≈-sym = sym
|
|
|
|
|
; ≈-trans = trans
|
|
|
|
|
}
|
|
|
|
|
; ⊔-assoc = ⊔-assoc
|
2023-07-15 13:12:21 -07:00
|
|
|
|
; ⊔-comm = ⊔-comm
|
|
|
|
|
; ⊔-idemp = ⊔-idem
|
2023-07-14 19:59:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
NatIsMinSemilattice : IsSemilattice ℕ _≡_ _⊓_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
NatIsMinSemilattice = record
|
2023-07-15 15:16:51 -07:00
|
|
|
|
{ ≈-equiv = record
|
|
|
|
|
{ ≈-refl = refl
|
|
|
|
|
; ≈-sym = sym
|
|
|
|
|
; ≈-trans = trans
|
|
|
|
|
}
|
|
|
|
|
; ⊔-assoc = ⊓-assoc
|
2023-07-15 13:12:21 -07:00
|
|
|
|
; ⊔-comm = ⊓-comm
|
|
|
|
|
; ⊔-idemp = ⊓-idem
|
2023-07-14 19:59:07 -07:00
|
|
|
|
}
|
2023-07-14 19:42:29 -07:00
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
module ForProd {a} {A B : Set a}
|
2023-07-15 14:40:11 -07:00
|
|
|
|
(_≈₁_ : A → A → Set a) (_≈₂_ : B → B → Set a)
|
2023-07-15 13:12:21 -07:00
|
|
|
|
(_⊔₁_ : A → A → A) (_⊔₂_ : B → B → B)
|
2023-07-15 14:40:11 -07:00
|
|
|
|
(sA : IsSemilattice A _≈₁_ _⊔₁_) (sB : IsSemilattice B _≈₂_ _⊔₂_) where
|
2023-07-15 13:12:21 -07:00
|
|
|
|
|
2023-07-14 21:20:16 -07:00
|
|
|
|
open Eq
|
|
|
|
|
open Data.Product
|
|
|
|
|
|
|
|
|
|
private
|
2023-07-15 14:40:11 -07:00
|
|
|
|
infix 4 _≈_
|
|
|
|
|
infixl 20 _⊔_
|
2023-07-14 21:20:16 -07:00
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
_≈_ : A × B → A × B → Set a
|
|
|
|
|
(a₁ , b₁) ≈ (a₂ , b₂) = (a₁ ≈₁ a₂) × (b₁ ≈₂ b₂)
|
2023-07-14 21:20:16 -07:00
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
_⊔_ : A × B → A × B → A × B
|
|
|
|
|
(a₁ , b₁) ⊔ (a₂ , b₂) = (a₁ ⊔₁ a₂ , b₁ ⊔₂ b₂)
|
2023-07-15 13:12:21 -07:00
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
⊔-assoc : (p₁ p₂ p₃ : A × B) → (p₁ ⊔ p₂) ⊔ p₃ ≈ p₁ ⊔ (p₂ ⊔ p₃)
|
|
|
|
|
⊔-assoc (a₁ , b₁) (a₂ , b₂) (a₃ , b₃) =
|
|
|
|
|
( IsSemilattice.⊔-assoc sA a₁ a₂ a₃
|
|
|
|
|
, IsSemilattice.⊔-assoc sB b₁ b₂ b₃
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
⊔-comm : (p₁ p₂ : A × B) → p₁ ⊔ p₂ ≈ p₂ ⊔ p₁
|
|
|
|
|
⊔-comm (a₁ , b₁) (a₂ , b₂) =
|
|
|
|
|
( IsSemilattice.⊔-comm sA a₁ a₂
|
|
|
|
|
, IsSemilattice.⊔-comm sB b₁ b₂
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
⊔-idemp : (p : A × B) → p ⊔ p ≈ p
|
|
|
|
|
⊔-idemp (a , b) =
|
|
|
|
|
( IsSemilattice.⊔-idemp sA a
|
|
|
|
|
, IsSemilattice.⊔-idemp sB b
|
|
|
|
|
)
|
|
|
|
|
|
2023-07-15 15:16:51 -07:00
|
|
|
|
≈-refl : {p : A × B} → p ≈ p
|
|
|
|
|
≈-refl =
|
|
|
|
|
( IsSemilattice.≈-refl sA
|
|
|
|
|
, IsSemilattice.≈-refl sB
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
≈-sym : {p₁ p₂ : A × B} → p₁ ≈ p₂ → p₂ ≈ p₁
|
|
|
|
|
≈-sym (a₁≈a₂ , b₁≈b₂) =
|
|
|
|
|
( IsSemilattice.≈-sym sA a₁≈a₂
|
|
|
|
|
, IsSemilattice.≈-sym sB b₁≈b₂
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
≈-trans : {p₁ p₂ p₃ : A × B} → p₁ ≈ p₂ → p₂ ≈ p₃ → p₁ ≈ p₃
|
|
|
|
|
≈-trans (a₁≈a₂ , b₁≈b₂) (a₂≈a₃ , b₂≈b₃) =
|
|
|
|
|
( IsSemilattice.≈-trans sA a₁≈a₂ a₂≈a₃
|
|
|
|
|
, IsSemilattice.≈-trans sB b₁≈b₂ b₂≈b₃
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
ProdIsSemilattice : IsSemilattice (A × B) _≈_ _⊔_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
ProdIsSemilattice = record
|
2023-07-15 15:16:51 -07:00
|
|
|
|
{ ≈-equiv = record
|
|
|
|
|
{ ≈-refl = ≈-refl
|
|
|
|
|
; ≈-sym = ≈-sym
|
|
|
|
|
; ≈-trans = ≈-trans
|
|
|
|
|
}
|
|
|
|
|
; ⊔-assoc = ⊔-assoc
|
2023-07-15 13:12:21 -07:00
|
|
|
|
; ⊔-comm = ⊔-comm
|
|
|
|
|
; ⊔-idemp = ⊔-idemp
|
2023-07-14 21:20:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 20:36:19 -07:00
|
|
|
|
module ForMap {a} {A B : Set a}
|
|
|
|
|
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
|
|
|
|
(_≈₂_ : B → B → Set a)
|
|
|
|
|
(_⊔₂_ : B → B → B)
|
|
|
|
|
(sB : IsSemilattice B _≈₂_ _⊔₂_) where
|
|
|
|
|
|
|
|
|
|
open import Map A B ≡-dec-A
|
2023-07-30 21:50:28 -07:00
|
|
|
|
open IsSemilattice sB renaming
|
|
|
|
|
( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym
|
|
|
|
|
; ⊔-assoc to ⊔₂-assoc; ⊔-comm to ⊔₂-comm; ⊔-idemp to ⊔₂-idemp
|
|
|
|
|
)
|
2023-07-30 20:36:19 -07:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
infix 4 _≈_
|
|
|
|
|
infixl 20 _⊔_
|
|
|
|
|
|
|
|
|
|
_≈_ : Map → Map → Set a
|
|
|
|
|
_≈_ = lift (_≈₂_)
|
|
|
|
|
|
|
|
|
|
_⊔_ : Map → Map → Map
|
|
|
|
|
m₁ ⊔ m₂ = union _⊔₂_ m₁ m₂
|
|
|
|
|
|
2023-08-05 12:48:44 -07:00
|
|
|
|
_⊓_ : Map → Map → Map
|
|
|
|
|
m₁ ⊓ m₂ = intersect _⊔₂_ m₁ m₂
|
|
|
|
|
|
2023-07-30 20:36:19 -07:00
|
|
|
|
module MapEquiv = IsEquivalenceInstances.ForMap A B ≡-dec-A _≈₂_ (IsSemilattice.≈-equiv sB)
|
|
|
|
|
|
|
|
|
|
MapIsUnionSemilattice : IsSemilattice Map _≈_ _⊔_
|
|
|
|
|
MapIsUnionSemilattice = record
|
|
|
|
|
{ ≈-equiv = MapEquiv.LiftEquivalence
|
2023-07-30 21:50:28 -07:00
|
|
|
|
; ⊔-assoc = union-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
|
|
|
|
|
; ⊔-comm = union-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
|
|
|
|
|
; ⊔-idemp = union-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
|
2023-07-30 20:36:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:48:44 -07:00
|
|
|
|
MapIsIntersectSemilattice : IsSemilattice Map _≈_ _⊓_
|
|
|
|
|
MapIsIntersectSemilattice = record
|
|
|
|
|
{ ≈-equiv = MapEquiv.LiftEquivalence
|
|
|
|
|
; ⊔-assoc = intersect-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
|
|
|
|
|
; ⊔-comm = intersect-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
|
|
|
|
|
; ⊔-idemp = intersect-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
module IsLatticeInstances where
|
2023-07-14 21:49:47 -07:00
|
|
|
|
module ForNat where
|
|
|
|
|
open Nat
|
|
|
|
|
open NatProps
|
|
|
|
|
open Eq
|
2023-07-15 13:12:21 -07:00
|
|
|
|
open IsSemilatticeInstances.ForNat
|
2023-07-14 21:49:47 -07:00
|
|
|
|
open Data.Product
|
|
|
|
|
|
|
|
|
|
private
|
2023-07-15 12:18:50 -07:00
|
|
|
|
max-bound₁ : {x y z : ℕ} → x ⊔ y ≡ z → x ≤ z
|
2023-07-15 14:40:11 -07:00
|
|
|
|
max-bound₁ {x} {y} {z} x⊔y≡z
|
|
|
|
|
rewrite sym x⊔y≡z
|
|
|
|
|
rewrite ⊔-comm x y = m≤n⇒m≤o⊔n y (≤-refl)
|
2023-07-15 12:18:50 -07:00
|
|
|
|
|
|
|
|
|
min-bound₁ : {x y z : ℕ} → x ⊓ y ≡ z → z ≤ x
|
2023-07-15 14:40:11 -07:00
|
|
|
|
min-bound₁ {x} {y} {z} x⊓y≡z
|
|
|
|
|
rewrite sym x⊓y≡z = m≤n⇒m⊓o≤n y (≤-refl)
|
2023-07-15 12:18:50 -07:00
|
|
|
|
|
2023-07-14 21:49:47 -07:00
|
|
|
|
minmax-absorb : {x y : ℕ} → x ⊓ (x ⊔ y) ≡ x
|
|
|
|
|
minmax-absorb {x} {y} = ≤-antisym x⊓x⊔y≤x (helper x⊓x≤x⊓x⊔y (⊓-idem x))
|
|
|
|
|
where
|
2023-07-15 12:18:50 -07:00
|
|
|
|
x⊓x⊔y≤x = min-bound₁ {x} {x ⊔ y} {x ⊓ (x ⊔ y)} refl
|
|
|
|
|
x⊓x≤x⊓x⊔y = ⊓-mono-≤ {x} {x} ≤-refl (max-bound₁ {x} {y} {x ⊔ y} refl)
|
2023-07-14 21:49:47 -07:00
|
|
|
|
|
|
|
|
|
-- >:(
|
|
|
|
|
helper : x ⊓ x ≤ x ⊓ (x ⊔ y) → x ⊓ x ≡ x → x ≤ x ⊓ (x ⊔ y)
|
|
|
|
|
helper x⊓x≤x⊓x⊔y x⊓x≡x rewrite x⊓x≡x = x⊓x≤x⊓x⊔y
|
|
|
|
|
|
|
|
|
|
maxmin-absorb : {x y : ℕ} → x ⊔ (x ⊓ y) ≡ x
|
|
|
|
|
maxmin-absorb {x} {y} = ≤-antisym (helper x⊔x⊓y≤x⊔x (⊔-idem x)) x≤x⊔x⊓y
|
|
|
|
|
where
|
2023-07-15 12:18:50 -07:00
|
|
|
|
x≤x⊔x⊓y = max-bound₁ {x} {x ⊓ y} {x ⊔ (x ⊓ y)} refl
|
|
|
|
|
x⊔x⊓y≤x⊔x = ⊔-mono-≤ {x} {x} ≤-refl (min-bound₁ {x} {y} {x ⊓ y} refl)
|
2023-07-14 21:49:47 -07:00
|
|
|
|
|
|
|
|
|
-- >:(
|
|
|
|
|
helper : x ⊔ (x ⊓ y) ≤ x ⊔ x → x ⊔ x ≡ x → x ⊔ (x ⊓ y) ≤ x
|
|
|
|
|
helper x⊔x⊓y≤x⊔x x⊔x≡x rewrite x⊔x≡x = x⊔x⊓y≤x⊔x
|
|
|
|
|
|
2023-07-15 14:40:11 -07:00
|
|
|
|
NatIsLattice : IsLattice ℕ _≡_ _⊔_ _⊓_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
NatIsLattice = record
|
|
|
|
|
{ joinSemilattice = NatIsMaxSemilattice
|
|
|
|
|
; meetSemilattice = NatIsMinSemilattice
|
|
|
|
|
; absorb-⊔-⊓ = λ x y → maxmin-absorb {x} {y}
|
|
|
|
|
; absorb-⊓-⊔ = λ x y → minmax-absorb {x} {y}
|
2023-07-14 21:49:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
module ForProd {a} {A B : Set a}
|
2023-07-15 14:40:11 -07:00
|
|
|
|
(_≈₁_ : A → A → Set a) (_≈₂_ : B → B → Set a)
|
2023-07-15 13:12:21 -07:00
|
|
|
|
(_⊔₁_ : A → A → A) (_⊓₁_ : A → A → A)
|
|
|
|
|
(_⊔₂_ : B → B → B) (_⊓₂_ : B → B → B)
|
2023-07-15 14:40:11 -07:00
|
|
|
|
(lA : IsLattice A _≈₁_ _⊔₁_ _⊓₁_) (lB : IsLattice B _≈₂_ _⊔₂_ _⊓₂_) where
|
2023-07-15 13:12:21 -07:00
|
|
|
|
|
2023-07-14 21:49:47 -07:00
|
|
|
|
private
|
2023-07-15 14:40:11 -07:00
|
|
|
|
module ProdJoin = IsSemilatticeInstances.ForProd _≈₁_ _≈₂_ _⊔₁_ _⊔₂_ (IsLattice.joinSemilattice lA) (IsLattice.joinSemilattice lB)
|
|
|
|
|
module ProdMeet = IsSemilatticeInstances.ForProd _≈₁_ _≈₂_ _⊓₁_ _⊓₂_ (IsLattice.meetSemilattice lA) (IsLattice.meetSemilattice lB)
|
|
|
|
|
|
|
|
|
|
infix 4 _≈_
|
|
|
|
|
infixl 20 _⊔_
|
|
|
|
|
|
|
|
|
|
_≈_ : (A × B) → (A × B) → Set a
|
|
|
|
|
(a₁ , b₁) ≈ (a₂ , b₂) = (a₁ ≈₁ a₂) × (b₁ ≈₂ b₂)
|
2023-07-15 13:12:21 -07:00
|
|
|
|
|
|
|
|
|
_⊔_ : (A × B) → (A × B) → (A × B)
|
|
|
|
|
(a₁ , b₁) ⊔ (a₂ , b₂) = (a₁ ⊔₁ a₂ , b₁ ⊔₂ b₂)
|
2023-07-14 21:49:47 -07:00
|
|
|
|
|
2023-07-15 13:12:21 -07:00
|
|
|
|
_⊓_ : (A × B) → (A × B) → (A × B)
|
|
|
|
|
(a₁ , b₁) ⊓ (a₂ , b₂) = (a₁ ⊓₁ a₂ , b₁ ⊓₂ b₂)
|
2023-07-14 21:49:47 -07:00
|
|
|
|
|
|
|
|
|
open Eq
|
|
|
|
|
open Data.Product
|
|
|
|
|
|
|
|
|
|
private
|
2023-07-15 14:40:11 -07:00
|
|
|
|
absorb-⊔-⊓ : (p₁ p₂ : A × B) → p₁ ⊔ (p₁ ⊓ p₂) ≈ p₁
|
|
|
|
|
absorb-⊔-⊓ (a₁ , b₁) (a₂ , b₂) =
|
|
|
|
|
( IsLattice.absorb-⊔-⊓ lA a₁ a₂
|
|
|
|
|
, IsLattice.absorb-⊔-⊓ lB b₁ b₂
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
absorb-⊓-⊔ : (p₁ p₂ : A × B) → p₁ ⊓ (p₁ ⊔ p₂) ≈ p₁
|
|
|
|
|
absorb-⊓-⊔ (a₁ , b₁) (a₂ , b₂) =
|
|
|
|
|
( IsLattice.absorb-⊓-⊔ lA a₁ a₂
|
|
|
|
|
, IsLattice.absorb-⊓-⊔ lB b₁ b₂
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
ProdIsLattice : IsLattice (A × B) _≈_ _⊔_ _⊓_
|
2023-07-15 13:12:21 -07:00
|
|
|
|
ProdIsLattice = record
|
|
|
|
|
{ joinSemilattice = ProdJoin.ProdIsSemilattice
|
|
|
|
|
; meetSemilattice = ProdMeet.ProdIsSemilattice
|
|
|
|
|
; absorb-⊔-⊓ = absorb-⊔-⊓
|
|
|
|
|
; absorb-⊓-⊔ = absorb-⊓-⊔
|
2023-07-13 23:22:29 -07:00
|
|
|
|
}
|