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 init_cell ≝
19 mk_TM STape init_cell_states
23 [ None ⇒ 〈1, Some ? 〈〈null,false〉,N〉〉
24 | Some _ ⇒ 〈1, None ?〉 ]
28 definition R_init_cell ≝ λt1,t2.
29 (∃c.current STape t1 = Some ? c ∧ t2 = t1) ∨
30 (current STape t1 = None ? ∧ t2 = midtape ? (left ? t1) 〈null,false〉 (right ? t1)).
32 axiom sem_init_cell : Realize ? init_cell R_init_cell.
34 definition swap_states : FinSet → FinSet ≝ λalpha:FinSet.FinProd (initN 4) alpha.
37 λalpha:FinSet.λd:alpha.
38 mk_TM alpha (mcl_states alpha)
42 [ None ⇒ 〈〈3,d〉,None ?〉
46 〈〈1,a'〉,Some ? 〈a',R〉〉
47 | S q' ⇒ match q' with
50 | S q' ⇒ match q' with
54 〈〈3,d〉,None ?〉 ] ] ] ])
56 (λq.let 〈q',a〉 ≝ q in q' == 3).
61 t1 = midtape alpha ls b (a::rs) →
62 t2 = midtape alpha ls a (b::rs).
66 ∀alpha:FinSet.∀d,a,ls,a0,rs.
67 step alpha (swap alpha d)
68 (mk_config ?? 〈0,a〉 (mk_tape … ls (Some ? a0) rs)) =
69 mk_config alpha (states ? (swap alpha d)) 〈1,a0〉
70 (tape_move_right alpha ls a0 rs).
78 ∀alpha:FinSet.∀d,a,ls,a0,rs.
79 step alpha (swap alpha d)
80 (mk_config ?? 〈1,a〉 (mk_tape … ls (Some ? a0) rs)) =
81 mk_config alpha (states ? (swap alpha d)) 〈2,a0〉
82 (tape_move_left alpha ls a rs).
83 #alpha #sep #a #ls #a0 * //
87 ∀alpha:FinSet.∀d,a,ls,a0,rs.
88 step alpha (swap alpha d)
89 (mk_config ?? 〈2,a〉 (mk_tape … ls (Some ? a0) rs)) =
90 mk_config alpha (states ? (swap alpha d)) 〈3,d〉
91 (tape_move_left alpha ls a rs).
92 #alpha #sep #a #ls #a0 * //
98 Realize alpha (swap alpha d) (R_swap alpha).
99 #alpha #d #tapein @(ex_intro ?? 4) cases tapein
100 [ @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
101 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
102 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
103 | #ls #c #rs cases rs
104 [ @ex_intro [| % [ % | #a #b #ls0 #rs0 #Hfalse destruct (Hfalse) ] ]
105 | -rs #r #rs @ex_intro
108 | #r0 #c0 #ls0 #rs0 #Htape destruct (Htape) normalize cases ls0
109 [% | #l1 #ls1 %] ] ] ] ]
112 axiom ssem_move_char_l :
114 Realize alpha (move_char_l alpha sep) (R_move_char_l alpha sep).
119 ls # current c # table # d? rs
121 ls # current c # table # d? rs init
123 ls # current c # table # d? rs
125 ls # current c # table # d rs ----------------------
127 ls # current c # table # d rs
129 ls # current c # table d # rs --------------------
131 ls # current c # table d # rs
133 ls # current c # d table # rs sub1
135 ls # current c # d table # rs
137 ls # current c d # table # rs -------------------
139 ls # current c d # table # rs -------------------
141 ls # current c d # table # rs
143 ls # c current d # table # rs sub1
145 ls # c current d # table # rs
147 ls c # current d # table # rs ------------------
169 (* l1 # l2 r ---> l1 r # l2
173 seq ? (move_l …) (seq ? (move_char_l STape 〈grid,false〉)
174 (swap STape 〈grid,false〉)).
175 definition R_mtr_aux ≝ λt1,t2.
176 ∀l1,l2,l3,r. t1 = midtape STape (l2@〈grid,false〉::l1) r l3 → no_grids l2 →
177 t2 = midtape STape l1 r (〈grid,false〉::reverse ? l2@l3).
179 lemma sem_mtr_aux : Realize ? mtr_aux R_mtr_aux.
181 cases (sem_seq … (sem_move_l …) (sem_seq … (ssem_move_char_l STape 〈grid,false〉)
182 (sem_swap STape 〈grid,false〉)) intape)
183 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
184 #l1 #l2 #l3 #r #Hintape #Hl2
185 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta #Hta
186 * #tb * whd in ⊢(%→?); generalize in match Hta; -Hta cases l2 in Hl2;
187 [ #_ #Hta #Htb lapply (Htb … Hta) -Htb * #Htb lapply (Htb (refl ??)) -Htb #Htb #_
188 whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … Hta) -Houtc #Houtc @Houtc
189 | #c0 #l0 #Hnogrids #Hta #Htb lapply (Htb … Hta) -Htb * #_ #Htb
190 lapply (Htb … (refl ??) ??)
191 [ cases (true_or_false (memb STape 〈grid,false〉 l0)) #Hmemb
192 [ @False_ind lapply (Hnogrids 〈grid,false〉 ?)
193 [ @memb_cons // | normalize #Hfalse destruct (Hfalse) ]
195 | % #Hc0 lapply (Hnogrids c0 ?)
196 [ @memb_hd | >Hc0 normalize #Hfalse destruct (Hfalse) ]
197 | #Htb whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … (refl ??)) -Houtc #Houtc
198 >reverse_cons >associative_append @Houtc
202 definition move_tape_r ≝
203 seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
204 (seq ? (swap STape 〈grid,false〉)
205 (seq ? mtr_aux (seq ? (move_l …) (seq ? mtr_aux (move_r …))))))).
207 definition R_move_tape_r ≝ λt1,t2.
208 ∀rs,n,table,c0,bc0,curconfig,ls0.
209 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
210 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
213 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@〈null,false〉::
214 〈grid,false〉::reverse STape table@[〈grid,false〉])) ∨
215 (∃r0,rs0.rs = r0::rs0 ∧
216 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@r0::
217 〈grid,false〉::reverse STape table@〈grid,false〉::rs0)).
219 lemma sem_move_tape_r : Realize ? move_tape_r R_move_tape_r.
221 cases (sem_seq …(sem_move_r …) (sem_seq … sem_init_cell (sem_seq … (sem_move_l …)
222 (sem_seq … (sem_swap STape 〈grid,false〉) (sem_seq … sem_mtr_aux
223 (sem_seq … (sem_move_l …) (sem_seq … sem_mtr_aux (sem_move_r …))))))) tapein)
224 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
225 #rs #n #table #c0 #bc0 #curconfig #ls0 #Hbitnullc0 #Hbitnullcc #Htable #Htapein
226 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Htapein) -Hta #Hta
227 * #tb * whd in ⊢ (%→?); *
229 generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
230 [ #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
231 #r1 #rs1 #Htapein #Hta change with (midtape ?? r1 rs1) in Hta:(???%); >Hta
232 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
233 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
234 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [ (*memb_reverse @(no_grids_in_table … Htable)*) @daemon ] -Hte #Hte
235 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
236 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
237 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
238 %2 @(ex_intro ?? r1) @(ex_intro ?? rs1) % [%] @Houtc
239 | * generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
240 [|#r1 #rs1 #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
241 #Htapein #Hta change with (rightof ???) in Hta:(???%); >Hta
242 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
243 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
244 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [(*same as above @(no_grids_in_table … Htable) *) @daemon ] -Hte #Hte
245 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
246 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
247 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
254 ls # current c # table # d rs
256 ls # current c # table # d rs
258 ls # current c # table d # rs
260 ls # current c # d table # rs
262 ls # current c # d table # rs
264 ls # current c d # table # rs
266 ls # current c d # table # rs
268 ls # c current c # table # rs
270 ls # c current c # table # rs
272 ls c # current c # table # rs
285 axiom move_tape_l : TM STape.
286 (* seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
287 (seq ? (swap STape 〈grid,false〉)
288 (seq ? mtr_aux (seq ? (move_l …) mtr_aux))))). *)
290 definition R_move_tape_l ≝ λt1,t2.
291 ∀rs,n,table,c0,bc0,curconfig,ls0.
292 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
293 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
296 t2 = midtape STape [] 〈grid,false〉
297 (reverse ? curconfig@〈null,false〉::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)) ∨
298 (∃l1,ls1. ls0 = l1::ls1 ∧
299 t2 = midtape STape ls1 〈grid,false〉
300 (reverse ? curconfig@l1::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)).
302 axiom sem_move_tape_l : Realize ? move_tape_l R_move_tape_l.
306 case bit false: move_tape_l
307 case bit true: move_tape_r
308 case null: adv_to_grid_l; move_l; adv_to_grid_l;
311 definition lift_tape ≝ λls,c,rs.
313 let c' ≝ match c0 with
317 mk_tape STape ls c' rs.
319 definition sim_current_of_tape ≝ λt.
320 match current STape t with
321 [ None ⇒ 〈null,false〉
325 definition move_of_unialpha ≝
327 [ bit x ⇒ match x with [ true ⇒ R | false ⇒ L ]
330 definition R_uni_step ≝ λt1,t2.
331 ∀n,table,c,c1,ls,rs,curs,curc,news,newc,mv.
333 match_in_table n (〈c,false〉::curs) 〈curc,false〉
334 (〈c1,false〉::news) 〈newc,false〉 〈mv,false〉 table →
335 t1 = midtape STape (〈grid,false〉::ls) 〈c,false〉
336 (curs@〈curc,false〉::〈grid,false〉::table@〈grid,false〉::rs) →
337 ∀t1',ls1,rs1.t1' = lift_tape ls 〈curc,false〉 rs →
338 (t2 = midtape STape (〈grid,false〉::ls1) 〈c1,false〉
339 (news@〈newc,false〉::〈grid,false〉::table@〈grid,false〉::rs1) ∧
340 lift_tape ls1 〈newc,false〉 rs1 =
341 tape_move STape t1' (Some ? 〈〈newc,false〉,move_of_unialpha mv〉)).
343 definition no_nulls ≝
344 λl:list STape.∀x.memb ? x l = true → is_null (\fst x) = false.
346 definition current_of_alpha ≝ λc:STape.
347 match \fst c with [ null ⇒ None ? | _ ⇒ Some ? c ].
355 definition legal_tape ≝ λls,c,rs.
356 no_marks (c::ls@rs) ∧ only_bits (ls@rs) ∧ bit_or_null (\fst c) = true ∧
357 (\fst c ≠ null ∨ ls = [] ∨ rs = []).
359 lemma legal_tape_left :
360 ∀ls,c,rs.legal_tape ls c rs →
361 left ? (mk_tape STape ls (current_of_alpha c) rs) = ls.
362 #ls * #c #bc #rs * * * #_ #_ #_ *
366 | * #Hfalse @False_ind /2/
368 | #Hls >Hls cases c // cases rs //
370 | #Hrs >Hrs cases c // cases ls //
374 axiom legal_tape_current :
375 ∀ls,c,rs.legal_tape ls c rs →
376 current ? (mk_tape STape ls (current_of_alpha c) rs) = current_of_alpha c.
378 axiom legal_tape_right :
379 ∀ls,c,rs.legal_tape ls c rs →
380 right ? (mk_tape STape ls (current_of_alpha c) rs) = rs.
383 lemma legal_tape_cases :
384 ∀ls,c,rs.legal_tape ls c rs →
385 \fst c ≠ null ∨ (\fst c = null ∧ (ls = [] ∨ rs = [])).
386 #ls #c #rs cases c #c0 #bc0 cases c0
387 [ #c1 normalize #_ % % #Hfalse destruct (Hfalse)
392 | #r0 #rs0 normalize * * #_ #Hrs destruct (Hrs) ]
394 |*: #_ % % #Hfalse destruct (Hfalse) ]
397 axiom legal_tape_conditions :
398 ∀ls,c,rs.(\fst c ≠ null ∨ ls = [] ∨ rs = []) → legal_tape ls c rs.
401 [ >(eq_pair_fst_snd ?? c) cases (\fst c)
403 | * #Hfalse @False_ind /2/
406 | cases ls [ * #Hfalse @False_ind /2/ ]
413 definition R_move_tape_r_abstract ≝ λt1,t2.
414 ∀rs,n,table,curc,curconfig,ls.
415 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
416 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
418 legal_tape ls 〈curc,false〉 rs →
419 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
421 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
422 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
423 lift_tape ls1 〈newc,false〉 rs1 =
424 tape_move_right STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
426 lemma lift_tape_not_null :
427 ∀ls,c,rs. is_null (\fst c) = false →
428 lift_tape ls c rs = mk_tape STape ls (Some ? c) rs.
429 #ls * #c0 #bc0 #rs cases c0
430 [|normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
434 axiom bit_not_null : ∀d.is_bit d = true → is_null d = false.
436 lemma mtr_concrete_to_abstract :
437 ∀t1,t2.R_move_tape_r t1 t2 → R_move_tape_r_abstract t1 t2.
438 #t1 #t2 whd in ⊢(%→?); #Hconcrete
439 #rs #n #table #curc #curconfig #ls #Hbitcurc #Hcurconfig #Htable #Ht1
440 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
441 cases (Hconcrete … Htable Ht1) //
443 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? [])
444 @(ex_intro ?? null) %
449 [ >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
451 | @Hnomarks @(memb_append_l1 … Hx') ]
452 | >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
454 | @Hbits @(memb_append_l1 … Hx') ]]
458 | * * #r0 #br0 * #rs0 * #Hrs
460 [ @(Hnomarks 〈r0,br0〉) @memb_cons @memb_append_l2 >Hrs @memb_hd]
461 #Hbr0 >Hbr0 in Hrs; #Hrs #Ht2
462 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? rs0)
466 | >Hrs >lift_tape_not_null
468 | @bit_not_null @(Hbits 〈r0,false〉) >Hrs @memb_append_l2 @memb_hd ] ]
470 [ #x #Hx cases (orb_true_l … Hx) #Hx'
472 | cases (memb_append … Hx') #Hx'' @Hnomarks
473 [ @(memb_append_l1 … Hx'')
474 | >Hrs @memb_cons @memb_append_l2 @(memb_cons … Hx'') ]
476 | whd in ⊢ (?%); #x #Hx cases (orb_true_l … Hx) #Hx'
478 | cases (memb_append … Hx') #Hx'' @Hbits
479 [ @(memb_append_l1 … Hx'') | >Hrs @memb_append_l2 @(memb_cons … Hx'') ]
481 | whd in ⊢ (??%?); >(Hbits 〈r0,false〉) //
482 @memb_append_l2 >Hrs @memb_hd ]
483 | % % % #Hr0 lapply (Hbits 〈r0,false〉?)
484 [ @memb_append_l2 >Hrs @memb_hd
485 | >Hr0 normalize #Hfalse destruct (Hfalse)
489 definition R_move_tape_l_abstract ≝ λt1,t2.
490 ∀rs,n,table,curc,curconfig,ls.
491 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
492 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
494 legal_tape ls 〈curc,false〉 rs →
495 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
497 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
498 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
499 lift_tape ls1 〈newc,false〉 rs1 =
500 tape_move_left STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
502 lemma mtl_concrete_to_abstract :
503 ∀t1,t2.R_move_tape_l t1 t2 → R_move_tape_l_abstract t1 t2.
504 #t1 #t2 whd in ⊢(%→?); #Hconcrete
505 #rs #n #table #curc #curconfig #ls #Hcurc #Hcurconfig #Htable #Ht1
506 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
507 cases (Hconcrete … Htable Ht1) //
510 @(ex_intro ?? (〈curc,false〉::rs))
511 @(ex_intro ?? null) %
516 [ #x #Hx cases (orb_true_l … Hx) #Hx'
518 | @Hnomarks >Hls @Hx' ]
519 | #x #Hx cases (orb_true_l … Hx) #Hx'
521 | @Hbits >Hls @Hx' ]]
525 | * * #l0 #bl0 * #ls0 * #Hls
527 [ @(Hnomarks 〈l0,bl0〉) @memb_cons @memb_append_l1 >Hls @memb_hd]
528 #Hbl0 >Hbl0 in Hls; #Hls #Ht2
529 @(ex_intro ?? ls0) @(ex_intro ?? (〈curc,false〉::rs))
533 | >Hls >lift_tape_not_null
535 | @bit_not_null @(Hbits 〈l0,false〉) >Hls @memb_append_l1 @memb_hd ] ]
537 [ #x #Hx cases (orb_true_l … Hx) #Hx'
539 | cases (memb_append … Hx') #Hx'' @Hnomarks
540 [ >Hls @memb_cons @memb_cons @(memb_append_l1 … Hx'')
541 | cases (orb_true_l … Hx'') #Hx'''
542 [ >(\P Hx''') @memb_hd
543 | @memb_cons @(memb_append_l2 … Hx''')]
546 | whd in ⊢ (?%); #x #Hx cases (memb_append … Hx) #Hx'
547 [ @Hbits >Hls @memb_cons @(memb_append_l1 … Hx')
548 | cases (orb_true_l … Hx') #Hx''
550 | @Hbits @(memb_append_l2 … Hx'')
552 | whd in ⊢ (??%?); >(Hbits 〈l0,false〉) //
553 @memb_append_l1 >Hls @memb_hd ]
554 | % % % #Hl0 lapply (Hbits 〈l0,false〉?)
555 [ @memb_append_l1 >Hls @memb_hd
556 | >Hl0 normalize #Hfalse destruct (Hfalse)
560 lemma Realize_to_Realize :
561 ∀alpha,M,R1,R2.(∀t1,t2.R1 t1 t2 → R2 t1 t2) → Realize alpha M R1 → Realize alpha M R2.
562 #alpha #M #R1 #R2 #Himpl #HR1 #intape
563 cases (HR1 intape) -HR1 #k * #outc * #Hloop #HR1
564 @(ex_intro ?? k) @(ex_intro ?? outc) % /2/
567 lemma sem_move_tape_l_abstract : Realize … move_tape_l R_move_tape_l_abstract.
568 @(Realize_to_Realize … mtl_concrete_to_abstract) //
571 lemma sem_move_tape_r_abstract : Realize … move_tape_r R_move_tape_r_abstract.
572 @(Realize_to_Realize … mtr_concrete_to_abstract) //
576 t1 = ls # cs c # table # rs
578 let simt ≝ lift_tape ls c rs in
579 let simt' ≝ move_left simt' in
581 t2 = left simt'# cs (sim_current_of_tape simt') # table # right simt'
587 definition R_exec_move ≝ λt1,t2.
588 ∀ls,current,table1,newcurrent,table2,rs.
589 t1 = midtape STape (current@〈grid,false〉::ls) 〈grid,false〉
590 (table1@〈comma,true〉::newcurrent@〈comma,false〉::move::table2@
592 table_TM (table1@〈comma,false〉::newcurrent@〈comma,false〉::move::table2) →
600 if is_true(current) (* current state is final *)
605 if is_marked(current) = false (* match ok *)
612 definition move_tape ≝
613 ifTM ? (test_char ? (λc:STape.c == 〈bit false,false〉))
614 (* spostamento a sinistra: verificare se per caso non conviene spostarsi
615 sulla prima grid invece dell'ultima *)
616 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_l)
617 (ifTM ? (test_char ? (λc:STape.c == 〈bit true,false〉))
618 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_r)
619 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
620 (seq ? (move_l …) (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))
623 definition R_move_tape ≝ λt1,t2.
624 ∀rs,n,table1,mv,table2,curc,curconfig,ls.
625 bit_or_null mv = true → only_bits_or_nulls curconfig →
626 (is_bit mv = true → is_bit curc = true) →
627 table_TM n (reverse ? table1@〈mv,false〉::table2) →
628 t1 = midtape STape (table1@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
629 〈mv,false〉 (table2@〈grid,false〉::rs) →
630 legal_tape ls 〈curc,false〉 rs →
631 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
633 legal_tape ls1 〈newc,false〉 rs1 ∧
634 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
635 〈grid,false〉::reverse ? table1@〈mv,false〉::table2@〈grid,false〉::rs1) ∧
636 ((mv = bit false ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_left STape ls 〈curc,false〉 rs) ∨
637 (mv = bit true ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_right STape ls 〈curc,false〉 rs) ∨
638 (mv = null ∧ ls1 = ls ∧ rs1 = rs ∧ curc = newc))).
640 lemma sem_move_tape : Realize ? move_tape R_move_tape.
642 cases (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit false,false〉))
643 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_l_abstract)
644 (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit true,false〉))
645 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_r_abstract)
646 (sem_seq … (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
647 (sem_seq … (sem_move_l …) (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))) intape)
648 #k * #outc * #Hloop #HR
649 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
650 #rs #n #table1 #mv #table2 #curc #curconfig #ls
651 #Hmv #Hcurconfig #Hmvcurc #Htable #Hintape #Htape #t1' #Ht1'
652 generalize in match HR; -HR *
653 [ * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
654 [| >Hintape % ] -Hta #Hceq #Hta lapply (\P Hceq) -Hceq #Hceq destruct (Hta Hceq)
655 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hintape) -Htb -Hintape
656 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
657 * #_ #Htb lapply (Htb … (refl ??) (refl ??) ?)
658 [ @daemon ] -Htb >append_cons <associative_append #Htb
659 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htb … Ht1') //
660 [ >reverse_append >reverse_append >reverse_reverse @Htable
663 -Houtc -Htb * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
664 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
667 [ >Houtc >reverse_append >reverse_append >reverse_reverse
668 >associative_append >associative_append %
671 | * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
672 [| >Hintape % ] -Hta #Hcneq cut (mv ≠ bit false)
673 [ lapply (\Pf Hcneq) @not_to_not #Heq >Heq % ] -Hcneq #Hcneq #Hta destruct (Hta)
675 [ * #tb * whd in ⊢ (%→?);#Htb cases (Htb 〈mv,false〉 ?)
676 [| >Hintape % ] -Htb #Hceq #Htb lapply (\P Hceq) -Hceq #Hceq destruct (Htb Hceq)
677 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape) -Htc -Hintape
678 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
679 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?)
680 [ @daemon ] -Htc >append_cons <associative_append #Htc
681 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htc … Ht1') //
682 [ >reverse_append >reverse_append >reverse_reverse @Htable
684 -Houtc -Htc * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
685 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
688 [ >Houtc >reverse_append >reverse_append >reverse_reverse
689 >associative_append >associative_append %
692 | * #tb * whd in ⊢ (%→?); #Htb cases (Htb 〈mv,false〉 ?)
693 [| >Hintape % ] -Htb #Hcneq' cut (mv ≠ bit true)
694 [ lapply (\Pf Hcneq') @not_to_not #Heq >Heq % ] -Hcneq' #Hcneq' #Htb destruct (Htb)
695 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape)
696 [ * >(bit_or_null_not_grid … Hmv) #Hfalse destruct (Hfalse) ] -Htc
697 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?) [@daemon] -Htc #Htc
698 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd -Htc
699 whd in ⊢ (???%→?); #Htd whd in ⊢ (%→?); #Houtc lapply (Houtc … Htd) -Houtc *
700 [ * cases Htape * * #_ #_ #Hcurc #_
701 >(bit_or_null_not_grid … Hcurc) #Hfalse destruct (Hfalse) ]
702 * #_ #Houtc lapply (Houtc … (refl ??) (refl ??) ?) [@daemon] -Houtc #Houtc
703 @(ex_intro ?? ls) @(ex_intro ?? rs) @(ex_intro ?? curc) %
708 generalize in match Hcneq; generalize in match Hcneq';
709 cases mv in Hmv; normalize //
710 [ * #_ normalize [ #Hfalse @False_ind cases Hfalse /2/ | #_ #Hfalse @False_ind cases Hfalse /2/ ]
711 |*: #Hfalse destruct (Hfalse) ]