annotate automaton-in-agda/src/non-regular.agda @ 301:30033f273f1d

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 31 Dec 2021 23:06:08 +0900
parents 67d8e42b7782
children 55f8031e4214
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
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
16 open FiniteSet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
18 inputnn : List In2 → Maybe (List In2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
19 inputnn [] = just []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
20 inputnn (i1 ∷ t) = just (i1 ∷ t)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
21 inputnn (i0 ∷ t) with inputnn t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
22 ... | nothing = nothing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
23 ... | just [] = nothing
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
24 ... | just (i0 ∷ t1) = nothing -- can't happen
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
25 ... | just (i1 ∷ t1) = just t1 -- remove i1 from later part
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
26
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
27 inputnn1 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
28 inputnn1 s with inputnn s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
29 ... | nothing = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
30 ... | just [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
31 ... | just _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
32
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
33 t1 = inputnn1 ( i0 ∷ i1 ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
34 t2 = inputnn1 ( i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] )
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
35 t3 = inputnn1 ( i0 ∷ i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] )
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
36
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
37 inputnn0 : ( n : ℕ ) → { Σ : Set } → ( x y : Σ ) → List Σ → List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
38 inputnn0 zero {_} _ _ s = s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
39 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
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
41 t4 : inputnn1 ( inputnn0 5 i0 i1 [] ) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
42 t4 = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
43
291
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
44 t5 : ( n : ℕ ) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
45 t5 n = inputnn1 ( inputnn0 n i0 i1 [] ) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
46
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
47 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
48 -- 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
49 -- The function is determinted by inputs,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
50 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
52 open RegularLanguage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
53 open Automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
55 open _∧_
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
57 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
58 tend : {q : Q} → aend fa q ≡ true → Trace fa [] q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
59 tnext : (q : Q) → {i : Σ} { is : List Σ}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
60 → 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
61
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
62 tr-len : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
63 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
64 → (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
65 tr-len {Q} {Σ} fa .[] q (tend x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
66 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
67
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
68 tr-accept→ : { Q : Set } { Σ : Set }
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
69 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
70 → (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
71 tr-accept→ {Q} {Σ} fa [] q (tend x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
72 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
73
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
74 tr-accept← : { Q : Set } { Σ : Set }
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
75 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
76 → (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
77 tr-accept← {Q} {Σ} fa [] q ac = tend ac
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
78 tr-accept← {Q} {Σ} fa (x ∷ []) q ac = tnext _ (tend ac )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
79 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
80
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
81 tr→qs : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
82 → (fa : Automaton Q Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
83 → (is : List Σ) → (q : Q) → Trace fa is q → List Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
84 tr→qs fa [] q (tend x) = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
85 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
86
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
87 tr→qs=is : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
88 → (fa : Automaton Q Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
89 → (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
90 tr→qs=is fa .[] q (tend x) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
91 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
92
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
93 open Data.Maybe
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
94
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
95 -- head : {a : Set} → List a → Maybe a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
96 -- head [] = nothing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
97 -- head (h ∷ _ ) = just h
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
98
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
99 tr-append1 : { Q : Set } { Σ : Set }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
100 → (fa : Automaton Q Σ )
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
101 → (i : Σ) → ( q : Q)
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
102 → (is : List Σ)
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
103 → Trace fa is ( δ fa q i ) → Trace fa (i ∷ is) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
104 tr-append1 fa i q is tr = tnext _ tr
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
105
279
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
106 open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
107
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
108 record TA1 { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) ( q qd : Q ) (is : List Σ) : Set where
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
109 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
110 y z : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
111 yz=is : y ++ z ≡ is
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
112 trace-z : Trace fa z qd
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
113 trace-yz : Trace fa (y ++ z) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
114
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
115 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
116 field
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
117 x y z : List Σ
298
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 297
diff changeset
118 xyz=is : x ++ y ++ z ≡ is
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
119 trace-xyz : Trace fa (x ++ y ++ z) q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
120 trace-xyyz : Trace fa (x ++ y ++ y ++ z) q
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
121
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
122 open import nat
277
42563cc6afdf non-regular
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 274
diff changeset
123
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
124 make-TA : { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) (q qd : Q) (is : List Σ)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
125 → (tr : Trace fa is q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
126 → 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
127 → TA fa q is
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
128 make-TA {Q} {Σ} fa 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
129 open TA
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
130 tra-phase2 : (q : Q) → (is : List Σ) → (tr : Trace fa is q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
131 → phase2 finq qd (tr→qs fa is q tr) ≡ true → TA1 fa q qd is
297
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 296
diff changeset
132 tra-phase2 q (i ∷ is) (tnext q tr) p with equal? finq qd q | inspect ( equal? finq qd) q
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
133 ... | true | record { eq = eq } = record { y = [] ; z = i ∷ is ; yz=is = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
134 ; trace-z = subst (λ k → Trace fa (i ∷ is) k ) (sym (equal→refl finq eq)) (tnext q tr) ; trace-yz = tnext q tr }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
135 ... | false | record { eq = eq } = record { y = i ∷ TA1.y ta ; z = TA1.z ta ; yz=is = cong (i ∷_ ) (TA1.yz=is ta )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
136 ; trace-z = TA1.trace-z ta ; trace-yz = tnext q ( TA1.trace-yz ta ) } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
137 ta : TA1 fa (δ fa q i) qd is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
138 ta = tra-phase2 (δ fa q i) is tr p
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
139 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
140 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
141 | 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
142 ... | 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)
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
143 ; trace-xyz = tnext q (TA1.trace-yz ta)
301
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 300
diff changeset
144 ; trace-xyyz = tnext q ( tra-02 (TA1.y ta) (δ fa q i) (sym (equal→refl finq eq)) {!!} {!!} {!!} ) } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 300
diff changeset
145 -- Trace fa ([] ++ (i ∷ TA1.y ta) ++ (i ∷ TA1.y ta) ++ TA1.z ta) q
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
146 -- tra-02 (i ∷ TA1.y ta) q (sym (equal→refl finq eq)) (tnext q (TA1.trace-yz ta)) {!!} {!!} } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
147 ta : TA1 fa (δ fa q i ) qd is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
148 ta = tra-phase2 (δ fa q i ) is tr p
301
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 300
diff changeset
149 tra-02 : (y1 : List Σ) → (q0 : Q) → q ≡ qd → (tr : Trace fa (y1 ++ TA1.z ta) q0)
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
150 → phase2 finq qd (tr→qs fa (y1 ++ TA1.z ta) q0 tr) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
151 → phase1 finq qd (tr→qs fa (y1 ++ TA1.z ta) q0 tr) ≡ false
301
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 300
diff changeset
152 → Trace fa (y1 ++ i ∷ TA1.y ta ++ TA1.z ta) q0
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
153 tra-02 [] q0 q=qd tr p np with equal? finq qd q0 | inspect ( equal? finq qd) q0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
154 ... | true | record { eq = eq } = subst (λ k → Trace fa (i ∷ TA1.y ta ++ TA1.z ta) k ) {!!} (tnext q (TA1.trace-yz ta) ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
155 tra-03 : q ≡ q0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
156 tra-03 = trans q=qd ((equal→refl finq eq) )
298
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 297
diff changeset
157 ... | false | record { eq = ne } = {!!}
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
158 tra-02 (y1 ∷ ys) q0 q=qd (tnext q tr) p np with equal? finq qd q | inspect ( equal? finq qd) q
298
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 297
diff changeset
159 ... | true | record { eq = eq } = {!!}
300
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 299
diff changeset
160 ... | false | record { eq = ne } = {!!} -- tnext q (tra-02 ys (δ fa q y1) q=qd tr p np )
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
161 ... | 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)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
162 ; 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
163 ta : TA fa (δ fa q i ) is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
164 ta = tra-phase1 (δ fa q i ) is tr np
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
165 ... | false | _ | _ | _ = record { x = i ∷ x ta ; y = y ta ; z = z ta ; xyz=is = cong (i ∷_ ) (xyz=is ta)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
166 ; 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
167 ta : TA fa (δ fa q i ) is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 298
diff changeset
168 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
169
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
170 open RegularLanguage
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
171 open import Data.Nat.Properties
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
172 open import nat
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
173
274
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
174 lemmaNN : (r : RegularLanguage In2 ) → ¬ ( (s : List In2) → isRegular inputnn1 s r )
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
175 lemmaNN r Rg = {!!} where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
176 n : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
177 n = suc (finite (afin r))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
178 nn = inputnn0 n i0 i1 []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
179 nn01 : (i : ℕ) → inputnn1 ( inputnn0 i i0 i1 [] ) ≡ true
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
180 nn01 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
181 nn01 (suc i) with nn01 i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
182 ... | t = {!!}
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
183 nn03 : accept (automaton r) (astart r) nn ≡ true
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
184 nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
185 count : In2 → List In2 → ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
186 count _ [] = 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
187 count i0 (i0 ∷ s) = suc (count i0 s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
188 count i1 (i1 ∷ s) = suc (count i1 s)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
189 count x (_ ∷ s) = count x s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
190 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: 291
diff changeset
191 nn10 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
192 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: 291
diff changeset
193 nn11 = {!!}
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
194 nntrace = trace (automaton r) (astart r) nn
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
195 nn04 : Trace (automaton r) nn (astart r)
280
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 279
diff changeset
196 nn04 = tr-accept← (automaton r) nn (astart r) nn03
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
197 nn07 : (n : ℕ) → length (inputnn0 n i0 i1 []) ≡ n + n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
198 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
199 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
200 nn08 zero s = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
201 nn08 (suc n) s = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
202 length (inputnn0 (suc n) i0 i1 s) ≡⟨ refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
203 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
204 suc (n + n + suc (length s)) ≡⟨ +-assoc (suc n) n _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
205 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
206 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
207 suc n + (suc n + length s) ≡⟨ sym (+-assoc (suc n) _ _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
208 suc n + suc n + length s ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
209 nn09 : (n m : ℕ) → n ≤ n + m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
210 nn09 zero m = z≤n
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
211 nn09 (suc n) m = s≤s (nn09 n m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
212 nn05 : length nntrace > finite (afin r)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
213 nn05 = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
214 suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
215 n + n ≡⟨ sym (nn07 n) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
216 length (inputnn0 n i0 i1 []) ≤⟨ refl-≤s ⟩
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
217 {!!} ≤⟨ {!!} ⟩
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
218 length nntrace ∎ where open ≤-Reasoning
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 295
diff changeset
219 nn02 : {!!} -- TA (automaton r) {!!} {!!} {!!}
295
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 294
diff changeset
220 nn02 = {!!} where -- make-TA (automaton r) (afin r) (Dup-in-list.dup nn06) _ _ (Dup-in-list.is-dup nn06) ? where
294
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
221 nn06 : Dup-in-list ( afin r) nntrace
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
222 nn06 = dup-in-list>n (afin r) nntrace nn05
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
223 nn12 : (x y z : List In2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
224 → ¬ y ≡ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
225 → 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: 291
diff changeset
226 nn12 x y z p q = {!!} where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
227 mono-color : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
228 mono-color [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
229 mono-color (i0 ∷ s) = mono-color0 s where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
230 mono-color0 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
231 mono-color0 [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
232 mono-color0 (i1 ∷ s) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
233 mono-color0 (i0 ∷ s) = mono-color0 s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
234 mono-color (i1 ∷ s) = mono-color1 s where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
235 mono-color1 : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
236 mono-color1 [] = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
237 mono-color1 (i0 ∷ s) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
238 mono-color1 (i1 ∷ s) = mono-color1 s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
239 mono-color (i1 ∷ s) = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
240 i1-i0? : List In2 → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
241 i1-i0? [] = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
242 i1-i0? (i1 ∷ []) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
243 i1-i0? (i0 ∷ []) = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
244 i1-i0? (i1 ∷ i0 ∷ s) = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
245 i1-i0? (_ ∷ s0 ∷ s1) = i1-i0? (s0 ∷ s1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
246 nn13 : mono-color y ≡ true → count i0 (x ++ y ++ z) ≡ count i1 (x ++ y ++ z) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
247 ¬ ( count i0 (x ++ y ++ y ++ z) ≡ count i1 (x ++ y ++ y ++ z) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
248 nn13 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
249 nn16 : (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: 291
diff changeset
250 nn16 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
251 nn15 : (s : List In2 ) → i1-i0? s ≡ true → accept (automaton r) (astart r) s ≡ false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
252 nn15 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
253 nn14 : mono-color y ≡ false → i1-i0? (x ++ y ++ y ++ z) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
254 nn14 = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
255 nn17 : 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: 291
diff changeset
256 nn17 p q with mono-color y | inspect mono-color y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
257 ... | true | record { eq = eq } = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
258 ... | false | record { eq = eq } = {!!} -- q ( nn15 (x ++ y ++ z) (nn14 eq))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 291
diff changeset
259