annotate agda/flcagl.agda @ 47:dfc2f65b07ea

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 06 Apr 2019 01:33:16 +0900
parents 964e4bd0272a
children 68e5f56cf01f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 open import Relation.Nullary
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 open import Relation.Binary.PropositionalEquality
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 module flcagl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 (A : Set)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ( _≟_ : (a b : A) → Dec ( a ≡ b ) ) where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Bool hiding ( _≟_ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 -- open import Data.Maybe
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Level renaming ( zero to Zero ; suc to succ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Size
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 module List where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 data List (i : Size) (A : Set) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 [] : List i A
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 _∷_ : {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
17
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 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
20 map f [] = []
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 map f ( x ∷ xs)= f x ∷ map f xs
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 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
24 foldr c n [] = n
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 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
26
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 any : ∀{i A} → (A → Bool) → List i A → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 any p xs = foldr _∨_ false (map p xs)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 module Lang where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 open List
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 record Lang (i : Size) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 coinductive
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 field
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 ν : Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 δ : ∀{j : Size< i} → A → Lang j
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 open Lang
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 _∋_ : ∀{i} → Lang i → List i A → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 l ∋ [] = ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 l ∋ ( a ∷ as ) = δ l a ∋ as
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 trie : ∀{i} (f : List i A → Bool) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 ν (trie f) = f []
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 δ (trie f) a = trie (λ as → f (a ∷ as))
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 ∅ : ∀{i} → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ν ∅ = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 δ ∅ x = ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 ε : ∀{i} → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 ν ε = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 δ ε x = ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 open import Relation.Nullary.Decidable
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 char : ∀{i} (a : A) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 ν (char a) = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 δ (char a) x = if ⌊ a ≟ x ⌋ then ε else ∅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 compl : ∀{i} (l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 ν (compl l) = not (ν l)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 δ (compl l) x = compl (δ l x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
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 _∪_ : ∀{i} (k l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 ν (k ∪ l) = ν k ∨ ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 δ (k ∪ l) x = δ k x ∪ δ l x
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
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 _·'_ : ∀{i} (k l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 ν (k ·' l) = ν k ∧ ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 δ (k ·' l) x = let k′l = δ k x ·' l in if ν k then k′l ∪ δ l x else k′l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 _·_ : ∀{i} (k l : Lang i ) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 ν (k · l) = ν k ∧ ν l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 δ (_·_ {i} k l) {j} x =
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 let
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 k′l : Lang j
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 k′l = _·_ {j} (δ k {j} x) l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 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
85
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 _* : ∀{i} (l : Lang i) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 ν (l *) = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 δ (l *) x = δ l x · (l *)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 record _≅⟨_⟩≅_ (l : Lang ∞ ) i (k : Lang ∞) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 coinductive
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 field ≅ν : ν l ≡ ν k
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 ≅δ : ∀ {j : Size< i } (a : A ) → δ l a ≅⟨ j ⟩≅ δ k a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 open _≅⟨_⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 ≅refl : ∀{i} {l : Lang ∞} → l ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ≅ν ≅refl = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ≅δ ≅refl a = ≅refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
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 ≅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
103 ≅ν (≅sym p) = sym (≅ν p)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 ≅δ (≅sym p) a = ≅sym (≅δ p a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 ≅trans : ∀{i} {k l m : Lang ∞}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 ( 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
108 ≅ν (≅trans p q) = trans (≅ν p) (≅ν q)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 ≅δ (≅trans p q) a = ≅trans (≅δ p a) (≅δ q a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 open import Relation.Binary
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 ≅isEquivalence : ∀(i : Size) → IsEquivalence _≅⟨ i ⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 ≅isEquivalence i = record { refl = ≅refl; sym = ≅sym; trans = ≅trans }
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 Bis : ∀(i : Size) → Setoid _ _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 Setoid.Carrier (Bis i) = Lang ∞
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 Setoid._≈_ (Bis i) = _≅⟨ i ⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 Setoid.isEquivalence (Bis i) = ≅isEquivalence i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 import Relation.Binary.EqReasoning as EqR
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 ≅trans′ : ∀ i (k l m : Lang ∞)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 ( 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
125 ≅trans′ i k l m p q = begin
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 k ≈⟨ p ⟩
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 l ≈⟨ q ⟩
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 m ∎ where open EqR (Bis i)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 open import Data.Bool.Properties
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 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
133 ≅ν (union-assoc k) = ∨-assoc (ν k) _ _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 ≅δ (union-assoc k) a = union-assoc (δ k a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 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
136 ≅ν (union-comm l k) = ∨-comm (ν l) _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 ≅δ (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
138 union-idem : ∀{i} (l : Lang ∞) → (l ∪ l ) ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 ≅ν (union-idem l) = ∨-idem _
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 ≅δ (union-idem l) a = union-idem (δ l a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 union-emptyl : ∀{i}{l : Lang ∞} → (∅ ∪ l ) ≅⟨ i ⟩≅ l
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 ≅ν union-emptyl = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 ≅δ union-emptyl a = union-emptyl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 union-cong : ∀{i}{k k′ l l′ : Lang ∞}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 (p : k ≅⟨ i ⟩≅ k′)(q : l ≅⟨ i ⟩≅ l′ ) → ( k ∪ l ) ≅⟨ i ⟩≅ ( k′ ∪ l′ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 ≅ν (union-cong p q) = cong₂ _∨_ (≅ν p) (≅ν q)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 ≅δ (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
149
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 -- union-union-distr : ∀{i} (k {l m} : Lang ∞) → ( ( k ∪ l ) ∪ m ) ≅⟨ i ⟩≅ ( ( k ∪ m ) ∪ ( l ∪ m ) )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 -- ≅ν (union-union-distr k) = {!!}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 -- ≅δ (union-union-distr k) a = {!!}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 withExample : (P : Bool → Set) (p : P true) (q : P false) →
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 {A : Set} (g : A → Bool) (x : A) → P (g x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 withExample P p q g x with g x
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 ... | true = p
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 ... | false = q
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 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
162 {g : A → A} (e : g x ≡ x) → P (g x)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 rewriteExample p e rewrite e = p
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
165 infixr 6 _∪_
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 infixr 7 _·_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 infix 5 _≅⟨_⟩≅_
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
168 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
169 concat-union-distribl : ∀{i} (k {l m} : Lang ∞) → ( k ∪ l ) · m ≅⟨ i ⟩≅ ( k · m ) ∪ ( l · m )
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 union-swap24 : {!!}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 union-swap24 = {!!}
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 concat-union-distribr : ∀{i} (k {l m} : Lang ∞) → k · ( l ∪ m ) ≅⟨ i ⟩≅ ( k · l ) ∪ ( k · m )
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
175 ≅ν (concat-union-distribr k) = {!!} -- ∧-distribʳ-∨ (ν k) _ _
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 ≅δ (concat-union-distribr k) a with ν k
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 ≅δ (concat-union-distribr k {l} {m}) a | true = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
178 δ k a · (l ∪ m) ∪ (δ l a ∪ δ m a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
179 -- ≈⟨ union-cong (concat-union-distribr (δ k a)) ⟩
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 ≈⟨ {!!} ⟩
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
181 (δ k a · l ∪ δ k a · m) ∪ (δ l a ∪ δ m a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
182 ≈⟨ {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
183 (δ 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
184
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 ≅δ (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
187
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
188 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
189 concat-congl : ∀{i} {m l k : Lang ∞} → l ≅⟨ i ⟩≅ k → l · m ≅⟨ i ⟩≅ k · m
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
190 concat-congr : ∀{i} {m l k : Lang ∞} → l ≅⟨ i ⟩≅ k → m · l ≅⟨ i ⟩≅ m · k
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
191 concat-assoc : ∀{i} (k {l m} : Lang ∞) → (k · l) · m ≅⟨ i ⟩≅ k · (l · m)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
192 concat-emptyl : ∀{i} l → ∅ · l ≅⟨ i ⟩≅ ∅
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
193 concat-emptyr : ∀{i} l → l · ∅ ≅⟨ i ⟩≅ ∅
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
194 concat-unitl : ∀{i} l → ε · l ≅⟨ i ⟩≅ l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
195 concat-unitr : ∀{i} l → l · ε ≅⟨ i ⟩≅ l
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
196 star-empty : ∀{i} → ∅ * ≅⟨ i ⟩≅ ε
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 star-concat-idem : ∀{i} (l : Lang ∞) → l * · l * ≅⟨ i ⟩≅ l *
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 ≅ν (star-concat-idem l) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 ≅δ (star-concat-idem l) a = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
201 δ ((l *) · (l *)) a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
202 ≈⟨ union-cong (concat-assoc _) ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
203 δ l a · (l * · l *) ∪ δ l a · l *
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
204 ≈⟨ union-cong (concat-congr (star-concat-idem _)) ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
205 δ l a · l * ∪ δ l a · l *
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
206 ≈⟨ union-idem _ ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
207 δ (l *) a
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 star-idem : ∀{i} (l : Lang ∞) → (l *) * ≅⟨ i ⟩≅ l *
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 ≅ν (star-idem l) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 ≅δ (star-idem l) a = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
213 δ ((l *) *) a ≈⟨ concat-assoc (δ l a) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
214 δ l a · (l *) · ((l *) *) ≈⟨ {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
215 δ l a · l * · l * ≈⟨ {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
216 δ l a · ((l *) *) ≈⟨ concat-congr (star-idem l) ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
217 δ l a · l *
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
220 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
221 star-rec : ∀{i} (l : Lang ∞) → l * ≅⟨ i ⟩≅ ε ∪ (l · l *)
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 star-from-rec : ∀{i} (k {l m} : Lang ∞)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 → ν k ≡ false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 → l ≅⟨ i ⟩≅ k · l ∪ m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 → l ≅⟨ i ⟩≅ k * · m
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 ≅ν (star-from-rec k n p) with ≅ν p
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
228 ... | b rewrite n = b
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 ≅δ (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
230 ... | q rewrite n = begin
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 (δ l a)
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
232 ≈⟨ q ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
233 δ k a · l ∪ δ m a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
234 ≈⟨ union-cong (concat-congr (star-from-rec k {l} {m} n p)) ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
235 (δ k a · (k * · m) ∪ δ m a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
236 ≈⟨ union-cong (≅sym (concat-assoc (δ k a))) ≅refl ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
237 (δ k a · (k *)) · m ∪ δ m a
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 open List
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 record DA (S : Set) : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 field ν : (s : S) → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 δ : (s : S)(a : A) → S
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 νs : ∀{i} (ss : List.List i S) → Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 νs ss = List.any ν ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 δ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
249 δs ss a = List.map (λ s → δ s a) ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 open Lang
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 lang : ∀{i} {S} (da : DA S) (s : S) → Lang i
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 Lang.ν (lang da s) = DA.ν da s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 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
256
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 open import Data.Unit hiding ( _≟_ )
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 open DA
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 ∅A : DA ⊤
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 ν ∅A s = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 δ ∅A s a = s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 εA : DA Bool
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 ν εA b = b
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 δ εA b a = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 open import Relation.Nullary.Decidable
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 data 3States : Set where
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 init acc err : 3States
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 charA : (a : A) → DA 3States
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 ν (charA a) init = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 ν (charA a) acc = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 ν (charA a) err = false
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 δ (charA a) init x =
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 if ⌊ a ≟ x ⌋ then acc else err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 δ (charA a) acc x = err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 δ (charA a) err x = err
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 complA : ∀{S} (da : DA S) → DA S
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 ν (complA da) s = not (ν da s)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 δ (complA da) s a = δ da s a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 open import Data.Product
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 _⊕_ : ∀{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
291 ν (da1 ⊕ da2) (s1 , s2) = ν da1 s1 ∨ ν da2 s2
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 δ (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
293
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 powA : ∀{S} (da : DA S) → DA (List ∞ S)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 ν (powA da) ss = νs da ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 δ (powA da) ss a = δs da ss a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 open _≅⟨_⟩≅_
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 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
301 ≅ν (powA-nil da) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 ≅δ (powA-nil da) a = powA-nil da
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 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
305 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
306 ≅ν (powA-cons da) = refl
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 ≅δ (powA-cons da) a = powA-cons da
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 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
310 ν (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
311 δ (composeA da1 s2 da2) (s1 , ss2) a =
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
312 δ 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
313
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 import Relation.Binary.EqReasoning as EqR
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 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
317 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
318 ≅ν (composeA-gen da1 da2 s1 s2 ss) = refl
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 ≅δ (composeA-gen da1 da2 s1 s2 ss) a with ν da1 s1
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
320 ... | 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
321 ... | true = begin
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
322 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
323 ≈⟨ 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
324 lang da1 (δ da1 s1 a) · lang da2 s2 ∪ lang (powA da2) (δs da2 (s2 ∷ ss) a)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
325 ≈⟨ {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
326 (lang da2 (δ da2 s2 a) ∪ lang (powA da2) (δs da2 ss a))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
327 ≈⟨ ≅sym {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
328 (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
329 ∎ where open EqR (Bis _)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
331 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
332 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
333 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
334
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 open import Data.Maybe
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 acceptingInitial : ∀{S} (s0 : S) (da : DA S) → DA (Maybe S)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 ν (acceptingInitial s0 da) (just s) = ν da s
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 δ (acceptingInitial s0 da) (just s) a = just (δ da s a)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 ν (acceptingInitial s0 da) nothing = true
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 δ (acceptingInitial s0 da) nothing a = just (δ da s0 a)
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
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 finalToInitial : ∀{S} (da : DA (Maybe S)) → DA (List ∞ (Maybe S))
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 ν (finalToInitial da) ss = νs da ss
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 δ (finalToInitial da) ss a =
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 let ss′ = δs da ss a
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 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
351
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 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
354 starA s0 da = finalToInitial (acceptingInitial s0 da)
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
357 postulate
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
358 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
359 lang (acceptingInitial s0 da) (just s) ≅⟨ i ⟩≅ lang da s
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
360 acceptingInitial-nothing : ∀{i S} (s0 : S) (da : DA S) →
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 lang (acceptingInitial s0 da) nothing ≅⟨ i ⟩≅ ε ∪ lang da s0
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
362 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
363 lang (starA s0 da) ss ≅⟨ i ⟩≅
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 lang (powA (acceptingInitial s0 da)) ss · (lang da s0) *
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
365 starA-correct : ∀{i S} (da : DA S) (s0 : S) →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 46
diff changeset
366 lang (starA s0 da) (nothing ∷ []) ≅⟨ i ⟩≅ (lang da s0) *
46
964e4bd0272a add coinduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367