annotate agda/regex1.agda @ 43:31e4bd173951

using Fin id
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 22 Dec 2018 03:08:21 +0900
parents ae69102153a9
children aa15eff1aeb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
1 module regex1 where
0
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to succ ; zero to Zero )
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
4 open import Data.Fin
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
5 open import Data.Nat hiding ( _≟_ )
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
6 open import Data.List hiding ( any )
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
7 import Data.Bool using ( Bool ; true ; false ; _∧_ )
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
8 open import Data.Bool using ( Bool ; true ; false ; _∧_ ; _∨_ )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
9 open import Relation.Binary.PropositionalEquality as RBF hiding ( [_] )
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10 open import Relation.Nullary using (¬_; Dec; yes; no)
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
11
0
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 data Regex ( Σ : Set ) : Set where
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 _* : Regex Σ → Regex Σ
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 _&_ : Regex Σ → Regex Σ → Regex Σ
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
16 _||_ : Regex Σ → Regex Σ → Regex Σ
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
17 <_> : Σ → Regex Σ
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
18
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
19 -- postulate a b c d : Set
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
20
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
21 data hoge : Set where
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
22 a : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
23 b : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
24 c : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
25 d : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
26
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
27 infixr 40 _&_ _||_
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
28
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
29 r1' = (< a > & < b >) & < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
30 r1 = < a > & < b > & < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
31 any = < a > || < b > || < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
32 r2 = ( any * ) & ( < a > & < b > & < c > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
33 r3 = ( any * ) & ( < a > & < b > & < c > & < a > & < b > & < c > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
34 r4 = ( < a > & < b > & < c > ) || ( < b > & < c > & < d > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
35 r5 = ( any * ) & ( < a > & < b > & < c > || < b > & < c > & < d > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
36
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
37 open import nfa
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
38
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
39 split : {Σ : Set} → (List Σ → Bool)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
40 → ( List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
41 split x y [] = x [] ∧ y []
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
42 split x y (h ∷ t) = (x [] ∧ y (h ∷ t)) ∨
41
ae69102153a9 cfg done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
43 split (λ t1 → x ( h ∷ t1 )) (λ t2 → y t2 ) t
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
44
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
45 {-# TERMINATING #-}
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
46 repeat : {Σ : Set} → (List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
47 repeat x [] = true
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
48 repeat {Σ} x ( h ∷ t ) = split x (repeat {Σ} x) ( h ∷ t )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
49
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
50 open FiniteSet
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
51
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
52 cmpi : {Σ : Set} → {n : ℕ } (fin : FiniteSet Σ {n}) → (x y : Σ ) → Dec (F←Q fin x ≡ F←Q fin y)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
53 cmpi fin x y = F←Q fin x ≟ F←Q fin y
4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
54
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
55 regular-language : {Σ : Set} → Regex Σ → {n : ℕ } (fin : FiniteSet Σ {n}) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
56 regular-language (x *) f = repeat ( regular-language x f )
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
57 regular-language (x & y) f = split ( regular-language x f ) ( regular-language y f )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
58 regular-language (x || y) f = λ s → ( regular-language x f s ) ∨ ( regular-language y f s)
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
59 regular-language < h > f [] = false
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
60 regular-language < h > f (h1 ∷ [] ) with cmpi f h h1
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
61 ... | yes _ = true
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
62 ... | no _ = false
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
63 regular-language < h > f _ = false
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
64
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
65 finIn2 : FiniteSet In2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
66 finIn2 = record {
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
67 Q←F = Q←F'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
68 ; F←Q = F←Q'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
69 ; finiso→ = finiso→'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
70 ; finiso← = finiso←'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
71 } where
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
72 Q←F' : Fin 2 → In2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
73 Q←F' zero = i0
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
74 Q←F' (suc zero) = i1
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
75 Q←F' (suc (suc ()))
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
76 F←Q' : In2 → Fin 2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
77 F←Q' i0 = zero
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
78 F←Q' i1 = suc (zero)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
79 finiso→' : (q : In2) → Q←F' (F←Q' q) ≡ q
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
80 finiso→' i0 = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
81 finiso→' i1 = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
82 finiso←' : (f : Fin 2) → F←Q' (Q←F' f) ≡ f
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
83 finiso←' zero = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
84 finiso←' (suc zero) = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
85 finiso←' (suc (suc ()))
11
8e66865fd9af fix sbconst
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
86
8e66865fd9af fix sbconst
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
87
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
88 test-r1 = < i0 > & < i1 >
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
89 test-r2 = regular-language (< i0 > & < i1 >) finIn2 ( i0 ∷ i1 ∷ [] )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
90 test-r3 = regular-language (< i0 > & < i1 >) finIn2 ( i0 ∷ i0 ∷ [] )
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
91
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
92 issub : {Σ : Set} {n : ℕ } → Regex Σ → Regex Σ → FiniteSet Σ {n} → Bool
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
93 issub (r *) s f = issub r s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
94 issub (r & r₁) s f = issub r s f ∨ issub r₁ s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
95 issub (r || r₁) s f = issub r s f ∨ issub r₁ s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
96 issub < x > < s > f with cmpi f x s
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
97 issub < x > < s > f | yes p = true
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
98 issub < x > < s > f | no ¬p = false
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
99 issub < x > s f = false
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
100
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
101 record RegexSub {Σ : Set} (R : Regex Σ) {n : ℕ } (fin : FiniteSet Σ {n} ): Set where
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
102 field
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
103 Subterm : Regex Σ
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
104 sub : issub R Subterm fin ≡ true
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
105
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
106 open import Data.Product
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
107
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
108
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
109 regex2nfa : {Σ : Set} → Regex Σ → {n : ℕ } (fin : FiniteSet Σ {n}) → NAutomaton (Regex Σ) Σ × ( List (Regex Σ) )
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
110 regex2nfa {Σ} (r *) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } , {!!} where
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
111 nr0 = proj₁ (regex2nfa r fin)
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
112 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
113 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nδ nr0 s0 i s1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
114 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
115 Nstart s0 = NAutomaton.Nstart nr0 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
116 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
117 Nend s0 = NAutomaton.Nend nr0 s0
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
118 regex2nfa {Σ} (r0 & r1) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } , {!!} where
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
119 nr0 = proj₁ (regex2nfa r0 fin)
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
120 nr1 = proj₁ (regex2nfa r1 fin)
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
121 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
122 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nδ nr1 s0 i s1 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
123 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
124 Nstart s0 = NAutomaton.Nstart nr0 s0 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nstart nr1 s0 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
125 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
126 Nend s0 = NAutomaton.Nend nr0 s0 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nend nr1 s0 )
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
127 regex2nfa {Σ} (r0 || r1) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } , {!!} where
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
128 nr0 = proj₁ (regex2nfa r0 fin)
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
129 nr1 = proj₁ (regex2nfa r1 fin)
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
130 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
131 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ NAutomaton.Nδ nr1 s0 i s1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
132 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
133 Nstart s0 = NAutomaton.Nstart nr0 s0 ∨ NAutomaton.Nstart nr1 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
134 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
135 Nend s0 = NAutomaton.Nend nr0 s0 ∨ NAutomaton.Nend nr1 s0
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
136 regex2nfa {Σ} < x > fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } , {!!} where
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
137 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
138 Nδ r1 s r2 with cmpi fin s x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
139 Nδ r1 s r2 | yes _ = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
140 Nδ r1 s r2 | no _ = false
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
141 Nstart : (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
142 Nstart < s > with cmpi fin s x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
143 ... | yes _ = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
144 ... | no _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
145 Nstart _ = false
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
146 Nend : (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
147 Nend _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
148
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
149 test-r4 = regex2nfa (< i0 > & < i1 >) finIn2
8
cdf75ae6f0c1 add subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
150
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
151 -- testr5 = Naccept test-r4 {!!} ( i0 ∷ i1 ∷ [] )
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
152
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
153 rfin : {Σ : Set} → (s : List ( Regex Σ)) → FiniteSet (Regex Σ ) {length s }
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
154 rfin {Σ} s = record {
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
155 Q←F = Q←F'
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
156 ; F←Q = F←Q'
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
157 ; finiso→ = finiso→'
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
158 ; finiso← = finiso←'
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
159 } where
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
160 Q←F' : Fin (length s) → Regex Σ
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
161 Q←F' = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
162 F←Q' : Regex Σ → Fin (length s)
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
163 F←Q' = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
164 finiso→' : (q : Regex Σ) → Q←F' (F←Q' q) ≡ q
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
165 finiso→' = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
166 finiso←' : (f : Fin (length s)) → F←Q' (Q←F' f) ≡ f
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
167 finiso←' = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
168
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
169 reglang⇔n=regex2nfa : {Σ : Set} → {n m : ℕ } (fin : FiniteSet Σ {n})
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
170 → ( regex : Regex Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
171 → ( In : List Σ )
38
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
172 → regular-language regex fin In ≡ Naccept {Regex Σ} {_} ( proj₁ ( regex2nfa {Σ} regex fin ))
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
173 (rfin (proj₂ ( regex2nfa {Σ} regex fin ) )) In
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
174 reglang⇔n=regex2nfa {Σ} {n} {m} fin (regex *) In = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
175 reglang⇔n=regex2nfa {Σ} {n} {m} fin (regex & regex₁) In = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
176 reglang⇔n=regex2nfa {Σ} {n} {m} fin (regex || regex₁) In = {!!}
ab265470c2d0 push down automaton example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 37
diff changeset
177 reglang⇔n=regex2nfa {Σ} {n} {m} fin < x > In = {!!}
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
178
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
179
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
180
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
181
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
182
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
183
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
184
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
185
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
186
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
187