Finish associativity proof

This commit is contained in:
Danila Fedorin 2023-07-30 19:54:38 -07:00
parent eca6181494
commit fceee34cee

View File

@ -345,6 +345,9 @@ module _ (_≈_ : B → B → Set b) where
module _ (f : B B B) where module _ (f : B B B) where
module _ (f-comm : (b₁ b₂ : B) f b₁ b₂ f b₂ b₁) module _ (f-comm : (b₁ b₂ : B) f b₁ b₂ f b₂ b₁)
(f-assoc : (b₁ b₂ b₃ : B) f (f b₁ b₂) b₃ f b₁ (f b₂ b₃)) where (f-assoc : (b₁ b₂ b₃ : B) f (f b₁ b₂) b₃ f b₁ (f b₂ b₃)) where
module I = ImplInsert f
union-comm : (m₁ m₂ : Map) lift (_≡_) (union f m₁ m₂) (union f m₂ m₁) union-comm : (m₁ m₂ : Map) lift (_≡_) (union f m₁ m₂) (union f m₂ m₁)
union-comm m₁ m₂ = (union-comm-subset m₁ m₂ , union-comm-subset m₂ m₁) union-comm m₁ m₂ = (union-comm-subset m₁ m₂ , union-comm-subset m₂ m₁)
where where
@ -353,47 +356,65 @@ module _ (f : B → B → B) where
with Expr-Provenance f k ((` m₁) (` m₂)) (∈-cong proj₁ k,v∈m₁m₂) with Expr-Provenance f k ((` m₁) (` m₂)) (∈-cong proj₁ k,v∈m₁m₂)
... | (_ , (bothᵘ {v₁} {v₂} (single v₁∈m₁) (single v₂∈m₂) , v₁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₂ = rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
(f v₂ v₁ , (f-comm v₁ v₂ , ImplInsert.union-combines f u₂ u₁ v₂∈m₂ v₁∈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₂)) ... | (_ , (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₂ = rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁∈m₁m₂ =
(v₁ , (refl , ImplInsert.union-preserves-∈₂ f k∉km₂ v₁∈m₁)) (v₁ , (refl , I.union-preserves-∈₂ k∉km₂ v₁∈m₁))
... | (_ , (in {v₂} k∉km₁ (single v₂∈m₂) , v₂∈m₁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₂ = rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₂∈m₁m₂ =
(v₂ , (refl , ImplInsert.union-preserves-∈₁ f u₂ v₂∈m₂ k∉km₁)) (v₂ , (refl , I.union-preserves-∈₁ u₂ v₂∈m₂ k∉km₁))
union-assoc₁ : (m₁ m₂ m₃ : Map) subset (_≡_) (union f (union f m₁ m₂) m₃) (union f m₁ (union f m₂ m₃)) union-assoc : (m₁ m₂ m₃ : Map) lift (_≡_) (union f (union f m₁ m₂) m₃) (union f m₁ (union f m₂ m₃))
union-assoc₁ m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) k v k,v∈m₁₂m₃ union-assoc m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) = (union-assoc₁ , union-assoc₂)
with Expr-Provenance f k (((` m₁) (` m₂)) (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃) where
... | (_ , (in k∉ke₁₂ (single {v₃} v₃∈e₃) , v₃∈m₁₂m₃)) union-assoc₁ : subset (_≡_) (union f (union f m₁ m₂) m₃) (union f m₁ (union f m₂ m₃))
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₃∈m₁₂m₃ = union-assoc₁ k v k,v∈m₁₂m₃
let (k∉ke₁ , k∉ke₂) = ImplInsert.∉-union-∉-either f {l₁ = l₁} {l₂ = l₂} k∉ke₁₂ with Expr-Provenance f k (((` m₁) (` m₂)) (` m₃)) (∈-cong proj₁ k,v∈m₁₂m₃)
in (v₃ , (refl , ImplInsert.union-preserves-∈₂ f k∉ke₁ (ImplInsert.union-preserves-∈₂ f k∉ke₂ v₃∈e₃))) ... | (_ , (in k∉ke₁₂ (single {v₃} v₃∈e₃) , v₃∈m₁₂m₃))
... | (_ , (in (in k∉ke₁ (single {v₂} v₂∈e₂)) k∉ke₃ , v₂∈m₁₂m₃)) rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₃∈m₁₂m₃ =
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂∈m₁₂m₃ = let (k∉ke₁ , k∉ke₂) = I.∉-union-∉-either {l₁ = l₁} {l₂ = l₂} k∉ke₁₂
(v₂ , (refl , ImplInsert.union-preserves-∈₂ f k∉ke₁ (ImplInsert.union-preserves-∈₁ f u₂ v₂∈e₂ k∉ke₃))) in (v₃ , (refl , I.union-preserves-∈₂ k∉ke₁ (I.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
... | (_ , (bothᵘ (in k∉ke₁ (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₂v₃∈m₁₂m₃)) ... | (_ , (in (in k∉ke₁ (single {v₂} v₂∈e₂)) k∉ke₃ , v₂∈m₁₂m₃))
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂v₃∈m₁₂m₃ = rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂∈m₁₂m₃ =
(f v₂ v₃ , (refl , ImplInsert.union-preserves-∈₂ f k∉ke₁ (ImplInsert.union-combines f u₂ u₃ v₂∈e₂ v₃∈e₃))) (v₂ , (refl , I.union-preserves-∈₂ k∉ke₁ (I.union-preserves-∈₁ u₂ v₂∈e₂ k∉ke₃)))
... | (_ , (in (in (single {v₁} v₁∈e₁) k∉ke₂) k∉ke₃ , v₁∈m₁₂m₃)) ... | (_ , (bothᵘ (in k∉ke₁ (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₂v₃∈m₁₂m₃))
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁∈m₁₂m₃ = rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₂v₃∈m₁₂m₃ =
(v₁ , (refl , ImplInsert.union-preserves-∈₁ f u₁ v₁∈e₁ (ImplInsert.union-preserves-∉ f k∉ke₂ k∉ke₃))) (f v₂ v₃ , (refl , I.union-preserves-∈₂ k∉ke₁ (I.union-combines u₂ u₃ v₂∈e₂ v₃∈e₃)))
... | (_ , (bothᵘ (in (single {v₁} v₁∈e₁) k∉ke₂) (single {v₃} v₃∈e₃) , v₁v₃∈m₁₂m₃)) ... | (_ , (in (in (single {v₁} v₁∈e₁) k∉ke₂) k∉ke₃ , v₁∈m₁₂m₃))
rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₃∈m₁₂m₃ = rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁∈m₁₂m₃ =
(f v₁ v₃ , (refl , ImplInsert.union-combines f u₁ (ImplInsert.union-preserves-Unique f l₂ l₃ u₃) v₁∈e₁ (ImplInsert.union-preserves-∈₂ f k∉ke₂ v₃∈e₃))) (v₁ , (refl , I.union-preserves-∈₁ u₁ v₁∈e₁ (I.union-preserves-∉ k∉ke₂ k∉ke₃)))
... | (_ , (in (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) k∉ke₃), v₁v₂∈m₁₂m₃) ... | (_ , (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₃ = rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₃∈m₁₂m₃ =
(f v₁ v₂ , (refl , ImplInsert.union-combines f u₁ (ImplInsert.union-preserves-Unique f l₂ l₃ u₃) v₁∈e₁ (ImplInsert.union-preserves-∈₁ f u₂ v₂∈e₂ k∉ke₃))) (f v₁ v₃ , (refl , I.union-combines u₁ (I.union-preserves-Unique l₂ l₃ u₃) v₁∈e₁ (I.union-preserves-∈₂ k∉ke₂ v₃∈e₃)))
... | (_ , (bothᵘ (bothᵘ (single {v₁} v₁∈e₁) (single {v₂} v₂∈e₂)) (single {v₃} v₃∈e₃) , v₁v₂v₃∈m₁₂m₃)) ... | (_ , (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₂v₃∈m₁₂m₃ = rewrite Map-functional {m = union f (union f m₁ m₂) m₃} k,v∈m₁₂m₃ v₁v₂∈m₁₂m₃ =
(f v₁ (f v₂ v₃) , (f-assoc v₁ v₂ v₃ , ImplInsert.union-combines f u₁ (ImplInsert.union-preserves-Unique f l₂ l₃ u₃) v₁∈e₁ (ImplInsert.union-combines f u₂ u₃ v₂∈e₂ v₃∈e₃))) (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₂ : (m₁ m₂ m₃ : Map) subset (_≡_) (union f m₁ (union f m₂ m₃)) (union f (union f m₁ m₂) m₃) union-assoc₂ : subset (_≡_) (union f m₁ (union f m₂ m₃)) (union f (union f m₁ m₂) m₃)
union-assoc₂ m₁@(l₁ , u₁) m₂@(l₂ , u₂) m₃@(l₃ , u₃) k v k,v∈m₁m₂₃ union-assoc₂ k v k,v∈m₁m₂₃
with Expr-Provenance f k ((` m₁) ((` m₂) (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃) with Expr-Provenance f k ((` m₁) ((` m₂) (` m₃))) (∈-cong proj₁ k,v∈m₁m₂₃)
... | (_ , (in k∉ke₁ (in k∉e₂ (single {v₃} v₁∈e₃)) , v₃∈m₁m₂₃)) = {!!} ... | (_ , (in k∉ke₁ (in k∉ke₂ (single {v₃} v₃∈e₃)) , v₃∈m₁m₂₃))
... | (_ , (in k∉ke₁ (in (single {v₂} v₂∈e₂) k∉e₃) , v₂∈m₁m₂₃)) = {!!} rewrite Map-functional {m = union f 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₂₃)) = {!!} (v₃ , (refl , I.union-preserves-∈₂ (I.union-preserves-∉ k∉ke₁ k∉ke₂) v₃∈e₃))
... | (_ , (in (single {v₁} v₁∈e₁) k∉ke₁₂ , v₁∈m₁m₂₃)) = {!!} ... | (_ , (in k∉ke₁ (in (single {v₂} v₂∈e₂) k∉ke₃) , v₂∈m₁m₂₃))
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in k∉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₂∈m₁m₂₃ =
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (in (single {v₂} v₂∈e₂) k∉e₃) , v₁v₂∈m₁m₂₃)) = {!!} (v₂ , (refl , I.union-preserves-∈₁ (I.union-preserves-Unique l₁ l₂ u₂) (I.union-preserves-∈₂ k∉ke₁ v₂∈e₂) k∉ke₃))
... | (_ , (bothᵘ (single {v₁} v₁∈e₁) (bothᵘ (single {v₂} v₂∈e₂) (single {v₃} v₁∈e₃)) , v₁v₂v₃∈m₁m₂₃)) = {!!} ... | (_ , (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₃))