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 axiom 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).
116 #src #dst #sig #n #D #is_sep #v #Hneq #Hsrc #Hdst
117 #a1 #a2 #Hcursrc #Hcurdst #Hsep
118 whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2
119 [ whd in match (trans ????);
120 >Hcursrc >Hcurdst whd in ⊢ (??(???%)?); >Hsep //
121 | whd in match (trans ????);
122 >Hcursrc >Hcurdst whd in ⊢ (??(????(???%))?); >Hsep whd in ⊢ (??(????(???%))?);
123 change with (pmap_vec ???????) in ⊢ (??%?);
124 whd in match (vec_map ?????);
125 >pmap_change >pmap_change >tape_move_null_action
126 @eq_f2 // @eq_f2 // >nth_change_vec_neq //
131 lemma sem_parmove_step :
132 ∀src,dst,sig,n,D.src ≠ dst → src < S n → dst < S n →
133 parmove_step src dst sig n D ⊨
134 [ parmove1: R_parmove_step_true src dst sig n D,
135 R_parmove_step_false src dst sig n ].
136 #src #dst #sig #n #D #Hneq #Hsrc #Hdst #int
137 lapply (refl ? (current ? (nth src ? int (niltape ?))))
138 cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?);
141 [ whd in ⊢ (??%?); >parmove_q0_q2_null_src /2/
142 <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
143 | normalize in ⊢ (%→?); #H destruct (H) ]
145 | #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?))))
146 cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?);
149 [ whd in ⊢ (??%?); >(parmove_q0_q2_null_dst …) /2/
150 [ <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
151 | <(nth_vec_map ?? (current …) src ? int (niltape ?)) // ]
152 | normalize in ⊢ (%→?); #H destruct (H) ]
156 [whd in ⊢ (??%?); >(parmove_q0_q1 … Hneq Hsrc Hdst ? b ??)
157 [2: <(nth_vec_map ?? (current …) dst ? int (niltape ?)) //
158 |3: <(nth_vec_map ?? (current …) src ? int (niltape ?)) //
160 | #_ %{a} %{b} % // % // ]
161 | * #H @False_ind @H % ]
165 definition parmove ≝ λsrc,dst,sig,n,D.
166 whileTM … (parmove_step src dst sig n D) parmove1.
168 definition R_parmoveL ≝
169 λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
171 nth src ? int (niltape ?) = midtape sig xs x rs →
172 ∀ls0,x0,target,rs0.|xs| = |target| →
173 nth dst ? int (niltape ?) = midtape sig (target@ls0) x0 rs0 →
175 (change_vec ?? int (mk_tape sig [] (None ?) (reverse ? xs@x::rs)) src)
176 (mk_tape sig (tail ? ls0) (option_hd ? ls0) (reverse ? target@x0::rs0)) dst) ∧
177 ((current ? (nth src ? int (niltape ?)) = None ? ∨
178 current ? (nth dst ? int (niltape ?)) = None ?) →
181 lemma wsem_parmoveL : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
182 parmove src dst sig n L ⊫ R_parmoveL src dst sig n.
183 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
184 lapply (sem_while … (sem_parmove_step src dst sig n L Hneq Hsrc Hdst) … Hloop) //
185 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
186 [ whd in ⊢ (%→?); * #H #Houtc % [2: #_ @Houtc ] cases H
187 [ #Hcurtb #x #xs #rs #Hsrctb >Hsrctb in Hcurtb; normalize in ⊢ (%→?);
188 #Hfalse destruct (Hfalse)
189 | #Hcur_dst #x #xs #rs #Hsrctb #ls0 #x0 #target
190 #rs0 #Hlen #Hdsttb >Hdsttb in Hcur_dst; normalize in ⊢ (%→?); #H destruct (H)
192 | #td #te * #c0 * #c1 * * #Hc0 #Hc1 #Hd #Hstar #IH #He
193 lapply (IH He) -IH * #IH1 #IH2 %
194 [ #x #xs #rs #Hsrc_td #ls0 #x0 #target
196 >Hsrc_td in Hc0; normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
197 >Hdst_td in Hd; >Hsrc_td @(list_cases2 … Hlen)
198 [ #Hxsnil #Htargetnil >Hxsnil >Htargetnil #Hd >IH2
199 [2: %1 >Hd >nth_change_vec_neq [|@(sym_not_eq … Hneq)]
201 >Hd -Hd @(eq_vec … (niltape ?))
202 #i #Hi cases (decidable_eq_nat i src) #Hisrc
203 [ >Hisrc >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
205 >(nth_change_vec_neq … src dst) [|@(sym_not_eq … Hneq)]
207 | cases (decidable_eq_nat i dst) #Hidst
208 [ >Hidst >nth_change_vec // >nth_change_vec //
209 >Hdst_td in Hc1; >Htargetnil
210 normalize in ⊢ (%→?); #Hc1 destruct (Hc1) cases ls0 //
211 | >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
212 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)]
213 >nth_change_vec_neq [|@(sym_not_eq … Hidst)]
214 >nth_change_vec_neq [|@(sym_not_eq … Hisrc)] %
217 | #hd1 #hd2 #tl1 #tl2 #Hxs #Htarget >Hxs >Htarget #Hd
218 >(IH1 hd1 tl1 (c0::rs) ? ls0 hd2 tl2 (x0::rs0))
219 [ >Hd >(change_vec_commute … ?? td ?? src dst) //
220 >change_vec_change_vec
221 >(change_vec_commute … ?? td ?? dst src) [|@sym_not_eq //]
222 >change_vec_change_vec
223 >reverse_cons >associative_append
224 >reverse_cons >associative_append %
225 | >Hd >nth_change_vec //
226 | >Hxs in Hlen; >Htarget normalize #Hlen destruct (Hlen) //
227 | >Hd >nth_change_vec_neq [|@sym_not_eq //]
230 | >Hc0 >Hc1 * [ #Hc0 destruct (Hc0) | #Hc1 destruct (Hc1) ]
234 lemma terminate_parmoveL : ∀src,dst,sig,n,t.
235 src ≠ dst → src < S n → dst < S n →
236 parmove src dst sig n L ↓ t.
237 #src #dst #sig #n #t #Hneq #Hsrc #Hdst
238 @(terminate_while … (sem_parmove_step …)) //
239 <(change_vec_same … t src (niltape ?))
240 cases (nth src (tape sig) t (niltape ?))
241 [ % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
242 |2,3: #a0 #al0 % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
243 | #ls lapply t -t elim ls
244 [#t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec // normalize in ⊢ (%→?);
245 #H1 destruct (H1) #Hcurdst >change_vec_change_vec #Ht1 %
246 #t2 * #y1 * #y2 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
247 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
248 |#l0 #ls0 #IH #t #c #rs % #t1 * #x1 * #x2 * * >nth_change_vec //
249 normalize in ⊢ (%→?); #H destruct (H) #Hcurdst
250 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
255 lemma sem_parmoveL : ∀src,dst,sig,n.
256 src ≠ dst → src < S n → dst < S n →
257 parmove src dst sig n L ⊨ R_parmoveL src dst sig n.
258 #src #dst #sig #n #Hneq #Hsrc #Hdst @WRealize_to_Realize
259 [/2/ | @wsem_parmoveL //]