2 \ 5h1
\ 6Moves
\ 5/h1
\ 6*)
6 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
10 | ps y ⇒ 〈 `y, false 〉
11 | pp y ⇒ 〈 `y, x == y 〉
12 | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2)
13 | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2)
14 | pk e ⇒ (move ? x e)^⊛ ].
16 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
17 move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
20 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
21 move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
24 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
25 move S x i^* = (move ? x i)^⊛.
29 Example. Let us consider the item
31 (•a + ϵ)((•b)*•a + •b)b
33 and the two moves w.r.t. the characters a and b.
34 For a, we have two possible positions (all other points gets erased); the innermost
35 point stops in front of the final b, while the other one broadcast inside (b^*a + b)b,
38 move((•a + ϵ)((•b)*•a + •b)b,a) = 〈(a + ϵ)((•b)^*•a + •b)•b, false〉
40 For b, we have two positions too. The innermost point stops in front of the final b too,
41 while the other point reaches the end of b* and must go back through b*a:
43 move((•a + ϵ)((•b)*•a + •b)b ,b) = 〈(a + ϵ)((•b)*•a + b)•b, false〉
47 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
49 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b.
50 pmove ? x 〈i,b〉 = move ? x i.
53 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b.
54 a::l1 = b::l2 → a = b.
55 #A #l1 #l2 #a #b #H destruct //
58 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
59 |\fst (move ? a i)| = |i|.
61 [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
62 |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); //
67 ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S.
68 \sem{move ? a i} w ↔ \sem{i} (a::w).
73 |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
74 [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
75 |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
77 |#i1 #i2 #HI1 #HI2 #w >move_cat
78 @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
79 @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r
80 @iff_trans[||@iff_sym @deriv_middot //]
82 |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w
83 @iff_trans[|@sem_oplus]
84 @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
85 |#i1 #HI1 #w >move_star
86 @iff_trans[|@sem_ostar] >same_kernel >sem_star_w
87 @iff_trans[||@iff_sym @deriv_middot //]
92 notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}.
93 let rec moves (S : DeqSet) w e on w : pre S ≝
96 | cons x w' ⇒ w' ↦* (move S x (\fst e))].
98 lemma moves_empty: ∀S:DeqSet.∀e:pre S.
102 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S.
103 moves ? (a::w) e = moves ? w (move S a (\fst e)).
106 lemma moves_left : ∀S,a,w,e.
107 moves S (w@[a]) e = move S a (\fst (moves S w e)).
108 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
111 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S.
112 iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
113 #S #a #w * #i #b cases b normalize
114 [% /2/ * // #H destruct |% normalize /2/]
117 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
118 |\fst (moves ? w e)| = |\fst e|.
122 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S.
123 (\snd (moves ? w e) = true) ↔ \sem{e} w.
125 [* #i #b >moves_empty cases b % /2/
126 |#a #w1 #Hind #e >moves_cons
127 @iff_trans [||@iff_sym @not_epsilon_sem]
128 @iff_trans [||@move_ok] @Hind
132 (************************ pit state ***************************)
133 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉.
135 let rec occur (S: DeqSet) (i: re S) on i ≝
140 | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
141 | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
144 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true →
145 move S a i = pit_pre S i.
147 [#x normalize cases (a==x) normalize // #H @False_ind /2/
148 |#i1 #i2 #Hind1 #Hind2 #H >move_cat
149 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
150 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
151 |#i1 #i2 #Hind1 #Hind2 #H >move_plus
152 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
153 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
154 |#i #Hind #H >move_star >Hind //
158 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
160 [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 //
161 |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 //
162 |#i #Hind >move_star >Hind //
166 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
170 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
171 moves S w e = pit_pre S (\fst e).
173 [#e * #H @False_ind @H normalize #a #abs @False_ind /2/
174 |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
175 [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a)
176 @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
177 [#H2 >(\P H2) // |#H2 @H1 //]
178 |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/