X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=weblib%2Ftutorial%2Fchapter9.ma;h=ba759d47cf34a8c20c42c5db01f8d8e42f86cdfc;hb=ccf5878f2a2ec7f952f140e162391708a740517b;hp=b3f46ae04282a96988fde5cd17d334c7fa48234c;hpb=cee37c7a5aa40d1b6d978a5e1aa3a2d91cdb7a63;p=helm.git diff --git a/weblib/tutorial/chapter9.ma b/weblib/tutorial/chapter9.ma index b3f46ae04..ba759d47c 100644 --- a/weblib/tutorial/chapter9.ma +++ b/weblib/tutorial/chapter9.ma @@ -11,30 +11,30 @@ lifted operators of the previous section: include "tutorial/chapter8.ma". -let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝ +let rec move (S: a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a) (x:S) (E: a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S) on E : a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S ≝ match E with - [ pz ⇒ 〈 `∅, false 〉 - | pe ⇒ 〈 ϵ, false 〉 - | ps y ⇒ 〈 `y, false 〉 - | pp y ⇒ 〈 `y, x == y 〉 - | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2) - | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2) - | pk e ⇒ (move ? x e)^⊛ ]. + [ pz ⇒ 〈a href="cic:/matita/tutorial/chapter7/pitem.con(0,1,1)"pz/a S, a href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a a title="Pair construction" href="cic:/fakeuri.def(1)"〉/a + | pe ⇒ a title="Pair construction" href="cic:/fakeuri.def(1)"〈/a a title="pitem epsilon" href="cic:/fakeuri.def(1)"ϵ/a, a href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a a title="Pair construction" href="cic:/fakeuri.def(1)"〉/a + | ps y ⇒ a title="Pair construction" href="cic:/fakeuri.def(1)"〈/a a title="pitem ps" href="cic:/fakeuri.def(1)"`/ay, a href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a a title="Pair construction" href="cic:/fakeuri.def(1)"〉/a + | pp y ⇒ a title="Pair construction" href="cic:/fakeuri.def(1)"〈/a a title="pitem ps" href="cic:/fakeuri.def(1)"`/ay, x a title="eqb" href="cic:/fakeuri.def(1)"=/aa title="eqb" href="cic:/fakeuri.def(1)"=/a y a title="Pair construction" href="cic:/fakeuri.def(1)"〉/a + | po e1 e2 ⇒ (move ? x e1) a title="oplus" href="cic:/fakeuri.def(1)"⊕/a (move ? x e2) + | pc e1 e2 ⇒ (move ? x e1) a title="lifted cat" href="cic:/fakeuri.def(1)"⊙/a (move ? x e2) + | pk e ⇒ (move ? x e)a title="lk" href="cic:/fakeuri.def(1)"^/aa title="lk" href="cic:/fakeuri.def(1)"⊛/a ]. -lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S. - move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2). +lemma move_plus: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀x:S.∀i1,i2:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S. + a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S x (i1 a title="pitem or" href="cic:/fakeuri.def(1)"+/a i2) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i1) a title="oplus" href="cic:/fakeuri.def(1)"⊕/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i2). // qed. -lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S. - move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2). +lemma move_cat: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀x:S.∀i1,i2:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S. + a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S x (i1 a title="pitem cat" href="cic:/fakeuri.def(1)"·/a i2) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i1) a title="lifted cat" href="cic:/fakeuri.def(1)"⊙/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i2). // qed. -lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S. - move S x i^* = (move ? x i)^⊛. +lemma move_star: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀x:S.∀i:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S. + a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S x ia title="pitem star" href="cic:/fakeuri.def(1)"^/aa title="pitem star" href="cic:/fakeuri.def(1)"*/a a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i)a title="lk" href="cic:/fakeuri.def(1)"^/aa title="lk" href="cic:/fakeuri.def(1)"⊛/a. // qed. (* -Example. Let us consider the item +bExample/b. Let us consider the item (•a + ϵ)((•b)*•a + •b)b @@ -43,147 +43,208 @@ For a, we have two possible positions (all other points gets erased); the innerm point stops in front of the final b, while the other one broadcast inside (b^*a + b)b, so - move((•a + ϵ)((•b)*•a + •b)b,a) = 〈(a + ϵ)((•b)^*•a + •b)•b, false〉 + move((•a + ϵ)((•b)*•a + •b)b,a) = 〈(a + ϵ)((•b)^*•a + •b)•b, false〉 For b, we have two positions too. The innermost point stops in front of the final b too, while the other point reaches the end of b* and must go back through b*a: - move((•a + ϵ)((•b)*•a + •b)b ,b) = 〈(a + ϵ)((•b)*•a + b)•b, false〉 + move((•a + ϵ)((•b)*•a + •b)b ,b) = 〈(a + ϵ)((•b)*•a + b)•b, false〉 *) -definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e). +definition pmove ≝ λS:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.λx:S.λe:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a e). -lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b. - pmove ? x 〈i,b〉 = move ? x i. +lemma pmove_def : ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀x:S.∀i:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S.∀b. + a href="cic:/matita/tutorial/chapter9/pmove.def(7)"pmove/a ? x a title="Pair construction" href="cic:/fakeuri.def(1)"〈/ai,ba title="Pair construction" href="cic:/fakeuri.def(1)"〉/a a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? x i. // qed. -lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b. - a::l1 = b::l2 → a = b. +lemma eq_to_eq_hd: ∀A.∀l1,l2:a href="cic:/matita/basics/list/list.ind(1,0,1)"list/a A.∀a,b. + aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/al1 a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a ba title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/al2 → a a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a b. #A #l1 #l2 #a #b #H destruct // qed. -lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S. - |\fst (move ? a i)| = |i|. +(* Obviously, a move does not change the carrier of the item, as one can easily +prove by induction on the item. *) + +lemma same_kernel: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀a:S.∀i:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S. + a title="forget" href="cic:/fakeuri.def(1)"|/aa title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? a i)a title="forget" href="cic:/fakeuri.def(1)"|/a a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a title="forget" href="cic:/fakeuri.def(1)"|/aia title="forget" href="cic:/fakeuri.def(1)"|/a. #S #a #i elim i // - [#i1 #i2 #H1 #H2 >move_cat >erase_odot // - |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); // + [#i1 #i2 #H1 #H2 >a href="cic:/matita/tutorial/chapter9/move_cat.def(7)"move_cat/a >a href="cic:/matita/tutorial/chapter8/erase_odot.def(7)"erase_odot/a // + |#i1 #i2 #H1 #H2 >a href="cic:/matita/tutorial/chapter9/move_plus.def(7)"move_plus/a whd in ⊢ (??%%); // ] qed. +(* Here is our first, major result, stating the correctness of the +move operation. The proof is a simple induction on i. *) + theorem move_ok: - ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S. - \sem{move ? a i} w ↔ \sem{i} (a::w). + ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀a:S.∀i:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S.∀w: a href="cic:/matita/tutorial/chapter6/word.def(3)"word/a S. + a title="in_prl" href="cic:/fakeuri.def(1)"\sem/a{a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a ? a ia title="in_prl" href="cic:/fakeuri.def(1)"}/a w a title="iff" href="cic:/fakeuri.def(1)"↔/a a title="in_pl" href="cic:/fakeuri.def(1)"\sem/a{ia title="in_pl" href="cic:/fakeuri.def(1)"}/a (aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aw). #S #a #i elim i - [normalize /2/ - |normalize /2/ - |normalize /2/ - |normalize #x #w cases (true_or_false (a==x)) #H >H normalize - [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/] - |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //] + [normalize /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/And.con(0,1,2)"conj/a/span/span/ + |normalize /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/And.con(0,1,2)"conj/a/span/span/ + |normalize /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/And.con(0,1,2)"conj/a/span/span/ + |normalize #x #w cases (a href="cic:/matita/basics/bool/true_or_false.def(1)"true_or_false/a (aa title="eqb" href="cic:/fakeuri.def(1)"=/aa title="eqb" href="cic:/fakeuri.def(1)"=/ax)) #H >H normalize + [>(\P H) % [* // #bot @a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a //| #H1 destruct /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/] + |% [@a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a |#H1 cases (\Pf H) #H2 @H2 destruct //] ] - |#i1 #i2 #HI1 #HI2 #w >move_cat - @iff_trans[|@sem_odot] >same_kernel >sem_cat_w - @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r - @iff_trans[||@iff_sym @deriv_middot //] - @cat_ext_l @HI1 - |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w - @iff_trans[|@sem_oplus] - @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //] - |#i1 #HI1 #w >move_star - @iff_trans[|@sem_ostar] >same_kernel >sem_star_w - @iff_trans[||@iff_sym @deriv_middot //] - @cat_ext_l @HI1 + |#i1 #i2 #HI1 #HI2 #w >a href="cic:/matita/tutorial/chapter9/move_cat.def(7)"move_cat/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[|@a href="cic:/matita/tutorial/chapter8/sem_odot.def(13)"sem_odot/a] >a href="cic:/matita/tutorial/chapter9/same_kernel.def(8)"same_kernel/a >a href="cic:/matita/tutorial/chapter7/sem_cat_w.def(8)"sem_cat_w/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[||@(a href="cic:/matita/basics/logic/iff_or_l.def(2)"iff_or_l/a … (HI2 w))] @a href="cic:/matita/basics/logic/iff_or_r.def(2)"iff_or_r/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[||@a href="cic:/matita/basics/logic/iff_sym.def(2)"iff_sym/a @a href="cic:/matita/tutorial/chapter6/deriv_middot.def(5)"deriv_middot/a //] + @a href="cic:/matita/tutorial/chapter6/cat_ext_l.def(5)"cat_ext_l/a @HI1 + |#i1 #i2 #HI1 #HI2 #w >(a href="cic:/matita/tutorial/chapter7/sem_plus.def(8)"sem_plus/a S i1 i2) >a href="cic:/matita/tutorial/chapter9/move_plus.def(7)"move_plus/a >a href="cic:/matita/tutorial/chapter7/sem_plus_w.def(8)"sem_plus_w/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[|@a href="cic:/matita/tutorial/chapter8/sem_oplus.def(9)"sem_oplus/a] + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[|@a href="cic:/matita/basics/logic/iff_or_l.def(2)"iff_or_l/a [|@HI2]| @a href="cic:/matita/basics/logic/iff_or_r.def(2)"iff_or_r/a //] + |#i1 #HI1 #w >a href="cic:/matita/tutorial/chapter9/move_star.def(7)"move_star/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[|@a href="cic:/matita/tutorial/chapter8/sem_ostar.def(13)"sem_ostar/a] >a href="cic:/matita/tutorial/chapter9/same_kernel.def(8)"same_kernel/a >a href="cic:/matita/tutorial/chapter7/sem_star_w.def(8)"sem_star_w/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a[||@a href="cic:/matita/basics/logic/iff_sym.def(2)"iff_sym/a @a href="cic:/matita/tutorial/chapter6/deriv_middot.def(5)"deriv_middot/a //] + @a href="cic:/matita/tutorial/chapter6/cat_ext_l.def(5)"cat_ext_l/a @HI1 ] qed. +(* The move operation is generalized to strings in the obvious way. *) + notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}. -let rec moves (S : DeqSet) w e on w : pre S ≝ + +let rec moves (S : a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a) w e on w : a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S ≝ match w with [ nil ⇒ e - | cons x w' ⇒ w' ↦* (move S x (\fst e))]. + | cons x w' ⇒ w' ↦* (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S x (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a e))]. -lemma moves_empty: ∀S:DeqSet.∀e:pre S. - moves ? [ ] e = e. +lemma moves_empty: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀e:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. + a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a ? a title="nil" href="cic:/fakeuri.def(1)"[/a a title="nil" href="cic:/fakeuri.def(1)"]/a e a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a e. // qed. -lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S. - moves ? (a::w) e = moves ? w (move S a (\fst e)). +lemma moves_cons: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀a:S.∀w.∀e:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. + a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a ? (aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aw) e a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a ? w (a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S a (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a e)). // qed. lemma moves_left : ∀S,a,w,e. - moves S (w@[a]) e = move S a (\fst (moves S w e)). -#S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons // + a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a S (wa title="append" href="cic:/fakeuri.def(1)"@/a(aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aa title="nil" href="cic:/fakeuri.def(1)"[/aa title="nil" href="cic:/fakeuri.def(1)"]/a)) e a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S a (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a (a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a S w e)). +#S #a #w elim w // #x #tl #Hind #e >a href="cic:/matita/tutorial/chapter9/moves_cons.def(8)"moves_cons/a >a href="cic:/matita/tutorial/chapter9/moves_cons.def(8)"moves_cons/a // qed. -lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S. - iff ((a::w) ∈ e) ((a::w) ∈ \fst e). +lemma not_epsilon_sem: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀a:S.∀w: a href="cic:/matita/tutorial/chapter6/word.def(3)"word/a S. ∀e:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. + a href="cic:/matita/basics/logic/iff.def(1)"iff/a ((aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aw) a title="in_prl mem" href="cic:/fakeuri.def(1)"∈/a e) ((aa title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aw) a title="in_pl mem" href="cic:/fakeuri.def(1)"∈/a a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a e). #S #a #w * #i #b cases b normalize - [% /2/ * // #H destruct |% normalize /2/] + [% /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a/span/span/ * // #H destruct |% normalize /span class="autotactic"2span class="autotrace" trace /span/span/] qed. -lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S. - |\fst (moves ? w e)| = |\fst e|. +lemma same_kernel_moves: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀w.∀e:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. + a title="forget" href="cic:/fakeuri.def(1)"|/aa title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a (a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a ? w e)a title="forget" href="cic:/fakeuri.def(1)"|/a a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a title="forget" href="cic:/fakeuri.def(1)"|/aa title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a ea title="forget" href="cic:/fakeuri.def(1)"|/a. #S #w elim w // qed. -theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S. - (\snd (moves ? w e) = true) ↔ \sem{e} w. +theorem decidable_sem: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀w: a href="cic:/matita/tutorial/chapter6/word.def(3)"word/a S. ∀e:a href="cic:/matita/tutorial/chapter7/pre.def(1)"pre/a S. + (a title="pair pi2" href="cic:/fakeuri.def(1)"\snd/a (a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a ? w e) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a) a title="iff" href="cic:/fakeuri.def(1)"↔/a a title="in_prl" href="cic:/fakeuri.def(1)"\sem/a{ea title="in_prl" href="cic:/fakeuri.def(1)"}/a w. #S #w elim w - [* #i #b >moves_empty cases b % /2/ - |#a #w1 #Hind #e >moves_cons - @iff_trans [||@iff_sym @not_epsilon_sem] - @iff_trans [||@move_ok] @Hind + [* #i #b >a href="cic:/matita/tutorial/chapter9/moves_empty.def(8)"moves_empty/a cases b % /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/tutorial/chapter7/true_to_epsilon.def(9)"true_to_epsilon/a/span/span/ #H @a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/absurd.def(2)"absurd/a/span/span/ + |#a #w1 #Hind #e >a href="cic:/matita/tutorial/chapter9/moves_cons.def(8)"moves_cons/a + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a [||@a href="cic:/matita/basics/logic/iff_sym.def(2)"iff_sym/a @a href="cic:/matita/tutorial/chapter9/not_epsilon_sem.def(9)"not_epsilon_sem/a] + @a href="cic:/matita/basics/logic/iff_trans.def(2)"iff_trans/a [||@a href="cic:/matita/tutorial/chapter9/move_ok.def(14)"move_ok/a] @Hind ] qed. -(************************ pit state ***************************) -definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉. +(* It is now clear that we can build a DFA D_e for e by taking pre as states, +and move as transition function; the initial state is •(e) and a state 〈i,b〉 is +final if and only if b is true. The fact that states in D_e are finite is obvious: +in fact, their cardinality is at most 2^{n+1} where n is the number of symbols in +e. This is one of the advantages of pointed regular expressions w.r.t. derivatives, +whose finite nature only holds after a suitable quotient. + +Let us discuss a couple of examples. + +bExample/b. +Below is the DFA associated with the regular expression (ac+bc)*. + +img src="http://www.cs.unibo.it/~asperti/FIGURES/acUbc.gif" alt="DFA for (ac+bc)" + +The graphical description of the automaton is the traditional one, with nodes for +states and labelled arcs for transitions. Unreachable states are not shown. +Final states are emphasized by a double circle: since a state 〈e,b〉 is final if and +only if b is true, we may just label nodes with the item. +The automaton is not minimal: it is easy to see that the two states corresponding to +the items (a•c +bc)* and (ac+b•c)* are equivalent (a way to prove it is to observe +that they define the same language!). In fact, an important property of pres e is that +each state has a clear semantics, given in terms of the specification e and not of the +behaviour of the automaton. As a consequence, the construction of the automaton is not +only direct, but also extremely intuitive and locally verifiable. + +Let us consider a more complex case. + +bExample/b. +Starting form the regular expression (a+ϵ)(b*a + b)b, we obtain the following automaton. -let rec occur (S: DeqSet) (i: re S) on i ≝ +img src="http://www.cs.unibo.it/~asperti/FIGURES/automaton.gif" alt="DFA for (a+ϵ)(b*a + b)b" + +Remarkably, this DFA is minimal, testifying the small number of states produced by our +technique (the pair of states 6-8 and 7-9 differ for the fact that 6 and 7 +are final, while 8 and 9 are not). + + +h2Move to pit/h2. + +We conclude this chapter with a few properties of the move opertions in relation +with the pit state. *) + +definition pit_pre ≝ λS.λi.a title="Pair construction" href="cic:/fakeuri.def(1)"〈/aa href="cic:/matita/tutorial/chapter8/blank.fix(0,1,3)"blank/a S (a title="forget" href="cic:/fakeuri.def(1)"|/aia title="forget" href="cic:/fakeuri.def(1)"|/a), a href="cic:/matita/basics/bool/bool.con(0,2,0)"false/aa title="Pair construction" href="cic:/fakeuri.def(1)"〉/a. + +(* The following function compute the list of characters occurring in a given +item i. *) + +let rec occur (S: a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a) (i: a href="cic:/matita/tutorial/chapter7/re.ind(1,0,1)"re/a S) on i ≝ match i with - [ z ⇒ [ ] - | e ⇒ [ ] - | s y ⇒ [y] - | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) - | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) + [ z ⇒ a title="nil" href="cic:/fakeuri.def(1)"[/a a title="nil" href="cic:/fakeuri.def(1)"]/a + | e ⇒ a title="nil" href="cic:/fakeuri.def(1)"[/a a title="nil" href="cic:/fakeuri.def(1)"]/a + | s y ⇒ ya title="cons" href="cic:/fakeuri.def(1)":/aa title="cons" href="cic:/fakeuri.def(1)":/aa title="nil" href="cic:/fakeuri.def(1)"[/aa title="nil" href="cic:/fakeuri.def(1)"]/a + | o e1 e2 ⇒ a href="cic:/matita/tutorial/chapter5/unique_append.fix(0,1,5)"unique_append/a ? (occur S e1) (occur S e2) + | c e1 e2 ⇒ a href="cic:/matita/tutorial/chapter5/unique_append.fix(0,1,5)"unique_append/a ? (occur S e1) (occur S e2) | k e ⇒ occur S e]. -lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true → - move S a i = pit_pre S i. +(* If a symbol a does not occur in i, then move(i,a) gets to the +pit state. *) + +lemma not_occur_to_pit: ∀S,a.∀i:a href="cic:/matita/tutorial/chapter7/pitem.ind(1,0,1)"pitem/a S. a href="cic:/matita/tutorial/chapter5/memb.fix(0,2,4)"memb/a S a (a href="cic:/matita/tutorial/chapter9/occur.fix(0,1,6)"occur/a S (a title="forget" href="cic:/fakeuri.def(1)"|/aia title="forget" href="cic:/fakeuri.def(1)"|/a)) a title="leibnitz's non-equality" href="cic:/fakeuri.def(1)"≠/a a href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a → + a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S a i a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S i. #S #a #i elim i // - [#x normalize cases (a==x) normalize // #H @False_ind /2/ - |#i1 #i2 #Hind1 #Hind2 #H >move_cat - >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //] - >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] // - |#i1 #i2 #Hind1 #Hind2 #H >move_plus - >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //] - >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] // - |#i #Hind #H >move_star >Hind // + [#x normalize cases (aa title="eqb" href="cic:/fakeuri.def(1)"=/aa title="eqb" href="cic:/fakeuri.def(1)"=/ax) normalize // #H @a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/absurd.def(2)"absurd/a/span/span/ + |#i1 #i2 #Hind1 #Hind2 #H >a href="cic:/matita/tutorial/chapter9/move_cat.def(7)"move_cat/a + >Hind1 [2:@(a href="cic:/matita/basics/logic/not_to_not.def(3)"not_to_not/a … H) #H1 @a href="cic:/matita/tutorial/chapter5/sublist_unique_append_l1.def(6)"sublist_unique_append_l1/a //] + >Hind2 [2:@(a href="cic:/matita/basics/logic/not_to_not.def(3)"not_to_not/a … H) #H1 @a href="cic:/matita/tutorial/chapter5/sublist_unique_append_l2.def(6)"sublist_unique_append_l2/a //] // + |#i1 #i2 #Hind1 #Hind2 #H >a href="cic:/matita/tutorial/chapter9/move_plus.def(7)"move_plus/a + >Hind1 [2:@(a href="cic:/matita/basics/logic/not_to_not.def(3)"not_to_not/a … H) #H1 @a href="cic:/matita/tutorial/chapter5/sublist_unique_append_l1.def(6)"sublist_unique_append_l1/a //] + >Hind2 [2:@(a href="cic:/matita/basics/logic/not_to_not.def(3)"not_to_not/a … H) #H1 @a href="cic:/matita/tutorial/chapter5/sublist_unique_append_l2.def(6)"sublist_unique_append_l2/a //] // + |#i #Hind #H >a href="cic:/matita/tutorial/chapter9/move_star.def(7)"move_star/a >Hind // ] qed. -lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i. +(* We cannot escape form the pit state. *) + +lemma move_pit: ∀S,a,i. a href="cic:/matita/tutorial/chapter9/move.fix(0,2,6)"move/a S a (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a (a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S i)) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S i. #S #a #i elim i // - [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 // - |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 // - |#i #Hind >move_star >Hind // + [#i1 #i2 #Hind1 #Hind2 >a href="cic:/matita/tutorial/chapter9/move_cat.def(7)"move_cat/a >Hind1 >Hind2 // + |#i1 #i2 #Hind1 #Hind2 >a href="cic:/matita/tutorial/chapter9/move_plus.def(7)"move_plus/a >Hind1 >Hind2 // + |#i #Hind >a href="cic:/matita/tutorial/chapter9/move_star.def(7)"move_star/a >Hind // ] qed. -lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i. +lemma moves_pit: ∀S,w,i. a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a S w (a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S i) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S i. #S #w #i elim w // qed. -lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) → - moves S w e = pit_pre S (\fst e). +(* If any character in w does not occur in i, then moves(i,w) gets +to the pit state. *) + +lemma to_pit: ∀S,w,e. a title="logical not" href="cic:/fakeuri.def(1)"¬/a a href="cic:/matita/tutorial/chapter5/sublist.def(5)"sublist/a S w (a href="cic:/matita/tutorial/chapter9/occur.fix(0,1,6)"occur/a S (a title="forget" href="cic:/fakeuri.def(1)"|/aa title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a ea title="forget" href="cic:/fakeuri.def(1)"|/a)) → + a href="cic:/matita/tutorial/chapter9/moves.fix(0,1,7)"moves/a S w e a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/tutorial/chapter9/pit_pre.def(4)"pit_pre/a S (a title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a e). #S #w elim w - [#e * #H @False_ind @H normalize #a #abs @False_ind /2/ - |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|)))) - [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a) - @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb) + [#e * #H @a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a @H normalize #a #abs @a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"False_ind/a /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/absurd.def(2)"absurd/a/span/span/ + |#a #tl #Hind #e #H cases (a href="cic:/matita/basics/bool/true_or_false.def(1)"true_or_false/a (a href="cic:/matita/tutorial/chapter5/memb.fix(0,2,4)"memb/a S a (a href="cic:/matita/tutorial/chapter9/occur.fix(0,1,6)"occur/a S (a title="forget" href="cic:/fakeuri.def(1)"|/aa title="pair pi1" href="cic:/fakeuri.def(1)"\fst/a ea title="forget" href="cic:/fakeuri.def(1)"|/a)))) + [#Htrue >a href="cic:/matita/tutorial/chapter9/moves_cons.def(8)"moves_cons/a whd in ⊢ (???%); <(a href="cic:/matita/tutorial/chapter9/same_kernel.def(8)"same_kernel/a … a) + @Hind >a href="cic:/matita/tutorial/chapter9/same_kernel.def(8)"same_kernel/a @(a href="cic:/matita/basics/logic/not_to_not.def(3)"not_to_not/a … H) #H1 #b #memb cases (a href="cic:/matita/basics/bool/orb_true_l.def(2)"orb_true_l/a … memb) [#H2 >(\P H2) // |#H2 @H1 //] - |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/ + |#Hfalse >a href="cic:/matita/tutorial/chapter9/moves_cons.def(8)"moves_cons/a >a href="cic:/matita/tutorial/chapter9/not_occur_to_pit.def(8)"not_occur_to_pit/a // >Hfalse /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/bool/eqnot_to_noteq.def(4)"eqnot_to_noteq/a/span/span/ ] ] qed. \ No newline at end of file