]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/re/moves.ma
Splitted re into lang.ma nd re.ma
[helm.git] / matita / matita / lib / re / moves.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "re/re.ma".
16 include "basics/lists/listb.ma".
17
18 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
19  match E with
20   [ pz ⇒ 〈 `∅, false 〉
21   | pe ⇒ 〈 ϵ, false 〉
22   | ps y ⇒ 〈 `y, false 〉
23   | pp y ⇒ 〈 `y, x == y 〉
24   | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2) 
25   | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2)
26   | pk e ⇒ (move ? x e)^⊛ ].
27   
28 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
29   move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
30 // qed.
31
32 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
33   move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
34 // qed.
35
36 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
37   move S x i^* = (move ? x i)^⊛.
38 // qed.
39
40 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
41
42 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b. 
43   pmove ? x 〈i,b〉 = move ? x i.
44 // qed.
45
46 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b. 
47   a::l1 = b::l2 → a = b.
48 #A #l1 #l2 #a #b #H destruct //
49 qed. 
50
51 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
52   |\fst (move ? a i)| = |i|.
53 #S #a #i elim i //
54   [#i1 #i2 >move_cat #H1 #H2 whd in ⊢ (???%); <H1 <H2 //
55   |#i1 #i2 >move_plus #H1 #H2 whd in ⊢ (???%); <H1 <H2 //
56   ]
57 qed.
58
59 theorem move_ok:
60  ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S. 
61    \sem{move ? a i} w ↔ \sem{i} (a::w).
62 #S #a #i elim i 
63   [normalize /2/
64   |normalize /2/
65   |normalize /2/
66   |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
67     [>(proj1 … (eqb_true …) H) % 
68       [* // #bot @False_ind //| #H1 destruct /2/]
69     |% [#bot @False_ind // 
70        | #H1 destruct @(absurd ((a==a)=true))
71          [>(proj2 … (eqb_true …) (refl …)) // | /2/] 
72        ]
73     ]
74   |#i1 #i2 #HI1 #HI2 #w >(sem_cat S i1 i2) >move_cat
75    @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
76    @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r %
77     [* #w1 * #w2 * * #eqw #w1in #w2in @(ex_intro … (a::w1))
78      @(ex_intro … w2) % // % normalize // cases (HI1 w1) /2/
79     |* #w1 * #w2 * cases w1
80       [* #_ #H @False_ind /2/
81       |#x #w3 * #eqaw normalize in eqaw; destruct #w3in #w2in 
82       @(ex_intro … w3) @(ex_intro … w2) % // % // cases (HI1 w3) /2/
83       ]
84     ]
85   |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w 
86    @iff_trans[|@sem_oplus] 
87    @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
88   |#i1 #HI1 #w >move_star 
89    @iff_trans[|@sem_ostar] >same_kernel >sem_star_w %
90     [* #w1 * #w2 * * #eqw #w1in #w2in 
91      @(ex_intro … (a::w1)) @(ex_intro … w2) % // % normalize //
92      cases (HI1 w1 ) /2/
93     |* #w1 * #w2 * cases w1
94       [* #_ #H @False_ind /2/
95       |#x #w3 * #eqaw normalize in eqaw; destruct #w3in #w2in 
96        @(ex_intro … w3) @(ex_intro … w2) % // % // cases (HI1 w3) /2/
97       ]
98     ]
99   ]
100 qed.
101     
102 notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}.
103 let rec moves (S : DeqSet) w e on w : pre S ≝
104  match w with
105   [ nil ⇒ e
106   | cons x w' ⇒ w' ↦* (move S x (\fst e))].
107
108 lemma moves_empty: ∀S:DeqSet.∀e:pre S. 
109   moves ? [ ] e = e.
110 // qed.
111
112 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S. 
113   moves ? (a::w)  e = moves ? w (move S a (\fst e)).
114 // qed.
115
116 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S. 
117   iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
118 #S #a #w * #i #b cases b normalize 
119   [% /2/ * // #H destruct |% normalize /2/]
120 qed.
121
122 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
123   |\fst (moves ? w e)| = |\fst e|.
124 #S #w elim w //
125 qed.
126
127 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S. 
128    (\snd (moves ? w e) = true)  ↔ \sem{e} w.
129 #S #w elim w 
130  [* #i #b >moves_empty cases b % /2/
131  |#a #w1 #Hind #e >moves_cons
132   @iff_trans [||@iff_sym @not_epsilon_sem]
133   @iff_trans [||@move_ok] @Hind
134  ]
135 qed.
136
137 lemma not_true_to_false: ∀b.b≠true → b =false.
138 #b * cases b // #H @False_ind /2/ 
139 qed. 
140
141 theorem equiv_sem: ∀S:DeqSet.∀e1,e2:pre S. 
142   iff (\sem{e1} =1 \sem{e2}) (∀w.\snd (moves ? w e1) = \snd (moves ? w e2)).
143 #S #e1 #e2 % 
144 [#same_sem #w 
145   cut (∀b1,b2. iff (b1 = true) (b2 = true) → (b1 = b2)) 
146     [* * // * #H1 #H2 [@sym_eq @H1 //| @H2 //]]
147   #Hcut @Hcut @iff_trans [|@decidable_sem] 
148   @iff_trans [|@same_sem] @iff_sym @decidable_sem
149 |#H #w1 @iff_trans [||@decidable_sem] <H @iff_sym @decidable_sem]
150 qed.
151
152 lemma moves_left : ∀S,a,w,e. 
153   moves S (w@[a]) e = move S a (\fst (moves S w e)). 
154 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
155 qed.
156
157 definition in_moves ≝ λS:DeqSet.λw.λe:pre S. \snd(w ↦* e).
158
159 (*
160 coinductive equiv (S:DeqSet) : pre S → pre S → Prop ≝
161  mk_equiv:
162   ∀e1,e2: pre S.
163    \snd e1  = \snd e2 →
164     (∀x. equiv S (move ? x (\fst e1)) (move ? x (\fst e2))) →
165      equiv S e1 e2.
166 *)
167
168 definition beqb ≝ λb1,b2.
169   match b1 with
170   [ true ⇒ b2
171   | false ⇒ notb b2
172   ].
173
174 lemma beqb_ok: ∀b1,b2. iff (beqb b1 b2 = true) (b1 = b2).
175 #b1 #b2 cases b1 cases b2 normalize /2/
176 qed.
177
178 definition Bin ≝ mk_DeqSet bool beqb beqb_ok. 
179
180 let rec beqitem S (i1,i2: pitem S) on i1 ≝ 
181   match i1 with
182   [ pz ⇒ match i2 with [ pz ⇒ true | _ ⇒ false]
183   | pe ⇒ match i2 with [ pe ⇒ true | _ ⇒ false]
184   | ps y1 ⇒ match i2 with [ ps y2 ⇒ y1==y2 | _ ⇒ false]
185   | pp y1 ⇒ match i2 with [ pp y2 ⇒ y1==y2 | _ ⇒ false]
186   | po i11 i12 ⇒ match i2 with 
187     [ po i21 i22 ⇒ beqitem S i11 i21 ∧ beqitem S i12 i22
188     | _ ⇒ false]
189   | pc i11 i12 ⇒ match i2 with 
190     [ pc i21 i22 ⇒ beqitem S i11 i21 ∧ beqitem S i12 i22
191     | _ ⇒ false]
192   | pk i11 ⇒ match i2 with [ pk i21 ⇒ beqitem S i11 i21 | _ ⇒ false]
193   ].
194
195 axiom beqitem_ok: ∀S,i1,i2. iff (beqitem S i1 i2 = true) (i1 = i2). 
196
197 definition DeqItem ≝ λS.
198   mk_DeqSet (pitem S) (beqitem S) (beqitem_ok S).
199
200 definition beqpre ≝ λS:DeqSet.λe1,e2:pre S. 
201   beqitem S (\fst e1) (\fst e2) ∧ beqb (\snd e1) (\snd e2).
202   
203 definition beqpairs ≝ λS:DeqSet.λp1,p2:(pre S)×(pre S). 
204   beqpre S (\fst p1) (\fst p2) ∧ beqpre S (\snd p1) (\snd p2).
205   
206 axiom beqpairs_ok: ∀S,p1,p2. iff (beqpairs S p1 p2 = true) (p1 = p2). 
207
208 definition space ≝ λS.mk_DeqSet ((pre S)×(pre S)) (beqpairs S) (beqpairs_ok S).
209
210 (* (sons S l p) computes all sons of p relative to characters in l *)
211
212 definition sons ≝ λS:DeqSet.λl:list S.λp:space S. 
213  map ?? (λa.〈move S a (\fst (\fst p)),move S a (\fst (\snd p))〉) l.
214
215 lemma memb_sons: ∀S,l,p,q. memb (space S) p (sons S l q) = true →
216   ∃a.(move ? a (\fst (\fst q)) = \fst p ∧
217       move ? a (\fst (\snd q)) = \snd p).
218 #S #l elim l [#p #q normalize in ⊢ (%→?); #abs @False_ind /2/] 
219 #a #tl #Hind #p #q #H cases (orb_true_l … H) -H
220   [#H @(ex_intro … a) <(proj1 … (eqb_true …)H) /2/
221   |#H @Hind @H
222   ]
223 qed.
224
225 let rec bisim S l n (frontier,visited: list (space S)) on n ≝
226   match n with 
227   [ O ⇒ 〈false,visited〉 (* assert false *)
228   | S m ⇒ 
229     match frontier with
230     [ nil ⇒ 〈true,visited〉
231     | cons hd tl ⇒
232       if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
233         bisim S l m (unique_append ? (filter ? (λx.notb (memb ? x (hd::visited))) 
234         (sons S l hd)) tl) (hd::visited)
235       else 〈false,visited〉
236     ]
237   ].
238   
239 lemma unfold_bisim: ∀S,l,n.∀frontier,visited: list (space S).
240   bisim S l n frontier visited =
241   match n with 
242   [ O ⇒ 〈false,visited〉 (* assert false *)
243   | S m ⇒ 
244     match frontier with
245     [ nil ⇒ 〈true,visited〉
246     | cons hd tl ⇒
247       if beqb (\snd (\fst hd)) (\snd (\snd hd)) then
248         bisim S l m (unique_append ? (filter ? (λx.notb(memb ? x (hd::visited))) 
249           (sons S l hd)) tl) (hd::visited)
250       else 〈false,visited〉
251     ]
252   ].
253 #S #l #n cases n // qed.
254   
255 lemma bisim_never: ∀S,l.∀frontier,visited: list (space S).
256   bisim S l O frontier visited = 〈false,visited〉.
257 #frontier #visited >unfold_bisim // 
258 qed.
259
260 lemma bisim_end: ∀Sig,l,m.∀visited: list (space Sig).
261   bisim Sig l (S m) [] visited = 〈true,visited〉.
262 #n #visisted >unfold_bisim // 
263 qed.
264
265 lemma bisim_step_true: ∀Sig,l,m.∀p.∀frontier,visited: list (space Sig).
266 beqb (\snd (\fst p)) (\snd (\snd p)) = true →
267   bisim Sig l (S m) (p::frontier) visited = 
268   bisim Sig l m (unique_append ? (filter ? (λx.notb(memb (space Sig) x (p::visited))) 
269     (sons Sig l p)) frontier) (p::visited).
270 #Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test // 
271 qed.
272
273 lemma bisim_step_false: ∀Sig,l,m.∀p.∀frontier,visited: list (space Sig).
274 beqb (\snd (\fst p)) (\snd (\snd p)) = false →
275   bisim Sig l (S m) (p::frontier) visited = 〈false,visited〉.
276 #Sig #l #m #p #frontier #visited #test >unfold_bisim normalize nodelta >test // 
277 qed.
278  
279 definition visited_inv ≝ λS.λe1,e2:pre S.λvisited: list (space S).
280 uniqueb ? visited = true ∧  
281   ∀p. memb ? p visited = true → 
282    (∃w.(moves S w e1 = \fst p) ∧ (moves S w e2 = \snd p)) ∧ 
283    (beqb (\snd (\fst p)) (\snd (\snd p)) = true).
284   
285 definition frontier_inv ≝ λS.λfrontier,visited: list (space S).
286 uniqueb ? frontier = true ∧ 
287 ∀p. memb ? p frontier = true →  
288   memb ? p visited = false ∧
289   ∃p1.((memb ? p1 visited = true) ∧
290    (∃a. move ? a (\fst (\fst p1)) = \fst p ∧ 
291         move ? a (\fst (\snd p1)) = \snd p)).
292
293 (* lemma andb_true: ∀b1,b2:bool. 
294   (b1 ∧ b2) = true → (b1 = true) ∧ (b2 = true).
295 #b1 #b2 cases b1 normalize #H [>H /2/ |@False_ind /2/].
296 qed.
297
298 lemma andb_true_r: ∀b1,b2:bool. 
299   (b1 = true) ∧ (b2 = true) → (b1 ∧ b2) = true.
300 #b1 #b2 cases b1 normalize * // 
301 qed. *)
302
303 lemma notb_eq_true_l: ∀b. notb b = true → b = false.
304 #b cases b normalize //
305 qed.
306
307 (*
308 lemma notb_eq_true_r: ∀b. b = false → notb b = true.
309 #b cases b normalize //
310 qed.
311  
312 lemma notb_eq_false_l:∀b. notb b = false → b = true.
313 #b cases b normalize //
314 qed.
315
316 lemma notb_eq_false_r:∀b. b = true → notb b = false.
317 #b cases b normalize //
318 qed. *)
319
320 (* include "arithmetics/exp.ma". *)
321
322 let rec pos S (i:re S) on i ≝ 
323   match i with
324   [ z ⇒ 0
325   | e ⇒ 0
326   | s y ⇒ 1
327   | o i1 i2 ⇒ pos S i1 + pos S i2
328   | c i1 i2 ⇒ pos S i1 + pos S i2
329   | k i ⇒ pos S i
330   ].
331
332   
333 let rec pitem_enum S (i:re S) on i ≝
334   match i with
335   [ z ⇒ [pz S]
336   | e ⇒ [pe S]
337   | s y ⇒ [ps S y; pp S y]
338   | o i1 i2 ⇒ compose ??? (po S) (pitem_enum S i1) (pitem_enum S i2)
339   | c i1 i2 ⇒ compose ??? (pc S) (pitem_enum S i1) (pitem_enum S i2)
340   | k i ⇒ map ?? (pk S) (pitem_enum S i)
341   ].
342
343 (* axiom pitem_enum_complete: ∀S:DeqSet.∀i: pitem S.
344   memb ((pitem S)×(pitem S)) i (pitem_enum ? (forget ? i)) = true. *)
345 (*
346 #i elim i
347   [//
348   |//
349   |* //
350   |* // 
351   |#i1 #i2 #Hind1 #Hind2 @memb_compose //
352   |#i1 #i2 #Hind1 #Hind2 @memb_compose //
353   |
354 *)
355
356 definition pre_enum ≝ λS.λi:re S.
357   compose ??? (λi,b.〈i,b〉) (pitem_enum S i) [true;false].
358  
359 definition space_enum ≝ λS.λi1,i2:re S.
360   compose ??? (λe1,e2.〈e1,e2〉) (pre_enum S i1) (pre_enum S i1).
361
362 axiom space_enum_complete : ∀S.∀e1,e2: pre S.
363   memb (space S) 〈e1,e2〉 (space_enum S (|\fst e1|) (|\fst e2|)) = true.
364    
365 lemma bisim_ok1: ∀S.∀e1,e2:pre S.\sem{e1}=1\sem{e2} → 
366  ∀l,n.∀frontier,visited:list (space S).
367  |space_enum S (|\fst e1|) (|\fst e2|)| < n + |visited|→
368  visited_inv S e1 e2 visited →  frontier_inv S frontier visited →
369  \fst (bisim S l n frontier visited) = true.
370 #Sig #e1 #e2 #same #l #n elim n 
371   [#frontier #visited #abs * #unique #H @False_ind @(absurd … abs)
372    @le_to_not_lt @sublist_length // * #e11 #e21 #membp 
373    cut ((|\fst e11| = |\fst e1|) ∧ (|\fst e21| = |\fst e2|))
374    [|* #H1 #H2 <H1 <H2 @space_enum_complete]
375    cases (H … membp) * #w * #we1 #we2 #_
376    <we1 <we2 % //    
377   |#m #HI * [#visited #vinv #finv >bisim_end //]
378    #p #front_tl #visited #Hn * #u_visited #vinv * #u_frontier #finv
379    cases (finv p (memb_hd …)) #Hp * #p2 * #visited_p2
380    * #a * #movea1 #movea2 
381    cut (∃w.(moves Sig w e1 = \fst p) ∧ (moves Sig w e2 = \snd p))
382      [cases (vinv … visited_p2) -vinv * #w1 * #mw1 #mw2 #_
383       @(ex_intro … (w1@[a])) /2/] 
384    -movea2 -movea1 -a -visited_p2 -p2 #reachp
385    cut (beqb (\snd (\fst p)) (\snd (\snd p)) = true)
386      [cases reachp #w * #move_e1 #move_e2 <move_e1 <move_e2
387       @(proj2 … (beqb_ok … )) @(proj1 … (equiv_sem … )) @same 
388      |#ptest >(bisim_step_true … ptest) @HI -HI
389        [<plus_n_Sm //
390        |% [whd in ⊢ (??%?); >Hp whd in ⊢ (??%?); //]
391         #p1 #H (cases (orb_true_l … H))
392          [#eqp <(proj1 … (eqb_true (space Sig) ? p1) eqp) % // 
393          |#visited_p1 @(vinv … visited_p1)
394          ]
395        |whd % [@unique_append_unique @(andb_true_r … u_frontier)]
396         @unique_append_elim #q #H
397          [% 
398            [@notb_eq_true_l @(filter_true … H) 
399            |@(ex_intro … p) % // 
400             @(memb_sons … (memb_filter_memb … H))
401            ]
402          |cases (finv q ?) [|@memb_cons //]
403           #nvq * #p1 * #Hp1 #reach %
404            [cut ((p==q) = false) [|#Hpq whd in ⊢ (??%?); >Hpq @nvq]
405             cases (andb_true … u_frontier) #notp #_ 
406             @(not_memb_to_not_eq … H) @notb_eq_true_l @notp 
407            |cases (proj2 … (finv q ?)) 
408              [#p1 *  #Hp1 #reach @(ex_intro … p1) % // @memb_cons //
409              |@memb_cons //
410              ]
411           ]
412         ]  
413       ]
414     ]
415   ]
416 qed.
417
418 definition all_true ≝ λS.λl.∀p. memb (space S) p l = true → 
419   (beqb (\snd (\fst p)) (\snd (\snd p)) = true).
420
421 definition sub_sons ≝ λS,l,l1,l2.∀x,a. 
422 memb (space S) x l1 = true → memb S a l = true →
423   memb (space S) 〈move ? a (\fst (\fst x)), move ? a (\fst (\snd x))〉 l2 = true.
424
425 lemma reachable_bisim: 
426  ∀S,l,n.∀frontier,visited,visited_res:list (space S).
427  all_true S visited →
428  sub_sons S l visited (frontier@visited) →
429  bisim S l n frontier visited = 〈true,visited_res〉 → 
430   (sub_sons S l visited_res visited_res ∧ 
431    sublist ? visited visited_res ∧
432    all_true S visited_res).
433 #S #l #n elim n
434   [#fron #vis #vis_res #_ #_ >bisim_never #H destruct
435   |#m #Hind * 
436     [(* case empty frontier *)
437      -Hind #vis #vis_res #allv #H normalize in  ⊢ (%→?);
438      #H1 destruct % // % // #p /2/ 
439     |#hd cases (true_or_false (beqb (\snd (\fst hd)) (\snd (\snd hd))))
440       [|(* case head of the frontier is non ok (absurd) *)
441        #H #tl #vis #vis_res #allv >(bisim_step_false … H) #_ #H1 destruct]
442      (* frontier = hd:: tl and hd is ok *)
443      #H #tl #visited #visited_res #allv >(bisim_step_true … H)
444      (* new_visited = hd::visited are all ok *)
445      cut (all_true S (hd::visited)) 
446       [#p #H cases (orb_true_l … H) 
447         [#eqp <(proj1 … (eqb_true …) eqp) // |@allv]]
448      (* we now exploit the induction hypothesis *)
449      #allh #subH #bisim cases (Hind … allh … bisim) -Hind
450       [* #H1 #H2 #H3 % // % // #p #H4 @H2 @memb_cons //]
451      (* the only thing left to prove is the sub_sons invariant *)  
452      #x #a #membx #memba
453      cases (orb_true_l … membx)
454       [(* case x = hd *) 
455        #eqhdx >(proj1 … (eqb_true …) eqhdx)
456        (* xa is the son of x w.r.t. a; we must distinguish the case xa 
457         was already visited form the case xa is new *)
458        letin xa ≝ 〈move S a (\fst (\fst x)), move S a (\fst (\snd x))〉
459        cases (true_or_false … (memb (space S) xa (x::visited)))
460         [(* xa visited - trivial *) #membxa @memb_append_l2 //
461         |(* xa new *) #membxa @memb_append_l1 @sublist_unique_append_l1 @memb_filter_l
462           [>membxa //
463           |(* this can be probably improved *)
464            generalize in match memba; -memba elim l
465             [whd in ⊢ (??%?→?); #abs @False_ind /2/
466             |#b #others #Hind #memba cases (orb_true_l … memba) #H
467               [>(proj1 … (eqb_true …) H) @memb_hd
468               |@memb_cons @Hind //
469               ]
470             ]
471           ]
472         ]
473       |(* case x in visited *)
474        #H1 letin xa ≝ 〈move S a (\fst (\fst x)), move S a (\fst (\snd x))〉
475        cases (memb_append … (subH x a H1 memba))  
476         [#H2 (cases (orb_true_l … H2)) 
477           [#H3 @memb_append_l2 >(proj1 … (eqb_true …) H3) @memb_hd
478           |#H3 @memb_append_l1 @sublist_unique_append_l2 @H3
479           ]
480         |#H2 @memb_append_l2 @memb_cons @H2
481         ]
482       ]
483     ]
484   ]
485 qed.
486
487 (* pit state *)
488 let rec blank_item (S: DeqSet) (i: re S) on i :pitem S ≝
489  match i with
490   [ z ⇒ `∅
491   | e ⇒ ϵ
492   | s y ⇒ `y
493   | o e1 e2 ⇒ (blank_item S e1) + (blank_item S e2) 
494   | c e1 e2 ⇒ (blank_item S e1) · (blank_item S e2)
495   | k e ⇒ (blank_item S e)^* ].
496  
497 definition pit_pre ≝ λS.λi.〈blank_item S (|i|), false〉. 
498
499 let rec occur (S: DeqSet) (i: re S) on i ≝  
500   match i with
501   [ z ⇒ [ ]
502   | e ⇒ [ ]
503   | s y ⇒ [y]
504   | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
505   | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
506   | k e ⇒ occur S e].
507   
508 axiom memb_single: ∀S,a,x. memb S a [x] = true → a = x.
509
510 axiom tech: ∀b. b ≠ true → b = false.
511 axiom tech2: ∀b. b = false → b ≠ true.
512
513 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) = false →
514   move S a i  = pit_pre S i.
515 #S #a #i elim i //
516   [#x cases (true_or_false (a==x)) 
517     [#H >(proj1 …(eqb_true …) H) whd in ⊢ ((??%?)→?); 
518      >(proj2 …(eqb_true …) (refl …)) whd in ⊢ ((??%?)→?); #abs @False_ind /2/
519     |#H normalize >H //
520     ]
521   |#i1 #i2 #Hind1 #Hind2 #H >move_cat >Hind1 [2:@tech 
522    @(not_to_not … (tech2 … H)) #H1 @sublist_unique_append_l1 //]
523    >Hind2 [2:@tech @(not_to_not … (tech2 … H)) #H1 @sublist_unique_append_l2 //]
524    //
525   |#i1 #i2 #Hind1 #Hind2 #H >move_plus >Hind1 [2:@tech 
526    @(not_to_not … (tech2 … H)) #H1 @sublist_unique_append_l1 //]
527    >Hind2 [2:@tech @(not_to_not … (tech2 … H)) #H1 @sublist_unique_append_l2 //]
528    //
529   |#i #Hind #H >move_star >Hind // @H
530   ]
531 qed.
532
533 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
534 #S #a #i elim i //
535   [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 // 
536   |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 // 
537   |#i #Hind >move_star >Hind //
538   ]
539 qed. 
540
541 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
542 #S #w #i elim w // #a #tl >moves_cons // 
543 qed. 
544  
545 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
546  moves S w e = pit_pre S (\fst e).
547 #S #w elim w
548   [(* orribile *)
549    #e * #H @False_ind @H normalize #a #abs @False_ind /2/
550   |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
551     [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a) 
552      @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
553       [#H2 <(proj1 … (eqb_true …) H2) // |#H2 @H1 //]
554     |#Hfalse >moves_cons >not_occur_to_pit //
555     ]
556   ]
557 qed.
558     
559 definition occ ≝ λS.λe1,e2:pre S. 
560   unique_append ? (occur S (|\fst e1|)) (occur S (|\fst e2|)).
561
562 (* definition occS ≝ λS:DeqSet.λoccur.
563   PSig S (λx.memb S x occur = true). *)
564
565 lemma occ_enough: ∀S.∀e1,e2:pre S.
566 (∀w.(sublist S w (occ S e1 e2))→
567  (beqb (\snd (moves S w e1)) (\snd (moves ? w e2))) = true) \to
568 ∀w.(beqb (\snd (moves S w e1)) (\snd (moves ? w e2))) = true.
569 #S #e1 #e2 #H #w
570 cut (sublist S w (occ S e1 e2) ∨ ¬(sublist S w (occ S e1 e2)))
571 [elim w 
572   [%1 #a normalize in ⊢ (%→?); #abs @False_ind /2/
573   |#a #tl * #subtl 
574     [cases (true_or_false (memb S a (occ S e1 e2))) #memba
575       [%1 whd #x #membx cases (orb_true_l … membx)
576         [#eqax <(proj1 … (eqb_true …) eqax) //
577         |@subtl
578         ]
579       |%2 @(not_to_not … (tech2 … memba)) #H1 @H1 @memb_hd
580       ]
581     |%2 @(not_to_not … subtl) #H1 #x #H2 @H1 @memb_cons //
582     ] 
583   ]
584 |* [@H] 
585  #H >to_pit 
586   [2: @(not_to_not … H) #H1 #a #memba  @sublist_unique_append_l1 @H1 //]
587  >to_pit
588   [2: @(not_to_not … H) #H1 #a #memba  @sublist_unique_append_l2 @H1 //]
589  //
590 ]
591 qed.
592
593 lemma bisim_char: ∀S.∀e1,e2:pre S.
594 (∀w.(beqb (\snd (moves S w e1)) (\snd (moves ? w e2))) = true) → 
595 \sem{e1}=1\sem{e2}.
596 #S #e1 #e2 #H @(proj2 … (equiv_sem …)) #w @(proj1 …(beqb_ok …)) @H
597 qed.
598
599 lemma bisim_ok2: ∀S.∀e1,e2:pre S.
600  (beqb (\snd e1) (\snd e2) = true) → ∀n.
601  \fst (bisim S (occ S e1 e2) n (sons S (occ S e1 e2) 〈e1,e2〉) [〈e1,e2〉]) = true → 
602    \sem{e1}=1\sem{e2}.
603 #S #e1 #e2 #Hnil #n 
604 letin rsig ≝ (occ S e1 e2)
605 letin frontier ≝ (sons S rsig 〈e1,e2〉)
606 letin visited_res ≝ (\snd (bisim S rsig n frontier [〈e1,e2〉])) 
607 #bisim_true
608 cut (bisim S rsig n frontier [〈e1,e2〉] = 〈true,visited_res〉)
609   [<bisim_true <eq_pair_fst_snd //] #H
610 cut (all_true S [〈e1,e2〉]) 
611   [#p #Hp cases (orb_true_l … Hp) 
612     [#eqp <(proj1 … (eqb_true …) eqp) // 
613     | whd in ⊢ ((??%?)→?); #abs @False_ind /2/
614     ]] #allH 
615 cut (sub_sons S rsig [〈e1,e2〉] (frontier@[〈e1,e2〉]))
616   [#x #a #H1 cases (orb_true_l … H1) 
617     [#eqx <(proj1 … (eqb_true …) eqx) #H2 @memb_append_l1 
618      whd in ⊢ (??(???%)?); @(memb_map … H2)
619     |whd in ⊢ ((??%?)→?); #abs @False_ind /2/
620     ]
621   ] #init
622 cases (reachable_bisim … allH init … H) * #H1 #H2 #H3
623 cut (∀w.sublist ? w (occ S e1 e2)→∀p.memb (space S) p visited_res = true → 
624   memb (space S) 〈moves ? w (\fst p), moves ? w (\snd p)〉 visited_res = true)
625   [#w elim w [//] 
626    #a #w1 #Hind #Hsub * #e11 #e21 #visp >moves_cons >moves_cons 
627    @(Hind ? 〈?,?〉) [#x #H4 @Hsub @memb_cons //] 
628    @(H1 〈?,?〉) // @Hsub @memb_hd] #all_reach
629 @bisim_char @occ_enough
630 #w #Hsub @(H3 〈?,?〉) @(all_reach w Hsub 〈?,?〉) @H2 //
631 qed.
632   
633 definition tt ≝ ps Bin true.
634 definition ff ≝ ps Bin false.
635 definition eps ≝ pe Bin.
636 definition exp1 ≝ (ff + tt · ff).
637 definition exp2 ≝  ff · (eps + tt).
638
639 definition exp3 ≝ move Bin true (\fst (•exp1)).
640 definition exp4 ≝ move Bin true (\fst (•exp2)).
641 definition exp5 ≝ move Bin false (\fst (•exp1)).
642 definition exp6 ≝ move Bin false (\fst (•exp2)).
643
644
645
646