Mercurial > hg > Members > kono > Proof > galois
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 |
rev | line source |
---|---|
48 | 1 module Putil where |
0 | 2 |
3 open import Level hiding ( suc ; zero ) | |
4 open import Algebra | |
5 open import Algebra.Structures | |
37 | 6 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ) |
41 | 7 open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ) renaming ( <-cmp to <-fcmp ) |
0 | 8 open import Data.Fin.Permutation |
9 open import Function hiding (id ; flip) | |
10 open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_) | |
11 open import Function.LeftInverse using ( _LeftInverseOf_ ) | |
12 open import Function.Equality using (Π) | |
17 | 13 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n ) |
14 open import Data.Nat.Properties -- using (<-trans) | |
16 | 15 open import Relation.Binary.PropositionalEquality |
46 | 16 open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ) renaming (reverse to rev ) |
16 | 17 open import nat |
0 | 18 |
48 | 19 open import Symmetric |
0 | 20 |
21 | |
16 | 22 open import Relation.Nullary |
23 open import Data.Empty | |
17 | 24 open import Relation.Binary.Core |
25 open import fin | |
16 | 26 |
38 | 27 -- An inductive construction of permutation |
34 | 28 |
48 | 29 -- we already have refl and trans in the Symmetric Group |
41 | 30 |
34 | 31 pprep : {n : ℕ } → Permutation n n → Permutation (suc n) (suc n) |
32 pprep {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where | |
33 | 33 p→ : Fin (suc n) → Fin (suc n) |
34 | 34 p→ zero = zero |
35 p→ (suc x) = suc ( perm ⟨$⟩ˡ x) | |
33 | 36 |
34 | 37 p← : Fin (suc n) → Fin (suc n) |
38 p← zero = zero | |
39 p← (suc x) = suc ( perm ⟨$⟩ʳ x) | |
40 | |
41 piso← : (x : Fin (suc n)) → p→ ( p← x ) ≡ x | |
42 piso← zero = refl | |
35 | 43 piso← (suc x) = cong (λ k → suc k ) (inverseˡ perm) |
33 | 44 |
34 | 45 piso→ : (x : Fin (suc n)) → p← ( p→ x ) ≡ x |
46 piso→ zero = refl | |
35 | 47 piso→ (suc x) = cong (λ k → suc k ) (inverseʳ perm) |
33 | 48 |
34 | 49 pswap : {n : ℕ } → Permutation n n → Permutation (suc (suc n)) (suc (suc n )) |
50 pswap {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where | |
51 p→ : Fin (suc (suc n)) → Fin (suc (suc n)) | |
52 p→ zero = suc zero | |
53 p→ (suc zero) = zero | |
54 p→ (suc (suc x)) = suc ( suc ( perm ⟨$⟩ˡ x) ) | |
18 | 55 |
34 | 56 p← : Fin (suc (suc n)) → Fin (suc (suc n)) |
57 p← zero = suc zero | |
58 p← (suc zero) = zero | |
59 p← (suc (suc x)) = suc ( suc ( perm ⟨$⟩ʳ x) ) | |
60 | |
61 piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x | |
62 piso← zero = refl | |
63 piso← (suc zero) = refl | |
35 | 64 piso← (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseˡ perm) |
16 | 65 |
34 | 66 piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x |
67 piso→ zero = refl | |
68 piso→ (suc zero) = refl | |
35 | 69 piso→ (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseʳ perm) |
34 | 70 |
71 -- enumeration | |
72 | |
44 | 73 psawpn : {n : ℕ} → 1 < n → Permutation n n |
74 psawpn {suc zero} (s≤s ()) | |
75 psawpn {suc n} (s≤s (s≤s x)) = pswap pid | |
34 | 76 |
35 | 77 pfill : { n m : ℕ } → m ≤ n → Permutation m m → Permutation n n |
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 | |
79 pfill1 : (i : ℕ ) → i ≤ n → Permutation (n - i) (n - i) → Permutation n n | |
80 pfill1 0 _ perm = perm | |
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 | 82 |
48 | 83 -- |
84 -- psawpim (inseert swap at position m ) | |
85 -- not easy to write directory beacause left-inverse-of may contains Fin relations | |
86 -- | |
45 | 87 psawpim : {n m : ℕ} → suc (suc m) ≤ n → Permutation n n |
88 psawpim {n} {m} m≤n = pfill m≤n ( psawpn (s≤s (s≤s z≤n)) ) | |
89 | |
90 n≤ : (i : ℕ ) → {j : ℕ } → i ≤ i + j | |
91 n≤ (zero) {j} = z≤n | |
92 n≤ (suc i) {j} = s≤s ( n≤ i ) | |
93 | |
94 lem0 : {n : ℕ } → n ≤ n | |
95 lem0 {zero} = z≤n | |
96 lem0 {suc n} = s≤s lem0 | |
97 | |
98 lem00 : {n m : ℕ } → n ≡ m → n ≤ m | |
99 lem00 refl = lem0 | |
44 | 100 |
101 -- pconcat : {n m : ℕ } → Permutation m m → Permutation n n → Permutation (m + n) (m + n) | |
102 -- pconcat {n} {m} p q = pfill {n + m} {m} ? p ∘ₚ ? | |
103 | |
104 -- inductivley enmumerate permutations | |
105 -- from n-1 length create n length inserting new element at position m | |
106 | |
48 | 107 -- 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] |
108 -- 1 ∷ 0 ∷ 2 ∷ 3 ∷ [] plist ( pins {3} (n≤ 1) ) | |
109 -- 1 ∷ 2 ∷ 0 ∷ 3 ∷ [] | |
110 -- 1 ∷ 2 ∷ 3 ∷ 0 ∷ [] | |
45 | 111 |
48 | 112 pins : {n m : ℕ} → m ≤ n → Permutation (suc n) (suc n) |
113 pins {_} {zero} _ = pid | |
114 pins {suc _} {suc zero} _ = pswap pid | |
115 pins {suc (suc n)} {suc m} (s≤s m<n) = pins1 (suc m) (suc (suc n)) lem0 where | |
116 pins1 : (i j : ℕ ) → j ≤ suc (suc n) → Permutation (suc (suc (suc n ))) (suc (suc (suc n))) | |
117 pins1 _ zero _ = pid | |
118 pins1 zero _ _ = pid | |
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 | 120 |
121 plist : {n : ℕ} → Permutation n n → List ℕ | |
122 plist {0} perm = [] | |
44 | 123 plist {suc j} perm = rev (plist1 j a<sa) where |
37 | 124 n = suc j |
125 plist1 : (i : ℕ ) → i < n → List ℕ | |
40 | 126 plist1 zero _ = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ {zero} (s≤s z≤n))) ∷ [] |
127 plist1 (suc i) (s≤s lt) = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ (s≤s lt))) ∷ plist1 i (<-trans lt a<sa) | |
37 | 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 | 133 open import logic |
134 | |
51 | 135 shrink : {n : ℕ} → (perm : Permutation (suc n) (suc n) ) → perm ⟨$⟩ˡ (fromℕ n) ≡ fromℕ n → Permutation n n |
50 | 136 shrink {n} perm p0=0 = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where |
51 | 137 shlem→ : (x : Fin n ) → toℕ (perm ⟨$⟩ˡ (fin+1 x)) < n |
138 shlem→ x with <-cmp (toℕ (perm ⟨$⟩ˡ (fin+1 x))) n | |
139 shlem→ x | tri< a ¬b ¬c = a | |
140 shlem→ x | tri≈ ¬a b ¬c = {!!} | |
141 shlem→ x | tri> ¬a ¬b c = {!!} | |
50 | 142 |
51 | 143 shlem← : (x : Fin n) → toℕ (perm ⟨$⟩ʳ (fin+1 x)) < n |
144 shlem← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n | |
145 shlem← x | tri< a ¬b ¬c = a | |
146 shlem← x | tri≈ ¬a b ¬c = {!!} | |
147 shlem← x | tri> ¬a ¬b c = {!!} | |
50 | 148 |
51 | 149 p→ : (x : Fin n ) → Fin n |
150 p→ x = fromℕ≤ (shlem→ x) | |
50 | 151 |
152 p← : Fin n → Fin n | |
51 | 153 p← x = fromℕ≤ (shlem← x) |
50 | 154 |
155 piso← : (x : Fin n ) → p→ ( p← x ) ≡ x | |
51 | 156 piso← x with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n |
157 piso← x | tri< a ¬b ¬c with <-cmp (toℕ (perm ⟨$⟩ʳ (fin+1 x))) n | |
158 piso← x | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = {!!} | |
159 piso← x | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = {!!} | |
160 piso← x | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = {!!} | |
161 piso← x | tri≈ ¬a b ¬c = {!!} | |
162 piso← x | tri> ¬a ¬b c = {!!} | |
50 | 163 |
164 piso→ : (x : Fin n ) → p← ( p→ x ) ≡ x | |
51 | 165 piso→ x = {!!} |
50 | 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 | 169 perm→FL {suc n} perm = (perm ⟨$⟩ˡ fromℕ≤ a<sa ) :: perm→FL ( shrink fl1 {!!} ) where |
170 fl1 : Permutation (suc n) (suc n) | |
171 fl1 = perm ∘ₚ pinv ( pins {!!}) | |
172 fl1=pprep : perm =p= pprep ( shrink fl1 {!!} ) | |
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 | 181 FL→iso (x :: fl) = {!!} --with FL→iso fl |
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 | 191 all-perm : (n : ℕ ) → List (Permutation (suc n) (suc n) ) |
192 all-perm n = pls6 n where | |
38 | 193 lem1 : {i n : ℕ } → i ≤ n → i < suc n |
194 lem1 z≤n = s≤s z≤n | |
195 lem1 (s≤s lt) = s≤s (lem1 lt) | |
196 lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n | |
197 lem2 i≤n = ≤-trans i≤n ( refl-≤s ) | |
40 | 198 pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) |
48 | 199 pls4 zero n i≤n perm x = (pprep perm ∘ₚ pins i≤n ) ∷ x |
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 | 201 pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) |
202 pls5 n [] x = x | |
203 pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y) | |
204 pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n)) | |
205 pls6 zero = pid ∷ [] | |
48 | 206 pls6 (suc n) = pls5 (suc n) (rev (pls6 n) ) [] -- rev to put id first |
207 | |
208 pls : (n : ℕ ) → List (List ℕ ) | |
209 pls n = Data.List.map plist (all-perm n) where |