]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/multi_universal/unistep.ma
Yippeee! Completes proof of soundness of the universal machine
[helm.git] / matita / matita / lib / turing / multi_universal / unistep.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
13 include "turing/multi_universal/unistep_aux.ma".
14
15 definition exec_move ≝ 
16   cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
17
18 definition R_exec_move ≝ λt1,t2:Vector (tape FSUnialpha) 3.
19 ∀c,m,ls1,ls2,rs2.
20   nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls1@[bar]) (None ?) [ ] → 
21   nth prg ? t1 (niltape ?) = midtape FSUnialpha (ls2@[bar]) m rs2 →
22   only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
23   c ≠ bar → m ≠ bar →
24   let new_obj ≝ 
25       tape_move_mono ? (nth obj ? t1 (niltape ?)) 
26         〈char_to_bit_option c, char_to_move m〉 in
27   let next_c ≝ low_char' (current ? new_obj) in 
28   let new_cfg ≝ midtape ? [ ] bar ((reverse ? ls1)@[next_c]) in 
29   let new_prg ≝ midtape FSUnialpha [ ] bar ((reverse ? ls2)@m::rs2) in
30   t2 = Vector_of_list ? [new_obj;new_cfg;new_prg].
31
32
33 lemma sem_exec_move: exec_move ⊨ R_exec_move.
34 @(sem_seq_app ??????? sem_cfg_to_obj1
35   (sem_seq ?????? sem_tape_move_obj
36    (sem_seq ?????? (sem_restart_tape ???) sem_obj_to_cfg1))) //
37 #ta #tout * #t1 * #semM1 * #t2 * #semM2 * #t3 * #semM3 #semM4 
38 #c #m #ls1 #ls2 #rs2 #Hcfg #Hprg #Honlybits #Hc #Hm 
39 (* M1 = cfg_to_obj *)
40 lapply (semM1 … Hcfg Hc) #Ht1 
41 (* M2 = tape_move *)
42 whd in semM2; >Ht1 in semM2; -Ht1
43 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] 
44 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] 
45 >Hprg #Ht2 lapply (Ht2 … (refl ??)) -Ht2
46 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
47 >nth_change_vec // >change_vec_commute [2:@eqb_false_to_not_eq %]
48 >change_vec_change_vec #Ht2 
49 (* M3 = restart prg *) 
50 whd in semM3; >Ht2 in semM3; #semM3 lapply (semM3 … (refl ??)); -semM3
51 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] 
52 >nth_change_vec_neq [2:@eqb_false_to_not_eq %] #Ht3
53 (* M4 = obj_to_cfg *) 
54 whd in semM4; >Ht3 in semM4; 
55 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
56 >nth_change_vec [2:@leb_true_to_le %] #semM4 lapply (semM4 … (refl ??)) -semM4
57 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
58 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
59 >nth_change_vec [2:@leb_true_to_le %] #semM4 >(semM4 ?)
60   [(* tape by tape *)
61    @(eq_vec … (niltape ?)) #i #lei2 
62    cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
63     [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
64       [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
65        >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
66        >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
67        >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
68        >nth_change_vec [2:@leb_true_to_le %] %
69       |#Hi >Hi (* obj tape *)
70        >nth_change_vec [2:@leb_true_to_le %] whd in ⊢ (???%);
71        >reverse_cons >reverse_append >reverse_single 
72        whd in match (option_hd ??); whd in match (tail ??);
73        whd in ⊢ (??%?); %
74       ]
75     |#Hi >Hi (* prg tape *)
76      >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
77      >nth_change_vec [2:@leb_true_to_le %] whd in ⊢ (???%);
78      >Hprg whd in match (list_of_tape ??); >reverse_append
79      >reverse_single % 
80     ]
81   |#b #Hcurrent @(list_of_tape_write ? is_bit … (char_to_bit_option c) ? Honlybits)
82     [#b0 cases c
83       [#b1 whd in ⊢ (??%?→?); #Hbit destruct (Hbit) %
84       |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
85       |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
86       ]
87     |>(list_of_tape_move … (char_to_move m)) @current_in_list @Hcurrent
88     ]
89   ]
90 qed.
91        
92 definition unistep ≝ 
93   match_m cfg prg FSUnialpha 2 · 
94   restart_tape cfg 2 · mmove cfg ? 2 R · copy prg cfg FSUnialpha 2 ·
95   exec_move.
96
97 (*
98 definition legal_tape ≝ λn,l,h,t.
99   ∃state,char,table.
100   nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
101   is_config n (bar::state@[char]) →  
102   nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
103   bar::table = table_TM n l h → *)
104   
105 definition deterministic_tuples ≝ λn,h,l.
106  ∀t1,t2,conf,out1,out2.
107   is_config n conf →
108   mem ? t1 l → mem ? t2 l →
109   tuple_encoding n h t1 = conf@out1 →
110     tuple_encoding n h t2 = conf@out2 → out1 = out2.
111
112 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
113   ∀state,char,table.
114   (* cfg *)
115   nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
116   is_config n (bar::state@[char]) →  
117   (* prg *)
118   nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
119   bar::table = table_TM n l h →
120   (* obj *)
121   only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
122   (* deterministic tuples *)
123   deterministic_tuples n h l →
124   let conf ≝ (bar::state@[char]) in
125   (∃ll,lr.bar::table = ll@conf@lr) →
126 (*
127     ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧ 
128     mem ? t l ∧  *)
129     ∀nstate,nchar,m,t. 
130     tuple_encoding n h t = (conf@nstate@[nchar;m])→ 
131     mem ? t l →
132     let new_obj ≝ 
133      tape_move_mono ? (nth obj ? t1 (niltape ?)) 
134        〈char_to_bit_option nchar,char_to_move m〉 in
135     let next_char ≝ low_char' (current ? new_obj) in
136     t2 = 
137       change_vec ??
138         (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
139         new_obj obj.
140         
141 lemma lt_obj : obj < 3. // qed.
142 lemma lt_cfg : cfg < 3. // qed.
143 lemma lt_prg : prg < 3. // qed.
144
145 definition R_copy_strict ≝ 
146   λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
147   ((current ? (nth src ? int (niltape ?)) = None ? ∨
148     current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧
149   (∀ls,x,x0,rs,ls0,rs0. 
150     nth src ? int (niltape ?) = midtape sig ls x rs →
151     nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 →
152     |rs0| ≤ |rs| → 
153     (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
154      outt = change_vec ?? 
155             (change_vec ?? int  
156               (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
157             (tail sig rs2)) src)
158             (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
159
160 lemma sem_copy_strict : ∀src,dst,sig,n. src ≠ dst → src < S n → dst < S n → 
161   copy src dst sig n ⊨ R_copy_strict src dst sig n.
162 #src #dst #sig #n #Hneq #Hsrc #Hdst @(Realize_to_Realize … (sem_copy …)) //
163 #ta #tb * #Htb1 #Htb2 % [ @Htb1 ]
164 #ls #x #x0 #rs #ls0 #rs0 #Htamid_src #Htamid_dst #Hlen
165 cases (Htb2 … Htamid_src Htamid_dst) -Htb1 -Htb2
166 [ * #rs1 * #rs2 * * #Hrs0 #Heq #Htb <Heq in Hlen; >Hrs0 >length_append
167   >(plus_n_O (|rs1|)) #Hlen cut (|rs2| ≤ 0) [ /2 by le_plus_to_le/ ]
168   #Hlenrs2 cut (rs2 = [ ]) 
169   [ cases rs2 in Hlenrs2; // #r3 #rs3 normalize #H @False_ind cases (not_le_Sn_O (|rs3|)) /2/ ]
170   #Hrs2 destruct (Hrs2) >append_nil in Hrs0; #Hrs0 destruct (Hrs0) -Hlenrs2 -Hlen
171   <plus_n_O <plus_n_O %{rs} %{[ ]} >append_nil % [ % // ] @Htb
172 | * #rs1 * #rs2 #H %{rs1} %{rs2} @H ]
173 qed.
174
175 lemma config_to_len : ∀n,b,q,c.is_config n (b::q@[c]) → |q| = S n.
176 #n #b #q #c * #q0 * #cin * * * #_ #_ #Hq0 #H >(?:q = q0) //
177 lapply (cons_injective_r ????? H) #H1 @(append_l1_injective … H1)
178 lapply (eq_f … (length ?) … H) normalize >length_append >length_append
179 <plus_n_Sm <plus_n_Sm <plus_n_O <plus_n_O #Hlen destruct (Hlen) //
180 qed.
181
182 lemma sem_unistep_low : ∀n,l,h.unistep ⊨ R_unistep n l h.
183 #n #l #h
184 @(sem_seq_app ??????? (sem_match_m cfg prg FSUnialpha 2 ???)
185   (sem_seq ?????? (sem_restart_tape ???)
186    (sem_seq ?????? (sem_move_multi ? 2 cfg R ?)
187     (sem_seq ?????? (sem_copy_strict prg cfg FSUnialpha 2 ???)
188      (sem_exec_move …)))))
189   /2 by le_n,sym_not_eq/
190 #ta #tb #HR #state #char #table #Hta_cfg #Hcfg #Hta_prg #Htable
191 #Hbits_obj #Hdeterm #Hmatching
192 #nstate #nchar #m #t #Htuple #Hmatch
193 cases HR -HR #tc * whd in ⊢ (%→?); 
194 >Hta_cfg #H cases (H ?? (refl ??)) -H 
195 (* prg starts with a bar, so it's not empty *) #_
196 >Hta_prg #H lapply (H ??? (refl ??)) -H *
197 [| cases Hmatching #ll * #lr #H >H 
198    #Hfalse @False_ind cases (Hfalse ll lr) #H1 @H1 //]
199 * #ll * #lr * #Hintable  #Htc
200 * #td * whd in ⊢ (%→?); >Htc
201 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
202 #Htd lapply (Htd ? (refl ??)) -Htd
203 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
204 >(?: list_of_tape ? (mk_tape ? (reverse ? (state@[char])@[bar]) (None ?) [ ]) =
205      bar::state@[char]) 
206 [|whd in ⊢ (??%?); >left_mk_tape >reverse_append >reverse_reverse
207   >current_mk_tape >right_mk_tape [| #_ %2 % ] normalize >append_nil % ]
208 whd in ⊢ (???(???(????%?)??)→?); whd in match (tail ??); #Htd
209 (* move cfg to R *)
210 * #te * whd in ⊢ (%→?); >Htd
211 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
212 >nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec [2:@leb_true_to_le %]
213 cut (∃ll1.ll@[bar] = bar::ll1) 
214 [ cases ll in Hintable; [ #_ %{[ ]} % ] 
215   #llhd #lltl normalize #H destruct (H) %{(lltl@[bar])} % ] * #ll1 #Hll1
216 >Htable in Hintable; #Hintable #Hte
217 (* copy *)
218 lapply (table_to_list ???? Hcfg ?? Hintable) * #out * #lr0 * #t0
219 * * #Hlr #Htuple_t0 #mem_t0 
220 cut (out = nstate@[nchar;m])
221   [@(Hdeterm … Hcfg mem_t0 Hmatch Htuple_t0 Htuple)] #Hout
222 >(append_cons ? nchar) in Htuple; #Htuple
223 lapply (tuple_to_config ?????? Hcfg … Htuple) #newconfig
224 cut (∃fo,so.state = fo::so ∧ |so| = n)
225 [ lapply (config_to_len … Hcfg) cases state [ normalize #H destruct (H) ]
226   #fo #so normalize #H destruct (H) %{fo} %{so} % // ]
227 * #fo * #so * #Hstate_exp #Hsolen
228 cut (∃fn,sn.nstate = fn::sn  ∧ |sn| = n)
229 [ lapply (config_to_len … newconfig) cases nstate [ normalize #H destruct (H) ]
230   #fn #sn normalize #H destruct (H) %{fn} %{sn} % // ]
231 * #fn * #sn * #Hnewstate_exp #Hsnlen
232 >Hstate_exp >Hout in Hlr; >Hnewstate_exp whd in ⊢ (???%→?); #Hlr
233 * #tf * * #_ >Hte >(nth_change_vec ?????? lt_prg)
234 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
235 >Hstate_exp >Hnewstate_exp >Hlr
236 whd in match (mk_tape ????); whd in match (tape_move ???);
237 #Htf cases (Htf ?????? (refl ??) (refl ??) ?) -Htf
238 [| whd in match (tail ??); >length_append >length_append 
239    >Hsolen >length_append >Hsnlen normalize //]
240 #rs1 * #rs2 whd in match (tail ??); * *
241 #Hrs1rs2 #Hrs1len
242 >change_vec_change_vec >change_vec_commute [|@sym_not_eq //]
243 >change_vec_change_vec >append_nil #Htf 
244 (* exec_move *)
245 >append_cons in Hrs1rs2; >associative_append #Hrs1rs2
246 cut ((sn@[nchar])=rs1)
247   [@(append_l1_injective ?????? Hrs1rs2) >Hrs1len 
248    >length_append >length_append normalize >Hsolen >Hsnlen % ] #Hrs1  
249 cut (m::lr0=rs2) [@(append_l2_injective ?????? Hrs1rs2) >Hrs1 % ] #Hrs2 
250 whd in ⊢ (%→?); >Htf >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
251 >nth_change_vec [2:@leb_true_to_le %] 
252 >nth_change_vec [2:@leb_true_to_le %]
253 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
254 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
255 >append_cons <Hrs1 >reverse_append >reverse_single 
256 <Hrs2 >(append_cons … bar ll) >Hll1 >reverse_cons
257 #sem_exec_move 
258 lapply
259   (sem_exec_move ? m ?
260     (([nchar]@reverse FSUnialpha sn)
261           @fn::reverse FSUnialpha (ll1@(fo::so)@[char])) lr0 … (refl ??) ????) 
262   [ cut (tuple_TM (S n) (tuple_encoding n h t)) // >Htuple
263     * #qin * #cin * #qout * #cout * #mv * * * * #_ #Hmv #_ #_
264     normalize >(?: bar::qin@cin::qout@[cout;mv] = (bar::qin@cin::qout@[cout])@[mv])
265     [| normalize >associative_append normalize >associative_append % ] 
266     >(?: bar::(state@[char])@(nstate@[nchar])@[m] = (bar::(state@[char])@(nstate@[nchar]))@[m]) 
267     [|normalize >associative_append >associative_append >associative_append >associative_append >associative_append % ] 
268     #Heq lapply (append_l2_injective_r ?????? Heq) // #H destruct (H) //
269   | cases newconfig #qout * #cout * * * #_ #Hcout #_ #H destruct (H) -H
270     lapply (append_l2_injective_r ?????? e0) // #H destruct (H) @Hcout 
271   |@Hbits_obj
272   |whd in ⊢ (??%?); >associative_append >associative_append 
273    >associative_append  %
274   |#Htb >Htb @(eq_vec … (niltape ?)) (* tape by tape *) #i #lei2 
275    cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
276     [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
277       [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
278        (* obj tape *)
279        >nth_change_vec [2:@leb_true_to_le %] % 
280       |(* cfg tape *) #eqi >eqi
281        >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
282        >nth_change_vec [2:@leb_true_to_le %]  
283        whd in ⊢ (??%?); cut (∀A.∀l:list A.[]@l = l) [//] #Hnil >Hnil
284        >reverse_append >reverse_single >reverse_reverse %
285        (* idem *)
286       ]
287     |(* prg tape *) #eqi >eqi
288       >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
289       >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
290       >Hta_prg whd in ⊢ (??%?); @eq_f @(cons_injective_r ? bar bar)
291       >Htable >Hintable >reverse_append >reverse_cons
292       >reverse_reverse >reverse_cons >reverse_reverse
293       >associative_append >associative_append >associative_append
294       >(append_cons ? bar ll) >Hll1 @eq_f @eq_f <Hstate_exp @eq_f
295       >Hnewstate_exp >Hlr normalize >associative_append >associative_append %
296     ]
297   ]
298 qed.
299
300 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
301   mk_tape B (map ?? f (left ? t)) 
302     (option_map ?? f (current ? t)) 
303     (map ?? f (right ? t)).
304
305 (* da spostare *)
306 lemma map_reverse: ∀A,B,f,l. 
307   map ?? f (reverse A l) = reverse B (map ?? f l).
308 #A #B #f #l elim l //
309 #a #l1 #Hind >reverse_cons >reverse_cons <map_append @eq_f2 //
310 qed.
311
312 lemma map_list_of_tape: ∀A,B,f,t.
313   list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
314 #A #B #f * // 
315   [#a #l normalize >rev_append_def >rev_append_def >append_nil
316    >append_nil <map_append <map_reverse @eq_f2 //
317   |#rs #a #ls normalize >rev_append_def >rev_append_def
318    >append_nil >append_nil <map_append normalize 
319    @eq_f2 //
320   ]
321 qed.
322
323 lemma low_char_current : ∀t.
324   low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
325   = low_char (current FinBool t).
326 * // qed.
327
328 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝ 
329 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
330   [tape_map ?? bit (ctape ?? c);
331    midtape ? [ ] bar 
332     ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
333    midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
334   ].
335
336 lemma obj_low_tapes: ∀M,c.
337   nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
338 // qed.
339
340 lemma cfg_low_tapes: ∀M,c.
341   nth cfg ? (low_tapes M c) (niltape ?) = 
342   midtape ? [ ] bar 
343     ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
344 // qed.
345
346 lemma prg_low_tapes: ∀M,c.
347   nth prg ? (low_tapes M c) (niltape ?) = 
348   midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
349 // qed.
350
351 (* commutation lemma for write *)
352 lemma map_write: ∀t,cout.
353  tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
354   = tape_map ?? bit (tape_write ? t cout).
355 #t * // #b whd in match (char_to_bit_option ?);
356 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
357 qed.
358
359 (* commutation lemma for moves *)
360 lemma map_move: ∀t,m.
361  tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
362   = tape_map ?? bit (tape_move ? t m).
363 #t * // whd in match (char_to_move ?);
364   [cases t // * // | cases t // #ls #a * //]
365 qed.
366   
367 (* commutation lemma for actions *)
368 lemma map_action: ∀t,cout,m.
369  tape_move ? (tape_write ? (tape_map FinBool ? bit t)
370     (char_to_bit_option (low_char cout))) (char_to_move (low_mv m)) 
371  = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
372 #t #cout #m >map_write >map_move % 
373 qed. 
374
375 lemma map_move_mono: ∀t,cout,m.
376  tape_move_mono ? (tape_map FinBool ? bit t)
377   〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
378  = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
379 @map_action
380 qed. 
381
382 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
383 ∀c:nconfig (no_states M).
384   t1 = low_tapes M c → 
385   t2 = low_tapes M (step ? M c). 
386
387 lemma R_unistep_equiv : ∀M,t1,t2. 
388   R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
389   R_unistep_high M t1 t2.
390 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
391 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
392 (* tup = current tuple *)
393 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉, 
394              ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
395 (* tup is in the graph *)
396 cut (mem ? tup (graph_enum ?? (ntrans M)))
397   [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
398 (* tupe target = 〈qout,cout,m〉 *)
399 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
400 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
401 (* new config *)
402 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
403   [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
404    cut (trans ? M 〈cstate  … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1 
405    >Heq1 %] #Hstep
406 (* new state *)
407 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
408 (* new tape *)
409 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
410   [>Hstep %] #Hnew_tape
411 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c)) 
412          (low_char (current ? (ctape ?? c)))
413          (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
414          ???????)        
415 [<Htable
416  lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll} 
417  %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)} 
418  >Htable1 @eq_f <associative_append @eq_f2 // >Htup
419  whd in ⊢ (??%?); @eq_f >associative_append %
420 |#tx #ty #conf #outx #outy #isconf #memx #memy #tuplex #tupley
421  @(deterministic M … (refl ??) memx memy isconf tuplex tupley)
422 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??) 
423   [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
424 |@sym_eq @Htable
425 |>Ht1 %
426 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
427  % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
428       |>length_map whd in match (length ??); @eq_f //]
429    |//]
430 |>Ht1 >cfg_low_tapes //] -H #H 
431 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout) 
432          (low_mv … m) tup ? Hingraph)
433   [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
434 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi 
435 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
436   [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
437     [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
438       [@False_ind /2/
439       |>Hi >obj_low_tapes >nth_change_vec //
440        >Ht1 >obj_low_tapes >Hstep @map_action 
441       ]
442     |>Hi >cfg_low_tapes >nth_change_vec_neq 
443       [|% whd in ⊢ (??%?→?);  #H destruct (H)]
444      >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape 
445      @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
446     ]
447   |(* program tapes do not change *)
448    >Hi >prg_low_tapes 
449    >nth_change_vec_neq [|% whd in ⊢ (??%?→?);  #H destruct (H)]
450    >nth_change_vec_neq [|% whd in ⊢ (??%?→?);  #H destruct (H)]
451    >Ht1 >prg_low_tapes //
452   ]
453 qed.
454
455 lemma sem_unistep : ∀M.unistep ⊨ R_unistep_high M.
456 #M @(Realize_to_Realize … (R_unistep_equiv …)) //
457 qed.