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: _ _ _ ... _ ---→ a b c ... z
30 0) (x,_) → (x,_)(R,R) → 1
37 definition trans_parmove_step ≝
39 λp:parmove_states × (Vector (option sig) (S n)).
42 [ O ⇒ match nth src ? a (None ?) with
43 [ None ⇒ 〈parmove2,null_action sig n〉
44 | Some a0 ⇒ match nth dst ? a (None ?) with
45 [ None ⇒ 〈parmove2,null_action ? n〉
46 | Some a1 ⇒ 〈parmove1,change_vec ? (S n)
48 (null_action ? n) (〈None ?,D〉) src)
51 [ O ⇒ (* 1 *) 〈parmove1,null_action ? n〉
52 | S _ ⇒ (* 2 *) 〈parmove2,null_action ? n〉 ] ].
54 definition parmove_step ≝
56 mk_mTM sig n parmove_states (trans_parmove_step src dst sig n D)
57 parmove0 (λq.q == parmove1 ∨ q == parmove2).
59 definition R_parmove_step_true ≝
60 λsrc,dst,sig,n,D.λint,outt: Vector (tape sig) (S n).
62 current ? (nth src ? int (niltape ?)) = Some ? x1 ∧
63 current ? (nth dst ? int (niltape ?)) = Some ? x2 ∧
66 (tape_move ? (nth src ? int (niltape ?)) D) src)
67 (tape_move ? (nth dst ? int (niltape ?)) D) dst.
69 definition R_parmove_step_false ≝
70 λsrc,dst:nat.λsig,n.λint,outt: Vector (tape sig) (S n).
71 (current ? (nth src ? int (niltape ?)) = None ? ∨
72 current ? (nth dst ? int (niltape ?)) = None ?) ∧
75 lemma parmove_q0_q2_null_src :
76 ∀src,dst,sig,n,D,v.src < S n → dst < S n →
77 nth src ? (current_chars ?? v) (None ?) = None ? →
78 step sig n (parmove_step src dst sig n D)
79 (mk_mconfig ??? parmove0 v) =
80 mk_mconfig ??? parmove2 v.
81 #src #dst #sig #n #D #v #Hsrc #Hdst #Hcurrent
82 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
84 [ whd in ⊢ (??(???%)?); >Hcurrent %
85 | whd in ⊢ (??(????(???%))?); >Hcurrent @tape_move_null_action ]
88 lemma parmove_q0_q2_null_dst :
89 ∀src,dst,sig,n,D,v,s.src < S n → dst < S n →
90 nth src ? (current_chars ?? v) (None ?) = Some ? s →
91 nth dst ? (current_chars ?? v) (None ?) = None ? →
92 step sig n (parmove_step src dst sig n D)
93 (mk_mconfig ??? parmove0 v) =
94 mk_mconfig ??? parmove2 v.
95 #src #dst #sig #n #D #v #s #Hsrc #Hdst #Hcursrc #Hcurdst
96 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?);
98 [ whd in ⊢ (??(???%)?); >Hcursrc whd in ⊢ (??(???%)?); >Hcurdst %
99 | whd in ⊢ (??(????(???%))?); >Hcursrc
100 whd in ⊢ (??(????(???%))?); >Hcurdst @tape_move_null_action ]
103 lemma parmove_q0_q1 :
104 ∀src,dst,sig,n,D,v.src ≠ dst → src < S n → dst < S n →
106 nth src ? (current_chars ?? v) (None ?) = Some ? a1 →
107 nth dst ? (current_chars ?? v) (None ?) = Some ? a2 →
108 step sig n (parmove_step src dst sig n D)
109 (mk_mconfig ??? parmove0 v) =
110 mk_mconfig ??? parmove1
113 (tape_move ? (nth src ? v (niltape ?)) D) src)
114 (tape_move ? (nth dst ? v (niltape ?)) D) dst).
115 #src #dst #sig #n #D #v #Hneq #Hsrc #Hdst
116 #a1 #a2 #Hcursrc #Hcurdst
117 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
118 [ whd in match (trans ????);
120 | whd in match (trans ????);
121 >Hcursrc >Hcurdst whd in ⊢ (??(????(???%))?);
122 >tape_move_multi_def <(change_vec_same ?? v dst (niltape ?)) in ⊢ (??%?);
123 >pmap_change <(change_vec_same ?? v src (niltape ?)) in ⊢(??%?);
124 >pmap_change <tape_move_multi_def >tape_move_null_action
125 @eq_f2 // >nth_change_vec_neq //
129 lemma sem_parmove_step :
130 ∀src,dst,sig,n,D.src ≠ dst → src < S n → dst < S n →
131 parmove_step src dst sig n D ⊨
132 [ parmove1: R_parmove_step_true src dst sig n D,
133 R_parmove_step_false src dst sig n ].
134 #src #dst #sig #n #D #Hneq #Hsrc #Hdst #int
135 lapply (refl ? (current ? (nth src ? int (niltape ?))))
136 cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?);
139 [ whd in ⊢ (??%?); >parmove_q0_q2_null_src /2/
140 | normalize in ⊢ (%→?); #H destruct (H) ]
142 | #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?))))
143 cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
146 [ whd in ⊢ (??%?); >(parmove_q0_q2_null_dst …) /2/
147 | normalize in ⊢ (%→?); #H destruct (H) ]
151 [whd in ⊢ (??%?); >(parmove_q0_q1 … Hneq Hsrc Hdst ? b ??)
152 [2: <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
153 |3: <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
155 | #_ %{a} %{b} % // % // ]
156 | * #H @False_ind @H % ]
160 definition parmove ≝ λsrc,dst,sig,n,D.
161 whileTM … (parmove_step src dst sig n D) parmove1.
163 definition R_parmoveL ≝
164 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
166 nth src ? int (niltape ?) = midtape sig xs x rs →
167 ∀ls0,x0,target,rs0.|xs| = |target| →
168 nth dst ? int (niltape ?) = midtape sig (target@ls0) x0 rs0 →
170 (change_vec ?? int (mk_tape sig [] (None ?) (reverse ? xs@x::rs)) src)
171 (mk_tape sig (tail ? ls0) (option_hd ? ls0) (reverse ? target@x0::rs0)) dst) ∧
172 ((current ? (nth src ? int (niltape ?)) = None ? ∨
173 current ? (nth dst ? int (niltape ?)) = None ?) →
176 lemma wsem_parmoveL : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
177 parmove src dst sig n L ⊫ R_parmoveL src dst sig n.
178 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
179 lapply (sem_while … (sem_parmove_step src dst sig n L Hneq Hsrc Hdst) … Hloop) //
180 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
181 [ whd in ⊢ (%→?); * #H #Houtc % [2: #_ @Houtc ] cases H
182 [ #Hcurtb #x #xs #rs #Hsrctb >Hsrctb in Hcurtb; normalize in ⊢ (%→?);
183 #Hfalse destruct (Hfalse)
184 | #Hcur_dst #x #xs #rs #Hsrctb #ls0 #x0 #target
185 #rs0 #Hlen #Hdsttb >Hdsttb in Hcur_dst; normalize in ⊢ (%→?); #H destruct (H)
187 | #td #te * #c0 * #c1 * * #Hc0 #Hc1 #Hd #Hstar #IH #He
188 lapply (IH He) -IH * #IH1 #IH2 %
189 [ #x #xs #rs #Hsrc_td #ls0 #x0 #target
191 >Hsrc_td in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
192 >Hdst_td in Hd; >Hsrc_td @(list_cases2 … Hlen)
193 [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2
194 [2: %1 >Hd >nth_change_vec_neq [|@(sym_not_eq … Hneq)]
196 >Hd -Hd @(eq_vec … (niltape ?))
197 #i #Hi cases (decidable_eq_nat i src) #Hisrc
198 [ >Hisrc >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
200 >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
202 | cases (decidable_eq_nat i dst) #Hidst
203 [ >Hidst >nth_change_vec // >nth_change_vec //
204 >Hdst_td in Hc1; >Htargetnil
205 normalize in ⊢ (%→?); #Hc1 destruct (Hc1) cases ls0 //
206 | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
207 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
208 >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
209 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)] %
212 | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
213 >(IH1 hd1 tl1 (c0::rs) ? ls0 hd2 tl2 (x0::rs0))
214 [ >Hd >(change_vec_commute … ?? td ?? src dst) //
215 >change_vec_change_vec
216 >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
217 >change_vec_change_vec
218 >reverse_cons >associative_append
219 >reverse_cons >associative_append %
220 | >Hd >nth_change_vec //
221 | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
222 | >Hd >nth_change_vec_neq [|@sym_not_eq //]
225 | >Hc0 >Hc1 * [ #Hc0 destruct (Hc0) | #Hc1 destruct (Hc1) ]
229 lemma terminate_parmoveL : ∀src,dst,sig,n,t.
230 src ≠ dst → src < S n → dst < S n →
231 parmove src dst sig n L ↓ t.
232 #src #dst #sig #n #t #Hneq #Hsrc #Hdst
233 @(terminate_while … (sem_parmove_step …)) //
234 <(change_vec_same … t src (niltape ?))
235 cases (nth src (tape sig) t (niltape ?))
236 [ % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
237 |2,3: #a0 #al0 % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
238 | #ls lapply t -t elim ls
239 [#t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?);
240 #H1 destruct (H1) #Hcurdst >change_vec_change_vec #Ht1 %
241 #t2 * #y1 * #y2 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
242 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
243 |#l0 #ls0 #IH #t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec //
244 normalize in ⊢ (%→?); #H destruct (H) #Hcurdst
245 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
250 lemma sem_parmoveL : ∀src,dst,sig,n.
251 src ≠ dst → src < S n → dst < S n →
252 parmove src dst sig n L ⊨ R_parmoveL src dst sig n.
253 #src #dst #sig #n #Hneq #Hsrc #Hdst @WRealize_to_Realize
254 [/2/ | @wsem_parmoveL //]