X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Fmatita%2Flib%2Fturing%2Fmulti_universal%2Funistep_aux.ma;h=5daeccb91554a4a8c5aa3b2749d230707ac68459;hb=53273ac4ac4e742f8767fc1f9ef0f279c0b80a1d;hp=7d0b63a3a9aeb259301ad45f1877fd8b6c9b06d6;hpb=46ce72f347ea8622dfaa01697de5a43b02dc5829;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 7d0b63a3a..5daeccb91 100644 --- a/matita/matita/lib/turing/multi_universal/unistep_aux.ma +++ b/matita/matita/lib/turing/multi_universal/unistep_aux.ma @@ -13,6 +13,7 @@ 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". (* @@ -59,7 +60,8 @@ definition obj_to_cfg ≝ mmove cfg FSUnialpha 2 L · (ifTM ?? (inject_TM ? (test_null ?) 2 obj) (copy_step obj cfg FSUnialpha 2 · - mmove cfg FSUnialpha 2 L) + 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 · @@ -70,7 +72,7 @@ definition R_obj_to_cfg ≝ λt1,t2:Vector (tape FSUnialpha) 3. 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 ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg) ∧ + (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))) @@ -107,7 +109,8 @@ lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg. (sem_if ?????????? (sem_test_null_multi ?? obj ?) (sem_seq ?????? (accRealize_to_Realize … (sem_copy_step …)) - (sem_move_multi ? 2 cfg L ?)) + (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 ?)))) // @@ -116,16 +119,28 @@ lemma sem_obj_to_cfg : obj_to_cfg ⊨ R_obj_to_cfg. #td * * [ * #te * * #Hcurtc #Hte * destruct (Hte) #te * * - [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte #Htd - * #tf * * * whd in ⊢ (%→%→%→%→?); #Htf1 #Htf2 #Htf3 #Htb + [ 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 (tf = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg) - [@daemon] -Htf1 -Htf2 -Htf3 #Htf destruct (Htf Hte Htd Htc Htb) - >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec - >nth_change_vec // >tape_move_mk_tape_R - @daemon + cut (tg = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg) + [@daemon] -Htg1 -Htg2 -Htg3 #Htg destruct (Htg Htf Hte Htd Htc Htb) + >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 Hcurtc1; [|@sym_not_eq //] >Hta2 + normalize in ⊢ (%→?); #H destruct (H) % + ] | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //] >Hta2 #H destruct (H) ] @@ -175,12 +190,67 @@ lemma sem_test_null_char : | 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_char: + ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n → + copy_char src dst sig n ⊨ R_copy_char src dst sig n. +#src #dst #sig #n #Hneq #Hsrc #Hdst #int +%{2} % [| % [ % | whd >copy_char_q0_q1 // ]] +qed. + definition cfg_to_obj ≝ mmove cfg FSUnialpha 2 L · (ifTM ?? (inject_TM ? test_null_char 2 cfg) (nop ? 2) - (copy_step cfg obj FSUnialpha 2 · - mmove cfg FSUnialpha 2 L) + (copy_char cfg obj FSUnialpha 2 · + mmove cfg FSUnialpha 2 L · + mmove obj FSUnialpha 2 L) tc_true) · inject_TM ? (move_to_end FSUnialpha L) 2 cfg · mmove cfg FSUnialpha 2 R. @@ -197,64 +267,293 @@ definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3. (change_vec ?? t1 (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj) (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg). + +lemma tape_move_mk_tape_L : + ∀sig,ls,c,rs. + (c = None ? → ls = [ ] ∨ rs = [ ]) → + tape_move ? (mk_tape sig ls c rs) L = + mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs). +#sig * [ * [ * | #c * ] | #l0 #ls0 * [ * +[| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ] +normalize // +qed. -axiom sem_cfg_to_obj : 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 ?????? (accRealize_to_Realize … (sem_copy_step …)) - (sem_move_multi ? 2 cfg L ?)) - (sem_inject ???? cfg ? (sem_write FSUnialpha null))) - (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?)) - (sem_move_multi ? 2 cfg R ?)))) // +lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj. +@(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?) + (sem_seq ?????? + (sem_if ?????????? + (acc_sem_inject ?????? cfg ? sem_test_null_char) + (sem_nop …) + (sem_seq ?????? (sem_copy_char …) + (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?)))) + (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?)) + (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //] #ta #tb * #tc * whd in ⊢ (%→?); #Htc * #td * * -[ * #te * * #Hcurtc #Hte - * destruct (Hte) #te * * - [ whd in ⊢ (%→%→?); * #x * #y * * -Hcurtc #Hcurtc1 #Hcurtc2 #Hte #Htd - * #tf * * * whd in ⊢ (%→%→%→%→?); #Htf1 #Htf2 #Htf3 #Htb - #c #ls #Hta1 % - [ #lso #x0 #rso #Hta2 >Hta1 in Htc; >eq_mk_tape_rightof - whd in match (tape_move ???); #Htc - cut (tf = change_vec ?? tc (mk_tape ? [ ] (None ?) (reverse ? ls@[x])) cfg) - [@daemon] -Htf1 -Htf2 -Htf3 #Htf destruct (Htf Hte Htd Htc Htb) - >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec - >nth_change_vec // >tape_move_mk_tape_R - @daemon - | #Hta2 >Htc in Hcurtc1; >nth_change_vec_neq [| @sym_not_eq //] - >Hta2 #H destruct (H) - ] - | * #Hcurtc0 #Hte #_ #_ #c #ls #Hta1 >Hta1 in Htc; >eq_mk_tape_rightof - whd in match (tape_move ???); #Htc >Htc in Hcurtc0; * - [ >Htc in Hcurtc; >nth_change_vec_neq [|@sym_not_eq //] - #Hcurtc #Hcurtc0 >Hcurtc0 in Hcurtc; * #H @False_ind @H % - | >nth_change_vec // normalize in ⊢ (%→?); #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) - [@daemon] -Htd1 -Htd2 #Htd - -Htf1 cut (tf = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[null])) cfg) - [@daemon] -Htf2 -Htf3 #Htf destruct (Htf Htd Htc Htb) +[ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd) + * #tf * * * #Htf1 #Htf2 #Htf3 + whd in ⊢ (%→?); #Htb + #c #ls #Hta % + [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc + cut (te = tc) [@daemon] -Hte1 -Hte2 #Hte + cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg) + [@daemon] -Htf1 -Htf2 -Htf3 #Htf + destruct (Htf Hte 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/ ] + >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) [ @daemon ] -Hte1 -Hte2 #Hte + cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg) + [@daemon] -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 *) -axiom tape_move_obj : mTM FSUnialpha 2. +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 ?]. + +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 restart_tape ≝ λi. + inject_TM ? (move_to_end FSUnialpha L) 2 i · + mmove i FSUnialpha 2 R. definition unistep ≝ - obj_to_cfg · match_m cfg prg FSUnialpha 2 · copy prg cfg FSUnialpha 2 · - cfg_to_obj · tape_move_obj. \ No newline at end of file + 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.λc:nconfig (no_states M).λt1,t2. + t1 = low_tapes M c → + t2 = low_tapes M (step ? M c). + +lemma R_unistep_equiv : ∀M,c,t1,t2. + R_unistep (no_states M) (graph_enum ?? (ntrans M)) (nhalt M) t1 t2 → + R_unistep_high M c t1 t2. +#M #c #t1 #t2 #H #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 >Ht2 @(eq_vec ? 3 … (niltape ?)) #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. + + + + \ No newline at end of file