X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Fmatita%2Flib%2Fturing%2Fbasic_machines.ma;h=c1559702a59770c27dc68bbfcf98e2d50f6aaa46;hb=caf822cbe34e204e6d1b72e272373b561c1a565a;hp=82d4758c250c31eeac7545f6dd89179c2996d52c;hpb=53656d48b302c50e775159dc62e56cd7b1550676;p=helm.git diff --git a/matita/matita/lib/turing/basic_machines.ma b/matita/matita/lib/turing/basic_machines.ma index 82d4758c2..c1559702a 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. @@ -32,7 +32,35 @@ lemma sem_write : ∀alpha,c.Realize ? (write alpha c) (R_write alpha c). #alpha #c #t @(ex_intro … 2) @ex_intro [|% [% |#ls #c #rs #Ht >Ht % ] ] qed. - + +definition R_write_strong ≝ λalpha,c,t1,t2. + t2 = midtape alpha (left ? t1) c (right ? t1). + +lemma sem_write_strong : ∀alpha,c.Realize ? (write alpha c) (R_write_strong alpha c). +#alpha #c #t @(ex_intro … 2) @ex_intro + [|% [% |cases t normalize // ] ] +qed. + +(***************************** replace a with f a *****************************) + +definition writef ≝ λalpha,f. + mk_TM alpha write_states + (λp.let 〈q,a〉 ≝ p in + match pi1 … q with + [ O ⇒ 〈wr1,Some ? (f a),N〉 + | S _ ⇒ 〈wr1,None ?,N〉 ]) + wr0 (λx.x == wr1). + +definition R_writef ≝ λalpha,f,t1,t2. + ∀c. current ? t1 = c → + t2 = midtape alpha (left ? t1) (f c) (right ? t1). + +lemma sem_writef : ∀alpha,f. + writef alpha f ⊨ R_writef alpha f. +#alpha #f #t @(ex_intro … 2) @ex_intro + [|% [% |cases t normalize // ] ] +qed. + (******************** moves the head one step to the right ********************) definition move_states ≝ initN 2. @@ -43,10 +71,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 +108,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. @@ -106,6 +134,30 @@ lemma sem_move_l : #ls1 #c1 #rs1 #H destruct cases ls1 // ] ] ] qed. +(* a slightly different move machine. *) +definition smove_states ≝ initN 2. + +definition smove0 : smove_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 2 (refl …)). +definition smove1 : smove_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 2 (refl …)). + +definition trans_smove ≝ + λsig,D. + λp:smove_states × (option sig). + let 〈q,a〉 ≝ p in match (pi1 … q) with + [ O ⇒ 〈smove1,None sig, D〉 + | S _ ⇒ 〈smove1,None sig, N〉 ]. + +definition move ≝ + λsig,D.mk_TM sig smove_states (trans_smove sig D) smove0 (λq.q == smove1). + +definition Rmove ≝ + λalpha,D,t1,t2. t2 = tape_move alpha t1 D. + +lemma sem_move_single : + ∀alpha,D.move alpha D ⊨ Rmove alpha D. +#alpha #D #int %{2} %{(mk_config ? smove_states smove1 ?)} [| % % ] +qed. + (********************************* test char **********************************) (* the test_char machine ends up in two different states q1 and q2 wether or not @@ -125,11 +177,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 ≝ @@ -197,6 +249,27 @@ lemma test_char_inv : #sig #P #f #t #t0 #HPt * #_ // qed. +definition test_null ≝ λalpha.test_char alpha (λ_.true). + +definition R_test_null_true ≝ λalpha,t1,t2. + current alpha t1 ≠ None ? ∧ t1 = t2. + +definition R_test_null_false ≝ λalpha,t1,t2. + current alpha t1 = None ? ∧ t1 = t2. + +lemma sem_test_null : ∀alpha. + test_null alpha ⊨ [ tc_true : R_test_null_true alpha, R_test_null_false alpha]. +#alpha #t1 cases (sem_test_char alpha (λ_.true) t1) #k * #outc * * #Hloop #Htrue +#Hfalse %{k} %{outc} % [ % +[ @Hloop +| #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #_ #Houtc1 % + [ >Hcurt1 % #H destruct (H) |