comparison Putil.agda @ 91:482ef04890f8

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 29 Aug 2020 07:48:45 +0900
parents bb8c5b366219
children 2e5d0b142eca
comparison
equal deleted inserted replaced
90:bb8c5b366219 91:482ef04890f8
129 pins {suc _} {suc zero} _ = pswap 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 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))) 131 pins1 : (i j : ℕ ) → j ≤ suc (suc n) → Permutation (suc (suc (suc n ))) (suc (suc (suc n)))
132 pins1 _ zero _ = pid 132 pins1 _ zero _ = pid
133 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 refl-≤s ) 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 )
135 135
136 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) 136 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
137 open ≡-Reasoning
137 138
138 pins' : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n) 139 pins' : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n)
139 pins' {_} {zero} _ = pid 140 pins' {_} {zero} _ = pid
140 pins' {suc n} {suc m} (s≤s m≤n) = permutation p← p→ record { left-inverse-of = piso← ; right-inverse-of = piso→ } where 141 pins' {suc n} {suc m} (s≤s m≤n) = permutation p← p→ record { left-inverse-of = piso← ; right-inverse-of = piso→ } where
141 142
142 next : Fin (suc (suc n)) → Fin (suc (suc n)) 143 next : Fin (suc (suc n)) → Fin (suc (suc n))
143 next zero = suc zero 144 next zero = suc zero
144 next (suc x) = fromℕ< (≤-trans (fin<n {_} {x} ) refl-≤s ) 145 next (suc x) = fromℕ< (≤-trans (fin<n {_} {x} ) a≤sa )
145 146
146 p→ : Fin (suc (suc n)) → Fin (suc (suc n)) 147 p→ : Fin (suc (suc n)) → Fin (suc (suc n))
147 p→ x with <-cmp (toℕ x) (suc m) 148 p→ x with <-cmp (toℕ x) (suc m)
148 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (s≤s a) (s≤s (s≤s m≤n) )) 149 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (s≤s a) (s≤s (s≤s m≤n) ))
149 ... | tri≈ ¬a b ¬c = zero 150 ... | tri≈ ¬a b ¬c = zero
150 ... | tri> ¬a ¬b c = x 151 ... | tri> ¬a ¬b c = x
151 152
152 p← : Fin (suc (suc n)) → Fin (suc (suc n)) 153 p← : Fin (suc (suc n)) → Fin (suc (suc n))
153 p← zero = fromℕ< (s≤s (s≤s m≤n)) 154 p← zero = fromℕ< (s≤s (s≤s m≤n))
154 p← (suc x) with <-cmp (toℕ x) (suc m) 155 p← (suc x) with <-cmp (toℕ x) (suc m)
155 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (fin<n {_} {x}) refl-≤s ) 156 ... | tri< a ¬b ¬c = fromℕ< (≤-trans (fin<n {_} {x}) a≤sa )
156 ... | tri≈ ¬a b ¬c = suc x 157 ... | tri≈ ¬a b ¬c = suc x
157 ... | tri> ¬a ¬b c = suc x 158 ... | tri> ¬a ¬b c = suc x
158 159
159 mm : toℕ (fromℕ< {suc m} {suc (suc n)} (s≤s (s≤s m≤n))) ≡ suc m 160 mm : toℕ (fromℕ< {suc m} {suc (suc n)} (s≤s (s≤s m≤n))) ≡ suc m
160 mm = toℕ-fromℕ< (s≤s (s≤s m≤n)) 161 mm = toℕ-fromℕ< (s≤s (s≤s m≤n))
161 162
162 mma : (x : Fin (suc n) ) → suc (toℕ x) ≤ suc m → toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) refl-≤s ) ) ≤ m 163 mma : (x : Fin (suc n) ) → suc (toℕ x) ≤ suc m → toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) a≤sa ) ) ≤ m
163 mma x (s≤s x<sm) = subst (λ k → k ≤ m) (sym (toℕ-fromℕ< (≤-trans fin<n refl-≤s ) )) x<sm 164 mma x (s≤s x<sm) = subst (λ k → k ≤ m) (sym (toℕ-fromℕ< (≤-trans fin<n a≤sa ) )) x<sm
164 165
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
165 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x 172 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x
166 piso← zero with <-cmp (toℕ (fromℕ< (s≤s (s≤s m≤n)))) (suc m) | mm 173 piso← zero with <-cmp (toℕ (fromℕ< (s≤s (s≤s m≤n)))) (suc m) | mm
167 ... | tri< a ¬b ¬c | t = ⊥-elim ( ¬b t ) 174 ... | tri< a ¬b ¬c | t = ⊥-elim ( ¬b t )
168 ... | tri≈ ¬a b ¬c | t = refl 175 ... | tri≈ ¬a b ¬c | t = refl
169 ... | tri> ¬a ¬b c | t = ⊥-elim ( ¬b t ) 176 ... | tri> ¬a ¬b c | t = ⊥-elim ( ¬b t )
170 piso← (suc x) with <-cmp (toℕ x) (suc m) 177 piso← (suc x) with <-cmp (toℕ x) (suc m)
171 ... | tri≈ ¬a b ¬c = ? 178 ... | tri> ¬a ¬b c with <-cmp (toℕ (suc x)) (suc m)
172 ... | tri> ¬a ¬b c = {!!} 179 ... | tri< a ¬b₁ ¬c = ⊥-elim ( nat-<> a (<-trans c a<sa ) )
173 ... | tri< a ¬b ¬c with <-cmp (toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) refl-≤s ) )) (suc m) 180 ... | tri≈ ¬a₁ b ¬c = ⊥-elim ( nat-≡< (sym b) (<-trans c a<sa ))
181 ... | tri> ¬a₁ ¬b₁ c₁ = refl
182 piso← (suc x) | tri≈ ¬a b ¬c with <-cmp (toℕ (suc x)) (suc m)
183 ... | tri< a ¬b ¬c₁ = ⊥-elim ( nat-≡< b (<-trans a<sa a) )
184 ... | tri≈ ¬a₁ refl ¬c₁ = ⊥-elim ( nat-≡< b a<sa )
185 ... | tri> ¬a₁ ¬b c = refl
186 piso← (suc x) | tri< a ¬b ¬c with <-cmp (toℕ ( fromℕ< (≤-trans (fin<n {_} {x}) a≤sa ) )) (suc m)
174 ... | tri≈ ¬a b ¬c₁ = ⊥-elim ( ¬a (s≤s (mma x a))) 187 ... | tri≈ ¬a b ¬c₁ = ⊥-elim ( ¬a (s≤s (mma x a)))
175 ... | tri> ¬a ¬b₁ c = ⊥-elim ( ¬a (s≤s (mma x a))) 188 ... | tri> ¬a ¬b₁ c = ⊥-elim ( ¬a (s≤s (mma x a)))
176 ... | tri< a₁ ¬b₁ ¬c₁ = p0 where 189 ... | tri< a₁ ¬b₁ ¬c₁ = p0 where
177 p2 : suc (suc (toℕ x)) ≤ suc (suc n) 190 p2 : suc (suc (toℕ x)) ≤ suc (suc n)
178 p2 = s≤s (fin<n {suc n} {x}) 191 p2 = s≤s (fin<n {suc n} {x})
179 p6 : suc (toℕ (fromℕ< (≤-trans (fin<n {_} {suc x}) (s≤s refl-≤s)))) ≤ suc (suc n) 192 p6 : suc (toℕ (fromℕ< (≤-trans (fin<n {_} {suc x}) (s≤s a≤sa)))) ≤ suc (suc n)
180 p6 = s≤s (≤-trans a₁ (s≤s m≤n)) 193 p6 = s≤s (≤-trans a₁ (s≤s m≤n))
181
182 p3 : toℕ (fromℕ< (≤-trans (fin<n {_} {suc x} ) (s≤s refl-≤s))) ≡ suc (toℕ x)
183 p3 = begin
184 toℕ (fromℕ< (≤-trans (fin<n {_} {suc x} ) (s≤s refl-≤s)))
185 ≡⟨ toℕ-fromℕ< ( s≤s ( ≤-trans fin<n refl-≤s ) ) ⟩
186 suc (toℕ x)
187 ∎ where open ≡-Reasoning
188 p0 : fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) )) ≡ suc x 194 p0 : fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) )) ≡ suc x
189 p0 = begin 195 p0 = begin
190 fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) )) 196 fromℕ< (≤-trans (s≤s a₁) (s≤s (s≤s m≤n) ))
191 ≡⟨⟩ 197 ≡⟨⟩
192 fromℕ< (s≤s (≤-trans a₁ (s≤s m≤n))) 198 fromℕ< (s≤s (≤-trans a₁ (s≤s m≤n)))
193 ≡⟨ lemma10 p3 {p6} {p2} ⟩ 199 ≡⟨ lemma10 (p3 x) {p6} {p2} ⟩
194 fromℕ< ( s≤s (fin<n {suc n} {x}) ) 200 fromℕ< ( s≤s (fin<n {suc n} {x}) )
195 ≡⟨ lemma3 {toℕ x} {suc n} (fin<n {suc (n)} {x}) ⟩ 201 ≡⟨⟩
196 suc (fromℕ< (fin<n {suc n} {x} )) 202 suc (fromℕ< (fin<n {suc n} {x} ))
197 ≡⟨ cong suc (fromℕ<-toℕ x (fin<n {suc n} {x}) ) ⟩ 203 ≡⟨ cong suc (fromℕ<-toℕ x _ ) ⟩
198 suc x 204 suc x
199 ∎ where open ≡-Reasoning 205
200 206
201 207
202 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x 208 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x
203 piso→ = {!!} 209 piso→ = {!!}
204 210
250 x ⟨$⟩ʳ zero 256 x ⟨$⟩ʳ zero
251 ≡⟨ toℕ-injective (headeq eq) ⟩ 257 ≡⟨ toℕ-injective (headeq eq) ⟩
252 y ⟨$⟩ʳ zero 258 y ⟨$⟩ʳ zero
253 ≡⟨ cong ( λ k → y ⟨$⟩ʳ k ) (sym (toℕ-injective b )) ⟩ 259 ≡⟨ cong ( λ k → y ⟨$⟩ʳ k ) (sym (toℕ-injective b )) ⟩
254 y ⟨$⟩ʳ q 260 y ⟨$⟩ʳ q
255 ∎ where 261
256 open ≡-Reasoning
257 pleq1 (suc i) (s≤s i<sn) eq q q<i with <-cmp (toℕ q) (suc i) 262 pleq1 (suc i) (s≤s i<sn) eq q q<i with <-cmp (toℕ q) (suc i)
258 ... | tri< a ¬b ¬c = pleq1 i (<-trans i<sn a<sa ) (taileq eq) q a 263 ... | tri< a ¬b ¬c = pleq1 i (<-trans i<sn a<sa ) (taileq eq) q a
259 ... | tri> ¬a ¬b c = ⊥-elim (nat-≤> c q<i ) 264 ... | tri> ¬a ¬b c = ⊥-elim (nat-≤> c q<i )
260 ... | tri≈ ¬a b ¬c = begin 265 ... | tri≈ ¬a b ¬c = begin
261 x ⟨$⟩ʳ q 266 x ⟨$⟩ʳ q
264 ≡⟨ toℕ-injective pleq2 ⟩ 269 ≡⟨ toℕ-injective pleq2 ⟩
265 y ⟨$⟩ʳ (suc (fromℕ< i<sn)) 270 y ⟨$⟩ʳ (suc (fromℕ< i<sn))
266 ≡⟨ cong (λ k → y ⟨$⟩ʳ k) (sym (pleq3 b)) ⟩ 271 ≡⟨ cong (λ k → y ⟨$⟩ʳ k) (sym (pleq3 b)) ⟩
267 y ⟨$⟩ʳ q 272 y ⟨$⟩ʳ q
268 ∎ where 273 ∎ where
269 open ≡-Reasoning
270 pleq3 : toℕ q ≡ suc i → q ≡ suc (fromℕ< i<sn) 274 pleq3 : toℕ q ≡ suc i → q ≡ suc (fromℕ< i<sn)
271 pleq3 tq=si = toℕ-injective ( begin 275 pleq3 tq=si = toℕ-injective ( begin
272 toℕ q 276 toℕ q
273 ≡⟨ b ⟩ 277 ≡⟨ b ⟩
274 suc i 278 suc i
275 ≡⟨ sym (toℕ-fromℕ< (s≤s i<sn)) ⟩ 279 ≡⟨ sym (toℕ-fromℕ< (s≤s i<sn)) ⟩
276 toℕ (fromℕ< (s≤s i<sn)) 280 toℕ (fromℕ< (s≤s i<sn))
277 ≡⟨⟩ 281 ≡⟨⟩
278 toℕ (suc (fromℕ< i<sn)) 282 toℕ (suc (fromℕ< i<sn))
279 ∎ ) where open ≡-Reasoning 283 ∎ )
280 pleq2 : toℕ ( x ⟨$⟩ʳ (suc (fromℕ< i<sn)) ) ≡ toℕ ( y ⟨$⟩ʳ (suc (fromℕ< i<sn)) ) 284 pleq2 : toℕ ( x ⟨$⟩ʳ (suc (fromℕ< i<sn)) ) ≡ toℕ ( y ⟨$⟩ʳ (suc (fromℕ< i<sn)) )
281 pleq2 = headeq eq 285 pleq2 = headeq eq
282 286
283 pprep-cong : {n : ℕ} → {x y : Permutation n n } → x =p= y → pprep x =p= pprep y 287 pprep-cong : {n : ℕ} → {x y : Permutation n n } → x =p= y → pprep x =p= pprep y
284 pprep-cong {n} {x} {y} x=y = record { peq = pprep-cong1 } where 288 pprep-cong {n} {x} {y} x=y = record { peq = pprep-cong1 } where
290 suc ( x ⟨$⟩ʳ q ) 294 suc ( x ⟨$⟩ʳ q )
291 ≡⟨ cong ( λ k → suc k ) ( peq x=y q ) ⟩ 295 ≡⟨ cong ( λ k → suc k ) ( peq x=y q ) ⟩
292 suc ( y ⟨$⟩ʳ q ) 296 suc ( y ⟨$⟩ʳ q )
293 ≡⟨⟩ 297 ≡⟨⟩
294 pprep y ⟨$⟩ʳ suc q 298 pprep y ⟨$⟩ʳ suc q
295 ∎ where open ≡-Reasoning 299
296 300
297 pprep-dist : {n : ℕ} → {x y : Permutation n n } → pprep (x ∘ₚ y) =p= (pprep x ∘ₚ pprep y) 301 pprep-dist : {n : ℕ} → {x y : Permutation n n } → pprep (x ∘ₚ y) =p= (pprep x ∘ₚ pprep y)
298 pprep-dist {n} {x} {y} = record { peq = pprep-dist1 } where 302 pprep-dist {n} {x} {y} = record { peq = pprep-dist1 } where
299 pprep-dist1 : (q : Fin (suc n)) → (pprep (x ∘ₚ y) ⟨$⟩ʳ q) ≡ ((pprep x ∘ₚ pprep y) ⟨$⟩ʳ q) 303 pprep-dist1 : (q : Fin (suc n)) → (pprep (x ∘ₚ y) ⟨$⟩ʳ q) ≡ ((pprep x ∘ₚ pprep y) ⟨$⟩ʳ q)
300 pprep-dist1 zero = refl 304 pprep-dist1 zero = refl
311 suc (suc (x ⟨$⟩ʳ q)) 315 suc (suc (x ⟨$⟩ʳ q))
312 ≡⟨ cong ( λ k → suc (suc k) ) ( peq x=y q ) ⟩ 316 ≡⟨ cong ( λ k → suc (suc k) ) ( peq x=y q ) ⟩
313 suc (suc (y ⟨$⟩ʳ q)) 317 suc (suc (y ⟨$⟩ʳ q))
314 ≡⟨⟩ 318 ≡⟨⟩
315 pswap y ⟨$⟩ʳ suc (suc q) 319 pswap y ⟨$⟩ʳ suc (suc q)
316 ∎ where open ≡-Reasoning 320
317 321
318 pswap-dist : {n : ℕ} → {x y : Permutation n n } → pprep (pprep (x ∘ₚ y)) =p= (pswap x ∘ₚ pswap y) 322 pswap-dist : {n : ℕ} → {x y : Permutation n n } → pprep (pprep (x ∘ₚ y)) =p= (pswap x ∘ₚ pswap y)
319 pswap-dist {n} {x} {y} = record { peq = pswap-dist1 } where 323 pswap-dist {n} {x} {y} = record { peq = pswap-dist1 } where
320 pswap-dist1 : (q : Fin (suc (suc n))) → ((pprep (pprep (x ∘ₚ y))) ⟨$⟩ʳ q) ≡ ((pswap x ∘ₚ pswap y) ⟨$⟩ʳ q) 324 pswap-dist1 : (q : Fin (suc (suc n))) → ((pprep (pprep (x ∘ₚ y))) ⟨$⟩ʳ q) ≡ ((pswap x ∘ₚ pswap y) ⟨$⟩ʳ q)
321 pswap-dist1 zero = refl 325 pswap-dist1 zero = refl
471 FL←iso : {n : ℕ } → (perm : Permutation n n ) → FL→perm ( perm→FL perm ) =p= perm 475 FL←iso : {n : ℕ } → (perm : Permutation n n ) → FL→perm ( perm→FL perm ) =p= perm
472 -- FL←iso {0} perm = record { peq = λ () } 476 -- FL←iso {0} perm = record { peq = λ () }
473 -- FL←iso {suc n} perm = {!!} 477 -- FL←iso {suc n} perm = {!!}
474 478
475 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n 479 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n
476 lem2 i≤n = ≤-trans i≤n ( refl-≤s ) 480 lem2 i≤n = ≤-trans i≤n ( a≤sa )
477 481
478 ∀-FL : (n : ℕ ) → List (FL (suc n)) 482 ∀-FL : (n : ℕ ) → List (FL (suc n))
479 ∀-FL x = fls6 x where 483 ∀-FL x = fls6 x where
480 fls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → FL n → List (FL (suc n)) → List (FL (suc n)) 484 fls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → FL n → List (FL (suc n)) → List (FL (suc n))
481 fls4 zero n i≤n perm x = (zero :: perm ) ∷ x 485 fls4 zero n i≤n perm x = (zero :: perm ) ∷ x
482 fls4 (suc i) n i≤n perm x = fls4 i n (≤-trans refl-≤s i≤n ) perm ((fromℕ< (s≤s i≤n) :: perm ) ∷ x) 486 fls4 (suc i) n i≤n perm x = fls4 i n (≤-trans a≤sa i≤n ) perm ((fromℕ< (s≤s i≤n) :: perm ) ∷ x)
483 fls5 : ( n : ℕ ) → List (FL n) → List (FL (suc n)) → List (FL (suc n)) 487 fls5 : ( n : ℕ ) → List (FL n) → List (FL (suc n)) → List (FL (suc n))
484 fls5 n [] x = x 488 fls5 n [] x = x
485 fls5 n (h ∷ x) y = fls5 n x (fls4 n n lem0 h y) 489 fls5 n (h ∷ x) y = fls5 n x (fls4 n n lem0 h y)
486 fls6 : ( n : ℕ ) → List (FL (suc n)) 490 fls6 : ( n : ℕ ) → List (FL (suc n))
487 fls6 zero = (zero :: f0) ∷ [] 491 fls6 zero = (zero :: f0) ∷ []
492 lem1 : {i n : ℕ } → i ≤ n → i < suc n 496 lem1 : {i n : ℕ } → i ≤ n → i < suc n
493 lem1 z≤n = s≤s z≤n 497 lem1 z≤n = s≤s z≤n
494 lem1 (s≤s lt) = s≤s (lem1 lt) 498 lem1 (s≤s lt) = s≤s (lem1 lt)
495 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) 499 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n))
496 pls4 zero n i≤n perm x = (pprep perm ∘ₚ pins i≤n ) ∷ x 500 pls4 zero n i≤n perm x = (pprep perm ∘ₚ pins i≤n ) ∷ x
497 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) 501 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)
498 pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) 502 pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n))
499 pls5 n [] x = x 503 pls5 n [] x = x
500 pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y) 504 pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y)
501 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n)) 505 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n))
502 pls6 zero = pid ∷ [] 506 pls6 zero = pid ∷ []