Move the lattice etc. instances into Lattice.Map
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
845a8a2236
commit
5d54e62c3a
|
@ -35,44 +35,3 @@ module IsEquivalenceInstances where
|
||||||
, IsEquivalence.≈-trans eB b₁≈b₂ b₂≈b₃
|
, IsEquivalence.≈-trans eB b₁≈b₂ b₂≈b₃
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
module ForMap {a b} (A : Set a) (B : Set b)
|
|
||||||
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
|
||||||
(_≈₂_ : B → B → Set b)
|
|
||||||
(eB : IsEquivalence B _≈₂_) where
|
|
||||||
|
|
||||||
open import Lattice.Map A B ≡-dec-A using (Map; lift; subset)
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
_≈_ : Map → Map → Set (Agda.Primitive._⊔_ a b)
|
|
||||||
_≈_ = lift _≈₂_
|
|
||||||
|
|
||||||
_⊆_ : Map → Map → Set (Agda.Primitive._⊔_ a b)
|
|
||||||
_⊆_ = subset _≈₂_
|
|
||||||
|
|
||||||
private
|
|
||||||
⊆-refl : (m : Map) → m ⊆ m
|
|
||||||
⊆-refl _ k v k,v∈m = (v , (≈₂-refl , k,v∈m))
|
|
||||||
|
|
||||||
⊆-trans : (m₁ m₂ m₃ : Map) → m₁ ⊆ m₂ → m₂ ⊆ m₃ → m₁ ⊆ m₃
|
|
||||||
⊆-trans _ _ _ m₁⊆m₂ m₂⊆m₃ k v k,v∈m₁ =
|
|
||||||
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₃))
|
|
||||||
|
|
||||||
LiftEquivalence : IsEquivalence Map _≈_
|
|
||||||
LiftEquivalence = record
|
|
||||||
{ ≈-refl = λ {m} → (⊆-refl m , ⊆-refl m)
|
|
||||||
; ≈-sym = λ {m₁} {m₂} (m₁⊆m₂ , 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₁
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
69
Lattice.agda
69
Lattice.agda
|
@ -215,48 +215,6 @@ module IsSemilatticeInstances where
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 Lattice.Map A B ≡-dec-A
|
|
||||||
open IsSemilattice sB renaming
|
|
||||||
( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym; ≈-⊔-cong to ≈₂-⊔₂-cong
|
|
||||||
; ⊔-assoc to ⊔₂-assoc; ⊔-comm to ⊔₂-comm; ⊔-idemp to ⊔₂-idemp
|
|
||||||
)
|
|
||||||
|
|
||||||
module MapEquiv = IsEquivalenceInstances.ForMap A B ≡-dec-A _≈₂_ (IsSemilattice.≈-equiv sB)
|
|
||||||
open MapEquiv using (_≈_) public
|
|
||||||
|
|
||||||
infixl 20 _⊔_
|
|
||||||
infixl 20 _⊓_
|
|
||||||
|
|
||||||
_⊔_ : Map → Map → Map
|
|
||||||
m₁ ⊔ m₂ = union _⊔₂_ m₁ m₂
|
|
||||||
|
|
||||||
_⊓_ : Map → Map → Map
|
|
||||||
m₁ ⊓ m₂ = intersect _⊔₂_ m₁ m₂
|
|
||||||
|
|
||||||
MapIsUnionSemilattice : IsSemilattice Map _≈_ _⊔_
|
|
||||||
MapIsUnionSemilattice = record
|
|
||||||
{ ≈-equiv = MapEquiv.LiftEquivalence
|
|
||||||
; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} → union-cong _≈₂_ _⊔₂_ ≈₂-⊔₂-cong {m₁} {m₂} {m₃} {m₄}
|
|
||||||
; ⊔-assoc = union-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
|
|
||||||
; ⊔-comm = union-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
|
|
||||||
; ⊔-idemp = union-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
|
|
||||||
}
|
|
||||||
|
|
||||||
MapIsIntersectSemilattice : IsSemilattice Map _≈_ _⊓_
|
|
||||||
MapIsIntersectSemilattice = record
|
|
||||||
{ ≈-equiv = MapEquiv.LiftEquivalence
|
|
||||||
; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} → intersect-cong _≈₂_ _⊔₂_ ≈₂-⊔₂-cong {m₁} {m₂} {m₃} {m₄}
|
|
||||||
; ⊔-assoc = intersect-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
|
|
||||||
; ⊔-comm = intersect-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
|
|
||||||
; ⊔-idemp = intersect-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
|
|
||||||
}
|
|
||||||
|
|
||||||
module IsLatticeInstances where
|
module IsLatticeInstances where
|
||||||
module ForNat where
|
module ForNat where
|
||||||
open Nat
|
open Nat
|
||||||
|
@ -329,33 +287,6 @@ module IsLatticeInstances where
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
module ForMap {a} {A B : Set a}
|
|
||||||
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
|
||||||
(_≈₂_ : B → B → Set a)
|
|
||||||
(_⊔₂_ : B → B → B)
|
|
||||||
(_⊓₂_ : B → B → B)
|
|
||||||
(lB : IsLattice B _≈₂_ _⊔₂_ _⊓₂_) where
|
|
||||||
|
|
||||||
open import Lattice.Map A B ≡-dec-A
|
|
||||||
open IsLattice lB renaming
|
|
||||||
( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym
|
|
||||||
; ⊔-idemp to ⊔₂-idemp; ⊓-idemp to ⊓₂-idemp
|
|
||||||
; absorb-⊔-⊓ to absorb-⊔₂-⊓₂; absorb-⊓-⊔ to absorb-⊓₂-⊔₂
|
|
||||||
)
|
|
||||||
|
|
||||||
module MapJoin = IsSemilatticeInstances.ForMap ≡-dec-A _≈₂_ _⊔₂_ (IsLattice.joinSemilattice lB)
|
|
||||||
open MapJoin using (_⊔_; _≈_) public
|
|
||||||
|
|
||||||
module MapMeet = IsSemilatticeInstances.ForMap ≡-dec-A _≈₂_ _⊓₂_ (IsLattice.meetSemilattice lB)
|
|
||||||
open MapMeet using (_⊓_) public
|
|
||||||
|
|
||||||
MapIsLattice : IsLattice Map _≈_ _⊔_ _⊓_
|
|
||||||
MapIsLattice = record
|
|
||||||
{ joinSemilattice = MapJoin.MapIsUnionSemilattice
|
|
||||||
; meetSemilattice = MapMeet.MapIsIntersectSemilattice
|
|
||||||
; absorb-⊔-⊓ = union-intersect-absorb _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ _⊓₂_ ⊔₂-idemp ⊓₂-idemp absorb-⊔₂-⊓₂ absorb-⊓₂-⊔₂
|
|
||||||
; absorb-⊓-⊔ = intersect-union-absorb _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ _⊓₂_ ⊔₂-idemp ⊓₂-idemp absorb-⊔₂-⊓₂ absorb-⊓₂-⊔₂
|
|
||||||
}
|
|
||||||
|
|
||||||
module IsFiniteHeightLatticeInstances where
|
module IsFiniteHeightLatticeInstances where
|
||||||
module ForProd {a} {A B : Set a}
|
module ForProd {a} {A B : Set a}
|
||||||
|
|
781
Lattice/Map.agda
781
Lattice/Map.agda
|
@ -1,3 +1,4 @@
|
||||||
|
open import Lattice
|
||||||
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; sym; trans; cong; subst)
|
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; sym; trans; cong; subst)
|
||||||
open import Relation.Binary.Definitions using (Decidable)
|
open import Relation.Binary.Definitions using (Decidable)
|
||||||
open import Relation.Binary.Core using (Rel)
|
open import Relation.Binary.Core using (Rel)
|
||||||
|
@ -5,8 +6,10 @@ open import Relation.Nullary using (Dec; yes; no; Reflects; ofʸ; ofⁿ)
|
||||||
open import Agda.Primitive using (Level) renaming (_⊔_ to _⊔ℓ_)
|
open import Agda.Primitive using (Level) renaming (_⊔_ to _⊔ℓ_)
|
||||||
|
|
||||||
module Lattice.Map {a b : Level} (A : Set a) (B : Set b)
|
module Lattice.Map {a b : Level} (A : Set a) (B : Set b)
|
||||||
|
(_≈₂_ : B → B → Set b)
|
||||||
|
(_⊔₂_ : B → B → B) (_⊓₂_ : B → B → B)
|
||||||
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
(≡-dec-A : Decidable (_≡_ {a} {A}))
|
||||||
where
|
(lB : IsLattice B _≈₂_ _⊔₂_ _⊓₂_) where
|
||||||
|
|
||||||
import Data.List.Membership.Propositional as MemProp
|
import Data.List.Membership.Propositional as MemProp
|
||||||
|
|
||||||
|
@ -16,7 +19,16 @@ open import Data.List using (List; map; []; _∷_; _++_)
|
||||||
open import Data.List.Relation.Unary.All using (All; []; _∷_)
|
open import Data.List.Relation.Unary.All using (All; []; _∷_)
|
||||||
open import Data.List.Relation.Unary.Any using (Any; here; there) -- TODO: re-export these with nicer names from map
|
open import Data.List.Relation.Unary.Any using (Any; here; there) -- TODO: re-export these with nicer names from map
|
||||||
open import Data.Product using (_×_; _,_; Σ; proj₁ ; proj₂)
|
open import Data.Product using (_×_; _,_; Σ; proj₁ ; proj₂)
|
||||||
open import Data.Empty using (⊥)
|
open import Data.Empty using (⊥; ⊥-elim)
|
||||||
|
open import Equivalence
|
||||||
|
|
||||||
|
open IsLattice lB using () renaming
|
||||||
|
( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym; ≈-trans to ≈₂-trans
|
||||||
|
; ≈-⊔-cong to ≈₂-⊔₂-cong; ≈-⊓-cong to ≈₂-⊓₂-cong
|
||||||
|
; ⊔-idemp to ⊔₂-idemp; ⊔-comm to ⊔₂-comm; ⊔-assoc to ⊔₂-assoc
|
||||||
|
; ⊓-idemp to ⊓₂-idemp; ⊓-comm to ⊓₂-comm; ⊓-assoc to ⊓₂-assoc
|
||||||
|
; absorb-⊔-⊓ to absorb-⊔₂-⊓₂; absorb-⊓-⊔ to absorb-⊓₂-⊔₂
|
||||||
|
)
|
||||||
|
|
||||||
keys : List (A × B) → List A
|
keys : List (A × B) → List A
|
||||||
keys = map proj₁
|
keys = map proj₁
|
||||||
|
@ -45,9 +57,6 @@ All¬-¬Any : ∀ {p c} {C : Set c} {P : C → Set p} {l : List C} → All (λ x
|
||||||
All¬-¬Any {l = x ∷ xs} (¬Px ∷ _) (here Px) = ¬Px Px
|
All¬-¬Any {l = x ∷ xs} (¬Px ∷ _) (here Px) = ¬Px Px
|
||||||
All¬-¬Any {l = x ∷ xs} (_ ∷ ¬Pxs) (there Pxs) = All¬-¬Any ¬Pxs Pxs
|
All¬-¬Any {l = x ∷ xs} (_ ∷ ¬Pxs) (there Pxs) = All¬-¬Any ¬Pxs Pxs
|
||||||
|
|
||||||
absurd : ∀ {a} {A : Set a} → ⊥ → A
|
|
||||||
absurd ()
|
|
||||||
|
|
||||||
private module _ where
|
private module _ where
|
||||||
open MemProp using (_∈_)
|
open MemProp using (_∈_)
|
||||||
|
|
||||||
|
@ -63,9 +72,9 @@ private module _ where
|
||||||
ListAB-functional _ (here k,v≡x) (here k,v'≡x) =
|
ListAB-functional _ (here k,v≡x) (here k,v'≡x) =
|
||||||
cong proj₂ (trans k,v≡x (sym k,v'≡x))
|
cong proj₂ (trans k,v≡x (sym k,v'≡x))
|
||||||
ListAB-functional (push k≢xs _) (here k,v≡x) (there k,v'∈xs)
|
ListAB-functional (push k≢xs _) (here k,v≡x) (there k,v'∈xs)
|
||||||
rewrite sym k,v≡x = absurd (unique-not-in (k≢xs , k,v'∈xs))
|
rewrite sym k,v≡x = ⊥-elim (unique-not-in (k≢xs , k,v'∈xs))
|
||||||
ListAB-functional (push k≢xs _) (there k,v∈xs) (here k,v'≡x)
|
ListAB-functional (push k≢xs _) (there k,v∈xs) (here k,v'≡x)
|
||||||
rewrite sym k,v'≡x = absurd (unique-not-in (k≢xs , k,v∈xs))
|
rewrite sym k,v'≡x = ⊥-elim (unique-not-in (k≢xs , k,v∈xs))
|
||||||
ListAB-functional {l = _ ∷ xs } (push _ uxs) (there k,v∈xs) (there k,v'∈xs) =
|
ListAB-functional {l = _ ∷ xs } (push _ uxs) (there k,v∈xs) (there k,v'∈xs) =
|
||||||
ListAB-functional uxs k,v∈xs k,v'∈xs
|
ListAB-functional uxs k,v∈xs k,v'∈xs
|
||||||
|
|
||||||
|
@ -91,12 +100,12 @@ private module _ where
|
||||||
locate {k} {(k' , v) ∷ xs} (here k≡k') rewrite k≡k' = (v , here refl)
|
locate {k} {(k' , v) ∷ xs} (here k≡k') rewrite k≡k' = (v , here refl)
|
||||||
locate {k} {(k' , v) ∷ xs} (there k∈kxs) = let (v , k,v∈xs) = locate k∈kxs in (v , there k,v∈xs)
|
locate {k} {(k' , v) ∷ xs} (there k∈kxs) = let (v , k,v∈xs) = locate k∈kxs in (v , there k,v∈xs)
|
||||||
|
|
||||||
private module ImplRelation (_≈_ : B → B → Set b) where
|
private module ImplRelation where
|
||||||
open MemProp using (_∈_)
|
open MemProp using (_∈_)
|
||||||
|
|
||||||
subset : List (A × B) → List (A × B) → Set (a ⊔ℓ b)
|
subset : List (A × B) → List (A × B) → Set (a ⊔ℓ b)
|
||||||
subset m₁ m₂ = ∀ (k : A) (v : B) → (k , v) ∈ m₁ →
|
subset m₁ m₂ = ∀ (k : A) (v : B) → (k , v) ∈ m₁ →
|
||||||
Σ B (λ v' → v ≈ v' × ((k , v') ∈ m₂))
|
Σ B (λ v' → v ≈₂ v' × ((k , v') ∈ m₂))
|
||||||
|
|
||||||
private module ImplInsert (f : B → B → B) where
|
private module ImplInsert (f : B → B → B) where
|
||||||
open import Data.List using (map)
|
open import Data.List using (map)
|
||||||
|
@ -124,7 +133,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
insert-keys-∈ {k} {v} {(k' , v') ∷ xs} (here k≡k')
|
insert-keys-∈ {k} {v} {(k' , v') ∷ xs} (here k≡k')
|
||||||
with (≡-dec-A k k')
|
with (≡-dec-A k k')
|
||||||
... | yes _ = refl
|
... | yes _ = refl
|
||||||
... | no k≢k' = absurd (k≢k' k≡k')
|
... | no k≢k' = ⊥-elim (k≢k' k≡k')
|
||||||
insert-keys-∈ {k} {v} {(k' , _) ∷ xs} (there k∈kxs)
|
insert-keys-∈ {k} {v} {(k' , _) ∷ xs} (there k∈kxs)
|
||||||
with (≡-dec-A k k')
|
with (≡-dec-A k k')
|
||||||
... | yes _ = refl
|
... | yes _ = refl
|
||||||
|
@ -135,7 +144,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
insert-keys-∉ {k} {v} {[]} _ = refl
|
insert-keys-∉ {k} {v} {[]} _ = refl
|
||||||
insert-keys-∉ {k} {v} {(k' , v') ∷ xs} k∉kl
|
insert-keys-∉ {k} {v} {(k' , v') ∷ xs} k∉kl
|
||||||
with (≡-dec-A k k')
|
with (≡-dec-A k k')
|
||||||
... | yes k≡k' = absurd (k∉kl (here k≡k'))
|
... | yes k≡k' = ⊥-elim (k∉kl (here k≡k'))
|
||||||
... | no _ = cong (λ xs' → k' ∷ xs')
|
... | no _ = cong (λ xs' → k' ∷ xs')
|
||||||
(insert-keys-∉ (λ k∈kxs → k∉kl (there k∈kxs)))
|
(insert-keys-∉ (λ k∈kxs → k∉kl (there k∈kxs)))
|
||||||
|
|
||||||
|
@ -157,7 +166,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
insert-fresh {l = []} k∉kl = here refl
|
insert-fresh {l = []} k∉kl = here refl
|
||||||
insert-fresh {k} {l = (k' , v') ∷ xs} k∉kl
|
insert-fresh {k} {l = (k' , v') ∷ xs} k∉kl
|
||||||
with ≡-dec-A k k'
|
with ≡-dec-A k k'
|
||||||
... | yes k≡k' = absurd (k∉kl (here k≡k'))
|
... | yes k≡k' = ⊥-elim (k∉kl (here k≡k'))
|
||||||
... | no _ = there (insert-fresh (λ k∈kxs → k∉kl (there k∈kxs)))
|
... | no _ = there (insert-fresh (λ k∈kxs → k∉kl (there k∈kxs)))
|
||||||
|
|
||||||
insert-preserves-∉k : ∀ {k k' : A} {v' : B} {l : List (A × B)} →
|
insert-preserves-∉k : ∀ {k k' : A} {v' : B} {l : List (A × B)} →
|
||||||
|
@ -179,7 +188,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
union-preserves-∉ {l₁ = []} _ k∉kl₂ = k∉kl₂
|
union-preserves-∉ {l₁ = []} _ k∉kl₂ = k∉kl₂
|
||||||
union-preserves-∉ {k} {(k' , v') ∷ xs₁} k∉kl₁ k∉kl₂
|
union-preserves-∉ {k} {(k' , v') ∷ xs₁} k∉kl₁ k∉kl₂
|
||||||
with ≡-dec-A k k'
|
with ≡-dec-A k k'
|
||||||
... | yes k≡k' = absurd (k∉kl₁ (here k≡k'))
|
... | yes k≡k' = ⊥-elim (k∉kl₁ (here k≡k'))
|
||||||
... | no k≢k' = insert-preserves-∉k k≢k' (union-preserves-∉ (λ k∈kxs₁ → k∉kl₁ (there k∈kxs₁)) k∉kl₂)
|
... | no k≢k' = insert-preserves-∉k k≢k' (union-preserves-∉ (λ k∈kxs₁ → k∉kl₁ (there k∈kxs₁)) k∉kl₂)
|
||||||
|
|
||||||
insert-preserves-∈k : ∀ {k k' : A} {v' : B} {l : List (A × B)} →
|
insert-preserves-∈k : ∀ {k k' : A} {v' : B} {l : List (A × B)} →
|
||||||
|
@ -212,9 +221,9 @@ private module ImplInsert (f : B → B → B) where
|
||||||
¬ k ∈k union l₁ l₂ → ¬ k ∈k l₁ × ¬ k ∈k l₂
|
¬ k ∈k union l₁ l₂ → ¬ k ∈k l₁ × ¬ k ∈k l₂
|
||||||
∉-union-∉-either {k} {l₁} {l₂} k∉l₁l₂
|
∉-union-∉-either {k} {l₁} {l₂} k∉l₁l₂
|
||||||
with ∈k-dec k l₁
|
with ∈k-dec k l₁
|
||||||
... | yes k∈kl₁ = absurd (k∉l₁l₂ (union-preserves-∈k₁ k∈kl₁))
|
... | yes k∈kl₁ = ⊥-elim (k∉l₁l₂ (union-preserves-∈k₁ k∈kl₁))
|
||||||
... | no k∉kl₁ with ∈k-dec k l₂
|
... | no k∉kl₁ with ∈k-dec k l₂
|
||||||
... | yes k∈kl₂ = absurd (k∉l₁l₂ (union-preserves-∈k₂ {l₁ = l₁} k∈kl₂))
|
... | yes k∈kl₂ = ⊥-elim (k∉l₁l₂ (union-preserves-∈k₂ {l₁ = l₁} k∈kl₂))
|
||||||
... | no k∉kl₂ = (k∉kl₁ , k∉kl₂)
|
... | no k∉kl₂ = (k∉kl₁ , k∉kl₂)
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,7 +231,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
¬ k ≡ k' → (k , v) ∈ l → (k , v) ∈ insert k' v' l
|
¬ k ≡ k' → (k , v) ∈ l → (k , v) ∈ insert k' v' l
|
||||||
insert-preserves-∈ {k} {k'} {l = x ∷ xs} k≢k' (here k,v=x)
|
insert-preserves-∈ {k} {k'} {l = x ∷ xs} k≢k' (here k,v=x)
|
||||||
rewrite sym k,v=x with ≡-dec-A k' k
|
rewrite sym k,v=x with ≡-dec-A k' k
|
||||||
... | yes k'≡k = absurd (k≢k' (sym k'≡k))
|
... | yes k'≡k = ⊥-elim (k≢k' (sym k'≡k))
|
||||||
... | no _ = here refl
|
... | no _ = here refl
|
||||||
insert-preserves-∈ {k} {k'} {l = (k'' , _) ∷ xs} k≢k' (there k,v∈xs)
|
insert-preserves-∈ {k} {k'} {l = (k'' , _) ∷ xs} k≢k' (there k,v∈xs)
|
||||||
with ≡-dec-A k' k''
|
with ≡-dec-A k' k''
|
||||||
|
@ -245,7 +254,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
|
|
||||||
k≢k' : ¬ k ≡ k'
|
k≢k' : ¬ k ≡ k'
|
||||||
k≢k' with ≡-dec-A k k'
|
k≢k' with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v∈xs₁))
|
... | yes k≡k' rewrite k≡k' = ⊥-elim (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v∈xs₁))
|
||||||
... | no k≢k' = k≢k'
|
... | no k≢k' = k≢k'
|
||||||
union-preserves-∈₁ {l₁ = (k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (here k,v≡k',v') k∉kl₂
|
union-preserves-∈₁ {l₁ = (k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (here k,v≡k',v') k∉kl₂
|
||||||
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v' =
|
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v' =
|
||||||
|
@ -257,10 +266,10 @@ private module ImplInsert (f : B → B → B) where
|
||||||
rewrite cong proj₁ k,v'≡k',v'' rewrite cong proj₂ k,v'≡k',v''
|
rewrite cong proj₁ k,v'≡k',v'' rewrite cong proj₂ k,v'≡k',v''
|
||||||
with ≡-dec-A k' k'
|
with ≡-dec-A k' k'
|
||||||
... | yes _ = here refl
|
... | yes _ = here refl
|
||||||
... | no k≢k' = absurd (k≢k' refl)
|
... | no k≢k' = ⊥-elim (k≢k' refl)
|
||||||
insert-combines {k} {l = (k' , v'') ∷ xs} (push k'≢xs uxs) (there k,v'∈xs)
|
insert-combines {k} {l = (k' , v'') ∷ xs} (push k'≢xs uxs) (there k,v'∈xs)
|
||||||
with ≡-dec-A k k'
|
with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v'∈xs))
|
... | yes k≡k' rewrite k≡k' = ⊥-elim (All¬-¬Any k'≢xs (∈-cong proj₁ k,v'∈xs))
|
||||||
... | no k≢k' = there (insert-combines uxs k,v'∈xs)
|
... | no k≢k' = there (insert-combines uxs k,v'∈xs)
|
||||||
|
|
||||||
union-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
union-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
||||||
|
@ -274,7 +283,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
where
|
where
|
||||||
k≢k' : ¬ k ≡ k'
|
k≢k' : ¬ k ≡ k'
|
||||||
k≢k' with ≡-dec-A k k'
|
k≢k' with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v₁∈xs₁))
|
... | yes k≡k' rewrite k≡k' = ⊥-elim (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v₁∈xs₁))
|
||||||
... | no k≢k' = k≢k'
|
... | no k≢k' = k≢k'
|
||||||
|
|
||||||
update : A → B → List (A × B) → List (A × B)
|
update : A → B → List (A × B) → List (A × B)
|
||||||
|
@ -383,7 +392,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v'
|
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v'
|
||||||
with ∈k-dec k' l₁
|
with ∈k-dec k' l₁
|
||||||
... | yes _ = here refl
|
... | yes _ = here refl
|
||||||
... | no k'∉kl₁ = absurd (k'∉kl₁ k∈kl₁)
|
... | no k'∉kl₁ = ⊥-elim (k'∉kl₁ k∈kl₁)
|
||||||
restrict-preserves-∈₂ {l₁ = l₁} {l₂ = (k' , v') ∷ xs} k∈kl₁ (there k,v∈xs)
|
restrict-preserves-∈₂ {l₁ = l₁} {l₂ = (k' , v') ∷ xs} k∈kl₁ (there k,v∈xs)
|
||||||
with ∈k-dec k' l₁
|
with ∈k-dec k' l₁
|
||||||
... | yes _ = there (restrict-preserves-∈₂ k∈kl₁ k,v∈xs)
|
... | yes _ = there (restrict-preserves-∈₂ k∈kl₁ k,v∈xs)
|
||||||
|
@ -394,7 +403,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
update-preserves-∈ {k} {k'} {v} {v'} {(k'' , v'') ∷ xs} k≢k' (here k,v≡k'',v'')
|
update-preserves-∈ {k} {k'} {v} {v'} {(k'' , v'') ∷ xs} k≢k' (here k,v≡k'',v'')
|
||||||
rewrite cong proj₁ k,v≡k'',v'' rewrite cong proj₂ k,v≡k'',v''
|
rewrite cong proj₁ k,v≡k'',v'' rewrite cong proj₂ k,v≡k'',v''
|
||||||
with ≡-dec-A k' k''
|
with ≡-dec-A k' k''
|
||||||
... | yes k'≡k'' = absurd (k≢k' (sym k'≡k''))
|
... | yes k'≡k'' = ⊥-elim (k≢k' (sym k'≡k''))
|
||||||
... | no _ = here refl
|
... | no _ = here refl
|
||||||
update-preserves-∈ {k} {k'} {v} {v'} {(k'' , v'') ∷ xs} k≢k' (there k,v∈xs)
|
update-preserves-∈ {k} {k'} {v} {v'} {(k'' , v'') ∷ xs} k≢k' (there k,v∈xs)
|
||||||
with ≡-dec-A k' k''
|
with ≡-dec-A k' k''
|
||||||
|
@ -413,10 +422,10 @@ private module ImplInsert (f : B → B → B) where
|
||||||
rewrite cong proj₁ k,v=k',v'' rewrite cong proj₂ k,v=k',v''
|
rewrite cong proj₁ k,v=k',v'' rewrite cong proj₂ k,v=k',v''
|
||||||
with ≡-dec-A k' k'
|
with ≡-dec-A k' k'
|
||||||
... | yes _ = here refl
|
... | yes _ = here refl
|
||||||
... | no k'≢k' = absurd (k'≢k' refl)
|
... | no k'≢k' = ⊥-elim (k'≢k' refl)
|
||||||
update-combines {k} {v} {v'} {(k' , v'') ∷ xs} (push k'≢xs uxs) (there k,v∈xs)
|
update-combines {k} {v} {v'} {(k' , v'') ∷ xs} (push k'≢xs uxs) (there k,v∈xs)
|
||||||
with ≡-dec-A k k'
|
with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v∈xs))
|
... | yes k≡k' rewrite k≡k' = ⊥-elim (All¬-¬Any k'≢xs (∈-cong proj₁ k,v∈xs))
|
||||||
... | no _ = there (update-combines uxs k,v∈xs)
|
... | no _ = there (update-combines uxs k,v∈xs)
|
||||||
|
|
||||||
updates-combine : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
updates-combine : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
||||||
|
@ -430,7 +439,7 @@ private module ImplInsert (f : B → B → B) where
|
||||||
where
|
where
|
||||||
k≢k' : ¬ k ≡ k'
|
k≢k' : ¬ k ≡ k'
|
||||||
k≢k' with ≡-dec-A k k'
|
k≢k' with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v₁∈xs))
|
... | yes k≡k' rewrite k≡k' = ⊥-elim (All¬-¬Any k'≢xs (∈-cong proj₁ k,v₁∈xs))
|
||||||
... | no k≢k' = k≢k'
|
... | no k≢k' = k≢k'
|
||||||
|
|
||||||
intersect-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
intersect-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
||||||
|
@ -452,400 +461,404 @@ _∈k_ k (kvs , _) = MemProp._∈_ k (keys kvs)
|
||||||
Map-functional : ∀ {k : A} {v v' : B} {m : Map} → (k , v) ∈ m → (k , v') ∈ m → v ≡ v'
|
Map-functional : ∀ {k : A} {v v' : B} {m : Map} → (k , v) ∈ m → (k , v') ∈ m → v ≡ v'
|
||||||
Map-functional {m = (l , ul)} k,v∈m k,v'∈m = ListAB-functional ul k,v∈m k,v'∈m
|
Map-functional {m = (l , ul)} k,v∈m k,v'∈m = ListAB-functional ul k,v∈m k,v'∈m
|
||||||
|
|
||||||
|
open ImplRelation renaming (subset to subset-impl)
|
||||||
|
|
||||||
|
_⊆_ : Map → Map → Set (a ⊔ℓ b)
|
||||||
|
_⊆_ (kvs₁ , _) (kvs₂ , _) = subset-impl kvs₁ kvs₂
|
||||||
|
|
||||||
|
⊆-refl : (m : Map) → m ⊆ m
|
||||||
|
⊆-refl _ k v k,v∈m = (v , (≈₂-refl , k,v∈m))
|
||||||
|
|
||||||
|
⊆-trans : (m₁ m₂ m₃ : Map) → m₁ ⊆ m₂ → m₂ ⊆ m₃ → m₁ ⊆ m₃
|
||||||
|
⊆-trans _ _ _ m₁⊆m₂ m₂⊆m₃ k v k,v∈m₁ =
|
||||||
|
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₃))
|
||||||
|
|
||||||
|
_≈_ : Map → Map → Set (a ⊔ℓ b)
|
||||||
|
_≈_ m₁ m₂ = m₁ ⊆ m₂ × m₂ ⊆ m₁
|
||||||
|
|
||||||
|
≈-equiv : IsEquivalence Map _≈_
|
||||||
|
≈-equiv = record
|
||||||
|
{ ≈-refl = λ {m} → (⊆-refl m , ⊆-refl m)
|
||||||
|
; ≈-sym = λ {m₁} {m₂} (m₁⊆m₂ , 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₁
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
data Expr : Set (a ⊔ℓ b) where
|
data Expr : Set (a ⊔ℓ b) where
|
||||||
`_ : Map → Expr
|
`_ : Map → Expr
|
||||||
_∪_ : Expr → Expr → Expr
|
_∪_ : Expr → Expr → Expr
|
||||||
_∩_ : Expr → Expr → Expr
|
_∩_ : Expr → Expr → Expr
|
||||||
|
|
||||||
module _ (f : B → B → B) where
|
open ImplInsert _⊔₂_ using (union-preserves-Unique) renaming (insert to insert-impl; union to union-impl)
|
||||||
open ImplInsert f renaming
|
open ImplInsert _⊓₂_ using (intersect-preserves-Unique) renaming (intersect to intersect-impl)
|
||||||
( insert to insert-impl
|
|
||||||
; union to union-impl
|
|
||||||
; intersect to intersect-impl
|
|
||||||
)
|
|
||||||
|
|
||||||
union : Map → Map → Map
|
_⊔_ : Map → Map → Map
|
||||||
union (kvs₁ , _) (kvs₂ , uks₂) = (union-impl kvs₁ kvs₂ , union-preserves-Unique kvs₁ kvs₂ uks₂)
|
_⊔_ (kvs₁ , _) (kvs₂ , uks₂) = (union-impl kvs₁ kvs₂ , union-preserves-Unique kvs₁ kvs₂ uks₂)
|
||||||
|
|
||||||
intersect : Map → Map → Map
|
_⊓_ : Map → Map → Map
|
||||||
intersect (kvs₁ , _) (kvs₂ , uks₂) = (intersect-impl kvs₁ kvs₂ , intersect-preserves-Unique {kvs₁} {kvs₂} uks₂)
|
_⊓_ (kvs₁ , _) (kvs₂ , uks₂) = (intersect-impl kvs₁ kvs₂ , intersect-preserves-Unique {kvs₁} {kvs₂} uks₂)
|
||||||
|
|
||||||
module _ (fUnion : B → B → B) (fIntersect : B → B → B) where
|
open ImplInsert _⊔₂_ using
|
||||||
open ImplInsert fUnion using
|
( union-combines
|
||||||
( union-combines
|
; union-preserves-∈₁
|
||||||
; union-preserves-∈₁
|
; union-preserves-∈₂
|
||||||
; union-preserves-∈₂
|
; union-preserves-∉
|
||||||
; union-preserves-∉
|
)
|
||||||
)
|
|
||||||
|
|
||||||
open ImplInsert fIntersect using
|
open ImplInsert _⊓₂_ using
|
||||||
( restrict-needs-both
|
( restrict-needs-both
|
||||||
; updates
|
; updates
|
||||||
; intersect-preserves-∉₁
|
; intersect-preserves-∉₁
|
||||||
; intersect-preserves-∉₂
|
; intersect-preserves-∉₂
|
||||||
; intersect-combines
|
; intersect-combines
|
||||||
)
|
)
|
||||||
|
|
||||||
⟦_⟧ : Expr -> Map
|
⟦_⟧ : Expr -> Map
|
||||||
⟦ ` m ⟧ = m
|
⟦ ` m ⟧ = m
|
||||||
⟦ e₁ ∪ e₂ ⟧ = union fUnion ⟦ e₁ ⟧ ⟦ e₂ ⟧
|
⟦ e₁ ∪ e₂ ⟧ = ⟦ e₁ ⟧ ⊔ ⟦ e₂ ⟧
|
||||||
⟦ e₁ ∩ e₂ ⟧ = intersect fIntersect ⟦ e₁ ⟧ ⟦ e₂ ⟧
|
⟦ e₁ ∩ e₂ ⟧ = ⟦ e₁ ⟧ ⊓ ⟦ e₂ ⟧
|
||||||
|
|
||||||
data Provenance (k : A) : B → Expr → Set (a ⊔ℓ b) where
|
data Provenance (k : A) : B → Expr → Set (a ⊔ℓ b) where
|
||||||
single : ∀ {v : B} {m : Map} → (k , v) ∈ m → Provenance k v (` m)
|
single : ∀ {v : B} {m : Map} → (k , v) ∈ m → Provenance k v (` m)
|
||||||
in₁ : ∀ {v : B} {e₁ e₂ : Expr} → Provenance k v e₁ → ¬ k ∈k ⟦ e₂ ⟧ → Provenance k v (e₁ ∪ e₂)
|
in₁ : ∀ {v : B} {e₁ e₂ : Expr} → Provenance k v e₁ → ¬ k ∈k ⟦ e₂ ⟧ → Provenance k v (e₁ ∪ e₂)
|
||||||
in₂ : ∀ {v : B} {e₁ e₂ : Expr} → ¬ k ∈k ⟦ e₁ ⟧ → Provenance k v e₂ → Provenance k v (e₁ ∪ e₂)
|
in₂ : ∀ {v : B} {e₁ e₂ : Expr} → ¬ k ∈k ⟦ e₁ ⟧ → Provenance k v e₂ → Provenance k v (e₁ ∪ e₂)
|
||||||
bothᵘ : ∀ {v₁ v₂ : B} {e₁ e₂ : Expr} → Provenance k v₁ e₁ → Provenance k v₂ e₂ → Provenance k (fUnion v₁ v₂) (e₁ ∪ e₂)
|
bothᵘ : ∀ {v₁ v₂ : B} {e₁ e₂ : Expr} → Provenance k v₁ e₁ → Provenance k v₂ e₂ → Provenance k (v₁ ⊔₂ v₂) (e₁ ∪ e₂)
|
||||||
bothⁱ : ∀ {v₁ v₂ : B} {e₁ e₂ : Expr} → Provenance k v₁ e₁ → Provenance k v₂ e₂ → Provenance k (fIntersect v₁ v₂) (e₁ ∩ e₂)
|
bothⁱ : ∀ {v₁ v₂ : B} {e₁ e₂ : Expr} → Provenance k v₁ e₁ → Provenance k v₂ e₂ → Provenance k (v₁ ⊓₂ v₂) (e₁ ∩ e₂)
|
||||||
|
|
||||||
Expr-Provenance : ∀ (k : A) (e : Expr) → k ∈k ⟦ e ⟧ → Σ B (λ v → (Provenance k v e × (k , v) ∈ ⟦ e ⟧))
|
Expr-Provenance : ∀ (k : A) (e : Expr) → k ∈k ⟦ e ⟧ → Σ B (λ v → (Provenance k v e × (k , v) ∈ ⟦ e ⟧))
|
||||||
Expr-Provenance k (` m) k∈km = let (v , k,v∈m) = locate k∈km in (v , (single k,v∈m , k,v∈m))
|
Expr-Provenance k (` m) k∈km = let (v , k,v∈m) = locate k∈km in (v , (single k,v∈m , k,v∈m))
|
||||||
Expr-Provenance k (e₁ ∪ e₂) k∈ke₁e₂
|
Expr-Provenance k (e₁ ∪ e₂) k∈ke₁e₂
|
||||||
with ∈k-dec k (proj₁ ⟦ e₁ ⟧) | ∈k-dec k (proj₁ ⟦ e₂ ⟧)
|
with ∈k-dec k (proj₁ ⟦ e₁ ⟧) | ∈k-dec k (proj₁ ⟦ e₂ ⟧)
|
||||||
... | yes k∈ke₁ | yes k∈ke₂ =
|
... | yes k∈ke₁ | yes k∈ke₂ =
|
||||||
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
||||||
(v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
(v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
||||||
in (fUnion v₁ v₂ , (bothᵘ g₁ g₂ , union-combines (proj₂ ⟦ e₁ ⟧) (proj₂ ⟦ e₂ ⟧) k,v₁∈e₁ k,v₂∈e₂))
|
in (v₁ ⊔₂ v₂ , (bothᵘ g₁ g₂ , union-combines (proj₂ ⟦ e₁ ⟧) (proj₂ ⟦ e₂ ⟧) k,v₁∈e₁ k,v₂∈e₂))
|
||||||
... | yes k∈ke₁ | no k∉ke₂ =
|
... | yes k∈ke₁ | no k∉ke₂ =
|
||||||
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
||||||
in (v₁ , (in₁ g₁ k∉ke₂ , union-preserves-∈₁ (proj₂ ⟦ e₁ ⟧) k,v₁∈e₁ k∉ke₂))
|
in (v₁ , (in₁ g₁ k∉ke₂ , union-preserves-∈₁ (proj₂ ⟦ e₁ ⟧) k,v₁∈e₁ k∉ke₂))
|
||||||
... | no k∉ke₁ | yes k∈ke₂ =
|
... | no k∉ke₁ | yes k∈ke₂ =
|
||||||
let (v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
let (v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
||||||
in (v₂ , (in₂ k∉ke₁ g₂ , union-preserves-∈₂ k∉ke₁ k,v₂∈e₂))
|
in (v₂ , (in₂ k∉ke₁ g₂ , union-preserves-∈₂ k∉ke₁ k,v₂∈e₂))
|
||||||
... | no k∉ke₁ | no k∉ke₂ = absurd (union-preserves-∉ k∉ke₁ k∉ke₂ k∈ke₁e₂)
|
... | no k∉ke₁ | no k∉ke₂ = ⊥-elim (union-preserves-∉ k∉ke₁ k∉ke₂ k∈ke₁e₂)
|
||||||
Expr-Provenance k (e₁ ∩ e₂) k∈ke₁e₂
|
Expr-Provenance k (e₁ ∩ e₂) k∈ke₁e₂
|
||||||
with ∈k-dec k (proj₁ ⟦ e₁ ⟧) | ∈k-dec k (proj₁ ⟦ e₂ ⟧)
|
with ∈k-dec k (proj₁ ⟦ e₁ ⟧) | ∈k-dec k (proj₁ ⟦ e₂ ⟧)
|
||||||
... | yes k∈ke₁ | yes k∈ke₂ =
|
... | yes k∈ke₁ | yes k∈ke₂ =
|
||||||
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
let (v₁ , (g₁ , k,v₁∈e₁)) = Expr-Provenance k e₁ k∈ke₁
|
||||||
(v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
(v₂ , (g₂ , k,v₂∈e₂)) = Expr-Provenance k e₂ k∈ke₂
|
||||||
in (fIntersect v₁ v₂ , (bothⁱ g₁ g₂ , intersect-combines (proj₂ ⟦ e₁ ⟧) (proj₂ ⟦ e₂ ⟧) k,v₁∈e₁ k,v₂∈e₂))
|
in (v₁ ⊓₂ v₂ , (bothⁱ g₁ g₂ , intersect-combines (proj₂ ⟦ e₁ ⟧) (proj₂ ⟦ e₂ ⟧) k,v₁∈e₁ k,v₂∈e₂))
|
||||||
... | yes k∈ke₁ | no k∉ke₂ = absurd (intersect-preserves-∉₂ {l₁ = proj₁ ⟦ e₁ ⟧} k∉ke₂ k∈ke₁e₂)
|
... | yes k∈ke₁ | no k∉ke₂ = ⊥-elim (intersect-preserves-∉₂ {l₁ = proj₁ ⟦ e₁ ⟧} k∉ke₂ k∈ke₁e₂)
|
||||||
... | no k∉ke₁ | yes k∈ke₂ = absurd (intersect-preserves-∉₁ {l₂ = proj₁ ⟦ e₂ ⟧} k∉ke₁ k∈ke₁e₂)
|
... | no k∉ke₁ | yes k∈ke₂ = ⊥-elim (intersect-preserves-∉₁ {l₂ = proj₁ ⟦ e₂ ⟧} k∉ke₁ k∈ke₁e₂)
|
||||||
... | no k∉ke₁ | no k∉ke₂ = absurd (intersect-preserves-∉₂ {l₁ = proj₁ ⟦ e₁ ⟧} k∉ke₂ k∈ke₁e₂)
|
... | no k∉ke₁ | no k∉ke₂ = ⊥-elim (intersect-preserves-∉₂ {l₁ = proj₁ ⟦ e₁ ⟧} k∉ke₂ k∈ke₁e₂)
|
||||||
|
|
||||||
|
data SubsetInfo (m₁ m₂ : Map) : Set (a ⊔ℓ b) where
|
||||||
|
extra : (k : A) → k ∈k m₁ → ¬ k ∈k m₂ → SubsetInfo m₁ m₂
|
||||||
|
mismatch : (k : A) (v₁ v₂ : B) → (k , v₁) ∈ m₁ → (k , v₂) ∈ m₂ → ¬ v₁ ≈₂ v₂ → SubsetInfo m₁ m₂
|
||||||
|
fine : m₁ ⊆ m₂ → SubsetInfo m₁ m₂
|
||||||
|
|
||||||
module _ (_≈_ : B → B → Set b) where
|
SubsetInfo-to-dec : ∀ {m₁ m₂ : Map} → SubsetInfo m₁ m₂ → Dec (m₁ ⊆ m₂)
|
||||||
open ImplRelation _≈_ renaming (subset to subset-impl)
|
SubsetInfo-to-dec (extra k k∈km₁ k∉km₂) =
|
||||||
|
let (v , k,v∈m₁) = locate k∈km₁
|
||||||
|
in no (λ m₁⊆m₂ →
|
||||||
|
let (v' , (_ , k,v'∈m₂)) = m₁⊆m₂ k v k,v∈m₁
|
||||||
|
in k∉km₂ (∈-cong proj₁ k,v'∈m₂))
|
||||||
|
SubsetInfo-to-dec {m₁} {m₂} (mismatch k v₁ v₂ k,v₁∈m₁ k,v₂∈m₂ v₁̷≈v₂) =
|
||||||
|
no (λ m₁⊆m₂ →
|
||||||
|
let (v' , (v₁≈v' , k,v'∈m₂)) = m₁⊆m₂ k v₁ k,v₁∈m₁
|
||||||
|
in v₁̷≈v₂ (subst (λ v'' → v₁ ≈₂ v'') (Map-functional {k} {v'} {v₂} {m₂} k,v'∈m₂ k,v₂∈m₂) v₁≈v')) -- for some reason, can't just use subst...
|
||||||
|
SubsetInfo-to-dec (fine m₁⊆m₂) = yes m₁⊆m₂
|
||||||
|
|
||||||
subset : Map → Map → Set (a ⊔ℓ b)
|
module _ (≈₂-dec : ∀ (b₁ b₂ : B) → Dec (b₁ ≈₂ b₂)) where
|
||||||
subset (kvs₁ , _) (kvs₂ , _) = subset-impl kvs₁ kvs₂
|
compute-SubsetInfo : ∀ m₁ m₂ → SubsetInfo m₁ m₂
|
||||||
|
compute-SubsetInfo ([] , _) m₂ = fine (λ k v ())
|
||||||
|
compute-SubsetInfo m₁@((k , v) ∷ xs₁ , push k≢xs₁ uxs₁) m₂@(l₂ , u₂)
|
||||||
|
with compute-SubsetInfo (xs₁ , uxs₁) m₂
|
||||||
|
... | extra k' k'∈kxs₁ k'∉km₂ = extra k' (there k'∈kxs₁) k'∉km₂
|
||||||
|
... | mismatch k' v₁ v₂ k',v₁∈xs₁ k',v₂∈m₂ v₁̷≈v₂ =
|
||||||
|
mismatch k' v₁ v₂ (there k',v₁∈xs₁) k',v₂∈m₂ v₁̷≈v₂
|
||||||
|
... | fine xs₁⊆m₂ with ∈k-dec k l₂
|
||||||
|
... | no k∉km₂ = extra k (here refl) k∉km₂
|
||||||
|
... | yes k∈km₂ with locate k∈km₂
|
||||||
|
... | (v' , k,v'∈m₂) with ≈₂-dec v v'
|
||||||
|
... | no v̷≈v' = mismatch k v v' (here refl) (k,v'∈m₂) v̷≈v'
|
||||||
|
... | yes v≈v' = fine m₁⊆m₂
|
||||||
|
where
|
||||||
|
m₁⊆m₂ : m₁ ⊆ m₂
|
||||||
|
m₁⊆m₂ k' v'' (here k,v≡k',v'')
|
||||||
|
rewrite cong proj₁ k,v≡k',v''
|
||||||
|
rewrite cong proj₂ k,v≡k',v'' =
|
||||||
|
(v' , (v≈v' , k,v'∈m₂))
|
||||||
|
m₁⊆m₂ k' v'' (there k,v≡k',v'') =
|
||||||
|
xs₁⊆m₂ k' v'' k,v≡k',v''
|
||||||
|
|
||||||
lift : Map → Map → Set (a ⊔ℓ b)
|
⊆-dec : ∀ m₁ m₂ → Dec (m₁ ⊆ m₂)
|
||||||
lift m₁ m₂ = subset m₁ m₂ × subset m₂ m₁
|
⊆-dec m₁ m₂ = SubsetInfo-to-dec (compute-SubsetInfo m₁ m₂)
|
||||||
|
|
||||||
private
|
≈-dec : ∀ m₁ m₂ → Dec (m₁ ≈ m₂)
|
||||||
data SubsetInfo (m₁ m₂ : Map) : Set (a ⊔ℓ b) where
|
≈-dec m₁ m₂
|
||||||
extra : (k : A) → k ∈k m₁ → ¬ k ∈k m₂ → SubsetInfo m₁ m₂
|
with ⊆-dec m₁ m₂ | ⊆-dec m₂ m₁
|
||||||
mismatch : (k : A) (v₁ v₂ : B) → (k , v₁) ∈ m₁ → (k , v₂) ∈ m₂ → ¬ v₁ ≈ v₂ → SubsetInfo m₁ m₂
|
... | yes m₁⊆m₂ | yes m₂⊆m₁ = yes (m₁⊆m₂ , m₂⊆m₁)
|
||||||
fine : subset m₁ m₂ → SubsetInfo m₁ m₂
|
... | _ | no m₂̷⊆m₁ = no (λ (_ , m₂⊆m₁) → m₂̷⊆m₁ m₂⊆m₁)
|
||||||
|
... | no m₁̷⊆m₂ | _ = no (λ (m₁⊆m₂ , _) → m₁̷⊆m₂ m₁⊆m₂)
|
||||||
|
|
||||||
SubsetInfo-to-dec : ∀ {m₁ m₂ : Map} → SubsetInfo m₁ m₂ → Dec (subset m₁ m₂)
|
private module I⊔ = ImplInsert _⊔₂_
|
||||||
SubsetInfo-to-dec (extra k k∈km₁ k∉km₂) =
|
private module I⊓ = ImplInsert _⊓₂_
|
||||||
let (v , k,v∈m₁) = locate k∈km₁
|
|
||||||
in no (λ m₁⊆m₂ →
|
|
||||||
let (v' , (_ , k,v'∈m₂)) = m₁⊆m₂ k v k,v∈m₁
|
|
||||||
in k∉km₂ (∈-cong proj₁ k,v'∈m₂))
|
|
||||||
SubsetInfo-to-dec {m₁} {m₂} (mismatch k v₁ v₂ k,v₁∈m₁ k,v₂∈m₂ v₁̷≈v₂) =
|
|
||||||
no (λ m₁⊆m₂ →
|
|
||||||
let (v' , (v₁≈v' , k,v'∈m₂)) = m₁⊆m₂ k v₁ k,v₁∈m₁
|
|
||||||
in v₁̷≈v₂ (subst (λ v'' → v₁ ≈ v'') (Map-functional {k} {v'} {v₂} {m₂} k,v'∈m₂ k,v₂∈m₂) v₁≈v')) -- for some reason, can't just use subst...
|
|
||||||
SubsetInfo-to-dec (fine m₁⊆m₂) = yes m₁⊆m₂
|
|
||||||
|
|
||||||
|
≈-⊔-cong : ∀ {m₁ m₂ m₃ m₄ : Map} → m₁ ≈ m₂ → m₃ ≈ m₄ → (m₁ ⊔ m₃) ≈ (m₂ ⊔ m₄)
|
||||||
|
≈-⊔-cong {m₁} {m₂} {m₃} {m₄} (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃) =
|
||||||
|
( ⊔-⊆ m₁ m₂ m₃ m₄ (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃)
|
||||||
|
, ⊔-⊆ m₂ m₁ m₄ m₃ (m₂⊆m₁ , m₁⊆m₂) (m₄⊆m₃ , m₃⊆m₄)
|
||||||
|
)
|
||||||
|
where
|
||||||
|
≈-∉-cong : ∀ {m₁ m₂ : Map} {k : A} → m₁ ≈ m₂ → ¬ k ∈k m₁ → ¬ k ∈k m₂
|
||||||
|
≈-∉-cong (m₁⊆m₂ , m₂⊆m₁) k∉km₁ k∈km₂ =
|
||||||
|
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
||||||
|
(_ , (_ , k,v₁∈m₁)) = m₂⊆m₁ _ v₂ k,v₂∈m₂
|
||||||
|
in k∉km₁ (∈-cong proj₁ k,v₁∈m₁)
|
||||||
|
|
||||||
module _ (≈-dec : ∀ (b₁ b₂ : B) → Dec (b₁ ≈ b₂)) where
|
⊔-⊆ : ∀ (m₁ m₂ m₃ m₄ : Map) → m₁ ≈ m₂ → m₃ ≈ m₄ → (m₁ ⊔ m₃) ⊆ (m₂ ⊔ m₄)
|
||||||
private
|
⊔-⊆ m₁ m₂ m₃ m₄ m₁≈m₂ m₃≈m₄ k v k,v∈m₁m₃
|
||||||
compute-SubsetInfo : ∀ m₁ m₂ → SubsetInfo m₁ m₂
|
with Expr-Provenance k ((` m₁) ∪ (` m₃)) (∈-cong proj₁ k,v∈m₁m₃)
|
||||||
compute-SubsetInfo ([] , _) m₂ = fine (λ k v ())
|
... | (_ , (bothᵘ (single {v₁} v₁∈m₁) (single {v₃} v₃∈m₃) , v₁v₃∈m₁m₃))
|
||||||
compute-SubsetInfo m₁@((k , v) ∷ xs₁ , push k≢xs₁ uxs₁) m₂@(l₂ , u₂)
|
rewrite Map-functional {m = m₁ ⊔ m₃} k,v∈m₁m₃ v₁v₃∈m₁m₃ =
|
||||||
with compute-SubsetInfo (xs₁ , uxs₁) m₂
|
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
||||||
... | extra k' k'∈kxs₁ k'∉km₂ = extra k' (there k'∈kxs₁) k'∉km₂
|
(v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
||||||
... | mismatch k' v₁ v₂ k',v₁∈xs₁ k',v₂∈m₂ v₁̷≈v₂ =
|
in (v₂ ⊔₂ v₄ , (≈₂-⊔₂-cong v₁≈v₂ v₃≈v₄ , I⊔.union-combines (proj₂ m₂) (proj₂ m₄) k,v₂∈m₂ k,v₄∈m₄))
|
||||||
mismatch k' v₁ v₂ (there k',v₁∈xs₁) k',v₂∈m₂ v₁̷≈v₂
|
... | (_ , (in₁ (single {v₁} v₁∈m₁) k∉km₃ , v₁∈m₁m₃))
|
||||||
... | fine xs₁⊆m₂ with ∈k-dec k l₂
|
rewrite Map-functional {m = m₁ ⊔ m₃} k,v∈m₁m₃ v₁∈m₁m₃ =
|
||||||
... | no k∉km₂ = extra k (here refl) k∉km₂
|
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
||||||
... | yes k∈km₂ with locate k∈km₂
|
k∉km₄ = ≈-∉-cong {m₃} {m₄} m₃≈m₄ k∉km₃
|
||||||
... | (v' , k,v'∈m₂) with ≈-dec v v'
|
in (v₂ , (v₁≈v₂ , I⊔.union-preserves-∈₁ (proj₂ m₂) k,v₂∈m₂ k∉km₄))
|
||||||
... | no v̷≈v' = mismatch k v v' (here refl) (k,v'∈m₂) v̷≈v'
|
... | (_ , (in₂ k∉km₁ (single {v₃} v₃∈m₃) , v₃∈m₁m₃))
|
||||||
... | yes v≈v' = fine m₁⊆m₂
|
rewrite Map-functional {m = m₁ ⊔ m₃} k,v∈m₁m₃ v₃∈m₁m₃ =
|
||||||
where
|
let (v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
||||||
m₁⊆m₂ : subset m₁ m₂
|
k∉km₂ = ≈-∉-cong {m₁} {m₂} m₁≈m₂ k∉km₁
|
||||||
m₁⊆m₂ k' v'' (here k,v≡k',v'')
|
in (v₄ , (v₃≈v₄ , I⊔.union-preserves-∈₂ k∉km₂ k,v₄∈m₄))
|
||||||
rewrite cong proj₁ k,v≡k',v''
|
|
||||||
rewrite cong proj₂ k,v≡k',v'' =
|
|
||||||
(v' , (v≈v' , k,v'∈m₂))
|
|
||||||
m₁⊆m₂ k' v'' (there k,v≡k',v'') =
|
|
||||||
xs₁⊆m₂ k' v'' k,v≡k',v''
|
|
||||||
|
|
||||||
subset-dec : ∀ m₁ m₂ → Dec (subset m₁ m₂)
|
≈-⊓-cong : ∀ {m₁ m₂ m₃ m₄ : Map} → m₁ ≈ m₂ → m₃ ≈ m₄ → (m₁ ⊓ m₃) ≈ (m₂ ⊓ m₄)
|
||||||
subset-dec m₁ m₂ = SubsetInfo-to-dec (compute-SubsetInfo m₁ m₂)
|
≈-⊓-cong {m₁} {m₂} {m₃} {m₄} (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃) =
|
||||||
|
( ⊓-⊆ m₁ m₂ m₃ m₄ (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃)
|
||||||
|
, ⊓-⊆ m₂ m₁ m₄ m₃ (m₂⊆m₁ , m₁⊆m₂) (m₄⊆m₃ , m₃⊆m₄)
|
||||||
|
)
|
||||||
|
where
|
||||||
|
⊓-⊆ : ∀ (m₁ m₂ m₃ m₄ : Map) → m₁ ≈ m₂ → m₃ ≈ m₄ → (m₁ ⊓ m₃) ⊆ (m₂ ⊓ m₄)
|
||||||
|
⊓-⊆ m₁ m₂ m₃ m₄ m₁≈m₂ m₃≈m₄ k v k,v∈m₁m₃
|
||||||
|
with Expr-Provenance k ((` m₁) ∩ (` m₃)) (∈-cong proj₁ k,v∈m₁m₃)
|
||||||
|
... | (_ , (bothⁱ (single {v₁} v₁∈m₁) (single {v₃} v₃∈m₃) , v₁v₃∈m₁m₃))
|
||||||
|
rewrite Map-functional {m = m₁ ⊓ m₃} k,v∈m₁m₃ v₁v₃∈m₁m₃ =
|
||||||
|
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
||||||
|
(v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
||||||
|
in (v₂ ⊓₂ v₄ , (≈₂-⊓₂-cong v₁≈v₂ v₃≈v₄ , I⊓.intersect-combines (proj₂ m₂) (proj₂ m₄) k,v₂∈m₂ k,v₄∈m₄))
|
||||||
|
|
||||||
lift-dec : ∀ m₁ m₂ → Dec (lift m₁ m₂)
|
⊔-idemp : ∀ (m : Map) → (m ⊔ m) ≈ m
|
||||||
lift-dec m₁ m₂
|
⊔-idemp m@(l , u) = (mm-m-⊆ , m-mm-⊆)
|
||||||
with subset-dec m₁ m₂ | subset-dec m₂ m₁
|
where
|
||||||
... | yes m₁⊆m₂ | yes m₂⊆m₁ = yes (m₁⊆m₂ , m₂⊆m₁)
|
mm-m-⊆ : (m ⊔ m) ⊆ m
|
||||||
... | _ | no m₂̷⊆m₁ = no (λ (_ , m₂⊆m₁) → m₂̷⊆m₁ m₂⊆m₁)
|
mm-m-⊆ k v k,v∈mm
|
||||||
... | no m₁̷⊆m₂ | _ = no (λ (m₁⊆m₂ , _) → m₁̷⊆m₂ m₁⊆m₂)
|
with Expr-Provenance k ((` m) ∪ (` m)) (∈-cong proj₁ k,v∈mm)
|
||||||
|
... | (_ , (bothᵘ (single {v'} v'∈m) (single {v''} v''∈m) , v'v''∈mm))
|
||||||
|
rewrite Map-functional {m = m} v'∈m v''∈m
|
||||||
|
rewrite Map-functional {m = m ⊔ m} k,v∈mm v'v''∈mm =
|
||||||
|
(v'' , (⊔₂-idemp v'' , v''∈m))
|
||||||
|
... | (_ , (in₁ (single {v'} v'∈m) k∉km , _)) = ⊥-elim (k∉km (∈-cong proj₁ v'∈m))
|
||||||
|
... | (_ , (in₂ k∉km (single {v''} v''∈m) , _)) = ⊥-elim (k∉km (∈-cong proj₁ v''∈m))
|
||||||
|
|
||||||
-- The Provenance type requires both union and intersection functions,
|
m-mm-⊆ : m ⊆ (m ⊔ m)
|
||||||
-- but sometimes here we're working with one operation only. Just use the
|
m-mm-⊆ k v k,v∈m = (v ⊔₂ v , (≈₂-sym (⊔₂-idemp v) , I⊔.union-combines u u k,v∈m k,v∈m))
|
||||||
-- union/intersection function for both -- it doesn't matter, since we don't
|
|
||||||
-- use the dual operations in these proofs.
|
|
||||||
|
|
||||||
module _ (f : B → B → B)
|
⊔-comm : ∀ (m₁ m₂ : Map) → (m₁ ⊔ m₂) ≈ (m₂ ⊔ m₁)
|
||||||
(≈-f-cong : ∀ {b₁ b₂ b₃ b₄} → b₁ ≈ b₂ → b₃ ≈ b₄ → f b₁ b₃ ≈ f b₂ b₄) where
|
⊔-comm m₁ m₂ = (⊔-comm-⊆ m₁ m₂ , ⊔-comm-⊆ m₂ m₁)
|
||||||
private module I = ImplInsert f
|
where
|
||||||
|
⊔-comm-⊆ : ∀ (m₁ m₂ : Map) → (m₁ ⊔ m₂) ⊆ (m₂ ⊔ m₁)
|
||||||
|
⊔-comm-⊆ m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
||||||
|
with Expr-Provenance k ((` m₁) ∪ (` m₂)) (∈-cong proj₁ k,v∈m₁m₂)
|
||||||
|
... | (_ , (bothᵘ {v₁} {v₂} (single v₁∈m₁) (single v₂∈m₂) , v₁v₂∈m₁m₂))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
||||||
|
(v₂ ⊔₂ v₁ , (⊔₂-comm v₁ v₂ , I⊔.union-combines u₂ u₁ v₂∈m₂ v₁∈m₁))
|
||||||
|
... | (_ , (in₁ {v₁} (single v₁∈m₁) k∉km₂ , v₁∈m₁m₂))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ m₂} k,v∈m₁m₂ v₁∈m₁m₂ =
|
||||||
|
(v₁ , (≈₂-refl , I⊔.union-preserves-∈₂ k∉km₂ v₁∈m₁))
|
||||||
|
... | (_ , (in₂ {v₂} k∉km₁ (single v₂∈m₂) , v₂∈m₁m₂))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ m₂} k,v∈m₁m₂ v₂∈m₁m₂ =
|
||||||
|
(v₂ , (≈₂-refl , I⊔.union-preserves-∈₁ u₂ v₂∈m₂ k∉km₁))
|
||||||
|
|
||||||
union-cong : ∀ {m₁ m₂ m₃ m₄ : Map} → lift m₁ m₂ → lift m₃ m₄ → lift (union f m₁ m₃) (union f m₂ m₄)
|
⊔-assoc : ∀ (m₁ m₂ m₃ : Map) → ((m₁ ⊔ m₂) ⊔ m₃) ≈ (m₁ ⊔ (m₂ ⊔ m₃))
|
||||||
union-cong {m₁} {m₂} {m₃} {m₄} (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃) =
|
⊔-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (⊔-assoc₁ , ⊔-assoc₂)
|
||||||
( union-subset m₁ m₂ m₃ m₄ (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃)
|
where
|
||||||
, union-subset m₂ m₁ m₄ m₃ (m₂⊆m₁ , m₁⊆m₂) (m₄⊆m₃ , m₃⊆m₄)
|
⊔-assoc₁ : ((m₁ ⊔ m₂) ⊔ m₃) ⊆ (m₁ ⊔ (m₂ ⊔ m₃))
|
||||||
)
|
⊔-assoc₁ k v k,v∈m₁₂m₃
|
||||||
where
|
with Expr-Provenance k (((` m₁) ∪ (` m₂)) ∪ (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃)
|
||||||
≈-∉-cong : ∀ {m₁ m₂ : Map} {k : A} → lift m₁ m₂ → ¬ k ∈k m₁ → ¬ k ∈k m₂
|
... | (_ , (in₂ k∉ke₁₂ (single {v₃} v₃∈e₃) , v₃∈m₁₂m₃))
|
||||||
≈-∉-cong (m₁⊆m₂ , m₂⊆m₁) k∉km₁ k∈km₂ =
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₃∈m₁₂m₃ =
|
||||||
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
let (k∉ke₁ , k∉ke₂) = I⊔.∉-union-∉-either {l₁ = l₁} {l₂ = l₂} k∉ke₁₂
|
||||||
(_ , (_ , k,v₁∈m₁)) = m₂⊆m₁ _ v₂ k,v₂∈m₂
|
in (v₃ , (≈₂-refl , I⊔.union-preserves-∈₂ k∉ke₁ (I⊔.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
|
||||||
in k∉km₁ (∈-cong proj₁ k,v₁∈m₁)
|
... | (_ , (in₁ (in₂ k∉ke₁ (single {v₂} v₂∈e₂)) k∉ke₃ , v₂∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₂∈m₁₂m₃ =
|
||||||
|
(v₂ , (≈₂-refl , I⊔.union-preserves-∈₂ k∉ke₁ (I⊔.union-preserves-∈₁ u₂ v₂∈e₂ k∉ke₃)))
|
||||||
|
... | (_ , (bothᵘ (in₂ k∉ke₁ (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₂v₃∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₂v₃∈m₁₂m₃ =
|
||||||
|
(v₂ ⊔₂ v₃ , (≈₂-refl , I⊔.union-preserves-∈₂ k∉ke₁ (I⊔.union-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
||||||
|
... | (_ , (in₁ (in₁ (single {v₁} v₁∈e₁) k∉ke₂) k∉ke₃ , v₁∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₁∈m₁₂m₃ =
|
||||||
|
(v₁ , (≈₂-refl , I⊔.union-preserves-∈₁ u₁ v₁∈e₁ (I⊔.union-preserves-∉ k∉ke₂ k∉ke₃)))
|
||||||
|
... | (_ , (bothᵘ (in₁ (single {v₁} v₁∈e₁) k∉ke₂) (single {v₃} v₃∈e₃) , v₁v₃∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₁v₃∈m₁₂m₃ =
|
||||||
|
(v₁ ⊔₂ v₃ , (≈₂-refl , I⊔.union-combines u₁ (I⊔.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I⊔.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
|
||||||
|
... | (_ , (in₁ (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) k∉ke₃), v₁v₂∈m₁₂m₃)
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₁v₂∈m₁₂m₃ =
|
||||||
|
(v₁ ⊔₂ v₂ , (≈₂-refl , I⊔.union-combines u₁ (I⊔.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I⊔.union-preserves-∈₁ u₂ v₂∈e₂ k∉ke₃)))
|
||||||
|
... | (_ , (bothᵘ (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₁v₂v₃∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊔ m₂) ⊔ m₃} k,v∈m₁₂m₃ v₁v₂v₃∈m₁₂m₃ =
|
||||||
|
(v₁ ⊔₂ (v₂ ⊔₂ v₃) , (⊔₂-assoc v₁ v₂ v₃ , I⊔.union-combines u₁ (I⊔.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I⊔.union-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
||||||
|
|
||||||
union-subset : ∀ (m₁ m₂ m₃ m₄ : Map) → lift m₁ m₂ → lift m₃ m₄ → subset (union f m₁ m₃) (union f m₂ m₄)
|
⊔-assoc₂ : (m₁ ⊔ (m₂ ⊔ m₃)) ⊆ ((m₁ ⊔ m₂) ⊔ m₃)
|
||||||
union-subset m₁ m₂ m₃ m₄ m₁≈m₂ m₃≈m₄ k v k,v∈m₁m₃
|
⊔-assoc₂ k v k,v∈m₁m₂₃
|
||||||
with Expr-Provenance f f k ((` m₁) ∪ (` m₃)) (∈-cong proj₁ k,v∈m₁m₃)
|
with Expr-Provenance k ((` m₁) ∪ ((` m₂) ∪ (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
|
||||||
... | (_ , (bothᵘ (single {v₁} v₁∈m₁) (single {v₃} v₃∈m₃) , v₁v₃∈m₁m₃))
|
... | (_ , (in₂ k∉ke₁ (in₂ k∉ke₂ (single {v₃} v₃∈e₃)) , v₃∈m₁m₂₃))
|
||||||
rewrite Map-functional {m = union f m₁ m₃} k,v∈m₁m₃ v₁v₃∈m₁m₃ =
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₃∈m₁m₂₃ =
|
||||||
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
(v₃ , (≈₂-refl , I⊔.union-preserves-∈₂ (I⊔.union-preserves-∉ k∉ke₁ k∉ke₂) v₃∈e₃))
|
||||||
(v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
... | (_ , (in₂ k∉ke₁ (in₁ (single {v₂} v₂∈e₂) k∉ke₃) , v₂∈m₁m₂₃))
|
||||||
in (f v₂ v₄ , (≈-f-cong v₁≈v₂ v₃≈v₄ , I.union-combines (proj₂ m₂) (proj₂ m₄) k,v₂∈m₂ k,v₄∈m₄))
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₂∈m₁m₂₃ =
|
||||||
... | (_ , (in₁ (single {v₁} v₁∈m₁) k∉km₃ , v₁∈m₁m₃))
|
(v₂ , (≈₂-refl , I⊔.union-preserves-∈₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) (I⊔.union-preserves-∈₂ k∉ke₁ v₂∈e₂) k∉ke₃))
|
||||||
rewrite Map-functional {m = union f m₁ m₃} k,v∈m₁m₃ v₁∈m₁m₃ =
|
... | (_ , (in₂ k∉ke₁ (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₂v₃∈m₁m₂₃))
|
||||||
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₂v₃∈m₁m₂₃ =
|
||||||
k∉km₄ = ≈-∉-cong {m₃} {m₄} m₃≈m₄ k∉km₃
|
(v₂ ⊔₂ v₃ , (≈₂-refl , I⊔.union-combines (I⊔.union-preserves-Unique l₁ l₂ u₂) u₃ (I⊔.union-preserves-∈₂ k∉ke₁ v₂∈e₂) v₃∈e₃))
|
||||||
in (v₂ , (v₁≈v₂ , I.union-preserves-∈₁ (proj₂ m₂) k,v₂∈m₂ k∉km₄))
|
... | (_ , (in₁ (single {v₁} v₁∈e₁) k∉ke₂₃ , v₁∈m₁m₂₃))
|
||||||
... | (_ , (in₂ k∉km₁ (single {v₃} v₃∈m₃) , v₃∈m₁m₃))
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₁∈m₁m₂₃ =
|
||||||
rewrite Map-functional {m = union f m₁ m₃} k,v∈m₁m₃ v₃∈m₁m₃ =
|
let (k∉ke₂ , k∉ke₃) = I⊔.∉-union-∉-either {l₁ = l₂} {l₂ = l₃} k∉ke₂₃
|
||||||
let (v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
in (v₁ , (≈₂-refl , I⊔.union-preserves-∈₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) (I⊔.union-preserves-∈₁ u₁ v₁∈e₁ k∉ke₂) k∉ke₃))
|
||||||
k∉km₂ = ≈-∉-cong {m₁} {m₂} m₁≈m₂ k∉km₁
|
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in₂ k∉ke₂ (single {v₃} v₃∈e₃)) , v₁v₃∈m₁m₂₃))
|
||||||
in (v₄ , (v₃≈v₄ , I.union-preserves-∈₂ k∉km₂ k,v₄∈m₄))
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₁v₃∈m₁m₂₃ =
|
||||||
|
(v₁ ⊔₂ v₃ , (≈₂-refl , I⊔.union-combines (I⊔.union-preserves-Unique l₁ l₂ u₂) u₃ (I⊔.union-preserves-∈₁ u₁ v₁∈e₁ k∉ke₂) v₃∈e₃))
|
||||||
|
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in₁ (single {v₂} v₂∈e₂) k∉ke₃) , v₁v₂∈m₁m₂₃))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₁v₂∈m₁m₂₃ =
|
||||||
|
(v₁ ⊔₂ v₂ , (≈₂-refl , I⊔.union-preserves-∈₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) (I⊔.union-combines u₁ u₂ v₁∈e₁ v₂∈e₂) k∉ke₃))
|
||||||
|
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ (m₂ ⊔ m₃)} k,v∈m₁m₂₃ v₁v₂v₃∈m₁m₂₃ =
|
||||||
|
((v₁ ⊔₂ v₂) ⊔₂ v₃ , (≈₂-sym (⊔₂-assoc v₁ v₂ v₃) , I⊔.union-combines (I⊔.union-preserves-Unique l₁ l₂ u₂) u₃ (I⊔.union-combines u₁ u₂ v₁∈e₁ v₂∈e₂) v₃∈e₃))
|
||||||
|
|
||||||
intersect-cong : ∀ {m₁ m₂ m₃ m₄ : Map} → lift m₁ m₂ → lift m₃ m₄ → lift (intersect f m₁ m₃) (intersect f m₂ m₄)
|
⊓-idemp : ∀ (m : Map) → (m ⊓ m) ≈ m
|
||||||
intersect-cong {m₁} {m₂} {m₃} {m₄} (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃) =
|
⊓-idemp m@(l , u) = (mm-m-⊆ , m-mm-⊆)
|
||||||
( intersect-subset m₁ m₂ m₃ m₄ (m₁⊆m₂ , m₂⊆m₁) (m₃⊆m₄ , m₄⊆m₃)
|
where
|
||||||
, intersect-subset m₂ m₁ m₄ m₃ (m₂⊆m₁ , m₁⊆m₂) (m₄⊆m₃ , m₃⊆m₄)
|
mm-m-⊆ : (m ⊓ m) ⊆ m
|
||||||
)
|
mm-m-⊆ k v k,v∈mm
|
||||||
where
|
with Expr-Provenance k ((` m) ∩ (` m)) (∈-cong proj₁ k,v∈mm)
|
||||||
intersect-subset : ∀ (m₁ m₂ m₃ m₄ : Map) → lift m₁ m₂ → lift m₃ m₄ → subset (intersect f m₁ m₃) (intersect f m₂ m₄)
|
... | (_ , (bothⁱ (single {v'} v'∈m) (single {v''} v''∈m) , v'v''∈mm))
|
||||||
intersect-subset m₁ m₂ m₃ m₄ m₁≈m₂ m₃≈m₄ k v k,v∈m₁m₃
|
rewrite Map-functional {m = m} v'∈m v''∈m
|
||||||
with Expr-Provenance f f k ((` m₁) ∩ (` m₃)) (∈-cong proj₁ k,v∈m₁m₃)
|
rewrite Map-functional {m = m ⊓ m} k,v∈mm v'v''∈mm =
|
||||||
... | (_ , (bothⁱ (single {v₁} v₁∈m₁) (single {v₃} v₃∈m₃) , v₁v₃∈m₁m₃))
|
(v'' , (⊓₂-idemp v'' , v''∈m))
|
||||||
rewrite Map-functional {m = intersect f m₁ m₃} k,v∈m₁m₃ v₁v₃∈m₁m₃ =
|
|
||||||
let (v₂ , (v₁≈v₂ , k,v₂∈m₂)) = proj₁ m₁≈m₂ k v₁ v₁∈m₁
|
|
||||||
(v₄ , (v₃≈v₄ , k,v₄∈m₄)) = proj₁ m₃≈m₄ k v₃ v₃∈m₃
|
|
||||||
in (f v₂ v₄ , (≈-f-cong v₁≈v₂ v₃≈v₄ , I.intersect-combines (proj₂ m₂) (proj₂ m₄) k,v₂∈m₂ k,v₄∈m₄))
|
|
||||||
|
|
||||||
module _ (≈-refl : ∀ {b : B} → b ≈ b)
|
m-mm-⊆ : m ⊆ (m ⊓ m)
|
||||||
(≈-sym : ∀ {b₁ b₂ : B} → b₁ ≈ b₂ → b₂ ≈ b₁)
|
m-mm-⊆ k v k,v∈m = (v ⊓₂ v , (≈₂-sym (⊓₂-idemp v) , I⊓.intersect-combines u u k,v∈m k,v∈m))
|
||||||
(f : B → B → B) where
|
|
||||||
private module I = ImplInsert f
|
|
||||||
|
|
||||||
module _ (f-idemp : ∀ (b : B) → f b b ≈ b) where
|
⊓-comm : ∀ (m₁ m₂ : Map) → (m₁ ⊓ m₂) ≈ (m₂ ⊓ m₁)
|
||||||
union-idemp : ∀ (m : Map) → lift (union f m m) m
|
⊓-comm m₁ m₂ = (⊓-comm-⊆ m₁ m₂ , ⊓-comm-⊆ m₂ m₁)
|
||||||
union-idemp m@(l , u) = (mm-m-subset , m-mm-subset)
|
where
|
||||||
where
|
⊓-comm-⊆ : ∀ (m₁ m₂ : Map) → (m₁ ⊓ m₂) ⊆ (m₂ ⊓ m₁)
|
||||||
mm-m-subset : subset (union f m m) m
|
⊓-comm-⊆ m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
||||||
mm-m-subset k v k,v∈mm
|
with Expr-Provenance k ((` m₁) ∩ (` m₂)) (∈-cong proj₁ k,v∈m₁m₂)
|
||||||
with Expr-Provenance f f k ((` m) ∪ (` m)) (∈-cong proj₁ k,v∈mm)
|
... | (_ , (bothⁱ {v₁} {v₂} (single v₁∈m₁) (single v₂∈m₂) , v₁v₂∈m₁m₂))
|
||||||
... | (_ , (bothᵘ (single {v'} v'∈m) (single {v''} v''∈m) , v'v''∈mm))
|
rewrite Map-functional {m = m₁ ⊓ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
||||||
rewrite Map-functional {m = m} v'∈m v''∈m
|
(v₂ ⊓₂ v₁ , (⊓₂-comm v₁ v₂ , I⊓.intersect-combines u₂ u₁ v₂∈m₂ v₁∈m₁))
|
||||||
rewrite Map-functional {m = union f m m} k,v∈mm v'v''∈mm =
|
|
||||||
(v'' , (f-idemp v'' , v''∈m))
|
|
||||||
... | (_ , (in₁ (single {v'} v'∈m) k∉km , _)) = absurd (k∉km (∈-cong proj₁ v'∈m))
|
|
||||||
... | (_ , (in₂ k∉km (single {v''} v''∈m) , _)) = absurd (k∉km (∈-cong proj₁ v''∈m))
|
|
||||||
|
|
||||||
m-mm-subset : subset m (union f m m)
|
⊓-assoc : ∀ (m₁ m₂ m₃ : Map) → ((m₁ ⊓ m₂) ⊓ m₃) ≈ (m₁ ⊓ (m₂ ⊓ m₃))
|
||||||
m-mm-subset k v k,v∈m = (f v v , (≈-sym (f-idemp v) , I.union-combines u u k,v∈m k,v∈m))
|
⊓-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (⊓-assoc₁ , ⊓-assoc₂)
|
||||||
|
where
|
||||||
|
⊓-assoc₁ : ((m₁ ⊓ m₂) ⊓ m₃) ⊆ (m₁ ⊓ (m₂ ⊓ m₃))
|
||||||
|
⊓-assoc₁ k v k,v∈m₁₂m₃
|
||||||
|
with Expr-Provenance k (((` m₁) ∩ (` m₂)) ∩ (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃)
|
||||||
|
... | (_ , (bothⁱ (bothⁱ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₁v₂v₃∈m₁₂m₃))
|
||||||
|
rewrite Map-functional {m = (m₁ ⊓ m₂) ⊓ m₃} k,v∈m₁₂m₃ v₁v₂v₃∈m₁₂m₃ =
|
||||||
|
(v₁ ⊓₂ (v₂ ⊓₂ v₃) , (⊓₂-assoc v₁ v₂ v₃ , I⊓.intersect-combines u₁ (I⊓.intersect-preserves-Unique {l₂} {l₃} u₃) v₁∈e₁ (I⊓.intersect-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
||||||
|
|
||||||
module _ (f-comm : ∀ (b₁ b₂ : B) → f b₁ b₂ ≈ f b₂ b₁) where
|
⊓-assoc₂ : (m₁ ⊓ (m₂ ⊓ m₃)) ⊆ ((m₁ ⊓ m₂) ⊓ m₃)
|
||||||
union-comm : ∀ (m₁ m₂ : Map) → lift (union f m₁ m₂) (union f m₂ m₁)
|
⊓-assoc₂ k v k,v∈m₁m₂₃
|
||||||
union-comm m₁ m₂ = (union-comm-subset m₁ m₂ , union-comm-subset m₂ m₁)
|
with Expr-Provenance k ((` m₁) ∩ ((` m₂) ∩ (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
|
||||||
where
|
... | (_ , (bothⁱ (single {v₁} v₁∈e₁) (bothⁱ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃))
|
||||||
union-comm-subset : ∀ (m₁ m₂ : Map) → subset (union f m₁ m₂) (union f m₂ m₁)
|
rewrite Map-functional {m = m₁ ⊓ (m₂ ⊓ m₃)} k,v∈m₁m₂₃ v₁v₂v₃∈m₁m₂₃ =
|
||||||
union-comm-subset m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
((v₁ ⊓₂ v₂) ⊓₂ v₃ , (≈₂-sym (⊓₂-assoc v₁ v₂ v₃) , I⊓.intersect-combines (I⊓.intersect-preserves-Unique {l₁} {l₂} u₂) u₃ (I⊓.intersect-combines u₁ u₂ v₁∈e₁ v₂∈e₂) v₃∈e₃))
|
||||||
with Expr-Provenance f f k ((` m₁) ∪ (` m₂)) (∈-cong proj₁ k,v∈m₁m₂)
|
|
||||||
... | (_ , (bothᵘ {v₁} {v₂} (single v₁∈m₁) (single v₂∈m₂) , v₁v₂∈m₁m₂))
|
|
||||||
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
|
||||||
(f v₂ v₁ , (f-comm v₁ v₂ , I.union-combines u₂ u₁ v₂∈m₂ v₁∈m₁))
|
|
||||||
... | (_ , (in₁ {v₁} (single v₁∈m₁) k∉km₂ , v₁∈m₁m₂))
|
|
||||||
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁∈m₁m₂ =
|
|
||||||
(v₁ , (≈-refl , I.union-preserves-∈₂ k∉km₂ v₁∈m₁))
|
|
||||||
... | (_ , (in₂ {v₂} k∉km₁ (single v₂∈m₂) , v₂∈m₁m₂))
|
|
||||||
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₂∈m₁m₂ =
|
|
||||||
(v₂ , (≈-refl , I.union-preserves-∈₁ u₂ v₂∈m₂ k∉km₁))
|
|
||||||
|
|
||||||
module _ (f-assoc : ∀ (b₁ b₂ b₃ : B) → f (f b₁ b₂) b₃ ≈ f b₁ (f b₂ b₃)) where
|
absorb-⊓-⊔ : ∀ (m₁ m₂ : Map) → (m₁ ⊓ (m₁ ⊔ m₂)) ≈ m₁
|
||||||
union-assoc : ∀ (m₁ m₂ m₃ : Map) → lift (union f (union f m₁ m₂) m₃) (union f m₁ (union f m₂ m₃))
|
absorb-⊓-⊔ m₁@(l₁ , u₁) m₂@(l₂ , u₂) = (absorb-⊓-⊔¹ , absorb-⊓-⊔²)
|
||||||
union-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (union-assoc₁ , union-assoc₂)
|
where
|
||||||
where
|
absorb-⊓-⊔¹ : (m₁ ⊓ (m₁ ⊔ m₂)) ⊆ m₁
|
||||||
union-assoc₁ : subset (union f (union f m₁ m₂) m₃) (union f m₁ (union f m₂ m₃))
|
absorb-⊓-⊔¹ k v k,v∈m₁m₁₂
|
||||||
union-assoc₁ k v k,v∈m₁₂m₃
|
with Expr-Provenance k ((` m₁) ∩ ((` m₁) ∪ (` m₂))) (∈-cong proj₁ k,v∈m₁m₁₂)
|
||||||
with Expr-Provenance f f k (((` m₁) ∪ (` m₂)) ∪ (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃)
|
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
||||||
... | (_ , (in₂ k∉ke₁₂ (single {v₃} v₃∈e₃) , v₃∈m₁₂m₃))
|
(bothᵘ (single {v₁'} k,v₁'∈m₁)
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₃∈m₁₂m₃ =
|
(single {v₂} v₂∈m₂)) , v₁v₁'v₂∈m₁m₁₂))
|
||||||
let (k∉ke₁ , k∉ke₂) = I.∉-union-∉-either {l₁ = l₁} {l₂ = l₂} k∉ke₁₂
|
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
||||||
in (v₃ , (≈-refl , I.union-preserves-∈₂ k∉ke₁ (I.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
|
rewrite Map-functional {m = m₁ ⊓ (m₁ ⊔ m₂)} k,v∈m₁m₁₂ v₁v₁'v₂∈m₁m₁₂ =
|
||||||
... | (_ , (in₁ (in₂ k∉ke₁ (single {v₂} v₂∈e₂)) k∉ke₃ , v₂∈m₁₂m₃))
|
(v₁' , (absorb-⊓₂-⊔₂ v₁' v₂ , k,v₁'∈m₁))
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂∈m₁₂m₃ =
|
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
||||||
(v₂ , (≈-refl , I.union-preserves-∈₂ k∉ke₁ (I.union-preserves-∈₁ u₂ v₂∈e₂ k∉ke₃)))
|
(in₁ (single {v₁'} k,v₁'∈m₁) _) , v₁v₁'∈m₁m₁₂))
|
||||||
... | (_ , (bothᵘ (in₂ k∉ke₁ (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₂v₃∈m₁₂m₃))
|
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂v₃∈m₁₂m₃ =
|
rewrite Map-functional {m = m₁ ⊓ (m₁ ⊔ m₂)} k,v∈m₁m₁₂ v₁v₁'∈m₁m₁₂ =
|
||||||
(f v₂ v₃ , (≈-refl , I.union-preserves-∈₂ k∉ke₁ (I.union-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
(v₁' , (⊓₂-idemp v₁' , k,v₁'∈m₁))
|
||||||
... | (_ , (in₁ (in₁ (single {v₁} v₁∈e₁) k∉ke₂) k∉ke₃ , v₁∈m₁₂m₃))
|
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁∈m₁₂m₃ =
|
(in₂ k∉m₁ _ ) , _)) = ⊥-elim (k∉m₁ (∈-cong proj₁ k,v₁∈m₁))
|
||||||
(v₁ , (≈-refl , I.union-preserves-∈₁ u₁ v₁∈e₁ (I.union-preserves-∉ k∉ke₂ k∉ke₃)))
|
|
||||||
... | (_ , (bothᵘ (in₁ (single {v₁} v₁∈e₁) k∉ke₂) (single {v₃} v₃∈e₃) , v₁v₃∈m₁₂m₃))
|
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₃∈m₁₂m₃ =
|
|
||||||
(f v₁ v₃ , (≈-refl , I.union-combines u₁ (I.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
|
|
||||||
... | (_ , (in₁ (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) k∉ke₃), v₁v₂∈m₁₂m₃)
|
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₂∈m₁₂m₃ =
|
|
||||||
(f v₁ v₂ , (≈-refl , I.union-combines u₁ (I.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I.union-preserves-∈₁ u₂ v₂∈e₂ k∉ke₃)))
|
|
||||||
... | (_ , (bothᵘ (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₁v₂v₃∈m₁₂m₃))
|
|
||||||
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₂v₃∈m₁₂m₃ =
|
|
||||||
(f v₁ (f v₂ v₃) , (f-assoc v₁ v₂ v₃ , I.union-combines u₁ (I.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I.union-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
|
||||||
|
|
||||||
union-assoc₂ : subset (union f m₁ (union f m₂ m₃)) (union f (union f m₁ m₂) m₃)
|
absorb-⊓-⊔² : m₁ ⊆ (m₁ ⊓ (m₁ ⊔ m₂))
|
||||||
union-assoc₂ k v k,v∈m₁m₂₃
|
absorb-⊓-⊔² k v k,v∈m₁
|
||||||
with Expr-Provenance f f k ((` m₁) ∪ ((` m₂) ∪ (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
|
with ∈k-dec k l₂
|
||||||
... | (_ , (in₂ k∉ke₁ (in₂ k∉ke₂ (single {v₃} v₃∈e₃)) , v₃∈m₁m₂₃))
|
... | yes k∈km₂ =
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₃∈m₁m₂₃ =
|
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
||||||
(v₃ , (≈-refl , I.union-preserves-∈₂ (I.union-preserves-∉ k∉ke₁ k∉ke₂) v₃∈e₃))
|
in (v ⊓₂ (v ⊔₂ v₂) , (≈₂-sym (absorb-⊓₂-⊔₂ v v₂) , I⊓.intersect-combines u₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) k,v∈m₁ (I⊔.union-combines u₁ u₂ k,v∈m₁ k,v₂∈m₂)))
|
||||||
... | (_ , (in₂ k∉ke₁ (in₁ (single {v₂} v₂∈e₂) k∉ke₃) , v₂∈m₁m₂₃))
|
... | no k∉km₂ = (v ⊓₂ v , (≈₂-sym (⊓₂-idemp v) , I⊓.intersect-combines u₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) k,v∈m₁ (I⊔.union-preserves-∈₁ u₁ k,v∈m₁ k∉km₂)))
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₂∈m₁m₂₃ =
|
|
||||||
(v₂ , (≈-refl , I.union-preserves-∈₁ (I.union-preserves-Unique l₁ l₂ u₂) (I.union-preserves-∈₂ k∉ke₁ v₂∈e₂) k∉ke₃))
|
|
||||||
... | (_ , (in₂ k∉ke₁ (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₂v₃∈m₁m₂₃))
|
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₂v₃∈m₁m₂₃ =
|
|
||||||
(f v₂ v₃ , (≈-refl , I.union-combines (I.union-preserves-Unique l₁ l₂ u₂) u₃ (I.union-preserves-∈₂ k∉ke₁ v₂∈e₂) v₃∈e₃))
|
|
||||||
... | (_ , (in₁ (single {v₁} v₁∈e₁) k∉ke₂₃ , v₁∈m₁m₂₃))
|
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₁∈m₁m₂₃ =
|
|
||||||
let (k∉ke₂ , k∉ke₃) = I.∉-union-∉-either {l₁ = l₂} {l₂ = l₃} k∉ke₂₃
|
|
||||||
in (v₁ , (≈-refl , I.union-preserves-∈₁ (I.union-preserves-Unique l₁ l₂ u₂) (I.union-preserves-∈₁ u₁ v₁∈e₁ k∉ke₂) k∉ke₃))
|
|
||||||
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in₂ k∉ke₂ (single {v₃} v₃∈e₃)) , v₁v₃∈m₁m₂₃))
|
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₁v₃∈m₁m₂₃ =
|
|
||||||
(f v₁ v₃ , (≈-refl , I.union-combines (I.union-preserves-Unique l₁ l₂ u₂) u₃ (I.union-preserves-∈₁ u₁ v₁∈e₁ k∉ke₂) v₃∈e₃))
|
|
||||||
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in₁ (single {v₂} v₂∈e₂) k∉ke₃) , v₁v₂∈m₁m₂₃))
|
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₁v₂∈m₁m₂₃ =
|
|
||||||
(f v₁ v₂ , (≈-refl , I.union-preserves-∈₁ (I.union-preserves-Unique l₁ l₂ u₂) (I.union-combines u₁ u₂ v₁∈e₁ v₂∈e₂) k∉ke₃))
|
|
||||||
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃))
|
|
||||||
rewrite Map-functional {m = union f m₁ (union f m₂ m₃)} k,v∈m₁m₂₃ v₁v₂v₃∈m₁m₂₃ =
|
|
||||||
(f (f v₁ v₂) v₃ , (≈-sym (f-assoc v₁ v₂ v₃) , I.union-combines (I.union-preserves-Unique l₁ l₂ u₂) u₃ (I.union-combines u₁ u₂ v₁∈e₁ v₂∈e₂) v₃∈e₃))
|
|
||||||
|
|
||||||
module _ (f-idemp : ∀ (b : B) → f b b ≈ b) where
|
absorb-⊔-⊓ : ∀ (m₁ m₂ : Map) → (m₁ ⊔ (m₁ ⊓ m₂)) ≈ m₁
|
||||||
intersect-idemp : ∀ (m : Map) → lift (intersect f m m) m
|
absorb-⊔-⊓ m₁@(l₁ , u₁) m₂@(l₂ , u₂) = (absorb-⊔-⊓¹ , absorb-⊔-⊓²)
|
||||||
intersect-idemp m@(l , u) = (mm-m-subset , m-mm-subset)
|
where
|
||||||
where
|
absorb-⊔-⊓¹ : (m₁ ⊔ (m₁ ⊓ m₂)) ⊆ m₁
|
||||||
mm-m-subset : subset (intersect f m m) m
|
absorb-⊔-⊓¹ k v k,v∈m₁m₁₂
|
||||||
mm-m-subset k v k,v∈mm
|
with Expr-Provenance k ((` m₁) ∪ ((` m₁) ∩ (` m₂))) (∈-cong proj₁ k,v∈m₁m₁₂)
|
||||||
with Expr-Provenance f f k ((` m) ∩ (` m)) (∈-cong proj₁ k,v∈mm)
|
... | (_ , (bothᵘ (single {v₁} k,v₁∈m₁)
|
||||||
... | (_ , (bothⁱ (single {v'} v'∈m) (single {v''} v''∈m) , v'v''∈mm))
|
(bothⁱ (single {v₁'} k,v₁'∈m₁)
|
||||||
rewrite Map-functional {m = m} v'∈m v''∈m
|
(single {v₂} k,v₂∈m₂)) , v₁v₁'v₂∈m₁m₁₂))
|
||||||
rewrite Map-functional {m = intersect f m m} k,v∈mm v'v''∈mm =
|
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
||||||
(v'' , (f-idemp v'' , v''∈m))
|
rewrite Map-functional {m = m₁ ⊔ (m₁ ⊓ m₂)} k,v∈m₁m₁₂ v₁v₁'v₂∈m₁m₁₂ =
|
||||||
|
(v₁' , (absorb-⊔₂-⊓₂ v₁' v₂ , k,v₁'∈m₁))
|
||||||
|
... | (_ , (in₁ (single {v₁} k,v₁∈m₁) k∉km₁₂ , k,v₁∈m₁m₁₂))
|
||||||
|
rewrite Map-functional {m = m₁ ⊔ (m₁ ⊓ m₂)} k,v∈m₁m₁₂ k,v₁∈m₁m₁₂ =
|
||||||
|
(v₁ , (≈₂-refl , k,v₁∈m₁))
|
||||||
|
... | (_ , (in₂ k∉km₁ (bothⁱ (single {v₁'} k,v₁'∈m₁)
|
||||||
|
(single {v₂} k,v₂∈m₂)) , _)) =
|
||||||
|
⊥-elim (k∉km₁ (∈-cong proj₁ k,v₁'∈m₁))
|
||||||
|
|
||||||
m-mm-subset : subset m (intersect f m m)
|
absorb-⊔-⊓² : m₁ ⊆ (m₁ ⊔ (m₁ ⊓ m₂))
|
||||||
m-mm-subset k v k,v∈m = (f v v , (≈-sym (f-idemp v) , I.intersect-combines u u k,v∈m k,v∈m))
|
absorb-⊔-⊓² k v k,v∈m₁
|
||||||
|
with ∈k-dec k l₂
|
||||||
|
... | yes k∈km₂ =
|
||||||
|
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
||||||
|
in (v ⊔₂ (v ⊓₂ v₂) , (≈₂-sym (absorb-⊔₂-⊓₂ v v₂) , I⊔.union-combines u₁ (I⊓.intersect-preserves-Unique {l₁} {l₂} u₂) k,v∈m₁ (I⊓.intersect-combines u₁ u₂ k,v∈m₁ k,v₂∈m₂)))
|
||||||
|
... | no k∉km₂ = (v , (≈₂-refl , I⊔.union-preserves-∈₁ u₁ k,v∈m₁ (I⊓.intersect-preserves-∉₂ {k} {l₁} {l₂} k∉km₂)))
|
||||||
|
|
||||||
module _ (f-comm : ∀ (b₁ b₂ : B) → f b₁ b₂ ≈ f b₂ b₁) where
|
isUnionSemilattice : IsSemilattice Map _≈_ _⊔_
|
||||||
intersect-comm : ∀ (m₁ m₂ : Map) → lift (intersect f m₁ m₂) (intersect f m₂ m₁)
|
isUnionSemilattice = record
|
||||||
intersect-comm m₁ m₂ = (intersect-comm-subset m₁ m₂ , intersect-comm-subset m₂ m₁)
|
{ ≈-equiv = ≈-equiv
|
||||||
where
|
; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} m₁≈m₂ m₃≈m₄ → ≈-⊔-cong {m₁} {m₂} {m₃} {m₄} m₁≈m₂ m₃≈m₄
|
||||||
intersect-comm-subset : ∀ (m₁ m₂ : Map) → subset (intersect f m₁ m₂) (intersect f m₂ m₁)
|
; ⊔-assoc = ⊔-assoc
|
||||||
intersect-comm-subset m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
; ⊔-comm = ⊔-comm
|
||||||
with Expr-Provenance f f k ((` m₁) ∩ (` m₂)) (∈-cong proj₁ k,v∈m₁m₂)
|
; ⊔-idemp = ⊔-idemp
|
||||||
... | (_ , (bothⁱ {v₁} {v₂} (single v₁∈m₁) (single v₂∈m₂) , v₁v₂∈m₁m₂))
|
}
|
||||||
rewrite Map-functional {m = intersect f m₁ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
|
||||||
(f v₂ v₁ , (f-comm v₁ v₂ , I.intersect-combines u₂ u₁ v₂∈m₂ v₁∈m₁))
|
|
||||||
|
|
||||||
module _ (f-assoc : ∀ (b₁ b₂ b₃ : B) → f (f b₁ b₂) b₃ ≈ f b₁ (f b₂ b₃)) where
|
isIntersectSemilattice : IsSemilattice Map _≈_ _⊓_
|
||||||
intersect-assoc : ∀ (m₁ m₂ m₃ : Map) → lift (intersect f (intersect f m₁ m₂) m₃) (intersect f m₁ (intersect f m₂ m₃))
|
isIntersectSemilattice = record
|
||||||
intersect-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (intersect-assoc₁ , intersect-assoc₂)
|
{ ≈-equiv = ≈-equiv
|
||||||
where
|
; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} m₁≈m₂ m₃≈m₄ → ≈-⊓-cong {m₁} {m₂} {m₃} {m₄} m₁≈m₂ m₃≈m₄
|
||||||
intersect-assoc₁ : subset (intersect f (intersect f m₁ m₂) m₃) (intersect f m₁ (intersect f m₂ m₃))
|
; ⊔-assoc = ⊓-assoc
|
||||||
intersect-assoc₁ k v k,v∈m₁₂m₃
|
; ⊔-comm = ⊓-comm
|
||||||
with Expr-Provenance f f k (((` m₁) ∩ (` m₂)) ∩ (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃)
|
; ⊔-idemp = ⊓-idemp
|
||||||
... | (_ , (bothⁱ (bothⁱ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₁v₂v₃∈m₁₂m₃))
|
}
|
||||||
rewrite Map-functional {m = intersect f (intersect f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₂v₃∈m₁₂m₃ =
|
|
||||||
(f v₁ (f v₂ v₃) , (f-assoc v₁ v₂ v₃ , I.intersect-combines u₁ (I.intersect-preserves-Unique {l₂} {l₃} u₃) v₁∈e₁ (I.intersect-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
|
|
||||||
|
|
||||||
intersect-assoc₂ : subset (intersect f m₁ (intersect f m₂ m₃)) (intersect f (intersect f m₁ m₂) m₃)
|
isLattice : IsLattice Map _≈_ _⊔_ _⊓_
|
||||||
intersect-assoc₂ k v k,v∈m₁m₂₃
|
isLattice = record
|
||||||
with Expr-Provenance f f k ((` m₁) ∩ ((` m₂) ∩ (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
|
{ joinSemilattice = isUnionSemilattice
|
||||||
... | (_ , (bothⁱ (single {v₁} v₁∈e₁) (bothⁱ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃))
|
; meetSemilattice = isIntersectSemilattice
|
||||||
rewrite Map-functional {m = intersect f m₁ (intersect f m₂ m₃)} k,v∈m₁m₂₃ v₁v₂v₃∈m₁m₂₃ =
|
; absorb-⊔-⊓ = absorb-⊔-⊓
|
||||||
(f (f v₁ v₂) v₃ , (≈-sym (f-assoc v₁ v₂ v₃) , I.intersect-combines (I.intersect-preserves-Unique {l₁} {l₂} u₂) u₃ (I.intersect-combines u₁ u₂ v₁∈e₁ v₂∈e₂) v₃∈e₃))
|
; absorb-⊓-⊔ = absorb-⊓-⊔
|
||||||
|
}
|
||||||
module _ (≈-refl : ∀ {b : B} → b ≈ b)
|
|
||||||
(≈-sym : ∀ {b₁ b₂ : B} → b₁ ≈ b₂ → b₂ ≈ b₁)
|
|
||||||
(_⊔₂_ : B → B → B) (_⊓₂_ : B → B → B)
|
|
||||||
(⊔₂-idemp : ∀ (b : B) → (b ⊔₂ b) ≈ b)
|
|
||||||
(⊓₂-idemp : ∀ (b : B) → (b ⊓₂ b) ≈ b)
|
|
||||||
(⊔₂-⊓₂-absorb : ∀ (b₁ b₂ : B) → (b₁ ⊔₂ (b₁ ⊓₂ b₂)) ≈ b₁)
|
|
||||||
(⊓₂-⊔₂-absorb : ∀ (b₁ b₂ : B) → (b₁ ⊓₂ (b₁ ⊔₂ b₂)) ≈ b₁)
|
|
||||||
where
|
|
||||||
private module I⊔ = ImplInsert _⊔₂_
|
|
||||||
private module I⊓ = ImplInsert _⊓₂_
|
|
||||||
|
|
||||||
private
|
|
||||||
_⊔_ = union _⊔₂_
|
|
||||||
_⊓_ = intersect _⊓₂_
|
|
||||||
|
|
||||||
intersect-union-absorb : ∀ (m₁ m₂ : Map) → lift (m₁ ⊓ (m₁ ⊔ m₂)) m₁
|
|
||||||
intersect-union-absorb m₁@(l₁ , u₁) m₂@(l₂ , u₂) = (intersect-union-absorb₁ , intersect-union-absorb₂)
|
|
||||||
where
|
|
||||||
intersect-union-absorb₁ : subset (m₁ ⊓ (m₁ ⊔ m₂)) m₁
|
|
||||||
intersect-union-absorb₁ k v k,v∈m₁m₁₂
|
|
||||||
with Expr-Provenance _ _ k ((` m₁) ∩ ((` m₁) ∪ (` m₂))) (∈-cong proj₁ k,v∈m₁m₁₂)
|
|
||||||
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
|
||||||
(bothᵘ (single {v₁'} k,v₁'∈m₁)
|
|
||||||
(single {v₂} v₂∈m₂)) , v₁v₁'v₂∈m₁m₁₂))
|
|
||||||
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
|
||||||
rewrite Map-functional {m = m₁ ⊓ (m₁ ⊔ m₂)} k,v∈m₁m₁₂ v₁v₁'v₂∈m₁m₁₂ =
|
|
||||||
(v₁' , (⊓₂-⊔₂-absorb v₁' v₂ , k,v₁'∈m₁))
|
|
||||||
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
|
||||||
(in₁ (single {v₁'} k,v₁'∈m₁) _) , v₁v₁'∈m₁m₁₂))
|
|
||||||
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
|
||||||
rewrite Map-functional {m = m₁ ⊓ (m₁ ⊔ m₂)} k,v∈m₁m₁₂ v₁v₁'∈m₁m₁₂ =
|
|
||||||
(v₁' , (⊓₂-idemp v₁' , k,v₁'∈m₁))
|
|
||||||
... | (_ , (bothⁱ (single {v₁} k,v₁∈m₁)
|
|
||||||
(in₂ k∉m₁ _ ) , _)) = absurd (k∉m₁ (∈-cong proj₁ k,v₁∈m₁))
|
|
||||||
|
|
||||||
intersect-union-absorb₂ : subset m₁ (m₁ ⊓ (m₁ ⊔ m₂))
|
|
||||||
intersect-union-absorb₂ k v k,v∈m₁
|
|
||||||
with ∈k-dec k l₂
|
|
||||||
... | yes k∈km₂ =
|
|
||||||
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
|
||||||
in (v ⊓₂ (v ⊔₂ v₂) , (≈-sym (⊓₂-⊔₂-absorb v v₂) , I⊓.intersect-combines u₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) k,v∈m₁ (I⊔.union-combines u₁ u₂ k,v∈m₁ k,v₂∈m₂)))
|
|
||||||
... | no k∉km₂ = (v ⊓₂ v , (≈-sym (⊓₂-idemp v) , I⊓.intersect-combines u₁ (I⊔.union-preserves-Unique l₁ l₂ u₂) k,v∈m₁ (I⊔.union-preserves-∈₁ u₁ k,v∈m₁ k∉km₂)))
|
|
||||||
|
|
||||||
union-intersect-absorb : ∀ (m₁ m₂ : Map) → lift (m₁ ⊔ (m₁ ⊓ m₂)) m₁
|
|
||||||
union-intersect-absorb m₁@(l₁ , u₁) m₂@(l₂ , u₂) = (union-intersect-absorb₁ , union-intersect-absorb₂)
|
|
||||||
where
|
|
||||||
union-intersect-absorb₁ : subset (m₁ ⊔ (m₁ ⊓ m₂)) m₁
|
|
||||||
union-intersect-absorb₁ k v k,v∈m₁m₁₂
|
|
||||||
with Expr-Provenance _ _ k ((` m₁) ∪ ((` m₁) ∩ (` m₂))) (∈-cong proj₁ k,v∈m₁m₁₂)
|
|
||||||
... | (_ , (bothᵘ (single {v₁} k,v₁∈m₁)
|
|
||||||
(bothⁱ (single {v₁'} k,v₁'∈m₁)
|
|
||||||
(single {v₂} k,v₂∈m₂)) , v₁v₁'v₂∈m₁m₁₂))
|
|
||||||
rewrite Map-functional {m = m₁} k,v₁∈m₁ k,v₁'∈m₁
|
|
||||||
rewrite Map-functional {m = m₁ ⊔ (m₁ ⊓ m₂)} k,v∈m₁m₁₂ v₁v₁'v₂∈m₁m₁₂ =
|
|
||||||
(v₁' , (⊔₂-⊓₂-absorb v₁' v₂ , k,v₁'∈m₁))
|
|
||||||
... | (_ , (in₁ (single {v₁} k,v₁∈m₁) k∉km₁₂ , k,v₁∈m₁m₁₂))
|
|
||||||
rewrite Map-functional {m = m₁ ⊔ (m₁ ⊓ m₂)} k,v∈m₁m₁₂ k,v₁∈m₁m₁₂ =
|
|
||||||
(v₁ , (≈-refl , k,v₁∈m₁))
|
|
||||||
... | (_ , (in₂ k∉km₁ (bothⁱ (single {v₁'} k,v₁'∈m₁)
|
|
||||||
(single {v₂} k,v₂∈m₂)) , _)) =
|
|
||||||
absurd (k∉km₁ (∈-cong proj₁ k,v₁'∈m₁))
|
|
||||||
|
|
||||||
union-intersect-absorb₂ : subset m₁ (m₁ ⊔ (m₁ ⊓ m₂))
|
|
||||||
union-intersect-absorb₂ k v k,v∈m₁
|
|
||||||
with ∈k-dec k l₂
|
|
||||||
... | yes k∈km₂ =
|
|
||||||
let (v₂ , k,v₂∈m₂) = locate k∈km₂
|
|
||||||
in (v ⊔₂ (v ⊓₂ v₂) , (≈-sym (⊔₂-⊓₂-absorb v v₂) , I⊔.union-combines u₁ (I⊓.intersect-preserves-Unique {l₁} {l₂} u₂) k,v∈m₁ (I⊓.intersect-combines u₁ u₂ k,v∈m₁ k,v₂∈m₂)))
|
|
||||||
... | no k∉km₂ = (v , (≈-refl , I⊔.union-preserves-∈₁ u₁ k,v∈m₁ (I⊓.intersect-preserves-∉₂ {k} {l₁} {l₂} k∉km₂)))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user