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/basic_machines.ma".
13 include "turing/if_machine.ma".
16 definition mut_step ≝ λalpha,D,test.
17 ifTM ? (test_char alpha test) (single_finalTM ? (move alpha D)) (nop ?) tc_true.
19 definition R_mut_step_true ≝ λalpha,D,test,t1,t2.
21 t1 = midtape alpha ls c rs ∧ test c = true ∧ t2 = tape_move ? t1 D.
23 definition R_mut_step_false ≝ λalpha,test.λt1,t2:tape alpha.
24 (∀ls,c,rs.t1 = midtape alpha ls c rs → test c = false)
27 definition mut_acc : ∀alpha,D,test.states ? (mut_step alpha D test) ≝
28 λalpha,D,test.(inr … (inl … (inr … start_nop))).
31 ∀alpha,D,test.mut_step alpha D test ⊨
32 [ mut_acc … : R_mut_step_true alpha D test, R_mut_step_false alpha test] .
34 @(acc_sem_if_app ??????????? (sem_test_char …)
35 (sem_move_single …) (sem_nop alpha) ??)
36 [#tb #tc #td * * #c * #Hcurtb #Htrue
37 cases (current_to_midtape … Hcurtb) #ls * #rs #Hmidtb
38 #tbtd #Hmove %{ls} %{c} %{rs} % // % //
39 |#tb #tc #td * #Hcurtb #Htb whd in ⊢ (%→?); #Htc whd % //
40 lapply (refl ? (current ? tb)) cases (current ? tb) in ⊢ (???%→?);
41 [#H #ls #c #rs #Htb >Htb in H; normalize #HF destruct (HF)
42 |#c #H #ls #c0 #rs #Htb @Hcurtb >Htb //
47 definition move_until ≝ λsig,D,test.
48 whileTM sig (mut_step sig D test) (mut_acc …).
50 definition R_move_l_until ≝
52 (current ? t1 = None ? → t2 = t1) ∧
53 ∀ls,a,rs.t1 = midtape sig ls a rs →
54 (test a = false ∧ t2 = t1) ∨
58 (∀x. mem ? x (a::ls1) → test x = true) ∧
59 t2 = midtape ? ls2 b ((reverse ? (a::ls1))@rs)) ∨
61 (∀x. mem ? x (a::ls) → test x = true) ∧
63 t2 = leftof ? b ((reverse ? lss)@rs))).
65 lemma sem_move_L_until:
67 WRealize sig (move_until sig L test) (R_move_l_until sig test).
68 #sig #test #inc #j #outc #Hloop
69 lapply (sem_while … (sem_mut_step sig L test) inc j outc Hloop) [%]
70 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
71 [ whd in ⊢ (% → ?); * #H1 #H2 %
73 |#ls #a #rs #Htapea % % [@(H1 … Htapea) |@H2]
75 | #tapeb #tapec #Hstar1 #HRtrue #IH #HRfalse
76 lapply (IH HRfalse) -IH -HRfalse whd in ⊢ (%→%);
78 [#Htapeb cases Hstar1 #ls * #b * #rs * *
79 #H1 >H1 in Htapeb; whd in ⊢ (??%?→?); #H destruct (H)
80 |#ls #b0 #rs #Htapeb cases Hstar1
81 #ls1 * #b * #rs1 * * >Htapeb #H destruct (H)
83 [whd in ⊢ (???%→?); #Htapec >Htapec in IH1; #IH1
84 %2 %2 %{b} %{[ ]} % [% [#x * [//|@False_ind] | //] |@IH1 //]
85 |#a #ls2 whd in ⊢ (???%→?); #Htapec
86 %2 cases (IH2 … Htapec)
89 %[%[%[//|//] |#x * [#eqxa >eqxa // |@False_ind]]
90 |>Hout >reverse_single @Htapec
94 %1 cases IH -IH #ls3 * #b0 * #ls4 * * * #H1 #H2 #H3 #H4
95 %{(a::ls3)} %{b0} %{ls4}
96 %[%[%[>H1 //|//]| #x * [#eqxb >eqxb //|@H3]]
97 |>H4 >reverse_cons in ⊢ (???%); >associative_append //
100 %2 cases IH -IH #b0 * #ls3 * * #H1 #H2 #H3
102 %[%[#x * [#eqxb >eqxb //|@H1]|>H2 //]
103 |>H3 >reverse_cons in ⊢ (???%); >associative_append //
111 definition R_move_R_until ≝
113 (current ? t1 = None ? → t2 = t1) ∧
114 ∀ls,a,rs.t1 = midtape sig ls a rs →
115 (test a = false ∧ t2 = t1) ∨
119 (∀x. mem ? x (a::rs1) → test x = true) ∧
120 t2 = midtape ? ((reverse ? (a::rs1))@ls) b rs2) ∨
122 (∀x. mem ? x (a::rs) → test x = true) ∧
124 t2 = rightof ? b ((reverse ? rss)@ls))).
126 lemma sem_move_R_until:
128 WRealize sig (move_until sig R test) (R_move_R_until sig test).
129 #sig #test #inc #j #outc #Hloop
130 lapply (sem_while … (sem_mut_step sig R test) inc j outc Hloop) [%]
131 -Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar)
132 [ whd in ⊢ (% → ?); * #H1 #H2 %
134 |#ls #a #rs #Htapea % % [@(H1 … Htapea) |@H2]
136 | #tapeb #tapec #Hstar1 #HRtrue #IH #HRfalse
137 lapply (IH HRfalse) -IH -HRfalse whd in ⊢ (%→%);
139 [#Htapeb cases Hstar1 #ls * #b * #rs * *
140 #H1 >H1 in Htapeb; whd in ⊢ (??%?→?); #H destruct (H)
141 |#ls #b0 #rs #Htapeb cases Hstar1
142 #ls1 * #b * #rs1 * * >Htapeb #H destruct (H)
144 [whd in ⊢ (???%→?); #Htapec >Htapec in IH1; #IH1
145 %2 %2 %{b} %{[ ]} % [% [#x * [//|@False_ind] | //] |@IH1 //]
146 |#a #rs2 whd in ⊢ (???%→?); #Htapec
147 %2 cases (IH2 … Htapec)
150 %[%[%[//|//] |#x * [#eqxa >eqxa // |@False_ind]]
151 |>Hout >reverse_single @Htapec
155 %1 cases IH -IH #rs3 * #b0 * #rs4 * * * #H1 #H2 #H3 #H4
156 %{(a::rs3)} %{b0} %{rs4}
157 %[%[%[>H1 //|//]| #x * [#eqxb >eqxb //|@H3]]
158 |>H4 >reverse_cons in ⊢ (???%); >associative_append //
161 %2 cases IH -IH #b0 * #rs3 * * #H1 #H2 #H3
163 %[%[#x * [#eqxb >eqxb //|@H1]|>H2 //]
164 |>H3 >reverse_cons in ⊢ (???%); >associative_append //
174 lemma WF_mut_niltape:
175 ∀alpha,D,test. WF ? (inv ? (R_mut_step_true alpha D test)) (niltape alpha).
176 #alpha #D #test @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * * #H destruct
179 lemma WF_mut_rightof:
180 ∀alpha,D,test,a,ls. WF ? (inv ? (R_mut_step_true alpha D test)) (rightof alpha a ls).
181 #alpha #D #test #a #ls @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * * #H destruct
185 ∀alpha,D,test,a,rs. WF ? (inv ? (R_mut_step_true alpha D test)) (leftof alpha a rs).
186 #alpha #D #test #a #rs @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * * #H destruct
189 lemma terminate_move_until_L:
190 ∀alpha,test.∀t. Terminate alpha (move_until alpha L test) t.
191 #alpha #test #t @(terminate_while … (sem_mut_step alpha L test)) [%]
192 cases t // #ls elim ls
193 [#c1 #l1 @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * *
195 |#a #ls1 #Hind #c1 #l1 @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * *
200 lemma terminate_move_until_R:
201 ∀alpha,test.∀t. Terminate alpha (move_until alpha R test) t.
202 #alpha #test #t @(terminate_while … (sem_mut_step alpha R test)) [%]
203 cases t // #ls #c #rs lapply c -c lapply ls -ls elim rs
204 [#c1 #l1 @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * *
206 |#a #ls1 #Hind #c1 #l1 @wf #t1 whd in ⊢ (%→?); * #ls * #b * #rs * *
211 lemma ssem_move_until_L :
213 Realize alpha (move_until alpha L test) (R_move_l_until alpha test).
216 lemma ssem_move_until_R :
218 Realize alpha (move_until alpha R test) (R_move_R_until alpha test).
221 (*********************************** extend ***********************************)
222 (* if current = Null write a character a. Used to dynamically extend the tape *)
224 definition extend ≝ λalpha,a.
225 ifTM ? (test_null alpha) (nop ?) (write alpha a) tc_true.
227 definition R_extend ≝ λalpha,a,t1,t2.
228 (current ? t1 = None ? → t2 = midtape alpha (left ? t1) a (right ? t1)) ∧
229 (current ? t1 ≠ None ? → t2 = t1).
231 lemma sem_extend : ∀alpha,a.
232 extend alpha a ⊨ R_extend alpha a.
234 @(sem_if_app … (sem_test_null …) (sem_nop … ) (sem_write_strong …) ??)
237 [#Hcur >Hcur in H1; * #H @False_ind @H //|#_ >H2 @H3]
239 [#_ >H2 @H3 | >H1 * #H @False_ind @H //]
243 (********************************** extend1 ***********************************)
244 (* a slightly different version: we add a to the left of the current position *)
246 definition extendL ≝ λalpha,a.
247 (move_l alpha) · (write alpha a) · (move_r alpha).
249 definition R_extendL ≝ λalpha,a,t1,t2.
250 (∀b,ls. t1 = leftof ? b ls → t2 = midtape alpha [a] b ls) ∧
251 (∀b,ls,rs. t1 = midtape ? ls b rs → t2 = midtape alpha (a::(tail ? ls)) b rs).
253 lemma sem_extendL : ∀alpha,a.
254 extendL alpha a ⊨ R_extendL alpha a.
256 @(sem_seq_app … (sem_move_l …)
257 (sem_seq … (sem_write_strong … ) (sem_move_r …) …))
258 #tin #tout * #t1 * * #Ht1a #Ht1b * #t2 * #Ht2 * #_ #Ht3 %
259 [#b #ls #Htin >Htin in Ht1a; #Ht1 <(Ht1 … (refl … )) in Ht2;
260 normalize in ⊢ (%→?); #Ht2 @(Ht3 … Ht2)
261 |#b #ls #rs #Htin lapply (Ht1b … Htin) #Ht1 >Ht1 in Ht2;
262 #Ht2 lapply(Ht3 ??? Ht2) cases ls normalize //