Debian Codegraph @

src/Data/Vec/Functional/Relation/Unary/All/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties related to All
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Vec.Functional.Relation.Unary.All.Properties where
10
11 open import Data.Nat.Base using (ℕ)
12 open import Data.Fin.Base using (zero; suc; _↑ˡ_; _↑ʳ_; splitAt)
13 open import Data.Fin.Properties using (splitAt-↑ˡ; splitAt-↑ʳ)
14 open import Data.Product.Base as Σ using (_×_; _,_; proj₁; proj₂; uncurry)
15 open import Data.Sum.Base using (_⊎_; inj₁; inj₂; [_,_])
16 open import Data.Vec.Functional as VF hiding (map)
17 open import Data.Vec.Functional.Relation.Unary.All
18 open import Function.Base using (const; _∘_)
19 open import Level using (Level)
20 open import Relation.Unary using (Pred; _⟨×⟩_)
21
22 private
23 variable
24 a p ℓ : Level
25 A B C : Set a
26 P Q R : Pred A p
27 m n : ℕ
28 x y : A
29 xs ys : Vector A n
30
31 ------------------------------------------------------------------------
32 -- map
33
34 map⁺ : ∀ {f : A → B} → (∀ {x} → P x → Q (f x)) →
35 All P xs → All Q (VF.map f xs)
36 map⁺ pq ps i = pq (ps i)
37
38 ------------------------------------------------------------------------
39 -- replicate
40
41 replicate⁺ : P x → All P (replicate n x)
42 replicate⁺ = const
43
44 ------------------------------------------------------------------------
45 -- _⊛_
46
47 ⊛⁺ : ∀ {fs : Vector (A → B) n} →
48 All (λ f → ∀ {x} → P x → Q (f x)) fs →
49 All P xs → All Q (fs ⊛ xs)
50 ⊛⁺ pqs ps i = (pqs i) (ps i)
51
52 ------------------------------------------------------------------------
53 -- zipWith
54
55 zipWith⁺ : ∀ {f} → (∀ {x y} → P x → Q y → R (f x y)) →
56 All P xs → All Q ys → All R (zipWith f xs ys)
57 zipWith⁺ pqr ps qs i = pqr (ps i) (qs i)
58
59 ------------------------------------------------------------------------
60 -- zip
61
62 zip⁺ : All P xs → All Q ys → All (P ⟨×⟩ Q) (zip xs ys)
63 zip⁺ ps qs i = ps i , qs i
64
65 zip⁻ : All (P ⟨×⟩ Q) (zip xs ys) → All P xs × All Q ys
66 zip⁻ pqs = proj₁ ∘ pqs , proj₂ ∘ pqs
67
68 ------------------------------------------------------------------------
69 -- head
70
71 head⁺ : ∀ (P : Pred A p) → All P xs → P (head xs)
72 head⁺ P ps = ps zero
73
74 ------------------------------------------------------------------------
75 -- tail
76
77 tail⁺ : ∀ (P : Pred A p) → All P xs → All P (tail xs)
78 tail⁺ P xs = xs ∘ suc
79
80 ------------------------------------------------------------------------
81 -- ++
82
83 module _ (P : Pred A p) {xs : Vector A m} {ys : Vector A n} where
84
85 ++⁺ : All P xs → All P ys → All P (xs ++ ys)
86 ++⁺ pxs pys i with splitAt m i
87 ... | inj₁ i′ = pxs i′
88 ... | inj₂ j′ = pys j′
89
90 module _ (P : Pred A p) (xs : Vector A m) {ys : Vector A n} where
91
92 ++⁻ˡ : All P (xs ++ ys) → All P xs
93 ++⁻ˡ ps i with ps (i ↑ˡ n)
94 ... | p rewrite splitAt-↑ˡ m i n = p
95
96 ++⁻ʳ : All P (xs ++ ys) → All P ys
97 ++⁻ʳ ps i with ps (m ↑ʳ i)
98 ... | p rewrite splitAt-↑ʳ m n i = p
99
100 ++⁻ : All P (xs ++ ys) → All P xs × All P ys
101 ++⁻ ps = ++⁻ˡ ps , ++⁻ʳ ps