annotate FLutil.agda @ 150:5e5e6cd7da2e

FLinsert done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 13 Sep 2020 09:33:57 +0900
parents 98c54cb6ee4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 module FLutil where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Level hiding ( suc ; zero )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Algebra
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Algebra.Structures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ; _≟_)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ; ≤-irrelevant ; _≟_ ) renaming ( <-cmp to <-fcmp )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Fin.Permutation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Function hiding (id ; flip)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Function.LeftInverse using ( _LeftInverseOf_ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Function.Equality using (Π)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open import Data.Nat.Properties -- using (<-trans)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 open import Relation.Binary.PropositionalEquality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 -- open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ; tail ) renaming (reverse to rev )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 open import nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 open import Symmetric
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 open import Data.Empty
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 open import Relation.Binary.Core
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 open import fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 open import Putil
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 open import Gutil
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 open import Solvable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 fmax : { n : ℕ } → FL n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 fmax {zero} = f0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 fmax {suc n} = fromℕ< a<sa :: fmax {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 fmax< : { n : ℕ } → {x : FL n } → ¬ (fmax f< x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 fmax< {suc n} {x :: y} (f<n lt) = nat-≤> (fmax1 x) lt where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 fmax1 : {n : ℕ } → (x : Fin (suc n)) → toℕ x ≤ toℕ (fromℕ< {n} a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 fmax1 {zero} zero = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 fmax1 {suc n} zero = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 fmax1 {suc n} (suc x) = s≤s (fmax1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 fmax< {suc n} {x :: y} (f<t lt) = fmax< {n} {y} lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 fmax¬ : { n : ℕ } → {x : FL n } → ¬ ( x ≡ fmax ) → x f< fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 fmax¬ {zero} {f0} ne = ⊥-elim ( ne refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 fmax¬ {suc n} {x} ne with FLcmp x fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 ... | tri< a ¬b ¬c = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 ... | tri≈ ¬a b ¬c = ⊥-elim ( ne b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ... | tri> ¬a ¬b c = ⊥-elim (fmax< c)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 FL0 : {n : ℕ } → FL n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 FL0 {zero} = f0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 FL0 {suc n} = zero :: FL0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 open import logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
132
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
56 FL0≤ : {n : ℕ } → FL0 {n} f≤ fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
57 FL0≤ {zero} = case1 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
58 FL0≤ {suc zero} = case1 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
59 FL0≤ {suc n} with <-fcmp zero (fromℕ< {n} a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
60 ... | tri< a ¬b ¬c = case2 (f<n a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
61 ... | tri≈ ¬a b ¬c with FL0≤ {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
62 ... | case1 x = case1 (subst₂ (λ j k → (zero :: FL0) ≡ (j :: k ) ) b x refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
63 ... | case2 x = case2 (subst (λ k → (zero :: FL0) f< (k :: fmax)) b (f<t x) )
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 fsuc : { n : ℕ } → (x : FL n ) → x f< fmax → FL n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 fsuc {n} (x :: y) (f<n lt) = fromℕ< fsuc1 :: y where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 fsuc2 : toℕ x < toℕ (fromℕ< a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 fsuc2 = lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 fsuc1 : suc (toℕ x) < n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 fsuc1 = ≤-trans (s≤s lt) ( s≤s ( toℕ≤pred[n] (fromℕ< a<sa)) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 fsuc (x :: y) (f<t lt) = x :: fsuc y lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
132
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
73 open import Data.List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
75 flist1 : {n : ℕ } (i : ℕ) → i < suc n → List (FL n) → List (FL n) → List (FL (suc n))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
76 flist1 zero i<n [] _ = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
77 flist1 zero i<n (a ∷ x ) z = ( zero :: a ) ∷ flist1 zero i<n x z
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
78 flist1 (suc i) (s≤s i<n) [] z = flist1 i (<-trans i<n a<sa) z z
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
79 flist1 (suc i) i<n (a ∷ x ) z = ((fromℕ< i<n ) :: a ) ∷ flist1 (suc i) i<n x z
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
80
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
81 flist : {n : ℕ } → FL n → List (FL n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
82 flist {zero} f0 = f0 ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
83 flist {suc n} (x :: y) = flist1 n a<sa (flist y) (flist y)
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 fr22 : fsuc (zero :: zero :: f0) (fmax¬ (λ ())) ≡ (suc zero :: zero :: f0)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 fr22 = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
132
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
88 fr4 : List (FL 4)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
89 fr4 = Data.List.reverse (flist (fmax {4}) )
131
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
132
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
91 fr5 : List (List ℕ)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
92 fr5 = map plist (map FL→perm (Data.List.reverse (flist (fmax {4}) )))
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
93
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
94 open import Relation.Nary using (⌊_⌋; fromWitness)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
95 open import Data.List.Fresh
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
96 open import Data.List.Fresh.Relation.Unary.All
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
97 open import Data.List.Fresh.Relation.Unary.Any as Any using (Any; here; there)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
98
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
100 FList : {n : ℕ } → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
101 FList {n} = List# (FL n) ⌊ _f<?_ ⌋
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
102
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
103 fr1 : FList
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
104 fr1 =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
105 ((# 0) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
106 ((# 0) :: ((# 1) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
107 ((# 1) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
108 ((# 2) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
109 ((# 2) :: ((# 1) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
110 []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
111
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
112 open import Data.Product
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
113 open import Data.Maybe
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
114
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
115 FLcons : {n : ℕ } → FL n → FList {n} → FList {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
116 FLcons {zero} f0 y = f0 ∷# []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
117 FLcons {suc n} x [] = x ∷# []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
118 FLcons {suc n} x (cons a y x₁) with FLcmp x a
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
119 ... | tri≈ ¬a b ¬c = (cons a y x₁)
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
120 ... | tri< a₁ ¬b ¬c = cons x ( cons a y x₁) (FLcons1 x₁) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
121 FLcons1 : a # y → x # (cons a y x₁)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
122 FLcons1 ay = ? , ?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
123 ... | tri> ¬a ¬b c with FLcons x y
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
124 ... | [] = a ∷# []
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
125 ... | cons a₁ t x₂ = cons a ( cons a₁ t x₂ ) FLcons2 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
126 FLcons2 : fresh (FL (suc n)) ⌊ _f<?_ ⌋ a (cons a₁ t x₂)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
127 FLcons2 = {!!} , {!!}
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
128
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
129 fr6 = FLcons ((# 1) :: ((# 1) :: ((# 0 ) :: f0))) fr1
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 132
diff changeset
130