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 mmove obj FSUnialpha 2 L)
64 (inject_TM ? (write FSUnialpha null) 2 cfg)
66 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
67 mmove cfg FSUnialpha 2 R.
69 definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3.
71 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
72 (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso →
74 (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧
75 (current ? (nth obj ? t1 (niltape ?)) = None ? →
77 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls)))
78 (tail ? (reverse ? (null::ls)))) cfg).
80 axiom sem_move_to_end_l : ∀sig. move_to_end sig L ⊨ R_move_to_end_l sig.
81 axiom accRealize_to_Realize :
82 ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc.
83 M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse.
85 lemma eq_mk_tape_rightof :
86 ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al.
90 axiom daemon : ∀P:Prop.P.
92 definition option_cons ≝ λsig.λc:option sig.λl.
93 match c with [ None ⇒ l | Some c0 ⇒ c0::l ].
95 lemma tape_move_mk_tape_R :
97 (c = None ? → ls = [ ] ∨ rs = [ ]) →
98 tape_move ? (mk_tape sig ls c rs) R =
99 mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs).
100 #sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
101 [| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
105 lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg.
106 @(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
109 (sem_test_null_multi ?? obj ?)
110 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
111 (sem_seq ?????? (sem_move_multi ? 2 cfg L ?)
112 (sem_move_multi ? 2 obj L ?)))
113 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
114 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
115 (sem_move_multi ? 2 cfg R ?)))) //
117 #tc * whd in ⊢ (%→?); #Htc *
119 [ * #te * * #Hcurtc #Hte
120 * destruct (Hte) #te * *
121 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte
122 * #tf * whd in ⊢ (%→%→?); #Htf #Htd
123 * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb
125 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
126 whd in match (tape_move ???); #Htc
127 cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
128 [@daemon] -Htg1 -Htg2 -Htg3 #Htg destruct (Htg Htf Hte Htd Htc Htb)
129 >change_vec_change_vec >change_vec_change_vec
130 >change_vec_commute // >change_vec_change_vec
131 >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
132 >change_vec_commute // >change_vec_change_vec
133 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
134 >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
135 >change_vec_commute [|@sym_not_eq //] @eq_f3 //
136 [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???);
137 [ #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same
138 | #r1 #rs1 #Hta2 whd in match (tape_move ???); <Hta2 @change_vec_same ]
139 | >tape_move_mk_tape_R [| #_ % %] >reverse_cons
140 >nth_change_vec_neq in Hcurtc1; [|@sym_not_eq //] >Hta2
141 normalize in ⊢ (%→?); #H destruct (H) %
143 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
144 >Hta2 #H destruct (H)
146 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
147 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
148 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
149 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
150 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
152 | * #te * * #Hcurtc #Hte
153 * whd in ⊢ (%→%→?); #Htd1 #Htd2
154 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
156 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
157 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
158 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
159 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
160 [@daemon] -Htd1 -Htd2 #Htd
161 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
162 [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
163 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
164 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
165 >reverse_cons >tape_move_mk_tape_R /2/ ]
169 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
171 definition R_test_null_char_true ≝ λt1,t2.
172 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
174 definition R_test_null_char_false ≝ λt1,t2.
175 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
177 lemma sem_test_null_char :
178 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
179 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
180 #Hfalse %{k} %{outc} % [ %
182 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
183 -Hcnull #H destruct (H) #Houtc1 %
184 [ @Hcurt1 | <Houtc1 % ] ]
185 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
186 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
187 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
192 definition cfg_to_obj ≝
193 mmove cfg FSUnialpha 2 L ·
194 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
196 (copy_step cfg obj FSUnialpha 2 ·
197 mmove cfg FSUnialpha 2 L ·
198 mmove obj FSUnialpha 2 L)
200 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
201 mmove cfg FSUnialpha 2 R.
203 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
205 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
207 t2 = change_vec ?? t1
208 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
209 (tail ? (reverse ? (c::ls)))) cfg) ∧
213 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
214 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
216 axiom sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
217 (*@(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
220 (sem_test_null_multi ?? obj ?)
221 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
222 (sem_move_multi ? 2 cfg L ?))
223 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
224 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
225 (sem_move_multi ? 2 cfg R ?)))) //
227 #tc * whd in ⊢ (%→?); #Htc *
229 [ * #te * * #Hcurtc #Hte
230 * destruct (Hte) #te * *
231 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte #Htd
232 * #tf * * * whd in ⊢ (%→%→%→%→?); #Htf1 #Htf2 #Htf3 #Htb
234 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
235 whd in match (tape_move ???); #Htc
236 cut (tf = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
237 [@daemon] -Htf1 -Htf2 -Htf3 #Htf destruct (Htf Hte Htd Htc Htb)
238 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
239 >nth_change_vec // >tape_move_mk_tape_R
241 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
242 >Hta2 #H destruct (H)
244 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
245 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
246 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
247 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
248 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
250 | * #te * * #Hcurtc #Hte
251 * whd in ⊢ (%→%→?); #Htd1 #Htd2
252 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
254 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
255 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
256 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
257 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
258 [@daemon] -Htd1 -Htd2 #Htd
259 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
260 [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
261 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
262 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
263 >reverse_cons >tape_move_mk_tape_R /2/ ]
268 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
269 del current di prg, che codifica la direzione in cui ci muoviamo *)
271 definition tape_move_obj : mTM FSUnialpha 2 ≝
273 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg)
274 (mmove obj FSUnialpha 2 L)
276 (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg)
277 (mmove obj FSUnialpha 2 R)
283 obj_to_cfg · match_m cfg prg FSUnialpha 2 ·
284 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
285 mmove cfg FSUnialpha 2 R · copy prg cfg FSUnialpha 2 ·
286 cfg_to_obj · tape_move_obj.