annotate FLutil.agda @ 174:8e8238b26ee7

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