]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/universal/uni_step.ma
043ee6dd482ee7f7c03a87555b95bd716e3b67b7
[helm.git] / matita / matita / lib / turing / universal / uni_step.ma
1 (*
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.           
5     ||I||                                                            
6     ||T||  
7     ||A||  
8     \   /  This file is distributed under the terms of the       
9      \ /   GNU General Public License Version 2   
10       V_____________________________________________________________*)
11
12
13 (* COMPARE BIT
14
15 *)
16
17 include "turing/universal/copy.ma".
18 include "turing/universal/move_tape.ma".
19 include "turing/universal/match_machines.ma".
20
21 (*
22
23 step :
24
25 if is_true(current) (* current state is final *)
26    then nop
27    else 
28    (* init_match *)
29    mark;
30    adv_to_grid_r;
31    move_r;
32    mark;
33    move_l;
34    adv_to_mark_l
35    (* /init_match *)
36    match_tuple;
37    if is_marked(current) = false (* match ok *)
38       then 
39            (* init_copy *)
40            move_l;
41            init_current;
42            move_r;
43            adv_to_mark_r;
44            adv_mark_r;
45            (* /init_copy *)
46            copy;
47            move_r;
48            (* move_tape *)
49            by cases on current: 
50              case bit false: move_tape_l
51              case bit true: move_tape_r
52              case null: adv_to_grid_l; move_l; adv_to_grid_l;
53            move_r;
54            (* /move_tape *)
55       else sink;
56         
57 *)
58
59 definition init_match ≝ 
60   mark ? · adv_to_mark_r ? (λc:STape.is_grid (\fst c)) · move_r ? · 
61     move_r ? · mark ? · move_l ? · adv_to_mark_l ? (is_marked ?).
62              
63 definition R_init_match ≝ λt1,t2.
64   ∀ls,l,rs,c,d. no_grids (〈c,false〉::l) → no_marks l → 
65   t1 = midtape STape ls 〈c,false〉 (l@〈grid,false〉::〈bar,false〉::〈d,false〉::rs) →
66   t2 = midtape STape ls 〈c,true〉 (l@〈grid,false〉::〈bar,false〉::〈d,true〉::rs).
67   
68 lemma sem_init_match : Realize ? init_match R_init_match.
69 #intape 
70 cases (sem_seq ????? (sem_mark ?)
71        (sem_seq ????? (sem_adv_to_mark_r ? (λc:STape.is_grid (\fst c)))
72         (sem_seq ????? (sem_move_r ?)
73          (sem_seq ????? (sem_move_r ?)
74           (sem_seq ????? (sem_mark ?)
75            (sem_seq ????? (sem_move_l ?)
76             (sem_adv_to_mark_l ? (is_marked ?))))))) intape)
77 #k * #outc * #Hloop #HR 
78 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
79 #ls #l #rs #c #d #Hnogrids #Hnomarks #Hintape
80 cases HR -HR
81 #ta * whd in ⊢ (%→?); * #Hta #_ lapply (Hta … Hintape) -Hta -Hintape #Hta
82 * #tb * whd in ⊢ (%→?); * #_ #Htb cases (Htb … Hta) -Htb -Hta 
83   [* #Hgridc @False_ind @(absurd … Hgridc) @eqnot_to_noteq 
84    @(Hnogrids 〈c,false〉) @memb_hd ]
85 * * #Hgrdic #Htb #_ lapply (Htb l 〈grid,false〉 (〈bar,false〉::〈d,false〉::rs) (refl …) (refl …) ?) 
86   [#x #membl @Hnogrids @memb_cons @membl] -Htb #Htb
87 * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc … Htb) -Htc -Htb #Htc
88 * #td * whd in ⊢ (%→?); * #_ #Htd lapply (Htd … Htc) -Htd -Htc #Htd
89 * #te * whd in ⊢ (%→?); * #Hte #_ lapply (Hte … Htd) -Hte -Htd #Hte
90 * #tf * whd in ⊢ (%→?); * #_ #Htf lapply (Htf … Hte) -Htf -Hte #Htf
91 whd in ⊢ (%→?); * #_ #Htg cases (Htg … Htf) -Htg -Htf
92 #_ #Htg cases (Htg (refl …)) -Htg #Htg #_
93 lapply (Htg (〈grid,false〉::reverse ? l) 〈c,true〉 ls (refl …) (refl …) ?) 
94   [#x #membl @Hnomarks @daemon] -Htg #Htg >Htg >reverse_cons >reverse_reverse
95    >associative_append %
96 qed.
97
98 (* init_copy 
99
100            init_current_on_match; (* no marks in current *)
101            move_r;
102            adv_to_mark_r;
103            adv_mark_r;
104
105 *)
106
107 definition init_copy ≝ 
108   init_current_on_match · move_r ? · 
109     adv_to_mark_r ? (is_marked ?) · adv_mark_r ?.
110
111 definition R_init_copy ≝ λt1,t2.
112   ∀l1,l2,c,ls,d,rs. 
113   no_marks l1 → no_grids l1 → 
114   no_marks l2 → is_grid c = false → 
115   t1 = midtape STape (l1@〈c,false〉::〈grid,false〉::ls) 〈grid,false〉 (l2@〈comma,true〉::〈d,false〉::rs) → 
116   t2 = midtape STape (〈comma,false〉::(reverse ? l2)@〈grid,false〉::l1@〈c,true〉::〈grid,false〉::ls) 〈d,true〉 rs.
117
118 lemma list_last: ∀A.∀l:list A.
119   l = [ ] ∨ ∃a,l1. l = l1@[a].
120 #A #l <(reverse_reverse ? l) cases (reverse A l)
121   [%1 //
122   |#a #l1 %2 @(ex_intro ?? a) @(ex_intro ?? (reverse ? l1)) //
123   ]
124 qed.
125    
126 lemma sem_init_copy : Realize ? init_copy R_init_copy.
127 #intape 
128 cases (sem_seq ????? sem_init_current_on_match
129         (sem_seq ????? (sem_move_r ?)
130           (sem_seq ????? (sem_adv_to_mark_r ? (is_marked ?))
131             (sem_adv_mark_r ?))) intape)
132 #k * #outc * #Hloop #HR 
133 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
134 #l1 #l2 #c #ls #d #rs #Hl1marks #Hl1grids #Hl2marks #Hc #Hintape
135 cases HR -HR
136 #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hl1grids Hc Hintape) -Hta -Hintape #Hta
137 * #tb * whd in ⊢ (%→?); * #_ #Htb lapply (Htb  … Hta) -Htb -Hta
138 generalize in match Hl1marks; -Hl1marks cases (list_last ? l1) 
139   [#eql1 >eql1 #Hl1marks whd in ⊢ ((???%)→?); whd in ⊢ ((???(????%))→?); #Htb
140    * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc  … Htb) -Htc -Htb *
141     [* whd in ⊢ ((??%?)→?); #Htemp destruct (Htemp)]
142    * * #_ #Htc #_ lapply (Htc … (refl …) (refl …) ?)
143     [#x #membx @Hl2marks @membx]
144    #Htc whd in ⊢ (%→?); * #Houtc #_ cases (Houtc (reverse ? l2@〈grid,false〉::〈c,true〉::〈grid,false〉::ls) comma)
145    -Houtc #Houtc lapply (Houtc … Htc) -Houtc -Htc #Houtc #_
146    >Houtc %
147   |* #c1 * #tl #eql1 >eql1 #Hl1marks >reverse_append >reverse_single 
148    whd in ⊢ ((???%)→?); whd in ⊢ ((???(????%))→?);
149    >associative_append whd in ⊢ ((???(????%))→?); #Htb
150    * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc  … Htb) -Htc -Htb *
151     [* >Hl1marks [#Htemp destruct (Htemp)] @memb_append_l2 @memb_hd]
152    * * #_ >append_cons <associative_append #Htc lapply (Htc … (refl …) (refl …) ?)
153     [#x #membx cases (memb_append … membx) -membx #membx
154       [cases (memb_append … membx) -membx #membx
155         [@Hl1marks @memb_append_l1 @daemon
156         |>(memb_single … membx) %
157         ]
158       |@Hl2marks @membx
159       ]]
160   -Htc #Htc #_ whd in ⊢ (%→?); * #Houtc #_ cases (Houtc (reverse (FinProd FSUnialpha FinBool) ((reverse STape tl@[〈grid,false〉])@l2)
161      @c1::〈c,true〉::〈grid,false〉::ls) comma)
162   -Houtc #Houtc lapply (Houtc … Htc) -Houtc -Htc #Houtc #_
163   >Houtc >reverse_append >reverse_append >reverse_single 
164   >reverse_reverse >associative_append >associative_append 
165   >associative_append %
166 qed.
167   
168 (* OLD 
169 definition init_copy ≝ 
170   seq ? (adv_mark_r ?) 
171     (seq ? init_current_on_match
172       (seq ? (move_r ?) 
173         (adv_to_mark_r ? (is_marked ?)))).
174
175 definition R_init_copy ≝ λt1,t2.
176   ∀l1,l2,c,l3,d,rs. 
177   no_marks l1 → no_grids l1 → 
178   no_marks l2 → no_grids l2 → is_grid c = false → is_grid d =false →
179   t1 = midtape STape (l1@〈grid,false〉::l2@〈c,false〉::〈grid,false〉::l3) 〈comma,true〉 (〈d,false〉::rs) → 
180   t2 = midtape STape (〈comma,false〉::l1@〈grid,false〉::l2@〈c,true〉::〈grid,false〉::l3) 〈d,true〉 rs.
181
182 lemma list_last: ∀A.∀l:list A.
183   l = [ ] ∨ ∃a,l1. l = l1@[a].
184 #A #l <(reverse_reverse ? l) cases (reverse A l)
185   [%1 //
186   |#a #l1 %2 @(ex_intro ?? a) @(ex_intro ?? (reverse ? l1)) //
187   ]
188 qed.
189    
190 lemma sem_init_copy : Realize ? init_copy R_init_copy.
191 #intape 
192 cases (sem_seq ????? (sem_adv_mark_r ?)
193        (sem_seq ????? sem_init_current_on_match
194         (sem_seq ????? (sem_move_r ?)
195          (sem_adv_to_mark_r ? (is_marked ?)))) intape)
196 #k * #outc * #Hloop #HR 
197 @(ex_intro ?? k) @(ex_intro ?? outc) % [@Hloop] -Hloop
198 #l1 #l2 #c #l3 #d #rs #Hl1marks #Hl1grids #Hl2marks #Hl2grids #Hc #Hd #Hintape
199 cases HR -HR
200 #ta * whd in ⊢ (%→?); #Hta lapply (Hta … Hintape) -Hta -Hintape #Hta
201 * #tb * whd in ⊢ (%→?); 
202 >append_cons #Htb lapply (Htb (〈comma,false〉::l1) l2 c … Hta) 
203   [@Hd |@Hc |@Hl2grids 
204    |#x #membx cases (orb_true_l … membx) -membx #membx 
205      [>(\P membx) // | @Hl1grids @membx]
206   ] -Htb #Htb
207 * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc -Htb
208 >reverse_append >reverse_cons cases (list_last ? l2)
209   [#Hl2 >Hl2 >associative_append whd in ⊢ ((???(??%%%))→?); #Htc
210    whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd -Htc
211     [* whd in ⊢ ((??%?)→?); #Habs destruct (Habs)]
212    * #_ #Htf lapply (Htf … (refl …) (refl …) ?) 
213     [#x >reverse_cons #membx cases (memb_append … membx) -membx #membx
214       [@Hl1marks @daemon |>(memb_single … membx) //] 
215     -Htf
216     |#Htf >Htf >reverse_reverse >associative_append %
217     ]
218   |* #a * #l21 #Heq >Heq >reverse_append >reverse_single 
219    >associative_append >associative_append >associative_append whd in ⊢ ((???(??%%%))→?); #Htc
220    whd in ⊢ (%→?); #Htd cases (Htd … Htc) -Htd -Htc
221     [* >Hl2marks [#Habs destruct (Habs) |>Heq @memb_append_l2 @memb_hd]]
222    * #_ <associative_append <associative_append #Htf lapply (Htf … (refl …) (refl …) ?) 
223     [#x >reverse_cons #membx cases (memb_append … membx) -membx #membx
224       [cases (memb_append … membx) -membx #membx
225         [@Hl2marks >Heq @memb_append_l1 @daemon
226         |>(memb_single … membx) //]
227       |cases (memb_append … membx) -membx #membx
228         [@Hl1marks @daemon |>(memb_single … membx) //]
229       ]
230     | #Htf >Htf >reverse_append >reverse_reverse
231       >reverse_append >reverse_reverse >associative_append 
232       >reverse_single >associative_append >associative_append 
233       >associative_append % 
234     ]
235   ]
236 qed. *)
237
238 definition exec_action ≝ 
239   init_copy · copy · move_r … · move_tape.
240
241 definition map_move ≝ 
242   λc,mv.match c with [ null ⇒ None ? | _ ⇒ Some ? 〈c,false,move_of_unialpha mv〉 ].
243
244 (* - aggiungere a legal_tape le condizioni
245        only_bits ls, rs; bit_or_null c
246    - ci vuole un lemma che dimostri 
247        bit_or_null c1 = true    bit_or_null mv = true
248        mv ≠ null → c1 ≠ null
249      dal fatto che c1 e mv sono contenuti nella table
250  *)
251
252 definition Pre_exec_action ≝ λt1.
253   ∃n,curconfig,ls,rs,c0,c1,s0,s1,table1,newconfig,mv,table2.
254   table_TM n (table1@〈comma,false〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2) ∧
255   no_marks curconfig ∧ only_bits (curconfig@[〈s0,false〉]) ∧
256   only_bits (〈s1,false〉::newconfig) ∧ bit_or_null c1 = true ∧
257   |curconfig| = |newconfig| ∧
258   legal_tape ls 〈c0,false〉 rs ∧
259   t1 = midtape STape (〈c0,false〉::curconfig@〈s0,false〉::〈grid,false〉::ls) 〈grid,false〉 
260     (table1@〈comma,true〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs).
261
262 definition R_exec_action ≝ λt1,t2.
263   ∀n,curconfig,ls,rs,c0,c1,s0,s1,table1,newconfig,mv,table2.
264   table_TM n (table1@〈comma,false〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2) → 
265   no_marks curconfig → only_bits (curconfig@[〈s0,false〉]) → 
266   only_bits (〈s1,false〉::newconfig) → bit_or_null c1 = true → 
267   |curconfig| = |newconfig| → 
268   legal_tape ls 〈c0,false〉 rs →
269   t1 = midtape STape (〈c0,false〉::curconfig@〈s0,false〉::〈grid,false〉::ls) 〈grid,false〉 
270     (table1@〈comma,true〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs) → 
271   ∀t1'.t1' = lift_tape ls 〈c0,false〉 rs → 
272   ∃ls1,rs1,c2.
273   t2 = midtape STape ls1 〈grid,false〉 
274     (〈s1,false〉::newconfig@〈c2,false〉::〈grid,false〉::
275      table1@〈comma,false〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs1) ∧   
276   lift_tape ls1 〈c2,false〉 rs1 = 
277   tape_move STape t1' (map_move c1 mv) ∧ legal_tape ls1 〈c2,false〉 rs1.
278   
279 (* move the following 2 lemmata to mono.ma *)
280 lemma tape_move_left_eq :
281   ∀A.∀t:tape A.∀c.
282   tape_move ? t (Some ? 〈c,L〉) = 
283   tape_move_left ? (left ? t) c (right ? t).
284 //
285 qed.
286
287 lemma tape_move_right_eq :
288   ∀A.∀t:tape A.∀c.
289   tape_move ? t (Some ? 〈c,R〉) = 
290   tape_move_right ? (left ? t) c (right ? t).
291 //
292 qed.
293
294 lemma lift_tape_not_null : 
295  ∀ls,c,bc,rs.c ≠ null → lift_tape ls 〈c,bc〉 rs = midtape ? ls 〈c,bc〉 rs.
296 #ls #c #bc #rs cases c //
297 #Hfalse @False_ind /2/
298 qed.
299
300 lemma merge_char_not_null :
301   ∀c1,c2.c1 ≠ null → merge_char c1 c2 ≠ null.
302 #c1 #c2 @not_to_not cases c2
303 [ #c1' normalize #Hfalse destruct (Hfalse)
304 | normalize //
305 | *: normalize #Hfalse destruct (Hfalse)
306 ]
307 qed.
308
309 lemma merge_char_null : ∀c.merge_char null c = c.
310 * //
311 qed.
312
313 lemma merge_char_cases : ∀c1,c2.merge_char c1 c2 = c1 ∨ merge_char c1 c2 = c2.
314 #c1 *
315 [ #c1' %2 %
316 | % %
317 | *: %2 % ]
318 qed.
319
320 (* lemma merge_char_c_bit :
321   ∀c1,c2.is_bit c2 = true → merge_char c1 c2 = c2.
322 #c1 *
323 [ #c2' #_ %
324 |*: normalize #Hfalse destruct (Hfalse) ]
325 qed.
326
327 lemma merge_char_c_bit :
328   ∀c1,c2.is_null c2 = true → merge_char c1 c2 = c1.
329 #c1 *
330 [ #c2' #_ %
331 |*: normalize #Hfalse destruct (Hfalse) ]
332 qed.
333
334 *)
335
336 (*lemma GRealize_to_Realize : 
337   ∀sig,M,R.GRealize sig M (λx.True) R → Realize sig M R.
338 #sig #M #R #HR #t @HR //
339 qed.*)
340
341 lemma sem_exec_action : GRealize ? exec_action Pre_exec_action R_exec_action.
342 @(sem_seq_app_guarded … (Realize_to_GRealize … sem_init_copy) ???)
343 [3:@(sem_seq_app_guarded … sem_copy)
344  [3:@(sem_seq_app_guarded … (Realize_to_GRealize … (sem_move_r STape)))
345   [3:@(Realize_to_GRealize … (sem_move_tape …))
346   |@(λt.True)
347   |4://
348   |5:@sub_reflexive]
349  |@(λt.True)
350  |4://
351  |5:@sub_reflexive]
352 |4:#t1 #t2 
353    * #n * #curconfig * #ls * #rs * #c0 * #c1 * #s0 * #s1 * #table1 * #newconfig 
354    * #mv * #table2 * * * * * * *
355    #Htable #Hcurconfig1 #Hcurconfig2 #Hnewconfig #Hc1 #Hlen #Htape #Ht1
356    whd in ⊢ (%→?); >Ht1 #HR
357    lapply (HR (〈c0,false〉::curconfig) table1 s0 ls s1 
358               (newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs) ???? (refl ??))
359    [(*Hcurconfig2*) @daemon
360    |(*by Htable *) @daemon
361    |(*Hcurconfig2*) @daemon
362    |(*Hcurconfig1*) @daemon ]
363    -HR #Ht2 whd
364    %{(〈grid,false〉::ls)} %{s0} %{s1} %{c0} %{c1} %{(〈mv,false〉::table2@〈grid,false〉::rs)}
365    %{newconfig} %{(〈comma,false〉::reverse ? table1)} %{curconfig} >Ht2
366    % [ % [ % [ % [ % [ % [ % [ % 
367    [ %
368    |(*by Htabel*) @daemon ]
369    |(*by Htable*) @daemon ]
370    |// ]
371    |>Hlen % ]
372    |@Hcurconfig2 ]
373    |@Hnewconfig ]
374    |cases Htape * * // ]
375    | // ] 
376    |1,2:skip]
377 #ta #outtape #HR #n #curconfig #ls #rs #c0 #c1 #s0 #s1 #table1 #newconfig #mv
378 #table2 #Htable #Hcurconfig1 #Hcurconfig2 #Hnewconfig #Hbitnullc1 #Hlen #Htape
379 #Hta #ta' #Hta'
380 cases HR -HR #tb * whd in ⊢ (%→?); #Htb 
381 lapply (Htb (〈c0,false〉::curconfig) table1 s0 ls s1 
382             (newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs)
383             ???? Hta) -Htb
384 [ (*Hcurconfig2*) @daemon
385 | (*Htable*) @daemon
386 | (* by Htape bit_or_null c0 = true, moreover Hcurconfig2 *) @daemon
387 | (*Hcurconfig1*) @daemon ]
388 #Htb * #tc * whd in ⊢ (%→?); #Htc
389 lapply (Htc (〈grid,false〉::ls) s0 s1 c0 c1 (〈mv,false〉::table2@〈grid,false〉::rs) newconfig (〈comma,false〉::reverse ? table1) curconfig Htb ????????) -Htc
390 [9:|*:(* bit_or_null c0,c1; |curconfig| = |newconfig|*) @daemon ]
391 #Htc * #td * whd in ⊢ (%→?); * #_ #Htd lapply (Htd … Htc) -Htd whd in ⊢(???(??%%%)→?);#Htd
392 whd in ⊢ (%→?); #Houtc whd in Htd:(???%); whd in Htd:(???(??%%%));
393 lapply (Houtc rs n 
394   (〈comma,false〉::〈c1,false〉::reverse ? newconfig@〈s1,false〉::〈comma,false〉::reverse ? table1)
395   mv table2 (merge_char c0 c1) (reverse ? newconfig@[〈s1,false〉]) ls ????????)
396 [3: cases Htape -Htape * * #Hnomarks #Hbits #Hc0 #Hlsrs % [ % [ %
397   [ #x #Hx cases (orb_true_l … Hx) #Hx'
398     [ >(\P Hx') %
399     | @Hnomarks @memb_cons // ]
400   | @Hbits ]
401   | cases (merge_char_cases c0 c1) #Hmerge >Hmerge // ]
402   | cases (true_or_false (c0 == null)) #Hc0'
403     [ cases Hlsrs -Hlsrs 
404       [ *
405         [ >(\P Hc0') * #Hfalse @False_ind /2/
406         | #Hlsnil % %2 // ]
407       | #Hrsnil %2 // ] 
408     | % % @merge_char_not_null @(\Pf Hc0') ] ]
409 |4:>Htd @(eq_f3 … (midtape ?))
410   [ @eq_f @eq_f >associative_append >associative_append %
411   | %
412   | % ]
413 | %
414 || >reverse_cons >reverse_cons >reverse_append >reverse_reverse 
415    >reverse_cons >reverse_cons >reverse_reverse
416    >associative_append >associative_append >associative_append
417    >associative_append >associative_append
418    @Htable
419 | (* well formedness of table *) @daemon
420 | (* Hnewconfig *) @daemon
421 | (* bit_or_null mv = true (well formedness of table) *) @daemon
422 | -Houtc * #ls1 * #rs1 * #newc * #Hnewtapelegal * #Houtc *
423   [ *
424     [ * #Hmv #Htapemove
425       @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc)
426       %
427       [ %
428         [ >Houtc -Houtc >reverse_append
429           >reverse_reverse >reverse_single @eq_f
430           >reverse_cons >reverse_cons >reverse_append >reverse_cons
431           >reverse_cons >reverse_reverse >reverse_reverse
432           >associative_append >associative_append
433           >associative_append >associative_append
434           >associative_append >associative_append %
435         | >Hmv >Hta' >Htapemove 
436           (* mv = bit false -→ c1 = bit ? *)
437           cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
438           >Hc1 >tape_move_left_eq >(legal_tape_left … Htape) 
439           >(legal_tape_right … Htape) %
440         ]
441       | //
442       ]
443     | * #Hmv #Htapemove 
444       @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
445       [ %
446         [ >Houtc -Houtc >reverse_append
447           >reverse_reverse >reverse_single @eq_f
448           >reverse_cons >reverse_cons >reverse_append >reverse_cons
449           >reverse_cons >reverse_reverse >reverse_reverse
450           >associative_append >associative_append
451           >associative_append >associative_append
452           >associative_append >associative_append %
453         |>Hmv >Hta' >Htapemove 
454           cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
455           >Hc1 >tape_move_right_eq >(legal_tape_left … Htape) 
456           >(legal_tape_right … Htape) %
457         ]
458       | //
459       ]
460     ]
461   | * * * #Hmv #Hlseq #Hrseq #Hnewc 
462     @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
463     [ %
464       [ >Houtc -Houtc >reverse_append
465         >reverse_reverse >reverse_single @eq_f
466         >reverse_cons >reverse_cons >reverse_append >reverse_cons
467         >reverse_cons >reverse_reverse >reverse_reverse
468         >associative_append >associative_append
469         >associative_append >associative_append
470         >associative_append >associative_append %
471       |>Hmv >Hta' cases c1 in Hnewc;
472         [ #c1' whd in ⊢ (??%?→?);#Hnewc <Hnewc
473           >Hlseq >Hrseq whd in ⊢ (??%%);
474           >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
475         | whd in ⊢ (??%?→?); #Hnewc >Hnewc >Hlseq >Hrseq %
476         |*: whd in ⊢ (??%?→?);#Hnewc <Hnewc
477           >Hlseq >Hrseq whd in ⊢ (??%%);
478           >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
479         ]
480       ]
481     | //
482     ]
483   ]
484 ]
485 qed.
486
487 (*
488 if is_false(current) (* current state is not final *)
489    then init_match;
490     match_tuple;
491     if is_marked(current) = false (* match ok *)
492       then 
493            exec_action
494            move_r;
495       else sink;
496    else nop;
497 *)
498
499 definition uni_step ≝ 
500   ifTM ? (test_char STape (λc.\fst c == bit false))
501     (single_finalTM ? 
502       (init_match · match_tuple ·
503         (ifTM ? (test_char ? (λc.¬is_marked ? c))
504           (exec_action · move_r …)
505           (nop ?) tc_true)))
506     (nop ?) tc_true.
507
508 definition R_uni_step_true ≝ λt1,t2.
509   ∀n,table,s0,s1,c0,c1,ls,rs,curconfig,newconfig,mv.
510   0 < |table| → table_TM (S n) table → 
511   match_in_table (S n) (〈s0,false〉::curconfig) 〈c0,false〉
512     (〈s1,false〉::newconfig) 〈c1,false〉 〈mv,false〉 table → 
513   legal_tape ls 〈c0,false〉 rs → 
514   t1 = midtape STape (〈grid,false〉::ls) 〈s0,false〉 
515     (curconfig@〈c0,false〉::〈grid,false〉::table@〈grid,false〉::rs) → 
516   ∀t1'.t1' = lift_tape ls 〈c0,false〉 rs → 
517   s0 = bit false ∧
518   ∃ls1,rs1,c2.
519   (t2 = midtape STape (〈grid,false〉::ls1) 〈s1,false〉 
520     (newconfig@〈c2,false〉::〈grid,false〉::table@〈grid,false〉::rs1) ∧
521    lift_tape ls1 〈c2,false〉 rs1 = 
522    tape_move STape t1' (map_move c1 mv) ∧ legal_tape ls1 〈c2,false〉 rs1).
523    
524 definition R_uni_step_false ≝ λt1,t2.
525   ∀b. current STape t1 = Some ? 〈bit b,false〉 → b = true ∧ t2 = t1.
526   
527 (*axiom sem_match_tuple : Realize ? match_tuple R_match_tuple.*)
528
529 definition us_acc : states ? uni_step ≝ (inr … (inl … (inr … start_nop))).
530
531 definition Pre_uni_step ≝ λt1.
532   ∃n,table,s0,s1,c0,c1,ls,rs,curconfig,newconfig,mv.
533   0 < |table| ∧ table_TM (S n) table ∧
534   match_in_table (S n) (〈s0,false〉::curconfig) 〈c0,false〉
535     (〈s1,false〉::newconfig) 〈c1,false〉 〈mv,false〉 table ∧
536   legal_tape ls 〈c0,false〉 rs ∧
537   t1 = midtape STape (〈grid,false〉::ls) 〈s0,false〉 
538     (curconfig@〈c0,false〉::〈grid,false〉::table@〈grid,false〉::rs).
539     
540 lemma sem_uni_step :
541   accGRealize ? uni_step us_acc Pre_uni_step
542      R_uni_step_true R_uni_step_false. 
543 @(acc_sem_if_app_guarded STape … (sem_test_char ? (λc:STape.\fst c == bit false)) 
544   ? (test_char_inv …) (sem_nop …) …)
545 [| @(sem_seq_app_guarded … (Realize_to_GRealize … sem_init_match) ???)
546   [ 5: @sub_reflexive
547   | 3: @(sem_seq_app_guarded … sem_match_tuple 
548          (Realize_to_GRealize … (sem_if ????????? (sem_test_char …  (λc.¬is_marked FSUnialpha c))
549           (sem_seq … sem_exec_action (sem_move_r …))
550           (sem_nop …))))
551      [@(λx.True)
552      |//
553      |@sub_reflexive]
554   ||| #t1 #t2 * #n * #table * #s0 * #s1 * #c0 * #c1 * #ls * #rs * #curconfig 
555       * #newconfig * #mv * * * *
556       #Hlen1 #Htable #Hmatch #Hlegal #Ht1
557       whd in ⊢ (%→?);
558       cut (∃tup,table0.table = tup@table0 ∧ tuple_TM (S n) tup)
559       [@daemon]
560       * #tup * #table0 * #Htableeq * #qin * #cin * #qout * #cout * #mv0
561       * * * * * * * * * *
562       #Hqinnomarks #_ #Hqinbits #_ #_ #_ #_ #_ #Hqinlen #_ #Htupeq
563       cut (∃d,qin0.qin = 〈d,false〉::qin0)
564       [ lapply Hqinlen lapply Hqinnomarks -Hqinlen -Hqinnomarks cases qin
565         [ #_ normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) 
566         | * #d #bd #qin0 #Hqinnomarks #_ %{d} %{qin0}
567           >(?:bd=false) [%]
568           @(Hqinnomarks 〈d,bd〉) @memb_hd ] ]
569       * #d * #qin0 #Hqineq
570       #Ht2 
571       lapply (Ht2 (〈grid,false〉::ls) (curconfig@[〈c0,false〉])
572                (qin0@〈cin,false〉::〈comma,false〉::qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0@〈grid,false〉::rs) s0 d ???)
573       [ >Ht1 @eq_f >associative_append @eq_f @eq_f @eq_f
574         >Htableeq >Htupeq >associative_append whd in ⊢ (??%?);
575         @eq_f >Hqineq >associative_append @eq_f whd in ⊢ (??%?);
576         @eq_f whd in ⊢ (??%?); @eq_f
577         >associative_append %
578       | @daemon
579       | @daemon
580       ]
581       #Ht2 % [| % [| % [| % [ @Ht2 ]
582         %2
583         (* ls0 = ls
584            c = s0
585            l1 = curconfig@[〈c0,false〉]
586            l2 = [〈bar,false〉]
587            c10 = d
588            l3 = qin0@[〈cin,false〉]
589            l4 = qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0
590            rs00 = rs
591            n0 = S n ?
592          *)
593         %{ls} %{s0} %{(curconfig@[〈c0,false〉])}
594         %{([〈bar,false〉])} %{d} %{(qin0@[〈cin,false〉])}
595         %{(qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0)}
596         %{rs} %{n} @daemon (* TODO *)
597       ]
598      ]
599     ]
600    ]
601  | #intape #outtape 
602   #ta whd in ⊢ (%→?); #Hta #HR
603   #n #fulltable #s0 #s1 #c0 #c1 #ls #rs #curconfig #newconfig #mv
604   #Htable_len cut (∃t0,table. fulltable =〈bar,false〉::〈t0,false〉::table) [(* 0 < |table| *) @daemon]
605   * #t0 * #table #Hfulltable >Hfulltable -fulltable 
606   #Htable #Hmatch #Htape #Hintape #t1' #Ht1'
607   >Hintape in Hta; * * * #c #bc *
608   whd in ⊢ (??%?→?); #HSome destruct (HSome) #Hc #Hta % [@(\P Hc)]
609   cases HR -HR 
610   #tb * whd in ⊢ (%→?); #Htb
611   lapply (Htb (〈grid,false〉::ls) (curconfig@[〈c0,false〉]) (table@〈grid,false〉::rs) c t0 ???)
612   [ >Hta >associative_append %
613   | @daemon
614   | @daemon
615   | -Hta -Htb #Htb * 
616     #tc * whd in ⊢ (%→?); #Htc cases (Htc … Htable … Htb) -Htb -Htc
617     [| * #Hcurrent #Hfalse @False_ind
618       (* absurd by Hmatch *) @daemon
619     | >(\P Hc) %
620     | (* Htable (con lemma) *) @daemon
621     | (* Hmatch *) @daemon
622     | (* Htable *) @daemon
623     | (* Htable, Hmatch → |config| = n 
624        necessaria modifica in R_match_tuple, le dimensioni non corrispondono
625       *) @daemon
626     ]
627     * #table1 * #newc * #mv1 * #table2 * #Htableeq #Htc *
628     [ * #td * whd in ⊢ (%→?); >Htc -Htc * * #c2 * whd in ⊢ (??%?→?); #Hc2 destruct (Hc2) 
629       #_ #Htd
630       cut (newc = 〈s1,false〉::newconfig@[〈c1,false〉]) [@daemon] #Hnewc
631       >Hnewc cut (mv1 = 〈mv,false〉)
632       [@daemon] #Hmv1
633       * #te * whd in ⊢ (%→?); #Hte
634       cut (td = midtape STape (〈c0,false〉::reverse STape curconfig@〈c,false〉::〈grid,false〉::ls) 
635               〈grid,false〉
636               ((table1@〈bar,false〉::〈c,false〉::curconfig@[〈c0,false〉])@〈comma,true〉::〈s1,false〉::
637                newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs))
638       [ >Htd @eq_f3 //
639         [ >reverse_append >reverse_single %
640         | >associative_append >associative_append normalize
641           >associative_append >Hmv1 >Hnewc @eq_f @eq_f @eq_f @eq_f @eq_f @eq_f
642           whd in ⊢ (??%?); >associative_append % 
643         ]
644       ]
645       -Htd #Htd lapply (Hte … (S n) … Htd … Ht1') -Htd -Hte
646       [ //
647       | (*|curconfig| = |newconfig|*) @daemon
648       | (* Htable → bit_or_null c1 = true *) @daemon
649       | (* only_bits (〈s1,false〉::newconfig) *) @daemon
650       | (* only_bits (curconfig@[〈s0,false〉]) *) @daemon
651       | (* no_marks (reverse ? curconfig) *) @daemon
652       | >Hmv1 in Htableeq; >Hnewc 
653         >associative_append >associative_append normalize
654         >associative_append >associative_append
655         #Htableeq <Htableeq // ]
656       * #ls1 * #rs1 * #c2 * * #Hte #Hliftte #Hlegalte
657       whd in ⊢ (%→?); * #_ #Houttape lapply (Houttape … Hte) -Houttape #Houttape
658       whd in Houttape:(???%); whd in Houttape:(???(??%%%));
659       @ex_intro [| @(ex_intro ?? rs1) @ex_intro [| % [ % 
660       [ >Houttape @eq_f @eq_f @eq_f @eq_f
661         change with ((〈bar,false〉::〈t0,false〉::table)@?) in ⊢ (???%);
662         >Htableeq >associative_append >associative_append 
663         >associative_append normalize >associative_append
664         >associative_append normalize >Hnewc <Hmv1
665         >associative_append normalize >associative_append
666         >Hmv1 % 
667       | @Hliftte
668       ]
669      | //
670      ]
671     ]
672    ] 
673   | * #td * whd in ⊢ (%→%→?); >Htc * #Htd
674     lapply (Htd ? (refl ??)) normalize in ⊢ (%→?);
675     #Hfalse destruct (Hfalse)
676   ]
677  ]
678 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #Ht1 #Ht2
679   #b #Hb >Hb in Ht1; * #Hc #Ht1 lapply (Hc ? (refl ??)) -Hc #Hb' %
680   // cases b in Hb'; normalize #H1 //
681 ]
682 qed.
683
684 (*
685 @(acc_sem_if_app STape … (sem_test_char ? (λc:STape.\fst c == bit false))
686    (sem_seq … sem_init_match      
687      (sem_seq … sem_match_tuple        
688        (sem_if … (* ????????? (sem_test_char …  (λc.¬is_marked FSUnialpha c)) *)
689           (sem_seq … sem_exec_action (sem_move_r …))
690           (sem_nop …))))
691    (sem_nop …)
692    …)
693 [@sem_test_char||]
694 [ #intape #outtape 
695   #ta whd in ⊢ (%→?); #Hta #HR
696   #n #fulltable #s0 #s1 #c0 #c1 #ls #rs #curconfig #newconfig #mv
697   #Htable_len cut (∃t0,table. fulltable =〈bar,false〉::〈t0,false〉::table) [(* 0 < |table| *) @daemon]
698   * #t0 * #table #Hfulltable >Hfulltable -fulltable 
699   #Htable #Hmatch #Htape #Hintape #t1' #Ht1'
700   >Hintape in Hta; * * * #c #bc *
701   whd in ⊢ (??%?→?); #HSome destruct (HSome) #Hc #Hta % [@(\P Hc)]
702   cases HR -HR 
703   #tb * whd in ⊢ (%→?); #Htb
704   lapply (Htb (〈grid,false〉::ls) (curconfig@[〈c0,false〉]) (table@〈grid,false〉::rs) c t0 ???)
705   [ >Hta >associative_append %
706   | @daemon
707   | @daemon
708   | -Hta -Htb #Htb * 
709     #tc * whd in ⊢ (%→?); #Htc cases (Htc … Htable … Htb) -Htb -Htc
710     [| * #Hcurrent #Hfalse @False_ind
711       (* absurd by Hmatch *) @daemon
712     | >(\P Hc) %
713     | (* Htable (con lemma) *) @daemon
714     | (* Hmatch *) @daemon
715     | (* Htable *) @daemon
716     | (* Htable, Hmatch → |config| = n 
717        necessaria modifica in R_match_tuple, le dimensioni non corrispondono
718       *) @daemon
719     ]
720     * #table1 * #newc * #mv1 * #table2 * #Htableeq #Htc *
721     [ * #td * whd in ⊢ (%→?); >Htc -Htc * * #c2 * whd in ⊢ (??%?→?); #Hc2 destruct (Hc2) 
722       #_ #Htd
723       cut (newc = 〈s1,false〉::newconfig@[〈c1,false〉]) [@daemon] #Hnewc
724       >Hnewc cut (mv1 = 〈mv,false〉)
725       [@daemon] #Hmv1
726       * #te * whd in ⊢ (%→?); #Hte
727       cut (td = midtape STape (〈c0,false〉::reverse STape curconfig@〈c,false〉::〈grid,false〉::ls) 
728               〈grid,false〉
729               ((table1@〈bar,false〉::〈c,false〉::curconfig@[〈c0,false〉])@〈comma,true〉::〈s1,false〉::
730                newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs))
731       [ >Htd @eq_f3 //
732         [ >reverse_append >reverse_single %
733         | >associative_append >associative_append normalize
734           >associative_append >Hmv1 >Hnewc @eq_f @eq_f @eq_f @eq_f @eq_f @eq_f
735           whd in ⊢ (??%?); >associative_append % 
736         ]
737       ]
738       -Htd #Htd lapply (Hte … (S n) … Htd … Ht1') -Htd -Hte
739       [ //
740       | (*|curconfig| = |newconfig|*) @daemon
741       | (* Htable → bit_or_null c1 = true *) @daemon
742       | (* only_bits (〈s1,false〉::newconfig) *) @daemon
743       | (* only_bits (curconfig@[〈s0,false〉]) *) @daemon
744       | (* no_marks (reverse ? curconfig) *) @daemon
745       | >Hmv1 in Htableeq; >Hnewc 
746         >associative_append >associative_append normalize
747         >associative_append >associative_append
748         #Htableeq <Htableeq // ]
749       * #ls1 * #rs1 * #c2 * * #Hte #Hliftte #Hlegalte
750       whd in ⊢ (%→?); * #_ #Houttape lapply (Houttape … Hte) -Houttape #Houttape
751       whd in Houttape:(???%); whd in Houttape:(???(??%%%));
752       @ex_intro [| @(ex_intro ?? rs1) @ex_intro [| % [ % 
753       [ >Houttape @eq_f @eq_f @eq_f @eq_f
754         change with ((〈bar,false〉::〈t0,false〉::table)@?) in ⊢ (???%);
755         >Htableeq >associative_append >associative_append 
756         >associative_append normalize >associative_append
757         >associative_append normalize >Hnewc <Hmv1
758         >associative_append normalize >associative_append
759         >Hmv1 % 
760       | @Hliftte
761       ]
762      | //
763      ]
764     ]
765    ] 
766   | * #td * whd in ⊢ (%→%→?); >Htc * #Htd
767     lapply (Htd ? (refl ??)) normalize in ⊢ (%→?);
768     #Hfalse destruct (Hfalse)
769   ]
770  ]
771 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #Ht1 #Ht2
772   #b #Hb >Hb in Ht1; * #Hc #Ht1 lapply (Hc ? (refl ??)) -Hc #Hb' %
773   // cases b in Hb'; normalize #H1 //
774 ]
775 qed.
776 *)