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_____________________________________________________________*)
17 include "turing/while_machine.ma".
18 include "turing/if_machine.ma".
19 include "turing/universal/tests.ma".
21 (* ADVANCE TO MARK (right)
23 sposta la testina a destra fino a raggiungere il primo carattere marcato
27 (* 0, a ≠ mark _ ⇒ 0, R
28 0, a = mark _ ⇒ 1, N *)
30 definition atm_states ≝ initN 3.
32 definition atmr_step ≝
33 λalpha:FinSet.λtest:alpha→bool.
34 mk_TM alpha atm_states
41 | false ⇒ 〈2,Some ? 〈a',R〉〉 ]])
44 definition Ratmr_step_true ≝
47 t1 = midtape alpha ls a rs ∧ test a = false ∧
48 t2 = mk_tape alpha (a::ls) (option_hd ? rs) (tail ? rs).
50 definition Ratmr_step_false ≝
53 (current alpha t1 = None ? ∨
54 (∃a.current ? t1 = Some ? a ∧ test a = true)).
57 ∀alpha,test,ls,a0,rs. test a0 = true →
58 step alpha (atmr_step alpha test)
59 (mk_config ?? 0 (midtape … ls a0 rs)) =
60 mk_config alpha (states ? (atmr_step alpha test)) 1
62 #alpha #test #ls #a0 #ts #Htest normalize >Htest %
66 ∀alpha,test,ls,a0,rs. test a0 = false →
67 step alpha (atmr_step alpha test)
68 (mk_config ?? 0 (midtape … ls a0 rs)) =
69 mk_config alpha (states ? (atmr_step alpha test)) 2
70 (mk_tape … (a0::ls) (option_hd ? rs) (tail ? rs)).
71 #alpha #test #ls #a0 #ts #Htest normalize >Htest cases ts //
76 accRealize alpha (atmr_step alpha test)
77 2 (Ratmr_step_true alpha test) (Ratmr_step_false alpha test).
80 @(ex_intro ?? (mk_config ?? 1 (niltape ?))) %
81 [ % // #Hfalse destruct | #_ % // % % ]
82 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? 1 (leftof ? a al)))
83 % [ % // #Hfalse destruct | #_ % // % % ]
84 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? 1 (rightof ? a al)))
85 % [ % // #Hfalse destruct | #_ % // % % ]
86 | #ls #c #rs @(ex_intro ?? 2)
87 cases (true_or_false (test c)) #Htest
88 [ @(ex_intro ?? (mk_config ?? 1 ?))
91 [ whd in ⊢ (??%?); >atmr_q0_q1 //
93 | #_ % // %2 @(ex_intro ?? c) % // ]
95 | @(ex_intro ?? (mk_config ?? 2 (mk_tape ? (c::ls) (option_hd ? rs) (tail ? rs))))
98 [ whd in ⊢ (??%?); >atmr_q0_q2 //
99 | #_ @(ex_intro ?? ls) @(ex_intro ?? c) @(ex_intro ?? rs)
102 | #Hfalse @False_ind @(absurd ?? Hfalse) %
108 definition R_adv_to_mark_r ≝ λalpha,test,t1,t2.
110 (t1 = midtape alpha ls c rs →
111 ((test c = true ∧ t2 = t1) ∨
113 ∀rs1,b,rs2. rs = rs1@b::rs2 →
114 test b = true → (∀x.memb ? x rs1 = true → test x = false) →
115 t2 = midtape ? (reverse ? rs1@c::ls) b rs2))).
117 definition adv_to_mark_r ≝
118 λalpha,test.whileTM alpha (atmr_step alpha test) 2.
120 lemma wsem_adv_to_mark_r :
122 WRealize alpha (adv_to_mark_r alpha test) (R_adv_to_mark_r alpha test).
123 #alpha #test #t #i #outc #Hloop
124 lapply (sem_while … (sem_atmr_step alpha test) t i outc Hloop) [%]
125 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
127 [ #H1 #ls #c #rs #H2 >H2 in H1; whd in ⊢ (??%? → ?);
128 #Hfalse destruct (Hfalse)
129 | * #a * #Ha #Htest #ls #c #rs #H2 %
130 >H2 in Ha; whd in ⊢ (??%? → ?); #Heq destruct (Heq) % //
133 | #tapea #tapeb #tapec #Hleft #Hright #IH #HRfalse
134 lapply (IH HRfalse) -IH #IH
135 #ls #c #rs #Htapea %2
136 cases Hleft #ls0 * #a0 * #rs0 * * #Htapea' #Htest #Htapeb
138 >Htapea' in Htapea; #Htapea destruct (Htapea) % // *
139 [ #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #_
141 [ * #_ #Houtc >Houtc >Htapeb %
142 | * #Hfalse >Hfalse in Htestb; #Htestb destruct (Htestb) ]
143 | #r1 #rs1 #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #Hmemb
145 [ * #Hfalse >(Hmemb …) in Hfalse;
146 [ #Hft destruct (Hft)
148 | * #Htestr1 #H1 >reverse_cons >associative_append
149 @H1 // #x #Hx @Hmemb @memb_cons //
154 lemma terminate_adv_to_mark_r :
156 ∀t.Terminate alpha (adv_to_mark_r alpha test) t.
158 @(terminate_while … (sem_atmr_step alpha test))
161 [ % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
162 |2,3: #a0 #al0 % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
163 | #ls #c #rs generalize in match c; -c generalize in match ls; -ls
165 [#ls #c % #t1 * #ls0 * #c0 * #rs0 * *
166 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
167 % #t2 * #ls1 * #c1 * #rs1 * * >Ht1
168 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
169 | #r0 #rs0 #IH #ls #c % #t1 * #ls0 * #c0 * #rs0 * *
170 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
177 lemma sem_adv_to_mark_r :
179 Realize alpha (adv_to_mark_r alpha test) (R_adv_to_mark_r alpha test).
185 marks the current character
188 definition mark_states ≝ initN 2.
191 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) mark_states
195 | Some a' ⇒ match q with
196 [ O ⇒ let 〈a'',b〉 ≝ a' in 〈1,Some ? 〈〈a'',true〉,N〉〉
197 | S q ⇒ 〈1,None ?〉 ] ])
200 definition R_mark ≝ λalpha,t1,t2.
202 t1 = midtape (FinProd … alpha FinBool) ls 〈c,b〉 rs →
203 t2 = midtape ? ls 〈c,true〉 rs.
206 ∀alpha.Realize ? (mark alpha) (R_mark alpha).
207 #alpha #intape @(ex_intro ?? 2) cases intape
209 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
211 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
213 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
215 @ex_intro [| % [ % | #ls0 #c0 #b0 #rs0 #H1 destruct (H1) % ] ] ]
220 moves the head one step to the right
224 definition move_states ≝ initN 2.
227 λalpha:FinSet.mk_TM alpha move_states
231 | Some a' ⇒ match q with
232 [ O ⇒ 〈1,Some ? 〈a',R〉〉
233 | S q ⇒ 〈1,None ?〉 ] ])
236 definition R_move_r ≝ λalpha,t1,t2.
238 t1 = midtape alpha ls c rs →
239 t2 = mk_tape ? (c::ls) (option_hd ? rs) (tail ? rs).
242 ∀alpha.Realize ? (move_r alpha) (R_move_r alpha).
243 #alpha #intape @(ex_intro ?? 2) cases intape
245 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
247 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
249 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
251 @ex_intro [| % [ % | #ls0 #c0 #rs0 #H1 destruct (H1)
257 moves the head one step to the right
262 λalpha:FinSet.mk_TM alpha move_states
266 | Some a' ⇒ match q with
267 [ O ⇒ 〈1,Some ? 〈a',L〉〉
268 | S q ⇒ 〈1,None ?〉 ] ])
271 definition R_move_l ≝ λalpha,t1,t2.
273 t1 = midtape alpha ls c rs →
274 t2 = mk_tape ? (tail ? ls) (option_hd ? ls) (c::rs).
277 ∀alpha.Realize ? (move_l alpha) (R_move_l alpha).
278 #alpha #intape @(ex_intro ?? 2) cases intape
280 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
282 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
284 [| % [ % | #ls #c #rs #Hfalse destruct ] ]
286 @ex_intro [| % [ % | #ls0 #c0 #rs0 #H1 destruct (H1)
290 (* MOVE RIGHT AND MARK machine
292 marks the first character on the right
294 (could be rewritten using (mark; move_right))
297 definition mrm_states ≝ initN 3.
299 definition move_right_and_mark ≝
300 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) mrm_states
304 | Some a' ⇒ match q with
305 [ O ⇒ 〈1,Some ? 〈a',R〉〉
307 [ O ⇒ let 〈a'',b〉 ≝ a' in
308 〈2,Some ? 〈〈a'',true〉,N〉〉
309 | S _ ⇒ 〈2,None ?〉 ] ] ])
312 definition R_move_right_and_mark ≝ λalpha,t1,t2.
314 t1 = midtape (FinProd … alpha FinBool) ls c (〈d,b〉::rs) →
315 t2 = midtape ? (c::ls) 〈d,true〉 rs.
317 lemma sem_move_right_and_mark :
318 ∀alpha.Realize ? (move_right_and_mark alpha) (R_move_right_and_mark alpha).
319 #alpha #intape @(ex_intro ?? 3) cases intape
321 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
323 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
325 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
327 [ @ex_intro [| % [ % | #ls0 #c0 #d0 #b0 #rs0 #Hfalse destruct ] ]
328 | * #d #b #rs @ex_intro
329 [| % [ % | #ls0 #c0 #d0 #b0 #rs0 #H1 destruct (H1) % ] ] ] ]
332 (* CLEAR MARK machine
334 clears the mark in the current character
337 definition clear_mark_states ≝ initN 3.
339 definition clear_mark ≝
340 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) clear_mark_states
344 | Some a' ⇒ match q with
345 [ O ⇒ let 〈a'',b〉 ≝ a' in 〈1,Some ? 〈〈a'',false〉,N〉〉
346 | S q ⇒ 〈1,None ?〉 ] ])
349 definition R_clear_mark ≝ λalpha,t1,t2.
351 t1 = midtape (FinProd … alpha FinBool) ls 〈c,b〉 rs →
352 t2 = midtape ? ls 〈c,false〉 rs.
354 lemma sem_clear_mark :
355 ∀alpha.Realize ? (clear_mark alpha) (R_clear_mark alpha).
356 #alpha #intape @(ex_intro ?? 2) cases intape
358 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
360 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
362 [| % [ % | #ls #c #b #rs #Hfalse destruct ] ]
364 @ex_intro [| % [ % | #ls0 #c0 #b0 #rs0 #H1 destruct (H1) % ] ] ]
367 (* ADVANCE MARK RIGHT machine
369 clears mark on current char,
370 moves right, and marks new current char
374 definition adv_mark_r ≝
376 seq ? (clear_mark alpha)
377 (seq ? (move_r ?) (mark alpha)).
379 definition R_adv_mark_r ≝ λalpha,t1,t2.
381 t1 = midtape (FinProd … alpha FinBool) ls 〈c,true〉 (〈d,b〉::rs) →
382 t2 = midtape ? (〈c,false〉::ls) 〈d,true〉 rs.
384 lemma sem_adv_mark_r :
385 ∀alpha.Realize ? (adv_mark_r alpha) (R_adv_mark_r alpha).
387 cases (sem_seq ????? (sem_clear_mark …)
388 (sem_seq ????? (sem_move_r ?) (sem_mark alpha)) intape)
389 #k * #outc * #Hloop whd in ⊢ (%→?);
390 * #ta * whd in ⊢ (%→?); #Hs1 * #tb * whd in ⊢ (%→%→?); #Hs2 #Hs3
391 @(ex_intro ?? k) @(ex_intro ?? outc) %
393 | -Hloop #ls #c #d #b #rs #Hintape @(Hs3 … b)
394 @(Hs2 ls 〈c,false〉 (〈d,b〉::rs))
399 (* ADVANCE TO MARK (left)
405 definition R_adv_to_mark_l ≝ λalpha,test,t1,t2.
407 (t1 = midtape alpha ls c rs →
408 ((test c = true ∧ t2 = t1) ∨
410 ∀ls1,b,ls2. ls = ls1@b::ls2 →
411 test b = true → (∀x.memb ? x ls1 = true → test x = false) →
412 t2 = midtape ? ls2 b (reverse ? ls1@c::rs)))).
414 axiom adv_to_mark_l : ∀alpha:FinSet.(alpha → bool) → TM alpha.
415 (* definition adv_to_mark_l ≝
416 λalpha,test.whileTM alpha (atml_step alpha test) 2. *)
418 axiom wsem_adv_to_mark_l :
420 WRealize alpha (adv_to_mark_l alpha test) (R_adv_to_mark_l alpha test).
422 #alpha #test #t #i #outc #Hloop
423 lapply (sem_while … (sem_atmr_step alpha test) t i outc Hloop) [%]
424 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
426 [ #H1 #ls #c #rs #H2 >H2 in H1; whd in ⊢ (??%? → ?);
427 #Hfalse destruct (Hfalse)
428 | * #a * #Ha #Htest #ls #c #rs #H2 %
429 >H2 in Ha; whd in ⊢ (??%? → ?); #Heq destruct (Heq) % //
432 | #tapea #tapeb #tapec #Hleft #Hright #IH #HRfalse
433 lapply (IH HRfalse) -IH #IH
434 #ls #c #rs #Htapea %2
435 cases Hleft #ls0 * #a0 * #rs0 * * #Htapea' #Htest #Htapeb
437 >Htapea' in Htapea; #Htapea destruct (Htapea) % // *
438 [ #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #_
440 [ * #_ #Houtc >Houtc >Htapeb %
441 | * #Hfalse >Hfalse in Htestb; #Htestb destruct (Htestb) ]
442 | #r1 #rs1 #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #Hmemb
444 [ * #Hfalse >(Hmemb …) in Hfalse;
445 [ #Hft destruct (Hft)
447 | * #Htestr1 #H1 >reverse_cons >associative_append
448 @H1 // #x #Hx @Hmemb @memb_cons //
454 axiom terminate_adv_to_mark_l :
456 ∀t.Terminate alpha (adv_to_mark_l alpha test) t.
459 @(terminate_while … (sem_atmr_step alpha test))
462 [ % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
463 |2,3: #a0 #al0 % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
464 | #ls #c #rs generalize in match c; -c generalize in match ls; -ls
466 [#ls #c % #t1 * #ls0 * #c0 * #rs0 * *
467 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
468 % #t2 * #ls1 * #c1 * #rs1 * * >Ht1
469 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
470 | #r0 #rs0 #IH #ls #c % #t1 * #ls0 * #c0 * #rs0 * *
471 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
479 lemma sem_adv_to_mark_l :
481 Realize alpha (adv_to_mark_l alpha test) (R_adv_to_mark_l alpha test).
486 ADVANCE BOTH MARKS machine
488 l1 does not contain marks ⇒
500 definition is_marked ≝
501 λalpha.λp:FinProd … alpha FinBool.
504 definition adv_both_marks ≝
505 λalpha.seq ? (adv_mark_r alpha)
507 (seq ? (adv_to_mark_l (FinProd alpha FinBool) (is_marked alpha))
508 (adv_mark_r alpha))).
510 definition R_adv_both_marks ≝
512 ∀l0,x,a,l1,x0,a0,l2. (∀c.memb ? c l1 = true → is_marked ? c = false) →
513 t1 = midtape (FinProd … alpha FinBool)
514 (l1@〈a,false〉::〈x,true〉::l0) 〈x0,true〉 (〈a0,false〉::l2) →
515 t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (reverse ? l1@〈x0,false〉::〈a0,true〉::l2).
517 lemma sem_adv_both_marks :
518 ∀alpha.Realize ? (adv_both_marks alpha) (R_adv_both_marks alpha).
520 cases (sem_seq ????? (sem_adv_mark_r …)
521 (sem_seq ????? (sem_move_l …)
522 (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
523 (sem_adv_mark_r alpha))) intape)
524 #k * #outc * #Hloop whd in ⊢ (%→?);
525 * #ta * whd in ⊢ (%→?); #Hs1 * #tb * whd in ⊢ (%→?); #Hs2
526 * #tc * whd in ⊢ (%→%→?); #Hs3 #Hs4
527 @(ex_intro ?? k) @(ex_intro ?? outc) %
529 | -Hloop #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape
531 lapply (Hs1 … Hintape) #Hta
532 lapply (Hs2 … Hta) #Htb
534 [ * #Hfalse normalize in Hfalse; destruct (Hfalse)
536 lapply (Hs3 (l1@[〈a,false〉]) 〈x,true〉 l0 ???)
537 [ #x1 #Hx1 cases (memb_append … Hx1)
539 | #Hx1' >(memb_single … Hx1') % ]
541 | >associative_append %
542 | >reverse_append #Htc @Htc ]
546 inductive unialpha : Type[0] ≝
547 | bit : bool → unialpha
552 definition unialpha_eq ≝
554 [ bit x ⇒ match a2 with [ bit y ⇒ ¬ xorb x y | _ ⇒ false ]
555 | comma ⇒ match a2 with [ comma ⇒ true | _ ⇒ false ]
556 | bar ⇒ match a2 with [ bar ⇒ true | _ ⇒ false ]
557 | grid ⇒ match a2 with [ grid ⇒ true | _ ⇒ false ] ].
559 definition DeqUnialpha ≝ mk_DeqSet unialpha unialpha_eq ?.
560 * [ #x * [ #y cases x cases y normalize % // #Hfalse destruct
561 | *: normalize % #Hfalse destruct ]
562 |*: * [1,5,9,13: #y ] normalize % #H1 destruct % ]
565 definition FSUnialpha ≝
566 mk_FinSet DeqUnialpha [bit true;bit false;comma;bar;grid] ?.
578 l0 x a* l1 x0 a0* l2 (f(x0) == true)
580 l0 x* a l1 x0* a0 l2 (f(x0) == false)
584 definition match_and_adv ≝
585 λalpha,f.ifTM ? (test_char ? f)
586 (adv_both_marks alpha) (nop ?) tc_true.
588 definition R_match_and_adv ≝
590 ∀l0,x,a,l1,x0,a0,l2. (∀c.memb ? c l1 = true → is_marked ? c = false) →
591 t1 = midtape (FinProd … alpha FinBool)
592 (l1@〈a,false〉::〈x,true〉::l0) 〈x0,true〉 (〈a0,false〉::l2) →
593 (f 〈x0,true〉 = true ∧ t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (reverse ? l1@〈x0,false〉::〈a0,true〉::l2))
594 ∨ (f 〈x0,true〉 = false ∧ t2 = t1).
596 lemma sem_match_and_adv :
597 ∀alpha,f.Realize ? (match_and_adv alpha f) (R_match_and_adv alpha f).
599 cases (sem_if ? (test_char ? f) … tc_true (sem_test_char ? f) (sem_adv_both_marks alpha) (sem_nop ?) intape)
600 #k * #outc * #Hloop #Hif @(ex_intro ?? k) @(ex_intro ?? outc)
603 [ * #ta * whd in ⊢ (%→%→?); #Hta #Houtc
604 #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape
605 >Hintape in Hta; #Hta cases (Hta … (refl ??)) -Hta #Hf #Hta % %
606 [ @Hf | @Houtc [ @Hl1 | @Hta ] ]
607 | * #ta * whd in ⊢ (%→%→?); #Hta #Houtc
608 #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape
609 >Hintape in Hta; #Hta cases (Hta … (refl ??)) -Hta #Hf #Hta %2 %
610 [ @Hf | >Houtc @Hta ]
616 then move_right; ----
618 if current (* x0 *) = 0
619 then advance_mark ----
626 definition comp_step_subcase ≝
627 λalpha,c,elseM.ifTM ? (test_char ? (λx.x == c))
629 (seq ? (adv_to_mark_r ? (is_marked alpha))
630 (match_and_adv ? (λx.x == c))))
633 definition R_comp_step_subcase ≝
634 λalpha,c,RelseM,t1,t2.
635 ∀l0,x,a,l1,x0,a0,l2. (∀c.memb ? c l1 = true → is_marked ? c = false) →
636 t1 = midtape (FinProd … alpha FinBool)
637 l0 〈x,true〉 (〈a,false〉::l1@〈x0,true〉::〈a0,false〉::l2) →
638 (〈x,true〉 = c ∧ x = x0 ∧
639 t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (l1@〈x0,false〉::〈a0,true〉::l2))
640 ∨ (〈x,true〉 = c ∧ x ≠ x0 ∧
641 t2 = midtape (FinProd … alpha FinBool)
642 (reverse ? l1@〈a,false〉::〈x,true〉::l0) 〈x0,true〉 (〈a0,false〉::l2))
643 ∨ (〈x,true〉 ≠ c ∧ RelseM t1 t2).
645 lemma sem_comp_step_subcase :
646 ∀alpha,c,elseM,RelseM.
647 Realize ? elseM RelseM →
648 Realize ? (comp_step_subcase alpha c elseM)
649 (R_comp_step_subcase alpha c RelseM).
650 #alpha #c #elseM #RelseM #Helse #intape
651 cases (sem_if ? (test_char ? (λx.x == c)) … tc_true
652 (sem_test_char ? (λx.x == c))
653 (sem_seq ????? (sem_move_r …)
654 (sem_seq ????? (sem_adv_to_mark_r ? (is_marked alpha))
655 (sem_match_and_adv ? (λx.x == c)))) Helse intape)
656 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc)
657 % [ @Hloop ] -Hloop cases HR -HR
658 [ * #ta * whd in ⊢ (%→?); #Hta * #tb * whd in ⊢ (%→?); #Htb
659 * #tc * whd in ⊢ (%→?); #Htc whd in ⊢ (%→?); #Houtc
660 #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape %
661 >Hintape in Hta; #Hta cases (Hta ? (refl ??)) -Hta
662 #Hx #Hta lapply (Htb … Hta) -Htb #Htb
663 cases (Htc … Htb) [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
664 -Htc * #_ #Htc lapply (Htc l1 〈x0,true〉 (〈a0,false〉::l2) (refl ??) (refl ??) Hl1)
665 -Htc #Htc cases (Houtc ???????? Htc) -Houtc
667 [ % [ @(\P Hx) | <(\P Hx0) in Hx; #Hx lapply (\P Hx) #Hx' destruct (Hx') % ]
668 | >Houtc >reverse_reverse % ]
670 [ % [ @(\P Hx) | <(\P Hx) in Hx0; #Hx0 lapply (\Pf Hx0) @not_to_not #Hx' >Hx' %]
672 | (* members of lists are invariant under reverse *) @daemon ]
673 | * #ta * whd in ⊢ (%→?); #Hta #Houtc
674 #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape %2
675 >Hintape in Hta; #Hta cases (Hta ? (refl ??)) -Hta #Hx #Hta %
684 MARK NEXT TUPLE machine
685 (partially axiomatized)
687 marks the first character after the first bar (rightwards)
690 axiom myalpha : FinSet.
691 axiom is_bar : FinProd … myalpha FinBool → bool.
692 axiom is_grid : FinProd … myalpha FinBool → bool.
693 definition bar_or_grid ≝ λc.is_bar c ∨ is_grid c.
694 axiom bar : FinProd … myalpha FinBool.
695 axiom grid : FinProd … myalpha FinBool.
697 definition mark_next_tuple ≝
698 seq ? (adv_to_mark_r ? bar_or_grid)
699 (ifTM ? (test_char ? is_bar)
700 (move_r_and_mark ?) (nop ?) 1).
702 definition R_mark_next_tuple ≝
705 (* c non può essere un separatore ... speriamo *)
706 t1 = midtape ? ls c (rs1@grid::rs2) →
707 memb ? grid rs1 = false → bar_or_grid c = false →
708 (∃rs3,rs4,d,b.rs1 = rs3 @ bar :: rs4 ∧
709 memb ? bar rs3 = false ∧
710 Some ? 〈d,b〉 = option_hd ? (rs4@grid::rs2) ∧
711 t2 = midtape ? (bar::reverse ? rs3@c::ls) 〈d,true〉 (tail ? (rs4@grid::rs2)))
713 (memb ? bar rs1 = false ∧
714 t2 = midtape ? (reverse ? rs1@c::ls) grid rs2).
718 (∀x.memb A x l = true → f x = false) ∨
719 (∃l1,c,l2.f c = true ∧ l = l1@c::l2 ∧ ∀x.memb ? x l1 = true → f c = false).
721 [ % #x normalize #Hfalse *)
723 theorem sem_mark_next_tuple :
724 Realize ? mark_next_tuple R_mark_next_tuple.
726 lapply (sem_seq ? (adv_to_mark_r ? bar_or_grid)
727 (ifTM ? (test_char ? is_bar) (mark ?) (nop ?) 1) ????)
730 |||#Hif cases (Hif intape) -Hif
731 #j * #outc * #Hloop * #ta * #Hleft #Hright
732 @(ex_intro ?? j) @ex_intro [|% [@Hloop] ]
734 #ls #c #rs1 #rs2 #Hrs #Hrs1 #Hc
736 [ * #Hfalse >Hfalse in Hc; #Htf destruct (Htf)
737 | * #_ #Hta cases (tech_split ? is_bar rs1)
738 [ #H1 lapply (Hta rs1 grid rs2 (refl ??) ? ?)
739 [ (* Hrs1, H1 *) @daemon
740 | (* bar_or_grid grid = true *) @daemon
741 | -Hta #Hta cases Hright
742 [ * #tb * whd in ⊢ (%→?); #Hcurrent
743 @False_ind cases(Hcurrent grid ?)
744 [ #Hfalse (* grid is not a bar *) @daemon
746 | * #tb * whd in ⊢ (%→?); #Hcurrent
747 cases (Hcurrent grid ?)
748 [ #_ #Htb whd in ⊢ (%→?); #Houtc
751 | >Houtc >Htb >Hta % ]
755 | * #rs3 * #c0 * #rs4 * * #Hc0 #Hsplit #Hrs3
756 % @(ex_intro ?? rs3) @(ex_intro ?? rs4)
757 lapply (Hta rs3 c0 (rs4@grid::rs2) ???)
758 [ #x #Hrs3' (* Hrs1, Hrs3, Hsplit *) @daemon
759 | (* bar → bar_or_grid *) @daemon
760 | >Hsplit >associative_append % ] -Hta #Hta
762 [ * #tb * whd in ⊢ (%→?); #Hta'
765 [ #_ #Htb' >Htb' in Htb; #Htb
766 generalize in match Hsplit; -Hsplit
768 [ >(eq_pair_fst_snd … grid)
769 #Hta #Hsplit >(Htb … Hta)
771 [ @(ex_intro ?? (\fst grid)) @(ex_intro ?? (\snd grid))
772 % [ % [ % [ (* Hsplit *) @daemon |(*Hrs3*) @daemon ] | % ] | % ]
773 | (* Hc0 *) @daemon ]
774 | #r5 #rs5 >(eq_pair_fst_snd … r5)
775 #Hta #Hsplit >(Htb … Hta)
777 [ @(ex_intro ?? (\fst r5)) @(ex_intro ?? (\snd r5))
778 % [ % [ % [ (* Hc0, Hsplit *) @daemon | (*Hrs3*) @daemon ] | % ]
779 | % ] | (* Hc0 *) @daemon ] ] | >Hta % ]
780 | * #tb * whd in ⊢ (%→?); #Hta'
783 [ #Hfalse @False_ind >Hfalse in Hc0;