summaryrefslogtreecommitdiff
path: root/Precond.agda
diff options
context:
space:
mode:
Diffstat (limited to 'Precond.agda')
-rw-r--r--Precond.agda81
1 files changed, 41 insertions, 40 deletions
diff --git a/Precond.agda b/Precond.agda
index ebb5412..bc619dc 100644
--- a/Precond.agda
+++ b/Precond.agda
@@ -18,7 +18,7 @@ import Data.List.All
open import Data.List.Any using (here ; there)
open Data.List.Any.Membership-≡ using (_∉_)
open import Data.Maybe using (just)
-open import Data.Product using (∃ ; _,_ ; proj₂)
+open import Data.Product using (∃ ; _,_ ; proj₁ ; proj₂)
open import Function using (flip ; _∘_ ; id)
open import Relation.Binary using (Setoid)
open import Relation.Binary.PropositionalEquality using (refl ; cong ; inspect ; [_] ; sym ; decSetoid)
@@ -26,70 +26,71 @@ open Relation.Binary.PropositionalEquality.≡-Reasoning using (begin_ ; _≡⟨
open import Relation.Nullary using (yes ; no)
open import Generic using (mapMV ; sequenceV ; sequence-map)
-open import FinMap using (FinMapMaybe ; lookupM ; union ; fromFunc ; empty ; insert ; lemma-lookupM-empty ; delete-many ; lemma-tabulate-∘ ; delete ; lemma-lookupM-delete)
+open import FinMap using (FinMapMaybe ; lookupM ; union ; fromFunc ; empty ; insert ; lemma-lookupM-empty ; delete-many ; lemma-tabulate-∘ ; delete ; lemma-lookupM-delete ; lemma-lookupM-fromFunc ; reshape ; lemma-reshape-id)
import CheckInsert
open CheckInsert (decSetoid deq) using (checkInsert ; lemma-checkInsert-new ; lemma-lookupM-checkInsert-other)
import BFF
-open import Bidir (decSetoid deq) using (_in-domain-of_ ; lemma-assoc-domain ; lemma-just-sequence)
+import Bidir
+open Bidir (decSetoid deq) using (_in-domain-of_ ; lemma-assoc-domain ; lemma-just-sequence)
import GetTypes
open GetTypes.PartialVecVec using (Get ; module Get)
-open BFF.PartialVecBFF (decSetoid deq) using (assoc ; enumerate ; denumerate ; bff)
-
-lemma-lookup-map-just : {n : ℕ} (f : Fin n) {A : Set} (v : Vec A n) → lookup f (map Maybe.just v) ≡ Maybe.just (lookup f v)
-lemma-lookup-map-just zero (x ∷ xs) = refl
-lemma-lookup-map-just (suc f) (x ∷ xs) = lemma-lookup-map-just f xs
+open BFF.PartialVecBFF (decSetoid deq) using (assoc ; enumerate ; denumerate ; bff ; enumeratel)
lemma-maybe-just : {A : Set} → (a : A) → (ma : Maybe A) → maybe′ Maybe.just (just a) ma ≡ Maybe.just (maybe′ id a ma)
lemma-maybe-just a (just x) = refl
lemma-maybe-just a nothing = refl
-lemma-union-delete-fromFunc : {m n : ℕ} {A : Set} {is : Vec (Fin n) m} {h : FinMapMaybe n A} {g : Vec A n} → (toList is) in-domain-of h → ∃ λ v → union h (delete-many is (map just g)) ≡ map just v
+lemma-union-delete-fromFunc : {m n : ℕ} {A : Set} {is : Vec (Fin n) m} {h : FinMapMaybe n A} {g : Fin n → A} → (toList is) in-domain-of h → ∃ λ v → union h (delete-many is (fromFunc g)) ≡ fromFunc v
lemma-union-delete-fromFunc {is = []} {h = h} {g = g} p = _ , (begin
- union h (map just g)
+ union h (fromFunc g)
≡⟨ lemma-tabulate-∘ (λ f → begin
- maybe′ just (lookup f (map just g)) (lookup f h)
- ≡⟨ cong (flip (maybe′ just) (lookup f h)) (lemma-lookup-map-just f g) ⟩
- maybe′ just (just (lookup f g)) (lookup f h)
- ≡⟨ lemma-maybe-just (lookup f g) (lookup f h) ⟩
- just (maybe′ id (lookup f g) (lookup f h)) ∎) ⟩
- tabulate (λ f → just (maybe′ id (lookup f g) (lookup f h)))
- ≡⟨ tabulate-∘ just (λ f → maybe′ id (lookup f g) (lookup f h)) ⟩
- map just (tabulate (λ f → maybe′ id (lookup f g) (lookup f h))) ∎)
-lemma-union-delete-fromFunc {n = n} {is = i ∷ is} {h = h} {g = g} ((x , px) Data.List.All.∷ ps) = _ , (begin
- union h (delete i (delete-many is (map just g)))
+ maybe′ just (lookupM f (fromFunc g)) (lookupM f h)
+ ≡⟨ cong (flip (maybe′ just) (lookupM f h)) (lemma-lookupM-fromFunc g f) ⟩
+ maybe′ just (just (g f)) (lookupM f h)
+ ≡⟨ lemma-maybe-just (g f) (lookupM f h) ⟩
+ just (maybe′ id (g f) (lookupM f h)) ∎) ⟩
+ tabulate (λ f → just (maybe′ id (g f) (lookup f h)))
+ ≡⟨ tabulate-∘ just (λ f → maybe′ id (g f) (lookup f h)) ⟩
+ map just (tabulate (λ f → maybe′ id (g f) (lookup f h))) ∎)
+lemma-union-delete-fromFunc {n = n} {is = i ∷ is} {h = h} {g = g} (Data.List.All._∷_ (x , px) ps) = _ , (begin
+ union h (delete i (delete-many is (fromFunc g)))
≡⟨ lemma-tabulate-∘ inner ⟩
- union h (delete-many is (map just g))
+ union h (delete-many is (fromFunc g))
≡⟨ proj₂ (lemma-union-delete-fromFunc ps) ⟩
map just _ ∎)
- where inner : (f : Fin n) → maybe′ just (lookupM f (delete i (delete-many is (map just g)))) (lookup f h) ≡ maybe′ just (lookupM f (delete-many is (map just g))) (lookup f h)
+ where inner : (f : Fin n) → maybe′ just (lookupM f (delete i (delete-many is (fromFunc g)))) (lookup f h) ≡ maybe′ just (lookupM f (delete-many is (fromFunc g))) (lookup f h)
inner f with f ≟ i
inner .i | yes refl = begin
- maybe′ just (lookupM i (delete i (delete-many is (map just g)))) (lookup i h)
+ maybe′ just (lookupM i (delete i (delete-many is (fromFunc g)))) (lookup i h)
≡⟨ cong (maybe′ just _) px ⟩
just x
≡⟨ cong (maybe′ just _) (sym px) ⟩
- maybe′ just (lookupM i (delete-many is (map just g))) (lookup i h) ∎
- inner f | no f≢i = cong (flip (maybe′ just) (lookup f h)) (lemma-lookupM-delete (delete-many is (map just g)) f≢i)
+ maybe′ just (lookupM i (delete-many is (fromFunc g))) (lookup i h) ∎
+ inner f | no f≢i = cong (flip (maybe′ just) (lookup f h)) (lemma-lookupM-delete (delete-many is (fromFunc g)) f≢i)
-assoc-enough : (G : Get) → {i : Get.|I| G} → (s : Vec Carrier (Get.|gl₁| G i)) → (v : Vec Carrier (Get.|gl₂| G i)) → ∃ (λ h → assoc (Get.get G (enumerate s)) v ≡ just h) → ∃ λ u → bff G s v ≡ just u
-assoc-enough G s v (h , p) = let w , pw = lemma-union-delete-fromFunc (lemma-assoc-domain (get s′) v h p) in _ , (begin
- bff G s v
- ≡⟨ cong (flip _>>=_ (flip mapMV s′ ∘ flip lookupM) ∘ _<$>_ (flip union g′)) p ⟩
- mapMV (flip lookupM (union h g′)) s′
- ≡⟨ sym (sequence-map (flip lookupM (union h g′)) s′) ⟩
- sequenceV (map (flip lookupM (union h g′)) s′)
- ≡⟨ cong (sequenceV ∘ flip map s′ ∘ flip lookupM) pw ⟩
- sequenceV (map (flip lookupM (map just w)) s′)
- ≡⟨ cong sequenceV (map-cong (λ f → lemma-lookup-map-just f w) s′) ⟩
- sequenceV (map (Maybe.just ∘ flip lookup w) s′)
- ≡⟨ cong sequenceV (map-∘ just (flip lookup w) s′) ⟩
- sequenceV (map Maybe.just (map (flip lookup w) s′))
- ≡⟨ lemma-just-sequence (map (flip lookup w) s′) ⟩
- just (map (flip lookup w) s′) ∎)
+assoc-enough : (G : Get) → {i : Get.|I| G} → (s : Vec Carrier (Get.|gl₁| G i)) → (v : Vec Carrier (Get.|gl₂| G i)) → ∃ (λ h → assoc (Get.get G (enumerate s)) v ≡ just h) → ∃ λ u → bff G i s v ≡ just u
+assoc-enough G {i} s v (h , p) = _ , (begin
+ bff G i s v
+ ≡⟨ cong (flip _>>=_ (flip mapMV t ∘ flip lookupM) ∘ _<$>_ (flip union (reshape g′ (Get.|gl₁| G i)))) p ⟩
+ mapMV (flip lookupM (union h (reshape g′ (Get.|gl₁| G i)))) t
+ ≡⟨ sym (sequence-map (flip lookupM (union h (reshape g′ (Get.|gl₁| G i)))) t) ⟩
+ sequenceV (map (flip lookupM (union h (reshape g′ (Get.|gl₁| G i)))) t)
+ ≡⟨ cong (sequenceV ∘ flip map t ∘ flip lookupM ∘ union h) (lemma-reshape-id g′) ⟩
+ sequenceV (map (flip lookupM (union h g′)) t)
+ ≡⟨ cong (sequenceV ∘ flip map t ∘ flip lookupM) (proj₂ wp) ⟩
+ sequenceV (map (flip lookupM (fromFunc (proj₁ wp))) t)
+ ≡⟨ cong sequenceV (map-cong (lemma-lookupM-fromFunc (proj₁ wp)) t) ⟩
+ sequenceV (map (Maybe.just ∘ proj₁ wp) t)
+ ≡⟨ cong sequenceV (map-∘ just (proj₁ wp) t) ⟩
+ sequenceV (map Maybe.just (map (proj₁ wp) t))
+ ≡⟨ lemma-just-sequence (map (proj₁ wp) t) ⟩
+ just (map (proj₁ wp) t) ∎)
where open Get G
s′ = enumerate s
g = fromFunc (denumerate s)
g′ = delete-many (get s′) g
+ t = enumeratel (Get.|gl₁| G i)
+ wp = lemma-union-delete-fromFunc (lemma-assoc-domain (get t) v h p)
data All-different {A : Set} : List A → Set where
different-[] : All-different []