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_____________________________________________________________*)
13 include "turing/universal/marks.ma".
15 definition copy_step_subcase ≝
16 λalpha,c,elseM.ifTM ? (test_char ? (λx.x == 〈c,true〉))
17 (seq (FinProd alpha FinBool) (adv_mark_r …)
19 (seq ? (adv_to_mark_l … (is_marked alpha))
20 (seq ? (write ? 〈c,false〉)
23 (seq ? (move_r …) (adv_to_mark_r … (is_marked alpha)))))))))
26 definition R_copy_step_subcase ≝
27 λalpha,c,RelseM,t1,t2.
29 t1 = midtape (FinProd … alpha FinBool) (l1@〈a0,false〉::〈x0,true〉::l2)
30 〈x,true〉 (〈a,false〉::l3) →
31 (∀c.memb ? c l1 = true → is_marked ? c = false) →
32 (x = c ∧ t2 = midtape ? (〈x,false〉::l1@〈a0,true〉::〈x,false〉::l2) 〈a,true〉 l3) ∨
33 (x ≠ c ∧ RelseM t1 t2).
35 lemma sem_copy_step_subcase :
36 ∀alpha,c,elseM,RelseM. Realize ? elseM RelseM →
37 Realize ? (copy_step_subcase alpha c elseM) (R_copy_step_subcase alpha c RelseM).
38 #alpha #c #elseM #RelseM #HelseM #intape
39 cases (sem_if ? (test_char ? (λx. x == 〈c,true〉)) ?????? tc_true (sem_test_char ? (λx.x == 〈c,true〉))
40 (sem_seq ????? (sem_adv_mark_r alpha)
41 (sem_seq ????? (sem_move_l …)
42 (sem_seq ????? (sem_adv_to_mark_l … (is_marked alpha))
43 (sem_seq ????? (sem_write ? 〈c,false〉)
44 (sem_seq ????? (sem_move_r …)
45 (sem_seq ????? (sem_mark …)
46 (sem_seq ????? (sem_move_r …) (sem_adv_to_mark_r … (is_marked alpha)))))))))
48 #k * #outc * #Hloop #HR %{k} %{outc} % [@Hloop] -Hloop
49 #a #l1 #x0 #a0 #l2 #x #l3 #Hintape #Hl1marks cases HR -HR
50 [ * #ta * whd in ⊢ (%→?); >Hintape * * #c0 * whd in ⊢ (??%?→?); #Hx #Hc #Hta
51 * #tb * whd in ⊢ (%→?); * #Htb cases (Htb (l1@〈a0,false〉::〈x0,true〉::l2) x) -Htb
52 #Htb lapply (Htb … Hta) -Htb #Htb #_ #_
53 * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc … Htb) -Htb -Htc #Htc
54 * #td * whd in ⊢ (%→?); * #_ #Htd cases (Htd … Htc) -Htd #_ #Htd cases (Htd (refl ??))
55 -Htd #Htd lapply (Htd (l1@[〈a0,false〉]) 〈x0,true〉 l2 ???) //
56 [#x1 #Hx1 cases (memb_append … Hx1) [ @Hl1marks | #Hsingle >(memb_single … Hsingle) % ]
57 |whd in ⊢ (??%?); // ]
59 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Hte -Htd -Htc #Hte
60 * #tf * whd in ⊢ (%→?); * #_ #Htf lapply (Htf … Hte) -Hte -Htf >reverse_append #Htf
61 * #tg * whd in ⊢ (%→?); * #Htg #_ lapply (Htg … Htf) -Htf -Htg >reverse_single #Htg
62 * #th * whd in ⊢ (%→?); * #_ #Hth lapply (Hth … Htg) -Htg -Hth
63 generalize in match Hl1marks; -Hl1marks @(list_elim_left … l1)
64 [ #Hl1marks #Hth whd in ⊢ (%→?); * #_ #Houtc cases (Houtc … Hth) -Houtc
65 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
66 * * #_ #Houtc #_ lapply (Houtc [] ?? (refl ??) (refl ??) Hl1marks) -Houtc
67 #Houtc % >(\P Hc) in Hx; #Hx destruct (Hx) % // @Houtc
68 | -l1 #c1 #l1 #_ #Hl1marks >reverse_append >reverse_single
69 #Hth whd in ⊢ (%→?); * #_ #Houtc cases (Houtc … Hth) -Houtc
70 [ * >Hl1marks [ #Hfalse destruct (Hfalse) ] @memb_append_l2 @memb_hd ]
71 * * #_ #Houtc lapply (Houtc (reverse ? l1@[〈x,false〉]) 〈a,true〉 l3 ? (refl ??) ?) -Houtc
72 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1
73 [@Hl1marks @memb_append_l1 <(reverse_reverse … l1) @memb_reverse @Hx1
74 |>(memb_single … Hx1) % ]
75 | normalize >associative_append % ]
76 #Houtc #_ % destruct (Hx) lapply (\P Hc) -Hc #Hc destruct (Hc) % //
77 >Houtc >reverse_append >reverse_reverse >associative_append >associative_append % ]
78 | * #ta * whd in ⊢ (%→?); >Hintape * #Hxc #Hta #Helse %2 %
80 % #Hxc0 >Hxc0 in Hxc; #Hxc lapply (Hxc 〈c,true〉 (refl …)) #Hfalse
81 cases (\Pf Hfalse) #Hfalse0 @Hfalse0 %
95 else if current = 1,tt
104 else if current = null
113 definition nocopy_subcase ≝
114 ifTM STape (test_char ? (λx:STape.x == 〈null,true〉))
115 (seq ? (adv_mark_r …)
117 (seq ? (adv_to_mark_l … (is_marked ?))
118 (seq ? (adv_mark_r …)
119 (seq ? (move_r …) (adv_to_mark_r … (is_marked ?)))))))
122 definition R_nocopy_subcase ≝
125 t1 = midtape STape (l1@〈a0,false〉::〈x0,true〉::l2)
126 〈x,true〉 (〈a,false〉::l3) →
127 (∀c.memb ? c l1 = true → is_marked ? c = false) →
129 t2 = midtape ? (〈x,false〉::l1@〈a0,true〉::〈x0,false〉::l2) 〈a,true〉 l3) ∨
130 (x ≠ null ∧ t2 = t1).
132 lemma sem_nocopy_subcase : Realize ? nocopy_subcase R_nocopy_subcase.
134 cases (sem_if ? (test_char ? (λx:STape.x == 〈null,true〉)) ?????? tc_true
135 (sem_test_char ? (λx:STape.x == 〈null,true〉))
136 (sem_seq … (sem_adv_mark_r …)
137 (sem_seq … (sem_move_l …)
138 (sem_seq … (sem_adv_to_mark_l … (is_marked ?))
139 (sem_seq … (sem_adv_mark_r …)
140 (sem_seq … (sem_move_r …)
141 (sem_adv_to_mark_r … (is_marked ?))))))) (sem_nop ?) intape)
142 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
143 #a #l1 #x0 #a0 #l2 #x #l3 #Hintape #Hl1marks cases HR -HR
144 [ * #ta * whd in ⊢ (%→?); >Hintape * * #c * whd in ⊢ (??%?→?); #Hc destruct (Hc) #Hx #Hta
145 * #tb * whd in ⊢ (%→?); * #Htb #_ cases (Htb (l1@〈a0,false〉::〈x0,true〉::l2) x) -Htb #Htb #_ lapply (Htb … Hta) -Hta -Htb #Htb
146 * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc … Htb) -Htb -Htc #Htc
147 * #td * whd in ⊢ (%→?); * #_ #Htd cases (Htd … Htc) -Htd #_ #Htd cases (Htd (refl …)) -Htd #Htd #_
148 lapply (Htd (l1@[〈a0,false〉]) 〈x0,true〉 l2 ? (refl …) ?)
149 [#x1 #Hx1 cases (memb_append … Hx1) [@Hl1marks| -Hx1 #Hx1 >(memb_single … Hx1) % ]
150 |>associative_append % ] -Htd >reverse_append in ⊢ (???%→?); >associative_append in ⊢ (???%→?); #Htd
151 * #te * whd in ⊢ (%→?); * #Hte cases (Hte l2 x0) -Hte #Hte #_ #_ lapply (Hte … Htd) -Hte -Htd -Htc #Hte
152 * #tf * whd in ⊢ (%→?); * #_ #Htf lapply (Htf … Hte) -Hte -Htf
153 generalize in match Hl1marks; -Hl1marks @(list_elim_left … l1)
154 [ #Hl1marks #Hth whd in ⊢ (%→?); * #_ #Houtc cases (Houtc … Hth) -Houtc
155 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
156 * * #_ #Houtc lapply (Houtc [] ?? (refl ??) (refl ??) Hl1marks) -Houtc
157 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) #_ % % [%] @Houtc
158 | -l1 #c1 #l1 #_ #Hl1marks >reverse_append >reverse_single
159 #Hth whd in ⊢ (%→?); * #_ #Houtc cases (Houtc … Hth) -Houtc
160 [ * >Hl1marks [ #Hfalse destruct (Hfalse) ] @memb_append_l2 @memb_hd ]
161 * * #Hc1 #Houtc #_ lapply (Houtc (reverse ? l1@[〈x,false〉]) 〈a,true〉 l3 ? (refl ??) ?) -Houtc
162 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1
163 [@Hl1marks @memb_append_l1 <(reverse_reverse … l1) @memb_reverse @Hx1
164 |>(memb_single … Hx1) % ]
165 | normalize >associative_append % ]
166 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) % % [%] >Houtc
167 >reverse_append >reverse_reverse >associative_append >associative_append % ]
168 | * #ta * whd in ⊢ (%→?); >Hintape * #Hxc
169 cut (x ≠ null) [ % #Hx cases (\Pf (Hxc ? (refl …))) #Hfalse @Hfalse >Hx % ] -Hxc #Hxnull
170 #Hta whd in ⊢ (%→?); #Houtc %2 % // <Hta @Houtc ]
173 definition copy_step ≝
174 ifTM ? (test_char STape (λc.bit_or_null (\fst c)))
175 (single_finalTM ? (copy_step_subcase FSUnialpha (bit false)
176 (copy_step_subcase FSUnialpha (bit true) nocopy_subcase)))
180 definition R_copy_step_true ≝
182 ∀ls,c,rs. t1 = midtape STape ls 〈c,true〉 rs →
183 bit_or_null c = true ∧
185 ls = (l1@〈a0,false〉::〈x0,true〉::l2) →
186 rs = (〈a,false〉::l3) →
189 t2 = midtape STape (〈bit x,false〉::l1@〈a0,true〉::〈bit x,false〉::l2) 〈a,true〉 l3) ∨
191 t2 = midtape ? (〈null,false〉::l1@〈a0,true〉::〈x0,false〉::l2) 〈a,true〉 l3))).
193 definition R_copy_step_false ≝
195 ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs →
196 bit_or_null (\fst c) = false ∧ t2 = t1.
198 lemma sem_copy_step :
199 accRealize ? copy_step (inr … (inl … (inr … start_nop))) R_copy_step_true R_copy_step_false.
201 @(acc_sem_if_app … (sem_test_char ? (λc:STape.bit_or_null (\fst c))) …
202 (sem_copy_step_subcase FSUnialpha (bit false) …
203 (sem_copy_step_subcase FSUnialpha (bit true) … (sem_nocopy_subcase …)))
205 [ #t1 #t2 #t3 whd in ⊢ (%→%→?); #H1 #H2 #ls #c #rs #Ht1 >Ht1 in H1;
206 * * #c0 * whd in ⊢ (??%?→?); #Hc0 destruct (Hc0) #Hc #Ht3 % //
207 #a #l1 #x0 #a0 #l2 #l3 #Hls #Hrs #Hl1marks >Hls in Ht3; >Hrs #Ht3
209 [ * #Hc' #Ht2 % %{false} % // <Hc' @Ht2
210 | * #Hnotfalse whd in ⊢ (%→?); #Ht2 cases (Ht2 … Ht3 ?) -Ht2
211 [ * #Hc' #Ht2 % %{true} % // <Hc' @Ht2
212 | * #Hnottrue whd in ⊢ (%→?); #Ht2 cases (Ht2 … Ht3 ?) -Ht2
213 [ * #Hc' #Ht2 %2 <Hc' % // @Ht2
214 | * #Hnotnull @False_ind
215 generalize in match Hnotnull;generalize in match Hnottrue;generalize in match Hnotfalse;
216 cases c in Hc; normalize
217 [ * [ #_ #_ * #Hfalse #_ | #_ * #Hfalse #_ #_ ]
219 |*: #Hfalse destruct (Hfalse) ] @Hfalse %
223 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #H1 #H2 #ls #c #rs #Ht1
224 >Ht1 in H1; * #Hcur #Ht3 % // @Hcur % ]
228 1) il primo carattere è marcato
229 2) l'ultimo carattere è l'unico che può essere null, gli altri sono bit
230 3) il terminatore non è né bit, né null
233 definition copy0 ≝ whileTM ? copy_step (inr … (inl … (inr … start_nop))).
235 let rec merge_config (l1,l2:list STape) ≝
238 | cons p1 l1' ⇒ match l2 with
241 let 〈c1,b1〉 ≝ p1 in let 〈c2,b2〉 ≝ p2 in
244 | _ ⇒ p2 ] :: merge_config l1' l2' ] ].
246 lemma merge_config_append :
247 ∀l1,l2,l3,l4.|l1| = |l2| →
248 merge_config (l1@l3) (l2@l4) = merge_config l1 l2@merge_config l3 l4.
249 #l1 #l2 #l3 #l4 #Hlen @(list_ind2 … Hlen)
251 | #t1 #t2 * #c1 #b1 * #c2 #b2 #IH whd in ⊢ (??%%); >IH % ]
254 definition R_copy0 ≝ λt1,t2.
255 ∀ls,c,c0,rs,l1,l3,l4.
256 t1 = midtape STape (l3@l4@〈c0,true〉::ls) 〈c,true〉 (l1@rs) →
257 no_marks l1 → no_marks (l3@l4) → |l1| = |l4| →
258 ∀l1',bv.〈c,false〉::l1 = l1'@[〈comma,bv〉] → only_bits_or_nulls l1' →
259 ∀l4',bg.l4@[〈c0,false〉] = 〈grid,bg〉::l4' → only_bits_or_nulls l4' →
260 (c = comma ∧ t2 = t1) ∨
262 t2 = midtape ? (reverse ? l1'@l3@〈grid,true〉::
263 merge_config l4' (reverse ? l1')@ls)
266 lemma inj_append_singleton_l1 :
267 ∀A.∀l1,l2:list A.∀a1,a2.l1@[a1] = l2@[a2] → l1 = l2.
268 #A #l1 #l2 #a1 #a2 #H lapply (eq_f … (reverse ?) … H)
269 >reverse_append >reverse_append normalize #H1 destruct
270 lapply (eq_f … (reverse ?) … e0) >reverse_reverse >reverse_reverse //
273 lemma inj_append_singleton_l2 :
274 ∀A.∀l1,l2:list A.∀a1,a2.l1@[a1] = l2@[a2] → a1 = a2.
275 #A #l1 #l2 #a1 #a2 #H lapply (eq_f … (reverse ?) … H)
276 >reverse_append >reverse_append normalize #H1 destruct %
279 axiom daemon : ∀P:Prop.P.
281 lemma list_cases2_full :
282 ∀T1,T2:Type[0].∀l1:list T1.∀l2:list T2.∀P:Prop.
283 length ? l1 = length ? l2 →
284 (l1 = [] → l2 = [] → P) →
285 (∀hd1,hd2,tl1,tl2.l1 = hd1::tl1 → l2 = hd2::tl2 → P) → P.
286 #T1 #T2 #l1 #l2 #P #Hl @(list_ind2 … Hl)
287 [ #Pnil #Pcons @Pnil //
288 | #tl1 #tl2 #hd1 #hd2 #IH1 #IH2 #Hp @Hp // ]
291 lemma wsem_copy0 : WRealize ? copy0 R_copy0.
292 #intape #k #outc #Hloop
293 lapply (sem_while … sem_copy_step intape k outc Hloop) [%] -Hloop
294 * #ta * #Hstar @(star_ind_l ??????? Hstar)
295 [ #tb whd in ⊢ (%→?); #Hleft
296 #ls #c #c0 #rs #l1 #l3 #l4 #Htb #Hl1nomarks #Hl3l4nomarks #Hlen #l1' #bv
297 #Hl1 #Hl1bits #l4' #bg #Hl4 #Hl4bits
298 cases (Hleft … Htb) -Hleft #Hc #Houtc % %
299 [ generalize in match Hl1bits; -Hl1bits cases l1' in Hl1;
300 [ normalize #Hl1 #c1 destruct (Hl1) %
301 | * #c' #b' #l0 #Heq normalize in Heq; destruct (Heq)
302 #Hl1bits lapply (Hl1bits 〈c',false〉 ?) [ @memb_hd ]
303 >Hc #Hfalse destruct ]
305 | #tb #tc #td whd in ⊢ (%→?→(?→%)→%→?); #Htc #Hstar1 #Hind #Htd
306 lapply (Hind Htd) -Hind #Hind
307 #ls #c #c0 #rs #l1 #l3 #l4 #Htb #Hl1nomarks #Hl3l4nomarks #Hlen #l1' #bv
308 #Hl1 #Hl1bits #l4' #bg #Hl4 #Hl4bits %2
309 cases (Htc … Htb) -Htc #Hcbitnull #Htc
310 % [ % #Hc' >Hc' in Hcbitnull; normalize #Hfalse destruct (Hfalse) ]
311 cut (|l1| = |reverse ? l4|) [>length_reverse @Hlen] #Hlen1
312 @(list_cases2_full … Hlen1)
313 [ (* case l1 = [] is discriminated because l1 contains at least comma *)
314 #Hl1nil @False_ind >Hl1nil in Hl1; cases l1' normalize
315 [ #Hl1 destruct normalize in Hcbitnull; destruct (Hcbitnull)
316 | #p0 #l0 normalize #Hfalse destruct (Hfalse) cases l0 in e0;
317 [ normalize #Hfalse1 destruct (Hfalse1)
318 | #p0' #l0' normalize #Hfalse1 destruct (Hfalse1) ] ]
319 | (* case c::l1 = c::a::l1'' *)
320 * #a #ba * #a0 #ba0 #l1'' #l4'' #Hl1cons #Hl4cons
321 lapply (eq_f ?? (reverse ?) ?? Hl4cons) >reverse_reverse >reverse_cons -Hl4cons #Hl4cons
323 [ >Hl1cons in Hl1nomarks; #Hl1nomarks lapply (Hl1nomarks 〈a,ba〉 ?)
324 [ @memb_hd | normalize // ] ] #Hba
326 [ >Hl4cons in Hl3l4nomarks; #Hl3l4nomarks lapply (Hl3l4nomarks 〈a0,ba0〉 ?)
327 [ @memb_append_l2 @memb_append_l2 @memb_hd | normalize // ] ] #Hba0
328 >Hba0 in Hl4cons; >Hba in Hl1cons; -Hba0 -Hba #Hl1cons #Hl4cons
329 >Hl4cons in Htc; >Hl1cons #Htc
330 lapply (Htc a (l3@reverse ? l4'') c0 a0 ls (l1''@rs) ? (refl ??) ?)
331 [ #x #Hx @Hl3l4nomarks >Hl4cons <associative_append
333 | >associative_append >associative_append %
335 cut (∃la.l1' = 〈c,false〉::la)
336 [ >Hl1cons in Hl1; cases l1'
337 [normalize #Hfalse destruct (Hfalse)
338 | #p #la normalize #Hla destruct (Hla) @(ex_intro ?? la) % ] ]
340 cut (∃lb.l4' = lb@[〈c0,false〉])
342 @(list_elim_left … l4')
343 [ #Heq lapply (eq_f … (length ?) … Heq)
344 >length_append >length_append
345 >commutative_plus normalize >commutative_plus normalize
348 >(inj_append_singleton_l2 ? (reverse ? l4''@[〈a0,false〉]) (〈grid,bg〉::tl) 〈c0,false〉 a1 Heq)
351 cut (|lb| = |reverse ? la|)
352 [ >Hla in Hl1; >Hlb in Hl4; #Hl4 #Hl1
353 >(?:l1 = la@[〈comma,bv〉]) in Hlen;
354 [|normalize in Hl1; destruct (Hl1) %]
355 >(?:l4 = 〈grid,bg〉::lb)
356 [|@(inj_append_singleton_l1 ?? (〈grid,bg〉::lb) ?? Hl4) ]
357 >length_append >commutative_plus >length_reverse
358 normalize #Hlalb destruct (Hlalb) //
361 (* by hyp on the first iteration step,
362 we consider whether c = bit x or c = null *)
365 lapply (Hind (〈bit x,false〉::ls) a a0 rs l1''
366 (〈bit x,false〉::l3) (reverse ? l4'') ????)
367 [ >Hl1cons in Hlen; >Hl4cons >length_append >commutative_plus
368 normalize #Hlen destruct (Hlen) //
369 | #x0 #Hx0 cases (orb_true_l … Hx0)
370 [ #Hx0eq >(\P Hx0eq) %
371 | -Hx0 #Hx0 @Hl3l4nomarks >Hl4cons
372 <associative_append @memb_append_l1 // ]
373 | #x0 #Hx0 @Hl1nomarks >Hl1cons @memb_cons //
374 | >Htc >associative_append %
376 <Hl1cons <Hl4cons #Hind lapply (Hind la bv ?? lb bg ??)
377 [ #x0 #Hx0 @Hl4bits >Hlb @memb_append_l1 //
378 | >Hlb in Hl4; normalize in ⊢ (%→?); #Hl4
379 @(inj_append_singleton_l1 ? l4 (〈grid,bg〉::lb) … Hl4)
380 | #x0 #Hx0 @Hl1bits >Hla @memb_cons //
381 | >Hla in Hl1; normalize in ⊢ (%→?); #Hl1
382 destruct (Hl1) // ] -Hind
383 (* by IH, we proceed by cases, whether a = comma
384 (consequently several lists = []) or not *)
387 cut (la = [] ∧ lb = [] ∧ l1'' = [] ∧ l4'' = [])
388 [ @daemon ] * * * #Hla1 #Hlb1 #Hl1nil #Hl4nil
389 >Hl1cons in Hl1; >Hla
391 >Hl4cons in Hl4; >Hlb #Hl4
392 >Hla1 >Hlb1 >Hl1nil >Hl4nil >Hx
393 cut (a0 = grid) [ @daemon ] #Ha0 <Ha <Ha0
394 normalize in ⊢ (??(??%?%)(??%?%)); >associative_append %
395 | * #Ha #Houtc1 >Houtc1 @eq_f3 //
396 >Hla >reverse_cons >associative_append @eq_f
397 >Hx whd in ⊢ (??%?); @eq_f whd in ⊢ (???%); @eq_f @eq_f
398 >Hlb >append_cons @eq_f2 // >(merge_config_append … Hlen2) %
403 lapply (Hind (〈c0,false〉::ls) a a0 rs l1'' (〈null,false〉::l3) (reverse ? l4'') ????)
404 [ >Hl1cons in Hlen; >Hl4cons >length_append >commutative_plus normalize
405 #Hlen destruct (Hlen) @e0
406 | #x0 #Hx0 cases (memb_append STape ? [〈null,false〉] (l3@reverse ? l4'') … Hx0) -Hx0 #Hx0
407 [ >(memb_single … Hx0) %
408 | @Hl3l4nomarks cases (memb_append … Hx0) -Hx0 #Hx0
410 | @memb_append_l2 >Hl4cons @memb_append_l1 // ]
412 | >Hl1cons #x' #Hx0 @Hl1nomarks >Hl1cons @memb_cons //
413 | >Htc @eq_f3 // >associative_append % ] -Hind <Hl1cons <Hl4cons #Hind
414 lapply (Hind la bv ?? lb bg ??)
415 [ #x0 #Hx0 @Hl4bits >Hlb @memb_append_l1 //
416 | >Hlb in Hl4; normalize in ⊢ (%→?); #Hl4
417 @(inj_append_singleton_l1 ? l4 (〈grid,bg〉::lb) … Hl4)
418 | #x0 #Hx0 @Hl1bits >Hla @memb_cons //
419 | >Hla in Hl1; normalize in ⊢ (%→?); #Hl1
420 destruct (Hl1) // ] -Hind *
421 (* by IH, we proceed by cases, whether a = comma
422 (consequently several lists = []) or not *)
423 [ * #Ha #Houtc1 >Hl1cons in Hl1; >Hla
425 >Hl4cons in Hl4; >Hlb #Hl4
426 cut (la = [] ∧ lb = [] ∧ l1'' = [] ∧ l4'' = [])
427 [@daemon] * * * #Hla1 #Hlb1 #Hl1nil #Hl4nil
428 >Hla1 >Hlb1 >Hl1nil >Hl4nil >Hc
429 cut (a0 = grid) [ @daemon ] #Ha0 <Ha <Ha0
430 normalize in ⊢ (??(??%?%)(??%?%)); >associative_append %
431 | * #Ha #Houtc1 >Houtc1 @eq_f3 //
432 >Hla >reverse_cons >associative_append @eq_f
433 >Hc whd in ⊢ (??%?); @eq_f whd in ⊢ (???%); @eq_f @eq_f
434 >Hlb >append_cons @eq_f2 // >(merge_config_append … Hlen2) %
440 definition merge_char ≝ λc1,c2.
447 merge_config (〈c1,false〉::conf1) (〈c2,false〉::conf2) =
448 〈merge_char c1 c2,false〉::merge_config conf1 conf2.
449 #c1 #c2 #conf1 #conf2 normalize @eq_f2 //
453 lemma merge_bits : ∀l1,l2.|l1| = |l2| → only_bits l2 → merge_config l1 l2 = l2.
454 #l1 #l2 #Hlen @(list_ind2 … Hlen) //
455 #tl1 #tl2 #hd1 #hd2 #IH
456 >(eq_pair_fst_snd … hd1) >(eq_pair_fst_snd … hd2) #Hbits
457 change with (cons ???) in ⊢ (??%?); @eq_f2
458 [ cases (\fst hd2) in Hbits;
460 |*: #Hfalse lapply (Hfalse … (memb_hd …)) normalize #Hfalse1 destruct (Hfalse1) ]
461 | @IH #x #Hx @Hbits @memb_cons // ]
464 lemma merge_config_c_nil :
465 ∀c.merge_config c [] = [].
466 #c cases c normalize //
469 lemma reverse_merge_config :
470 ∀c1,c2.|c1| = |c2| → reverse ? (merge_config c1 c2) =
471 merge_config (reverse ? c1) (reverse ? c2).
472 #c1 #c2 <(length_reverse ? c1) <(length_reverse ? c2) #Hlen
473 <(reverse_reverse ? c1) in ⊢ (??%?); <(reverse_reverse ? c2) in ⊢ (??%?);
474 generalize in match Hlen; @(list_ind2 … Hlen) -Hlen //
475 #tl1 #tl2 #hd1 #hd2 #IH whd in ⊢ (??%%→?); #Hlen destruct (Hlen) -Hlen
476 <(length_reverse ? tl1) in e0; <(length_reverse ? tl2) #Hlen
477 >reverse_cons >reverse_cons >(merge_config_append ???? Hlen)
478 >reverse_append >(eq_pair_fst_snd ?? hd1) >(eq_pair_fst_snd ?? hd2)
479 whd in ⊢ (??%%); @eq_f2 // @IH //
484 seq STape copy0 (seq ? (move_l …) (seq ? (adv_to_mark_l … (is_marked ?))
485 (seq ? (clear_mark …) (seq ? (adv_to_mark_r … (is_marked ?)) (clear_mark …))))).
488 s0, s1 = caratteri di testa dello stato
489 c0 = carattere corrente del nastro oggetto
490 c1 = carattere in scrittura sul nastro oggetto
492 questa dimostrazione sfrutta il fatto che
493 merge_config (l0@[c0]) (l1@[c1]) = l1@[merge_char c0 c1]
494 se l0 e l1 non contengono null
497 definition R_copy ≝ λt1,t2.
498 ∀ls,s0,s1,c0,c1,rs,l1,l3,l4.
499 t1 = midtape STape (l3@〈grid,false〉::〈c0,false〉::l4@〈s0,true〉::ls) 〈s1,true〉 (l1@〈c1,false〉::〈comma,false〉::rs) →
500 no_marks l1 → no_marks l3 → no_marks l4 → |l1| = |l4| →
501 only_bits (l4@[〈s0,false〉]) → only_bits (〈s1,false〉::l1) →
502 bit_or_null c0 = true → bit_or_null c1 = true →
503 t2 = midtape STape (〈c1,false〉::reverse ? l1@〈s1,false〉::l3@〈grid,false〉::
504 〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)
507 axiom sem_copy0 : Realize ? copy0 R_copy0.
509 definition option_cons ≝ λA.λa:option A.λl.
515 axiom sem_copy : Realize ? copy R_copy.
518 cases (sem_seq … (sem_copy0 …)
519 (sem_seq … (sem_move_l …)
520 (sem_seq … (sem_adv_to_mark_l … (is_marked ?))
521 (sem_seq … (sem_clear_mark …)
522 (sem_seq … (sem_adv_to_mark_r … (is_marked ?)) (sem_clear_mark …))))) intape)
523 #k * #outc * #Hloop #HR %{k} %{outc} % [@Hloop] -Hloop
524 #ls #s0 #s1 #c0 #c1 #rs #l1 #l2 #l3 #Hintape #Hl1marks #Hl2marks #Hl3marks #Hlen
525 #Hbits1 #Hbits2 #Hc0bits #Hc1bits
526 cases HR -HR #ta * whd in ⊢ (%→?); #Hta
527 cut (ta = midtape STape (〈c1,false〉::reverse ? l1@〈s1,false〉::l2@〈grid,true〉::
528 〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)
530 [lapply (Hta ls s1 s0 rs (l1@[〈c1,false〉;〈comma,false〉]) l2 (〈grid,false〉::〈c0,false〉::l3) ?)
531 [>associative_append in ⊢ (???(????%)); normalize in ⊢ (???(??%%%)); @Hintape ]
532 -Hta #Hta cases (Hta ??? (〈s1,false〉::l1@[〈c1,false〉]) false ? ? ?? (refl ??) ?)
533 [3: #x #Hx cases (memb_append … Hx) -Hx #Hx
535 | cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) % | >(memb_single … Hx) % ]]
536 |4: #x #Hx cases (memb_append … Hx) -Hx #Hx
538 | cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) % | cases (orb_true_l … Hx) [-Hx #Hx >(\P Hx) % | @Hl3marks ] ] ]
539 |5: >length_append normalize >Hlen >commutative_plus %
540 |6: normalize >associative_append %
541 |7: #x #Hx cases (memb_append ?? (〈s1,false〉::l1) … Hx) -Hx #Hx
542 [ whd in ⊢ (??%?); >(Hbits2 … Hx) %
543 | >(memb_single … Hx) // ]
544 |8: #x #Hx cases (memb_append … Hx) -Hx #Hx
545 [ cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) // | whd in ⊢ (??%?); >Hbits1 // @memb_append_l1 // ]
546 | >(memb_single … Hx) whd in ⊢ (??%?); >(Hbits1 〈s0,false〉) // @memb_append_l2 @memb_hd ]
547 | * #Hs1 @False_ind >Hs1 in Hbits2; #Hbits2 lapply (Hbits2 〈comma,false〉 ?) //
548 normalize #Hfalse destruct (Hfalse)
549 | * #Hs1 #Ht2 >Ht2 >reverse_cons >reverse_append >reverse_single @eq_f3 //
550 >merge_cons >merge_bits
551 [2: #x #Hx @Hbits2 cases (memb_append STape ? (reverse ? l1) ? Hx) -Hx #Hx
552 [@daemon | >(memb_single … Hx) @memb_hd ]
553 |3: >length_append >length_append >length_reverse >Hlen % ]
554 normalize >associative_append normalize >associative_append %
556 ] -Hta #Hta * #tb * whd in ⊢ (%→?); #Htb
557 lapply (Htb … Hta) -Htb #Htb change with (midtape ????) in Htb:(???%);
558 * #tc * whd in ⊢ (%→?); #Htc
560 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
562 lapply (Htc (reverse ? l1@〈s1,false〉::l2) 〈grid,true〉
563 (〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)???)
564 [ #x #Hx cases (memb_append … Hx) -Hx #Hx
566 | cases (orb_true_l … Hx) -Hx #Hx
567 [ >(\P Hx) % | @(Hl2marks … Hx) ] ]
569 | whd in ⊢ (??%?); >associative_append % ] -Htc #Htc
570 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
571 * #te * whd in ⊢ (%→?); #Hte cases (Hte … Htd) -Hte -Htd
572 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
574 lapply (Hte (reverse ? (reverse ? l1@〈s1,false〉::l2)@[〈c1,false〉])
575 〈comma,true〉 rs ? (refl ??) ?) -Hte
576 [ >reverse_append >reverse_cons >reverse_reverse #x #Hx
577 cases (memb_append … Hx) -Hx #Hx
578 [ cases (memb_append … Hx) -Hx #Hx
579 [ cases (memb_append … Hx) -Hx #Hx
581 | lapply (memb_single … Hx) -Hx #Hx >Hx % ]
583 | lapply (memb_single … Hx) -Hx #Hx >Hx % ]
584 | >reverse_append >reverse_reverse >reverse_cons
585 >associative_append >associative_append >associative_append
586 >associative_append >associative_append % ]
587 #Hte whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc #Houtc >Houtc
589 >reverse_append >reverse_append >reverse_single >reverse_cons
590 >reverse_append >reverse_append >reverse_reverse >reverse_reverse
591 >reverse_single >associative_append >associative_append %