annotate FL.agda @ 139:065d8410d346

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 09 Sep 2020 11:14:36 +0900
parents 6bb9b3f7b844
children 6006d2beaf24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module FL where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level hiding ( suc ; zero )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ; _≟_)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ; ≤-irrelevant ; _≟_ ) renaming ( <-cmp to <-fcmp )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Fin.Permutation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Relation.Binary.PropositionalEquality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ; tail ) renaming (reverse to rev )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Data.Product
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Relation.Nullary
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Data.Empty
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Relation.Binary.Core
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import Relation.Binary.Definitions
137
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 136
diff changeset
15 open import logic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 136
diff changeset
16 open import nat
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 infixr 100 _::_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 data FL : (n : ℕ )→ Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 f0 : FL 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 _::_ : { n : ℕ } → Fin (suc n ) → FL n → FL (suc n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 data _f<_ : {n : ℕ } (x : FL n ) (y : FL n) → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 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
26 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
27
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 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
29 FLeq refl = refl , refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 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
32 f-<> (f<n x) (f<n x₁) = nat-<> x x₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 f-<> (f<n x) (f<t lt2) = nat-≡< refl x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 f-<> (f<t lt) (f<n x) = nat-≡< refl x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 f-<> (f<t lt) (f<t lt2) = f-<> lt lt2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 f-≡< : {n : ℕ } {x : FL n } {y : FL n} → x ≡ y → y f< x → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 f-≡< refl (f<n x) = nat-≡< refl x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 f-≡< refl (f<t lt) = f-≡< refl lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 FLcmp : {n : ℕ } → Trichotomous {Level.zero} {FL n} _≡_ _f<_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 FLcmp f0 f0 = tri≈ (λ ()) refl (λ ())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 FLcmp (xn :: xt) (yn :: yt) with <-fcmp xn yn
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ... | 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
45 ... | 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
46 ... | tri≈ ¬a refl ¬c with FLcmp xt yt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 ... | 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
48 ... | 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
49 ... | 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
50
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
51 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
52 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
53 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
54 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
55 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
56
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 infixr 250 _f<?_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 _f<?_ : {n : ℕ} → (x y : FL n ) → Dec (x f< y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 x f<? y with FLcmp x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 ... | tri< a ¬b ¬c = yes a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 ... | tri≈ ¬a refl ¬c = no ( ¬a )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 ... | tri> ¬a ¬b c = no ( ¬a )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 _f≤_ : {n : ℕ } (x : FL n ) (y : FL n) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 _f≤_ x y = (x ≡ y ) ∨ (x f< y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 FL0 : {n : ℕ } → FL n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 FL0 {zero} = f0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 FL0 {suc n} = zero :: FL0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 fmax : { n : ℕ } → FL n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 fmax {zero} = f0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 fmax {suc n} = fromℕ< a<sa :: fmax {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 fmax< : { n : ℕ } → {x : FL n } → ¬ (fmax f< x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 fmax< {suc n} {x :: y} (f<n lt) = nat-≤> (fmax1 x) lt where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 fmax1 : {n : ℕ } → (x : Fin (suc n)) → toℕ x ≤ toℕ (fromℕ< {n} a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 fmax1 {zero} zero = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 fmax1 {suc n} zero = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 fmax1 {suc n} (suc x) = s≤s (fmax1 x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 fmax< {suc n} {x :: y} (f<t lt) = fmax< {n} {y} lt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 fmax¬ : { n : ℕ } → {x : FL n } → ¬ ( x ≡ fmax ) → x f< fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 fmax¬ {zero} {f0} ne = ⊥-elim ( ne refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 fmax¬ {suc n} {x} ne with FLcmp x fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 ... | tri< a ¬b ¬c = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ... | tri≈ ¬a b ¬c = ⊥-elim ( ne b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ... | tri> ¬a ¬b c = ⊥-elim (fmax< c)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 FL0≤ : {n : ℕ } → FL0 {n} f≤ fmax
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 FL0≤ {zero} = case1 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 FL0≤ {suc zero} = case1 refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 FL0≤ {suc n} with <-fcmp zero (fromℕ< {n} a<sa)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 ... | tri< a ¬b ¬c = case2 (f<n a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 ... | tri≈ ¬a b ¬c with FL0≤ {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ... | case1 x = case1 (subst₂ (λ j k → (zero :: FL0) ≡ (j :: k ) ) b x refl )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ... | 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
100
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 open import Relation.Binary as B hiding (Decidable; _⇔_)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 -- f≤-isDecTotalOrder : ∀ {n} → IsDecTotalOrder _≡_ (_f≤_ {n})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 -- f≤-isDecTotalOrder = record { isTotalOrder = record { isPartialOrder = record { isPreorder = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 -- ; antisym = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 -- }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 -- ; total = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 -- }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 -- ; _≟_ = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 -- ; _≤?_ = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 -- }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 open import Data.Sum.Base as Sum -- inj₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 total : {n : ℕ } → Total (_f≤_ {n})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 total f0 f0 = inj₁ (case1 refl)
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
117 total (x :: xt) (y :: yt) with <-fcmp x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
118 ... | tri< a ¬b ¬c = inj₁ (case2 (f<n a))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
119 ... | tri> ¬a ¬b c = inj₂ (case2 (f<n c))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
120 ... | tri≈ ¬a b ¬c with FLcmp xt yt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
121 ... | tri< a ¬b ¬c₁ = inj₁ (case2 (subst (λ k → (x :: xt ) f< (k :: yt) ) b (f<t a)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
122 ... | tri≈ ¬a₁ b₁ ¬c₁ = inj₁ (case1 (subst₂ (λ j k → j :: k ≡ y :: yt ) (sym b) (sym b₁ ) refl ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
123 ... | tri> ¬a₁ ¬b c = inj₂ (case2 (subst (λ k → (y :: yt ) f< (k :: xt) ) (sym b) (f<t c)))
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
125 open import Relation.Nary using (⌊_⌋)
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 open import Data.List.Fresh
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 open import Data.List.Fresh.Relation.Unary.All
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 open import Data.List.Fresh.Relation.Unary.Any as Any using (Any; here; there)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 FList : {n : ℕ } → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 FList {n} = List# (FL n) ⌊ _f<?_ ⌋
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 fr1 : FList
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 fr1 =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 ((# 0) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 ((# 0) :: ((# 1) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 ((# 1) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 ((# 2) :: ((# 0) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 ((# 2) :: ((# 1) :: ((# 0 ) :: f0))) ∷#
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 open import Data.Product
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 -- open import Data.Maybe
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 -- open TotalOrder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
146 open import Relation.Nullary.Decidable hiding (⌊_⌋)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
147 open import Data.Bool -- hiding (T)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
148 open import Data.Unit.Base using (⊤ ; tt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
149
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
150 -- T : Data.Bool.Bool → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
151 -- T true = ⊤
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
152 -- T false = ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
153
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
154 -- fresh a [] = ⊤
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
155 -- fresh a (x ∷# xs) = R a x × fresh a xs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
156
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
157 -- toWitness
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
158 -- 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
159 -- ttf< {n} {x} {a} x<a with x f<? a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
160 -- ... | yes y = subst (λ k → Data.Bool.T k ) refl tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
161 -- ... | no nn = ⊥-elim ( nn x<a )
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
162
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
163 FLinsert : {n : ℕ } → FL n → FList {n} → FList {n}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
164 FLinsert {zero} f0 y = f0 ∷# []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
165 FLinsert {suc n} x [] = x ∷# []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
166 FLinsert {suc n} x (cons a y x₁) with total x a
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
167 ... | inj₁ (case1 eq) = cons a y x₁
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
168 FLinsert {suc n} x (cons a y x₁) | inj₁ (case2 lt) = cons x ( cons a y x₁) ( Level.lift (fromWitness lt ) , ttf a lt y x₁) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
169 ttf : (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
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
170 ttf a _ [] fr = Level.lift tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
171 ttf a lt (cons a₁ y x1) (lift lt1 , x2 ) = (Level.lift (fromWitness (ttf1 lt1 lt ))) , ttf a₁ (ttf1 lt1 lt) y x1 where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
172 ttf1 : True (a f<? a₁) → x f< a → x f< a₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
173 ttf1 t x<a = f<-trans x<a (toWitness t)
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
174 ... | inj₂ (case1 eq) = cons a y x₁
139
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
175 ... | inj₂ (case2 lt) = cons a ( FLinsert x y ) (ttf2 y) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
176 ttf2 : (y : FList {suc n}) → fresh (FL (suc n)) ⌊ _f<?_ ⌋ a (FLinsert x y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
177 ttf2 [] with FLinsert x []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
178 ... | [] = Level.lift tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
179 ... | cons a t x = {!!} , {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
180 ttf2 (cons a [] x) = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
181 ttf2 (cons a (cons a₁ y x₁) x) = {!!}
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
183 fr6 = FLinsert ((# 1) :: ((# 1) :: ((# 0 ) :: f0))) fr1