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 <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
141 | normalize in ⊢ (%→?); #H destruct (H) ]
143 | #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?))))
144 cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
147 [ whd in ⊢ (??%?); >(parmove_q0_q2_null_dst …) /2/
148 [ <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
149 | <(nth_vec_map ?? (current …) src ? int (niltape ?)) // ]
150 | normalize in ⊢ (%→?); #H destruct (H) ]
154 [whd in ⊢ (??%?); >(parmove_q0_q1 … Hneq Hsrc Hdst ? b ??)
155 [2: <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
156 |3: <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
158 | #_ %{a} %{b} % // % // ]
159 | * #H @False_ind @H % ]
163 definition parmove ≝ λsrc,dst,sig,n,D.
164 whileTM … (parmove_step src dst sig n D) parmove1.
166 definition R_parmoveL ≝
167 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
169 nth src ? int (niltape ?) = midtape sig xs x rs →
170 ∀ls0,x0,target,rs0.|xs| = |target| →
171 nth dst ? int (niltape ?) = midtape sig (target@ls0) x0 rs0 →
173 (change_vec ?? int (mk_tape sig [] (None ?) (reverse ? xs@x::rs)) src)
174 (mk_tape sig (tail ? ls0) (option_hd ? ls0) (reverse ? target@x0::rs0)) dst) ∧
175 ((current ? (nth src ? int (niltape ?)) = None ? ∨
176 current ? (nth dst ? int (niltape ?)) = None ?) →
179 lemma wsem_parmoveL : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
180 parmove src dst sig n L ⊫ R_parmoveL src dst sig n.
181 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
182 lapply (sem_while … (sem_parmove_step src dst sig n L Hneq Hsrc Hdst) … Hloop) //
183 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
184 [ whd in ⊢ (%→?); * #H #Houtc % [2: #_ @Houtc ] cases H
185 [ #Hcurtb #x #xs #rs #Hsrctb >Hsrctb in Hcurtb; normalize in ⊢ (%→?);
186 #Hfalse destruct (Hfalse)
187 | #Hcur_dst #x #xs #rs #Hsrctb #ls0 #x0 #target
188 #rs0 #Hlen #Hdsttb >Hdsttb in Hcur_dst; normalize in ⊢ (%→?); #H destruct (H)
190 | #td #te * #c0 * #c1 * * #Hc0 #Hc1 #Hd #Hstar #IH #He
191 lapply (IH He) -IH * #IH1 #IH2 %
192 [ #x #xs #rs #Hsrc_td #ls0 #x0 #target
194 >Hsrc_td in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
195 >Hdst_td in Hd; >Hsrc_td @(list_cases2 … Hlen)
196 [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2
197 [2: %1 >Hd >nth_change_vec_neq [|@(sym_not_eq … Hneq)]
199 >Hd -Hd @(eq_vec … (niltape ?))
200 #i #Hi cases (decidable_eq_nat i src) #Hisrc
201 [ >Hisrc >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
203 >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
205 | cases (decidable_eq_nat i dst) #Hidst
206 [ >Hidst >nth_change_vec // >nth_change_vec //
207 >Hdst_td in Hc1; >Htargetnil
208 normalize in ⊢ (%→?); #Hc1 destruct (Hc1) cases ls0 //
209 | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
210 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
211 >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
212 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)] %
215 | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
216 >(IH1 hd1 tl1 (c0::rs) ? ls0 hd2 tl2 (x0::rs0))
217 [ >Hd >(change_vec_commute … ?? td ?? src dst) //
218 >change_vec_change_vec
219 >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
220 >change_vec_change_vec
221 >reverse_cons >associative_append
222 >reverse_cons >associative_append %
223 | >Hd >nth_change_vec //
224 | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
225 | >Hd >nth_change_vec_neq [|@sym_not_eq //]
228 | >Hc0 >Hc1 * [ #Hc0 destruct (Hc0) | #Hc1 destruct (Hc1) ]
232 lemma terminate_parmoveL : ∀src,dst,sig,n,t.
233 src ≠ dst → src < S n → dst < S n →
234 parmove src dst sig n L ↓ t.
235 #src #dst #sig #n #t #Hneq #Hsrc #Hdst
236 @(terminate_while … (sem_parmove_step …)) //
237 <(change_vec_same … t src (niltape ?))
238 cases (nth src (tape sig) t (niltape ?))
239 [ % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
240 |2,3: #a0 #al0 % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
241 | #ls lapply t -t elim ls
242 [#t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?);
243 #H1 destruct (H1) #Hcurdst >change_vec_change_vec #Ht1 %
244 #t2 * #y1 * #y2 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
245 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
246 |#l0 #ls0 #IH #t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec //
247 normalize in ⊢ (%→?); #H destruct (H) #Hcurdst
248 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
253 lemma sem_parmoveL : ∀src,dst,sig,n.
254 src ≠ dst → src < S n → dst < S n →
255 parmove src dst sig n L ⊨ R_parmoveL src dst sig n.
256 #src #dst #sig #n #Hneq #Hsrc #Hdst @WRealize_to_Realize
257 [/2/ | @wsem_parmoveL //]