annotate Putil.agda @ 51:3e677c24a6cc

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Aug 2020 14:43:35 +0900
parents ddec1ef4f5e4
children 0377ac873d39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
1 module Putil 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 )
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Fin.Permutation
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Function hiding (id ; flip)
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_)
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Function.LeftInverse using ( _LeftInverseOf_ )
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Function.Equality using (Π)
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
13 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
14 open import Data.Nat.Properties -- using (<-trans)
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
15 open import Relation.Binary.PropositionalEquality
46
88f9aff7eb71 eperm done?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 45
diff changeset
16 open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ) renaming (reverse to rev )
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
17 open import nat
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
19 open import Symmetric
0
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
dc677bac3c54 Permutation group
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
22 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
23 open import Data.Empty
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
24 open import Relation.Binary.Core
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 16
diff changeset
25 open import fin
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
26
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
27 -- An inductive construction of permutation
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
28
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
29 -- we already have refl and trans in the Symmetric Group
41
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
30
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
31 pprep : {n : ℕ } → Permutation n n → Permutation (suc n) (suc n)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
32 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
33 p→ : Fin (suc n) → Fin (suc n)
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
34 p→ zero = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
35 p→ (suc x) = suc ( perm ⟨$⟩ˡ x)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
36
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
37 p← : Fin (suc n) → Fin (suc n)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
38 p← zero = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
39 p← (suc x) = suc ( perm ⟨$⟩ʳ x)
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
40
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
41 piso← : (x : Fin (suc n)) → p→ ( p← x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
42 piso← zero = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
43 piso← (suc x) = cong (λ k → suc k ) (inverseˡ perm)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
44
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
45 piso→ : (x : Fin (suc n)) → p← ( p→ x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
46 piso→ zero = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
47 piso→ (suc x) = cong (λ k → suc k ) (inverseʳ perm)
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
48
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
49 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
50 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
51 p→ : Fin (suc (suc n)) → Fin (suc (suc n))
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
52 p→ zero = suc zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
53 p→ (suc zero) = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
54 p→ (suc (suc x)) = suc ( suc ( perm ⟨$⟩ˡ x) )
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
55
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
56 p← : Fin (suc (suc n)) → Fin (suc (suc n))
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
57 p← zero = suc zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
58 p← (suc zero) = zero
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
59 p← (suc (suc x)) = suc ( suc ( perm ⟨$⟩ʳ x) )
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
60
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
61 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
62 piso← zero = refl
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
63 piso← (suc zero) = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
64 piso← (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseˡ perm)
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
65
34
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
66 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
67 piso→ zero = refl
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
68 piso→ (suc zero) = refl
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
69 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
70
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
71 -- enumeration
c9dbbe12a03b inductive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
72
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
73 psawpn : {n : ℕ} → 1 < n → Permutation n n
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
74 psawpn {suc zero} (s≤s ())
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
75 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
76
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
77 pfill : { n m : ℕ } → m ≤ n → Permutation m m → Permutation n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
78 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
79 pfill1 : (i : ℕ ) → i ≤ n → Permutation (n - i) (n - i) → Permutation n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
80 pfill1 0 _ perm = perm
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
81 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
82
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
83 --
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
84 -- psawpim (inseert swap at position m )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
85 -- not easy to write directory beacause left-inverse-of may contains Fin relations
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
86 --
45
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
87 psawpim : {n m : ℕ} → suc (suc m) ≤ n → Permutation n n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
88 psawpim {n} {m} m≤n = pfill m≤n ( psawpn (s≤s (s≤s z≤n)) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
89
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
90 n≤ : (i : ℕ ) → {j : ℕ } → i ≤ i + j
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
91 n≤ (zero) {j} = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
92 n≤ (suc i) {j} = s≤s ( n≤ i )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
93
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
94 lem0 : {n : ℕ } → n ≤ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
95 lem0 {zero} = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
96 lem0 {suc n} = s≤s lem0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
97
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
98 lem00 : {n m : ℕ } → n ≡ m → n ≤ m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
99 lem00 refl = lem0
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
100
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
101 -- 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
102 -- 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
103
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
104 -- inductivley enmumerate permutations
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
105 -- 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
106
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
107 -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ []
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
108 -- 1 ∷ 0 ∷ 2 ∷ 3 ∷ [] plist ( pins {3} (n≤ 1) )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
109 -- 1 ∷ 2 ∷ 0 ∷ 3 ∷ []
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
110 -- 1 ∷ 2 ∷ 3 ∷ 0 ∷ []
45
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
111
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
112 pins : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n)
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
113 pins {_} {zero} _ = pid
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
114 pins {suc _} {suc zero} _ = pswap pid
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
115 pins {suc (suc n)} {suc m} (s≤s m<n) = pins1 (suc m) (suc (suc n)) lem0 where
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
116 pins1 : (i j : ℕ ) → j ≤ suc (suc n) → Permutation (suc (suc (suc n ))) (suc (suc (suc n)))
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
117 pins1 _ zero _ = pid
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
118 pins1 zero _ _ = pid
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
119 pins1 (suc i) (suc j) (s≤s si≤n) = psawpim {suc (suc (suc n))} {j} (s≤s (s≤s si≤n)) ∘ₚ pins1 i j (≤-trans si≤n refl-≤s )
37
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
120
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
121 plist : {n : ℕ} → Permutation n n → List ℕ
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
122 plist {0} perm = []
44
9ce6141ef479 start again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 41
diff changeset
123 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
124 n = suc j
32db08b3c1a3 emumelation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
125 plist1 : (i : ℕ ) → i < n → List ℕ
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
126 plist1 zero _ = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ {zero} (s≤s z≤n))) ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
127 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
128
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
129 data FL : (n : ℕ )→ Set where
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
130 f0 : FL 0
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
131 _::_ : { n : ℕ } → Fin (suc n ) → FL n → FL (suc n)
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
132
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
133 open import logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
134
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
135 shrink : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → perm ⟨$⟩ˡ (fromℕ n) ≡ fromℕ n → Permutation n n
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
136 shrink {n} perm p0=0 = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
137 shlem→ : (x : Fin n ) → toℕ (perm ⟨$⟩ˡ (fin+1 x)) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
138 shlem→ x with <-cmp (toℕ (perm ⟨$⟩ˡ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
139 shlem→ x | tri< a ¬b ¬c = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
140 shlem→ x | tri≈ ¬a b ¬c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
141 shlem→ x | tri> ¬a ¬b c = {!!}
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
142
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
143 shlem← : (x : Fin n) → toℕ (perm ⟨$⟩ʳ (fin+1 x)) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
144 shlem← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
145 shlem← x | tri< a ¬b ¬c = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
146 shlem← x | tri≈ ¬a b ¬c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
147 shlem← x | tri> ¬a ¬b c = {!!}
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
148
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
149 p→ : (x : Fin n ) → Fin n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
150 p→ x = fromℕ≤ (shlem→ x)
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
151
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
152 p← : Fin n → Fin n
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
153 p← x = fromℕ≤ (shlem← x)
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
154
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
155 piso← : (x : Fin n ) → p→ ( p← x ) ≡ x
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
156 piso← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
157 piso← x | tri< a ¬b ¬c with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
158 piso← x | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
159 piso← x | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
160 piso← x | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
161 piso← x | tri≈ ¬a b ¬c = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
162 piso← x | tri> ¬a ¬b c = {!!}
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
163
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
164 piso→ : (x : Fin n ) → p← ( p→ x ) ≡ x
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
165 piso→ x = {!!}
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
166
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
167 perm→FL : {n : ℕ } → Permutation n n → FL n
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
168 perm→FL {zero} perm = f0
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
169 perm→FL {suc n} perm = (perm ⟨$⟩ˡ fromℕ≤ a<sa ) :: perm→FL ( shrink fl1 {!!} ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
170 fl1 : Permutation (suc n) (suc n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
171 fl1 = perm ∘ₚ pinv ( pins {!!})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
172 fl1=pprep : perm =p= pprep ( shrink fl1 {!!} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
173 fl1=pprep = {!!}
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
174
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
175 FL→perm : {n : ℕ } → FL n → Permutation n n
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
176 FL→perm f0 = pid
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
177 FL→perm (x :: fl) = pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x )
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
178
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
179 FL→iso : {n : ℕ } → (fl : FL n ) → perm→FL ( FL→perm fl ) ≡ fl
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
180 FL→iso f0 = refl
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
181 FL→iso (x :: fl) = {!!} --with FL→iso fl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
182 -- ... | t = {!!}
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
183
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
184 open _=p=_
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
185 FL←iso : {n : ℕ } → (perm : Permutation n n ) → FL→perm ( perm→FL perm ) =p= perm
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
186 FL←iso {0} perm = record { peq = λ () }
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
187 FL←iso {suc n} perm = {!!} where
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
188 fl0 : {n : ℕ } → (fl : FL n ) → {!!}
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
189 fl0 = {!!}
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
190
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
191 all-perm : (n : ℕ ) → List (Permutation (suc n) (suc n) )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
192 all-perm n = pls6 n where
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
193 lem1 : {i n : ℕ } → i ≤ n → i < suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
194 lem1 z≤n = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
195 lem1 (s≤s lt) = s≤s (lem1 lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
196 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
197 lem2 i≤n = ≤-trans i≤n ( refl-≤s )
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
198 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n))
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
199 pls4 zero n i≤n perm x = (pprep perm ∘ₚ pins i≤n ) ∷ x
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
200 pls4 (suc i) n i≤n perm x = pls4 i n (≤-trans refl-≤s i≤n ) perm (pprep perm ∘ₚ pins {n} {suc i} i≤n ∷ x)
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
201 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
202 pls5 n [] x = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
203 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
204 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
205 pls6 zero = pid ∷ []
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
206 pls6 (suc n) = pls5 (suc n) (rev (pls6 n) ) [] -- rev to put id first
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
207
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
208 pls : (n : ℕ ) → List (List ℕ )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
209 pls n = Data.List.map plist (all-perm n) where