Mercurial > hg > Members > kono > Proof > automaton
annotate agda/automaton.agda @ 24:9406c2571fe7
naccept1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 05 Nov 2018 07:53:48 +0900 |
parents | 02b4ecc9972c |
children | ab265470c2d0 |
rev | line source |
---|---|
0 | 1 module automaton where |
2 | |
24 | 3 -- open import Level renaming ( suc to succ ; zero to Zero ) |
2 | 4 open import Data.Nat |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
5 open import Data.List |
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
6 open import Data.Maybe |
24 | 7 open import Data.Bool using ( Bool ; true ; false ; _∧_ ) |
3 | 8 open import Relation.Binary.PropositionalEquality hiding ( [_] ) |
9 | 9 open import Relation.Nullary using (¬_; Dec; yes; no) |
0 | 10 |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
11 record Automaton ( Q : Set ) ( Σ : Set ) |
0 | 12 : Set where |
1 | 13 field |
14 δ : Q → Σ → Q | |
15 astart : Q | |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
16 aend : Q → Bool |
1 | 17 |
18 open Automaton | |
0 | 19 |
20 data States1 : Set where | |
1 | 21 sr : States1 |
22 ss : States1 | |
23 st : States1 | |
0 | 24 |
25 data In2 : Set where | |
26 i0 : In2 | |
27 i1 : In2 | |
28 | |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
29 moves : { Q : Set } { Σ : Set } |
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
30 → Automaton Q Σ |
0 | 31 → Q → List Σ → Q |
1 | 32 moves {Q} { Σ} M q L = move q L |
0 | 33 where |
34 move : (q : Q ) ( L : List Σ ) → Q | |
35 move q [] = q | |
24 | 36 move q ( H ∷ T ) = move ( δ M q H) T |
0 | 37 |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
38 accept : { Q : Set } { Σ : Set } |
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
39 → Automaton Q Σ |
0 | 40 → List Σ → Bool |
1 | 41 accept {Q} { Σ} M L = move (astart M) L |
0 | 42 where |
43 move : (q : Q ) ( L : List Σ ) → Bool | |
1 | 44 move q [] = aend M q |
45 move q ( H ∷ T ) = move ( (δ M) q H ) T | |
0 | 46 |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
47 transition1 : States1 → In2 → States1 |
1 | 48 transition1 sr i0 = sr |
49 transition1 sr i1 = ss | |
50 transition1 ss i0 = sr | |
51 transition1 ss i1 = st | |
52 transition1 st i0 = sr | |
53 transition1 st i1 = st | |
0 | 54 |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
55 fin1 : States1 → Bool |
1 | 56 fin1 st = true |
24 | 57 fin1 ss = false |
58 fin1 sr = false | |
0 | 59 |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
60 am1 : Automaton States1 In2 |
1 | 61 am1 = record { δ = transition1 ; astart = sr ; aend = fin1 } |
0 | 62 |
63 | |
64 example1-1 = accept am1 ( i0 ∷ i1 ∷ i0 ∷ [] ) | |
65 example1-2 = accept am1 ( i1 ∷ i1 ∷ i1 ∷ [] ) | |
66 | |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
67 reachable : { Q : Set } { Σ : Set } |
1 | 68 → (M : Automaton Q Σ ) |
0 | 69 → (q : Q ) |
13
02b4ecc9972c
start exp version of subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
70 → (L : List Σ ) → Set |
1 | 71 reachable M q L = moves M (astart M) L ≡ q |
0 | 72 |
1 | 73 example1-3 = reachable am1 st ( i1 ∷ i1 ∷ i1 ∷ [] ) |
0 | 74 |
24 | 75 ieq : (i i' : In2 ) → Dec ( i ≡ i' ) |
76 ieq i0 i0 = yes refl | |
77 ieq i1 i1 = yes refl | |
78 ieq i0 i1 = no ( λ () ) | |
79 ieq i1 i0 = no ( λ () ) | |
0 | 80 |