summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BFF.agda55
-rw-r--r--Bidir.agda167
-rw-r--r--CheckInsert.agda97
-rw-r--r--Precond.agda44
4 files changed, 186 insertions, 177 deletions
diff --git a/BFF.agda b/BFF.agda
index 612c2c3..2888a3d 100644
--- a/BFF.agda
+++ b/BFF.agda
@@ -6,9 +6,10 @@ open import Data.Maybe using (Maybe ; just ; nothing ; maybe′)
open import Data.List using (List ; [] ; _∷_ ; map ; length)
open import Data.Vec using (Vec ; toList ; fromList ; tabulate ; allFin) renaming (lookup to lookupV ; map to mapV ; [] to []V ; _∷_ to _∷V_)
open import Function using (id ; _∘_ ; flip)
+open import Relation.Binary.Core using (Decidable ; _≡_)
open import FinMap
-open import CheckInsert
+import CheckInsert
import FreeTheorems
_>>=_ : {A B : Set} → Maybe A → (A → Maybe B) → Maybe B
@@ -17,43 +18,45 @@ _>>=_ = flip (flip maybe′ nothing)
fmap : {A B : Set} → (A → B) → Maybe A → Maybe B
fmap f = maybe′ (λ a → just (f a)) nothing
-module ListBFF where
+module ListBFF (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where
open FreeTheorems.ListList public using (get-type)
+ open CheckInsert Carrier deq
- assoc : {A : Set} {n : ℕ} → EqInst A → List (Fin n) → List A → Maybe (FinMapMaybe n A)
- assoc _ [] [] = just empty
- assoc eq (i ∷ is) (b ∷ bs) = (assoc eq is bs) >>= (checkInsert eq i b)
- assoc _ _ _ = nothing
+ assoc : {n : ℕ} → List (Fin n) → List Carrier → Maybe (FinMapMaybe n Carrier)
+ assoc [] [] = just empty
+ assoc (i ∷ is) (b ∷ bs) = (assoc is bs) >>= (checkInsert i b)
+ assoc _ _ = nothing
- enumerate : {A : Set} → (l : List A) → List (Fin (length l))
+ enumerate : (l : List Carrier) → List (Fin (length l))
enumerate l = toList (tabulate id)
- denumerate : {A : Set} (l : List A) → Fin (length l) → A
+ denumerate : (l : List Carrier) → Fin (length l) → Carrier
denumerate l = flip lookupV (fromList l)
- bff : get-type → ({B : Set} → EqInst B → List B → List B → Maybe (List B))
- bff get eq s v = let s′ = enumerate s
- g = fromFunc (denumerate s)
- h = assoc eq (get s′) v
- h′ = fmap (flip union g) h
- in fmap (flip map s′ ∘ flip lookup) h′
+ bff : get-type → (List Carrier → List Carrier → Maybe (List Carrier))
+ bff get s v = let s′ = enumerate s
+ g = fromFunc (denumerate s)
+ h = assoc (get s′) v
+ h′ = fmap (flip union g) h
+ in fmap (flip map s′ ∘ flip lookup) h′
-module VecBFF where
+module VecBFF (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where
open FreeTheorems.VecVec public using (get-type)
+ open CheckInsert Carrier deq
- assoc : {A : Set} {n m : ℕ} → EqInst A → Vec (Fin n) m → Vec A m → Maybe (FinMapMaybe n A)
- assoc _ []V []V = just empty
- assoc eq (i ∷V is) (b ∷V bs) = (assoc eq is bs) >>= (checkInsert eq i b)
+ assoc : {n m : ℕ} → Vec (Fin n) m → Vec Carrier m → Maybe (FinMapMaybe n Carrier)
+ assoc []V []V = just empty
+ assoc (i ∷V is) (b ∷V bs) = (assoc is bs) >>= (checkInsert i b)
- enumerate : {A : Set} {n : ℕ} → Vec A n → Vec (Fin n) n
+ enumerate : {n : ℕ} → Vec Carrier n → Vec (Fin n) n
enumerate _ = tabulate id
- denumerate : {A : Set} {n : ℕ} → Vec A n → Fin n → A
+ denumerate : {n : ℕ} → Vec Carrier n → Fin n → Carrier
denumerate = flip lookupV
- bff : {getlen : ℕ → ℕ} → (get-type getlen) → ({B : Set} {n : ℕ} → EqInst B → Vec B n → Vec B (getlen n) → Maybe (Vec B n))
- bff get eq s v = let s′ = enumerate s
- g = fromFunc (denumerate s)
- h = assoc eq (get s′) v
- h′ = fmap (flip union g) h
- in fmap (flip mapV s′ ∘ flip lookupV) h′
+ bff : {getlen : ℕ → ℕ} → (get-type getlen) → ({n : ℕ} → Vec Carrier n → Vec Carrier (getlen n) → Maybe (Vec Carrier n))
+ bff get s v = let s′ = enumerate s
+ g = fromFunc (denumerate s)
+ h = assoc (get s′) v
+ h′ = fmap (flip union g) h
+ in fmap (flip mapV s′ ∘ flip lookupV) h′
diff --git a/Bidir.agda b/Bidir.agda
index 2567d8f..437dccf 100644
--- a/Bidir.agda
+++ b/Bidir.agda
@@ -1,4 +1,6 @@
-module Bidir where
+open import Relation.Binary.Core using (Decidable ; _≡_)
+
+module Bidir (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
@@ -15,142 +17,143 @@ open import Data.Empty using (⊥-elim)
open import Function using (id ; _∘_ ; flip)
open import Relation.Nullary using (yes ; no)
open import Relation.Nullary.Negation using (contradiction)
-open import Relation.Binary.Core using (_≡_ ; refl)
+open import Relation.Binary.Core using (refl)
open import Relation.Binary.PropositionalEquality using (cong ; sym ; inspect ; [_] ; _≗_ ; trans)
open Relation.Binary.PropositionalEquality.≡-Reasoning using (begin_ ; _≡⟨_⟩_ ; _∎)
import FreeTheorems
open FreeTheorems.VecVec using (get-type ; free-theorem)
open import FinMap
-open import CheckInsert
+import CheckInsert
+open CheckInsert Carrier deq
open import BFF using (_>>=_ ; fmap)
-open BFF.VecBFF using (assoc ; enumerate ; denumerate ; bff)
+open BFF.VecBFF Carrier deq using (assoc ; enumerate ; denumerate ; bff)
-lemma-1 : {τ : Set} {m n : ℕ} → (eq : EqInst τ) → (f : Fin n → τ) → (is : Vec (Fin n) m) → assoc eq is (map f is) ≡ just (restrict f (toList is))
-lemma-1 eq f [] = refl
-lemma-1 eq f (i ∷ is′) = begin
- assoc eq (i ∷ is′) (map f (i ∷ is′))
+lemma-1 : {m n : ℕ} → (f : Fin n → Carrier) → (is : Vec (Fin n) m) → assoc is (map f is) ≡ just (restrict f (toList is))
+lemma-1 f [] = refl
+lemma-1 f (i ∷ is′) = begin
+ assoc (i ∷ is′) (map f (i ∷ is′))
≡⟨ refl ⟩
- assoc eq is′ (map f is′) >>= checkInsert eq i (f i)
- ≡⟨ cong (λ m → m >>= checkInsert eq i (f i)) (lemma-1 eq f is′) ⟩
- just (restrict f (toList is′)) >>= (checkInsert eq i (f i))
+ assoc is′ (map f is′) >>= checkInsert i (f i)
+ ≡⟨ cong (λ m → m >>= checkInsert i (f i)) (lemma-1 f is′) ⟩
+ just (restrict f (toList is′)) >>= (checkInsert i (f i))
≡⟨ refl ⟩
- checkInsert eq i (f i) (restrict f (toList is′))
- ≡⟨ lemma-checkInsert-restrict eq f i (toList is′) ⟩
+ checkInsert i (f i) (restrict f (toList is′))
+ ≡⟨ lemma-checkInsert-restrict f i (toList is′) ⟩
just (restrict f (toList (i ∷ is′))) ∎
-lemma-lookupM-assoc : {A : Set} {m n : ℕ} → (eq : EqInst A) → (i : Fin n) → (is : Vec (Fin n) m) → (x : A) → (xs : Vec A m) → (h : FinMapMaybe n A) → assoc eq (i ∷ is) (x ∷ xs) ≡ just h → lookupM i h ≡ just x
-lemma-lookupM-assoc eq i is x xs h p with assoc eq is xs
-lemma-lookupM-assoc eq i is x xs h () | nothing
-lemma-lookupM-assoc eq i is x xs h p | just h' = apply-checkInsertProof eq i x h' record
+lemma-lookupM-assoc : {m n : ℕ} → (i : Fin n) → (is : Vec (Fin n) m) → (x : Carrier) → (xs : Vec Carrier m) → (h : FinMapMaybe n Carrier) → assoc (i ∷ is) (x ∷ xs) ≡ just h → lookupM i h ≡ just x
+lemma-lookupM-assoc i is x xs h p with assoc is xs
+lemma-lookupM-assoc i is x xs h () | nothing
+lemma-lookupM-assoc i is x xs h p | just h' = apply-checkInsertProof i x h' record
{ same = λ lookupM≡justx → begin
lookupM i h
- ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym p) (lemma-checkInsert-same eq i x h' lookupM≡justx))) ⟩
+ ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym p) (lemma-checkInsert-same i x h' lookupM≡justx))) ⟩
lookupM i h'
≡⟨ lookupM≡justx ⟩
just x ∎
; new = λ lookupM≡nothing → begin
lookupM i h
- ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym p) (lemma-checkInsert-new eq i x h' lookupM≡nothing))) ⟩
+ ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym p) (lemma-checkInsert-new i x h' lookupM≡nothing))) ⟩
lookupM i (insert i x h')
≡⟨ lemma-lookupM-insert i x h' ⟩
just x ∎
- ; wrong = λ x' x≢x' lookupM≡justx' → lemma-just≢nothing (trans (sym p) (lemma-checkInsert-wrong eq i x h' x' x≢x' lookupM≡justx'))
+ ; wrong = λ x' x≢x' lookupM≡justx' → lemma-just≢nothing (trans (sym p) (lemma-checkInsert-wrong i x h' x' x≢x' lookupM≡justx'))
}
-lemma-∉-lookupM-assoc : {A : Set} {m n : ℕ} → (eq : EqInst A) → (i : Fin n) → (is : Vec (Fin n) m) → (xs : Vec A m) → (h : FinMapMaybe n A) → assoc eq is xs ≡ just h → (i ∉ toList is) → lookupM i h ≡ nothing
-lemma-∉-lookupM-assoc eq i [] [] h ph i∉is = begin
+lemma-∉-lookupM-assoc : {m n : ℕ} → (i : Fin n) → (is : Vec (Fin n) m) → (xs : Vec Carrier m) → (h : FinMapMaybe n Carrier) → assoc is xs ≡ just h → (i ∉ toList is) → lookupM i h ≡ nothing
+lemma-∉-lookupM-assoc i [] [] h ph i∉is = begin
lookupM i h
≡⟨ cong (lookupM i) (sym (lemma-from-just ph)) ⟩
lookupM i empty
≡⟨ lemma-lookupM-empty i ⟩
nothing ∎
-lemma-∉-lookupM-assoc eq i (i' ∷ is') (x' ∷ xs') h ph i∉is with assoc eq is' xs' | inspect (assoc eq is') xs'
-lemma-∉-lookupM-assoc eq i (i' ∷ is') (x' ∷ xs') h () i∉is | nothing | [ ph' ]
-lemma-∉-lookupM-assoc eq i (i' ∷ is') (x' ∷ xs') h ph i∉is | just h' | [ ph' ] = apply-checkInsertProof eq i' x' h' record {
+lemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') h ph i∉is with assoc is' xs' | inspect (assoc is') xs'
+lemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') h () i∉is | nothing | [ ph' ]
+lemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') h ph i∉is | just h' | [ ph' ] = apply-checkInsertProof i' x' h' record {
same = λ lookupM-i'-h'≡just-x' → begin
lookupM i h
- ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym ph) (lemma-checkInsert-same eq i' x' h' lookupM-i'-h'≡just-x'))) ⟩
+ ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym ph) (lemma-checkInsert-same i' x' h' lookupM-i'-h'≡just-x'))) ⟩
lookupM i h'
- ≡⟨ lemma-∉-lookupM-assoc eq i is' xs' h' ph' (i∉is ∘ there) ⟩
+ ≡⟨ lemma-∉-lookupM-assoc i is' xs' h' ph' (i∉is ∘ there) ⟩
nothing ∎
; new = λ lookupM-i'-h'≡nothing → begin
lookupM i h
- ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym ph) (lemma-checkInsert-new eq i' x' h' lookupM-i'-h'≡nothing))) ⟩
+ ≡⟨ cong (lookupM i) (lemma-from-just (trans (sym ph) (lemma-checkInsert-new i' x' h' lookupM-i'-h'≡nothing))) ⟩
lookupM i (insert i' x' h')
≡⟨ sym (lemma-lookupM-insert-other i i' x' h' (i∉is ∘ here)) ⟩
lookupM i h'
- ≡⟨ lemma-∉-lookupM-assoc eq i is' xs' h' ph' (i∉is ∘ there) ⟩
+ ≡⟨ lemma-∉-lookupM-assoc i is' xs' h' ph' (i∉is ∘ there) ⟩
nothing ∎
- ; wrong = λ x'' x'≢x'' lookupM-i'-h'≡just-x'' → lemma-just≢nothing (trans (sym ph) (lemma-checkInsert-wrong eq i' x' h' x'' x'≢x'' lookupM-i'-h'≡just-x''))
+ ; wrong = λ x'' x'≢x'' lookupM-i'-h'≡just-x'' → lemma-just≢nothing (trans (sym ph) (lemma-checkInsert-wrong i' x' h' x'' x'≢x'' lookupM-i'-h'≡just-x''))
}
_in-domain-of_ : {n : ℕ} {A : Set} → (is : List (Fin n)) → (FinMapMaybe n A) → Set
_in-domain-of_ is h = All (λ i → ∃ λ x → lookupM i h ≡ just x) is
-lemma-assoc-domain : {m n : ℕ} {A : Set} → (eq : EqInst A) → (is : Vec (Fin n) m) → (xs : Vec A m) → (h : FinMapMaybe n A) → assoc eq is xs ≡ just h → (toList is) in-domain-of h
-lemma-assoc-domain eq [] [] h ph = Data.List.All.[]
-lemma-assoc-domain eq (i' ∷ is') (x' ∷ xs') h ph with assoc eq is' xs' | inspect (assoc eq is') xs'
-lemma-assoc-domain eq (i' ∷ is') (x' ∷ xs') h () | nothing | [ ph' ]
-lemma-assoc-domain eq (i' ∷ is') (x' ∷ xs') h ph | just h' | [ ph' ] = apply-checkInsertProof eq i' x' h' record {
+lemma-assoc-domain : {m n : ℕ} → (is : Vec (Fin n) m) → (xs : Vec Carrier m) → (h : FinMapMaybe n Carrier) → assoc is xs ≡ just h → (toList is) in-domain-of h
+lemma-assoc-domain [] [] h ph = Data.List.All.[]
+lemma-assoc-domain (i' ∷ is') (x' ∷ xs') h ph with assoc is' xs' | inspect (assoc is') xs'
+lemma-assoc-domain (i' ∷ is') (x' ∷ xs') h () | nothing | [ ph' ]
+lemma-assoc-domain (i' ∷ is') (x' ∷ xs') h ph | just h' | [ ph' ] = apply-checkInsertProof i' x' h' record {
same = λ lookupM-i'-h'≡just-x' → Data.List.All._∷_
- (x' , (trans (cong (lookupM i') (lemma-from-just (trans (sym ph) (lemma-checkInsert-same eq i' x' h' lookupM-i'-h'≡just-x')))) lookupM-i'-h'≡just-x'))
- (lemma-assoc-domain eq is' xs' h (trans ph' (trans (sym (lemma-checkInsert-same eq i' x' h' lookupM-i'-h'≡just-x')) ph)))
+ (x' , (trans (cong (lookupM i') (lemma-from-just (trans (sym ph) (lemma-checkInsert-same i' x' h' lookupM-i'-h'≡just-x')))) lookupM-i'-h'≡just-x'))
+ (lemma-assoc-domain is' xs' h (trans ph' (trans (sym (lemma-checkInsert-same i' x' h' lookupM-i'-h'≡just-x')) ph)))
; new = λ lookupM-i'-h'≡nothing → Data.List.All._∷_
- (x' , (trans (cong (lookupM i') (lemma-from-just (trans (sym ph) (lemma-checkInsert-new eq i' x' h' lookupM-i'-h'≡nothing)))) (lemma-lookupM-insert i' x' h')))
+ (x' , (trans (cong (lookupM i') (lemma-from-just (trans (sym ph) (lemma-checkInsert-new i' x' h' lookupM-i'-h'≡nothing)))) (lemma-lookupM-insert i' x' h')))
(Data.List.All.map
- (λ {i} p → proj₁ p , lemma-lookupM-checkInsert eq i i' (proj₁ p) x' h' h (proj₂ p) ph)
- (lemma-assoc-domain eq is' xs' h' ph'))
- ; wrong = λ x'' x'≢x'' lookupM-i'-h'≡just-x'' → lemma-just≢nothing (trans (sym ph) (lemma-checkInsert-wrong eq i' x' h' x'' x'≢x'' lookupM-i'-h'≡just-x''))
+ (λ {i} p → proj₁ p , lemma-lookupM-checkInsert i i' (proj₁ p) x' h' h (proj₂ p) ph)
+ (lemma-assoc-domain is' xs' h' ph'))
+ ; wrong = λ x'' x'≢x'' lookupM-i'-h'≡just-x'' → lemma-just≢nothing (trans (sym ph) (lemma-checkInsert-wrong i' x' h' x'' x'≢x'' lookupM-i'-h'≡just-x''))
}
-lemma-map-lookupM-insert : {m n : ℕ} {A : Set} → (eq : EqInst A) → (i : Fin n) → (is : Vec (Fin n) m) → (x : A) → (h : FinMapMaybe n A) → i ∉ (toList is) → (toList is) in-domain-of h → map (flip lookupM (insert i x h)) is ≡ map (flip lookupM h) is
-lemma-map-lookupM-insert eq i [] x h i∉is ph = refl
-lemma-map-lookupM-insert eq i (i' ∷ is') x h i∉is ph = begin
+lemma-map-lookupM-insert : {m n : ℕ} → (i : Fin n) → (is : Vec (Fin n) m) → (x : Carrier) → (h : FinMapMaybe n Carrier) → i ∉ (toList is) → (toList is) in-domain-of h → map (flip lookupM (insert i x h)) is ≡ map (flip lookupM h) is
+lemma-map-lookupM-insert i [] x h i∉is ph = refl
+lemma-map-lookupM-insert i (i' ∷ is') x h i∉is ph = begin
lookupM i' (insert i x h) ∷ map (flip lookupM (insert i x h)) is'
≡⟨ cong (flip _∷_ (map (flip lookupM (insert i x h)) is')) (sym (lemma-lookupM-insert-other i' i x h (i∉is ∘ here ∘ sym))) ⟩
lookupM i' h ∷ map (flip lookupM (insert i x h)) is'
- ≡⟨ cong (_∷_ (lookupM i' h)) (lemma-map-lookupM-insert eq i is' x h (i∉is ∘ there) (Data.List.All.tail ph)) ⟩
+ ≡⟨ cong (_∷_ (lookupM i' h)) (lemma-map-lookupM-insert i is' x h (i∉is ∘ there) (Data.List.All.tail ph)) ⟩
lookupM i' h ∷ map (flip lookupM h) is' ∎
-lemma-map-lookupM-assoc : {m n : ℕ} {A : Set} → (eq : EqInst A) → (i : Fin n) → (is : Vec (Fin n) m) → (x : A) → (xs : Vec A m) → (h : FinMapMaybe n A) → (h' : FinMapMaybe n A) → assoc eq is xs ≡ just h' → checkInsert eq i x h' ≡ just h → map (flip lookupM h) is ≡ map (flip lookupM h') is
-lemma-map-lookupM-assoc eq i [] x [] h h' ph' ph = refl
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' ph with any (_≟_ i) (toList (i' ∷ is'))
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p with Data.List.All.lookup (lemma-assoc-domain eq (i' ∷ is') (x' ∷ xs') h' ph') p
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p | (x'' , p') with lookupM i h'
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p | (x'' , refl) | .(just x'') with eq x x''
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h .h ph' refl | yes p | (.x , refl) | .(just x) | yes refl = refl
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' () | yes p | (x'' , refl) | .(just x'') | no ¬p
-lemma-map-lookupM-assoc eq i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | no ¬p rewrite lemma-∉-lookupM-assoc eq i (i' ∷ is') (x' ∷ xs') h' ph' ¬p = begin
+lemma-map-lookupM-assoc : {m n : ℕ} → (i : Fin n) → (is : Vec (Fin n) m) → (x : Carrier) → (xs : Vec Carrier m) → (h : FinMapMaybe n Carrier) → (h' : FinMapMaybe n Carrier) → assoc is xs ≡ just h' → checkInsert i x h' ≡ just h → map (flip lookupM h) is ≡ map (flip lookupM h') is
+lemma-map-lookupM-assoc i [] x [] h h' ph' ph = refl
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' ph with any (_≟_ i) (toList (i' ∷ is'))
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p with Data.List.All.lookup (lemma-assoc-domain (i' ∷ is') (x' ∷ xs') h' ph') p
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p | (x'' , p') with lookupM i h'
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | yes p | (x'' , refl) | .(just x'') with deq x x''
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h .h ph' refl | yes p | (.x , refl) | .(just x) | yes refl = refl
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' () | yes p | (x'' , refl) | .(just x'') | no ¬p
+lemma-map-lookupM-assoc i (i' ∷ is') x (x' ∷ xs') h h' ph' ph | no ¬p rewrite lemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') h' ph' ¬p = begin
map (flip lookupM h) (i' ∷ is')
≡⟨ map-cong (λ i'' → cong (lookupM i'') (lemma-from-just (sym ph))) (i' ∷ is') ⟩
map (flip lookupM (insert i x h')) (i' ∷ is')
- ≡⟨ lemma-map-lookupM-insert eq i (i' ∷ is') x h' ¬p (lemma-assoc-domain eq (i' ∷ is') (x' ∷ xs') h' ph') ⟩
+ ≡⟨ lemma-map-lookupM-insert i (i' ∷ is') x h' ¬p (lemma-assoc-domain (i' ∷ is') (x' ∷ xs') h' ph') ⟩
map (flip lookupM h') (i' ∷ is') ∎
-lemma-2 : {τ : Set} {m n : ℕ} → (eq : EqInst τ) → (is : Vec (Fin n) m) → (v : Vec τ m) → (h : FinMapMaybe n τ) → assoc eq is v ≡ just h → map (flip lookupM h) is ≡ map just v
-lemma-2 eq [] [] h p = refl
-lemma-2 eq (i ∷ is) (x ∷ xs) h p with assoc eq is xs | inspect (assoc eq is) xs
-lemma-2 eq (i ∷ is) (x ∷ xs) h () | nothing | _
-lemma-2 eq (i ∷ is) (x ∷ xs) h p | just h' | [ ir ] = begin
+lemma-2 : {m n : ℕ} → (is : Vec (Fin n) m) → (v : Vec Carrier m) → (h : FinMapMaybe n Carrier) → assoc is v ≡ just h → map (flip lookupM h) is ≡ map just v
+lemma-2 [] [] h p = refl
+lemma-2 (i ∷ is) (x ∷ xs) h p with assoc is xs | inspect (assoc is) xs
+lemma-2 (i ∷ is) (x ∷ xs) h () | nothing | _
+lemma-2 (i ∷ is) (x ∷ xs) h p | just h' | [ ir ] = begin
map (flip lookupM h) (i ∷ is)
≡⟨ refl ⟩
lookupM i h ∷ map (flip lookupM h) is
- ≡⟨ cong (flip _∷_ (map (flip lookupM h) is)) (lemma-lookupM-assoc eq i is x xs h (begin
- assoc eq (i ∷ is) (x ∷ xs)
- ≡⟨ cong (flip _>>=_ (checkInsert eq i x)) ir ⟩
- checkInsert eq i x h'
+ ≡⟨ cong (flip _∷_ (map (flip lookupM h) is)) (lemma-lookupM-assoc i is x xs h (begin
+ assoc (i ∷ is) (x ∷ xs)
+ ≡⟨ cong (flip _>>=_ (checkInsert i x)) ir ⟩
+ checkInsert i x h'
≡⟨ p ⟩
just h ∎) ) ⟩
just x ∷ map (flip lookupM h) is
- ≡⟨ cong (_∷_ (just x)) (lemma-map-lookupM-assoc eq i is x xs h h' ir p) ⟩
+ ≡⟨ cong (_∷_ (just x)) (lemma-map-lookupM-assoc i is x xs h h' ir p) ⟩
just x ∷ map (flip lookupM h') is
- ≡⟨ cong (_∷_ (just x)) (lemma-2 eq is xs h' ir) ⟩
+ ≡⟨ cong (_∷_ (just x)) (lemma-2 is xs h' ir) ⟩
just x ∷ map just xs
≡⟨ refl ⟩
map just (x ∷ xs) ∎
-lemma-map-denumerate-enumerate : {m : ℕ} {A : Set} → (as : Vec A m) → map (denumerate as) (enumerate as) ≡ as
+lemma-map-denumerate-enumerate : {m : ℕ} → (as : Vec Carrier m) → map (denumerate as) (enumerate as) ≡ as
lemma-map-denumerate-enumerate [] = refl
lemma-map-denumerate-enumerate (a ∷ as) = cong (_∷_ a) (begin
map (flip lookupVec (a ∷ as)) (tabulate Fin.suc)
@@ -165,16 +168,16 @@ lemma-map-denumerate-enumerate (a ∷ as) = cong (_∷_ a) (begin
≡⟨ lemma-map-denumerate-enumerate as ⟩
as ∎)
-theorem-1 : {getlen : ℕ → ℕ} → (get : get-type getlen) → {m : ℕ} {τ : Set} → (eq : EqInst τ) → (s : Vec τ m) → bff get eq s (get s) ≡ just s
-theorem-1 get eq s = begin
- bff get eq s (get s)
- ≡⟨ cong (bff get eq s ∘ get) (sym (lemma-map-denumerate-enumerate s)) ⟩
- bff get eq s (get (map (denumerate s) (enumerate s)))
- ≡⟨ cong (bff get eq s) (free-theorem get (denumerate s) (enumerate s)) ⟩
- bff get eq s (map (denumerate s) (get (enumerate s)))
+theorem-1 : {getlen : ℕ → ℕ} → (get : get-type getlen) → {m : ℕ} → (s : Vec Carrier m) → bff get s (get s) ≡ just s
+theorem-1 get s = begin
+ bff get s (get s)
+ ≡⟨ cong (bff get s ∘ get) (sym (lemma-map-denumerate-enumerate s)) ⟩
+ bff get s (get (map (denumerate s) (enumerate s)))
+ ≡⟨ cong (bff get s) (free-theorem get (denumerate s) (enumerate s)) ⟩
+ bff get s (map (denumerate s) (get (enumerate s)))
≡⟨ refl ⟩
- fmap (flip map (enumerate s) ∘ flip lookup) (fmap (flip union (fromFunc (denumerate s))) (assoc eq (get (enumerate s)) (map (denumerate s) (get (enumerate s)))))
- ≡⟨ cong (fmap (flip map (enumerate s) ∘ flip lookup) ∘ fmap (flip union (fromFunc (denumerate s)))) (lemma-1 eq (denumerate s) (get (enumerate s))) ⟩
+ fmap (flip map (enumerate s) ∘ flip lookup) (fmap (flip union (fromFunc (denumerate s))) (assoc (get (enumerate s)) (map (denumerate s) (get (enumerate s)))))
+ ≡⟨ cong (fmap (flip map (enumerate s) ∘ flip lookup) ∘ fmap (flip union (fromFunc (denumerate s)))) (lemma-1 (denumerate s) (get (enumerate s))) ⟩
fmap (flip map (enumerate s) ∘ flip lookup) (fmap (flip union (fromFunc (flip lookupVec s))) (just (restrict (denumerate s) (toList (get (enumerate s))))))
≡⟨ refl ⟩
just ((flip map (enumerate s) ∘ flip lookup) (union (restrict (denumerate s) (toList (get (enumerate s)))) (fromFunc (denumerate s))))
@@ -218,16 +221,16 @@ lemma-union-not-used h h' (i ∷ is') p | x , lookupM-i-h≡just-x = begin
≡⟨ cong (_∷_ (lookupM i h)) (lemma-union-not-used h h' is' (Data.List.All.tail p)) ⟩
lookupM i h ∷ map (flip lookupM h) is' ∎
-theorem-2 : {getlen : ℕ → ℕ} (get : get-type getlen) → {τ : Set} {m : ℕ} → (eq : EqInst τ) → (v : Vec τ (getlen m)) → (s u : Vec τ m) → bff get eq s v ≡ just u → get u ≡ v
-theorem-2 get eq v s u p with lemma-fmap-just (assoc eq (get (enumerate s)) v) (proj₂ (lemma-fmap-just (fmap (flip union (fromFunc (denumerate s))) (assoc eq (get (enumerate s)) v)) p))
-theorem-2 get eq v s u p | h , ph = begin
+theorem-2 : {getlen : ℕ → ℕ} (get : get-type getlen) → {m : ℕ} → (v : Vec Carrier (getlen m)) → (s u : Vec Carrier m) → bff get s v ≡ just u → get u ≡ v
+theorem-2 get v s u p with lemma-fmap-just (assoc (get (enumerate s)) v) (proj₂ (lemma-fmap-just (fmap (flip union (fromFunc (denumerate s))) (assoc (get (enumerate s)) v)) p))
+theorem-2 get v s u p | h , ph = begin
get u
≡⟨ lemma-from-just (begin
just (get u)
≡⟨ refl ⟩
fmap get (just u)
≡⟨ cong (fmap get) (sym p) ⟩
- fmap get (bff get eq s v)
+ fmap get (bff get s v)
≡⟨ cong (fmap get ∘ fmap (flip map (enumerate s) ∘ flip lookup) ∘ fmap (flip union (fromFunc (denumerate s)))) ph ⟩
fmap get (fmap (flip map (enumerate s) ∘ flip lookup) (fmap (flip union (fromFunc (denumerate s))) (just h)))
≡⟨ refl ⟩
@@ -238,9 +241,9 @@ theorem-2 get eq v s u p | h , ph = begin
map (flip lookup (union h (fromFunc (denumerate s)))) (get (enumerate s))
≡⟨ lemma-from-map-just (begin
map just (map (flip lookup (union h (fromFunc (denumerate s)))) (get (enumerate s)))
- ≡⟨ lemma-union-not-used h (fromFunc (denumerate s)) (get (enumerate s)) (lemma-assoc-domain eq (get (enumerate s)) v h ph) ⟩
+ ≡⟨ lemma-union-not-used h (fromFunc (denumerate s)) (get (enumerate s)) (lemma-assoc-domain (get (enumerate s)) v h ph) ⟩
map (flip lookupM h) (get (enumerate s))
- ≡⟨ lemma-2 eq (get (enumerate s)) v h ph ⟩
+ ≡⟨ lemma-2 (get (enumerate s)) v h ph ⟩
map just v
∎) ⟩
v ∎
diff --git a/CheckInsert.agda b/CheckInsert.agda
index 40a57d6..01f1302 100644
--- a/CheckInsert.agda
+++ b/CheckInsert.agda
@@ -1,4 +1,6 @@
-module CheckInsert where
+open import Relation.Binary.Core using (Decidable ; _≡_)
+
+module CheckInsert (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
@@ -7,86 +9,83 @@ open import Data.Maybe using (Maybe ; nothing ; just)
open import Data.List using (List ; [] ; _∷_)
open import Relation.Nullary using (Dec ; yes ; no)
open import Relation.Nullary.Negation using (contradiction)
-open import Relation.Binary.Core using (_≡_ ; refl ; _≢_)
+open import Relation.Binary.Core using (refl ; _≢_)
open import Relation.Binary.PropositionalEquality using (cong ; sym ; inspect ; [_] ; trans)
open Relation.Binary.PropositionalEquality.≡-Reasoning using (begin_ ; _≡⟨_⟩_ ; _∎)
open import FinMap
-EqInst : Set → Set
-EqInst A = (x y : A) → Dec (x ≡ y)
-
-checkInsert : {A : Set} {n : ℕ} → EqInst A → Fin n → A → FinMapMaybe n A → Maybe (FinMapMaybe n A)
-checkInsert eq i b m with lookupM i m
-checkInsert eq i b m | just c with eq b c
-checkInsert eq i b m | just .b | yes refl = just m
-checkInsert eq i b m | just c | no ¬p = nothing
-checkInsert eq i b m | nothing = just (insert i b m)
+checkInsert : {n : ℕ} → Fin n → Carrier → FinMapMaybe n Carrier → Maybe (FinMapMaybe n Carrier)
+checkInsert i b m with lookupM i m
+checkInsert i b m | just c with deq b c
+checkInsert i b m | just .b | yes refl = just m
+checkInsert i b m | just c | no ¬p = nothing
+checkInsert i b m | nothing = just (insert i b m)
-record checkInsertProof {A : Set} {n : ℕ} (eq : EqInst A) (i : Fin n) (x : A) (m : FinMapMaybe n A) (P : Set) : Set where
+record checkInsertProof {n : ℕ} (i : Fin n) (x : Carrier) (m : FinMapMaybe n Carrier) (P : Set) : Set where
field
same : lookupM i m ≡ just x → P
new : lookupM i m ≡ nothing → P
- wrong : (x' : A) → x ≢ x' → lookupM i m ≡ just x' → P
+ wrong : (x' : Carrier) → x ≢ x' → lookupM i m ≡ just x' → P
-apply-checkInsertProof : {A P : Set} {n : ℕ} → (eq : EqInst A) → (i : Fin n) → (x : A) → (m : FinMapMaybe n A) → checkInsertProof eq i x m P → P
-apply-checkInsertProof eq i x m rp with lookupM i m | inspect (lookupM i) m
-apply-checkInsertProof eq i x m rp | just x' | il with eq x x'
-apply-checkInsertProof eq i x m rp | just .x | [ il ] | yes refl = checkInsertProof.same rp il
-apply-checkInsertProof eq i x m rp | just x' | [ il ] | no x≢x' = checkInsertProof.wrong rp x' x≢x' il
-apply-checkInsertProof eq i x m rp | nothing | [ il ] = checkInsertProof.new rp il
+apply-checkInsertProof : {P : Set} {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → checkInsertProof i x m P → P
+apply-checkInsertProof i x m rp with lookupM i m | inspect (lookupM i) m
+apply-checkInsertProof i x m rp | just x' | il with deq x x'
+apply-checkInsertProof i x m rp | just .x | [ il ] | yes refl = checkInsertProof.same rp il
+apply-checkInsertProof i x m rp | just x' | [ il ] | no x≢x' = checkInsertProof.wrong rp x' x≢x' il
+apply-checkInsertProof i x m rp | nothing | [ il ] = checkInsertProof.new rp il
-lemma-checkInsert-same : {A : Set} {n : ℕ} → (eq : EqInst A) → (i : Fin n) → (x : A) → (m : FinMapMaybe n A) → lookupM i m ≡ just x → checkInsert eq i x m ≡ just m
-lemma-checkInsert-same eq i x m p with lookupM i m
-lemma-checkInsert-same eq i x m refl | .(just x) with eq x x
-lemma-checkInsert-same eq i x m refl | .(just x) | yes refl = refl
-lemma-checkInsert-same eq i x m refl | .(just x) | no x≢x = contradiction refl x≢x
+lemma-checkInsert-same : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → lookupM i m ≡ just x → checkInsert i x m ≡ just m
+lemma-checkInsert-same i x m p with lookupM i m
+lemma-checkInsert-same i x m refl | .(just x) with deq x x
+lemma-checkInsert-same i x m refl | .(just x) | yes refl = refl
+lemma-checkInsert-same i x m refl | .(just x) | no x≢x = contradiction refl x≢x
-lemma-checkInsert-new : {A : Set} {n : ℕ} → (eq : EqInst A) → (i : Fin n) → (x : A) → (m : FinMapMaybe n A) → lookupM i m ≡ nothing → checkInsert eq i x m ≡ just (insert i x m)
-lemma-checkInsert-new eq i x m p with lookupM i m
-lemma-checkInsert-new eq i x m refl | .nothing = refl
+lemma-checkInsert-new : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → lookupM i m ≡ nothing → checkInsert i x m ≡ just (insert i x m)
+lemma-checkInsert-new i x m p with lookupM i m
+lemma-checkInsert-new i x m refl | .nothing = refl
-lemma-checkInsert-wrong : {A : Set} {n : ℕ} → (eq : EqInst A) → (i : Fin n) → (x : A) → (m : FinMapMaybe n A) → (x' : A) → x ≢ x' → lookupM i m ≡ just x' → checkInsert eq i x m ≡ nothing
-lemma-checkInsert-wrong eq i x m x' d p with lookupM i m
-lemma-checkInsert-wrong eq i x m x' d refl | .(just x') with eq x x'
-lemma-checkInsert-wrong eq i x m x' d refl | .(just x') | yes q = contradiction q d
-lemma-checkInsert-wrong eq i x m x' d refl | .(just x') | no ¬q = refl
+lemma-checkInsert-wrong : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → (x' : Carrier) → x ≢ x' → lookupM i m ≡ just x' → checkInsert i x m ≡ nothing
+lemma-checkInsert-wrong i x m x' d p with lookupM i m
+lemma-checkInsert-wrong i x m x' d refl | .(just x') with deq x x'
+lemma-checkInsert-wrong i x m x' d refl | .(just x') | yes q = contradiction q d
+lemma-checkInsert-wrong i x m x' d refl | .(just x') | no ¬q = refl
-record checkInsertEqualProof {A : Set} {n : ℕ} (eq : EqInst A) (i : Fin n) (x : A) (m : FinMapMaybe n A) (e : Maybe (FinMapMaybe n A)) : Set where
+record checkInsertEqualProof {n : ℕ} (i : Fin n) (x : Carrier) (m : FinMapMaybe n Carrier) (e : Maybe (FinMapMaybe n Carrier)) : Set where
field
same : lookupM i m ≡ just x → just m ≡ e
new : lookupM i m ≡ nothing → just (insert i x m) ≡ e
- wrong : (x' : A) → x ≢ x' → lookupM i m ≡ just x' → nothing ≡ e
+ wrong : (x' : Carrier) → x ≢ x' → lookupM i m ≡ just x' → nothing ≡ e
-lift-checkInsertProof : {A : Set} {n : ℕ} {eq : EqInst A} {i : Fin n} {x : A} {m : FinMapMaybe n A} {e : Maybe (FinMapMaybe n A)} → checkInsertEqualProof eq i x m e → checkInsertProof eq i x m (checkInsert eq i x m ≡ e)
-lift-checkInsertProof {_} {_} {eq} {i} {x} {m} o = record
- { same = λ p → trans (lemma-checkInsert-same eq i x m p) (checkInsertEqualProof.same o p)
- ; new = λ p → trans (lemma-checkInsert-new eq i x m p) (checkInsertEqualProof.new o p)
- ; wrong = λ x' q p → trans (lemma-checkInsert-wrong eq i x m x' q p) (checkInsertEqualProof.wrong o x' q p)
+lift-checkInsertProof : {n : ℕ} {i : Fin n} {x : Carrier} {m : FinMapMaybe n Carrier} {e : Maybe (FinMapMaybe n Carrier)} → checkInsertEqualProof i x m e → checkInsertProof i x m (checkInsert i x m ≡ e)
+lift-checkInsertProof {_} {i} {x} {m} o = record
+ { same = λ p → trans (lemma-checkInsert-same i x m p) (checkInsertEqualProof.same o p)
+ ; new = λ p → trans (lemma-checkInsert-new i x m p) (checkInsertEqualProof.new o p)
+ ; wrong = λ x' q p → trans (lemma-checkInsert-wrong i x m x' q p) (checkInsertEqualProof.wrong o x' q p)
}
-lemma-checkInsert-restrict : {τ : Set} {n : ℕ} → (eq : EqInst τ) → (f : Fin n → τ) → (i : Fin n) → (is : List (Fin n)) → checkInsert eq i (f i) (restrict f is) ≡ just (restrict f (i ∷ is))
-lemma-checkInsert-restrict {τ} eq f i is = apply-checkInsertProof eq i (f i) (restrict f is) (lift-checkInsertProof record
+lemma-checkInsert-restrict : {n : ℕ} → (f : Fin n → Carrier) → (i : Fin n) → (is : List (Fin n)) → checkInsert i (f i) (restrict f is) ≡ just (restrict f (i ∷ is))
+lemma-checkInsert-restrict f i is = apply-checkInsertProof i (f i) (restrict f is) (lift-checkInsertProof record
{ same = λ lookupM≡justx → cong just (lemma-insert-same (restrict f is) i (f i) lookupM≡justx)
; new = λ lookupM≡nothing → refl
; wrong = λ x' x≢x' lookupM≡justx' → contradiction (lemma-lookupM-restrict i f is x' lookupM≡justx') x≢x'
})
-lemma-lookupM-checkInsert : {A : Set} {n : ℕ} → (eq : EqInst A) → (i j : Fin n) → (x y : A) → (h h' : FinMapMaybe n A) → lookupM i h ≡ just x → checkInsert eq j y h ≡ just h' → lookupM i h' ≡ just x
-lemma-lookupM-checkInsert eq i j x y h h' pl ph' with lookupM j h | inspect (lookupM j) h
-lemma-lookupM-checkInsert eq i j x y h .(insert j y h) pl refl | nothing | pl' with i ≟ j
-lemma-lookupM-checkInsert eq i .i x y h .(insert i y h) pl refl | nothing | [ pl' ] | yes refl = lemma-just≢nothing (begin just x ≡⟨ sym pl ⟩ lookupM i h ≡⟨ pl' ⟩ (nothing ∎))
-lemma-lookupM-checkInsert eq i j x y h .(insert j y h) pl refl | nothing | pl' | no ¬p = begin
+lemma-lookupM-checkInsert : {n : ℕ} → (i j : Fin n) → (x y : Carrier) → (h h' : FinMapMaybe n Carrier) → lookupM i h ≡ just x → checkInsert j y h ≡ just h' → lookupM i h' ≡ just x
+lemma-lookupM-checkInsert i j x y h h' pl ph' with lookupM j h | inspect (lookupM j) h
+lemma-lookupM-checkInsert i j x y h .(insert j y h) pl refl | nothing | pl' with i ≟ j
+lemma-lookupM-checkInsert i .i x y h .(insert i y h) pl refl | nothing | [ pl' ] | yes refl = lemma-just≢nothing (begin just x ≡⟨ sym pl ⟩ lookupM i h ≡⟨ pl' ⟩ (nothing ∎))
+lemma-lookupM-checkInsert i j x y h .(insert j y h) pl refl | nothing | pl' | no ¬p = begin
lookupM i (insert j y h)
≡⟨ sym (lemma-lookupM-insert-other i j y h ¬p) ⟩
lookupM i h
≡⟨ pl ⟩
just x ∎
-lemma-lookupM-checkInsert eq i j x y h h' pl ph' | just z | pl' with eq y z
-lemma-lookupM-checkInsert eq i j x y h h' pl ph' | just .y | pl' | yes refl = begin
+lemma-lookupM-checkInsert i j x y h h' pl ph' | just z | pl' with deq y z
+lemma-lookupM-checkInsert i j x y h h' pl ph' | just .y | pl' | yes refl = begin
lookupM i h'
≡⟨ cong (lookupM i) (lemma-from-just (sym ph')) ⟩
lookupM i h
≡⟨ pl ⟩
just x ∎
-lemma-lookupM-checkInsert eq i j x y h h' pl () | just z | pl' | no ¬p
+lemma-lookupM-checkInsert i j x y h h' pl () | just z | pl' | no ¬p
diff --git a/Precond.agda b/Precond.agda
index 18d6a85..a6d2d37 100644
--- a/Precond.agda
+++ b/Precond.agda
@@ -1,4 +1,6 @@
-module Precond where
+open import Relation.Binary.Core using (Decidable ; _≡_)
+
+module Precond (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where
open import Data.Nat using (ℕ) renaming (zero to nzero ; suc to nsuc)
open import Data.Fin using (Fin ; zero ; suc)
@@ -8,29 +10,31 @@ open Data.List.Any.Membership-≡ using (_∉_)
open import Data.Maybe using (just)
open import Data.Product using (∃ ; _,_)
open import Function using (flip ; _∘_)
-open import Relation.Binary.Core using (_≡_ ; _≢_)
+open import Relation.Binary.Core using (_≢_)
open import Relation.Binary.PropositionalEquality using (refl ; cong)
open Relation.Binary.PropositionalEquality.≡-Reasoning using (begin_ ; _≡⟨_⟩_ ; _∎)
open import FinMap using (FinMap ; FinMapMaybe ; union ; fromFunc ; empty ; insert)
-open import CheckInsert using (EqInst ; checkInsert ; lemma-checkInsert-new)
+import CheckInsert
+open CheckInsert Carrier deq using (checkInsert ; lemma-checkInsert-new)
open import BFF using (fmap ; _>>=_)
-open import Bidir using (lemma-∉-lookupM-assoc)
+import Bidir
+open Bidir Carrier deq using (lemma-∉-lookupM-assoc)
-open BFF.VecBFF using (get-type ; assoc ; enumerate ; denumerate ; bff)
+open BFF.VecBFF Carrier deq using (get-type ; assoc ; enumerate ; denumerate ; bff)
-assoc-enough : {getlen : ℕ → ℕ} (get : get-type getlen) → {B : Set} {m : ℕ} → (eq : EqInst B) → (s : Vec B m) → (v : Vec B (getlen m)) → (h : FinMapMaybe m B) → assoc eq (get (enumerate s)) v ≡ just h → ∃ λ u → bff get eq s v ≡ just u
-assoc-enough get {B} {m} eq s v h p = map (flip lookup (union h g)) s′ , (begin
- bff get eq s v
+assoc-enough : {getlen : ℕ → ℕ} (get : get-type getlen) → {m : ℕ} → (s : Vec Carrier m) → (v : Vec Carrier (getlen m)) → (h : FinMapMaybe m Carrier) → assoc (get (enumerate s)) v ≡ just h → ∃ λ u → bff get s v ≡ just u
+assoc-enough get {m} s v h p = map (flip lookup (union h g)) s′ , (begin
+ bff get s v
≡⟨ refl ⟩
- fmap (flip map s′ ∘ flip lookup) (fmap (flip union g) (assoc eq (get s′) v))
+ fmap (flip map s′ ∘ flip lookup) (fmap (flip union g) (assoc (get s′) v))
≡⟨ cong (fmap (flip map s′ ∘ flip lookup)) (cong (fmap (flip union g)) p) ⟩
fmap (flip map s′ ∘ flip lookup) (fmap (flip union g) (just h))
≡⟨ refl ⟩
just (map (flip lookup (union h g)) s′) ∎)
where s′ : Vec (Fin m) m
s′ = enumerate s
- g : FinMap m B
+ g : FinMap m Carrier
g = fromFunc (denumerate s)
all-different : {A : Set} {n : ℕ} → Vec A n → Set
@@ -58,14 +62,14 @@ different-∉ x [] p ()
different-∉ x (y ∷ ys) p (here px) = p zero (suc zero) (λ ()) px
different-∉ x (y ∷ ys) p (there pxs) = different-∉ x ys (different-drop y (x ∷ ys) (different-swap x y ys p)) pxs
-different-assoc : {B : Set} {m n : ℕ} → (eq : EqInst B) → (u : Vec (Fin n) m) → (v : Vec B m) → all-different u → ∃ λ h → assoc eq u v ≡ just h
-different-assoc eq [] [] p = empty , refl
-different-assoc eq (u ∷ us) (v ∷ vs) p with different-assoc eq us vs (λ i j i≢j → p (suc i) (suc j) (i≢j ∘ suc-injective))
-different-assoc eq (u ∷ us) (v ∷ vs) p | h , p' = insert u v h , (begin
- assoc eq (u ∷ us) (v ∷ vs)
+different-assoc : {m n : ℕ} → (u : Vec (Fin n) m) → (v : Vec Carrier m) → all-different u → ∃ λ h → assoc u v ≡ just h
+different-assoc [] [] p = empty , refl
+different-assoc (u ∷ us) (v ∷ vs) p with different-assoc us vs (λ i j i≢j → p (suc i) (suc j) (i≢j ∘ suc-injective))
+different-assoc (u ∷ us) (v ∷ vs) p | h , p' = insert u v h , (begin
+ assoc (u ∷ us) (v ∷ vs)
≡⟨ refl ⟩
- assoc eq us vs >>= checkInsert eq u v
- ≡⟨ cong (flip _>>=_ (checkInsert eq u v)) p' ⟩
- checkInsert eq u v h
- ≡⟨ lemma-checkInsert-new eq u v h (lemma-∉-lookupM-assoc eq u us vs h p' (different-∉ u us p)) ⟩
- just (insert u v h) ∎) \ No newline at end of file
+ assoc us vs >>= checkInsert u v
+ ≡⟨ cong (flip _>>=_ (checkInsert u v)) p' ⟩
+ checkInsert u v h
+ ≡⟨ lemma-checkInsert-new u v h (lemma-∉-lookupM-assoc u us vs h p' (different-∉ u us p)) ⟩
+ just (insert u v h) ∎)