annotate automaton-in-agda/src/sbconst2.agda @ 406:a60132983557

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 08 Nov 2023 21:35:54 +0900
parents af8f630b7e60
children 207e6c4e155c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
406
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 405
diff changeset
1 {-# OPTIONS --cubical-compatible --safe #-}
405
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
2
32
cd311109d63b suset construction for subset function nfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
3 module sbconst2 where
13
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Level renaming ( suc to succ ; zero to Zero )
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Nat
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
7 open import Data.Fin
13
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.List
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import automaton
32
cd311109d63b suset construction for subset function nfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
11 open import nfa
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
12 open import logic
13
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open NAutomaton
32
cd311109d63b suset construction for subset function nfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
14 open Automaton
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
15 open import Relation.Binary.PropositionalEquality hiding ( [_] )
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
16
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
17 open Bool
13
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
332
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
19 -- exits : check subset of Q ( Q → Bool) is not empty
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
20 --- ( Q → Σ → Q → Bool ) transition of NFA
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
21 --- (Q → Bool) → Σ → (Q → Bool) generate transition of Automaton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
23 δconv : { Q : Set } { Σ : Set } → ( ( Q → Bool ) → Bool ) → ( Q → Σ → Q → Bool ) → (Q → Bool) → Σ → (Q → Bool)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
24 δconv {Q} { Σ} exists nδ f i q = exists ( λ r → f r /\ nδ r i q )
13
02b4ecc9972c start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
26 subset-construction : { Q : Set } { Σ : Set } →
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
27 ( ( Q → Bool ) → Bool ) →
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
28 (NAutomaton Q Σ ) → (Automaton (Q → Bool) Σ )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
29 subset-construction {Q} { Σ} exists NFA = record {
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
30 δ = λ q x → δconv exists ( Nδ NFA ) q x
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
31 ; aend = λ f → exists ( λ q → f q /\ Nend NFA q )
70
702ce92c45ab add concat
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 69
diff changeset
32 }
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
33
398
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
34 subset-construction' : { Q : Set } { Σ : Set } →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
35 ( ( Q → Bool ) → Bool ) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
36 (NAutomaton Q Σ ) → (Automaton (Q → Bool) Σ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
37 subset-construction' {Q} { Σ} exists NFA = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
38 δ = λ f i q → exists ( λ r → f r /\ Nδ NFA r i q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
39 ; aend = λ f → exists ( λ q → f q /\ Nend NFA q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
40 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 332
diff changeset
41
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
42 test4 = subset-construction existsS1 am2
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
43
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
44 test51 = accept test4 start1 ( i0 ∷ i1 ∷ i0 ∷ [] )
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
45 test61 = accept test4 start1 ( i1 ∷ i1 ∷ i1 ∷ [] )
14
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
46
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
47 subset-construction-lemma→ : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) →
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
48 (NFA : NAutomaton Q Σ ) → (astart : Q → Bool )
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
49 → (x : List Σ)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
50 → Naccept NFA exists astart x ≡ true
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
51 → accept ( subset-construction exists NFA ) astart x ≡ true
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
52 subset-construction-lemma→ {Q} {Σ} exists NFA astart x naccept = lemma1 x astart naccept where
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
53 lemma1 : (x : List Σ) → ( states : Q → Bool )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
54 → Naccept NFA exists states x ≡ true
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
55 → accept ( subset-construction exists NFA ) states x ≡ true
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
56 lemma1 [] states naccept = naccept
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
57 lemma1 (h ∷ t ) states naccept = lemma1 t (δconv exists (Nδ NFA) states h) naccept
32
cd311109d63b suset construction for subset function nfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
58
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
59 subset-construction-lemma← : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) →
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
60 (NFA : NAutomaton Q Σ ) → (astart : Q → Bool )
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
61 → (x : List Σ)
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
62 → accept ( subset-construction exists NFA ) astart x ≡ true
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
63 → Naccept NFA exists astart x ≡ true
268
8006cbd87b20 fix concat dfa
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
64 subset-construction-lemma← {Q} {Σ} exists NFA astart x saccept = lemma2 x astart saccept where
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
65 lemma2 : (x : List Σ) → ( states : Q → Bool )
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
66 → accept ( subset-construction exists NFA ) states x ≡ true
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
67 → Naccept NFA exists states x ≡ true
69
f124fceba460 subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 44
diff changeset
68 lemma2 [] states saccept = saccept
141
b3f05cd08d24 clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 70
diff changeset
69 lemma2 (h ∷ t ) states saccept = lemma2 t (δconv exists (Nδ NFA) states h) saccept
332
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
71
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 268
diff changeset
72