annotate automaton-in-agda/src/non-regular.agda @ 309:acb0214ea4d8

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 02 Jan 2022 15:27:17 +0900
parents 2effd9a23299
children 271ded718895
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module non-regular where
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Data.Nat
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
4 open import Data.Empty
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.List
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 277
diff changeset
6 open import Data.Maybe hiding ( map )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Relation.Binary.PropositionalEquality hiding ( [_] )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import logic
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import automaton
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
10 open import automaton-ex
278
e89957b99662 dup in finiteSet in long list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 277
diff changeset
11 open import finiteSetUtil
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import finiteSet
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Relation.Nullary
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
14 open import regular-language
306
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
15 open import nat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
16
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
18 open FiniteSet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
20 inputnn : List In2 → Maybe (List In2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
21 inputnn [] = just []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
22 inputnn (i1 ∷ t) = just (i1 ∷ t)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
23 inputnn (i0 ∷ t) with inputnn t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
24 ... | nothing = nothing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
25 ... | just [] = nothing
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
26 ... | just (i0 ∷ t1) = nothing -- can't happen
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
27 ... | just (i1 ∷ t1) = just t1 -- remove i1 from later part
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
28
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
29 inputnn1 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
30 inputnn1 s with inputnn s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
31 ... | nothing = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
32 ... | just [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
33 ... | just _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
34
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
35 t1 = inputnn1 ( i0 ∷ i1 ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
36 t2 = inputnn1 ( i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] )
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
37 t3 = inputnn1 ( i0 ∷ i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] )
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
39 inputnn0 : ( n : ℕ ) → { Σ : Set } → ( x y : Σ ) → List Σ → List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
40 inputnn0 zero {_} _ _ s = s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
41 inputnn0 (suc n) x y s = x ∷ ( inputnn0 n x y ( y ∷ s ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
42
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
43 t4 : inputnn1 ( inputnn0 5 i0 i1 [] ) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
44 t4 = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
45
291
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
46 t5 : ( n : ℕ ) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
47 t5 n = inputnn1 ( inputnn0 n i0 i1 [] ) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
48
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
49 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
50 -- if there is an automaton with n states , which accespt inputnn1, it has a trasition function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
51 -- The function is determinted by inputs,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
52 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
53
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
54 open RegularLanguage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
55 open Automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
56
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
57 open _∧_
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
59 data Trace { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) : (is : List Σ) → Q → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
60 tend : {q : Q} → aend fa q ≡ true → Trace fa [] q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
61 tnext : (q : Q) → {i : Σ} { is : List Σ}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
62 → Trace fa is (δ fa q i) → Trace fa (i ∷ is) q
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
63
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
64 tr-len : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
65 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
66 → (is : List Σ) → (q : Q) → Trace fa is q → suc (length is) ≡ length (trace fa q is )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
67 tr-len {Q} {Σ} fa .[] q (tend x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
68 tr-len {Q} {Σ} fa (i ∷ is) q (tnext .q t) = cong suc (tr-len {Q} {Σ} fa is (δ fa q i) t)
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
69
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
70 tr-accept→ : { Q : Set } { Σ : Set }
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
71 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
72 → (is : List Σ) → (q : Q) → Trace fa is q → accept fa q is ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
73 tr-accept→ {Q} {Σ} fa [] q (tend x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
74 tr-accept→ {Q} {Σ} fa (i ∷ is) q (tnext _ tr) = tr-accept→ {Q} {Σ} fa is (δ fa q i) tr
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
75
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
76 tr-accept← : { Q : Set } { Σ : Set }
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
77 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
78 → (is : List Σ) → (q : Q) → accept fa q is ≡ true → Trace fa is q
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
79 tr-accept← {Q} {Σ} fa [] q ac = tend ac
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
80 tr-accept← {Q} {Σ} fa (x ∷ []) q ac = tnext _ (tend ac )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
81 tr-accept← {Q} {Σ} fa (x ∷ x1 ∷ is) q ac = tnext _ (tr-accept← fa (x1 ∷ is) (δ fa q x) ac)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
82
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
83 tr→qs : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
84 → (fa : Automaton Q Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
85 → (is : List Σ) → (q : Q) → Trace fa is q → List Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
86 tr→qs fa [] q (tend x) = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
87 tr→qs fa (i ∷ is) q (tnext q tr) = q ∷ tr→qs fa is (δ fa q i) tr
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
88
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
89 tr→qs=is : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
90 → (fa : Automaton Q Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
91 → (is : List Σ) → (q : Q) → (tr : Trace fa is q ) → length is ≡ length (tr→qs fa is q tr)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
92 tr→qs=is fa .[] q (tend x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
93 tr→qs=is fa (i ∷ is) q (tnext .q tr) = cong suc (tr→qs=is fa is (δ fa q i) tr)
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
94
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
95 open Data.Maybe
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
96
306
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
97 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
98 open import Relation.Binary.Definitions
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
99 open import Data.Unit using (⊤ ; tt)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
100 open import Data.Nat.Properties
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
101
306
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
102 sometime : { a : Set } (x : List a ) → (n : ℕ) → n ≤ length x → (P : a → Set) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
103 sometime {a} [] .zero z≤n P = ⊤
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
104 sometime {a} (x ∷ x₁) zero z≤n P = P x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
105 sometime {a} (x ∷ x₁) (suc n) (s≤s lt) P = sometime {a} x₁ n lt P
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
106
306
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
107 get : { a : Set } (x : List a ) → (n : ℕ) → Maybe a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
108 get [] zero = nothing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
109 get [] (suc n) = nothing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
110 get (x ∷ x₁) zero = just x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
111 get (x ∷ x₁) (suc n) = get x₁ n
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
112
307
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
113 is0-bool : ( i : ℕ ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
114 is0-bool zero = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
115 is0-bool (suc i) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
116
309
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
117 data QDSEQ { Q : Set } { Σ : Set } { fa : Automaton Q Σ} ( finq : FiniteSet Q) (qd : Q) (z1 : List Σ) :
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
118 {q : Q} {y2 : List Σ} → Trace fa (y2 ++ z1) q → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
119 qd-next : (i : Σ) (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) (δ fa q i)) → equal? finq qd q ≡ is0-bool (length y2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
120 → QDSEQ finq qd z1 tr
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
121 → QDSEQ finq qd z1 (tnext q tr)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 308
diff changeset
122
302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 301
diff changeset
123 record TA1 { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) ( q qd : Q ) (is : List Σ) : Set where
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
124 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
125 y z : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
126 yz=is : y ++ z ≡ is
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
127 trace-z : Trace fa z qd
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
128 trace-yz : Trace fa (y ++ z) q
307
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
129 q=qd : equal? finq qd q ≡ is0-bool (length y)
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
130
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
131 record TA { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) ( q : Q ) (is : List Σ) : Set where
279
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
132 field
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
133 x y z : List Σ
298
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 297
diff changeset
134 xyz=is : x ++ y ++ z ≡ is
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
135 trace-xyz : Trace fa (x ++ y ++ z) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
136 trace-xyyz : Trace fa (x ++ y ++ y ++ z) q
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
137 non-nil-y : ¬ (y ≡ [])
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
138
305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
139 make-TA : { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (fins : FiniteSet Σ) (finq : FiniteSet Q) (q qd : Q) (is : List Σ)
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
140 → (tr : Trace fa is q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
141 → dup-in-list finq qd (tr→qs fa is q tr) ≡ true
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
142 → TA fa q is
305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
143 make-TA {Q} {Σ} fa fins finq q qd is tr dup = tra-phase1 q is tr dup where
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
144 open TA
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
145 tra-phase2 : (q : Q) → (is : List Σ) → (tr : Trace fa is q )
302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 301
diff changeset
146 → phase2 finq qd (tr→qs fa is q tr) ≡ true → TA1 fa finq q qd is
297
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 296
diff changeset
147 tra-phase2 q (i ∷ is) (tnext q tr) p with equal? finq qd q | inspect ( equal? finq qd) q
307
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
148 ... | true | record { eq = eq } = record { y = [] ; z = i ∷ is ; yz=is = refl ; q=qd = eq
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
149 ; trace-z = subst (λ k → Trace fa (i ∷ is) k ) (sym (equal→refl finq eq)) (tnext q tr) ; trace-yz = tnext q tr }
307
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
150 ... | false | record { eq = eq } = record { y = i ∷ TA1.y ta ; z = TA1.z ta ; yz=is = cong (i ∷_ ) (TA1.yz=is ta ) ; q=qd = eq
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
151 ; trace-z = TA1.trace-z ta ; trace-yz = tnext q ( TA1.trace-yz ta ) } where
302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 301
diff changeset
152 ta : TA1 fa finq (δ fa q i) qd is
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
153 ta = tra-phase2 (δ fa q i) is tr p
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
154 tra-phase1 : (q : Q) → (is : List Σ) → (tr : Trace fa is q ) → phase1 finq qd (tr→qs fa is q tr) ≡ true → TA fa q is
297
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 296
diff changeset
155 tra-phase1 q (i ∷ is) (tnext q tr) p with equal? finq qd q | inspect (equal? finq qd) q
298
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 297
diff changeset
156 | phase1 finq qd (tr→qs fa is (δ fa q i) tr) | inspect ( phase1 finq qd) (tr→qs fa is (δ fa q i) tr)
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
157 ... | true | record { eq = eq } | false | record { eq = np} = record { x = [] ; y = i ∷ TA1.y ta ; z = TA1.z ta ; xyz=is = cong (i ∷_ ) (TA1.yz=is ta)
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
158 ; non-nil-y = λ ()
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
159 ; trace-xyz = tnext q (TA1.trace-yz ta)
308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
160 ; trace-xyyz = tra-04 (i ∷ TA1.y ta) q (tnext q (subst (λ k → Trace fa (y1 ++ z1) (δ fa k i) ) (equal→refl finq eq) tryz0)) } where
302
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 301
diff changeset
161 ta : TA1 fa finq (δ fa q i ) qd is
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
162 ta = tra-phase2 (δ fa q i ) is tr p
308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
163 y1 = TA1.y ta
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
164 z1 = TA1.z ta
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
165 tryz0 : Trace fa (y1 ++ z1) (δ fa qd i)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
166 tryz0 = subst₂ (λ j k → Trace fa k (δ fa j i) ) (sym (equal→refl finq eq)) (sym (TA1.yz=is ta)) tr
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
167 tryz : Trace fa (i ∷ y1 ++ z1) qd
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
168 tryz = tnext qd tryz0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
169 tra-06 : equal? finq qd (δ fa q i) ≡ is0-bool (length y1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
170 tra-06 = TA1.q=qd ta
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
171 tra-05 : (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) q) → equal? finq qd q ≡ is0-bool (length y2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
172 tra-05 y2 q tr = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
173 tra-04 : (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) q)
306
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 305
diff changeset
174 → Trace fa (y2 ++ (i ∷ y1) ++ z1) q
308
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
175 tra-04 [] q tr with equal? finq qd q | inspect (equal? finq qd) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
176 ... | true | record { eq = eq } = subst (λ k → Trace fa (i ∷ y1 ++ z1) k) (equal→refl finq eq) tryz
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
177 ... | false | record { eq = ne } = ⊥-elim ( ¬-bool ne (tra-05 [] q tr) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
178 tra-04 (y0 ∷ y2) q (tnext q tr) with equal? finq qd q | inspect (equal? finq qd) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
179 ... | true | record { eq = eq } = ⊥-elim ( ¬-bool (tra-05 (y0 ∷ y2) q (tnext q tr)) eq ) where -- y2 + z1 contains two qd
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 307
diff changeset
180 ... | false | record { eq = ne } = tnext q (tra-04 y2 (δ fa q y0) tr )
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
181 ... | true | record { eq = eq } | true | record { eq = np} = record { x = i ∷ x ta ; y = y ta ; z = z ta ; xyz=is = cong (i ∷_ ) (xyz=is ta)
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
182 ; non-nil-y = non-nil-y ta
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
183 ; trace-xyz = tnext q (trace-xyz ta ) ; trace-xyyz = tnext q (trace-xyyz ta )} where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
184 ta : TA fa (δ fa q i ) is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
185 ta = tra-phase1 (δ fa q i ) is tr np
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
186 ... | false | _ | _ | _ = record { x = i ∷ x ta ; y = y ta ; z = z ta ; xyz=is = cong (i ∷_ ) (xyz=is ta)
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
187 ; non-nil-y = non-nil-y ta
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
188 ; trace-xyz = tnext q (trace-xyz ta ) ; trace-xyyz = tnext q (trace-xyyz ta )} where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
189 ta : TA fa (δ fa q i ) is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
190 ta = tra-phase1 (δ fa q i ) is tr p
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
191
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
192 open RegularLanguage
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
193 open import Data.Nat.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
194 open import nat
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
195
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
196 lemmaNN : (r : RegularLanguage In2 ) → ¬ ( (s : List In2) → isRegular inputnn1 s r )
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
197 lemmaNN r Rg = {!!} where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
198 n : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
199 n = suc (finite (afin r))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
200 nn = inputnn0 n i0 i1 []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
201 nn01 : (i : ℕ) → inputnn1 ( inputnn0 i i0 i1 [] ) ≡ true
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
202 nn01 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
203 nn01 (suc i) with nn01 i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
204 ... | t = {!!}
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
205 nn03 : accept (automaton r) (astart r) nn ≡ true
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
206 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n)
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
207 nn09 : (n m : ℕ) → n ≤ n + m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
208 nn09 zero m = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
209 nn09 (suc n) m = s≤s (nn09 n m)
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
210 nn04 : Trace (automaton r) nn (astart r)
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
211 nn04 = tr-accept← (automaton r) nn (astart r) nn03
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
212 nntrace = trace (automaton r) (astart r) nn
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
213 nn07 : (n : ℕ) → length (inputnn0 n i0 i1 []) ≡ n + n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
214 nn07 n = subst (λ k → length (inputnn0 n i0 i1 []) ≡ k) (+-comm (n + n) _ ) (nn08 n [] )where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
215 nn08 : (n : ℕ) → (s : List In2) → length (inputnn0 n i0 i1 s) ≡ n + n + length s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
216 nn08 zero s = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
217 nn08 (suc n) s = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
218 length (inputnn0 (suc n) i0 i1 s) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
219 suc (length (inputnn0 n i0 i1 (i1 ∷ s))) ≡⟨ cong suc (nn08 n (i1 ∷ s)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
220 suc (n + n + suc (length s)) ≡⟨ +-assoc (suc n) n _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
221 suc n + (n + suc (length s)) ≡⟨ cong (λ k → suc n + k) (sym (+-assoc n _ _)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
222 suc n + ((n + 1) + length s) ≡⟨ cong (λ k → suc n + (k + length s)) (+-comm n _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
223 suc n + (suc n + length s) ≡⟨ sym (+-assoc (suc n) _ _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
224 suc n + suc n + length s ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
225 nn05 : length nntrace > finite (afin r)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
226 nn05 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
227 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
228 n + n ≡⟨ sym (nn07 n) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
229 length (inputnn0 n i0 i1 []) ≤⟨ refl-≤s ⟩
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
230 {!!} ≤⟨ {!!} ⟩
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
231 length nntrace ∎ where open ≤-Reasoning
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
232 nn06 : Dup-in-list ( afin r) nntrace
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
233 nn06 = dup-in-list>n (afin r) nntrace nn05
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
234 TAnn : TA (automaton r) (astart r) nn
305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
235 TAnn = make-TA (automaton r) {!!} (afin r) (astart r) {!!} nn {!!} {!!}
304
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
236 count : In2 → List In2 → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
237 count _ [] = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
238 count i0 (i0 ∷ s) = suc (count i0 s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
239 count i1 (i1 ∷ s) = suc (count i1 s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
240 count x (_ ∷ s) = count x s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
241 nn11 : {x : In2} → (s t : List In2) → count x (s ++ t) ≡ count x s + count x t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
242 nn11 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
243 nn10 : (s : List In2) → accept (automaton r) (astart r) s ≡ true → count i0 s ≡ count i1 s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
244 nn10 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
245 i1-i0? : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
246 i1-i0? [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
247 i1-i0? (i1 ∷ []) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
248 i1-i0? (i0 ∷ []) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
249 i1-i0? (i1 ∷ i0 ∷ s) = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
250 i1-i0? (_ ∷ s0 ∷ s1) = i1-i0? (s0 ∷ s1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
251 nn20 : {s s0 s1 : List In2} → accept (automaton r) (astart r) s ≡ true → ¬ ( s ≡ s0 ++ i1 ∷ i0 ∷ s1 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
252 nn20 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
253 mono-color : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
254 mono-color [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
255 mono-color (i0 ∷ s) = mono-color0 s where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
256 mono-color0 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
257 mono-color0 [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
258 mono-color0 (i1 ∷ s) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
259 mono-color0 (i0 ∷ s) = mono-color0 s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
260 mono-color (i1 ∷ s) = mono-color1 s where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
261 mono-color1 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
262 mono-color1 [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
263 mono-color1 (i0 ∷ s) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
264 mono-color1 (i1 ∷ s) = mono-color1 s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
265 record Is10 (s : List In2) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
266 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
267 s0 s1 : List In2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
268 is-10 : s ≡ s0 ++ i1 ∷ i0 ∷ s1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
269 not-mono : { s : List In2 } → ¬ (mono-color s ≡ true) → Is10 (s ++ s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
270 not-mono = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
271 mono-count : { s : List In2 } → mono-color s ≡ true → (length s ≡ count i0 s) ∨ ( length s ≡ count i1 s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
272 mono-count = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
273 tann : {x y z : List In2} → ¬ y ≡ [] → accept (automaton r) (astart r) (x ++ y ++ z) ≡ true → ¬ (accept (automaton r) (astart r) (x ++ y ++ y ++ z) ≡ true )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
274 tann {x} {y} {z} ny axyz axyyz with mono-color y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
275 ... | true = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
276 ... | false = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 303
diff changeset
277