Prove semilattice properties for intersect

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2023-08-05 12:40:30 -07:00
parent 12e76527cc
commit d3e0db449c

View File

@ -433,6 +433,12 @@ private module ImplInsert (f : B → B → B) where
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v₁∈xs)) ... | yes k≡k' rewrite k≡k' = absurd (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)}
Unique (keys l₁) Unique (keys l₂)
(k , v₁) l₁ (k , v₂) l₂ (k , f v₁ v₂) intersect l₁ l₂
intersect-combines u₁ u₂ k,v₁∈l₁ k,v₂∈l₂ =
restrict-preserves-∈₂ (∈-cong proj₁ k,v₁∈l₁) (updates-combine u₁ u₂ k,v₁∈l₁ k,v₂∈l₂)
Map : Set (a b) Map : Set (a b)
Map = Σ (List (A × B)) (λ l Unique (keys l)) Map = Σ (List (A × B)) (λ l Unique (keys l))
@ -475,10 +481,9 @@ module _ (fUnion : B → B → B) (fIntersect : B → B → B) where
open ImplInsert fIntersect using open ImplInsert fIntersect using
( restrict-needs-both ( restrict-needs-both
; updates ; updates
; updates-combine
; intersect-preserves-∉₁ ; intersect-preserves-∉₁
; intersect-preserves-∉₂ ; intersect-preserves-∉₂
; restrict-preserves-∈₂ ; intersect-combines
) )
⟦_⟧ : Expr -> Map ⟦_⟧ : Expr -> Map
@ -513,7 +518,7 @@ module _ (fUnion : B → B → B) (fIntersect : B → B → B) where
... | 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₂ , restrict-preserves-∈₂ k∈ke₁ (updates-combine (proj₂ e₁ ) (proj₂ e₂ ) k,v₁∈e₁ k,v₂∈e₂))) in (fIntersect 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₂ = absurd (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₂ = absurd (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₂ = absurd (intersect-preserves-∉₂ {l₁ = proj₁ e₁ } k∉ke₂ k∈ke₁e₂)
@ -534,7 +539,7 @@ module _ (_≈_ : B → B → Set b) where
module I = ImplInsert f module I = ImplInsert f
-- The Provenance type requires both union and intersection functions, -- The Provenance type requires both union and intersection functions,
-- but here we're working with union only. Just use the union function -- but here we're working with one operation only. Just use the union function
-- for both -- it doesn't matter, since we don't use intersection in -- for both -- it doesn't matter, since we don't use intersection in
-- these proofs. -- these proofs.
@ -627,3 +632,47 @@ module _ (_≈_ : B → B → Set b) where
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃)) ... | (_ , (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₂₃ = 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₃)) (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
intersect-idemp : (m : Map) lift (intersect f m m) m
intersect-idemp m@(l , u) = (mm-m-subset , m-mm-subset)
where
mm-m-subset : subset (intersect f m m) m
mm-m-subset k v k,v∈mm
with Expr-Provenance f f 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 = intersect f m m} k,v∈mm v'v''∈mm =
(v'' , (f-idemp v'' , v''∈m))
m-mm-subset : subset m (intersect f 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))
module _ (f-comm : (b₁ b₂ : B) f b₁ b₂ f b₂ b₁) where
intersect-comm : (m₁ m₂ : Map) lift (intersect f m₁ m₂) (intersect f m₂ m₁)
intersect-comm m₁ m₂ = (intersect-comm-subset m₁ m₂ , intersect-comm-subset m₂ m₁)
where
intersect-comm-subset : (m₁ m₂ : Map) subset (intersect f m₁ m₂) (intersect f m₂ m₁)
intersect-comm-subset m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
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 = 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
intersect-assoc : (m₁ m₂ m₃ : Map) lift (intersect f (intersect f m₁ m₂) m₃) (intersect f m₁ (intersect f m₂ m₃))
intersect-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (intersect-assoc₁ , intersect-assoc₂)
where
intersect-assoc₁ : subset (intersect f (intersect f m₁ m₂) m₃) (intersect f m₁ (intersect f m₂ m₃))
intersect-assoc₁ k v k,v∈m₁₂m₃
with Expr-Provenance f f 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 = 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₃)
intersect-assoc₂ k v k,v∈m₁m₂₃
with Expr-Provenance f f k ((` m₁) ((` m₂) (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
... | (_ , (bothⁱ (single {v₁} v₁∈e₁) (bothⁱ (single {v₂} v₂∈e₂) (single {v₃} v₃∈e₃)) , v₁v₂v₃∈m₁m₂₃))
rewrite Map-functional {m = intersect f m₁ (intersect f m₂ m₃)} k,v∈m₁m₂₃ v₁v₂v₃∈m₁m₂₃ =
(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₃))