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_____________________________________________________________*)
13 include "turing/multi_universal/unistep_aux.ma".
15 definition exec_move ≝
16 cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
18 definition R_exec_move ≝ λt1,t2:Vector (tape FSUnialpha) 3.
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 ?))) →
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].
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
40 lapply (semM1 … Hcfg Hc) #Ht1
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
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 ?)
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 ??);
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
81 |#b #Hcurrent @(list_of_tape_write ? is_bit … (char_to_bit_option c) ? Honlybits)
83 [#b1 whd in ⊢ (??%?→?); #Hbit destruct (Hbit) %
84 |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
85 |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
87 |>(list_of_tape_move … (char_to_move m)) @current_in_list @Hcurrent
93 match_m cfg prg FSUnialpha 2 ·
94 restart_tape cfg 2 · mmove cfg ? 2 R · copy prg cfg FSUnialpha 2 ·
98 definition legal_tape ≝ λn,l,h,t.
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 → *)
105 definition deterministic_tuples ≝ λn,h,l.
106 ∀t1,t2,conf,out1,out2.
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.
112 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
115 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
116 is_config n (bar::state@[char]) →
118 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
119 bar::table = table_TM n l h →
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) →
127 ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧
130 tuple_encoding n h t = (conf@nstate@[nchar;m])→
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
138 (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
141 lemma lt_obj : obj < 3. // qed.
142 lemma lt_cfg : cfg < 3. // qed.
143 lemma lt_prg : prg < 3. // qed.
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 →
153 (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
156 (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
158 (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
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 ]
175 axiom daemon : ∀P:Prop.P.
177 lemma sem_unistep : ∀n,l,h.unistep ⊨ R_unistep n l h.
179 @(sem_seq_app ??????? (sem_match_m cfg prg FSUnialpha 2 ???)
180 (sem_seq ?????? (sem_restart_tape ???)
181 (sem_seq ?????? (sem_move_multi ? 2 cfg R ?)
182 (sem_seq ?????? (sem_copy_strict prg cfg FSUnialpha 2 ???)
183 (sem_exec_move …)))))
184 /2 by le_n,sym_not_eq/
185 #ta #tb #HR #state #char #table #Hta_cfg #Hcfg #Hta_prg #Htable
186 #Hbits_obj #Hdeterm #Hmatching
187 #nstate #nchar #m #t #Htuple #Hmatch
188 cases HR -HR #tc * whd in ⊢ (%→?);
189 >Hta_cfg #H cases (H ?? (refl ??)) -H
190 (* prg starts with a bar, so it's not empty *) #_
191 >Hta_prg #H lapply (H ??? (refl ??)) -H *
192 [| cases Hmatching #ll * #lr #H >H
193 #Hfalse @False_ind cases (Hfalse ll lr) #H1 @H1 //]
194 * #ll * #lr * #Hintable #Htc
195 * #td * whd in ⊢ (%→?); >Htc
196 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
197 #Htd lapply (Htd ? (refl ??)) -Htd
198 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
199 >(?: list_of_tape ? (mk_tape ? (reverse ? (state@[char])@[bar]) (None ?) [ ]) =
201 [|whd in ⊢ (??%?); >left_mk_tape >reverse_append >reverse_reverse
202 >current_mk_tape >right_mk_tape [| #_ %2 % ] normalize >append_nil % ]
203 whd in ⊢ (???(???(????%?)??)→?); whd in match (tail ??); #Htd
205 * #te * whd in ⊢ (%→?); >Htd
206 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
207 >nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec [2:@leb_true_to_le %]
208 >Htable in Hintable; #Hintable #Hte
210 lapply (table_to_list ???? Hcfg ?? Hintable) * #out * #lr0 * #t0
211 * * #Hlr #Htuple_t0 #mem_t0
212 cut (out = nstate@[nchar;m])
213 [@(Hdeterm … Hcfg mem_t0 Hmatch Htuple_t0 Htuple)] #Hout
214 >(append_cons ? nchar) in Htuple; #Htuple
215 lapply (tuple_to_config ?????? Hcfg … Htuple) #newconfig
216 cut (∃fo,so.state = fo::so ∧ |so| = n)
217 [ @daemon ] * #fo * #so * #Hstate_exp #Hsolen
218 cut (∃fn,sn.nstate = fn::sn ∧ |sn| = n)
219 [ @daemon ] * #fn * #sn * #Hnewstate_exp #Hsnlen
220 >Hstate_exp >Hout in Hlr; >Hnewstate_exp whd in ⊢ (???%→?); #Hlr
221 * #tf * * #_ >Hte >(nth_change_vec ?????? lt_prg)
222 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
223 >Hstate_exp >Hnewstate_exp >Hlr
224 whd in match (mk_tape ????); whd in match (tape_move ???);
225 #Htf cases (Htf ?????? (refl ??) (refl ??) ?) -Htf
226 [| whd in match (tail ??); >length_append >length_append
227 >Hsolen >length_append >Hsnlen normalize //]
228 #rs1 * #rs2 whd in match (tail ??); * *
230 >change_vec_change_vec >change_vec_commute [|@sym_not_eq //]
231 >change_vec_change_vec >append_nil #Htf
233 >append_cons in Hrs1rs2; >associative_append #Hrs1rs2
234 cut ((sn@[nchar])=rs1)
235 [@(append_l1_injective ?????? Hrs1rs2) >Hrs1len
236 >length_append >length_append normalize >Hsolen >Hsnlen % ] #Hrs1
237 cut (m::lr0=rs2) [@(append_l2_injective ?????? Hrs1rs2) >Hrs1 % ] #Hrs2
238 cut (∃ll1. ll@[bar] = bar::ll1)
239 [@daemon (* ll is at the begininng of a table *)] * #ll1 #Hll
240 whd in ⊢ (%→?); >Htf >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
241 >nth_change_vec [2:@leb_true_to_le %]
242 >nth_change_vec [2:@leb_true_to_le %]
243 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
244 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
245 >append_cons <Hrs1 >reverse_append >reverse_single
246 <Hrs2 >(append_cons … bar ll) >Hll >reverse_cons
250 (([nchar]@reverse FSUnialpha sn)
251 @fn::reverse FSUnialpha (ll1@(fo::so)@[char])) lr0 … (refl ??) ????)
255 |whd in ⊢ (??%?); >associative_append >associative_append
256 >associative_append %
257 |#Htb >Htb @(eq_vec … (niltape ?)) (* tape by tape *) #i #lei2
258 cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
259 [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
260 [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
262 >nth_change_vec [2:@leb_true_to_le %] %
263 |(* cfg tape *) #eqi >eqi
264 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
265 >nth_change_vec [2:@leb_true_to_le %]
266 whd in ⊢ (??%?); cut (∀A.∀l:list A.[]@l = l) [//] #Hnil >Hnil
267 >reverse_append >reverse_single >reverse_reverse %
270 |(* prg tape *) #eqi >eqi
271 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
272 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
273 >Hta_prg whd in ⊢ (??%?); @eq_f @(cons_injective_r ? bar bar)
274 >Htable >Hintable >reverse_append >reverse_cons
275 >reverse_reverse >reverse_cons >reverse_reverse
276 >associative_append >associative_append >associative_append
277 >(append_cons ? bar ll) >Hll @eq_f @eq_f <Hstate_exp @eq_f
278 >Hnewstate_exp >Hlr normalize >associative_append >associative_append %
283 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
284 mk_tape B (map ?? f (left ? t))
285 (option_map ?? f (current ? t))
286 (map ?? f (right ? t)).
289 lemma map_reverse: ∀A,B,f,l.
290 map ?? f (reverse A l) = reverse B (map ?? f l).
291 #A #B #f #l elim l //
292 #a #l1 #Hind >reverse_cons >reverse_cons <map_append @eq_f2 //
295 lemma map_list_of_tape: ∀A,B,f,t.
296 list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
298 [#a #l normalize >rev_append_def >rev_append_def >append_nil
299 >append_nil <map_append <map_reverse @eq_f2 //
300 |#rs #a #ls normalize >rev_append_def >rev_append_def
301 >append_nil >append_nil <map_append normalize
306 lemma low_char_current : ∀t.
307 low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
308 = low_char (current FinBool t).
311 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝
312 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
313 [tape_map ?? bit (ctape ?? c);
315 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
316 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
319 lemma obj_low_tapes: ∀M,c.
320 nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
323 lemma cfg_low_tapes: ∀M,c.
324 nth cfg ? (low_tapes M c) (niltape ?) =
326 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
329 lemma prg_low_tapes: ∀M,c.
330 nth prg ? (low_tapes M c) (niltape ?) =
331 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
334 (* commutation lemma for write *)
335 lemma map_write: ∀t,cout.
336 tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
337 = tape_map ?? bit (tape_write ? t cout).
338 #t * // #b whd in match (char_to_bit_option ?);
339 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
342 (* commutation lemma for moves *)
343 lemma map_move: ∀t,m.
344 tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
345 = tape_map ?? bit (tape_move ? t m).
346 #t * // whd in match (char_to_move ?);
347 [cases t // * // | cases t // #ls #a * //]
350 (* commutation lemma for actions *)
351 lemma map_action: ∀t,cout,m.
352 tape_move ? (tape_write ? (tape_map FinBool ? bit t)
353 (char_to_bit_option (low_char cout))) (char_to_move (low_mv m))
354 = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
355 #t #cout #m >map_write >map_move %
358 lemma map_move_mono: ∀t,cout,m.
359 tape_move_mono ? (tape_map FinBool ? bit t)
360 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
361 = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
365 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
366 ∀c:nconfig (no_states M).
368 t2 = low_tapes M (step ? M c).
370 lemma R_unistep_equiv : ∀M,t1,t2.
371 R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
372 R_unistep_high M t1 t2.
373 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
374 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
375 (* tup = current tuple *)
376 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉,
377 ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
378 (* tup is in the graph *)
379 cut (mem ? tup (graph_enum ?? (ntrans M)))
380 [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
381 (* tupe target = 〈qout,cout,m〉 *)
382 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
383 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
385 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
386 [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
387 cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1
390 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
392 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
393 [>Hstep %] #Hnew_tape
394 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
395 (low_char (current ? (ctape ?? c)))
396 (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
399 lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
400 %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
401 >Htable1 @eq_f <associative_append @eq_f2 // >Htup
402 whd in ⊢ (??%?); @eq_f >associative_append %
403 |#tx #ty #conf #outx #outy #isconf #memx #memy #tuplex #tupley
404 @(deterministic M … (refl ??) memx memy isconf tuplex tupley)
405 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
406 [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
409 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
410 % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
411 |>length_map whd in match (length ??); @eq_f //]
413 |>Ht1 >cfg_low_tapes //] -H #H
414 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout)
415 (low_mv … m) tup ? Hingraph)
416 [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
417 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi
418 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
419 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
420 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
422 |>Hi >obj_low_tapes >nth_change_vec //
423 >Ht1 >obj_low_tapes >Hstep @map_action
425 |>Hi >cfg_low_tapes >nth_change_vec_neq
426 [|% whd in ⊢ (??%?→?); #H destruct (H)]
427 >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape
428 @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
430 |(* program tapes do not change *)
432 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
433 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
434 >Ht1 >prg_low_tapes //