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/simple_machines.ma".
13 include "turing/multi_universal/unistep_aux.ma".
15 axiom sem_unistep: ∀M. unistep ⊨ R_unistep_high M.
18 match c with [ bit b ⇒ notb b | _ ⇒ true].
21 ifTM ?? (mtestR ? cfg 2 stop)
22 (single_finalTM ?? unistep)
23 (nop …) (mtestR_acc ? cfg 2 stop).
25 definition acc_body : states ?? uni_body ≝ (inr … (inl … (inr … start_nop))).
27 definition ub_R_true ≝ λM,t1,t2.
28 ∀c: nconfig (no_states M).
30 t2=low_tapes M (step FinBool M c) ∧ halt ? M (cstate … c) = false.
32 definition ub_R_false ≝ λM,t1,t2.
33 ∀c: nconfig (no_states M).
34 t1 = low_tapes M c → t1 = t2 ∧ halt ? M (cstate … c) = true.
36 lemma sem_uni_body: ∀M.
37 uni_body ⊨ [acc_body: ub_R_true M, ub_R_false M].
39 @(acc_sem_if_app ????????????
40 (sem_mtestR ? cfg 2 stop (le_S ?? (le_n 1)))
43 [#t1 #t2 #t3 whd in ⊢ (%→?); #Htest #Ht2 * #q #Mt #Ht1
44 >Ht1 in Htest; >cfg_low_tapes whd in match (bits_of_state ???);
45 #Htest lapply (Htest … (refl ??)) * <Ht1 #Ht3 #Hstop >Ht3 in Ht2;
46 #Ht2 % [@Ht2 //] lapply Hstop whd in match (nhalt ??);
47 cases (nhalt M q) whd in match (stop ?); * /2/
48 |#t1 #t2 #t3 whd in ⊢ (%→?); #Htest #Hnop >Hnop -Hnop * #q #Mt #Ht1 >Ht1 in Htest;
49 >cfg_low_tapes whd in match (bits_of_state ???);
50 #Htest lapply (Htest … (refl ??)) whd in match (nhalt ??);
51 cases (nhalt M q) whd in match (stop ?); * /2/
55 definition universalTM ≝ whileTM ?? uni_body acc_body.
57 definition low_R ≝ λM,q,R.λt1,t2:Vector (tape FSUnialpha) 3.
58 ∀Mt. t1 = low_tapes M (mk_config ?? q Mt) →
59 ∃cout. R Mt (ctape … cout) ∧
60 halt ? M (cstate … cout) = true ∧ t2 = low_tapes M cout.
62 theorem sem_universal: ∀M:normalTM. ∀q.
63 universalTM ⊫ low_R M q (R_TM FinBool M q).
64 #M #q #intape #i #outc #Hloop
65 lapply (sem_while … (sem_uni_body M … ) intape i outc Hloop) [%] -Hloop
66 * #ta * #Hstar lapply q -q @(star_ind_l ??????? Hstar) -Hstar
67 [#q whd in ⊢ (%→?); #HFalse whd #Mt #Hta
68 lapply (HFalse … Hta) * #Hta1 #Hhalt %{(mk_config ?? q Mt)} %
69 [%[%{1} %{(mk_config ?? q Mt)} % // whd in ⊢ (??%?); >Hhalt % |@Hhalt]
72 |#t1 #t2 whd in ⊢ (%→?); #Hstep #Hstar #IH #q #Hta whd #Mt #Ht1
73 lapply (Hstep … Ht1) * -Hstep #Ht2 #Hhalt
74 lapply(IH (cstate … (step FinBool M (mk_config ?? q Mt))) Hta ??) [@Ht2|skip] -IH
75 * #cout * * #HRTM #Hhalt1 #Houtc
77 %[%[cases HRTM #k * #outc1 * <config_expand #Hloop #Houtc1
79 [whd in ⊢ (??%?); >Hhalt whd in ⊢ (??%?); @Hloop
88 theorem sem_universal2: ∀M:normalTM. ∀R.
89 M ⊫ R → universalTM ⊫ (low_R M (start ? M) R).
90 #M #R #HMR lapply (sem_universal … M (start ? M)) @WRealize_to_WRealize
91 #t1 #t2 whd in ⊢ (%→%); #H #tape1 #Htape1 cases (H ? Htape1)
92 #c * * #HRTM #Hhalt #Ht2 %{c}
93 % [% [@(R_TM_to_R … HRTM) @HMR | //] | //]
96 axiom terminate_UTM: ∀M:normalTM.∀t.
97 M ↓ t → universalTM ↓ (low_tapes M (mk_config ?? (start ? M) t)).
106 lemma current_embedding: ∀c.
107 high_c (〈match c with [None ⇒ null | Some b ⇒ bit b],false〉) = c.
110 lemma tape_embedding: ∀ls,c,rs.
112 (map ?? (λb.〈bit b,false〉) ls)
113 (〈match c with [None ⇒ null | Some b ⇒ bit b],false〉)
114 (map ?? (λb.〈bit b,false〉) rs) = mk_tape ? ls c rs.
115 #ls #c #rs >high_tape_eq >bool_embedding >bool_embedding
119 definition high_move ≝ λc,mv.
121 [ bit b ⇒ Some ? 〈b,move_of_unialpha mv〉
125 definition map_move ≝
126 λc,mv.match c with [ null ⇒ None ? | _ ⇒ Some ? 〈c,false,move_of_unialpha mv〉 ].
128 definition low_step_R_true ≝ λt1,t2.
130 ∀c: nconfig (no_states M).
131 t1 = low_config M c →
132 halt ? M (cstate … c) = false ∧
133 t2 = low_config M (step ? M c).
135 definition low_tape_aux : ∀M:normalTM.tape FinBool → tape STape ≝
137 let current_low ≝ match current … t with
138 [ None ⇒ None ? | Some b ⇒ Some ? 〈bit b,false〉] in
139 let low_left ≝ map … (λb.〈bit b,false〉) (left … t) in
140 let low_right ≝ map … (λb.〈bit b,false〉) (right … t) in
141 mk_tape STape low_left current_low low_right.
143 lemma left_of_low_tape: ∀M,t.
144 left ? (low_tape_aux M t) = map … (λb.〈bit b,false〉) (left … t).
148 lemma right_of_low_tape: ∀M,t.
149 right ? (low_tape_aux M t) = map … (λb.〈bit b,false〉) (right … t).
153 definition low_move ≝ λaction:option (bool × move).
156 |Some act ⇒ Some ? (〈〈bit (\fst act),false〉,\snd act〉)].
158 (* simulation lemma *)
159 lemma low_tape_move : ∀M,action,t.
160 tape_move STape (low_tape_aux M t) (low_move action) =
161 low_tape_aux M (tape_move FinBool t action).
163 * #b #mv #t cases mv cases t //
164 [#ls #c #rs cases ls //|#ls #c #rs cases rs //]
167 lemma left_of_lift: ∀ls,c,rs. left ? (lift_tape ls c rs) = ls.
168 #ls * #c #b #rs cases c // cases ls // cases rs //
171 lemma right_of_lift: ∀ls,c,rs. legal_tape ls c rs →
172 right ? (lift_tape ls c rs) = rs.
173 #ls * #c #b #rs * #_ cases c // cases ls cases rs // #a #tll #b #tlr
174 #H @False_ind cases H [* [#H1 /2/ |#H1 destruct] |#H1 destruct]
178 lemma current_of_lift: ∀ls,c,b,rs. legal_tape ls 〈c,b〉 rs →
179 current STape (lift_tape ls 〈c,b〉 rs) =
180 match c with [null ⇒ None ? | _ ⇒ Some ? 〈c,b〉].
181 #ls #c #b #rs cases c // whd in ⊢ (%→?); * #_
182 * [* [#Hnull @False_ind /2/ | #Hls >Hls whd in ⊢ (??%%); cases rs //]
183 |#Hrs >Hrs whd in ⊢ (??%%); cases ls //]
186 lemma current_of_lift_None: ∀ls,c,b,rs. legal_tape ls 〈c,b〉 rs →
187 current STape (lift_tape ls 〈c,b〉 rs) = None ? →
189 #ls #c #b #rs #Hlegal >(current_of_lift … Hlegal) cases c normalize
190 [#b #H destruct |// |3,4,5:#H destruct ]
193 lemma current_of_lift_Some: ∀ls,c,c1,rs. legal_tape ls c rs →
194 current STape (lift_tape ls c rs) = Some ? c1 →
196 #ls * #c #cb #b #rs #Hlegal >(current_of_lift … Hlegal) cases c normalize
197 [#b1 #H destruct // |#H destruct |3,4,5:#H destruct //]
200 lemma current_of_low_None: ∀M,t. current FinBool t = None ? →
201 current STape (low_tape_aux M t) = None ?.
202 #M #t cases t // #l #b #r whd in ⊢ ((??%?)→?); #H destruct
205 lemma current_of_low_Some: ∀M,t,b. current FinBool t = Some ? b →
206 current STape (low_tape_aux M t) = Some ? 〈bit b,false〉.
208 [#b whd in ⊢ ((??%?)→?); #H destruct
209 |#b #l #b1 whd in ⊢ ((??%?)→?); #H destruct
210 |#b #l #b1 whd in ⊢ ((??%?)→?); #H destruct
211 |#c #c1 #l #r whd in ⊢ ((??%?)→?); #H destruct %
215 lemma current_of_low:∀M,tape,ls,c,rs. legal_tape ls c rs →
216 lift_tape ls c rs = low_tape_aux M tape →
217 c = 〈match current … tape with
218 [ None ⇒ null | Some b ⇒ bit b], false〉.
219 #M #tape #ls * #c #cb #rs #Hlegal #Hlift
220 cut (current ? (lift_tape ls 〈c,cb〉 rs) = current ? (low_tape_aux M tape))
221 [@eq_f @Hlift] -Hlift #Hlift
222 cut (current … tape = None ? ∨ ∃b.current … tape = Some ? b)
223 [cases (current … tape) [%1 // | #b1 %2 /2/ ]] *
224 [#Hcurrent >Hcurrent normalize
225 >(current_of_low_None …Hcurrent) in Hlift; #Hlift
226 >(current_of_lift_None … Hlegal Hlift)
227 @eq_f cases Hlegal * * #Hmarks #_ #_ #_ @(Hmarks 〈c,cb〉) @memb_hd
228 |* #b #Hcurrent >Hcurrent normalize
229 >(current_of_low_Some …Hcurrent) in Hlift; #Hlift
230 @(current_of_lift_Some … Hlegal Hlift)
235 lemma current_of_low:∀M,tape,ls,c,rs. legal_tape ls c rs →
236 lift_tape ls c rs = low_tape_aux M tape →
237 c = 〈match current … tape with
238 [ None ⇒ null | Some b ⇒ bit b], false〉.
239 #M #tape #ls * #c #cb #rs * * #_ #H cases (orb_true_l … H)
240 [cases c [2,3,4,5: whd in ⊢ ((??%?)→?); #Hfalse destruct]
242 [whd in ⊢ ((??%%)→?); #H destruct
243 |#a #l whd in ⊢ ((??%%)→?); #H destruct
244 |#a #l whd in ⊢ ((??%%)→?); #H destruct
245 |#a #l #r whd in ⊢ ((??%%)→?); #H destruct //
248 [#b whd in ⊢ ((??%?)→?); #Hfalse destruct
249 |3,4,5:whd in ⊢ ((??%?)→?); #Hfalse destruct]
250 #_ * [* [#Habs @False_ind /2/
251 |#Hls >Hls whd in ⊢ ((??%%)→?); *)
254 (* sufficent conditions to have a low_level_config *)
255 lemma is_low_config: ∀ls,c,rs,M,s,tape,qhd,q_tl,table.
257 table = flatten ? (tuples_list (no_states M) (nhalt M) (graph_enum ?? (ntrans M))) →
258 lift_tape ls c rs = low_tape_aux M tape →
259 〈qhd,false〉::q_tl = m_bits_of_state (no_states M) (nhalt M) s →
260 midtape STape (〈grid,false〉::ls)
262 (q_tl@c::〈grid,false〉::table@〈grid,false〉::rs) =
263 low_config M (mk_config ?? s tape).
264 #ls #c #rs #M #s #tape #qhd #q_tl #table #Hlegal #Htable
265 #Hlift #Hstate whd in match (low_config ??); <Hstate
267 [@eq_f <(left_of_lift ls c rs) >Hlift //
268 | cut (∀A.∀a,b:A.∀l1,l2. a::l1 = b::l2 → a=b)
269 [#A #a #b #l1 #l2 #H destruct (H) %] #Hcut
271 |@eq_f <(current_of_low … Hlegal Hlift) @eq_f @eq_f <Htable @eq_f @eq_f
272 <(right_of_lift ls c rs Hlegal) >Hlift @right_of_low_tape
276 lemma unistep_true_to_low_step: ∀t1,t2.
277 R_uni_step_true t1 t2 → low_step_R_true t1 t2.
278 #t1 #t2 (* whd in ⊢ (%→%); *) #Huni_step * #n #posn #t #h * #qin #tape #eqt1
279 cases (low_config_eq … eqt1)
280 #low_left * #low_right * #table * #q_low_hd * #q_low_tl * #current_low
281 ***** #Hlow_left #Hlow_right #Htable #Hq_low #Hcurrent_low #Ht1
282 letin trg ≝ (t 〈qin,current ? tape〉)
283 letin qout_low ≝ (m_bits_of_state n h (\fst trg))
284 letin qout_low_hd ≝ (hd ? qout_low 〈bit true,false〉)
285 letin qout_low_tl ≝ (tail ? qout_low)
286 letin low_act ≝ (low_action (\snd (t 〈qin,current ? tape〉)))
287 letin low_cout ≝ (\fst low_act)
288 letin low_m ≝ (\snd low_act)
289 lapply (Huni_step n table q_low_hd (\fst qout_low_hd)
290 current_low low_cout low_left low_right q_low_tl qout_low_tl low_m … Ht1)
293 @(trans_to_match n h t 〈qin,current ? tape〉 … (refl …))
294 >Hq_low >Hcurrent_low whd in match (mk_tuple ?????);
295 >(eq_pair_fst_snd … (t …)) whd in ⊢ (??%?);
296 >(eq_pair_fst_snd … (low_action …)) %
300 -Ht1 #Huni_step lapply (Huni_step ? (refl …)) -Huni_step *
301 #q_low_head_false * #ls1 * #rs1 * #c2 * *
302 #Ht2 #Hlift #Hlegal %
303 [whd in ⊢ (??%?); >q_low_head_false in Hq_low;
304 whd in ⊢ ((???%)→?); generalize in match (h qin);
306 |>Ht2 whd in match (step FinBool ??);
307 whd in match (trans ???);
308 >(eq_pair_fst_snd … (t ?))
309 @is_low_config // >Hlift
310 <low_tape_move @eq_f2
311 [>Hlow_left >Hlow_right >Hcurrent_low whd in ⊢ (??%%);
312 cases (current …tape) [%] #b whd in ⊢ (??%%); %
313 |whd in match low_cout; whd in match low_m; whd in match low_act;
314 generalize in match (\snd (t ?)); * [%] * #b #mv
315 whd in ⊢ (??(?(???%)?)%); cases mv %
320 definition low_step_R_false ≝ λt1,t2.
322 ∀c: nconfig (no_states M).
323 t1 = low_config M c → halt ? M (cstate … c) = true ∧ t1 = t2.
325 lemma unistep_false_to_low_step: ∀t1,t2.
326 R_uni_step_false t1 t2 → low_step_R_false t1 t2.
327 #t1 #t2 (* whd in ⊢ (%→%); *) #Huni_step * #n #posn #t #h * #qin #tape #eqt1
328 cases (low_config_eq … eqt1) #low_left * #low_right * #table * #q_low_hd * #q_low_tl * #current_low
329 ***** #_ #_ #_ #Hqin #_ #Ht1 whd in match (halt ???);
330 cases (Huni_step (h qin) ?) [/2/] >Ht1 whd in ⊢ (??%?); @eq_f
331 normalize in Hqin; destruct (Hqin) %
334 definition low_R ≝ λM,qstart,R,t1,t2.
335 ∀tape1. t1 = low_config M (mk_config ?? qstart tape1) →
336 ∃q,tape2.R tape1 tape2 ∧
337 halt ? M q = true ∧ t2 = low_config M (mk_config ?? q tape2).
340 uni_step ⊨ [us_acc: low_step_R_true, low_step_R_false].
343 definition universalTM ≝ whileTM ? uni_step us_acc.
345 theorem sem_universal: ∀M:normalTM. ∀qstart.
346 universalTM ⊫ (low_R M qstart (R_TM FinBool M qstart)).
349 theorem sem_universal2: ∀M:normalTM. ∀R.
350 M ⊫ R → universalTM ⊫ (low_R M (start ? M) R).
351 #M #R #HMR lapply (sem_universal … M (start ? M)) @WRealize_to_WRealize
352 #t1 #t2 whd in ⊢ (%→%); #H #tape1 #Htape1 cases (H ? Htape1)
353 #q * #tape2 * * #HRTM #Hhalt #Ht2 @(ex_intro … q) @(ex_intro … tape2)
354 % [% [@(R_TM_to_R … HRTM) @HMR | //] | //]
357 axiom terminate_UTM: ∀M:normalTM.∀t.
358 M ↓ t → universalTM ↓ (low_config M (mk_config ?? (start ? M) t)).