Mercurial > hg > Members > kono > Proof > galois
view Symmetric.agda @ 44:9ce6141ef479
start again
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 20 Aug 2020 21:59:22 +0900 |
parents | 84c84695de94 |
children | a3ee2ca4f07d |
line wrap: on
line source
module Symmetric where open import Level hiding ( suc ; zero ) open import Algebra open import Algebra.Structures open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ) open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ) renaming ( <-cmp to <-fcmp ) open import Data.Product open import Data.Fin.Permutation open import Function hiding (id ; flip) open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_) open import Function.LeftInverse using ( _LeftInverseOf_ ) open import Function.Equality using (Π) open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n ) open import Data.Nat.Properties -- using (<-trans) open import Relation.Binary.PropositionalEquality open import Data.List using (List; []; _∷_ ; length ; _++_ ) renaming (reverse to rev ) open import nat fid : {p : ℕ } → Fin p → Fin p fid x = x -- Data.Fin.Permutation.id pid : {p : ℕ } → Permutation p p pid = permutation fid fid record { left-inverse-of = λ x → refl ; right-inverse-of = λ x → refl } -- Data.Fin.Permutation.flip pinv : {p : ℕ } → Permutation p p → Permutation p p pinv {p} P = permutation (_⟨$⟩ˡ_ P) (_⟨$⟩ʳ_ P ) record { left-inverse-of = λ x → inverseʳ P ; right-inverse-of = λ x → inverseˡ P } record _=p=_ {p : ℕ } ( x y : Permutation p p ) : Set where field peq : ( q : Fin p ) → x ⟨$⟩ʳ q ≡ y ⟨$⟩ʳ q open _=p=_ prefl : {p : ℕ } { x : Permutation p p } → x =p= x peq (prefl {p} {x}) q = refl psym : {p : ℕ } { x y : Permutation p p } → x =p= y → y =p= x peq (psym {p} {x} {y} eq ) q = sym (peq eq q) ptrans : {p : ℕ } { x y z : Permutation p p } → x =p= y → y =p= z → x =p= z peq (ptrans {p} {x} {y} x=y y=z ) q = trans (peq x=y q) (peq y=z q) Symmetric : ℕ → Group Level.zero Level.zero Symmetric p = record { Carrier = Permutation p p ; _≈_ = _=p=_ ; _∙_ = _∘ₚ_ ; ε = pid ; _⁻¹ = pinv ; isGroup = record { isMonoid = record { isSemigroup = record { isMagma = record { isEquivalence = record {refl = prefl ; trans = ptrans ; sym = psym } ; ∙-cong = presp } ; assoc = passoc } ; identity = ( (λ q → record { peq = λ q → refl } ) , (λ q → record { peq = λ q → refl } )) } ; inverse = ( (λ x → record { peq = λ q → inverseʳ x} ) , (λ x → record { peq = λ q → inverseˡ x} )) ; ⁻¹-cong = λ i=j → record { peq = λ q → p-inv i=j q } } } where presp : {x y u v : Permutation p p } → x =p= y → u =p= v → (x ∘ₚ u) =p= (y ∘ₚ v) presp {x} {y} {u} {v} x=y u=v = record { peq = λ q → lemma4 q } where lemma4 : (q : Fin p) → ((x ∘ₚ u) ⟨$⟩ʳ q) ≡ ((y ∘ₚ v) ⟨$⟩ʳ q) lemma4 q = trans (cong (λ k → Inverse.to u Π.⟨$⟩ k) (peq x=y q) ) (peq u=v _ ) passoc : (x y z : Permutation p p) → ((x ∘ₚ y) ∘ₚ z) =p= (x ∘ₚ (y ∘ₚ z)) passoc x y z = record { peq = λ q → refl } p-inv : {i j : Permutation p p} → i =p= j → (q : Fin p) → pinv i ⟨$⟩ʳ q ≡ pinv j ⟨$⟩ʳ q p-inv {i} {j} i=j q = begin i ⟨$⟩ˡ q ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (inverseʳ j) ) ⟩ i ⟨$⟩ˡ ( j ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (peq i=j _ )) ⟩ i ⟨$⟩ˡ ( i ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ inverseˡ i ⟩ j ⟨$⟩ˡ q ∎ where open ≡-Reasoning open import Relation.Nullary open import Data.Empty open import Relation.Binary.Core open import fin -- An inductive construction of permutation -- we already have refl and trans pprep : {n : ℕ } → Permutation n n → Permutation (suc n) (suc n) pprep {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where p→ : Fin (suc n) → Fin (suc n) p→ zero = zero p→ (suc x) = suc ( perm ⟨$⟩ˡ x) p← : Fin (suc n) → Fin (suc n) p← zero = zero p← (suc x) = suc ( perm ⟨$⟩ʳ x) piso← : (x : Fin (suc n)) → p→ ( p← x ) ≡ x piso← zero = refl piso← (suc x) = cong (λ k → suc k ) (inverseˡ perm) piso→ : (x : Fin (suc n)) → p← ( p→ x ) ≡ x piso→ zero = refl piso→ (suc x) = cong (λ k → suc k ) (inverseʳ perm) pswap : {n : ℕ } → Permutation n n → Permutation (suc (suc n)) (suc (suc n )) pswap {n} perm = permutation p→ p← record { left-inverse-of = piso→ ; right-inverse-of = piso← } where p→ : Fin (suc (suc n)) → Fin (suc (suc n)) p→ zero = suc zero p→ (suc zero) = zero p→ (suc (suc x)) = suc ( suc ( perm ⟨$⟩ˡ x) ) p← : Fin (suc (suc n)) → Fin (suc (suc n)) p← zero = suc zero p← (suc zero) = zero p← (suc (suc x)) = suc ( suc ( perm ⟨$⟩ʳ x) ) piso← : (x : Fin (suc (suc n)) ) → p→ ( p← x ) ≡ x piso← zero = refl piso← (suc zero) = refl piso← (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseˡ perm) piso→ : (x : Fin (suc (suc n)) ) → p← ( p→ x ) ≡ x piso→ zero = refl piso→ (suc zero) = refl piso→ (suc (suc x)) = cong (λ k → suc (suc k) ) (inverseʳ perm) -- enumeration psawpn : {n : ℕ} → 1 < n → Permutation n n psawpn {suc zero} (s≤s ()) psawpn {suc n} (s≤s (s≤s x)) = pswap pid pfill : { n m : ℕ } → m ≤ n → Permutation m m → Permutation n n 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 pfill1 : (i : ℕ ) → i ≤ n → Permutation (n - i) (n - i) → Permutation n n pfill1 0 _ perm = perm pfill1 (suc i) i<n perm = pfill1 i (≤to< i<n) (subst (λ k → Permutation k k ) (si-sn=i-n i<n ) ( pprep perm ) ) psawpim : {n m : ℕ} → 1 < m → m ≤ n → Permutation n n psawpim {n} {m} 1<m m≤n = pfill m≤n ( psawpn 1<m ) -- pconcat : {n m : ℕ } → Permutation m m → Permutation n n → Permutation (m + n) (m + n) -- pconcat {n} {m} p q = pfill {n + m} {m} ? p ∘ₚ ? -- inductivley enmumerate permutations -- from n-1 length create n length inserting new element at position m eperm : {n m : ℕ} → m ≤ n → Permutation n n → Permutation (suc n) (suc n) eperm {0} {0} z≤n perm = pid eperm {suc n} {0} z≤n perm = pprep perm eperm {n} {suc m} (s≤s m<n) perm = eperm1 m 2 lemm3 (pprep perm) where lemm3 : 2 + m ≤ suc n lemm3 = s≤s (s≤s m<n) eperm1 : (m i : ℕ ) → i + m ≤ suc n → Permutation (suc n)(suc n) → Permutation (suc n)(suc n) eperm1 zero i i<ssm perm = perm ∘ₚ (psawpim {suc n} {i + m} {!!} {!!} ) --- 1 < i + m , i + m ≤ suc (suc n) -- m<n : m ≤ n , i<ssm : i + zero ≤ suc (suc n) eperm1 (suc m) i i<ssm perm = eperm1 m (suc i) (lemm4 i<ssm ) perm where lemm4 : i + suc m ≤ suc n → suc i + m ≤ suc n lemm4 lt = begin suc i + m ≡⟨ cong (λ k → suc k ) ( +-comm i _ ) ⟩ suc m + i ≡⟨ +-comm (suc m) _ ⟩ i + suc m ≤⟨ lt ⟩ suc n ∎ where open ≤-Reasoning plist : {n : ℕ} → Permutation n n → List ℕ plist {0} perm = [] plist {suc j} perm = rev (plist1 j a<sa) where n = suc j plist1 : (i : ℕ ) → i < n → List ℕ plist1 zero _ = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ {zero} (s≤s z≤n))) ∷ [] plist1 (suc i) (s≤s lt) = toℕ ( perm ⟨$⟩ˡ (fromℕ≤ (s≤s lt))) ∷ plist1 i (<-trans lt a<sa) testp = plist (psawpim {6} {4} (s≤s (s≤s z≤n)) (s≤s (s≤s (s≤s (s≤s z≤n))))) testi00 = plist(pid {3} ) -- 0 ∷ 1 ∷ 2 ∷ [] testi = plist (pid {3} ∘ₚ psawpim {3} {2} (s≤s (s≤s z≤n)) (s≤s (s≤s z≤n))) -- 0 ∷ 2 ∷ 1 ∷ [] -- 1 ∷ 0 ∷ 2 ∷ [] testi0 = plist (pid {3} ∘ₚ psawpim {3} {3} (s≤s (s≤s z≤n)) (s≤s ( s≤s (s≤s z≤n)))) -- 1 ∷ 0 ∷ 2 ∷ [] -- 1 ∷ 2 ∷ 0 ∷ [] test0 = plist (eperm {1} {0} z≤n pid) test1 = plist (eperm {1} {1} (s≤s z≤n) pid) test = eperm {3} ( s≤s ( s≤s z≤n )) ( eperm (s≤s z≤n) pid ) test11 = plist (eperm {2} {0} z≤n (eperm {1} {0} z≤n pid)) test12 = plist (eperm {2} {0} z≤n (eperm {1} {1} (s≤s z≤n) pid)) test21 = plist (eperm {2} {1} (s≤s z≤n) (eperm {1} {0} z≤n pid)) test22 = plist (eperm {2} {1} (s≤s z≤n) (eperm {1} {1} (s≤s z≤n) pid)) test23 = plist (eperm {2} {2} (s≤s (s≤s z≤n)) (eperm {1} {0} z≤n pid)) test24 = plist (eperm {2} {2} (s≤s (s≤s z≤n)) (eperm {1} {1} (s≤s z≤n) pid)) test3 = test11 ∷ test12 ∷ test21 ∷ test22 ∷ test23 ∷ test24 ∷ [] lem0 : {n : ℕ } → n ≤ n lem0 {zero} = z≤n lem0 {suc n} = s≤s lem0 lem00 : {n m : ℕ } → n ≡ m → n ≤ m lem00 refl = lem0 pls : (n : ℕ ) → List (List ℕ ) pls n = Data.List.map plist (pls6 n) where lem1 : {i n : ℕ } → i ≤ n → i < suc n lem1 z≤n = s≤s z≤n lem1 (s≤s lt) = s≤s (lem1 lt) lem2 : {i n : ℕ } → i ≤ n → i ≤ suc n lem2 i≤n = ≤-trans i≤n ( refl-≤s ) pls4 : ( i n : ℕ ) → (i<n : i ≤ n ) → Permutation n n → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) pls4 zero n i≤n perm x = pid ∷ x pls4 (suc i) n i≤n perm x = pls4 i n (≤-trans refl-≤s i≤n ) perm (eperm {n} {i} (≤-trans refl-≤s i≤n ) perm ∷ x) pls5 : ( n : ℕ ) → List (Permutation n n) → List (Permutation (suc n) (suc n)) → List (Permutation (suc n) (suc n)) pls5 n [] x = x pls5 n (h ∷ x) y = pls5 n x (pls4 n n lem0 h y) pls6 : ( n : ℕ ) → List (Permutation (suc n) (suc n)) pls6 zero = pid ∷ [] pls6 (suc n) = pls5 (suc n) (pls6 n) []