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 copy_char_states ≝ initN 3.
57 definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
58 definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
60 definition trans_copy_char ≝
61 λsrc,dst.λsig:FinSet.λn.
62 λp:copy_char_states × (Vector (option sig) (S n)).
65 [ O ⇒ 〈cc1,change_vec ? (S n)
66 (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
67 (〈nth src ? a (None ?),R〉) dst〉
68 | S _ ⇒ 〈cc1,null_action ? n〉 ].
70 definition copy_char ≝
72 mk_mTM sig n copy_char_states (trans_copy_char src dst sig n)
75 definition R_copy_char ≝
76 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
79 (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
80 (tape_move_mono ? (nth dst ? int (niltape ?))
81 〈current ? (nth src ? int (niltape ?)), R〉) dst.
83 lemma copy_char_q0_q1 :
84 ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n →
85 step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) =
89 (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
90 (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst).
91 #src #dst #sig #n #v #Heq #Hsrc #Hdst
93 <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
94 <(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
95 >tape_move_multi_def @eq_f2 //
96 >pmap_change >pmap_change <tape_move_multi_def
97 >tape_move_null_action @eq_f2 // @eq_f2
99 | >change_vec_same >change_vec_same // ]
103 ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
104 copy_char src dst sig n ⊨ R_copy_char src dst sig n.
105 #src #dst #sig #n #Hneq #Hsrc #Hdst #int
106 %{2} % [| % [ % | whd >copy_char_q0_q1 // ]]
109 definition obj ≝ (0:DeqNat).
110 definition cfg ≝ (1:DeqNat).
111 definition prg ≝ (2:DeqNat).
113 definition obj_to_cfg ≝
114 mmove cfg FSUnialpha 2 L ·
115 (ifTM ?? (inject_TM ? (test_null ?) 2 obj)
116 (copy_char obj cfg FSUnialpha 2 ·
117 mmove cfg FSUnialpha 2 L ·
118 mmove obj FSUnialpha 2 L)
119 (inject_TM ? (write FSUnialpha null) 2 cfg)
121 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
122 mmove cfg FSUnialpha 2 R.
124 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
126 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
127 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
128 t2 = change_vec ?? t1
129 (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧
130 (current ? (nth obj ? t1 (niltape ?)) = None ? →
131 t2 = change_vec ?? t1
132 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls)))
133 (tail ? (reverse ? (null::ls)))) cfg).
135 axiom accRealize_to_Realize :
136 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
137 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
139 lemma eq_mk_tape_rightof :
140 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
144 lemma tape_move_mk_tape_R :
146 (c = None ? → ls = [ ] ∨ rs = [ ]) →
147 tape_move ? (mk_tape sig ls c rs) R =
148 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
149 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
150 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
154 lemma eq_vec_change_vec : ∀sig,n.∀v1,v2:Vector sig n.∀i,t,d.
156 (∀j.i ≠ j → nth j ? v1 d = nth j ? v2 d) →
157 v2 = change_vec ?? v1 t i.
158 #sig #n #v1 #v2 #i #t #d #H1 #H2 @(eq_vec … d)
159 #i0 #Hlt cases (decidable_eq_nat i0 i) #Hii0
160 [ >Hii0 >nth_change_vec //
161 | >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @H2 @sym_not_eq // ]
164 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
165 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
168 (sem_test_null_multi ?? obj ?)
169 (sem_seq ?????? (sem_copy_char …)
170 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
171 (sem_move_multi ? 2 obj L ?)))
172 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
173 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
174 (sem_move_multi ? 2 cfg R ?)))) //
176 #tc * whd in ⊢ (%→?); #Htc *
178 [ * #te * * #Hcurtc #Hte
179 * destruct (Hte) #te * whd in ⊢ (%→?); #Hte
180 cut (∃x.current ? (nth obj ? tc (niltape ?)) = Some ? x)
181 [ cases (current ? (nth obj ? tc (niltape ?))) in Hcurtc;
182 [ * #H @False_ind /2/ | #x #_ %{x} % ] ] * #x #Hcurtc'
183 (* [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte *)
184 * #tf * whd in ⊢ (%→%→?); #Htf #Htd
185 * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb
187 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
188 whd in match (tape_move ???); #Htc
189 cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
190 [ lapply (eq_vec_change_vec ??????? (Htg2 ls x [ ] ?) Htg3) //
191 >Htd >nth_change_vec_neq // >Htf >nth_change_vec //
192 >Hte >Hcurtc' >nth_change_vec // >Htc >nth_change_vec // ]
193 -Htg1 -Htg2 -Htg3 #Htg destruct
194 >change_vec_change_vec >change_vec_change_vec
195 >change_vec_commute // >change_vec_change_vec
196 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
197 >change_vec_commute // >change_vec_change_vec
198 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
199 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
200 >change_vec_commute [|@sym_not_eq //] @eq_f3 //
201 [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
202 [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
203 | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
204 | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
205 >nth_change_vec_neq in Hcurtc'; [|@sym_not_eq //] >Hta2
206 normalize in ⊢ (%→?); #H destruct (H) %
208 | #Hta2 >Htc in Hcurtc'; >nth_change_vec_neq [| @sym_not_eq //]
209 >Hta2 #H destruct (H)
211 | * #te * * #Hcurtc #Hte
212 * whd in ⊢ (%→%→?); #Htd1 #Htd2
213 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
215 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
216 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
217 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
218 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
219 [ lapply (eq_vec_change_vec ??????? (Htd1 ls c [ ] ?) Htd2) //
220 >Htc >nth_change_vec // ] -Htd1 -Htd2 #Htd
221 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
222 [ lapply (eq_vec_change_vec ??????? (Htf2 ls null [ ] ?) Htf3) //
223 >Htd >nth_change_vec // ] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
224 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
225 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
226 >reverse_cons >tape_move_mk_tape_R /2/ ]
230 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
232 definition R_test_null_char_true ≝ λt1,t2.
233 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
235 definition R_test_null_char_false ≝ λt1,t2.
236 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
238 lemma sem_test_null_char :
239 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
240 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
241 #Hfalse %{k} %{outc} % [ %
243 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
244 -Hcnull #H destruct (H) #Houtc1 %
245 [ @Hcurt1 | <Houtc1 % ] ]
246 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
247 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
248 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
253 definition cfg_to_obj ≝
254 mmove cfg FSUnialpha 2 L ·
255 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
257 (copy_char cfg obj FSUnialpha 2 ·
258 mmove cfg FSUnialpha 2 L ·
259 mmove obj FSUnialpha 2 L)
261 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
262 mmove cfg FSUnialpha 2 R.
264 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
266 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
268 t2 = change_vec ?? t1
269 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
270 (tail ? (reverse ? (c::ls)))) cfg) ∧
274 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
275 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
277 lemma tape_move_mk_tape_L :
279 (c = None ? → ls = [ ] ∨ rs = [ ]) →
280 tape_move ? (mk_tape sig ls c rs) L =
281 mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs).
282 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
283 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
287 lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
288 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
291 (acc_sem_inject ?????? cfg ? sem_test_null_char)
293 (sem_seq ?????? (sem_copy_char …)
294 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
295 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
296 (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
298 #tc * whd in ⊢ (%→?); #Htc *
300 [ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
301 * #tf * * * #Htf1 #Htf2 #Htf3
304 [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
306 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2) >change_vec_same // ]
308 cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
309 [ lapply (eq_vec_change_vec ??????? (Htf2 ls c [ ] ?) Htf3) //
310 >Hte >Htc >nth_change_vec // ] -Htf1 -Htf2 -Htf3 #Htf
311 destruct (Htf Hte Htc Htb)
312 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
313 >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ]
315 | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
316 >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?);
317 #H destruct (H) @False_ind cases Hc /2/ ]
319 | * #te * * * #Hcurtc #Hte1 #Hte2
320 * #tf * whd in ⊢ (%→?); #Htf
321 * #tg * whd in ⊢ (%→%→?); #Htg #Htd
322 * #th * * * #Hth1 #Hth2 #Hth3
325 [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L //
326 >Hc normalize in ⊢ (%→?); * #H @False_ind /2/
328 [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2)
329 >change_vec_same // ] -Hte1 -Hte2 #Hte
330 cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
331 [ lapply (eq_vec_change_vec ??????? (Hth2 ls c [ ] ?) Hth3) //
332 >Htd >nth_change_vec_neq // >Htg >nth_change_vec //
333 >Htf >nth_change_vec_neq // >nth_change_vec //
334 >Hte >Htc >nth_change_vec // >Hta // ] -Hth1 -Hth2 -Hth3 #Hth
335 destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
336 >change_vec_change_vec >change_vec_change_vec
337 >change_vec_commute // >change_vec_change_vec
338 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
339 >change_vec_commute // >change_vec_change_vec
340 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
341 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
342 >change_vec_commute [|@sym_not_eq //]
344 [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??);
345 @eq_f2 // cases (nth obj ? ta (niltape ?))
346 [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try %
348 | >reverse_cons >tape_move_mk_tape_R // #_ % % ]
353 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
354 del current di prg, che codifica la direzione in cui ci muoviamo *)
356 definition char_to_move ≝ λc.match c with
357 [ bit b ⇒ if b then R else L
360 definition char_to_bit_option ≝ λc.match c with
361 [ bit b ⇒ Some ? (bit b)
364 definition tape_move_obj : mTM FSUnialpha 2 ≝
366 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
367 (mmove obj FSUnialpha 2 L)
369 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
370 (mmove obj FSUnialpha 2 R)
375 definition R_tape_move_obj' ≝ λt1,t2:Vector (tape FSUnialpha) 3.
376 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit false) →
377 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) L) obj) ∧
378 (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit true) →
379 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) R) obj) ∧
380 (current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit false) →
381 current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit true) →
384 lemma sem_tape_move_obj' : tape_move_obj ⊨ R_tape_move_obj'.
385 #ta cases (sem_if ??????????
386 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit false)))
387 (sem_move_multi ? 2 obj L ?)
389 (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit true)))
390 (sem_move_multi ? 2 obj R ?)
392 #i * #outc * #Hloop #HR %{i} %{outc} % [@Hloop] -i
394 [ * #tb * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htb1 #Htb2
395 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
396 [ >Hcurta_prg #H destruct (H) >(?:tb = ta)
397 [| lapply (eq_vec_change_vec ??????? Htb1 Htb2)
398 >change_vec_same // ] %
399 | >Hcurta_prg #H destruct (H) destruct (Hc) ]
400 | >Hcurta_prg >Hc * #H @False_ind /2/ ]
401 | * #tb * * * #Hnotfalse #Htb1 #Htb2 cut (tb = ta)
402 [ lapply (eq_vec_change_vec ??????? Htb1 Htb2)
403 >change_vec_same // ] -Htb1 -Htb2 #Htb destruct (Htb) *
404 [ * #tc * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htc1 #Htc2
405 whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ %
406 [ >Hcurta_prg #H destruct (H) destruct (Hc)
407 | >Hcurta_prg #H destruct (H) >(?:tc = ta)
408 [| lapply (eq_vec_change_vec ??????? Htc1 Htc2)
409 >change_vec_same // ] % ]
410 | >Hcurta_prg >Hc #_ * #H @False_ind /2/ ]
411 | * #tc * * * #Hnottrue #Htc1 #Htc2 cut (tc = ta)
412 [ lapply (eq_vec_change_vec ??????? Htc1 Htc2)
413 >change_vec_same // ] -Htc1 -Htc2
414 #Htc destruct (Htc) whd in ⊢ (%→?); #Houtc % [ %
415 [ #Hcurta_prg lapply (\Pf (Hnotfalse ? Hcurta_prg)) * #H @False_ind /2/
416 | #Hcurta_prg lapply (\Pf (Hnottrue ? Hcurta_prg)) * #H @False_ind /2/ ]
422 definition R_tape_move_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
423 ∀c. current ? (nth prg ? t1 (niltape ?)) = Some ? c →
424 t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) (char_to_move c)) obj.
426 lemma sem_tape_move_obj : tape_move_obj ⊨ R_tape_move_obj.
427 @(Realize_to_Realize … sem_tape_move_obj')
428 #ta #tb * * #Htb1 #Htb2 #Htb3 * [ *
430 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
431 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
432 | #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???);
433 >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H)
437 definition list_of_tape ≝ λsig.λt:tape sig.
438 reverse ? (left ? t)@option_cons ? (current ? t) (right ? t).
440 definition restart_tape ≝ λi,n.
441 mmove i FSUnialpha n L ·
442 inject_TM ? (move_to_end FSUnialpha L) n i ·
443 mmove i FSUnialpha n R.
445 definition R_restart_tape ≝ λi,n.λint,outt:Vector (tape FSUnialpha) (S n).
446 ∀t.t = nth i ? int (niltape ?) →
447 outt = change_vec ?? int
448 (mk_tape ? [ ] (option_hd ? (list_of_tape ? t)) (tail ? (list_of_tape ? t))) i.
450 lemma sem_restart_tape : ∀i,n.i < S n → restart_tape i n ⊨ R_restart_tape i n.
452 @(sem_seq_app ??????? (sem_move_multi ? n i L ?)
453 (sem_seq ?????? (sem_inject ???? i ? (sem_move_to_end_l ?))
454 (sem_move_multi ? n i R ?))) [1,2,3:@le_S_S_to_le //]
455 #ta #tb * #tc * whd in ⊢ (%→?); #Htc
456 * #td * * * #Htd1 #Htd2 #Htd3
457 whd in ⊢ (%→?); #Htb *
458 [ #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
459 cut (td = tc) [@daemon]
460 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
461 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
463 | #r0 #rs0 #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
464 cut (td = tc) [@daemon]
465 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
466 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
468 | #l0 #ls0 #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
469 cut (td = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls0@[l0])) i)
471 #Htd >Htd in Htb; >Htc >change_vec_change_vec >change_vec_change_vec
472 >nth_change_vec // #Htb >Htb <(reverse_reverse ? ls0) in ⊢ (???%);
473 cases (reverse ? ls0)
475 | #l1 #ls1 >reverse_cons
476 >(?: list_of_tape ? (rightof ? l0 (reverse ? ls1@[l1])) =
478 [|change with (reverse ??@?) in ⊢ (??%?);
479 whd in match (left ??); >reverse_cons >reverse_append
480 whd in ⊢ (??%?); @eq_f >reverse_reverse normalize >append_nil % ] % ]
482 [ #c #rs #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
483 cut (td = tc) [@daemon]
484 (* >Htc in Htd1; >nth_change_vec // *) -Htd1 -Htd2 -Htd3
485 #Htd >Htd in Htb; >Htc >change_vec_change_vec >nth_change_vec //
487 | #l0 #ls0 #c #rs #Hta_i <Hta_i in Htc; whd in ⊢ (???(????%?)→?); #Htc
488 cut (td = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls0@l0::c::rs)) i)
490 #Htd >Htd in Htb; >Htc >change_vec_change_vec >change_vec_change_vec
491 >nth_change_vec // #Htb >Htb <(reverse_reverse ? ls0) in ⊢ (???%);
492 cases (reverse ? ls0)
494 | #l1 #ls1 >reverse_cons
495 >(?: list_of_tape ? (midtape ? (l0::reverse ? ls1@[l1]) c rs) =
497 [|change with (reverse ??@?) in ⊢ (??%?);
498 whd in match (left ??); >reverse_cons >reverse_append
499 whd in ⊢ (??%?); @eq_f >reverse_reverse normalize
500 >associative_append % ] % ]
506 match_m cfg prg FSUnialpha 2 ·
507 restart_tape cfg 2 · mmove cfg ? 2 R · copy prg cfg FSUnialpha 2 ·
508 cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
511 definition legal_tape ≝ λn,l,h,t.
513 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
514 is_config n (bar::state@[char]) →
515 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
516 bar::table = table_TM n l h → *)
518 definition low_char' ≝ λc.
521 | Some b ⇒ if (is_bit b) then b else null
524 lemma low_char_option : ∀s.
525 low_char' (option_map FinBool FSUnialpha bit s) = low_char s.
529 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
532 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
533 is_config n (bar::state@[char]) →
535 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
536 bar::table = table_TM n l h →
538 only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
539 let conf ≝ (bar::state@[char]) in
540 (∃ll,lr.bar::table = ll@conf@lr) →
542 ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧
545 tuple_encoding n h t = (conf@nstate@[nchar;m])→
548 tape_move_mono ? (nth obj ? t1 (niltape ?))
549 〈char_to_bit_option nchar,char_to_move m〉 in
550 let next_char ≝ low_char' (current ? new_obj) in
553 (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
556 lemma lt_obj : obj < 3. // qed.
557 lemma lt_cfg : cfg < 3. // qed.
558 lemma lt_prg : prg < 3. // qed.
560 definition R_copy_strict ≝
561 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
562 ((current ? (nth src ? int (niltape ?)) = None ? ∨
563 current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧
564 (∀ls,x,x0,rs,ls0,rs0.
565 nth src ? int (niltape ?) = midtape sig ls x rs →
566 nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 →
568 (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
571 (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
573 (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
575 axiom sem_copy_strict : ∀src,dst,sig,n. src ≠ dst → src < S n → dst < S n →
576 copy src dst sig n ⊨ R_copy_strict src dst sig n.
578 lemma sem_unistep : ∀n,l,h.unistep ⊨ R_unistep n l h.
580 @(sem_seq_app ??????? (sem_match_m cfg prg FSUnialpha 2 ???)
581 (sem_seq ?????? (sem_restart_tape ???)
582 (sem_seq ?????? (sem_move_multi ? 2 cfg R ?)
583 (sem_seq ?????? (sem_copy_strict prg cfg FSUnialpha 2 ???)
584 (sem_seq ?????? sem_cfg_to_obj
585 (sem_seq ?????? sem_tape_move_obj
586 (sem_seq ?????? (sem_restart_tape ???) sem_obj_to_cfg)))))))
587 /2 by le_n,sym_not_eq/
588 #ta #tb #HR #state #char #table #Hta_cfg #Hcfg #Hta_prg #Htable
589 #Hbits_obj #Htotaltable
590 #nstate #nchar #m #t #Htuple #Hmatch
591 cases HR -HR #tc * whd in ⊢ (%→?);
592 >Hta_cfg #H cases (H ?? (refl ??)) -H
593 (* prg starts with a bar, so it's not empty *) #_
594 >Hta_prg #H lapply (H ??? (refl ??)) -H *
595 [| cases Htotaltable #ll * #lr #H >H
596 #Hfalse @False_ind cases (Hfalse ll lr) #H1 @H1 //]
597 * #ll * #lr * #Hintable -Htotaltable #Htc
598 * #td * whd in ⊢ (%→?); >Htc
599 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
600 #Htd lapply (Htd ? (refl ??)) -Htd
601 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
602 >(?: list_of_tape ? (mk_tape ? (reverse ? (state@[char])@[bar]) (None ?) [ ]) =
604 [|whd in ⊢ (??%?); >left_mk_tape >reverse_append >reverse_reverse
605 >current_mk_tape >right_mk_tape normalize >append_nil % ]
606 whd in ⊢ (???(???(????%?)??)→?); whd in match (tail ??); #Htd
608 * #te * whd in ⊢ (%→?); >Htd
609 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
610 >nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec //
611 >Htable in Hintable; #Hintable #Hte
613 cases (cfg_in_table_to_tuple ???? Hcfg ?? Hintable)
614 #newstate * #m0 * #lr0 * * #Hlr destruct (Hlr) #Hnewcfg #Hm0
615 cut (∃fo,so,co.state = fo::so@[co] ∧ |so| = n)
616 [ @daemon ] * #fo * #so * #co * #Hstate_exp #Hsolen
617 cut (∃fn,sn,cn.newstate = fn::sn@[cn] ∧ |sn| = n)
618 [ @daemon ] * #fn * #sn * #cn * #Hnewstate_exp #Hsnlen
619 * #tf * * #_ >Hte >(nth_change_vec ?????? lt_prg)
620 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
621 >Hstate_exp >Hnewstate_exp
622 whd in match (mk_tape ????); whd in match (tape_move ???);
623 #Htf cases (Htf ?????? (refl ??) (refl ??) ?)
624 [| whd in match (tail ??); >length_append >length_append
625 >Hsolen >length_append >length_append >Hsnlen
626 <plus_n_Sm <plus_n_Sm <plus_n_Sm <plus_n_O <plus_n_O normalize // ]
627 #rs1 * #rs2 whd in match (tail ??); * *
628 >append_cons #Hrs1rs2 #Hrs1len
629 >change_vec_change_vec >change_vec_commute [|@sym_not_eq //]
630 >change_vec_change_vec #Htf
632 * #tg * whd in ⊢ (%→?); >Htf
633 >nth_change_vec_neq [|@sym_not_eq //]
634 >(nth_change_vec ?????? lt_cfg)
635 lapply (append_l1_injective ?????? Hrs1rs2)
636 [ >Hsnlen >Hrs1len >length_append >length_append >length_append >length_append
637 normalize >Hsolen >Hsnlen % ]
638 #Hrs1 <Hrs1 >reverse_append #Htg cases (Htg ?? (refl ??)) -Htg #Htg1 #Htg2
646 match_m cfg prg FSUnialpha 2 ·
647 restart_tape cfg · copy prg cfg FSUnialpha 2 ·
648 cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
650 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
651 mk_tape B (map ?? f (left ? t))
652 (option_map ?? f (current ? t))
653 (map ?? f (right ? t)).
655 lemma map_list_of_tape: ∀A,B,f,t.
656 list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
657 #A #B #f * // normalize // #ls #c #rs <map_append %
660 lemma low_char_current : ∀t.
661 low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
662 = low_char (current FinBool t).
665 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝
666 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
667 [tape_map ?? bit (ctape ?? c);
669 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
670 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
673 lemma obj_low_tapes: ∀M,c.
674 nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
677 lemma cfg_low_tapes: ∀M,c.
678 nth cfg ? (low_tapes M c) (niltape ?) =
680 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
683 lemma prg_low_tapes: ∀M,c.
684 nth prg ? (low_tapes M c) (niltape ?) =
685 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
688 (* commutation lemma for write *)
689 lemma map_write: ∀t,cout.
690 tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
691 = tape_map ?? bit (tape_write ? t cout).
692 #t * // #b whd in match (char_to_bit_option ?);
693 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
696 (* commutation lemma for moves *)
697 lemma map_move: ∀t,m.
698 tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
699 = tape_map ?? bit (tape_move ? t m).
700 #t * // whd in match (char_to_move ?);
701 [cases t // * // | cases t // #ls #a * //]
704 (* commutation lemma for actions *)
705 lemma map_action: ∀t,cout,m.
706 tape_move ? (tape_write ? (tape_map FinBool ? bit t)
707 (char_to_bit_option (low_char cout))) (char_to_move (low_mv m))
708 = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
709 #t #cout #m >map_write >map_move %
712 lemma map_move_mono: ∀t,cout,m.
713 tape_move_mono ? (tape_map FinBool ? bit t)
714 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
715 = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
719 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
720 ∀c:nconfig (no_states M).
722 t2 = low_tapes M (step ? M c).
724 lemma R_unistep_equiv : ∀M,t1,t2.
725 R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
726 R_unistep_high M t1 t2.
727 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
728 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
729 (* tup = current tuple *)
730 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉,
731 ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
732 (* tup is in the graph *)
733 cut (mem ? tup (graph_enum ?? (ntrans M)))
734 [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
735 (* tupe target = 〈qout,cout,m〉 *)
736 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
737 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
739 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
740 [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
741 cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1
744 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
746 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
747 [>Hstep %] #Hnew_tape
748 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
749 (low_char (current ? (ctape ?? c)))
750 (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
753 lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
754 %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
755 >Htable1 @eq_f <associative_append @eq_f2 // >Htup
756 whd in ⊢ (??%?); @eq_f >associative_append %
757 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
758 [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
761 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
762 % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
763 |>length_map whd in match (length ??); @eq_f //]
765 |>Ht1 >cfg_low_tapes //] -H #H
766 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout)
767 (low_mv … m) tup ? Hingraph)
768 [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
769 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi
770 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
771 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
772 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
774 |>Hi >obj_low_tapes >nth_change_vec //
775 >Ht1 >obj_low_tapes >Hstep @map_action
777 |>Hi >cfg_low_tapes >nth_change_vec_neq
778 [|% whd in ⊢ (??%?→?); #H destruct (H)]
779 >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape
780 @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
782 |(* program tapes do not change *)
784 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
785 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
786 >Ht1 >prg_low_tapes //