Debian Codegraph @

src/Data/Vec/Relation/Unary/Unique/Setoid/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of unique vectors (setoid equality)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Vec.Relation.Unary.Unique.Setoid.Properties where
10
11 open import Data.Fin.Base using (Fin; zero; suc)
12 open import Data.Vec.Base 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.Vec.Relation.Unary.Unique.Setoid
17 import Data.Vec.Relation.Unary.AllPairs.Properties as AllPairs
18 open import Data.Nat.Base using (ℕ; _+_)
19 open import Function.Base using (_∘_; id)
20 open import Level using (Level)
21 open import Relation.Binary.Core using (Rel)
22 open import Relation.Binary.Bundles using (Setoid)
23 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
24 open import Relation.Nullary.Negation using (contradiction; contraposition)
25
26 private
27 variable
28 a b c p ℓ ℓ₁ ℓ₂ ℓ₃ : Level
29
30 ------------------------------------------------------------------------
31 -- Introduction (⁺) and elimination (⁻) rules for list operations
32 ------------------------------------------------------------------------
33 -- map
34
35 module _ (S : Setoid a ℓ₁) (R : Setoid b ℓ₂) where
36
37 open Setoid S renaming (_≈_ to _≈₁_)
38 open Setoid R renaming (_≈_ to _≈₂_)
39
40 map⁺ : ∀ {f} → (∀ {x y} → f x ≈₂ f y → x ≈₁ y) →
41 ∀ {n xs} → Unique S {n} xs → Unique R {n} (map f xs)
42 map⁺ inj xs! = AllPairs.map⁺ (AllPairs.map (contraposition inj) xs!)
43
44 ------------------------------------------------------------------------
45 -- take & drop
46
47 module _ (S : Setoid a ℓ) where
48
49 drop⁺ : ∀ {n} m {xs} → Unique S {m + n} xs → Unique S {n} (drop m xs)
50 drop⁺ = AllPairs.drop⁺
51
52 take⁺ : ∀ {n} m {xs} → Unique S {m + n} xs → Unique S {m} (take m xs)
53 take⁺ = AllPairs.take⁺
54
55 ------------------------------------------------------------------------
56 -- tabulate
57
58 module _ (S : Setoid a ℓ) where
59
60 open Setoid S renaming (Carrier to A)
61
62 tabulate⁺ : ∀ {n} {f : Fin n → A} → (∀ {i j} → f i ≈ f j → i ≡ j) →
63 Unique S (tabulate f)
64 tabulate⁺ f-inj = AllPairs.tabulate⁺ (_∘ f-inj)
65
66 ------------------------------------------------------------------------
67 -- lookup
68
69 module _ (S : Setoid a ℓ) where
70
71 open Setoid S
72
73 lookup-injective : ∀ {n xs} → Unique S {n} xs → ∀ i j → lookup xs i ≈ lookup xs j → i ≡ j
74 lookup-injective (px ∷ pxs) zero zero eq = ≡.refl
75 lookup-injective (px ∷ pxs) zero (suc j) eq = contradiction eq (All.lookup⁺ px j)
76 lookup-injective (px ∷ pxs) (suc i) zero eq = contradiction (sym eq) (All.lookup⁺ px i)
77 lookup-injective (px ∷ pxs) (suc i) (suc j) eq = ≡.cong suc (lookup-injective pxs i j eq)