annotate agda/regular-language.agda @ 101:37a38f1d8d0d

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 12 Nov 2019 18:54:44 +0900
parents 0b1b9a28a707
children 137d39e3dc7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module regular-language 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 renaming ( suc to Suc ; zero to Zero )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.List
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Nat hiding ( _≟_ )
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
6 open import Data.Fin hiding ( _+_ )
72
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
7 open import Data.Empty
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
8 open import Data.Unit
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Product
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 -- open import Data.Maybe
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 Relation.Binary.PropositionalEquality hiding ( [_] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import logic
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
14 open import nat
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open import automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 open import finiteSet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 language : { Σ : Set } → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 language {Σ} = List Σ → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 language-L : { Σ : Set } → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 language-L {Σ} = List (List Σ)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 open Automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 record RegularLanguage ( Σ : Set ) : Set (Suc Zero) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 states : Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 astart : states
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
30 aℕ : ℕ
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
31 afin : FiniteSet states {aℕ}
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 automaton : Automaton states Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 contain : List Σ → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 contain x = accept automaton astart x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 Union : {Σ : Set} → ( A B : language {Σ} ) → language {Σ}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 Union {Σ} A B x = (A x ) \/ (B x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 split : {Σ : Set} → (List Σ → Bool)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 → ( List Σ → Bool) → List Σ → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 split x y [] = x [] /\ y []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 split x y (h ∷ t) = (x [] /\ y (h ∷ t)) \/
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 split (λ t1 → x ( h ∷ t1 )) (λ t2 → y t2 ) t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Concat : {Σ : Set} → ( A B : language {Σ} ) → language {Σ}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 Concat {Σ} A B = split A B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 {-# TERMINATING #-}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 Star : {Σ : Set} → ( A : language {Σ} ) → language {Σ}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 Star {Σ} A = split A ( Star {Σ} A )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
52 test-AB→split : {Σ : Set} → {A B : List In2 → Bool} → split A B ( i0 ∷ i1 ∷ i0 ∷ [] ) ≡ (
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
53 ( A [] /\ B ( i0 ∷ i1 ∷ i0 ∷ [] ) ) \/
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
54 ( A ( i0 ∷ [] ) /\ B ( i1 ∷ i0 ∷ [] ) ) \/
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
55 ( A ( i0 ∷ i1 ∷ [] ) /\ B ( i0 ∷ [] ) ) \/
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
56 ( A ( i0 ∷ i1 ∷ i0 ∷ [] ) /\ B [] )
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
57 )
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
58 test-AB→split {_} {A} {B} = refl
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
59
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 open RegularLanguage
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 isRegular : {Σ : Set} → (A : language {Σ} ) → ( x : List Σ ) → (r : RegularLanguage Σ ) → Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 isRegular A x r = A x ≡ contain r x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
73
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
64 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
65 fin-× : {A B : Set} → { a b : ℕ } → FiniteSet A {a} → FiniteSet B {b} → FiniteSet (A × B) {a * b}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
66
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 M-Union : {Σ : Set} → (A B : RegularLanguage Σ ) → RegularLanguage Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 M-Union {Σ} A B = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 states = states A × states B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 ; astart = ( astart A , astart B )
73
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
71 ; aℕ = aℕ A * aℕ B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
72 ; afin = fin-× (afin A) (afin B)
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ; automaton = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 δ = λ q x → ( δ (automaton A) (proj₁ q) x , δ (automaton B) (proj₂ q) x )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 ; aend = λ q → ( aend (automaton A) (proj₁ q) \/ aend (automaton B) (proj₂ q) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 closed-in-union : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Union (contain A) (contain B)) x ( M-Union A B )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 closed-in-union A B [] = lemma where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 lemma : aend (automaton A) (astart A) \/ aend (automaton B) (astart B) ≡
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 aend (automaton A) (astart A) \/ aend (automaton B) (astart B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 lemma = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 closed-in-union {Σ} A B ( h ∷ t ) = lemma1 t ((δ (automaton A) (astart A) h)) ((δ (automaton B) (astart B) h)) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 lemma1 : (t : List Σ) → (qa : states A ) → (qb : states B ) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 accept (automaton A) qa t \/ accept (automaton B) qb t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 ≡ accept (automaton (M-Union A B)) (qa , qb) t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 lemma1 [] qa qb = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 lemma1 (h ∷ t ) qa qb = lemma1 t ((δ (automaton A) qa h)) ((δ (automaton B) qb h))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 -- M-Concat : {Σ : Set} → (A B : RegularLanguage Σ ) → RegularLanguage Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 -- M-Concat {Σ} A B = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 -- states = states A ∨ states B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 -- ; astart = case1 (astart A )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 -- ; automaton = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 -- δ = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 -- ; aend = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 -- }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 -- }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 -- closed-in-concat : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Concat (contain A) (contain B)) x ( M-Concat A B )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 -- closed-in-concat = {!!}
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
103
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
104 open import nfa
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
105 open import sbconst2
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
106 open FiniteSet
86
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 76
diff changeset
107 open import Data.Nat.Properties hiding ( _≟_ )
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
108 open import Relation.Binary as B hiding (Decidable)
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
109
73
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
110 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
111 fin-∨ : {A B : Set} → { a b : ℕ } → FiniteSet A {a} → FiniteSet B {b} → FiniteSet (A ∨ B) {a + b}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
112 fin→ : {A : Set} → { a : ℕ } → FiniteSet A {a} → FiniteSet (A → Bool ) {exp 2 a}
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
113
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
114 Concat-NFA : {Σ : Set} → (A B : RegularLanguage Σ ) → NAutomaton (states A ∨ states B) Σ
86
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 76
diff changeset
115 Concat-NFA {Σ} A B = record { Nδ = δnfa ; Nend = nend }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 76
diff changeset
116 module Concat-NFA where
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
117 δnfa : states A ∨ states B → Σ → states A ∨ states B → Bool
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
118 δnfa (case1 q) i (case1 q₁) = equal? (afin A) (δ (automaton A) q i) q₁
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
119 δnfa (case1 qa) i (case2 qb) = (aend (automaton A) qa ) /\
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
120 (equal? (afin B) qb (δ (automaton B) (astart B) i) )
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
121 δnfa (case2 q) i (case2 q₁) = equal? (afin B) (δ (automaton B) q i) q₁
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
122 δnfa _ i _ = false
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
123 nend : states A ∨ states B → Bool
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
124 nend (case2 q) = aend (automaton B) q
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
125 nend (case1 q) = aend (automaton A) q /\ aend (automaton B) (astart B) -- empty B case
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
126
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
127 Concat-NFA-start : {Σ : Set} → (A B : RegularLanguage Σ ) → states A ∨ states B → Bool
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
128 Concat-NFA-start A B q = equal? (fin-∨ (afin A) (afin B)) (case1 (astart A)) q
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
129
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
130 M-Concat : {Σ : Set} → (A B : RegularLanguage Σ ) → RegularLanguage Σ
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
131 M-Concat {Σ} A B = record {
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
132 states = states A ∨ states B → Bool
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
133 ; astart = Concat-NFA-start A B
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
134 ; aℕ = finℕ finf
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
135 ; afin = finf
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
136 ; automaton = subset-construction fin (Concat-NFA A B) (case1 (astart A))
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
137 } where
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
138 fin : FiniteSet (states A ∨ states B ) {aℕ A + aℕ B}
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
139 fin = fin-∨ (afin A) (afin B)
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
140 finf : FiniteSet (states A ∨ states B → Bool )
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
141 finf = fin→ fin
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
142
72
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
143 record Split {Σ : Set} (A : List Σ → Bool ) ( B : List Σ → Bool ) (x : List Σ ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
144 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
145 sp0 : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
146 sp1 : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
147 sp-concat : sp0 ++ sp1 ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
148 prop0 : A sp0 ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
149 prop1 : B sp1 ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
150
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
151 open Split
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
152
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
153 list-empty++ : {Σ : Set} → (x y : List Σ) → x ++ y ≡ [] → (x ≡ [] ) ∧ (y ≡ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
154 list-empty++ [] [] refl = record { proj1 = refl ; proj2 = refl }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
155 list-empty++ [] (x ∷ y) ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
156 list-empty++ (x ∷ x₁) y ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
157
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
158 open _∧_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 71
diff changeset
159
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
160 open import Relation.Binary.PropositionalEquality hiding ( [_] )
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
161
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
162 c-split-lemma : {Σ : Set} → (A B : List Σ → Bool ) → (h : Σ) → ( t : List Σ ) → split A B (h ∷ t ) ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
163 → ( ¬ (A [] ≡ true )) ∨ ( ¬ (B ( h ∷ t ) ≡ true) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
164 → split (λ t1 → A (h ∷ t1)) B t ≡ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
165 c-split-lemma {Σ} A B h t eq (case1 ¬p ) = sym ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
166 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
167 ≡⟨ sym eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
168 split A B (h ∷ t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
169 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
170 A [] /\ B (h ∷ t) \/ split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
171 ≡⟨ cong ( λ k → k \/ split (λ t1 → A (h ∷ t1)) B t ) (bool-and-1 (¬-bool-t ¬p)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
172 false \/ split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
173 ≡⟨ bool-or-1 refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
174 split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
175 ∎ ) where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
176 c-split-lemma {Σ} A B h t eq (case2 ¬p ) = sym ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
177 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
178 ≡⟨ sym eq ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
179 split A B (h ∷ t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
180 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
181 A [] /\ B (h ∷ t) \/ split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
182 ≡⟨ cong ( λ k → k \/ split (λ t1 → A (h ∷ t1)) B t ) (bool-and-2 (¬-bool-t ¬p)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
183 false \/ split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
184 ≡⟨ bool-or-1 refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
185 split (λ t1 → A (h ∷ t1)) B t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
186 ∎ ) where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
187
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
188 split→AB : {Σ : Set} → (A B : List Σ → Bool ) → ( x : List Σ ) → split A B x ≡ true → Split A B x
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
189 split→AB {Σ} A B [] eq with bool-≡-? (A []) true | bool-≡-? (B []) true
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
190 split→AB {Σ} A B [] eq | yes eqa | yes eqb =
73
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 72
diff changeset
191 record { sp0 = [] ; sp1 = [] ; sp-concat = refl ; prop0 = eqa ; prop1 = eqb }
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
192 split→AB {Σ} A B [] eq | yes p | no ¬p = ⊥-elim (lemma-∧-1 eq (¬-bool-t ¬p ))
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
193 split→AB {Σ} A B [] eq | no ¬p | t = ⊥-elim (lemma-∧-0 eq (¬-bool-t ¬p ))
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
194 split→AB {Σ} A B (h ∷ t ) eq with bool-≡-? (A []) true | bool-≡-? (B (h ∷ t )) true
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
195 ... | yes px | yes py = record { sp0 = [] ; sp1 = h ∷ t ; sp-concat = refl ; prop0 = px ; prop1 = py }
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
196 ... | no px | _ with split→AB (λ t1 → A ( h ∷ t1 )) B t (c-split-lemma A B h t eq (case1 px) )
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
197 ... | S = record { sp0 = h ∷ sp0 S ; sp1 = sp1 S ; sp-concat = cong ( λ k → h ∷ k) (sp-concat S) ; prop0 = prop0 S ; prop1 = prop1 S }
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
198 split→AB {Σ} A B (h ∷ t ) eq | _ | no px with split→AB (λ t1 → A ( h ∷ t1 )) B t (c-split-lemma A B h t eq (case2 px) )
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
199 ... | S = record { sp0 = h ∷ sp0 S ; sp1 = sp1 S ; sp-concat = cong ( λ k → h ∷ k) (sp-concat S) ; prop0 = prop0 S ; prop1 = prop1 S }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
200
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
201 AB→split : {Σ : Set} → (A B : List Σ → Bool ) → ( x y : List Σ ) → A x ≡ true → B y ≡ true → split A B (x ++ y ) ≡ true
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
202 AB→split {Σ} A B [] [] eqa eqb = begin
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
203 split A B []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
204 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
205 A [] /\ B []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
206 ≡⟨ cong₂ (λ j k → j /\ k ) eqa eqb ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
207 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
208 ∎ where open ≡-Reasoning
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
209 AB→split {Σ} A B [] (h ∷ y ) eqa eqb = begin
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
210 split A B (h ∷ y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
211 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
212 A [] /\ B (h ∷ y) \/ split (λ t1 → A (h ∷ t1)) B y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
213 ≡⟨ cong₂ (λ j k → j /\ k \/ split (λ t1 → A (h ∷ t1)) B y ) eqa eqb ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
214 true /\ true \/ split (λ t1 → A (h ∷ t1)) B y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
215 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
216 true \/ split (λ t1 → A (h ∷ t1)) B y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
217 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
218 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
219 ∎ where open ≡-Reasoning
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
220 AB→split {Σ} A B (h ∷ t) y eqa eqb = begin
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
221 split A B ((h ∷ t) ++ y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
222 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
223 A [] /\ B (h ∷ t ++ y) \/ split (λ t1 → A (h ∷ t1)) B (t ++ y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
224 ≡⟨ cong ( λ k → A [] /\ B (h ∷ t ++ y) \/ k ) ( begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
225 split (λ t1 → A (h ∷ t1)) B (t ++ y)
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
226 ≡⟨ AB→split {Σ} (λ t1 → A (h ∷ t1)) B t y eqa eqb ⟩
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
227 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
228 ∎ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
229 A [] /\ B (h ∷ t ++ y) \/ true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
230 ≡⟨ bool-or-3 ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
231 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
232 ∎ where open ≡-Reasoning
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 73
diff changeset
233
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
234 open NAutomaton
89
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
235 open import Data.List.Properties
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
236
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
237 closed-in-concat : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Concat (contain A) (contain B)) x ( M-Concat A B )
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
238 closed-in-concat {Σ} A B x = ≡-Bool-func closed-in-concat→ closed-in-concat← where
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
239 finab = (fin-∨ (afin A) (afin B))
76
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 75
diff changeset
240 NFA = (Concat-NFA A B)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 75
diff changeset
241 abmove : (q : states A ∨ states B) → (h : Σ ) → states A ∨ states B
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 75
diff changeset
242 abmove (case1 q) h = case1 (δ (automaton A) q h)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 75
diff changeset
243 abmove (case2 q) h = case2 (δ (automaton B) q h)
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
244 lemma-nmove-ab : (q : states A ∨ states B) → (h : Σ ) → Nδ NFA q h (abmove q h) ≡ true
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
245 lemma-nmove-ab (case1 q) _ = equal?-refl (afin A)
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
246 lemma-nmove-ab (case2 q) _ = equal?-refl (afin B)
76
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 75
diff changeset
247 nmove : (q : states A ∨ states B) (nq : states A ∨ states B → Bool ) → (nq q ≡ true) → ( h : Σ ) →
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
248 exists finab (λ qn → nq qn /\ Nδ NFA qn h (abmove q h)) ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
249 nmove (case1 q) nq nqt h = found finab (case1 q) ( bool-and-tt nqt (lemma-nmove-ab (case1 q) h) )
100
0b1b9a28a707 roll back
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
250 nmove (case2 q) nq nqt h = found finab (case2 q) ( bool-and-tt nqt (lemma-nmove-ab (case2 q) h) )
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
251 acceptB : (z : List Σ) → (q : states B) → (nq : states A ∨ states B → Bool ) → (nq (case2 q) ≡ true) → ( accept (automaton B) q z ≡ true )
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
252 → Naccept NFA finab nq z ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
253 acceptB [] q nq nqt fb = lemma8 where
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
254 lemma8 : exists finab ( λ q → nq q /\ Nend NFA q ) ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
255 lemma8 = found finab (case2 q) ( bool-and-tt nqt fb )
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
256 acceptB (h ∷ t ) q nq nq=q fb = acceptB t (δ (automaton B) q h) (Nmoves NFA finab nq h) (nmove (case2 q) nq nq=q h) fb
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
257 acceptA : (y z : List Σ) → (q : states A) → (nq : states A ∨ states B → Bool ) → (nq (case1 q) ≡ true)
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
258 → ( accept (automaton A) q y ≡ true ) → ( accept (automaton B) (astart B) z ≡ true )
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
259 → Naccept NFA finab nq (y ++ z) ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
260 acceptA [] [] q nq nqt fa fb = found finab (case1 q) (bool-and-tt nqt (bool-and-tt fa fb ))
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
261 acceptA [] (h ∷ z) q nq nq=q fa fb = acceptB z nextb (Nmoves NFA finab nq h) lemma70 fb where
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
262 nextb : states B
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
263 nextb = δ (automaton B) (astart B) h
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
264 lemma70 : exists finab (λ qn → nq qn /\ Nδ NFA qn h (case2 nextb)) ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
265 lemma70 = found finab (case1 q) ( bool-and-tt nq=q (bool-and-tt fa (lemma-nmove-ab (case2 (astart B)) h) ))
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
266 acceptA (h ∷ t) z q nq nq=q fa fb = acceptA t z (δ (automaton A) q h) (Nmoves NFA finab nq h) (nmove (case1 q) nq nq=q h) fa fb where
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
267 acceptAB : Split (contain A) (contain B) x
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
268 → Naccept NFA finab (equal? finab (case1 (astart A))) x ≡ true
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
269 acceptAB S = subst ( λ k → Naccept NFA finab (equal? finab (case1 (astart A))) k ≡ true ) ( sp-concat S )
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
270 (acceptA (sp0 S) (sp1 S) (astart A) (equal? finab (case1 (astart A))) (equal?-refl finab) (prop0 S) (prop1 S) )
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
271
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
272 closed-in-concat→ : Concat (contain A) (contain B) x ≡ true → contain (M-Concat A B) x ≡ true
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
273 closed-in-concat→ concat with split→AB (contain A) (contain B) x concat
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
274 ... | S = begin
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
275 accept (subset-construction finab NFA (case1 (astart A))) (Concat-NFA-start A B ) x
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
276 ≡⟨ ≡-Bool-func (subset-construction-lemma← finab NFA (case1 (astart A)) x )
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
277 (subset-construction-lemma→ finab NFA (case1 (astart A)) x ) ⟩
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
278 Naccept NFA finab (equal? finab (case1 (astart A))) x
88
e7b3a2856ccb clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
279 ≡⟨ acceptAB S ⟩
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
280 true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
281 ∎ where open ≡-Reasoning
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
282
92
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
283 open Found
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
284
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
285 data AB-state (nq : states A ∨ states B → Bool ) (qa : states A) (x : List Σ) : Set (Level.suc Level.zero) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
286 state-A : ((q : states A ∨ states B ) → nq q ≡ true → q ≡ case1 qa ) → AB-state nq qa x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
287 state-AB : ((q : states A ∨ states B ) → ( nq q ≡ true ) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
288 ( (q ≡ case1 qa) ∨ ({qb : states B} → nq (case2 qb) ≡ true → ( accept (automaton B) qb x ≡ false ) ))) → AB-state nq qa x
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
289
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
290 open AB-state
100
0b1b9a28a707 roll back
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
291 contain-A : (x : List Σ) → (nq : states A ∨ states B → Bool ) → (fn : Naccept NFA finab nq x ≡ true )
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
292 → (qa : states A ) → AB-state nq qa x
94
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 93
diff changeset
293 → split (accept (automaton A) qa ) (contain B) x ≡ true
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
294 contain-A [] nq fn qa cond with found← finab fn | found-q (found← finab fn) | cond | inspect found-q (found← finab fn)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
295 contain-A [] nq fn qa cond | S | s | state-A nq=t | record { eq = refl } with nq=t (found-q S) (bool-∧→tt-0 (found-p S))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
296 ... | refl = bool-∧→tt-1 (found-p S)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
297 contain-A [] nq fn qa cond | S | s | state-AB cond-b | _ with cond-b (found-q S) (bool-∧→tt-0 (found-p S))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
298 contain-A [] nq fn qa cond | S | s | state-AB cond-b | _ | case1 refl = bool-∧→tt-1 (found-p S)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
299 contain-A [] nq fn qa cond | S | case2 qb | state-AB cond-b | record { eq = refl } | case2 accept-B = ⊥-elim ( lemma11 accept-B ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
300 lemma11 : ( nq (case2 qb ) ≡ true → aend (automaton B) qb ≡ false ) → ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
301 lemma11 accept-B = ¬-bool ( accept-B (bool-∧→tt-0 (found-p S))) (bool-∧→tt-1 (found-p S ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 100
diff changeset
302 contain-A [] nq fn qa cond | S | case1 qa' | state-AB cond-b | record { eq = refl } | case2 accept-B = {!!}
100
0b1b9a28a707 roll back
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
303 contain-A (h ∷ t) nq fn qa cond with bool-≡-? ((aend (automaton A) qa) /\ accept (automaton B) (δ (automaton B) (astart B) h) t ) true
95
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 94
diff changeset
304 ... | yes eq = bool-or-41 eq
100
0b1b9a28a707 roll back
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
305 ... | no ne = bool-or-31 (contain-A t (Nmoves NFA finab nq h) fn (δ (automaton A) qa h) {!!} ) where
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
306
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
307 lemma10 : Naccept NFA finab (equal? finab (case1 (astart A))) x ≡ true → split (contain A) (contain B) x ≡ true
100
0b1b9a28a707 roll back
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
308 lemma10 CC = contain-A x (Concat-NFA-start A B ) CC (astart A) {!!} where
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
309
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
310 closed-in-concat← : contain (M-Concat A B) x ≡ true → Concat (contain A) (contain B) x ≡ true
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
311 closed-in-concat← C with subset-construction-lemma← finab NFA (case1 (astart A)) x C
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
312 ... | CC = lemma10 CC
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
313
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
314
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
315
87
217ef727574a reverse direction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
316