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".
13 include "turing/inject.ma".
14 include "turing/while_multi.ma".
16 definition parmove_states ≝ initN 3.
18 definition parmove0 : parmove_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
19 definition parmove1 : parmove_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
20 definition parmove2 : parmove_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)).
24 src: a b c ... z # ---→ a b c ... z #
27 dst: _ _ _ ... _ d ---→ a b c ... z d
30 0) (x ≠ sep,_) → (x,x)(R,R) → 1
37 definition trans_parmove_step ≝
38 λsrc,dst,sig,n,D,is_sep.
39 λp:parmove_states × (Vector (option sig) (S n)).
42 [ O ⇒ match nth src ? a (None ?) with
43 [ None ⇒ 〈parmove2,null_action ? n〉
45 if is_sep a0 then 〈parmove2,null_action ? n〉
46 else match nth dst ? a (None ?) with
47 [ None ⇒ 〈parmove2,null_action ? n〉
48 | Some a1 ⇒ 〈parmove1,change_vec ? (S n)
50 (null_action ? n) (〈Some ? a0,D〉) src)
51 (〈Some ? a1,D〉) dst〉 ] ]
53 [ O ⇒ (* 1 *) 〈parmove1,null_action ? n〉
54 | S _ ⇒ (* 2 *) 〈parmove2,null_action ? n〉 ] ].
56 definition parmove_step ≝
57 λsrc,dst,sig,n,D,is_sep.
58 mk_mTM sig n parmove_states (trans_parmove_step src dst sig n D is_sep)
59 parmove0 (λq.q == parmove1 ∨ q == parmove2).
61 definition R_parmove_step_true ≝
62 λsrc,dst,sig,n,D,is_sep.λint,outt: Vector (tape sig) (S n).
64 current ? (nth src ? int (niltape ?)) = Some ? x1 ∧
65 current ? (nth dst ? int (niltape ?)) = Some ? x2 ∧
69 (tape_move ? (tape_write ? (nth src ? int (niltape ?)) (Some ? x1)) D) src)
70 (tape_move ? (tape_write ? (nth dst ? int (niltape ?)) (Some ? x2)) D) dst.
72 definition R_parmove_step_false ≝
73 λsrc,dst:nat.λsig,n,is_sep.λint,outt: Vector (tape sig) (S n).
75 current ? (nth src ? int (niltape ?)) = Some ? x1 ∧
77 current ? (nth src ? int (niltape ?)) = None ? ∨
78 current ? (nth dst ? int (niltape ?)) = None ?) ∧
81 lemma parmove_q0_q2_null_src :
82 ∀src,dst,sig,n,D,is_sep,v.src < S n → dst < S n →
83 nth src ? (current_chars ?? v) (None ?) = None ? →
84 step sig n (parmove_step src dst sig n D is_sep)
85 (mk_mconfig ??? parmove0 v) =
86 mk_mconfig ??? parmove2 v.
87 #src #dst #sig #n #D #is_sep #v #Hsrc #Hdst #Hcurrent
88 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
90 [ whd in ⊢ (??(???%)?); >Hcurrent %
91 | whd in ⊢ (??(????(???%))?); >Hcurrent @tape_move_null_action ]
94 lemma parmove_q0_q2_sep :
95 ∀src,dst,sig,n,D,is_sep,v,s.src < S n → dst < S n →
96 nth src ? (current_chars ?? v) (None ?) = Some ? s → is_sep s = true →
97 step sig n (parmove_step src dst sig n D is_sep)
98 (mk_mconfig ??? parmove0 v) =
99 mk_mconfig ??? parmove2 v.
100 #src #dst #sig #n #D #is_sep #v #s #Hsrc #Hdst #Hcurrent #Hsep
101 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
103 [ whd in ⊢ (??(???%)?); >Hcurrent whd in ⊢ (??(???%)?); >Hsep %
104 | whd in ⊢ (??(????(???%))?); >Hcurrent
105 whd in ⊢ (??(????(???%))?); >Hsep @tape_move_null_action ]
108 lemma parmove_q0_q2_null_dst :
109 ∀src,dst,sig,n,D,is_sep,v,s.src < S n → dst < S n →
110 nth src ? (current_chars ?? v) (None ?) = Some ? s → is_sep s = false →
111 nth dst ? (current_chars ?? v) (None ?) = None ? →
112 step sig n (parmove_step src dst sig n D is_sep)
113 (mk_mconfig ??? parmove0 v) =
114 mk_mconfig ??? parmove2 v.
115 #src #dst #sig #n #D #is_sep #v #s #Hsrc #Hdst #Hcursrc #Hsep #Hcurdst
116 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
118 [ whd in ⊢ (??(???%)?); >Hcursrc whd in ⊢ (??(???%)?); >Hsep >Hcurdst %
119 | whd in ⊢ (??(????(???%))?); >Hcursrc
120 whd in ⊢ (??(????(???%))?); >Hsep >Hcurdst @tape_move_null_action ]
123 axiom parmove_q0_q1 :
124 ∀src,dst,sig,n,D,is_sep,v.src ≠ dst → src < S n → dst < S n →
126 nth src ? (current_chars ?? v) (None ?) = Some ? a1 →
127 nth dst ? (current_chars ?? v) (None ?) = Some ? a2 →
129 step sig n (parmove_step src dst sig n D is_sep)
130 (mk_mconfig ??? parmove0 v) =
131 mk_mconfig ??? parmove1
134 (tape_move ? (tape_write ? (nth src ? v (niltape ?)) (Some ? a1)) D) src)
135 (tape_move ? (tape_write ? (nth dst ? v (niltape ?)) (Some ? a2)) D) dst).
137 #src #dst #sig #n #D #is_sep #v #Hneq #Hsrc #Hdst
138 #a1 #a2 #Hcursrc #Hcurdst #Hsep
139 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
140 [ whd in match (trans ????);
141 >Hcursrc >Hcurdst whd in ⊢ (??(???%)?); >Hsep //
142 | whd in match (trans ????);
143 >Hcursrc >Hcurdst whd in ⊢ (??(????(???%))?); >Hsep whd in ⊢ (??(????(???%))?);
144 change with (pmap_vec ???????) in ⊢ (??%?);
145 whd in match (vec_map ?????);
146 >pmap_change >pmap_change >tape_move_null_action
147 @eq_f2 // @eq_f2 // >nth_change_vec_neq //
152 lemma sem_parmove_step :
153 ∀src,dst,sig,n,D,is_sep.src ≠ dst → src < S n → dst < S n →
154 parmove_step src dst sig n D is_sep ⊨
155 [ parmove1: R_parmove_step_true src dst sig n D is_sep,
156 R_parmove_step_false src dst sig n is_sep ].
157 #src #dst #sig #n #D #is_sep #Hneq #Hsrc #Hdst #int
158 lapply (refl ? (current ? (nth src ? int (niltape ?))))
159 cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?);
162 [ whd in ⊢ (??%?); >parmove_q0_q2_null_src /2/
163 <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
164 | normalize in ⊢ (%→?); #H destruct (H) ]
165 | #_ % // % %2 // ] ]
166 | #a #Ha cases (true_or_false (is_sep a)) #Hsep
169 [ whd in ⊢ (??%?); >(parmove_q0_q2_sep … Hsep) /2/
170 <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
171 | normalize in ⊢ (%→?); #H destruct (H) ]
172 | #_ % // % % %{a} % // ] ]
173 | lapply (refl ? (current ? (nth dst ? int (niltape ?))))
174 cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
177 [ whd in ⊢ (??%?); >(parmove_q0_q2_null_dst … Hsep) /2/
178 [ <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
179 | <(nth_vec_map ?? (current …) src ? int (niltape ?)) // ]
180 | normalize in ⊢ (%→?); #H destruct (H) ]
184 [whd in ⊢ (??%?); >(parmove_q0_q1 … Hneq Hsrc Hdst ? b ?? Hsep) //
185 [ <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
186 | <(nth_vec_map ?? (current …) src ? int (niltape ?)) // ]
187 | #_ %{a} %{b} % // % // % // ]
188 | * #H @False_ind @H % ]
192 definition parmove ≝ λsrc,dst,sig,n,D,is_sep.
193 whileTM … (parmove_step src dst sig n D is_sep) parmove1.
195 definition R_parmoveL ≝
196 λsrc,dst,sig,n,is_sep.λint,outt: Vector (tape sig) (S n).
198 nth src ? int (niltape ?) = midtape sig (xs@sep::ls) x rs →
199 (∀c.memb ? c (x::xs) = true → is_sep c = false) → is_sep sep = true →
200 ∀ls0,x0,target,c,rs0.|xs| = |target| →
201 nth dst ? int (niltape ?) = midtape sig (target@c::ls0) x0 rs0 →
203 (change_vec ?? int (midtape sig ls sep (reverse ? xs@x::rs)) src)
204 (midtape sig ls0 c (reverse ? target@x0::rs0)) dst) ∧
205 (((∃s.current ? (nth src ? int (niltape ?)) = Some ? s ∧ is_sep s = true) ∨
206 current ? (nth src ? int (niltape ?)) = None ? ∨
207 current ? (nth dst ? int (niltape ?)) = None ?) →
210 lemma wsem_parmoveL : ∀src,dst,sig,n,is_sep.src ≠ dst → src < S n → dst < S n →
211 parmove src dst sig n L is_sep ⊫ R_parmoveL src dst sig n is_sep.
212 #src #dst #sig #n #is_sep #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
213 lapply (sem_while … (sem_parmove_step src dst sig n L is_sep Hneq Hsrc Hdst) … Hloop) //
214 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
215 [ whd in ⊢ (%→?); * #H #Houtc % [2: #_ @Houtc ] cases H
216 [ * [ * #x * #Hx #Hsep #ls #x0 #xs #rs #sep #Hsrctc #Hnosep >Hsrctc in Hx; normalize in ⊢ (%→?);
217 #Hx0 destruct (Hx0) lapply (Hnosep ? (memb_hd …)) >Hsep
218 #Hfalse destruct (Hfalse)
219 | #Hcur_src #ls #x0 #xs #rs #sep #Hsrctc >Hsrctc in Hcur_src;
220 normalize in ⊢ (%→?); #H destruct (H)]
221 |#Hcur_dst #ls #x0 #xs #rs #sep #Hsrctc #Hnosep #Hsep #ls0 #x1 #target
222 #c #rs0 #Hlen #Hdsttc >Hdsttc in Hcur_dst; normalize in ⊢ (%→?); #H destruct (H)
224 | #td #te * #c0 * #c1 * * * #Hc0 #Hc1 #Hc0nosep #Hd #Hstar #IH #He
225 lapply (IH He) -IH * #IH1 #IH2 %
226 [ #ls #x #xs #rs #sep #Hsrc_tc #Hnosep #Hsep #ls0 #x0 #target
227 #c #rs0 #Hlen #Hdst_tc
228 >Hsrc_tc in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
229 >Hdst_tc in Hd; >Hsrc_tc @(list_cases2 … Hlen)
230 [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2
231 [2: %1 %1 %{sep} % // >Hd >nth_change_vec_neq [|@(sym_not_eq … Hneq)]
233 >Hd -Hd @(eq_vec … (niltape ?))
234 #i #Hi cases (decidable_eq_nat i src) #Hisrc
235 [ >Hisrc >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
237 >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
239 | cases (decidable_eq_nat i dst) #Hidst
240 [ >Hidst >nth_change_vec // >nth_change_vec //
241 >Hdst_tc in Hc1; >Htargetnil
242 normalize in ⊢ (%→?); #Hc1 destruct (Hc1) %
243 | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
244 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
245 >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
246 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)] %
249 | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
250 >(IH1 ls hd1 tl1 (c0::rs) sep ?? Hsep ls0 hd2 tl2 c (x0::rs0))
251 [ >Hd >(change_vec_commute … ?? td ?? src dst) //
252 >change_vec_change_vec
253 >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
254 >change_vec_change_vec
255 >reverse_cons >associative_append
256 >reverse_cons >associative_append %
257 | >Hd >nth_change_vec // >Hdst_tc >Htarget >Hdst_tc in Hc1;
258 normalize in ⊢ (%→?); #H destruct (H) //
259 | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
260 | <Hxs #c1 #Hc1 @Hnosep @memb_cons //
261 | >Hd >nth_change_vec_neq [|@sym_not_eq //]
264 | >Hc0 >Hc1 * [* [ * #c * #Hc destruct (Hc) >Hc0nosep]] #Habs destruct (Habs)
268 lemma terminate_parmoveL : ∀src,dst,sig,n,is_sep,t.
269 src ≠ dst → src < S n → dst < S n →
270 parmove src dst sig n L is_sep ↓ t.
271 #src #dst #sig #n #is_sep #t #Hneq #Hsrc #Hdst
272 @(terminate_while … (sem_parmove_step …)) //
273 <(change_vec_same … t src (niltape ?))
274 cases (nth src (tape sig) t (niltape ?))
275 [ % #t1 * #x1 * #x2 * * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
276 |2,3: #a0 #al0 % #t1 * #x1 * #x2 * * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
277 | #ls lapply t -t elim ls
278 [#t #c #rs % #t1 * #x1 * #x2 * * * >nth_change_vec // normalize in ⊢ (%→?);
279 #H1 destruct (H1) #Hcurdst #Hxsep >change_vec_change_vec #Ht1 %
280 #t2 * #y1 * #y2 * * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
281 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
282 |#l0 #ls0 #IH #t #c #rs % #t1 * #x1 * #x2 * * * >nth_change_vec //
283 normalize in ⊢ (%→?); #H destruct (H) #Hcurdst #Hxsep
284 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
289 lemma sem_parmoveL : ∀src,dst,sig,n,is_sep.
290 src ≠ dst → src < S n → dst < S n →
291 parmove src dst sig n L is_sep ⊨ R_parmoveL src dst sig n is_sep.
292 #src #dst #sig #n #is_sep #Hneq #Hsrc #Hdst @WRealize_to_Realize
293 [/2/ | @wsem_parmoveL //]