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_____________________________________________________________*)
17 include "turing/universal/marks.ma".
19 definition STape ≝ FinProd … FSUnialpha FinBool.
21 definition only_bits ≝ λl.
22 ∀c.memb STape c l = true → is_bit (\fst c) = true.
24 definition only_bits_or_nulls ≝ λl.
25 ∀c.memb STape c l = true → bit_or_null (\fst c) = true.
27 definition no_grids ≝ λl.
28 ∀c.memb STape c l = true → is_grid (\fst c) = false.
30 definition no_bars ≝ λl.
31 ∀c.memb STape c l = true → is_bar (\fst c) = false.
33 definition no_marks ≝ λl.
34 ∀c.memb STape c l = true → is_marked ? c = false.
36 lemma bit_not_grid: ∀d. is_bit d = true → is_grid d = false.
37 * // normalize #H destruct
40 lemma bit_or_null_not_grid: ∀d. bit_or_null d = true → is_grid d = false.
41 * // normalize #H destruct
44 lemma bit_not_bar: ∀d. is_bit d = true → is_bar d = false.
45 * // normalize #H destruct
48 lemma bit_or_null_not_bar: ∀d. bit_or_null d = true → is_bar d = false.
49 * // normalize #H destruct
52 (* by definition, a tuple is not marked *)
53 definition tuple_TM : nat → list STape → Prop ≝
56 only_bits_or_nulls qin ∧ only_bits_or_nulls qout ∧ bit_or_null mv = true ∧
57 |qin| = n ∧ |qout| = n (* ∧ |mv| = ? *) ∧
58 t = qin@〈comma,false〉::qout@〈comma,false〉::[〈mv,false〉].
60 inductive table_TM : nat → list STape → Prop ≝
61 | ttm_nil : ∀n.table_TM n []
62 | ttm_cons : ∀n,t1,T.tuple_TM n t1 → table_TM n T → table_TM n (t1@〈bar,false〉::T).
64 lemma no_grids_in_table: ∀n.∀l.table_TM n l → no_grids l.
66 [normalize #n #x #H destruct
67 |#m #t1 #t2 * #qin * #qout * #mv * * * * * *
68 #Hmarks #Hqin #Hqout #Hmv #_ #_ #Heq #Ht2 #Hind
70 cases (memb_append … membx) -membx #membx
71 [cases (memb_append … membx) -membx #membx
72 [@bit_or_null_not_grid @Hqin //
73 |cases (orb_true_l … membx) -membx #membx
75 |cases (memb_append … membx) -membx #membx
76 [@bit_or_null_not_grid @Hqout //
77 |cases (orb_true_l … membx) -membx #membx
79 |@bit_or_null_not_grid >(memb_single … membx) @Hmv
84 |cases (orb_true_l … membx) -membx #membx
92 lemma no_marks_in_table: ∀n.∀l.table_TM n l → no_marks l.
94 [normalize #n #x #H destruct
95 |#m #t1 #t2 * #qin * #qout * #mv * * * * * *
96 #Hmarks #_ #_ #_ #_ #_ #_ #Ht2 #Hind
97 #x #Hx cases (memb_append … Hx) -Hx #Hx
99 |cases (orb_true_l … Hx) -Hx #Hx
107 axiom last_of_table: ∀n,l,b.¬ table_TM n (l@[〈bar,b〉]).
110 l0 x* a l1 x0* a0 l2 ------> l0 x a* l1 x0 a0* l2
113 if current (* x *) = #
116 then move_right; ----
118 if current (* x0 *) = 0
119 then advance_mark ----
123 else x = 1 (* analogo *)
129 MARK NEXT TUPLE machine
130 (partially axiomatized)
132 marks the first character after the first bar (rightwards)
135 definition bar_or_grid ≝ λc:STape.is_bar (\fst c) ∨ is_grid (\fst c).
137 definition mark_next_tuple ≝
138 seq ? (adv_to_mark_r ? bar_or_grid)
139 (ifTM ? (test_char ? (λc:STape.is_bar (\fst c)))
140 (move_right_and_mark ?) (nop ?) 1).
142 definition R_mark_next_tuple ≝
145 (* c non può essere un separatore ... speriamo *)
146 t1 = midtape STape ls c (rs1@〈grid,false〉::rs2) →
147 no_marks rs1 → no_grids rs1 → bar_or_grid c = false →
148 (∃rs3,rs4,d,b.rs1 = rs3 @ 〈bar,false〉 :: rs4 ∧
150 Some ? 〈d,b〉 = option_hd ? (rs4@〈grid,false〉::rs2) ∧
151 t2 = midtape STape (〈bar,false〉::reverse ? rs3@c::ls) 〈d,true〉 (tail ? (rs4@〈grid,false〉::rs2)))
153 (no_bars rs1 ∧ t2 = midtape ? (reverse ? rs1@c::ls) 〈grid,false〉 rs2).
157 (∀x.memb A x l = true → f x = false) ∨
158 (∃l1,c,l2.f c = true ∧ l = l1@c::l2 ∧ ∀x.memb ? x l1 = true → f x = false).
160 [ % #x normalize #Hfalse *)
162 theorem sem_mark_next_tuple :
163 Realize ? mark_next_tuple R_mark_next_tuple.
165 lapply (sem_seq ? (adv_to_mark_r ? bar_or_grid)
166 (ifTM ? (test_char ? (λc:STape.is_bar (\fst c))) (move_right_and_mark ?) (nop ?) 1) ????)
167 [@sem_if [5: // |6: @sem_move_right_and_mark |7: // |*:skip]
169 |||#Hif cases (Hif intape) -Hif
170 #j * #outc * #Hloop * #ta * #Hleft #Hright
171 @(ex_intro ?? j) @ex_intro [|% [@Hloop] ]
173 #ls #c #rs1 #rs2 #Hrs #Hrs1 #Hrs1' #Hc
175 [ * #Hfalse >Hfalse in Hc; #Htf destruct (Htf)
176 | * #_ #Hta cases (tech_split STape (λc.is_bar (\fst c)) rs1)
177 [ #H1 lapply (Hta rs1 〈grid,false〉 rs2 (refl ??) ? ?)
178 [ * #x #b #Hx whd in ⊢ (??%?); >(Hrs1' … Hx) >(H1 … Hx) %
180 | -Hta #Hta cases Hright
181 [ * #tb * whd in ⊢ (%→?); #Hcurrent
182 @False_ind cases (Hcurrent 〈grid,false〉 ?)
183 [ normalize #Hfalse destruct (Hfalse)
185 | * #tb * whd in ⊢ (%→?); #Hcurrent
186 cases (Hcurrent 〈grid,false〉 ?)
187 [ #_ #Htb whd in ⊢ (%→?); #Houtc
190 | >Houtc >Htb >Hta % ]
194 | * #rs3 * #c0 * #rs4 * * #Hc0 #Hsplit #Hrs3
195 % @(ex_intro ?? rs3) @(ex_intro ?? rs4)
196 lapply (Hta rs3 c0 (rs4@〈grid,false〉::rs2) ???)
197 [ #x #Hrs3' whd in ⊢ (??%?); >Hsplit in Hrs1;>Hsplit in Hrs3;
198 #Hrs3 #Hrs1 >(Hrs1 …) [| @memb_append_l1 @Hrs3'|]
199 >(Hrs3 … Hrs3') @Hrs1' >Hsplit @memb_append_l1 //
200 | whd in ⊢ (??%?); >Hc0 %
201 | >Hsplit >associative_append % ] -Hta #Hta
203 [ * #tb * whd in ⊢ (%→?); #Hta'
206 [ #_ #Htb' >Htb' in Htb; #Htb
207 generalize in match Hsplit; -Hsplit
209 [ #Hta #Hsplit >(Htb … Hta)
210 >(?:c0 = 〈bar,false〉)
211 [ @(ex_intro ?? grid) @(ex_intro ?? false)
213 [(* Hsplit *) @daemon |(*Hrs3*) @daemon ] | % ] | % ]
214 | (* Hc0 *) @daemon ]
215 | #r5 #rs5 >(eq_pair_fst_snd … r5)
216 #Hta #Hsplit >(Htb … Hta)
217 >(?:c0 = 〈bar,false〉)
218 [ @(ex_intro ?? (\fst r5)) @(ex_intro ?? (\snd r5))
219 % [ % [ % [ (* Hc0, Hsplit *) @daemon | (*Hrs3*) @daemon ] | % ]
220 | % ] | (* Hc0 *) @daemon ] ] | >Hta % ]
221 | * #tb * whd in ⊢ (%→?); #Hta'
224 [ #Hfalse @False_ind >Hfalse in Hc0;
230 definition init_current_on_match ≝
232 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
233 (seq ? (move_r ?) (mark ?)))).
235 definition R_init_current_on_match ≝ λt1,t2.
236 ∀l1,l2,c,rs. no_grids l1 → is_grid c = false →
237 t1 = midtape STape (l1@〈c,false〉::〈grid,false〉::l2) 〈grid,false〉 rs →
238 t2 = midtape STape (〈grid,false〉::l2) 〈c,true〉 ((reverse ? l1)@〈grid,false〉::rs).
240 lemma sem_init_current_on_match :
241 Realize ? init_current_on_match R_init_current_on_match.
243 cases (sem_seq ????? (sem_move_l ?)
244 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
245 (sem_seq ????? (sem_move_r ?) (sem_mark ?))) intape)
246 #k * #outc * #Hloop #HR
247 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
248 #l1 #l2 #c #rs #Hl1 #Hc #Hintape
249 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta -Hintape
250 generalize in match Hl1; cases l1
251 [#Hl1 whd in ⊢ ((???(??%%%))→?); #Hta
252 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hta) -Hta
253 [* >Hc #Htemp destruct (Htemp) ]
254 * #_ #Htc lapply (Htc [ ] 〈grid,false〉 ? (refl ??) (refl …) Hl1)
255 whd in ⊢ ((???(??%%%))→?); -Htc #Htc
256 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htc -Htd
257 whd in ⊢ ((???(??%%%))→?); #Htd
258 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htd) -Houtc #Houtc
260 |#d #tl #Htl whd in ⊢ ((???(??%%%))→?); #Hta
261 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hta) -Htb
262 [* >(Htl … (memb_hd …)) #Htemp destruct (Htemp)]
263 * #Hd >append_cons #Htb lapply (Htb … (refl ??) (refl …) ?)
264 [#x #membx cases (memb_append … membx) -membx #membx
265 [@Htl @memb_cons @membx | >(memb_single … membx) @Hc]]-Htb #Htb
266 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htb -Htc
267 >reverse_append >associative_append whd in ⊢ ((???(??%%%))→?); #Htc
268 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htc) -Houtc #Houtc
269 >Houtc >reverse_cons >associative_append %
274 definition init_current_gen ≝
275 seq ? (adv_to_mark_l ? (is_marked ?))
276 (seq ? (clear_mark ?)
278 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
279 (seq ? (move_r ?) (mark ?))))).
281 definition R_init_current_gen ≝ λt1,t2.
282 ∀l1,c,l2,b,l3,c1,rs,c0,b0. no_marks l1 → no_grids l2 →
283 Some ? 〈c0,b0〉 = option_hd ? (reverse ? (〈c,true〉::l2)) →
284 t1 = midtape STape (l1@〈c,true〉::l2@〈grid,b〉::l3) 〈c1,false〉 rs →
285 t2 = midtape STape (〈grid,b〉::l3) 〈c0,true〉
286 ((tail ? (reverse ? (l1@〈c,false〉::l2))@〈c1,false〉::rs)).
288 lemma sem_init_current_gen : Realize ? init_current_gen R_init_current_gen.
290 cases (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
291 (sem_seq ????? (sem_clear_mark ?)
292 (sem_seq ????? (sem_move_l ?)
293 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
294 (sem_seq ????? (sem_move_r ?) (sem_mark ?))))) intape)
295 #k * #outc * #Hloop #HR
296 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
297 #l1 #c #l2 #b #l3 #c1 #rs #c0 #b0 #Hl1 #Hl2 #Hc #Hintape
298 cases HR -HR #ta * whd in ⊢ (%→?); #Hta cases (Hta … Hintape) -Hta -Hintape
299 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
300 * #_ #Hta lapply (Hta l1 〈c,true〉 ? (refl ??) ??) [@Hl1|%] -Hta #Hta
301 * #tb * whd in ⊢ (%→?); #Htb lapply (Htb … Hta) -Htb -Hta #Htb
302 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc -Htb
303 generalize in match Hc; generalize in match Hl2; cases l2
304 [#_ whd in ⊢ ((???%)→?); #Htemp destruct (Htemp)
305 whd in ⊢ ((???(??%%%))→?); #Htc
306 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
307 [2: * whd in ⊢ (??%?→?); #Htemp destruct (Htemp) ]
308 * #_ #Htd >Htd in Htc; -Htd #Htd
309 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Htd
310 >reverse_append >reverse_cons
311 whd in ⊢ ((???(??%%%))→?); #Hte
312 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
314 |#d #tl #Htl #Hc0 whd in ⊢ ((???(??%%%))→?); #Htc
315 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
316 [* >(Htl … (memb_hd …)) whd in ⊢ (??%?→?); #Htemp destruct (Htemp)]
317 * #Hd #Htd lapply (Htd … (refl ??) (refl ??) ?)
318 [#x #membx @Htl @memb_cons @membx] -Htd #Htd
319 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Htd
320 >reverse_append >reverse_cons >reverse_cons
321 >reverse_cons in Hc0; >reverse_cons cases (reverse ? tl)
322 [normalize in ⊢ (%→?); #Hc0 destruct (Hc0) #Hte
323 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
325 |* #c2 #b2 #tl2 normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
326 whd in ⊢ ((???(??%%%))→?); #Hte
327 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
328 >Houtc >associative_append >associative_append >associative_append %
333 definition init_current ≝
334 seq ? (adv_to_mark_l ? (is_marked ?))
335 (seq ? (clear_mark ?)
336 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
337 (seq ? (move_r ?) (mark ?)))).
339 definition R_init_current ≝ λt1,t2.
340 ∀l1,c,l2,b,l3,c1,rs,c0,b0. no_marks l1 → no_grids l2 → is_grid c = false →
341 Some ? 〈c0,b0〉 = option_hd ? (reverse ? (〈c,true〉::l2)) →
342 t1 = midtape STape (l1@〈c,true〉::l2@〈grid,b〉::l3) 〈c1,false〉 rs →
343 t2 = midtape STape (〈grid,b〉::l3) 〈c0,true〉
344 ((tail ? (reverse ? (l1@〈c,false〉::l2))@〈c1,false〉::rs)).
346 lemma sem_init_current : Realize ? init_current R_init_current.
348 cases (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
349 (sem_seq ????? (sem_clear_mark ?)
350 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
351 (sem_seq ????? (sem_move_r ?) (sem_mark ?)))) intape)
352 #k * #outc * #Hloop #HR
353 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop]
354 cases HR -HR #ta * whd in ⊢ (%→?); #Hta
355 * #tb * whd in ⊢ (%→?); #Htb
356 * #tc * whd in ⊢ (%→?); #Htc
357 * #td * whd in ⊢ (%→%→?); #Htd #Houtc
358 #l1 #c #l2 #b #l3 #c1 #rs #c0 #b0 #Hl1 #Hl2 #Hc #Hc0 #Hintape
359 cases (Hta … Hintape) [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
360 -Hta * #_ #Hta lapply (Hta l1 〈c,true〉 ? (refl ??) ??) [@Hl1|%]
361 -Hta #Hta lapply (Htb … Hta) -Htb #Htb cases (Htc … Htb) [ >Hc -Hc * #Hc destruct (Hc) ]
362 -Htc * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?) [@Hl2]
363 -Htc #Htc lapply (Htd … Htc) -Htd
364 >reverse_append >reverse_cons
365 >reverse_cons in Hc0; cases (reverse … l2)
366 [ normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
367 #Htd >(Houtc … Htd) %
368 | * #c2 #b2 #tl2 normalize in ⊢ (%→?);
369 #Hc0 #Htd >(Houtc … Htd)
370 whd in ⊢ (???%); destruct (Hc0)
371 >associative_append >associative_append %
375 definition match_tuple_step ≝
376 ifTM ? (test_char ? (λc:STape.¬ is_grid (\fst c)))
379 (ifTM ? (test_char ? (λc:STape.is_grid (\fst c)))
381 (seq ? mark_next_tuple
382 (ifTM ? (test_char ? (λc:STape.is_grid (\fst c)))
383 (mark ?) (seq ? (move_l ?) init_current) tc_true)) tc_true)))
386 definition R_match_tuple_step_true ≝ λt1,t2.
387 ∀ls,c,l1,l2,c1,l3,l4,rs,n.
388 bit_or_null c = true → only_bits_or_nulls l1 → no_marks l1 (* → no_grids l2 *) → bit_or_null c1 = true →
389 only_bits_or_nulls l3 → n = |l1| → |l1| = |l3| →
390 table_TM (S n) (l2@〈bar,false〉::〈c1,false〉::l3@〈comma,false〉::l4) →
391 t1 = midtape STape (〈grid,false〉::ls) 〈c,true〉
392 (l1@〈grid,false〉::l2@〈bar,false〉::〈c1,true〉::l3@〈comma,false〉::l4@〈grid,false〉::rs) →
394 (〈c,false〉::l1 = 〈c1,false〉::l3 ∧
395 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls) 〈grid,false〉
396 (l2@〈bar,false〉::〈c1,false〉::l3@〈comma,true〉::l4@〈grid,false〉::rs))
398 (* non facciamo match e marchiamo la prossima tupla *)
399 ((〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧
400 ∃c2,l5,l6.l4 = l5@〈bar,false〉::〈c2,false〉::l6 ∧
401 (* condizioni su l5 l6 l7 *)
402 t2 = midtape STape (〈grid,false〉::ls) 〈c,true〉
403 (l1@〈grid,false〉::l2@〈bar,false〉::〈c1,false〉::l3@〈comma,false〉::
404 l5@〈bar,false〉::〈c2,true〉::l6@〈grid,false〉::rs))
406 (* non facciamo match e non c'è una prossima tupla:
407 non specifichiamo condizioni sul nastro di output, perché
408 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
409 (〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧ no_bars l4 ∧ current ? t2 = Some ? 〈grid,true〉)).
411 definition R_match_tuple_step_false ≝ λt1,t2.
412 ∀ls,c,rs.t1 = midtape STape ls c rs → is_grid (\fst c) = true ∧ t2 = t1.
414 include alias "basics/logic.ma".
417 lemma eq_f4: ∀A1,A2,A3,A4,B.∀f:A1 → A2 →A3 →A4 →B.
418 ∀x1,x2,x3,x4,y1,y2,y3,y4. x1 = y1 → x2 = y2 →x3=y3 →x4 = y4 →
419 f x1 x2 x3 x4 = f y1 y2 y3 y4.
423 lemma some_option_hd: ∀A.∀l:list A.∀a.∃b.
424 Some ? b = option_hd ? (l@[a]) .
425 #A #l #a cases l normalize /2/
428 axiom tech_split2 : ∀A,l1,l2,l3,l4,x.
429 memb A x l1 = false → memb ? x l3 = false →
430 l1@x::l2 = l3@x::l4 → l1 = l3 ∧ l2 = l4.
432 axiom injective_append : ∀A,l.injective … (λx.append A x l).
434 lemma sem_match_tuple_step:
435 accRealize ? match_tuple_step (inr … (inl … (inr … 0)))
436 R_match_tuple_step_true R_match_tuple_step_false.
437 @(acc_sem_if_app … (sem_test_char ? (λc:STape.¬ is_grid (\fst c))) …
438 (sem_seq … sem_compare
439 (sem_if … (sem_test_char ? (λc:STape.is_grid (\fst c)))
441 (sem_seq … sem_mark_next_tuple
442 (sem_if … (sem_test_char ? (λc:STape.is_grid (\fst c)))
443 (sem_mark ?) (sem_seq … (sem_move_l …) (sem_init_current …))))))
445 [(* is_grid: termination case *)
446 2:#t1 #t2 #t3 whd in ⊢ (%→?); #H #H1 whd #ls #c #rs #Ht1
447 cases (H c ?) [2: >Ht1 %] #Hgrid #Heq %
448 [@injective_notb @Hgrid | <Heq @H1]
449 |#tapea #tapeout #tapeb whd in ⊢ (%→?); #Htapea
450 * #tapec * #Hcompare #Hor
451 #ls #c #l1 #l2 #c1 #l3 #l4 #rs #n #Hc #Hl1bars #Hl1marks #Hc1 #Hl3 #eqn
452 #eqlen #Htable #Htapea1 cases (Htapea 〈c,true〉 ?) >Htapea1 [2:%]
453 #notgridc -Htapea -Htapea1 -tapea #Htapeb
454 cases (Hcompare … Htapeb) -Hcompare -Htapeb * #_ #_ #Hcompare
455 cases (Hcompare c c1 l1 l3 (l2@[〈bar,false〉]) (l4@〈grid,false〉::rs) eqlen Hl1bars Hl3 Hl1marks … (refl …) Hc ?)
457 [* #Htemp destruct (Htemp) #Htapec %1 % [%]
458 >Htapec in Hor; -Htapec *
459 [2: * #t3 * whd in ⊢ (%→?); #H @False_ind
460 cases (H … (refl …)) whd in ⊢ ((??%?)→?); #H destruct (H)
461 |* #taped * whd in ⊢ (%→?); #Htaped cases (Htaped ? (refl …)) -Htaped *
462 #Htaped whd in ⊢ (%→?); #Htapeout >Htapeout >Htaped >associative_append
465 |* #la * #c' * #d' * #lb * #lc * * * #H1 #H2 #H3 #Htapec
466 cut (〈c,false〉::l1 ≠ 〈c1,false〉::l3)
468 [@(not_to_not …H1) normalize #H destruct %
469 |#x #tl @not_to_not normalize #H destruct //
472 cut (bit_or_null d' = true)
474 [normalize in ⊢ (%→?); #H destruct //
475 |#x #tl #H @(Hl3 〈d',false〉)
476 normalize in H; destruct @memb_append_l2 @memb_hd
479 >Htapec in Hor; -Htapec *
480 [* #taped * whd in ⊢ (%→?); #H @False_ind
481 cases (H … (refl …)) >(bit_or_null_not_grid ? Hd') #Htemp destruct (Htemp)
482 |* #taped * whd in ⊢ (%→?); #H cases (H … (refl …)) -H #_
483 #Htaped * #tapee * whd in ⊢ (%→?); #Htapee
484 <(associative_append ? lc (〈comma,false〉::l4)) in Htaped; #Htaped
485 cases (Htapee … Htaped ???) -Htaped -Htapee
486 [* #rs3 * * (* we proceed by cases on rs4 *)
487 [(* rs4 is empty : the case is absurd since the tape
488 cannot end with a bar *)
489 * #d * #b * * * #Heq1 @False_ind
490 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut
491 >Hcut in Htable; >H3 >associative_append
492 normalize >Heq1 >Hcut <associative_append >Hcut
493 <associative_append #Htable @(absurd … Htable)
496 * #d2 #b2 #rs3' * #d * #b * * * #Heq1 #Hnobars
497 cut (memb STape 〈d2,b2〉 (l2@〈bar,false〉::〈c1,false〉::l3@〈comma,false〉::l4) = true)
498 [@memb_append_l2 @memb_cons
499 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut
500 >Hcut >H3 >associative_append @memb_append_l2
501 @memb_cons >Heq1 @memb_append_l2 @memb_cons @memb_hd] #d2intable
502 cut (is_grid d2 = false)
503 [@(no_grids_in_table … Htable … 〈d2,b2〉 d2intable)] #Hd2
505 [@(no_marks_in_table … Htable … 〈d2,b2〉 d2intable)] #Hb2
506 >Hb2 in Heq1; #Heq1 -Hb2 -b2
507 whd in ⊢ ((???%)→?); #Htemp destruct (Htemp) #Htapee >Htapee -Htapee *
508 [(* we know current is not grid *)
509 * #tapef * whd in ⊢ (%→?); #Htapef
510 cases (Htapef … (refl …)) >Hd2 #Htemp destruct (Htemp)
511 |* #tapef * whd in ⊢ (%→?); #Htapef
512 cases (Htapef … (refl …)) #_ -Htapef #Htapef
513 * #tapeg >Htapef -Htapef *
516 #H lapply (H … (refl …)) whd in ⊢ (???%→?); -H #Htapeg
519 whd in ⊢ (%→?); #Htapeout
520 %1 cases (some_option_hd ? (reverse ? (reverse ? la)) 〈c',true〉)
523 (Htapeout (reverse ? rs3 @〈d',false〉::reverse ? la@reverse ? (l2@[〈bar,false〉])@(〈grid,false〉::reverse ? lb))
524 c' (reverse ? la) false ls bar (〈d2,true〉::rs3'@〈grid,false〉::rs) c00 b00 ?????) -Htapeout
525 [whd in ⊢ (??(??%??)?); @eq_f3 [2:%|3: %]
527 generalize in match (〈c',true〉::reverse ? la@〈grid,false〉::ls); #l
528 whd in ⊢ (???(???%)); >associative_append >associative_append %
529 |>reverse_cons @Hoption
531 [normalize in ⊢ (%→?); #Htemp destruct (Htemp)
532 @injective_notb @notgridc
533 |#x #tl normalize in ⊢ (%→?); #Htemp destruct (Htemp)
534 @bit_or_null_not_grid @(Hl1bars 〈c',false〉) @memb_append_l2 @memb_hd
536 |cut (only_bits_or_nulls (la@(〈c',false〉::lb)))
537 [<H2 whd #c0 #Hmemb cases (orb_true_l … Hmemb)
538 [#eqc0 >(\P eqc0) @Hc |@Hl1bars]
539 |#Hl1' #x #Hx @bit_or_null_not_grid @Hl1'
540 @memb_append_l1 @daemon
543 |>reverse_append >reverse_cons >reverse_reverse
544 >reverse_append >reverse_reverse
545 >reverse_cons >reverse_append >reverse_reverse
546 >reverse_append >reverse_cons >reverse_reverse
548 #Htapeout % [@Hnoteq]
550 cut (∃rs32.rs3 = lc@〈comma,false〉::rs32)
551 [ (*cases (tech_split STape (λc.c == 〈bar,false〉) l4)
553 | * #l41 * * #cbar #bfalse * #l42 * * #Hbar #Hl4 #Hl41
554 @(ex_intro ?? l41) >Hl4 in Heq1; #Heq1
556 cut (sublist … lc l3)
557 [ #x #Hx cases la in H3;
558 [ normalize #H3 destruct (H3) @Hx
559 | #p #la' normalize #Hla' destruct (Hla')
560 @memb_append_l2 @memb_cons @Hx ] ] #Hsublist*)
564 (〈c1,false〉::l3@〈comma,false〉::l4= la@〈d',false〉::rs3@〈bar,false〉::〈d2,b2〉::rs3')
566 cut (l4=rs32@〈bar,false〉::〈d2,false〉::rs3')
567 [ >Hrs3 in Heq1; @daemon ] #Hl4
568 @(ex_intro … rs32) @(ex_intro … rs3') %
572 |(*>Hrs3 *)>append_cons
573 > (?:l1@〈grid,false〉::l2@〈bar,false〉::〈c1,false〉::l3@〈comma,false〉::rs32@〈bar,false〉::〈d2,true〉::rs3'@〈grid,false〉::rs
574 = (l1@〈grid,false〉::l2@〈bar,false〉::〈c1,false〉::l3@〈comma,false〉::rs32@[〈bar,false〉])@〈d2,true〉::rs3'@〈grid,false〉::rs)
575 [|>associative_append normalize
576 >associative_append normalize
577 >associative_append normalize
578 >associative_append normalize
581 @(injective_append … (〈d2,false〉::rs3'))
582 >(?:(la@[〈c',false〉])@((((lb@[〈grid,false〉])@l2@[〈bar,false〉])@la)@[〈d',false〉])@rs3
583 =((la@〈c',false〉::lb)@([〈grid,false〉]@l2@[〈bar,false〉]@la@[〈d',false〉]@rs3)))
584 [|>associative_append >associative_append
585 >associative_append >associative_append >associative_append
586 >associative_append >associative_append % ]
587 <H2 normalize (* <Hrs3 *)
588 >associative_append >associative_append >associative_append
589 @eq_f normalize @eq_f >associative_append
590 >associative_append @eq_f normalize @eq_f
591 >(append_cons ? 〈d',false〉) >associative_append
592 <Heq1 >Hl4 <associative_append <append_cons
594 >associative_append normalize
595 >associative_append normalize %
601 |* #Hnobars #Htapee >Htapee -Htapee *
602 [whd in ⊢ (%→?); * #tapef * whd in ⊢ (%→?); #Htapef
603 cases (Htapef … (refl …)) -Htapef #_ #Htapef >Htapef -Htapef
604 whd in ⊢ (%→?); #Htapeout %2
605 >(Htapeout … (refl …)) %
608 | whd #x #Hx @Hnobars @memb_append_l2 @memb_cons //
612 |whd in ⊢ (%→?); * #tapef * whd in ⊢ (%→?); #Htapef
613 cases (Htapef … (refl …)) -Htapef
614 whd in ⊢ ((??%?)→?); #Htemp destruct (Htemp)
616 |(* no marks in table *)
617 #x #membx @(no_marks_in_table … Htable)
618 @memb_append_l2 @memb_cons
619 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut >Hcut
620 >H3 >associative_append @memb_append_l2 @memb_cons @membx
621 |(* no grids in table *)
622 #x #membx @(no_grids_in_table … Htable)
623 @memb_append_l2 @memb_cons
624 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut >Hcut
625 >H3 >associative_append @memb_append_l2 @memb_cons @membx
626 |whd in ⊢ (??%?); >(bit_or_null_not_grid … Hd') >(bit_or_null_not_bar … Hd') %
629 |#x #membx @(no_marks_in_table … Htable)
630 @memb_append_l2 @memb_cons @memb_cons @memb_append_l1 @membx
631 |#x #membx @(no_marks_in_table … Htable)
632 cases (memb_append … membx) -membx #membx
633 [@memb_append_l1 @membx | @memb_append_l2 >(memb_single … membx) @memb_hd]
634 |>associative_append %
643 scrolls through the tuples in the transition table until one matching the
644 current configuration is found
647 definition match_tuple ≝ whileTM ? match_tuple_step (inr … (inl … (inr … 0))).
649 definition R_match_tuple ≝ λt1,t2.
651 is_bit c = true → only_bits_or_nulls l1 → is_bit c1 = true → n = |l1| →
652 table_TM (S n) (〈c1,false〉::l2) →
653 t1 = midtape STape (〈grid,false〉::ls) 〈c,true〉
654 (l1@〈grid,false〉::〈c1,true〉::l2@〈grid,false〉::rs) →
657 〈c1,false〉::l2 = l3@〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l4 ∧
658 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls) 〈grid,false〉
659 (l3@〈c,false〉::l1@〈comma,true〉::newc@〈comma,false〉::mv::l4@〈grid,false〉::rs))
661 (* non facciamo match su nessuna tupla;
662 non specifichiamo condizioni sul nastro di output, perché
663 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
664 (current ? t2 = Some ? 〈grid,true〉 ∧
666 〈c1,false〉::l2 ≠ l3@〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l4).