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/universal/move_char_c.ma".
13 include "turing/universal/move_char_l.ma".
14 include "turing/universal/tuples.ma".
16 definition init_cell_states ≝ initN 2.
18 definition ics0 : init_cell_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 2 (refl …)).
19 definition ics1 : init_cell_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 2 (refl …)).
21 definition init_cell ≝
22 mk_TM STape init_cell_states
26 [ None ⇒ 〈ics1, Some ? 〈〈null,false〉,N〉〉
27 | Some _ ⇒ 〈ics1, None ?〉 ]
28 | S _ ⇒ 〈ics1,None ?〉 ])
31 definition R_init_cell ≝ λt1,t2.
32 (∃c.current STape t1 = Some ? c ∧ t2 = t1) ∨
33 (current STape t1 = None ? ∧ t2 = midtape ? (left ? t1) 〈null,false〉 (right ? t1)).
35 axiom sem_init_cell : Realize ? init_cell R_init_cell.
37 definition swap_states : FinSet → FinSet ≝ λalpha:FinSet.FinProd (initN 4) alpha.
39 definition swap0 : initN 4 ≝ mk_Sig ?? 0 (leb_true_to_le 1 4 (refl …)).
40 definition swap1 : initN 4 ≝ mk_Sig ?? 1 (leb_true_to_le 2 4 (refl …)).
41 definition swap2 : initN 4 ≝ mk_Sig ?? 2 (leb_true_to_le 3 4 (refl …)).
42 definition swap3 : initN 4 ≝ mk_Sig ?? 3 (leb_true_to_le 4 4 (refl …)).
45 λalpha:FinSet.λd:alpha.
46 mk_TM alpha (swap_states alpha)
49 let q' ≝ pi1 nat (λi.i<4) q' in (* perche' devo passare il predicato ??? *)
51 [ None ⇒ 〈〈swap3,d〉,None ?〉
55 〈〈swap1,a'〉,Some ? 〈a',R〉〉
56 | S q' ⇒ match q' with
58 〈〈swap2,a'〉,Some ? 〈b,L〉〉
59 | S q' ⇒ match q' with
61 〈〈swap3,d〉,Some ? 〈b,N〉〉
63 〈〈swap3,d〉,None ?〉 ] ] ] ])
65 (λq.let 〈q',a〉 ≝ q in q' == swap3).
70 t1 = midtape alpha ls b (a::rs) →
71 t2 = midtape alpha ls a (b::rs).
75 ∀alpha:FinSet.∀d,a,ls,a0,rs.
76 step alpha (swap alpha d)
77 (mk_config ?? 〈0,a〉 (mk_tape … ls (Some ? a0) rs)) =
78 mk_config alpha (states ? (swap alpha d)) 〈1,a0〉
79 (tape_move_right alpha ls a0 rs).
87 ∀alpha:FinSet.∀d,a,ls,a0,rs.
88 step alpha (swap alpha d)
89 (mk_config ?? 〈1,a〉 (mk_tape … ls (Some ? a0) rs)) =
90 mk_config alpha (states ? (swap alpha d)) 〈2,a0〉
91 (tape_move_left alpha ls a rs).
92 #alpha #sep #a #ls #a0 * //
96 ∀alpha:FinSet.∀d,a,ls,a0,rs.
97 step alpha (swap alpha d)
98 (mk_config ?? 〈2,a〉 (mk_tape … ls (Some ? a0) rs)) =
99 mk_config alpha (states ? (swap alpha d)) 〈3,d〉
100 (tape_move_left alpha ls a rs).
101 #alpha #sep #a #ls #a0 * //
107 Realize alpha (swap alpha d) (R_swap alpha).
108 #alpha #d #tapein @(ex_intro ?? 4) cases tapein
109 [ @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
110 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
111 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
112 | #ls #c #rs cases rs
113 [ @ex_intro [| % [ % | #a #b #ls0 #rs0 #Hfalse destruct (Hfalse) ] ]
114 | -rs #r #rs @ex_intro
117 | #r0 #c0 #ls0 #rs0 #Htape destruct (Htape) normalize cases ls0
118 [% | #l1 #ls1 %] ] ] ] ]
121 axiom ssem_move_char_l :
123 Realize alpha (move_char_l alpha sep) (R_move_char_l alpha sep).
128 ls # current c # table # d? rs
130 ls # current c # table # d? rs init
132 ls # current c # table # d? rs
134 ls # current c # table # d rs ----------------------
136 ls # current c # table # d rs
138 ls # current c # table d # rs --------------------
140 ls # current c # table d # rs
142 ls # current c # d table # rs sub1
144 ls # current c # d table # rs
146 ls # current c d # table # rs -------------------
148 ls # current c d # table # rs -------------------
150 ls # current c d # table # rs
152 ls # c current d # table # rs sub1
154 ls # c current d # table # rs
156 ls c # current d # table # rs ------------------
178 (* l1 # l2 r ---> l1 r # l2
182 seq ? (move_l …) (seq ? (move_char_l STape 〈grid,false〉)
183 (swap STape 〈grid,false〉)).
184 definition R_mtr_aux ≝ λt1,t2.
185 ∀l1,l2,l3,r. t1 = midtape STape (l2@〈grid,false〉::l1) r l3 → no_grids l2 →
186 t2 = midtape STape l1 r (〈grid,false〉::reverse ? l2@l3).
188 lemma sem_mtr_aux : Realize ? mtr_aux R_mtr_aux.
190 cases (sem_seq … (sem_move_l …) (sem_seq … (ssem_move_char_l STape 〈grid,false〉)
191 (sem_swap STape 〈grid,false〉)) intape)
192 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
193 #l1 #l2 #l3 #r #Hintape #Hl2
194 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta #Hta
195 * #tb * whd in ⊢(%→?); generalize in match Hta; -Hta cases l2 in Hl2;
196 [ #_ #Hta #Htb lapply (Htb … Hta) -Htb * #Htb lapply (Htb (refl ??)) -Htb #Htb #_
197 whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … Hta) -Houtc #Houtc @Houtc
198 | #c0 #l0 #Hnogrids #Hta #Htb lapply (Htb … Hta) -Htb * #_ #Htb
199 lapply (Htb … (refl ??) ??)
200 [ cases (true_or_false (memb STape 〈grid,false〉 l0)) #Hmemb
201 [ @False_ind lapply (Hnogrids 〈grid,false〉 ?)
202 [ @memb_cons // | normalize #Hfalse destruct (Hfalse) ]
204 | % #Hc0 lapply (Hnogrids c0 ?)
205 [ @memb_hd | >Hc0 normalize #Hfalse destruct (Hfalse) ]
206 | #Htb whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … (refl ??)) -Houtc #Houtc
207 >reverse_cons >associative_append @Houtc
211 definition move_tape_r ≝
212 seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
213 (seq ? (swap STape 〈grid,false〉)
214 (seq ? mtr_aux (seq ? (move_l …) (seq ? mtr_aux (move_r …))))))).
216 definition R_move_tape_r ≝ λt1,t2.
217 ∀rs,n,table,c0,bc0,curconfig,ls0.
218 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
219 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
222 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@〈null,false〉::
223 〈grid,false〉::reverse STape table@[〈grid,false〉])) ∨
224 (∃r0,rs0.rs = r0::rs0 ∧
225 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@r0::
226 〈grid,false〉::reverse STape table@〈grid,false〉::rs0)).
228 lemma sem_move_tape_r : Realize ? move_tape_r R_move_tape_r.
230 cases (sem_seq …(sem_move_r …) (sem_seq … sem_init_cell (sem_seq … (sem_move_l …)
231 (sem_seq … (sem_swap STape 〈grid,false〉) (sem_seq … sem_mtr_aux
232 (sem_seq … (sem_move_l …) (sem_seq … sem_mtr_aux (sem_move_r …))))))) tapein)
233 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
234 #rs #n #table #c0 #bc0 #curconfig #ls0 #Hbitnullc0 #Hbitnullcc #Htable #Htapein
235 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Htapein) -Hta #Hta
236 * #tb * whd in ⊢ (%→?); *
238 generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
239 [ #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
240 #r1 #rs1 #Htapein #Hta change with (midtape ?? r1 rs1) in Hta:(???%); >Hta
241 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
242 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
243 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [ (*memb_reverse @(no_grids_in_table … Htable)*) @daemon ] -Hte #Hte
244 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
245 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
246 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
247 %2 @(ex_intro ?? r1) @(ex_intro ?? rs1) % [%] @Houtc
248 | * generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
249 [|#r1 #rs1 #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
250 #Htapein #Hta change with (rightof ???) in Hta:(???%); >Hta
251 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
252 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
253 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [(*same as above @(no_grids_in_table … Htable) *) @daemon ] -Hte #Hte
254 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
255 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
256 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
263 ls # current c # table # d rs
265 ls # current c # table # d rs
267 ls # current c # table d # rs
269 ls # current c # d table # rs
271 ls # current c # d table # rs
273 ls # current c d # table # rs
275 ls # current c d # table # rs
277 ls # c current c # table # rs
279 ls # c current c # table # rs
281 ls c # current c # table # rs
294 axiom move_tape_l : TM STape.
295 (* seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
296 (seq ? (swap STape 〈grid,false〉)
297 (seq ? mtr_aux (seq ? (move_l …) mtr_aux))))). *)
299 definition R_move_tape_l ≝ λt1,t2.
300 ∀rs,n,table,c0,bc0,curconfig,ls0.
301 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
302 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
305 t2 = midtape STape [] 〈grid,false〉
306 (reverse ? curconfig@〈null,false〉::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)) ∨
307 (∃l1,ls1. ls0 = l1::ls1 ∧
308 t2 = midtape STape ls1 〈grid,false〉
309 (reverse ? curconfig@l1::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)).
311 axiom sem_move_tape_l : Realize ? move_tape_l R_move_tape_l.
315 case bit false: move_tape_l
316 case bit true: move_tape_r
317 case null: adv_to_grid_l; move_l; adv_to_grid_l;
320 definition lift_tape ≝ λls,c,rs.
322 let c' ≝ match c0 with
326 mk_tape STape ls c' rs.
328 definition sim_current_of_tape ≝ λt.
329 match current STape t with
330 [ None ⇒ 〈null,false〉
334 definition move_of_unialpha ≝
336 [ bit x ⇒ match x with [ true ⇒ R | false ⇒ L ]
339 definition R_uni_step ≝ λt1,t2.
340 ∀n,table,c,c1,ls,rs,curs,curc,news,newc,mv.
342 match_in_table n (〈c,false〉::curs) 〈curc,false〉
343 (〈c1,false〉::news) 〈newc,false〉 〈mv,false〉 table →
344 t1 = midtape STape (〈grid,false〉::ls) 〈c,false〉
345 (curs@〈curc,false〉::〈grid,false〉::table@〈grid,false〉::rs) →
346 ∀t1',ls1,rs1.t1' = lift_tape ls 〈curc,false〉 rs →
347 (t2 = midtape STape (〈grid,false〉::ls1) 〈c1,false〉
348 (news@〈newc,false〉::〈grid,false〉::table@〈grid,false〉::rs1) ∧
349 lift_tape ls1 〈newc,false〉 rs1 =
350 tape_move STape t1' (Some ? 〈〈newc,false〉,move_of_unialpha mv〉)).
352 definition no_nulls ≝
353 λl:list STape.∀x.memb ? x l = true → is_null (\fst x) = false.
355 definition current_of_alpha ≝ λc:STape.
356 match \fst c with [ null ⇒ None ? | _ ⇒ Some ? c ].
364 definition legal_tape ≝ λls,c,rs.
365 no_marks (c::ls@rs) ∧ only_bits (ls@rs) ∧ bit_or_null (\fst c) = true ∧
366 (\fst c ≠ null ∨ ls = [] ∨ rs = []).
368 lemma legal_tape_left :
369 ∀ls,c,rs.legal_tape ls c rs →
370 left ? (mk_tape STape ls (current_of_alpha c) rs) = ls.
371 #ls * #c #bc #rs * * * #_ #_ #_ *
375 | * #Hfalse @False_ind /2/
377 | #Hls >Hls cases c // cases rs //
379 | #Hrs >Hrs cases c // cases ls //
383 axiom legal_tape_current :
384 ∀ls,c,rs.legal_tape ls c rs →
385 current ? (mk_tape STape ls (current_of_alpha c) rs) = current_of_alpha c.
387 axiom legal_tape_right :
388 ∀ls,c,rs.legal_tape ls c rs →
389 right ? (mk_tape STape ls (current_of_alpha c) rs) = rs.
392 lemma legal_tape_cases :
393 ∀ls,c,rs.legal_tape ls c rs →
394 \fst c ≠ null ∨ (\fst c = null ∧ (ls = [] ∨ rs = [])).
395 #ls #c #rs cases c #c0 #bc0 cases c0
396 [ #c1 normalize #_ % % #Hfalse destruct (Hfalse)
401 | #r0 #rs0 normalize * * #_ #Hrs destruct (Hrs) ]
403 |*: #_ % % #Hfalse destruct (Hfalse) ]
406 axiom legal_tape_conditions :
407 ∀ls,c,rs.(\fst c ≠ null ∨ ls = [] ∨ rs = []) → legal_tape ls c rs.
410 [ >(eq_pair_fst_snd ?? c) cases (\fst c)
412 | * #Hfalse @False_ind /2/
415 | cases ls [ * #Hfalse @False_ind /2/ ]
422 definition R_move_tape_r_abstract ≝ λt1,t2.
423 ∀rs,n,table,curc,curconfig,ls.
424 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
425 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
427 legal_tape ls 〈curc,false〉 rs →
428 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
430 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
431 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
432 lift_tape ls1 〈newc,false〉 rs1 =
433 tape_move_right STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
435 lemma lift_tape_not_null :
436 ∀ls,c,rs. is_null (\fst c) = false →
437 lift_tape ls c rs = mk_tape STape ls (Some ? c) rs.
438 #ls * #c0 #bc0 #rs cases c0
439 [|normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
443 axiom bit_not_null : ∀d.is_bit d = true → is_null d = false.
445 lemma mtr_concrete_to_abstract :
446 ∀t1,t2.R_move_tape_r t1 t2 → R_move_tape_r_abstract t1 t2.
447 #t1 #t2 whd in ⊢(%→?); #Hconcrete
448 #rs #n #table #curc #curconfig #ls #Hbitcurc #Hcurconfig #Htable #Ht1
449 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
450 cases (Hconcrete … Htable Ht1) //
452 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? [])
453 @(ex_intro ?? null) %
458 [ >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
460 | @Hnomarks @(memb_append_l1 … Hx') ]
461 | >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
463 | @Hbits @(memb_append_l1 … Hx') ]]
467 | * * #r0 #br0 * #rs0 * #Hrs
469 [ @(Hnomarks 〈r0,br0〉) @memb_cons @memb_append_l2 >Hrs @memb_hd]
470 #Hbr0 >Hbr0 in Hrs; #Hrs #Ht2
471 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? rs0)
475 | >Hrs >lift_tape_not_null
477 | @bit_not_null @(Hbits 〈r0,false〉) >Hrs @memb_append_l2 @memb_hd ] ]
479 [ #x #Hx cases (orb_true_l … Hx) #Hx'
481 | cases (memb_append … Hx') #Hx'' @Hnomarks
482 [ @(memb_append_l1 … Hx'')
483 | >Hrs @memb_cons @memb_append_l2 @(memb_cons … Hx'') ]
485 | whd in ⊢ (?%); #x #Hx cases (orb_true_l … Hx) #Hx'
487 | cases (memb_append … Hx') #Hx'' @Hbits
488 [ @(memb_append_l1 … Hx'') | >Hrs @memb_append_l2 @(memb_cons … Hx'') ]
490 | whd in ⊢ (??%?); >(Hbits 〈r0,false〉) //
491 @memb_append_l2 >Hrs @memb_hd ]
492 | % % % #Hr0 lapply (Hbits 〈r0,false〉?)
493 [ @memb_append_l2 >Hrs @memb_hd
494 | >Hr0 normalize #Hfalse destruct (Hfalse)
498 definition R_move_tape_l_abstract ≝ λt1,t2.
499 ∀rs,n,table,curc,curconfig,ls.
500 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
501 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
503 legal_tape ls 〈curc,false〉 rs →
504 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
506 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
507 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
508 lift_tape ls1 〈newc,false〉 rs1 =
509 tape_move_left STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
511 lemma mtl_concrete_to_abstract :
512 ∀t1,t2.R_move_tape_l t1 t2 → R_move_tape_l_abstract t1 t2.
513 #t1 #t2 whd in ⊢(%→?); #Hconcrete
514 #rs #n #table #curc #curconfig #ls #Hcurc #Hcurconfig #Htable #Ht1
515 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
516 cases (Hconcrete … Htable Ht1) //
519 @(ex_intro ?? (〈curc,false〉::rs))
520 @(ex_intro ?? null) %
525 [ #x #Hx cases (orb_true_l … Hx) #Hx'
527 | @Hnomarks >Hls @Hx' ]
528 | #x #Hx cases (orb_true_l … Hx) #Hx'
530 | @Hbits >Hls @Hx' ]]
534 | * * #l0 #bl0 * #ls0 * #Hls
536 [ @(Hnomarks 〈l0,bl0〉) @memb_cons @memb_append_l1 >Hls @memb_hd]
537 #Hbl0 >Hbl0 in Hls; #Hls #Ht2
538 @(ex_intro ?? ls0) @(ex_intro ?? (〈curc,false〉::rs))
542 | >Hls >lift_tape_not_null
544 | @bit_not_null @(Hbits 〈l0,false〉) >Hls @memb_append_l1 @memb_hd ] ]
546 [ #x #Hx cases (orb_true_l … Hx) #Hx'
548 | cases (memb_append … Hx') #Hx'' @Hnomarks
549 [ >Hls @memb_cons @memb_cons @(memb_append_l1 … Hx'')
550 | cases (orb_true_l … Hx'') #Hx'''
551 [ >(\P Hx''') @memb_hd
552 | @memb_cons @(memb_append_l2 … Hx''')]
555 | whd in ⊢ (?%); #x #Hx cases (memb_append … Hx) #Hx'
556 [ @Hbits >Hls @memb_cons @(memb_append_l1 … Hx')
557 | cases (orb_true_l … Hx') #Hx''
559 | @Hbits @(memb_append_l2 … Hx'')
561 | whd in ⊢ (??%?); >(Hbits 〈l0,false〉) //
562 @memb_append_l1 >Hls @memb_hd ]
563 | % % % #Hl0 lapply (Hbits 〈l0,false〉?)
564 [ @memb_append_l1 >Hls @memb_hd
565 | >Hl0 normalize #Hfalse destruct (Hfalse)
569 lemma Realize_to_Realize :
570 ∀alpha,M,R1,R2.(∀t1,t2.R1 t1 t2 → R2 t1 t2) → Realize alpha M R1 → Realize alpha M R2.
571 #alpha #M #R1 #R2 #Himpl #HR1 #intape
572 cases (HR1 intape) -HR1 #k * #outc * #Hloop #HR1
573 @(ex_intro ?? k) @(ex_intro ?? outc) % /2/
576 lemma sem_move_tape_l_abstract : Realize … move_tape_l R_move_tape_l_abstract.
577 @(Realize_to_Realize … mtl_concrete_to_abstract) //
580 lemma sem_move_tape_r_abstract : Realize … move_tape_r R_move_tape_r_abstract.
581 @(Realize_to_Realize … mtr_concrete_to_abstract) //
585 t1 = ls # cs c # table # rs
587 let simt ≝ lift_tape ls c rs in
588 let simt' ≝ move_left simt' in
590 t2 = left simt'# cs (sim_current_of_tape simt') # table # right simt'
596 definition R_exec_move ≝ λt1,t2.
597 ∀ls,current,table1,newcurrent,table2,rs.
598 t1 = midtape STape (current@〈grid,false〉::ls) 〈grid,false〉
599 (table1@〈comma,true〉::newcurrent@〈comma,false〉::move::table2@
601 table_TM (table1@〈comma,false〉::newcurrent@〈comma,false〉::move::table2) →
609 if is_true(current) (* current state is final *)
614 if is_marked(current) = false (* match ok *)
621 definition move_tape ≝
622 ifTM ? (test_char ? (λc:STape.c == 〈bit false,false〉))
623 (* spostamento a sinistra: verificare se per caso non conviene spostarsi
624 sulla prima grid invece dell'ultima *)
625 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_l)
626 (ifTM ? (test_char ? (λc:STape.c == 〈bit true,false〉))
627 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_r)
628 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
629 (seq ? (move_l …) (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))
632 definition R_move_tape ≝ λt1,t2.
633 ∀rs,n,table1,mv,table2,curc,curconfig,ls.
634 bit_or_null mv = true → only_bits_or_nulls curconfig →
635 (is_bit mv = true → is_bit curc = true) →
636 table_TM n (reverse ? table1@〈mv,false〉::table2) →
637 t1 = midtape STape (table1@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
638 〈mv,false〉 (table2@〈grid,false〉::rs) →
639 legal_tape ls 〈curc,false〉 rs →
640 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
642 legal_tape ls1 〈newc,false〉 rs1 ∧
643 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
644 〈grid,false〉::reverse ? table1@〈mv,false〉::table2@〈grid,false〉::rs1) ∧
645 ((mv = bit false ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_left STape ls 〈curc,false〉 rs) ∨
646 (mv = bit true ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_right STape ls 〈curc,false〉 rs) ∨
647 (mv = null ∧ ls1 = ls ∧ rs1 = rs ∧ curc = newc))).
649 lemma sem_move_tape : Realize ? move_tape R_move_tape.
651 cases (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit false,false〉))
652 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_l_abstract)
653 (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit true,false〉))
654 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_r_abstract)
655 (sem_seq … (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
656 (sem_seq … (sem_move_l …) (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))) intape)
657 #k * #outc * #Hloop #HR
658 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
659 #rs #n #table1 #mv #table2 #curc #curconfig #ls
660 #Hmv #Hcurconfig #Hmvcurc #Htable #Hintape #Htape #t1' #Ht1'
661 generalize in match HR; -HR *
662 [ * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
663 [| >Hintape % ] -Hta #Hceq #Hta lapply (\P Hceq) -Hceq #Hceq destruct (Hta Hceq)
664 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hintape) -Htb -Hintape
665 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
666 * #_ #Htb lapply (Htb … (refl ??) (refl ??) ?)
667 [ @daemon ] -Htb >append_cons <associative_append #Htb
668 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htb … Ht1') //
669 [ >reverse_append >reverse_append >reverse_reverse @Htable
672 -Houtc -Htb * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
673 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
676 [ >Houtc >reverse_append >reverse_append >reverse_reverse
677 >associative_append >associative_append %
680 | * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
681 [| >Hintape % ] -Hta #Hcneq cut (mv ≠ bit false)
682 [ lapply (\Pf Hcneq) @not_to_not #Heq >Heq % ] -Hcneq #Hcneq #Hta destruct (Hta)
684 [ * #tb * whd in ⊢ (%→?);#Htb cases (Htb 〈mv,false〉 ?)
685 [| >Hintape % ] -Htb #Hceq #Htb lapply (\P Hceq) -Hceq #Hceq destruct (Htb Hceq)
686 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape) -Htc -Hintape
687 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
688 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?)
689 [ @daemon ] -Htc >append_cons <associative_append #Htc
690 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htc … Ht1') //
691 [ >reverse_append >reverse_append >reverse_reverse @Htable
693 -Houtc -Htc * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
694 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
697 [ >Houtc >reverse_append >reverse_append >reverse_reverse
698 >associative_append >associative_append %
701 | * #tb * whd in ⊢ (%→?); #Htb cases (Htb 〈mv,false〉 ?)
702 [| >Hintape % ] -Htb #Hcneq' cut (mv ≠ bit true)
703 [ lapply (\Pf Hcneq') @not_to_not #Heq >Heq % ] -Hcneq' #Hcneq' #Htb destruct (Htb)
704 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape)
705 [ * >(bit_or_null_not_grid … Hmv) #Hfalse destruct (Hfalse) ] -Htc
706 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?) [@daemon] -Htc #Htc
707 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd -Htc
708 whd in ⊢ (???%→?); #Htd whd in ⊢ (%→?); #Houtc lapply (Houtc … Htd) -Houtc *
709 [ * cases Htape * * #_ #_ #Hcurc #_
710 >(bit_or_null_not_grid … Hcurc) #Hfalse destruct (Hfalse) ]
711 * #_ #Houtc lapply (Houtc … (refl ??) (refl ??) ?) [@daemon] -Houtc #Houtc
712 @(ex_intro ?? ls) @(ex_intro ?? rs) @(ex_intro ?? curc) %
717 generalize in match Hcneq; generalize in match Hcneq';
718 cases mv in Hmv; normalize //
719 [ * #_ normalize [ #Hfalse @False_ind cases Hfalse /2/ | #_ #Hfalse @False_ind cases Hfalse /2/ ]
720 |*: #Hfalse destruct (Hfalse) ]