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_____________________________________________________________*)
12 include "turing/multi_universal/moves_2.ma".
13 include "turing/multi_universal/match.ma".
14 include "turing/multi_universal/copy.ma".
15 include "turing/multi_universal/alphabet.ma".
16 include "turing/multi_universal/tuples.ma".
29 current (in.obj) = None
40 (if (current(in.obj)) == None
55 definition obj ≝ (0:DeqNat).
56 definition cfg ≝ (1:DeqNat).
57 definition prg ≝ (2:DeqNat).
59 definition obj_to_cfg ≝
60 mmove cfg FSUnialpha 2 L ·
61 (ifTM ?? (inject_TM ? (test_null ?) 2 obj)
62 (copy_step obj cfg FSUnialpha 2 ·
63 mmove cfg FSUnialpha 2 L ·
64 mmove obj FSUnialpha 2 L)
65 (inject_TM ? (write FSUnialpha null) 2 cfg)
67 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
68 mmove cfg FSUnialpha 2 R.
70 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
72 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
73 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
75 (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧
76 (current ? (nth obj ? t1 (niltape ?)) = None ? →
78 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls)))
79 (tail ? (reverse ? (null::ls)))) cfg).
81 axiom sem_move_to_end_l : ∀sig. move_to_end sig L ⊨ R_move_to_end_l sig.
82 axiom accRealize_to_Realize :
83 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
84 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
86 lemma eq_mk_tape_rightof :
87 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
91 axiom daemon : ∀P:Prop.P.
93 definition option_cons ≝ λsig.λc:option sig.λl.
94 match c with [ None ⇒ l | Some c0 ⇒ c0::l ].
96 lemma tape_move_mk_tape_R :
98 (c = None ? → ls = [ ] ∨ rs = [ ]) →
99 tape_move ? (mk_tape sig ls c rs) R =
100 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
101 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
102 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
106 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
107 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
110 (sem_test_null_multi ?? obj ?)
111 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
112 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
113 (sem_move_multi ? 2 obj L ?)))
114 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
115 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
116 (sem_move_multi ? 2 cfg R ?)))) //
118 #tc * whd in ⊢ (%→?); #Htc *
120 [ * #te * * #Hcurtc #Hte
121 * destruct (Hte) #te * *
122 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte
123 * #tf * whd in ⊢ (%→%→?); #Htf #Htd
124 * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb
126 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
127 whd in match (tape_move ???); #Htc
128 cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
129 [@daemon] -Htg1 -Htg2 -Htg3 #Htg destruct (Htg Htf Hte Htd Htc Htb)
130 >change_vec_change_vec >change_vec_change_vec
131 >change_vec_commute // >change_vec_change_vec
132 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
133 >change_vec_commute // >change_vec_change_vec
134 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
135 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
136 >change_vec_commute [|@sym_not_eq //] @eq_f3 //
137 [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
138 [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
139 | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
140 | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
141 >nth_change_vec_neq in Hcurtc1; [|@sym_not_eq //] >Hta2
142 normalize in ⊢ (%→?); #H destruct (H) %
144 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
145 >Hta2 #H destruct (H)
147 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
148 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
149 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
150 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
151 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
153 | * #te * * #Hcurtc #Hte
154 * whd in ⊢ (%→%→?); #Htd1 #Htd2
155 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
157 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
158 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
159 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
160 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
161 [@daemon] -Htd1 -Htd2 #Htd
162 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
163 [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
164 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
165 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
166 >reverse_cons >tape_move_mk_tape_R /2/ ]
170 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
172 definition R_test_null_char_true ≝ λt1,t2.
173 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
175 definition R_test_null_char_false ≝ λt1,t2.
176 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
178 lemma sem_test_null_char :
179 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
180 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
181 #Hfalse %{k} %{outc} % [ %
183 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
184 -Hcnull #H destruct (H) #Houtc1 %
185 [ @Hcurt1 | <Houtc1 % ] ]
186 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
187 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
188 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
193 definition copy_char_states ≝ initN 3.
195 definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
196 definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
198 definition trans_copy_char ≝
199 λsrc,dst.λsig:FinSet.λn.
200 λp:copy_char_states × (Vector (option sig) (S n)).
203 [ O ⇒ 〈cc1,change_vec ? (S n)
204 (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
205 (〈nth src ? a (None ?),R〉) dst〉
206 | S _ ⇒ 〈cc1,null_action ? n〉 ].
208 definition copy_char ≝
210 mk_mTM sig n copy_char_states (trans_copy_char src dst sig n)
213 definition R_copy_char ≝
214 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
217 (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
218 (tape_move_mono ? (nth dst ? int (niltape ?))
219 〈current ? (nth src ? int (niltape ?)), R〉) dst.
221 lemma copy_char_q0_q1 :
222 ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n →
223 step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) =
227 (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
228 (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst).
229 #src #dst #sig #n #v #Heq #Hsrc #Hdst
231 <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
232 <(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
233 >tape_move_multi_def @eq_f2 //
234 >pmap_change >pmap_change <tape_move_multi_def
235 >tape_move_null_action @eq_f2 // @eq_f2
237 | >change_vec_same >change_vec_same // ]
241 ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
242 copy_char src dst sig n ⊨ R_copy_char src dst sig n.
243 #src #dst #sig #n #Hneq #Hsrc #Hdst #int
244 %{2} % [| % [ % | whd >copy_char_q0_q1 // ]]
247 definition cfg_to_obj ≝
248 mmove cfg FSUnialpha 2 L ·
249 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
251 (copy_char cfg obj FSUnialpha 2 ·
252 mmove cfg FSUnialpha 2 L ·
253 mmove obj FSUnialpha 2 L)
255 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
256 mmove cfg FSUnialpha 2 R.
258 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
260 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
262 t2 = change_vec ?? t1
263 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
264 (tail ? (reverse ? (c::ls)))) cfg) ∧
268 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
269 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
271 lemma tape_move_mk_tape_L :
273 (c = None ? → ls = [ ] ∨ rs = [ ]) →
274 tape_move ? (mk_tape sig ls c rs) L =
275 mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs).
276 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
277 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
281 lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
282 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
285 (acc_sem_inject ?????? cfg ? sem_test_null_char)
287 (sem_seq ?????? (sem_copy_char …)
288 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
289 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
290 (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
292 #tc * whd in ⊢ (%→?); #Htc *
294 [ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
295 * #tf * * * #Htf1 #Htf2 #Htf3
298 [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
299 cut (te = tc) [@daemon] -Hte1 -Hte2 #Hte
300 cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
301 [@daemon] -Htf1 -Htf2 -Htf3 #Htf
302 destruct (Htf Hte Htc Htb)
303 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
304 >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ]
306 | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
307 >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?);
308 #H destruct (H) @False_ind cases Hc /2/ ]
310 | * #te * * * #Hcurtc #Hte1 #Hte2
311 * #tf * whd in ⊢ (%→?); #Htf
312 * #tg * whd in ⊢ (%→%→?); #Htg #Htd
313 * #th * * * #Hth1 #Hth2 #Hth3
316 [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L //
317 >Hc normalize in ⊢ (%→?); * #H @False_ind /2/
318 | cut (te = tc) [ @daemon ] -Hte1 -Hte2 #Hte
319 cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
320 [@daemon] -Hth1 -Hth2 -Hth3 #Hth
321 destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
322 >change_vec_change_vec >change_vec_change_vec
323 >change_vec_commute // >change_vec_change_vec
324 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
325 >change_vec_commute // >change_vec_change_vec
326 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
327 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
328 >change_vec_commute [|@sym_not_eq //]
330 [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??);
331 @eq_f2 // cases (nth obj ? ta (niltape ?))
332 [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try %
334 | >reverse_cons >tape_move_mk_tape_R // #_ % % ]
339 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
340 del current di prg, che codifica la direzione in cui ci muoviamo *)
342 definition char_to_move ≝ λc.match c with
343 [ bit b ⇒ if b then R else L
346 definition char_to_bit_option ≝ λc.match c with
347 [ bit b ⇒ Some ? (bit b)
350 definition tape_move_obj : mTM FSUnialpha 2 ≝
352 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
353 (mmove obj FSUnialpha 2 L)
355 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
356 (mmove obj FSUnialpha 2 R)
361 definition R_tape_move_obj' ≝ λt1,t2:Vector (tape FSUnialpha) 3.
362 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit false) →
363 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) L) obj) ∧
364 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit true) →
365 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) R) obj) ∧
366 (current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit false) →
367 current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit true) →
370 lemma sem_tape_move_obj' : tape_move_obj ⊨ R_tape_move_obj'.
371 #ta cases (sem_if ??????????
372 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit false)))
373 (sem_move_multi ? 2 obj L ?)
375 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit true)))
376 (sem_move_multi ? 2 obj R ?)
378 #i * #outc * #Hloop #HR %{i} %{outc} % [@Hloop] -i
380 [ * #tb * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htb1 #Htb2
381 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
382 [ >Hcurta_prg #H destruct (H) >(?:tb = ta) [|@daemon] %
383 | >Hcurta_prg #H destruct (H) destruct (Hc) ]
384 | >Hcurta_prg >Hc * #H @False_ind /2/ ]
385 | * #tb * * * #Hnotfalse #Htb1 #Htb2 cut (tb = ta) [@daemon] -Htb1 -Htb2
386 #Htb destruct (Htb) *
387 [ * #tc * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htc1 #Htc2
388 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
389 [ >Hcurta_prg #H destruct (H) destruct (Hc)
390 | >Hcurta_prg #H destruct (H) >(?:tc = ta) [|@daemon] % ]
391 | >Hcurta_prg >Hc #_ * #H @False_ind /2/ ]
392 | * #tc * * * #Hnottrue #Htc1 #Htc2 cut (tc = ta) [@daemon] -Htc1 -Htc2
393 #Htc destruct (Htc) whd in ⊢ (%→?); #Houtc % [ %
394 [ #Hcurta_prg lapply (\Pf (Hnotfalse ? Hcurta_prg)) * #H @False_ind /2/
395 | #Hcurta_prg lapply (\Pf (Hnottrue ? Hcurta_prg)) * #H @False_ind /2/ ]
401 definition R_tape_move_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
402 ∀c. current ? (nth prg ? t1 (niltape ?)) = Some ? c →
403 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) (char_to_move c)) obj.
405 lemma sem_tape_move_obj : tape_move_obj ⊨ R_tape_move_obj.
406 @(Realize_to_Realize … sem_tape_move_obj')
407 #ta #tb * * #Htb1 #Htb2 #Htb3 * [ *
409 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
410 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
411 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
412 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
416 definition restart_tape ≝ λi.
417 inject_TM ? (move_to_end FSUnialpha L) 2 i ·
418 mmove i FSUnialpha 2 R.
421 match_m cfg prg FSUnialpha 2 ·
422 restart_tape cfg · copy prg cfg FSUnialpha 2 ·
423 cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
426 definition legal_tape ≝ λn,l,h,t.
428 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
429 is_config n (bar::state@[char]) →
430 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
431 bar::table = table_TM n l h → *)
433 definition list_of_tape ≝ λsig,t.
434 left sig t@option_cons ? (current ? t) (right ? t).
436 definition low_char' ≝ λc.
439 | Some b ⇒ if (is_bit b) then b else null
442 lemma low_char_option : ∀s.
443 low_char' (option_map FinBool FSUnialpha bit s) = low_char s.
447 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
450 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
451 is_config n (bar::state@[char]) →
453 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
454 bar::table = table_TM n l h →
456 only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
457 let conf ≝ (bar::state@[char]) in
458 (∃ll,lr.bar::table = ll@conf@lr) →
460 ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧
463 tuple_encoding n h t = (conf@nstate@[nchar;m])→
466 tape_move_mono ? (nth obj ? t1 (niltape ?))
467 〈char_to_bit_option nchar,char_to_move m〉 in
468 let next_char ≝ low_char' (current ? new_obj) in
471 (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
474 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
475 mk_tape B (map ?? f (left ? t))
476 (option_map ?? f (current ? t))
477 (map ?? f (right ? t)).
479 lemma map_list_of_tape: ∀A,B,f,t.
480 list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
481 #A #B #f * // normalize // #ls #c #rs <map_append %
484 lemma low_char_current : ∀t.
485 low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
486 = low_char (current FinBool t).
489 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝
490 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
491 [tape_map ?? bit (ctape ?? c);
493 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
494 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
497 lemma obj_low_tapes: ∀M,c.
498 nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
501 lemma cfg_low_tapes: ∀M,c.
502 nth cfg ? (low_tapes M c) (niltape ?) =
504 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
507 lemma prg_low_tapes: ∀M,c.
508 nth prg ? (low_tapes M c) (niltape ?) =
509 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
512 (* commutation lemma for write *)
513 lemma map_write: ∀t,cout.
514 tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
515 = tape_map ?? bit (tape_write ? t cout).
516 #t * // #b whd in match (char_to_bit_option ?);
517 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
520 (* commutation lemma for moves *)
521 lemma map_move: ∀t,m.
522 tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
523 = tape_map ?? bit (tape_move ? t m).
524 #t * // whd in match (char_to_move ?);
525 [cases t // * // | cases t // #ls #a * //]
528 (* commutation lemma for actions *)
529 lemma map_action: ∀t,cout,m.
530 tape_move ? (tape_write ? (tape_map FinBool ? bit t)
531 (char_to_bit_option (low_char cout))) (char_to_move (low_mv m))
532 = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
533 #t #cout #m >map_write >map_move %
536 lemma map_move_mono: ∀t,cout,m.
537 tape_move_mono ? (tape_map FinBool ? bit t)
538 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
539 = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
543 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
544 ∀c:nconfig (no_states M).
546 t2 = low_tapes M (step ? M c).
548 lemma R_unistep_equiv : ∀M,t1,t2.
549 R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
550 R_unistep_high M t1 t2.
551 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
552 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
553 (* tup = current tuple *)
554 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉,
555 ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
556 (* tup is in the graph *)
557 cut (mem ? tup (graph_enum ?? (ntrans M)))
558 [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
559 (* tupe target = 〈qout,cout,m〉 *)
560 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
561 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
563 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
564 [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
565 cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1
568 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
570 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
571 [>Hstep %] #Hnew_tape
572 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
573 (low_char (current ? (ctape ?? c)))
574 (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
577 lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
578 %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
579 >Htable1 @eq_f <associative_append @eq_f2 // >Htup
580 whd in ⊢ (??%?); @eq_f >associative_append %
581 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
582 [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
585 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
586 % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
587 |>length_map whd in match (length ??); @eq_f //]
589 |>Ht1 >cfg_low_tapes //] -H #H
590 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout)
591 (low_mv … m) tup ? Hingraph)
592 [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
593 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi
594 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
595 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
596 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
598 |>Hi >obj_low_tapes >nth_change_vec //
599 >Ht1 >obj_low_tapes >Hstep @map_action
601 |>Hi >cfg_low_tapes >nth_change_vec_neq
602 [|% whd in ⊢ (??%?→?); #H destruct (H)]
603 >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape
604 @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
606 |(* program tapes do not change *)
608 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
609 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
610 >Ht1 >prg_low_tapes //