annotate automaton-in-agda/src/deriveUtil.agda @ 324:329adb1b71c7

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 14 Jan 2022 22:58:25 +0900
parents f60c1041ae8e
children 113330c6e896
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
271
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module deriveUtil where
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to succ ; zero to Zero )
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Data.Nat
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Fin
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.List
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import regex
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import automaton
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import nfa
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import logic
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open NAutomaton
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open Automaton
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import Relation.Binary.PropositionalEquality hiding ( [_] )
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 open import Relation.Nullary
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 open Bool
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 data alpha2 : Set where
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 a : alpha2
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 b : alpha2
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 a-eq? : (x y : alpha2) → Dec (x ≡ y)
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 a-eq? a a = yes refl
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 a-eq? b b = yes refl
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 a-eq? a b = no (λ ())
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 a-eq? b a = no (λ ())
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 open Regex
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
272
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
32 open import finiteSet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
33
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
34 fin-a : FiniteSet alpha2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
35 fin-a = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
36 finite = finite0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
37 ; Q←F = Q←F0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
38 ; F←Q = F←Q0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
39 ; finiso→ = finiso→0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
40 ; finiso← = finiso←0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
41 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
42 finite0 : ℕ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
43 finite0 = 2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
44 Q←F0 : Fin finite0 → alpha2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
45 Q←F0 zero = a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
46 Q←F0 (suc zero) = b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
47 F←Q0 : alpha2 → Fin finite0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
48 F←Q0 a = # 0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
49 F←Q0 b = # 1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
50 finiso→0 : (q : alpha2) → Q←F0 ( F←Q0 q ) ≡ q
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
51 finiso→0 a = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
52 finiso→0 b = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
53 finiso←0 : (f : Fin finite0 ) → F←Q0 ( Q←F0 f ) ≡ f
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
54 finiso←0 zero = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
55 finiso←0 (suc zero) = refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
56
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
58 open import derive alpha2 fin-a a-eq?
271
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 test11 = regex→automaton ( < a > & < b > )
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 test12 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ b ∷ [] )
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 test13 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ a ∷ [] )
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
5e066b730d73 regex cmp
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 test14 = regex-match ( ( < a > & < b > ) * ) ( a ∷ b ∷ a ∷ a ∷ [] )
272
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
66 test15 = regex-derive ( ( < a > & < b > ) * ∷ [] )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
67 test16 = regex-derive test15
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
68 test17 : regex-derive test16 ≡ test16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 271
diff changeset
69 test17 = refl