]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/turing/mono.ma
progress
[helm.git] / matita / matita / lib / turing / mono.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 include "basics/vectors.ma".
13 (* include "basics/relations.ma". *)
14
15 (*
16 record tape (sig:FinSet): Type[0] ≝ 
17 { left : list (option sig);
18   right: list (option sig)
19 }.
20 *)
21
22 inductive tape (sig:FinSet) : Type[0] ≝ 
23 | niltape : tape sig
24 | leftof  : sig → list sig → tape sig
25 | rightof : sig → list sig → tape sig
26 | midtape : list sig → sig → list sig → tape sig.
27
28 definition left ≝ 
29  λsig.λt:tape sig.match t with
30  [ niltape ⇒ [] 
31  | leftof _ _ ⇒ [] 
32  | rightof s l ⇒ s::l
33  | midtape l _ _ ⇒ l ].
34
35 definition right ≝ 
36  λsig.λt:tape sig.match t with
37  [ niltape ⇒ [] 
38  | leftof s r ⇒ s::r 
39  | rightof _ _ ⇒ []
40  | midtape _ _ r ⇒ r ].
41  
42  
43 definition current ≝ 
44  λsig.λt:tape sig.match t with
45  [ midtape _ c _ ⇒ Some ? c
46  | _ ⇒ None ? ].
47  
48 definition mk_tape : 
49   ∀sig:FinSet.list sig → option sig → list sig → tape sig ≝ 
50   λsig,lt,c,rt.match c with
51   [ Some c' ⇒ midtape sig lt c' rt
52   | None ⇒ match lt with 
53     [ nil ⇒ match rt with
54       [ nil ⇒ niltape ?
55       | cons r0 rs0 ⇒ leftof ? r0 rs0 ]
56     | cons l0 ls0 ⇒ rightof ? l0 ls0 ] ].
57
58 inductive move : Type[0] ≝
59 | L : move 
60 | R : move
61 | N : move
62 .
63
64 (* We do not distinuish an input tape *)
65
66 record TM (sig:FinSet): Type[1] ≝ 
67 { states : FinSet;
68   trans : states × (option sig) → states × (option (sig × move));
69   start: states;
70   halt : states → bool
71 }.
72
73 record config (sig,states:FinSet): Type[0] ≝ 
74 { cstate : states;
75   ctape: tape sig
76 }.
77
78 (* definition option_hd ≝ λA.λl:list (option A).
79   match l with
80   [nil ⇒ None ?
81   |cons a _ ⇒ a
82   ].
83   *)
84
85 (*definition tape_write ≝ λsig.λt:tape sig.λs:sig.
86   <left ? t) s (right ? t).
87   [ None ⇒ t
88   | Some s' ⇒ midtape ? (left ? t) s' (right ? t) ].*)
89   
90 definition tape_move_left ≝ λsig:FinSet.λlt:list sig.λc:sig.λrt:list sig.
91   match lt with
92   [ nil ⇒ leftof sig c rt
93   | cons c0 lt0 ⇒ midtape sig lt0 c0 (c::rt) ].
94   
95 definition tape_move_right ≝ λsig:FinSet.λlt:list sig.λc:sig.λrt:list sig.
96   match rt with
97   [ nil ⇒ rightof sig c lt
98   | cons c0 rt0 ⇒ midtape sig (c::lt) c0 rt0 ].
99
100 definition tape_move ≝ λsig.λt: tape sig.λm:option (sig × move).
101   match m with
102   [ None ⇒ t
103   | Some m' ⇒ 
104     let 〈s,m1〉 ≝ m' in 
105     match m1 with
106       [ R ⇒ tape_move_right ? (left ? t) s (right ? t)
107       | L ⇒ tape_move_left ? (left ? t) s (right ? t)
108       | N ⇒ midtape ? (left ? t) s (right ? t)
109       ] ].
110 (*
111   (None,[]) → □
112   (None,a::[]) → □
113   (None,a::b::rs) → None::b::rs
114   (Some a,[]) → [Some a]
115   (Some a,b::rs) → Some a::rs
116   *)
117 (*
118 definition option_cons ≝ λA.λa:option A.λl.
119   match a with
120   [ None ⇒ match l with
121     [ nil ⇒ []
122     | cons _ _ ⇒ a::l ]
123   | Some _ ⇒ a::l ].
124   
125 (* definition tape_update := λsig.λt: tape sig.λs:option sig.
126   let newright ≝ 
127     match right ? t with
128     [ nil ⇒ match s with
129       [ None ⇒ [] 
130       | Some a ⇒ [Some ? a] ]
131     | cons b rs ⇒ match s with
132       [ None ⇒ match rs with
133         [ nil ⇒ [] 
134         | cons _ _ ⇒ None ?::rs ]
135       | Some a ⇒ Some ? a::rs ] ]
136   in mk_tape ? (left ? t) newright. *)
137   
138 definition tape_move ≝ λsig.λt:tape sig.λm:option sig × move.
139   let 〈s,m1〉 ≝ m in match m1 with
140     [ R ⇒ mk_tape sig (option_cons ? s (left ? t)) (tail ? (right ? t))
141     | L ⇒ mk_tape sig (tail ? (left ? t)) 
142            (option_cons ? (option_hd ? (left ? t))
143              (option_cons ? s (tail ? (right ? t))))
144     | N ⇒ mk_tape sig (left ? t) (option_cons ? s (tail ? (right ? t)))
145     ].
146 *)
147   
148 definition step ≝ λsig.λM:TM sig.λc:config sig (states sig M).
149   let current_char ≝ current ? (ctape ?? c) in
150   let 〈news,mv〉 ≝ trans sig M 〈cstate ?? c,current_char〉 in
151   mk_config ?? news (tape_move sig (ctape ?? c) mv).
152   
153 let rec loop (A:Type[0]) n (f:A→A) p a on n ≝
154   match n with 
155   [ O ⇒ None ?
156   | S m ⇒ if p a then (Some ? a) else loop A m f p (f a)
157   ].
158   
159 lemma loop_S_true : 
160   ∀A,n,f,p,a.  p a = true → 
161   loop A (S n) f p a = Some ? a.
162 #A #n #f #p #a #pa normalize >pa //
163 qed.
164
165 lemma loop_S_false : 
166   ∀A,n,f,p,a.  p a = false → 
167   loop A (S n) f p a = loop A n f p (f a).
168 normalize #A #n #f #p #a #Hpa >Hpa %
169 qed.  
170   
171 lemma loop_incr : ∀A,f,p,k1,k2,a1,a2. 
172   loop A k1 f p a1 = Some ? a2 → 
173     loop A (k2+k1) f p a1 = Some ? a2.
174 #A #f #p #k1 #k2 #a1 #a2 generalize in match a1; elim k1
175 [normalize #a0 #Hfalse destruct
176 |#k1' #IH #a0 <plus_n_Sm whd in ⊢ (??%? → ??%?);
177  cases (true_or_false (p a0)) #Hpa0 >Hpa0 whd in ⊢ (??%? → ??%?); // @IH
178 ]
179 qed.
180
181 lemma loop_merge : ∀A,f,p,q.(∀b. p b = false → q b = false) →
182  ∀k1,k2,a1,a2,a3,a4.
183    loop A k1 f p a1 = Some ? a2 → 
184      f a2 = a3 → q a2 = false → 
185        loop A k2 f q a3 = Some ? a4 →
186          loop A (k1+k2) f q a1 = Some ? a4.
187 #Sig #f #p #q #Hpq #k1 elim k1 
188   [normalize #k2 #a1 #a2 #a3 #a4 #H destruct
189   |#k1' #Hind #k2 #a1 #a2 #a3 #a4 normalize in ⊢ (%→?);
190    cases (true_or_false (p a1)) #pa1 >pa1 normalize in ⊢ (%→?);
191    [#eqa1a2 destruct #eqa2a3 #Hqa2 #H
192     whd in ⊢ (??(??%???)?); >plus_n_Sm @loop_incr
193     whd in ⊢ (??%?); >Hqa2 >eqa2a3 @H
194    |normalize >(Hpq … pa1) normalize 
195     #H1 #H2 #H3 @(Hind … H2) //
196    ]
197  ]
198 qed.
199
200 lemma loop_split : ∀A,f,p,q.(∀b. q b = true → p b = true) →
201  ∀k,a1,a2.
202    loop A k f q a1 = Some ? a2 → 
203    ∃k1,a3.
204     loop A k1 f p a1 = Some ? a3 ∧ 
205       loop A (S(k-k1)) f q a3 = Some ? a2.
206 #A #f #p #q #Hpq #k elim k
207   [#a1 #a2 normalize #Heq destruct
208   |#i #Hind #a1 #a2 normalize 
209    cases (true_or_false (q a1)) #Hqa1 >Hqa1 normalize
210     [ #Ha1a2 destruct
211      @(ex_intro … 1) @(ex_intro … a2) % 
212        [normalize >(Hpq …Hqa1) // |>Hqa1 //]
213     |#Hloop cases (true_or_false (p a1)) #Hpa1 
214        [@(ex_intro … 1) @(ex_intro … a1) % 
215          [normalize >Hpa1 // |>Hqa1 <Hloop normalize //]
216        |cases (Hind …Hloop) #k2 * #a3 * #Hloop1 #Hloop2
217         @(ex_intro … (S k2)) @(ex_intro … a3) %
218          [normalize >Hpa1 normalize // | @Hloop2 ]
219        ]
220     ]
221   ]
222 qed.
223
224 (*
225 lemma loop_split : ∀A,f,p,q.(∀b. p b = false → q b = false) →
226  ∀k1,k2,a1,a2,a3.
227    loop A k1 f p a1 = Some ? a2 → 
228      loop A k2 f q a2 = Some ? a3 →
229        loop A (k1+k2) f q a1 = Some ? a3.
230 #Sig #f #p #q #Hpq #k1 elim k1 
231   [normalize #k2 #a1 #a2 #a3 #H destruct
232   |#k1' #Hind #k2 #a1 #a2 #a3 normalize in ⊢ (%→?→?);
233    cases (true_or_false (p a1)) #pa1 >pa1 normalize in ⊢ (%→?);
234    [#eqa1a2 destruct #H @loop_incr //
235    |normalize >(Hpq … pa1) normalize 
236     #H1 #H2 @(Hind … H2) //
237    ]
238  ]
239 qed.
240 *)
241
242 definition initc ≝ λsig.λM:TM sig.λt.
243   mk_config sig (states sig M) (start sig M) t.
244
245 definition Realize ≝ λsig.λM:TM sig.λR:relation (tape sig).
246 ∀t.∃i.∃outc.
247   loop ? i (step sig M) (λc.halt sig M (cstate ?? c)) (initc sig M t) = Some ? outc ∧
248   R t (ctape ?? outc).
249
250 definition WRealize ≝ λsig.λM:TM sig.λR:relation (tape sig).
251 ∀t,i,outc.
252   loop ? i (step sig M) (λc.halt sig M (cstate ?? c)) (initc sig M t) = Some ? outc → 
253   R t (ctape ?? outc).
254
255 definition Terminate ≝ λsig.λM:TM sig.λt. ∃i,outc.
256   loop ? i (step sig M) (λc.halt sig M (cstate ?? c)) (initc sig M t) = Some ? outc.
257
258 lemma WRealize_to_Realize : ∀sig.∀M: TM sig.∀R.
259   (∀t.Terminate sig M t) → WRealize sig M R → Realize sig M R.
260 #sig #M #R #HT #HW #t cases (HT … t) #i * #outc #Hloop 
261 @(ex_intro … i) @(ex_intro … outc) % // @(HW … i) //
262 qed.
263
264 lemma loop_eq : ∀sig,f,q,i,j,a,x,y. 
265   loop sig i f q a = Some ? x → loop sig j f q a = Some ? y → x = y.
266 #sig #f #q #i #j @(nat_elim2 … i j)
267 [ #n #a #x #y normalize #Hfalse destruct (Hfalse)
268 | #n #a #x #y #H1 normalize #Hfalse destruct (Hfalse)
269 | #n1 #n2 #IH #a #x #y normalize cases (q a) normalize
270   [ #H1 #H2 destruct %
271   | /2/ ]
272 ]
273 qed.
274
275 theorem Realize_to_WRealize : ∀sig,M,R.Realize sig M R → WRealize sig M R.
276 #sig #M #R #H1 #inc #i #outc #Hloop
277 cases (H1 inc) #k * #outc1 * #Hloop1 #HR
278 >(loop_eq … Hloop Hloop1) //
279 qed.
280
281 definition accRealize ≝ λsig.λM:TM sig.λacc:states sig M.λRtrue,Rfalse:relation (tape sig).
282 ∀t.∃i.∃outc.
283   loop ? i (step sig M) (λc.halt sig M (cstate ?? c)) (initc sig M t) = Some ? outc ∧
284   (cstate ?? outc = acc → Rtrue t (ctape ?? outc)) ∧ 
285   (cstate ?? outc ≠ acc → Rfalse t (ctape ?? outc)).
286
287 (* Compositions *)
288
289 definition seq_trans ≝ λsig. λM1,M2 : TM sig. 
290 λp. let 〈s,a〉 ≝ p in
291   match s with 
292   [ inl s1 ⇒ 
293       if halt sig M1 s1 then 〈inr … (start sig M2), None ?〉
294       else 
295       let 〈news1,m〉 ≝ trans sig M1 〈s1,a〉 in
296       〈inl … news1,m〉
297   | inr s2 ⇒ 
298       let 〈news2,m〉 ≝ trans sig M2 〈s2,a〉 in
299       〈inr … news2,m〉
300   ].
301  
302 definition seq ≝ λsig. λM1,M2 : TM sig. 
303   mk_TM sig 
304     (FinSum (states sig M1) (states sig M2))
305     (seq_trans sig M1 M2) 
306     (inl … (start sig M1))
307     (λs.match s with
308       [ inl _ ⇒ false | inr s2 ⇒ halt sig M2 s2]). 
309
310 definition Rcomp ≝ λA.λR1,R2:relation A.λa1,a2.
311   ∃am.R1 a1 am ∧ R2 am a2.
312
313 (*
314 definition injectRl ≝ λsig.λM1.λM2.λR.
315    λc1,c2. ∃c11,c12. 
316      inl … (cstate sig M1 c11) = cstate sig (seq sig M1 M2) c1 ∧ 
317      inl … (cstate sig M1 c12) = cstate sig (seq sig M1 M2) c2 ∧
318      ctape sig M1 c11 = ctape sig (seq sig M1 M2) c1 ∧ 
319      ctape sig M1 c12 = ctape sig (seq sig M1 M2) c2 ∧ 
320      R c11 c12.
321
322 definition injectRr ≝ λsig.λM1.λM2.λR.
323    λc1,c2. ∃c21,c22. 
324      inr … (cstate sig M2 c21) = cstate sig (seq sig M1 M2) c1 ∧ 
325      inr … (cstate sig M2 c22) = cstate sig (seq sig M1 M2) c2 ∧
326      ctape sig M2 c21 = ctape sig (seq sig M1 M2) c1 ∧ 
327      ctape sig M2 c22 = ctape sig (seq sig M1 M2) c2 ∧ 
328      R c21 c22.
329      
330 definition Rlink ≝ λsig.λM1,M2.λc1,c2.
331   ctape sig (seq sig M1 M2) c1 = ctape sig (seq sig M1 M2) c2 ∧
332   cstate sig (seq sig M1 M2) c1 = inl … (halt sig M1) ∧
333   cstate sig (seq sig M1 M2) c2 = inr … (start sig M2). *)
334   
335 interpretation "relation composition" 'compose R1 R2 = (Rcomp ? R1 R2).
336
337 definition lift_confL ≝ 
338   λsig,S1,S2,c.match c with 
339   [ mk_config s t ⇒ mk_config sig (FinSum S1 S2) (inl … s) t ].
340   
341 definition lift_confR ≝ 
342   λsig,S1,S2,c.match c with
343   [ mk_config s t ⇒ mk_config sig (FinSum S1 S2) (inr … s) t ].
344   
345 definition halt_liftL ≝ 
346   λS1,S2,halt.λs:FinSum S1 S2.
347   match s with
348   [ inl s1 ⇒ halt s1
349   | inr _ ⇒ true ]. (* should be vacuous in all cases we use halt_liftL *)
350
351 definition halt_liftR ≝ 
352   λS1,S2,halt.λs:FinSum S1 S2.
353   match s with
354   [ inl _ ⇒ false 
355   | inr s2 ⇒ halt s2 ].
356       
357 lemma p_halt_liftL : ∀sig,S1,S2,halt,c.
358   halt (cstate sig S1 c) =
359      halt_liftL S1 S2 halt (cstate … (lift_confL … c)).
360 #sig #S1 #S2 #halt #c cases c #s #t %
361 qed.
362
363 lemma trans_liftL : ∀sig,M1,M2,s,a,news,move.
364   halt ? M1 s = false → 
365   trans sig M1 〈s,a〉 = 〈news,move〉 → 
366   trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inl … news,move〉.
367 #sig (*#M1*) * #Q1 #T1 #init1 #halt1 #M2 #s #a #news #move
368 #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans %
369 qed.
370
371 lemma trans_liftR : ∀sig,M1,M2,s,a,news,move.
372   halt ? M2 s = false → 
373   trans sig M2 〈s,a〉 = 〈news,move〉 → 
374   trans sig (seq sig M1 M2) 〈inr … s,a〉 = 〈inr … news,move〉.
375 #sig #M1 * #Q2 #T2 #init2 #halt2 #s #a #news #move
376 #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans %
377 qed.
378
379 lemma config_eq : 
380   ∀sig,M,c1,c2.
381   cstate sig M c1 = cstate sig M c2 → 
382   ctape sig M c1 = ctape sig M c2 →  c1 = c2.
383 #sig #M1 * #s1 #t1 * #s2 #t2 //
384 qed.
385
386 lemma step_lift_confR : ∀sig,M1,M2,c0.
387  halt ? M2 (cstate ?? c0) = false → 
388  step sig (seq sig M1 M2) (lift_confR sig (states ? M1) (states ? M2) c0) =
389  lift_confR sig (states ? M1) (states ? M2) (step sig M2 c0).
390 #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 * #s #t
391   lapply (refl ? (trans ?? 〈s,current sig t〉))
392   cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %);
393   #s0 #m0 cases t
394   [ #Heq #Hhalt
395   | 2,3: #s1 #l1 #Heq #Hhalt 
396   |#ls #s1 #rs #Heq #Hhalt ]
397   whd in ⊢ (???(????%)); >Heq
398   whd in ⊢ (???%);
399   whd in ⊢ (??(???%)?); whd in ⊢ (??%?);
400   >(trans_liftR … Heq) //
401 qed.
402
403 lemma step_lift_confL : ∀sig,M1,M2,c0.
404  halt ? M1 (cstate ?? c0) = false → 
405  step sig (seq sig M1 M2) (lift_confL sig (states ? M1) (states ? M2) c0) =
406  lift_confL sig ?? (step sig M1 c0).
407 #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 * #s #t
408   lapply (refl ? (trans ?? 〈s,current sig t〉))
409   cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %);
410   #s0 #m0 cases t
411   [ #Heq #Hhalt
412   | 2,3: #s1 #l1 #Heq #Hhalt 
413   |#ls #s1 #rs #Heq #Hhalt ]
414   whd in ⊢ (???(????%)); >Heq
415   whd in ⊢ (???%);
416   whd in ⊢ (??(???%)?); whd in ⊢ (??%?);
417   >(trans_liftL … Heq) //
418 qed.
419
420 lemma loop_lift : ∀A,B,k,lift,f,g,h,hlift,c1,c2.
421   (∀x.hlift (lift x) = h x) → 
422   (∀x.h x = false → lift (f x) = g (lift x)) → 
423   loop A k f h c1 = Some ? c2 → 
424   loop B k g hlift (lift c1) = Some ? (lift … c2).
425 #A #B #k #lift #f #g #h #hlift #c1 #c2 #Hfg #Hhlift
426 generalize in match c1; elim k
427 [#c0 normalize in ⊢ (??%? → ?); #Hfalse destruct (Hfalse)
428 |#k0 #IH #c0 whd in ⊢ (??%? → ??%?);
429  cases (true_or_false (h c0)) #Hc0 >Hfg >Hc0
430  [ normalize #Heq destruct (Heq) %
431  | normalize <Hhlift // @IH ]
432 qed.
433
434 (* 
435 lemma loop_liftL : ∀sig,k,M1,M2,c1,c2.
436   loop ? k (step sig M1) (λc.halt sig M1 (cstate ?? c)) c1 = Some ? c2 →
437     loop ? k (step sig (seq sig M1 M2)) 
438       (λc.halt_liftL ?? (halt sig M1) (cstate ?? c)) (lift_confL … c1) = 
439     Some ? (lift_confL … c2).
440 #sig #k #M1 #M2 #c1 #c2 generalize in match c1;
441 elim k
442 [#c0 normalize in ⊢ (??%? → ?); #Hfalse destruct (Hfalse)
443 |#k0 #IH #c0 whd in ⊢ (??%? → ??%?);
444  cases (true_or_false (halt ?? (cstate sig (states ? M1) c0))) #Hc0 >Hc0
445  [ >(?: halt_liftL ?? (halt sig M1) (cstate sig ? (lift_confL … c0)) = true)
446    [ whd in ⊢ (??%? → ??%?); #Hc2 destruct (Hc2) %
447    | <Hc0 cases c0 // ]
448  | >(?: halt_liftL ?? (halt sig M1) (cstate ?? (lift_confL … c0)) = false)
449    [whd in ⊢ (??%? → ??%?); #Hc2 <(IH ? Hc2) @eq_f
450     @step_lift_confL //
451    | <Hc0 cases c0 // ]
452 qed.
453
454 lemma loop_liftR : ∀sig,k,M1,M2,c1,c2.
455   loop ? k (step sig M2) (λc.halt sig M2 (cstate ?? c)) c1 = Some ? c2 →
456     loop ? k (step sig (seq sig M1 M2)) 
457       (λc.halt sig (seq sig M1 M2) (cstate ?? c)) (lift_confR … c1) = 
458     Some ? (lift_confR … c2).
459 #sig #k #M1 #M2 #c1 #c2 generalize in match c1;
460 elim k
461 [#c0 normalize in ⊢ (??%? → ?); #Hfalse destruct (Hfalse)
462 |#k0 #IH #c0 whd in ⊢ (??%? → ??%?);
463  cases (true_or_false (halt ?? (cstate sig ? c0))) #Hc0 >Hc0
464  [ >(?: halt ? (seq sig M1 M2) (cstate sig ? (lift_confR … c0)) = true)
465    [ whd in ⊢ (??%? → ??%?); #Hc2 destruct (Hc2) %
466    | <Hc0 cases c0 // ]
467  | >(?: halt ? (seq sig M1 M2) (cstate sig ? (lift_confR … c0)) = false)
468    [whd in ⊢ (??%? → ??%?); #Hc2 <(IH ? Hc2) @eq_f
469     @step_lift_confR //
470    | <Hc0 cases c0 // ]
471  ]
472 qed.  
473
474 *)
475     
476 lemma loop_Some : 
477   ∀A,k,f,p,a,b.loop A k f p a = Some ? b → p b = true.
478 #A #k #f #p elim k 
479 [#a #b normalize #Hfalse destruct
480 |#k0 #IH #a #b whd in ⊢ (??%? → ?); cases (true_or_false (p a)) #Hpa
481  [ >Hpa normalize #H1 destruct //
482  | >Hpa normalize @IH
483  ]
484 ]
485 qed. 
486
487 lemma trans_liftL_true : ∀sig,M1,M2,s,a.
488   halt ? M1 s = true → 
489   trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inr … (start ? M2),None ?〉.
490 #sig #M1 #M2 #s #a
491 #Hhalt whd in ⊢ (??%?); >Hhalt %
492 qed.
493
494 lemma eq_ctape_lift_conf_L : ∀sig,S1,S2,outc.
495   ctape sig (FinSum S1 S2) (lift_confL … outc) = ctape … outc.
496 #sig #S1 #S2 #outc cases outc #s #t %
497 qed.
498   
499 lemma eq_ctape_lift_conf_R : ∀sig,S1,S2,outc.
500   ctape sig (FinSum S1 S2) (lift_confR … outc) = ctape … outc.
501 #sig #S1 #S2 #outc cases outc #s #t %
502 qed.
503
504 theorem sem_seq: ∀sig,M1,M2,R1,R2.
505   Realize sig M1 R1 → Realize sig M2 R2 → 
506     Realize sig (seq sig M1 M2) (R1 ∘ R2).
507 #sig #M1 #M2 #R1 #R2 #HR1 #HR2 #t 
508 cases (HR1 t) #k1 * #outc1 * #Hloop1 #HM1
509 cases (HR2 (ctape sig (states ? M1) outc1)) #k2 * #outc2 * #Hloop2 #HM2
510 @(ex_intro … (k1+k2)) @(ex_intro … (lift_confR … outc2))
511 %
512 [@(loop_merge ??????????? 
513    (loop_lift ??? (lift_confL sig (states sig M1) (states sig M2))
514    (step sig M1) (step sig (seq sig M1 M2)) 
515    (λc.halt sig M1 (cstate … c)) 
516    (λc.halt_liftL ?? (halt sig M1) (cstate … c)) … Hloop1))
517   [ * *
518    [ #sl #tl whd in ⊢ (??%? → ?); #Hl %
519    | #sr #tr whd in ⊢ (??%? → ?); #Hr destruct (Hr) ]
520   || #c0 #Hhalt <step_lift_confL //
521   | #x <p_halt_liftL %
522   |6:cases outc1 #s1 #t1 %
523   |7:@(loop_lift … (initc ?? (ctape … outc1)) … Hloop2) 
524     [ * #s2 #t2 %
525     | #c0 #Hhalt <step_lift_confR // ]
526   |whd in ⊢ (??(???%)?);whd in ⊢ (??%?);
527    generalize in match Hloop1; cases outc1 #sc1 #tc1 #Hloop10 
528    >(trans_liftL_true sig M1 M2 ??) 
529     [ whd in ⊢ (??%?); whd in ⊢ (???%);
530       @config_eq whd in ⊢ (???%); //
531     | @(loop_Some ?????? Hloop10) ]
532  ]
533 | @(ex_intro … (ctape ? (FinSum (states ? M1) (states ? M2)) (lift_confL … outc1)))
534   % // >eq_ctape_lift_conf_L >eq_ctape_lift_conf_R //
535 ]
536 qed.
537