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/multi_universal/moves_2.ma".
25 current (in.obj) = None
36 (if (current(in.obj)) == None
51 definition obj_to_cfg ≝
52 mmove cfg unialpha 3 L ·
53 mmove cfg unialpha 3 L ·
54 if_TM ?? (inject_TM ? (test_null ?) 3 obj)
60 definition o2c_states ≝ initN 3.
62 definition copy0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
63 definition copy1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
64 definition copy2 : copy_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
67 definition trans_copy_step ≝
68 λsrc,dst.λsig:FinSet.λn.
69 λp:copy_states × (Vector (option sig) (S n)).
72 [ O ⇒ match nth src ? a (None ?) with
73 [ None ⇒ 〈copy2,null_action sig n〉
74 | Some ai ⇒ match nth dst ? a (None ?) with
75 [ None ⇒ 〈copy2,null_action ? n〉
77 〈copy1,change_vec ? (S n)
78 (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
83 [ O ⇒ (* 1 *) 〈copy1,null_action ? n〉
84 | S _ ⇒ (* 2 *) 〈copy2,null_action ? n〉 ] ].
86 definition copy_step ≝
88 mk_mTM sig n copy_states (trans_copy_step src dst sig n)
89 copy0 (λq.q == copy1 ∨ q == copy2).
91 definition R_comp_step_true ≝
92 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
94 current ? (nth src ? int (niltape ?)) = Some ? x ∧
95 current ? (nth dst ? int (niltape ?)) = Some ? y ∧
98 (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
99 (tape_move_mono ? (nth dst ? int (niltape ?)) 〈Some ? x, R〉) dst.
101 definition R_comp_step_false ≝
102 λsrc,dst:nat.λsig,n.λint,outt: Vector (tape sig) (S n).
103 (current ? (nth src ? int (niltape ?)) = None ? ∨
104 current ? (nth dst ? int (niltape ?)) = None ?) ∧ outt = int.
106 lemma copy_q0_q2_null :
107 ∀src,dst,sig,n,v.src < S n → dst < S n →
108 (nth src ? (current_chars ?? v) (None ?) = None ? ∨
109 nth dst ? (current_chars ?? v) (None ?) = None ?) →
110 step sig n (copy_step src dst sig n) (mk_mconfig ??? copy0 v)
111 = mk_mconfig ??? copy2 v.
112 #src #dst #sig #n #v #Hi #Hj
113 whd in ⊢ (? → ??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (?→??%?);
116 [ whd in ⊢ (??(???%)?); >Hcurrent %
117 | whd in ⊢ (??(????(???%))?); >Hcurrent @tape_move_null_action ]
119 [ whd in ⊢ (??(???%)?); >Hcurrent cases (nth src ?? (None sig)) //
120 | whd in ⊢ (??(????(???%))?); >Hcurrent
121 cases (nth src ?? (None sig)) [|#x] @tape_move_null_action ] ]
125 ∀src,dst,sig,n,v,a,b.src ≠ dst → src < S n → dst < S n →
126 nth src ? (current_chars ?? v) (None ?) = Some ? a →
127 nth dst ? (current_chars ?? v) (None ?) = Some ? b →
128 step sig n (copy_step src dst sig n) (mk_mconfig ??? copy0 v) =
132 (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
133 (tape_move_mono ? (nth dst ? v (niltape ?)) 〈Some ? a, R〉) dst).
134 #src #dst #sig #n #v #a #b #Heq #Hsrc #Hdst #Ha1 #Ha2
135 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
136 [ whd in match (trans ????);
137 >Ha1 >Ha2 whd in ⊢ (??(???%)?); >(\b ?) //
138 | whd in match (trans ????);
139 >Ha1 >Ha2 whd in ⊢ (??(????(???%))?); >(\b ?) //
140 change with (change_vec ?????) in ⊢ (??(????%)?);
141 <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
142 <(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
144 >pmap_change >pmap_change <tape_move_multi_def
145 >tape_move_null_action
146 @eq_f2 // >nth_change_vec_neq //
150 lemma sem_copy_step :
151 ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
152 copy_step src dst sig n ⊨
153 [ copy1: R_comp_step_true src dst sig n,
154 R_comp_step_false src dst sig n ].
155 #src #dst #sig #n #Hneq #Hsrc #Hdst #int
156 lapply (refl ? (current ? (nth src ? int (niltape ?))))
157 cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?);
160 [ whd in ⊢ (??%?); >copy_q0_q2_null /2/
161 | normalize in ⊢ (%→?); #H destruct (H) ]
163 | #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?))))
164 cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
167 [ whd in ⊢ (??%?); >copy_q0_q2_null /2/
168 | normalize in ⊢ (%→?); #H destruct (H) ]
169 | #_ % // %2 >Hcur_dst % ] ]
172 [whd in ⊢ (??%?); >(copy_q0_q1 … a b Hneq Hsrc Hdst) //
173 | #_ %{a} %{b} % // % //]
174 | * #H @False_ind @H %
181 definition copy ≝ λsrc,dst,sig,n.
182 whileTM … (copy_step src dst sig n) copy1.
185 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
186 ((current ? (nth src ? int (niltape ?)) = None ? ∨
187 current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧
188 (∀ls,x,x0,rs,ls0,rs0.
189 nth src ? int (niltape ?) = midtape sig ls x rs →
190 nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 →
191 (∃rs01,rs02.rs0 = rs01@rs02 ∧ |rs01| = |rs| ∧
194 (mk_tape sig (reverse sig rs@x::ls) (None sig) []) src)
195 (mk_tape sig (reverse sig rs@x::ls0) (option_hd sig rs02)
196 (tail sig rs02)) dst) ∨
197 (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
200 (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
202 (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
204 lemma wsem_copy : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
205 copy src dst sig n ⊫ R_copy src dst sig n.
206 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
207 lapply (sem_while … (sem_copy_step src dst sig n Hneq Hsrc Hdst) … Hloop) //
208 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
209 [ whd in ⊢ (%→?); * #Hnone #Hout %
211 |#ls #x #x0 #rs #ls0 #rs0 #Hsrc1 #Hdst1 @False_ind cases Hnone
212 [>Hsrc1 normalize #H destruct (H) | >Hdst1 normalize #H destruct (H)]
214 |#tc #td * #x * #y * * #Hcx #Hcy #Htd #Hstar #IH #He lapply (IH He) -IH *
216 [* [>Hcx #H destruct (H) | >Hcy #H destruct (H)]
217 |#ls #x' #y' #rs #ls0 #rs0 #Hnth_src #Hnth_dst
218 >Hnth_src in Hcx; whd in ⊢ (??%?→?); #H destruct (H)
219 >Hnth_dst in Hcy; whd in ⊢ (??%?→?); #H destruct (H)
220 >Hnth_src in Htd; >Hnth_dst -Hnth_src -Hnth_dst
222 [(* the source tape is empty after the move *)
224 [%1 >Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] >nth_change_vec //]
225 #Hout (* whd in match (tape_move ???); *) %1 %{([])} %{rs0} %
227 |whd in match (reverse ??); whd in match (reverse ??);
228 >Hout >Htd @eq_f2 // cases rs0 //
231 [(* the dst tape is empty after the move *)
232 #Htd lapply (IH1 ?) [%2 >Htd >nth_change_vec //]
233 #Hout (* whd in match (tape_move ???); *) %2 %{[ ]} %{(c1::tl1)} %
235 |whd in match (reverse ??); whd in match (reverse ??);
238 |#c2 #tl2 whd in match (tape_move_mono ???); whd in match (tape_move_mono ???);
240 cut (nth src (tape sig) td (niltape sig)=midtape sig (x::ls) c1 tl1)
241 [>Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] @nth_change_vec //]
243 cut (nth dst (tape sig) td (niltape sig)=midtape sig (x::ls0) c2 tl2)
244 [>Htd @nth_change_vec //]
245 #Hdst_td cases (IH2 … Hsrc_td Hdst_td) -Hsrc_td -Hdst_td
246 [* #rs01 * #rs02 * * #H1 #H2 #H3 %1
247 %{(c2::rs01)} %{rs02} % [% [@eq_f //|normalize @eq_f @H2]]
248 >Htd in H3; >change_vec_commute // >change_vec_change_vec
249 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
250 #H >reverse_cons >associative_append >associative_append @H
251 |* #rs11 * #rs12 * * #H1 #H2 #H3 %2
252 %{(c1::rs11)} %{rs12} % [% [@eq_f //|normalize @eq_f @H2]]
253 >Htd in H3; >change_vec_commute // >change_vec_change_vec
254 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
255 #H >reverse_cons >associative_append >associative_append @H
263 lemma terminate_copy : ∀src,dst,sig,n,t.
264 src ≠ dst → src < S n → dst < S n → copy src dst sig n ↓ t.
265 #src #dst #sig #n #t #Hneq #Hsrc #Hdts
266 @(terminate_while … (sem_copy_step …)) //
267 <(change_vec_same … t src (niltape ?))
268 cases (nth src (tape sig) t (niltape ?))
269 [ % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
270 |2,3: #a0 #al0 % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
271 | #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs
272 [#t #ls #c % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?);
273 #H1 destruct (H1) #_ >change_vec_change_vec #Ht1 %
274 #t2 * #x0 * #y0 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
275 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
276 |#r0 #rs0 #IH #t #ls #c % #t1 * #x * #y * * >nth_change_vec //
277 normalize in ⊢ (%→?); #H destruct (H) #Hcur
278 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
283 lemma sem_copy : ∀src,dst,sig,n.
284 src ≠ dst → src < S n → dst < S n →
285 copy src dst sig n ⊨ R_copy src dst sig n.
286 #i #j #sig #n #Hneq #Hi #Hj @WRealize_to_Realize [/2/| @wsem_copy // ]