| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Properties of permutation |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Vec.Functional.Relation.Binary.Permutation.Properties where |
| 10 |
|
| 11 |
open import Level using (Level) |
| 12 |
open import Data.Product.Base using (_,_; proj₁; proj₂) |
| 13 |
open import Data.Nat.Base using (ℕ) |
| 14 |
open import Data.Fin.Permutation using (id; flip; _⟨$⟩ʳ_; inverseʳ; _∘ₚ_) |
| 15 |
open import Data.Vec.Functional using (Vector) |
| 16 |
open import Data.Vec.Functional.Relation.Binary.Permutation using (_↭_) |
| 17 |
open import Relation.Binary.PropositionalEquality.Core |
| 18 |
using (_≡_; refl; trans; cong) |
| 19 |
open import Relation.Binary.PropositionalEquality.Properties |
| 20 |
using (module ≡-Reasoning) |
| 21 |
open import Relation.Binary.Indexed.Heterogeneous |
| 22 |
using (Reflexive; Symmetric; Transitive; IsIndexedEquivalence; IndexedSetoid) |
| 23 |
|
| 24 |
private |
| 25 |
variable |
| 26 |
a : Level |
| 27 |
A : Set a |
| 28 |
n : ℕ |
| 29 |
xs ys : Vector A n |
| 30 |
|
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- Basics |
| 34 |
|
| 35 |
↭-refl : Reflexive (Vector A) _↭_ |
| 36 |
↭-refl = id , λ _ → refl |
| 37 |
|
| 38 |
↭-reflexive : xs ≡ ys → xs ↭ ys |
| 39 |
↭-reflexive refl = ↭-refl |
| 40 |
|
| 41 |
↭-sym : Symmetric (Vector A) _↭_ |
| 42 |
proj₁ (↭-sym (xs↭ys , _)) = flip xs↭ys |
| 43 |
proj₂ (↭-sym {x = xs} {ys} (xs↭ys , xs↭ys≡)) i = begin |
| 44 |
ys (flip xs↭ys ⟨$⟩ʳ i) ≡⟨ xs↭ys≡ _ ⟨ |
| 45 |
xs (xs↭ys ⟨$⟩ʳ (flip xs↭ys ⟨$⟩ʳ i)) ≡⟨ cong xs (inverseʳ xs↭ys) ⟩ |
| 46 |
xs i ∎ |
| 47 |
where open ≡-Reasoning |
| 48 |
|
| 49 |
↭-trans : Transitive (Vector A) _↭_ |
| 50 |
proj₁ (↭-trans (xs↭ys , _) (ys↭zs , _)) = ys↭zs ∘ₚ xs↭ys |
| 51 |
proj₂ (↭-trans (_ , xs↭ys) (_ , ys↭zs)) _ = trans (xs↭ys _) (ys↭zs _) |
| 52 |
|
| 53 |
------------------------------------------------------------------------ |
| 54 |
-- Structure |
| 55 |
|
| 56 |
isIndexedEquivalence : IsIndexedEquivalence (Vector A) _↭_ |
| 57 |
isIndexedEquivalence {A = A} = record |
| 58 |
{ refl = ↭-refl |
| 59 |
; sym = ↭-sym |
| 60 |
; trans = λ {n₁ n₂ n₃} {xs : Vector A n₁} {ys : Vector A n₂} {zs : Vector A n₃} |
| 61 |
xs↭ys ys↭zs → ↭-trans {i = n₁} {i = xs} xs↭ys ys↭zs |
| 62 |
} |
| 63 |
|
| 64 |
------------------------------------------------------------------------ |
| 65 |
-- Bundle |
| 66 |
|
| 67 |
indexedSetoid : {A : Set a} → IndexedSetoid ℕ a _ |
| 68 |
indexedSetoid {A = A} = record |
| 69 |
{ Carrier = Vector A |
| 70 |
; _≈_ = _↭_ |
| 71 |
; isEquivalence = isIndexedEquivalence |
| 72 |
} |