X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=matita%2Fmatita%2Flib%2Fturing%2Fmulti_universal%2Funistep_aux.ma;h=4f37564c0ea459d8aa8365813dec2084917e13e5;hb=dabd7add16b4e678f48bc15cd0d992b80fbc9216;hp=f240cea9788d5ab6810beb3b3dbce4acb6c8af01;hpb=789726e7f992ff6a37b91799fb081f8013703b49;p=helm.git diff --git a/matita/matita/lib/turing/multi_universal/unistep_aux.ma b/matita/matita/lib/turing/multi_universal/unistep_aux.ma index f240cea97..4f37564c0 100644 --- a/matita/matita/lib/turing/multi_universal/unistep_aux.ma +++ b/matita/matita/lib/turing/multi_universal/unistep_aux.ma @@ -10,6 +10,10 @@ V_____________________________________________________________*) include "turing/multi_universal/moves_2.ma". +include "turing/multi_universal/match.ma". +include "turing/multi_universal/copy.ma". +include "turing/multi_universal/alphabet.ma". +include "turing/multi_universal/tuples.ma". (* @@ -48,240 +52,585 @@ include "turing/multi_universal/moves_2.ma". cfg_to_obj *) -definition obj_to_cfg ≝ - mmove cfg unialpha 3 L · - mmove cfg unialpha 3 L · - if_TM ?? (inject_TM ? (test_null ?) 3 obj) - ( +definition copy_char_states ≝ initN 3. +definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)). +definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)). - - -definition o2c_states ≝ initN 3. - -definition copy0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)). -definition copy1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)). -definition copy2 : copy_states ≝ mk_Sig ?? 2 (leb_true_to_le 3 3 (refl …)). - - -definition trans_copy_step ≝ +definition trans_copy_char ≝ λsrc,dst.λsig:FinSet.λn. - λp:copy_states × (Vector (option sig) (S n)). + λp:copy_char_states × (Vector (option sig) (S n)). let 〈q,a〉 ≝ p in match pi1 … q with - [ O ⇒ match nth src ? a (None ?) with - [ None ⇒ 〈copy2,null_action sig n〉 - | Some ai ⇒ match nth dst ? a (None ?) with - [ None ⇒ 〈copy2,null_action ? n〉 - | Some aj ⇒ - 〈copy1,change_vec ? (S n) + [ O ⇒ 〈cc1,change_vec ? (S n) (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src) - (〈Some ? ai,R〉) dst〉 - ] - ] - | S q ⇒ match q with - [ O ⇒ (* 1 *) 〈copy1,null_action ? n〉 - | S _ ⇒ (* 2 *) 〈copy2,null_action ? n〉 ] ]. - -definition copy_step ≝ + (〈nth src ? a (None ?),R〉) dst〉 + | S _ ⇒ 〈cc1,null_action ? n〉 ]. + +definition copy_char ≝ λsrc,dst,sig,n. - mk_mTM sig n copy_states (trans_copy_step src dst sig n) - copy0 (λq.q == copy1 ∨ q == copy2). + mk_mTM sig n copy_char_states (trans_copy_char src dst sig n) + cc0 (λq.q == cc1). -definition R_comp_step_true ≝ +definition R_copy_char ≝ λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n). - ∃x,y. - current ? (nth src ? int (niltape ?)) = Some ? x ∧ - current ? (nth dst ? int (niltape ?)) = Some ? y ∧ - outt = change_vec ?? - (change_vec ?? int - (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src) - (tape_move_mono ? (nth dst ? int (niltape ?)) 〈Some ? x, R〉) dst. - -definition R_comp_step_false ≝ - λsrc,dst:nat.λsig,n.λint,outt: Vector (tape sig) (S n). - (current ? (nth src ? int (niltape ?)) = None ? ∨ - current ? (nth dst ? int (niltape ?)) = None ?) ∧ outt = int. - -lemma copy_q0_q2_null : - ∀src,dst,sig,n,v.src < S n → dst < S n → - (nth src ? (current_chars ?? v) (None ?) = None ? ∨ - nth dst ? (current_chars ?? v) (None ?) = None ?) → - step sig n (copy_step src dst sig n) (mk_mconfig ??? copy0 v) - = mk_mconfig ??? copy2 v. -#src #dst #sig #n #v #Hi #Hj -whd in ⊢ (? → ??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (?→??%?); -* #Hcurrent -[ @eq_f2 - [ whd in ⊢ (??(???%)?); >Hcurrent % - | whd in ⊢ (??(????(???%))?); >Hcurrent @tape_move_null_action ] -| @eq_f2 - [ whd in ⊢ (??(???%)?); >Hcurrent cases (nth src ?? (None sig)) // - | whd in ⊢ (??(????(???%))?); >Hcurrent - cases (nth src ?? (None sig)) [|#x] @tape_move_null_action ] ] -qed. + outt = change_vec ?? + (change_vec ?? int + (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src) + (tape_move_mono ? (nth dst ? int (niltape ?)) + 〈current ? (nth src ? int (niltape ?)), R〉) dst. -lemma copy_q0_q1 : - ∀src,dst,sig,n,v,a,b.src ≠ dst → src < S n → dst < S n → - nth src ? (current_chars ?? v) (None ?) = Some ? a → - nth dst ? (current_chars ?? v) (None ?) = Some ? b → - step sig n (copy_step src dst sig n) (mk_mconfig ??? copy0 v) = - mk_mconfig ??? copy1 +lemma copy_char_q0_q1 : + ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n → + step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) = + mk_mconfig ??? cc1 (change_vec ? (S n) (change_vec ?? v (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src) - (tape_move_mono ? (nth dst ? v (niltape ?)) 〈Some ? a, R〉) dst). -#src #dst #sig #n #v #a #b #Heq #Hsrc #Hdst #Ha1 #Ha2 -whd in ⊢ (??%?); >(eq_pair_fst_snd … (trans ????)) whd in ⊢ (??%?); @eq_f2 -[ whd in match (trans ????); - >Ha1 >Ha2 whd in ⊢ (??(???%)?); >(\b ?) // -| whd in match (trans ????); - >Ha1 >Ha2 whd in ⊢ (??(????(???%))?); >(\b ?) // - change with (change_vec ?????) in ⊢ (??(????%)?); - <(change_vec_same … v dst (niltape ?)) in ⊢ (??%?); - <(change_vec_same … v src (niltape ?)) in ⊢ (??%?); - >tape_move_multi_def - >pmap_change >pmap_change tape_move_null_action - @eq_f2 // >nth_change_vec_neq // -] + (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst). +#src #dst #sig #n #v #Heq #Hsrc #Hdst +whd in ⊢ (??%?); +<(change_vec_same … v dst (niltape ?)) in ⊢ (??%?); +<(change_vec_same … v src (niltape ?)) in ⊢ (??%?); +>tape_move_multi_def @eq_f2 // +>pmap_change >pmap_change tape_move_null_action @eq_f2 // @eq_f2 +[ >change_vec_same % +| >change_vec_same >change_vec_same // ] qed. -lemma sem_copy_step : +lemma sem_copy_char: ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n → - copy_step src dst sig n ⊨ - [ copy1: R_comp_step_true src dst sig n, - R_comp_step_false src dst sig n ]. + copy_char src dst sig n ⊨ R_copy_char src dst sig n. #src #dst #sig #n #Hneq #Hsrc #Hdst #int -lapply (refl ? (current ? (nth src ? int (niltape ?)))) -cases (current ? (nth src ? int (niltape ?))) in ⊢ (???%→?); -[ #Hcur_src %{2} % - [| % [ % - [ whd in ⊢ (??%?); >copy_q0_q2_null /2/ - | normalize in ⊢ (%→?); #H destruct (H) ] - | #_ % // % // ] ] -| #a #Ha lapply (refl ? (current ? (nth dst ? int (niltape ?)))) - cases (current ? (nth dst ? int (niltape ?))) in ⊢ (???%→?); - [ #Hcur_dst %{2} % - [| % [ % - [ whd in ⊢ (??%?); >copy_q0_q2_null /2/ - | normalize in ⊢ (%→?); #H destruct (H) ] - | #_ % // %2 >Hcur_dst % ] ] - | #b #Hb %{2} % - [| % [ % - [whd in ⊢ (??%?); >(copy_q0_q1 … a b Hneq Hsrc Hdst) // - | #_ %{a} %{b} % // % //] - | * #H @False_ind @H % +%{2} % [| % [ % | whd >copy_char_q0_q1 // ]] +qed. + +definition obj ≝ (0:DeqNat). +definition cfg ≝ (1:DeqNat). +definition prg ≝ (2:DeqNat). + +definition obj_to_cfg ≝ + mmove cfg FSUnialpha 2 L · + (ifTM ?? (inject_TM ? (test_null ?) 2 obj) + (copy_char obj cfg FSUnialpha 2 · + mmove cfg FSUnialpha 2 L · + mmove obj FSUnialpha 2 L) + (inject_TM ? (write FSUnialpha null) 2 cfg) + tc_true) · + inject_TM ? (move_to_end FSUnialpha L) 2 cfg · + mmove cfg FSUnialpha 2 R. + +definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3. + ∀c,ls. + nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] → + (∀lso,x,rso.nth obj ? t1 (niltape ?) = midtape FSUnialpha lso x rso → + t2 = change_vec ?? t1 + (mk_tape ? [ ] (option_hd ? (reverse ? (x::ls))) (tail ? (reverse ? (x::ls)))) cfg) ∧ + (current ? (nth obj ? t1 (niltape ?)) = None ? → + t2 = change_vec ?? t1 + (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (null::ls))) + (tail ? (reverse ? (null::ls)))) cfg). + +axiom accRealize_to_Realize : + ∀sig,n.∀M:mTM sig n.∀Rtrue,Rfalse,acc. + M ⊨ [ acc: Rtrue, Rfalse ] → M ⊨ Rtrue ∪ Rfalse. + +lemma eq_mk_tape_rightof : + ∀alpha,a,al.mk_tape alpha (a::al) (None ?) [ ] = rightof ? a al. +#alpha #a #al % +qed. + +definition option_cons ≝ λsig.λc:option sig.λl. + match c with [ None ⇒ l | Some c0 ⇒ c0::l ]. + +lemma tape_move_mk_tape_R : + ∀sig,ls,c,rs. + (c = None ? → ls = [ ] ∨ rs = [ ]) → + tape_move ? (mk_tape sig ls c rs) R = + mk_tape ? (option_cons ? c ls) (option_hd ? rs) (tail ? rs). +#sig * [ * [ * | #c * ] | #l0 #ls0 * [ * +[| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ] +normalize // +qed. + +lemma eq_vec_change_vec : ∀sig,n.∀v1,v2:Vector sig n.∀i,t,d. + nth i ? v2 d = t → + (∀j.i ≠ j → nth j ? v1 d = nth j ? v2 d) → + v2 = change_vec ?? v1 t i. +#sig #n #v1 #v2 #i #t #d #H1 #H2 @(eq_vec … d) +#i0 #Hlt cases (decidable_eq_nat i0 i) #Hii0 +[ >Hii0 >nth_change_vec // +| >nth_change_vec_neq [|@sym_not_eq //] @sym_eq @H2 @sym_not_eq // ] +qed. + +lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg. +@(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?) + (sem_seq ?????? + (sem_if ?????????? + (sem_test_null_multi ?? obj ?) + (sem_seq ?????? (sem_copy_char …) + (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) + (sem_move_multi ? 2 obj L ?))) + (sem_inject ???? cfg ? (sem_write FSUnialpha null))) + (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?)) + (sem_move_multi ? 2 cfg R ?)))) // +#ta #tb * +#tc * whd in ⊢ (%→?); #Htc * +#td * * +[ * #te * * #Hcurtc #Hte + * destruct (Hte) #te * whd in ⊢ (%→?); #Hte + cut (∃x.current ? (nth obj ? tc (niltape ?)) = Some ? x) + [ cases (current ? (nth obj ? tc (niltape ?))) in Hcurtc; + [ * #H @False_ind /2/ | #x #_ %{x} % ] ] * #x #Hcurtc' +(* [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte *) + * #tf * whd in ⊢ (%→%→?); #Htf #Htd + * #tg * * * whd in ⊢ (%→%→%→%→?); #Htg1 #Htg2 #Htg3 #Htb + #c #ls #Hta1 % + [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof + whd in match (tape_move ???); #Htc + cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg) + [ lapply (eq_vec_change_vec ??????? (Htg2 ls x [ ] ?) Htg3) // + >Htd >nth_change_vec_neq // >Htf >nth_change_vec // + >Hte >Hcurtc' >nth_change_vec // >Htc >nth_change_vec // ] + -Htg1 -Htg2 -Htg3 #Htg destruct + >change_vec_change_vec >change_vec_change_vec + >change_vec_commute // >change_vec_change_vec + >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec + >change_vec_commute // >change_vec_change_vec + >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //] + >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //] + >change_vec_commute [|@sym_not_eq //] @eq_f3 // + [ >Hta2 cases rso in Hta2; whd in match (tape_move_mono ???); + [ #Hta2 whd in match (tape_move ???); tape_move_mk_tape_R [| #_ % %] >reverse_cons + >nth_change_vec_neq in Hcurtc'; [|@sym_not_eq //] >Hta2 + normalize in ⊢ (%→?); #H destruct (H) % ] + | #Hta2 >Htc in Hcurtc'; >nth_change_vec_neq [| @sym_not_eq //] + >Hta2 #H destruct (H) ] - ] +| * #te * * #Hcurtc #Hte + * whd in ⊢ (%→%→?); #Htd1 #Htd2 + * #tf * * * #Htf1 #Htf2 #Htf3 whd in ⊢ (%→?); #Htb + #c #ls #Hta1 % + [ #lso #x #rso #Hta2 >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //] + >Hta2 normalize in ⊢ (%→?); #H destruct (H) + | #_ >Hta1 in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc + destruct (Hte) cut (td = change_vec ?? tc (midtape ? ls null []) cfg) + [ lapply (eq_vec_change_vec ??????? (Htd1 ls c [ ] ?) Htd2) // + >Htc >nth_change_vec // ] -Htd1 -Htd2 #Htd + -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg) + [ lapply (eq_vec_change_vec ??????? (Htf2 ls null [ ] ?) Htf3) // + >Htd >nth_change_vec // ] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb) + >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec + >change_vec_change_vec >change_vec_change_vec >nth_change_vec // + >reverse_cons >tape_move_mk_tape_R /2/ ] ] qed. -definition copy ≝ λsrc,dst,sig,n. - whileTM … (copy_step src dst sig n) copy1. +definition test_null_char ≝ test_char FSUnialpha (λc.c == null). -definition R_copy ≝ - λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n). - ((current ? (nth src ? int (niltape ?)) = None ? ∨ - current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧ - (∀ls,x,x0,rs,ls0,rs0. - nth src ? int (niltape ?) = midtape sig ls x rs → - nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 → - (∃rs01,rs02.rs0 = rs01@rs02 ∧ |rs01| = |rs| ∧ - outt = change_vec ?? - (change_vec ?? int - (mk_tape sig (reverse sig rs@x::ls) (None sig) []) src) - (mk_tape sig (reverse sig rs@x::ls0) (option_hd sig rs02) - (tail sig rs02)) dst) ∨ - (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧ - outt = change_vec ?? - (change_vec ?? int - (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2) - (tail sig rs2)) src) - (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)). - -lemma wsem_copy : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n → - copy src dst sig n ⊫ R_copy src dst sig n. -#src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop -lapply (sem_while … (sem_copy_step src dst sig n Hneq Hsrc Hdst) … Hloop) // --Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar -[ whd in ⊢ (%→?); * #Hnone #Hout % - [#_ @Hout - |#ls #x #x0 #rs #ls0 #rs0 #Hsrc1 #Hdst1 @False_ind cases Hnone - [>Hsrc1 normalize #H destruct (H) | >Hdst1 normalize #H destruct (H)] - ] -|#tc #td * #x * #y * * #Hcx #Hcy #Htd #Hstar #IH #He lapply (IH He) -IH * - #IH1 #IH2 % - [* [>Hcx #H destruct (H) | >Hcy #H destruct (H)] - |#ls #x' #y' #rs #ls0 #rs0 #Hnth_src #Hnth_dst - >Hnth_src in Hcx; whd in ⊢ (??%?→?); #H destruct (H) - >Hnth_dst in Hcy; whd in ⊢ (??%?→?); #H destruct (H) - >Hnth_src in Htd; >Hnth_dst -Hnth_src -Hnth_dst - cases rs - [(* the source tape is empty after the move *) - #Htd lapply (IH1 ?) - [%1 >Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] >nth_change_vec //] - #Hout (* whd in match (tape_move ???); *) %1 %{([])} %{rs0} % - [% [// | // ] - |whd in match (reverse ??); whd in match (reverse ??); - >Hout >Htd @eq_f2 // cases rs0 // - ] - |#c1 #tl1 cases rs0 - [(* the dst tape is empty after the move *) - #Htd lapply (IH1 ?) [%2 >Htd >nth_change_vec //] - #Hout (* whd in match (tape_move ???); *) %2 %{[ ]} %{(c1::tl1)} % - [% [// | // ] - |whd in match (reverse ??); whd in match (reverse ??); - >Hout >Htd @eq_f2 // - ] - |#c2 #tl2 whd in match (tape_move_mono ???); whd in match (tape_move_mono ???); - #Htd - cut (nth src (tape sig) td (niltape sig)=midtape sig (x::ls) c1 tl1) - [>Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] @nth_change_vec //] - #Hsrc_td - cut (nth dst (tape sig) td (niltape sig)=midtape sig (x::ls0) c2 tl2) - [>Htd @nth_change_vec //] - #Hdst_td cases (IH2 … Hsrc_td Hdst_td) -Hsrc_td -Hdst_td - [* #rs01 * #rs02 * * #H1 #H2 #H3 %1 - %{(c2::rs01)} %{rs02} % [% [@eq_f //|normalize @eq_f @H2]] - >Htd in H3; >change_vec_commute // >change_vec_change_vec - >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec - #H >reverse_cons >associative_append >associative_append @H - |* #rs11 * #rs12 * * #H1 #H2 #H3 %2 - %{(c1::rs11)} %{rs12} % [% [@eq_f //|normalize @eq_f @H2]] - >Htd in H3; >change_vec_commute // >change_vec_change_vec - >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec - #H >reverse_cons >associative_append >associative_append @H - ] - ] - ] +definition R_test_null_char_true ≝ λt1,t2. + current FSUnialpha t1 = Some ? null ∧ t1 = t2. + +definition R_test_null_char_false ≝ λt1,t2. + current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2. + +lemma sem_test_null_char : + test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false]. +#t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue +#Hfalse %{k} %{outc} % [ % +[ @Hloop +| #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull) + -Hcnull #H destruct (H) #Houtc1 % + [ @Hcurt1 | Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??)) + >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ] + #H destruct (H) + | Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc + cut (te = tc) + [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2) >change_vec_same // ] + -Hte1 -Hte2 #Hte + cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg) + [ lapply (eq_vec_change_vec ??????? (Htf2 ls c [ ] ?) Htf3) // + >Hte >Htc >nth_change_vec // ] -Htf1 -Htf2 -Htf3 #Htf + destruct (Htf Hte Htc Htb) + >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec + >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ] + >reverse_cons % + | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc + >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?); + #H destruct (H) @False_ind cases Hc /2/ ] + * #tf * * +| * #te * * * #Hcurtc #Hte1 #Hte2 + * #tf * whd in ⊢ (%→?); #Htf + * #tg * whd in ⊢ (%→%→?); #Htg #Htd + * #th * * * #Hth1 #Hth2 #Hth3 + whd in ⊢ (%→?); #Htb + #c #ls #Hta % #Hc + [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L // + >Hc normalize in ⊢ (%→?); * #H @False_ind /2/ + | cut (te = tc) + [ lapply (eq_vec_change_vec ??????? (sym_eq … Hte1) Hte2) + >change_vec_same // ] -Hte1 -Hte2 #Hte + cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg) + [ lapply (eq_vec_change_vec ??????? (Hth2 ls c [ ] ?) Hth3) // + >Htd >nth_change_vec_neq // >Htg >nth_change_vec // + >Htf >nth_change_vec_neq // >nth_change_vec // + >Hte >Htc >nth_change_vec // >Hta // ] -Hth1 -Hth2 -Hth3 #Hth + destruct (Hth Hte Hta Htb Htd Htg Htc Htf) + >change_vec_change_vec >change_vec_change_vec + >change_vec_commute // >change_vec_change_vec + >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec + >change_vec_commute // >change_vec_change_vec + >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //] + >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //] + >change_vec_commute [|@sym_not_eq //] + @eq_f3 // + [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??); + @eq_f2 // cases (nth obj ? ta (niltape ?)) + [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try % + cases rs0 // + | >reverse_cons >tape_move_mk_tape_R // #_ % % ] ] +] qed. - + +(* macchina che muove il nastro obj a destra o sinistra a seconda del valore + del current di prg, che codifica la direzione in cui ci muoviamo *) + +definition char_to_move ≝ λc.match c with + [ bit b ⇒ if b then R else L + | _ ⇒ N]. + +definition char_to_bit_option ≝ λc.match c with + [ bit b ⇒ Some ? (bit b) + | _ ⇒ None ?]. -lemma terminate_copy : ∀src,dst,sig,n,t. - src ≠ dst → src < S n → dst < S n → copy src dst sig n ↓ t. -#src #dst #sig #n #t #Hneq #Hsrc #Hdts -@(terminate_while … (sem_copy_step …)) // -<(change_vec_same … t src (niltape ?)) -cases (nth src (tape sig) t (niltape ?)) -[ % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct -|2,3: #a0 #al0 % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); #Hx destruct -| #ls #c #rs lapply c -c lapply ls -ls lapply t -t elim rs - [#t #ls #c % #t1 * #x * #y * * >nth_change_vec // normalize in ⊢ (%→?); - #H1 destruct (H1) #_ >change_vec_change_vec #Ht1 % - #t2 * #x0 * #y0 * * >Ht1 >nth_change_vec_neq [|@sym_not_eq //] - >nth_change_vec // normalize in ⊢ (%→?); #H destruct (H) - |#r0 #rs0 #IH #t #ls #c % #t1 * #x * #y * * >nth_change_vec // - normalize in ⊢ (%→?); #H destruct (H) #Hcur - >change_vec_change_vec >change_vec_commute // #Ht1 >Ht1 @IH +definition tape_move_obj : mTM FSUnialpha 2 ≝ + ifTM ?? + (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit false)) 2 prg) + (mmove obj FSUnialpha 2 L) + (ifTM ?? + (inject_TM ? (test_char ? (λc:FSUnialpha.c == bit true)) 2 prg) + (mmove obj FSUnialpha 2 R) + (nop ??) + tc_true) + tc_true. + +definition R_tape_move_obj' ≝ λt1,t2:Vector (tape FSUnialpha) 3. + (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit false) → + t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) L) obj) ∧ + (current ? (nth prg ? t1 (niltape ?)) = Some ? (bit true) → + t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) R) obj) ∧ + (current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit false) → + current ? (nth prg ? t1 (niltape ?)) ≠ Some ? (bit true) → + t2 = t1). + +lemma sem_tape_move_obj' : tape_move_obj ⊨ R_tape_move_obj'. +#ta cases (sem_if ?????????? + (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit false))) + (sem_move_multi ? 2 obj L ?) + (sem_if ?????????? + (acc_sem_inject ?????? prg ? (sem_test_char ? (λc:FSUnialpha.c == bit true))) + (sem_move_multi ? 2 obj R ?) + (sem_nop …)) ta) // +#i * #outc * #Hloop #HR %{i} %{outc} % [@Hloop] -i +cases HR -HR +[ * #tb * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htb1 #Htb2 + whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ % + [ >Hcurta_prg #H destruct (H) >(?:tb = ta) + [| lapply (eq_vec_change_vec ??????? Htb1 Htb2) + >change_vec_same // ] % + | >Hcurta_prg #H destruct (H) destruct (Hc) ] + | >Hcurta_prg >Hc * #H @False_ind /2/ ] +| * #tb * * * #Hnotfalse #Htb1 #Htb2 cut (tb = ta) + [ lapply (eq_vec_change_vec ??????? Htb1 Htb2) + >change_vec_same // ] -Htb1 -Htb2 #Htb destruct (Htb) * + [ * #tc * * * * #c * #Hcurta_prg #Hc lapply (\P Hc) -Hc #Hc #Htc1 #Htc2 + whd in ⊢ (%→%); #Houtc >Houtc -Houtc % [ % + [ >Hcurta_prg #H destruct (H) destruct (Hc) + | >Hcurta_prg #H destruct (H) >(?:tc = ta) + [| lapply (eq_vec_change_vec ??????? Htc1 Htc2) + >change_vec_same // ] % ] + | >Hcurta_prg >Hc #_ * #H @False_ind /2/ ] + | * #tc * * * #Hnottrue #Htc1 #Htc2 cut (tc = ta) + [ lapply (eq_vec_change_vec ??????? Htc1 Htc2) + >change_vec_same // ] -Htc1 -Htc2 + #Htc destruct (Htc) whd in ⊢ (%→?); #Houtc % [ % + [ #Hcurta_prg lapply (\Pf (Hnotfalse ? Hcurta_prg)) * #H @False_ind /2/ + | #Hcurta_prg lapply (\Pf (Hnottrue ? Hcurta_prg)) * #H @False_ind /2/ ] + | #_ #_ @Houtc ] ] ] qed. -lemma sem_copy : ∀src,dst,sig,n. - src ≠ dst → src < S n → dst < S n → - copy src dst sig n ⊨ R_copy src dst sig n. -#i #j #sig #n #Hneq #Hi #Hj @WRealize_to_Realize [/2/| @wsem_copy // ] +definition R_tape_move_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3. + ∀c. current ? (nth prg ? t1 (niltape ?)) = Some ? c → + t2 = change_vec ?? t1 (tape_move ? (nth obj ? t1 (niltape ?)) (char_to_move c)) obj. + +lemma sem_tape_move_obj : tape_move_obj ⊨ R_tape_move_obj. +@(Realize_to_Realize … sem_tape_move_obj') +#ta #tb * * #Htb1 #Htb2 #Htb3 * [ * +[ @Htb2 | @Htb1 ] +| #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???); + >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H) +| #Hcurta_prg change with (nth obj ? ta (niltape ?)) in match (tape_move ???); + >change_vec_same @Htb3 >Hcurta_prg % #H destruct (H) +] +qed. + +definition restart_tape ≝ λi. + inject_TM ? (move_to_end FSUnialpha L) 2 i · + mmove i FSUnialpha 2 R. + +definition unistep ≝ + match_m cfg prg FSUnialpha 2 · + restart_tape cfg · copy prg cfg FSUnialpha 2 · + cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg. + +(* +definition legal_tape ≝ λn,l,h,t. + ∃state,char,table. + nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) → + is_config n (bar::state@[char]) → + nth prg ? t1 (niltape ?) = midtape ? [ ] bar table → + bar::table = table_TM n l h → *) + +definition list_of_tape ≝ λsig,t. + left sig t@option_cons ? (current ? t) (right ? t). + +definition low_char' ≝ λc. + match c with + [ None ⇒ null + | Some b ⇒ if (is_bit b) then b else null + ]. + +lemma low_char_option : ∀s. + low_char' (option_map FinBool FSUnialpha bit s) = low_char s. +* // +qed. + +definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3. + ∀state,char,table. + (* cfg *) + nth cfg ? t1 (niltape ?) = midtape ? [ ] bar (state@[char]) → + is_config n (bar::state@[char]) → + (* prg *) + nth prg ? t1 (niltape ?) = midtape ? [ ] bar table → + bar::table = table_TM n l h → + (* obj *) + only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) → + let conf ≝ (bar::state@[char]) in + (∃ll,lr.bar::table = ll@conf@lr) → +(* + ∃nstate,nchar,m,t. tuple_encoding n h t = (conf@nstate@[nchar;m]) ∧ + mem ? t l ∧ *) + ∀nstate,nchar,m,t. + tuple_encoding n h t = (conf@nstate@[nchar;m])→ + mem ? t l → + let new_obj ≝ + tape_move_mono ? (nth obj ? t1 (niltape ?)) + 〈char_to_bit_option nchar,char_to_move m〉 in + let next_char ≝ low_char' (current ? new_obj) in + t2 = + change_vec ?? + (change_vec ?? t1 (midtape ? [ ] bar (nstate@[next_char])) cfg) + new_obj obj. + +definition tape_map ≝ λA,B:FinSet.λf:A→B.λt. + mk_tape B (map ?? f (left ? t)) + (option_map ?? f (current ? t)) + (map ?? f (right ? t)). + +lemma map_list_of_tape: ∀A,B,f,t. + list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t). +#A #B #f * // normalize // #ls #c #rs map_write >map_move % +qed. + +lemma map_move_mono: ∀t,cout,m. + tape_move_mono ? (tape_map FinBool ? bit t) + 〈char_to_bit_option (low_char cout), char_to_move (low_mv m)〉 + = tape_map ?? bit (tape_move_mono ? t 〈cout,m〉). +@map_action +qed. + +definition R_unistep_high ≝ λM:normalTM.λt1,t2. +∀c:nconfig (no_states M). + t1 = low_tapes M c → + t2 = low_tapes M (step ? M c). + +lemma R_unistep_equiv : ∀M,t1,t2. + R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 → + R_unistep_high M t1 t2. +#M #t1 #t2 #H whd whd in match (nconfig ?); #c #Ht1 +lapply (initial_bar ? (nhalt M) (graph_enum ?? (ntrans M)) (nTM_nog ?)) #Htable +(* tup = current tuple *) +cut (∃t.t = 〈〈cstate … c,current ? (ctape … c)〉, + ntrans M 〈cstate … c,current ? (ctape … c)〉〉) [% //] * #tup #Htup +(* tup is in the graph *) +cut (mem ? tup (graph_enum ?? (ntrans M))) + [@memb_to_mem >Htup @(graph_enum_complete … (ntrans M)) %] #Hingraph +(* tupe target = 〈qout,cout,m〉 *) +lapply (decomp_target ? (ntrans M 〈cstate … c,current ? (ctape … c)〉)) +* #qout * #cout * #m #Htg >Htg in Htup; #Htup +(* new config *) +cut (step FinBool M c = mk_config ?? qout (tape_move ? (tape_write ? (ctape … c) cout) m)) + [>(config_expand … c) whd in ⊢ (??%?); (* >Htg ?? why not?? *) + cut (trans ? M 〈cstate … c, current ? (ctape … c)〉 = 〈qout,cout,m〉) [Heq1 %] #Hstep +(* new state *) +cut (cstate ?? (step FinBool M c) = qout) [>Hstep %] #Hnew_state +(* new tape *) +cut (ctape ?? (step FinBool M c) = tape_move ? (tape_write ? (ctape … c) cout) m) + [>Hstep %] #Hnew_tape +lapply(H (bits_of_state ? (nhalt M) (cstate ?? c)) + (low_char (current ? (ctape ?? c))) + (tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M))) + ??????) +[Htable1 @eq_f Htup + whd in ⊢ (??%?); @eq_f >associative_append % +|>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??) + [#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]] +|@sym_eq @Htable +|>Ht1 % +|%{(bits_of_state ? (nhalt M) (cstate ?? c))} %{(low_char (current ? (ctape ?? c)))} + % [% [% [// | cases (current ??) normalize [|#b] % #Hd destruct (Hd)] + |>length_map whd in match (length ??); @eq_f //] + |//] +|>Ht1 >cfg_low_tapes //] -H #H +lapply(H (bits_of_state … (nhalt M) qout) (low_char … cout) + (low_mv … m) tup ? Hingraph) + [>Htup whd in ⊢ (??%?); @eq_f >associative_append %] -H +#Ht2 @(eq_vec ? 3 ?? (niltape ?) ?) >Ht2 #i #Hi +cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi + [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi + [cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi + [@False_ind /2/ + |>Hi >obj_low_tapes >nth_change_vec // + >Ht1 >obj_low_tapes >Hstep @map_action + ] + |>Hi >cfg_low_tapes >nth_change_vec_neq + [|% whd in ⊢ (??%?→?); #H destruct (H)] + >nth_change_vec // >Hnew_state @eq_f @eq_f >Hnew_tape + @eq_f2 [|2:%] >Ht1 >obj_low_tapes >map_move_mono >low_char_current % + ] + |(* program tapes do not change *) + >Hi >prg_low_tapes + >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)] + >nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)] + >Ht1 >prg_low_tapes // + ] +qed.