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
84 match_m cfg prg FSUnialpha 2 ·
85 restart_tape cfg 2 · mmove cfg ? 2 R · copy prg cfg FSUnialpha 2 ·
86 cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
89 definition legal_tape ≝ λn,l,h,t.
91 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
92 is_config n (bar::state@[char]) →
93 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
94 bar::table = table_TM n l h → *)
96 definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
99 nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) →
100 is_config n (bar::state@[char]) →
102 nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
103 bar::table = table_TM n l h →
105 only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
106 let conf ≝ (bar::state@[char]) in
107 (∃ll,lr.bar::table = ll@conf@lr) →
109 ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧
112 tuple_encoding n h t = (conf@nstate@[nchar;m])→
115 tape_move_mono ? (nth obj ? t1 (niltape ?))
116 〈char_to_bit_option nchar,char_to_move m〉 in
117 let next_char ≝ low_char' (current ? new_obj) in
120 (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg)
123 lemma lt_obj : obj < 3. // qed.
124 lemma lt_cfg : cfg < 3. // qed.
125 lemma lt_prg : prg < 3. // qed.
127 definition R_copy_strict ≝
128 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
129 ((current ? (nth src ? int (niltape ?)) = None ? ∨
130 current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧
131 (∀ls,x,x0,rs,ls0,rs0.
132 nth src ? int (niltape ?) = midtape sig ls x rs →
133 nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 →
135 (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
138 (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
140 (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
142 axiom sem_copy_strict : ∀src,dst,sig,n. src ≠ dst → src < S n → dst < S n →
143 copy src dst sig n ⊨ R_copy_strict src dst sig n.
145 lemma sem_unistep : ∀n,l,h.unistep ⊨ R_unistep n l h.
147 @(sem_seq_app ??????? (sem_match_m cfg prg FSUnialpha 2 ???)
148 (sem_seq ?????? (sem_restart_tape ???)
149 (sem_seq ?????? (sem_move_multi ? 2 cfg R ?)
150 (sem_seq ?????? (sem_copy_strict prg cfg FSUnialpha 2 ???)
151 (sem_seq ?????? sem_cfg_to_obj1
152 (sem_seq ?????? sem_tape_move_obj
153 (sem_seq ?????? (sem_restart_tape ???) sem_obj_to_cfg)))))))
154 /2 by le_n,sym_not_eq/
155 #ta #tb #HR #state #char #table #Hta_cfg #Hcfg #Hta_prg #Htable
156 #Hbits_obj #Htotaltable
157 #nstate #nchar #m #t #Htuple #Hmatch
158 cases HR -HR #tc * whd in ⊢ (%→?);
159 >Hta_cfg #H cases (H ?? (refl ??)) -H
160 (* prg starts with a bar, so it's not empty *) #_
161 >Hta_prg #H lapply (H ??? (refl ??)) -H *
162 [| cases Htotaltable #ll * #lr #H >H
163 #Hfalse @False_ind cases (Hfalse ll lr) #H1 @H1 //]
164 * #ll * #lr * #Hintable -Htotaltable #Htc
165 * #td * whd in ⊢ (%→?); >Htc
166 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
167 #Htd lapply (Htd ? (refl ??)) -Htd
168 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
169 >(?: list_of_tape ? (mk_tape ? (reverse ? (state@[char])@[bar]) (None ?) [ ]) =
171 [|whd in ⊢ (??%?); >left_mk_tape >reverse_append >reverse_reverse
172 >current_mk_tape >right_mk_tape normalize >append_nil % ]
173 whd in ⊢ (???(???(????%?)??)→?); whd in match (tail ??); #Htd
175 * #te * whd in ⊢ (%→?); >Htd
176 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
177 >nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec //
178 >Htable in Hintable; #Hintable #Hte
180 cases (cfg_in_table_to_tuple ???? Hcfg ?? Hintable)
181 #newstate * #m0 * #lr0 * * #Hlr destruct (Hlr) #Hnewcfg #Hm0
182 cut (∃fo,so,co.state = fo::so@[co] ∧ |so| = n)
183 [ @daemon ] * #fo * #so * #co * #Hstate_exp #Hsolen
184 cut (∃fn,sn,cn.newstate = fn::sn@[cn] ∧ |sn| = n)
185 [ @daemon ] * #fn * #sn * #cn * #Hnewstate_exp #Hsnlen
186 * #tf * * #_ >Hte >(nth_change_vec ?????? lt_prg)
187 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
188 >Hstate_exp >Hnewstate_exp
189 whd in match (mk_tape ????); whd in match (tape_move ???);
190 #Htf cases (Htf ?????? (refl ??) (refl ??) ?) -Htf
191 [| whd in match (tail ??); >length_append >length_append
192 >Hsolen >length_append >length_append >Hsnlen
193 <plus_n_Sm <plus_n_Sm <plus_n_Sm <plus_n_O <plus_n_O normalize // ]
194 #rs1 * #rs2 whd in match (tail ??); * *
195 >append_cons #Hrs1rs2 #Hrs1len
196 >change_vec_change_vec >change_vec_commute [|@sym_not_eq //]
197 >change_vec_change_vec #Htf
199 * #tg * whd in ⊢ (%→?); >Htf
200 >nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
201 lapply (append_l1_injective ?????? Hrs1rs2)
202 [ >Hsnlen >Hrs1len >length_append >length_append >length_append >length_append
203 normalize >Hsolen >Hsnlen % ] #Hrs1 <Hrs1 >reverse_append >reverse_single
204 >associative_append #Htg lapply (Htg … (refl ??) Hm0) -Htg
206 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
207 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
213 cut ((mk_tape FSUnialpha []
214 (option_hd FSUnialpha
215 (reverse FSUnialpha (m0::[]@reverse FSUnialpha (sn@[cn])@[fn; bar])))
217 (reverse FSUnialpha (m0::[]@reverse FSUnialpha (sn@[cn])@[fn; bar])))) =
218 midtape ? [ ] bar (fn::sn@[cn;m0]))
219 [cut (reverse FSUnialpha (m0::[]@reverse FSUnialpha (sn@[cn])@[fn; bar]) =
221 [>reverse_cons whd in ⊢ (??(??(??%)?)?); >reverse_append >reverse_reverse
222 >append_cons in ⊢ (???%); % ] #Hrev >Hrev % ] #Hmk_tape >Hmk_tape -Hmk_tape
225 >reverse_append >reverse_append
227 <reverse_cons >reverse_cons
230 >(change_vec_commute ????? cfg prg) [2:@eqb_false_to_not_eq %]
231 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
232 >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
233 lapply (append_l1_injective ?????? Hrs1rs2)
234 [ >Hsnlen >Hrs1len >length_append >length_append >length_append >length_append
235 normalize >Hsolen >Hsnlen % ]
236 #Hrs1 <Hrs1 >reverse_append #Htg cases (Htg ?? (refl ??)) -Htg
246 match_m cfg prg FSUnialpha 2 ·
247 restart_tape cfg · copy prg cfg FSUnialpha 2 ·
248 cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
250 definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
251 mk_tape B (map ?? f (left ? t))
252 (option_map ?? f (current ? t))
253 (map ?? f (right ? t)).
255 lemma map_list_of_tape: ∀A,B,f,t.
256 list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
257 #A #B #f * // normalize // #ls #c #rs <map_append %
260 lemma low_char_current : ∀t.
261 low_char' (current FSUnialpha (tape_map FinBool FSUnialpha bit t))
262 = low_char (current FinBool t).
265 definition low_tapes: ∀M:normalTM.∀c:nconfig (no_states M).Vector ? 3 ≝
266 λM:normalTM.λc:nconfig (no_states M).Vector_of_list ?
267 [tape_map ?? bit (ctape ?? c);
269 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]);
270 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
273 lemma obj_low_tapes: ∀M,c.
274 nth obj ? (low_tapes M c) (niltape ?) = tape_map ?? bit (ctape ?? c).
277 lemma cfg_low_tapes: ∀M,c.
278 nth cfg ? (low_tapes M c) (niltape ?) =
280 ((bits_of_state ? (nhalt M) (cstate ?? c))@[low_char (current ? (ctape ?? c))]).
283 lemma prg_low_tapes: ∀M,c.
284 nth prg ? (low_tapes M c) (niltape ?) =
285 midtape ? [ ] bar (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))).
288 (* commutation lemma for write *)
289 lemma map_write: ∀t,cout.
290 tape_write ? (tape_map FinBool ? bit t) (char_to_bit_option (low_char cout))
291 = tape_map ?? bit (tape_write ? t cout).
292 #t * // #b whd in match (char_to_bit_option ?);
293 whd in ⊢ (??%%); @eq_f3 [elim t // | // | elim t //]
296 (* commutation lemma for moves *)
297 lemma map_move: ∀t,m.
298 tape_move ? (tape_map FinBool ? bit t) (char_to_move (low_mv m))
299 = tape_map ?? bit (tape_move ? t m).
300 #t * // whd in match (char_to_move ?);
301 [cases t // * // | cases t // #ls #a * //]
304 (* commutation lemma for actions *)
305 lemma map_action: ∀t,cout,m.
306 tape_move ? (tape_write ? (tape_map FinBool ? bit t)
307 (char_to_bit_option (low_char cout))) (char_to_move (low_mv m))
308 = tape_map ?? bit (tape_move ? (tape_write ? t cout) m).
309 #t #cout #m >map_write >map_move %
312 lemma map_move_mono: ∀t,cout,m.
313 tape_move_mono ? (tape_map FinBool ? bit t)
314 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉
315 = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉).
319 definition R_unistep_high ≝ λM:normalTM.λt1,t2.
320 ∀c:nconfig (no_states M).
322 t2 = low_tapes M (step ? M c).
324 lemma R_unistep_equiv : ∀M,t1,t2.
325 R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 →
326 R_unistep_high M t1 t2.
327 #M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1
328 lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable
329 (* tup = current tuple *)
330 cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉,
331 ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup
332 (* tup is in the graph *)
333 cut (mem ? tup (graph_enum ?? (ntrans M)))
334 [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph
335 (* tupe target = 〈qout,cout,m〉 *)
336 lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉))
337 * #qout * #cout * #m #Htg >Htg in Htup; #Htup
339 cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m))
340 [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *)
341 cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [<Htg %] #Heq1
344 cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state
346 cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m)
347 [>Hstep %] #Hnew_tape
348 lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
349 (low_char (current ? (ctape ?? c)))
350 (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
353 lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
354 %{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
355 >Htable1 @eq_f <associative_append @eq_f2 // >Htup
356 whd in ⊢ (??%?); @eq_f >associative_append %
357 |>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
358 [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
361 |%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))}
362 % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)]
363 |>length_map whd in match (length ??); @eq_f //]
365 |>Ht1 >cfg_low_tapes //] -H #H
366 lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout)
367 (low_mv … m) tup ? Hingraph)
368 [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H
369 #Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi
370 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
371 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
372 [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
374 |>Hi >obj_low_tapes >nth_change_vec //
375 >Ht1 >obj_low_tapes >Hstep @map_action
377 |>Hi >cfg_low_tapes >nth_change_vec_neq
378 [|% whd in ⊢ (??%?→?); #H destruct (H)]
379 >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape
380 @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current %
382 |(* program tapes do not change *)
384 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
385 >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
386 >Ht1 >prg_low_tapes //