Mercurial > hg > Members > kono > Proof > galois
annotate Putil.agda @ 105:e435dbe2e7a6
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Sep 2020 17:45:33 +0900 |
parents | 2d0738a38ac9 |
children | 02f54eab9205 |
rev | line source |
---|---|
90 | 1 {-# OPTIONS --allow-unsolved-metas #-} |
48 | 2 module Putil where |
0 | 3 |
4 open import Level hiding ( suc ; zero ) | |
5 open import Algebra | |
6 open import Algebra.Structures | |
37 | 7 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ) |
90 | 8 open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ; ≤-irrelevant ) renaming ( <-cmp to <-fcmp ) |
0 | 9 open import Data.Fin.Permutation |
10 open import Function hiding (id ; flip) | |
11 open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_) | |
12 open import Function.LeftInverse using ( _LeftInverseOf_ ) | |
13 open import Function.Equality using (Π) | |
17 | 14 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n ) |
15 open import Data.Nat.Properties -- using (<-trans) | |
16 | 16 open import Relation.Binary.PropositionalEquality |
80 | 17 open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ; tail ) renaming (reverse to rev ) |
16 | 18 open import nat |
0 | 19 |
48 | 20 open import Symmetric |
0 | 21 |
22 | |
16 | 23 open import Relation.Nullary |
24 open import Data.Empty | |
17 | 25 open import Relation.Binary.Core |
80 | 26 open import Relation.Binary.Definitions |
17 | 27 open import fin |
16 | 28 |
38 | 29 -- An inductive construction of permutation |
34 | 30 |
59 | 31 -- Todo |
32 -- | |
33 -- describe property of pins ( move 0 to any position) | |
34 -- describe property of shrink ( remove one column ) | |
35 -- prove FL→iso | |
36 -- prove FL←iso | |
37 | |
48 | 38 -- we already have refl and trans in the Symmetric Group |
41 | 39 |
34 | 40 pprep : {n : ℕ } → Permutation n n → Permutation (suc n) (suc n) |
41 pprep {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where | |
33 | 42 p→ : Fin (suc n) → Fin (suc n) |
34 | 43 p→ zero = zero |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
44 p→ (suc x) = suc ( perm ⟨$⟩ʳ x) |
33 | 45 |
34 | 46 p← : Fin (suc n) → Fin (suc n) |
47 p← zero = zero | |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
48 p← (suc x) = suc ( perm ⟨$⟩ˡ x) |
34 | 49 |
50 piso← : (x : Fin (suc n)) → p→ ( p← x ) ≡ x | |
51 piso← zero = refl | |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
52 piso← (suc x) = cong (λ k → suc k ) (inverseʳ perm) |
33 | 53 |
34 | 54 piso→ : (x : Fin (suc n)) → p← ( p→ x ) ≡ x |
55 piso→ zero = refl | |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
56 piso→ (suc x) = cong (λ k → suc k ) (inverseˡ perm) |
33 | 57 |
34 | 58 pswap : {n : ℕ } → Permutation n n → Permutation (suc (suc n)) (suc (suc n )) |
59 pswap {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where | |
60 p→ : Fin (suc (suc n)) → Fin (suc (suc n)) | |
61 p→ zero = suc zero | |
62 p→ (suc zero) = zero | |
62 | 63 p→ (suc (suc x)) = suc ( suc ( perm ⟨$⟩ʳ x) ) |
18 | 64 |
34 | 65 p← : Fin (suc (suc n)) → Fin (suc (suc n)) |
66 p← zero = suc zero | |
67 p← (suc zero) = zero | |
62 | 68 p← (suc (suc x)) = suc ( suc ( perm ⟨$⟩ˡ x) ) |
34 | 69 |
70 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x | |
71 piso← zero = refl | |
72 piso← (suc zero) = refl | |
62 | 73 piso← (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseʳ perm) |
16 | 74 |
34 | 75 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x |
76 piso→ zero = refl | |
77 piso→ (suc zero) = refl | |
62 | 78 piso→ (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseˡ perm) |
34 | 79 |
80 -- enumeration | |
81 | |
44 | 82 psawpn : {n : ℕ} → 1 < n → Permutation n n |
83 psawpn {suc zero} (s≤s ()) | |
84 psawpn {suc n} (s≤s (s≤s x)) = pswap pid | |
34 | 85 |
35 | 86 pfill : { n m : ℕ } → m ≤ n → Permutation m m → Permutation n n |
87 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 | |
88 pfill1 : (i : ℕ ) → i ≤ n → Permutation (n - i) (n - i) → Permutation n n | |
89 pfill1 0 _ perm = perm | |
90 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 | 91 |
48 | 92 -- |
93 -- psawpim (inseert swap at position m ) | |
94 -- | |
45 | 95 psawpim : {n m : ℕ} → suc (suc m) ≤ n → Permutation n n |
96 psawpim {n} {m} m≤n = pfill m≤n ( psawpn (s≤s (s≤s z≤n)) ) | |
97 | |
98 n≤ : (i : ℕ ) → {j : ℕ } → i ≤ i + j | |
99 n≤ (zero) {j} = z≤n | |
100 n≤ (suc i) {j} = s≤s ( n≤ i ) | |
101 | |
102 lem0 : {n : ℕ } → n ≤ n | |
103 lem0 {zero} = z≤n | |
104 lem0 {suc n} = s≤s lem0 | |
105 | |
106 lem00 : {n m : ℕ } → n ≡ m → n ≤ m | |
107 lem00 refl = lem0 | |
44 | 108 |
80 | 109 plist1 : {n : ℕ} → Permutation (suc n) (suc n) → (i : ℕ ) → i < suc n → List ℕ |
110 plist1 {n} perm zero _ = toℕ ( perm ⟨$⟩ˡ (fromℕ< {zero} (s≤s z≤n))) ∷ [] | |
111 plist1 {n} perm (suc i) (s≤s lt) = toℕ ( perm ⟨$⟩ˡ (fromℕ< (s≤s lt))) ∷ plist1 perm i (<-trans lt a<sa) | |
112 | |
37 | 113 plist : {n : ℕ} → Permutation n n → List ℕ |
114 plist {0} perm = [] | |
80 | 115 plist {suc n} perm = rev (plist1 perm n a<sa) |
116 | |
89 | 117 -- pconcat : {n m : ℕ } → Permutation m m → Permutation n n → Permutation (m + n) (m + n) |
118 -- pconcat {n} {m} p q = pfill {n + m} {m} ? p ∘ₚ ? | |
119 | |
120 -- inductivley enmumerate permutations | |
121 -- from n-1 length create n length inserting new element at position m | |
122 | |
123 -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] | |
124 -- 1 ∷ 0 ∷ 2 ∷ 3 ∷ [] plist ( pins {3} (n≤ 1) ) 1 ∷ 0 ∷ 2 ∷ 3 ∷ [] | |
125 -- 1 ∷ 2 ∷ 0 ∷ 3 ∷ [] plist ( pins {3} (n≤ 2) ) 2 ∷ 0 ∷ 1 ∷ 3 ∷ [] | |
126 -- 1 ∷ 2 ∷ 3 ∷ 0 ∷ [] plist ( pins {3} (n≤ 3) ) 3 ∷ 0 ∷ 1 ∷ 2 ∷ [] | |
94 | 127 -- pins : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n) |
128 -- pins {_} {zero} _ = pid | |
129 -- pins {suc _} {suc zero} _ = pswap pid | |
130 -- pins {suc (suc n)} {suc m} (s≤s m<n) = pins1 (suc m) (suc (suc n)) lem0 where | |
131 -- pins1 : (i j : ℕ ) → j ≤ suc (suc n) → Permutation (suc (suc (suc n ))) (suc (suc (suc n))) | |
132 -- pins1 _ zero _ = pid | |
133 -- pins1 zero _ _ = pid | |
134 -- 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 a≤sa ) | |
89 | 135 |
90 | 136 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) |
91 | 137 open ≡-Reasoning |
90 | 138 |
94 | 139 pins : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n) |
140 pins {_} {zero} _ = pid | |
141 pins {suc n} {suc m} (s≤s m≤n) = permutation p← p→ record { left-inverse-of = piso← ; right-inverse-of = piso→ } where | |
89 | 142 |
143 next : Fin (suc (suc n)) → Fin (suc (suc n)) | |
144 next zero = suc zero | |
91 | 145 next (suc x) = fromℕ< (≤-trans (fin<n {_} {x} ) a≤sa ) |
89 | 146 |
147 p→ : Fin (suc (suc n)) → Fin (suc (suc n)) | |
148 p→ x with <-cmp (toℕ x) (suc m) | |
90 | 149 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (s≤s a) (s≤s (s≤s m≤n) )) |
89 | 150 ... | tri≈ ¬a b ¬c = zero |
151 ... | tri> ¬a ¬b c = x | |
152 | |
153 p← : Fin (suc (suc n)) → Fin (suc (suc n)) | |
154 p← zero = fromℕ< (s≤s (s≤s m≤n)) | |
155 p← (suc x) with <-cmp (toℕ x) (suc m) | |
91 | 156 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (fin<n {_} {x}) a≤sa ) |
89 | 157 ... | tri≈ ¬a b ¬c = suc x |
158 ... | tri> ¬a ¬b c = suc x | |
90 | 159 |
160 mm : toℕ (fromℕ< {suc m} {suc (suc n)} (s≤s (s≤s m≤n))) ≡ suc m | |
161 mm = toℕ-fromℕ< (s≤s (s≤s m≤n)) | |
162 | |
91 | 163 mma : (x : Fin (suc n) ) → suc (toℕ x) ≤ suc m → toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) a≤sa ) ) ≤ m |
164 mma x (s≤s x<sm) = subst (λ k → k ≤ m) (sym (toℕ-fromℕ< (≤-trans fin<n a≤sa ) )) x<sm | |
89 | 165 |
91 | 166 p3 : (x : Fin (suc n) ) → toℕ (fromℕ< (≤-trans (fin<n {_} {suc x} ) (s≤s a≤sa))) ≡ suc (toℕ x) |
167 p3 x = begin | |
168 toℕ (fromℕ< (≤-trans (fin<n {_} {suc x} ) (s≤s a≤sa))) | |
169 ≡⟨ toℕ-fromℕ< ( s≤s ( ≤-trans fin<n a≤sa ) ) ⟩ | |
170 suc (toℕ x) | |
171 ∎ | |
92 | 172 |
173 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x | |
174 piso→ zero with <-cmp (toℕ (fromℕ< (≤-trans (s≤s z≤n) (s≤s (s≤s m≤n) )))) (suc m) | |
175 ... | tri< a ¬b ¬c = refl | |
176 piso→ (suc x) with <-cmp (toℕ (suc x)) (suc m) | |
94 | 177 ... | tri≈ ¬a refl ¬c = p13 where |
178 p13 : fromℕ< (s≤s (s≤s m≤n)) ≡ suc x | |
179 p13 = cong (λ k → suc k ) (fromℕ<-toℕ _ (s≤s m≤n) ) | |
95 | 180 ... | tri> ¬a ¬b c = p16 (suc x) refl where |
181 p16 : (y : Fin (suc (suc n))) → y ≡ suc x → p← y ≡ suc x | |
182 p16 zero eq = ⊥-elim ( nat-≡< (cong (λ k → suc (toℕ k) ) eq) (s≤s (s≤s (z≤n)))) | |
183 p16 (suc y) eq with <-cmp (toℕ y) (suc m) -- suc (suc m) < toℕ (suc x) | |
96 | 184 ... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< refl ( ≤-trans c (subst (λ k → k < suc m) p17 a )) ) where |
185 -- x = suc m case, c : suc (suc m) ≤ suc (toℕ x), a : suc (toℕ y) ≤ suc m, suc y ≡ suc x | |
186 p17 : toℕ y ≡ toℕ x | |
187 p17 with <-cmp (toℕ y) (toℕ x) | cong toℕ eq | |
188 ... | tri< a ¬b ¬c | seq = ⊥-elim ( nat-≡< seq (s≤s a) ) | |
189 ... | tri≈ ¬a b ¬c | seq = b | |
190 ... | tri> ¬a ¬b c | seq = ⊥-elim ( nat-≡< (sym seq) (s≤s c)) | |
95 | 191 ... | tri≈ ¬a b ¬c = eq |
192 ... | tri> ¬a ¬b c₁ = eq | |
92 | 193 ... | tri< a ¬b ¬c = p10 (fromℕ< (≤-trans (s≤s a) (s≤s (s≤s m≤n) ))) refl where |
194 p10 : (y : Fin (suc (suc n)) ) → y ≡ fromℕ< (≤-trans (s≤s a) (s≤s (s≤s m≤n) )) → p← y ≡ suc x | |
195 p10 zero () | |
93 | 196 p10 (suc y) eq = p15 where |
197 p12 : toℕ y ≡ suc (toℕ x) | |
198 p12 = begin | |
199 toℕ y | |
200 ≡⟨ cong (λ k → Data.Nat.pred (toℕ k)) eq ⟩ | |
201 toℕ (fromℕ< (≤-trans a (s≤s m≤n))) | |
202 ≡⟨ toℕ-fromℕ< {suc (toℕ x)} {suc n} (≤-trans a (s≤s m≤n)) ⟩ | |
203 suc (toℕ x) | |
92 | 204 ∎ |
93 | 205 p15 : p← (suc y) ≡ suc x |
206 p15 with <-cmp (toℕ y) (suc m) -- eq : suc y ≡ suc (suc (fromℕ< (≤-pred (≤-trans a (s≤s m≤n))))) , a : suc x < suc m | |
207 ... | tri< a₁ ¬b ¬c = p11 where | |
208 p11 : fromℕ< (≤-trans (fin<n {_} {y}) a≤sa ) ≡ suc x | |
209 p11 = begin | |
210 fromℕ< (≤-trans (fin<n {_} {y}) a≤sa ) | |
211 ≡⟨ fromℕ<-irrelevant _ _ p12 _ (s≤s (fin<n {suc n})) ⟩ | |
212 suc (fromℕ< (fin<n {suc n} {x} )) | |
213 ≡⟨ cong suc (fromℕ<-toℕ x _ ) ⟩ | |
214 suc x | |
215 ∎ | |
216 ... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< b (subst (λ k → k < suc m) (sym p12) a )) -- suc x < suc m -> y = suc x → toℕ y < suc m | |
217 ... | tri> ¬a ¬b c = ⊥-elim ( nat-<> c (subst (λ k → k < suc m) (sym p12) a )) | |
92 | 218 |
89 | 219 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x |
90 | 220 piso← zero with <-cmp (toℕ (fromℕ< (s≤s (s≤s m≤n)))) (suc m) | mm |
221 ... | tri< a ¬b ¬c | t = ⊥-elim ( ¬b t ) | |
222 ... | tri≈ ¬a b ¬c | t = refl | |
223 ... | tri> ¬a ¬b c | t = ⊥-elim ( ¬b t ) | |
224 piso← (suc x) with <-cmp (toℕ x) (suc m) | |
91 | 225 ... | tri> ¬a ¬b c with <-cmp (toℕ (suc x)) (suc m) |
226 ... | tri< a ¬b₁ ¬c = ⊥-elim ( nat-<> a (<-trans c a<sa ) ) | |
227 ... | tri≈ ¬a₁ b ¬c = ⊥-elim ( nat-≡< (sym b) (<-trans c a<sa )) | |
228 ... | tri> ¬a₁ ¬b₁ c₁ = refl | |
229 piso← (suc x) | tri≈ ¬a b ¬c with <-cmp (toℕ (suc x)) (suc m) | |
230 ... | tri< a ¬b ¬c₁ = ⊥-elim ( nat-≡< b (<-trans a<sa a) ) | |
231 ... | tri≈ ¬a₁ refl ¬c₁ = ⊥-elim ( nat-≡< b a<sa ) | |
232 ... | tri> ¬a₁ ¬b c = refl | |
233 piso← (suc x) | tri< a ¬b ¬c with <-cmp (toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) a≤sa ) )) (suc m) | |
90 | 234 ... | tri≈ ¬a b ¬c₁ = ⊥-elim ( ¬a (s≤s (mma x a))) |
235 ... | tri> ¬a ¬b₁ c = ⊥-elim ( ¬a (s≤s (mma x a))) | |
236 ... | tri< a₁ ¬b₁ ¬c₁ = p0 where | |
237 p2 : suc (suc (toℕ x)) ≤ suc (suc n) | |
238 p2 = s≤s (fin<n {suc n} {x}) | |
91 | 239 p6 : suc (toℕ (fromℕ< (≤-trans (fin<n {_} {suc x}) (s≤s a≤sa)))) ≤ suc (suc n) |
90 | 240 p6 = s≤s (≤-trans a₁ (s≤s m≤n)) |
241 p0 : fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) )) ≡ suc x | |
242 p0 = begin | |
243 fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) )) | |
244 ≡⟨⟩ | |
245 fromℕ< (s≤s (≤-trans a₁ (s≤s m≤n))) | |
91 | 246 ≡⟨ lemma10 (p3 x) {p6} {p2} ⟩ |
90 | 247 fromℕ< ( s≤s (fin<n {suc n} {x}) ) |
91 | 248 ≡⟨⟩ |
90 | 249 suc (fromℕ< (fin<n {suc n} {x} )) |
91 | 250 ≡⟨ cong suc (fromℕ<-toℕ x _ ) ⟩ |
90 | 251 suc x |
91 | 252 ∎ |
90 | 253 |
94 | 254 t7 = plist (pins {3} (n≤ 3)) ∷ plist (flip ( pins {3} (n≤ 3) )) ∷ plist ( pins {3} (n≤ 3) ∘ₚ flip ( pins {3} (n≤ 3))) ∷ [] |
255 -- t8 = {!!} | |
89 | 256 |
97 | 257 open import logic |
258 | |
259 open _∧_ | |
260 | |
261 perm1 : {perm : Permutation 1 1 } {q : Fin 1} → (perm ⟨$⟩ʳ q ≡ # 0) ∧ ((perm ⟨$⟩ˡ q ≡ # 0)) | |
262 perm1 {p} {q} = ⟪ perm01 _ _ , perm00 _ _ ⟫ where | |
263 perm01 : (x y : Fin 1) → (p ⟨$⟩ʳ x) ≡ y | |
264 perm01 x y with p ⟨$⟩ʳ x | |
265 perm01 zero zero | zero = refl | |
266 perm00 : (x y : Fin 1) → (p ⟨$⟩ˡ x) ≡ y | |
267 perm00 x y with p ⟨$⟩ˡ x | |
268 perm00 zero zero | zero = refl | |
269 | |
270 | |
271 p=0 : {n : ℕ } → (perm : Permutation (suc n) (suc n) ) → ((perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) ⟨$⟩ˡ (# 0)) ≡ # 0 | |
272 p=0 {zero} perm with ((perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) ⟨$⟩ˡ (# 0)) | |
273 ... | zero = refl | |
274 p=0 {suc n} perm with perm ⟨$⟩ʳ (# 0) | inspect (_⟨$⟩ʳ_ perm ) (# 0)| toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0)) | inspect toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0)) | |
275 ... | zero | record { eq = e} | m<n | _ = p001 where | |
276 p001 : perm ⟨$⟩ˡ ( pins m<n ⟨$⟩ʳ zero) ≡ zero | |
277 p001 = subst (λ k → perm ⟨$⟩ˡ k ≡ zero ) e (inverseˡ perm) | |
278 ... | suc t | record { eq = e } | m<n | record { eq = e1 } = p002 where -- m<n : suc (toℕ t) ≤ suc n | |
279 p002 : perm ⟨$⟩ˡ ( pins m<n ⟨$⟩ʳ zero) ≡ zero | |
280 p002 = p005 zero (toℕ t) refl m<n refl where -- suc (toℕ t) ≤ suc n | |
281 p003 : (s : Fin (suc (suc n))) → s ≡ (perm ⟨$⟩ʳ (# 0)) → perm ⟨$⟩ˡ s ≡ # 0 | |
282 p003 s eq = subst (λ k → perm ⟨$⟩ˡ k ≡ zero ) (sym eq) (inverseˡ perm) | |
283 p005 : (x : Fin (suc (suc n))) → (m : ℕ ) → x ≡ zero → (m≤n : suc m ≤ suc n ) → m ≡ toℕ t → perm ⟨$⟩ˡ ( pins m≤n ⟨$⟩ʳ zero) ≡ zero | |
284 p005 zero m eq (s≤s m≤n) meq = p004 where | |
285 p004 : perm ⟨$⟩ˡ (fromℕ< (s≤s (s≤s m≤n))) ≡ zero | |
286 p004 = p003 (fromℕ< (s≤s (s≤s m≤n))) ( | |
287 begin | |
288 fromℕ< (s≤s (s≤s m≤n)) | |
289 ≡⟨ fromℕ<-irrelevant _ _ (cong suc meq) (s≤s (s≤s m≤n)) (subst (λ k → suc k < suc (suc n)) meq (s≤s (s≤s m≤n)) ) ⟩ | |
290 fromℕ< (subst (λ k → suc k < suc (suc n)) meq (s≤s (s≤s m≤n)) ) | |
291 ≡⟨ fromℕ<-toℕ {suc (suc n)} (suc t) (subst (λ k → suc k < suc (suc n)) meq (s≤s (s≤s m≤n)) ) ⟩ | |
292 suc t | |
293 ≡⟨ sym e ⟩ | |
294 (perm ⟨$⟩ʳ (# 0)) | |
295 ∎ ) | |
296 | |
101 | 297 px=x : {n : ℕ } → (x : Fin (suc n)) → pins ( toℕ≤pred[n] x ) ⟨$⟩ʳ (# 0) ≡ x |
298 px=x {n} zero = refl | |
103 | 299 px=x {suc n} (suc x) = p001 where |
300 p002 : fromℕ< (s≤s (toℕ≤pred[n] x)) ≡ x | |
301 p002 = fromℕ<-toℕ x (s≤s (toℕ≤pred[n] x)) | |
302 p001 : (pins (toℕ≤pred[n] (suc x)) ⟨$⟩ʳ (# 0)) ≡ suc x | |
303 p001 with <-cmp 0 ((toℕ x)) | |
304 ... | tri< a ¬b ¬c = cong suc p002 | |
305 ... | tri≈ ¬a b ¬c = cong suc p002 | |
97 | 306 |
307 -- pp : {n : ℕ } → (perm : Permutation (suc n) (suc n) ) → Fin (suc n) | |
308 -- pp perm → (( perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) ⟨$⟩ˡ (# 0)) | |
309 | |
80 | 310 plist2 : {n : ℕ} → Permutation (suc n) (suc n) → (i : ℕ ) → i < suc n → List ℕ |
311 plist2 {n} perm zero _ = toℕ ( perm ⟨$⟩ʳ (fromℕ< {zero} (s≤s z≤n))) ∷ [] | |
312 plist2 {n} perm (suc i) (s≤s lt) = toℕ ( perm ⟨$⟩ʳ (fromℕ< (s≤s lt))) ∷ plist2 perm i (<-trans lt a<sa) | |
313 | |
314 plist0 : {n : ℕ} → Permutation n n → List ℕ | |
315 plist0 {0} perm = [] | |
316 plist0 {suc n} perm = plist2 perm n a<sa | |
317 | |
85 | 318 open _=p=_ |
319 | |
86
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
320 -- |
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
321 -- plist cong |
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
322 -- |
85 | 323 ←pleq : {n : ℕ} → (x y : Permutation n n ) → x =p= y → plist0 x ≡ plist0 y |
324 ←pleq {zero} x y eq = refl | |
325 ←pleq {suc n} x y eq = ←pleq1 n a<sa where | |
326 ←pleq1 : (i : ℕ ) → (i<sn : i < suc n ) → plist2 x i i<sn ≡ plist2 y i i<sn | |
327 ←pleq1 zero _ = cong ( λ k → toℕ k ∷ [] ) ( peq eq (fromℕ< {zero} (s≤s z≤n))) | |
328 ←pleq1 (suc i) (s≤s lt) = cong₂ ( λ j k → toℕ j ∷ k ) ( peq eq (fromℕ< (s≤s lt))) ( ←pleq1 i (<-trans lt a<sa) ) | |
80 | 329 |
330 headeq : {A : Set } → {x y : A } → {xt yt : List A } → (x ∷ xt) ≡ (y ∷ yt) → x ≡ y | |
331 headeq refl = refl | |
332 | |
333 taileq : {A : Set } → {x y : A } → {xt yt : List A } → (x ∷ xt) ≡ (y ∷ yt) → xt ≡ yt | |
334 taileq refl = refl | |
335 | |
86
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
336 -- |
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
337 -- plist equalizer |
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
338 -- |
80 | 339 pleq : {n : ℕ} → (x y : Permutation n n ) → plist0 x ≡ plist0 y → x =p= y |
340 pleq {0} x y refl = record { peq = λ q → pleq0 q } where | |
341 pleq0 : (q : Fin 0 ) → (x ⟨$⟩ʳ q) ≡ (y ⟨$⟩ʳ q) | |
342 pleq0 () | |
343 pleq {suc n} x y eq = record { peq = λ q → pleq1 n a<sa eq q fin<n } where | |
344 pleq1 : (i : ℕ ) → (i<sn : i < suc n ) → plist2 x i i<sn ≡ plist2 y i i<sn → (q : Fin (suc n)) → toℕ q < suc i → x ⟨$⟩ʳ q ≡ y ⟨$⟩ʳ q | |
81 | 345 pleq1 zero i<sn eq q q<i with <-cmp (toℕ q) zero |
346 ... | tri< () ¬b ¬c | |
347 ... | tri> ¬a ¬b c = ⊥-elim (nat-≤> c q<i ) | |
348 ... | tri≈ ¬a b ¬c = begin | |
349 x ⟨$⟩ʳ q | |
350 ≡⟨ cong ( λ k → x ⟨$⟩ʳ k ) (toℕ-injective b )⟩ | |
351 x ⟨$⟩ʳ zero | |
352 ≡⟨ toℕ-injective (headeq eq) ⟩ | |
353 y ⟨$⟩ʳ zero | |
354 ≡⟨ cong ( λ k → y ⟨$⟩ʳ k ) (sym (toℕ-injective b )) ⟩ | |
355 y ⟨$⟩ʳ q | |
91 | 356 ∎ |
80 | 357 pleq1 (suc i) (s≤s i<sn) eq q q<i with <-cmp (toℕ q) (suc i) |
358 ... | tri< a ¬b ¬c = pleq1 i (<-trans i<sn a<sa ) (taileq eq) q a | |
81 | 359 ... | tri> ¬a ¬b c = ⊥-elim (nat-≤> c q<i ) |
80 | 360 ... | tri≈ ¬a b ¬c = begin |
361 x ⟨$⟩ʳ q | |
362 ≡⟨ cong (λ k → x ⟨$⟩ʳ k) (pleq3 b) ⟩ | |
363 x ⟨$⟩ʳ (suc (fromℕ< i<sn)) | |
364 ≡⟨ toℕ-injective pleq2 ⟩ | |
365 y ⟨$⟩ʳ (suc (fromℕ< i<sn)) | |
366 ≡⟨ cong (λ k → y ⟨$⟩ʳ k) (sym (pleq3 b)) ⟩ | |
367 y ⟨$⟩ʳ q | |
368 ∎ where | |
369 pleq3 : toℕ q ≡ suc i → q ≡ suc (fromℕ< i<sn) | |
370 pleq3 tq=si = toℕ-injective ( begin | |
371 toℕ q | |
372 ≡⟨ b ⟩ | |
373 suc i | |
374 ≡⟨ sym (toℕ-fromℕ< (s≤s i<sn)) ⟩ | |
375 toℕ (fromℕ< (s≤s i<sn)) | |
376 ≡⟨⟩ | |
377 toℕ (suc (fromℕ< i<sn)) | |
91 | 378 ∎ ) |
80 | 379 pleq2 : toℕ ( x ⟨$⟩ʳ (suc (fromℕ< i<sn)) ) ≡ toℕ ( y ⟨$⟩ʳ (suc (fromℕ< i<sn)) ) |
380 pleq2 = headeq eq | |
37 | 381 |
87 | 382 pprep-cong : {n : ℕ} → {x y : Permutation n n } → x =p= y → pprep x =p= pprep y |
383 pprep-cong {n} {x} {y} x=y = record { peq = pprep-cong1 } where | |
384 pprep-cong1 : (q : Fin (suc n)) → (pprep x ⟨$⟩ʳ q) ≡ (pprep y ⟨$⟩ʳ q) | |
385 pprep-cong1 zero = refl | |
386 pprep-cong1 (suc q) = begin | |
387 pprep x ⟨$⟩ʳ suc q | |
388 ≡⟨⟩ | |
389 suc ( x ⟨$⟩ʳ q ) | |
390 ≡⟨ cong ( λ k → suc k ) ( peq x=y q ) ⟩ | |
391 suc ( y ⟨$⟩ʳ q ) | |
392 ≡⟨⟩ | |
393 pprep y ⟨$⟩ʳ suc q | |
91 | 394 ∎ |
87 | 395 |
396 pprep-dist : {n : ℕ} → {x y : Permutation n n } → pprep (x ∘ₚ y) =p= (pprep x ∘ₚ pprep y) | |
397 pprep-dist {n} {x} {y} = record { peq = pprep-dist1 } where | |
398 pprep-dist1 : (q : Fin (suc n)) → (pprep (x ∘ₚ y) ⟨$⟩ʳ q) ≡ ((pprep x ∘ₚ pprep y) ⟨$⟩ʳ q) | |
399 pprep-dist1 zero = refl | |
400 pprep-dist1 (suc q) = cong ( λ k → suc k ) refl | |
401 | |
402 pswap-cong : {n : ℕ} → {x y : Permutation n n } → x =p= y → pswap x =p= pswap y | |
403 pswap-cong {n} {x} {y} x=y = record { peq = pswap-cong1 } where | |
404 pswap-cong1 : (q : Fin (suc (suc n))) → (pswap x ⟨$⟩ʳ q) ≡ (pswap y ⟨$⟩ʳ q) | |
405 pswap-cong1 zero = refl | |
406 pswap-cong1 (suc zero) = refl | |
407 pswap-cong1 (suc (suc q)) = begin | |
408 pswap x ⟨$⟩ʳ suc (suc q) | |
409 ≡⟨⟩ | |
410 suc (suc (x ⟨$⟩ʳ q)) | |
411 ≡⟨ cong ( λ k → suc (suc k) ) ( peq x=y q ) ⟩ | |
412 suc (suc (y ⟨$⟩ʳ q)) | |
413 ≡⟨⟩ | |
414 pswap y ⟨$⟩ʳ suc (suc q) | |
91 | 415 ∎ |
87 | 416 |
417 pswap-dist : {n : ℕ} → {x y : Permutation n n } → pprep (pprep (x ∘ₚ y)) =p= (pswap x ∘ₚ pswap y) | |
418 pswap-dist {n} {x} {y} = record { peq = pswap-dist1 } where | |
419 pswap-dist1 : (q : Fin (suc (suc n))) → ((pprep (pprep (x ∘ₚ y))) ⟨$⟩ʳ q) ≡ ((pswap x ∘ₚ pswap y) ⟨$⟩ʳ q) | |
420 pswap-dist1 zero = refl | |
421 pswap-dist1 (suc zero) = refl | |
422 pswap-dist1 (suc (suc q)) = cong ( λ k → suc (suc k) ) refl | |
86
c5329963c583
(x : Permutation 1 1 ) → x =p= pid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
85
diff
changeset
|
423 |
49
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
424 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
|
425 f0 : FL 0 |
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
426 _::_ : { 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
|
427 |
88 | 428 shlem→ : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → (p0=0 : perm ⟨$⟩ˡ (# 0) ≡ # 0 ) → (x : Fin (suc n) ) → perm ⟨$⟩ˡ x ≡ zero → x ≡ zero |
429 shlem→ perm p0=0 x px=0 = begin | |
61 | 430 x ≡⟨ sym ( inverseʳ perm ) ⟩ |
431 perm ⟨$⟩ʳ ( perm ⟨$⟩ˡ x) ≡⟨ cong (λ k → perm ⟨$⟩ʳ k ) px=0 ⟩ | |
432 perm ⟨$⟩ʳ zero ≡⟨ cong (λ k → perm ⟨$⟩ʳ k ) (sym p0=0) ⟩ | |
433 perm ⟨$⟩ʳ ( perm ⟨$⟩ˡ zero) ≡⟨ inverseʳ perm ⟩ | |
434 zero | |
435 ∎ where open ≡-Reasoning | |
54 | 436 |
88 | 437 shlem← : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → (p0=0 : perm ⟨$⟩ˡ (# 0) ≡ # 0 ) → (x : Fin (suc n)) → perm ⟨$⟩ʳ x ≡ zero → x ≡ zero |
438 shlem← perm p0=0 x px=0 = begin | |
61 | 439 x ≡⟨ sym (inverseˡ perm ) ⟩ |
440 perm ⟨$⟩ˡ ( perm ⟨$⟩ʳ x ) ≡⟨ cong (λ k → perm ⟨$⟩ˡ k ) px=0 ⟩ | |
441 perm ⟨$⟩ˡ zero ≡⟨ p0=0 ⟩ | |
442 zero | |
443 ∎ where open ≡-Reasoning | |
54 | 444 |
88 | 445 sh2 : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → (p0=0 : perm ⟨$⟩ˡ (# 0) ≡ # 0 ) → {x : Fin n} → ¬ perm ⟨$⟩ˡ (suc x) ≡ zero |
446 sh2 perm p0=0 {x} eq with shlem→ perm p0=0 (suc x) eq | |
447 sh2 perm p0=0 {x} eq | () | |
448 | |
449 sh1 : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → (p0=0 : perm ⟨$⟩ˡ (# 0) ≡ # 0 ) → {x : Fin n} → ¬ perm ⟨$⟩ʳ (suc x) ≡ zero | |
450 sh1 perm p0=0 {x} eq with shlem← perm p0=0 (suc x) eq | |
451 sh1 perm p0=0 {x} eq | () | |
452 | |
453 | |
454 -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] → 0 ∷ 1 ∷ 2 ∷ [] | |
455 shrink : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → perm ⟨$⟩ˡ (# 0) ≡ # 0 → Permutation n n | |
456 shrink {n} perm p0=0 = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where | |
57 | 457 |
61 | 458 p→ : Fin n → Fin n |
88 | 459 p→ x with perm ⟨$⟩ʳ (suc x) | inspect (_⟨$⟩ʳ_ perm ) (suc x) |
460 p→ x | zero | record { eq = e } = ⊥-elim ( sh1 perm p0=0 {x} e ) | |
61 | 461 p→ x | suc t | _ = t |
50 | 462 |
463 p← : Fin n → Fin n | |
88 | 464 p← x with perm ⟨$⟩ˡ (suc x) | inspect (_⟨$⟩ˡ_ perm ) (suc x) |
465 p← x | zero | record { eq = e } = ⊥-elim ( sh2 perm p0=0 {x} e ) | |
61 | 466 p← x | suc t | _ = t |
50 | 467 |
468 piso← : (x : Fin n ) → p→ ( p← x ) ≡ x | |
88 | 469 piso← x with perm ⟨$⟩ˡ (suc x) | inspect (_⟨$⟩ˡ_ perm ) (suc x) |
470 piso← x | zero | record { eq = e } = ⊥-elim ( sh2 perm p0=0 {x} e ) | |
471 piso← x | suc t | _ with perm ⟨$⟩ʳ (suc t) | inspect (_⟨$⟩ʳ_ perm ) (suc t) | |
472 piso← x | suc t | _ | zero | record { eq = e } = ⊥-elim ( sh1 perm p0=0 e ) | |
61 | 473 piso← x | suc t | record { eq = e0 } | suc t1 | record { eq = e1 } = begin |
474 t1 | |
475 ≡⟨ plem0 plem1 ⟩ | |
52 | 476 x |
61 | 477 ∎ where |
478 open ≡-Reasoning | |
479 plem0 : suc t1 ≡ suc x → t1 ≡ x | |
480 plem0 refl = refl | |
481 plem1 : suc t1 ≡ suc x | |
482 plem1 = begin | |
483 suc t1 | |
484 ≡⟨ sym e1 ⟩ | |
88 | 485 Inverse.to perm Π.⟨$⟩ suc t |
486 ≡⟨ cong (λ k → Inverse.to perm Π.⟨$⟩ k ) (sym e0) ⟩ | |
487 Inverse.to perm Π.⟨$⟩ ( Inverse.from perm Π.⟨$⟩ suc x ) | |
488 ≡⟨ inverseʳ perm ⟩ | |
61 | 489 suc x |
490 ∎ | |
50 | 491 |
492 piso→ : (x : Fin n ) → p← ( p→ x ) ≡ x | |
88 | 493 piso→ x with perm ⟨$⟩ʳ (suc x) | inspect (_⟨$⟩ʳ_ perm ) (suc x) |
494 piso→ x | zero | record { eq = e } = ⊥-elim ( sh1 perm p0=0 {x} e ) | |
495 piso→ x | suc t | _ with perm ⟨$⟩ˡ (suc t) | inspect (_⟨$⟩ˡ_ perm ) (suc t) | |
496 piso→ x | suc t | _ | zero | record { eq = e } = ⊥-elim ( sh2 perm p0=0 e ) | |
61 | 497 piso→ x | suc t | record { eq = e0 } | suc t1 | record { eq = e1 } = begin |
498 t1 | |
499 ≡⟨ plem2 plem3 ⟩ | |
53 | 500 x |
61 | 501 ∎ where |
502 open ≡-Reasoning | |
503 plem2 : suc t1 ≡ suc x → t1 ≡ x | |
504 plem2 refl = refl | |
505 plem3 : suc t1 ≡ suc x | |
506 plem3 = begin | |
507 suc t1 | |
508 ≡⟨ sym e1 ⟩ | |
88 | 509 Inverse.from perm Π.⟨$⟩ suc t |
510 ≡⟨ cong (λ k → Inverse.from perm Π.⟨$⟩ k ) (sym e0 ) ⟩ | |
511 Inverse.from perm Π.⟨$⟩ ( Inverse.to perm Π.⟨$⟩ suc x ) | |
512 ≡⟨ inverseˡ perm ⟩ | |
61 | 513 suc x |
514 ∎ | |
57 | 515 |
88 | 516 shrink-iso : { n : ℕ } → {perm : Permutation n n} → shrink (pprep perm) refl =p= perm |
517 shrink-iso {n} {perm} = record { peq = λ q → refl } | |
518 | |
98 | 519 shrink-cong : { n : ℕ } → {x y : Permutation (suc n) (suc n)} |
520 → x =p= y | |
521 → (x=0 : x ⟨$⟩ˡ (# 0) ≡ # 0 ) → (y=0 : y ⟨$⟩ˡ (# 0) ≡ # 0 ) → shrink x x=0 =p= shrink y y=0 | |
99 | 522 shrink-cong {n} {x} {y} x=y x=0 y=0 = record { peq = p002 } where |
523 p002 : (q : Fin n) → (shrink x x=0 ⟨$⟩ʳ q) ≡ (shrink y y=0 ⟨$⟩ʳ q) | |
524 p002 q with x ⟨$⟩ʳ (suc q) | inspect (_⟨$⟩ʳ_ x ) (suc q) | y ⟨$⟩ʳ (suc q) | inspect (_⟨$⟩ʳ_ y ) (suc q) | |
525 p002 q | zero | record { eq = ex } | zero | ey = ⊥-elim ( sh1 x x=0 ex ) | |
526 p002 q | zero | record { eq = ex } | suc py | ey = ⊥-elim ( sh1 x x=0 ex ) | |
527 p002 q | suc px | ex | zero | record { eq = ey } = ⊥-elim ( sh1 y y=0 ey ) | |
528 p002 q | suc px | record { eq = ex } | suc py | record { eq = ey } = p003 ( begin | |
529 suc px | |
530 ≡⟨ sym ex ⟩ | |
531 x ⟨$⟩ʳ (suc q) | |
532 ≡⟨ peq x=y (suc q) ⟩ | |
533 y ⟨$⟩ʳ (suc q) | |
534 ≡⟨ ey ⟩ | |
535 suc py | |
536 ∎ ) where | |
537 p003 : suc px ≡ suc py → px ≡ py | |
538 p003 refl = refl | |
98 | 539 |
57 | 540 FL→perm : {n : ℕ } → FL n → Permutation n n |
541 FL→perm f0 = pid | |
542 FL→perm (x :: fl) = pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x ) | |
543 | |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
544 t40 = (# 2) :: ( (# 1) :: (( # 0 ) :: f0 )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
545 t4 = FL→perm ((# 2) :: t40 ) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
546 |
61 | 547 -- t1 = plist (shrink (pid {3} ∘ₚ (pins (n≤ 1))) refl) |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
548 t2 = plist ((pid {5} ) ∘ₚ transpose (# 2) (# 4)) ∷ plist (pid {5} ∘ₚ reverse ) ∷ [] |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
549 t3 = plist (FL→perm t40) -- ∷ plist (pprep (FL→perm t40)) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
550 -- ∷ plist ( pprep (FL→perm t40) ∘ₚ pins ( n≤ 0 {3} )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
551 -- ∷ plist ( pprep (FL→perm t40 )∘ₚ pins ( n≤ 1 {2} )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
552 -- ∷ plist ( pprep (FL→perm t40 )∘ₚ pins ( n≤ 2 {1} )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
553 -- ∷ plist ( pprep (FL→perm t40 )∘ₚ pins ( n≤ 3 {0} )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
554 ∷ plist ( FL→perm ((# 0) :: t40)) -- (0 ∷ 1 ∷ 2 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
555 ∷ plist ( FL→perm ((# 1) :: t40)) -- (0 ∷ 2 ∷ 1 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
556 ∷ plist ( FL→perm ((# 2) :: t40)) -- (1 ∷ 0 ∷ 2 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
557 ∷ plist ( FL→perm ((# 3) :: t40)) -- (2 ∷ 0 ∷ 1 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
558 -- ∷ plist ( FL→perm ((# 3) :: ((# 2) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) -- (1 ∷ 2 ∷ 0 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
559 -- ∷ plist ( FL→perm ((# 3) :: ((# 2) :: ( (# 1) :: (( # 0 ) :: f0 )) ))) -- (2 ∷ 1 ∷ 0 ∷ []) ∷ |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
560 -- ∷ plist ( (flip (FL→perm ((# 3) :: ((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) ))))) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
561 -- ∷ plist ( (flip (FL→perm ((# 3) :: ((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) ))) ∘ₚ (FL→perm ((# 3) :: (((# 1) :: ( (# 0) :: (( # 0 ) :: f0 )) )))) )) |
57 | 562 ∷ [] |
50 | 563 |
58 | 564 |
49
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
565 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
|
566 perm→FL {zero} perm = f0 |
98 | 567 perm→FL {suc n} perm = (perm ⟨$⟩ʳ (# 0)) :: perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm) ) |
568 -- perm→FL {suc n} perm = (perm ⟨$⟩ʳ (# 0)) :: perm→FL (remove (# 0) perm) | |
569 | |
570 pcong-pF : {n : ℕ } → {x y : Permutation n n} → x =p= y → perm→FL x ≡ perm→FL y | |
99 | 571 pcong-pF {zero} eq = refl |
100 | 572 pcong-pF {suc n} {x} {y} eq = cong₂ (λ j k → j :: k ) ( peq eq (# 0)) (pcong-pF (shrink-cong (presp eq p001 ) (p=0 x) (p=0 y))) where |
573 p002 : x ⟨$⟩ʳ (# 0) ≡ y ⟨$⟩ʳ (# 0) | |
574 p002 = peq eq (# 0) | |
575 p001 : flip (pins (toℕ≤pred[n] (x ⟨$⟩ʳ (# 0)))) =p= flip (pins (toℕ≤pred[n] (y ⟨$⟩ʳ (# 0)))) | |
576 p001 = subst ( λ k → flip (pins (toℕ≤pred[n] (x ⟨$⟩ʳ (# 0)))) =p= flip (pins (toℕ≤pred[n] k ))) p002 prefl | |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
577 |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
578 -- t5 = plist t4 ∷ plist ( t4 ∘ₚ flip (pins ( n≤ 3 ) )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
579 t5 = plist (t4) ∷ plist (flip t4) |
74 | 580 ∷ ( toℕ (t4 ⟨$⟩ˡ fromℕ< a<sa) ∷ [] ) |
61 | 581 ∷ ( toℕ (t4 ⟨$⟩ʳ (# 0)) ∷ [] ) |
60
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
582 -- ∷ plist ( t4 ∘ₚ flip (pins ( n≤ 1 ) )) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
583 ∷ plist (remove (# 0) t4 ) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
584 ∷ plist ( FL→perm t40 ) |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
585 ∷ [] |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
586 |
48926e810f5f
perm→FL done. pprep fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
587 t6 = perm→FL t4 |
49
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
588 |
105 | 589 ---- |
590 -- if n is fixed, perm→FL ( FL→perm fl ) ≡ fl is refl for each concrete fl | |
591 -- so we may prove this easily by co-induction | |
592 -- | |
98 | 593 FL→iso : {n : ℕ } → (fl : FL n ) → perm→FL ( FL→perm fl ) ≡ fl |
594 FL→iso f0 = refl | |
100 | 595 FL→iso {suc n} (x :: fl) = cong₂ ( λ j k → j :: k ) f001 f002 where |
98 | 596 perm = pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x ) |
597 f001 : perm ⟨$⟩ʳ (# 0) ≡ x | |
100 | 598 f001 = begin |
599 (pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x )) ⟨$⟩ʳ (# 0) | |
101 | 600 ≡⟨⟩ |
601 pins ( toℕ≤pred[n] x ) ⟨$⟩ʳ (# 0) | |
602 ≡⟨ px=x x ⟩ | |
100 | 603 x |
604 ∎ | |
98 | 605 x=0 : (perm ∘ₚ flip (pins (toℕ≤pred[n] x))) ⟨$⟩ˡ (# 0) ≡ # 0 |
100 | 606 x=0 = subst ( λ k → (perm ∘ₚ flip (pins (toℕ≤pred[n] k))) ⟨$⟩ˡ (# 0) ≡ # 0 ) f001 (p=0 perm) |
98 | 607 x=0' : (pprep (FL→perm fl) ∘ₚ pid) ⟨$⟩ˡ (# 0) ≡ # 0 |
100 | 608 x=0' = refl |
103 | 609 f003 : (q : Fin (suc n)) → |
610 ((perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) ⟨$⟩ʳ q) ≡ | |
611 ((perm ∘ₚ flip (pins (toℕ≤pred[n] x))) ⟨$⟩ʳ q) | |
612 f003 q = cong (λ k → (perm ∘ₚ flip (pins (toℕ≤pred[n] k))) ⟨$⟩ʳ q ) f001 | |
98 | 613 f002 : perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm) ) ≡ fl |
614 f002 = begin | |
615 perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm) ) | |
103 | 616 ≡⟨ pcong-pF (shrink-cong {n} {perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))} {perm ∘ₚ flip (pins (toℕ≤pred[n] x))} record {peq = f003 } (p=0 perm) x=0) ⟩ |
98 | 617 perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] x))) x=0 ) |
618 ≡⟨⟩ | |
619 perm→FL (shrink ((pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x )) ∘ₚ flip (pins (toℕ≤pred[n] x))) x=0 ) | |
103 | 620 ≡⟨ pcong-pF (shrink-cong (passoc (pprep (FL→perm fl)) (pins ( toℕ≤pred[n] x )) (flip (pins (toℕ≤pred[n] x))) ) x=0 x=0) ⟩ |
98 | 621 perm→FL (shrink (pprep (FL→perm fl) ∘ₚ (pins ( toℕ≤pred[n] x ) ∘ₚ flip (pins (toℕ≤pred[n] x)))) x=0 ) |
103 | 622 ≡⟨ pcong-pF (shrink-cong {n} {pprep (FL→perm fl) ∘ₚ (pins ( toℕ≤pred[n] x ) ∘ₚ flip (pins (toℕ≤pred[n] x)))} {pprep (FL→perm fl) ∘ₚ pid} |
623 ( presp {suc n} {pprep (FL→perm fl) } {_} {(pins ( toℕ≤pred[n] x ) ∘ₚ flip (pins (toℕ≤pred[n] x)))} {pid} prefl | |
624 record { peq = λ q → inverseˡ (pins ( toℕ≤pred[n] x )) } ) x=0 x=0') ⟩ | |
98 | 625 perm→FL (shrink (pprep (FL→perm fl) ∘ₚ pid) x=0' ) |
103 | 626 ≡⟨ pcong-pF (shrink-cong {n} {pprep (FL→perm fl) ∘ₚ pid} {pprep (FL→perm fl)} record {peq = λ q → refl } x=0' x=0') ⟩ -- prefl won't work |
98 | 627 perm→FL (shrink (pprep (FL→perm fl)) x=0' ) |
628 ≡⟨ pcong-pF shrink-iso ⟩ | |
629 perm→FL ( FL→perm fl ) | |
630 ≡⟨ FL→iso fl ⟩ | |
631 fl | |
632 ∎ | |
633 | |
104 | 634 pcong-Fp : {n : ℕ } → {x y : FL n} → x ≡ y → FL→perm x =p= FL→perm y |
635 pcong-Fp {n} {x} {x} refl = prefl | |
49
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
636 |
104 | 637 FL←iso : {n : ℕ } → (perm : Permutation n n ) → FL→perm ( perm→FL perm ) =p= perm |
638 FL←iso {0} perm = record { peq = λ () } | |
639 FL←iso {suc n} perm with perm→FL perm | inspect perm→FL perm | |
640 ... | x :: fl | record { eq = e } = ptrans (pcong-Fp e ) f004 where | |
105 | 641 f003 : perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm)) ≡ fl |
642 f003 = {!!} | |
643 f004 : FL→perm ( x :: fl ) =p= perm | |
104 | 644 f004 = record { peq = λ q → ( begin |
645 (pprep (FL→perm fl) ∘ₚ pins ( toℕ≤pred[n] x )) ⟨$⟩ʳ q | |
105 | 646 ≡⟨ cong (λ k → (pprep (FL→perm k) ∘ₚ pins ( toℕ≤pred[n] x )) ⟨$⟩ʳ q ) (sym f003 ) ⟩ |
104 | 647 (pprep (FL→perm (perm→FL (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm) ))) ∘ₚ pins ( toℕ≤pred[n] x )) ⟨$⟩ʳ q |
105 | 648 ≡⟨ peq (presp (pprep-cong (FL←iso _ ) ) prefl ) q ⟩ |
104 | 649 (pprep (shrink (perm ∘ₚ flip (pins (toℕ≤pred[n] (perm ⟨$⟩ʳ (# 0))))) (p=0 perm)) ∘ₚ pins ( toℕ≤pred[n] x )) ⟨$⟩ʳ q |
650 ≡⟨ {!!} ⟩ | |
651 perm ⟨$⟩ʳ q | |
652 ∎ ) } | |
49
8b3b95362ca9
remove (fromℕ≤ a<sa) perm is no good
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
653 |
66 | 654 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n |
91 | 655 lem2 i≤n = ≤-trans i≤n ( a≤sa ) |
66 | 656 |
67
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
657 ∀-FL : (n : ℕ ) → List (FL (suc n)) |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
658 ∀-FL x = fls6 x where |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
659 fls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → FL n → List (FL (suc n)) → List (FL (suc n)) |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
660 fls4 zero n i≤n perm x = (zero :: perm ) ∷ x |
91 | 661 fls4 (suc i) n i≤n perm x = fls4 i n (≤-trans a≤sa i≤n ) perm ((fromℕ< (s≤s i≤n) :: perm ) ∷ x) |
67
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
662 fls5 : ( n : ℕ ) → List (FL n) → List (FL (suc n)) → List (FL (suc n)) |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
663 fls5 n [] x = x |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
664 fls5 n (h ∷ x) y = fls5 n x (fls4 n n lem0 h y) |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
665 fls6 : ( n : ℕ ) → List (FL (suc n)) |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
666 fls6 zero = (zero :: f0) ∷ [] |
3825082ebdbd
∀-FL : (n : ℕ ) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
667 fls6 (suc n) = fls5 (suc n) (fls6 n) [] |
65 | 668 |
97 | 669 tf1 = ∀-FL 4 |
670 tf2 = Data.List.map (λ k → ⟪ plist (FL→perm k ) , k ⟫ ) tf1 | |
671 | |
48 | 672 all-perm : (n : ℕ ) → List (Permutation (suc n) (suc n) ) |
673 all-perm n = pls6 n where | |
38 | 674 lem1 : {i n : ℕ } → i ≤ n → i < suc n |
675 lem1 z≤n = s≤s z≤n | |
676 lem1 (s≤s lt) = s≤s (lem1 lt) | |
40 | 677 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) |
48 | 678 pls4 zero n i≤n perm x = (pprep perm ∘ₚ pins i≤n ) ∷ x |
91 | 679 pls4 (suc i) n i≤n perm x = pls4 i n (≤-trans a≤sa i≤n ) perm (pprep perm ∘ₚ pins {n} {suc i} i≤n ∷ x) |
40 | 680 pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) |
681 pls5 n [] x = x | |
682 pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y) | |
683 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n)) | |
684 pls6 zero = pid ∷ [] | |
48 | 685 pls6 (suc n) = pls5 (suc n) (rev (pls6 n) ) [] -- rev to put id first |
686 | |
687 pls : (n : ℕ ) → List (List ℕ ) | |
75 | 688 pls n = Data.List.map plist (all-perm n) |