annotate Putil.agda @ 58:80d61b6776d3

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Aug 2020 20:07:23 +0900
parents 518d364a58a3
children afa989a4b7e9
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
56
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
135 -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] → 0 ∷ 1 ∷ 2 ∷ []
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
136 shrink : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → perm ⟨$⟩ˡ (fromℕ n) ≡ fromℕ n → Permutation n n
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
137 shrink {n} perm pn=n = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
139 sh3 : (x : Fin n) → ¬ ( toℕ (perm ⟨$⟩ˡ (fin+1 x)) ≡ n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
140 sh3 x eq = ⊥-elim ( nat-≡< sh31 fin<n ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
141 sh31 : toℕ x ≡ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
142 sh31 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
143 toℕ x
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
144 ≡⟨ sym fin+1-toℕ ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
145 toℕ (fin+1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
146 ≡⟨ cong (λ k → toℕ k ) (sym ( inverseʳ perm)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
147 toℕ (perm ⟨$⟩ʳ (perm ⟨$⟩ˡ (fin+1 x)))
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
148 ≡⟨ cong (λ k → toℕ (perm ⟨$⟩ʳ k )) (sym (toℕ→from eq)) ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
149 toℕ (perm ⟨$⟩ʳ fromℕ n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
150 ≡⟨ cong ( λ k → toℕ (perm ⟨$⟩ʳ k )) (sym pn=n) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
151 toℕ (perm ⟨$⟩ʳ (perm ⟨$⟩ˡ (fromℕ n) ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
152 ≡⟨ cong (λ k → toℕ k ) ( inverseʳ perm ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
153 toℕ (fromℕ n)
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
154 ≡⟨ toℕ-fromℕ _ ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
155 n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
156 ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
157 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
158
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
159 sh4 : (x : Fin n) → ¬ ( toℕ (perm ⟨$⟩ʳ (fin+1 x)) ≡ n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
160 sh4 x eq = ⊥-elim ( nat-≡< sh41 fin<n ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
161 sh41 : toℕ x ≡ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
162 sh41 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
163 toℕ x
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
164 ≡⟨ sym fin+1-toℕ ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
165 toℕ (fin+1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
166 ≡⟨ cong (λ k → toℕ k ) (sym ( inverseˡ perm)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
167 toℕ (perm ⟨$⟩ˡ (perm ⟨$⟩ʳ (fin+1 x)))
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
168 ≡⟨ cong (λ k → toℕ (perm ⟨$⟩ˡ k )) (sym (toℕ→from eq)) ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
169 toℕ ((perm ⟨$⟩ˡ fromℕ n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
170 ≡⟨ cong (λ k → toℕ k) pn=n ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
171 toℕ (fromℕ n)
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
172 ≡⟨ toℕ-fromℕ _ ⟩
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
173 n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
174 ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
175 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
176
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
177 sh5 : (x : Fin n) → ¬ ( toℕ (perm ⟨$⟩ˡ (fin+1 x)) > n )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
178 sh5 x lt = ⊥-elim ( nat-≤> lt (fin<n {suc n} {perm ⟨$⟩ˡ (fin+1 x)}))
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
179
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
180 sh6 : (x : Fin n) → ¬ ( toℕ (perm ⟨$⟩ʳ (fin+1 x)) > n )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
181 sh6 x lt = ⊥-elim ( nat-≤> lt (fin<n {suc n} {perm ⟨$⟩ʳ (fin+1 x)}))
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
182
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
183 shlem→ : (x : Fin n ) → toℕ (perm ⟨$⟩ˡ (fin+1 x)) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
184 shlem→ x with <-cmp (toℕ (perm ⟨$⟩ˡ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
185 shlem→ x | tri< a ¬b ¬c = a
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
186 shlem→ x | tri≈ ¬a b ¬c = ⊥-elim ( sh3 x b )
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
187 shlem→ x | tri> ¬a ¬b c = ⊥-elim ( sh5 x c )
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
188
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
189 shlem← : (x : Fin n) → toℕ (perm ⟨$⟩ʳ (fin+1 x)) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
190 shlem← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
191 shlem← x | tri< a ¬b ¬c = a
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
192 shlem← x | tri≈ ¬a b ¬c = ⊥-elim ( sh4 x b )
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
193 shlem← x | tri> ¬a ¬b c = ⊥-elim ( sh6 x c )
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
194
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
195 p→ : (x : Fin n ) → Fin n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
196 p→ x = fromℕ≤ (shlem→ x)
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
197
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
198 p← : Fin n → Fin n
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
199 p← x = fromℕ≤ (shlem← x)
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
200
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
201 ff : { x y n : ℕ } → (x ≡ y ) → (x<n : x < n) → (y<n : y < n) → fromℕ≤ x<n ≡ fromℕ≤ y<n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
202 ff refl _ _ = lemma10 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
203
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
204 -- a : (toℕ (Inverse.to perm Π.⟨$⟩ fin+1 x)) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
205 -- a₁ : (toℕ (Inverse.from perm Π.⟨$⟩ fin+1 (fromℕ≤ a))) < n
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
206 piso← : (x : Fin n ) → p→ ( p← x ) ≡ x
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
207 piso← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
208 piso← x | tri< a ¬b ¬c with <-cmp (toℕ (perm ⟨$⟩ˡ (fin+1 (fromℕ≤ a)))) n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
209 piso← x | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
210 fromℕ≤ a₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
211 ≡⟨ ff sh1 a₁ (toℕ<n x) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
212 fromℕ≤ (toℕ<n x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
213 ≡⟨ fromℕ≤-toℕ _ _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
214 x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
215 ∎ where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
216 open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
217 sh1 : toℕ (Inverse.from perm Π.⟨$⟩ fin+1 (fromℕ≤ a)) ≡ toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
218 sh1 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
219 toℕ (Inverse.from perm Π.⟨$⟩ fin+1 (fromℕ≤ a))
53
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
220 ≡⟨ cong (λ k → toℕ (Inverse.from perm Π.⟨$⟩ k)) (fin+1≤ a ) ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
221 toℕ (Inverse.from perm Π.⟨$⟩ (fromℕ≤ (<-trans a a<sa ) ))
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
222 ≡⟨ cong (λ k → toℕ (Inverse.from perm Π.⟨$⟩ k)) (fromℕ≤-toℕ (Inverse.to perm Π.⟨$⟩ (fin+1 x)) (<-trans a a<sa) ) ⟩
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
223 toℕ (Inverse.from perm Π.⟨$⟩ ( Inverse.to perm Π.⟨$⟩ (fin+1 x) ))
53
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
224 ≡⟨ cong (λ k → toℕ k) (inverseˡ perm) ⟩
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
225 toℕ (fin+1 x)
53
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
226 ≡⟨ fin+1-toℕ ⟩
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
227 toℕ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
228
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
229 piso← x | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim ( sh3 (fromℕ≤ a) b )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
230 piso← x | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = ⊥-elim ( sh5 _ c )
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
231 piso← x | tri≈ ¬a b ¬c = ⊥-elim ( sh4 x b )
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
232 piso← x | tri> ¬a ¬b c = ⊥-elim ( sh6 x c )
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
233
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
234 piso→ : (x : Fin n ) → p← ( p→ x ) ≡ x
53
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
235 piso→ x with <-cmp (toℕ (perm ⟨$⟩ˡ (fin+1 x))) n
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
236 piso→ x | tri< a ¬b ¬c with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 (fromℕ≤ a)))) n
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
237 piso→ x | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = begin
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
238 fromℕ≤ a₁
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
239 ≡⟨ ff sh2 a₁ (toℕ<n x) ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
240 fromℕ≤ (toℕ<n x)
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
241 ≡⟨ fromℕ≤-toℕ _ _ ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
242 x
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
243 ∎ where
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
244 open ≡-Reasoning
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
245 sh2 : toℕ (Inverse.to perm Π.⟨$⟩ fin+1 (fromℕ≤ a)) ≡ toℕ x
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
246 sh2 = begin
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
247 toℕ (Inverse.to perm Π.⟨$⟩ fin+1 (fromℕ≤ a))
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
248 ≡⟨ cong (λ k → toℕ (Inverse.to perm Π.⟨$⟩ k)) (fin+1≤ a ) ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
249 toℕ (Inverse.to perm Π.⟨$⟩ (fromℕ≤ (<-trans a a<sa ) ))
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
250 ≡⟨ cong (λ k → toℕ (Inverse.to perm Π.⟨$⟩ k)) (fromℕ≤-toℕ (Inverse.from perm Π.⟨$⟩ (fin+1 x)) (<-trans a a<sa) ) ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
251 toℕ (Inverse.to perm Π.⟨$⟩ ( Inverse.from perm Π.⟨$⟩ (fin+1 x) ))
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
252 ≡⟨ cong (λ k → toℕ k) (inverseʳ perm) ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
253 toℕ (fin+1 x)
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
254 ≡⟨ fin+1-toℕ ⟩
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
255 toℕ x
2283d6f8a2fb connected
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
256
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
257 piso→ x | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim ( sh4 (fromℕ≤ a) b )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
258 piso→ x | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = ⊥-elim ( sh6 _ c )
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
259 piso→ x | tri≈ ¬a b ¬c = ⊥-elim ( sh3 x b )
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
260 piso→ x | tri> ¬a ¬b c = ⊥-elim ( sh5 x c )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
261
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
262 FL→perm : {n : ℕ } → FL n → Permutation n n
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
263 FL→perm f0 = pid
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
264 FL→perm (x :: fl) = pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x )
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
265
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
266 t1 = plist (shrink (pid {3} ∘ₚ (pins (n≤ 1))) refl)
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
267 t3 = plist (pid {4} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
268 ∷ plist ( FL→perm ((# 0) :: ((# 0) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) -- (0 ∷ 1 ∷ 2 ∷ []) ∷
57
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
269 ∷ plist ( FL→perm ((# 1) :: ((# 0) :: ( (# 1) :: (( # 0 ) :: f0 )) ))) -- (0 ∷ 2 ∷ 1 ∷ []) ∷
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
270 ∷ plist ( FL→perm ((# 1) :: ((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) -- (1 ∷ 0 ∷ 2 ∷ []) ∷
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
271 ∷ plist ( FL→perm ((# 1) :: ((# 1) :: ( (# 1) :: (( # 0 ) :: f0 )) ))) -- (2 ∷ 0 ∷ 1 ∷ []) ∷
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
272 ∷ plist ( FL→perm ((# 1) :: ((# 2) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) -- (1 ∷ 2 ∷ 0 ∷ []) ∷
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
273 ∷ plist ( FL→perm ((# 1) :: ((# 2) :: ( (# 1) :: (( # 0 ) :: f0 )) ))) -- (2 ∷ 1 ∷ 0 ∷ []) ∷
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
274 ∷ plist ( (flip (FL→perm ((# 1) :: ((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) )))))
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
275 ∷ plist ( (flip (FL→perm ((# 1) :: ((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) ∘ₚ (FL→perm ((# 1) :: (((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) )))) ))
518d364a58a3 shrink worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 56
diff changeset
276 ∷ []
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
277
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
278 t4 = FL→perm ((# 1) :: ((# 1) :: ( (# 1) :: (( # 0 ) :: f0 )) ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
279 -- t5 = plist t4 ∷ plist ( t4 ∘ₚ flip (pins ( n≤ 3 ) ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
280 t5 = plist (flip t4)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
281 ∷ ( toℕ (t4 ⟨$⟩ˡ fromℕ≤ a<sa) ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
282 ∷ ( toℕ (t4 ⟨$⟩ʳ fromℕ≤ ( fin<n {_} {(t4 ⟨$⟩ˡ fromℕ≤ a<sa)})) ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
283 ∷ plist (shrink ( t4 ∘ₚ flip (pins ( n≤ 3 ) ) ) refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
284 ∷ plist ( FL→perm (((# 1) :: ( (# 1) :: (( # 0 ) :: f0 )) )))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
285 ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
286
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
287
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
288 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
289 perm→FL {zero} perm = f0
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
290 perm→FL {suc n} perm = (perm ⟨$⟩ˡ fromℕ≤ a<sa ) :: perm→FL ( shrink fl1 fl4 ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
291 fl2 : Fin (suc n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
292 fl2 = perm ⟨$⟩ʳ fromℕ≤ (fin<n {suc n} {perm ⟨$⟩ˡ fromℕ≤ a<sa} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
293 fl3 : toℕ fl2 < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
294 fl3 = {!!}
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
295 fl1 : Permutation (suc n) (suc n)
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
296 fl1 = perm ∘ₚ pinv ( pins fl3 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
297 fl4 : (fl1 ⟨$⟩ˡ fromℕ n) ≡ fromℕ n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
298 fl4 = {!!}
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
299
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
300 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
301 FL→iso f0 = refl
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
302 FL→iso (x :: fl) = {!!}
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
303
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
304 open _=p=_
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
305 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
306 FL←iso {0} perm = record { peq = λ () }
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 57
diff changeset
307 FL←iso {suc n} perm = {!!}
49
8b3b95362ca9 remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
308
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
309 all-perm : (n : ℕ ) → List (Permutation (suc n) (suc n) )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
310 all-perm n = pls6 n where
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
311 lem1 : {i n : ℕ } → i ≤ n → i < suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
312 lem1 z≤n = s≤s z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
313 lem1 (s≤s lt) = s≤s (lem1 lt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
314 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
315 lem2 i≤n = ≤-trans i≤n ( refl-≤s )
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
316 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
317 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
318 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
319 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
320 pls5 n [] x = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
321 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
322 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
323 pls6 zero = pid ∷ []
48
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
324 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
325
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
326 pls : (n : ℕ ) → List (List ℕ )
ac2f21a2d467 cleanup
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
327 pls n = Data.List.map plist (all-perm n) where