From 77bf99a9ac05a61573d621d576e269870668f076 Mon Sep 17 00:00:00 2001 From: Andrea Asperti Date: Fri, 21 Dec 2012 12:39:18 +0000 Subject: [PATCH] Many changes --- matita/matita/lib/turing/basic_machines.ma | 42 +++--- matita/matita/lib/turing/if_machine.ma | 50 +++---- matita/matita/lib/turing/mono.ma | 86 ++++++----- matita/matita/lib/turing/universal/marks.ma | 135 ++++++++++++++++++ .../lib/turing/universal/match_machines.ma | 28 ++++ matita/matita/lib/turing/while_machine.ma | 2 +- 6 files changed, 261 insertions(+), 82 deletions(-) diff --git a/matita/matita/lib/turing/basic_machines.ma b/matita/matita/lib/turing/basic_machines.ma index a23576829..4f1977dd4 100644 --- a/matita/matita/lib/turing/basic_machines.ma +++ b/matita/matita/lib/turing/basic_machines.ma @@ -21,8 +21,8 @@ definition write ≝ λalpha,c. mk_TM alpha write_states (λp.let 〈q,a〉 ≝ p in match pi1 … q with - [ O ⇒ 〈wr1,Some ? 〈c,N〉〉 - | S _ ⇒ 〈wr1,None ?〉 ]) + [ O ⇒ 〈wr1,Some ? c,N〉 + | S _ ⇒ 〈wr1,None ?,N〉 ]) wr0 (λx.x == wr1). definition R_write ≝ λalpha,c,t1,t2. @@ -43,10 +43,10 @@ definition move_r ≝ λalpha:FinSet.mk_TM alpha move_states (λp.let 〈q,a〉 ≝ p in match a with - [ None ⇒ 〈move1,None ?〉 + [ None ⇒ 〈move1,None ?,N〉 | Some a' ⇒ match (pi1 … q) with - [ O ⇒ 〈move1,Some ? 〈a',R〉〉 - | S q ⇒ 〈move1,None ?〉 ] ]) + [ O ⇒ 〈move1,Some ? a',R〉 + | S q ⇒ 〈move1,None ?,N〉 ] ]) move0 (λq.q == move1). definition R_move_r ≝ λalpha,t1,t2. @@ -80,10 +80,10 @@ definition move_l ≝ λalpha:FinSet.mk_TM alpha move_states (λp.let 〈q,a〉 ≝ p in match a with - [ None ⇒ 〈move1,None ?〉 + [ None ⇒ 〈move1,None ?,N〉 | Some a' ⇒ match pi1 … q with - [ O ⇒ 〈move1,Some ? 〈a',L〉〉 - | S q ⇒ 〈move1,None ?〉 ] ]) + [ O ⇒ 〈move1,Some ? a',L〉 + | S q ⇒ 〈move1,None ?,N〉 ] ]) move0 (λq.q == move1). definition R_move_l ≝ λalpha,t1,t2. @@ -125,11 +125,11 @@ definition test_char ≝ mk_TM alpha tc_states (λp.let 〈q,a〉 ≝ p in match a with - [ None ⇒ 〈tc_false, None ?〉 + [ None ⇒ 〈tc_false, None ?,N〉 | Some a' ⇒ match test a' with - [ true ⇒ 〈tc_true,None ?〉 - | false ⇒ 〈tc_false,None ?〉 ]]) + [ true ⇒ 〈tc_true,None ?,N〉 + | false ⇒ 〈tc_false,None ?,N〉 ]]) tc_start (λx.notb (x == tc_start)). definition Rtc_true ≝ @@ -234,15 +234,15 @@ definition swap_r ≝ let 〈q',b〉 ≝ q in let q' ≝ pi1 nat (λi.i<4) q' in match a with - [ None ⇒ 〈〈swap3,foo〉,None ?〉 (* if tape is empty then stop *) + [ None ⇒ 〈〈swap3,foo〉,None ?,N〉 (* if tape is empty then stop *) | Some a' ⇒ match q' with - [ O ⇒ (* q0 *) 〈〈swap1,a'〉,Some ? 〈a',R〉〉 (* save in register and move R *) + [ O ⇒ (* q0 *) 〈〈swap1,a'〉,Some ? a',R〉 (* save in register and move R *) | S q' ⇒ match q' with - [ O ⇒ (* q1 *) 〈〈swap2,a'〉,Some ? 〈b,L〉〉 (* swap with register and move L *) + [ O ⇒ (* q1 *) 〈〈swap2,a'〉,Some ? b,L〉 (* swap with register and move L *) | S q' ⇒ match q' with - [ O ⇒ (* q2 *) 〈〈swap3,foo〉,Some ? 〈b,N〉〉 (* copy from register and stay *) - | S q' ⇒ (* q3 *) 〈〈swap3,foo〉,None ?〉 (* final state *) + [ O ⇒ (* q2 *) 〈〈swap3,foo〉,Some ? b,N〉 (* copy from register and stay *) + | S q' ⇒ (* q3 *) 〈〈swap3,foo〉,None ?,N〉 (* final state *) ] ] ]]) @@ -283,15 +283,15 @@ definition swap_l ≝ let 〈q',b〉 ≝ q in let q' ≝ pi1 nat (λi.i<4) q' in match a with - [ None ⇒ 〈〈swap3,foo〉,None ?〉 (* if tape is empty then stop *) + [ None ⇒ 〈〈swap3,foo〉,None ?,N〉 (* if tape is empty then stop *) | Some a' ⇒ match q' with - [ O ⇒ (* q0 *) 〈〈swap1,a'〉,Some ? 〈a',L〉〉 (* save in register and move L *) + [ O ⇒ (* q0 *) 〈〈swap1,a'〉,Some ? a',L〉 (* save in register and move L *) | S q' ⇒ match q' with - [ O ⇒ (* q1 *) 〈〈swap2,a'〉,Some ? 〈b,R〉〉 (* swap with register and move R *) + [ O ⇒ (* q1 *) 〈〈swap2,a'〉,Some ? b,R〉 (* swap with register and move R *) | S q' ⇒ match q' with - [ O ⇒ (* q2 *) 〈〈swap3,foo〉,Some ? 〈b,N〉〉 (* copy from register and stay *) - | S q' ⇒ (* q3 *) 〈〈swap3,foo〉,None ?〉 (* final state *) + [ O ⇒ (* q2 *) 〈〈swap3,foo〉,Some ? b,N〉 (* copy from register and stay *) + | S q' ⇒ (* q3 *) 〈〈swap3,foo〉,None ?,N〉 (* final state *) ] ] ]]) diff --git a/matita/matita/lib/turing/if_machine.ma b/matita/matita/lib/turing/if_machine.ma index f778ff308..27e81f549 100644 --- a/matita/matita/lib/turing/if_machine.ma +++ b/matita/matita/lib/turing/if_machine.ma @@ -43,16 +43,16 @@ definition if_trans ≝ λsig. λM1,M2,M3 : TM sig. λq:states sig M1. match s with [ inl s1 ⇒ if halt sig M1 s1 then - if s1==q then 〈inr … (inl … (start sig M2)), None ?〉 - else 〈inr … (inr … (start sig M3)), None ?〉 - else let 〈news1,m〉 ≝ trans sig M1 〈s1,a〉 in - 〈inl … news1,m〉 + if s1==q then 〈inr … (inl … (start sig M2)), None ?,N〉 + else 〈inr … (inr … (start sig M3)), None ?,N〉 + else let 〈news1,newa,m〉 ≝ trans sig M1 〈s1,a〉 in + 〈inl … news1,newa,m〉 | inr s' ⇒ match s' with - [ inl s2 ⇒ let 〈news2,m〉 ≝ trans sig M2 〈s2,a〉 in - 〈inr … (inl … news2),m〉 - | inr s3 ⇒ let 〈news3,m〉 ≝ trans sig M3 〈s3,a〉 in - 〈inr … (inr … news3),m〉 + [ inl s2 ⇒ let 〈news2,newa,m〉 ≝ trans sig M2 〈s2,a〉 in + 〈inr … (inl … news2),newa,m〉 + | inr s3 ⇒ let 〈news3,newa,m〉 ≝ trans sig M3 〈s3,a〉 in + 〈inr … (inr … news3),newa,m〉 ] ]. @@ -69,27 +69,27 @@ definition ifTM ≝ λsig. λcondM,thenM,elseM : TM sig. | inr s3 ⇒ halt sig elseM s3 ]]). (****************************** lifting lemmas ********************************) -lemma trans_if_liftM1 : ∀sig,M1,M2,M3,acc,s,a,news,move. +lemma trans_if_liftM1 : ∀sig,M1,M2,M3,acc,s,a,news,newa,move. halt ? M1 s = false → - trans sig M1 〈s,a〉 = 〈news,move〉 → - trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inl … news,move〉. -#sig * #Q1 #T1 #init1 #halt1 #M2 #M3 #acc #s #a #news #move + trans sig M1 〈s,a〉 = 〈news,newa,move〉 → + trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inl … news,newa,move〉. +#sig * #Q1 #T1 #init1 #halt1 #M2 #M3 #acc #s #a #news #newa #move #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans % qed. -lemma trans_if_liftM2 : ∀sig,M1,M2,M3,acc,s,a,news,move. +lemma trans_if_liftM2 : ∀sig,M1,M2,M3,acc,s,a,news,newa,move. halt ? M2 s = false → - trans sig M2 〈s,a〉 = 〈news,move〉 → - trans sig (ifTM sig M1 M2 M3 acc) 〈inr … (inl … s),a〉 = 〈inr… (inl … news),move〉. -#sig #M1 * #Q2 #T2 #init2 #halt2 #M3 #acc #s #a #news #move + trans sig M2 〈s,a〉 = 〈news,newa,move〉 → + trans sig (ifTM sig M1 M2 M3 acc) 〈inr … (inl … s),a〉 = 〈inr… (inl … news),newa,move〉. +#sig #M1 * #Q2 #T2 #init2 #halt2 #M3 #acc #s #a #news #newa #move #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans % qed. -lemma trans_if_liftM3 : ∀sig,M1,M2,M3,acc,s,a,news,move. +lemma trans_if_liftM3 : ∀sig,M1,M2,M3,acc,s,a,news,newa,move. halt ? M3 s = false → - trans sig M3 〈s,a〉 = 〈news,move〉 → - trans sig (ifTM sig M1 M2 M3 acc) 〈inr … (inr … s),a〉 = 〈inr… (inr … news),move〉. -#sig #M1 * #Q2 #T2 #init2 #halt2 #M3 #acc #s #a #news #move + trans sig M3 〈s,a〉 = 〈news,newa,move〉 → + trans sig (ifTM sig M1 M2 M3 acc) 〈inr … (inr … s),a〉 = 〈inr… (inr … news),newa,move〉. +#sig #M1 * #Q2 #T2 #init2 #halt2 #M3 #acc #s #a #news #newa #move #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans % qed. @@ -100,7 +100,7 @@ lemma step_if_liftM1 : ∀sig,M1,M2,M3,acc,c0. #sig #M1 #M2 #M3 #acc * #s #t lapply (refl ? (trans ?? 〈s,current sig t〉)) cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %); - #s0 #m0 cases t + * #s0 #a0 #m0 cases t [ #Heq #Hhalt | 2,3: #s1 #l1 #Heq #Hhalt |#ls #s1 #rs #Heq #Hhalt ] @@ -115,7 +115,7 @@ lemma step_if_liftM2 : ∀sig,M1,M2,M3,acc,c0. #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 #M3 #acc * #s #t lapply (refl ? (trans ?? 〈s,current sig t〉)) cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %); - #s0 #m0 cases t + * #s0 #a0 #m0 cases t [ #Heq #Hhalt | 2,3: #s1 #l1 #Heq #Hhalt |#ls #s1 #rs #Heq #Hhalt ] @@ -130,7 +130,7 @@ lemma step_if_liftM3 : ∀sig,M1,M2,M3,acc,c0. #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 #M3 #acc * #s #t lapply (refl ? (trans ?? 〈s,current sig t〉)) cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %); - #s0 #m0 cases t + * #s0 #a0 #m0 cases t [ #Heq #Hhalt | 2,3: #s1 #l1 #Heq #Hhalt |#ls #s1 #rs #Heq #Hhalt ] @@ -140,13 +140,13 @@ qed. lemma trans_if_M1true_acc : ∀sig,M1,M2,M3,acc,s,a. halt ? M1 s = true → s==acc = true → - trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inr … (inl … (start ? M2)),None ?〉. + trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inr … (inl … (start ? M2)),None ?,N〉. #sig #M1 #M2 #M3 #acc #s #a #Hhalt #Hacc whd in ⊢ (??%?); >Hhalt >Hacc % qed. lemma trans_if_M1true_notacc : ∀sig,M1,M2,M3,acc,s,a. halt ? M1 s = true → s==acc = false → - trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inr … (inr … (start ? M3)),None ?〉. + trans sig (ifTM sig M1 M2 M3 acc) 〈inl … s,a〉 = 〈inr … (inr … (start ? M3)),None ?,N〉. #sig #M1 #M2 #M3 #acc #s #a #Hhalt #Hacc whd in ⊢ (??%?); >Hhalt >Hacc % qed. diff --git a/matita/matita/lib/turing/mono.ma b/matita/matita/lib/turing/mono.ma index d5fc9a187..39ecff800 100644 --- a/matita/matita/lib/turing/mono.ma +++ b/matita/matita/lib/turing/mono.ma @@ -67,31 +67,47 @@ inductive move : Type[0] ≝ record TM (sig:FinSet): Type[1] ≝ { states : FinSet; - trans : states × (option sig) → states × (option (sig × move)); + trans : states × (option sig) → states × (option sig) × move; start: states; halt : states → bool }. -definition tape_move_left ≝ λsig:FinSet.λlt:list sig.λc:sig.λrt:list sig. - match lt with - [ nil ⇒ leftof sig c rt - | cons c0 lt0 ⇒ midtape sig lt0 c0 (c::rt) ]. +definition tape_move_left ≝ λsig:FinSet.λt:tape sig. + match t with + [ niltape ⇒ niltape sig + | leftof _ _ ⇒ t + | rightof a ls ⇒ midtape sig ls a [ ] + | midtape ls a rs ⇒ + match ls with + [ nil ⇒ leftof sig a rs + | cons a0 ls0 ⇒ midtape sig ls0 a0 (a::rs) + ] + ]. + +definition tape_move_right ≝ λsig:FinSet.λt:tape sig. + match t with + [ niltape ⇒ niltape sig + | rightof _ _ ⇒ t + | leftof a rs ⇒ midtape sig [ ] a rs + | midtape ls a rs ⇒ + match rs with + [ nil ⇒ rightof sig a ls + | cons a0 rs0 ⇒ midtape sig (a::ls) a0 rs0 + ] + ]. -definition tape_move_right ≝ λsig:FinSet.λlt:list sig.λc:sig.λrt:list sig. - match rt with - [ nil ⇒ rightof sig c lt - | cons c0 rt0 ⇒ midtape sig (c::lt) c0 rt0 ]. +definition tape_write ≝ λsig.λt: tape sig.λs:option sig. + match s with + [ None ⇒ t + | Some s0 ⇒ midtape ? (left ? t) s0 (right ? t) + ]. -definition tape_move ≝ λsig.λt: tape sig.λm:option (sig × move). +definition tape_move ≝ λsig.λt: tape sig.λm:move. match m with - [ None ⇒ t - | Some m' ⇒ - let 〈s,m1〉 ≝ m' in - match m1 with - [ R ⇒ tape_move_right ? (left ? t) s (right ? t) - | L ⇒ tape_move_left ? (left ? t) s (right ? t) - | N ⇒ midtape ? (left ? t) s (right ? t) - ] ]. + [ R ⇒ tape_move_right ? t + | L ⇒ tape_move_left ? t + | N ⇒ t + ]. record config (sig,states:FinSet): Type[0] ≝ { cstate : states; @@ -111,8 +127,8 @@ qed. definition step ≝ λsig.λM:TM sig.λc:config sig (states sig M). let current_char ≝ current ? (ctape ?? c) in - let 〈news,mv〉 ≝ trans sig M 〈cstate ?? c,current_char〉 in - mk_config ?? news (tape_move sig (ctape ?? c) mv). + let 〈news,a,mv〉 ≝ trans sig M 〈cstate ?? c,current_char〉 in + mk_config ?? news (tape_move sig (tape_write ? (ctape ?? c) a) mv). (******************************** loop ****************************************) let rec loop (A:Type[0]) n (f:A→A) p a on n ≝ @@ -367,7 +383,7 @@ definition start_nop : initN 1 ≝ mk_Sig ?? 0 (le_n … 1). definition nop ≝ λalpha:FinSet.mk_TM alpha nop_states - (λp.let 〈q,a〉 ≝ p in 〈q,None ?〉) + (λp.let 〈q,a〉 ≝ p in 〈q,None ?,N〉) start_nop (λ_.true). definition R_nop ≝ λalpha.λt1,t2:tape alpha.t2 = t1. @@ -390,9 +406,9 @@ definition seq_trans ≝ λsig. λM1,M2 : TM sig. λp. let 〈s,a〉 ≝ p in match s with [ inl s1 ⇒ - if halt sig M1 s1 then 〈inr … (start sig M2), None ?〉 - else let 〈news1,m〉 ≝ trans sig M1 〈s1,a〉 in 〈inl … news1,m〉 - | inr s2 ⇒ let 〈news2,m〉 ≝ trans sig M2 〈s2,a〉 in 〈inr … news2,m〉 + if halt sig M1 s1 then 〈inr … (start sig M2), None ?,N〉 + else let 〈news1,newa,m〉 ≝ trans sig M1 〈s1,a〉 in 〈inl … news1,newa,m〉 + | inr s2 ⇒ let 〈news2,newa,m〉 ≝ trans sig M2 〈s2,a〉 in 〈inr … news2,newa,m〉 ]. definition seq ≝ λsig. λM1,M2 : TM sig. @@ -432,19 +448,19 @@ lemma p_halt_liftL : ∀sig,S1,S2,halt,c. #sig #S1 #S2 #halt #c cases c #s #t % qed. -lemma trans_seq_liftL : ∀sig,M1,M2,s,a,news,move. +lemma trans_seq_liftL : ∀sig,M1,M2,s,a,news,newa,move. halt ? M1 s = false → - trans sig M1 〈s,a〉 = 〈news,move〉 → - trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inl … news,move〉. -#sig (*#M1*) * #Q1 #T1 #init1 #halt1 #M2 #s #a #news #move + trans sig M1 〈s,a〉 = 〈news,newa,move〉 → + trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inl … news,newa,move〉. +#sig (*#M1*) * #Q1 #T1 #init1 #halt1 #M2 #s #a #news #newa #move #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans % qed. -lemma trans_seq_liftR : ∀sig,M1,M2,s,a,news,move. +lemma trans_seq_liftR : ∀sig,M1,M2,s,a,news,newa,move. halt ? M2 s = false → - trans sig M2 〈s,a〉 = 〈news,move〉 → - trans sig (seq sig M1 M2) 〈inr … s,a〉 = 〈inr … news,move〉. -#sig #M1 * #Q2 #T2 #init2 #halt2 #s #a #news #move + trans sig M2 〈s,a〉 = 〈news,newa,move〉 → + trans sig (seq sig M1 M2) 〈inr … s,a〉 = 〈inr … news,newa,move〉. +#sig #M1 * #Q2 #T2 #init2 #halt2 #s #a #news #newa #move #Hhalt #Htrans whd in ⊢ (??%?); >Hhalt >Htrans % qed. @@ -455,7 +471,7 @@ lemma step_seq_liftR : ∀sig,M1,M2,c0. #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 * #s #t lapply (refl ? (trans ?? 〈s,current sig t〉)) cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %); - #s0 #m0 cases t + * #s0 #a0 #m0 cases t [ #Heq #Hhalt | 2,3: #s1 #l1 #Heq #Hhalt |#ls #s1 #rs #Heq #Hhalt ] @@ -470,7 +486,7 @@ lemma step_seq_liftL : ∀sig,M1,M2,c0. #sig #M1 (* * #Q1 #T1 #init1 #halt1 *) #M2 * #s #t lapply (refl ? (trans ?? 〈s,current sig t〉)) cases (trans ?? 〈s,current sig t〉) in ⊢ (???% → %); - #s0 #m0 cases t + * #s0 #a0 #m0 cases t [ #Heq #Hhalt | 2,3: #s1 #l1 #Heq #Hhalt |#ls #s1 #rs #Heq #Hhalt ] @@ -480,7 +496,7 @@ qed. lemma trans_liftL_true : ∀sig,M1,M2,s,a. halt ? M1 s = true → - trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inr … (start ? M2),None ?〉. + trans sig (seq sig M1 M2) 〈inl … s,a〉 = 〈inr … (start ? M2),None ?,N〉. #sig #M1 #M2 #s #a #Hhalt whd in ⊢ (??%?); >Hhalt % qed. diff --git a/matita/matita/lib/turing/universal/marks.ma b/matita/matita/lib/turing/universal/marks.ma index 8f1e1f129..ad67b4abb 100644 --- a/matita/matita/lib/turing/universal/marks.ma +++ b/matita/matita/lib/turing/universal/marks.ma @@ -1386,3 +1386,138 @@ qed. lemma sem_compare : Realize ? compare R_compare. /2/ qed. + +(* new *) +definition R_compare_new := + λt1,t2. + ∀ls,c,rs.t1 = midtape (FinProd … FSUnialpha FinBool) ls c rs → + (∀c'.bit_or_null c' = false → c = 〈c',true〉 → t2 = midtape ? ls 〈c',false〉 rs) ∧ + (∀c'. c = 〈c',false〉 → t2 = t1) ∧ +(* forse manca il caso no marks in rs *) + ∀b,b0,bs,b0s,comma,l1,l2. + |bs| = |b0s| → + (∀c.memb (FinProd … FSUnialpha FinBool) c bs = true → bit_or_null (\fst c) = true) → + (∀c.memb ? c bs = true → is_marked ? c = false) → + (∀c.memb ? c b0s = true → is_marked ? c = false) → + (∀c.memb ? c l1 = true → is_marked ? c = false) → + c = 〈b,true〉 → bit_or_null b = true → + rs = bs@〈grid,false〉::l1@〈b0,true〉::b0s@〈comma,false〉::l2 → + (〈b,true〉::bs = 〈b0,true〉::b0s ∧ + t2 = midtape ? (reverse ? bs@〈b,false〉::ls) + 〈grid,false〉 (l1@〈b0,false〉::b0s@〈comma,true〉::l2)) ∨ + (∃la,c',d',lb,lc.c' ≠ d' ∧ + 〈b,false〉::bs = la@〈c',false〉::lb ∧ + 〈b0,false〉::b0s = la@〈d',false〉::lc ∧ + t2 = midtape (FinProd … FSUnialpha FinBool) (reverse ? la@ + reverse ? l1@ + 〈grid,false〉:: + reverse ? lb@ + 〈c',true〉:: + reverse ? la@ls) + 〈d',false〉 (lc@〈comma,false〉::l2)). + +lemma wsem_compare_new : WRealize ? compare R_compare_new. +#t #i #outc #Hloop +lapply (sem_while ?????? sem_comp_step t i outc Hloop) [%] +-Hloop * #t1 * #Hstar @(star_ind_l ??????? Hstar) +[ #tapea whd in ⊢ (%→?); #Rfalse #ls #c #rs #Htapea % + [ % + [ #c' #Hc' #Hc lapply (Rfalse … Htapea) -Rfalse * >Hc + whd in ⊢ (??%?→?); #Hfalse destruct (Hfalse) + | #c' #Hc lapply (Rfalse … Htapea) -Rfalse * #_ + #Htrue @Htrue ] + | #b #b0 #bs #b0s #l1 #l2 #Hlen #Hbs1 #Hb0s1 #Hbs2 #Hb0s2 #Hl1 #Hc + cases (Rfalse … Htapea) -Rfalse >Hc whd in ⊢ (??%?→?);#Hfalse destruct (Hfalse) + ] +| #tapea #tapeb #tapec #Hleft #Hright #IH #Htapec lapply (IH Htapec) -Htapec -IH #IH + whd in Hleft; #ls #c #rs #Htapea cases Hleft -Hleft + #ls0 * #c' * #rs0 * >Htapea #Hdes destruct (Hdes) * * + cases (true_or_false (bit_or_null c')) #Hc' + [2: #Htapeb lapply (Htapeb Hc') -Htapeb #Htapeb #_ #_ % + [%[#c1 #Hc1 #Heqc destruct (Heqc) + cases (IH … Htapeb) * #_ #H #_ Hc' #Hfalse @False_ind destruct (Hfalse) + ] + |#_ (* no marks in rs ??? *) #_ #Hleft % + [ % + [ #c'' #Hc'' #Heq destruct (Heq) >Hc'' in Hc'; #H destruct (H) + | #c0 #Hfalse destruct (Hfalse) + ] + |#b #b0 #bs #b0s #comma #l1 #l2 #Hlen #Hbs1 #Hbs2 #Hb0s2 #Hl1 + #Heq destruct (Heq) #_ >append_cons; (memb_single … memc1) %] + |@Hl1 @memc1 + ] + |* (* manca il caso in cui dopo una parte uguale il + secondo nastro finisca ... ???? *) + #_ cases (true_or_false (b==b0)) #eqbb0 + [2: #_ #Htapeb %2 lapply (Htapeb … (\Pf eqbb0)) -Htapeb #Htapeb + cases (IH … Htapeb) * #_ #Hout #_ + @(ex_intro … []) @(ex_intro … b) @(ex_intro … b0) + @(ex_intro … bs) @(ex_intro … b0s) % + [%[%[@(\Pf eqbb0) | %] | %] + |>(Hout … (refl …)) -Hout >Htapeb @eq_f3 [2,3:%] + >reverse_append >reverse_append >associative_append + >associative_append % + ] + |lapply Hbs1 lapply Hbs2 lapply Hb0s2 lapply Hrs + -Hbs1 -Hbs2 -Hb0s2 -Hrs + @(list_cases2 … Hlen) + [#Hrs #_ #_ #_ >associative_append >associative_append #Htapeb #_ + lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb + cases (IH … Htapeb) -IH * #Hout #_ #_ %1 % + [>(\P eqbb0) % + |>(Hout grid (refl …) (refl …)) @eq_f + normalize >associative_append % + ] + |* #a1 #ba1 * #a2 #ba2 #tl1 #tl2 #HlenS #Hrs #Hb0s2 #Hbs2 #Hbs1 + cut (ba1 = false) [@(Hbs2 〈a1,ba1〉) @memb_hd] #Hba1 >Hba1 + >associative_append >associative_append #Htapeb #_ + lapply (Htapeb … (\P eqbb0) … (refl …) (refl …)) -Htapeb #Htapeb + cases (IH … Htapeb) -IH * #_ #_ + cut (ba2=false) [@(Hb0s2 〈a2,ba2〉) @memb_hd] #Hba2 >Hba2 + #IH cases(IH a1 a2 ??? (l1@[〈b0,false〉]) l2 HlenS ???? (refl …) ??) + [4:#x #memx @Hbs1 @memb_cons @memx + |5:#x #memx @Hbs2 @memb_cons @memx + |6:#x #memx @Hb0s2 @memb_cons @memx + |7:#x #memx cases (memb_append …memx) -memx #memx + [@Hl1 @memx | >(memb_single … memx) %] + |8:@(Hbs1 〈a1,ba1〉) @memb_hd + |9: >associative_append >associative_append % + |-IH -Hbs1 -Hbs2 -Hrs * + #Ha1a2 #Houtc %1 % + [>(\P eqbb0) @eq_f destruct (Ha1a2) % + |>Houtc @eq_f3 + [>reverse_cons >associative_append % + |% + |>associative_append % + ] + ] + |-IH -Hbs1 -Hbs2 -Hrs * + #la * #c' * #d' * #lb * #lc * * * + #Hcd #H1 #H2 #Houtc %2 + @(ex_intro … (〈b,false〉::la)) @(ex_intro … c') @(ex_intro … d') + @(ex_intro … lb) @(ex_intro … lc) % + [%[%[@Hcd | >H1 %] |>(\P eqbb0) >Hba2 >H2 %] + |>Houtc @eq_f3 + [>(\P eqbb0) >reverse_append >reverse_cons + >reverse_cons >associative_append >associative_append + >associative_append >associative_append % + |% + |% + ] + ] + ] + ] + ] + ] + ] + ] +] +qed. \ No newline at end of file diff --git a/matita/matita/lib/turing/universal/match_machines.ma b/matita/matita/lib/turing/universal/match_machines.ma index eef43f14a..6c7ccc923 100644 --- a/matita/matita/lib/turing/universal/match_machines.ma +++ b/matita/matita/lib/turing/universal/match_machines.ma @@ -287,6 +287,34 @@ definition match_tuple_step ≝ (ifTM ? (test_char ? (λc:STape.is_grid (\fst c))) (mark ?) (move_l ? · init_current) tc_true)) tc_true))) (nop ?) tc_true. + +definition R_match_tuple_step_true_new ≝ λt1,t2. + ∃ls,cur,rs.t1 = midtape STape ls cur rs \wedge + \fst cur ≠ grid ∧ + (∀ls0,c,l1,l2,c1,l3,l4,rs0,n. + only_bits_or_nulls l1 → no_marks l1 (* → no_grids l2 *) → + bit_or_null c = true → bit_or_null c1 = true → + only_bits_or_nulls l3 → S n = |l1| → |l1| = |l3| → + table_TM (S n) (l2@〈c1,false〉::l3@〈comma,false〉::l4) → + ls = 〈grid,false〉::ls0 → cur = 〈c,true〉 → + rs = l1@〈grid,false〉::l2@〈c1,true〉::l3@〈comma,false〉::l4@〈grid,false〉::rs0 → + (* facciamo match *) + (〈c,false〉::l1 = 〈c1,false〉::l3 ∧ + t2 = midtape ? (reverse ? l1@〈c,false〉::〈grid,false〉::ls0) 〈grid,false〉 + (l2@〈c1,false〉::l3@〈comma,true〉::l4@〈grid,false〉::rs0)) + ∨ + (* non facciamo match e marchiamo la prossima tupla *) + (〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧ + ∃c2,l5,l6.l4 = l5@〈bar,false〉::〈c2,false〉::l6 ∧ + (* condizioni su l5 l6 l7 *) + t2 = midtape STape (〈grid,false〉::ls0) 〈c,true〉 + (l1@〈grid,false〉::l2@〈c1,false〉::l3@〈comma,false〉:: + l5@〈bar,false〉::〈c2,true〉::l6@〈grid,false〉::rs0)) + ∨ + (* non facciamo match e non c'è una prossima tupla: + non specifichiamo condizioni sul nastro di output, perché + non eseguiremo altre operazioni, quindi il suo formato non ci interessa *) + (〈c,false〉::l1 ≠ 〈c1,false〉::l3 ∧ no_bars l4 ∧ current ? t2 = Some ? 〈grid,true〉)). (* universal version definition R_match_tuple_step_true ≝ λt1,t2. diff --git a/matita/matita/lib/turing/while_machine.ma b/matita/matita/lib/turing/while_machine.ma index 6bde5396b..24e3cfd55 100644 --- a/matita/matita/lib/turing/while_machine.ma +++ b/matita/matita/lib/turing/while_machine.ma @@ -18,7 +18,7 @@ distinguished final state $q$ to the initial state. *) definition while_trans ≝ λsig. λM : TM sig. λq:states sig M. λp. let 〈s,a〉 ≝ p in - if s == q then 〈start ? M, None ?〉 + if s == q then 〈start ? M, None ?,N〉 else trans ? M p. definition whileTM ≝ λsig. λM : TM sig. λqacc: states ? M. -- 2.39.2