annotate nfa.agda @ 10:ef43350ea0e2

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 15 Nov 2020 14:36:25 +0900
parents 8a6660c5b1da
children 554fa6e5a09d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 module nfa where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to Suc ; zero to Zero )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Relation.Binary.PropositionalEquality
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.List
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
7 open import Relation.Nullary
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import automaton
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import logic
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 record NAutomaton {n : Level} ( Q : Set n ) ( Σ : Set )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 : Set (Suc n) where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 field
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 Nδ : Q → Σ → Q → Set
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15 NF : Q → Set
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 open NAutomaton
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
19 naccept : {n : Level} {Q : Set n} {Σ : Set } → (Nexists : (Q → Set) → Set) → NAutomaton Q Σ → (Q → Set) → List Σ → Set
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
20 naccept {n} {Q} {Σ} Nexists nfa qs [] = Nexists (λ p → qs p ∧ NF nfa p )
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
21 naccept {n} {Q} {Σ} Nexists nfa qs (x ∷ input) =
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
22 naccept Nexists nfa (λ p' → Nexists (λ p → qs p ∧ Nδ nfa p x p' )) input
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
23
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
24 qlist : {n : Level} {Q : Set n} → (P : Q → Set ) → ((q : Q) → Dec ( P q)) → List Q → List Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
25 qlist P dec [] = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
26 qlist P dec (q ∷ qs) with dec q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
27 ... | yes _ = q ∷ qlist P dec qs
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
28 ... | no _ = qlist P dec qs
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
30 ntrace : {n : Level} {Q : Set n} {Σ : Set } → (Nexists : (Q → Set) → Set) → (nfa : NAutomaton Q Σ) → (qs : Q → Set ) → (input : List Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
31 → naccept Nexists nfa qs input
6
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
32 → ((q : Q) → Dec (qs q))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
33 → (next-dec : (qs : Q → Set) → ((q : Q) → Dec (qs q)) → (x : Σ) → (q : Q ) → Dec (Nexists (λ nq → qs nq ∧ Nδ nfa nq x q)))
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
34 → List Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
35 → List (List Q)
6
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
36 ntrace {n} {Q} {Σ} Nexists nfa qs [] a dec next-dec L = qlist qs dec L ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
37 ntrace {n} {Q} {Σ} Nexists nfa qs (x ∷ t) a dec next-dec L =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
38 qlist qs dec L ∷ ( ntrace Nexists nfa (λ q' → Nexists (λ q → qs q ∧ Nδ nfa q x q' )) t a (next-dec qs dec x) next-dec L )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
40 data exists-in-Q3 (P : Q3 → Set) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
41 qe1 : P q₁ → exists-in-Q3 P
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
42 qe2 : P q₂ → exists-in-Q3 P
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
43 qe3 : P q₃ → exists-in-Q3 P
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
45 record FindQ {n : Level} (Q : Set n) (Nexists : (Q → Set) → Set) : Set (Suc n) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
46 field
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
47 create : {P : Q → Set} (q : Q ) → P q → Nexists (λ q → P q)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
48 found : {P : Q → Set} → Nexists (λ q → P q) → Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
49 exists : {P : Q → Set} → (n : Nexists (λ q → P q)) → P (found n)
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
51 FindQ3 : FindQ Q3 exists-in-Q3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
52 FindQ3 = record { create = create ; found = found ; exists = exists } where
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
53 create : {P : Q3 → Set} (q : Q3) → P q → exists-in-Q3 P
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
54 create q₁ p = qe1 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
55 create q₂ p = qe2 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
56 create q₃ p = qe3 p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
57 found : {P : Q3 → Set} → exists-in-Q3 P → Q3
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
58 found (qe1 x) = q₁
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
59 found (qe2 x) = q₂
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
60 found (qe3 x) = q₃
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
61 exists : {P : Q3 → Set} (n : exists-in-Q3 P) → P (found n)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
62 exists (qe1 x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
63 exists (qe2 x) = x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
64 exists (qe3 x) = x
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
65
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 data transition136 : Q3 → Σ2 → Q3 → Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 d0 : transition136 q₁ s1 q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 d1 : transition136 q₁ s0 q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 d2 : transition136 q₂ s0 q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 d3 : transition136 q₂ s0 q₃
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 d4 : transition136 q₂ s1 q₃
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 d5 : transition136 q₃ s0 q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 start136 : Q3 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 start136 q = q ≡ q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 nfa136 : NAutomaton Q3 Σ2
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
78 nfa136 = record { Nδ = transition136 ; NF = λ q → q ≡ q₁ }
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
80 example136-1 = naccept exists-in-Q3 nfa136 start136 ( s0 ∷ s1 ∷ s0 ∷ s0 ∷ [] )
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
82 example136-0 = naccept exists-in-Q3 nfa136 start136 ( s0 ∷ [] )
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
84 example136-2 = naccept exists-in-Q3 nfa136 start136 ( s1 ∷ s0 ∷ s1 ∷ s0 ∷ s1 ∷ [] )
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
86 subset-construction : {n : Level} { Q : Set n } { Σ : Set } → (Nexists : (Q → Set) → Set) →
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 (NAutomaton Q Σ ) → Automaton {Suc Zero ⊔ n} (Q → Set) Σ
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
88 subset-construction {n} {Q} { Σ} Nexists nfa = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
89 δ = λ qs x q' → Nexists (λ q → qs q ∧ Nδ nfa q x q' )
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
90 ; F = λ qs → Nexists ( λ q → qs q ∧ NF nfa q )
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
93 dfa136 : Automaton (Q3 → Set) Σ2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
94 dfa136 = subset-construction exists-in-Q3 nfa136
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
95
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
96 t136 : accept dfa136 start136 (s0 ∷ s1 ∷ s0 ∷ s0 ∷ []) → List ( Q3 → Set )
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
97 t136 = trace dfa136 start136 (s0 ∷ s1 ∷ s0 ∷ s0 ∷ [] )
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
98
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
99 open _∧_
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
100
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 subset-construction-lemma→ : { Q : Set } { Σ : Set } →
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
102 (Nexists : (Q → Set) → Set) →
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 (NFA : NAutomaton Q Σ ) → (astart : Q → Set )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 → (x : List Σ)
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
105 → naccept Nexists NFA ( λ q1 → astart q1) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
106 → accept ( subset-construction Nexists NFA ) ( λ q1 → astart q1) x
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
107 subset-construction-lemma→ {Q} {Σ} Nexists nfa qs [] na = na
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
108 subset-construction-lemma→ {Q} {Σ} Nexists nfa qs (x ∷ t) na =
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
109 subset-construction-lemma→ Nexists nfa (λ q' → Nexists (λ q → qs q ∧ Nδ nfa q x q' )) t na
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 subset-construction-lemma← : { Q : Set } { Σ : Set } →
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
112 (Nexists : (Q → Set) → Set) →
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 (NFA : NAutomaton Q Σ ) → (astart : Q → Set )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 → (x : List Σ)
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
115 → accept ( subset-construction Nexists NFA ) ( λ q1 → astart q1) x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
116 → naccept Nexists NFA ( λ q1 → astart q1) x
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
117 subset-construction-lemma← {Q} {Σ} Nexists nfa qs [] a = a
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
118 subset-construction-lemma← {Q} {Σ} Nexists nfa qs (x ∷ t) a =
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
119 subset-construction-lemma← Nexists nfa (λ q' → Nexists (λ q → qs q ∧ Nδ nfa q x q' )) t a
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 open import regular-language
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 open RegularLanguage
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 open Automaton
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 open import Data.Empty
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
127 Union-Nexists : {n m : Level} → {A : Set n} → {B : Set m} → ( (A → Set) → Set )→ ( (B → Set) → Set ) → ( (A ∨ B → Set) → Set )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
128 Union-Nexists {n} {m} {A} {B} PA PB P = PA (λ q → P (case1 q)) ∨ PB (λ q → P (case2 q))
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
130 Concat-NFA : {n : Level} {Σ : Set} → (A B : RegularLanguage {n} Σ ) → NAutomaton (states A ∨ states B) Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
131 Concat-NFA {n} {Σ} A B = record { Nδ = δnfa ; NF = nend }
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 module Concat-NFA where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 data δnfa : states A ∨ states B → Σ → states A ∨ states B → Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 a-case : {q : states A} {i : Σ } → δnfa ( case1 q) i (case1 (δ (automaton A) q i))
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 ab-trans : {q : states A} {i : Σ } → F (automaton A) q → δnfa ( case1 q) i (case2 (δ (automaton B) (astart B) i))
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 b-case : {q : states B} {i : Σ } → δnfa ( case2 q) i (case2 (δ (automaton B) q i))
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 nend : states A ∨ states B → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 nend (case2 q) = F (automaton B) q
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 nend (case1 q) = F (automaton A) q ∧ F (automaton B) (astart B) -- empty B case
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
141 data state-is {n : Level} {Σ : Set } (A B : RegularLanguage {n} Σ ) : (q : states A ∨ states B ) → Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
142 this : state-is A B (case1 (astart A))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
143
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
144 record Split {Σ : Set} (A : List Σ → Set ) ( B : List Σ → Set ) (x : List Σ ) : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
145 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
146 sp0 : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
147 sp1 : List Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
148 sp-concat : sp0 ++ sp1 ≡ x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
149 prop0 : A sp0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
150 prop1 : B sp1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
151
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
152 open Split
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
153 split→AB : {Σ : Set} → (A B : List Σ → Set ) → ( x : List Σ ) → split A B x → Split A B x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
154 split→AB A B [] sp = record { sp0 = [] ; sp1 = [] ; sp-concat = refl ; prop0 = proj1 sp ; prop1 = proj2 sp }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
155 split→AB A B (x ∷ t) (case1 sp) = record { sp0 = [] ; sp1 = x ∷ t ; sp-concat = refl ; prop0 = proj1 sp ; prop1 = proj2 sp }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
156 split→AB A B (x ∷ t) (case2 sp) with split→AB (λ t1 → A ( x ∷ t1 )) B t sp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
157 ... | Sn = record { sp0 = x ∷ sp0 Sn ; sp1 = sp1 Sn ; sp-concat = cong (λ k → x ∷ k) (sp-concat Sn) ; prop0 = prop0 Sn ; prop1 = prop1 Sn }
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 closed-in-concat : {n : Level} {Σ : Set } → (A B : RegularLanguage {n} Σ ) → ( x : List Σ )
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
160 (PA : (states A → Set) → Set) (FA : FindQ (states A) PA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
161 (PB : (states B → Set) → Set) (FB : FindQ (states B) PB)
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
162 → isRegular (Concat {n} (contain A) (contain B)) x record {states = states A ∨ states B → Set ; astart = λ q → state-is A B q
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
163 ; automaton = subset-construction (Union-Nexists PA PB) ( Concat-NFA A B )}
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
164 closed-in-concat {n} {Σ} A B x PA FA PB FB = [ closed-in-concat→ x , closed-in-concat← x ] where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
165 open FindQ
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
166 fa : RegularLanguage Σ
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
167 fa = record {states = states A ∨ states B → Set ; astart = λ q → state-is A B q
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
168 ; automaton = subset-construction (Union-Nexists PA PB) ( Concat-NFA A B )}
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
169 closed-in-concat→ : (x : List Σ) → Concat {n} {Σ} (contain A) (contain B) x → contain fa x
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
170 closed-in-concat→ [] c = cc1 c where
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
171 cc1 : contain A [] ∧ contain B [] →
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
172 PA (λ q → astart fa (case1 q) ∧ NF (Concat-NFA A B) (case1 q)) ∨ PB (λ q → astart fa (case2 q) ∧ NF (Concat-NFA A B) (case2 q))
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
173 cc1 ctab = case1 (create FA (astart A) [ this , [ proj1 ctab , proj2 ctab ] ] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
174 -- fina : (F (automaton A) (astart A) ∧ accept (automaton B) (δ (automaton B) (astart B) x) t)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
175 closed-in-concat→ (x ∷ t) (case1 fina ) = {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
176 -- sp : split (λ t1 → accept (automaton A) (δ (automaton A) (astart A) x) t1) (λ x₁ → accept (automaton B) (astart B) x₁) t
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
177 closed-in-concat→ (x ∷ t) (case2 sp ) = {!!}
8
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
178 closed-in-concat← : (x : List Σ) → contain fa x → Concat {n} {Σ} (contain A) (contain B) x
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
179 closed-in-concat← [] cn = cc2 cn where
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
180 cc2 : PA (λ q → astart fa (case1 q) ∧ NF (Concat-NFA A B) (case1 q)) ∨ PB (λ q → astart fa (case2 q) ∧ NF (Concat-NFA A B) (case2 q))
894feefc3084 subset construction lemma
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
181 → contain A [] ∧ contain B []
10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
182 -- ca : PA (λ q → state-is A B (case1 q) ∧ F (automaton A) q ∧ F (automaton B) (astart B))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
183 cc2 (case1 ca) = [ subst (λ k → accept (automaton A) k [] ) (cc5 _ (proj1 (exists FA ca))) cc3 , proj2 (proj2 (exists FA ca)) ] where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
184 cc5 : (q : states A) → state-is A B (case1 q) → q ≡ astart A
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
185 cc5 q this = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
186 cc3 : accept (automaton A) (found FA ca ) []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
187 cc3 = proj1 (proj2 (exists FA ca))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
188 cc2 (case2 cb) with proj1 (exists FB cb)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
189 ... | ()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
190 closed-in-concat← (x ∷ t) cn = {!!}
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195