comparison automaton-in-agda/src/non-regular.agda @ 316:fd07e3205cea

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 03 Jan 2022 11:41:58 +0900
parents 25ae77240238
children 16e47a3c4eda
comparison
equal deleted inserted replaced
315:25ae77240238 316:fd07e3205cea
97 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) 97 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
98 open import Relation.Binary.Definitions 98 open import Relation.Binary.Definitions
99 open import Data.Unit using (⊤ ; tt) 99 open import Data.Unit using (⊤ ; tt)
100 open import Data.Nat.Properties 100 open import Data.Nat.Properties
101 101
102 sometime : { a : Set } (x : List a ) → (n : ℕ) → n ≤ length x → (P : a → Set) → Set
103 sometime {a} [] .zero z≤n P = ⊤
104 sometime {a} (x ∷ x₁) zero z≤n P = P x
105 sometime {a} (x ∷ x₁) (suc n) (s≤s lt) P = sometime {a} x₁ n lt P
106
107 get : { a : Set } (x : List a ) → (n : ℕ) → Maybe a
108 get [] zero = nothing
109 get [] (suc n) = nothing
110 get (x ∷ x₁) zero = just x
111 get (x ∷ x₁) (suc n) = get x₁ n
112
113 is0-bool : ( i : ℕ ) → Bool
114 is0-bool zero = true
115 is0-bool (suc i) = false
116
117 data QDSEQ { Q : Set } { Σ : Set } { fa : Automaton Q Σ} ( finq : FiniteSet Q) (qd : Q) (z1 : List Σ) : 102 data QDSEQ { Q : Set } { Σ : Set } { fa : Automaton Q Σ} ( finq : FiniteSet Q) (qd : Q) (z1 : List Σ) :
118 {q : Q} {y2 : List Σ} → Trace fa (y2 ++ z1) q → Set where 103 {q : Q} {y2 : List Σ} → Trace fa (y2 ++ z1) q → Set where
119 qd-nil : (q : Q) → (tr : Trace fa z1 q) → equal? finq qd q ≡ true → QDSEQ finq qd z1 tr 104 qd-nil : (q : Q) → (tr : Trace fa z1 q) → equal? finq qd q ≡ true → QDSEQ finq qd z1 tr
120 qd-next : {i : Σ} (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) (δ fa q i)) → equal? finq qd q ≡ false 105 qd-next : {i : Σ} (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) (δ fa q i)) → equal? finq qd q ≡ false
121 → QDSEQ finq qd z1 tr 106 → QDSEQ finq qd z1 tr
126 y z : List Σ 111 y z : List Σ
127 yz=is : y ++ z ≡ is 112 yz=is : y ++ z ≡ is
128 trace-z : Trace fa z qd 113 trace-z : Trace fa z qd
129 trace-yz : Trace fa (y ++ z) q 114 trace-yz : Trace fa (y ++ z) q
130 q=qd : QDSEQ finq qd z trace-yz 115 q=qd : QDSEQ finq qd z trace-yz
131 -- q=qd : equal? finq qd q ≡ is0-bool (length y) 116
117 --
118 -- using accept ≡ true may simplify the make-TA
119 -- QDSEQ is too complex, should we generate (lengty y ≡ 0 → equal ) ∧ ...
120 --
121 -- like this ...
122 -- record TA2 { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) ( q qd : Q ) (is : List Σ) : Set where
123 -- field
124 -- y z : List Σ
125 -- yz=is : y ++ z ≡ is
126 -- trace-z : accpet fa z qd ≡ true
127 -- trace-yz : accept fa (y ++ z) q ≡ true
128 -- q=qd : last (tr→qs fa q trace-yz) ≡ just qd
129 -- ¬q=qd : non-last (tr→qs fa q trace-yz) ≡ just qd
132 130
133 record TA { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) ( q : Q ) (is : List Σ) : Set where 131 record TA { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) ( q : Q ) (is : List Σ) : Set where
134 field 132 field
135 x y z : List Σ 133 x y z : List Σ
136 xyz=is : x ++ y ++ z ≡ is 134 xyz=is : x ++ y ++ z ≡ is
170 z1 = TA1.z ta 168 z1 = TA1.z ta
171 tryz0 : Trace fa (y1 ++ z1) (δ fa qd i) 169 tryz0 : Trace fa (y1 ++ z1) (δ fa qd i)
172 tryz0 = subst₂ (λ j k → Trace fa k (δ fa j i) ) (sym (equal→refl finq eq)) (sym (TA1.yz=is ta)) tr 170 tryz0 = subst₂ (λ j k → Trace fa k (δ fa j i) ) (sym (equal→refl finq eq)) (sym (TA1.yz=is ta)) tr
173 tryz : Trace fa (i ∷ y1 ++ z1) qd 171 tryz : Trace fa (i ∷ y1 ++ z1) qd
174 tryz = tnext qd tryz0 172 tryz = tnext qd tryz0
173 -- create Trace (y ++ y ++ z)
175 tra-04 : (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) q) 174 tra-04 : (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) q)
176 → QDSEQ finq qd z1 {q} {y2} tr 175 → QDSEQ finq qd z1 {q} {y2} tr
177 → Trace fa (y2 ++ (i ∷ y1) ++ z1) q 176 → Trace fa (y2 ++ (i ∷ y1) ++ z1) q
178 tra-04 [] q tr (qd-nil q _ x₁) with equal? finq qd q | inspect (equal? finq qd) q 177 tra-04 [] q tr (qd-nil q _ x₁) with equal? finq qd q | inspect (equal? finq qd) q
179 ... | true | record { eq = eq } = subst (λ k → Trace fa (i ∷ y1 ++ z1) k) (equal→refl finq eq) tryz 178 ... | true | record { eq = eq } = subst (λ k → Trace fa (i ∷ y1 ++ z1) k) (equal→refl finq eq) tryz
199 n : ℕ 198 n : ℕ
200 n = suc (finite (afin r)) 199 n = suc (finite (afin r))
201 nn = inputnn0 n i0 i1 [] 200 nn = inputnn0 n i0 i1 []
202 nn01 : (i : ℕ) → inputnn1 ( inputnn0 i i0 i1 [] ) ≡ true 201 nn01 : (i : ℕ) → inputnn1 ( inputnn0 i i0 i1 [] ) ≡ true
203 nn01 zero = refl 202 nn01 zero = refl
204 nn01 (suc i) with nn01 i 203 nn01 (suc i) = {!!} where
205 ... | t = {!!} 204 nn02 : (i : ℕ) → ( x : List In2) → inputnn ( inputnn0 i i0 i1 x ) ≡ inputnn x
205 nn02 zero _ = refl
206 nn02 (suc i) x with inputnn (inputnn0 (suc i) i0 i1 x)
207 ... | nothing = {!!}
208 ... | just [] = {!!}
209 ... | just (i0 ∷ t1) = {!!}
210 ... | just (i1 ∷ t1) = {!!}
206 nn03 : accept (automaton r) (astart r) nn ≡ true 211 nn03 : accept (automaton r) (astart r) nn ≡ true
207 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n) 212 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n)
208 nn09 : (n m : ℕ) → n ≤ n + m 213 nn09 : (n m : ℕ) → n ≤ n + m
209 nn09 zero m = z≤n 214 nn09 zero m = z≤n
210 nn09 (suc n) m = s≤s (nn09 n m) 215 nn09 (suc n) m = s≤s (nn09 n m)
225 suc n + suc n + length s ∎ where open ≡-Reasoning 230 suc n + suc n + length s ∎ where open ≡-Reasoning
226 nn05 : length nntrace > finite (afin r) 231 nn05 : length nntrace > finite (afin r)
227 nn05 = begin 232 nn05 = begin
228 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩ 233 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩
229 n + n ≡⟨ sym (nn07 n) ⟩ 234 n + n ≡⟨ sym (nn07 n) ⟩
230 length (inputnn0 n i0 i1 []) ≤⟨ refl-≤s ⟩ 235 length (inputnn0 n i0 i1 []) ≡⟨ tr→qs=is (automaton r) (inputnn0 n i0 i1 []) (astart r) nn04 ⟩
231 {!!} ≤⟨ {!!} ⟩
232 length nntrace ∎ where open ≤-Reasoning 236 length nntrace ∎ where open ≤-Reasoning
233 nn06 : Dup-in-list ( afin r) (tr→qs (automaton r) nn (astart r) nn04) 237 nn06 : Dup-in-list ( afin r) (tr→qs (automaton r) nn (astart r) nn04)
234 nn06 = dup-in-list>n (afin r) nntrace nn05 238 nn06 = dup-in-list>n (afin r) nntrace nn05
235 TAnn : TA (automaton r) (astart r) nn 239 TAnn : TA (automaton r) (astart r) nn
236 TAnn = make-TA (automaton r) (afin r) (astart r) (Dup-in-list.dup nn06) nn nn04 (Dup-in-list.is-dup nn06) 240 TAnn = make-TA (automaton r) (afin r) (astart r) (Dup-in-list.dup nn06) nn nn04 (Dup-in-list.is-dup nn06)
238 count _ [] = 0 242 count _ [] = 0
239 count i0 (i0 ∷ s) = suc (count i0 s) 243 count i0 (i0 ∷ s) = suc (count i0 s)
240 count i1 (i1 ∷ s) = suc (count i1 s) 244 count i1 (i1 ∷ s) = suc (count i1 s)
241 count x (_ ∷ s) = count x s 245 count x (_ ∷ s) = count x s
242 nn11 : {x : In2} → (s t : List In2) → count x (s ++ t) ≡ count x s + count x t 246 nn11 : {x : In2} → (s t : List In2) → count x (s ++ t) ≡ count x s + count x t
243 nn11 = {!!} 247 nn11 {x} [] t = refl
248 nn11 {i0} (i0 ∷ s) t = cong suc ( nn11 s t )
249 nn11 {i0} (i1 ∷ s) t = nn11 s t
250 nn11 {i1} (i0 ∷ s) t = nn11 s t
251 nn11 {i1} (i1 ∷ s) t = cong suc ( nn11 s t )
244 nn10 : (s : List In2) → accept (automaton r) (astart r) s ≡ true → count i0 s ≡ count i1 s 252 nn10 : (s : List In2) → accept (automaton r) (astart r) s ≡ true → count i0 s ≡ count i1 s
245 nn10 = {!!} 253 nn10 = {!!}
246 i1-i0? : List In2 → Bool 254 i1-i0? : List In2 → Bool
247 i1-i0? [] = false 255 i1-i0? [] = false
248 i1-i0? (i1 ∷ []) = false 256 i1-i0? (i1 ∷ []) = false
249 i1-i0? (i0 ∷ []) = false 257 i1-i0? (i0 ∷ []) = false
250 i1-i0? (i1 ∷ i0 ∷ s) = true 258 i1-i0? (i1 ∷ i0 ∷ s) = true
251 i1-i0? (_ ∷ s0 ∷ s1) = i1-i0? (s0 ∷ s1) 259 i1-i0? (_ ∷ s0 ∷ s1) = i1-i0? (s0 ∷ s1)
252 nn20 : {s s0 s1 : List In2} → accept (automaton r) (astart r) s ≡ true → ¬ ( s ≡ s0 ++ i1 ∷ i0 ∷ s1 ) 260 nn20 : {s s0 s1 : List In2} → accept (automaton r) (astart r) s ≡ true → ¬ ( s ≡ s0 ++ i1 ∷ i0 ∷ s1 )
253 nn20 = {!!} 261 nn20 {s} {s0} {s1} p np = {!!}
254 mono-color : List In2 → Bool 262 mono-color : List In2 → Bool
255 mono-color [] = true 263 mono-color [] = true
256 mono-color (i0 ∷ s) = mono-color0 s where 264 mono-color (i0 ∷ s) = mono-color0 s where
257 mono-color0 : List In2 → Bool 265 mono-color0 : List In2 → Bool
258 mono-color0 [] = true 266 mono-color0 [] = true