annotate automaton-in-agda/src/flcagl.agda @ 330:407684f806e4

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 16 Nov 2022 17:43:10 +0900
parents e5cf49902db3
children af8f630b7e60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
1 {-# OPTIONS --sized-types #-}
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 open import Relation.Nullary
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Relation.Binary.PropositionalEquality
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 module flcagl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 (A : Set)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ( _≟_ : (a b : A) → Dec ( a ≡ b ) ) where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Bool hiding ( _≟_ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 -- open import Data.Maybe
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Level renaming ( zero to Zero ; suc to succ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Size
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 module List where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 data List (i : Size) (A : Set) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 [] : List i A
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 _∷_ : {j : Size< i} (x : A) (xs : List j A) → List i A
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 map : ∀{i A B} → (A → B) → List i A → List i B
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 map f [] = []
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 map f ( x ∷ xs)= f x ∷ map f xs
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 foldr : ∀{i} {A B : Set} → (A → B → B) → B → List i A → B
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 foldr c n [] = n
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 foldr c n (x ∷ xs) = c x (foldr c n xs)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 any : ∀{i A} → (A → Bool) → List i A → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 any p xs = foldr _∨_ false (map p xs)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 module Lang where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 open List
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 record Lang (i : Size) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 coinductive
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 field
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 ν : Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 δ : ∀{j : Size< i} → A → Lang j
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 open Lang
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 _∋_ : ∀{i} → Lang i → List i A → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 l ∋ [] = ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 l ∋ ( a ∷ as ) = δ l a ∋ as
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 trie : ∀{i} (f : List i A → Bool) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ν (trie f) = f []
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 δ (trie f) a = trie (λ as → f (a ∷ as))
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ∅ : ∀{i} → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 ν ∅ = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 δ ∅ x = ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 ε : ∀{i} → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 ν ε = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 δ ε x = ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 open import Relation.Nullary.Decidable
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 char : ∀{i} (a : A) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 ν (char a) = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 δ (char a) x = if ⌊ a ≟ x ⌋ then ε else ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 compl : ∀{i} (l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 ν (compl l) = not (ν l)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 δ (compl l) x = compl (δ l x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 _∪_ : ∀{i} (k l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 ν (k ∪ l) = ν k ∨ ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 δ (k ∪ l) x = δ k x ∪ δ l x
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
75 _·_ : ∀{i} (k l : Lang i) → Lang i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
76 ν (k · l) = ν k ∧ ν l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
77 δ (k · l) x = let k′l = δ k x · l in if ν k then k′l ∪ δ l x else k′l
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
79 _*_ : ∀{i} (k l : Lang i ) → Lang i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
80 ν (k * l) = ν k ∧ ν l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
81 δ (_*_ {i} k l) {j} x =
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 let
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 k′l : Lang j
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
84 k′l = _*_ {j} (δ k {j} x) l
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 in if ν k then _∪_ {j} k′l (δ l {j} x) else k′l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 _* : ∀{i} (l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 ν (l *) = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 δ (l *) x = δ l x · (l *)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 record _≅⟨_⟩≅_ (l : Lang ∞ ) i (k : Lang ∞) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 coinductive
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 field ≅ν : ν l ≡ ν k
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ≅δ : ∀ {j : Size< i } (a : A ) → δ l a ≅⟨ j ⟩≅ δ k a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 open _≅⟨_⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ≅refl : ∀{i} {l : Lang ∞} → l ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ≅ν ≅refl = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 ≅δ ≅refl a = ≅refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 ≅sym : ∀{i} {k l : Lang ∞} (p : l ≅⟨ i ⟩≅ k) → k ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 ≅ν (≅sym p) = sym (≅ν p)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 ≅δ (≅sym p) a = ≅sym (≅δ p a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 ≅trans : ∀{i} {k l m : Lang ∞}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 ( p : k ≅⟨ i ⟩≅ l ) ( q : l ≅⟨ i ⟩≅ m ) → k ≅⟨ i ⟩≅ m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 ≅ν (≅trans p q) = trans (≅ν p) (≅ν q)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 ≅δ (≅trans p q) a = ≅trans (≅δ p a) (≅δ q a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 open import Relation.Binary
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 ≅isEquivalence : ∀(i : Size) → IsEquivalence _≅⟨ i ⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 ≅isEquivalence i = record { refl = ≅refl; sym = ≅sym; trans = ≅trans }
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 Bis : ∀(i : Size) → Setoid _ _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 Setoid.Carrier (Bis i) = Lang ∞
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 Setoid._≈_ (Bis i) = _≅⟨ i ⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 Setoid.isEquivalence (Bis i) = ≅isEquivalence i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
266
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
122 -- import Relation.Binary.EqReasoning as EqR
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
123 import Relation.Binary.Reasoning.Setoid as EqR
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 ≅trans′ : ∀ i (k l m : Lang ∞)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 ( p : k ≅⟨ i ⟩≅ l ) ( q : l ≅⟨ i ⟩≅ m ) → k ≅⟨ i ⟩≅ m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 ≅trans′ i k l m p q = begin
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 k ≈⟨ p ⟩
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 l ≈⟨ q ⟩
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 m ∎ where open EqR (Bis i)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 open import Data.Bool.Properties
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 union-assoc : ∀{i} (k {l m} : Lang ∞) → ((k ∪ l) ∪ m ) ≅⟨ i ⟩≅ ( k ∪ (l ∪ m) )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 ≅ν (union-assoc k) = ∨-assoc (ν k) _ _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 ≅δ (union-assoc k) a = union-assoc (δ k a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 union-comm : ∀{i} (l k : Lang ∞) → (l ∪ k ) ≅⟨ i ⟩≅ ( k ∪ l )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 ≅ν (union-comm l k) = ∨-comm (ν l) _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 ≅δ (union-comm l k) a = union-comm (δ l a) (δ k a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 union-idem : ∀{i} (l : Lang ∞) → (l ∪ l ) ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 ≅ν (union-idem l) = ∨-idem _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 ≅δ (union-idem l) a = union-idem (δ l a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 union-emptyl : ∀{i}{l : Lang ∞} → (∅ ∪ l ) ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 ≅ν union-emptyl = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 ≅δ union-emptyl a = union-emptyl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 union-cong : ∀{i}{k k′ l l′ : Lang ∞}
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
148 (p : k ≅⟨ i ⟩≅ k′) (q : l ≅⟨ i ⟩≅ l′ ) → ( k ∪ l ) ≅⟨ i ⟩≅ ( k′ ∪ l′ )
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 ≅ν (union-cong p q) = cong₂ _∨_ (≅ν p) (≅ν q)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 ≅δ (union-cong p q) a = union-cong (≅δ p a) (≅δ q a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 withExample : (P : Bool → Set) (p : P true) (q : P false) →
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 {A : Set} (g : A → Bool) (x : A) → P (g x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 withExample P p q g x with g x
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 ... | true = p
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 ... | false = q
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 rewriteExample : {A : Set} {P : A → Set} {x : A} (p : P x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 {g : A → A} (e : g x ≡ x) → P (g x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 rewriteExample p e rewrite e = p
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
162 infixr 6 _∪_
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 infixr 7 _·_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 infix 5 _≅⟨_⟩≅_
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
165
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
166 union-congl : ∀{i}{k k′ l : Lang ∞}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
167 (p : k ≅⟨ i ⟩≅ k′) → ( k ∪ l ) ≅⟨ i ⟩≅ ( k′ ∪ l )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
168 union-congl eq = union-cong eq ≅refl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
169
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
170 union-congr : ∀{i}{k l l′ : Lang ∞}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
171 (p : l ≅⟨ i ⟩≅ l′) → ( k ∪ l ) ≅⟨ i ⟩≅ ( k ∪ l′ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
172 union-congr eq = union-cong ≅refl eq
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
173
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
174 union-swap24 : ∀{i} ({x y z w} : Lang ∞) → (x ∪ y) ∪ z ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
175 ≅⟨ i ⟩≅ (x ∪ z) ∪ y ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
176 union-swap24 {_} {x} {y} {z} {w} = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
177 (x ∪ y) ∪ z ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
178 ≈⟨ union-assoc x ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
179 x ∪ y ∪ z ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
180 ≈⟨ union-congr (≅sym ( union-assoc y)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
181 x ∪ ((y ∪ z) ∪ w)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
182 ≈⟨ ≅sym ( union-assoc x ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
183 (x ∪ ( y ∪ z)) ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
184 ≈⟨ union-congl (union-congr (union-comm y z )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
185 ( x ∪ (z ∪ y)) ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
186 ≈⟨ union-congl (≅sym ( union-assoc x )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
187 ((x ∪ z) ∪ y) ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
188 ≈⟨ union-assoc (x ∪ z) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
189 (x ∪ z) ∪ y ∪ w
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
190
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
191 where open EqR (Bis _)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 concat-union-distribr : ∀{i} (k {l m} : Lang ∞) → k · ( l ∪ m ) ≅⟨ i ⟩≅ ( k · l ) ∪ ( k · m )
48
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
194 ≅ν (concat-union-distribr k) = ∧-distribˡ-∨ (ν k) _ _
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 ≅δ (concat-union-distribr k) a with ν k
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 ≅δ (concat-union-distribr k {l} {m}) a | true = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
197 δ k a · (l ∪ m) ∪ (δ l a ∪ δ m a)
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
198 ≈⟨ union-congl (concat-union-distribr _) ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
199 (δ k a · l ∪ δ k a · m) ∪ (δ l a ∪ δ m a)
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
200 ≈⟨ union-swap24 ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
201 (δ k a · l ∪ δ l a) ∪ (δ k a · m ∪ δ m a)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 ≅δ (concat-union-distribr k) a | false = concat-union-distribr (δ k a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
206 concat-union-distribl : ∀{i} (k {l m} : Lang ∞) → ( k ∪ l ) · m ≅⟨ i ⟩≅ ( k · m ) ∪ ( l · m )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
207 ≅ν (concat-union-distribl k {l} {m}) = ∧-distribʳ-∨ _ (ν k) _
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
208 ≅δ (concat-union-distribl k {l} {m}) a with ν k | ν l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
209 ≅δ (concat-union-distribl k {l} {m}) a | false | false = concat-union-distribl (δ k a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
210 ≅δ (concat-union-distribl k {l} {m}) a | false | true = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
211 (if false ∨ true then (δ k a ∪ δ l a) · m ∪ δ m a else (δ k a ∪ δ l a) · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
212 ≈⟨ ≅refl ⟩
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
213 ((δ k a ∪ δ l a) · m ) ∪ δ m a
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
214 ≈⟨ union-congl (concat-union-distribl _) ⟩
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
215 (δ k a · m ∪ δ l a · m) ∪ δ m a
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
216 ≈⟨ union-assoc _ ⟩
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
217 (δ k a · m) ∪ ( δ l a · m ∪ δ m a )
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
218 ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
219 (if false then δ k a · m ∪ δ m a else δ k a · m) ∪ (if true then δ l a · m ∪ δ m a else δ l a · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
220
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
221 where open EqR (Bis _)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
222 ≅δ (concat-union-distribl k {l} {m}) a | true | false = begin
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
223 (if true ∨ false then (δ k a ∪ δ l a) · m ∪ δ m a else (δ k a ∪ δ l a) · m) ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
224 ((δ k a ∪ δ l a) · m ) ∪ δ m a ≈⟨ union-congl (concat-union-distribl _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
225 (δ k a · m ∪ δ l a · m) ∪ δ m a ≈⟨ union-assoc _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
226 δ k a · m ∪ ( δ l a · m ∪ δ m a ) ≈⟨ union-congr ( union-comm _ _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
227 δ k a · m ∪ δ m a ∪ δ l a · m ≈⟨ ≅sym ( union-assoc _ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
228 (δ k a · m ∪ δ m a) ∪ δ l a · m ≈⟨ ≅refl ⟩
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
229 ((if true then δ k a · m ∪ δ m a else δ k a · m) ∪ (if false then δ l a · m ∪ δ m a else δ l a · m))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
230
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
231 where open EqR (Bis _)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
232 ≅δ (concat-union-distribl k {l} {m}) a | true | true = begin
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
233 (if true ∨ true then (δ k a ∪ δ l a) · m ∪ δ m a else (δ k a ∪ δ l a) · m) ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
234 (δ k a ∪ δ l a) · m ∪ δ m a ≈⟨ union-congl ( concat-union-distribl _ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
235 (δ k a · m ∪ δ l a · m) ∪ δ m a ≈⟨ union-assoc _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
236 δ k a · m ∪ ( δ l a · m ∪ δ m a ) ≈⟨ ≅sym ( union-congr ( union-congr ( union-idem _ ) ) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
237 δ k a · m ∪ ( δ l a · m ∪ (δ m a ∪ δ m a) ) ≈⟨ ≅sym ( union-congr ( union-assoc _ )) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
238 δ k a · m ∪ ( (δ l a · m ∪ δ m a ) ∪ δ m a ) ≈⟨ union-congr ( union-congl ( union-comm _ _) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
239 δ k a · m ∪ ( (δ m a ∪ δ l a · m ) ∪ δ m a ) ≈⟨ ≅sym ( union-assoc _ ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
240 ( δ k a · m ∪ (δ m a ∪ δ l a · m )) ∪ δ m a ≈⟨ ≅sym ( union-congl ( union-assoc _ ) ) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
241 ((δ k a · m ∪ δ m a) ∪ δ l a · m) ∪ δ m a ≈⟨ union-assoc _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
242 (δ k a · m ∪ δ m a) ∪ δ l a · m ∪ δ m a ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
243 ((if true then δ k a · m ∪ δ m a else δ k a · m) ∪ (if true then δ l a · m ∪ δ m a else δ l a · m))
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
244
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
245 where open EqR (Bis _)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
246
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
247 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
248 concat-emptyl : ∀{i} l → ∅ · l ≅⟨ i ⟩≅ ∅
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
249 concat-emptyr : ∀{i} l → l · ∅ ≅⟨ i ⟩≅ ∅
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
250 concat-unitl : ∀{i} l → ε · l ≅⟨ i ⟩≅ l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
251 concat-unitr : ∀{i} l → l · ε ≅⟨ i ⟩≅ l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
252 star-empty : ∀{i} → ∅ * ≅⟨ i ⟩≅ ε
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
254 concat-congl : ∀{i} {m l k : Lang ∞} → l ≅⟨ i ⟩≅ k → l · m ≅⟨ i ⟩≅ k · m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
255 ≅ν (concat-congl {i} {m} p ) = cong (λ x → x ∧ ( ν m )) ( ≅ν p )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
256 ≅δ (concat-congl {i} {m} {l} {k} p ) a with ν k | ν l | ≅ν p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
257 ≅δ (concat-congl {i} {m} {l} {k} p) a | false | false | refl = concat-congl (≅δ p a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
258 ≅δ (concat-congl {i} {m} {l} {k} p) a | true | true | refl = union-congl (concat-congl (≅δ p a))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
259
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
260 concat-congr : ∀{i} {m l k : Lang ∞} → l ≅⟨ i ⟩≅ k → m · l ≅⟨ i ⟩≅ m · k
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
261 ≅ν (concat-congr {i} {m} {_} {k} p ) = cong (λ x → ( ν m ) ∧ x ) ( ≅ν p )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
262 ≅δ (concat-congr {i} {m} {l} {k} p ) a with ν m | ν k | ν l | ≅ν p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
263 ≅δ (concat-congr {i} {m} {l} {k} p) a | false | x | .x | refl = concat-congr p
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
264 ≅δ (concat-congr {i} {m} {l} {k} p) a | true | x | .x | refl = union-cong (concat-congr p ) ( ≅δ p a )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
265
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
266 concat-assoc : ∀{i} (k {l m} : Lang ∞) → (k · l) · m ≅⟨ i ⟩≅ k · (l · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
267 ≅ν (concat-assoc {i} k {l} {m} ) = ∧-assoc ( ν k ) ( ν l ) ( ν m )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
268 ≅δ (concat-assoc {i} k {l} {m} ) a with ν k
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
269 ≅δ (concat-assoc {i} k {l} {m}) a | false = concat-assoc _
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
270 ≅δ (concat-assoc {i} k {l} {m}) a | true with ν l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
271 ≅δ (concat-assoc {i} k {l} {m}) a | true | false = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
272 ( if false then (δ k a · l ∪ δ l a) · m ∪ δ m a else (δ k a · l ∪ δ l a) · m )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
273 ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
274 (δ k a · l ∪ δ l a) · m
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
275 ≈⟨ concat-union-distribl _ ⟩
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
276 ((δ k a · l) · m ) ∪ ( δ l a · m )
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
277 ≈⟨ union-congl (concat-assoc _) ⟩
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
278 (δ k a · l · m ) ∪ ( δ l a · m )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
279 ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
280 δ k a · l · m ∪ (if false then δ l a · m ∪ δ m a else δ l a · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
281 ∎ where open EqR (Bis _)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
282 ≅δ (concat-assoc {i} k {l} {m}) a | true | true = begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
283 (if true then (δ k a · l ∪ δ l a) · m ∪ δ m a else (δ k a · l ∪ δ l a) · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
284 ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
285 ((( δ k a · l ) ∪ δ l a) · m ) ∪ δ m a
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
286 ≈⟨ union-congl (concat-union-distribl _ ) ⟩
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
287 ((δ k a · l) · m ∪ ( δ l a · m )) ∪ δ m a
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
288 ≈⟨ union-congl ( union-congl (concat-assoc _)) ⟩
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
289 (( δ k a · l · m ) ∪ ( δ l a · m )) ∪ δ m a
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
290 ≈⟨ union-assoc _ ⟩
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
291 ( δ k a · l · m ) ∪ ( ( δ l a · m ) ∪ δ m a )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
292 ≈⟨ ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
293 δ k a · l · m ∪ (if true then δ l a · m ∪ δ m a else δ l a · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
294 ∎ where open EqR (Bis _)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
295
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 star-concat-idem : ∀{i} (l : Lang ∞) → l * · l * ≅⟨ i ⟩≅ l *
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 ≅ν (star-concat-idem l) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 ≅δ (star-concat-idem l) a = begin
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
299 δ ((l *) · (l *)) a ≈⟨ union-congl (concat-assoc _) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
300 δ l a · (l * · l *) ∪ δ l a · l * ≈⟨ union-congl (concat-congr (star-concat-idem _)) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
301 δ l a · l * ∪ δ l a · l * ≈⟨ union-idem _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
302 δ (l *) a ∎ where open EqR (Bis _)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 star-idem : ∀{i} (l : Lang ∞) → (l *) * ≅⟨ i ⟩≅ l *
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 ≅ν (star-idem l) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 ≅δ (star-idem l) a = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
307 δ ((l *) *) a ≈⟨ concat-assoc (δ l a) ⟩
48
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
308 δ l a · ((l *) · ((l *) *)) ≈⟨ concat-congr ( concat-congr (star-idem l )) ⟩
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
309 δ l a · ((l *) · (l *)) ≈⟨ concat-congr (star-concat-idem l ) ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
310 δ l a · l *
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
313 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
314 star-rec : ∀{i} (l : Lang ∞) → l * ≅⟨ i ⟩≅ ε ∪ (l · l *)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 star-from-rec : ∀{i} (k {l m} : Lang ∞)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 → ν k ≡ false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 → l ≅⟨ i ⟩≅ k · l ∪ m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 → l ≅⟨ i ⟩≅ k * · m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 ≅ν (star-from-rec k n p) with ≅ν p
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
321 ... | b rewrite n = b
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 ≅δ (star-from-rec k {l} {m} n p) a with ≅δ p a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 ... | q rewrite n = begin
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 (δ l a)
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
325 ≈⟨ q ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
326 δ k a · l ∪ δ m a
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
327 ≈⟨ union-congl (concat-congr (star-from-rec k {l} {m} n p)) ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
328 (δ k a · (k * · m) ∪ δ m a)
51
bc0400528027 flcagl finish
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 50
diff changeset
329 ≈⟨ union-congl (≅sym (concat-assoc _)) ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
330 (δ k a · (k *)) · m ∪ δ m a
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 open List
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 record DA (S : Set) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 field ν : (s : S) → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 δ : (s : S)(a : A) → S
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 νs : ∀{i} (ss : List.List i S) → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 νs ss = List.any ν ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 δs : ∀{i} (ss : List.List i S) (a : A) → List.List i S
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 δs ss a = List.map (λ s → δ s a) ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 open Lang
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 lang : ∀{i} {S} (da : DA S) (s : S) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 Lang.ν (lang da s) = DA.ν da s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 Lang.δ (lang da s) a = lang da (DA.δ da s a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 open import Data.Unit hiding ( _≟_ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 open DA
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 ∅A : DA ⊤
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 ν ∅A s = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 δ ∅A s a = s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 εA : DA Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 ν εA b = b
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 δ εA b a = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 open import Relation.Nullary.Decidable
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 data 3States : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 init acc err : 3States
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 charA : (a : A) → DA 3States
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 ν (charA a) init = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 ν (charA a) acc = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 ν (charA a) err = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 δ (charA a) init x =
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 if ⌊ a ≟ x ⌋ then acc else err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 δ (charA a) acc x = err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 δ (charA a) err x = err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 complA : ∀{S} (da : DA S) → DA S
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 ν (complA da) s = not (ν da s)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 δ (complA da) s a = δ da s a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 open import Data.Product
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 _⊕_ : ∀{S1 S2} (da1 : DA S1) (da2 : DA S2) → DA (S1 × S2)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 ν (da1 ⊕ da2) (s1 , s2) = ν da1 s1 ∨ ν da2 s2
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 δ (da1 ⊕ da2) (s1 , s2) a = δ da1 s1 a , δ da2 s2 a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 powA : ∀{S} (da : DA S) → DA (List ∞ S)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 ν (powA da) ss = νs da ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 δ (powA da) ss a = δs da ss a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 open _≅⟨_⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 powA-nil : ∀{i S} (da : DA S) → lang (powA da) [] ≅⟨ i ⟩≅ ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 ≅ν (powA-nil da) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 ≅δ (powA-nil da) a = powA-nil da
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 powA-cons : ∀{i S} (da : DA S) {s : S} {ss : List ∞ S} →
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 lang (powA da) (s ∷ ss) ≅⟨ i ⟩≅ lang da s ∪ lang (powA da) ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 ≅ν (powA-cons da) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 ≅δ (powA-cons da) a = powA-cons da
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 composeA : ∀{S1 S2} (da1 : DA S1)(s2 : S2)(da2 : DA S2) → DA (S1 × List ∞ S2)
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
403 ν (composeA da1 s2 da2) (s1 , ss2) = (ν da1 s1 ∧ ν da2 s2) ∨ νs da2 ss2
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 δ (composeA da1 s2 da2) (s1 , ss2) a =
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
405 δ da1 s1 a , δs da2 (if ν da1 s1 then s2 ∷ ss2 else ss2) a
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
266
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
407 -- import Relation.Binary.EqReasoning as EqR
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 183
diff changeset
408 import Relation.Binary.Reasoning.Setoid as EqR
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 composeA-gen : ∀{i S1 S2} (da1 : DA S1) (da2 : DA S2) → ∀(s1 : S1)(s2 : S2)(ss : List ∞ S2) →
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 lang (composeA da1 s2 da2) (s1 , ss) ≅⟨ i ⟩≅ lang da1 s1 · lang da2 s2 ∪ lang (powA da2) ss
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
412 ≅ν (composeA-gen da1 da2 s1 s2 ss) = refl
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 ≅δ (composeA-gen da1 da2 s1 s2 ss) a with ν da1 s1
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
414 ... | false = composeA-gen da1 da2 (δ da1 s1 a) s2 (δs da2 ss a)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 ... | true = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
416 lang (composeA da1 s2 da2) (δ da1 s1 a , δ da2 s2 a ∷ δs da2 ss a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
417 ≈⟨ composeA-gen da1 da2 (δ da1 s1 a) s2 (δs da2 (s2 ∷ ss) a) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
418 lang da1 (δ da1 s1 a) · lang da2 s2 ∪ lang (powA da2) (δs da2 (s2 ∷ ss) a)
49
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
419 ≈⟨ union-congr (powA-cons da2) ⟩
48
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
420 lang da1 (δ da1 s1 a) · lang da2 s2 ∪
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
421 (lang da2 (δ da2 s2 a) ∪ lang (powA da2) (δs da2 ss a))
68e5f56cf01f fix coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 47
diff changeset
422 ≈⟨ ≅sym (union-assoc _) ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
423 (lang da1 (δ da1 s1 a) · lang da2 s2 ∪ lang da2 (δ da2 s2 a)) ∪ lang (powA da2) (δs da2 ss a)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
426 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
427 composeA-correct : ∀{i S1 S2} (da1 : DA S1) (da2 : DA S2) s1 s2 →
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 lang (composeA da1 s2 da2) (s1 , []) ≅⟨ i ⟩≅ lang da1 s1 · lang da2 s2
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 open import Data.Maybe
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 acceptingInitial : ∀{S} (s0 : S) (da : DA S) → DA (Maybe S)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 ν (acceptingInitial s0 da) (just s) = ν da s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 δ (acceptingInitial s0 da) (just s) a = just (δ da s a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 ν (acceptingInitial s0 da) nothing = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 δ (acceptingInitial s0 da) nothing a = just (δ da s0 a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 finalToInitial : ∀{S} (da : DA (Maybe S)) → DA (List ∞ (Maybe S))
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 ν (finalToInitial da) ss = νs da ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 δ (finalToInitial da) ss a =
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 let ss′ = δs da ss a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 in if νs da ss then δ da nothing a ∷ ss′ else ss′
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 starA : ∀{S}(s0 : S)(da : DA S) → DA (List ∞(Maybe S))
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 starA s0 da = finalToInitial (acceptingInitial s0 da)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
452 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
453 acceptingInitial-just : ∀{i S} (s0 : S) (da : DA S) {s : S} →
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 lang (acceptingInitial s0 da) (just s) ≅⟨ i ⟩≅ lang da s
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
455 acceptingInitial-nothing : ∀{i S} (s0 : S) (da : DA S) →
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 lang (acceptingInitial s0 da) nothing ≅⟨ i ⟩≅ ε ∪ lang da s0
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
457 starA-lemma : ∀{i S}(da : DA S)(s0 : S)(ss : List ∞ (Maybe S))→
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 lang (starA s0 da) ss ≅⟨ i ⟩≅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 lang (powA (acceptingInitial s0 da)) ss · (lang da s0) *
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
460 starA-correct : ∀{i S} (da : DA S) (s0 : S) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
461 lang (starA s0 da) (nothing ∷ []) ≅⟨ i ⟩≅ (lang da s0) *
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
463 record NAutomaton ( Q : Set ) ( Σ : Set )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
464 : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
465 field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
466 Nδ : Q → Σ → Q → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
467 Nstart : Q → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
468 Nend : Q → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
469
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
470 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
471 exists : { S : Set} → ( S → Bool ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
472
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
473 nlang : ∀{i} {S} (nfa : NAutomaton S A ) (s : S → Bool ) → Lang i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
474 Lang.ν (nlang nfa s) = exists ( λ x → (s x ∧ NAutomaton.Nend nfa x ))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
475 Lang.δ (nlang nfa s) a = nlang nfa (λ x → s x ∧ (NAutomaton.Nδ nfa x a) x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
476
119
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
477 nlang1 : ∀{i} {S} (nfa : NAutomaton S A ) (s : S → Bool ) → Lang i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
478 Lang.ν (nlang1 nfa s) = NAutomaton.Nend nfa {!!}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
479 Lang.δ (nlang1 nfa s) a = nlang1 nfa (λ x → s x ∧ (NAutomaton.Nδ nfa x a) x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 52
diff changeset
480
52
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
481 -- nlang' : ∀{i} {S} (nfa : DA (S → Bool) ) (s : S → Bool ) → Lang i
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
482 -- Lang.ν (nlang' nfa s) = DA.ν nfa s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
483 -- Lang.δ (nlang' nfa s) a = nlang' nfa (DA.δ nfa s a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 51
diff changeset
484