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/turing.ma".
14 (******************* inject a mono machine into a multi tape one **********************)
15 definition inject_trans ≝ λsig,states:FinSet.λn,i:nat.
16 λtrans:states × (option sig) → states × (option sig × move).
17 λp:states × (Vector (option sig) (S n)).
19 let 〈nq,na〉 ≝ trans 〈q,nth i ? a (None ?)〉 in
20 〈nq, change_vec ? (S n) (null_action ? n) na i〉.
22 definition inject_TM ≝ λsig.λM:TM sig.λn,i.
25 (inject_trans sig (states ? M) n i ?) (* (trans sig M))*)
29 lapply (trans sig M) #trans #x lapply (trans x) * *
30 #s #a #m % [ @s | % [ @a | @m ] ]
33 axiom current_chars_change_vec: ∀sig,n,v,a,i. i < S n →
34 current_chars sig ? (change_vec ? (S n) v a i) =
35 change_vec ? (S n)(current_chars ?? v) (current ? a) i.
37 lemma inject_trans_def :∀sig:FinSet.∀n,i:nat.i < S n →
39 trans sig M 〈s,a〉 = 〈sn,an,mn〉 →
40 cic:/matita/turing/turing/trans.fix(0,2,9) sig n (inject_TM sig M n i) 〈s,change_vec ? (S n) v a i〉 =
41 〈sn,change_vec ? (S n) (null_action ? n) 〈an,mn〉 i〉.
42 #sig #n #i #Hlt #M #v #s #a #sn #an #mn #Htrans
43 whd in ⊢ (??%?); >nth_change_vec // >Htrans //
46 lemma inj_ter: ∀A,B,C.∀p:A×B×C.
47 p = 〈\fst (\fst p), \snd (\fst p), \snd p〉.
50 lemma inject_step : ∀sig,n,M,i,q,t,nq,nt,v. i < S n →
51 step sig M (mk_config ?? q t) = mk_config ?? nq nt →
52 cic:/matita/turing/turing/step.def(12) sig n (inject_TM sig M n i)
53 (mk_mconfig ?? n q (change_vec ? (S n) v t i))
54 = mk_mconfig ?? n nq (change_vec ? (S n) v nt i).
55 #sig #n #M #i #q #t #nq #nt #v #lein whd in ⊢ (??%?→?);
56 whd in match (step ????); >(current_chars_change_vec … lein)
57 >(inj_ter … (trans sig M ?)) whd in ⊢ (??%?→?); #H
58 >(inject_trans_def sig n i lein M …)
59 [|>(eq_pair_fst_snd ?? (trans sig M 〈q,current sig t〉))
60 >(eq_pair_fst_snd ?? (\fst (trans sig M 〈q,current sig t〉))) %
62 whd in ⊢ (??%?); @eq_f2 [destruct (H) // ]
63 @(eq_vec … (niltape ?)) #i0 #lei0n
64 cases (decidable_eq_nat … i i0) #Hii0
65 [ >Hii0 >nth_change_vec // >tape_move_multi_def >pmap_change >nth_change_vec // destruct (H) //
66 | >nth_change_vec_neq // >tape_move_multi_def >pmap_change >nth_change_vec_neq //
67 <tape_move_multi_def >tape_move_null_action //
71 lemma halt_inject: ∀sig,n,M,i,x.
72 cic:/matita/turing/turing/halt.fix(0,2,9) sig n (inject_TM sig M n i) x
76 lemma de_option: ∀A,a,b. Some A a = Some A b → a = b.
77 #A #a #b #H destruct //
80 lemma loop_inject: ∀sig,n,M,i,k,ins,int,outs,outt,vt.i < S n →
81 loopM sig M k (mk_config ?? ins int) = Some ? (mk_config ?? outs outt) →
82 cic:/matita/turing/turing/loopM.def(13) sig n (inject_TM sig M n i) k (mk_mconfig ?? n ins (change_vec ?? vt int i))
83 =Some ? (mk_mconfig sig ? n outs (change_vec ?? vt outt i)).
84 #sig #n #M #i #k elim k -k
85 [#ins #int #outs #outt #vt #Hin normalize in ⊢ (%→?); #H destruct
86 |#k #Hind #ins #int #outs #outt #vt #Hin whd in ⊢ (??%?→??%?);
87 >halt_inject whd in match (cstate ????);
88 cases (true_or_false (halt sig M ins)) #Hhalt >Hhalt
90 [#H @eq_f whd in ⊢ (??%?); lapply (de_option ??? H) -H
91 whd in ⊢ (??%?→?); #H @eq_f2
92 [whd in ⊢ (??%?); destruct (H) //
93 |@(eq_vec … (niltape ?)) #j #lejn
94 cases (true_or_false (eqb i j)) #eqij
95 [>(eqb_true_to_eq … eqij) >nth_change_vec //
96 destruct (H) >nth_change_vec //
100 |>(config_expand … (step ???)) #H <(Hind … H) //
101 >loopM_unfold @eq_f >inject_step //
107 lemma cstate_inject: ∀sig,n,M,i,x. *)
109 definition inject_R ≝ λsig.λR:relation (tape sig).λn,i:nat.
110 λv1,v2: (Vector (tape sig) (S n)).
111 R (nth i ? v1 (niltape ?)) (nth i ? v2 (niltape ?)) ∧
112 ∀j. i ≠ j → nth j ? v1 (niltape ?) = nth j ? v2 (niltape ?).
115 lemma nth_make : ∀A,i,n,j,a,d. i < n → nth i ? (make_veci A a n j) d = a (j+i).
117 [#n #j #a #d #ltOn @(lt_O_n_elim … ltOn) <plus_n_O //
118 |#m #Hind #n #j #a #d #Hlt lapply Hlt @(lt_O_n_elim … (ltn_to_ltO … Hlt))
119 #p <plus_n_Sm #ltmp @Hind @le_S_S_to_le //
124 lemma mk_config_eq_s: ∀S,sig,s1,s2,t1,t2.
125 mk_config S sig s1 t1 = mk_config S sig s2 t2 → s1=s2.
126 #S #sig #s1 #s2 #t1 #t2 #H destruct //
129 lemma mk_config_eq_t: ∀S,sig,s1,s2,t1,t2.
130 mk_config S sig s1 t1 = mk_config S sig s2 t2 → s1=s2.
131 #S #sig #s1 #s2 #t1 #t2 #H destruct //
135 theorem sem_inject: ∀sig.∀M:TM sig.∀R.∀n,i.
136 i≤n → M ⊨ R → inject_TM sig M n i ⊨ inject_R sig R n i.
137 #sig #M #R #n #i #lein #HR #vt cases (HR (nth i ? vt (niltape ?)))
138 #k * * #outs #outt * #Hloop #HRout @(ex_intro ?? k)
139 @(ex_intro ?? (mk_mconfig ?? n outs (change_vec ? (S n) vt outt i))) %
140 [whd in ⊢ (??(?????%)?); <(change_vec_same ?? vt i (niltape ?)) in ⊢ (??%?);
141 @loop_inject /2 by refl, trans_eq, le_S_S/
142 |%[>nth_change_vec // @le_S_S //
143 |#j #i >nth_change_vec_neq //
148 theorem acc_sem_inject: ∀sig.∀M:TM sig.∀Rtrue,Rfalse,acc.∀n,i.
149 i≤n → M ⊨ [ acc : Rtrue, Rfalse ] →
150 inject_TM sig M n i ⊨ [ acc : inject_R sig Rtrue n i, inject_R sig Rfalse n i ].
151 #sig #M #Rtrue #Rfalse #acc #n #i #lein #HR #vt cases (HR (nth i ? vt (niltape ?)))
152 #k * * #outs #outt * * #Hloop #HRtrue #HRfalse @(ex_intro ?? k)
153 @(ex_intro ?? (mk_mconfig ?? n outs (change_vec ? (S n) vt outt i))) % [ %
154 [whd in ⊢ (??(?????%)?); <(change_vec_same ?? vt i (niltape ?)) in ⊢ (??%?);
155 @loop_inject /2 by refl, trans_eq, le_S_S/
157 [>nth_change_vec /2 by le_S_S/
158 |#j #Hneq >nth_change_vec_neq //
161 [>nth_change_vec /2 by le_S_S/ @HRfalse @Hqfalse
162 |#j #Hneq >nth_change_vec_neq //