1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "turing/multi_universal/moves.ma".
16 include "turing/if_multi.ma".
17 include "turing/inject.ma".
18 include "turing/basic_machines.ma".
20 definition compare_states ≝ initN 3.
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 …)).
28 0) (x,x) → (x,x)(R,R) → 1
35 definition trans_compare_step ≝
36 λi,j.λsig:FinSet.λn.λis_endc.
37 λp:compare_states × (Vector (option sig) (S n)).
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 notb (is_endc ai) ∧ ai == aj
45 then 〈comp1,change_vec ? (S n)
46 (change_vec ? (S n) (null_action ? n) (Some ? 〈ai,R〉) i)
48 else 〈comp2,null_action ? n〉 ]
51 [ O ⇒ (* 1 *) 〈comp1,null_action ? n〉
52 | S _ ⇒ (* 2 *) 〈comp2,null_action ? n〉 ] ].
54 definition compare_step ≝
56 mk_mTM sig n compare_states (trans_compare_step i j sig n is_endc)
57 comp0 (λq.q == comp1 ∨ q == comp2).
59 definition R_comp_step_true ≝
60 λi,j,sig,n,is_endc.λint,outt: Vector (tape sig) (S n).
63 current ? (nth i ? int (niltape ?)) = Some ? x ∧
64 current ? (nth j ? int (niltape ?)) = Some ? x ∧
67 (tape_move ? (nth i ? int (niltape ?)) (Some ? 〈x,R〉)) i)
68 (tape_move ? (nth j ? int (niltape ?)) (Some ? 〈x,R〉)) j.
70 definition R_comp_step_false ≝
71 λi,j:nat.λsig,n,is_endc.λint,outt: Vector (tape sig) (S n).
72 ((∃x.current ? (nth i ? int (niltape ?)) = Some ? x ∧ is_endc x = true) ∨
73 current ? (nth i ? int (niltape ?)) ≠ current ? (nth j ? int (niltape ?)) ∨
74 current ? (nth i ? int (niltape ?)) = None ? ∨
75 current ? (nth j ? int (niltape ?)) = None ?) ∧ outt = int.
77 lemma comp_q0_q2_null :
78 ∀i,j,sig,n,is_endc,v.i < S n → j < S n →
79 (nth i ? (current_chars ?? v) (None ?) = None ? ∨
80 nth j ? (current_chars ?? v) (None ?) = None ?) →
81 step sig n (compare_step i j sig n is_endc) (mk_mconfig ??? comp0 v)
82 = mk_mconfig ??? comp2 v.
83 #i #j #sig #n #is_endc #v #Hi #Hj
84 whd in ⊢ (? → ??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (?→??%?);
87 [ whd in ⊢ (??(???%)?); >Hcurrent %
88 | whd in ⊢ (??(???????(???%))?); >Hcurrent @tape_move_null_action ]
90 [ whd in ⊢ (??(???%)?); >Hcurrent cases (nth i ?? (None sig)) //
91 | whd in ⊢ (??(???????(???%))?); >Hcurrent
92 cases (nth i ?? (None sig)) [|#x] @tape_move_null_action ] ]
95 lemma comp_q0_q2_neq :
96 ∀i,j,sig,n,is_endc,v.i < S n → j < S n →
97 ((∃x.nth i ? (current_chars ?? v) (None ?) = Some ? x ∧ is_endc x = true) ∨
98 nth i ? (current_chars ?? v) (None ?) ≠ nth j ? (current_chars ?? v) (None ?)) →
99 step sig n (compare_step i j sig n is_endc) (mk_mconfig ??? comp0 v)
100 = mk_mconfig ??? comp2 v.
101 #i #j #sig #n #is_endc #v #Hi #Hj lapply (refl ? (nth i ?(current_chars ?? v)(None ?)))
102 cases (nth i ?? (None ?)) in ⊢ (???%→?);
103 [ #Hnth #_ @comp_q0_q2_null // % //
104 | #ai #Hai lapply (refl ? (nth j ?(current_chars ?? v)(None ?)))
105 cases (nth j ?? (None ?)) in ⊢ (???%→?);
106 [ #Hnth #_ @comp_q0_q2_null // %2 //
108 [ * #c * >Hai #Heq #Hendc whd in ⊢ (??%?);
109 >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
110 [ whd in match (trans ????); >Hai >Haj destruct (Heq)
111 whd in ⊢ (??(???%)?); >Hendc //
112 | whd in match (trans ????); >Hai >Haj destruct (Heq)
113 whd in ⊢ (??(???????(???%))?); >Hendc @tape_move_null_action
116 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
117 [ whd in match (trans ????); >Hai >Haj
118 whd in ⊢ (??(???%)?); cut ((¬is_endc ai∧ai==aj)=false)
119 [>(\bf ?) /2 by not_to_not/ cases (is_endc ai) // |#Hcut >Hcut //]
120 | whd in match (trans ????); >Hai >Haj
121 whd in ⊢ (??(???????(???%))?); cut ((¬is_endc ai∧ai==aj)=false)
122 [>(\bf ?) /2 by not_to_not/ cases (is_endc ai) //
123 |#Hcut >Hcut @tape_move_null_action
132 ∀i,j,sig,n,is_endc,v,a.i ≠ j → i < S n → j < S n →
133 nth i ? (current_chars ?? v) (None ?) = Some ? a → is_endc a = false →
134 nth j ? (current_chars ?? v) (None ?) = Some ? a →
135 step sig n (compare_step i j sig n is_endc) (mk_mconfig ??? comp0 v) =
139 (tape_move ? (nth i ? v (niltape ?)) (Some ? 〈a,R〉)) i)
140 (tape_move ? (nth j ? v (niltape ?)) (Some ? 〈a,R〉)) j).
141 #i #j #sig #n #is_endc #v #a #Heq #Hi #Hj #Ha1 #Hnotendc #Ha2
142 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
143 [ whd in match (trans ????);
144 >Ha1 >Ha2 whd in ⊢ (??(???%)?); >Hnotendc >(\b ?) //
145 | whd in match (trans ????);
146 >Ha1 >Ha2 whd in ⊢ (??(???????(???%))?); >Hnotendc >(\b ?) //
147 change with (change_vec ?????) in ⊢ (??(???????%)?);
148 <(change_vec_same … v j (niltape ?)) in ⊢ (??%?);
149 <(change_vec_same … v i (niltape ?)) in ⊢ (??%?);
150 >pmap_change >pmap_change >tape_move_null_action
151 @eq_f2 // @eq_f2 // >nth_change_vec_neq //
155 lemma sem_comp_step :
156 ∀i,j,sig,n,is_endc.i ≠ j → i < S n → j < S n →
157 compare_step i j sig n is_endc ⊨
158 [ comp1: R_comp_step_true i j sig n is_endc,
159 R_comp_step_false i j sig n is_endc ].
160 #i #j #sig #n #is_endc #Hneq #Hi #Hj #int
161 lapply (refl ? (current ? (nth i ? int (niltape ?))))
162 cases (current ? (nth i ? int (niltape ?))) in ⊢ (???%→?);
165 [ whd in ⊢ (??%?); >comp_q0_q2_null /2/ % <Hcuri in ⊢ (???%);
167 | normalize in ⊢ (%→?); #H destruct (H) ]
168 | #_ % // % %2 // ] ]
169 | #a #Ha lapply (refl ? (current ? (nth j ? int (niltape ?))))
170 cases (current ? (nth j ? int (niltape ?))) in ⊢ (???%→?);
173 [ whd in ⊢ (??%?); >comp_q0_q2_null /2/ %2 <Hcurj in ⊢ (???%);
175 | normalize in ⊢ (%→?); #H destruct (H) ]
176 | #_ % // >Ha >Hcurj % % %2 % #H destruct (H) ] ]
178 cases (true_or_false (is_endc a)) #Haendc
181 [whd in ⊢ (??%?); >comp_q0_q2_neq //
182 % %{a} % // <Ha @sym_eq @nth_vec_map
183 | normalize in ⊢ (%→?); #H destruct (H) ]
184 | #_ % // % % % >Ha %{a} % // ]
186 |cases (true_or_false (a == b)) #Hab
189 [whd in ⊢ (??%?); >(comp_q0_q1 … a Hneq Hi Hj) //
190 [>(\P Hab) <Hb @sym_eq @nth_vec_map
191 |<Ha @sym_eq @nth_vec_map ]
192 | #_ whd >(\P Hab) %{b} % // % // <(\P Hab) % // ]
193 | * #H @False_ind @H %
197 [whd in ⊢ (??%?); >comp_q0_q2_neq //
198 <(nth_vec_map ?? (current …) i ? int (niltape ?))
199 <(nth_vec_map ?? (current …) j ? int (niltape ?)) %2 >Ha >Hb
200 @(not_to_not ??? (\Pf Hab)) #H destruct (H) %
201 | normalize in ⊢ (%→?); #H destruct (H) ]
202 | #_ % // % % %2 >Ha >Hb @(not_to_not ??? (\Pf Hab)) #H destruct (H) % ] ]
209 definition compare ≝ λi,j,sig,n,is_endc.
210 whileTM … (compare_step i j sig n is_endc) comp1.
212 definition R_compare ≝
213 λi,j,sig,n,is_endc.λint,outt: Vector (tape sig) (S n).
214 ((∃x.current ? (nth i ? int (niltape ?)) = Some ? x ∧ is_endc x = true) ∨
215 (current ? (nth i ? int (niltape ?)) ≠ current ? (nth j ? int (niltape ?)) ∨
216 current ? (nth i ? int (niltape ?)) = None ? ∨
217 current ? (nth j ? int (niltape ?)) = None ?) → outt = int) ∧
218 (∀ls,x,xs,ci,rs,ls0,cj,rs0.
219 nth i ? int (niltape ?) = midtape sig ls x (xs@ci::rs) →
220 nth j ? int (niltape ?) = midtape sig ls0 x (xs@cj::rs0) →
221 (∀c0. memb ? c0 (x::xs) = true → is_endc c0 = false) →
222 (is_endc ci = true ∨ ci ≠ cj) →
224 (change_vec ?? int (midtape sig (reverse ? xs@x::ls) ci rs) i)
225 (midtape sig (reverse ? xs@x::ls0) cj rs0) j).
227 lemma wsem_compare : ∀i,j,sig,n,is_endc.i ≠ j → i < S n → j < S n →
228 compare i j sig n is_endc ⊫ R_compare i j sig n is_endc.
229 #i #j #sig #n #is_endc #Hneq #Hi #Hj #ta #k #outc #Hloop
230 lapply (sem_while … (sem_comp_step i j sig n is_endc Hneq Hi Hj) … Hloop) //
231 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
232 [ #tc whd in ⊢ (%→?); * * [ * [ *
233 [* #curi * #Hcuri #Hendi #Houtc %
235 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi #Hnthj #Hnotendc
237 >Hnthi in Hcuri; normalize in ⊢ (%→?); #H destruct (H)
238 >(Hnotendc ? (memb_hd … )) in Hendi; #H destruct (H)
242 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi #Hnthj
243 >Hnthi in Hcicj; >Hnthj normalize in ⊢ (%→?); * #H @False_ind @H %
247 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi >Hnthi in Hci;
248 normalize in ⊢ (%→?); #H destruct (H) ] ]
251 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #_ #Hnthj >Hnthj in Hcj;
252 normalize in ⊢ (%→?); #H destruct (H) ] ]
253 | #tc #td #te * #x * * * #Hendcx #Hci #Hcj #Hd #Hstar #IH #He lapply (IH He) -IH *
255 [ >Hci >Hcj * [* #x0 * #H destruct (H) >Hendcx #H destruct (H)
256 |* [* #H @False_ind [cases H -H #H @H % | destruct (H)] | #H destruct (H)]]
257 | #ls #c0 #xs #ci #rs #ls0 #cj #rs0 cases xs
258 [ #Hnthi #Hnthj #Hnotendc #Hcicj >IH1
260 [ @eq_f3 // >(?:c0=x) [ >Hnthi % ]
261 >Hnthi in Hci;normalize #H destruct (H) %
262 | >(?:c0=x) [ >Hnthj % ]
263 >Hnthi in Hci;normalize #H destruct (H) % ]
264 | >Hd >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
265 >nth_change_vec // >Hnthi >Hnthj normalize
267 [%1 %{ci} % // | %2 %1 %1 @(not_to_not ??? Hcase) #H destruct (H) % ]
269 | #x0 #xs0 #Hnthi #Hnthj #Hnotendc #Hcicj
270 >(IH2 (c0::ls) x0 xs0 ci rs (c0::ls0) cj rs0 … Hcicj)
271 [ >Hd >change_vec_commute in ⊢ (??%?); //
272 >change_vec_change_vec >change_vec_commute in ⊢ (??%?); //
274 | #c1 #Hc1 @Hnotendc @memb_cons @Hc1
275 | >Hd >nth_change_vec // >Hnthj normalize
276 >Hnthi in Hci;normalize #H destruct (H) %
277 | >Hd >nth_change_vec_neq [|@sym_not_eq //] >Hnthi
278 >nth_change_vec // normalize
279 >Hnthi in Hci;normalize #H destruct (H) %
284 lemma terminate_compare : ∀i,j,sig,n,is_endc,t.
285 i ≠ j → i < S n → j < S n →
286 compare i j sig n is_endc ↓ t.
287 #i #j #sig #n #is_endc #t #Hneq #Hi #Hj
288 @(terminate_while … (sem_comp_step …)) //
289 <(change_vec_same … t i (niltape ?))
290 cases (nth i (tape sig) t (niltape ?))
291 [ % #t1 * #x * * * #_ >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
292 |2,3: #a0 #al0 % #t1 * #x * * * #_ >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
293 | #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs
294 [#t #ls #c % #t1 * #x * * * #Hendcx >nth_change_vec // normalize in ⊢ (%→?);
295 #H1 destruct (H1) #Hxsep >change_vec_change_vec #Ht1 %
296 #t2 * #x0 * * * #Hendcx0 >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
297 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
298 |#r0 #rs0 #IH #t #ls #c % #t1 * #x * * >nth_change_vec //
299 normalize in ⊢ (%→?); #H destruct (H) #Hcur
300 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
305 lemma sem_compare : ∀i,j,sig,n,is_endc.
306 i ≠ j → i < S n → j < S n →
307 compare i j sig n is_endc ⊨ R_compare i j sig n is_endc.
308 #i #j #sig #n #is_endc #Hneq #Hi #Hj @WRealize_to_Realize /2/
313 |confin 0/1 confout move
324 definition match_step ≝ λsrc,dst,sig,n,is_startc,is_endc.
325 compare src dst sig n ·
326 (ifTM ?? (inject_TM ? (test_char ? (λa.is_endc a == false)) n src)
328 (parmove src dst sig n L is_startc · (inject_TM ? (move_r ?) n dst)))
332 definition Rtc_multi_true ≝
333 λalpha,test,n,i.λt1,t2:Vector ? (S n).
334 (∃c. current alpha (nth i ? t1 (niltape ?)) = Some ? c ∧ test c = true) ∧ t2 = t1.
336 definition Rtc_multi_false ≝
337 λalpha,test,n,i.λt1,t2:Vector ? (S n).
338 (∀c. current alpha (nth i ? t1 (niltape ?)) = Some ? c → test c = false) ∧ t2 = t1.
340 definition R_match_step_false ≝
341 λsrc,dst,sig,n,is_endc.λint,outt: Vector (tape sig) (S n).
342 (((∃x.current ? (nth src ? int (niltape ?)) = Some ? x ∧ is_endc x = true) ∨
343 (* current ? (nth src ? int (niltape ?)) ≠ current ? (nth dst ? int (niltape ?)) ∨ *)
344 current sig (nth src (tape sig) int (niltape sig)) = None ? ∨
345 current sig (nth dst (tape sig) int (niltape sig)) = None ? ) ∧ outt = int) ∨
346 ∃ls,ls0,rs,rs0,x,xs. ∀rsi,rsj,end,c.
347 rs = end::rsi → rs0 = c::rsj →
348 is_endc x = false ∧ is_endc end = true ∧
349 nth src ? int (niltape ?) = midtape sig ls x (xs@rs) ∧
350 nth dst ? int (niltape ?) = midtape sig ls0 x (xs@rs0) ∧
352 (change_vec ?? int (midtape sig (reverse ? xs@x::ls) end rsi) src)
353 (midtape sig (reverse ? xs@x::ls0) c rsj) dst.
355 definition R_match_step_true ≝
356 λsrc,dst,sig,n,is_startc,is_endc.λint,outt: Vector (tape sig) (S n).
357 ∀s.current sig (nth src (tape sig) int (niltape sig)) = Some ? s →
359 (∀c.c ∈ right ? (nth src (tape sig) int (niltape sig)) = true → is_startc c = false) →
360 (∀s1.current sig (nth dst (tape sig) int (niltape sig)) = Some ? s1 →
362 outt = change_vec ?? int
363 (tape_move … (nth dst ? int (niltape ?)) (Some ? 〈s1,R〉)) dst ∧ is_endc s = false) ∧
364 (∀ls,x,xs,ci,rs,ls0,cj,rs0.
365 nth src ? int (niltape ?) = midtape sig ls x (xs@ci::rs) →
366 nth dst ? int (niltape ?) = midtape sig ls0 x (xs@cj::rs0) → ci ≠ cj →
367 outt = change_vec ?? int
368 (tape_move … (nth dst ? int (niltape ?)) (Some ? 〈x,R〉)) dst ∧ is_endc ci = false).
370 lemma sem_test_char_multi :
371 ∀alpha,test,n,i.i ≤ n →
372 inject_TM ? (test_char ? test) n i ⊨
373 [ tc_true : Rtc_multi_true alpha test n i, Rtc_multi_false alpha test n i ].
374 #alpha #test #n #i #Hin #int
375 cases (acc_sem_inject … Hin (sem_test_char alpha test) int)
376 #k * #outc * * #Hloop #Htrue #Hfalse %{k} %{outc} % [ %
378 | #Hqtrue lapply (Htrue Hqtrue) * * * #c *
379 #Hcur #Htestc #Hnth_i #Hnth_j %
381 | @(eq_vec … (niltape ?)) #i0 #Hi0
382 cases (decidable_eq_nat i0 i) #Hi0i
384 | @sym_eq @Hnth_j @sym_not_eq // ] ] ]
385 | #Hqfalse lapply (Hfalse Hqfalse) * * #Htestc #Hnth_i #Hnth_j %
387 | @(eq_vec … (niltape ?)) #i0 #Hi0
388 cases (decidable_eq_nat i0 i) #Hi0i
390 | @sym_eq @Hnth_j @sym_not_eq // ] ] ]
393 axiom comp_list: ∀S:DeqSet. ∀l1,l2:list S. ∃l,tl1,tl2.
394 l1 = l@tl1 ∧ l2 = l@tl2 ∧ ∀a,b,tla,tlb. tl1 = a::tla → tl2 = b::tlb → a≠b.
396 axiom daemon : ∀X:Prop.X.
398 lemma sem_match_step :
399 ∀src,dst,sig,n,is_startc,is_endc.src ≠ dst → src < S n → dst < S n →
400 match_step src dst sig n is_startc is_endc ⊨
401 [ inr ?? (inr ?? (inl … (inr ?? start_nop))) :
402 R_match_step_true src dst sig n is_startc is_endc,
403 R_match_step_false src dst sig n is_endc ].
404 #src #dst #sig #n #is_startc #is_endc #Hneq #Hsrc #Hdst
405 @(acc_sem_seq_app sig n … (sem_compare src dst sig n Hneq Hsrc Hdst)
406 (acc_sem_if ? n … (sem_test_char_multi sig (λa.is_endc a == false) n src (le_S_S_to_le … Hsrc))
408 (sem_parmoveL ???? is_startc Hneq Hsrc Hdst)
409 (sem_inject … dst (le_S_S_to_le … Hdst) (sem_move_r ? )))
411 [#ta #tb #tc * #Hcomp1 #Hcomp2 * #td * * * #c * #Hcurtc #Hcend #Htd >Htd -Htd
412 #Htb #s #Hcurta_src #Hstart #Hnotstart %
413 [ #s1 #Hcurta_dst #Hneqss1
414 lapply Htb lapply Hcurtc -Htb -Hcurtc >(?:tc=ta)
415 [|@Hcomp1 % % >Hcurta_src >Hcurta_dst @(not_to_not … Hneqss1) #H destruct (H) % ]
416 #Hcurtc * #te * * #_ #Hte >Hte // whd in ⊢ (%→?); * * #_ #Htbdst #Htbelse %
417 [ @(eq_vec … (niltape ?)) #i #Hi cases (decidable_eq_nat i dst) #Hidst
418 [ >Hidst >nth_change_vec // cases (current_to_midtape … Hcurta_dst)
419 #ls * #rs #Hta_mid >(Htbdst … Hta_mid) >Hta_mid cases rs //
420 | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @Htbelse @sym_not_eq // ]
421 | >Hcurtc in Hcurta_src; #H destruct (H) cases (is_endc s) in Hcend;
422 normalize #H destruct (H) // ]
423 |#ls #x #xs #ci #rs #ls0 #cj #rs0 #Htasrc_mid #Htadst_mid #Hcicj
424 lapply (Hcomp2 … Htasrc_mid Htadst_mid Hcicj) -Hcomp2 #Hcomp2
425 cases Htb #td * * #Htd #_ >Htasrc_mid in Hcurta_src; normalize in ⊢ (%→?);
427 >(Htd ls ci (reverse ? xs) rs s ??? ls0 cj (reverse ? xs) s rs0 (refl ??)) //
428 [| >Hcomp2 >nth_change_vec //
429 | #c0 #Hc0 @(Hnotstart c0) >Htasrc_mid
430 cases (orb_true_l … Hc0) -Hc0 #Hc0
431 [@memb_append_l2 >(\P Hc0) @memb_hd
432 |@memb_append_l1 <(reverse_reverse …xs) @memb_reverse //
434 | >Hcomp2 >nth_change_vec_neq [|@sym_not_eq // ] @nth_change_vec // ]
435 * * #_ #Htbdst #Htbelse %
436 [ @(eq_vec … (niltape ?)) #i #Hi cases (decidable_eq_nat i dst) #Hidst
437 [ >Hidst >nth_change_vec // >Htadst_mid >(Htbdst ls0 s (xs@cj::rs0))
439 | >nth_change_vec // ]
440 | >nth_change_vec_neq [|@sym_not_eq //]
441 <Htbelse [|@sym_not_eq // ]
442 >nth_change_vec_neq [|@sym_not_eq //]
444 cases (decidable_eq_nat i src) #Hisrc
445 [ >Hisrc >nth_change_vec // >Htasrc_mid //
446 | >nth_change_vec_neq [|@sym_not_eq //]
447 <(Htbelse i) [|@sym_not_eq // ]
448 >Hcomp2 >nth_change_vec_neq [|@sym_not_eq // ]
449 >nth_change_vec_neq [|@sym_not_eq // ] //
452 | >Hcomp2 in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
453 >nth_change_vec // whd in ⊢ (??%?→?);
454 #H destruct (H) cases (is_endc c) in Hcend;
455 normalize #H destruct (H) // ]
457 |#intape #outtape #ta * #Hcomp1 #Hcomp2 * #tb * * #Hc #Htb
458 whd in ⊢ (%→?); #Hout >Hout >Htb whd
459 lapply (current_to_midtape sig (nth src ? intape (niltape ?)))
460 cases (current … (nth src ? intape (niltape ?))) in Hcomp1;
461 [#Hcomp1 #_ %1 % [%1 %2 // | @Hcomp1 %1 %2 %]
462 |#c_src lapply (current_to_midtape sig (nth dst ? intape (niltape ?)))
463 cases (current … (nth dst ? intape (niltape ?)))
464 [#_ #Hcomp1 #_ %1 % [%2 % | @Hcomp1 %2 %]
465 |#c_dst cases (true_or_false (c_src == c_dst)) #Hceq
466 [#Hmid_dst cases (Hmid_dst c_dst (refl …)) -Hmid_dst
467 #ls_dst * #rs_dst #Hmid_dst #_
468 #Hmid_src cases (Hmid_src c_src (refl …)) -Hmid_src
469 #ls_src * #rs_src #Hmid_src %2
470 cases (comp_list … rs_src rs_dst) #xs * #rsi * #rsj * *
471 #Hrs_src #Hrs_dst #Hneq
472 %{ls_src} %{ls_dst} %{rsi} %{rsj} %{c_src} %{xs}
473 #rsi0 #rsj0 #end #c #Hend #Hc_dst
474 >Hrs_src in Hmid_src; >Hend #Hmid_src
475 >Hrs_dst in Hmid_dst; >Hc_dst <(\P Hceq) #Hmid_dst
476 lapply(Hcomp2 … Hmid_src Hmid_dst ?)
477 [@(Hneq … Hend Hc_dst)]
478 -Hcomp2 #Hcomp2 <Hcomp2
480 [>Hcomp2 in Hc; >nth_change_vec_neq [|@sym_not_eq //]
481 >nth_change_vec // #H lapply (H ? (refl …))
482 cases (is_endc end) normalize //
485 |#_ #Hcomp1 #Hsrc cases (Hsrc ? (refl ??)) -Hsrc #ls * #rs #Hsrc
487 [% % %{c_src} % // lapply (Hc c_src) -Hc >Hcomp1
488 [| % % @(not_to_not ??? (\Pf Hceq)) #H destruct (H) // ]
489 cases (is_endc c_src) //
490 >Hsrc #Hc lapply (Hc (refl ??)) normalize #H destruct (H)
491 |@Hcomp1 %1 %1 @(not_to_not ??? (\Pf Hceq)) #H destruct (H) //
498 definition match_m ≝ λsrc,dst,sig,n,is_startc,is_endc.
499 whileTM … (match_step src dst sig n is_startc is_endc)
500 (inr ?? (inr ?? (inl … (inr ?? start_nop)))).
502 definition R_match_m ≝
503 λi,j,sig,n,is_startc,is_endc.λint,outt: Vector (tape sig) (S n).
504 (((∃x.current ? (nth i ? int (niltape ?)) = Some ? x ∧ is_endc x = true) ∨
505 current ? (nth i ? int (niltape ?)) = None ? ∨
506 current ? (nth j ? int (niltape ?)) = None ?) → outt = int) ∧
507 (∀ls,x,xs,ci,rs,ls0,x0,rs0.
508 is_startc x = true → is_endc ci = true →
509 nth i ? int (niltape ?) = midtape sig ls x (xs@ci::rs) →
510 nth j ? int (niltape ?) = midtape sig ls0 x0 rs0 →
511 ∃l,cj,l1.x0::rs0 = l@x::xs@cj::l1 ∧
513 (change_vec ?? int (midtape sig (reverse ? xs@x::ls) ci rs) i)
514 (midtape sig ((reverse ? (l@x::xs))@ls0) cj l1) j).
516 lemma wsem_match_m : ∀src,dst,sig,n,is_startc,is_endc.
517 src ≠ dst → src < S n → dst < S n →
518 match_m src dst sig n is_startc is_endc ⊫ R_match_m src dst sig n is_startc is_endc.
519 #src #dst #sig #n #is_startc #is_endc #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
520 lapply (sem_while … (sem_match_step src dst sig n is_startc is_endc Hneq Hsrc Hdst) … Hloop) //
521 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
522 [ #tc whd in ⊢ (%→?); *
524 [ * #cur_src * #H1 #H2 #Houtc %
526 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #_ #_ #Hnthi #Hnthj
527 >Hnthi in Hcicj; >Hnthj normalize in ⊢ (%→?); * #H @False_ind @H %
531 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #Hnthi >Hnthi in Hci;
532 normalize in ⊢ (%→?); #H destruct (H) ] ]
535 | #ls #x #xs #ci #rs #ls0 #cj #rs0 #_ #Hnthj >Hnthj in Hcj;
536 normalize in ⊢ (%→?); #H destruct (H) ] ]
540 [ #tc whd in ⊢ (%→?); * * [ *