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.
8 \ / This file is distributed under the terms of the
9 \ / GNU General Public License Version 2
10 V_____________________________________________________________*)
12 include "turing/multi_universal/moves_2.ma".
13 include "turing/multi_universal/match.ma".
14 include "turing/multi_universal/copy.ma".
15 include "turing/multi_universal/alphabet.ma".
16 include "turing/multi_universal/tuples.ma".
29 current (in.obj) = None
40 (if (current(in.obj)) == None
55 definition copy_char_states ≝ initN 3.
57 definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
58 definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
60 definition trans_copy_char ≝
61 λsrc,dst.λsig:FinSet.λn.
62 λp:copy_char_states × (Vector (option sig) (S n)).
65 [ O ⇒ 〈cc1,change_vec ? (S n)
66 (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
67 (〈nth src ? a (None ?),R〉) dst〉
68 | S _ ⇒ 〈cc1,null_action ? n〉 ].
70 definition copy_char ≝
72 mk_mTM sig n copy_char_states (trans_copy_char src dst sig n)
75 definition R_copy_char ≝
76 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
79 (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
80 (tape_move_mono ? (nth dst ? int (niltape ?))
81 〈current ? (nth src ? int (niltape ?)), R〉) dst.
83 lemma copy_char_q0_q1 :
84 ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n →
85 step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) =
89 (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
90 (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst).
91 #src #dst #sig #n #v #Heq #Hsrc #Hdst
93 <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
94 <(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
95 >tape_move_multi_def @eq_f2 //
96 >pmap_change >pmap_change <tape_move_multi_def
97 >tape_move_null_action @eq_f2 // @eq_f2
99 | >change_vec_same >change_vec_same // ]
103 ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
104 copy_char src dst sig n ⊨ R_copy_char src dst sig n.
105 #src #dst #sig #n #Hneq #Hsrc #Hdst #int
106 %{2} % [| % [ % | whd >copy_char_q0_q1 // ]]
109 definition obj ≝ (0:DeqNat).
110 definition cfg ≝ (1:DeqNat).
111 definition prg ≝ (2:DeqNat).
113 definition obj_to_cfg ≝
114 mmove cfg FSUnialpha 2 L ·
115 (ifTM ?? (inject_TM ? (test_null ?) 2 obj)
116 (copy_char obj cfg FSUnialpha 2 ·
117 mmove cfg FSUnialpha 2 L ·
118 mmove obj FSUnialpha 2 L)
119 (inject_TM ? (write FSUnialpha null) 2 cfg)
121 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
122 mmove cfg FSUnialpha 2 R.
124 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
126 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
127 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
128 t2 = change_vec ?? t1
129 (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧
130 (current ? (nth obj ? t1 (niltape ?)) = None ? →
131 t2 = change_vec ?? t1
132 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls)))
133 (tail ? (reverse ? (null::ls)))) cfg).
135 axiom accRealize_to_Realize :
136 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
137 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
139 lemma eq_mk_tape_rightof :
140 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
144 lemma tape_move_mk_tape_R :
146 (c = None ? → ls = [ ] ∨ rs = [ ]) →
147 tape_move ? (mk_tape sig ls c rs) R =
148 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
149 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
150 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
154 lemma eq_vec_change_vec : ∀sig,n.∀v1,v2:Vector sig n.∀i,t,d.
156 (∀j.i ≠ j → nth j ? v1 d = nth j ? v2 d) →
157 v2 = change_vec ?? v1 t i.
158 #sig #n #v1 #v2 #i #t #d #H1 #H2 @(eq_vec … d)
159 #i0 #Hlt cases (decidable_eq_nat i0 i) #Hii0
160 [ >Hii0 >nth_change_vec //
161 | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @H2 @sym_not_eq // ]
164 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
165 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
168 (sem_test_null_multi ?? obj ?)
169 (sem_seq ?????? (sem_copy_char …)
170 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
171 (sem_move_multi ? 2 obj L ?)))
172 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
173 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
174 (sem_move_multi ? 2 cfg R ?)))) //
176 #tc * whd in ⊢ (%→?); #Htc *
178 [ * #te * * #Hcurtc #Hte
179 * destruct (Hte) #te * whd in ⊢ (%→?); #Hte
180 cut (∃x.current ? (nth obj ? tc (niltape ?)) = Some ? x)
181 [ cases (current ? (nth obj ? tc (niltape ?))) in Hcurtc;
182 [ * #H @False_ind /2/ | #x #_ %{x} % ] ] * #x #Hcurtc'
183 (* [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte *)
184 * #tf * whd in ⊢ (%→%→?); #Htf #Htd
185 * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb
187 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
188 whd in match (tape_move ???); #Htc
189 cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
190 [ lapply (eq_vec_change_vec ??????? (Htg2 ls x [ ] ?) Htg3) //
191 >Htd >nth_change_vec_neq // >Htf >nth_change_vec //
192 >Hte >Hcurtc' >nth_change_vec // >Htc >nth_change_vec // ]
193 -Htg1 -Htg2 -Htg3 #Htg destruct
194 >change_vec_change_vec >change_vec_change_vec
195 >change_vec_commute // >change_vec_change_vec
196 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
197 >change_vec_commute // >change_vec_change_vec
198 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
199 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
200 >change_vec_commute [|@sym_not_eq //] @eq_f3 //
201 [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
202 [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
203 | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
204 | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
205 >nth_change_vec_neq in Hcurtc'; [|@sym_not_eq //] >Hta2
206 normalize in ⊢ (%→?); #H destruct (H) %
208 | #Hta2 >Htc in Hcurtc'; >nth_change_vec_neq [| @sym_not_eq //]
209 >Hta2 #H destruct (H)
211 | * #te * * #Hcurtc #Hte
212 * whd in ⊢ (%→%→?); #Htd1 #Htd2
213 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
215 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
216 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
217 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
218 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
219 [ lapply (eq_vec_change_vec ??????? (Htd1 ls c [ ] ?) Htd2) //
220 >Htc >nth_change_vec // ] -Htd1 -Htd2 #Htd
221 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
222 [ lapply (eq_vec_change_vec ??????? (Htf2 ls null [ ] ?) Htf3) //
223 >Htd >nth_change_vec // ] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
224 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
225 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
226 >reverse_cons >tape_move_mk_tape_R /2/ ]
230 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
232 definition R_test_null_char_true ≝ λt1,t2.
233 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
235 definition R_test_null_char_false ≝ λt1,t2.
236 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
238 lemma sem_test_null_char :
239 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
240 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
241 #Hfalse %{k} %{outc} % [ %
243 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
244 -Hcnull #H destruct (H) #Houtc1 %
245 [ @Hcurt1 | <Houtc1 % ] ]
246 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
247 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
248 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
253 definition cfg_to_obj ≝
254 mmove cfg FSUnialpha 2 L ·
255 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
257 (copy_char cfg obj FSUnialpha 2 ·
258 mmove cfg FSUnialpha 2 L ·
259 mmove obj FSUnialpha 2 L)
261 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
262 mmove cfg FSUnialpha 2 R.
264 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
266 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
268 t2 = change_vec ?? t1
269 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
270 (tail ? (reverse ? (c::ls)))) cfg) ∧
274 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
275 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
277 lemma tape_move_mk_tape_L :
279 (c = None ? → ls = [ ] ∨ rs = [ ]) →
280 tape_move ? (mk_tape sig ls c rs) L =
281 mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs).
282 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
283 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
287 lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
288 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
291 (acc_sem_inject ?????? cfg ? sem_test_null_char)
293 (sem_seq ?????? (sem_copy_char …)
294 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
295 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
296 (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
298 #tc * whd in ⊢ (%→?); #Htc *
300 [ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
301 * #tf * * * #Htf1 #Htf2 #Htf3
304 [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
306 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2) >change_vec_same // ]
308 cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
309 [ lapply (eq_vec_change_vec ??????? (Htf2 ls c [ ] ?) Htf3) //
310 >Hte >Htc >nth_change_vec // ] -Htf1 -Htf2 -Htf3 #Htf
311 destruct (Htf Hte Htc Htb)
312 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
313 >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ]
315 | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
316 >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?);
317 #H destruct (H) @False_ind cases Hc /2/ ]
319 | * #te * * * #Hcurtc #Hte1 #Hte2
320 * #tf * whd in ⊢ (%→?); #Htf
321 * #tg * whd in ⊢ (%→%→?); #Htg #Htd
322 * #th * * * #Hth1 #Hth2 #Hth3
325 [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L //
326 >Hc normalize in ⊢ (%→?); * #H @False_ind /2/
328 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2)
329 >change_vec_same // ] -Hte1 -Hte2 #Hte
330 cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
331 [ lapply (eq_vec_change_vec ??????? (Hth2 ls c [ ] ?) Hth3) //
332 >Htd >nth_change_vec_neq // >Htg >nth_change_vec //
333 >Htf >nth_change_vec_neq // >nth_change_vec //
334 >Hte >Htc >nth_change_vec // >Hta // ] -Hth1 -Hth2 -Hth3 #Hth
335 destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
336 >change_vec_change_vec >change_vec_change_vec
337 >change_vec_commute // >change_vec_change_vec
338 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
339 >change_vec_commute // >change_vec_change_vec
340 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
341 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
342 >change_vec_commute [|@sym_not_eq //]
344 [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??);
345 @eq_f2 // cases (nth obj ? ta (niltape ?))
346 [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try %
348 | >reverse_cons >tape_move_mk_tape_R // #_ % % ]
353 definition char_to_move ≝ λc.match c with
354 [ bit b ⇒ if b then R else L
357 definition char_to_bit_option ≝ λc.match c with
358 [ bit b ⇒ Some ? (bit b)
361 definition R_cfg_to_obj1 ≝ λt1,t2:Vector (tape FSUnialpha) 3.
363 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
366 tape_write ? (nth obj ? t1 (niltape ?)) (char_to_bit_option c) in
368 (change_vec ?? t1 new_obj obj)
369 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg.
371 lemma sem_cfg_to_obj1: cfg_to_obj ⊨ R_cfg_to_obj1.
372 @(Realize_to_Realize … sem_cfg_to_obj) #t1 #t2 #H #c #ls #Hcfg #Hbar
373 cases (H c ls Hcfg) cases (true_or_false (c==null)) #Hc
374 [#Ht2 #_ >(Ht2 (\P Hc)) -Ht2 @(eq_vec … (niltape ?))
375 #i #lei2 cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
376 [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
377 [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
378 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
379 >nth_change_vec_neq in ⊢ (???%); [2:@eqb_false_to_not_eq %]
380 >nth_change_vec // >(\P Hc) %
381 |#Hi >Hi >nth_change_vec //
383 |#Hi >Hi >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
384 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
385 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] %
387 |#_ #Ht2 >(Ht2 (\Pf Hc)) -Ht2 @(eq_vec … (niltape ?))
388 #i #lei2 cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
389 [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
390 [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
391 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
392 >nth_change_vec_neq in ⊢ (???%); [2:@eqb_false_to_not_eq %]
393 >nth_change_vec // >nth_change_vec //
394 lapply (\bf Hbar) lapply Hc elim c //
395 [whd in ⊢ (??%?→?); #H destruct (H)
396 |#_ whd in ⊢ (??%?→?); #H destruct (H)
398 |#Hi >Hi >nth_change_vec //
400 |#Hi >Hi >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
401 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
402 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] %
408 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
409 del current di prg, che codifica la direzione in cui ci muoviamo *)
411 definition tape_move_obj : mTM FSUnialpha 2 ≝
413 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
414 (mmove obj FSUnialpha 2 L)
416 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
417 (mmove obj FSUnialpha 2 R)
422 definition R_tape_move_obj' ≝ λt1,t2:Vector (tape FSUnialpha) 3.
423 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit false) →
424 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) L) obj) ∧
425 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit true) →
426 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) R) obj) ∧
427 (current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit false) →
428 current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit true) →
431 lemma sem_tape_move_obj' : tape_move_obj ⊨ R_tape_move_obj'.
432 #ta cases (sem_if ??????????
433 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit false)))
434 (sem_move_multi ? 2 obj L ?)
436 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit true)))
437 (sem_move_multi ? 2 obj R ?)
439 #i * #outc * #Hloop #HR %{i} %{outc} % [@Hloop] -i
441 [ * #tb * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htb1 #Htb2
442 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
443 [ >Hcurta_prg #H destruct (H) >(?:tb = ta)
444 [| lapply (eq_vec_change_vec ??????? Htb1 Htb2)
445 >change_vec_same // ] %
446 | >Hcurta_prg #H destruct (H) destruct (Hc) ]
447 | >Hcurta_prg >Hc * #H @False_ind /2/ ]
448 | * #tb * * * #Hnotfalse #Htb1 #Htb2 cut (tb = ta)
449 [ lapply (eq_vec_change_vec ??????? Htb1 Htb2)
450 >change_vec_same // ] -Htb1 -Htb2 #Htb destruct (Htb) *
451 [ * #tc * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htc1 #Htc2
452 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
453 [ >Hcurta_prg #H destruct (H) destruct (Hc)
454 | >Hcurta_prg #H destruct (H) >(?:tc = ta)
455 [| lapply (eq_vec_change_vec ??????? Htc1 Htc2)
456 >change_vec_same // ] % ]
457 | >Hcurta_prg >Hc #_ * #H @False_ind /2/ ]
458 | * #tc * * * #Hnottrue #Htc1 #Htc2 cut (tc = ta)
459 [ lapply (eq_vec_change_vec ??????? Htc1 Htc2)
460 >change_vec_same // ] -Htc1 -Htc2
461 #Htc destruct (Htc) whd in ⊢ (%→?); #Houtc % [ %
462 [ #Hcurta_prg lapply (\Pf (Hnotfalse ? Hcurta_prg)) * #H @False_ind /2/
463 | #Hcurta_prg lapply (\Pf (Hnottrue ? Hcurta_prg)) * #H @False_ind /2/ ]
469 definition R_tape_move_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
470 ∀c. current ? (nth prg ? t1 (niltape ?)) = Some ? c →
471 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) (char_to_move c)) obj.
473 lemma sem_tape_move_obj : tape_move_obj ⊨ R_tape_move_obj.
474 @(Realize_to_Realize … sem_tape_move_obj')
475 #ta #tb * * #Htb1 #Htb2 #Htb3 * [ *
477 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
478 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
479 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
480 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
484 definition list_of_tape ≝ λsig.λt:tape sig.
485 reverse ? (left ? t)@option_cons ? (current ? t) (right ? t).
487 definition restart_tape ≝ λi,n.
488 mmove i FSUnialpha n L ·
489 inject_TM ? (move_to_end FSUnialpha L) n i ·
490 mmove i FSUnialpha n R.
492 definition R_restart_tape ≝ λi,n.λint,outt:Vector (tape FSUnialpha) (S n).
493 ∀t.t = nth i ? int (niltape ?) →
494 outt = change_vec ?? int
495 (mk_tape ? [ ] (option_hd ? (list_of_tape ? t)) (tail ? (list_of_tape ? t))) i.
497 lemma sem_restart_tape : ∀i,n.i < S n → restart_tape i n ⊨ R_restart_tape i n.
499 @(sem_seq_app ??????? (sem_move_multi ? n i L ?)
500 (sem_seq ?????? (sem_inject ???? i ? (sem_move_to_end_l ?))
501 (sem_move_multi ? n i R ?))) [1,2,3:@le_S_S_to_le //]
502 #ta #tb * #tc * whd in ⊢ (%→?); #Htc
503 * #td * * * #Htd1 #Htd2 #Htd3
504 whd in ⊢ (%→?); #Htb *
505 [ #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
506 cut (td = tc) [@daemon]
507 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
508 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
510 | #r0 #rs0 #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
511 cut (td = tc) [@daemon]
512 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
513 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
515 | #l0 #ls0 #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
516 cut (td = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls0@[l0])) i)
518 #Htd >Htd in Htb; >Htc >change_vec_change_vec >change_vec_change_vec
519 >nth_change_vec // #Htb >Htb <(reverse_reverse ? ls0) in ⊢ (???%);
520 cases (reverse ? ls0)
522 | #l1 #ls1 >reverse_cons
523 >(?: list_of_tape ? (rightof ? l0 (reverse ? ls1@[l1])) =
525 [|change with (reverse ??@?) in ⊢ (??%?);
526 whd in match (left ??); >reverse_cons >reverse_append
527 whd in ⊢ (??%?); @eq_f >reverse_reverse normalize >append_nil % ] % ]
529 [ #c #rs #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
530 cut (td = tc) [@daemon]
531 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
532 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
534 | #l0 #ls0 #c #rs #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
535 cut (td = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls0@l0::c::rs)) i)
537 #Htd >Htd in Htb; >Htc >change_vec_change_vec >change_vec_change_vec
538 >nth_change_vec // #Htb >Htb <(reverse_reverse ? ls0) in ⊢ (???%);
539 cases (reverse ? ls0)
541 | #l1 #ls1 >reverse_cons
542 >(?: list_of_tape ? (midtape ? (l0::reverse ? ls1@[l1]) c rs) =
544 [|change with (reverse ??@?) in ⊢ (??%?);
545 whd in match (left ??); >reverse_cons >reverse_append
546 whd in ⊢ (??%?); @eq_f >reverse_reverse normalize
547 >associative_append % ] % ]