annotate Symmetric.agda @ 44:9ce6141ef479

start again
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 20 Aug 2020 21:59:22 +0900
parents 84c84695de94
children a3ee2ca4f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
1 module Symmetric where
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level hiding ( suc ; zero )
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Algebra
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Algebra.Structures
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
6 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ )
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
7 open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ) renaming ( <-cmp to <-fcmp )
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
8 open import Data.Product
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Fin.Permutation
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Function hiding (id ; flip)
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_)
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Function.LeftInverse using ( _LeftInverseOf_ )
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Function.Equality using (Π)
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
14 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
15 open import Data.Nat.Properties -- using (<-trans)
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
16 open import Relation.Binary.PropositionalEquality
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
17 open import Data.List using (List; []; _∷_ ; length ; _++_ ) renaming (reverse to rev )
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
18 open import nat
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 fid : {p : ℕ } → Fin p → Fin p
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 fid x = x
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 -- Data.Fin.Permutation.id
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 pid : {p : ℕ } → Permutation p p
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 pid = permutation fid fid record { left-inverse-of = λ x → refl ; right-inverse-of = λ x → refl }
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 -- Data.Fin.Permutation.flip
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 pinv : {p : ℕ } → Permutation p p → Permutation p p
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 pinv {p} P = permutation (_⟨$⟩ˡ_ P) (_⟨$⟩ʳ_ P ) record { left-inverse-of = λ x → inverseʳ P ; right-inverse-of = λ x → inverseˡ P }
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
31 record _=p=_ {p : ℕ } ( x y : Permutation p p ) : Set where
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
32 field
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
33 peq : ( q : Fin p ) → x ⟨$⟩ʳ q ≡ y ⟨$⟩ʳ q
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
35 open _=p=_
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
37 prefl : {p : ℕ } { x : Permutation p p } → x =p= x
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
38 peq (prefl {p} {x}) q = refl
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
39
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
40 psym : {p : ℕ } { x y : Permutation p p } → x =p= y → y =p= x
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
41 peq (psym {p} {x} {y} eq ) q = sym (peq eq q)
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
42
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
43 ptrans : {p : ℕ } { x y z : Permutation p p } → x =p= y → y =p= z → x =p= z
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
44 peq (ptrans {p} {x} {y} x=y y=z ) q = trans (peq x=y q) (peq y=z q)
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
46 Symmetric : ℕ → Group Level.zero Level.zero
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
47 Symmetric p = record {
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 Carrier = Permutation p p
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
49 ; _≈_ = _=p=_
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 ; _∙_ = _∘ₚ_
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ; ε = pid
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 ; _⁻¹ = pinv
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
53 ; isGroup = record { isMonoid = record { isSemigroup = record { isMagma = record {
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
54 isEquivalence = record {refl = prefl ; trans = ptrans ; sym = psym }
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 ; ∙-cong = presp }
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 ; assoc = passoc }
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
57 ; identity = ( (λ q → record { peq = λ q → refl } ) , (λ q → record { peq = λ q → refl } )) }
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
58 ; inverse = ( (λ x → record { peq = λ q → inverseʳ x} ) , (λ x → record { peq = λ q → inverseˡ x} ))
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
59 ; ⁻¹-cong = λ i=j → record { peq = λ q → p-inv i=j q }
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 } where
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
62 presp : {x y u v : Permutation p p } → x =p= y → u =p= v → (x ∘ₚ u) =p= (y ∘ₚ v)
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
63 presp {x} {y} {u} {v} x=y u=v = record { peq = λ q → lemma4 q } where
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
64 lemma4 : (q : Fin p) → ((x ∘ₚ u) ⟨$⟩ʳ q) ≡ ((y ∘ₚ v) ⟨$⟩ʳ q)
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
65 lemma4 q = trans (cong (λ k → Inverse.to u Π.⟨$⟩ k) (peq x=y q) ) (peq u=v _ )
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
66 passoc : (x y z : Permutation p p) → ((x ∘ₚ y) ∘ₚ z) =p= (x ∘ₚ (y ∘ₚ z))
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
67 passoc x y z = record { peq = λ q → refl }
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
68 p-inv : {i j : Permutation p p} → i =p= j → (q : Fin p) → pinv i ⟨$⟩ʳ q ≡ pinv j ⟨$⟩ʳ q
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
69 p-inv {i} {j} i=j q = begin
4
121213cfc85a add Solvable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
70 i ⟨$⟩ˡ q ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (inverseʳ j) ) ⟩
121213cfc85a add Solvable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
71 i ⟨$⟩ˡ ( j ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (peq i=j _ )) ⟩
121213cfc85a add Solvable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
72 i ⟨$⟩ˡ ( i ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ inverseˡ i ⟩
121213cfc85a add Solvable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
73 j ⟨$⟩ˡ q
3
6e77fefcbe41 Permutation Group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
74 ∎ where open ≡-Reasoning
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
76 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
77 open import Data.Empty
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
78 open import Relation.Binary.Core
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
79 open import fin
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
80
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
81 -- An inductive construction of permutation
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
82
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
83 -- we already have refl and trans
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
84
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
85 pprep : {n : ℕ } → Permutation n n → Permutation (suc n) (suc n)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
86 pprep {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
87 p→ : Fin (suc n) → Fin (suc n)
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
88 p→ zero = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
89 p→ (suc x) = suc ( perm ⟨$⟩ˡ x)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
90
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
91 p← : Fin (suc n) → Fin (suc n)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
92 p← zero = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
93 p← (suc x) = suc ( perm ⟨$⟩ʳ x)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
94
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
95 piso← : (x : Fin (suc n)) → p→ ( p← x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
96 piso← zero = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
97 piso← (suc x) = cong (λ k → suc k ) (inverseˡ perm)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
98
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
99 piso→ : (x : Fin (suc n)) → p← ( p→ x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
100 piso→ zero = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
101 piso→ (suc x) = cong (λ k → suc k ) (inverseʳ perm)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
102
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
103 pswap : {n : ℕ } → Permutation n n → Permutation (suc (suc n)) (suc (suc n ))
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
104 pswap {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
105 p→ : Fin (suc (suc n)) → Fin (suc (suc n))
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
106 p→ zero = suc zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
107 p→ (suc zero) = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
108 p→ (suc (suc x)) = suc ( suc ( perm ⟨$⟩ˡ x) )
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
109
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
110 p← : Fin (suc (suc n)) → Fin (suc (suc n))
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
111 p← zero = suc zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
112 p← (suc zero) = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
113 p← (suc (suc x)) = suc ( suc ( perm ⟨$⟩ʳ x) )
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
114
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
115 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
116 piso← zero = refl
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
117 piso← (suc zero) = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
118 piso← (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseˡ perm)
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
119
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
120 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
121 piso→ zero = refl
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
122 piso→ (suc zero) = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
123 piso→ (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseʳ perm)
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
124
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
125 -- enumeration
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
126
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
127 psawpn : {n : ℕ} → 1 < n → Permutation n n
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
128 psawpn {suc zero} (s≤s ())
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
129 psawpn {suc n} (s≤s (s≤s x)) = pswap pid
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
130
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
131 pfill : { n m : ℕ } → m ≤ n → Permutation m m → Permutation n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
132 pfill {n} {m} m≤n perm = pfill1 (n - m) (n-m<n n m ) (subst (λ k → Permutation k k ) (n-n-m=m m≤n ) perm) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
133 pfill1 : (i : ℕ ) → i ≤ n → Permutation (n - i) (n - i) → Permutation n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
134 pfill1 0 _ perm = perm
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
135 pfill1 (suc i) i<n perm = pfill1 i (≤to< i<n) (subst (λ k → Permutation k k ) (si-sn=i-n i<n ) ( pprep perm ) )
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
136
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
137 psawpim : {n m : ℕ} → 1 < m → m ≤ n → Permutation n n
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
138 psawpim {n} {m} 1<m m≤n = pfill m≤n ( psawpn 1<m )
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
139
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
140 -- pconcat : {n m : ℕ } → Permutation m m → Permutation n n → Permutation (m + n) (m + n)
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
141 -- pconcat {n} {m} p q = pfill {n + m} {m} ? p ∘ₚ ?
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
142
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
143 -- inductivley enmumerate permutations
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
144 -- from n-1 length create n length inserting new element at position m
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
145
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
146 eperm : {n m : ℕ} → m ≤ n → Permutation n n → Permutation (suc n) (suc n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
147 eperm {0} {0} z≤n perm = pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
148 eperm {suc n} {0} z≤n perm = pprep perm
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
149 eperm {n} {suc m} (s≤s m<n) perm = eperm1 m 2 lemm3 (pprep perm) where
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
150 lemm3 : 2 + m ≤ suc n
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
151 lemm3 = s≤s (s≤s m<n)
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
152 eperm1 : (m i : ℕ ) → i + m ≤ suc n → Permutation (suc n)(suc n) → Permutation (suc n)(suc n)
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
153 eperm1 zero i i<ssm perm = perm ∘ₚ (psawpim {suc n} {i + m} {!!} {!!} ) --- 1 < i + m , i + m ≤ suc (suc n)
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
154 -- m<n : m ≤ n , i<ssm : i + zero ≤ suc (suc n)
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
155 eperm1 (suc m) i i<ssm perm = eperm1 m (suc i) (lemm4 i<ssm ) perm where
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
156 lemm4 : i + suc m ≤ suc n → suc i + m ≤ suc n
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
157 lemm4 lt = begin
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
158 suc i + m ≡⟨ cong (λ k → suc k ) ( +-comm i _ ) ⟩
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
159 suc m + i ≡⟨ +-comm (suc m) _ ⟩
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
160 i + suc m ≤⟨ lt ⟩
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
161 suc n
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
162 ∎ where open ≤-Reasoning
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
163
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
164 plist : {n : ℕ} → Permutation n n → List ℕ
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
165 plist {0} perm = []
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
166 plist {suc j} perm = rev (plist1 j a<sa) where
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
167 n = suc j
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
168 plist1 : (i : ℕ ) → i < n → List ℕ
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
169 plist1 zero _ = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ {zero} (s≤s z≤n))) ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
170 plist1 (suc i) (s≤s lt) = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ (s≤s lt))) ∷ plist1 i (<-trans lt a<sa)
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
171
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
172 testp = plist (psawpim {6} {4} (s≤s (s≤s z≤n)) (s≤s (s≤s (s≤s (s≤s z≤n)))))
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
173 testi00 = plist(pid {3} ) -- 0 ∷ 1 ∷ 2 ∷ []
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
174 testi = plist (pid {3} ∘ₚ psawpim {3} {2} (s≤s (s≤s z≤n)) (s≤s (s≤s z≤n))) -- 0 ∷ 2 ∷ 1 ∷ [] -- 1 ∷ 0 ∷ 2 ∷ []
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
175 testi0 = plist (pid {3} ∘ₚ psawpim {3} {3} (s≤s (s≤s z≤n)) (s≤s ( s≤s (s≤s z≤n)))) -- 1 ∷ 0 ∷ 2 ∷ [] -- 1 ∷ 2 ∷ 0 ∷ []
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
176
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
177 test0 = plist (eperm {1} {0} z≤n pid)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
178 test1 = plist (eperm {1} {1} (s≤s z≤n) pid)
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
179 test = eperm {3} ( s≤s ( s≤s z≤n )) ( eperm (s≤s z≤n) pid )
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
180 test11 = plist (eperm {2} {0} z≤n (eperm {1} {0} z≤n pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
181 test12 = plist (eperm {2} {0} z≤n (eperm {1} {1} (s≤s z≤n) pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
182 test21 = plist (eperm {2} {1} (s≤s z≤n) (eperm {1} {0} z≤n pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
183 test22 = plist (eperm {2} {1} (s≤s z≤n) (eperm {1} {1} (s≤s z≤n) pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
184 test23 = plist (eperm {2} {2} (s≤s (s≤s z≤n)) (eperm {1} {0} z≤n pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
185 test24 = plist (eperm {2} {2} (s≤s (s≤s z≤n)) (eperm {1} {1} (s≤s z≤n) pid))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
186 test3 = test11 ∷ test12 ∷ test21 ∷ test22 ∷ test23 ∷ test24 ∷ []
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
187
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
188 lem0 : {n : ℕ } → n ≤ n
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
189 lem0 {zero} = z≤n
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
190 lem0 {suc n} = s≤s lem0
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
191
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
192 lem00 : {n m : ℕ } → n ≡ m → n ≤ m
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
193 lem00 refl = lem0
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
194
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
195 pls : (n : ℕ ) → List (List ℕ )
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
196 pls n = Data.List.map plist (pls6 n) where
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
197 lem1 : {i n : ℕ } → i ≤ n → i < suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
198 lem1 z≤n = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
199 lem1 (s≤s lt) = s≤s (lem1 lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
200 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
201 lem2 i≤n = ≤-trans i≤n ( refl-≤s )
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
202 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
203 pls4 zero n i≤n perm x = pid ∷ x
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
204 pls4 (suc i) n i≤n perm x = pls4 i n (≤-trans refl-≤s i≤n ) perm (eperm {n} {i} (≤-trans refl-≤s i≤n ) perm ∷ x)
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
205 pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
206 pls5 n [] x = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
207 pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
208 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
209 pls6 zero = pid ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
210 pls6 (suc n) = pls5 (suc n) (pls6 n) []