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/if_machine.ma".
18 include "turing/basic_machines.ma".
19 include "turing/universal/alphabet.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 atm0 : atm_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
33 definition atm1 : atm_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
34 definition atm2 : atm_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
36 definition atmr_step ≝
37 λalpha:FinSet.λtest:alpha→bool.
38 mk_TM alpha atm_states
41 [ None ⇒ 〈atm1, None ?〉
44 [ true ⇒ 〈atm1,None ?〉
45 | false ⇒ 〈atm2,Some ? 〈a',R〉〉 ]])
46 atm0 (λx.notb (x == atm0)).
48 definition Ratmr_step_true ≝
51 t1 = midtape alpha ls a rs ∧ test a = false ∧
52 t2 = mk_tape alpha (a::ls) (option_hd ? rs) (tail ? rs).
54 definition Ratmr_step_false ≝
57 (current alpha t1 = None ? ∨
58 (∃a.current ? t1 = Some ? a ∧ test a = true)).
61 ∀alpha,test,ls,a0,rs. test a0 = true →
62 step alpha (atmr_step alpha test)
63 (mk_config ?? atm0 (midtape … ls a0 rs)) =
64 mk_config alpha (states ? (atmr_step alpha test)) atm1
66 #alpha #test #ls #a0 #ts #Htest whd in ⊢ (??%?);
67 whd in match (trans … 〈?,?〉); >Htest %
71 ∀alpha,test,ls,a0,rs. test a0 = false →
72 step alpha (atmr_step alpha test)
73 (mk_config ?? atm0 (midtape … ls a0 rs)) =
74 mk_config alpha (states ? (atmr_step alpha test)) atm2
75 (mk_tape … (a0::ls) (option_hd ? rs) (tail ? rs)).
76 #alpha #test #ls #a0 #ts #Htest whd in ⊢ (??%?);
77 whd in match (trans … 〈?,?〉); >Htest cases ts //
82 accRealize alpha (atmr_step alpha test)
83 atm2 (Ratmr_step_true alpha test) (Ratmr_step_false alpha test).
86 @(ex_intro ?? (mk_config ?? atm1 (niltape ?))) %
87 [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
88 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? atm1 (leftof ? a al)))
89 % [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
90 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? atm1 (rightof ? a al)))
91 % [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
92 | #ls #c #rs @(ex_intro ?? 2)
93 cases (true_or_false (test c)) #Htest
94 [ @(ex_intro ?? (mk_config ?? atm1 ?))
97 [ whd in ⊢ (??%?); >atmr_q0_q1 //
98 | whd in ⊢ ((??%%)→?); #Hfalse destruct ]
99 | #_ % // %2 @(ex_intro ?? c) % // ]
101 | @(ex_intro ?? (mk_config ?? atm2 (mk_tape ? (c::ls) (option_hd ? rs) (tail ? rs))))
104 [ whd in ⊢ (??%?); >atmr_q0_q2 //
105 | #_ @(ex_intro ?? ls) @(ex_intro ?? c) @(ex_intro ?? rs)
108 | #Hfalse @False_ind @(absurd ?? Hfalse) %
114 lemma dec_test: ∀alpha,rs,test.
115 decidable (∀c.memb alpha c rs = true → test c = false).
116 #alpha #rs #test elim rs
117 [%1 #n normalize #H destruct
118 |#a #tl cases (true_or_false (test a)) #Ha
119 [#_ %2 % #Hall @(absurd ?? not_eq_true_false) <Ha
121 |* [#Hall %1 #c #memc cases (orb_true_l … memc)
122 [#eqca >(\P eqca) @Ha |@Hall]
123 |#Hnall %2 @(not_to_not … Hnall) #Hall #c #memc @Hall @memb_cons //
127 definition R_adv_to_mark_r ≝ λalpha,test,t1,t2.
128 (current ? t1 = None ? → t1 = t2) ∧
130 (t1 = midtape alpha ls c rs →
131 ((test c = true ∧ t2 = t1) ∨
133 (∀rs1,b,rs2. rs = rs1@b::rs2 →
134 test b = true → (∀x.memb ? x rs1 = true → test x = false) →
135 t2 = midtape ? (reverse ? rs1@c::ls) b rs2) ∧
136 ((∀x.memb ? x rs = true → test x = false) →
137 ∀a,l.reverse ? (c::rs) = a::l →
138 t2 = rightof alpha a (l@ls))))).
140 definition adv_to_mark_r ≝
141 λalpha,test.whileTM alpha (atmr_step alpha test) atm2.
143 lemma wsem_adv_to_mark_r :
145 WRealize alpha (adv_to_mark_r alpha test) (R_adv_to_mark_r alpha test).
146 #alpha #test #t #i #outc #Hloop
147 lapply (sem_while … (sem_atmr_step alpha test) t i outc Hloop) [%]
148 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
152 |#ls #c #rs #H2 >H2 in H1; whd in ⊢ (??%? → ?);
153 #Hfalse destruct (Hfalse)
155 | * #a * #Ha #Htest %
156 [ >Ha #H destruct (H);
158 >H2 in Ha; whd in ⊢ (??%? → ?); #Heq destruct (Heq) % //
162 | #tapeb #tapec #Hleft #Hright #IH #HRfalse
163 lapply (IH HRfalse) -IH #IH %
164 [cases Hleft #ls * #a * #rs * * #Htapea #_ #_ >Htapea
165 whd in ⊢((??%?)→?); #H destruct (H);
166 |#ls #c #rs #Htapea %2
167 cases Hleft #ls0 * #a0 * #rs0 * * #Htapea' #Htest #Htapeb
168 >Htapea' in Htapea; #Htapea destruct (Htapea) % [ % // ]
170 [ #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #_
171 cases (proj2 ?? IH … Htapeb)
172 [ * #_ #Houtc >Houtc >Htapeb %
173 | * * >Htestb #Hfalse destruct (Hfalse) ]
174 | #r1 #rs1 #b #rs2 #Hrs >Hrs in Htapeb; #Htapeb #Htestb #Hmemb
175 cases (proj2 ?? IH … Htapeb)
176 [ * #Hfalse >(Hmemb …) in Hfalse;
177 [ #Hft destruct (Hft)
179 | * * #Htestr1 #H1 #_ >reverse_cons >associative_append
180 @H1 // #x #Hx @Hmemb @memb_cons //
183 |cases rs in Htapeb; normalize in ⊢ (%→?);
184 [#Htapeb #_ #a0 #l whd in ⊢ ((??%?)→?); #Hrev destruct (Hrev)
185 >Htapeb in IH; #IH cases (proj1 ?? IH … (refl …)) //
186 |#r1 #rs1 #Htapeb #Hmemb
187 cases (proj2 ?? IH … Htapeb) [ * >Hmemb [ #Hfalse destruct(Hfalse) ] @memb_hd ]
188 * #_ #H1 #a #l <(reverse_reverse … l) cases (reverse … l)
189 [#H cut (c::r1::rs1 = [a])
190 [<(reverse_reverse … (c::r1::rs1)) >H //]
191 #Hrev destruct (Hrev)
192 |#a1 #l2 >reverse_cons >reverse_cons >reverse_cons
193 #Hrev cut ([c] = [a1])
194 [@(append_l2_injective_r ?? (a::reverse … l2) … Hrev) //]
195 #Ha <Ha >associative_append @H1
196 [#x #membx @Hmemb @memb_cons @membx
197 |<(append_l1_injective_r ?? (a::reverse … l2) … Hrev) //
201 lemma terminate_adv_to_mark_r :
203 ∀t.Terminate alpha (adv_to_mark_r alpha test) t.
205 @(terminate_while … (sem_atmr_step alpha test))
208 [ % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
209 |2,3: #a0 #al0 % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
210 | #ls #c #rs generalize in match c; -c generalize in match ls; -ls
212 [#ls #c % #t1 * #ls0 * #c0 * #rs0 * *
213 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
214 % #t2 * #ls1 * #c1 * #rs1 * * >Ht1
215 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
216 | #r0 #rs0 #IH #ls #c % #t1 * #ls0 * #c0 * #rs0 * *
217 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
224 lemma sem_adv_to_mark_r :
226 Realize alpha (adv_to_mark_r alpha test) (R_adv_to_mark_r alpha test).
232 marks the current character
235 definition mark_states ≝ initN 2.
237 definition ms0 : mark_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 2 (refl …)).
238 definition ms1 : mark_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 2 (refl …)).
241 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) mark_states
244 [ None ⇒ 〈ms1,None ?〉
245 | Some a' ⇒ match (pi1 … q) with
246 [ O ⇒ let 〈a'',b〉 ≝ a' in 〈ms1,Some ? 〈〈a'',true〉,N〉〉
247 | S q ⇒ 〈ms1,None ?〉 ] ])
250 definition R_mark ≝ λalpha,t1,t2.
252 t1 = midtape (FinProd … alpha FinBool) ls 〈c,b〉 rs →
253 t2 = midtape ? ls 〈c,true〉 rs) ∧
254 (current ? t1 = None ? → t2 = t1).
257 ∀alpha.Realize ? (mark alpha) (R_mark alpha).
258 #alpha #intape @(ex_intro ?? 2) cases intape
260 [| % [ % | % [#ls #c #b #rs #Hfalse destruct | // ]]]
262 [| % [ % | % [#ls #c #b #rs #Hfalse destruct | // ]]]
264 [| % [ % | % [#ls #c #b #rs #Hfalse destruct ] // ]]
266 @ex_intro [| % [ % | %
267 [#ls0 #c0 #b0 #rs0 #H1 destruct (H1) %
268 | whd in ⊢ ((??%?)→?); #H1 destruct (H1)]]]
272 (* MOVE RIGHT AND MARK machine
274 marks the first character on the right
276 (could be rewritten using (mark; move_right))
279 definition mrm_states ≝ initN 3.
281 definition mrm0 : mrm_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
282 definition mrm1 : mrm_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
283 definition mrm2 : mrm_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
285 definition move_right_and_mark ≝
286 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) mrm_states
289 [ None ⇒ 〈mrm2,None ?〉
290 | Some a' ⇒ match pi1 … q with
291 [ O ⇒ 〈mrm1,Some ? 〈a',R〉〉
293 [ O ⇒ let 〈a'',b〉 ≝ a' in
294 〈mrm2,Some ? 〈〈a'',true〉,N〉〉
295 | S _ ⇒ 〈mrm2,None ?〉 ] ] ])
298 definition R_move_right_and_mark ≝ λalpha,t1,t2.
300 t1 = midtape (FinProd … alpha FinBool) ls c (〈d,b〉::rs) →
301 t2 = midtape ? (c::ls) 〈d,true〉 rs.
303 lemma sem_move_right_and_mark :
304 ∀alpha.Realize ? (move_right_and_mark alpha) (R_move_right_and_mark alpha).
305 #alpha #intape @(ex_intro ?? 3) cases intape
307 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
309 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
311 [| % [ % | #ls #c #d #b #rs #Hfalse destruct ] ]
313 [ @ex_intro [| % [ % | #ls0 #c0 #d0 #b0 #rs0 #Hfalse destruct ] ]
314 | * #d #b #rs @ex_intro
315 [| % [ % | #ls0 #c0 #d0 #b0 #rs0 #H1 destruct (H1) % ] ] ] ]
318 (* CLEAR MARK machine
320 clears the mark in the current character
323 definition clear_mark_states ≝ initN 3.
325 definition clear0 : clear_mark_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
326 definition clear1 : clear_mark_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
327 definition claer2 : clear_mark_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
329 definition clear_mark ≝
330 λalpha:FinSet.mk_TM (FinProd … alpha FinBool) clear_mark_states
333 [ None ⇒ 〈clear1,None ?〉
334 | Some a' ⇒ match pi1 … q with
335 [ O ⇒ let 〈a'',b〉 ≝ a' in 〈clear1,Some ? 〈〈a'',false〉,N〉〉
336 | S q ⇒ 〈clear1,None ?〉 ] ])
337 clear0 (λq.q == clear1).
339 definition R_clear_mark ≝ λalpha,t1,t2.
340 (current ? t1 = None ? → t1 = t2) ∧
342 t1 = midtape (FinProd … alpha FinBool) ls 〈c,b〉 rs →
343 t2 = midtape ? ls 〈c,false〉 rs.
345 lemma sem_clear_mark :
346 ∀alpha.Realize ? (clear_mark alpha) (R_clear_mark alpha).
347 #alpha #intape @(ex_intro ?? 2) cases intape
349 [| % [ % | % [#_ %|#ls #c #b #rs #Hfalse destruct ]]]
351 [| % [ % | % [#_ %|#ls #c #b #rs #Hfalse destruct ]]]
353 [| % [ % | % [#_ %|#ls #c #b #rs #Hfalse destruct ]]]
355 @ex_intro [| % [ % | %
356 [whd in ⊢ (??%?→?); #H destruct| #ls0 #c0 #b0 #rs0 #H1 destruct (H1) % ]]]]
359 (* ADVANCE MARK RIGHT machine
361 clears mark on current char,
362 moves right, and marks new current char
366 definition adv_mark_r ≝
368 clear_mark alpha · move_r ? · mark alpha.
370 definition R_adv_mark_r ≝ λalpha,t1,t2.
373 t1 = midtape (FinProd … alpha FinBool) ls 〈c,true〉 (〈d,b〉::rs) →
374 t2 = midtape ? (〈c,false〉::ls) 〈d,true〉 rs) ∧
375 (t1 = midtape (FinProd … alpha FinBool) ls 〈c,true〉 [ ] →
376 t2 = rightof ? 〈c,false〉 ls)) ∧
377 (current ? t1 = None ? → t1 = t2).
379 lemma sem_adv_mark_r :
380 ∀alpha.Realize ? (adv_mark_r alpha) (R_adv_mark_r alpha).
382 @(sem_seq_app … (sem_clear_mark …)
383 (sem_seq ????? (sem_move_r ?) (sem_mark alpha)) …)
384 #intape #outtape whd in ⊢ (%→?); * #ta *
385 whd in ⊢ (%→?); #Hs1 whd in ⊢ (%→?); * #tb * #Hs2 whd in ⊢ (%→?); #Hs3 %
387 [#d #b #rs #Hintape @(proj1 … Hs3 ?? b ?)
388 @(proj2 … Hs2 ls 〈c,false〉 (〈d,b〉::rs))
389 @(proj2 ?? Hs1 … Hintape)
390 |#Hintape lapply (proj2 ?? Hs1 … Hintape) #Hta lapply (proj2 … Hs2 … Hta)
391 whd in ⊢ ((???%)→?); #Htb <Htb @(proj2 … Hs3) >Htb //
393 |#Hcur lapply(proj1 ?? Hs1 … Hcur) #Hta >Hta >Hta in Hcur; #Hcur
394 lapply (proj1 ?? Hs2 … Hcur) #Htb >Htb >Htb in Hcur; #Hcur
395 @sym_eq @(proj2 ?? Hs3) @Hcur
399 (* ADVANCE TO MARK (left)
404 definition atml_step ≝
405 λalpha:FinSet.λtest:alpha→bool.
406 mk_TM alpha atm_states
409 [ None ⇒ 〈atm1, None ?〉
412 [ true ⇒ 〈atm1,None ?〉
413 | false ⇒ 〈atm2,Some ? 〈a',L〉〉 ]])
414 atm0 (λx.notb (x == atm0)).
416 definition Ratml_step_true ≝
419 t1 = midtape alpha ls a rs ∧ test a = false ∧
420 t2 = mk_tape alpha (tail ? ls) (option_hd ? ls) (a :: rs).
422 definition Ratml_step_false ≝
425 (current alpha t1 = None ? ∨
426 (∃a.current ? t1 = Some ? a ∧ test a = true)).
429 ∀alpha,test,ls,a0,rs. test a0 = true →
430 step alpha (atml_step alpha test)
431 (mk_config ?? atm0 (midtape … ls a0 rs)) =
432 mk_config alpha (states ? (atml_step alpha test)) atm1
433 (midtape … ls a0 rs).
434 #alpha #test #ls #a0 #ts #Htest whd in ⊢ (??%?);
435 whd in match (trans … 〈?,?〉); >Htest %
439 ∀alpha,test,ls,a0,rs. test a0 = false →
440 step alpha (atml_step alpha test)
441 (mk_config ?? atm0 (midtape … ls a0 rs)) =
442 mk_config alpha (states ? (atml_step alpha test)) atm2
443 (mk_tape … (tail ? ls) (option_hd ? ls) (a0 :: rs)).
444 #alpha #test #ls #a0 #rs #Htest whd in ⊢ (??%?);
445 whd in match (trans … 〈?,?〉); >Htest cases ls //
448 lemma sem_atml_step :
450 accRealize alpha (atml_step alpha test)
451 atm2 (Ratml_step_true alpha test) (Ratml_step_false alpha test).
454 @(ex_intro ?? (mk_config ?? atm1 (niltape ?))) %
455 [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
456 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? atm1 (leftof ? a al)))
457 % [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
458 | #a #al @(ex_intro ?? 2) @(ex_intro ?? (mk_config ?? atm1 (rightof ? a al)))
459 % [ % // whd in ⊢ ((??%%)→?); #Hfalse destruct | #_ % // % % ]
460 | #ls #c #rs @(ex_intro ?? 2)
461 cases (true_or_false (test c)) #Htest
462 [ @(ex_intro ?? (mk_config ?? atm1 ?))
465 [ whd in ⊢ (??%?); >atml_q0_q1 //
466 | whd in ⊢ ((??%%)→?); #Hfalse destruct ]
467 | #_ % // %2 @(ex_intro ?? c) % // ]
469 | @(ex_intro ?? (mk_config ?? atm2 (mk_tape ? (tail ? ls) (option_hd ? ls) (c::rs))))
472 [ whd in ⊢ (??%?); >atml_q0_q2 //
473 | #_ @(ex_intro ?? ls) @(ex_intro ?? c) @(ex_intro ?? rs)
476 | #Hfalse @False_ind @(absurd ?? Hfalse) %
482 definition R_adv_to_mark_l ≝ λalpha,test,t1,t2.
483 (current ? t1 = None ? → t1 = t2) ∧
485 (t1 = midtape alpha ls c rs →
486 ((test c = true → t2 = t1) ∧
488 (∀ls1,b,ls2. ls = ls1@b::ls2 →
489 test b = true → (∀x.memb ? x ls1 = true → test x = false) →
490 t2 = midtape ? ls2 b (reverse ? ls1@c::rs)) ∧
491 ((∀x.memb ? x ls = true → test x = false) →
492 ∀a,l. reverse ? (c::ls) = a::l → t2 = leftof ? a (l@rs))
495 definition adv_to_mark_l ≝
496 λalpha,test.whileTM alpha (atml_step alpha test) atm2.
498 lemma wsem_adv_to_mark_l :
500 WRealize alpha (adv_to_mark_l alpha test) (R_adv_to_mark_l alpha test).
501 #alpha #test #t #i #outc #Hloop
502 lapply (sem_while … (sem_atml_step alpha test) t i outc Hloop) [%]
503 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
507 |#ls #c #rs #H2 >H2 in H1; whd in ⊢ (??%? → ?);
508 #Hfalse destruct (Hfalse)
510 | * #a * #Ha #Htest %
511 [>Ha #H destruct (H);
514 |#Hc @False_ind >H2 in Ha; whd in ⊢ ((??%?)→?);
519 | #tapeb #tapec #Hleft #Hright #IH #HRfalse
520 lapply (IH HRfalse) -IH #IH %
521 [cases Hleft #ls0 * #a0 * #rs0 * * #Htapea #_ #_ >Htapea
522 whd in ⊢ ((??%?)→?); #H destruct (H)
523 |#ls #c #rs #Htapea %
524 [#Hc cases Hleft #ls0 * #a0 * #rs0 * * #Htapea' #Htest @False_ind
525 >Htapea' in Htapea; #H destruct /2/
526 |cases Hleft #ls0 * #a * #rs0 *
527 * #Htapea1 >Htapea in Htapea1; #H destruct (H) #_ #Htapeb
530 [#b #ls2 #Hls >Hls in Htapeb; #Htapeb #Htestb #_
531 cases (proj2 ?? IH … Htapeb) #H1 #_ >H1 // >Htapeb %
532 |#l1 #ls1 #b #ls2 #Hls >Hls in Htapeb; #Htapeb #Htestb #Hmemb
533 cases (proj2 ?? IH … Htapeb) #_ #H1 >reverse_cons >associative_append
534 @(proj1 ?? (H1 ?) … (refl …) Htestb …)
536 |#x #memx @Hmemb @memb_cons @memx
539 |cases ls0 in Htapeb; normalize in ⊢ (%→?);
540 [#Htapeb #Htest #a0 #l whd in ⊢ ((??%?)→?); #Hrev destruct (Hrev)
541 >Htapeb in IH; #IH cases (proj1 ?? IH … (refl …)) //
543 cases (proj2 ?? IH … Htapeb) #_ #H1 #Htest #a0 #l
544 <(reverse_reverse … l) cases (reverse … l)
545 [#H cut (a::l1::ls1 = [a0])
546 [<(reverse_reverse … (a::l1::ls1)) >H //]
547 #Hrev destruct (Hrev)
548 |#a1 #l2 >reverse_cons >reverse_cons >reverse_cons
549 #Hrev cut ([a] = [a1])
550 [@(append_l2_injective_r ?? (a0::reverse … l2) … Hrev) //]
551 #Ha <Ha >associative_append @(proj2 ?? (H1 ?))
553 |#x #membx @Htest @memb_cons @membx
554 |<(append_l1_injective_r ?? (a0::reverse … l2) … Hrev) //
563 lemma terminate_adv_to_mark_l :
565 ∀t.Terminate alpha (adv_to_mark_l alpha test) t.
567 @(terminate_while … (sem_atml_step alpha test))
570 [ % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
571 |2,3: #a0 #al0 % #t1 * #ls0 * #c0 * #rs0 * * #Hfalse destruct (Hfalse)
573 [#c #rs % #t1 * #ls0 * #c0 * #rs0 * *
574 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
575 % #t2 * #ls1 * #c1 * #rs1 * * >Ht1
576 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
577 | #rs0 #r0 #IH #ls #c % #t1 * #ls0 * #c0 * #rs0 * *
578 #H1 destruct (H1) #Hc0 #Ht1 normalize in Ht1;
585 lemma sem_adv_to_mark_l :
587 Realize alpha (adv_to_mark_l alpha test) (R_adv_to_mark_l alpha test).
592 ADVANCE BOTH MARKS machine
594 l1 does not contain marks ⇒
606 definition adv_both_marks ≝ λalpha.
607 adv_mark_r alpha · move_l ? ·
608 adv_to_mark_l (FinProd alpha FinBool) (is_marked alpha) ·
611 definition R_adv_both_marks ≝ λalpha,t1,t2.
613 t1 = midtape (FinProd … alpha FinBool) ls 〈x0,true〉 rs →
614 (rs = [ ] → (* first case: rs empty *)
615 t2 = rightof (FinProd … alpha FinBool) 〈x0,false〉 ls) ∧
616 (∀l0,x,a,a0,b,l1,l1',l2.
617 ls = (l1@〈x,true〉::l0) →
618 (∀c.memb ? c l1 = true → is_marked ? c = false) →
620 reverse ? (〈x0,false〉::l1) = 〈a,false〉::l1' →
621 t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (l1'@〈a0,true〉::l2)).
623 lemma sem_adv_both_marks :
624 ∀alpha.Realize ? (adv_both_marks alpha) (R_adv_both_marks alpha).
626 @(sem_seq_app … (sem_adv_mark_r …)
627 (sem_seq ????? (sem_move_l …)
628 (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
629 (sem_adv_mark_r alpha))) …)
630 #intape #outtape * #tapea * #Hta * #tb * #Htb * #tc * #Htc #Hout
631 #ls #c #rs #Hintape %
632 [#Hrs >Hrs in Hintape; #Hintape lapply (proj2 ?? (proj1 ?? Hta … ) … Hintape) -Hta #Hta
633 lapply (proj1 … Htb) >Hta -Htb #Htb lapply (Htb (refl …)) -Htb #Htb
634 lapply (proj1 ?? Htc) <Htb -Htc #Htc lapply (Htc (refl …)) -Htc #Htc
635 @sym_eq >Htc @(proj2 ?? Hout …) <Htc %
636 |#l0 #x #a #a0 #b #l1 #l1' #l2 #Hls #Hmarks #Hrs #Hrev
637 >Hrs in Hintape; >Hls #Hintape
638 @(proj1 ?? (proj1 ?? Hout … ) ? false) -Hout
639 lapply (proj1 … (proj1 … Hta …) … Hintape) #Htapea
640 lapply (proj2 … Htb … Htapea) -Htb
641 whd in match (mk_tape ????) ; #Htapeb
642 lapply (proj1 ?? (proj2 ?? (proj2 ?? Htc … Htapeb) (refl …))) -Htc #Htc
643 change with ((?::?)@?) in match (cons ???); <Hrev >reverse_cons
644 >associative_append @Htc [%|%|@Hmarks]
649 definition R_adv_both_marks ≝
651 ∀l0,x,a,l1,x0,a0,l2. (∀c.memb ? c l1 = true → is_marked ? c = false) →
652 (t1 = midtape (FinProd … alpha FinBool)
653 (l1@〈a,false〉::〈x,true〉::l0) 〈x0,true〉 (〈a0,false〉::l2) →
654 t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (reverse ? l1@〈x0,false〉::〈a0,true〉::l2)) ∧
655 (t1 = midtape (FinProd … alpha FinBool)
656 (l1@〈a,false〉::〈x,true〉::l0) 〈x0,true〉 [] →
657 t2 = rightof ? 〈x0,false〉 (l1@〈a,false〉::〈x,true〉::l0)).
659 lemma sem_adv_both_marks :
660 ∀alpha.Realize ? (adv_both_marks alpha) (R_adv_both_marks alpha).
662 cases (sem_seq ????? (sem_adv_mark_r …)
663 (sem_seq ????? (sem_move_l …)
664 (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
665 (sem_adv_mark_r alpha))) intape)
666 #k * #outc * #Hloop whd in ⊢ (%→?);
667 * #ta * whd in ⊢ (%→?); #Hs1 * #tb * whd in ⊢ (%→?); #Hs2
668 * #tc * whd in ⊢ (%→%→?); #Hs3 #Hs4
669 @(ex_intro ?? k) @(ex_intro ?? outc) %
671 | -Hloop #l0 #x #a #l1 #x0 #a0 #l2 #Hl1 #Hintape
673 lapply (Hs1 … Hintape) #Hta
674 lapply (proj2 … Hs2 … Hta) #Htb
676 [ * #Hfalse normalize in Hfalse; destruct (Hfalse)
678 lapply (Hs3 (l1@[〈a,false〉]) 〈x,true〉 l0 ???)
679 [ #x1 #Hx1 cases (memb_append … Hx1)
681 | #Hx1' >(memb_single … Hx1') % ]
683 | >associative_append %
684 | >reverse_append #Htc @Htc ]
696 l0 x a* l1 x0 a0* l2 (f(x0) == true)
698 l0 x* a l1 x0* a0 l2 (f(x0) == false)
702 definition match_and_adv ≝
703 λalpha,f.ifTM ? (test_char ? f)
704 (adv_both_marks alpha) (clear_mark ?) tc_true.
706 definition R_match_and_adv ≝
709 t1 = midtape (FinProd … alpha FinBool) ls 〈x0,true〉 rs →
710 ((* first case: (f 〈x0,true〉 = false) *)
711 (f 〈x0,true〉 = false) →
712 t2 = midtape (FinProd … alpha FinBool) ls 〈x0,false〉 rs) ∧
713 ((f 〈x0,true〉 = true) → rs = [ ] → (* second case: rs empty *)
714 t2 = rightof (FinProd … alpha FinBool) 〈x0,false〉 ls) ∧
715 ((f 〈x0,true〉 = true) →
716 ∀l0,x,a,a0,b,l1,l1',l2.
717 (* third case: we expect to have a mark on the left! *)
718 ls = (l1@〈x,true〉::l0) →
719 (∀c.memb ? c l1 = true → is_marked ? c = false) →
721 reverse ? (〈x0,false〉::l1) = 〈a,false〉::l1' →
722 t2 = midtape ? (〈x,false〉::l0) 〈a,true〉 (l1'@〈a0,true〉::l2)).
724 lemma sem_match_and_adv :
725 ∀alpha,f.Realize ? (match_and_adv alpha f) (R_match_and_adv alpha f).
727 cases (sem_if ? (test_char ? f) … tc_true (sem_test_char ? f) (sem_adv_both_marks alpha) (sem_clear_mark ?) intape)
728 #k * #outc * #Hloop #Hif @(ex_intro ?? k) @(ex_intro ?? outc)
731 @(sem_if_app … (sem_test_char ? f) (sem_adv_both_marks alpha) (sem_clear_mark ?))
732 #intape #outape #Htb * #H *)
734 [ * #ta * whd in ⊢ (%→%→?); * * #c * #Hcurrent #fc #Hta #Houtc
735 #ls #x #rs #Hintape >Hintape in Hcurrent; whd in ⊢ ((??%?)→?); #H destruct (H) %
736 [%[>fc #H destruct (H)
737 |#_ #Hrs >Hrs in Hintape; #Hintape >Hintape in Hta; #Hta
738 cases (Houtc … Hta) #Houtc #_ @Houtc //
740 |#l0 #x0 #a #a0 #b #l1 #l1' #l2 #Hls #Hmarks #Hrs #Hrev >Hintape in Hta; #Hta
741 @(proj2 ?? (Houtc … Hta) … Hls Hmarks Hrs Hrev)
743 | * #ta * * #H #Hta * #_ #Houtc #ls #c #rs #Hintape
744 >Hintape in H; #H lapply(H … (refl …)) #fc %
745 [%[#_ >Hintape in Hta; #Hta @(Houtc … Hta)
753 definition R_match_and_adv_of ≝
754 λalpha,t1,t2.current (FinProd … alpha FinBool) t1 = None ? → t2 = t1.
756 lemma sem_match_and_adv_of :
757 ∀alpha,f.Realize ? (match_and_adv alpha f) (R_match_and_adv_of alpha).
759 cases (sem_if ? (test_char ? f) … tc_true (sem_test_char ? f) (sem_adv_both_marks alpha) (sem_clear_mark ?) intape)
760 #k * #outc * #Hloop #Hif @(ex_intro ?? k) @(ex_intro ?? outc)
763 [ * #ta * whd in ⊢ (%→%→?); #Hta #Houtc #Hcur
764 cases Hta * #x >Hcur * #Hfalse destruct (Hfalse)
765 | * #ta * whd in ⊢ (%→%→?); * #_ #Hta * #Houtc #_ <Hta #Hcur >(Houtc Hcur) % ]
768 lemma sem_match_and_adv_full :
769 ∀alpha,f.Realize ? (match_and_adv alpha f)
770 (R_match_and_adv alpha f ∩ R_match_and_adv_of alpha).
771 #alpha #f #intape cases (sem_match_and_adv ? f intape)
772 #i * #outc * #Hloop #HR1 %{i} %{outc} % // % //
773 cases (sem_match_and_adv_of ? f intape) #i0 * #outc0 * #Hloop0 #HR2
774 >(loop_eq … Hloop Hloop0) //
777 definition comp_step_subcase ≝ λalpha,c,elseM.
778 ifTM ? (test_char ? (λx.x == c))
779 (move_r … · adv_to_mark_r ? (is_marked alpha) · match_and_adv ? (λx.x == c))
782 definition R_comp_step_subcase ≝
783 λalpha,c,RelseM,t1,t2.
784 ∀ls,x,rs.t1 = midtape (FinProd … alpha FinBool) ls 〈x,true〉 rs →
786 ((* test true but no marks in rs *)
787 (∀c.memb ? c rs = true → is_marked ? c = false) →
788 ∀a,l. (a::l) = reverse ? (〈x,true〉::rs) →
789 t2 = rightof (FinProd alpha FinBool) a (l@ls)) ∧
791 (∀c.memb ? c l1 = true → is_marked ? c = false) →
792 rs = l1@〈x0,true〉::l2 →
794 l2 = [ ] → (* test true but l2 is empty *)
795 t2 = rightof ? 〈x0,false〉 ((reverse ? l1)@〈x,true〉::ls)) ∧
797 ∀a,a0,b,l1',l2'. (* test true and l2 is not empty *)
798 〈a,false〉::l1' = l1@[〈x0,false〉] →
800 t2 = midtape ? (〈x,false〉::ls) 〈a,true〉 (l1'@〈a0,true〉::l2')) ∧
801 (x ≠ x0 →(* test false *)
802 t2 = midtape (FinProd … alpha FinBool) ((reverse ? l1)@〈x,true〉::ls) 〈x0,false〉 l2)) ∧
803 (〈x,true〉 ≠ c → RelseM t1 t2).
805 lemma dec_marked: ∀alpha,rs.
806 decidable (∀c.memb ? c rs = true → is_marked alpha c = false).
808 [%1 #n normalize #H destruct
809 |#a #tl cases (true_or_false (is_marked ? a)) #Ha
810 [#_ %2 % #Hall @(absurd ?? not_eq_true_false) <Ha
812 |* [#Hall %1 #c #memc cases (orb_true_l … memc)
813 [#eqca >(\P eqca) @Ha |@Hall]
814 |#Hnall %2 @(not_to_not … Hnall) #Hall #c #memc @Hall @memb_cons //
818 (* axiom daemon:∀P:Prop.P. *)
820 lemma sem_comp_step_subcase :
821 ∀alpha,c,elseM,RelseM.
822 Realize ? elseM RelseM →
823 Realize ? (comp_step_subcase alpha c elseM)
824 (R_comp_step_subcase alpha c RelseM).
825 #alpha #c #elseM #RelseM #Helse #intape
826 cases (sem_if ? (test_char ? (λx.x == c)) … tc_true
827 (sem_test_char ? (λx.x == c))
828 (sem_seq ????? (sem_move_r …)
829 (sem_seq ????? (sem_adv_to_mark_r ? (is_marked alpha))
830 (sem_match_and_adv_full ? (λx.x == c)))) Helse intape)
831 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc)
832 % [ @Hloop ] -Hloop cases HR -HR
833 [* #ta * whd in ⊢ (%→?); * * #cin * #Hcin #Hcintrue #Hta * #tb * whd in ⊢ (%→?); #Htb
834 * #tc * whd in ⊢ (%→?); #Htc * whd in ⊢ (%→%→?); #Houtc #Houtc1
835 #ls #x #rs #Hintape >Hintape in Hcin; whd in ⊢ ((??%?)→?); #H destruct (H) %
836 [#_ cases (dec_marked ? rs) #Hdec
839 >Hintape in Hta; #Hta
840 lapply (proj2 ?? Htb … Hta) -Htb -Hta cases rs in Hdec;
842 [#_ whd in ⊢ ((???%)→?); #Htb >Htb in Htc; #Htc
843 lapply (proj1 ?? Htc (refl …)) -Htc #Htc <Htc in Houtc1; #Houtc1
844 normalize in ⊢ (???%→?); #Hl1 destruct(Hl1) @(Houtc1 (refl …))
845 |#r0 #rs0 #Hdec whd in ⊢ ((???%)→?); #Htb >Htb in Htc; #Htc
846 >reverse_cons >reverse_cons #Hl1
847 cases (proj2 ?? Htc … (refl …))
848 [* >(Hdec …) [ #Hfalse destruct(Hfalse) ] @memb_hd
849 |* #_ -Htc #Htc cut (∃l2.l1 = l2@[〈x,true〉])
850 [generalize in match Hl1; -Hl1 <(reverse_reverse … l1)
852 [#Hl1 cut ([a]=〈x,true〉::r0::rs0)
853 [ <(reverse_reverse … (〈x,true〉::r0::rs0))
854 >reverse_cons >reverse_cons <Hl1 %
855 | #Hfalse destruct(Hfalse)]
856 |#a0 #l10 >reverse_cons #Heq
857 lapply (append_l2_injective_r ? (a::reverse ? l10) ???? Heq) //
858 #Ha0 destruct(Ha0) /2/ ]
859 |* #l2 #Hl2 >Hl2 in Hl1; #Hl1
860 lapply (append_l1_injective_r ? (a::l2) … Hl1) // -Hl1 #Hl1
861 >reverse_cons in Htc; #Htc lapply (Htc … (sym_eq … Hl1))
862 [ #x0 #Hmemb @Hdec @memb_cons @Hmemb ]
863 -Htc #Htc >Htc in Houtc1; #Houtc1 >associative_append @Houtc1 %
867 |#l1 #x0 #l2 #_ #Hrs @False_ind
868 @(absurd ?? not_eq_true_false)
869 change with (is_marked ? 〈x0,true〉) in match true;
870 @Hdec >Hrs @memb_append_l2 @memb_hd
872 |% [#H @False_ind @(absurd …H Hdec)]
873 (* by cases on l1 *) *
874 [#x0 #l2 #Hdec normalize in ⊢ (%→?); #Hrs >Hrs in Hintape; #Hintape
875 >Hintape in Hta; (* * * #x1 * whd in ⊢ ((??%?)→?); #H destruct (H) #Hx *)
876 #Hta lapply (proj2 … Htb … Hta) -Htb -Hta
877 whd in match (mk_tape ????); whd in match (tail ??); #Htb cases Htc -Htc
878 #_ #Htc cases (Htc … Htb) -Htc
879 [2: * * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
880 * * #Htc >Htb in Htc; -Htb #Htc cases (Houtc … Htc) -Houtc *
881 #H1 #H2 #H3 cases (true_or_false (x==x0)) #eqxx0
882 [>(\P eqxx0) % [2: #H @False_ind /2/] %
883 [#_ #Hl2 >(H2 … Hl2) <(\P eqxx0) [% | @Hcintrue]
884 |#_ #a #a0 #b #l1' #l2' normalize in ⊢ (%→?); #Hdes destruct (Hdes)
885 #Hl2 @(H3 … Hdec … Hl2) <(\P eqxx0) [@Hcintrue | % | @reverse_single]
887 |% [% #eqx @False_ind lapply (\Pf eqxx0) #Habs @(absurd … eqx Habs)]
888 #_ @H1 @(\bf ?) @(not_to_not ??? (\Pf eqxx0)) <(\P Hcintrue)
889 #Hdes destruct (Hdes) %
891 |#l1hd #l1tl #x0 #l2 #Hdec normalize in ⊢ (%→?); #Hrs >Hrs in Hintape; #Hintape
892 >Hintape in Hta; (* * * #x1 * whd in ⊢ ((??%?)→?); #H destruct (H) #Hx *)
893 #Hta lapply (proj2 … Htb … Hta) -Htb -Hta
894 whd in match (mk_tape ????); whd in match (tail ??); #Htb cases Htc -Htc
895 #_ #Htc cases (Htc … Htb) -Htc
896 [* #Hfalse @False_ind >(Hdec … (memb_hd …)) in Hfalse; #H destruct]
897 * * #_ #Htc lapply (Htc … (refl …) (refl …) ?) -Htc
898 [#x1 #membx1 @Hdec @memb_cons @membx1] #Htc
899 cases (Houtc … Htc) -Houtc *
900 #H1 #H2 #H3 #_ cases (true_or_false (x==x0)) #eqxx0
901 [>(\P eqxx0) % [2: #H @False_ind /2/] %
902 [#_ #Hl2 >(H2 … Hl2) <(\P eqxx0)
903 [>reverse_cons >associative_append % | @Hcintrue]
904 |#_ #a #a0 #b #l1' #l2' normalize in ⊢ (%→?); #Hdes (* destruct (Hdes) *)
905 #Hl2 @(H3 ?????? (reverse … (l1hd::l1tl)) … Hl2) <(\P eqxx0)
907 |>reverse_cons >associative_append %
908 |#c0 #memc @Hdec <(reverse_reverse ? (l1hd::l1tl)) @memb_reverse @memc
909 |>Hdes >reverse_cons >reverse_reverse >(\P eqxx0) %
912 |% [% #eqx @False_ind lapply (\Pf eqxx0) #Habs @(absurd … eqx Habs)]
913 #_ >reverse_cons >associative_append @H1 @(\bf ?)
914 @(not_to_not ??? (\Pf eqxx0)) <(\P Hcintrue) #Hdes
919 |>(\P Hcintrue) * #Hfalse @False_ind @Hfalse %
921 | * #ta * * #Hcur #Hta #Houtc
922 #l0 #x #rs #Hintape >Hintape in Hcur; #Hcur lapply (Hcur ? (refl …)) -Hcur #Hc %
923 [ #Hfalse >Hfalse in Hc; #Hc cases (\Pf Hc) #Hc @False_ind @Hc %
924 | -Hc #Hc <Hintape <Hta @Houtc ] ]
930 + se è un bit, ho fallito il confronto della tupla corrente
931 + se è un separatore, la tupla fa match
934 ifTM ? (test_char ? is_marked)
935 (single_finalTM … (comp_step_subcase unialpha 〈bit false,true〉
936 (comp_step_subcase unialpha 〈bit true,true〉
941 definition comp_step ≝
942 ifTM ? (test_char ? (is_marked ?))
943 (single_finalTM … (comp_step_subcase FSUnialpha 〈bit false,true〉
944 (comp_step_subcase FSUnialpha 〈bit true,true〉
945 (comp_step_subcase FSUnialpha 〈null,true〉
952 lemma mem_append : ∀A,x,l1,l2. mem A x (l1@l2) →
953 mem A x l1 ∨ mem A x l2.
954 #A #x #l1 elim l1 normalize [/2/]
955 #a #tl #Hind #l2 * [#eqxa %1 /2/ |#memx cases (Hind … memx) /3/]
958 let rec split_on A (l:list A) f acc on l ≝
962 if f a then 〈acc,a::tl〉 else split_on A tl f (a::acc)
965 lemma split_on_spec: ∀A:DeqSet.∀l,f,acc,res1,res2.
966 split_on A l f acc = 〈res1,res2〉 →
967 (∃l1. res1 = l1@acc ∧
968 reverse ? l1@res2 = l ∧
969 ∀x. memb ? x l1 =true → f x = false) ∧
970 ∀a,tl. res2 = a::tl → f a = true.
972 [#acc #res1 #res2 normalize in ⊢ (%→?); #H destruct %
973 [@(ex_intro … []) % normalize [% % | #x #H destruct]
976 |#a #tl #Hind #acc #res1 #res2 normalize in ⊢ (%→?);
977 cases (true_or_false (f a)) #Hfa >Hfa normalize in ⊢ (%→?);
979 [% [@(ex_intro … []) % normalize [% % | #x #H destruct]
980 |#a1 #tl1 #H destruct (H) //]
981 |cases (Hind (a::acc) res1 res2 H) * #l1 * *
982 #Hres1 #Htl #Hfalse #Htrue % [2:@Htrue] @(ex_intro … (l1@[a])) %
983 [% [>associative_append @Hres1 | >reverse_append <Htl % ]
984 |#x #Hmemx cases (memb_append ???? Hmemx)
985 [@Hfalse | #H >(memb_single … H) //]
991 axiom mem_reverse: ∀A,l,x. mem A x (reverse ? l) → mem A x l.
993 lemma split_on_spec_ex: ∀A:DeqSet.∀l,f.∃l1,l2.
994 l1@l2 = l ∧ (∀x:A. memb ? x l1 = true → f x = false) ∧
995 ∀a,tl. l2 = a::tl → f a = true.
996 #A #l #f @(ex_intro … (reverse … (\fst (split_on A l f []))))
997 @(ex_intro … (\snd (split_on A l f [])))
998 cases (split_on_spec A l f [ ] ?? (eq_pair_fst_snd …)) * #l1 * *
999 >append_nil #Hl1 >Hl1 #Hl #Hfalse #Htrue %
1000 [% [@Hl|#x #memx @Hfalse <(reverse_reverse … l1) @memb_reverse //] | @Htrue]
1003 (* versione esistenziale *)
1005 definition R_comp_step_true ≝ λt1,t2.
1006 ∃ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls 〈c,true〉 rs ∧
1007 ((* bit_or_null c = false *)
1008 (bit_or_null c = false → t2 = midtape ? ls 〈c,false〉 rs) ∧
1009 (* no marks in rs *)
1010 (bit_or_null c = true →
1011 (∀c.memb ? c rs = true → is_marked ? c = false) →
1012 ∀a,l. (a::l) = reverse ? (〈c,true〉::rs) →
1013 t2 = rightof (FinProd FSUnialpha FinBool) a (l@ls)) ∧
1015 bit_or_null c = true →
1016 (∀c.memb ? c l1 = true → is_marked ? c = false) →
1017 rs = l1@〈c0,true〉::l2 →
1019 l2 = [ ] → (* test true but l2 is empty *)
1020 t2 = rightof ? 〈c0,false〉 ((reverse ? l1)@〈c,true〉::ls)) ∧
1022 ∀a,a0,b,l1',l2'. (* test true and l2 is not empty *)
1023 〈a,false〉::l1' = l1@[〈c0,false〉] →
1025 t2 = midtape ? (〈c,false〉::ls) 〈a,true〉 (l1'@〈a0,true〉::l2')) ∧
1026 (c ≠ c0 →(* test false *)
1027 t2 = midtape (FinProd … FSUnialpha FinBool)
1028 ((reverse ? l1)@〈c,true〉::ls) 〈c0,false〉 l2))).
1030 definition R_comp_step_false ≝
1032 ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs →
1033 is_marked ? c = false ∧ t2 = t1.
1035 lemma is_marked_to_exists: ∀alpha,c. is_marked alpha c = true →
1037 #alpha * #c * [#_ @(ex_intro … c) //| normalize #H destruct]
1040 lemma exists_current: ∀alpha,c,t.
1041 current alpha t = Some alpha c → ∃ls,rs. t= midtape ? ls c rs.
1043 [whd in ⊢ (??%?→?); #H destruct
1044 |#a #l whd in ⊢ (??%?→?); #H destruct
1045 |#a #l whd in ⊢ (??%?→?); #H destruct
1046 |#ls #c1 #rs whd in ⊢ (??%?→?); #H destruct
1047 @(ex_intro … ls) @(ex_intro … rs) //
1051 lemma sem_comp_step :
1052 accRealize ? comp_step (inr … (inl … (inr … start_nop)))
1053 R_comp_step_true R_comp_step_false.
1054 @(acc_sem_if_app … (sem_test_char ? (is_marked ?))
1055 (sem_comp_step_subcase FSUnialpha 〈bit false,true〉 ??
1056 (sem_comp_step_subcase FSUnialpha 〈bit true,true〉 ??
1057 (sem_comp_step_subcase FSUnialpha 〈null,true〉 ??
1058 (sem_clear_mark …))))
1060 [#intape #outape #ta #Hta #Htb cases Hta * #cm * #Hcur
1061 cases (exists_current … Hcur) #ls * #rs #Hintape #cmark
1062 cases (is_marked_to_exists … cmark) #c #Hcm
1063 >Hintape >Hcm -Hintape -Hcm #Hta
1064 @(ex_intro … ls) @(ex_intro … c) @(ex_intro …rs) % [//] lapply Hta -Hta
1065 (* #ls #c #rs #Hintape whd in Hta;
1066 >Hintape in Hta; * #_ -Hintape forse non serve *)
1067 cases (true_or_false (c==bit false)) #Hc
1069 [%[whd in ⊢ ((??%?)→?); #Hdes destruct
1070 |#Hc @(proj1 ?? (proj1 ?? (Htb … Hta) (refl …)))
1072 |#l1 #c0 #l2 #Hc @(proj2 ?? (proj1 ?? (Htb … Hta) (refl …)))
1074 |cases (true_or_false (c==bit true)) #Hc1
1076 cut (〈bit true, true〉 ≠ 〈bit false, true〉) [% #Hdes destruct] #Hneq %
1077 [%[whd in ⊢ ((??%?)→?); #Hdes destruct
1078 |#Hc @(proj1 … (proj1 ?? (proj2 ?? (Htb … Hta) Hneq … Hta) (refl …)))
1080 |#l1 #c0 #l2 #Hc @(proj2 ?? (proj1 ?? (proj2 ?? (Htb … Hta) Hneq … Hta)(refl …)))
1082 |cases (true_or_false (c==null)) #Hc2
1084 cut (〈null, true〉 ≠ 〈bit false, true〉) [% #Hdes destruct] #Hneq
1085 cut (〈null, true〉 ≠ 〈bit true, true〉) [% #Hdes destruct] #Hneq1 %
1086 [%[whd in ⊢ ((??%?)→?); #Hdes destruct
1087 |#Hc @(proj1 … (proj1 ?? (proj2 ?? (proj2 ?? (Htb … Hta) Hneq … Hta) Hneq1 … Hta) (refl …)))
1089 |#l1 #c0 #l2 #Hc @(proj2 ?? (proj1 ?? (proj2 ?? (proj2 ?? (Htb … Hta) Hneq … Hta) Hneq1 … Hta) (refl …)))
1091 |#Hta cut (bit_or_null c = false)
1092 [lapply Hc; lapply Hc1; lapply Hc2 -Hc -Hc1 -Hc2
1093 cases c normalize [* normalize /2/] /2/] #Hcut %
1094 [%[cases (Htb … Hta) #_ -Htb #Htb
1095 cases (Htb … Hta) [2: % #H destruct (H) normalize in Hc; destruct] #_ -Htb #Htb
1096 cases (Htb … Hta) [2: % #H destruct (H) normalize in Hc1; destruct] #_ -Htb #Htb
1097 lapply (Htb ?) [% #H destruct (H) normalize in Hc2; destruct]
1098 * #_ #Houttape #_ @(Houttape … Hta)
1101 |#l1 #c0 #l2 >Hcut #H destruct
1106 |#intape #outape #ta #Hta #Htb #ls #c #rs #Hintape
1107 >Hintape in Hta; whd in ⊢ (%→?); * #Hmark #Hta % [@Hmark //]
1114 definition compare ≝
1115 whileTM ? comp_step (inr … (inl … (inr … start_nop))).
1118 definition R_compare :=
1122 ∀ls,c,b,rs.t1 = midtape ? ls 〈c,b〉 rs →
1123 (b = true → rs = ....) →
1124 (b = false ∧ ....) ∨
1127 rs = cs@l1@〈c0,true〉::cs0@l2
1131 ls 〈c,b〉 cs l1 〈c0,b0〉 cs0 l2
1135 ls (hd (Ls@〈grid,false〉))* (tail (Ls@〈grid,false〉)) l1 (hd (Ls@〈comma,false〉))* (tail (Ls@〈comma,false〉)) l2
1136 ^^^^^^^^^^^^^^^^^^^^^^^
1138 ls Ls 〈grid,false〉 l1 Ls 〈comma,true〉 l2
1143 ls (hd (Ls@〈c,false〉))* (tail (Ls@〈c,false〉)) l1 (hd (Ls@〈d,false〉))* (tail (Ls@〈d,false〉)) l2
1144 ^^^^^^^^^^^^^^^^^^^^^^^
1147 ls Ls 〈c,true〉 l1 Ls 〈d,false〉 l2
1153 (∃la,d.〈b,true〉::bs = la@[〈grid,d〉] ∧ ∀x.memb ? x la → is_bit (\fst x) = true) →
1154 (∃lb,d0.〈b0,true〉::b0s = lb@[〈comma,d0〉] ∧ ∀x.memb ? x lb → is_bit (\fst x) = true) →
1155 t1 = midtape ? l0 〈b,true〉 (bs@l1@〈b0,true〉::b0s@l2 →
1157 mk_tape left (option current) right
1159 (b = grid ∧ b0 = comma ∧ bs = [] ∧ b0s = [] ∧
1160 t2 = midtape ? l0 〈grid,false〉 (l1@〈comma,true〉::l2)) ∨
1161 (b = bit x ∧ b = c ∧ bs = b0s
1164 definition list_cases2: ∀A.∀P:list A →list A →Prop.∀l1,l2. |l1| = |l2| →
1165 P [ ] [ ] → (∀a1,a2:A.∀tl1,tl2. |tl1| = |tl2| → P (a1::tl1) (a2::tl2)) → P l1 l2.
1166 #A #P #l1 #l2 #Hlen lapply Hlen @(list_ind2 … Hlen) //
1167 #tl1 #tl2 #hd1 #hd2 #Hind normalize #HlenS #H1 #H2 @H2 //
1170 definition R_compare :=
1172 ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs →
1173 (∀c'.bit_or_null c' = false → c = 〈c',true〉 → t2 = midtape ? ls 〈c',false〉 rs) ∧
1174 (∀c'. c = 〈c',false〉 → t2 = t1) ∧
1175 (* forse manca il caso no marks in rs *)
1178 (∀c.memb (FinProd … FSUnialpha FinBool) c bs = true → bit_or_null (\fst c) = true) →
1179 (∀c.memb (FinProd … FSUnialpha FinBool) c b0s = true → bit_or_null (\fst c) = true) →
1180 (∀c.memb ? c bs = true → is_marked ? c = false) →
1181 (∀c.memb ? c b0s = true → is_marked ? c = false) →
1182 (∀c.memb ? c l1 = true → is_marked ? c = false) →
1183 c = 〈b,true〉 → bit_or_null b = true →
1184 rs = bs@〈grid,false〉::l1@〈b0,true〉::b0s@〈comma,false〉::l2 →
1185 (〈b,true〉::bs = 〈b0,true〉::b0s ∧
1186 t2 = midtape ? (reverse ? bs@〈b,false〉::ls)
1187 〈grid,false〉 (l1@〈b0,false〉::b0s@〈comma,true〉::l2)) ∨
1188 (∃la,c',d',lb,lc.c' ≠ d' ∧
1189 〈b,false〉::bs = la@〈c',false〉::lb ∧
1190 〈b0,false〉::b0s = la@〈d',false〉::lc ∧
1191 t2 = midtape (FinProd … FSUnialpha FinBool) (reverse ? la@
1197 〈d',false〉 (lc@〈comma,false〉::l2)).
1199 lemma wsem_compare : WRealize ? compare R_compare.
1201 lapply (sem_while ?????? sem_comp_step t i outc Hloop) [%]
1202 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
1203 [ whd in ⊢ (%→?); #Rfalse #ls #c #rs #Htapea %
1205 [ #c' #Hc' #Hc lapply (Rfalse … Htapea) -Rfalse * >Hc
1206 whd in ⊢ (??%?→?); #Hfalse destruct (Hfalse)
1207 | #c' #Hc lapply (Rfalse … Htapea) -Rfalse * #_
1209 | #b #b0 #bs #b0s #l1 #l2 #Hlen #Hbs1 #Hb0s1 #Hbs2 #Hb0s2 #Hl1 #Hc
1210 cases (Rfalse … Htapea) -Rfalse >Hc whd in ⊢ (??%?→?);#Hfalse destruct (Hfalse)
1212 | #tapeb #tapec #Hleft #Hright #IH #Htapec lapply (IH Htapec) -Htapec -IH #IH
1213 whd in Hleft; #ls #c #rs #Htapea cases Hleft -Hleft
1214 #ls0 * #c' * #rs0 * >Htapea #Hdes destruct (Hdes) * *
1215 cases (true_or_false (bit_or_null c')) #Hc'
1216 [2: #Htapeb lapply (Htapeb Hc') -Htapeb #Htapeb #_ #_ %
1217 [%[#c1 #Hc1 #Heqc destruct (Heqc)
1218 cases (IH … Htapeb) * #_ #H #_ <Htapeb @(H … (refl…))
1219 |#c1 #Heqc destruct (Heqc)
1221 |#b #b0 #bs #b0s #l1 #l2 #_ #_ #_ #_ #_ #_
1222 #Heq destruct (Heq) >Hc' #Hfalse @False_ind destruct (Hfalse)
1224 |#_ (* no marks in rs ??? *) #_ #Hleft %
1226 [ #c'' #Hc'' #Heq destruct (Heq) >Hc'' in Hc'; #H destruct (H)
1227 | #c0 #Hfalse destruct (Hfalse)
1229 |#b #b0 #bs #b0s #l1 #l2 #Hlen #Hbs1 #Hb0s1 #Hbs2 #Hb0s2 #Hl1
1230 #Heq destruct (Heq) #_ >append_cons; <associative_append #Hrs
1231 cases (Hleft … Hc' … Hrs) -Hleft
1232 [2: #c1 #memc1 cases (memb_append … memc1) -memc1 #memc1
1233 [cases (memb_append … memc1) -memc1 #memc1
1234 [@Hbs2 @memc1 |>(memb_single … memc1) %]
1237 |* (* manca il caso in cui dopo una parte uguale il
1238 secondo nastro finisca ... ???? *)
1239 #_ cases (true_or_false (b==b0)) #eqbb0
1240 [2: #_ #Htapeb %2 lapply (Htapeb … (\Pf eqbb0)) -Htapeb #Htapeb
1241 cases (IH … Htapeb) * #_ #Hout #_
1242 @(ex_intro … []) @(ex_intro … b) @(ex_intro … b0)
1243 @(ex_intro … bs) @(ex_intro … b0s) %
1244 [%[%[@(\Pf eqbb0) | %] | %]
1245 |>(Hout … (refl …)) -Hout >Htapeb @eq_f3 [2,3:%]
1246 >reverse_append >reverse_append >associative_append
1247 >associative_append %
1249 |lapply Hbs1 lapply Hb0s1 lapply Hbs2 lapply Hb0s2 lapply Hrs
1250 -Hbs1 -Hb0s1 -Hbs2 -Hb0s2 -Hrs
1251 @(list_cases2 … Hlen)
1252 [#Hrs #_ #_ #_ #_ >associative_append >associative_append #Htapeb #_
1253 lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb
1254 cases (IH … Htapeb) -IH * #Hout #_ #_ %1 %
1256 |>(Hout grid (refl …) (refl …)) @eq_f
1257 normalize >associative_append %
1259 |* #a1 #ba1 * #a2 #ba2 #tl1 #tl2 #HlenS #Hrs #Hb0s2 #Hbs2 #Hb0s1 #Hbs1
1260 cut (ba1 = false) [@(Hbs2 〈a1,ba1〉) @memb_hd] #Hba1 >Hba1
1261 >associative_append >associative_append #Htapeb #_
1262 lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb
1263 cases (IH … Htapeb) -IH * #_ #_
1264 cut (ba2=false) [@(Hb0s2 〈a2,ba2〉) @memb_hd] #Hba2 >Hba2
1265 #IH cases(IH a1 a2 ?? (l1@[〈b0,false〉]) l2 HlenS ????? (refl …) ??)
1266 [3:#x #memx @Hbs1 @memb_cons @memx
1267 |4:#x #memx @Hb0s1 @memb_cons @memx
1268 |5:#x #memx @Hbs2 @memb_cons @memx
1269 |6:#x #memx @Hb0s2 @memb_cons @memx
1270 |7:#x #memx cases (memb_append …memx) -memx #memx
1271 [@Hl1 @memx | >(memb_single … memx) %]
1272 |8:@(Hbs1 〈a1,ba1〉) @memb_hd
1273 |9: >associative_append >associative_append %
1274 |-IH -Hbs1 -Hb0s1 -Hbs2 -Hrs *
1276 [>(\P eqbb0) @eq_f destruct (Ha1a2) %
1278 [>reverse_cons >associative_append %
1280 |>associative_append %
1283 |-IH -Hbs1 -Hb0s1 -Hbs2 -Hrs *
1284 #la * #c' * #d' * #lb * #lc * * *
1285 #Hcd #H1 #H2 #Houtc %2
1286 @(ex_intro … (〈b,false〉::la)) @(ex_intro … c') @(ex_intro … d')
1287 @(ex_intro … lb) @(ex_intro … lc) %
1288 [%[%[@Hcd | >H1 %] |>(\P eqbb0) >Hba2 >H2 %]
1290 [>(\P eqbb0) >reverse_append >reverse_cons
1291 >reverse_cons >associative_append >associative_append
1292 >associative_append >associative_append %
1306 lemma WF_cst_niltape:
1307 WF ? (inv ? R_comp_step_true) (niltape (FinProd FSUnialpha FinBool)).
1308 @wf #t1 whd in ⊢ (%→?); * #ls * #c * #rs * #H destruct
1311 lemma WF_cst_rightof:
1312 ∀a,ls. WF ? (inv ? R_comp_step_true) (rightof (FinProd FSUnialpha FinBool) a ls).
1313 #a #ls @wf #t1 whd in ⊢ (%→?); * #ls * #c * #rs * #H destruct
1316 lemma WF_cst_leftof:
1317 ∀a,ls. WF ? (inv ? R_comp_step_true) (leftof (FinProd FSUnialpha FinBool) a ls).
1318 #a #ls @wf #t1 whd in ⊢ (%→?); * #ls * #c * #rs * #H destruct
1321 lemma WF_cst_midtape_false:
1322 ∀ls,c,rs. WF ? (inv ? R_comp_step_true)
1323 (midtape (FinProd … FSUnialpha FinBool) ls 〈c,false〉 rs).
1324 #ls #c #rs @wf #t1 whd in ⊢ (%→?); * #ls' * #c' * #rs' * #H destruct
1328 lemma not_nil_to_exists:∀A.∀l: list A. l ≠ [ ] →
1330 #A * [* #H @False_ind @H // | #a #tl #_ @(ex_intro … a) @(ex_intro … tl) //]
1333 lemma terminate_compare:
1334 ∀t. Terminate ? compare t.
1335 #t @(terminate_while … sem_comp_step) [%]
1336 cases t // #ls * #c * //
1338 (* we cannot proceed by structural induction on the right tape,
1339 since compare moves the marks! *)
1340 cut (∃len. |rs| = len) [/2/]
1341 * #len lapply rs lapply c lapply ls -ls -c -rs elim len
1342 [#ls #c #rs #Hlen >(lenght_to_nil … Hlen) @wf #t1 whd in ⊢ (%→?); * #ls0 * #c0 * #rs0 * #Hmid destruct (Hmid)
1343 * * #H1 #H2 #_ cases (true_or_false (bit_or_null c0)) #Hc0
1344 [>(H2 Hc0 … (refl …)) // #x whd in ⊢ ((??%?)→?); #Hdes destruct
1347 |-len #len #Hind #ls #c #rs #Hlen @wf #t1 whd in ⊢ (%→?); * #ls0 * #c0 * #rs0 * #Hmid destruct (Hmid)
1348 * * #H1 #H2 #H3 cases (true_or_false (bit_or_null c0)) #Hc0
1349 [-H1 cases (split_on_spec_ex ? rs0 (is_marked ?)) #rs1 * #rs2
1351 [(* no marks in right tape *)
1352 * * >append_nil #H >H -H #Hmarks #_
1353 cases (not_nil_to_exists ? (reverse (FSUnialpha×bool) (〈c0,true〉::rs0)) ?)
1354 [2: % >reverse_cons #H cases (nil_to_nil … H) #_ #H1 destruct]
1355 #a0 * #tl #H4 >(H2 Hc0 Hmarks a0 tl H4) //
1356 |(* the first marked element is a0 *)
1357 * #a0 #a0b #rs3 * * #H4 #H5 #H6 lapply (H3 ? a0 rs3 … Hc0 H5 ?)
1358 [<H4 @eq_f @eq_f2 [@eq_f @(H6 〈a0,a0b〉 … (refl …)) | %]
1359 |cases (true_or_false (c0==a0)) #eqc0a0 (* comparing a0 with c0 *)
1360 [* * (* we check if we have elements at the right of a0 *)
1361 lapply H4 -H4 cases rs3
1362 [#_ #Ht1 #_ #_ >(Ht1 (\P eqc0a0) (refl …)) //
1363 |(* a1 will be marked *)
1364 cases (not_nil_to_exists ? (rs1@[〈a0,false〉]) ?)
1365 [2: % #H cases (nil_to_nil … H) #_ #H1 destruct]
1366 * #a2 #a2b * #tl2 #H7 * #a1 #a1b #rs4 #H4 #_ #Ht1 #_
1368 [lapply (memb_hd ? 〈a2,a2b〉 tl2) >H7 #mema2
1369 cases (memb_append … mema2)
1370 [@H5 |#H lapply(memb_single … H) #H2 destruct %]
1372 #Ha2b >Ha2b in H7; #H7
1373 >(Ht1 (\P eqc0a0) … H7 (refl …)) @Hind -Hind -Ht1 -Ha2b -H2 -H3 -H5 -H6
1374 <H4 in Hlen; >length_append normalize <plus_n_Sm #Hlen1
1375 >length_append normalize <(injective_S … Hlen1) @eq_f2 //
1376 cut (|〈a2,false〉::tl2|=|rs1@[〈a0,false〉]|) [>H7 %]
1377 >length_append normalize <plus_n_Sm <plus_n_O //
1379 |(* c0 =/= a0 *) * * #_ #_ #Ht1 >(Ht1 (\Pf eqc0a0)) //
1387 lemma sem_compare : Realize ? compare R_compare.
1391 definition R_compare_new :=
1393 ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs →
1394 (∀c'.bit_or_null c' = false → c = 〈c',true〉 → t2 = midtape ? ls 〈c',false〉 rs) ∧
1395 (∀c'. c = 〈c',false〉 → t2 = t1) ∧
1396 (* forse manca il caso no marks in rs *)
1397 ∀b,b0,bs,b0s,comma,l1,l2.
1399 (∀c.memb (FinProd … FSUnialpha FinBool) c bs = true → bit_or_null (\fst c) = true) →
1400 (∀c.memb ? c bs = true → is_marked ? c = false) →
1401 (∀c.memb ? c b0s = true → is_marked ? c = false) →
1402 (∀c.memb ? c l1 = true → is_marked ? c = false) →
1403 c = 〈b,true〉 → bit_or_null b = true →
1404 rs = bs@〈grid,false〉::l1@〈b0,true〉::b0s@〈comma,false〉::l2 →
1405 (〈b,true〉::bs = 〈b0,true〉::b0s ∧
1406 t2 = midtape ? (reverse ? bs@〈b,false〉::ls)
1407 〈grid,false〉 (l1@〈b0,false〉::b0s@〈comma,true〉::l2)) ∨
1408 (∃la,c',d',lb,lc.c' ≠ d' ∧
1409 〈b,false〉::bs = la@〈c',false〉::lb ∧
1410 〈b0,false〉::b0s = la@〈d',false〉::lc ∧
1411 t2 = midtape (FinProd … FSUnialpha FinBool) (reverse ? la@
1417 〈d',false〉 (lc@〈comma,false〉::l2)).
1419 lemma wsem_compare_new : WRealize ? compare R_compare_new.
1421 lapply (sem_while ?????? sem_comp_step t i outc Hloop) [%]
1422 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
1423 [ #tapea whd in ⊢ (%→?); #Rfalse #ls #c #rs #Htapea %
1425 [ #c' #Hc' #Hc lapply (Rfalse … Htapea) -Rfalse * >Hc
1426 whd in ⊢ (??%?→?); #Hfalse destruct (Hfalse)
1427 | #c' #Hc lapply (Rfalse … Htapea) -Rfalse * #_
1429 | #b #b0 #bs #b0s #l1 #l2 #Hlen #Hbs1 #Hb0s1 #Hbs2 #Hb0s2 #Hl1 #Hc
1430 cases (Rfalse … Htapea) -Rfalse >Hc whd in ⊢ (??%?→?);#Hfalse destruct (Hfalse)
1432 | #tapea #tapeb #tapec #Hleft #Hright #IH #Htapec lapply (IH Htapec) -Htapec -IH #IH
1433 whd in Hleft; #ls #c #rs #Htapea cases Hleft -Hleft
1434 #ls0 * #c' * #rs0 * >Htapea #Hdes destruct (Hdes) * *
1435 cases (true_or_false (bit_or_null c')) #Hc'
1436 [2: #Htapeb lapply (Htapeb Hc') -Htapeb #Htapeb #_ #_ %
1437 [%[#c1 #Hc1 #Heqc destruct (Heqc)
1438 cases (IH … Htapeb) * #_ #H #_ <Htapeb @(H … (refl…))
1439 |#c1 #Heqc destruct (Heqc)
1441 |#b #b0 #bs #b0s #comma #l1 #l2 #_ #_ #_ #_ #_
1442 #Heq destruct (Heq) >Hc' #Hfalse @False_ind destruct (Hfalse)
1444 |#_ (* no marks in rs ??? *) #_ #Hleft %
1446 [ #c'' #Hc'' #Heq destruct (Heq) >Hc'' in Hc'; #H destruct (H)
1447 | #c0 #Hfalse destruct (Hfalse)
1449 |#b #b0 #bs #b0s #comma #l1 #l2 #Hlen #Hbs1 #Hbs2 #Hb0s2 #Hl1
1450 #Heq destruct (Heq) #_ >append_cons; <associative_append #Hrs
1451 cases (Hleft … Hc' … Hrs) -Hleft
1452 [2: #c1 #memc1 cases (memb_append … memc1) -memc1 #memc1
1453 [cases (memb_append … memc1) -memc1 #memc1
1454 [@Hbs2 @memc1 |>(memb_single … memc1) %]
1457 |* (* manca il caso in cui dopo una parte uguale il
1458 secondo nastro finisca ... ???? *)
1459 #_ cases (true_or_false (b==b0)) #eqbb0
1460 [2: #_ #Htapeb %2 lapply (Htapeb … (\Pf eqbb0)) -Htapeb #Htapeb
1461 cases (IH … Htapeb) * #_ #Hout #_
1462 @(ex_intro … []) @(ex_intro … b) @(ex_intro … b0)
1463 @(ex_intro … bs) @(ex_intro … b0s) %
1464 [%[%[@(\Pf eqbb0) | %] | %]
1465 |>(Hout … (refl …)) -Hout >Htapeb @eq_f3 [2,3:%]
1466 >reverse_append >reverse_append >associative_append
1467 >associative_append %
1469 |lapply Hbs1 lapply Hbs2 lapply Hb0s2 lapply Hrs
1470 -Hbs1 -Hbs2 -Hb0s2 -Hrs
1471 @(list_cases2 … Hlen)
1472 [#Hrs #_ #_ #_ >associative_append >associative_append #Htapeb #_
1473 lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb
1474 cases (IH … Htapeb) -IH * #Hout #_ #_ %1 %
1476 |>(Hout grid (refl …) (refl …)) @eq_f
1477 normalize >associative_append %
1479 |* #a1 #ba1 * #a2 #ba2 #tl1 #tl2 #HlenS #Hrs #Hb0s2 #Hbs2 #Hbs1
1480 cut (ba1 = false) [@(Hbs2 〈a1,ba1〉) @memb_hd] #Hba1 >Hba1
1481 >associative_append >associative_append #Htapeb #_
1482 lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb
1483 cases (IH … Htapeb) -IH * #_ #_
1484 cut (ba2=false) [@(Hb0s2 〈a2,ba2〉) @memb_hd] #Hba2 >Hba2
1485 #IH cases(IH a1 a2 ??? (l1@[〈b0,false〉]) l2 HlenS ???? (refl …) ??)
1486 [4:#x #memx @Hbs1 @memb_cons @memx
1487 |5:#x #memx @Hbs2 @memb_cons @memx
1488 |6:#x #memx @Hb0s2 @memb_cons @memx
1489 |7:#x #memx cases (memb_append …memx) -memx #memx
1490 [@Hl1 @memx | >(memb_single … memx) %]
1491 |8:@(Hbs1 〈a1,ba1〉) @memb_hd
1492 |9: >associative_append >associative_append %
1493 |-IH -Hbs1 -Hbs2 -Hrs *
1495 [>(\P eqbb0) @eq_f destruct (Ha1a2) %
1497 [>reverse_cons >associative_append %
1499 |>associative_append %
1502 |-IH -Hbs1 -Hbs2 -Hrs *
1503 #la * #c' * #d' * #lb * #lc * * *
1504 #Hcd #H1 #H2 #Houtc %2
1505 @(ex_intro … (〈b,false〉::la)) @(ex_intro … c') @(ex_intro … d')
1506 @(ex_intro … lb) @(ex_intro … lc) %
1507 [%[%[@Hcd | >H1 %] |>(\P eqbb0) >Hba2 >H2 %]
1509 [>(\P eqbb0) >reverse_append >reverse_cons
1510 >reverse_cons >associative_append >associative_append
1511 >associative_append >associative_append %