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/tuples.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 #Hta cases (Hta … (refl ??)) -Hta #Hx #Hta
51 * #tb * whd in ⊢ (%→?); #Htb lapply (Htb … Hta) -Hta -Htb #Htb
52 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htb -Htc #Htc
53 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
54 [ >Htc * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
55 * #_ #Htd lapply (Htd (l1@[〈a0,false〉]) 〈x0,true〉 l2 ? (refl ??) ?) -Htd
56 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1 [@(Hl1marks ? Hx1)|>(memb_single … Hx1) %]
57 | normalize >associative_append % ] #Htd
58 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Hte -Htd -Htc #Hte
59 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Hte -Htf >reverse_append #Htf
60 * #tg * whd in ⊢ (%→?); #Htg lapply (Htg … Htf) -Htf -Htg >reverse_single #Htg
61 * #th * whd in ⊢ (%→?); #Hth lapply (Hth … Htg) -Htg -Hth
62 generalize in match Hl1marks; -Hl1marks @(list_elim_left … l1)
63 [ #Hl1marks #Hth whd in ⊢ (%→?); #Houtc cases (Houtc … Hth) -Houtc
64 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
65 * #_ #Houtc lapply (Houtc [] ?? (refl ??) (refl ??) Hl1marks) -Houtc
66 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) % % [%] @Houtc
67 | -l1 #c1 #l1 #_ #Hl1marks >reverse_append >reverse_single
68 #Hth whd in ⊢ (%→?); #Houtc cases (Houtc … Hth) -Houtc
69 [ * >Hl1marks [ #Hfalse destruct (Hfalse) ] @memb_append_l2 @memb_hd ]
70 * #_ #Houtc lapply (Houtc (reverse ? l1@[〈x,false〉]) 〈a,true〉 l3 ? (refl ??) ?) -Houtc
71 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1 [ @Hl1marks @memb_append_l1 @daemon | >(memb_single … Hx1) % ]
72 | normalize >associative_append % ]
73 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) % % [%] >Houtc
74 >reverse_append >reverse_reverse >associative_append >associative_append % ]
75 | * #ta * whd in ⊢ (%→?); >Hintape #Hta cases (Hta ? (refl ??)) -Hta
76 #Hxc #Hta >Hta #Houtc %2 % // lapply (\Pf Hxc) @not_to_not #Heq >Heq % ]
89 else if current = 1,tt
98 else if current = null
107 definition nocopy_subcase ≝
108 ifTM STape (test_char ? (λx:STape.x == 〈null,true〉))
109 (seq ? (adv_mark_r …)
111 (seq ? (adv_to_mark_l … (is_marked ?))
112 (seq ? (adv_mark_r …)
113 (seq ? (move_r …) (adv_to_mark_r … (is_marked ?)))))))
116 definition R_nocopy_subcase ≝
119 t1 = midtape STape (l1@〈a0,false〉::〈x0,true〉::l2)
120 〈x,true〉 (〈a,false〉::l3) →
121 (∀c.memb ? c l1 = true → is_marked ? c = false) →
123 t2 = midtape ? (〈x,false〉::l1@〈a0,true〉::〈x0,false〉::l2) 〈a,true〉 l3) ∨
124 (x ≠ null ∧ t2 = t1).
126 lemma sem_nocopy_subcase : Realize ? nocopy_subcase R_nocopy_subcase.
128 cases (sem_if ? (test_char ? (λx:STape.x == 〈null,true〉)) ?????? tc_true
129 (sem_test_char ? (λx:STape.x == 〈null,true〉))
130 (sem_seq … (sem_adv_mark_r …)
131 (sem_seq … (sem_move_l …)
132 (sem_seq … (sem_adv_to_mark_l … (is_marked ?))
133 (sem_seq … (sem_adv_mark_r …)
134 (sem_seq … (sem_move_r …)
135 (sem_adv_to_mark_r … (is_marked ?))))))) (sem_nop ?) intape)
136 #k * #outc * #Hloop #HR @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
137 #a #l1 #x0 #a0 #l2 #x #l3 #Hintape #Hl1marks cases HR -HR
138 [ * #ta * whd in ⊢ (%→?); >Hintape #Hta cases (Hta … (refl ??)) -Hta #Hx #Hta
139 * #tb * whd in ⊢ (%→?); #Htb lapply (Htb … Hta) -Hta -Htb #Htb
140 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htb -Htc #Htc
141 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
142 [ >Htc * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
143 * #_ #Htd lapply (Htd (l1@[〈a0,false〉]) 〈x0,true〉 l2 ? (refl ??) ?) -Htd
144 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1 [@(Hl1marks ? Hx1)|>(memb_single … Hx1) %]
145 | normalize >associative_append % ] >reverse_append #Htd
146 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Hte -Htd -Htc #Hte
147 * #tf * whd in ⊢ (%→?); #Htf lapply (Htf … Hte) -Hte -Htf
148 generalize in match Hl1marks; -Hl1marks @(list_elim_left … l1)
149 [ #Hl1marks #Hth whd in ⊢ (%→?); #Houtc cases (Houtc … Hth) -Houtc
150 [ * normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
151 * #_ #Houtc lapply (Houtc [] ?? (refl ??) (refl ??) Hl1marks) -Houtc
152 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) % % [%] @Houtc
153 | -l1 #c1 #l1 #_ #Hl1marks >reverse_append >reverse_single
154 #Hth whd in ⊢ (%→?); #Houtc cases (Houtc … Hth) -Houtc
155 [ * >Hl1marks [ #Hfalse destruct (Hfalse) ] @memb_append_l2 @memb_hd ]
156 * #_ #Houtc lapply (Houtc (reverse ? l1@[〈x,false〉]) 〈a,true〉 l3 ? (refl ??) ?) -Houtc
157 [ #x1 #Hx1 cases (memb_append … Hx1) -Hx1 #Hx1 [ @Hl1marks @memb_append_l1 @daemon | >(memb_single … Hx1) % ]
158 | normalize >associative_append % ]
159 #Houtc lapply (\P Hx) -Hx #Hx destruct (Hx) % % [%] >Houtc
160 >reverse_append >reverse_reverse >associative_append >associative_append % ]
161 | * #ta * whd in ⊢ (%→?); >Hintape #Hta cases (Hta ? (refl ??)) -Hta
162 #Hxc #Hta >Hta whd in ⊢ (%→?); #Houtc %2 %
163 [ lapply (\Pf Hxc) @not_to_not #Heq >Heq %
167 definition copy_step ≝
168 ifTM ? (test_char STape (λc.bit_or_null (\fst c)))
169 (single_finalTM ? (copy_step_subcase FSUnialpha (bit false)
170 (copy_step_subcase FSUnialpha (bit true) nocopy_subcase)))
174 definition R_copy_step_true ≝
176 ∀ls,c,rs. t1 = midtape STape ls 〈c,true〉 rs →
177 bit_or_null c = true ∧
179 ls = (l1@〈a0,false〉::〈x0,true〉::l2) →
180 rs = (〈a,false〉::l3) →
183 t2 = midtape STape (〈bit x,false〉::l1@〈a0,true〉::〈bit x,false〉::l2) 〈a,true〉 l3) ∨
185 t2 = midtape ? (〈null,false〉::l1@〈a0,true〉::〈x0,false〉::l2) 〈a,true〉 l3))).
187 definition R_copy_step_false ≝
189 ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs →
190 bit_or_null (\fst c) = false ∧ t2 = t1.
192 lemma sem_copy_step :
193 accRealize ? copy_step (inr … (inl … (inr … start_nop))) R_copy_step_true R_copy_step_false.
195 @(acc_sem_if_app … (sem_test_char ? (λc:STape.bit_or_null (\fst c))) …
196 (sem_copy_step_subcase FSUnialpha (bit false) …
197 (sem_copy_step_subcase FSUnialpha (bit true) … (sem_nocopy_subcase …)))
199 [ #t1 #t2 #t3 whd in ⊢ (%→%→?); #H1 #H2 #ls #c #rs #Ht1 >Ht1 in H1; #H1
200 cases (H1 … (refl ??)) #Hc #Ht3 % [ @Hc ]
201 #a #l1 #x0 #a0 #l2 #l3 #Hls #Hrs #Hl1marks >Hls in Ht3; >Hrs #Ht3
203 [ * #Hc' #Ht2 % %{false} % // <Hc' @Ht2
204 | * #Hnotfalse whd in ⊢ (%→?); #Ht2 cases (Ht2 … Ht3 ?) -Ht2
205 [ * #Hc' #Ht2 % %{true} % // <Hc' @Ht2
206 | * #Hnottrue whd in ⊢ (%→?); #Ht2 cases (Ht2 … Ht3 ?) -Ht2
207 [ * #Hc' #Ht2 %2 <Hc' % // @Ht2
208 | * #Hnotnull @False_ind
209 generalize in match Hnotnull;generalize in match Hnottrue;generalize in match Hnotfalse;
210 cases c in Hc; normalize
211 [ * [ #_ #_ * #Hfalse #_ | #_ * #Hfalse #_ #_ ]
213 |*: #Hfalse destruct (Hfalse) ] @Hfalse %
217 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #H1 #H2 #ls #c #rs #Ht1
218 >Ht1 in H1; #H1 cases (H1 … (refl ??)) #_ #Ht3 cases (H1 ? (refl ??)) -H1
224 1) il primo carattere è marcato
225 2) l'ultimo carattere è l'unico che può essere null, gli altri sono bit
226 3) il terminatore non è né bit, né null
229 definition copy0 ≝ whileTM ? copy_step (inr … (inl … (inr … start_nop))).
231 let rec merge_config (l1,l2:list STape) ≝
234 | cons p1 l1' ⇒ match l2 with
237 let 〈c1,b1〉 ≝ p1 in let 〈c2,b2〉 ≝ p2 in
240 | _ ⇒ p2 ] :: merge_config l1' l2' ] ].
242 lemma merge_config_append :
243 ∀l1,l2,l3,l4.|l1| = |l2| →
244 merge_config (l1@l3) (l2@l4) = merge_config l1 l2@merge_config l3 l4.
245 #l1 #l2 #l3 #l4 #Hlen @(list_ind2 … Hlen)
247 | #t1 #t2 * #c1 #b1 * #c2 #b2 #IH whd in ⊢ (??%%); >IH % ]
250 definition R_copy0 ≝ λt1,t2.
251 ∀ls,c,c0,rs,l1,l3,l4.
252 t1 = midtape STape (l3@l4@〈c0,true〉::ls) 〈c,true〉 (l1@rs) →
253 no_marks l1 → no_marks (l3@l4) → |l1| = |l4| →
254 ∀l1',bv.〈c,false〉::l1 = l1'@[〈comma,bv〉] → only_bits_or_nulls l1' →
255 ∀l4',bg.l4@[〈c0,false〉] = 〈grid,bg〉::l4' → only_bits_or_nulls l4' →
256 (c = comma ∧ t2 = t1) ∨
258 t2 = midtape ? (reverse ? l1'@l3@〈grid,true〉::
259 merge_config l4' (reverse ? l1')@ls)
262 lemma inj_append_singleton_l1 :
263 ∀A.∀l1,l2:list A.∀a1,a2.l1@[a1] = l2@[a2] → l1 = l2.
264 #A #l1 #l2 #a1 #a2 #H lapply (eq_f … (reverse ?) … H)
265 >reverse_append >reverse_append normalize #H1 destruct
266 lapply (eq_f … (reverse ?) … e0) >reverse_reverse >reverse_reverse //
269 lemma inj_append_singleton_l2 :
270 ∀A.∀l1,l2:list A.∀a1,a2.l1@[a1] = l2@[a2] → a1 = a2.
271 #A #l1 #l2 #a1 #a2 #H lapply (eq_f … (reverse ?) … H)
272 >reverse_append >reverse_append normalize #H1 destruct %
275 lemma wsem_copy0 : WRealize ? copy0 R_copy0.
276 #intape #k #outc #Hloop
277 lapply (sem_while … sem_copy_step intape k outc Hloop) [%] -Hloop
278 * #ta * #Hstar @(star_ind_l ??????? Hstar)
279 [ #tb whd in ⊢ (%→?); #Hleft
280 #ls #c #c0 #rs #l1 #l3 #l4 #Htb #Hl1nomarks #Hl3l4nomarks #Hlen #l1' #bv
281 #Hl1 #Hl1bits #l4' #bg #Hl4 #Hl4bits
282 cases (Hleft … Htb) -Hleft #Hc #Houtc % %
283 [ generalize in match Hl1bits; -Hl1bits cases l1' in Hl1;
284 [ normalize #Hl1 #c1 destruct (Hl1) %
285 | * #c' #b' #l0 #Heq normalize in Heq; destruct (Heq)
286 #Hl1bits lapply (Hl1bits 〈c',false〉 ?) [ @memb_hd ]
287 >Hc #Hfalse destruct ]
289 | #tb #tc #td whd in ⊢ (%→?→(?→%)→%→?); #Htc #Hstar1 #Hind #Htd
290 lapply (Hind Htd) -Hind #Hind
291 #ls #c #c0 #rs #l1 #l3 #l4 #Htb #Hl1nomarks #Hl3l4nomarks #Hlen #l1' #bv
292 #Hl1 #Hl1bits #l4' #bg #Hl4 #Hl4bits %2
293 cases (Htc … Htb) -Htc #Hcbitnull #Htc
294 % [ % #Hc' >Hc' in Hcbitnull; normalize #Hfalse destruct (Hfalse) ]
295 cut (|l1| = |reverse ? l4|) [@daemon] #Hlen1
296 @(list_cases2 … Hlen1)
297 [ (* case l1 = [] is discriminated because l1 contains at least comma *)
298 #Hl1nil @False_ind >Hl1nil in Hl1; cases l1' normalize
299 [ #Hl1 destruct normalize in Hcbitnull; destruct (Hcbitnull)
300 | #p0 #l0 normalize #Hfalse destruct (Hfalse) cases l0 in e0;
301 [ normalize #Hfalse1 destruct (Hfalse1)
302 | #p0' #l0' normalize #Hfalse1 destruct (Hfalse1) ] ]
303 | (* case c::l1 = c::a::l1'' *)
304 * #a #ba * #a0 #ba0 #l1'' #l4'' #Hl1cons #Hl4cons
305 lapply (eq_f ?? (reverse ?) ?? Hl4cons) >reverse_reverse >reverse_cons -Hl4cons #Hl4cons
307 [ >Hl1cons in Hl1nomarks; #Hl1nomarks lapply (Hl1nomarks 〈a,ba〉 ?)
308 [ @memb_hd | normalize // ] ] #Hba
310 [ >Hl4cons in Hl3l4nomarks; #Hl3l4nomarks lapply (Hl3l4nomarks 〈a0,ba0〉 ?)
311 [ @memb_append_l2 @memb_append_l2 @memb_hd | normalize // ] ] #Hba0
312 >Hba0 in Hl4cons; >Hba in Hl1cons; -Hba0 -Hba #Hl1cons #Hl4cons
313 >Hl4cons in Htc; >Hl1cons #Htc
314 lapply (Htc a (l3@reverse ? l4'') c0 a0 ls (l1''@rs) ? (refl ??) ?)
315 [ #x #Hx @Hl3l4nomarks >Hl4cons <associative_append
317 | >associative_append >associative_append %
319 cut (∃la.l1' = 〈c,false〉::la)
320 [ >Hl1cons in Hl1; cases l1'
321 [normalize #Hfalse destruct (Hfalse)
322 | #p #la normalize #Hla destruct (Hla) @(ex_intro ?? la) % ] ]
324 cut (∃lb.l4' = lb@[〈c0,false〉])
326 @(list_elim_left … l4')
327 [ #Heq lapply (eq_f … (length ?) … Heq)
328 >length_append >length_append
329 >commutative_plus normalize >commutative_plus normalize
332 >(inj_append_singleton_l2 ? (reverse ? l4''@[〈a0,false〉]) (〈grid,bg〉::tl) 〈c0,false〉 a1 Heq)
335 cut (|lb| = |reverse ? la|)
336 [ >Hla in Hl1; >Hlb in Hl4; #Hl4 #Hl1
337 >(?:l1 = la@[〈comma,bv〉]) in Hlen;
338 [|normalize in Hl1; destruct (Hl1) %]
339 >(?:l4 = 〈grid,bg〉::lb)
340 [|@(inj_append_singleton_l1 ?? (〈grid,bg〉::lb) ?? Hl4) ]
341 >length_append >commutative_plus >length_reverse
342 normalize #Hlalb destruct (Hlalb) //
345 (* by hyp on the first iteration step,
346 we consider whether c = bit x or c = null *)
349 lapply (Hind (〈bit x,false〉::ls) a a0 rs l1''
350 (〈bit x,false〉::l3) (reverse ? l4'') ????)
351 [ >Hl1cons in Hlen; >Hl4cons >length_append >commutative_plus
352 normalize #Hlen destruct (Hlen) //
353 | #x0 #Hx0 cases (orb_true_l … Hx0)
354 [ #Hx0eq >(\P Hx0eq) %
355 | -Hx0 #Hx0 @Hl3l4nomarks >Hl4cons
356 <associative_append @memb_append_l1 // ]
357 | #x0 #Hx0 @Hl1nomarks >Hl1cons @memb_cons //
358 | >Htc >associative_append %
360 <Hl1cons <Hl4cons #Hind lapply (Hind la bv ?? lb bg ??)
361 [ #x0 #Hx0 @Hl4bits >Hlb @memb_append_l1 //
362 | >Hlb in Hl4; normalize in ⊢ (%→?); #Hl4
363 @(inj_append_singleton_l1 ? l4 (〈grid,bg〉::lb) … Hl4)
364 | #x0 #Hx0 @Hl1bits >Hla @memb_cons //
365 | >Hla in Hl1; normalize in ⊢ (%→?); #Hl1
366 destruct (Hl1) // ] -Hind
367 (* by IH, we proceed by cases, whether a = comma
368 (consequently several lists = []) or not *)
371 cut (la = [] ∧ lb = [] ∧ l1'' = [] ∧ l4'' = [])
372 [ @daemon ] * * * #Hla1 #Hlb1 #Hl1nil #Hl4nil
373 >Hl1cons in Hl1; >Hla
375 >Hl4cons in Hl4; >Hlb #Hl4
376 >Hla1 >Hlb1 >Hl1nil >Hl4nil >Hx
377 cut (a0 = grid) [ @daemon ] #Ha0 <Ha <Ha0
378 normalize in ⊢ (??(??%?%)(??%?%)); >associative_append %
379 | * #Ha #Houtc1 >Houtc1 @eq_f3 //
380 >Hla >reverse_cons >associative_append @eq_f
381 >Hx whd in ⊢ (??%?); @eq_f whd in ⊢ (???%); @eq_f @eq_f
382 >Hlb >append_cons @eq_f2 // >(merge_config_append … Hlen2) %
387 lapply (Hind (〈c0,false〉::ls) a a0 rs l1'' (〈null,false〉::l3) (reverse ? l4'') ????)
388 [ >Hl1cons in Hlen; >Hl4cons >length_append >commutative_plus normalize
389 #Hlen destruct (Hlen) @e0
390 | #x0 #Hx0 cases (memb_append STape ? [〈null,false〉] (l3@reverse ? l4'') … Hx0) -Hx0 #Hx0
391 [ >(memb_single … Hx0) %
392 | @Hl3l4nomarks cases (memb_append … Hx0) -Hx0 #Hx0
394 | @memb_append_l2 >Hl4cons @memb_append_l1 // ]
396 | >Hl1cons #x' #Hx0 @Hl1nomarks >Hl1cons @memb_cons //
397 | >Htc @eq_f3 // >associative_append % ] -Hind <Hl1cons <Hl4cons #Hind
398 lapply (Hind la bv ?? lb bg ??)
399 [ #x0 #Hx0 @Hl4bits >Hlb @memb_append_l1 //
400 | >Hlb in Hl4; normalize in ⊢ (%→?); #Hl4
401 @(inj_append_singleton_l1 ? l4 (〈grid,bg〉::lb) … Hl4)
402 | #x0 #Hx0 @Hl1bits >Hla @memb_cons //
403 | >Hla in Hl1; normalize in ⊢ (%→?); #Hl1
404 destruct (Hl1) // ] -Hind *
405 (* by IH, we proceed by cases, whether a = comma
406 (consequently several lists = []) or not *)
407 [ * #Ha #Houtc1 >Hl1cons in Hl1; >Hla
409 >Hl4cons in Hl4; >Hlb #Hl4
410 cut (la = [] ∧ lb = [] ∧ l1'' = [] ∧ l4'' = [])
411 [@daemon] * * * #Hla1 #Hlb1 #Hl1nil #Hl4nil
412 >Hla1 >Hlb1 >Hl1nil >Hl4nil >Hc
413 cut (a0 = grid) [ @daemon ] #Ha0 <Ha <Ha0
414 normalize in ⊢ (??(??%?%)(??%?%)); >associative_append %
415 | * #Ha #Houtc1 >Houtc1 @eq_f3 //
416 >Hla >reverse_cons >associative_append @eq_f
417 >Hc whd in ⊢ (??%?); @eq_f whd in ⊢ (???%); @eq_f @eq_f
418 >Hlb >append_cons @eq_f2 // >(merge_config_append … Hlen2) %
424 definition merge_char ≝ λc1,c2.
431 merge_config (〈c1,false〉::conf1) (〈c2,false〉::conf2) =
432 〈merge_char c1 c2,false〉::merge_config conf1 conf2.
433 #c1 #c2 #conf1 #conf2 normalize @eq_f2 //
437 lemma merge_bits : ∀l1,l2.|l1| = |l2| → only_bits l2 → merge_config l1 l2 = l2.
438 #l1 #l2 #Hlen @(list_ind2 … Hlen) //
439 #tl1 #tl2 #hd1 #hd2 #IH
440 >(eq_pair_fst_snd … hd1) >(eq_pair_fst_snd … hd2) #Hbits
441 change with (cons ???) in ⊢ (??%?); @eq_f2
442 [ cases (\fst hd2) in Hbits;
444 |*: #Hfalse lapply (Hfalse … (memb_hd …)) normalize #Hfalse1 destruct (Hfalse1) ]
445 | @IH #x #Hx @Hbits @memb_cons // ]
448 lemma merge_config_c_nil :
449 ∀c.merge_config c [] = [].
450 #c cases c normalize //
453 lemma reverse_merge_config :
454 ∀c1,c2.|c1| = |c2| → reverse ? (merge_config c1 c2) =
455 merge_config (reverse ? c1) (reverse ? c2).
456 #c1 #c2 <(length_reverse ? c1) <(length_reverse ? c2) #Hlen
457 <(reverse_reverse ? c1) in ⊢ (??%?); <(reverse_reverse ? c2) in ⊢ (??%?);
458 generalize in match Hlen; @(list_ind2 … Hlen) -Hlen //
459 #tl1 #tl2 #hd1 #hd2 #IH whd in ⊢ (??%%→?); #Hlen destruct (Hlen) -Hlen
460 <(length_reverse ? tl1) in e0; <(length_reverse ? tl2) #Hlen
461 >reverse_cons >reverse_cons >(merge_config_append ???? Hlen)
462 >reverse_append >(eq_pair_fst_snd ?? hd1) >(eq_pair_fst_snd ?? hd2)
463 whd in ⊢ (??%%); @eq_f2 // @IH //
468 seq STape copy0 (seq ? (move_l …) (seq ? (adv_to_mark_l … (is_marked ?))
469 (seq ? (clear_mark …) (seq ? (adv_to_mark_r … (is_marked ?)) (clear_mark …))))).
472 s0, s1 = caratteri di testa dello stato
473 c0 = carattere corrente del nastro oggetto
474 c1 = carattere in scrittura sul nastro oggetto
476 questa dimostrazione sfrutta il fatto che
477 merge_config (l0@[c0]) (l1@[c1]) = l1@[merge_char c0 c1]
478 se l0 e l1 non contengono null
481 definition R_copy ≝ λt1,t2.
482 ∀ls,s0,s1,c0,c1,rs,l1,l3,l4.
483 t1 = midtape STape (l3@〈grid,false〉::〈c0,false〉::l4@〈s0,true〉::ls) 〈s1,true〉 (l1@〈c1,false〉::〈comma,false〉::rs) →
484 no_marks l1 → no_marks l3 → no_marks l4 → |l1| = |l4| →
485 only_bits (l4@[〈s0,false〉]) → only_bits (〈s1,false〉::l1) →
486 bit_or_null c0 = true → bit_or_null c1 = true →
487 t2 = midtape STape (〈c1,false〉::reverse ? l1@〈s1,false〉::l3@〈grid,false〉::
488 〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)
491 axiom sem_copy0 : Realize ? copy0 R_copy0.
493 definition option_cons ≝ λA.λa:option A.λl.
498 lemma sem_copy : Realize ? copy R_copy.
500 cases (sem_seq … (sem_copy0 …)
501 (sem_seq … (sem_move_l …)
502 (sem_seq … (sem_adv_to_mark_l … (is_marked ?))
503 (sem_seq … (sem_clear_mark …)
504 (sem_seq … (sem_adv_to_mark_r … (is_marked ?)) (sem_clear_mark …))))) intape)
505 #k * #outc * #Hloop #HR %{k} %{outc} % [@Hloop] -Hloop
506 #ls #s0 #s1 #c0 #c1 #rs #l1 #l2 #l3 #Hintape #Hl1marks #Hl2marks #Hl3marks #Hlen
507 #Hbits1 #Hbits2 #Hc0bits #Hc1bits
508 cases HR -HR #ta * whd in ⊢ (%→?); #Hta
509 cut (ta = midtape STape (〈c1,false〉::reverse ? l1@〈s1,false〉::l2@〈grid,true〉::
510 〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)
512 [lapply (Hta ls s1 s0 rs (l1@[〈c1,false〉;〈comma,false〉]) l2 (〈grid,false〉::〈c0,false〉::l3) ?)
513 [>associative_append in ⊢ (???(????%)); normalize in ⊢ (???(??%%%)); @Hintape ]
514 -Hta #Hta cases (Hta ??? (〈s1,false〉::l1@[〈c1,false〉]) false ? ? ?? (refl ??) ?)
515 [3: #x #Hx cases (memb_append … Hx) -Hx #Hx
517 | cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) % | >(memb_single … Hx) % ]]
518 |4: #x #Hx cases (memb_append … Hx) -Hx #Hx
520 | cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) % | cases (orb_true_l … Hx) [-Hx #Hx >(\P Hx) % | @Hl3marks ] ] ]
521 |5: >length_append normalize >Hlen >commutative_plus %
522 |6: normalize >associative_append %
523 |7: #x #Hx cases (memb_append ?? (〈s1,false〉::l1) … Hx) -Hx #Hx
524 [ whd in ⊢ (??%?); >(Hbits2 … Hx) %
525 | >(memb_single … Hx) // ]
526 |8: #x #Hx cases (memb_append … Hx) -Hx #Hx
527 [ cases (orb_true_l … Hx) -Hx #Hx [ >(\P Hx) // | whd in ⊢ (??%?); >Hbits1 // @memb_append_l1 // ]
528 | >(memb_single … Hx) whd in ⊢ (??%?); >(Hbits1 〈s0,false〉) // @memb_append_l2 @memb_hd ]
529 | * #Hs1 @False_ind >Hs1 in Hbits2; #Hbits2 lapply (Hbits2 〈comma,false〉 ?) //
530 normalize #Hfalse destruct (Hfalse)
531 | * #Hs1 #Ht2 >Ht2 >reverse_cons >reverse_append >reverse_single @eq_f3 //
532 >merge_cons >merge_bits
533 [2: #x #Hx @Hbits2 cases (memb_append STape ? (reverse ? l1) ? Hx) -Hx #Hx
534 [@daemon | >(memb_single … Hx) @memb_hd ]
535 |3: >length_append >length_append >length_reverse >Hlen % ]
536 normalize >associative_append normalize >associative_append %
538 ] -Hta #Hta * #tb * whd in ⊢ (%→?); #Htb
539 lapply (Htb … Hta) -Htb #Htb change with (midtape ????) in Htb:(???%);
540 * #tc * whd in ⊢ (%→?); #Htc
542 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
544 lapply (Htc (reverse ? l1@〈s1,false〉::l2) 〈grid,true〉
545 (〈merge_char c0 c1,false〉::reverse ? l1@〈s1,false〉::ls)???)
546 [ #x #Hx cases (memb_append … Hx) -Hx #Hx
548 | cases (orb_true_l … Hx) -Hx #Hx
549 [ >(\P Hx) % | @(Hl2marks … Hx) ] ]
551 | whd in ⊢ (??%?); >associative_append % ] -Htc #Htc
552 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htd #Htd
553 * #te * whd in ⊢ (%→?); #Hte cases (Hte … Htd) -Hte -Htd
554 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
556 lapply (Hte (reverse ? (reverse ? l1@〈s1,false〉::l2)@[〈c1,false〉])
557 〈comma,true〉 rs ? (refl ??) ?) -Hte
558 [ >reverse_append >reverse_cons >reverse_reverse #x #Hx
559 cases (memb_append … Hx) -Hx #Hx
560 [ cases (memb_append … Hx) -Hx #Hx
561 [ cases (memb_append … Hx) -Hx #Hx
563 | lapply (memb_single … Hx) -Hx #Hx >Hx % ]
565 | lapply (memb_single … Hx) -Hx #Hx >Hx % ]
566 | >reverse_append >reverse_reverse >reverse_cons
567 >associative_append >associative_append >associative_append
568 >associative_append >associative_append % ]
569 #Hte whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc #Houtc >Houtc
571 >reverse_append >reverse_append >reverse_single >reverse_cons
572 >reverse_append >reverse_append >reverse_reverse >reverse_reverse
573 >reverse_single >associative_append >associative_append %