]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/universal/uni_step.ma
Adding GRealize to uni_step.
[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 definition R_exec_action ≝ λt1,t2.
252   ∀n,curconfig,ls,rs,c0,c1,s0,s1,table1,newconfig,mv,table2.
253   table_TM n (table1@〈comma,false〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2) → 
254   no_marks curconfig → only_bits (curconfig@[〈s0,false〉]) → 
255   only_bits (〈s1,false〉::newconfig) → bit_or_null c1 = true → 
256   |curconfig| = |newconfig| → 
257   legal_tape ls 〈c0,false〉 rs →
258   t1 = midtape STape (〈c0,false〉::curconfig@〈s0,false〉::〈grid,false〉::ls) 〈grid,false〉 
259     (table1@〈comma,true〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs) → 
260   ∀t1'.t1' = lift_tape ls 〈c0,false〉 rs → 
261   ∃ls1,rs1,c2.
262   t2 = midtape STape ls1 〈grid,false〉 
263     (〈s1,false〉::newconfig@〈c2,false〉::〈grid,false〉::
264      table1@〈comma,false〉::〈s1,false〉::newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs1) ∧   
265   lift_tape ls1 〈c2,false〉 rs1 = 
266   tape_move STape t1' (map_move c1 mv) ∧ legal_tape ls1 〈c2,false〉 rs1.
267   
268 (* move the following 2 lemmata to mono.ma *)
269 lemma tape_move_left_eq :
270   ∀A.∀t:tape A.∀c.
271   tape_move ? t (Some ? 〈c,L〉) = 
272   tape_move_left ? (left ? t) c (right ? t).
273 //
274 qed.
275
276 lemma tape_move_right_eq :
277   ∀A.∀t:tape A.∀c.
278   tape_move ? t (Some ? 〈c,R〉) = 
279   tape_move_right ? (left ? t) c (right ? t).
280 //
281 qed.
282
283 lemma lift_tape_not_null : 
284  ∀ls,c,bc,rs.c ≠ null → lift_tape ls 〈c,bc〉 rs = midtape ? ls 〈c,bc〉 rs.
285 #ls #c #bc #rs cases c //
286 #Hfalse @False_ind /2/
287 qed.
288
289 lemma merge_char_not_null :
290   ∀c1,c2.c1 ≠ null → merge_char c1 c2 ≠ null.
291 #c1 #c2 @not_to_not cases c2
292 [ #c1' normalize #Hfalse destruct (Hfalse)
293 | normalize //
294 | *: normalize #Hfalse destruct (Hfalse)
295 ]
296 qed.
297
298 lemma merge_char_null : ∀c.merge_char null c = c.
299 * //
300 qed.
301
302 lemma merge_char_cases : ∀c1,c2.merge_char c1 c2 = c1 ∨ merge_char c1 c2 = c2.
303 #c1 *
304 [ #c1' %2 %
305 | % %
306 | *: %2 % ]
307 qed.
308
309 (* lemma merge_char_c_bit :
310   ∀c1,c2.is_bit c2 = true → merge_char c1 c2 = c2.
311 #c1 *
312 [ #c2' #_ %
313 |*: normalize #Hfalse destruct (Hfalse) ]
314 qed.
315
316 lemma merge_char_c_bit :
317   ∀c1,c2.is_null c2 = true → merge_char c1 c2 = c1.
318 #c1 *
319 [ #c2' #_ %
320 |*: normalize #Hfalse destruct (Hfalse) ]
321 qed.
322
323 *)
324
325 lemma sem_exec_action : Realize ? exec_action R_exec_action.
326 #intape
327 cases (sem_seq … sem_init_copy
328         (sem_seq … sem_copy
329           (sem_seq … (sem_move_r …) sem_move_tape )) intape)
330 #k * #outc * #Hloop #HR
331 @(ex_intro ?? k) @(ex_intro ?? outc) % [ @Hloop ] -Hloop
332 #n #curconfig #ls #rs #c0 #c1 #s0 #s1 #table1 #newconfig #mv #table2
333 #Htable #Hcurconfig1 #Hcurconfig2 #Hnewconfig #Hc1 #Hlen #Htape #Hintape #t1' #Ht1'
334 cases HR -HR #ta * whd in ⊢ (%→?); #Hta
335 lapply (Hta (〈c0,false〉::curconfig) table1 s0 ls s1
336         (newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs) … Hintape) -Hta
337 [ (*Hcurconfig2*) @daemon
338 | (*Htable*) @daemon
339 | (*bit_or_null c0 = true *) @daemon
340 | (*Hcurconfig1*) @daemon
341 | #Hta * #tb * whd in ⊢ (%→?); #Htb
342   lapply (Htb (〈grid,false〉::ls) s0 s1 c0 c1 (〈mv,false〉::table2@〈grid,false〉::rs) newconfig (〈comma,false〉::reverse ? table1) curconfig Hta ????????) -Htb
343   [9:|*:(* bit_or_null c0,c1; |curconfig| = |newconfig|*) @daemon ]
344   #Htb * #tc * whd in ⊢ (%→?); * #_ #Htc lapply (Htc … Htb) -Htc whd in ⊢(???(??%%%)→?);#Htc
345   whd in ⊢ (%→?); #Houtc whd in Htc:(???%); whd in Htc:(???(??%%%));
346   lapply (Houtc rs n 
347     (〈comma,false〉::〈c1,false〉::reverse ? newconfig@〈s1,false〉::〈comma,false〉::reverse ? table1)
348     mv table2 (merge_char c0 c1) (reverse ? newconfig@[〈s1,false〉]) ls ????????)
349   [3: cases Htape -Htape * * #Hnomarks #Hbits #Hc0 #Hlsrs % [ % [ %
350     [ #x #Hx cases (orb_true_l … Hx) #Hx'
351       [ >(\P Hx') %
352       | @Hnomarks @memb_cons // ]
353     | @Hbits ]
354     | cases (merge_char_cases c0 c1) #Hmerge >Hmerge // ]
355     | cases (true_or_false (c0 == null)) #Hc0'
356       [ cases Hlsrs -Hlsrs 
357         [ *
358           [ >(\P Hc0') * #Hfalse @False_ind /2/
359           | #Hlsnil % %2 // ]
360         | #Hrsnil %2 // ] 
361       | % % @merge_char_not_null @(\Pf Hc0') ] ]
362   |4:>Htc @(eq_f3 … (midtape ?))
363     [ @eq_f @eq_f >associative_append >associative_append %
364     | %
365     | % ]
366   | %
367   || >reverse_cons >reverse_cons >reverse_append >reverse_reverse 
368      >reverse_cons >reverse_cons >reverse_reverse
369      >associative_append >associative_append >associative_append
370      >associative_append >associative_append
371      @Htable
372   | (* well formedness of table *) @daemon
373   | (* Hnewconfig *) @daemon
374   | (* bit_or_null mv = true (well formedness of table) *) @daemon
375   | -Houtc * #ls1 * #rs1 * #newc * #Hnewtapelegal * #Houtc *
376     [ *
377       [ * #Hmv #Htapemove
378         @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc)
379         %
380         [ %
381           [ >Houtc -Houtc >reverse_append
382             >reverse_reverse >reverse_single @eq_f
383             >reverse_cons >reverse_cons >reverse_append >reverse_cons
384             >reverse_cons >reverse_reverse >reverse_reverse
385             >associative_append >associative_append
386             >associative_append >associative_append
387             >associative_append >associative_append %
388           | >Hmv >Ht1' >Htapemove 
389             (* mv = bit false -→ c1 = bit ? *)
390             cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
391             >Hc1 >tape_move_left_eq >(legal_tape_left … Htape) 
392             >(legal_tape_right … Htape) %
393           ]
394         | //
395         ]
396       | * #Hmv #Htapemove 
397         @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
398         [ %
399           [ >Houtc -Houtc >reverse_append
400             >reverse_reverse >reverse_single @eq_f
401             >reverse_cons >reverse_cons >reverse_append >reverse_cons
402             >reverse_cons >reverse_reverse >reverse_reverse
403             >associative_append >associative_append
404             >associative_append >associative_append
405             >associative_append >associative_append %
406           |>Hmv >Ht1' >Htapemove 
407             cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
408             >Hc1 >tape_move_right_eq >(legal_tape_left … Htape) 
409             >(legal_tape_right … Htape) %
410           ]
411         | //
412         ]
413       ]
414     | * * * #Hmv #Hlseq #Hrseq #Hnewc 
415       @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
416       [ %
417         [ >Houtc -Houtc >reverse_append
418           >reverse_reverse >reverse_single @eq_f
419           >reverse_cons >reverse_cons >reverse_append >reverse_cons
420           >reverse_cons >reverse_reverse >reverse_reverse
421           >associative_append >associative_append
422           >associative_append >associative_append
423           >associative_append >associative_append %
424         |>Hmv >Ht1' cases c1 in Hnewc;
425           [ #c1' whd in ⊢ (??%?→?);#Hnewc <Hnewc
426             >Hlseq >Hrseq whd in ⊢ (??%%);
427             >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
428           | whd in ⊢ (??%?→?); #Hnewc >Hnewc >Hlseq >Hrseq %
429           |*: whd in ⊢ (??%?→?);#Hnewc <Hnewc
430             >Hlseq >Hrseq whd in ⊢ (??%%);
431             >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
432           ]
433         ]
434       | //
435       ]
436     ]
437   ]
438 ]
439 qed.
440
441 (*
442 if is_false(current) (* current state is not final *)
443    then init_match;
444     match_tuple;
445     if is_marked(current) = false (* match ok *)
446       then 
447            exec_action
448            move_r;
449       else sink;
450    else nop;
451 *)
452
453 definition uni_step ≝ 
454   ifTM ? (test_char STape (λc.\fst c == bit false))
455     (single_finalTM ? 
456       (init_match · match_tuple ·
457         (ifTM ? (test_char ? (λc.¬is_marked ? c))
458           (exec_action · move_r …)
459           (nop ?) tc_true)))
460     (nop ?) tc_true.
461
462 definition R_uni_step_true ≝ λt1,t2.
463   ∀n,table,s0,s1,c0,c1,ls,rs,curconfig,newconfig,mv.
464   0 < |table| → table_TM (S n) table → 
465   match_in_table (S n) (〈s0,false〉::curconfig) 〈c0,false〉
466     (〈s1,false〉::newconfig) 〈c1,false〉 〈mv,false〉 table → 
467   legal_tape ls 〈c0,false〉 rs → 
468   t1 = midtape STape (〈grid,false〉::ls) 〈s0,false〉 
469     (curconfig@〈c0,false〉::〈grid,false〉::table@〈grid,false〉::rs) → 
470   ∀t1'.t1' = lift_tape ls 〈c0,false〉 rs → 
471   s0 = bit false ∧
472   ∃ls1,rs1,c2.
473   (t2 = midtape STape (〈grid,false〉::ls1) 〈s1,false〉 
474     (newconfig@〈c2,false〉::〈grid,false〉::table@〈grid,false〉::rs1) ∧
475    lift_tape ls1 〈c2,false〉 rs1 = 
476    tape_move STape t1' (map_move c1 mv) ∧ legal_tape ls1 〈c2,false〉 rs1).
477    
478 definition R_uni_step_false ≝ λt1,t2.
479   ∀b. current STape t1 = Some ? 〈bit b,false〉 → b = true ∧ t2 = t1.
480   
481 (*axiom sem_match_tuple : Realize ? match_tuple R_match_tuple.*)
482
483 definition us_acc : states ? uni_step ≝ (inr … (inl … (inr … start_nop))).
484
485 definition Pre_uni_step ≝ λt1.
486   ∃n,table,s0,s1,c0,c1,ls,rs,curconfig,newconfig,mv.
487   0 < |table| ∧ table_TM (S n) table ∧
488   match_in_table (S n) (〈s0,false〉::curconfig) 〈c0,false〉
489     (〈s1,false〉::newconfig) 〈c1,false〉 〈mv,false〉 table ∧
490   legal_tape ls 〈c0,false〉 rs ∧
491   t1 = midtape STape (〈grid,false〉::ls) 〈s0,false〉 
492     (curconfig@〈c0,false〉::〈grid,false〉::table@〈grid,false〉::rs).
493     
494 lemma sem_uni_step :
495   accGRealize ? uni_step us_acc Pre_uni_step
496      R_uni_step_true R_uni_step_false. 
497 @(acc_sem_if_app_guarded STape … (sem_test_char ? (λc:STape.\fst c == bit false)) 
498   ? (test_char_inv …) (sem_nop …) …)
499 [| @(sem_seq_app_guarded … (Realize_to_GRealize … sem_init_match) ???)
500   [ 5: @sub_reflexive
501   | 3: @(sem_seq_app_guarded … sem_match_tuple 
502          (Realize_to_GRealize … (sem_if ????????? (sem_test_char …  (λc.¬is_marked FSUnialpha c))
503           (sem_seq … sem_exec_action (sem_move_r …))
504           (sem_nop …))))
505      [@(λx.True)
506      |//
507      |@sub_reflexive]
508   ||| #t1 #t2 * #n * #table * #s0 * #s1 * #c0 * #c1 * #ls * #rs * #curconfig 
509       * #newconfig * #mv * * * *
510       #Hlen1 #Htable #Hmatch #Hlegal #Ht1
511       whd in ⊢ (%→?);
512       cut (∃tup,table0.table = tup@table0 ∧ tuple_TM (S n) tup)
513       [@daemon]
514       * #tup * #table0 * #Htableeq * #qin * #cin * #qout * #cout * #mv0
515       * * * * * * * * * *
516       #Hqinnomarks #_ #Hqinbits #_ #_ #_ #_ #_ #Hqinlen #_ #Htupeq
517       cut (∃d,qin0.qin = 〈d,false〉::qin0)
518       [ lapply Hqinlen lapply Hqinnomarks -Hqinlen -Hqinnomarks cases qin
519         [ #_ normalize in ⊢ (%→?); #Hfalse destruct (Hfalse) 
520         | * #d #bd #qin0 #Hqinnomarks #_ %{d} %{qin0}
521           >(?:bd=false) [%]
522           @(Hqinnomarks 〈d,bd〉) @memb_hd ] ]
523       * #d * #qin0 #Hqineq
524       #Ht2 
525       lapply (Ht2 (〈grid,false〉::ls) (curconfig@[〈c0,false〉])
526                (qin0@〈cin,false〉::〈comma,false〉::qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0@〈grid,false〉::rs) s0 d ???)
527       [ >Ht1 @eq_f >associative_append @eq_f @eq_f @eq_f
528         >Htableeq >Htupeq >associative_append whd in ⊢ (??%?);
529         @eq_f >Hqineq >associative_append @eq_f whd in ⊢ (??%?);
530         @eq_f whd in ⊢ (??%?); @eq_f
531         >associative_append %
532       | @daemon
533       | @daemon
534       ]
535       #Ht2 % [| % [| % [| % [ @Ht2 ]
536         %2
537         (* ls0 = ls
538            c = s0
539            l1 = curconfig@[〈c0,false〉]
540            l2 = [〈bar,false〉]
541            c10 = d
542            l3 = qin0@[〈cin,false〉]
543            l4 = qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0
544            rs00 = rs
545            n0 = S n ?
546          *)
547         %{ls} %{s0} %{(curconfig@[〈c0,false〉])}
548         %{([〈bar,false〉])} %{d} %{(qin0@[〈cin,false〉])}
549         %{(qout@〈cout,false〉::〈comma,false〉::〈mv0,false〉::table0)}
550         %{rs} %{n} @daemon (* TODO *)
551       ]
552      ]
553     ]
554    ]
555  | #intape #outtape 
556   #ta whd in ⊢ (%→?); #Hta #HR
557   #n #fulltable #s0 #s1 #c0 #c1 #ls #rs #curconfig #newconfig #mv
558   #Htable_len cut (∃t0,table. fulltable =〈bar,false〉::〈t0,false〉::table) [(* 0 < |table| *) @daemon]
559   * #t0 * #table #Hfulltable >Hfulltable -fulltable 
560   #Htable #Hmatch #Htape #Hintape #t1' #Ht1'
561   >Hintape in Hta; * * * #c #bc *
562   whd in ⊢ (??%?→?); #HSome destruct (HSome) #Hc #Hta % [@(\P Hc)]
563   cases HR -HR 
564   #tb * whd in ⊢ (%→?); #Htb
565   lapply (Htb (〈grid,false〉::ls) (curconfig@[〈c0,false〉]) (table@〈grid,false〉::rs) c t0 ???)
566   [ >Hta >associative_append %
567   | @daemon
568   | @daemon
569   | -Hta -Htb #Htb * 
570     #tc * whd in ⊢ (%→?); #Htc cases (Htc … Htable … Htb) -Htb -Htc
571     [| * #Hcurrent #Hfalse @False_ind
572       (* absurd by Hmatch *) @daemon
573     | >(\P Hc) %
574     | (* Htable (con lemma) *) @daemon
575     | (* Hmatch *) @daemon
576     | (* Htable *) @daemon
577     | (* Htable, Hmatch → |config| = n 
578        necessaria modifica in R_match_tuple, le dimensioni non corrispondono
579       *) @daemon
580     ]
581     * #table1 * #newc * #mv1 * #table2 * #Htableeq #Htc *
582     [ * #td * whd in ⊢ (%→?); >Htc -Htc * * #c2 * whd in ⊢ (??%?→?); #Hc2 destruct (Hc2) 
583       #_ #Htd
584       cut (newc = 〈s1,false〉::newconfig@[〈c1,false〉]) [@daemon] #Hnewc
585       >Hnewc cut (mv1 = 〈mv,false〉)
586       [@daemon] #Hmv1
587       * #te * whd in ⊢ (%→?); #Hte
588       cut (td = midtape STape (〈c0,false〉::reverse STape curconfig@〈c,false〉::〈grid,false〉::ls) 
589               〈grid,false〉
590               ((table1@〈bar,false〉::〈c,false〉::curconfig@[〈c0,false〉])@〈comma,true〉::〈s1,false〉::
591                newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs))
592       [ >Htd @eq_f3 //
593         [ >reverse_append >reverse_single %
594         | >associative_append >associative_append normalize
595           >associative_append >Hmv1 >Hnewc @eq_f @eq_f @eq_f @eq_f @eq_f @eq_f
596           whd in ⊢ (??%?); >associative_append % 
597         ]
598       ]
599       -Htd #Htd lapply (Hte … (S n) … Htd … Ht1') -Htd -Hte
600       [ //
601       | (*|curconfig| = |newconfig|*) @daemon
602       | (* Htable → bit_or_null c1 = true *) @daemon
603       | (* only_bits (〈s1,false〉::newconfig) *) @daemon
604       | (* only_bits (curconfig@[〈s0,false〉]) *) @daemon
605       | (* no_marks (reverse ? curconfig) *) @daemon
606       | >Hmv1 in Htableeq; >Hnewc 
607         >associative_append >associative_append normalize
608         >associative_append >associative_append
609         #Htableeq <Htableeq // ]
610       * #ls1 * #rs1 * #c2 * * #Hte #Hliftte #Hlegalte
611       whd in ⊢ (%→?); * #_ #Houttape lapply (Houttape … Hte) -Houttape #Houttape
612       whd in Houttape:(???%); whd in Houttape:(???(??%%%));
613       @ex_intro [| @(ex_intro ?? rs1) @ex_intro [| % [ % 
614       [ >Houttape @eq_f @eq_f @eq_f @eq_f
615         change with ((〈bar,false〉::〈t0,false〉::table)@?) in ⊢ (???%);
616         >Htableeq >associative_append >associative_append 
617         >associative_append normalize >associative_append
618         >associative_append normalize >Hnewc <Hmv1
619         >associative_append normalize >associative_append
620         >Hmv1 % 
621       | @Hliftte
622       ]
623      | //
624      ]
625     ]
626    ] 
627   | * #td * whd in ⊢ (%→%→?); >Htc * #Htd
628     lapply (Htd ? (refl ??)) normalize in ⊢ (%→?);
629     #Hfalse destruct (Hfalse)
630   ]
631  ]
632 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #Ht1 #Ht2
633   #b #Hb >Hb in Ht1; * #Hc #Ht1 lapply (Hc ? (refl ??)) -Hc #Hb' %
634   // cases b in Hb'; normalize #H1 //
635 ]
636 qed.
637
638 (*
639 @(acc_sem_if_app STape … (sem_test_char ? (λc:STape.\fst c == bit false))
640    (sem_seq … sem_init_match      
641      (sem_seq … sem_match_tuple        
642        (sem_if … (* ????????? (sem_test_char …  (λc.¬is_marked FSUnialpha c)) *)
643           (sem_seq … sem_exec_action (sem_move_r …))
644           (sem_nop …))))
645    (sem_nop …)
646    …)
647 [@sem_test_char||]
648 [ #intape #outtape 
649   #ta whd in ⊢ (%→?); #Hta #HR
650   #n #fulltable #s0 #s1 #c0 #c1 #ls #rs #curconfig #newconfig #mv
651   #Htable_len cut (∃t0,table. fulltable =〈bar,false〉::〈t0,false〉::table) [(* 0 < |table| *) @daemon]
652   * #t0 * #table #Hfulltable >Hfulltable -fulltable 
653   #Htable #Hmatch #Htape #Hintape #t1' #Ht1'
654   >Hintape in Hta; * * * #c #bc *
655   whd in ⊢ (??%?→?); #HSome destruct (HSome) #Hc #Hta % [@(\P Hc)]
656   cases HR -HR 
657   #tb * whd in ⊢ (%→?); #Htb
658   lapply (Htb (〈grid,false〉::ls) (curconfig@[〈c0,false〉]) (table@〈grid,false〉::rs) c t0 ???)
659   [ >Hta >associative_append %
660   | @daemon
661   | @daemon
662   | -Hta -Htb #Htb * 
663     #tc * whd in ⊢ (%→?); #Htc cases (Htc … Htable … Htb) -Htb -Htc
664     [| * #Hcurrent #Hfalse @False_ind
665       (* absurd by Hmatch *) @daemon
666     | >(\P Hc) %
667     | (* Htable (con lemma) *) @daemon
668     | (* Hmatch *) @daemon
669     | (* Htable *) @daemon
670     | (* Htable, Hmatch → |config| = n 
671        necessaria modifica in R_match_tuple, le dimensioni non corrispondono
672       *) @daemon
673     ]
674     * #table1 * #newc * #mv1 * #table2 * #Htableeq #Htc *
675     [ * #td * whd in ⊢ (%→?); >Htc -Htc * * #c2 * whd in ⊢ (??%?→?); #Hc2 destruct (Hc2) 
676       #_ #Htd
677       cut (newc = 〈s1,false〉::newconfig@[〈c1,false〉]) [@daemon] #Hnewc
678       >Hnewc cut (mv1 = 〈mv,false〉)
679       [@daemon] #Hmv1
680       * #te * whd in ⊢ (%→?); #Hte
681       cut (td = midtape STape (〈c0,false〉::reverse STape curconfig@〈c,false〉::〈grid,false〉::ls) 
682               〈grid,false〉
683               ((table1@〈bar,false〉::〈c,false〉::curconfig@[〈c0,false〉])@〈comma,true〉::〈s1,false〉::
684                newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs))
685       [ >Htd @eq_f3 //
686         [ >reverse_append >reverse_single %
687         | >associative_append >associative_append normalize
688           >associative_append >Hmv1 >Hnewc @eq_f @eq_f @eq_f @eq_f @eq_f @eq_f
689           whd in ⊢ (??%?); >associative_append % 
690         ]
691       ]
692       -Htd #Htd lapply (Hte … (S n) … Htd … Ht1') -Htd -Hte
693       [ //
694       | (*|curconfig| = |newconfig|*) @daemon
695       | (* Htable → bit_or_null c1 = true *) @daemon
696       | (* only_bits (〈s1,false〉::newconfig) *) @daemon
697       | (* only_bits (curconfig@[〈s0,false〉]) *) @daemon
698       | (* no_marks (reverse ? curconfig) *) @daemon
699       | >Hmv1 in Htableeq; >Hnewc 
700         >associative_append >associative_append normalize
701         >associative_append >associative_append
702         #Htableeq <Htableeq // ]
703       * #ls1 * #rs1 * #c2 * * #Hte #Hliftte #Hlegalte
704       whd in ⊢ (%→?); * #_ #Houttape lapply (Houttape … Hte) -Houttape #Houttape
705       whd in Houttape:(???%); whd in Houttape:(???(??%%%));
706       @ex_intro [| @(ex_intro ?? rs1) @ex_intro [| % [ % 
707       [ >Houttape @eq_f @eq_f @eq_f @eq_f
708         change with ((〈bar,false〉::〈t0,false〉::table)@?) in ⊢ (???%);
709         >Htableeq >associative_append >associative_append 
710         >associative_append normalize >associative_append
711         >associative_append normalize >Hnewc <Hmv1
712         >associative_append normalize >associative_append
713         >Hmv1 % 
714       | @Hliftte
715       ]
716      | //
717      ]
718     ]
719    ] 
720   | * #td * whd in ⊢ (%→%→?); >Htc * #Htd
721     lapply (Htd ? (refl ??)) normalize in ⊢ (%→?);
722     #Hfalse destruct (Hfalse)
723   ]
724  ]
725 | #t1 #t2 #t3 whd in ⊢ (%→%→?); #Ht1 #Ht2
726   #b #Hb >Hb in Ht1; * #Hc #Ht1 lapply (Hc ? (refl ??)) -Hc #Hb' %
727   // cases b in Hb'; normalize #H1 //
728 ]
729 qed.
730 *)