Reformat the code to roughly fit into 80 columns.

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2023-07-26 17:31:09 -07:00
parent 489b0532df
commit 12217e6928

View File

@ -28,9 +28,11 @@ data Unique {c} {C : Set c} : List C → Set c where
Unique xs Unique xs
Unique (x xs) Unique (x xs)
Unique-append : {c} {C : Set c} {x : C} {xs : List C} ¬ MemProp._∈_ x xs Unique xs Unique (xs ++ (x [])) Unique-append : {c} {C : Set c} {x : C} {xs : List C}
¬ MemProp._∈_ x xs Unique xs Unique (xs ++ (x []))
Unique-append {c} {C} {x} {[]} _ _ = push [] empty Unique-append {c} {C} {x} {[]} _ _ = push [] empty
Unique-append {c} {C} {x} {x' xs'} x∉xs (push x'≢ uxs') = push (help x'≢) (Unique-append (λ x∈xs' x∉xs (there x∈xs')) uxs') Unique-append {c} {C} {x} {x' xs'} x∉xs (push x'≢ uxs') =
push (help x'≢) (Unique-append (λ x∈xs' x∉xs (there x∈xs')) uxs')
where where
x'≢x : ¬ x' x x'≢x : ¬ x' x
x'≢x x'≡x = x∉xs (here (sym x'≡x)) x'≢x x'≡x = x∉xs (here (sym x'≡x))
@ -45,21 +47,30 @@ absurd ()
private module _ where private module _ where
open MemProp using (_∈_) open MemProp using (_∈_)
unique-not-in : {k : A} {v : B} {l : List (A × B)} ¬ (All (λ k' ¬ k k') (keys l) × (k , v) l) unique-not-in : {k : A} {v : B} {l : List (A × B)}
unique-not-in {l = (k' , _) xs} (k≢k' _ , here k',≡x) = k≢k' (cong proj₁ k',≡x) ¬ (All (λ k' ¬ k k') (keys l) × (k , v) l)
unique-not-in {l = _ xs} (_ rest , there k,v'∈xs) = unique-not-in (rest , k,v'∈xs) unique-not-in {l = (k' , _) xs} (k≢k' _ , here k',≡x) =
k≢k' (cong proj₁ k',≡x)
unique-not-in {l = _ xs} (_ rest , there k,v'∈xs) =
unique-not-in (rest , k,v'∈xs)
ListAB-functional : {k : A} {v v' : B} {l : List (A × B)} Unique (keys l) (k , v) l (k , v') l v v' ListAB-functional : {k : A} {v v' : B} {l : List (A × B)}
ListAB-functional _ (here k,v≡x) (here k,v'≡x) = cong proj₂ (trans k,v≡x (sym k,v'≡x)) Unique (keys l) (k , v) l (k , v') l v v'
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)) ListAB-functional _ (here k,v≡x) (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)) cong proj₂ (trans k,v≡x (sym k,v'≡x))
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 (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))
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))
ListAB-functional {l = _ xs } (push _ uxs) (there k,v∈xs) (there k,v'∈xs) =
ListAB-functional uxs k,v∈xs k,v'∈xs
private module ImplRelation (_≈_ : B B Set b) where private module ImplRelation (_≈_ : B B Set b) 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₁ Σ B (λ v' v v' × ((k , v') m₂)) subset m₁ m₂ = (k : A) (v : B) (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)
@ -82,23 +93,30 @@ private module ImplInsert (f : B → B → B) where
merge : List (A × B) List (A × B) List (A × B) merge : List (A × B) List (A × B) List (A × B)
merge m₁ m₂ = foldr insert m₂ m₁ merge m₁ m₂ = foldr insert m₂ m₁
insert-keys-∈ : (k : A) (v : B) (l : List (A × B)) k ∈k l keys l keys (insert k v l) insert-keys-∈ : (k : A) (v : B) (l : List (A × B))
insert-keys-∈ k v ((k' , v') xs) (here k≡k') with (≡-dec-A k k') k ∈k l keys l keys (insert k v l)
insert-keys-∈ k v ((k' , v') xs) (here k≡k')
with (≡-dec-A k k')
... | yes _ = refl ... | yes _ = refl
... | no k≢k' = absurd (k≢k' k≡k') ... | no k≢k' = absurd (k≢k' k≡k')
insert-keys-∈ k v ((k' , _) xs) (there k∈kxs) with (≡-dec-A k k') insert-keys-∈ k v ((k' , _) xs) (there k∈kxs)
with (≡-dec-A k k')
... | yes _ = refl ... | yes _ = refl
... | no _ = cong (λ xs' k' xs') (insert-keys-∈ k v xs k∈kxs) ... | no _ = cong (λ xs' k' xs') (insert-keys-∈ k v xs k∈kxs)
insert-keys-∉ : (k : A) (v : B) (l : List (A × B)) ¬ (k ∈k l) (keys l ++ (k [])) keys (insert k v l) insert-keys-∉ : (k : A) (v : B) (l : List (A × B))
¬ (k ∈k l) (keys l ++ (k [])) keys (insert k v l)
insert-keys-∉ k v [] _ = refl insert-keys-∉ k v [] _ = refl
insert-keys-∉ k v ((k' , v') xs) k∉kl with (≡-dec-A k k') insert-keys-∉ k v ((k' , v') xs) k∉kl
with (≡-dec-A k k')
... | yes k≡k' = absurd (k∉kl (here k≡k')) ... | yes k≡k' = absurd (k∉kl (here k≡k'))
... | no _ = cong (λ xs' k' xs') (insert-keys-∉ k v xs (λ k∈kxs k∉kl (there k∈kxs))) ... | no _ = cong (λ xs' k' xs')
(insert-keys-∉ k v xs (λ k∈kxs k∉kl (there k∈kxs)))
∈k-dec : (k : A) (l : List (A × B)) Dec (k ∈k l) ∈k-dec : (k : A) (l : List (A × B)) Dec (k ∈k l)
∈k-dec k [] = no (λ ()) ∈k-dec k [] = no (λ ())
∈k-dec k ((k' , v) xs) with (≡-dec-A k k') ∈k-dec k ((k' , v) xs)
with (≡-dec-A k k')
... | yes k≡k' = yes (here k≡k') ... | yes k≡k' = yes (here k≡k')
... | no k≢k' with (∈k-dec k xs) ... | no k≢k' with (∈k-dec k xs)
... | yes k∈kxs = yes (there k∈kxs) ... | yes k∈kxs = yes (there k∈kxs)
@ -108,42 +126,55 @@ private module ImplInsert (f : B → B → B) where
witness (here k≡k') = k≢k' k≡k' witness (here k≡k') = k≢k' k≡k'
witness (there k∈kxs) = k∉kxs k∈kxs witness (there k∈kxs) = k∉kxs k∈kxs
insert-preserves-Unique : (k : A) (v : B) (l : List (A × B)) Unique (keys l) Unique (keys (insert k v l)) ∈-cong : {c d} {C : Set c} {D : Set d} {c : C} {l : List C}
insert-preserves-Unique k v l u with (∈k-dec k l) (f : C D) c l f c map f l
∈-cong f (here c≡c') = here (cong f c≡c')
∈-cong f (there c∈xs) = there (∈-cong f c∈xs)
insert-preserves-Unique : (k : A) (v : B) (l : List (A × B))
Unique (keys l) Unique (keys (insert k v l))
insert-preserves-Unique k v l u
with (∈k-dec k l)
... | yes k∈kl rewrite insert-keys-∈ k v l k∈kl = u ... | yes k∈kl rewrite insert-keys-∈ k v l k∈kl = u
... | no k∉kl rewrite sym (insert-keys-∉ k v l k∉kl) = Unique-append k∉kl u ... | no k∉kl rewrite sym (insert-keys-∉ k v l k∉kl) = Unique-append k∉kl u
merge-preserves-Unique : (l₁ l₂ : List (A × B)) Unique (keys l₂) Unique (keys (merge l₁ l₂)) merge-preserves-Unique : (l₁ l₂ : List (A × B))
Unique (keys l₂) Unique (keys (merge l₁ l₂))
merge-preserves-Unique [] l₂ u₂ = u₂ merge-preserves-Unique [] l₂ u₂ = u₂
merge-preserves-Unique ((k₁ , v₁) xs₁) l₂ u₂ = insert-preserves-Unique k₁ v₁ (merge xs₁ l₂) (merge-preserves-Unique xs₁ l₂ u₂) merge-preserves-Unique ((k₁ , v₁) xs₁) l₂ u₂ =
insert-preserves-Unique k₁ v₁ (merge xs₁ l₂)
(merge-preserves-Unique xs₁ l₂ u₂)
insert-preserves-other-keys : (k k' : A) (v v' : B) (l : List (A × B)) ¬ k k' (k , v) l (k , v) insert k' v' l insert-preserves-other-keys : (k k' : A) (v v' : B) (l : List (A × B))
insert-preserves-other-keys k k' v v' (x xs) k≢k' (here k,v=x) rewrite sym k,v=x with ≡-dec-A k' k ¬ k k' (k , v) l (k , v) insert k' v' l
insert-preserves-other-keys k k' v v' (x xs) k≢k' (here k,v=x)
rewrite sym k,v=x with ≡-dec-A k' k
... | yes k'≡k = absurd (k≢k' (sym k'≡k)) ... | yes k'≡k = absurd (k≢k' (sym k'≡k))
... | no _ = here refl ... | no _ = here refl
insert-preserves-other-keys k k' v v' ((k'' , _) xs) k≢k' (there k,v∈xs) with ≡-dec-A k' k'' insert-preserves-other-keys k k' v v' ((k'' , _) xs) k≢k' (there k,v∈xs)
with ≡-dec-A k' k''
... | yes _ = there k,v∈xs ... | yes _ = there k,v∈xs
... | no _ = there (insert-preserves-other-keys k k' v v' xs k≢k' k,v∈xs) ... | no _ = there (insert-preserves-other-keys k k' v v' xs k≢k' k,v∈xs)
merge-preserves-keys₁ : (k : A) (v : B) (l₁ l₂ : List (A × B)) ¬ k ∈k l₁ (k , v) l₂ (k , v) merge l₁ l₂ merge-preserves-keys₁ : (k : A) (v : B) (l₁ l₂ : List (A × B))
¬ k ∈k l₁ (k , v) l₂ (k , v) merge l₁ l₂
merge-preserves-keys₁ k v [] l₂ _ k,v∈l₂ = k,v∈l₂ merge-preserves-keys₁ k v [] l₂ _ k,v∈l₂ = k,v∈l₂
merge-preserves-keys₁ k v ((k' , v') xs₁) l₂ k∉kl₁ k,v∈l₂ = merge-preserves-keys₁ k v ((k' , v') xs₁) l₂ k∉kl₁ k,v∈l₂ =
let recursion = merge-preserves-keys₁ k v xs₁ l₂ (λ k∈xs₁ k∉kl₁ (there k∈xs₁)) k,v∈l₂ let recursion = merge-preserves-keys₁ k v xs₁ l₂ (λ k∈xs₁ k∉kl₁ (there k∈xs₁)) k,v∈l₂
in insert-preserves-other-keys k k' v v' _ (λ k≡k' k∉kl₁ (here k≡k')) recursion in insert-preserves-other-keys k k' v v' _ (λ k≡k' k∉kl₁ (here k≡k')) recursion
insert-preserves-other-key : (k : A) (v : B) (l : List (A × B)) ¬ k ∈k l (k , v) insert k v l insert-preserves-other-key : (k : A) (v : B) (l : List (A × B))
¬ k ∈k l (k , v) insert k v l
insert-preserves-other-key k v [] k∉kl = here refl insert-preserves-other-key k v [] k∉kl = here refl
insert-preserves-other-key k v ((k' , v') xs) k∉kl with ≡-dec-A k k' insert-preserves-other-key k v ((k' , v') xs) k∉kl
with ≡-dec-A k k'
... | yes k≡k' = absurd (k∉kl (here k≡k')) ... | yes k≡k' = absurd (k∉kl (here k≡k'))
... | no _ = there (insert-preserves-other-key k v xs (λ k∈kxs k∉kl (there k∈kxs))) ... | no _ = there (insert-preserves-other-key k v xs (λ k∈kxs k∉kl (there k∈kxs)))
∈-cong : {c d} {C : Set c} {D : Set d} {c : C} {l : List C} (f : C D) c l f c map f l
∈-cong f (here c≡c') = here (cong f c≡c')
∈-cong f (there c∈xs) = there (∈-cong f c∈xs)
-- prove that ¬ k ∈k m → (k , v) ∈ insert k v m -- prove that ¬ k ∈k m → (k , v) ∈ insert k v m
merge-preserves-keys₂ : (k : A) (v : B) (l₁ l₂ : List (A × B)) Unique (keys l₁) (k , v) l₁ ¬ k ∈k l₂ (k , v) merge l₁ l₂ merge-preserves-keys₂ : (k : A) (v : B) (l₁ l₂ : List (A × B))
Unique (keys l₁) (k , v) l₁ ¬ k ∈k l₂ (k , v) merge l₁ l₂
merge-preserves-keys₂ k v ((k' , v') xs₁) l₂ (push k'≢xs₁ uxs₁) (here _) k∉kl₂ = {!!} -- hard! merge-preserves-keys₂ k v ((k' , v') xs₁) l₂ (push k'≢xs₁ uxs₁) (here _) k∉kl₂ = {!!} -- hard!
-- where -- where
-- rest : ∀ (l l' : List (A × B)) → All (λ k'' → ¬ k ≡ k'') (keys l) → ¬ k ∈k l' → ¬ k ∈k merge l l' -- rest : ∀ (l l' : List (A × B)) → All (λ k'' → ¬ k ≡ k'') (keys l) → ¬ k ∈k l' → ¬ k ∈k merge l l'