Add uniqueness preservation proof for merge

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2023-07-24 23:02:43 -07:00
parent 87a476ab9e
commit 232bd65809

View File

@ -106,6 +106,10 @@ insert-preserves-unique f k v l u with (∈k-dec k l)
... | yes k∈kl rewrite insert-keys-∈ f k v l k∈kl = u ... | yes k∈kl rewrite insert-keys-∈ f k v l k∈kl = u
... | no k∉kl rewrite sym (insert-keys-∉ f k v l k∉kl) = Unique-append k∉kl u ... | no k∉kl rewrite sym (insert-keys-∉ f k v l k∉kl) = Unique-append k∉kl u
merge-preserves-unique : (f : B B B) (l₁ l₂ : List (A × B)) Unique (keys l₂) Unique (keys (merge f l₁ l₂))
merge-preserves-unique f [] l₂ u₂ = u₂
merge-preserves-unique f ((k₁ , v₁) xs₁) l₂ u₂ = insert-preserves-unique f k₁ v₁ (merge f xs₁ l₂) (merge-preserves-unique f xs₁ l₂ u₂)
Map-functional : (k : A) (v v' : B) (xs : List (A × B)) Unique (keys ((k , v) xs)) Data.List.Membership.Propositional._∈_ (k , v') ((k , v) xs) v v' Map-functional : (k : A) (v v' : B) (xs : List (A × B)) Unique (keys ((k , v) xs)) Data.List.Membership.Propositional._∈_ (k , v') ((k , v) xs) v v'
Map-functional k v v' _ _ (here k,v'≡k,v) = sym (cong proj₂ k,v'≡k,v) Map-functional k v v' _ _ (here k,v'≡k,v) = sym (cong proj₂ k,v'≡k,v)
Map-functional k v v' xs (push k≢ _) (there k,v'∈xs) = absurd (unique-not-in xs v' (k≢ , k,v'∈xs)) Map-functional k v v' xs (push k≢ _) (there k,v'∈xs) = absurd (unique-not-in xs v' (k≢ , k,v'∈xs))