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.
23 = true → is_bit (\fst c) = true.
25 definition only_bits_or_nulls ≝ λl.
26 ∀c.memb STape c l = true → bit_or_null (\fst c) = true.
28 definition no_grids ≝ λl.
29 ∀c.memb STape c l = true → is_grid (\fst c) = false.
31 definition no_bars ≝ λl.
32 ∀c.memb STape c l = true → is_bar (\fst c) = false.
34 definition no_marks ≝ λl.
35 ∀c.memb STape c l = true → is_marked ? c = false.
37 lemma bit_not_grid: ∀d. is_bit d = true → is_grid d = false.
38 * // normalize #H destruct
41 lemma bit_or_null_not_grid: ∀d. bit_or_null d = true → is_grid d = false.
42 * // normalize #H destruct
45 lemma bit_not_bar: ∀d. is_bit d = true → is_bar d = false.
46 * // normalize #H destruct
49 lemma bit_or_null_not_bar: ∀d. bit_or_null d = true → is_bar d = false.
50 * // normalize #H destruct
53 definition mk_tuple ≝ λqin,cin,qout,cout,mv.
54 〈bar,false〉 :: qin @ cin :: 〈comma,false〉:: qout @ cout :: 〈comma,false〉 :: [mv].
56 (* by definition, a tuple is not marked *)
57 definition tuple_TM : nat → list STape → Prop ≝
58 λn,t.∃qin,cin,qout,cout,mv.
59 no_marks qin ∧ no_marks qout ∧
60 only_bits qin ∧ only_bits qout ∧
61 bit_or_null cin = true ∧ bit_or_null cout = true ∧ bit_or_null mv = true ∧
62 (cout = null → mv = null) ∧
63 |qin| = n ∧ |qout| = n ∧
64 t = mk_tuple qin 〈cin,false〉 qout 〈cout,false〉 〈mv,false〉.
66 inductive table_TM (n:nat) : list STape → Prop ≝
67 | ttm_nil : table_TM n []
68 | ttm_cons : ∀t1,T.tuple_TM n t1 → table_TM n T → table_TM n (t1@T).
70 inductive match_in_table (n:nat) (qin:list STape) (cin: STape)
71 (qout:list STape) (cout:STape) (mv:STape)
75 tuple_TM n (mk_tuple qin cin qout cout mv) →
76 match_in_table n qin cin qout cout mv
77 (mk_tuple qin cin qout cout mv @tb)
79 ∀qin0,cin0,qout0,cout0,mv0,tb.
80 tuple_TM n (mk_tuple qin0 cin0 qout0 cout0 mv0) →
81 match_in_table n qin cin qout cout mv tb →
82 match_in_table n qin cin qout cout mv
83 (mk_tuple qin0 cin0 qout0 cout0 mv0@tb).
85 axiom tuple_len : ∀n,t.tuple_TM n t → |t| = 2*n+6.
86 axiom append_eq_tech1 :
87 ∀A,l1,l2,l3,l4.l1@l2 = l3@l4 → |l1| < |l3| → ∃la:list A.l1@la = l3.
88 axiom append_eq_tech2 :
89 ∀A,l1,l2,l3,l4,a.l1@a::l2 = l3@l4 → memb A a l4 = false → ∃la:list A.l3 = l1@a::la.
90 (*axiom list_decompose_cases :
91 ∀A,l1,l2,l3,l4,a.l1@a::l2 = l3@l4 → ∃la,lb:list A.l3 = la@a::lb ∨ l4 = la@a::lb.
92 axiom list_decompose_l :
93 ∀A,l1,l2,l3,l4,a.l1@a::l2 = l3@l4 → memb A a l4 = false →
94 ∃la,lb.l2 = la@lb ∧ l3 = l1@a::la.*)
95 axiom list_decompose_r :
96 ∀A,l1,l2,l3,l4,a.l1@a::l2 = l3@l4 → memb A a l3 = false →
97 ∃la,lb.l1 = la@lb ∧ l4 = lb@a::l2.
98 (*axiom list_decompose_memb :
99 ∀A,l1,l2,l3,l4,a.l1@a::l2 = l3@l4 → |l1| < |l3| → memb A a l3 = true.*)
101 lemma table_invert_r : ∀n,t,T.
102 tuple_TM n t → table_TM n (t@T) → table_TM n T.
103 #n #t #T #Htuple #Htable inversion Htable
104 [ cases Htuple #qin * #cin * #qout * #cout * #mv * #_ #Ht >Ht
105 normalize #Hfalse destruct (Hfalse)
106 | #t0 #T0 #Htuple0 #Htable0 #_ #Heq
107 lapply (append_l2_injective ?????? Heq)
108 [ >(tuple_len … Htuple) >(tuple_len … Htuple0) % ]
109 -Heq #Heq destruct (Heq) // ]
112 lemma match_in_table_to_tuple :
113 ∀n,T,qin,cin,qout,cout,mv.
114 match_in_table n qin cin qout cout mv T → table_TM n T →
115 tuple_TM n (mk_tuple qin cin qout cout mv).
116 #n #T #qin #cin #qout #cout #mv #Hmatch elim Hmatch
118 | #qin0 #cin0 #qout0 #cout0 #mv0 #tb #Htuple #Hmatch #IH #Htable
119 @IH @(table_invert_r ???? Htable) @Htuple
123 lemma match_in_table_append :
124 ∀n,T,qin,cin,qout,cout,mv,t.
126 match_in_table n qin cin qout cout mv (t@T) →
127 t = mk_tuple qin cin qout cout mv ∨ match_in_table n qin cin qout cout mv T.
128 #n #T #qin #cin #qout #cout #mv #t #Ht #Hmatch inversion Hmatch
129 [ #T0 #H #H1 % >(append_l1_injective … H1) //
130 >(tuple_len … Ht) >(tuple_len … H) %
131 | #qin0 #cin0 #qout0 #cout0 #mv0 #T0 #H #H1 #_ #H2 %2
132 >(append_l2_injective … H2) // >(tuple_len … Ht) >(tuple_len … H) %
136 lemma generic_match_to_match_in_table_tech :
137 ∀n,t,T0,T1,T2.tuple_TM n t → table_TM n (T1@〈bar,false〉::T2) →
138 t@T0 = T1@〈bar,false〉::T2 → T1 = [] ∨ ∃T3.T1 = t@T3.
139 #n #t #T0 #T1 #T2 #Ht cases T1
141 | normalize #c #T1c #Htable #Heq %2
142 cases Ht in Heq; #qin * #cin * #qout * #cout * #mv **********
143 #Hqin1 #Hqout1 #Hqin2 #Hqout2 #Hcin #Hcout #Hmv #Hcoutmv #Hqinlen #Hqoutlen
144 #Heqt >Heqt whd in ⊢ (??%%→?); #Ht lapply (cons_injective_r ????? Ht)
145 #Ht' cases (list_decompose_r STape … (sym_eq … Ht') ?)
146 [ #la * #lb * #HT1c #HT0 %{lb} >HT1c @(eq_f2 ??? (append ?) (c::la)) //
147 >HT0 in Ht'; >HT1c >associative_append in ⊢ (???%→?); #Ht'
148 <(append_l1_injective_r … Ht') // <(cons_injective_l ????? Ht) %
152 lemma generic_match_to_match_in_table :
154 ∀qin,cin,qout,cout,mv.|qin| = n → |qout| = n →
155 only_bits qin → only_bits qout →
156 bit_or_null (\fst cin) = true → bit_or_null (\fst cout) = true →
157 bit_or_null (\fst mv) = true →
159 T = (t1@〈bar,false〉::qin@cin::〈comma,false〉::qout@cout::〈comma,false〉::[mv])@t2 →
160 match_in_table n qin cin qout cout mv T.
161 #n #T #Htable #qin #cin #qout #cout #mv #Hlenqin #Hlenqout
162 #Hqinbits #Hqoutbits #Hcin #Hcout #Hmv
164 [ * [ #t2 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
165 | #c0 #t1 #t2 normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) ]
166 | #tuple #T0 #H1 #Htable0#IH #t1 #t2 #HT cases H1 #qin0 * #cin0 * #qout0 * #cout0 * #mv0
168 #Hqin0marks #Hqout0marks #Hqin0bits #Hqout0bits #Hcin0 #Hcout0 #Hmv0 #Hcout0mv0
169 #Hlenqin0 #Hlenqout0 #Htuple
170 lapply (generic_match_to_match_in_table_tech n ? T0 t1
171 (qin@cin::〈comma,false〉::qout@[cout;〈comma,false〉;mv]@t2) H1) #Htmp
173 lapply (ttm_cons … T0 H1 Htable0) <Htuple in ⊢ (%→?); >HT
174 >associative_append normalize >associative_append normalize
175 >associative_append #Htable cases (Htmp Htable ?)
176 [ #Ht1 >Htuple in HT; >Ht1 normalize in ⊢ (??%%→?);
177 >associative_append >associative_append #HT
178 cut (qin0 = qin ∧ (〈cin0,false〉 = cin ∧ (qout0 = qout ∧
179 (〈cout0,false〉 = cout ∧ (〈mv0,false〉 = mv ∧ T0 = t2)))))
180 [ lapply (cons_injective_r ????? HT) -HT #HT
181 lapply (append_l1_injective … HT) [ >Hlenqin @Hlenqin0 ]
182 #Hqin % [ @Hqin ] -Hqin
183 lapply (append_l2_injective … HT) [ >Hlenqin @Hlenqin0 ] -HT #HT
184 lapply (cons_injective_l ????? HT) #Hcin % [ @Hcin ] -Hcin
185 lapply (cons_injective_r ????? HT) -HT #HT
186 lapply (cons_injective_r ????? HT) -HT
187 >associative_append >associative_append #HT
188 lapply (append_l1_injective … HT) [ >Hlenqout @Hlenqout0 ]
189 #Hqout % [ @Hqout ] -Hqout
190 lapply (append_l2_injective … HT) [ >Hlenqout @Hlenqout0 ] -HT normalize #HT
191 lapply (cons_injective_l ????? HT) #Hcout % [ @Hcout ] -Hcout
192 lapply (cons_injective_r ????? HT) -HT #HT
193 lapply (cons_injective_r ????? HT) -HT #HT
194 lapply (cons_injective_l ????? HT) #Hmv % [ @Hmv ] -Hmv
195 @(cons_injective_r ????? HT) ]
196 -HT * #Hqin * #Hcin * #Hqout * #Hcout * #Hmv #HT0
197 >(?:〈bar,false〉::qin0@(〈cin0,false〉::〈comma,false〉::qout0@
198 [〈cout0,false〉;〈comma,false〉;〈mv0,false〉])@T0 = tuple@T0)
199 [ >Htuple >Hqin >Hqout >Hcin >Hcout >Hmv % //
200 | >Htuple normalize >associative_append normalize >associative_append
201 normalize >associative_append % ]
202 | * #T3 #HT3 >HT3 in HT; >associative_append; >associative_append #HT
203 lapply (append_l2_injective … HT) // -HT #HT %2 //
204 @(IH T3 t2) >HT >associative_append %
205 |>HT >associative_append normalize >associative_append normalize
206 >associative_append % ]
211 lemma table_invert_l : ∀n,T0,qin,cin,qout,cout,mv.
212 table_TM n (mk_tuple qin cin qout cout mv@〈bar,false〉::T0) →
213 tuple_TM n (mk_tuple qin cin qout cout mv).
214 #n #T #qin #cin #qout #cout #mv #HT inversion HT
215 [ change with (append ???) in ⊢ (??(??%?)?→?);cases qin [ #Hfalse | #t0 #ts0 #Hfalse] normalize in Hfalse; destruct (Hfalse)
216 | #t0 #T0 #Ht0 #HT0 #_
219 lemma table_invert_r : ∀n,T0,qin,cin,qout,cout,mv.
220 table n (mk_tuple qin cin qout cout mv@〈bar,false〉::T0) → table n T0.
223 lemma no_grids_in_tuple : ∀n,l.tuple_TM n l → no_grids l.
224 #n #l * #qin * #cin * #qout * #cout * #mv * * * * * * * * * *
225 #_ #_ #Hqin #Hqout #Hcin #Hcout #Hmv #_ #_ #_ #Hl >Hl
226 #c #Hc cases (orb_true_l … Hc) -Hc #Hc
228 | cases (memb_append … Hc) -Hc #Hc
229 [ @bit_not_grid @(Hqin … Hc)
230 | cases (orb_true_l … Hc) -Hc #Hc
231 [ change with (c == 〈cin,false〉 = true) in Hc; >(\P Hc) @bit_or_null_not_grid //
232 | cases (orb_true_l … Hc) -Hc #Hc
233 [ change with (c == 〈comma,false〉 = true) in Hc; >(\P Hc) %
234 | cases (memb_append …Hc) -Hc #Hc
235 [ @bit_not_grid @(Hqout … Hc)
236 | cases (orb_true_l … Hc) -Hc #Hc
237 [ change with (c == 〈cout,false〉 = true) in Hc; >(\P Hc) @bit_or_null_not_grid //
238 | cases (orb_true_l … Hc) -Hc #Hc
239 [ change with (c == 〈comma,false〉 = true) in Hc; >(\P Hc) %
240 | >(memb_single … Hc) @bit_or_null_not_grid @Hmv
244 lemma no_marks_in_tuple : ∀n,l.tuple_TM n l → no_marks l.
245 #n #l * #qin * #cin * #qout * #cout * #mv * * * * * * * * * *
246 #Hqin #Hqout #_ #_ #_ #_ #_ #_ #_ #_ #Hl >Hl
247 #c #Hc cases (orb_true_l … Hc) -Hc #Hc
249 | cases (memb_append … Hc) -Hc #Hc
251 | cases (orb_true_l … Hc) -Hc #Hc
252 [ change with (c == 〈cin,false〉 = true) in Hc; >(\P Hc) %
253 | cases (orb_true_l … Hc) -Hc #Hc
254 [ change with (c == 〈comma,false〉 = true) in Hc; >(\P Hc) %
255 | cases (memb_append … Hc) -Hc #Hc
257 | cases (orb_true_l … Hc) -Hc #Hc
258 [ change with (c == 〈cout,false〉 = true) in Hc; >(\P Hc) %
259 | cases (orb_true_l … Hc) -Hc #Hc
260 [ change with (c == 〈comma,false〉 = true) in Hc; >(\P Hc) %
261 | >(memb_single … Hc) %
265 lemma no_grids_in_table: ∀n.∀l.table_TM n l → no_grids l.
267 [normalize #c #H destruct
268 |#t1 #t2 #Ht1 #Ht2 #IH lapply (no_grids_in_tuple … Ht1) -Ht1 #Ht1 #x #Hx
269 cases (memb_append … Hx) -Hx #Hx
274 lemma no_marks_in_table: ∀n.∀l.table_TM n l → no_marks l.
276 [normalize #c #H destruct
277 |#t1 #t2 #Ht1 #Ht2 #IH lapply (no_marks_in_tuple … Ht1) -Ht1 #Ht1 #x #Hx
278 cases (memb_append … Hx) -Hx #Hx
283 axiom last_of_table: ∀n,l,b.¬ table_TM n (l@[〈bar,b〉]).
286 l0 x* a l1 x0* a0 l2 ------> l0 x a* l1 x0 a0* l2
289 if current (* x *) = #
292 then move_right; ----
294 if current (* x0 *) = 0
295 then advance_mark ----
299 else x = 1 (* analogo *)
305 MARK NEXT TUPLE machine
306 (partially axiomatized)
308 marks the first character after the first bar (rightwards)
311 definition bar_or_grid ≝ λc:STape.is_bar (\fst c) ∨ is_grid (\fst c).
313 definition mark_next_tuple ≝
314 seq ? (adv_to_mark_r ? bar_or_grid)
315 (ifTM ? (test_char ? (λc:STape.is_bar (\fst c)))
316 (move_right_and_mark ?) (nop ?) tc_true).
318 definition R_mark_next_tuple ≝
321 (* c non può essere un separatore ... speriamo *)
322 t1 = midtape STape ls c (rs1@〈grid,false〉::rs2) →
323 no_marks rs1 → no_grids rs1 → bar_or_grid c = false →
324 (∃rs3,rs4,d,b.rs1 = rs3 @ 〈bar,false〉 :: rs4 ∧
326 Some ? 〈d,b〉 = option_hd ? (rs4@〈grid,false〉::rs2) ∧
327 t2 = midtape STape (〈bar,false〉::reverse ? rs3@c::ls) 〈d,true〉 (tail ? (rs4@〈grid,false〉::rs2)))
329 (no_bars rs1 ∧ t2 = midtape ? (reverse ? rs1@c::ls) 〈grid,false〉 rs2).
333 (∀x.memb A x l = true → f x = false) ∨
334 (∃l1,c,l2.f c = true ∧ l = l1@c::l2 ∧ ∀x.memb ? x l1 = true → f x = false).
336 [ % #x normalize #Hfalse *)
338 theorem sem_mark_next_tuple :
339 Realize ? mark_next_tuple R_mark_next_tuple.
341 lapply (sem_seq ? (adv_to_mark_r ? bar_or_grid)
342 (ifTM ? (test_char ? (λc:STape.is_bar (\fst c))) (move_right_and_mark ?) (nop ?) tc_true) ????)
343 [@sem_if [5: // |6: @sem_move_right_and_mark |7: // |*:skip]
345 |||#Hif cases (Hif intape) -Hif
346 #j * #outc * #Hloop * #ta * #Hleft #Hright
347 @(ex_intro ?? j) @ex_intro [|% [@Hloop] ]
349 #ls #c #rs1 #rs2 #Hrs #Hrs1 #Hrs1' #Hc
351 [ * #Hfalse >Hfalse in Hc; #Htf destruct (Htf)
352 | * #_ #Hta cases (tech_split STape (λc.is_bar (\fst c)) rs1)
353 [ #H1 lapply (Hta rs1 〈grid,false〉 rs2 (refl ??) ? ?)
354 [ * #x #b #Hx whd in ⊢ (??%?); >(Hrs1' … Hx) >(H1 … Hx) %
356 | -Hta #Hta cases Hright
357 [ * #tb * whd in ⊢ (%→?); #Hcurrent
358 @False_ind cases (Hcurrent 〈grid,false〉 ?)
359 [ normalize in ⊢ (%→?); #Hfalse destruct (Hfalse)
361 | * #tb * whd in ⊢ (%→?); #Hcurrent
362 cases (Hcurrent 〈grid,false〉 ?)
363 [ #_ #Htb whd in ⊢ (%→?); #Houtc
366 | >Houtc >Htb >Hta % ]
370 | * #rs3 * #c0 * #rs4 * * #Hc0 #Hsplit #Hrs3
371 % @(ex_intro ?? rs3) @(ex_intro ?? rs4)
372 lapply (Hta rs3 c0 (rs4@〈grid,false〉::rs2) ???)
373 [ #x #Hrs3' whd in ⊢ (??%?); >Hsplit in Hrs1;>Hsplit in Hrs3;
374 #Hrs3 #Hrs1 >(Hrs1 …) [| @memb_append_l1 @Hrs3'|]
375 >(Hrs3 … Hrs3') @Hrs1' >Hsplit @memb_append_l1 //
376 | whd in ⊢ (??%?); >Hc0 %
377 | >Hsplit >associative_append % ] -Hta #Hta
379 [ * #tb * whd in ⊢ (%→?); #Hta'
382 [ #_ #Htb' >Htb' in Htb; #Htb
383 generalize in match Hsplit; -Hsplit
385 [ #Hta #Hsplit >(Htb … Hta)
386 >(?:c0 = 〈bar,false〉)
387 [ @(ex_intro ?? grid) @(ex_intro ?? false)
389 [(* Hsplit *) @daemon |(*Hrs3*) @daemon ] | % ] | % ]
390 | (* Hc0 *) @daemon ]
391 | #r5 #rs5 >(eq_pair_fst_snd … r5)
392 #Hta #Hsplit >(Htb … Hta)
393 >(?:c0 = 〈bar,false〉)
394 [ @(ex_intro ?? (\fst r5)) @(ex_intro ?? (\snd r5))
395 % [ % [ % [ (* Hc0, Hsplit *) @daemon | (*Hrs3*) @daemon ] | % ]
396 | % ] | (* Hc0 *) @daemon ] ] | >Hta % ]
397 | * #tb * whd in ⊢ (%→?); #Hta'
400 [ #Hfalse @False_ind >Hfalse in Hc0;
406 definition init_current_on_match ≝
408 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
409 (seq ? (move_r ?) (mark ?)))).
411 definition R_init_current_on_match ≝ λt1,t2.
412 ∀l1,l2,c,rs. no_grids l1 → is_grid c = false →
413 t1 = midtape STape (l1@〈c,false〉::〈grid,false〉::l2) 〈grid,false〉 rs →
414 t2 = midtape STape (〈grid,false〉::l2) 〈c,true〉 ((reverse ? l1)@〈grid,false〉::rs).
416 lemma sem_init_current_on_match :
417 Realize ? init_current_on_match R_init_current_on_match.
419 cases (sem_seq ????? (sem_move_l ?)
420 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
421 (sem_seq ????? (sem_move_r ?) (sem_mark ?))) intape)
422 #k * #outc * #Hloop #HR
423 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
424 #l1 #l2 #c #rs #Hl1 #Hc #Hintape
425 cases HR -HR #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta -Hintape
426 generalize in match Hl1; cases l1
427 [#Hl1 whd in ⊢ ((???(??%%%))→?); #Hta
428 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hta) -Hta
429 [* >Hc #Htemp destruct (Htemp) ]
430 * #_ #Htc lapply (Htc [ ] 〈grid,false〉 ? (refl ??) (refl …) Hl1)
431 whd in ⊢ ((???(??%%%))→?); -Htc #Htc
432 * #td * whd in ⊢ (%→?); #Htd lapply (Htd … Htc) -Htc -Htd
433 whd in ⊢ ((???(??%%%))→?); #Htd
434 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htd) -Houtc #Houtc
436 |#d #tl #Htl whd in ⊢ ((???(??%%%))→?); #Hta
437 * #tb * whd in ⊢ (%→?); #Htb cases (Htb … Hta) -Htb
438 [* >(Htl … (memb_hd …)) #Htemp destruct (Htemp)]
439 * #Hd >append_cons #Htb lapply (Htb … (refl ??) (refl …) ?)
440 [#x #membx cases (memb_append … membx) -membx #membx
441 [@Htl @memb_cons @membx | >(memb_single … membx) @Hc]]-Htb #Htb
442 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htb -Htc
443 >reverse_append >associative_append whd in ⊢ ((???(??%%%))→?); #Htc
444 whd in ⊢ (%→?); #Houtc lapply (Houtc … Htc) -Houtc #Houtc
445 >Houtc >reverse_cons >associative_append %
450 definition init_current_gen ≝
451 seq ? (adv_to_mark_l ? (is_marked ?))
452 (seq ? (clear_mark ?)
454 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
455 (seq ? (move_r ?) (mark ?))))).
457 definition R_init_current_gen ≝ λt1,t2.
458 ∀l1,c,l2,b,l3,c1,rs,c0,b0. no_marks l1 → no_grids l2 →
459 Some ? 〈c0,b0〉 = option_hd ? (reverse ? (〈c,true〉::l2)) →
460 t1 = midtape STape (l1@〈c,true〉::l2@〈grid,b〉::l3) 〈c1,false〉 rs →
461 t2 = midtape STape (〈grid,b〉::l3) 〈c0,true〉
462 ((tail ? (reverse ? (l1@〈c,false〉::l2))@〈c1,false〉::rs)).
464 lemma sem_init_current_gen : Realize ? init_current_gen R_init_current_gen.
466 cases (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
467 (sem_seq ????? (sem_clear_mark ?)
468 (sem_seq ????? (sem_move_l ?)
469 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
470 (sem_seq ????? (sem_move_r ?) (sem_mark ?))))) intape)
471 #k * #outc * #Hloop #HR
472 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
473 #l1 #c #l2 #b #l3 #c1 #rs #c0 #b0 #Hl1 #Hl2 #Hc #Hintape
474 cases HR -HR #ta * whd in ⊢ (%→?); #Hta cases (Hta … Hintape) -Hta -Hintape
475 [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
476 * #_ #Hta lapply (Hta l1 〈c,true〉 ? (refl ??) ??) [@Hl1|%] -Hta #Hta
477 * #tb * whd in ⊢ (%→?); #Htb lapply (Htb … Hta) -Htb -Hta #Htb
478 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc -Htb
479 generalize in match Hc; generalize in match Hl2; cases l2
480 [#_ whd in ⊢ ((???%)→?); #Htemp destruct (Htemp)
481 whd in ⊢ ((???(??%%%))→?); #Htc
482 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
483 [2: * whd in ⊢ (??%?→?); #Htemp destruct (Htemp) ]
484 * #_ #Htd >Htd in Htc; -Htd #Htd
485 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Htd
486 >reverse_append >reverse_cons
487 whd in ⊢ ((???(??%%%))→?); #Hte
488 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
490 |#d #tl #Htl #Hc0 whd in ⊢ ((???(??%%%))→?); #Htc
491 * #td * whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd
492 [* >(Htl … (memb_hd …)) whd in ⊢ (??%?→?); #Htemp destruct (Htemp)]
493 * #Hd #Htd lapply (Htd … (refl ??) (refl ??) ?)
494 [#x #membx @Htl @memb_cons @membx] -Htd #Htd
495 * #te * whd in ⊢ (%→?); #Hte lapply (Hte … Htd) -Htd
496 >reverse_append >reverse_cons >reverse_cons
497 >reverse_cons in Hc0; >reverse_cons cases (reverse ? tl)
498 [normalize in ⊢ (%→?); #Hc0 destruct (Hc0) #Hte
499 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
501 |* #c2 #b2 #tl2 normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
502 whd in ⊢ ((???(??%%%))→?); #Hte
503 whd in ⊢ (%→?); #Houtc lapply (Houtc … Hte) -Houtc -Hte #Houtc
504 >Houtc >associative_append >associative_append >associative_append %
510 definition init_current ≝
511 seq ? (adv_to_mark_l ? (is_marked ?))
512 (seq ? (clear_mark ?)
513 (seq ? (adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
514 (seq ? (move_r ?) (mark ?)))).
516 definition R_init_current ≝ λt1,t2.
517 ∀l1,c,l2,b,l3,c1,rs,c0,b0. no_marks l1 → no_grids l2 → is_grid c = false →
518 Some ? 〈c0,b0〉 = option_hd ? (reverse ? (〈c,true〉::l2)) →
519 t1 = midtape STape (l1@〈c,true〉::l2@〈grid,b〉::l3) 〈c1,false〉 rs →
520 t2 = midtape STape (〈grid,b〉::l3) 〈c0,true〉
521 ((tail ? (reverse ? (l1@〈c,false〉::l2))@〈c1,false〉::rs)).
523 lemma sem_init_current : Realize ? init_current R_init_current.
525 cases (sem_seq ????? (sem_adv_to_mark_l ? (is_marked ?))
526 (sem_seq ????? (sem_clear_mark ?)
527 (sem_seq ????? (sem_adv_to_mark_l ? (λc:STape.is_grid (\fst c)))
528 (sem_seq ????? (sem_move_r ?) (sem_mark ?)))) intape)
529 #k * #outc * #Hloop #HR
530 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop]
531 cases HR -HR #ta * whd in ⊢ (%→?); #Hta
532 * #tb * whd in ⊢ (%→?); #Htb
533 * #tc * whd in ⊢ (%→?); #Htc
534 * #td * whd in ⊢ (%→%→?); #Htd #Houtc
535 #l1 #c #l2 #b #l3 #c1 #rs #c0 #b0 #Hl1 #Hl2 #Hc #Hc0 #Hintape
536 cases (Hta … Hintape) [ * #Hfalse normalize in Hfalse; destruct (Hfalse) ]
537 -Hta * #_ #Hta lapply (Hta l1 〈c,true〉 ? (refl ??) ??) [@Hl1|%]
538 -Hta #Hta lapply (Htb … Hta) -Htb #Htb cases (Htc … Htb) [ >Hc -Hc * #Hc destruct (Hc) ]
539 -Htc * #_ #Htc lapply (Htc … (refl ??) (refl ??) ?) [@Hl2]
540 -Htc #Htc lapply (Htd … Htc) -Htd
541 >reverse_append >reverse_cons
542 >reverse_cons in Hc0; cases (reverse … l2)
543 [ normalize in ⊢ (%→?); #Hc0 destruct (Hc0)
544 #Htd >(Houtc … Htd) %
545 | * #c2 #b2 #tl2 normalize in ⊢ (%→?);
546 #Hc0 #Htd >(Houtc … Htd)
547 whd in ⊢ (???%); destruct (Hc0)
548 >associative_append >associative_append %
552 definition match_tuple_step ≝
553 ifTM ? (test_char ? (λc:STape.¬ is_grid (\fst c)))
556 (ifTM ? (test_char ? (λc:STape.is_grid (\fst c)))
558 (seq ? mark_next_tuple
559 (ifTM ? (test_char ? (λc:STape.is_grid (\fst c)))
560 (mark ?) (seq ? (move_l ?) init_current) tc_true)) tc_true)))
563 definition R_match_tuple_step_true ≝ λt1,t2.
564 ∀ls,cur,rs.t1 = midtape STape ls cur rs →
566 (∀ls0,c,l1,l2,c1,l3,l4,rs0,n.
567 only_bits_or_nulls l1 → no_marks l1 (* → no_grids l2 *) →
568 bit_or_null c = true → bit_or_null c1 = true →
569 only_bits_or_nulls l3 → S n = |l1| → |l1| = |l3| →
570 table_TM (S n) (l2@〈c1,false〉::l3@〈comma,false〉::l4) →
571 ls = 〈grid,false〉::ls0 → cur = 〈c,true〉 →
572 rs = l1@〈grid,false〉::l2@〈c1,true〉::l3@〈comma,false〉::l4@〈grid,false〉::rs0 →
574 (〈c,false〉::l1 = 〈c1,false〉::l3 ∧
575 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls0) 〈grid,false〉
576 (l2@〈c1,false〉::l3@〈comma,true〉::l4@〈grid,false〉::rs0))
578 (* non facciamo match e marchiamo la prossima tupla *)
579 (〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧
580 ∃c2,l5,l6.l4 = l5@〈bar,false〉::〈c2,false〉::l6 ∧
581 (* condizioni su l5 l6 l7 *)
582 t2 = midtape STape (〈grid,false〉::ls0) 〈c,true〉
583 (l1@〈grid,false〉::l2@〈c1,false〉::l3@〈comma,false〉::
584 l5@〈bar,false〉::〈c2,true〉::l6@〈grid,false〉::rs0))
586 (* non facciamo match e non c'è una prossima tupla:
587 non specifichiamo condizioni sul nastro di output, perché
588 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
589 (〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧ no_bars l4 ∧ current ? t2 = Some ? 〈grid,true〉)).
591 definition R_match_tuple_step_false ≝ λt1,t2.
592 ∀ls,c,rs.t1 = midtape STape ls c rs → is_grid (\fst c) = true ∧ t2 = t1.
594 include alias "basics/logic.ma".
597 lemma eq_f4: ∀A1,A2,A3,A4,B.∀f:A1 → A2 →A3 →A4 →B.
598 ∀x1,x2,x3,x4,y1,y2,y3,y4. x1 = y1 → x2 = y2 →x3=y3 →x4 = y4 →
599 f x1 x2 x3 x4 = f y1 y2 y3 y4.
603 lemma some_option_hd: ∀A.∀l:list A.∀a.∃b.
604 Some ? b = option_hd ? (l@[a]) .
605 #A #l #a cases l normalize /2/
608 axiom tech_split2 : ∀A,l1,l2,l3,l4,x.
609 memb A x l1 = false → memb ? x l3 = false →
610 l1@x::l2 = l3@x::l4 → l1 = l3 ∧ l2 = l4.
612 axiom injective_append : ∀A,l.injective … (λx.append A x l).
614 lemma sem_match_tuple_step:
615 accRealize ? match_tuple_step (inr … (inl … (inr … start_nop)))
616 R_match_tuple_step_true R_match_tuple_step_false.
617 @(acc_sem_if_app … (sem_test_char ? (λc:STape.¬ is_grid (\fst c))) …
618 (sem_seq … sem_compare
619 (sem_if … (sem_test_char ? (λc:STape.is_grid (\fst c)))
621 (sem_seq … sem_mark_next_tuple
622 (sem_if … (sem_test_char ? (λc:STape.is_grid (\fst c)))
623 (sem_mark ?) (sem_seq … (sem_move_l …) (sem_init_current …))))))
625 [(* is_grid: termination case *)
626 2:#t1 #t2 #t3 whd in ⊢ (%→?); #H #H1 whd #ls #c #rs #Ht1
627 cases (H c ?) [2: >Ht1 %] #Hgrid #Heq %
628 [@injective_notb @Hgrid | <Heq @H1]
629 |#tapea #tapeout #tapeb whd in ⊢ (%→?); #Hcur
630 * #tapec * whd in ⊢ (%→?); #Hcompare #Hor
631 #ls #cur #rs #Htapea >Htapea in Hcur; #Hcur cases (Hcur ? (refl ??))
632 -Hcur #Hcur #Htapeb %
633 [ % #Hfalse >Hfalse in Hcur; normalize #Hfalse1 destruct (Hfalse1)]
634 #ls0 #c #l1 #l2 #c1 #l3 #l4 #rs0 #n #Hl1bitnull #Hl1marks #Hc #Hc1 #Hl3 #eqn
635 #eqlen #Htable #Hls #Hcur #Hrs -Htapea >Hls in Htapeb; >Hcur >Hrs #Htapeb
636 cases (Hcompare … Htapeb) -Hcompare -Htapeb * #_ #_ #Hcompare
637 cases (Hcompare c c1 l1 l3 l2 (l4@〈grid,false〉::rs0) eqlen Hl1bitnull Hl3 Hl1marks … (refl …) Hc ?)
639 [* #Htemp destruct (Htemp) #Htapec %1 % % [%]
640 >Htapec in Hor; -Htapec *
641 [2: * #t3 * whd in ⊢ (%→?); #H @False_ind
642 cases (H … (refl …)) whd in ⊢ ((??%?)→?); #H destruct (H)
643 |* #taped * whd in ⊢ (%→?); #Htaped cases (Htaped ? (refl …)) -Htaped *
644 #Htaped whd in ⊢ (%→?); #Htapeout >Htapeout >Htaped
647 |* #la * #c' * #d' * #lb * #lc * * * #H1 #H2 #H3 #Htapec
648 cut (〈c,false〉::l1 ≠ 〈c1,false〉::l3)
650 [@(not_to_not …H1) normalize #H destruct %
651 |#x #tl @not_to_not normalize #H destruct //
654 cut (bit_or_null d' = true)
656 [normalize in ⊢ (%→?); #H destruct //
657 |#x #tl #H @(Hl3 〈d',false〉)
658 normalize in H; destruct @memb_append_l2 @memb_hd
661 >Htapec in Hor; -Htapec *
662 [* #taped * whd in ⊢ (%→?); #H @False_ind
663 cases (H … (refl …)) >(bit_or_null_not_grid ? Hd') #Htemp destruct (Htemp)
664 |* #taped * whd in ⊢ (%→?); #H cases (H … (refl …)) -H #_
665 #Htaped * #tapee * whd in ⊢ (%→?); #Htapee
666 <(associative_append ? lc (〈comma,false〉::l4)) in Htaped; #Htaped
667 cases (Htapee … Htaped ???) -Htaped -Htapee
668 [* #rs3 * * (* we proceed by cases on rs4 *)
669 [(* rs4 is empty : the case is absurd since the tape
670 cannot end with a bar *)
671 * #d * #b * * * #Heq1 @False_ind
672 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut
673 >Hcut in Htable; >H3 >associative_append
674 normalize >Heq1 <associative_append >Hcut
675 <associative_append #Htable @(absurd … Htable)
678 * #d2 #b2 #rs3' * #d * #b * * * #Heq1 #Hnobars
679 cut (memb STape 〈d2,b2〉 (l2@〈c1,false〉::l3@〈comma,false〉::l4) = true)
681 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut
682 >Hcut >H3 >associative_append @memb_append_l2
683 @memb_cons >Heq1 @memb_append_l2 @memb_cons @memb_hd] #d2intable
684 cut (is_grid d2 = false)
685 [@(no_grids_in_table … Htable … 〈d2,b2〉 d2intable)] #Hd2
687 [@(no_marks_in_table … Htable … 〈d2,b2〉 d2intable)] #Hb2
688 >Hb2 in Heq1; #Heq1 -Hb2 -b2
689 whd in ⊢ ((???%)→?); #Htemp destruct (Htemp) #Htapee >Htapee -Htapee *
690 [(* we know current is not grid *)
691 * #tapef * whd in ⊢ (%→?); #Htapef
692 cases (Htapef … (refl …)) >Hd2 #Htemp destruct (Htemp)
693 |* #tapef * whd in ⊢ (%→?); #Htapef
694 cases (Htapef … (refl …)) #_ -Htapef #Htapef
695 * #tapeg >Htapef -Htapef *
698 #H lapply (H … (refl …)) whd in ⊢ (???%→?); -H #Htapeg
701 whd in ⊢ (%→?); #Htapeout
702 cases (some_option_hd ? (reverse ? (reverse ? la)) 〈c',true〉)
705 (Htapeout (reverse ? rs3 @〈d',false〉::reverse ? la@reverse ? l2@(〈grid,false〉::reverse ? lb))
706 c' (reverse ? la) false ls0 bar (〈d2,true〉::rs3'@〈grid,false〉::rs0) c00 b00 ?????) -Htapeout
707 [whd in ⊢ (??(??%??)?); @eq_f3 [2:%|3: %]
709 generalize in match (〈c',true〉::reverse ? la@〈grid,false〉::ls0); #l
710 whd in ⊢ (???(???%)); >associative_append >associative_append %
711 |>reverse_cons @Hoption
713 [normalize in ⊢ (%→?); #Htemp destruct (Htemp)
714 @bit_or_null_not_grid @Hc
715 |#x #tl normalize in ⊢ (%→?); #Htemp destruct (Htemp)
716 @bit_or_null_not_grid @(Hl1bitnull 〈c',false〉) @memb_append_l2 @memb_hd
718 |cut (only_bits_or_nulls (la@(〈c',false〉::lb)))
719 [<H2 whd #c0 #Hmemb cases (orb_true_l … Hmemb)
720 [#eqc0 >(\P eqc0) @Hc |@Hl1bitnull]
721 |#Hl1' #x #Hx @bit_or_null_not_grid @Hl1'
722 @memb_append_l1 @daemon
724 |@daemon] #Htapeout % %2 % //
726 cut (∃rs32.rs3 = lc@〈comma,false〉::rs32)
727 [ (*cases (tech_split STape (λc.c == 〈bar,false〉) l4)
729 | * #l41 * * #cbar #bfalse * #l42 * * #Hbar #Hl4 #Hl41
730 @(ex_intro ?? l41) >Hl4 in Heq1; #Heq1
732 cut (sublist … lc l3)
733 [ #x #Hx cases la in H3;
734 [ normalize #H3 destruct (H3) @Hx
735 | #p #la' normalize #Hla' destruct (Hla')
736 @memb_append_l2 @memb_cons @Hx ] ] #Hsublist*)
740 (〈c1,false〉::l3@〈comma,false〉::l4= la@〈d',false〉::rs3@〈bar,false〉::〈d2,b2〉::rs3')
742 cut (l4=rs32@〈bar,false〉::〈d2,false〉::rs3')
743 [ >Hrs3 in Heq1; @daemon ] #Hl4
744 @(ex_intro … rs32) @(ex_intro … rs3') % [@Hl4]
746 [(* by Hoption, H2 *) @daemon
747 |(*>Hrs3 *)>append_cons
748 > (?:l1@〈grid,false〉::l2@〈c1,false〉::l3@〈comma,false〉::rs32@〈bar,false〉::〈d2,true〉::rs3'@〈grid,false〉::rs
749 = (l1@〈grid,false〉::l2@〈c1,false〉::l3@〈comma,false〉::rs32@[〈bar,false〉])@〈d2,true〉::rs3'@〈grid,false〉::rs)
750 [|>associative_append normalize
751 >associative_append normalize
752 >associative_append normalize
753 >associative_append normalize
755 >reverse_append >reverse_append >reverse_cons
756 >reverse_reverse >reverse_cons >reverse_reverse
757 >reverse_append >reverse_append >reverse_cons
758 >reverse_reverse >reverse_reverse >reverse_reverse
759 >(?:(la@[〈c',false〉])@((((lb@[〈grid,false〉])@l2)@la)@[〈d',false〉])@rs3
760 =((la@〈c',false〉::lb)@([〈grid,false〉]@l2@la@[〈d',false〉]@rs3)))
761 [|>associative_append >associative_append
762 >associative_append >associative_append >associative_append
763 >associative_append % ]
764 <H2 normalize in ⊢ (??%?); >Hrs3
765 >associative_append >associative_append normalize
766 >associative_append >associative_append
768 >(?:la@(〈d',false〉::lc@〈comma,false〉::rs32)@〈bar,false〉::〈d2,true〉::rs3'@〈grid,false〉::rs0 =
769 (la@〈d',false〉::lc)@〈comma,false〉::rs32@〈bar,false〉::〈d2,true〉::rs3'@〈grid,false〉::rs0 )
770 [| >associative_append normalize >associative_append % ]
775 |* #Hnobars #Htapee >Htapee -Htapee *
776 [whd in ⊢ (%→?); * #tapef * whd in ⊢ (%→?); #Htapef
777 cases (Htapef … (refl …)) -Htapef #_ #Htapef >Htapef -Htapef
778 whd in ⊢ (%→?); #Htapeout %2 %
779 [% [//] whd #x #Hx @Hnobars @memb_append_l2 @memb_cons //
780 | >(Htapeout … (refl …)) % ]
781 |whd in ⊢ (%→?); * #tapef * whd in ⊢ (%→?); #Htapef
782 cases (Htapef … (refl …)) -Htapef
783 whd in ⊢ ((??%?)→?); #Htemp destruct (Htemp)
785 |(* no marks in table *)
786 #x #membx @(no_marks_in_table … Htable)
788 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut >Hcut
789 >H3 >associative_append @memb_append_l2 @memb_cons @membx
790 |(* no grids in table *)
791 #x #membx @(no_grids_in_table … Htable)
793 cut (∀A,l1,l2.∀a:A. a::l1@l2=(a::l1)@l2) [//] #Hcut >Hcut
794 >H3 >associative_append @memb_append_l2 @memb_cons @membx
795 |whd in ⊢ (??%?); >(bit_or_null_not_grid … Hd') >(bit_or_null_not_bar … Hd') %
798 |#x #membx @(no_marks_in_table … Htable)
799 @memb_append_l2 @memb_cons @memb_append_l1 @membx
800 |#x #membx @(no_marks_in_table … Htable)
801 @memb_append_l1 @membx
810 scrolls through the tuples in the transition table until one matching the
811 current configuration is found
814 definition match_tuple ≝ whileTM ? match_tuple_step (inr … (inl … (inr … start_nop))).
816 lemma is_grid_true : ∀c.is_grid c = true → c = grid.
817 * normalize [ #b ] #H // destruct (H)
820 (* possible variante ?
821 definition weakR_match_tuple ≝ λt1,t2.
822 (∀ls,cur,rs,b. t1 = midtape STape ls 〈grid,b〉 rs → t2 = t1) ∧
823 (∀c,l1,c1,l2,l3,ls0,rs0,n.
824 t1 = midtape STape (〈grid,false〉::ls0) 〈bit c,true〉 rs
825 (l1@〈grid,false〉::l2@〈bit c1,true〉::l3@〈grid,false〉::rs0) →
826 only_bits_or_nulls l1 → no_marks l1 → S n = |l1| →
827 table_TM (S n) (l2@〈c1,false〉::l3) →
830 〈c1,false〉::l3 = l4@〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l5 ∧
831 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls0) 〈grid,false〉
832 (l2@l4@〈c,false〉::l1@〈comma,true〉::newc@〈comma,false〉::mv::l5@
835 (* non facciamo match su nessuna tupla;
836 non specifichiamo condizioni sul nastro di output, perché
837 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
838 (current ? t2 = Some ? 〈grid,true〉 ∧
840 〈c1,false〉::l3 ≠ l4@〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l5)).
843 definition R_match_tuple0 ≝ λt1,t2.
845 t1 = midtape STape ls cur rs →
846 (is_grid (\fst cur) = true → t2 = t1) ∧
847 (∀c,l1,c1,l2,l3,ls0,rs0,n.
848 ls = 〈grid,false〉::ls0 →
850 rs = l1@〈grid,false〉::l2@〈bar,false〉::〈c1,true〉::l3@〈grid,false〉::rs0 →
851 is_bit c = true → is_bit c1 = true →
852 only_bits_or_nulls l1 → no_marks l1 → S n = |l1| →
853 table_TM (S n) (l2@〈bar,false〉::〈c1,false〉::l3) →
856 〈bar,false〉::〈c1,false〉::l3 = l4@〈bar,false〉::〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l5 ∧
857 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls0) 〈grid,false〉
858 (l2@l4@〈bar,false〉::〈c,false〉::l1@〈comma,true〉::newc@〈comma,false〉::mv::l5@
861 (* non facciamo match su nessuna tupla;
862 non specifichiamo condizioni sul nastro di output, perché
863 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
864 (current ? t2 = Some ? 〈grid,true〉 ∧
866 〈bar,false〉::〈c1,false〉::l3 ≠ l4@〈bar,false〉::〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l5)).
868 axiom table_bit_after_bar :
869 ∀n,l1,c,l2.table_TM n (l1@〈bar,false〉::〈c,false〉::l2) → is_bit c = true.
871 lemma wsem_match_tuple : WRealize ? match_tuple R_match_tuple0.
872 #intape #k #outc #Hloop
873 lapply (sem_while … sem_match_tuple_step intape k outc Hloop) [%] -Hloop
874 * #ta * #Hstar @(star_ind_l ??????? Hstar)
875 [ #tb whd in ⊢ (%→?); #Hleft
876 #ls #cur #rs #Htb cases (Hleft … Htb) #Hgrid #Houtc %
878 | #c #l1 #c1 #l2 #l3 #ls0 #rs0 #n #Hls #Hcur #Hrs
879 >Hcur in Hgrid; #Hgrid >(is_grid_true … Hgrid) normalize in ⊢ (%→?);
882 | (* in the interesting case, we execute a true iteration, then we restart the
883 while cycle, finally we end with a false iteration *)
884 #tb #tc #td whd in ⊢ (%→?); #Htc
885 #Hstar1 #IH whd in ⊢ (%→?); #Hright lapply (IH Hright) -IH whd in ⊢ (%→?); #IH
887 [ (* cur can't be true because we assume at least one iteration *)
888 #Hcur cases (Htc … Htb) * #Hfalse @False_ind @Hfalse @(is_grid_true … Hcur)
889 | (* current and a tuple are marked *)
890 #c #l1 #c1 #l2 #l3 #ls0 #rs0 #n #Hls #Hcur #Hrs #Hc #Hc1 #Hl1bitnull #Hl1marks
891 #Hl1len #Htable cases (Htc … Htb) -Htc -Htb * #_ #Htc
892 (* expose the marked tuple in table *)
893 cut (∃la,lb,mv,lc.l3 = la@〈comma,false〉::lb@〈comma,false〉::mv::lc ∧
894 S n = |la| ∧ only_bits_or_nulls la)
895 [@daemon] * #la * #lb * #mv * #lc * * #Hl3 #Hlalen #Hlabitnull
896 >Hl3 in Htable; >append_cons #Htable
897 >(?: l2@〈bar,false〉::〈c1,true〉::l3@〈grid,false〉::rs0
898 = (l2@[〈bar,false〉])@〈c1,true〉::la@〈comma,false〉::(lb@〈comma,false〉::mv::
899 lc)@〈grid,false〉::rs0) in Hrs;
900 [| >associative_append normalize >Hl3
901 >associative_append normalize % ] #Hrs
902 cases (Htc ????????? Hl1bitnull Hl1marks ?? Hlabitnull Hl1len ? Htable Hls Hcur Hrs)
904 |4: whd in ⊢ (??%?); >Hc1 %
905 |3: whd in ⊢ (??%?); >Hc %
907 [ (* case 1: match successful *)
908 * #Heq #Htc % %{[]} %{lb} %{mv} %{lc} destruct (Heq) %
910 | cases (IH … Htc) -IH #Houtc #_ >(Houtc (refl ??))
911 >Htc @eq_f normalize >associative_append normalize
912 >associative_append normalize %
914 | (* case 2: tuples don't match, we still have other tuples to try *)
915 * #Hdiff * #c2 * #l5 * #l6 * #Heqlblc #Htc
916 cases (IH ??? … Htc) -IH #_ #IH
917 (* by induction hypothesis *)
918 lapply (IH ? l1 c2 (l2@〈bar,false〉::〈c1,false〉::la@〈comma,false〉::l5) l6 ? rs0 n (refl ??) (refl ??) ???????)
919 [ generalize in match Htable;
920 >associative_append normalize
921 >associative_append normalize >Heqlblc
922 >associative_append normalize //
928 | >associative_append normalize
929 >associative_append normalize
930 >associative_append %
932 [ (* the while finally matches a tuple *)
933 * #l7 * #newc * #mv0 * #l8 * #Hl7l8 #Houtc %
934 >Heqlblc @(ex_intro ?? (〈bar,false〉::〈c1,false〉::la@〈comma,false〉::l5@l7))
935 %{newc} %{mv0} %{l8} %
936 [ normalize >Hl7l8 >associative_append normalize
937 >associative_append %
938 | >Houtc @eq_f >associative_append normalize
939 >associative_append normalize >associative_append
940 normalize >associative_append %
942 | (* the while fails finding a tuple: there are no matches in the whole table *)
943 * #Houtc #Hdiff1 %2 %
945 | #l50 #newc #mv0 #l51 >Heqlblc
951 | (* match failed and there is no next tuple: the next while cycle will just exit *)
952 * * #Hdiff #Hnobars generalize in match (refl ? tc);
953 cases tc in ⊢ (???% → %);
954 [ #_ normalize in ⊢ (??%?→?); #Hfalse destruct (Hfalse)
955 |2,3: #x #xs #_ normalize in ⊢ (??%?→?); #Hfalse destruct (Hfalse) ]
956 #ls1 #cur1 #rs1 #Htc normalize in ⊢ (??%?→?); #Hcur1
957 cases (IH … Htc) -IH #IH #_ %2 %
958 [ destruct (Hcur1) >IH [ >Htc % | % ]
960 (* no_bars except the first one, where the tuple does not match ⇒
968 definition R_match_tuple ≝ λt1,t2.
970 is_bit c = true → is_bit c1 = true →
971 only_bits_or_nulls l1 → no_marks l1 → S n = |l1| →
972 table_TM (S n) (〈bar,false〉::〈c1,false〉::l2) →
973 t1 = midtape STape (〈grid,false〉::ls) 〈c,true〉
974 (l1@〈grid,false〉::〈bar,false〉::〈c1,true〉::l2@〈grid,false〉::rs) →
977 〈bar,false〉::〈c1,false〉::l2 = l3@〈bar,false〉::〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l4 ∧
978 t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls) 〈grid,false〉
979 (l3@〈bar,false〉::〈c,false〉::l1@〈comma,true〉::newc@〈comma,false〉::mv::l4@〈grid,false〉::rs))
981 (* non facciamo match su nessuna tupla;
982 non specifichiamo condizioni sul nastro di output, perché
983 non eseguiremo altre operazioni, quindi il suo formato non ci interessa *)
984 (current ? t2 = Some ? 〈grid,true〉 ∧
986 〈bar,false〉::〈c1,false〉::l2 ≠ l3@〈bar,false〉::〈c,false〉::l1@〈comma,false〉::newc@〈comma,false〉::mv::l4).
988 (* we still haven't proved termination *)
989 axiom sem_match_tuple0 : Realize ? match_tuple R_match_tuple0.
991 axiom Realize_to_Realize :
992 ∀alpha,M,R1,R2.(∀t1,t2.R1 t1 t2 → R2 t1 t2) → Realize alpha M R1 → Realize alpha M R2.
994 lemma sem_match_tuple : Realize ? match_tuple R_match_tuple.
995 generalize in match sem_match_tuple0; @Realize_to_Realize
996 #t1 #t2 #HR #ls #c #l1 #c1 #l2 #rs #n #Hc #Hc1 #Hl1bitsnulls #Hl1marks #Hl1len #Htable #Ht1
997 cases (HR … Ht1) -HR #_ #HR
998 @(HR ??? [] … (refl ??) (refl ??) (refl ??) Hc Hc1 Hl1bitsnulls Hl1marks