Debian Codegraph @

src/Data/Vec/Properties/WithK.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Some Vec-related properties that depend on the K rule or make use
5 -- of heterogeneous equality
6 ------------------------------------------------------------------------
7
8 {-# OPTIONS --with-K --safe #-}
9
10 module Data.Vec.Properties.WithK where
11
12 open import Data.Nat.Base using (ℕ; suc)
13 open import Data.Nat.Properties using (+-assoc)
14 open import Data.Vec.Base
15 open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong)
16 open import Relation.Binary.HeterogeneousEquality as ≅ using (_≅_; refl)
17
18 ------------------------------------------------------------------------
19 -- _[_]=_
20
21 module _ {a} {A : Set a} where
22
23 []=-irrelevant : ∀ {n} {xs : Vec A n} {i x} →
24 (p q : xs [ i ]= x) → p ≡ q
25 []=-irrelevant here here = refl
26 []=-irrelevant (there xs[i]=x) (there xs[i]=x′) =
27 cong there ([]=-irrelevant xs[i]=x xs[i]=x′)
28
29 ------------------------------------------------------------------------
30 -- _++_
31
32 module _ {a} {A : Set a} where
33
34 ++-assoc : ∀ {m n k} (xs : Vec A m) (ys : Vec A n) (zs : Vec A k) →
35 (xs ++ ys) ++ zs ≅ xs ++ (ys ++ zs)
36 ++-assoc [] ys zs = refl
37 ++-assoc {suc m} (x ∷ xs) ys zs =
38 ≅.icong (Vec A) (+-assoc m _ _) (x ∷_) (++-assoc xs ys zs)
39
40 ------------------------------------------------------------------------
41 -- foldr
42
43 foldr-cong : ∀ {a b} {A : Set a}
44 {B : ℕ → Set b} {f : ∀ {n} → A → B n → B (suc n)} {d}
45 {C : ℕ → Set b} {g : ∀ {n} → A → C n → C (suc n)} {e} →
46 (∀ {n x} {y : B n} {z : C n} → y ≅ z → f x y ≅ g x z) →
47 d ≅ e → ∀ {n} (xs : Vec A n) →
48 foldr B f d xs ≅ foldr C g e xs
49 foldr-cong _ d≅e [] = d≅e
50 foldr-cong f≅g d≅e (x ∷ xs) = f≅g (foldr-cong f≅g d≅e xs)
51
52 ------------------------------------------------------------------------
53 -- foldl
54
55 foldl-cong : ∀ {a b} {A : Set a}
56 {B : ℕ → Set b} {f : ∀ {n} → B n → A → B (suc n)} {d}
57 {C : ℕ → Set b} {g : ∀ {n} → C n → A → C (suc n)} {e} →
58 (∀ {n x} {y : B n} {z : C n} → y ≅ z → f y x ≅ g z x) →
59 d ≅ e → ∀ {n} (xs : Vec A n) →
60 foldl B f d xs ≅ foldl C g e xs
61 foldl-cong _ d≅e [] = d≅e
62 foldl-cong f≅g d≅e (x ∷ xs) = foldl-cong f≅g (f≅g d≅e) xs