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 definition option_cons ≝ λsig.λc:option sig.λl.
92 match c with [ None ⇒ l | Some c0 ⇒ c0::l ].
94 lemma tape_move_mk_tape_R :
96 (c = None ? → ls = [ ] ∨ rs = [ ]) →
97 tape_move ? (mk_tape sig ls c rs) R =
98 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
99 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
100 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
104 lemma eq_vec_change_vec : ∀sig,n.∀v1,v2:Vector sig n.∀i,t,d.
106 (∀j.i ≠ j → nth j ? v1 d = nth j ? v2 d) →
107 v2 = change_vec ?? v1 t i.
108 #sig #n #v1 #v2 #i #t #d #H1 #H2 @(eq_vec … d)
109 #i0 #Hlt cases (decidable_eq_nat i0 i) #Hii0
110 [ >Hii0 >nth_change_vec //
111 | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @H2 @sym_not_eq // ]
114 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
115 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
118 (sem_test_null_multi ?? obj ?)
119 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
120 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
121 (sem_move_multi ? 2 obj L ?)))
122 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
123 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
124 (sem_move_multi ? 2 cfg R ?)))) //
126 #tc * whd in ⊢ (%→?); #Htc *
128 [ * #te * * #Hcurtc #Hte
129 * destruct (Hte) #te * *
130 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte
131 * #tf * whd in ⊢ (%→%→?); #Htf #Htd
132 * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb
134 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
135 whd in match (tape_move ???); #Htc
136 cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
137 [ lapply (eq_vec_change_vec ??????? (Htg2 ls x [ ] ?) Htg3) //
138 >Htd >nth_change_vec_neq // >Htf >nth_change_vec //
139 >Hte >nth_change_vec // >Htc >nth_change_vec // ] -Htg1 -Htg2 -Htg3 #Htg
141 >change_vec_change_vec >change_vec_change_vec
142 >change_vec_commute // >change_vec_change_vec
143 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
144 >change_vec_commute // >change_vec_change_vec
145 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
146 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
147 >change_vec_commute [|@sym_not_eq //] @eq_f3 //
148 [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
149 [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
150 | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
151 | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
152 >nth_change_vec_neq in Hcurtc1; [|@sym_not_eq //] >Hta2
153 normalize in ⊢ (%→?); #H destruct (H) %
155 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
156 >Hta2 #H destruct (H)
158 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
159 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
160 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
161 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
162 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
164 | * #te * * #Hcurtc #Hte
165 * whd in ⊢ (%→%→?); #Htd1 #Htd2
166 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
168 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
169 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
170 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
171 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
172 [ lapply (eq_vec_change_vec ??????? (Htd1 ls c [ ] ?) Htd2) //
173 >Htc >nth_change_vec // ] -Htd1 -Htd2 #Htd
174 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
175 [ lapply (eq_vec_change_vec ??????? (Htf2 ls null [ ] ?) Htf3) //
176 >Htd >nth_change_vec // ] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
177 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
178 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
179 >reverse_cons >tape_move_mk_tape_R /2/ ]
183 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
185 definition R_test_null_char_true ≝ λt1,t2.
186 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
188 definition R_test_null_char_false ≝ λt1,t2.
189 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
191 lemma sem_test_null_char :
192 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
193 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
194 #Hfalse %{k} %{outc} % [ %
196 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
197 -Hcnull #H destruct (H) #Houtc1 %
198 [ @Hcurt1 | <Houtc1 % ] ]
199 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
200 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
201 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
206 definition copy_char_states ≝ initN 3.
208 definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
209 definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
211 definition trans_copy_char ≝
212 λsrc,dst.λsig:FinSet.λn.
213 λp:copy_char_states × (Vector (option sig) (S n)).
216 [ O ⇒ 〈cc1,change_vec ? (S n)
217 (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
218 (〈nth src ? a (None ?),R〉) dst〉
219 | S _ ⇒ 〈cc1,null_action ? n〉 ].
221 definition copy_char ≝
223 mk_mTM sig n copy_char_states (trans_copy_char src dst sig n)
226 definition R_copy_char ≝
227 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
230 (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
231 (tape_move_mono ? (nth dst ? int (niltape ?))
232 〈current ? (nth src ? int (niltape ?)), R〉) dst.
234 lemma copy_char_q0_q1 :
235 ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n →
236 step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) =
240 (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
241 (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst).
242 #src #dst #sig #n #v #Heq #Hsrc #Hdst
244 <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
245 <(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
246 >tape_move_multi_def @eq_f2 //
247 >pmap_change >pmap_change <tape_move_multi_def
248 >tape_move_null_action @eq_f2 // @eq_f2
250 | >change_vec_same >change_vec_same // ]
254 ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
255 copy_char src dst sig n ⊨ R_copy_char src dst sig n.
256 #src #dst #sig #n #Hneq #Hsrc #Hdst #int
257 %{2} % [| % [ % | whd >copy_char_q0_q1 // ]]
260 definition cfg_to_obj ≝
261 mmove cfg FSUnialpha 2 L ·
262 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
264 (copy_char cfg obj FSUnialpha 2 ·
265 mmove cfg FSUnialpha 2 L ·
266 mmove obj FSUnialpha 2 L)
268 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
269 mmove cfg FSUnialpha 2 R.
271 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
273 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
275 t2 = change_vec ?? t1
276 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
277 (tail ? (reverse ? (c::ls)))) cfg) ∧
281 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
282 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
284 lemma tape_move_mk_tape_L :
286 (c = None ? → ls = [ ] ∨ rs = [ ]) →
287 tape_move ? (mk_tape sig ls c rs) L =
288 mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs).
289 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
290 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
294 lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
295 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
298 (acc_sem_inject ?????? cfg ? sem_test_null_char)
300 (sem_seq ?????? (sem_copy_char …)
301 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
302 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
303 (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
305 #tc * whd in ⊢ (%→?); #Htc *
307 [ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
308 * #tf * * * #Htf1 #Htf2 #Htf3
311 [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
313 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2) >change_vec_same // ]
315 cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
316 [ lapply (eq_vec_change_vec ??????? (Htf2 ls c [ ] ?) Htf3) //
317 >Hte >Htc >nth_change_vec // ] -Htf1 -Htf2 -Htf3 #Htf
318 destruct (Htf Hte Htc Htb)
319 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
320 >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ]
322 | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
323 >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?);
324 #H destruct (H) @False_ind cases Hc /2/ ]
326 | * #te * * * #Hcurtc #Hte1 #Hte2
327 * #tf * whd in ⊢ (%→?); #Htf
328 * #tg * whd in ⊢ (%→%→?); #Htg #Htd
329 * #th * * * #Hth1 #Hth2 #Hth3
332 [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L //
333 >Hc normalize in ⊢ (%→?); * #H @False_ind /2/
335 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2)
336 >change_vec_same // ] -Hte1 -Hte2 #Hte
337 cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
338 [ lapply (eq_vec_change_vec ??????? (Hth2 ls c [ ] ?) Hth3) //
339 >Htd >nth_change_vec_neq // >Htg >nth_change_vec //
340 >Htf >nth_change_vec_neq // >nth_change_vec //
341 >Hte >Htc >nth_change_vec // >Hta // ] -Hth1 -Hth2 -Hth3 #Hth
342 destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
343 >change_vec_change_vec >change_vec_change_vec
344 >change_vec_commute // >change_vec_change_vec
345 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
346 >change_vec_commute // >change_vec_change_vec
347 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
348 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
349 >change_vec_commute [|@sym_not_eq //]
351 [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??);
352 @eq_f2 // cases (nth obj ? ta (niltape ?))
353 [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try %
355 | >reverse_cons >tape_move_mk_tape_R // #_ % % ]
360 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
361 del current di prg, che codifica la direzione in cui ci muoviamo *)
363 definition char_to_move ≝ λc.match c with
364 [ bit b ⇒ if b then R else L
367 definition char_to_bit_option ≝ λc.match c with
368 [ bit b ⇒ Some ? (bit b)
371 definition tape_move_obj : mTM FSUnialpha 2 ≝
373 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
374 (mmove obj FSUnialpha 2 L)
376 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
377 (mmove obj FSUnialpha 2 R)
382 definition R_tape_move_obj' ≝ λt1,t2:Vector (tape FSUnialpha) 3.
383 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit false) →
384 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) L) obj) ∧
385 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit true) →
386 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) R) obj) ∧
387 (current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit false) →
388 current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit true) →
391 lemma sem_tape_move_obj' : tape_move_obj ⊨ R_tape_move_obj'.
392 #ta cases (sem_if ??????????
393 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit false)))
394 (sem_move_multi ? 2 obj L ?)
396 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit true)))
397 (sem_move_multi ? 2 obj R ?)
399 #i * #outc * #Hloop #HR %{i} %{outc} % [@Hloop] -i
401 [ * #tb * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htb1 #Htb2
402 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
403 [ >Hcurta_prg #H destruct (H) >(?:tb = ta)
404 [| lapply (eq_vec_change_vec ??????? Htb1 Htb2)
405 >change_vec_same // ] %
406 | >Hcurta_prg #H destruct (H) destruct (Hc) ]
407 | >Hcurta_prg >Hc * #H @False_ind /2/ ]
408 | * #tb * * * #Hnotfalse #Htb1 #Htb2 cut (tb = ta)
409 [ lapply (eq_vec_change_vec ??????? Htb1 Htb2)
410 >change_vec_same // ] -Htb1 -Htb2 #Htb destruct (Htb) *
411 [ * #tc * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htc1 #Htc2
412 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
413 [ >Hcurta_prg #H destruct (H) destruct (Hc)
414 | >Hcurta_prg #H destruct (H) >(?:tc = ta)
415 [| lapply (eq_vec_change_vec ??????? Htc1 Htc2)
416 >change_vec_same // ] % ]
417 | >Hcurta_prg >Hc #_ * #H @False_ind /2/ ]
418 | * #tc * * * #Hnottrue #Htc1 #Htc2 cut (tc = ta)
419 [ lapply (eq_vec_change_vec ??????? Htc1 Htc2)
420 >change_vec_same // ] -Htc1 -Htc2
421 #Htc destruct (Htc) whd in ⊢ (%→?); #Houtc % [ %
422 [ #Hcurta_prg lapply (\Pf (Hnotfalse ? Hcurta_prg)) * #H @False_ind /2/
423 | #Hcurta_prg lapply (\Pf (Hnottrue ? Hcurta_prg)) * #H @False_ind /2/ ]
429 definition R_tape_move_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
430 ∀c. current ? (nth prg ? t1 (niltape ?)) = Some ? c →
431 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) (char_to_move c)) obj.
433 lemma sem_tape_move_obj : tape_move_obj ⊨ R_tape_move_obj.
434 @(Realize_to_Realize … sem_tape_move_obj')
435 #ta #tb * * #Htb1 #Htb2 #Htb3 * [ *
437 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
438 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
439 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
440 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
444 definition restart_tape ≝ λi.
445 inject_TM ? (move_to_end FSUnialpha L) 2 i ·
446 mmove i FSUnialpha 2 R.
449 match_m cfg prg FSUnialpha 2 ·
450 restart_tape cfg · copy prg cfg FSUnialpha 2 ·
451 cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
454 definition legal_tape ≝ λn,l,h,t.
456 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
457 is_config n (bar::state@[char]) →
458 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
459 bar::table = table_TM n l h → *)
461 definition list_of_tape ≝ λsig,t.
462 left sig t@option_cons ? (current ? t) (right ? t).
464 definition low_char' ≝ λc.
467 | Some b ⇒ if (is_bit b) then b else null
470 lemma low_char_option : ∀s.
471 low_char' (option_map FinBool FSUnialpha bit s) = low_char s.
475 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
478 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
479 is_config n (bar::state@[char]) →
481 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
482 bar::table = table_TM n l h →
484 only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
485 let conf ≝ (bar::state@[char]) in
486 (∃ll,lr.bar::table = ll@conf@lr) →
488 ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧
491 tuple_encoding n h t = (conf@nstate@[nchar;m])→
494 tape_move_mono ? (nth obj ? t1 (niltape ?))
495 〈char_to_bit_option nchar,char_to_move m〉 in
496 let next_char ≝ low_char' (current ? new_obj) in
499 (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
502 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
503 mk_tape B (map ?? f (left ? t))
504 (option_map ?? f (current ? t))
505 (map ?? f (right ? t)).
507 lemma map_list_of_tape: ∀A,B,f,t.
508 list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
509 #A #B #f * // normalize // #ls #c #rs <map_append %
512 lemma low_char_current : ∀t.
513 low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
514 = low_char (current FinBool t).
517 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝
518 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
519 [tape_map ?? bit (ctape ?? c);
521 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
522 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
525 lemma obj_low_tapes: ∀M,c.
526 nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
529 lemma cfg_low_tapes: ∀M,c.
530 nth cfg ? (low_tapes M c) (niltape ?) =
532 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
535 lemma prg_low_tapes: ∀M,c.
536 nth prg ? (low_tapes M c) (niltape ?) =
537 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
540 (* commutation lemma for write *)
541 lemma map_write: ∀t,cout.
542 tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
543 = tape_map ?? bit (tape_write ? t cout).
544 #t * // #b whd in match (char_to_bit_option ?);
545 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
548 (* commutation lemma for moves *)
549 lemma map_move: ∀t,m.
550 tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
551 = tape_map ?? bit (tape_move ? t m).
552 #t * // whd in match (char_to_move ?);
553 [cases t // * // | cases t // #ls #a * //]
556 (* commutation lemma for actions *)
557 lemma map_action: ∀t,cout,m.
558 tape_move ? (tape_write ? (tape_map FinBool ? bit t)
559 (char_to_bit_option (low_char cout))) (char_to_move (low_mv m))
560 = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
561 #t #cout #m >map_write >map_move %
564 lemma map_move_mono: ∀t,cout,m.
565 tape_move_mono ? (tape_map FinBool ? bit t)
566 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
567 = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
571 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
572 ∀c:nconfig (no_states M).
574 t2 = low_tapes M (step ? M c).
576 lemma R_unistep_equiv : ∀M,t1,t2.
577 R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
578 R_unistep_high M t1 t2.
579 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
580 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
581 (* tup = current tuple *)
582 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉,
583 ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
584 (* tup is in the graph *)
585 cut (mem ? tup (graph_enum ?? (ntrans M)))
586 [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
587 (* tupe target = 〈qout,cout,m〉 *)
588 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
589 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
591 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
592 [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
593 cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1
596 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
598 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
599 [>Hstep %] #Hnew_tape
600 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
601 (low_char (current ? (ctape ?? c)))
602 (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
605 lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
606 %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
607 >Htable1 @eq_f <associative_append @eq_f2 // >Htup
608 whd in ⊢ (??%?); @eq_f >associative_append %
609 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
610 [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
613 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
614 % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
615 |>length_map whd in match (length ??); @eq_f //]
617 |>Ht1 >cfg_low_tapes //] -H #H
618 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout)
619 (low_mv … m) tup ? Hingraph)
620 [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
621 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi
622 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
623 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
624 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
626 |>Hi >obj_low_tapes >nth_change_vec //
627 >Ht1 >obj_low_tapes >Hstep @map_action
629 |>Hi >cfg_low_tapes >nth_change_vec_neq
630 [|% whd in ⊢ (??%?→?); #H destruct (H)]
631 >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape
632 @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
634 |(* program tapes do not change *)
636 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
637 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
638 >Ht1 >prg_low_tapes //