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 …)).
22 definition init_cell ≝
23 mk_TM STape init_cell_states
27 [ None ⇒ 〈ics1, Some ? 〈〈null,false〉,N〉〉
28 | Some _ ⇒ 〈1, None ?〉 ]
29 | S _ ⇒ 〈ics1,None ?〉 ])
32 definition R_init_cell ≝ λt1,t2.
33 (∃c.current STape t1 = Some ? c ∧ t2 = t1) ∨
34 (current STape t1 = None ? ∧ t2 = midtape ? (left ? t1) 〈null,false〉 (right ? t1)).
36 axiom sem_init_cell : Realize ? init_cell R_init_cell.
38 definition swap_states : FinSet → FinSet ≝ λalpha:FinSet.FinProd (initN 4) alpha.
41 λalpha:FinSet.λd:alpha.
42 mk_TM alpha (mcl_states alpha)
46 [ None ⇒ 〈〈3,d〉,None ?〉
50 〈〈1,a'〉,Some ? 〈a',R〉〉
51 | S q' ⇒ match q' with
54 | S q' ⇒ match q' with
58 〈〈3,d〉,None ?〉 ] ] ] ])
60 (λq.let 〈q',a〉 ≝ q in q' == 3).
65 t1 = midtape alpha ls b (a::rs) →
66 t2 = midtape alpha ls a (b::rs).
70 ∀alpha:FinSet.∀d,a,ls,a0,rs.
71 step alpha (swap alpha d)
72 (mk_config ?? 〈0,a〉 (mk_tape … ls (Some ? a0) rs)) =
73 mk_config alpha (states ? (swap alpha d)) 〈1,a0〉
74 (tape_move_right alpha ls a0 rs).
82 ∀alpha:FinSet.∀d,a,ls,a0,rs.
83 step alpha (swap alpha d)
84 (mk_config ?? 〈1,a〉 (mk_tape … ls (Some ? a0) rs)) =
85 mk_config alpha (states ? (swap alpha d)) 〈2,a0〉
86 (tape_move_left alpha ls a rs).
87 #alpha #sep #a #ls #a0 * //
91 ∀alpha:FinSet.∀d,a,ls,a0,rs.
92 step alpha (swap alpha d)
93 (mk_config ?? 〈2,a〉 (mk_tape … ls (Some ? a0) rs)) =
94 mk_config alpha (states ? (swap alpha d)) 〈3,d〉
95 (tape_move_left alpha ls a rs).
96 #alpha #sep #a #ls #a0 * //
102 Realize alpha (swap alpha d) (R_swap alpha).
103 #alpha #d #tapein @(ex_intro ?? 4) cases tapein
104 [ @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
105 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
106 | #a #al @ex_intro [| % [ % | #a #b #ls #rs #Hfalse destruct (Hfalse) ] ]
107 | #ls #c #rs cases rs
108 [ @ex_intro [| % [ % | #a #b #ls0 #rs0 #Hfalse destruct (Hfalse) ] ]
109 | -rs #r #rs @ex_intro
112 | #r0 #c0 #ls0 #rs0 #Htape destruct (Htape) normalize cases ls0
113 [% | #l1 #ls1 %] ] ] ] ]
116 axiom ssem_move_char_l :
118 Realize alpha (move_char_l alpha sep) (R_move_char_l alpha sep).
123 ls # current c # table # d? rs
125 ls # current c # table # d? rs init
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 # table d # rs --------------------
135 ls # current c # table d # rs
137 ls # current c # d table # rs sub1
139 ls # current c # d table # rs
141 ls # current c d # table # rs -------------------
143 ls # current c d # table # rs -------------------
145 ls # current c d # table # rs
147 ls # c current d # table # rs sub1
149 ls # c current d # table # rs
151 ls c # current d # table # rs ------------------
173 (* l1 # l2 r ---> l1 r # l2
177 seq ? (move_l …) (seq ? (move_char_l STape 〈grid,false〉)
178 (swap STape 〈grid,false〉)).
179 definition R_mtr_aux ≝ λt1,t2.
180 ∀l1,l2,l3,r. t1 = midtape STape (l2@〈grid,false〉::l1) r l3 → no_grids l2 →
181 t2 = midtape STape l1 r (〈grid,false〉::reverse ? l2@l3).
183 lemma sem_mtr_aux : Realize ? mtr_aux R_mtr_aux.
185 cases (sem_seq … (sem_move_l …) (sem_seq … (ssem_move_char_l STape 〈grid,false〉)
186 (sem_swap STape 〈grid,false〉)) intape)
187 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
188 #l1 #l2 #l3 #r #Hintape #Hl2
189 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta #Hta
190 * #tb * whd in ⊢(%→?); generalize in match Hta; -Hta cases l2 in Hl2;
191 [ #_ #Hta #Htb lapply (Htb … Hta) -Htb * #Htb lapply (Htb (refl ??)) -Htb #Htb #_
192 whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … Hta) -Houtc #Houtc @Houtc
193 | #c0 #l0 #Hnogrids #Hta #Htb lapply (Htb … Hta) -Htb * #_ #Htb
194 lapply (Htb … (refl ??) ??)
195 [ cases (true_or_false (memb STape 〈grid,false〉 l0)) #Hmemb
196 [ @False_ind lapply (Hnogrids 〈grid,false〉 ?)
197 [ @memb_cons // | normalize #Hfalse destruct (Hfalse) ]
199 | % #Hc0 lapply (Hnogrids c0 ?)
200 [ @memb_hd | >Hc0 normalize #Hfalse destruct (Hfalse) ]
201 | #Htb whd in ⊢(%→?); >Htb #Houtc lapply (Houtc … (refl ??)) -Houtc #Houtc
202 >reverse_cons >associative_append @Houtc
206 definition move_tape_r ≝
207 seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
208 (seq ? (swap STape 〈grid,false〉)
209 (seq ? mtr_aux (seq ? (move_l …) (seq ? mtr_aux (move_r …))))))).
211 definition R_move_tape_r ≝ λt1,t2.
212 ∀rs,n,table,c0,bc0,curconfig,ls0.
213 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
214 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
217 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@〈null,false〉::
218 〈grid,false〉::reverse STape table@[〈grid,false〉])) ∨
219 (∃r0,rs0.rs = r0::rs0 ∧
220 t2 = midtape STape (〈c0,bc0〉::ls0) 〈grid,false〉 (reverse STape curconfig@r0::
221 〈grid,false〉::reverse STape table@〈grid,false〉::rs0)).
223 lemma sem_move_tape_r : Realize ? move_tape_r R_move_tape_r.
225 cases (sem_seq …(sem_move_r …) (sem_seq … sem_init_cell (sem_seq … (sem_move_l …)
226 (sem_seq … (sem_swap STape 〈grid,false〉) (sem_seq … sem_mtr_aux
227 (sem_seq … (sem_move_l …) (sem_seq … sem_mtr_aux (sem_move_r …))))))) tapein)
228 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
229 #rs #n #table #c0 #bc0 #curconfig #ls0 #Hbitnullc0 #Hbitnullcc #Htable #Htapein
230 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Htapein) -Hta #Hta
231 * #tb * whd in ⊢ (%→?); *
233 generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
234 [ #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
235 #r1 #rs1 #Htapein #Hta change with (midtape ?? r1 rs1) in Hta:(???%); >Hta
236 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
237 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
238 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [ (*memb_reverse @(no_grids_in_table … Htable)*) @daemon ] -Hte #Hte
239 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
240 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
241 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
242 %2 @(ex_intro ?? r1) @(ex_intro ?? rs1) % [%] @Houtc
243 | * generalize in match Hta; generalize in match Htapein; -Htapein -Hta cases rs
244 [|#r1 #rs1 #_ #Hta >Hta normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
245 #Htapein #Hta change with (rightof ???) in Hta:(???%); >Hta
246 #Hr0 whd in Hr0:(??%?); #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc #Htc
247 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
248 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd ?) [(*same as above @(no_grids_in_table … Htable) *) @daemon ] -Hte #Hte
249 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Htf #Htf
250 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf ?) [ #x #Hx @bit_or_null_not_grid @Hbitnullcc // ] -Htg #Htg
251 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htg) -Houtc #Houtc
258 ls # current c # table # d rs
260 ls # current c # table # d rs
262 ls # current c # table d # rs
264 ls # current c # d table # rs
266 ls # current c # d table # rs
268 ls # current c d # table # rs
270 ls # current c d # table # rs
272 ls # c current c # table # rs
274 ls # c current c # table # rs
276 ls c # current c # table # rs
289 axiom move_tape_l : TM STape.
290 (* seq ? (move_r …) (seq ? init_cell (seq ? (move_l …)
291 (seq ? (swap STape 〈grid,false〉)
292 (seq ? mtr_aux (seq ? (move_l …) mtr_aux))))). *)
294 definition R_move_tape_l ≝ λt1,t2.
295 ∀rs,n,table,c0,bc0,curconfig,ls0.
296 bit_or_null c0 = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
297 t1 = midtape STape (table@〈grid,false〉::〈c0,bc0〉::curconfig@〈grid,false〉::ls0)
300 t2 = midtape STape [] 〈grid,false〉
301 (reverse ? curconfig@〈null,false〉::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)) ∨
302 (∃l1,ls1. ls0 = l1::ls1 ∧
303 t2 = midtape STape ls1 〈grid,false〉
304 (reverse ? curconfig@l1::〈grid,false〉::reverse ? table@〈grid,false〉::〈c0,bc0〉::rs)).
306 axiom sem_move_tape_l : Realize ? move_tape_l R_move_tape_l.
310 case bit false: move_tape_l
311 case bit true: move_tape_r
312 case null: adv_to_grid_l; move_l; adv_to_grid_l;
315 definition lift_tape ≝ λls,c,rs.
317 let c' ≝ match c0 with
321 mk_tape STape ls c' rs.
323 definition sim_current_of_tape ≝ λt.
324 match current STape t with
325 [ None ⇒ 〈null,false〉
329 definition move_of_unialpha ≝
331 [ bit x ⇒ match x with [ true ⇒ R | false ⇒ L ]
334 definition R_uni_step ≝ λt1,t2.
335 ∀n,table,c,c1,ls,rs,curs,curc,news,newc,mv.
337 match_in_table n (〈c,false〉::curs) 〈curc,false〉
338 (〈c1,false〉::news) 〈newc,false〉 〈mv,false〉 table →
339 t1 = midtape STape (〈grid,false〉::ls) 〈c,false〉
340 (curs@〈curc,false〉::〈grid,false〉::table@〈grid,false〉::rs) →
341 ∀t1',ls1,rs1.t1' = lift_tape ls 〈curc,false〉 rs →
342 (t2 = midtape STape (〈grid,false〉::ls1) 〈c1,false〉
343 (news@〈newc,false〉::〈grid,false〉::table@〈grid,false〉::rs1) ∧
344 lift_tape ls1 〈newc,false〉 rs1 =
345 tape_move STape t1' (Some ? 〈〈newc,false〉,move_of_unialpha mv〉)).
347 definition no_nulls ≝
348 λl:list STape.∀x.memb ? x l = true → is_null (\fst x) = false.
350 definition current_of_alpha ≝ λc:STape.
351 match \fst c with [ null ⇒ None ? | _ ⇒ Some ? c ].
359 definition legal_tape ≝ λls,c,rs.
360 no_marks (c::ls@rs) ∧ only_bits (ls@rs) ∧ bit_or_null (\fst c) = true ∧
361 (\fst c ≠ null ∨ ls = [] ∨ rs = []).
363 lemma legal_tape_left :
364 ∀ls,c,rs.legal_tape ls c rs →
365 left ? (mk_tape STape ls (current_of_alpha c) rs) = ls.
366 #ls * #c #bc #rs * * * #_ #_ #_ *
370 | * #Hfalse @False_ind /2/
372 | #Hls >Hls cases c // cases rs //
374 | #Hrs >Hrs cases c // cases ls //
378 axiom legal_tape_current :
379 ∀ls,c,rs.legal_tape ls c rs →
380 current ? (mk_tape STape ls (current_of_alpha c) rs) = current_of_alpha c.
382 axiom legal_tape_right :
383 ∀ls,c,rs.legal_tape ls c rs →
384 right ? (mk_tape STape ls (current_of_alpha c) rs) = rs.
387 lemma legal_tape_cases :
388 ∀ls,c,rs.legal_tape ls c rs →
389 \fst c ≠ null ∨ (\fst c = null ∧ (ls = [] ∨ rs = [])).
390 #ls #c #rs cases c #c0 #bc0 cases c0
391 [ #c1 normalize #_ % % #Hfalse destruct (Hfalse)
396 | #r0 #rs0 normalize * * #_ #Hrs destruct (Hrs) ]
398 |*: #_ % % #Hfalse destruct (Hfalse) ]
401 axiom legal_tape_conditions :
402 ∀ls,c,rs.(\fst c ≠ null ∨ ls = [] ∨ rs = []) → legal_tape ls c rs.
405 [ >(eq_pair_fst_snd ?? c) cases (\fst c)
407 | * #Hfalse @False_ind /2/
410 | cases ls [ * #Hfalse @False_ind /2/ ]
417 definition R_move_tape_r_abstract ≝ λt1,t2.
418 ∀rs,n,table,curc,curconfig,ls.
419 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
420 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
422 legal_tape ls 〈curc,false〉 rs →
423 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
425 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
426 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
427 lift_tape ls1 〈newc,false〉 rs1 =
428 tape_move_right STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
430 lemma lift_tape_not_null :
431 ∀ls,c,rs. is_null (\fst c) = false →
432 lift_tape ls c rs = mk_tape STape ls (Some ? c) rs.
433 #ls * #c0 #bc0 #rs cases c0
434 [|normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
438 axiom bit_not_null : ∀d.is_bit d = true → is_null d = false.
440 lemma mtr_concrete_to_abstract :
441 ∀t1,t2.R_move_tape_r t1 t2 → R_move_tape_r_abstract t1 t2.
442 #t1 #t2 whd in ⊢(%→?); #Hconcrete
443 #rs #n #table #curc #curconfig #ls #Hbitcurc #Hcurconfig #Htable #Ht1
444 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
445 cases (Hconcrete … Htable Ht1) //
447 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? [])
448 @(ex_intro ?? null) %
453 [ >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
455 | @Hnomarks @(memb_append_l1 … Hx') ]
456 | >append_nil #x #Hx cases (orb_true_l … Hx) #Hx'
458 | @Hbits @(memb_append_l1 … Hx') ]]
462 | * * #r0 #br0 * #rs0 * #Hrs
464 [ @(Hnomarks 〈r0,br0〉) @memb_cons @memb_append_l2 >Hrs @memb_hd]
465 #Hbr0 >Hbr0 in Hrs; #Hrs #Ht2
466 @(ex_intro ?? (〈curc,false〉::ls)) @(ex_intro ?? rs0)
470 | >Hrs >lift_tape_not_null
472 | @bit_not_null @(Hbits 〈r0,false〉) >Hrs @memb_append_l2 @memb_hd ] ]
474 [ #x #Hx cases (orb_true_l … Hx) #Hx'
476 | cases (memb_append … Hx') #Hx'' @Hnomarks
477 [ @(memb_append_l1 … Hx'')
478 | >Hrs @memb_cons @memb_append_l2 @(memb_cons … Hx'') ]
480 | whd in ⊢ (?%); #x #Hx cases (orb_true_l … Hx) #Hx'
482 | cases (memb_append … Hx') #Hx'' @Hbits
483 [ @(memb_append_l1 … Hx'') | >Hrs @memb_append_l2 @(memb_cons … Hx'') ]
485 | whd in ⊢ (??%?); >(Hbits 〈r0,false〉) //
486 @memb_append_l2 >Hrs @memb_hd ]
487 | % % % #Hr0 lapply (Hbits 〈r0,false〉?)
488 [ @memb_append_l2 >Hrs @memb_hd
489 | >Hr0 normalize #Hfalse destruct (Hfalse)
493 definition R_move_tape_l_abstract ≝ λt1,t2.
494 ∀rs,n,table,curc,curconfig,ls.
495 is_bit curc = true → only_bits_or_nulls curconfig → table_TM n (reverse ? table) →
496 t1 = midtape STape (table@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
498 legal_tape ls 〈curc,false〉 rs →
499 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
501 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
502 〈grid,false〉::reverse ? table@〈grid,false〉::rs1) ∧
503 lift_tape ls1 〈newc,false〉 rs1 =
504 tape_move_left STape ls 〈curc,false〉 rs ∧ legal_tape ls1 〈newc,false〉 rs1).
506 lemma mtl_concrete_to_abstract :
507 ∀t1,t2.R_move_tape_l t1 t2 → R_move_tape_l_abstract t1 t2.
508 #t1 #t2 whd in ⊢(%→?); #Hconcrete
509 #rs #n #table #curc #curconfig #ls #Hcurc #Hcurconfig #Htable #Ht1
510 * * * #Hnomarks #Hbits #Hcurc #Hlegal #t1' #Ht1'
511 cases (Hconcrete … Htable Ht1) //
514 @(ex_intro ?? (〈curc,false〉::rs))
515 @(ex_intro ?? null) %
520 [ #x #Hx cases (orb_true_l … Hx) #Hx'
522 | @Hnomarks >Hls @Hx' ]
523 | #x #Hx cases (orb_true_l … Hx) #Hx'
525 | @Hbits >Hls @Hx' ]]
529 | * * #l0 #bl0 * #ls0 * #Hls
531 [ @(Hnomarks 〈l0,bl0〉) @memb_cons @memb_append_l1 >Hls @memb_hd]
532 #Hbl0 >Hbl0 in Hls; #Hls #Ht2
533 @(ex_intro ?? ls0) @(ex_intro ?? (〈curc,false〉::rs))
537 | >Hls >lift_tape_not_null
539 | @bit_not_null @(Hbits 〈l0,false〉) >Hls @memb_append_l1 @memb_hd ] ]
541 [ #x #Hx cases (orb_true_l … Hx) #Hx'
543 | cases (memb_append … Hx') #Hx'' @Hnomarks
544 [ >Hls @memb_cons @memb_cons @(memb_append_l1 … Hx'')
545 | cases (orb_true_l … Hx'') #Hx'''
546 [ >(\P Hx''') @memb_hd
547 | @memb_cons @(memb_append_l2 … Hx''')]
550 | whd in ⊢ (?%); #x #Hx cases (memb_append … Hx) #Hx'
551 [ @Hbits >Hls @memb_cons @(memb_append_l1 … Hx')
552 | cases (orb_true_l … Hx') #Hx''
554 | @Hbits @(memb_append_l2 … Hx'')
556 | whd in ⊢ (??%?); >(Hbits 〈l0,false〉) //
557 @memb_append_l1 >Hls @memb_hd ]
558 | % % % #Hl0 lapply (Hbits 〈l0,false〉?)
559 [ @memb_append_l1 >Hls @memb_hd
560 | >Hl0 normalize #Hfalse destruct (Hfalse)
564 lemma Realize_to_Realize :
565 ∀alpha,M,R1,R2.(∀t1,t2.R1 t1 t2 → R2 t1 t2) → Realize alpha M R1 → Realize alpha M R2.
566 #alpha #M #R1 #R2 #Himpl #HR1 #intape
567 cases (HR1 intape) -HR1 #k * #outc * #Hloop #HR1
568 @(ex_intro ?? k) @(ex_intro ?? outc) % /2/
571 lemma sem_move_tape_l_abstract : Realize … move_tape_l R_move_tape_l_abstract.
572 @(Realize_to_Realize … mtl_concrete_to_abstract) //
575 lemma sem_move_tape_r_abstract : Realize … move_tape_r R_move_tape_r_abstract.
576 @(Realize_to_Realize … mtr_concrete_to_abstract) //
580 t1 = ls # cs c # table # rs
582 let simt ≝ lift_tape ls c rs in
583 let simt' ≝ move_left simt' in
585 t2 = left simt'# cs (sim_current_of_tape simt') # table # right simt'
591 definition R_exec_move ≝ λt1,t2.
592 ∀ls,current,table1,newcurrent,table2,rs.
593 t1 = midtape STape (current@〈grid,false〉::ls) 〈grid,false〉
594 (table1@〈comma,true〉::newcurrent@〈comma,false〉::move::table2@
596 table_TM (table1@〈comma,false〉::newcurrent@〈comma,false〉::move::table2) →
604 if is_true(current) (* current state is final *)
609 if is_marked(current) = false (* match ok *)
616 definition move_tape ≝
617 ifTM ? (test_char ? (λc:STape.c == 〈bit false,false〉))
618 (* spostamento a sinistra: verificare se per caso non conviene spostarsi
619 sulla prima grid invece dell'ultima *)
620 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_l)
621 (ifTM ? (test_char ? (λc:STape.c == 〈bit true,false〉))
622 (seq ? (adv_to_mark_r ? (λc:STape.is_grid (\fst c))) move_tape_r)
623 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
624 (seq ? (move_l …) (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))
627 definition R_move_tape ≝ λt1,t2.
628 ∀rs,n,table1,mv,table2,curc,curconfig,ls.
629 bit_or_null mv = true → only_bits_or_nulls curconfig →
630 (is_bit mv = true → is_bit curc = true) →
631 table_TM n (reverse ? table1@〈mv,false〉::table2) →
632 t1 = midtape STape (table1@〈grid,false〉::〈curc,false〉::curconfig@〈grid,false〉::ls)
633 〈mv,false〉 (table2@〈grid,false〉::rs) →
634 legal_tape ls 〈curc,false〉 rs →
635 ∀t1'.t1' = lift_tape ls 〈curc,false〉 rs →
637 legal_tape ls1 〈newc,false〉 rs1 ∧
638 (t2 = midtape STape ls1 〈grid,false〉 (reverse ? curconfig@〈newc,false〉::
639 〈grid,false〉::reverse ? table1@〈mv,false〉::table2@〈grid,false〉::rs1) ∧
640 ((mv = bit false ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_left STape ls 〈curc,false〉 rs) ∨
641 (mv = bit true ∧ lift_tape ls1 〈newc,false〉 rs1 = tape_move_right STape ls 〈curc,false〉 rs) ∨
642 (mv = null ∧ ls1 = ls ∧ rs1 = rs ∧ curc = newc))).
644 lemma sem_move_tape : Realize ? move_tape R_move_tape.
646 cases (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit false,false〉))
647 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_l_abstract)
648 (sem_if ? (test_char ??) … tc_true (sem_test_char ? (λc:STape.c == 〈bit true,false〉))
649 (sem_seq … (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c))) sem_move_tape_r_abstract)
650 (sem_seq … (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
651 (sem_seq … (sem_move_l …) (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))))) intape)
652 #k * #outc * #Hloop #HR
653 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
654 #rs #n #table1 #mv #table2 #curc #curconfig #ls
655 #Hmv #Hcurconfig #Hmvcurc #Htable #Hintape #Htape #t1' #Ht1'
656 generalize in match HR; -HR *
657 [ * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
658 [| >Hintape % ] -Hta #Hceq #Hta lapply (\P Hceq) -Hceq #Hceq destruct (Hta Hceq)
659 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hintape) -Htb -Hintape
660 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
661 * #_ #Htb lapply (Htb … (refl ??) (refl ??) ?)
662 [ @daemon ] -Htb >append_cons <associative_append #Htb
663 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htb … Ht1') //
664 [ >reverse_append >reverse_append >reverse_reverse @Htable
667 -Houtc -Htb * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
668 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
671 [ >Houtc >reverse_append >reverse_append >reverse_reverse
672 >associative_append >associative_append %
675 | * #ta * whd in ⊢ (%→?); #Hta cases (Hta 〈mv,false〉 ?)
676 [| >Hintape % ] -Hta #Hcneq cut (mv ≠ bit false)
677 [ lapply (\Pf Hcneq) @not_to_not #Heq >Heq % ] -Hcneq #Hcneq #Hta destruct (Hta)
679 [ * #tb * whd in ⊢ (%→?);#Htb cases (Htb 〈mv,false〉 ?)
680 [| >Hintape % ] -Htb #Hceq #Htb lapply (\P Hceq) -Hceq #Hceq destruct (Htb Hceq)
681 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape) -Htc -Hintape
682 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
683 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?)
684 [ @daemon ] -Htc >append_cons <associative_append #Htc
685 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htc … Ht1') //
686 [ >reverse_append >reverse_append >reverse_reverse @Htable
688 -Houtc -Htc * #ls1 * #rs1 * #newc * * #Houtc #Hnewtape #Hnewtapelegal
689 @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
692 [ >Houtc >reverse_append >reverse_append >reverse_reverse
693 >associative_append >associative_append %
696 | * #tb * whd in ⊢ (%→?); #Htb cases (Htb 〈mv,false〉 ?)
697 [| >Hintape % ] -Htb #Hcneq' cut (mv ≠ bit true)
698 [ lapply (\Pf Hcneq') @not_to_not #Heq >Heq % ] -Hcneq' #Hcneq' #Htb destruct (Htb)
699 * #tc * whd in ⊢ (%→?); #Htc cases (Htc … Hintape)
700 [ * >(bit_or_null_not_grid … Hmv) #Hfalse destruct (Hfalse) ] -Htc
701 * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?) [@daemon] -Htc #Htc
702 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd -Htc
703 whd in ⊢ (???%→?); #Htd whd in ⊢ (%→?); #Houtc lapply (Houtc … Htd) -Houtc *
704 [ * cases Htape * * #_ #_ #Hcurc #_
705 >(bit_or_null_not_grid … Hcurc) #Hfalse destruct (Hfalse) ]
706 * #_ #Houtc lapply (Houtc … (refl ??) (refl ??) ?) [@daemon] -Houtc #Houtc
707 @(ex_intro ?? ls) @(ex_intro ?? rs) @(ex_intro ?? curc) %
712 generalize in match Hcneq; generalize in match Hcneq';
713 cases mv in Hmv; normalize //
714 [ * #_ normalize [ #Hfalse @False_ind cases Hfalse /2/ | #_ #Hfalse @False_ind cases Hfalse /2/ ]
715 |*: #Hfalse destruct (Hfalse) ]