annotate automaton.agda @ 20:bdca72fe271e default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 03 Dec 2020 06:44:49 +0900
parents e168140d15b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 {-# OPTIONS --allow-unsolved-metas #-}
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 module automaton where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level hiding ( suc ; zero )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Empty
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Relation.Nullary
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Relation.Binary.PropositionalEquality -- hiding (_⇔_)
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import logic
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.List
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 record Automaton {n : Level} (Q : Set n) (Σ : Set ) : Set ((Level.suc n) ) where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 field
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 δ : Q → Σ → Q
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 F : Q → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open Automaton
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 accept : {n : Level} {Q : Set n} {Σ : Set } → Automaton Q Σ → Q → List Σ → Set
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
18 accept {n} {Q} {Σ} atm q [] = F atm q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
19 accept {n} {Q} {Σ} atm q (x ∷ input) =
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 accept atm (δ atm q x ) input
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
22 -- data Dec' {n : Level} (P : Set n) : Set n where -- Law of Exclude Middle / LEM
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
23 -- yes' : (p : P ) → Dec' P
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
24 -- no' : (p : ¬ P ) → Dec' P
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
25
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
26 record Automaton-Language {n : Level} (Q : Set n) (Σ : Set ) : Set ((Level.suc n) ) where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
27 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
28 ATM : Automaton Q Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
29 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
30 startq : Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
31 decF : (q : Q) → Dec (F ATM q )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
32 accept-by : (x : List Σ ) → (q : Q) → Dec ( accept ATM q x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
33 -- Accept : (x : List Σ ) → accept-by x startq where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
34 -- accept-by : (x : List Σ ) → (q : Q) → Dec ( accept ATM q x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
35 -- accept-by [] q = decF q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
36 -- accept-by (x ∷ t) q = accept-by t (δ ATM q x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
37
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 trace : {n : Level} {Q : Set n} {Σ : Set } → (A : Automaton Q Σ) → (start : Q) → (input : List Σ ) → accept A start input → List Q
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 trace {n} {Q} {Σ} A q [] a = q ∷ []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 trace {n} {Q} {Σ} A q (x ∷ t) a = q ∷ ( trace A (δ A q x) t a )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
42 trace' : {n : Level} {Q : Set n} {Σ : Set } → (A : Automaton Q Σ) → (start : Q) → (input : List Σ ) → List Q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
43 trace' {n} {Q} {Σ} A q [] = q ∷ []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
44 trace' {n} {Q} {Σ} A q (x ∷ t) = q ∷ ( trace' A (δ A q x) t )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
45
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 data Q3 : Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 q₁ : Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 q₂ : Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 q₃ : Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 data Σ2 : Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 s0 : Σ2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 s1 : Σ2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 δ16 : Q3 → Σ2 → Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 δ16 q₁ s0 = q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 δ16 q₁ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 δ16 q₂ s0 = q₃
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 δ16 q₂ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 δ16 q₃ s0 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 δ16 q₃ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 δ16' : Q3 → Σ2 → Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 δ16' q₁ s0 = q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 δ16' q₁ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 δ16' q₂ s0 = q₃
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 δ16' q₂ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 δ16' q₃ s0 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 δ16' q₃ s1 = q₃
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 data a16end : Q3 → Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 a16q2 : a16end 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 a16 : Automaton Q3 Σ2
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
75 a16 = record { δ = δ16 ; F = λ q → a16end q }
0
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 a16' : Automaton Q3 Σ2
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
78 a16' = record { δ = δ16' ; F = λ q → q ≡ q₂ }
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 --
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 -- ∷ → ∷ → ∷ → []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 -- ↓ ↓ ↓
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 -- s0 s0 s1
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 --
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 input1 : List Σ2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 input1 = s0 ∷ s0 ∷ s1 ∷ []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 input2 : List Σ2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 input2 = s0 ∷ s0 ∷ s0 ∷ []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 test1 : accept a16 q₁ input1
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 test1 = a16q2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 lemma0 : accept a16 q₁ input1 ≡ a16end q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 lemma0 = begin
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 accept a16 q₁ ( s0 ∷ s0 ∷ s1 ∷ [] )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 ≡⟨ refl ⟩ -- x ≡ x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 accept a16 q₁ ( s0 ∷ s1 ∷ [] )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ≡⟨⟩
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 accept a16 q₁ ( s1 ∷ [] )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ≡⟨⟩
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 accept a16 q₂ []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 ≡⟨⟩
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 a16end q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 ∎ where open ≡-Reasoning
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 lemma1 : List Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 lemma1 = trace a16 q₁ input1 a16q2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 test1' : accept a16' q₁ input1
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 test1' = refl
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 lemma2 : List Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 lemma2 = trace a16' q₁ input1 refl
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 test2 : ¬ ( accept a16 q₁ input2 )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 test2 ()
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 open import Data.Bool
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 open import Data.Unit
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 -- contains at least 1 s1
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 c1 : List Σ2 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 c1 [] = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 c1 (s1 ∷ t) = ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 c1 (_ ∷ t) = c1 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 -- even number of s0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 even0 : List Σ2 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 odd0 : List Σ2 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 odd0 [] = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 odd0 (s0 ∷ t) = even0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 odd0 (s1 ∷ t) = odd0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 even0 [] = ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 even0 (s0 ∷ t) = odd0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 even0 (s1 ∷ t) = even0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 -- after
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 a0 : List Σ2 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 a0 [] = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 a0 (s1 ∷ t ) = even0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 a0 (s0 ∷ t ) = a0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 -- data ⊥ : Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 --
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 -- data ⊤ : Set where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 -- tt : ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 -- tt : ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 lemma-a : (x : List Σ2 ) → accept a16' q₁ x → a0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 lemma-a x a = a1 x a where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 a3 : (x : List Σ2 ) → accept a16' q₃ x → odd0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 a2 : (x : List Σ2 ) → accept a16' q₂ x → even0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 a3 [] ()
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 a3 (s0 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 a3 (s1 ∷ t) a = a3 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 a2 [] a = tt
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 a2 (s0 ∷ t) a = a3 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 a2 (s1 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 a1 : (x : List Σ2 ) → accept a16' q₁ x → a0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 a1 [] () -- a16' does not accept []
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 a1 (s0 ∷ t) a = a1 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 a1 (s1 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 -- ¬_ : Set → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 -- ¬_ _ = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 lemma-not-a : ¬ ( (x : List Σ2 ) → accept a16 q₁ x → a0 x )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 lemma-not-a not1 with not1 (s1 ∷ s0 ∷ s1 ∷ [] ) a16q2
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 ... | ()
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 -- can we prove negation similar to the lemma-a?
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 -- lemma-not-a' : ¬ ((x : List Σ2 ) → accept a16 q₁ x → a0 x)
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 -- lemma-not-a' not = {!!} where
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 -- a3 : (x : List Σ2 ) → accept a16 q₃ x → odd0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 -- a2 : (x : List Σ2 ) → accept a16 q₂ x → even0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 -- a3 (s0 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 -- a3 (s1 ∷ t) a = {!!}
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 -- a2 [] a = tt
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 -- a2 (s0 ∷ t) a = a3 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 -- a2 (s1 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 -- a1 : (x : List Σ2 ) → accept a16 q₁ x → a0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 -- a1 [] ()
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 -- a1 (s0 ∷ t) a = a1 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 -- a1 (s1 ∷ t) a = a2 t a
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 open import Data.Nat
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 evenℕ : ℕ → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 oddℕ : ℕ → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 oddℕ zero = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 oddℕ (suc n) = evenℕ n
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 evenℕ zero = ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 evenℕ (suc n) = oddℕ n
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 count-s0 : (x : List Σ2 ) → ℕ
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 count-s0 [] = zero
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 count-s0 (s0 ∷ t) = suc ( count-s0 t )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 count-s0 (s1 ∷ t) = count-s0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 e1 : (x : List Σ2 ) → even0 x → evenℕ ( count-s0 x )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 o1 : (x : List Σ2 ) → odd0 x → oddℕ ( count-s0 x )
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 e1 [] e = tt
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 e1 (s0 ∷ t) o = o1 t o
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 e1 (s1 ∷ t) e = e1 t e
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 o1 [] ()
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 o1 (s0 ∷ t) e = e1 t e
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 o1 (s1 ∷ t) o = o1 t o
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 δ19 : Q3 → Σ2 → Q3
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 δ19 q₁ s0 = q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 δ19 q₁ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 δ19 q₂ s0 = q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 δ19 q₂ s1 = q₂
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 δ19 q₃ _ = q₁
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 a19 : Automaton Q3 Σ2
1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
219 a19 = record { δ = δ19 ; F = λ q → q ≡ q₁ }
0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 -- input is empty or ends in s0
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 end0 : List Σ2 → Set
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 end0 [] = ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 end0 (s0 ∷ [] ) = ⊤
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 end0 (s1 ∷ [] ) = ⊥
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 end0 (x ∷ t ) = end0 t
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 lemma-b : (x : List Σ2 ) → accept a19 q₁ x → end0 x
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 lemma-b = {!!}
9615a94b18ca new automaton in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231