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 definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
157 definition R_test_null_char_true ≝ λt1,t2.
158 current FSUnialpha t1 = Some ? null ∧ t1 = t2.
160 definition R_test_null_char_false ≝ λt1,t2.
161 current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
163 lemma sem_test_null_char :
164 test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
165 #t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
166 #Hfalse %{k} %{outc} % [ %
168 | #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
169 -Hcnull #H destruct (H) #Houtc1 %
170 [ @Hcurt1 | <Houtc1 % ] ]
171 | #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
172 [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
173 >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
178 definition cfg_to_obj ≝
179 mmove cfg FSUnialpha 2 L ·
180 (ifTM ?? (inject_TM ? test_null_char 2 cfg)
182 (copy_step cfg obj FSUnialpha 2 ·
183 mmove cfg FSUnialpha 2 L)
185 inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
186 mmove cfg FSUnialpha 2 R.
188 definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
190 nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
192 t2 = change_vec ?? t1
193 (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
194 (tail ? (reverse ? (c::ls)))) cfg) ∧
198 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
199 (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
201 axiom sem_cfg_to_obj : obj_to_cfg ⊨ R_obj_to_cfg.
202 (*@(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
205 (sem_test_null_multi ?? obj ?)
206 (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …))
207 (sem_move_multi ? 2 cfg L ?))
208 (sem_inject ???? cfg ? (sem_write FSUnialpha null)))
209 (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
210 (sem_move_multi ? 2 cfg R ?)))) //
212 #tc * whd in ⊢ (%→?); #Htc *
214 [ * #te * * #Hcurtc #Hte
215 * destruct (Hte) #te * *
216 [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte #Htd
217 * #tf * * * whd in ⊢ (%→%→%→%→?); #Htf1 #Htf2 #Htf3 #Htb
219 [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof
220 whd in match (tape_move ???); #Htc
221 cut (tf = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg)
222 [@daemon] -Htf1 -Htf2 -Htf3 #Htf destruct (Htf Hte Htd Htc Htb)
223 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
224 >nth_change_vec // >tape_move_mk_tape_R
226 | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //]
227 >Hta2 #H destruct (H)
229 | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof
230 whd in match (tape_move ???); #Htc >Htc in Hcurtc0; *
231 [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
232 #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H %
233 | >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) ]
235 | * #te * * #Hcurtc #Hte
236 * whd in ⊢ (%→%→?); #Htd1 #Htd2
237 * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb
239 [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //]
240 >Hta2 normalize in ⊢ (%→?); #H destruct (H)
241 | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
242 destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg)
243 [@daemon] -Htd1 -Htd2 #Htd
244 -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg)
245 [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb)
246 >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
247 >change_vec_change_vec >change_vec_change_vec >nth_change_vec //
248 >reverse_cons >tape_move_mk_tape_R /2/ ]
253 (* macchina che muove il nastro obj a destra o sinistra a seconda del valore
254 del current di prg, che codifica la direzione in cui ci muoviamo *)
256 axiom tape_move_obj : mTM FSUnialpha 2.
259 obj_to_cfg · match_m cfg prg FSUnialpha 2 · copy prg cfg FSUnialpha 2 ·
260 cfg_to_obj · tape_move_obj.