2 include "basics/listb.ma".
4 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
9 | pp y ⇒ 〈 `y, x == y 〉
10 | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2)
11 | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2)
12 | pk e ⇒ (move ? x e)^⊛ ].
14 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
15 move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
18 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
19 move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
22 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
23 move S x i^* = (move ? x i)^⊛.
26 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
28 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b.
29 pmove ? x 〈i,b〉 = move ? x i.
32 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b.
33 a::l1 = b::l2 → a = b.
34 #A #l1 #l2 #a #b #H destruct //
37 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
38 |\fst (move ? a i)| = |i|.
40 [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
41 |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); //
46 ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S.
47 \sem{move ? a i} w ↔ \sem{i} (a::w).
52 |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
53 [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
54 |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
56 |#i1 #i2 #HI1 #HI2 #w >move_cat
57 @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
58 @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r
59 @iff_trans[||@iff_sym @deriv_middot //]
61 |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w
62 @iff_trans[|@sem_oplus]
63 @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
64 |#i1 #HI1 #w >move_star
65 @iff_trans[|@sem_ostar] >same_kernel >sem_star_w
66 @iff_trans[||@iff_sym @deriv_middot //]
71 notation > "x ↦* E" non associative with precedence 65 for @{moves ? $x $E}.
72 let rec moves (S : DeqSet) w e on w : pre S ≝
75 | cons x w' ⇒ w' ↦* (move S x (\fst e))].
77 lemma moves_empty: ∀S:DeqSet.∀e:pre S.
81 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S.
82 moves ? (a::w) e = moves ? w (move S a (\fst e)).
85 lemma moves_left : ∀S,a,w,e.
86 moves S (w@[a]) e = move S a (\fst (moves S w e)).
87 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
90 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S.
91 iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
92 #S #a #w * #i #b cases b normalize
93 [% /2/ * // #H destruct |% normalize /2/]
96 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
97 |\fst (moves ? w e)| = |\fst e|.
101 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S.
102 (\snd (moves ? w e) = true) ↔ \sem{e} w.
104 [* #i #b >moves_empty cases b % /2/
105 |#a #w1 #Hind #e >moves_cons
106 @iff_trans [||@iff_sym @not_epsilon_sem]
107 @iff_trans [||@move_ok] @Hind
111 (************************ pit state ***************************)
112 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉.
114 let rec occur (S: DeqSet) (i: re S) on i ≝
119 | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
120 | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
123 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true →
124 move S a i = pit_pre S i.
126 [#x normalize cases (a==x) normalize // #H @False_ind /2/
127 |#i1 #i2 #Hind1 #Hind2 #H >move_cat
128 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
129 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
130 |#i1 #i2 #Hind1 #Hind2 #H >move_plus
131 >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
132 >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
133 |#i #Hind #H >move_star >Hind //
137 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
139 [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 //
140 |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 //
141 |#i #Hind >move_star >Hind //
145 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
149 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
150 moves S w e = pit_pre S (\fst e).
152 [#e * #H @False_ind @H normalize #a #abs @False_ind /2/
153 |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
154 [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a)
155 @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
156 [#H2 >(\P H2) // |#H2 @H1 //]
157 |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/
163 definition cofinal ≝ λS.λp:(pre S)×(pre S).
164 \snd (\fst p) = \snd (\snd p).
166 theorem equiv_sem: ∀S:DeqSet.∀e1,e2:pre S.
167 \sem{e1} =1 \sem{e2} ↔ ∀w.cofinal ? 〈moves ? w e1,moves ? w e2〉.
170 cut (∀b1,b2. iff (b1 = true) (b2 = true) → (b1 = b2))
171 [* * // * #H1 #H2 [@sym_eq @H1 //| @H2 //]]
172 #Hcut @Hcut @iff_trans [|@decidable_sem]
173 @iff_trans [|@same_sem] @iff_sym @decidable_sem
174 |#H #w1 @iff_trans [||@decidable_sem] <H @iff_sym @decidable_sem]
177 definition occ ≝ λS.λe1,e2:pre S.
178 unique_append ? (occur S (|\fst e1|)) (occur S (|\fst e2|)).
180 lemma occ_enough: ∀S.∀e1,e2:pre S.
181 (∀w.(sublist S w (occ S e1 e2))→ cofinal ? 〈moves ? w e1,moves ? w e2〉)
182 →∀w.cofinal ? 〈moves ? w e1,moves ? w e2〉.
184 cases (decidable_sublist S w (occ S e1 e2)) [@H] -H #H
185 >to_pit [2: @(not_to_not … H) #H1 #a #memba @sublist_unique_append_l1 @H1 //]
186 >to_pit [2: @(not_to_not … H) #H1 #a #memba @sublist_unique_append_l2 @H1 //]
190 lemma equiv_sem_occ: ∀S.∀e1,e2:pre S.
191 (∀w.(sublist S w (occ S e1 e2))→ cofinal ? 〈moves ? w e1,moves ? w e2〉)
192 → \sem{e1}=1\sem{e2}.
193 #S #e1 #e2 #H @(proj2 … (equiv_sem …)) @occ_enough #w @H
196 definition sons ≝ λS:DeqSet.λl:list S.λp:(pre S)×(pre S).
197 map ?? (λa.〈move S a (\fst (\fst p)),move S a (\fst (\snd p))〉) l.
199 lemma memb_sons: ∀S,l.∀p,q:(pre S)×(pre S). memb ? p (sons ? l q) = true →
200 ∃a.(move ? a (\fst (\fst q)) = \fst p ∧
201 move ? a (\fst (\snd q)) = \snd p).
202 #S #l elim l [#p #q normalize in ⊢ (%→?); #abs @False_ind /2/]
203 #a #tl #Hind #p #q #H cases (orb_true_l … H) -H
204 [#H @(ex_intro … a) >(\P H) /2/ |#H @Hind @H]
207 definition is_bisim ≝ λS:DeqSet.λl:list ?.λalpha:list S.
208 ∀p:(pre S)×(pre S). memb ? p l = true → cofinal ? p ∧ (sublist ? (sons ? alpha p) l).
210 lemma bisim_to_sem: ∀S:DeqSet.∀l:list ?.∀e1,e2: pre S.
211 is_bisim S l (occ S e1 e2) → memb ? 〈e1,e2〉 l = true → \sem{e1}=1\sem{e2}.
212 #S #l #e1 #e2 #Hbisim #Hmemb @equiv_sem_occ
213 #w #Hsub @(proj1 … (Hbisim 〈moves S w e1,moves S w e2〉 ?))
214 lapply Hsub @(list_elim_left … w) [//]
215 #a #w1 #Hind #Hsub >moves_left >moves_left @(proj2 …(Hbisim …(Hind ?)))
216 [#x #Hx @Hsub @memb_append_l1 //
217 |cut (memb S a (occ S e1 e2) = true) [@Hsub @memb_append_l2 //] #occa
223 let rec bisim S l n (frontier,visited: list ?) on n ≝
225 [ O ⇒ 〈false,visited〉 (* assert false *)
228 [ nil ⇒ 〈true,visited〉
230 if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
231 bisim S l m (unique_append ? (filter ? (λx.notb (memb ? x (hd::visited)))
232 (sons S l hd)) tl) (hd::visited)
237 lemma unfold_bisim: ∀S,l,n.∀frontier,visited: list ?.
238 bisim S l n frontier visited =
240 [ O ⇒ 〈false,visited〉 (* assert false *)
243 [ nil ⇒ 〈true,visited〉
245 if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
246 bisim S l m (unique_append ? (filter ? (λx.notb(memb ? x (hd::visited)))
247 (sons S l hd)) tl) (hd::visited)
251 #S #l #n cases n // qed.
253 lemma bisim_never: ∀S,l.∀frontier,visited: list ?.
254 bisim S l O frontier visited = 〈false,visited〉.
255 #frontier #visited >unfold_bisim //
258 lemma bisim_end: ∀Sig,l,m.∀visited: list ?.
259 bisim Sig l (S m) [] visited = 〈true,visited〉.
260 #n #visisted >unfold_bisim //
263 lemma bisim_step_true: ∀Sig,l,m.∀p.∀frontier,visited: list ?.
264 beqb (\snd (\fst p)) (\snd (\snd p)) = true →
265 bisim Sig l (S m) (p::frontier) visited =
266 bisim Sig l m (unique_append ? (filter ? (λx.notb(memb ? x (p::visited)))
267 (sons Sig l p)) frontier) (p::visited).
268 #Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
271 lemma bisim_step_false: ∀Sig,l,m.∀p.∀frontier,visited: list ?.
272 beqb (\snd (\fst p)) (\snd (\snd p)) = false →
273 bisim Sig l (S m) (p::frontier) visited = 〈false,visited〉.
274 #Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test //
277 lemma notb_eq_true_l: ∀b. notb b = true → b = false.
278 #b cases b normalize //
281 let rec pitem_enum S (i:re S) on i ≝
285 | s y ⇒ [ps S y; pp S y]
286 | o i1 i2 ⇒ compose ??? (po S) (pitem_enum S i1) (pitem_enum S i2)
287 | c i1 i2 ⇒ compose ??? (pc S) (pitem_enum S i1) (pitem_enum S i2)
288 | k i ⇒ map ?? (pk S) (pitem_enum S i)
291 lemma pitem_enum_complete : ∀S.∀i:pitem S.
292 memb (DeqItem S) i (pitem_enum S (|i|)) = true.
295 |3,4:#c normalize >(\b (refl … c)) //
296 |5,6:#i1 #i2 #Hind1 #Hind2 @(memb_compose (DeqItem S) (DeqItem S)) //
297 |#i #Hind @(memb_map (DeqItem S)) //
301 definition pre_enum ≝ λS.λi:re S.
302 compose ??? (λi,b.〈i,b〉) (pitem_enum S i) [true;false].
304 lemma pre_enum_complete : ∀S.∀e:pre S.
305 memb ? e (pre_enum S (|\fst e|)) = true.
306 #S * #i #b @(memb_compose (DeqItem S) DeqBool ? (λi,b.〈i,b〉))
307 // cases b normalize //
310 definition space_enum ≝ λS.λi1,i2:re S.
311 compose ??? (λe1,e2.〈e1,e2〉) (pre_enum S i1) (pre_enum S i2).
313 lemma space_enum_complete : ∀S.∀e1,e2: pre S.
314 memb ? 〈e1,e2〉 (space_enum S (|\fst e1|) (|\fst e2|)) = true.
315 #S #e1 #e2 @(memb_compose … (λi,b.〈i,b〉))
318 definition all_reachable ≝ λS.λe1,e2:pre S.λl: list ?.
320 ∀p. memb ? p l = true →
321 ∃w.(moves S w e1 = \fst p) ∧ (moves S w e2 = \snd p).
323 definition disjoint ≝ λS:DeqSet.λl1,l2.
324 ∀p:S. memb S p l1 = true → memb S p l2 = false.
326 lemma bisim_correct: ∀S.∀e1,e2:pre S.\sem{e1}=1\sem{e2} →
327 ∀l,n.∀frontier,visited:list ((pre S)×(pre S)).
328 |space_enum S (|\fst e1|) (|\fst e2|)| < n + |visited|→
329 all_reachable S e1 e2 visited →
330 all_reachable S e1 e2 frontier →
331 disjoint ? frontier visited →
332 \fst (bisim S l n frontier visited) = true.
333 #Sig #e1 #e2 #same #l #n elim n
334 [#frontier #visited #abs * #unique #H @False_ind @(absurd … abs)
335 @le_to_not_lt @sublist_length // * #e11 #e21 #membp
336 cut ((|\fst e11| = |\fst e1|) ∧ (|\fst e21| = |\fst e2|))
337 [|* #H1 #H2 <H1 <H2 @space_enum_complete]
338 cases (H … membp) #w * #we1 #we2 <we1 <we2 % >same_kernel_moves //
339 |#m #HI * [#visited #vinv #finv >bisim_end //]
340 #p #front_tl #visited #Hn * #u_visited #r_visited * #u_frontier #r_frontier
342 cut (∃w.(moves ? w e1 = \fst p) ∧ (moves ? w e2 = \snd p))
343 [@(r_frontier … (memb_hd … ))] #rp
344 cut (beqb (\snd (\fst p)) (\snd (\snd p)) = true)
345 [cases rp #w * #fstp #sndp <fstp <sndp @(\b ?)
346 @(proj1 … (equiv_sem … )) @same] #ptest
347 >(bisim_step_true … ptest) @HI -HI
349 |% [whd in ⊢ (??%?); >(disjoint … (memb_hd …)) whd in ⊢ (??%?); //
350 |#p1 #H (cases (orb_true_l … H)) [#eqp >(\P eqp) // |@r_visited]
352 |whd % [@unique_append_unique @(andb_true_r … u_frontier)]
353 @unique_append_elim #q #H
354 [cases (memb_sons … (memb_filter_memb … H)) -H
355 #a * #m1 #m2 cases rp #w1 * #mw1 #mw2 @(ex_intro … (w1@[a]))
356 >moves_left >moves_left >mw1 >mw2 >m1 >m2 % //
357 |@r_frontier @memb_cons //
359 |@unique_append_elim #q #H
360 [@injective_notb @(filter_true … H)
361 |cut ((q==p) = false)
362 [|#Hpq whd in ⊢ (??%?); >Hpq @disjoint @memb_cons //]
363 cases (andb_true … u_frontier) #notp #_ @(\bf ?)
364 @(not_to_not … not_eq_true_false) #eqqp <notp <eqqp >H //
370 definition all_true ≝ λS.λl.∀p:(pre S) × (pre S). memb ? p l = true →
371 (beqb (\snd (\fst p)) (\snd (\snd p)) = true).
373 definition sub_sons ≝ λS,l,l1,l2.∀x:(pre S) × (pre S).
374 memb ? x l1 = true → sublist ? (sons ? l x) l2.
376 lemma bisim_complete:
377 ∀S,l,n.∀frontier,visited,visited_res:list ?.
379 sub_sons S l visited (frontier@visited) →
380 bisim S l n frontier visited = 〈true,visited_res〉 →
381 is_bisim S visited_res l ∧ sublist ? (frontier@visited) visited_res.
383 [#fron #vis #vis_res #_ #_ >bisim_never #H destruct
385 [(* case empty frontier *)
386 -Hind #vis #vis_res #allv #H normalize in ⊢ (%→?);
388 [#membp % [@(\P ?) @allv //| @H //]|#H1 @H1]
389 |#hd cases (true_or_false (beqb (\snd (\fst hd)) (\snd (\snd hd))))
390 [|(* case head of the frontier is non ok (absurd) *)
391 #H #tl #vis #vis_res #allv >(bisim_step_false … H) #_ #H1 destruct]
392 (* frontier = hd:: tl and hd is ok *)
393 #H #tl #visited #visited_res #allv >(bisim_step_true … H)
394 (* new_visited = hd::visited are all ok *)
395 cut (all_true S (hd::visited))
396 [#p #H1 cases (orb_true_l … H1) [#eqp >(\P eqp) @H |@allv]]
397 (* we now exploit the induction hypothesis *)
398 #allh #subH #bisim cases (Hind … allh … bisim) -bisim -Hind
399 [#H1 #H2 % // #p #membp @H2 -H2 cases (memb_append … membp) -membp #membp
400 [cases (orb_true_l … membp) -membp #membp
401 [@memb_append_l2 >(\P membp) @memb_hd
402 |@memb_append_l1 @sublist_unique_append_l2 //
404 |@memb_append_l2 @memb_cons //
406 |(* the only thing left to prove is the sub_sons invariant *)
407 #x #membx cases (orb_true_l … membx)
409 #eqhdx <(\P eqhdx) #xa #membxa
410 (* xa is a son of x; we must distinguish the case xa
411 was already visited form the case xa is new *)
412 cases (true_or_false … (memb ? xa (x::visited)))
413 [(* xa visited - trivial *) #membxa @memb_append_l2 //
414 |(* xa new *) #membxa @memb_append_l1 @sublist_unique_append_l1 @memb_filter_l
417 |(* case x in visited *)
418 #H1 #xa #membxa cases (memb_append … (subH x … H1 … membxa))
419 [#H2 (cases (orb_true_l … H2))
420 [#H3 @memb_append_l2 <(\P H3) @memb_hd
421 |#H3 @memb_append_l1 @sublist_unique_append_l2 @H3
423 |#H2 @memb_append_l2 @memb_cons @H2
430 definition equiv ≝ λSig.λre1,re2:re Sig.
431 let e1 ≝ •(blank ? re1) in
432 let e2 ≝ •(blank ? re2) in
433 let n ≝ S (length ? (space_enum Sig (|\fst e1|) (|\fst e2|))) in
434 let sig ≝ (occ Sig e1 e2) in
435 (bisim ? sig n [〈e1,e2〉] []).
437 theorem euqiv_sem : ∀Sig.∀e1,e2:re Sig.
438 \fst (equiv ? e1 e2) = true ↔ \sem{e1} =1 \sem{e2}.
440 [#H @eqP_trans [|@eqP_sym @re_embedding] @eqP_trans [||@re_embedding]
441 cut (equiv ? re1 re2 = 〈true,\snd (equiv ? re1 re2)〉)
443 cases (bisim_complete … Hcut)
444 [2,3: #p whd in ⊢ ((??%?)→?); #abs @False_ind /2/]
445 #Hbisim #Hsub @(bisim_to_sem … Hbisim)
447 |#H @(bisim_correct ? (•(blank ? re1)) (•(blank ? re2)))
448 [@eqP_trans [|@re_embedding] @eqP_trans [|@H] @eqP_sym @re_embedding
450 |% // #p whd in ⊢ ((??%?)→?); #abs @False_ind /2/
451 |% // #p #H >(memb_single … H) @(ex_intro … ϵ) /2/
457 lemma eqbnat_true : ∀n,m. eqbnat n m = true ↔ n = m.
458 #n #m % [@eqbnat_true_to_eq | @eq_to_eqbnat_true]
461 definition DeqNat ≝ mk_DeqSet nat eqbnat eqbnat_true.
463 definition a ≝ s DeqNat O.
464 definition b ≝ s DeqNat (S O).
465 definition c ≝ s DeqNat (S (S O)).
467 definition exp1 ≝ ((a·b)^*·a).
468 definition exp2 ≝ a·(b·a)^*.
469 definition exp4 ≝ (b·a)^*.
471 definition exp6 ≝ a·(a ·a ·b^* + b^* ).
472 definition exp7 ≝ a · a^* · b^*.
474 definition exp8 ≝ a·a·a·a·a·a·a·a·(a^* ).
475 definition exp9 ≝ (a·a·a + a·a·a·a·a)^*.
477 example ex1 : \fst (equiv ? (exp8+exp9) exp9) = true.