X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=inline;f=matita%2Fmatita%2Flib%2Fre%2Fmoves.ma;h=1372b49760ee677eea226d73a3a70392bc869e86;hb=913512bbc9202f2109d53acd43dc8c0270b17184;hp=116212a56faab8dcf7a605a9401b6e8fb41c18f2;hpb=537a73f4aca66ef57108a51cd9cc61b478571f33;p=helm.git
diff --git a/matita/matita/lib/re/moves.ma b/matita/matita/lib/re/moves.ma
index 116212a56..1372b4976 100644
--- a/matita/matita/lib/re/moves.ma
+++ b/matita/matita/lib/re/moves.ma
@@ -13,10 +13,24 @@
(**************************************************************************)
include "re/re.ma".
+include "basics/lists/listb.ma".
+
+(*
+Moves
+
+We now define the move operation, that corresponds to the advancement of the
+state in response to the processing of an input character a. The intuition is
+clear: we have to look at points inside $e$ preceding the given character a,
+let the point traverse the character, and broadcast it. All other points must
+be removed.
+
+We can give a particularly elegant definition in terms of the
+lifted operators of the previous section:
+*)
let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S â
match E with
- [ pz â â© â
, false âª
+ [ pz â â© `â
, false âª
| pe â ⩠ϵ, false âª
| ps y â â© `y, false âª
| pp y â â© `y, x == y âª
@@ -36,12 +50,6 @@ lemma move_star: âS:DeqSet.âx:S.âi:pitem S.
move S x i^* = (move ? x i)^â.
// qed.
-lemma fst_eq : âA,B.âa:A.âb:B. \fst â©a,b⪠= a.
-// qed.
-
-lemma snd_eq : âA,B.âa:A.âb:B. \snd â©a,b⪠= b.
-// qed.
-
definition pmove â λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
lemma pmove_def : âS:DeqSet.âx:S.âi:pitem S.âb.
@@ -53,15 +61,13 @@ lemma eq_to_eq_hd: âA.âl1,l2:list A.âa,b.
#A #l1 #l2 #a #b #H destruct //
qed.
-axiom same_kernel: âS:DeqSet.âa:S.âi:pitem S.
+lemma same_kernel: âS:DeqSet.âa:S.âi:pitem S.
|\fst (move ? a i)| = |i|.
-(* #S #a #i elim i //
- [#i1 #i2 >move_cat
- cases (move S a i1) #i11 #b1 >fst_eq #IH1
- cases (move S a i2) #i21 #b2 >fst_eq #IH2
- normalize *)
-
-axiom epsilon_in_star: âS.âA:word S â Prop. A^* [ ].
+#S #a #i elim i //
+ [#i1 #i2 >move_cat #H1 #H2 whd in ⢠(???%);
move_plus #H1 #H2 whd in ⢠(???%); H normalize
- [>(proj1 ⦠(eqb_true â¦) H) %
- [* // #bot @False_ind //| #H1 destruct /2/]
- |% [#bot @False_ind //
- | #H1 destruct @(absurd ((a==a)=true))
- [>(proj2 ⦠(eqb_true â¦) (refl â¦)) // | /2/]
- ]
- ]
- |#i1 #i2 #HI1 #HI2 #w >(sem_cat S i1 i2) >move_cat
- @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
- @iff_trans[||@(iff_or_l ⦠(HI2 w))] @iff_or_r %
- [* #w1 * #w2 * * #eqw #w1in #w2in @(ex_intro ⦠(a::w1))
- @(ex_intro ⦠w2) % // % normalize // cases (HI1 w1) /2/
- |* #w1 * #w2 * cases w1
- [* #_ #H @False_ind /2/
- |#x #w3 * #eqaw normalize in eqaw; destruct #w3in #w2in
- @(ex_intro ⦠w3) @(ex_intro ⦠w2) % // % // cases (HI1 w3) /2/
- ]
+ [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
+ |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
]
+ |#i1 #i2 #HI1 #HI2 #w
+ (* lhs = wâ\sem{move S a (i1·i2)} *)
+ >move_cat
+ (* lhs = wâ\sem{move S a i1}â\sem{move S a i2} *)
+ @iff_trans[|@sem_odot] >same_kernel
+ (* lhs = wâ\sem{move S a i1}·\sem{|i2|} ⨠aâ\sem{move S a i2} *)
+ (* now we work on the rhs, that is
+ rhs = a::w1â\sem{i1·i2} *)
+ >sem_cat_w
+ (* rhs = a::w1â\sem{i1}\sem{|i2|} ⨠a::wâ\sem{i2} *)
+ @iff_trans[||@(iff_or_l ⦠(HI2 w))]
+ (* rhs = a::w1â\sem{i1}\sem{|i2|} ⨠wâ\sem{move S a i2} *)
+ @iff_or_r
+ check deriv_middot
+ (* we are left to prove that
+ wâ\sem{move S a i1}·\sem{|i2|} â a::wâ\sem{i1}\sem{|i2|}
+ we use deriv_middot on the rhs *)
+ @iff_trans[||@iff_sym @deriv_middot //]
+ (* wâ\sem{move S a i1}·\sem{|i2|} â wâ(deriv S \sem{i1} a) · \sem{|i2|} *)
+ @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 %
- [* #w1 * #w2 * * #eqw #w1in #w2in
- @(ex_intro ⦠(a::w1)) @(ex_intro ⦠w2) % // % normalize //
- cases (HI1 w1 ) /2/
- |* #w1 * #w2 * cases w1
- [* #_ #H @False_ind /2/
- |#x #w3 * #eqaw normalize in eqaw; destruct #w3in #w2in
- @(ex_intro ⦠w3) @(ex_intro ⦠w2) % // % // cases (HI1 w3) /2/
- ]
- ]
+ @iff_trans[|@sem_ostar] >same_kernel >sem_star_w
+ @iff_trans[||@iff_sym @deriv_middot //]
+ @cat_ext_l @HI1
]
qed.
@@ -110,7 +114,7 @@ notation > "x â¦* E" non associative with precedence 60 for @{moves ? $x $E}.
let rec moves (S : DeqSet) w e on w : pre S â
match w with
[ nil â e
- | cons x w' â w' â¦* (move S x (\fst e))].
+ | cons x w' â w' â¦* (move S x (\fst e))].
lemma moves_empty: âS:DeqSet.âe:pre S.
moves ? [ ] e = e.
@@ -120,9 +124,14 @@ lemma moves_cons: âS:DeqSet.âa:S.âw.âe:pre S.
moves ? (a::w) e = moves ? w (move S a (\fst 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 //
+qed.
+
lemma not_epsilon_sem: âS:DeqSet.âa:S.âw: word S. âe:pre S.
iff ((a::w) â e) ((a::w) â \fst e).
-#S #a #w * #i #b >fst_eq cases b normalize
+#S #a #w * #i #b cases b normalize
[% /2/ * // #H destruct |% normalize /2/]
qed.
@@ -132,21 +141,77 @@ lemma same_kernel_moves: âS:DeqSet.âw.âe:pre S.
qed.
theorem decidable_sem: âS:DeqSet.âw: word S. âe:pre S.
- (\snd (moves ? w e) = true) â \sem{e} w.
+ (\snd (moves ? w e) = true) â \sem{e} w.
#S #w elim w
[* #i #b >moves_empty cases b % /2/
|#a #w1 #Hind #e >moves_cons
+ check not_epsilon_sem
@iff_trans [||@iff_sym @not_epsilon_sem]
@iff_trans [||@move_ok] @Hind
]
qed.
-lemma not_true_to_false: âb.bâ true â b =false.
-#b * cases b // #H @False_ind /2/
+(************************ pit state ***************************)
+definition pit_pre â λS.λi.â©blank S (|i|), falseâª.
+
+let rec occur (S: DeqSet) (i: re 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)
+ | 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.
+#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 //
+ ]
+qed.
+
+lemma move_pit: âS,a,i. move S a (\fst (pit_pre S i)) = pit_pre 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 //
+ ]
qed.
+lemma moves_pit: âS,w,i. moves S w (pit_pre S i) = pit_pre S i.
+#S #w #i elim w // #a #tl >moves_cons //
+qed.
+
+lemma to_pit: âS,w,e. ¬ sublist S w (occur S (|\fst e|)) â
+ moves S w e = pit_pre S (\fst 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)
+ [#H2 >(\P H2) // |#H2 @H1 //]
+ |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/
+ ]
+ ]
+qed.
+
+(* bisimulation *)
+definition cofinal â λS.λp:(pre S)Ã(pre S).
+ \snd (\fst p) = \snd (\snd p).
+
+(* As a corollary of decidable_sem, we have that two expressions
+e1 and e2 are equivalent iff for any word w the states reachable
+through w are cofinal. *)
+
theorem equiv_sem: âS:DeqSet.âe1,e2:pre S.
- iff (\sem{e1} =1 \sem{e2}) (âw.\snd (moves ? w e1) = \snd (moves ? w e2)).
+ \sem{e1} =1 \sem{e2} â âw.cofinal ? â©moves ? w e1,moves ? w e2âª.
#S #e1 #e2 %
[#same_sem #w
cut (âb1,b2. iff (b1 = true) (b2 = true) â (b1 = b2))
@@ -156,78 +221,95 @@ theorem equiv_sem: âS:DeqSet.âe1,e2:pre S.
|#H #w1 @iff_trans [||@decidable_sem] to_pit [2: @(not_to_not ⦠H) #H1 #a #memba @sublist_unique_append_l1 @H1 //]
+ >to_pit [2: @(not_to_not ⦠H) #H1 #a #memba @sublist_unique_append_l2 @H1 //]
+ //
qed.
-definition Bin â mk_DeqSet bool beqb beqb_ok.
-
-let rec beqitem S (i1,i2: pitem S) on i1 â
- match i1 with
- [ pz â match i2 with [ pz â true | _ â false]
- | pe â match i2 with [ pe â true | _ â false]
- | ps y1 â match i2 with [ ps y2 â y1==y2 | _ â false]
- | pp y1 â match i2 with [ pp y2 â y1==y2 | _ â false]
- | po i11 i12 â match i2 with
- [ po i21 i22 â beqitem S i11 i21 ⧠beqitem S i12 i22
- | _ â false]
- | pc i11 i12 â match i2 with
- [ pc i21 i22 â beqitem S i11 i21 ⧠beqitem S i12 i22
- | _ â false]
- | pk i11 â match i2 with [ pk i21 â beqitem S i11 i21 | _ â false]
- ].
-
-axiom beqitem_ok: âS,i1,i2. iff (beqitem S i1 i2 = true) (i1 = i2).
+(* The following is a stronger version of equiv_sem, relative to characters
+occurring the given regular expressions. *)
-definition BinItem â
- mk_DeqSet (pitem Bin) (beqitem Bin) (beqitem_ok Bin).
+lemma equiv_sem_occ: âS.âe1,e2:pre S.
+(âw.(sublist S w (occ S e1 e2))â cofinal ? â©moves ? w e1,moves ? w e2âª)
+â \sem{e1}=1\sem{e2}.
+#S #e1 #e2 #H @(proj2 ⦠(equiv_sem â¦)) @occ_enough #w @H
+qed.
-definition beqpre â λS:DeqSet.λe1,e2:pre S.
- beqitem S (\fst e1) (\fst e2) ⧠beqb (\snd e1) (\snd e2).
-
-definition beqpairs â λS:DeqSet.λp1,p2:(pre S)Ã(pre S).
- beqpre S (\fst p1) (\fst p2) ⧠beqpre S (\snd p1) (\snd p2).
-
-axiom beqpairs_ok: âS,p1,p2. iff (beqpairs S p1 p2 = true) (p1 = p2).
+(*
+We say that a list of pairs of pres is a bisimulation if it is closed
+w.r.t. moves, and all its members are cofinal.
+*)
-definition space â λS.mk_DeqSet ((pre S)Ã(pre S)) (beqpairs S) (beqpairs_ok S).
+(* the sons of p w.r.t a list of symbols l are all states reachable from p
+with a move in l *)
-definition sons â λp:space Bin.
- [â©move Bin true (\fst (\fst p)), move Bin true (\fst (\snd p))âª;
- â©move Bin false (\fst (\fst p)), move Bin false (\fst (\snd p))âª
- ].
+definition sons â λS:DeqSet.λl:list S.λp:(pre S)Ã(pre S).
+ map ?? (λa.â©move S a (\fst (\fst p)),move S a (\fst (\snd p))âª) l.
-axiom memb_sons: âp,q. memb (space Bin) p (sons q) = true â
+lemma memb_sons: âS,l.âp,q:(pre S)Ã(pre S). memb ? p (sons ? l q) = true â
âa.(move ? a (\fst (\fst q)) = \fst p â§
move ? a (\fst (\snd q)) = \snd p).
+#S #l elim l [#p #q normalize in ⢠(%â?); #abs @False_ind /2/]
+#a #tl #Hind #p #q #H cases (orb_true_l ⦠H) -H
+ [#H @(ex_intro ⦠a) >(\P H) /2/ |#H @Hind @H]
+qed.
+
+definition is_bisim â λS:DeqSet.λl:list ?.λalpha:list S.
+ âp:(pre S)Ã(pre S). memb ? p l = true â cofinal ? p ⧠(sublist ? (sons ? alpha p) l).
-(*
-let rec test_sons (l:list (space Bin)) â
- match l with
- [ nil â true
- | cons hd tl â
- beqb (\snd (\fst hd)) (\snd (\snd hd)) ⧠test_sons tl
- ]. *)
+(* Using lemma equiv_sem_occ it is easy to prove the following result: *)
+
+lemma bisim_to_sem: âS:DeqSet.âl:list ?.âe1,e2: pre S.
+ is_bisim S l (occ S e1 e2) â memb ? â©e1,e2⪠l = true â \sem{e1}=1\sem{e2}.
+#S #l #e1 #e2 #Hbisim #Hmemb @equiv_sem_occ
+#w #Hsub @(proj1 ⦠(Hbisim â©moves S w e1,moves S w e2⪠?))
+lapply Hsub @(list_elim_left ⦠w) [//]
+#a #w1 #Hind #Hsub >moves_left >moves_left @(proj2 â¦(Hbisim â¦(Hind ?)))
+ [#x #Hx @Hsub @memb_append_l1 //
+ |cut (memb S a (occ S e1 e2) = true) [@Hsub @memb_append_l2 //] #occa
+ @(memb_map ⦠occa)
+ ]
+qed.
-let rec bisim (n:nat) (frontier,visited: list (space Bin)) â
+(* This is already an interesting result: checking if l is a bisimulation
+is decidable, hence we could generate l with some untrusted piece of code
+and then run a (boolean version of) is_bisim to check that it is actually
+a bisimulation.
+However, in order to prove that equivalence of regular expressions
+is decidable we must prove that we can always effectively build such a list
+(or find a counterexample).
+The idea is that the list we are interested in is just the set of
+all pair of pres reachable from the initial pair via some
+sequence of moves.
+
+The algorithm for computing reachable nodes in graph is a very
+traditional one. We split nodes in two disjoint lists: a list of
+visited nodes and a frontier, composed by all nodes connected
+to a node in visited but not visited already. At each step we select a node
+a from the frontier, compute its sons, add a to the set of
+visited nodes and the (not already visited) sons to the frontier.
+
+Instead of fist computing reachable nodes and then performing the
+bisimilarity test we can directly integrate it in the algorithm:
+the set of visited nodes is closed by construction w.r.t. reachability,
+so we have just to check cofinality for any node we add to visited.
+
+Here is the extremely simple algorithm: *)
+
+let rec bisim S l n (frontier,visited: list ?) on n â
match n with
[ O â â©false,visited⪠(* assert false *)
| S m â
@@ -235,14 +317,14 @@ let rec bisim (n:nat) (frontier,visited: list (space Bin)) â
[ nil â â©true,visitedâª
| cons hd tl â
if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
- bisim m (unique_append ? (filter ? (λx.notb (memb ? x (hd::visited)))
- (sons hd)) tl) (hd::visited)
+ bisim S l m (unique_append ? (filter ? (λx.notb (memb ? x (hd::visited)))
+ (sons S l hd)) tl) (hd::visited)
else â©false,visitedâª
]
].
-lemma unfold_bisim: ân.âfrontier,visited: list (space Bin).
- bisim n frontier visited =
+lemma unfold_bisim: âS,l,n.âfrontier,visited: list ?.
+ bisim S l n frontier visited =
match n with
[ O â â©false,visited⪠(* assert false *)
| S m â
@@ -250,89 +332,52 @@ lemma unfold_bisim: ân.âfrontier,visited: list (space Bin).
[ nil â â©true,visitedâª
| cons hd tl â
if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
- bisim m (unique_append ? (filter ? (λx.notb(memb ? x (hd::visited))) (sons hd)) tl) (hd::visited)
+ bisim S l m (unique_append ? (filter ? (λx.notb(memb ? x (hd::visited)))
+ (sons S l hd)) tl) (hd::visited)
else â©false,visitedâª
]
].
-#n cases n // qed.
-
-lemma bisim_never: âfrontier,visited: list (space Bin).
- bisim O frontier visited = â©false,visitedâª.
+#S #l #n cases n // qed.
+
+(* The integer n is an upper bound to the number of recursive call,
+equal to the dimension of the graph. It returns a pair composed
+by a boolean and a the set of visited nodes; the boolean is true
+if and only if all visited nodes are cofinal.
+
+The following results explicitly state the behaviour of bisim is the general
+case and in some relevant instances *)
+
+lemma bisim_never: âS,l.âfrontier,visited: list ?.
+ bisim S l O frontier visited = â©false,visitedâª.
#frontier #visited >unfold_bisim //
qed.
-lemma bisim_end: âm.âvisited: list (space Bin).
- bisim (S m) [] visited = â©true,visitedâª.
+lemma bisim_end: âSig,l,m.âvisited: list ?.
+ bisim Sig l (S m) [] visited = â©true,visitedâª.
#n #visisted >unfold_bisim //
qed.
-lemma bisim_step_true: âm.âp.âfrontier,visited: list (space Bin).
+lemma bisim_step_true: âSig,l,m.âp.âfrontier,visited: list ?.
beqb (\snd (\fst p)) (\snd (\snd p)) = true â
- bisim (S m) (p::frontier) visited =
- bisim m (unique_append ? (filter ? (λx.notb(memb (space Bin) x (p::visited))) (sons p)) frontier) (p::visited).
-#m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
+ bisim Sig l (S m) (p::frontier) visited =
+ bisim Sig l m (unique_append ? (filter ? (λx.notb(memb ? x (p::visited)))
+ (sons Sig l p)) frontier) (p::visited).
+#Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
qed.
-lemma bisim_step_false: âm.âp.âfrontier,visited: list (space Bin).
+lemma bisim_step_false: âSig,l,m.âp.âfrontier,visited: list ?.
beqb (\snd (\fst p)) (\snd (\snd p)) = false â
- bisim (S m) (p::frontier) visited = â©false,visitedâª.
-#m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
-qed.
-
-definition visited_inv â λe1,e2:pre Bin.λvisited: list (space Bin).
-uniqueb ? visited = true â§
- âp. memb ? p visited = true â
- (âw.(moves Bin w e1 = \fst p) ⧠(moves Bin w e2 = \snd p)) â§
- (beqb (\snd (\fst p)) (\snd (\snd p)) = true).
-
-definition frontier_inv â λfrontier,visited: list (space Bin).
-uniqueb ? frontier = true â§
-âp. memb ? p frontier = true â
- memb ? p visited = false â§
- âp1.((memb ? p1 visited = true) â§
- (âa. move ? a (\fst (\fst p1)) = \fst p â§
- move ? a (\fst (\snd p1)) = \snd p)).
-
-(* lemma andb_true: âb1,b2:bool.
- (b1 ⧠b2) = true â (b1 = true) ⧠(b2 = true).
-#b1 #b2 cases b1 normalize #H [>H /2/ |@False_ind /2/].
+ bisim Sig l (S m) (p::frontier) visited = â©false,visitedâª.
+#Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
qed.
-lemma andb_true_r: âb1,b2:bool.
- (b1 = true) ⧠(b2 = true) â (b1 ⧠b2) = true.
-#b1 #b2 cases b1 normalize * //
-qed. *)
-
lemma notb_eq_true_l: âb. notb b = true â b = false.
#b cases b normalize //
qed.
-lemma notb_eq_true_r: âb. b = false â notb b = true.
-#b cases b normalize //
-qed.
-
-lemma notb_eq_false_l:âb. notb b = false â b = true.
-#b cases b normalize //
-qed.
+(* In order to prove termination of bisim we must be able to effectively
+enumerate all possible pres: *)
-lemma notb_eq_false_r:âb. b = true â notb b = false.
-#b cases b normalize //
-qed.
-
-
-include "arithmetics/exp.ma".
-
-let rec pos S (i:re S) on i â
- match i with
- [ z â 0
- | e â 0
- | s y â 1
- | o i1 i2 â pos S i1 + pos S i2
- | c i1 i2 â pos S i1 + pos S i2
- | k i â pos S i
- ].
-
-
let rec pitem_enum S (i:re S) on i â
match i with
[ z â [pz S]
@@ -342,125 +387,146 @@ let rec pitem_enum S (i:re S) on i â
| c i1 i2 â compose ??? (pc S) (pitem_enum S i1) (pitem_enum S i2)
| k i â map ?? (pk S) (pitem_enum S i)
].
-
-axiom pitem_enum_complete: âi: pitem Bin.
- memb BinItem i (pitem_enum ? (forget ? i)) = true.
-(*
-#i elim i
- [//
- |//
- |* //
- |* //
- |#i1 #i2 #Hind1 #Hind2 @memb_compose //
- |#i1 #i2 #Hind1 #Hind2 @memb_compose //
- |
-*)
+
+lemma pitem_enum_complete : âS.âi:pitem S.
+ memb (DeqItem S) i (pitem_enum S (|i|)) = true.
+#S #i elim i
+ [1,2://
+ |3,4:#c normalize >(\b (refl ⦠c)) //
+ |5,6:#i1 #i2 #Hind1 #Hind2 @(memb_compose (DeqItem S) (DeqItem S)) //
+ |#i #Hind @(memb_map (DeqItem S)) //
+ ]
+qed.
definition pre_enum â λS.λi:re S.
compose ??? (λi,b.â©i,bâª) (pitem_enum S i) [true;false].
+
+lemma pre_enum_complete : âS.âe:pre S.
+ memb ? e (pre_enum S (|\fst e|)) = true.
+#S * #i #b @(memb_compose (DeqItem S) DeqBool ? (λi,b.â©i,bâª))
+// cases b normalize //
+qed.
definition space_enum â λS.λi1,i2:re S.
- compose ??? (λe1,e2.â©e1,e2âª) (pre_enum S i1) (pre_enum S i1).
-
-axiom space_enum_complete : âS.âe1,e2: pre S.
- memb (space S) â©e1,e2⪠(space_enum S (|\fst e1|) (|\fst e2|)) = true.
-
-lemma bisim_ok1: âe1,e2:pre Bin.\sem{e1}=1\sem{e2} â
- ân.âfrontier,visited:list (space Bin).
- |space_enum Bin (|\fst e1|) (|\fst e2|)| < n + |visited|â
- visited_inv e1 e2 visited â frontier_inv frontier visited â
- \fst (bisim n frontier visited) = true.
-#e1 #e2 #same #n elim n
+ compose ??? (λe1,e2.â©e1,e2âª) (pre_enum S i1) (pre_enum S i2).
+
+lemma space_enum_complete : âS.âe1,e2: pre S.
+ memb ? â©e1,e2⪠(space_enum S (|\fst e1|) (|\fst e2|)) = true.
+#S #e1 #e2 @(memb_compose ⦠(λi,b.â©i,bâª))
+// qed.
+
+(* We are ready to prove that bisim is correct; we use the invariant
+that at each call of bisim the two lists visited and frontier only contain
+nodes reachable from \langle e_1,e_2\rangle, hence it is absurd to suppose
+to meet a pair which is not cofinal. *)
+
+definition all_reachable â λS.λe1,e2:pre S.λl: list ?.
+uniqueb ? l = true â§
+ âp. memb ? p l = true â
+ âw.(moves S w e1 = \fst p) ⧠(moves S w e2 = \snd p).
+
+definition disjoint â λS:DeqSet.λl1,l2.
+ âp:S. memb S p l1 = true â memb S p l2 = false.
+
+lemma bisim_correct: âS.âe1,e2:pre S.\sem{e1}=1\sem{e2} â
+ âl,n.âfrontier,visited:list ((pre S)Ã(pre S)).
+ |space_enum S (|\fst e1|) (|\fst e2|)| < n + |visited|â
+ all_reachable S e1 e2 visited â
+ all_reachable S e1 e2 frontier â
+ disjoint ? frontier visited â
+ \fst (bisim S l n frontier visited) = true.
+#Sig #e1 #e2 #same #l #n elim n
[#frontier #visited #abs * #unique #H @False_ind @(absurd ⦠abs)
@le_to_not_lt @sublist_length // * #e11 #e21 #membp
cut ((|\fst e11| = |\fst e1|) ⧠(|\fst e21| = |\fst e2|))
[|* #H1 #H2 fst_eq >snd_eq #we1 #we2 #_
- same_kernel_moves //
|#m #HI * [#visited #vinv #finv >bisim_end //]
- #p #front_tl #visited #Hn * #u_visited #vinv * #u_frontier #finv
- cases (finv p (memb_hd â¦)) #Hp * #p2 * #visited_p2
- * #a * #movea1 #movea2
- cut (âw.(moves Bin w e1 = \fst p) ⧠(moves Bin w e2 = \snd p))
- [cases (vinv ⦠visited_p2) -vinv * #w1 * #mw1 #mw2 #_
- @(ex_intro ⦠(w1@[a])) /2/]
- -movea2 -movea1 -a -visited_p2 -p2 #reachp
+ #p #front_tl #visited #Hn * #u_visited #r_visited * #u_frontier #r_frontier
+ #disjoint
+ cut (âw.(moves ? w e1 = \fst p) ⧠(moves ? w e2 = \snd p))
+ [@(r_frontier ⦠(memb_hd ⦠))] #rp
cut (beqb (\snd (\fst p)) (\snd (\snd p)) = true)
- [cases reachp #w * #move_e1 #move_e2 (bisim_step_true ⦠ptest) @HI -HI
- [Hpq @nvq]
- cases (andb_true_l ⦠u_frontier) #notp #_
- @(not_memb_to_not_eq ⦠H) @notb_eq_true_l @notp
- |cases (proj2 ⦠(finv q ?))
- [#p1 * #Hp1 #reach @(ex_intro ⦠p1) % // @memb_cons //
- |@memb_cons //
- ]
- ]
- ]
- ]
- ]
- ]
-qed.
+ [cases rp #w * #fstp #sndp (bisim_step_true ⦠ptest) @HI -HI
+ [(disjoint ⦠(memb_hd â¦)) whd in ⢠(??%?); //
+ |#p1 #H (cases (orb_true_l ⦠H)) [#eqp >(\P eqp) // |@r_visited]
+ ]
+ |whd % [@unique_append_unique @(andb_true_r ⦠u_frontier)]
+ @unique_append_elim #q #H
+ [cases (memb_sons ⦠(memb_filter_memb ⦠H)) -H
+ #a * #m1 #m2 cases rp #w1 * #mw1 #mw2 @(ex_intro ⦠(w1@[a]))
+ >moves_left >moves_left >mw1 >mw2 >m1 >m2 % //
+ |@r_frontier @memb_cons //
+ ]
+ |@unique_append_elim #q #H
+ [@injective_notb @(filter_true ⦠H)
+ |cut ((q==p) = false)
+ [|#Hpq whd in ⢠(??%?); >Hpq @disjoint @memb_cons //]
+ cases (andb_true ⦠u_frontier) #notp #_ @(\bf ?)
+ @(not_to_not ⦠not_eq_true_false) #eqqp H //
+ ]
+ ]
+ ]
+qed.
-definition all_true â λl.âp. memb (space Bin) p l = true â
+definition all_true â λS.λl.âp:(pre S) à (pre S). memb ? p l = true â
(beqb (\snd (\fst p)) (\snd (\snd p)) = true).
-definition sub_sons â λl1,l2.âx,a.
-memb (space Bin) x l1 = true â
- memb (space Bin) â©move ? a (\fst (\fst x)), move ? a (\fst (\snd x))⪠l2 = true.
-
-lemma reachable_bisim:
- ân.âfrontier,visited,visited_res:list (space Bin).
- all_true visited â
- sub_sons visited (frontier@visited) â
- bisim n frontier visited = â©true,visited_res⪠â
- (sub_sons visited_res visited_res â§
- sublist ? visited visited_res â§
- all_true visited_res).
-#n elim n
+definition sub_sons â λS,l,l1,l2.âx:(pre S) à (pre S).
+memb ? x l1 = true â sublist ? (sons ? l x) l2.
+
+(* For completeness, we use the invariant that all the nodes in visited are cofinal,
+and the sons of visited are either in visited or in the frontier; since
+at the end frontier is empty, visited is hence a bisimulation. *)
+
+lemma bisim_complete:
+ âS,l,n.âfrontier,visited,visited_res:list ?.
+ all_true S visited â
+ sub_sons S l visited (frontier@visited) â
+ bisim S l n frontier visited = â©true,visited_res⪠â
+ is_bisim S visited_res l ⧠sublist ? (frontier@visited) visited_res.
+#S #l #n elim n
[#fron #vis #vis_res #_ #_ >bisim_never #H destruct
|#m #Hind *
- [-Hind #vis #vis_res #allv #H normalize in ⢠(%â?);
- #H1 destruct % // % // #p /2/
+ [(* case empty frontier *)
+ -Hind #vis #vis_res #allv #H normalize in ⢠(%â?);
+ #H1 destruct % #p
+ [#membp % [@(\P ?) @allv //| @H //]|#H1 @H1]
|#hd cases (true_or_false (beqb (\snd (\fst hd)) (\snd (\snd hd))))
- [|#H #tl #vis #vis_res #allv >(bisim_step_false ⦠H) #_ #H1 destruct]
+ [|(* case head of the frontier is non ok (absurd) *)
+ #H #tl #vis #vis_res #allv >(bisim_step_false ⦠H) #_ #H1 destruct]
+ (* frontier = hd:: tl and hd is ok *)
#H #tl #visited #visited_res #allv >(bisim_step_true ⦠H)
- cut (all_true (hd::visited))
- [#p #H cases (orb_true_l ⦠H)
- [#eqp <(proj1 ⦠(eqb_true â¦) eqp) // |@allv]]
- #allh #subH #bisim cases (Hind ⦠allh ⦠bisim) -Hind
- [* #H1 #H2 #H3 % // % // #p #H4 @H2 @memb_cons //]
- #x #a #membx
- cases (orb_true_l ⦠membx)
- [#eqhdx >(proj1 ⦠(eqb_true â¦) eqhdx)
- letin xa â â©move Bin a (\fst (\fst x)), move Bin a (\fst (\snd x))âª
- cases (true_or_false ⦠(memb (space Bin) xa (x::visited)))
- [#membxa @memb_append_l2 //
- |#membxa @memb_append_l1 @sublist_unique_append_l1 @memb_filter_l
- [whd in ⢠(??(??%%)?); cases a [@memb_hd |@memb_cons @memb_hd]
- |>membxa //
+ (* new_visited = hd::visited are all ok *)
+ cut (all_true S (hd::visited))
+ [#p #H1 cases (orb_true_l ⦠H1) [#eqp >(\P eqp) @H |@allv]]
+ (* we now exploit the induction hypothesis *)
+ #allh #subH #bisim cases (Hind ⦠allh ⦠bisim) -bisim -Hind
+ [#H1 #H2 % // #p #membp @H2 -H2 cases (memb_append ⦠membp) -membp #membp
+ [cases (orb_true_l ⦠membp) -membp #membp
+ [@memb_append_l2 >(\P membp) @memb_hd
+ |@memb_append_l1 @sublist_unique_append_l2 //
]
+ |@memb_append_l2 @memb_cons //
+ ]
+ |(* the only thing left to prove is the sub_sons invariant *)
+ #x #membx cases (orb_true_l ⦠membx)
+ [(* case x = hd *)
+ #eqhdx <(\P eqhdx) #xa #membxa
+ (* xa is a son of x; we must distinguish the case xa
+ was already visited form the case xa is new *)
+ cases (true_or_false ⦠(memb ? xa (x::visited)))
+ [(* xa visited - trivial *) #membxa @memb_append_l2 //
+ |(* xa new *) #membxa @memb_append_l1 @sublist_unique_append_l1 @memb_filter_l
+ [>membxa //|//]
]
- |#H1 letin xa â â©move Bin a (\fst (\fst x)), move Bin a (\fst (\snd x))âª
- cases (memb_append ⦠(subH x a H1))
+ |(* case x in visited *)
+ #H1 #xa #membxa cases (memb_append ⦠(subH x ⦠H1 ⦠membxa))
[#H2 (cases (orb_true_l ⦠H2))
- [#H3 @memb_append_l2 >(proj1 ⦠(eqb_true â¦) H3) @memb_hd
+ [#H3 @memb_append_l2 <(\P H3) @memb_hd
|#H3 @memb_append_l1 @sublist_unique_append_l2 @H3
]
|#H2 @memb_append_l2 @memb_cons @H2
@@ -468,48 +534,86 @@ lemma reachable_bisim:
]
]
]
-qed.
-
-axiom bisim_char: âe1,e2:pre Bin.
-(âw.(beqb (\snd (moves ? w e1)) (\snd (moves ? w e2))) = true) â
-\sem{e1}=1\sem{e2}.
-
-lemma bisim_ok2: âe1,e2:pre Bin.
- (beqb (\snd e1) (\snd e2) = true) â
- ân.âfrontier:list (space Bin).
- sub_sons [â©e1,e2âª] (frontier@[â©e1,e2âª]) â
- \fst (bisim n frontier [â©e1,e2âª]) = true â \sem{e1}=1\sem{e2}.
-#e1 #e2 #Hnil #n #frontier #init #bisim_true
-letin visited_res â (\snd (bisim n frontier [â©e1,e2âª]))
-cut (bisim n frontier [â©e1,e2âª] = â©true,visited_resâª)
- [fst_eq >snd_eq >moves_cons >moves_cons
- @(Hind â©?,?âª) @(H1 â©?,?âª) //] #all_reach
-@bisim_char #w @(H3 â©?,?âª) @(all_reach w â©?,?âª) @H2 //
qed.
-
-definition tt â ps Bin true.
-definition ff â ps Bin false.
-definition eps â pe Bin.
-definition exp1 â (ff + tt · ff).
-definition exp2 â ff · (eps + tt).
-
-definition exp3 â move Bin true (\fst (â¢exp1)).
-definition exp4 â move Bin true (\fst (â¢exp2)).
-definition exp5 â move Bin false (\fst (â¢exp1)).
-definition exp6 â move Bin false (\fst (â¢exp2)).
-
-example comp1 : bequiv 15 (â¢exp1) (â¢exp2) [ ] = false .
-normalize //
+
+definition equiv â λSig.λre1,re2:re Sig.
+ let e1 â â¢(blank ? re1) in
+ let e2 â â¢(blank ? re2) in
+ let n â S (length ? (space_enum Sig (|\fst e1|) (|\fst e2|))) in
+ let sig â (occ Sig e1 e2) in
+ (bisim ? sig n [â©e1,e2âª] []).
+
+theorem euqiv_sem : âSig.âe1,e2:re Sig.
+ \fst (equiv ? e1 e2) = true â \sem{e1} =1 \sem{e2}.
+#Sig #re1 #re2 %
+ [#H @eqP_trans [|@eqP_sym @re_embedding] @eqP_trans [||@re_embedding]
+ cut (equiv ? re1 re2 = â©true,\snd (equiv ? re1 re2)âª)
+ [(memb_single ⦠H) @(ex_intro ⦠ϵ) /2/
+ |#p #_ normalize //
+ ]
+ ]
qed.
+definition eqbnat â λn,m:nat. eqb n m.
+
+lemma eqbnat_true : ân,m. eqbnat n m = true â n = m.
+#n #m % [@eqb_true_to_eq | @eq_to_eqb_true]
+qed.
+
+definition DeqNat â mk_DeqSet nat eqbnat eqbnat_true.
+
+definition a â s DeqNat 0.
+definition b â s DeqNat 1.
+definition c â s DeqNat 2.
+
+definition exp1 â ((a·b)^*·a).
+definition exp2 â a·(b·a)^*.
+definition exp4 â (b·a)^*.
+
+definition exp5 â (a·(a·(a·b)^*·b)^*·b)^*.
+
+example
+ moves1: \snd (moves DeqNat [0;1;0] (â¢(blank ? exp2))) = true.
+normalize //
+qed.
+
+example
+ moves2: \snd (moves DeqNat [0;1;0;0;0] (â¢(blank ? exp2))) = false.
+normalize // qed.
+
+example
+ moves3: \snd (moves DeqNat [0;0;0;1;0;1;1;0;1;1] (â¢(blank ? exp5))) = true.
+normalize // qed.
+
+example
+ moves4: \snd (moves DeqNat [0;0;0;1;0;1;1;0;1;1;1;0] (â¢(blank ? exp5))) = false.
+normalize // qed.
+
+definition exp6 â a·(a ·a ·b^* + b^* ).
+definition exp7 â a · a^* · b^*.
+
+definition exp8 â a·a·a·a·a·a·a·a·(a^* ).
+definition exp9 â (a·a·a + a·a·a·a·a)^*.
+
+example ex1 : \fst (equiv ? (exp8+exp9) exp9) = true.
+normalize // qed.
+
+definition exp10 â a·a·a·a·a·a·a·a·a·a·a·a·(a^* ).
+definition exp11 â (a·a·a·a·a + a·a·a·a·a·a·a)^*.
+
+example ex2 : \fst (equiv ? (exp10+exp11) exp10) = true.
+normalize // qed.
+
+
+
+\v
\ No newline at end of file