]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/multi_universal/moves_2.ma
progress
[helm.git] / matita / matita / lib / turing / multi_universal / moves_2.ma
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic   
3     ||A||  Library of Mathematics, developed at the Computer Science 
4     ||T||  Department of the University of Bologna, Italy.           
5     ||I||                                                            
6     ||T||  
7     ||A||  
8     \   /  This file is distributed under the terms of the       
9      \ /   GNU General Public License Version 2   
10       V_____________________________________________________________*)
11
12 include "turing/turing.ma".
13 include "turing/inject.ma".
14 include "turing/while_multi.ma".
15 include "turing/while_machine.ma".
16
17 definition parmove_states ≝ initN 3.
18
19 definition parmove0 : parmove_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
20 definition parmove1 : parmove_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
21 definition parmove2 : parmove_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
22
23 (*
24
25 src: a b c ... z ---→ a b c ... z 
26      ^                            ^
27
28 dst: _ _ _ ... _ ---→ a b c ... z 
29      ^                            ^
30
31 0) (x,_) → (x,_)(R,R) → 1
32    (None,_) → None 2
33 1) (_,_) → None 1
34 2) (_,_) → None 2
35
36 *)
37
38 definition trans_parmove_step ≝ 
39  λsrc,dst,sig,n,D.
40  λp:parmove_states × (Vector (option sig) (S n)).
41  let 〈q,a〉 ≝ p in
42  match pi1 … q with
43  [ O ⇒ match nth src ? a (None ?) with
44    [ None ⇒ 〈parmove2,null_action sig n〉
45    | Some a0 ⇒ match nth dst ? a (None ?) with
46      [ None ⇒ 〈parmove2,null_action ? n〉
47      | Some a1 ⇒ 〈parmove1,change_vec ? (S n)
48                           (change_vec ?(S n)
49                            (null_action ? n) (〈None ?,D〉) src)
50                           (〈None ?,D〉) dst〉 ] ]
51  | S q ⇒ match q with 
52    [ O ⇒ (* 1 *) 〈parmove1,null_action ? n〉
53    | S _ ⇒ (* 2 *) 〈parmove2,null_action ? n〉 ] ].
54
55 definition parmove_step ≝ 
56   λsrc,dst,sig,n,D.
57   mk_mTM sig n parmove_states (trans_parmove_step src dst sig n D) 
58     parmove0 (λq.q == parmove1 ∨ q == parmove2).
59
60 definition R_parmove_step_true ≝ 
61   λsrc,dst,sig,n,D.λint,outt: Vector (tape sig) (S n).
62   ∃x1,x2.
63    current ? (nth src ? int (niltape ?)) = Some ? x1 ∧
64    current ? (nth dst ? int (niltape ?)) = Some ? x2 ∧
65    outt = change_vec ?? 
66             (change_vec ?? int
67               (tape_move ? (nth src ? int (niltape ?)) D) src)
68             (tape_move ? (nth dst ? int (niltape ?)) D) dst.
69
70 definition R_parmove_step_false ≝ 
71   λsrc,dst:nat.λsig,n.λint,outt: Vector (tape sig) (S n).
72   (current ? (nth src ? int (niltape ?)) = None ?  ∨
73    current ? (nth dst ? int (niltape ?)) = None ?) ∧
74    outt = int.
75
76 lemma parmove_q0_q2_null_src :
77   ∀src,dst,sig,n,D,v.src < S n → dst < S n → 
78   nth src ? (current_chars ?? v) (None ?) = None ? → 
79   step sig n (parmove_step src dst sig n D)
80     (mk_mconfig ??? parmove0 v) =
81     mk_mconfig ??? parmove2 v.
82 #src #dst #sig #n #D #v #Hsrc #Hdst #Hcurrent
83 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
84 @eq_f2
85 [ whd in ⊢ (??(???%)?); >Hcurrent %
86 | whd in ⊢ (??(????(???%))?); >Hcurrent @tape_move_null_action ]
87 qed.
88
89 lemma parmove_q0_q2_null_dst :
90   ∀src,dst,sig,n,D,v,s.src < S n → dst < S n → 
91   nth src ? (current_chars ?? v) (None ?) = Some ? s → 
92   nth dst ? (current_chars ?? v) (None ?) = None ? → 
93   step sig n (parmove_step src dst sig n D)
94     (mk_mconfig ??? parmove0 v) =
95     mk_mconfig ??? parmove2 v.
96 #src #dst #sig #n #D #v #s #Hsrc #Hdst #Hcursrc #Hcurdst
97 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
98 @eq_f2
99 [ whd in ⊢ (??(???%)?); >Hcursrc whd in ⊢ (??(???%)?); >Hcurdst %
100 | whd in ⊢ (??(????(???%))?); >Hcursrc
101   whd in ⊢ (??(????(???%))?); >Hcurdst @tape_move_null_action ]
102 qed.
103
104 lemma parmove_q0_q1 :
105   ∀src,dst,sig,n,D,v.src ≠ dst → src < S n → dst < S n → 
106   ∀a1,a2.
107   nth src ? (current_chars ?? v) (None ?) = Some ? a1 →
108   nth dst ? (current_chars ?? v) (None ?) = Some ? a2 → 
109   step sig n (parmove_step src dst sig n D)
110     (mk_mconfig ??? parmove0 v) =
111     mk_mconfig ??? parmove1 
112      (change_vec ? (S n) 
113        (change_vec ?? v
114          (tape_move ? (nth src ? v (niltape ?)) D) src)
115        (tape_move ? (nth dst ? v (niltape ?)) D) dst).
116 #src #dst #sig #n #D #v #Hneq #Hsrc #Hdst
117 #a1 #a2 #Hcursrc #Hcurdst
118 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
119 [ whd in match (trans ????);
120   >Hcursrc >Hcurdst %
121 | whd in match (trans ????);
122   >Hcursrc >Hcurdst whd in ⊢ (??(????(???%))?); 
123   >tape_move_multi_def <(change_vec_same ?? v dst (niltape ?)) in ⊢ (??%?);
124   >pmap_change <(change_vec_same ?? v src (niltape ?)) in ⊢(??%?);
125   >pmap_change <tape_move_multi_def >tape_move_null_action
126   @eq_f2 // >nth_change_vec_neq //
127 ]
128 qed.
129
130 lemma sem_parmove_step :
131   ∀src,dst,sig,n,D.src ≠ dst → src < S n → dst < S n → 
132   parmove_step src dst sig n D ⊨ 
133     [ parmove1: R_parmove_step_true src dst sig n D, 
134              R_parmove_step_false src dst sig n ].
135 #src #dst #sig #n #D #Hneq #Hsrc #Hdst #int
136 lapply (refl ? (current ? (nth src ? int (niltape ?))))
137 cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?);
138 [ #Hcursrc %{2} %
139   [| % [ %
140     [ whd in ⊢ (??%?); >parmove_q0_q2_null_src /2/
141     | normalize in ⊢ (%→?); #H destruct (H) ]
142     | #_ % // % // ] ]
143 | #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?))))
144   cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
145   [ #Hcurdst %{2} %
146     [| % [ %
147       [ whd in ⊢ (??%?); >(parmove_q0_q2_null_dst …) /2/ 
148       | normalize in ⊢ (%→?); #H destruct (H) ]
149       | #_ % // %2 // ] ]
150   | #b #Hb %{2} %
151     [| % [ % 
152       [whd in ⊢  (??%?); >(parmove_q0_q1 … Hneq Hsrc Hdst ? b ??)
153         [2: <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
154         |3: <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
155         | // ]
156       | #_ %{a} %{b} % // % // ]
157       | * #H @False_ind @H % ]
158 ]]]
159 qed.
160
161 definition parmove ≝ λsrc,dst,sig,n,D.
162   whileTM … (parmove_step src dst sig n D) parmove1.
163
164 definition R_parmoveL ≝ 
165   λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
166   (∀x,xs,rs.
167     nth src ? int (niltape ?) = midtape sig xs x rs → 
168     ∀ls0,x0,target,rs0.|xs| = |target| → 
169     nth dst ? int (niltape ?) = midtape sig (target@ls0) x0 rs0 → 
170     outt = change_vec ?? 
171            (change_vec ?? int (mk_tape sig [] (None ?) (reverse ? xs@x::rs)) src)
172            (mk_tape sig (tail ? ls0) (option_hd ? ls0) (reverse ? target@x0::rs0)) dst) ∧
173   (∀x,xs,rs.
174     nth dst ? int (niltape ?) = midtape sig xs x rs → 
175     ∀ls0,x0,target,rs0.|xs| = |target| → 
176     nth src ? int (niltape ?) = midtape sig (target@ls0) x0 rs0 → 
177     outt = change_vec ?? 
178            (change_vec ?? int (mk_tape sig [] (None ?) (reverse ? xs@x::rs)) dst)
179            (mk_tape sig (tail ? ls0) (option_hd ? ls0) (reverse ? target@x0::rs0)) src) ∧
180   ((current ? (nth src ? int (niltape ?)) = None ? ∨
181     current ? (nth dst ? int (niltape ?)) = None ?) →
182     outt = int).
183   
184 lemma wsem_parmoveL : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n → 
185   parmove src dst sig n L ⊫ R_parmoveL src dst sig n.
186 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
187 lapply (sem_while … (sem_parmove_step src dst sig n L Hneq Hsrc Hdst) … Hloop) //
188 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
189 [ whd in ⊢ (%→?); * #H #Houtc % [2: #_ @Houtc ] cases H #Hcurtb
190   [ % 
191     [ #x #xs #rs #Hsrctb >Hsrctb in Hcurtb; normalize in ⊢ (%→?);
192       #Hfalse destruct (Hfalse)
193     | #x #xs #rs #Hdsttb #ls0 #x0 #target #rs0 #Hlen #Hsrctb >Hsrctb in Hcurtb;
194       normalize in ⊢ (%→?); #H destruct (H)
195     ]
196   | %
197     [ #x #xs #rs #Hsrctb #ls0 #x0 #target 
198       #rs0 #Hlen #Hdsttb >Hdsttb in Hcurtb; normalize in ⊢ (%→?); #H destruct (H)
199     | #x #xs #rs #Hdsttb >Hdsttb in Hcurtb; normalize in ⊢ (%→?);
200       #Hfalse destruct (Hfalse)
201     ]
202   ]  
203 | #td #te * #c0 * #c1 * * #Hc0 #Hc1 #Hd #Hstar #IH #He 
204   lapply (IH He) -IH * * #IH1a #IH1b #IH2 % [ %
205   [ #x #xs #rs #Hsrc_td #ls0 #x0 #target
206     #rs0 #Hlen #Hdst_td
207     >Hsrc_td in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
208     >Hdst_td in Hd; >Hsrc_td @(list_cases2 … Hlen)
209     [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2 
210       [2: %1 >Hd >nth_change_vec_neq [|@(sym_not_eq … Hneq)]
211       >nth_change_vec //]  
212       >Hd -Hd @(eq_vec … (niltape ?))
213       #i #Hi cases (decidable_eq_nat i src) #Hisrc
214       [ >Hisrc >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
215         >nth_change_vec //
216         >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
217         >nth_change_vec //
218       | cases (decidable_eq_nat i dst) #Hidst
219         [ >Hidst >nth_change_vec // >nth_change_vec //
220           >Hdst_td in Hc1; >Htargetnil
221           normalize in ⊢ (%→?); #Hc1 destruct (Hc1) cases ls0 //
222         | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
223           >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
224           >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
225           >nth_change_vec_neq [|@(sym_not_eq … Hisrc)] % 
226         ]
227       ]
228     | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
229       >(IH1a hd1 tl1 (c0::rs) ? ls0 hd2 tl2 (x0::rs0))
230       [ >Hd >(change_vec_commute … ?? td ?? src dst) //
231         >change_vec_change_vec
232         >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
233         >change_vec_change_vec
234         >reverse_cons >associative_append
235         >reverse_cons >associative_append % 
236       | >Hd >nth_change_vec //
237       | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
238       | >Hd >nth_change_vec_neq [|@sym_not_eq //]
239         >nth_change_vec // ]
240     ]
241   | #x #xs #rs #Hdst_td #ls0 #x0 #target
242     #rs0 #Hlen #Hsrc_td
243     >Hdst_td in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
244     >Hsrc_td in Hd; >Hdst_td @(list_cases2 … Hlen)
245     [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2 
246       [2: %2 >Hd >nth_change_vec //]
247       >Hd -Hd @(eq_vec … (niltape ?))
248       #i #Hi cases (decidable_eq_nat i dst) #Hidst
249       [ >Hidst >(nth_change_vec_neq … dst src) //
250         >nth_change_vec // >nth_change_vec //
251       | cases (decidable_eq_nat i src) #Hisrc
252         [ >Hisrc >nth_change_vec // >(nth_change_vec_neq …) [|@sym_not_eq //]
253           >Hsrc_td in Hc1; >Htargetnil
254           normalize in ⊢ (%→?); #Hc1 destruct (Hc1) >nth_change_vec //
255           cases ls0 //
256         | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
257           >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
258           >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
259           >nth_change_vec_neq [|@(sym_not_eq … Hidst)] % 
260         ]
261       ]
262     | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
263       >(IH1b hd1 tl1 (x::rs) ? ls0 hd2 tl2 (x0::rs0))
264       [ >Hd >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
265         >change_vec_change_vec
266         >(change_vec_commute … ?? td ?? src dst) //
267         >change_vec_change_vec
268         >reverse_cons >associative_append
269         >reverse_cons >associative_append
270         >change_vec_commute [|@sym_not_eq //] %
271       | >Hd >nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec //
272       | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
273       | >Hd >nth_change_vec // ]
274     ]
275   ]
276 | >Hc0 >Hc1 * [ #Hc0 destruct (Hc0) | #Hc1 destruct (Hc1) ]
277 ] ]
278 qed.
279  
280 lemma terminate_parmoveL :  ∀src,dst,sig,n,t.
281   src ≠ dst → src < S n → dst < S n → 
282   parmove src dst sig n L ↓ t.
283 #src #dst #sig #n #t #Hneq #Hsrc #Hdst
284 @(terminate_while … (sem_parmove_step …)) //
285 <(change_vec_same … t src (niltape ?))
286 cases (nth src (tape sig) t (niltape ?))
287 [ % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct 
288 |2,3: #a0 #al0 % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
289 | #ls lapply t -t elim ls
290   [#t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?);
291    #H1 destruct (H1) #Hcurdst >change_vec_change_vec #Ht1 % 
292    #t2 * #y1 * #y2 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
293    >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
294   |#l0 #ls0 #IH #t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec //
295    normalize in ⊢ (%→?); #H destruct (H) #Hcurdst
296    >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
297   ]
298 ]
299 qed.
300
301 lemma sem_parmoveL : ∀src,dst,sig,n.
302   src ≠ dst → src < S n → dst < S n → 
303   parmove src dst sig n L ⊨ R_parmoveL src dst sig n.
304 #src #dst #sig #n #Hneq #Hsrc #Hdst @WRealize_to_Realize 
305 [/2/ | @wsem_parmoveL //]
306 qed.
307
308 (* while {
309      if current != null 
310         then move_r
311         else nop
312      }
313  *)
314  
315 definition mte_states ≝ initN 3.
316 definition mte0 : mte_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
317 definition mte1 : mte_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
318 definition mte2 : mte_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
319
320 definition mte_step ≝ 
321   λalpha:FinSet.λD.mk_TM alpha mte_states
322   (λp.let 〈q,a〉 ≝ p in
323     match a with
324     [ None ⇒ 〈mte1,None ?,N〉
325     | Some a' ⇒ match (pi1 … q) with
326       [ O ⇒ 〈mte2,Some ? a',D〉
327       | S q ⇒ 〈mte2,None ?,N〉 ] ])
328   mte0 (λq.q == mte1 ∨ q == mte2).
329   
330 definition R_mte_step_true ≝ λalpha,D,t1,t2.
331   ∃ls,c,rs.
332     t1 = midtape alpha ls c rs ∧ t2 = tape_move ? t1 D.
333
334 definition R_mte_step_false ≝ λalpha.λt1,t2:tape alpha.
335   current ? t1 = None ? ∧ t1 = t2.
336
337 lemma sem_mte_step :
338   ∀alpha,D.mte_step alpha D ⊨ [ mte2 : R_mte_step_true alpha D, R_mte_step_false alpha ] .
339 #alpha #D #intape @(ex_intro ?? 2) cases intape
340 [ @ex_intro
341   [| % [ % [ % | normalize #H destruct ] | #_ % // ] ]
342 |#a #al @ex_intro
343   [| % [ % [ % | normalize #H destruct ] | #_ % // ] ]
344 |#a #al @ex_intro
345   [| % [ % [ % | normalize #H destruct ] | #_ % // ] ]
346 | #ls #c #rs
347   @ex_intro [| % [ % [ % | #_ %{ls} %{c} %{rs} % // ]
348                      | normalize in ⊢ (?(??%?)→?); * #H @False_ind /2/ ] ] ]
349 qed.
350
351 definition move_to_end ≝ λsig,D.whileTM sig (mte_step sig D) mte2.
352
353 definition R_move_to_end_r ≝ 
354   λsig,int,outt.
355   (current ? int = None ? → outt = int) ∧
356   ∀ls,c,rs.int = midtape sig ls c rs → outt = mk_tape ? (reverse ? rs@c::ls) (None ?) [ ].
357   
358 lemma wsem_move_to_end_r : ∀sig. move_to_end sig R ⊫ R_move_to_end_r sig.
359 #sig #ta #k #outc #Hloop
360 lapply (sem_while … (sem_mte_step sig R) … Hloop) //
361 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
362 [ * #Hcurtb #Houtc % /2/ #ls #c #rs #Htb >Htb in Hcurtb; normalize in ⊢ (%→?); #H destruct (H)
363 | #tc #td * #ls * #c * #rs * #Htc >Htc cases rs
364   [ normalize in ⊢ (%→?); #Htd >Htd #Hstar #IH whd in ⊢ (%→?); #Hfalse
365     lapply (IH Hfalse) -IH * #Htd1 #_ %
366     [ normalize in ⊢ (%→?); #H destruct (H)
367     | #ls0 #c0 #rs0 #H destruct (H) >Htd1 // ]
368   | #r0 #rs0 whd in ⊢ (???%→?); #Htd >Htd #Hstar #IH whd in ⊢ (%→?); #Hfalse
369     lapply (IH Hfalse) -IH * #_ #IH %
370     [ normalize in ⊢ (%→?); #H destruct (H)
371     | #ls1 #c1 #rs1 #H destruct (H) >reverse_cons >associative_append @IH % ] ] ]
372 qed.
373
374 lemma terminate_move_to_end_r :  ∀sig,t.move_to_end sig R ↓ t.
375 #sig #t @(terminate_while … (sem_mte_step sig R …)) //
376 cases t
377 [ % #t1 * #ls * #c * #rs * #H destruct
378 |2,3: #a0 #al0 % #t1 * #ls * #c * #rs * #H destruct
379 | #ls #c #rs lapply c -c lapply ls -ls elim rs
380   [ #ls #c % #t1 * #ls0 * #c0 * #rs0 * #Hmid #Ht1 destruct %
381     #t2 * #ls1 * #c1 * #rs1 * normalize in ⊢ (%→?); #H destruct
382   | #r0 #rs0 #IH #ls #c % #t1 * #ls1 * #c1 * #rs1 * #Hmid #Ht1 destruct @IH
383   ]
384 ]
385 qed.
386
387 lemma sem_move_to_end_r : ∀sig. move_to_end sig R ⊨ R_move_to_end_r sig.
388 #sig @WRealize_to_Realize //
389 qed.
390
391 definition R_move_to_end_l ≝ 
392   λsig,int,outt.
393   (current ? int = None ? → outt = int) ∧
394   ∀ls,c,rs.int = midtape sig ls c rs → outt = mk_tape ? [ ] (None ?) (reverse ? ls@c::rs).
395   
396 lemma wsem_move_to_end_l : ∀sig. move_to_end sig L ⊫ R_move_to_end_l sig.
397 #sig #ta #k #outc #Hloop
398 lapply (sem_while … (sem_mte_step sig L) … Hloop) //
399 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
400 [ * #Hcurtb #Houtc % /2/ #ls #c #rs #Htb >Htb in Hcurtb; normalize in ⊢ (%→?); #H destruct (H)
401 | #tc #td * #ls * #c * #rs * #Htc >Htc cases ls
402   [ normalize in ⊢ (%→?); #Htd >Htd #Hstar #IH whd in ⊢ (%→?); #Hfalse
403     lapply (IH Hfalse) -IH * #Htd1 #_ %
404     [ normalize in ⊢ (%→?); #H destruct (H)
405     | #ls0 #c0 #rs0 #H destruct (H) >Htd1 // ]
406   | #l0 #ls0 whd in ⊢ (???%→?); #Htd >Htd #Hstar #IH whd in ⊢ (%→?); #Hfalse
407     lapply (IH Hfalse) -IH * #_ #IH %
408     [ normalize in ⊢ (%→?); #H destruct (H)
409     | #ls1 #c1 #rs1 #H destruct (H) >reverse_cons >associative_append @IH % ] ] ]
410 qed.
411
412 lemma terminate_move_to_end_l :  ∀sig,t.move_to_end sig L ↓ t.
413 #sig #t @(terminate_while … (sem_mte_step sig L …)) //
414 cases t
415 [ % #t1 * #ls * #c * #rs * #H destruct
416 |2,3: #a0 #al0 % #t1 * #ls * #c * #rs * #H destruct
417 | #ls elim ls
418   [ #c #rs % #t1 * #ls0 * #c0 * #rs0 * #Hmid #Ht1 destruct %
419     #t2 * #ls1 * #c1 * #rs1 * normalize in ⊢ (%→?); #H destruct
420   | #l0 #ls0 #IH #c #rs % #t1 * #ls1 * #c1 * #rs1 * #Hmid #Ht1 destruct @IH
421   ]
422 ]
423 qed.
424
425 lemma sem_move_to_end_l : ∀sig. move_to_end sig L ⊨ R_move_to_end_l sig.
426 #sig @WRealize_to_Realize //
427 qed.