| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Semi-heterogeneous vector equality over setoids |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Relation.Binary.Bundles using (Setoid) |
| 10 |
|
| 11 |
module Data.Vec.Relation.Binary.Equality.Setoid |
| 12 |
{a ℓ} (S : Setoid a ℓ) where |
| 13 |
|
| 14 |
open import Data.Nat.Base using (ℕ; zero; suc; _+_) |
| 15 |
open import Data.Fin.Base using (zero; suc) |
| 16 |
open import Data.Vec.Base |
| 17 |
open import Data.Vec.Relation.Binary.Pointwise.Inductive as PW |
| 18 |
using (Pointwise) |
| 19 |
open import Level using (_⊔_) |
| 20 |
open import Relation.Binary.Core using (REL) |
| 21 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 22 |
open import Relation.Binary.Definitions using (Reflexive; Sym; Trans) |
| 23 |
|
| 24 |
open Setoid S renaming (Carrier to A) |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Definition of equality |
| 28 |
|
| 29 |
infix 4 _≋_ |
| 30 |
|
| 31 |
_≋_ : ∀ {m n} → REL (Vec A m) (Vec A n) (a ⊔ ℓ) |
| 32 |
_≋_ = Pointwise _≈_ |
| 33 |
|
| 34 |
open Pointwise public using ([]; _∷_) |
| 35 |
open PW public using (length-equal) |
| 36 |
|
| 37 |
------------------------------------------------------------------------ |
| 38 |
-- Relational properties |
| 39 |
|
| 40 |
≋-refl : ∀ {n} → Reflexive (_≋_ {n}) |
| 41 |
≋-refl = PW.refl refl |
| 42 |
|
| 43 |
≋-sym : ∀ {n m} → Sym _≋_ (_≋_ {m} {n}) |
| 44 |
≋-sym = PW.sym sym |
| 45 |
|
| 46 |
≋-trans : ∀ {n m o} → Trans (_≋_ {m}) (_≋_ {n} {o}) (_≋_) |
| 47 |
≋-trans = PW.trans trans |
| 48 |
|
| 49 |
≋-isEquivalence : ∀ n → IsEquivalence (_≋_ {n}) |
| 50 |
≋-isEquivalence = PW.isEquivalence isEquivalence |
| 51 |
|
| 52 |
≋-setoid : ℕ → Setoid a (a ⊔ ℓ) |
| 53 |
≋-setoid = PW.setoid S |
| 54 |
|
| 55 |
------------------------------------------------------------------------ |
| 56 |
-- map |
| 57 |
|
| 58 |
open PW public using ( map⁺) |
| 59 |
|
| 60 |
------------------------------------------------------------------------ |
| 61 |
-- ++ |
| 62 |
|
| 63 |
open PW public using (++⁺ ; ++⁻ ; ++ˡ⁻; ++ʳ⁻) |
| 64 |
|
| 65 |
++-identityˡ : ∀ {n} (xs : Vec A n) → [] ++ xs ≋ xs |
| 66 |
++-identityˡ _ = ≋-refl |
| 67 |
|
| 68 |
++-identityʳ : ∀ {n} (xs : Vec A n) → xs ++ [] ≋ xs |
| 69 |
++-identityʳ [] = [] |
| 70 |
++-identityʳ (x ∷ xs) = refl ∷ ++-identityʳ xs |
| 71 |
|
| 72 |
++-assoc : ∀ {n m k} (xs : Vec A n) (ys : Vec A m) (zs : Vec A k) → |
| 73 |
(xs ++ ys) ++ zs ≋ xs ++ (ys ++ zs) |
| 74 |
++-assoc [] ys zs = ≋-refl |
| 75 |
++-assoc (x ∷ xs) ys zs = refl ∷ ++-assoc xs ys zs |
| 76 |
|
| 77 |
map-++ : ∀ {b m n} {B : Set b} |
| 78 |
(f : B → A) (xs : Vec B m) {ys : Vec B n} → |
| 79 |
map f (xs ++ ys) ≋ map f xs ++ map f ys |
| 80 |
map-++ f [] = ≋-refl |
| 81 |
map-++ f (x ∷ xs) = refl ∷ map-++ f xs |
| 82 |
|
| 83 |
map-[]≔ : ∀ {b n} {B : Set b} |
| 84 |
(f : B → A) (xs : Vec B n) i p → |
| 85 |
map f (xs [ i ]≔ p) ≋ map f xs [ i ]≔ f p |
| 86 |
map-[]≔ f (x ∷ xs) zero p = refl ∷ ≋-refl |
| 87 |
map-[]≔ f (x ∷ xs) (suc i) p = refl ∷ map-[]≔ f xs i p |
| 88 |
|
| 89 |
------------------------------------------------------------------------ |
| 90 |
-- concat |
| 91 |
|
| 92 |
open PW public using (concat⁺; concat⁻) |
| 93 |
|
| 94 |
------------------------------------------------------------------------ |
| 95 |
-- replicate |
| 96 |
|
| 97 |
replicate-shiftʳ : ∀ {m} n x (xs : Vec A m) → |
| 98 |
replicate n x ++ (x ∷ xs) ≋ |
| 99 |
replicate (1 + n) x ++ xs |
| 100 |
replicate-shiftʳ zero x xs = ≋-refl |
| 101 |
replicate-shiftʳ (suc n) x xs = refl ∷ (replicate-shiftʳ n x xs) |
| 102 |
|
| 103 |
------------------------------------------------------------------------ |
| 104 |
-- DEPRECATED |
| 105 |
------------------------------------------------------------------------ |
| 106 |
-- Please use the new names as continuing support for the old names is |
| 107 |
-- not guaranteed. |
| 108 |
|
| 109 |
-- Version 2.0 |
| 110 |
|
| 111 |
map-++-commute = map-++ |
| 112 |
{-# WARNING_ON_USAGE map-++-commute |
| 113 |
"Warning: map-++-commute was deprecated in v2.0. |
| 114 |
Please use map-++ instead." |
| 115 |
#-} |