Debian Codegraph @

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

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties related to Linked
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Vec.Relation.Unary.Linked.Properties where
10
11 open import Data.Vec.Base as Vec
12 open import Data.Vec.Relation.Unary.All as All using (All; []; _∷_)
13 import Data.Vec.Relation.Unary.All.Properties as All
14 open import Data.Vec.Relation.Unary.Linked as Linked
15 using (Linked; []; [-]; _∷_)
16 open import Data.Fin.Base using (zero; suc; _<_)
17 open import Data.Nat.Base using (ℕ; zero; suc; s<s⁻¹)
18 open import Level using (Level)
19 open import Function.Base using (_on_)
20 open import Relation.Binary.Core using (Rel)
21 open import Relation.Binary.Definitions using (Transitive)
22 open import Relation.Unary using (Pred; Decidable)
23
24 private
25 variable
26 a b p r ℓ : Level
27 m n : ℕ
28 A : Set a
29 B : Set b
30 R : Rel A r
31
32 ------------------------------------------------------------------------
33 -- Relationship to other predicates
34 ------------------------------------------------------------------------
35
36 module _ (trans : Transitive R) where
37
38 Linked⇒All : ∀ {v} {xs : Vec _ (suc n)} → R v (head xs) →
39 Linked R xs → All (R v) xs
40 Linked⇒All Rvx [-] = Rvx ∷ []
41 Linked⇒All Rvx (Rxy ∷ Rxs) = Rvx ∷ Linked⇒All (trans Rvx Rxy) Rxs
42
43 lookup⁺ : ∀ {i j} {xs : Vec _ n} →
44 Linked R xs → i < j →
45 R (lookup xs i) (lookup xs j)
46 lookup⁺ {i = zero} {j = suc j} (rx ∷ rxs) i<j = All.lookup⁺ (Linked⇒All rx rxs) j
47 lookup⁺ {i = suc i} {j = suc j} (_ ∷ rxs) i<j = lookup⁺ rxs (s<s⁻¹ i<j)
48
49 ------------------------------------------------------------------------
50 -- Introduction (⁺) and elimination (⁻) rules for vec operations
51 ------------------------------------------------------------------------
52 -- map
53
54 map⁺ : ∀ {f : B → A} {xs} → Linked (R on f) {n} xs → Linked R (map f xs)
55 map⁺ [] = []
56 map⁺ [-] = [-]
57 map⁺ (Rxy ∷ [-]) = Rxy ∷ [-]
58 map⁺ (Rxy ∷ Rxs@(_ ∷ _)) = Rxy ∷ map⁺ Rxs
59
60 map⁻ : ∀ {f : B → A} {xs} → Linked R {n} (map f xs) → Linked (R on f) xs
61 map⁻ {xs = []} [] = []
62 map⁻ {xs = x ∷ []} [-] = [-]
63 map⁻ {xs = x ∷ _ ∷ _} (Rxy ∷ Rxs) = Rxy ∷ map⁻ Rxs