]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/multi_universal/match.ma
match
[helm.git] / matita / matita / lib / turing / multi_universal / match.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "turing/multi_universal/moves.ma".
16 include "turing/if_multi.ma".
17 include "turing/inject.ma".
18 include "turing/basic_machines.ma".
19
20 definition compare_states ≝ initN 3.
21
22 definition comp0 : compare_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
23 definition comp1 : compare_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
24 definition comp2 : compare_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
25
26 (*
27
28 0) (x,x) → (x,x)(R,R) → 1
29    (x,y≠x) → None 2
30 1) (_,_) → None 1
31 2) (_,_) → None 2
32
33 *)
34
35 definition trans_compare_step ≝ 
36  λi,j.λsig:FinSet.λn.
37  λp:compare_states × (Vector (option sig) (S n)).
38  let 〈q,a〉 ≝ p in
39  match pi1 … q with
40  [ O ⇒ match nth i ? a (None ?) with
41    [ None ⇒ 〈comp2,null_action ? n〉
42    | Some ai ⇒ match nth j ? a (None ?) with 
43      [ None ⇒ 〈comp2,null_action ? n〉
44      | Some aj ⇒ if ai == aj 
45          then 〈comp1,change_vec ? (S n) 
46                       (change_vec ? (S n) (null_action ? n) (Some ? 〈ai,R〉) i)
47                         (Some ? 〈aj,R〉) j〉
48          else 〈comp2,null_action ? n〉 ]
49    ]
50  | S q ⇒ match q with 
51    [ O ⇒ (* 1 *) 〈comp1,null_action ? n〉
52    | S _ ⇒ (* 2 *) 〈comp2,null_action ? n〉 ] ].
53
54 definition compare_step ≝ 
55   λi,j,sig,n.
56   mk_mTM sig n compare_states (trans_compare_step i j sig n) 
57     comp0 (λq.q == comp1 ∨ q == comp2).
58
59 definition R_comp_step_true ≝ 
60   λi,j,sig,n.λint,outt: Vector (tape sig) (S n).
61   ∃x.
62    current ? (nth i ? int (niltape ?)) = Some ? x ∧
63    current ? (nth j ? int (niltape ?)) = Some ? x ∧
64    outt = change_vec ?? 
65             (change_vec ?? int
66               (tape_move ? (nth i ? int (niltape ?)) (Some ? 〈x,R〉)) i)
67             (tape_move ? (nth j ? int (niltape ?)) (Some ? 〈x,R〉)) j.
68
69 definition R_comp_step_false ≝ 
70   λi,j:nat.λsig,n.λint,outt: Vector (tape sig) (S n).
71   (current ? (nth i ? int (niltape ?)) ≠ current ? (nth j ? int (niltape ?)) ∨
72    current ? (nth i ? int (niltape ?)) = None ? ∨
73    current ? (nth j ? int (niltape ?)) = None ?) ∧ outt = int.
74
75 lemma comp_q0_q2_null :
76   ∀i,j,sig,n,v.i < S n → j < S n → 
77   (nth i ? (current_chars ?? v) (None ?) = None ? ∨
78    nth j ? (current_chars ?? v) (None ?) = None ?) → 
79   step sig n (compare_step i j sig n) (mk_mconfig ??? comp0 v) 
80   = mk_mconfig ??? comp2 v.
81 #i #j #sig #n #v #Hi #Hj
82 whd in ⊢ (? → ??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (?→??%?);
83 * #Hcurrent
84 [ @eq_f2
85   [ whd in ⊢ (??(???%)?); >Hcurrent %
86   | whd in ⊢ (??(???????(???%))?); >Hcurrent @tape_move_null_action ]
87 | @eq_f2
88   [ whd in ⊢ (??(???%)?); >Hcurrent cases (nth i ?? (None sig)) //
89   | whd in ⊢ (??(???????(???%))?); >Hcurrent
90     cases (nth i ?? (None sig)) [|#x] @tape_move_null_action ] ]
91 qed.
92
93 lemma comp_q0_q2_neq :
94   ∀i,j,sig,n,v.i < S n → j < S n → 
95   nth i ? (current_chars ?? v) (None ?) ≠ nth j ? (current_chars ?? v) (None ?) → 
96   step sig n (compare_step i j sig n) (mk_mconfig ??? comp0 v) 
97   = mk_mconfig ??? comp2 v.
98 #i #j #sig #n #v #Hi #Hj lapply (refl ? (nth i ?(current_chars ?? v)(None ?)))
99 cases (nth i ?? (None ?)) in ⊢ (???%→?);
100 [ #Hnth #_ @comp_q0_q2_null // % //
101 | #ai #Hai lapply (refl ? (nth j ?(current_chars ?? v)(None ?)))
102   cases (nth j ?? (None ?)) in ⊢ (???%→?);
103   [ #Hnth #_ @comp_q0_q2_null // %2 //
104   | #aj #Haj #Hneq
105     whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
106     [ whd in match (trans ????); >Hai >Haj
107       whd in ⊢ (??(???%)?); >(\bf ?) // @(not_to_not … Hneq) //
108     | whd in match (trans ????); >Hai >Haj
109       whd in ⊢ (??(???????(???%))?); >(\bf ?) /2 by not_to_not/
110       @tape_move_null_action
111 ] ]
112 qed.
113
114 lemma comp_q0_q1 :
115   ∀i,j,sig,n,v,a.i ≠ j → i < S n → j < S n → 
116   nth i ? (current_chars ?? v) (None ?) = Some ? a →
117   nth j ? (current_chars ?? v) (None ?) = Some ? a → 
118   step sig n (compare_step i j sig n) (mk_mconfig ??? comp0 v) =
119     mk_mconfig ??? comp1 
120      (change_vec ? (S n) 
121        (change_vec ?? v
122          (tape_move ? (nth i ? v (niltape ?)) (Some ? 〈a,R〉)) i)
123        (tape_move ? (nth j ? v (niltape ?)) (Some ? 〈a,R〉)) j).
124 #i #j #sig #n #v #a #Heq #Hi #Hj #Ha1 #Ha2
125 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
126 [ whd in match (trans ????);
127   >Ha1 >Ha2 whd in ⊢ (??(???%)?); >(\b ?) //
128 | whd in match (trans ????);
129   >Ha1 >Ha2 whd in ⊢ (??(???????(???%))?); >(\b ?) //
130   change with (change_vec ?????) in ⊢ (??(???????%)?);
131   <(change_vec_same … v j (niltape ?)) in ⊢ (??%?);
132   <(change_vec_same … v i (niltape ?)) in ⊢ (??%?);
133   >pmap_change >pmap_change >tape_move_null_action
134   @eq_f2 // @eq_f2 // >nth_change_vec_neq //
135 ]
136 qed.
137
138 lemma sem_comp_step :
139   ∀i,j,sig,n.i ≠ j → i < S n → j < S n → 
140   compare_step i j sig n ⊨ 
141     [ comp1: R_comp_step_true i j sig n, 
142              R_comp_step_false i j sig n ].
143 #i #j #sig #n #Hneq #Hi #Hj #int
144 lapply (refl ? (current ? (nth i ? int (niltape ?))))
145 cases (current ? (nth i ? int (niltape ?))) in ⊢ (???%→?);
146 [ #Hcuri %{2} %
147   [| % [ %
148     [ whd in ⊢ (??%?); >comp_q0_q2_null /2/ % <Hcuri in ⊢ (???%); 
149       @sym_eq @nth_vec_map
150     | normalize in ⊢ (%→?); #H destruct (H) ]
151   | #_ % // % %2 // ] ]
152 | #a #Ha lapply (refl ? (current ? (nth j ? int (niltape ?))))
153   cases (current ? (nth j ? int (niltape ?))) in ⊢ (???%→?);
154   [ #Hcurj %{2} %
155     [| % [ %
156        [ whd in ⊢ (??%?); >comp_q0_q2_null /2/ %2 <Hcurj in ⊢ (???%); 
157          @sym_eq @nth_vec_map
158        | normalize in ⊢ (%→?); #H destruct (H) ]
159        | #_ % >Ha >Hcurj % % % #H destruct (H) ] ]
160   | #b #Hb %{2} cases (true_or_false (a == b)) #Hab
161     [ %
162       [| % [ % 
163         [whd in ⊢  (??%?);  >(comp_q0_q1 … a Hneq Hi Hj) //
164           [>(\P Hab) <Hb @sym_eq @nth_vec_map
165           |<Ha @sym_eq @nth_vec_map ]
166         | #_ whd >(\P Hab) %{b} % // % // <(\P Hab) // ]
167         | * #H @False_ind @H %
168       ] ]
169     | %
170       [| % [ % 
171         [whd in ⊢  (??%?);  >comp_q0_q2_neq //
172          <(nth_vec_map ?? (current …) i ? int (niltape ?))
173          <(nth_vec_map ?? (current …) j ? int (niltape ?)) >Ha >Hb
174          @(not_to_not ??? (\Pf Hab)) #H destruct (H) %
175         | normalize in ⊢ (%→?); #H destruct (H) ]
176       | #_ % // % % >Ha >Hb @(not_to_not ??? (\Pf Hab)) #H destruct (H) % ] ]
177     ]
178   ]
179 ]
180 qed.
181
182 definition compare ≝ λi,j,sig,n.
183   whileTM … (compare_step i j sig n) comp1.
184
185 definition R_compare ≝ 
186   λi,j,sig,n.λint,outt: Vector (tape sig) (S n).
187   ((current ? (nth i ? int (niltape ?)) 
188     ≠ current ? (nth j ? int (niltape ?)) ∨
189     current ? (nth i ? int (niltape ?)) = None ? ∨
190     current ? (nth j ? int (niltape ?)) = None ?) → outt = int) ∧
191   (∀ls,x,xs,ci,rs,ls0,cj,rs0. 
192     nth i ? int (niltape ?) = midtape sig ls x (xs@ci::rs) →
193     nth j ? int (niltape ?) = midtape sig ls0 x (xs@cj::rs0) → ci ≠ cj → 
194     outt = change_vec ?? 
195            (change_vec ?? int (midtape sig (reverse ? xs@x::ls) ci rs) i)
196            (midtape sig (reverse ? xs@x::ls0) cj rs0) j).
197           
198 lemma wsem_compare : ∀i,j,sig,n.i ≠ j → i < S n → j < S n → 
199   compare i j sig n ⊫ R_compare i j sig n.
200 #i #j #sig #n #Hneq #Hi #Hj #ta #k #outc #Hloop
201 lapply (sem_while … (sem_comp_step i j sig n Hneq Hi Hj) … Hloop) //
202 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
203 [ #tc whd in ⊢ (%→?); * * [ *
204   [ #Hcicj #Houtc % 
205     [ #_ @Houtc
206     | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi #Hnthj
207       >Hnthi in Hcicj; >Hnthj normalize in ⊢ (%→?); * #H @False_ind @H %
208     ]
209   | #Hci #Houtc %
210     [ #_ @Houtc
211     | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi >Hnthi in Hci;
212       normalize in ⊢ (%→?); #H destruct (H) ] ]
213   | #Hcj #Houtc %
214     [ #_ @Houtc
215     | #ls #x #xs #ci #rs #ls0 #cj #rs0 #_ #Hnthj >Hnthj in Hcj;
216       normalize in ⊢ (%→?); #H destruct (H) ] ]
217   | #tc #td #te * #x * * #Hci #Hcj #Hd #Hstar #IH #He lapply (IH He) -IH *
218     #IH1 #IH2 %
219     [ >Hci >Hcj * [* [* #H @False_ind @H % | #H destruct (H)] | #H destruct (H)] 
220     | #ls #c0 #xs #ci #rs #ls0 #cj #rs0 cases xs
221       [ #Hnthi #Hnthj #Hcicj >IH1 
222         [ >Hd @eq_f3 // 
223           [ @eq_f3 // >(?:c0=x) [ >Hnthi % ]
224             >Hnthi in Hci;normalize #H destruct (H) %
225           | >(?:c0=x) [ >Hnthj % ]
226             >Hnthi in Hci;normalize #H destruct (H) % ]
227         | >Hd >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
228           >nth_change_vec // >Hnthi >Hnthj normalize %1 %1 @(not_to_not ??? Hcicj)
229           #H destruct (H) % ]
230       | #x0 #xs0 #Hnthi #Hnthj #Hcicj
231         >(IH2 (c0::ls) x0 xs0 ci rs (c0::ls0) cj rs0 … Hcicj)
232         [ >Hd >change_vec_commute in ⊢ (??%?); //
233           >change_vec_change_vec >change_vec_commute in ⊢ (??%?); //
234           @sym_not_eq //
235         | >Hd >nth_change_vec // >Hnthj normalize
236           >Hnthi in Hci;normalize #H destruct (H) %
237         | >Hd >nth_change_vec_neq [|@sym_not_eq //] >Hnthi
238           >nth_change_vec // normalize
239           >Hnthi in Hci;normalize #H destruct (H) %
240         ]
241 ]]]
242 qed.      
243  
244 lemma terminate_compare :  ∀i,j,sig,n,t.
245   i ≠ j → i < S n → j < S n → 
246   compare i j sig n  ↓ t.
247 #i #j #sig #n #t #Hneq #Hi #Hj
248 @(terminate_while … (sem_comp_step …)) //
249 <(change_vec_same … t i (niltape ?))
250 cases (nth i (tape sig) t (niltape ?))
251 [ % #t1 * #x * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct 
252 |2,3: #a0 #al0 % #t1 * #x * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
253 | #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs
254   [#t #ls #c % #t1 * #x * * >nth_change_vec // normalize in ⊢ (%→?);
255    #H1 destruct (H1) #Hxsep >change_vec_change_vec #Ht1 % 
256    #t2 * #x0 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
257    >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
258   |#r0 #rs0 #IH #t #ls #c % #t1 * #x * * >nth_change_vec //
259    normalize in ⊢ (%→?); #H destruct (H) #Hcur
260    >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
261   ]
262 ]
263 qed.
264
265 lemma sem_compare : ∀i,j,sig,n.
266   i ≠ j → i < S n → j < S n → 
267   compare i j sig n ⊨ R_compare i j sig n.
268 #i #j #sig #n #Hneq #Hi #Hj @WRealize_to_Realize /2/
269 qed.
270
271 (*
272    |conf1   $
273    |confin 0/1 confout move
274
275   match machine step ≝
276     compare;
277     if (cur(src) != $)
278       then
279         parmoveL;
280         moveR(dst);
281       else nop
282  *)
283
284 definition match_step ≝ λsrc,dst,sig,n,is_startc,is_endc.
285   compare src dst sig n ·
286     (ifTM ?? (inject_TM ? (test_char ? (λa.is_endc a == false)) n src)
287       (single_finalTM ??
288         (parmove src dst sig n L is_startc · (inject_TM ? (move_r ?) n dst)))
289       (nop …)
290       tc_true).
291       
292 definition Rtc_multi_true ≝ 
293   λalpha,test,n,i.λt1,t2:Vector ? (S n).
294    (∃c. current alpha (nth i ? t1 (niltape ?)) = Some ? c ∧ test c = true) ∧ t2 = t1.
295    
296 definition Rtc_multi_false ≝ 
297   λalpha,test,n,i.λt1,t2:Vector ? (S n).
298     (∀c. current alpha (nth i ? t1 (niltape ?)) = Some ? c → test c = false) ∧ t2 = t1.
299    
300 definition R_match_step_false ≝  
301   λsrc,dst,sig,n,is_endc.λint,outt: Vector (tape sig) (S n).
302    ((current ? (nth src ? int (niltape ?)) ≠ current ? (nth dst ? int (niltape ?)) ∨   
303      current sig (nth src (tape sig) int (niltape sig)) = None ? ∨
304      current sig (nth dst (tape sig) int (niltape sig)) = None ? ) ∧ outt = int) ∨
305    ∃ls,ls0,rs,rs0,x,xs. ∀rsi,rsj,end,c. 
306     rs = end::rsi → rs0 = c::rsj →
307     is_endc end = true ∧
308     nth src ? int (niltape ?) = midtape sig ls x (xs@rs) ∧
309     nth dst ? int (niltape ?) = midtape sig ls0 x (xs@rs0) ∧
310     outt = change_vec ??
311            (change_vec ?? int (midtape sig (reverse ? xs@x::ls) end rsi) src)
312            (midtape sig (reverse ? xs@x::ls0) c rsj) dst.
313
314 definition R_match_step_true ≝ 
315   λsrc,dst,sig,n,is_startc,is_endc.λint,outt: Vector (tape sig) (S n).
316   ∀s.current sig (nth src (tape sig) int (niltape sig)) = Some ? s → 
317   is_startc s = true →
318   (∀s1.current sig (nth dst (tape sig) int (niltape sig)) = Some ? s1 →
319    s ≠ s1 →  
320    outt = change_vec ?? int 
321           (tape_move … (nth dst ? int (niltape ?)) (Some ? 〈s1,R〉)) dst ∧ is_endc s = false) ∧  
322   (∀ls,x,xs,ci,rs,ls0,cj,rs0. 
323     nth src ? int (niltape ?) = midtape sig ls x (xs@ci::rs) →
324     nth dst ? int (niltape ?) = midtape sig ls0 x (xs@cj::rs0) → ci ≠ cj → 
325     outt = change_vec ?? int 
326            (tape_move … (nth dst ? int (niltape ?)) (Some ? 〈x,R〉)) dst ∧ is_endc ci = false).
327     
328 lemma sem_test_char_multi :
329   ∀alpha,test,n,i.i ≤ n → 
330   inject_TM ? (test_char ? test) n i ⊨ 
331   [ tc_true : Rtc_multi_true alpha test n i, Rtc_multi_false alpha test n i ].
332 #alpha #test #n #i #Hin #int
333 cases (acc_sem_inject … Hin (sem_test_char alpha test) int)
334 #k * #outc * * #Hloop #Htrue #Hfalse %{k} %{outc} % [ %
335 [ @Hloop
336 | #Hqtrue lapply (Htrue Hqtrue) * * * #c *
337   #Hcur #Htestc #Hnth_i #Hnth_j %
338   [ %{c} % //
339   | @(eq_vec … (niltape ?)) #i0 #Hi0
340     cases (decidable_eq_nat i0 i) #Hi0i
341     [ >Hi0i @Hnth_i
342     | @sym_eq @Hnth_j @sym_not_eq // ] ] ]
343 | #Hqfalse lapply (Hfalse Hqfalse) * * #Htestc #Hnth_i #Hnth_j %
344   [ @Htestc
345   | @(eq_vec … (niltape ?)) #i0 #Hi0
346     cases (decidable_eq_nat i0 i) #Hi0i
347     [ >Hi0i @Hnth_i
348     | @sym_eq @Hnth_j @sym_not_eq // ] ] ]
349 qed.
350
351 axiom comp_list: ∀S:DeqSet. ∀l1,l2:list S. ∃l,tl1,tl2. 
352   l1 = l@tl1 ∧ l2 = l@tl2 ∧ ∀a,b,tla,tlb. tl1 = a::tla → tl2 = b::tlb → a≠b.
353   
354 axiom daemon : ∀X:Prop.X.
355   
356 lemma sem_match_step :
357   ∀src,dst,sig,n,is_startc,is_endc.src ≠ dst → src < S n → dst < S n → 
358   match_step src dst sig n is_startc is_endc ⊨ 
359     [ inr ?? (inr ?? (inl … (inr ?? start_nop))) : 
360       R_match_step_true src dst sig n is_startc is_endc, 
361       R_match_step_false src dst sig n is_endc ].
362 #src #dst #sig #n #is_startc #is_endc #Hneq #Hsrc #Hdst 
363 @(acc_sem_seq_app sig n … (sem_compare src dst sig n Hneq Hsrc Hdst)
364     (acc_sem_if ? n … (sem_test_char_multi sig (λa.is_endc a == false) n src (le_S_S_to_le … Hsrc))
365       (sem_seq … 
366         (sem_parmoveL ???? is_startc Hneq Hsrc Hdst) 
367         (sem_inject … dst (le_S_S_to_le … Hdst) (sem_move_r ? )))
368       (sem_nop …)))
369 [#ta #tb #tc * #Hcomp1 #Hcomp2 * #td * * * #c * #Hcurtc #Hcend #Htd >Htd -Htd
370  #Htb #s #Hcurta_src #Hstart %
371  [ #s1 #Hcurta_dst #Hneqss1
372    lapply Htb lapply Hcurtc -Htb -Hcurtc >(?:tc=ta) 
373    [|@Hcomp1 % % >Hcurta_src >Hcurta_dst @(not_to_not … Hneqss1) #H destruct (H) % ]
374    #Hcurtc * #te * * #_ #Hte >Hte // whd in ⊢ (%→?); * * #_ #Htbdst #Htbelse %
375    [ @(eq_vec … (niltape ?)) #i #Hi cases (decidable_eq_nat i dst) #Hidst
376      [ >Hidst >nth_change_vec // cases (current_to_midtape … Hcurta_dst)
377        #ls * #rs #Hta_mid >(Htbdst … Hta_mid) >Hta_mid cases rs //
378      | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @Htbelse @sym_not_eq // ]
379    | >Hcurtc in Hcurta_src; #H destruct (H) cases (is_endc s) in Hcend;
380      normalize #H destruct (H) // ]
381  |#ls #x #xs #ci #rs #ls0 #cj #rs0 #Htasrc_mid #Htadst_mid #Hcicj
382   lapply (Hcomp2 … Htasrc_mid Htadst_mid Hcicj) -Hcomp2 #Hcomp2
383   cases Htb #td * * #Htd #_ >Htasrc_mid in Hcurta_src; normalize in ⊢ (%→?);
384   #H destruct (H)
385   >(Htd ls ci (reverse ? xs) rs s ??? ls0 cj (reverse ? xs) s rs0 (refl ??)) //
386   [| >Hcomp2 >nth_change_vec //
387    | @daemon
388    | >Hcomp2 >nth_change_vec_neq [|@sym_not_eq // ] @nth_change_vec // ]
389   * * #_ #Htbdst #Htbelse %
390   [ @(eq_vec … (niltape ?)) #i #Hi cases (decidable_eq_nat i dst) #Hidst
391      [ >Hidst >nth_change_vec // >Htadst_mid >(Htbdst ls0 s (xs@cj::rs0))
392        [ cases xs //
393        | >nth_change_vec // ]
394      | >nth_change_vec_neq [|@sym_not_eq //]
395        <Htbelse [|@sym_not_eq // ]
396        >nth_change_vec_neq [|@sym_not_eq //]
397        STOP.
398        
399        >nth_change_vec in Htbdst; // #Htbdst >(Htbdst
400      … Htadst_mid) >Hta_mid cases rs //
401      | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @Htbelse @sym_not_eq // ]
402    | >Hcurtc in Hcurta_src; #H destruct (H) cases (is_endc s) in Hcend;
403      normalize #H destruct (H) // ]
404 |#intape #outtape #ta * #Hcomp1 #Hcomp2 * #tb * * #Hc #Htb 
405  whd in ⊢ (%→?); #Hout >Hout >Htb whd
406  lapply (current_to_midtape sig (nth src ? intape (niltape ?)))
407  cases (current … (nth src ? intape (niltape ?))) in Hcomp1; 
408   [#Hcomp1 #_ %1 % [%1 %2 // | @Hcomp1 %1 %2 %]
409   |#c_src lapply (current_to_midtape sig (nth dst ? intape (niltape ?)))
410    cases (current … (nth dst ? intape (niltape ?))) 
411     [#_ #Hcomp1 #_ %1 % [%2 % | @Hcomp1 %2 %]
412     |#c_dst cases (true_or_false (c_src == c_dst)) #Hceq
413       [#Hmid_dst cases (Hmid_dst c_dst (refl …)) -Hmid_dst
414        #ls_dst * #rs_dst #Hmid_dst #_ 
415        #Hmid_src cases (Hmid_src c_src (refl …)) -Hmid_src
416        #ls_src * #rs_src #Hmid_src %2 
417        cases (comp_list … rs_src rs_dst) #xs * #rsi * #rsj * * 
418        #Hrs_src #Hrs_dst #Hneq    
419        %{ls_src} %{ls_dst} %{rsi} %{rsj} %{c_src} %{xs} 
420        #rsi0 #rsj0 #end #c #Hend #Hc_dst
421        >Hrs_src in Hmid_src; >Hend #Hmid_src
422        >Hrs_dst in Hmid_dst; >Hc_dst <(\P Hceq) #Hmid_dst
423        lapply(Hcomp2 … Hmid_src Hmid_dst ?)
424         [@(Hneq … Hend Hc_dst)]
425        -Hcomp2 #Hcomp2 <Hcomp2
426         % // % [ % 
427           [>Hcomp2 in Hc; >nth_change_vec_neq [|@sym_not_eq //]
428            >nth_change_vec // #H lapply (H ? (refl …)) 
429            cases (is_endc end) normalize //
430           |@Hmid_src]
431           |@Hmid_dst]
432       |#_ #Hcomp1 #_ %1 % 
433         [% % @(not_to_not ??? (\Pf Hceq)) #H destruct (H) //
434         |@Hcomp1 %1 %1 @(not_to_not ??? (\Pf Hceq)) #H destruct (H) //
435         ]
436       ]
437     ]
438   ] 
439
440
441 2:#t1 #t2 #t3 whd in ⊢ (%→?); * #Hc #H #H1 whd #ls #c #rs #Ht1 %
442   [lapply(Hc c ?) [>Ht1 %] #Hgrid @injective_notb @Hgrid |>H1 @H]
443  
444
445
446