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".
13 include "turing/multi_universal/match.ma".
14 include "turing/multi_universal/copy.ma".
15 include "turing/multi_universal/alphabet.ma".
28 current (in.obj) = None
39 (if (current(in.obj)) == None
54 definition obj ≝ (0:DeqNat).
55 definition cfg ≝ (1:DeqNat).
56 definition prg ≝ (2:DeqNat).
58 definition obj_to_cfg ≝
59 mmove cfg FSUnialpha 2 L ·
60 (ifTM ?? (inject_TM ? (test_null ?) 2 obj)
61 (copy_step obj cfg FSUnialpha 2 ·
62 mmove cfg FSUnialpha 2 L)
63 (inject_TM ? (write FSUnialpha null) 2 cfg)
65 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
66 mmove cfg FSUnialpha 2 R.
68 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
70 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
71 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
73 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg) ∧
74 (current ? (nth obj ? t1 (niltape ?)) = None ? →
76 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls)))
77 (tail ? (reverse ? (null::ls)))) cfg).
79 axiom sem_move_to_end_l : ∀sig. move_to_end sig L ⊨ R_move_to_end_l sig.
80 axiom accRealize_to_Realize :
81 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
82 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
84 lemma eq_mk_tape_rightof :
85 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
89 axiom daemon : ∀P:Prop.P.
91 definition option_cons ≝ λsig.λc:option sig.λl.
92 match c with [ None ⇒ l | Some c0 ⇒ c0::l ].
94 lemma tape_move_mk_tape_R :
96 (c = None ? → ls = [ ] ∨ rs = [ ]) →
97 tape_move ? (mk_tape sig ls c rs) R =
98 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
99 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
100 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
104 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
105 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
108 (sem_test_null_multi ?? obj ?)
109 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
110 (sem_move_multi ? 2 cfg L ?))
111 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
112 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
113 (sem_move_multi ? 2 cfg R ?)))) //
115 #tc * whd in ⊢ (%→?); #Htc *
117 [ * #te * * #Hcurtc #Hte
118 * destruct (Hte) #te * *
119 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte #Htd
120 * #tf * * * whd in ⊢ (%→%→%→%→?); #Htf1 #Htf2 #Htf3 #Htb
122 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
123 whd in match (tape_move ???); #Htc
124 cut (tf = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
125 [@daemon] -Htf1 -Htf2 -Htf3 #Htf destruct (Htf Hte Htd Htc Htb)
126 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
127 >nth_change_vec // >tape_move_mk_tape_R
129 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
130 >Hta2 #H destruct (H)
132 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
133 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
134 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
135 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
136 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
138 | * #te * * #Hcurtc #Hte
139 * whd in ⊢ (%→%→?); #Htd1 #Htd2
140 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
142 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
143 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
144 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
145 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
146 [@daemon] -Htd1 -Htd2 #Htd
147 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
148 [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
149 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
150 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
151 >reverse_cons >tape_move_mk_tape_R /2/ ]
155 lemma wsem_copy : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
156 copy src dst sig n ⊫ R_copy src dst sig n.
157 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
158 lapply (sem_while … (sem_copy_step src dst sig n Hneq Hsrc Hdst) … Hloop) //
159 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
160 [ whd in ⊢ (%→?); * #Hnone #Hout %
162 |#ls #x #x0 #rs #ls0 #rs0 #Hsrc1 #Hdst1 @False_ind cases Hnone
163 [>Hsrc1 normalize #H destruct (H) | >Hdst1 normalize #H destruct (H)]
165 |#tc #td * #x * #y * * #Hcx #Hcy #Htd #Hstar #IH #He lapply (IH He) -IH *
167 [* [>Hcx #H destruct (H) | >Hcy #H destruct (H)]
168 |#ls #x' #y' #rs #ls0 #rs0 #Hnth_src #Hnth_dst
169 >Hnth_src in Hcx; whd in ⊢ (??%?→?); #H destruct (H)
170 >Hnth_dst in Hcy; whd in ⊢ (??%?→?); #H destruct (H)
171 >Hnth_src in Htd; >Hnth_dst -Hnth_src -Hnth_dst
173 [(* the source tape is empty after the move *)
175 [%1 >Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] >nth_change_vec //]
176 #Hout (* whd in match (tape_move ???); *) %1 %{([])} %{rs0} %
178 |whd in match (reverse ??); whd in match (reverse ??);
179 >Hout >Htd @eq_f2 // cases rs0 //
182 [(* the dst tape is empty after the move *)
183 #Htd lapply (IH1 ?) [%2 >Htd >nth_change_vec //]
184 #Hout (* whd in match (tape_move ???); *) %2 %{[ ]} %{(c1::tl1)} %
186 |whd in match (reverse ??); whd in match (reverse ??);
189 |#c2 #tl2 whd in match (tape_move_mono ???); whd in match (tape_move_mono ???);
191 cut (nth src (tape sig) td (niltape sig)=midtape sig (x::ls) c1 tl1)
192 [>Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] @nth_change_vec //]
194 cut (nth dst (tape sig) td (niltape sig)=midtape sig (x::ls0) c2 tl2)
195 [>Htd @nth_change_vec //]
196 #Hdst_td cases (IH2 … Hsrc_td Hdst_td) -Hsrc_td -Hdst_td
197 [* #rs01 * #rs02 * * #H1 #H2 #H3 %1
198 %{(c2::rs01)} %{rs02} % [% [@eq_f //|normalize @eq_f @H2]]
199 >Htd in H3; >change_vec_commute // >change_vec_change_vec
200 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
201 #H >reverse_cons >associative_append >associative_append @H
202 |* #rs11 * #rs12 * * #H1 #H2 #H3 %2
203 %{(c1::rs11)} %{rs12} % [% [@eq_f //|normalize @eq_f @H2]]
204 >Htd in H3; >change_vec_commute // >change_vec_change_vec
205 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
206 #H >reverse_cons >associative_append >associative_append @H
214 lemma terminate_copy : ∀src,dst,sig,n,t.
215 src ≠ dst → src < S n → dst < S n → copy src dst sig n ↓ t.
216 #src #dst #sig #n #t #Hneq #Hsrc #Hdts
217 @(terminate_while … (sem_copy_step …)) //
218 <(change_vec_same … t src (niltape ?))
219 cases (nth src (tape sig) t (niltape ?))
220 [ % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
221 |2,3: #a0 #al0 % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
222 | #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs
223 [#t #ls #c % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?);
224 #H1 destruct (H1) #_ >change_vec_change_vec #Ht1 %
225 #t2 * #x0 * #y0 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
226 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
227 |#r0 #rs0 #IH #t #ls #c % #t1 * #x * #y * * >nth_change_vec //
228 normalize in ⊢ (%→?); #H destruct (H) #Hcur
229 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
234 lemma sem_copy : ∀src,dst,sig,n.
235 src ≠ dst → src < S n → dst < S n →
236 copy src dst sig n ⊨ R_copy src dst sig n.
237 #i #j #sig #n #Hneq #Hi #Hj @WRealize_to_Realize [/2/| @wsem_copy // ]