]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/multi_universal/unistep_aux.ma
progress
[helm.git] / matita / matita / lib / turing / multi_universal / unistep_aux.ma
1 (*
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.           
5     ||I||                                                            
6     ||T||  
7     ||A||  
8     \   /  This file is distributed under the terms of the       
9      \ /   GNU General Public License Version 2   
10       V_____________________________________________________________*)
11
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".
17
18 (*
19
20   in.obj : ...  x ...
21                 ^
22   in.cfg : ...  ? ? ...
23                     ^
24                 
25   out.cfg : ... 1 x ...
26                   ^
27                   
28   ---------------------
29   current (in.obj) = None
30   
31   in.cfg : ...  ? ? ...
32                     ^
33
34   out.cfg : ... 0 0 ...
35                   ^
36                   
37   obj_to_cfg ≝ 
38     move_l(cfg);
39     move_l(cfg);
40     (if (current(in.obj)) == None
41        then write(0,cfg);
42             move_r(cfg);
43             write(0,cfg);
44        else write(1,cfg);
45             move_r(cfg);
46             copy_step(obj,cfg);
47             move_l(obj);)
48     move_to_end_l(cfg);
49     move_r(cfg);
50        
51   
52   cfg_to_obj
53 *)
54
55 definition obj ≝ (0:DeqNat).
56 definition cfg ≝ (1:DeqNat).
57 definition prg ≝ (2:DeqNat).
58
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)
66      tc_true) ·
67   inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
68   mmove cfg FSUnialpha 2 R.
69   
70 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
71   ∀c,ls.
72   nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] → 
73   (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso → 
74    t2 = change_vec ?? t1 
75          (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧
76   (current ? (nth obj ? t1 (niltape ?)) = None ? → 
77    t2 = change_vec ?? t1
78          (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls))) 
79            (tail ? (reverse ? (null::ls)))) cfg).
80            
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.
85   
86 lemma eq_mk_tape_rightof :
87  ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
88 #alpha #a #al %
89 qed.
90
91 axiom daemon : ∀P:Prop.P.
92
93 definition option_cons ≝ λsig.λc:option sig.λl.
94   match c with [ None ⇒ l | Some c0 ⇒ c0::l ].
95
96 lemma tape_move_mk_tape_R :
97   ∀sig,ls,c,rs.
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 * ] ] 
103 normalize //
104 qed.
105
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 ?)
108    (sem_seq ??????
109     (sem_if ??????????
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 ?)))) //
117 #ta #tb *
118 #tc * whd in ⊢ (%→?); #Htc *
119 #td * *
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
125     #c #ls #Hta1 %
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) %
143       ]
144     | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
145       >Hta2 #H destruct (H)
146     ]
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) ]
152   ]
153 | * #te * * #Hcurtc #Hte
154   * whd in ⊢ (%→%→?); #Htd1 #Htd2
155   * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
156   #c #ls #Hta1 %
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/ ]
167 ]
168 qed.
169
170 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
171
172 definition R_test_null_char_true ≝ λt1,t2.
173   current FSUnialpha t1 = Some ? null ∧ t1 = t2.
174   
175 definition R_test_null_char_false ≝ λt1,t2.
176   current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
177   
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} % [ %
182 [ @Hloop
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 ??)) ]
189     #H destruct (H)
190   | <Houtc % ] ]
191 qed.
192
193 definition copy_char_states ≝ initN 3.
194
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 …)).
197
198 definition trans_copy_char ≝ 
199  λsrc,dst.λsig:FinSet.λn.
200  λp:copy_char_states × (Vector (option sig) (S n)).
201  let 〈q,a〉 ≝ p in
202  match pi1 … q with
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〉 ].
207
208 definition copy_char ≝ 
209   λsrc,dst,sig,n.
210   mk_mTM sig n copy_char_states (trans_copy_char src dst sig n) 
211     cc0 (λq.q == cc1).
212
213 definition R_copy_char ≝ 
214   λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
215   outt = change_vec ?? 
216          (change_vec ?? int
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.
220
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) =
224     mk_mconfig ??? cc1 
225      (change_vec ? (S n) 
226        (change_vec ?? 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
230 whd in ⊢ (??%?);
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
236 [ >change_vec_same %
237 | >change_vec_same >change_vec_same // ]
238 qed.
239
240 lemma sem_copy_char:
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 // ]]
245 qed.
246
247 definition cfg_to_obj ≝
248   mmove cfg FSUnialpha 2 L ·
249   (ifTM ?? (inject_TM ? test_null_char 2 cfg)
250     (nop ? 2)
251     (copy_char cfg obj FSUnialpha 2 ·
252      mmove cfg FSUnialpha 2 L ·
253      mmove obj FSUnialpha 2 L) 
254      tc_true) ·
255   inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
256   mmove cfg FSUnialpha 2 R.
257   
258 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
259   ∀c,ls.
260   nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] → 
261   (c = null → 
262    t2 = change_vec ?? t1
263          (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls))) 
264            (tail ? (reverse ? (c::ls)))) cfg) ∧
265   (c ≠ null → 
266    t2 = change_vec ??
267           (change_vec ?? t1
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).
270
271 lemma sem_cfg_to_obj : cfg_to_obj ⊨  R_cfg_to_obj.
272 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
273   (sem_seq ??????
274    (sem_if ??????????
275     (acc_sem_inject ?????? cfg ? sem_test_null_char)
276     (sem_nop …)
277     (sem_seq ?????? (sem_copy_char …)
278      (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
279    (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
280     (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
281 #ta #tb *
282 #tc * whd in ⊢ (%→?); #Htc *
283 #td * *
284 [ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
285   * #tf * * * #Htf1 #Htf2 #Htf3
286   whd in ⊢ (%→?); #Htb
287   #c #ls #Hta %
288   [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
289     cut (te = tc) [@daemon] -Hte1 -Hte2 #Hte
290     cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
291     [@daemon] -Htf1 -Htf2 -Htf3 #Htf
292     destruct (Htf Hte Htc Htb)
293     >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
294     >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ] 
295     >reverse_cons %
296   | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
297     >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?); 
298     #H destruct (H) @False_ind cases Hc /2/ ]
299   * #tf * *
300 | * #te * * * #Hcurtc #Hte1 #Hte2
301   * #tf * whd in ⊢ (%→?); #Htf
302   * #tg * whd in ⊢ (%→%→?); #Htg #Htd
303   * #th * * * #Hth1 #Hth2 #Hth3
304   whd in ⊢ (%→?); #Htb 
305   #c #ls #Hta % #Hc
306   [ cut (te = tc) [ @daemon ] -Hte1 -Hte2 #Hte
307     cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
308     [@daemon] -Hth1 -Hth2 -Hth3 #Hth
309     destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
310     >change_vec_change_vec >change_vec_change_vec
311     >change_vec_commute // >change_vec_change_vec
312     >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
313     >change_vec_commute // >change_vec_change_vec    
314     >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //] 
315     >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
316     >change_vec_commute [|@sym_not_eq //]
317     @eq_f3 //
318     [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
319       [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
320       | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
321     | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
322       >nth_change_vec_neq in Hcurtc1; [|@sym_not_eq //] >Hta2
323       normalize in ⊢ (%→?); #H destruct (H) %
324     ]
325     
326   #c #ls #Hta % #Hc
327   [ >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
328       >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?); >Hc
329       * #H @False_ind /2/
330     | >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
331       cut (te = tc) [@daemon] -Hte1 -Hte2 #Hte
332 qed.
333 *)
334
335 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
336    del current di prg, che codifica la direzione in cui ci muoviamo *)
337
338 definition char_to_move ≝ λc.match c with
339   [ bit b ⇒ if b then R else L
340   | _ ⇒ N].
341
342 definition char_to_bit_option ≝ λc.match c with
343   [ bit b ⇒ Some ? (bit b)
344   | _ ⇒ None ?]. 
345  
346 definition tape_move_obj : mTM FSUnialpha 2 ≝ 
347   ifTM ?? 
348    (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
349    (mmove obj FSUnialpha 2 L)
350    (ifTM ?? 
351     (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
352     (mmove obj FSUnialpha 2 R)
353     (nop ??)
354     tc_true)
355    tc_true.
356
357 definition restart_tape ≝ λi. 
358   inject_TM ? (move_to_end FSUnialpha L) 2 i ·
359   mmove i FSUnialpha 2 R. 
360
361 definition unistep ≝ 
362   match_m cfg prg FSUnialpha 2 · 
363   restart_tape cfg · copy prg cfg FSUnialpha 2 ·
364   cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
365
366 (*
367 definition legal_tape ≝ λn,l,h,t.
368   ∃state,char,table.
369   nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
370   is_config n (bar::state@[char]) →  
371   nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
372   bar::table = table_TM n l h → *)
373
374 definition list_of_tape ≝ λsig,t. 
375   left sig t@option_cons ? (current ? t) (right ? t).
376
377 definition low_char' ≝ λc.
378   match c with
379   [ None ⇒ null 
380   | Some b ⇒ if (is_bit b) then b else null
381   ].
382   
383 lemma low_char_option : ∀s.
384   low_char' (option_map FinBool FSUnialpha bit s) = low_char s.
385 * //
386 qed.
387
388 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
389   ∀state,char,table.
390   (* cfg *)
391   nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
392   is_config n (bar::state@[char]) →  
393   (* prg *)
394   nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
395   bar::table = table_TM n l h →
396   (* obj *)
397   only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
398   let conf ≝ (bar::state@[char]) in
399   (∃ll,lr.bar::table = ll@conf@lr) →
400 (*
401     ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧ 
402     mem ? t l ∧  *)
403     ∀nstate,nchar,m,t. 
404     tuple_encoding n h t = (conf@nstate@[nchar;m])→ 
405     mem ? t l →
406     let new_obj ≝ 
407      tape_move_mono ? (nth obj ? t1 (niltape ?)) 
408        〈char_to_bit_option nchar,char_to_move m〉 in
409     let next_char ≝ low_char' (current ? new_obj) in
410     t2 = 
411       change_vec ??
412         (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
413         new_obj obj.
414
415 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
416   mk_tape B (map ?? f (left ? t)) 
417     (option_map ?? f (current ? t)) 
418     (map ?? f (right ? t)).
419     
420 lemma map_list_of_tape: ∀A,B,f,t.
421   list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
422 #A #B #f * // normalize // #ls #c #rs <map_append %
423 qed.
424
425 lemma low_char_current : ∀t.
426   low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
427   = low_char (current FinBool t).
428 * // qed.
429
430 definition low_tapes ≝ λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
431   [tape_map ?? bit (ctape ?? c);
432    midtape ? [ ] bar 
433     ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
434    midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
435   ].
436   
437 lemma obj_low_tapes: ∀M,c.
438   nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
439 // qed.
440
441 lemma cfg_low_tapes: ∀M,c.
442   nth cfg ? (low_tapes M c) (niltape ?) = 
443   midtape ? [ ] bar 
444     ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
445 // qed.
446
447 lemma prg_low_tapes: ∀M,c.
448   nth prg ? (low_tapes M c) (niltape ?) = 
449   midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
450 // qed.
451
452 (* commutation lemma for write *)
453 lemma map_write: ∀t,cout.
454  tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
455   = tape_map ?? bit (tape_write ? t cout).
456 #t * // #b whd in match (char_to_bit_option ?);
457 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
458 qed.
459
460 (* commutation lemma for moves *)
461 lemma map_move: ∀t,m.
462  tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
463   = tape_map ?? bit (tape_move ? t m).
464 #t * // whd in match (char_to_move ?);
465   [cases t // * // | cases t // #ls #a * //]
466 qed.
467   
468 (* commutation lemma for actions *)
469 lemma map_action: ∀t,cout,m.
470  tape_move ? (tape_write ? (tape_map FinBool ? bit t)
471     (char_to_bit_option (low_char cout))) (char_to_move (low_mv m)) 
472  = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
473 #t #cout #m >map_write >map_move % 
474 qed. 
475
476 lemma map_move_mono: ∀t,cout,m.
477  tape_move_mono ? (tape_map FinBool ? bit t)
478   〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
479  = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
480 @map_action
481 qed. 
482
483 definition R_unistep_high ≝ λM:normalTM.λc:nconfig (no_states M).λt1,t2.
484   t1 = low_tapes M c → 
485   t2 = low_tapes M (step ? M c). 
486
487 lemma R_unistep_equiv : ∀M,c,t1,t2. 
488   R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
489   R_unistep_high M c t1 t2.
490 #M #c #t1 #t2 #H #Ht1
491 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
492 (* tup = current tuple *)
493 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉, 
494              ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
495 (* tup is in the graph *)
496 cut (mem ? tup (graph_enum ?? (ntrans M)))
497   [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
498 (* tupe target = 〈qout,cout,m〉 *)
499 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
500 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
501 (* new config *)
502 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
503   [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
504    cut (trans ? M 〈cstate  … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1 
505    >Heq1 %] #Hstep
506 (* new state *)
507 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
508 (* new tape *)
509 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
510   [>Hstep %] #Hnew_tape
511 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c)) 
512          (low_char (current ? (ctape ?? c)))
513          (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
514          ??????)
515 [<Htable
516  lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll} 
517  %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)} 
518  >Htable1 @eq_f <associative_append @eq_f2 // >Htup
519  whd in ⊢ (??%?); @eq_f >associative_append %
520 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??) 
521   [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
522 |@sym_eq @Htable
523 |>Ht1 %
524 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
525  % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
526       |>length_map whd in match (length ??); @eq_f //]
527    |//]
528 |>Ht1 >cfg_low_tapes //] -H #H 
529 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout) 
530          (low_mv … m) tup ? Hingraph)
531   [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
532 #Ht2 >Ht2 @(eq_vec ? 3 … (niltape ?)) #i #Hi 
533 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
534   [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
535     [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
536       [@False_ind /2/
537       |>Hi >obj_low_tapes >nth_change_vec //
538        >Ht1 >obj_low_tapes >Hstep @map_action 
539       ]
540     |>Hi >cfg_low_tapes >nth_change_vec_neq 
541       [|% whd in ⊢ (??%?→?);  #H destruct (H)]
542      >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape 
543      @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
544     ]
545   |(* program tapes do not change *)
546    >Hi >prg_low_tapes 
547    >nth_change_vec_neq [|% whd in ⊢ (??%?→?);  #H destruct (H)]
548    >nth_change_vec_neq [|% whd in ⊢ (??%?→?);  #H destruct (H)]
549    >Ht1 >prg_low_tapes //
550   ]
551 qed. 
552    
553
554     
555