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
58 definition obj_to_cfg ≝
59 mmove cfg FSUnialpha 2 L ·
60 mmove cfg FSUnialpha 2 L ·
61 (ifTM ?? (inject_TM ? (test_null ?) 2 obj)
62 (inject_TM ? (write FSUnialpha (bit false)) 2 cfg ·
63 inject_TM ? (move_r FSUnialpha) 2 cfg ·
64 inject_TM ? (write FSUnialpha (bit false)) 2 cfg)
65 (inject_TM ? (write FSUnialpha (bit true)) 2 cfg ·
66 inject_TM ? (move_r FSUnialpha) 2 cfg ·
67 copy_step obj cfg FSUnialpha 2) tc_true) ·
68 inject_TM ? (move_l FSUnialpha) 2 cfg ·
69 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
70 inject_TM ? (move_r FSUnialpha) 2 cfg.
72 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
74 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::opt::ls) (None ?) [ ] →
75 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
77 (mk_tape ? [ ] (option_hd ? (reverse ? (c::opt::ls))) (tail ? (reverse ? (c::opt::ls)))) cfg) ∧
78 (current ? (nth obj ? t1 (niltape ?)) = None ? →
80 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (bit false::bit false::ls)))
81 (tail ? (reverse ? (bit false :: bit false::ls)))) cfg).
83 axiom sem_move_to_end_l : ∀sig. move_to_end sig L ⊨ R_move_to_end_l sig.
84 axiom accRealize_to_Realize :
85 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
86 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
88 lemma eq_mk_tape_rightof :
89 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
93 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
94 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
95 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
98 (sem_test_null_multi ?? obj ?)
99 (sem_seq ?????? (sem_inject ???? cfg ? (sem_write FSUnialpha (bit false)))
100 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_r ?))
101 (sem_inject ???? cfg ? (sem_write FSUnialpha (bit false)))))
102 (sem_seq ?????? (sem_inject ???? cfg ? (sem_write FSUnialpha (bit true)))
103 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_r ?)) (accRealize_to_Realize … (sem_copy_step …)))))
104 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_l ?))
105 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
106 (sem_inject ???? cfg ? (sem_move_r ?))))))) //
108 #tc * whd in ⊢ (%→?); #Htc *
109 #td * whd in ⊢ (%→?); #Htd *
111 [ * #tf * * #Hcurtd #Htf *
112 #tg * * whd in ⊢ (%→?); #Htg1 #Htg2 *
113 #th * * * whd in ⊢ (%→%→?); #Hth1 #Hth2 #Hth3 * whd in ⊢ (%→?);
115 #tj * * * #Htj1 #Htj2 #Htj3 *
116 #tk * * * #Htk1 #Htk2 #Htk3 * whd in ⊢ (%→?);
117 #Htb1 #Htb2 #c #opt_mark #ls #Hta1 %
118 [ #lso #x #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
119 >Htc in Htd; >nth_change_vec // >change_vec_change_vec
120 change with (midtape ????) in match (tape_move ???); #Htd >Htd in Htf; #Htf
126 lemma wsem_copy : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
127 copy src dst sig n ⊫ R_copy src dst sig n.
128 #src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
129 lapply (sem_while … (sem_copy_step src dst sig n Hneq Hsrc Hdst) … Hloop) //
130 -Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
131 [ whd in ⊢ (%→?); * #Hnone #Hout %
133 |#ls #x #x0 #rs #ls0 #rs0 #Hsrc1 #Hdst1 @False_ind cases Hnone
134 [>Hsrc1 normalize #H destruct (H) | >Hdst1 normalize #H destruct (H)]
136 |#tc #td * #x * #y * * #Hcx #Hcy #Htd #Hstar #IH #He lapply (IH He) -IH *
138 [* [>Hcx #H destruct (H) | >Hcy #H destruct (H)]
139 |#ls #x' #y' #rs #ls0 #rs0 #Hnth_src #Hnth_dst
140 >Hnth_src in Hcx; whd in ⊢ (??%?→?); #H destruct (H)
141 >Hnth_dst in Hcy; whd in ⊢ (??%?→?); #H destruct (H)
142 >Hnth_src in Htd; >Hnth_dst -Hnth_src -Hnth_dst
144 [(* the source tape is empty after the move *)
146 [%1 >Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] >nth_change_vec //]
147 #Hout (* whd in match (tape_move ???); *) %1 %{([])} %{rs0} %
149 |whd in match (reverse ??); whd in match (reverse ??);
150 >Hout >Htd @eq_f2 // cases rs0 //
153 [(* the dst tape is empty after the move *)
154 #Htd lapply (IH1 ?) [%2 >Htd >nth_change_vec //]
155 #Hout (* whd in match (tape_move ???); *) %2 %{[ ]} %{(c1::tl1)} %
157 |whd in match (reverse ??); whd in match (reverse ??);
160 |#c2 #tl2 whd in match (tape_move_mono ???); whd in match (tape_move_mono ???);
162 cut (nth src (tape sig) td (niltape sig)=midtape sig (x::ls) c1 tl1)
163 [>Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] @nth_change_vec //]
165 cut (nth dst (tape sig) td (niltape sig)=midtape sig (x::ls0) c2 tl2)
166 [>Htd @nth_change_vec //]
167 #Hdst_td cases (IH2 … Hsrc_td Hdst_td) -Hsrc_td -Hdst_td
168 [* #rs01 * #rs02 * * #H1 #H2 #H3 %1
169 %{(c2::rs01)} %{rs02} % [% [@eq_f //|normalize @eq_f @H2]]
170 >Htd in H3; >change_vec_commute // >change_vec_change_vec
171 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
172 #H >reverse_cons >associative_append >associative_append @H
173 |* #rs11 * #rs12 * * #H1 #H2 #H3 %2
174 %{(c1::rs11)} %{rs12} % [% [@eq_f //|normalize @eq_f @H2]]
175 >Htd in H3; >change_vec_commute // >change_vec_change_vec
176 >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
177 #H >reverse_cons >associative_append >associative_append @H
185 lemma terminate_copy : ∀src,dst,sig,n,t.
186 src ≠ dst → src < S n → dst < S n → copy src dst sig n ↓ t.
187 #src #dst #sig #n #t #Hneq #Hsrc #Hdts
188 @(terminate_while … (sem_copy_step …)) //
189 <(change_vec_same … t src (niltape ?))
190 cases (nth src (tape sig) t (niltape ?))
191 [ % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
192 |2,3: #a0 #al0 % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct
193 | #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs
194 [#t #ls #c % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?);
195 #H1 destruct (H1) #_ >change_vec_change_vec #Ht1 %
196 #t2 * #x0 * #y0 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //]
197 >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H)
198 |#r0 #rs0 #IH #t #ls #c % #t1 * #x * #y * * >nth_change_vec //
199 normalize in ⊢ (%→?); #H destruct (H) #Hcur
200 >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH
205 lemma sem_copy : ∀src,dst,sig,n.
206 src ≠ dst → src < S n → dst < S n →
207 copy src dst sig n ⊨ R_copy src dst sig n.
208 #i #j #sig #n #Hneq #Hi #Hj @WRealize_to_Realize [/2/| @wsem_copy // ]