Debian Codegraph @

src/Data/Fin/Permutation/Components.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Component functions of permutations found in `Data.Fin.Permutation`
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Fin.Permutation.Components where
10
11 open import Data.Bool.Base using (Bool; true; false)
12 open import Data.Fin.Base using (Fin; suc; opposite; toℕ)
13 open import Data.Fin.Properties
14 using (_≟_; opposite-prop; opposite-involutive; opposite-suc)
15 open import Data.Nat.Base as ℕ using (zero; suc; _∸_)
16 open import Data.Product.Base using (proj₂)
17 open import Function.Base using (_∘_)
18 open import Relation.Nullary.Reflects using (invert)
19 open import Relation.Nullary using (does; _because_; yes; no)
20 open import Relation.Nullary.Decidable using (dec-true; dec-false)
21 open import Relation.Binary.PropositionalEquality.Core
22 using (_≡_; refl; sym; trans)
23 open import Relation.Binary.PropositionalEquality.Properties
24 using (module ≡-Reasoning)
25 open import Algebra.Definitions using (Involutive)
26 open ≡-Reasoning
27
28 ------------------------------------------------------------------------
29 -- Functions
30 ------------------------------------------------------------------------
31
32 -- 'tranpose i j' swaps the places of 'i' and 'j'.
33
34 transpose : ∀ {n} → Fin n → Fin n → Fin n → Fin n
35 transpose i j k with does (k ≟ i)
36 ... | true = j
37 ... | false with does (k ≟ j)
38 ... | true = i
39 ... | false = k
40
41 ------------------------------------------------------------------------
42 -- Properties
43 ------------------------------------------------------------------------
44
45 transpose-inverse : ∀ {n} (i j : Fin n) {k} →
46 transpose i j (transpose j i k) ≡ k
47 transpose-inverse i j {k} with k ≟ j
48 ... | true because [k≡j] rewrite dec-true (i ≟ i) refl = sym (invert [k≡j])
49 ... | false because [k≢j] with k ≟ i
50 ... | true because [k≡i]
51 rewrite dec-false (j ≟ i) (invert [k≢j] ∘ trans (invert [k≡i]) ∘ sym)
52 | dec-true (j ≟ j) refl
53 = sym (invert [k≡i])
54 ... | false because [k≢i] rewrite dec-false (k ≟ i) (invert [k≢i])
55 | dec-false (k ≟ j) (invert [k≢j]) = refl
56
57 ------------------------------------------------------------------------
58 -- DEPRECATED NAMES
59 ------------------------------------------------------------------------
60 -- Please use the new names as continuing support for the old names is
61 -- not guaranteed.
62
63 -- Version 2.0
64
65 reverse = opposite
66 {-# WARNING_ON_USAGE reverse
67 "Warning: reverse was deprecated in v2.0.
68 Please use opposite from Data.Fin.Base instead."
69 #-}
70
71 reverse-prop = opposite-prop
72 {-# WARNING_ON_USAGE reverse-prop
73 "Warning: reverse-prop was deprecated in v2.0.
74 Please use opposite-prop from Data.Fin.Properties instead."
75 #-}
76
77 reverse-involutive = opposite-involutive
78 {-# WARNING_ON_USAGE reverse-involutive
79 "Warning: reverse-involutive was deprecated in v2.0.
80 Please use opposite-involutive from Data.Fin.Properties instead."
81 #-}
82
83 reverse-suc : ∀ {n} {i : Fin n} → toℕ (opposite (suc i)) ≡ toℕ (opposite i)
84 reverse-suc {i = i} = opposite-suc i
85 {-# WARNING_ON_USAGE reverse-suc
86 "Warning: reverse-suc was deprecated in v2.0.
87 Please use opposite-suc from Data.Fin.Properties instead."
88 #-}