2 \ 5h1
\ 6Moves
\ 5/h1
\ 6We now define the move operation, that corresponds to the advancement of the
3 state in response to the processing of an input character a. The intuition is
4 clear: we have to look at points inside $e$ preceding the given character a,
5 let the point traverse the character, and broadcast it. All other points must
8 We can give a particularly elegant definition in terms of the
9 lifted operators of the previous section:
12 include "tutorial/chapter8.ma".
14 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
18 | ps y ⇒ 〈 `y, false 〉
19 | pp y ⇒ 〈 `y, x == y 〉
20 | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2)
21 | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2)
22 | pk e ⇒ (move ? x e)^⊛ ].
24 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
25 move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
28 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
29 move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
32 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
33 move S x i^* = (move ? x i)^⊛.
37 Example. Let us consider the item
39 (•a + ϵ)((•b)*•a + •b)b
41 and the two moves w.r.t. the characters a and b.
42 For a, we have two possible positions (all other points gets erased); the innermost
43 point stops in front of the final b, while the other one broadcast inside (b^*a + b)b,
46 move((•a + ϵ)((•b)*•a + •b)b,a) = 〈(a + ϵ)((•b)^*•a + •b)•b, false〉
48 For b, we have two positions too. The innermost point stops in front of the final b too,
49 while the other point reaches the end of b* and must go back through b*a:
51 move((•a + ϵ)((•b)*•a + •b)b ,b) = 〈(a + ϵ)((•b)*•a + b)•b, false〉
55 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
57 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b.
58 pmove ? x 〈i,b〉 = move ? x i.
61 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b.
62 a::l1 = b::l2 → a = b.
63 #A #l1 #l2 #a #b #H destruct //
66 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
67 |\fst (move ? a i)| = |i|.
69 [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
70 |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); //
75 ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S.
76 \sem{move ? a i} w ↔ \sem{i} (a::w).
81 |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
82 [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
83 |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
85 |#i1 #i2 #HI1 #HI2 #w >move_cat
86 @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
87 @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r
88 @iff_trans[||@iff_sym @deriv_middot //]
90 |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w
91 @iff_trans[|@sem_oplus]
92 @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
93 |#i1 #HI1 #w >move_star
94 @iff_trans[|@sem_ostar] >same_kernel >sem_star_w
95 @iff_trans[||@iff_sym @deriv_middot //]
100 notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}.
101 let rec moves (S : DeqSet) w e on w : pre S ≝
104 | cons x w' ⇒ w' ↦* (move S x (\fst e))].
106 lemma moves_empty: ∀S:DeqSet.∀e:pre S.
110 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S.
111 moves ? (a::w) e = moves ? w (move S a (\fst e)).
114 lemma moves_left : ∀S,a,w,e.
115 moves S (w@[a]) e = move S a (\fst (moves S w e)).
116 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
119 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S.
120 iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
121 #S #a #w * #i #b cases b normalize
122 [% /2/ * // #H destruct |% normalize /2/]
125 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
126 |\fst (moves ? w e)| = |\fst e|.
130 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S.
131 (\snd (moves ? w e) = true) ↔ \sem{e} w.
133 [* #i #b >moves_empty cases b % /2/
134 |#a #w1 #Hind #e >moves_cons
135 @iff_trans [||@iff_sym @not_epsilon_sem]
136 @iff_trans [||@move_ok] @Hind
140 (************************ pit state ***************************)
141 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉.
143 let rec occur (S: DeqSet) (i: re S) on i ≝
148 | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
149 | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
152 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true →
153 move S a i = pit_pre S i.
155 [#x normalize cases (a==x) normalize // #H @False_ind /2/
156 |#i1 #i2 #Hind1 #Hind2 #H >move_cat
157 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
158 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
159 |#i1 #i2 #Hind1 #Hind2 #H >move_plus
160 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
161 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
162 |#i #Hind #H >move_star >Hind //
166 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
168 [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 //
169 |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 //
170 |#i #Hind >move_star >Hind //
174 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
178 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
179 moves S w e = pit_pre S (\fst e).
181 [#e * #H @False_ind @H normalize #a #abs @False_ind /2/
182 |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
183 [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a)
184 @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
185 [#H2 >(\P H2) // |#H2 @H1 //]
186 |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/