Debian Codegraph @

src/Data/Vec/Relation/Unary/AllPairs/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties related to AllPairs
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Vec.Relation.Unary.AllPairs.Properties where
10
11 open import Data.Vec.Base using (_∷_; map; _++_; concat; take; drop; tabulate)
12 import Data.Vec.Properties as Vec
13 open import Data.Vec.Relation.Unary.All as All using (All; []; _∷_)
14 import Data.Vec.Relation.Unary.All.Properties as All
15 open import Data.Vec.Relation.Unary.AllPairs as AllPairs using (AllPairs; []; _∷_)
16 open import Data.Bool.Base using (true; false)
17 open import Data.Fin.Base using (Fin)
18 open import Data.Fin.Properties using (suc-injective)
19 open import Data.Nat.Base using (zero; suc; _+_)
20 open import Function.Base using (_∘_)
21 open import Level using (Level)
22 open import Relation.Binary.Core using (Rel)
23 open import Relation.Binary.PropositionalEquality.Core using (_≢_)
24
25 private
26 variable
27 a b c p ℓ : Level
28 A : Set a
29 B : Set b
30 C : Set c
31
32 ------------------------------------------------------------------------
33 -- Introduction (⁺) and elimination (⁻) rules for vector operations
34 ------------------------------------------------------------------------
35 -- map
36
37 module _ {R : Rel A ℓ} {f : B → A} where
38
39 map⁺ : ∀ {n xs} → AllPairs (λ x y → R (f x) (f y)) {n} xs →
40 AllPairs R {n} (map f xs)
41 map⁺ [] = []
42 map⁺ (x∉xs ∷ xs!) = All.map⁺ x∉xs ∷ map⁺ xs!
43
44 ------------------------------------------------------------------------
45 -- ++
46
47 module _ {R : Rel A ℓ} where
48
49 ++⁺ : ∀ {n m xs ys} → AllPairs R {n} xs → AllPairs R {m} ys →
50 All (λ x → All (R x) ys) xs → AllPairs R (xs ++ ys)
51 ++⁺ [] Rys _ = Rys
52 ++⁺ (px ∷ Rxs) Rys (Rxys ∷ Rxsys) = All.++⁺ px Rxys ∷ ++⁺ Rxs Rys Rxsys
53
54 ------------------------------------------------------------------------
55 -- concat
56
57 module _ {R : Rel A ℓ} where
58
59 concat⁺ : ∀ {n m xss} → All (AllPairs R {n}) {m} xss →
60 AllPairs (λ xs ys → All (λ x → All (R x) ys) xs) xss →
61 AllPairs R (concat xss)
62 concat⁺ [] [] = []
63 concat⁺ (pxs ∷ pxss) (Rxsxss ∷ Rxss) = ++⁺ pxs (concat⁺ pxss Rxss)
64 (All.map All.concat⁺ (All.All-swap Rxsxss))
65
66 ------------------------------------------------------------------------
67 -- take and drop
68
69 module _ {R : Rel A ℓ} where
70
71 take⁺ : ∀ {n} m {xs} → AllPairs R {m + n} xs → AllPairs R {m} (take m xs)
72 take⁺ zero pxs = []
73 take⁺ (suc m) {x ∷ xs} (px ∷ pxs) = All.take⁺ m px ∷ take⁺ m pxs
74
75 drop⁺ : ∀ {n} m {xs} → AllPairs R {m + n} xs → AllPairs R {n} (drop m xs)
76 drop⁺ zero pxs = pxs
77 drop⁺ (suc m) (_ ∷ pxs) = drop⁺ m pxs
78
79 ------------------------------------------------------------------------
80 -- tabulate
81
82 module _ {R : Rel A ℓ} where
83
84 tabulate⁺ : ∀ {n} {f : Fin n → A} → (∀ {i j} → i ≢ j → R (f i) (f j)) →
85 AllPairs R (tabulate f)
86 tabulate⁺ {zero} fᵢ~fⱼ = []
87 tabulate⁺ {suc n} fᵢ~fⱼ =
88 All.tabulate⁺ (λ j → fᵢ~fⱼ λ()) ∷
89 tabulate⁺ (fᵢ~fⱼ ∘ (_∘ suc-injective))