141
|
1 module automaton-ex where
|
|
2
|
|
3 open import Data.Nat
|
|
4 open import Data.List
|
|
5 open import Data.Maybe
|
|
6 open import Relation.Binary.PropositionalEquality hiding ( [_] )
|
|
7 open import Relation.Nullary using (¬_; Dec; yes; no)
|
|
8 open import logic
|
|
9
|
|
10 open import automaton
|
|
11 open Automaton
|
|
12
|
|
13 data StatesQ : Set where
|
|
14 q1 : StatesQ
|
|
15 q2 : StatesQ
|
|
16 q3 : StatesQ
|
|
17
|
|
18 data In2 : Set where
|
|
19 i0 : In2
|
|
20 i1 : In2
|
|
21 transitionQ : StatesQ → In2 → StatesQ
|
|
22 transitionQ q1 i0 = q1
|
|
23 transitionQ q1 i1 = q2
|
|
24 transitionQ q2 i0 = q3
|
|
25 transitionQ q2 i1 = q2
|
|
26 transitionQ q3 i0 = q2
|
|
27 transitionQ q3 i1 = q2
|
|
28
|
|
29 aendQ : StatesQ → Bool
|
|
30 aendQ q2 = true
|
|
31 aendQ _ = false
|
|
32
|
|
33 a1 : Automaton StatesQ In2
|
|
34 a1 = record {
|
|
35 δ = transitionQ
|
|
36 ; aend = aendQ
|
|
37 }
|
|
38
|
|
39 test1 : accept a1 q1 ( i0 ∷ i1 ∷ i0 ∷ [] ) ≡ false
|
|
40 test1 = refl
|
|
41 test2 = accept a1 q1 ( i0 ∷ i1 ∷ i0 ∷ i1 ∷ [] )
|
|
42
|
|
43 data States1 : Set where
|
|
44 sr : States1
|
|
45 ss : States1
|
|
46 st : States1
|
|
47
|
|
48 transition1 : States1 → In2 → States1
|
|
49 transition1 sr i0 = sr
|
|
50 transition1 sr i1 = ss
|
|
51 transition1 ss i0 = sr
|
|
52 transition1 ss i1 = st
|
|
53 transition1 st i0 = sr
|
|
54 transition1 st i1 = st
|
|
55
|
|
56 fin1 : States1 → Bool
|
|
57 fin1 st = true
|
|
58 fin1 ss = false
|
|
59 fin1 sr = false
|
|
60
|
|
61 am1 : Automaton States1 In2
|
|
62 am1 = record { δ = transition1 ; aend = fin1 }
|
|
63
|
|
64
|
|
65 example1-1 = accept am1 sr ( i0 ∷ i1 ∷ i0 ∷ [] )
|
|
66 example1-2 = accept am1 sr ( i1 ∷ i1 ∷ i1 ∷ [] )
|
|
67 trace-2 = trace am1 sr ( i1 ∷ i1 ∷ i1 ∷ [] )
|
|
68
|
|
69 example1-3 = reachable am1 sr st ( i1 ∷ i1 ∷ i1 ∷ [] )
|
|
70
|
|
71 ieq : (i i' : In2 ) → Dec ( i ≡ i' )
|
|
72 ieq i0 i0 = yes refl
|
|
73 ieq i1 i1 = yes refl
|
|
74 ieq i0 i1 = no ( λ () )
|
|
75 ieq i1 i0 = no ( λ () )
|
|
76
|