Mercurial > hg > Members > kono > Proof > galois
annotate FLutil.agda @ 197:57188c35ea1a
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 30 Nov 2020 00:36:01 +0900 |
parents | 03d40f6e98b1 |
children | c93a60686dce |
rev | line source |
---|---|
153 | 1 {-# OPTIONS --allow-unsolved-metas #-} |
151 | 2 module FLutil where |
134 | 3 |
4 open import Level hiding ( suc ; zero ) | |
5 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ; _≟_) | |
156 | 6 open import Data.Fin.Properties hiding ( <-trans ; ≤-refl ; ≤-trans ; ≤-irrelevant ; _≟_ ) renaming ( <-cmp to <-fcmp ) |
172 | 7 open import Data.Fin.Permutation -- hiding ([_,_]) |
134 | 8 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n ) |
173 | 9 open import Data.Nat.Properties as DNP |
172 | 10 open import Relation.Binary.PropositionalEquality hiding ( [_] ) |
153 | 11 open import Data.List using (List; []; _∷_ ; length ; _++_ ; tail ) renaming (reverse to rev ) |
134 | 12 open import Data.Product |
13 open import Relation.Nullary | |
14 open import Data.Empty | |
15 open import Relation.Binary.Core | |
172 | 16 open import Relation.Binary.Definitions |
137 | 17 open import logic |
18 open import nat | |
134 | 19 |
20 infixr 100 _::_ | |
21 | |
22 data FL : (n : ℕ )→ Set where | |
23 f0 : FL 0 | |
24 _::_ : { n : ℕ } → Fin (suc n ) → FL n → FL (suc n) | |
25 | |
26 data _f<_ : {n : ℕ } (x : FL n ) (y : FL n) → Set where | |
27 f<n : {m : ℕ } {xn yn : Fin (suc m) } {xt yt : FL m} → xn Data.Fin.< yn → (xn :: xt) f< ( yn :: yt ) | |
28 f<t : {m : ℕ } {xn : Fin (suc m) } {xt yt : FL m} → xt f< yt → (xn :: xt) f< ( xn :: yt ) | |
29 | |
30 FLeq : {n : ℕ } {xn yn : Fin (suc n)} {x : FL n } {y : FL n} → xn :: x ≡ yn :: y → ( xn ≡ yn ) × (x ≡ y ) | |
31 FLeq refl = refl , refl | |
32 | |
33 f-<> : {n : ℕ } {x : FL n } {y : FL n} → x f< y → y f< x → ⊥ | |
34 f-<> (f<n x) (f<n x₁) = nat-<> x x₁ | |
35 f-<> (f<n x) (f<t lt2) = nat-≡< refl x | |
36 f-<> (f<t lt) (f<n x) = nat-≡< refl x | |
37 f-<> (f<t lt) (f<t lt2) = f-<> lt lt2 | |
38 | |
39 f-≡< : {n : ℕ } {x : FL n } {y : FL n} → x ≡ y → y f< x → ⊥ | |
40 f-≡< refl (f<n x) = nat-≡< refl x | |
41 f-≡< refl (f<t lt) = f-≡< refl lt | |
42 | |
43 FLcmp : {n : ℕ } → Trichotomous {Level.zero} {FL n} _≡_ _f<_ | |
44 FLcmp f0 f0 = tri≈ (λ ()) refl (λ ()) | |
45 FLcmp (xn :: xt) (yn :: yt) with <-fcmp xn yn | |
46 ... | tri< a ¬b ¬c = tri< (f<n a) (λ eq → nat-≡< (cong toℕ (proj₁ (FLeq eq)) ) a) (λ lt → f-<> lt (f<n a) ) | |
47 ... | tri> ¬a ¬b c = tri> (λ lt → f-<> lt (f<n c) ) (λ eq → nat-≡< (cong toℕ (sym (proj₁ (FLeq eq)) )) c) (f<n c) | |
48 ... | tri≈ ¬a refl ¬c with FLcmp xt yt | |
49 ... | tri< a ¬b ¬c₁ = tri< (f<t a) (λ eq → ¬b (proj₂ (FLeq eq) )) (λ lt → f-<> lt (f<t a) ) | |
50 ... | tri≈ ¬a₁ refl ¬c₁ = tri≈ (λ lt → f-≡< refl lt ) refl (λ lt → f-≡< refl lt ) | |
51 ... | tri> ¬a₁ ¬b c = tri> (λ lt → f-<> lt (f<t c) ) (λ eq → ¬b (proj₂ (FLeq eq) )) (f<t c) | |
52 | |
138 | 53 f<-trans : {n : ℕ } { x y z : FL n } → x f< y → y f< z → x f< z |
54 f<-trans {suc n} (f<n x) (f<n x₁) = f<n ( Data.Fin.Properties.<-trans x x₁ ) | |
55 f<-trans {suc n} (f<n x) (f<t y<z) = f<n x | |
56 f<-trans {suc n} (f<t x<y) (f<n x) = f<n x | |
57 f<-trans {suc n} (f<t x<y) (f<t y<z) = f<t (f<-trans x<y y<z) | |
58 | |
134 | 59 infixr 250 _f<?_ |
60 | |
61 _f<?_ : {n : ℕ} → (x y : FL n ) → Dec (x f< y ) | |
62 x f<? y with FLcmp x y | |
63 ... | tri< a ¬b ¬c = yes a | |
64 ... | tri≈ ¬a refl ¬c = no ( ¬a ) | |
65 ... | tri> ¬a ¬b c = no ( ¬a ) | |
66 | |
67 _f≤_ : {n : ℕ } (x : FL n ) (y : FL n) → Set | |
68 _f≤_ x y = (x ≡ y ) ∨ (x f< y ) | |
69 | |
70 FL0 : {n : ℕ } → FL n | |
71 FL0 {zero} = f0 | |
72 FL0 {suc n} = zero :: FL0 | |
73 | |
74 fmax : { n : ℕ } → FL n | |
75 fmax {zero} = f0 | |
76 fmax {suc n} = fromℕ< a<sa :: fmax {n} | |
77 | |
78 fmax< : { n : ℕ } → {x : FL n } → ¬ (fmax f< x ) | |
79 fmax< {suc n} {x :: y} (f<n lt) = nat-≤> (fmax1 x) lt where | |
80 fmax1 : {n : ℕ } → (x : Fin (suc n)) → toℕ x ≤ toℕ (fromℕ< {n} a<sa) | |
81 fmax1 {zero} zero = z≤n | |
82 fmax1 {suc n} zero = z≤n | |
83 fmax1 {suc n} (suc x) = s≤s (fmax1 x) | |
84 fmax< {suc n} {x :: y} (f<t lt) = fmax< {n} {y} lt | |
85 | |
86 fmax¬ : { n : ℕ } → {x : FL n } → ¬ ( x ≡ fmax ) → x f< fmax | |
87 fmax¬ {zero} {f0} ne = ⊥-elim ( ne refl ) | |
88 fmax¬ {suc n} {x} ne with FLcmp x fmax | |
89 ... | tri< a ¬b ¬c = a | |
90 ... | tri≈ ¬a b ¬c = ⊥-elim ( ne b) | |
91 ... | tri> ¬a ¬b c = ⊥-elim (fmax< c) | |
92 | |
93 FL0≤ : {n : ℕ } → FL0 {n} f≤ fmax | |
94 FL0≤ {zero} = case1 refl | |
95 FL0≤ {suc zero} = case1 refl | |
96 FL0≤ {suc n} with <-fcmp zero (fromℕ< {n} a<sa) | |
97 ... | tri< a ¬b ¬c = case2 (f<n a) | |
98 ... | tri≈ ¬a b ¬c with FL0≤ {n} | |
99 ... | case1 x = case1 (subst₂ (λ j k → (zero :: FL0) ≡ (j :: k ) ) b x refl ) | |
100 ... | case2 x = case2 (subst (λ k → (zero :: FL0) f< (k :: fmax)) b (f<t x) ) | |
101 | |
151 | 102 open import Data.Nat.Properties using ( ≤-trans ; <-trans ) |
103 fsuc : { n : ℕ } → (x : FL n ) → x f< fmax → FL n | |
104 fsuc {n} (x :: y) (f<n lt) = fromℕ< fsuc1 :: y where | |
105 fsuc1 : suc (toℕ x) < n | |
106 fsuc1 = Data.Nat.Properties.≤-trans (s≤s lt) ( s≤s ( toℕ≤pred[n] (fromℕ< a<sa)) ) | |
107 fsuc (x :: y) (f<t lt) = x :: fsuc y lt | |
108 | |
174 | 109 -- fsuc0 : { n : ℕ } → (x : FL n ) → FL n |
110 -- fsuc0 {n} (x :: y) (f<n lt) = fromℕ< fsuc2 :: y where | |
111 -- fsuc2 : suc (toℕ x) < n | |
112 -- fsuc2 = Data.Nat.Properties.≤-trans (s≤s lt) ( s≤s ( toℕ≤pred[n] (fromℕ< a<sa)) ) | |
113 -- fsuc0 (x :: y) (f<t lt) = x :: fsuc y lt | |
114 | |
115 open import Data.Maybe | |
116 open import fin | |
117 | |
118 fpredm : { n : ℕ } → (x : FL n ) → Maybe (FL n) | |
119 fpredm f0 = nothing | |
120 fpredm (x :: y) with fpredm y | |
121 ... | just y1 = just (x :: y1) | |
122 fpredm (zero :: y) | nothing = nothing | |
123 fpredm (suc x :: y) | nothing = just (fin+1 x :: fmax) | |
124 | |
125 ¬<FL0 : {n : ℕ} {y : FL n} → ¬ y f< FL0 | |
126 ¬<FL0 {suc n} {zero :: y} (f<t lt) = ¬<FL0 {n} {y} lt | |
127 | |
128 fpred : { n : ℕ } → (x : FL n ) → FL0 f< x → FL n | |
129 fpred (zero :: y) (f<t lt) = zero :: fpred y lt | |
130 fpred (x :: y) (f<n lt) with FLcmp FL0 y | |
131 ... | tri< a ¬b ¬c = x :: fpred y a | |
132 ... | tri> ¬a ¬b c = ⊥-elim (¬<FL0 c) | |
133 fpred {suc _} (suc x :: y) (f<n lt) | tri≈ ¬a b ¬c = fin+1 x :: fmax | |
134 | |
135 fpred< : { n : ℕ } → (x : FL n ) → (lt : FL0 f< x ) → fpred x lt f< x | |
136 fpred< (zero :: y) (f<t lt) = f<t (fpred< y lt) | |
137 fpred< (suc x :: y) (f<n lt) with FLcmp FL0 y | |
138 ... | tri< a ¬b ¬c = f<t ( fpred< y a) | |
139 ... | tri> ¬a ¬b c = ⊥-elim (¬<FL0 c) | |
140 ... | tri≈ ¬a refl ¬c = f<n fpr1 where | |
141 fpr1 : {n : ℕ } {x : Fin n} → fin+1 x Data.Fin.< suc x | |
142 fpr1 {suc _} {zero} = s≤s z≤n | |
143 fpr1 {suc _} {suc x} = s≤s fpr1 | |
144 | |
151 | 145 flist1 : {n : ℕ } (i : ℕ) → i < suc n → List (FL n) → List (FL n) → List (FL (suc n)) |
146 flist1 zero i<n [] _ = [] | |
147 flist1 zero i<n (a ∷ x ) z = ( zero :: a ) ∷ flist1 zero i<n x z | |
148 flist1 (suc i) (s≤s i<n) [] z = flist1 i (Data.Nat.Properties.<-trans i<n a<sa) z z | |
149 flist1 (suc i) i<n (a ∷ x ) z = ((fromℕ< i<n ) :: a ) ∷ flist1 (suc i) i<n x z | |
150 | |
151 flist : {n : ℕ } → FL n → List (FL n) | |
152 flist {zero} f0 = f0 ∷ [] | |
153 flist {suc n} (x :: y) = flist1 n a<sa (flist y) (flist y) | |
154 | |
155 fr22 : fsuc (zero :: zero :: f0) (fmax¬ (λ ())) ≡ (suc zero :: zero :: f0) | |
156 fr22 = refl | |
157 | |
158 fr4 : List (FL 4) | |
174 | 159 fr4 = Data.List.reverse (flist (fmax {4}) ) |
151 | 160 -- fr5 : List (List ℕ) |
161 -- fr5 = map plist (map FL→perm (Data.List.reverse (flist (fmax {4}) ))) | |
162 | |
185 | 163 FL1 : List ℕ → List ℕ |
164 FL1 [] = [] | |
165 FL1 (x ∷ y) = suc x ∷ FL1 y | |
166 | |
167 FL→plist : {n : ℕ} → FL n → List ℕ | |
168 FL→plist {0} f0 = [] | |
169 FL→plist {suc n} (zero :: y) = zero ∷ FL1 (FL→plist y) | |
170 FL→plist {suc n} (suc x :: y) with FL→plist y | |
171 ... | [] = zero ∷ [] | |
172 ... | x1 ∷ t = suc x1 ∷ FL2 x t where | |
173 FL2 : {n : ℕ} → Fin n → List ℕ → List ℕ | |
174 FL2 zero y = zero ∷ FL1 y | |
175 FL2 (suc i) [] = zero ∷ [] | |
176 FL2 (suc i) (x ∷ y) = suc x ∷ FL2 i y | |
177 | |
178 tt0 = (# 2) :: (# 1) :: (# 0) :: zero :: f0 | |
179 tt1 = FL→plist tt0 | |
180 -- tt2 = plist ( FL→perm tt0 ) | |
181 | |
182 open _∧_ | |
183 | |
184 find-zero : {n i : ℕ} → List ℕ → i < n → Fin n ∧ List ℕ | |
185 find-zero [] i<n = record { proj1 = fromℕ< i<n ; proj2 = [] } | |
186 find-zero x (s≤s z≤n) = record { proj1 = fromℕ< (s≤s z≤n) ; proj2 = x } | |
187 find-zero (zero ∷ y) (s≤s (s≤s i<n)) = record { proj1 = fromℕ< (s≤s (s≤s i<n)) ; proj2 = y } | |
188 find-zero (suc x ∷ y) (s≤s (s≤s i<n)) with find-zero y (s≤s i<n) | |
189 ... | record { proj1 = i ; proj2 = y1 } = record { proj1 = suc i ; proj2 = suc x ∷ y1 } | |
190 | |
191 plist→FL : {n : ℕ} → List ℕ → FL n | |
192 plist→FL {zero} [] = f0 | |
193 plist→FL {suc n} [] = zero :: plist→FL {n} [] | |
194 plist→FL {zero} x = f0 | |
195 plist→FL {suc n} x with find-zero x a<sa | |
196 ... | record { proj1 = i ; proj2 = y } = i :: plist→FL y | |
197 | |
198 tt2 = 2 ∷ 1 ∷ 0 ∷ 3 ∷ [] | |
199 tt3 : FL 4 | |
200 tt3 = plist→FL tt2 | |
201 -- tt4 = proj1 (find-zero {5} {4} tt2 a<sa) , proj2 (find-zero {5} {4} tt2 a<sa) | |
151 | 202 |
134 | 203 open import Relation.Binary as B hiding (Decidable; _⇔_) |
204 open import Data.Sum.Base as Sum -- inj₁ | |
138 | 205 open import Relation.Nary using (⌊_⌋) |
172 | 206 open import Data.List.Fresh hiding ([_]) |
134 | 207 |
153 | 208 FList : (n : ℕ ) → Set |
209 FList n = List# (FL n) ⌊ _f<?_ ⌋ | |
134 | 210 |
153 | 211 fr1 : FList 3 |
134 | 212 fr1 = |
213 ((# 0) :: ((# 0) :: ((# 0 ) :: f0))) ∷# | |
214 ((# 0) :: ((# 1) :: ((# 0 ) :: f0))) ∷# | |
215 ((# 1) :: ((# 0) :: ((# 0 ) :: f0))) ∷# | |
216 ((# 2) :: ((# 0) :: ((# 0 ) :: f0))) ∷# | |
217 ((# 2) :: ((# 1) :: ((# 0 ) :: f0))) ∷# | |
218 [] | |
219 | |
220 open import Data.Product | |
135 | 221 open import Relation.Nullary.Decidable hiding (⌊_⌋) |
172 | 222 -- open import Data.Bool hiding (_<_ ; _≤_ ) |
135 | 223 open import Data.Unit.Base using (⊤ ; tt) |
224 | |
138 | 225 -- fresh a [] = ⊤ |
226 -- fresh a (x ∷# xs) = R a x × fresh a xs | |
227 | |
228 -- toWitness | |
229 -- ttf< : {n : ℕ } → {x a : FL n } → x f< a → T (isYes (x f<? a)) | |
230 -- ttf< {n} {x} {a} x<a with x f<? a | |
231 -- ... | yes y = subst (λ k → Data.Bool.T k ) refl tt | |
232 -- ... | no nn = ⊥-elim ( nn x<a ) | |
135 | 233 |
176
cf7622b185a6
∀Flist non terminating
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
234 ttf : {n : ℕ } {x a : FL (n)} → x f< a → (y : FList (n)) → fresh (FL (n)) ⌊ _f<?_ ⌋ a y → fresh (FL (n)) ⌊ _f<?_ ⌋ x y |
143 | 235 ttf _ [] fr = Level.lift tt |
236 ttf {_} {x} {a} lt (cons a₁ y x1) (lift lt1 , x2 ) = (Level.lift (fromWitness (ttf1 lt1 lt ))) , ttf (ttf1 lt1 lt) y x1 where | |
141 | 237 ttf1 : True (a f<? a₁) → x f< a → x f< a₁ |
238 ttf1 t x<a = f<-trans x<a (toWitness t) | |
239 | |
151 | 240 -- by https://gist.github.com/aristidb/1684202 |
241 | |
153 | 242 FLinsert : {n : ℕ } → FL n → FList n → FList n |
243 FLfresh : {n : ℕ } → (a x : FL (suc n) ) → (y : FList (suc n) ) → a f< x | |
148 | 244 → fresh (FL (suc n)) ⌊ _f<?_ ⌋ a y → fresh (FL (suc n)) ⌊ _f<?_ ⌋ a (FLinsert x y) |
138 | 245 FLinsert {zero} f0 y = f0 ∷# [] |
246 FLinsert {suc n} x [] = x ∷# [] | |
148 | 247 FLinsert {suc n} x (cons a y x₁) with FLcmp x a |
248 ... | tri≈ ¬a b ¬c = cons a y x₁ | |
249 ... | tri< lt ¬b ¬c = cons x ( cons a y x₁) ( Level.lift (fromWitness lt ) , ttf lt y x₁) | |
153 | 250 FLinsert {suc n} x (cons a [] x₁) | tri> ¬a ¬b lt = cons a ( x ∷# [] ) ( Level.lift (fromWitness lt) , Level.lift tt ) |
251 FLinsert {suc n} x (cons a y yr) | tri> ¬a ¬b a<x = cons a (FLinsert x y) (FLfresh a x y a<x yr ) | |
147 | 252 |
150 | 253 FLfresh a x [] a<x (Level.lift tt) = Level.lift (fromWitness a<x) , Level.lift tt |
254 FLfresh a x (cons b [] (Level.lift tt)) a<x (Level.lift a<b , a<y) with FLcmp x b | |
151 | 255 ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , Level.lift tt |
149 | 256 ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , Level.lift tt |
151 | 257 ... | tri> ¬a ¬b b<x = Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt |
150 | 258 FLfresh a x (cons b y br) a<x (Level.lift a<b , a<y) with FLcmp x b |
151 | 259 ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , ttf (toWitness a<b) y br |
260 ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , ttf a<x y br | |
150 | 261 FLfresh a x (cons b [] br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x = |
151 | 262 Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt |
150 | 263 FLfresh a x (cons b (cons a₁ y x₁) br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x = |
151 | 264 Level.lift a<b , FLfresh a x (cons a₁ y x₁) a<x a<y |
134 | 265 |
138 | 266 fr6 = FLinsert ((# 1) :: ((# 1) :: ((# 0 ) :: f0))) fr1 |
151 | 267 |
152 | 268 -- open import Data.List.Fresh.Relation.Unary.All |
269 -- fr7 = append ( ((# 1) :: ((# 1) :: ((# 0 ) :: f0))) ∷# [] ) fr1 ( ({!!} , {!!} ) ∷ [] ) | |
270 | |
179 | 271 Flist : {n : ℕ } (i : ℕ) → i < suc n → FList n → FList n → FList (suc n) |
272 Flist zero i<n [] _ = [] | |
182
eb94265d2a39
Any based proof computation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
273 Flist zero i<n (a ∷# x ) z = FLinsert ( zero :: a ) (Flist zero i<n x z ) |
180 | 274 Flist (suc i) (s≤s i<n) [] z = Flist i (<-trans i<n a<sa) z z |
182
eb94265d2a39
Any based proof computation done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
275 Flist (suc i) i<n (a ∷# x ) z = FLinsert ((fromℕ< i<n ) :: a ) (Flist (suc i) i<n x z ) |
152 | 276 |
179 | 277 ∀Flist : {n : ℕ } → FL n → FList n |
278 ∀Flist {zero} f0 = f0 ∷# [] | |
279 ∀Flist {suc n} (x :: y) = Flist n a<sa (∀Flist y) (∀Flist y) | |
176
cf7622b185a6
∀Flist non terminating
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
280 |
cf7622b185a6
∀Flist non terminating
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
281 ¬x<FL0 : {n : ℕ} {x : FL n} → ¬ ( x f< FL0 ) |
cf7622b185a6
∀Flist non terminating
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
282 ¬x<FL0 {suc n} {zero :: y} (f<t not) = ¬x<FL0 {n} {y} not |
cf7622b185a6
∀Flist non terminating
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
283 |
153 | 284 fr8 : FList 4 |
179 | 285 fr8 = ∀Flist fmax |
154 | 286 |
172 | 287 fr9 : FList 3 |
179 | 288 fr9 = ∀Flist fmax |
174 | 289 |
154 | 290 open import Data.List.Fresh.Relation.Unary.Any |
156 | 291 open import Data.List.Fresh.Relation.Unary.All |
154 | 292 |
293 x∈FLins : {n : ℕ} → (x : FL n ) → (xs : FList n) → Any (x ≡_ ) (FLinsert x xs) | |
294 x∈FLins {zero} f0 [] = here refl | |
295 x∈FLins {zero} f0 (cons f0 xs x) = here refl | |
296 x∈FLins {suc n} x [] = here refl | |
297 x∈FLins {suc n} x (cons a xs x₁) with FLcmp x a | |
298 ... | tri< x<a ¬b ¬c = here refl | |
299 ... | tri≈ ¬a b ¬c = here b | |
300 x∈FLins {suc n} x (cons a [] x₁) | tri> ¬a ¬b a<x = there ( here refl ) | |
301 x∈FLins {suc n} x (cons a (cons a₁ xs x₂) x₁) | tri> ¬a ¬b a<x = there ( x∈FLins x (cons a₁ xs x₂) ) | |
302 | |
173 | 303 nextAny : {n : ℕ} → {x h : FL n } → {L : FList n} → {hr : fresh (FL n) ⌊ _f<?_ ⌋ h L } → Any (x ≡_ ) L → Any (x ≡_ ) (cons h L hr ) |
304 nextAny (here x₁) = there (here x₁) | |
305 nextAny (there any) = there (there any) | |
306 | |
197 | 307 insAny : {n : ℕ} → {x h : FL n } → (L : FList n) → Any (_≡_ x) L → Any (_≡_ x) (FLinsert h L) |
308 insAny {zero} {f0} {f0} (cons a L xr) (here refl) = here refl | |
309 insAny {zero} {f0} {f0} (cons a L xr) (there any) = insAny {zero} {f0} {f0} L any | |
310 insAny {suc n} {x} {h} (cons a L xr) any with FLcmp h x | FLinsert h (cons a L xr) | inspect (FLinsert h) (cons a L xr) | |
311 ... | tri< a₁ ¬b ¬c | [] | record { eq = eq } = ? | |
312 ... | tri< a₁ ¬b ¬c | cons a₂ t x₁ | record { eq = eq } = subst (λ k → Any (_≡_ x) k ) {!!} (there {_} {_} {_} {{!!}} {{!!}} {{!!}} any) | |
313 ... | tri≈ ¬a b ¬c | t | record { eq = eq }= subst (λ k → Any (_≡_ x) k ) {!!} (here refl) | |
314 insAny {suc n} {x} {h} (cons a [] xr) any | tri> ¬a ¬b c | t | record { eq = eq } = {!!} | |
315 insAny {suc n} {x} {h} (cons a (cons a₁ L x₁) xr) (here x₂) | tri> ¬a ¬b c | t | record { eq = eq } = subst (λ k → Any (_≡_ x) k) {!!} (here {!!}) | |
316 insAny {suc n} {x} {h} (cons a (cons a₁ L x₁) xr) (there any) | tri> ¬a ¬b c | t | record { eq = eq } = subst (λ k → Any (_≡_ x) k) {!!} (there {!!}) | |
317 | |
185 | 318 AnyFList : {n : ℕ } → (x : FL n ) → Any (x ≡_ ) (∀Flist fmax) |
319 AnyFList {zero} f0 = here refl | |
191 | 320 AnyFList {suc zero} (zero :: f0) = here refl |
321 AnyFList {suc (suc n)} (x :: y) = subst (λ k → Any (_≡_ (k :: y)) (Flist (suc n) a<sa (∀Flist fmax) (∀Flist fmax) )) | |
322 (fromℕ<-toℕ _ _) ( AnyFList1 (suc n) (toℕ x) a<sa (∀Flist fmax) (∀Flist fmax) fin<n fin<n (AnyFList y)) where | |
323 AnyFList1 : (i x : ℕ) → (i<n : i < suc (suc n) ) → (L L1 : FList (suc n) ) → (x<n : x < suc (suc n) ) → x < suc i → Any (y ≡_ ) L | |
324 → Any (((fromℕ< x<n) :: y) ≡_ ) (Flist i i<n L L1) | |
325 AnyFList1 zero x i<n [] L1 (s≤s x<i) _ () | |
326 AnyFList1 zero zero i<n (cons a L xr) L1 x<n (s≤s z≤n) (here refl) = x∈FLins (zero :: a) (Flist 0 i<n L L1) | |
327 AnyFList1 zero zero i<n (cons a L xr) L1 x<n (s≤s z≤n) (there wh) with AnyFList1 zero zero i<n L L1 x<n (s≤s z≤n) wh | |
328 ... | t = {!!} | |
329 AnyFList1 (suc i) x i<n L L1 x<n x<i wh = {!!} | |
152 | 330 |
331 -- FLinsert membership | |
332 | |
333 module FLMB { n : ℕ } where | |
334 | |
335 FL-Setoid : Setoid Level.zero Level.zero | |
336 FL-Setoid = record { Carrier = FL n ; _≈_ = _≡_ ; isEquivalence = record { sym = sym ; refl = refl ; trans = trans }} | |
337 | |
338 open import Data.List.Fresh.Membership.Setoid FL-Setoid | |
339 | |
153 | 340 FLinsert-mb : (x : FL n ) → (xs : FList n) → x ∈ FLinsert x xs |
154 | 341 FLinsert-mb x xs = x∈FLins {n} x xs |
153 | 342 |
154 | 343 |