]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/re/re.ma
Pairs are now records.
[helm.git] / matita / matita / lib / re / re.ma
1
2
3 (**************************************************************************)
4 (*       ___                                                              *)
5 (*      ||M||                                                             *)
6 (*      ||A||       A project by Andrea Asperti                           *)
7 (*      ||T||                                                             *)
8 (*      ||I||       Developers:                                           *)
9 (*      ||T||         The HELM team.                                      *)
10 (*      ||A||         http://helm.cs.unibo.it                             *)
11 (*      \   /                                                             *)
12 (*       \ /        This file is distributed under the terms of the       *)
13 (*        v         GNU General Public License Version 2                  *)
14 (*                                                                        *)
15 (**************************************************************************)
16
17 include "arithmetics/nat.ma".
18 include "basics/lists/list.ma".
19 include "basics/sets.ma".
20
21 definition word ≝ λS:DeqSet.list S.
22
23 inductive re (S: DeqSet) : Type[0] ≝
24    z: re S
25  | e: re S
26  | s: S → re S
27  | c: re S → re S → re S
28  | o: re S → re S → re S
29  | k: re S → re S.
30  
31 (* notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.*)
32 notation "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
33 interpretation "star" 'pk a = (k ? a).
34 interpretation "or" 'plus a b = (o ? a b).
35            
36 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
37 interpretation "cat" 'pc a b = (c ? a b).
38
39 (* to get rid of \middot 
40 ncoercion c  : ∀S:DeqSet.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
41 *)
42
43 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
44 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
45 interpretation "atom" 'ps a = (s ? a).
46
47 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
48 interpretation "epsilon" 'epsilon = (e ?).
49
50 notation "`∅" non associative with precedence 90 for @{ 'empty }.
51 interpretation "empty" 'empty = (z ?).
52
53 let rec flatten (S : DeqSet) (l : list (word S)) on l : word S ≝ 
54 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
55
56 let rec conjunct (S : DeqSet) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
57 match l with [ nil ⇒ True | cons w tl ⇒ r w ∧ conjunct ? tl r ]. 
58
59 (*
60 definition empty_lang ≝ λS.λw:word S.False.
61 notation "{}" non associative with precedence 90 for @{'empty_lang}.
62 interpretation "empty lang" 'empty_lang = (empty_lang ?).
63
64 definition sing_lang ≝ λS.λx,w:word S.x=w.
65 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.*)
66 interpretation "sing lang" 'singl x = (sing_lang ? x).
67
68 definition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
69 interpretation "union lang" 'union a b = (union ? a b). *)
70
71 definition cat : ∀S,l1,l2,w.Prop ≝ 
72   λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
73 interpretation "cat lang" 'pc a b = (cat ? a b).
74
75 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l. 
76 interpretation "star lang" 'pk l = (star ? l).
77
78 let rec in_l (S : DeqSet) (r : re S) on r : word S → Prop ≝ 
79 match r with
80 [ z ⇒ ∅
81 | e ⇒ { [ ] }
82 | s x ⇒ { [x] }
83 | c r1 r2 ⇒ (in_l ? r1) · (in_l ? r2)
84 | o r1 r2 ⇒ (in_l ? r1) ∪ (in_l ? r2)
85 | k r1 ⇒ (in_l ? r1) ^*].
86
87 notation "\sem{term 19 E}" non associative with precedence 75 for @{'in_l $E}.
88 interpretation "in_l" 'in_l E = (in_l ? E).
89 interpretation "in_l mem" 'mem w l = (in_l ? l w).
90
91 lemma rsem_star : ∀S.∀r: re S. \sem{r^*} = \sem{r}^*.
92 // qed.
93
94 inductive pitem (S: DeqSet) : Type[0] ≝
95    pz: pitem S
96  | pe: pitem S
97  | ps: S → pitem S
98  | pp: S → pitem S
99  | pc: pitem S → pitem S → pitem S
100  | po: pitem S → pitem S → pitem S
101  | pk: pitem S → pitem S.
102  
103 definition pre ≝ λS.pitem S × bool.
104
105 interpretation "pstar" 'pk a = (pk ? a).
106 interpretation "por" 'plus a b = (po ? a b).
107 interpretation "pcat" 'pc a b = (pc ? a b).
108 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
109 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
110 interpretation "ppatom" 'pp a = (pp ? a).
111
112 (* to get rid of \middot 
113 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S  ≝ pc on _p : pitem ? to ∀_:?.?.
114 *)
115
116 interpretation "patom" 'ps a = (ps ? a).
117 interpretation "pepsilon" 'epsilon = (pe ?).
118 interpretation "pempty" 'empty = (pz ?).
119
120 let rec forget (S: DeqSet) (l : pitem S) on l: re S ≝
121  match l with
122   [ pz ⇒ `∅
123   | pe ⇒ ϵ
124   | ps x ⇒ `x
125   | pp x ⇒ `x
126   | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
127   | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
128   | pk E ⇒ (forget ? E)^* ].
129   
130 (* notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.*)
131 interpretation "forget" 'norm a = (forget ? a).
132
133 let rec in_pl (S : DeqSet) (r : pitem S) on r : word S → Prop ≝ 
134 match r with
135 [ pz ⇒ ∅
136 | pe ⇒ ∅
137 | ps _ ⇒ ∅
138 | pp x ⇒ { [x] }
139 | pc r1 r2 ⇒ (in_pl ? r1) · \sem{forget ? r2} ∪ (in_pl ? r2)
140 | po r1 r2 ⇒ (in_pl ? r1) ∪ (in_pl ? r2)
141 | pk r1 ⇒ (in_pl ? r1) · \sem{forget ? r1}^*  ].
142
143 interpretation "in_pl" 'in_l E = (in_pl ? E).
144 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
145
146 (*
147 definition epsilon : ∀S:DeqSet.bool → word S → Prop
148 ≝ λS,b.if b then { ([ ] : word S) } else ∅. 
149
150 interpretation "epsilon" 'epsilon = (epsilon ?).
151 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
152 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b). *)
153
154 definition in_prl ≝ λS : DeqSet.λp:pre S. 
155   if (\snd p) then \sem{\fst p} ∪ { ([ ] : word S) } else \sem{\fst p}.
156   
157 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
158 interpretation "in_prl" 'in_l E = (in_prl ? E).
159
160 lemma sem_pre_true : ∀S.∀i:pitem S. 
161   \sem{〈i,true〉} = \sem{i} ∪ { ([ ] : word S) }. 
162 // qed.
163
164 lemma sem_pre_false : ∀S.∀i:pitem S. 
165   \sem{〈i,false〉} = \sem{i}. 
166 // qed.
167
168 lemma sem_cat: ∀S.∀i1,i2:pitem S. 
169   \sem{i1 · i2} = \sem{i1} · \sem{|i2|} ∪ \sem{i2}.
170 // qed.
171
172 lemma sem_cat_w: ∀S.∀i1,i2:pitem S.∀w.
173   \sem{i1 · i2} w = ((\sem{i1} · \sem{|i2|}) w ∨ \sem{i2} w).
174 // qed.
175
176 lemma sem_plus: ∀S.∀i1,i2:pitem S. 
177   \sem{i1 + i2} = \sem{i1} ∪ \sem{i2}.
178 // qed.
179
180 lemma sem_plus_w: ∀S.∀i1,i2:pitem S.∀w. 
181   \sem{i1 + i2} w = (\sem{i1} w ∨ \sem{i2} w).
182 // qed.
183
184 lemma sem_star : ∀S.∀i:pitem S.
185   \sem{i^*} = \sem{i} · \sem{|i|}^*.
186 // qed.
187
188 lemma sem_star_w : ∀S.∀i:pitem S.∀w.
189   \sem{i^*} w = (∃w1,w2.w1 @ w2 = w ∧ \sem{i} w1 ∧ \sem{|i|}^* w2).
190 // qed.
191
192 lemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
193 #S #w1 #w2 cases w1 // #a #tl normalize #H destruct qed.
194
195 lemma not_epsilon_lp : ∀S:DeqSet.∀e:pitem S. ¬ ([ ] ∈ e).
196 #S #e elim e normalize /2/  
197   [#r1 #r2 * #n1 #n2 % * /2/ * #w1 * #w2 * * #H 
198    >(append_eq_nil …H…) /2/
199   |#r1 #r2 #n1 #n2 % * /2/
200   |#r #n % * #w1 * #w2 * * #H >(append_eq_nil …H…) /2/
201   ]
202 qed.
203
204 (* lemma 12 *)
205 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
206 #S * #i #b cases b // normalize #H @False_ind /2/ 
207 qed.
208
209 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
210 #S * #i #b #btrue normalize in btrue; >btrue %2 // 
211 qed.
212
213 definition lo ≝ λS:DeqSet.λa,b:pre S.〈\fst a + \fst b,\snd a ∨ \snd b〉.
214 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
215 interpretation "oplus" 'oplus a b = (lo ? a b).
216
217 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1∨b2〉.
218 // qed.
219
220 definition pre_concat_r ≝ λS:DeqSet.λi:pitem S.λe:pre S.
221   match e with [ mk_Prod i1 b ⇒ 〈i · i1, b〉].
222  
223 notation "i ◂ e" left associative with precedence 60 for @{'ltrif $i $e}.
224 interpretation "pre_concat_r" 'ltrif i e = (pre_concat_r ? i e).
225   
226 definition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
227 notation "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
228 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
229
230 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop. 
231   A = B → A =1 B. 
232 #S #A #B #H >H /2/ qed.
233
234 lemma sem_pre_concat_r : ∀S,i.∀e:pre S.
235   \sem{i ◂ e} =1 \sem{i} · \sem{|\fst e|} ∪ \sem{e}.
236 #S #i * #i1 #b1 cases b1 /2/
237 >sem_pre_true >sem_cat >sem_pre_true /2/ 
238 qed.
239  
240 definition lc ≝ λS:DeqSet.λbcast:∀S:DeqSet.pitem S → pre S.λe1:pre S.λi2:pitem S.
241   match e1 with 
242   [ mk_Prod i1 b1 ⇒ match b1 with 
243     [ true ⇒ (i1 ◂ (bcast ? i2)) 
244     | false ⇒ 〈i1 · i2,false〉
245     ]
246   ].
247         
248 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S. 
249   match e with 
250   [ mk_Prod i b ⇒ 〈\fst (f i), \snd (f i) ∨ b〉].
251
252 notation "a ▸ b" left associative with precedence 60 for @{'lc eclose $a $b}.
253 interpretation "lc" 'lc op a b = (lc ? op a b).
254
255 definition lk ≝ λS:DeqSet.λbcast:∀S:DeqSet.∀E:pitem S.pre S.λe:pre S.
256   match e with 
257   [ mk_Prod i1 b1 ⇒
258     match b1 with 
259     [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
260     |false ⇒ 〈i1^*,false〉
261     ]
262   ]. 
263
264 (*
265 lemma oplus_tt : ∀S: DeqSet.∀i1,i2:pitem S. 
266   〈i1,true〉 ⊕ 〈i2,true〉  = 〈i1 + i2,true〉.
267 // qed.
268
269 lemma oplus_tf : ∀S: DeqSet.∀i1,i2:pitem S. 
270   〈i1,true〉 ⊕ 〈i2,false〉  = 〈i1 + i2,true〉.
271 // qed.
272
273 lemma oplus_ft : ∀S: DeqSet.∀i1,i2:pitem S. 
274   〈i1,false〉 ⊕ 〈i2,true〉  = 〈i1 + i2,true〉.
275 // qed.
276
277 lemma oplus_ff : ∀S: DeqSet.∀i1,i2:pitem S. 
278   〈i1,false〉 ⊕ 〈i2,false〉  = 〈i1 + i2,false〉.
279 // qed. *)
280
281 (* notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.*)
282 interpretation "lk" 'lk op a = (lk ? op a).
283 notation "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
284
285 notation "•" non associative with precedence 60 for @{eclose ?}.
286
287 let rec eclose (S: DeqSet) (i: pitem S) on i : pre S ≝
288  match i with
289   [ pz ⇒ 〈 `∅, false 〉
290   | pe ⇒ 〈 ϵ,  true 〉
291   | ps x ⇒ 〈 `.x, false〉
292   | pp x ⇒ 〈 `.x, false 〉
293   | po i1 i2 ⇒ •i1 ⊕ •i2
294   | pc i1 i2 ⇒ •i1 ▸ i2
295   | pk i ⇒ 〈(\fst (•i))^*,true〉].
296   
297 notation "• x" non associative with precedence 60 for @{'eclose $x}.
298 interpretation "eclose" 'eclose x = (eclose ? x).
299
300 lemma eclose_plus: ∀S:DeqSet.∀i1,i2:pitem S.
301   •(i1 + i2) = •i1 ⊕ •i2.
302 // qed.
303
304 lemma eclose_dot: ∀S:DeqSet.∀i1,i2:pitem S.
305   •(i1 · i2) = •i1 ▸ i2.
306 // qed.
307
308 lemma eclose_star: ∀S:DeqSet.∀i:pitem S.
309   •i^* = 〈(\fst(•i))^*,true〉.
310 // qed.
311
312 definition reclose ≝ λS. lift S (eclose S). 
313 interpretation "reclose" 'eclose x = (reclose ? x).
314
315 (* theorem 16: 2 *)
316 lemma sem_oplus: ∀S:DeqSet.∀e1,e2:pre S.
317   \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}. 
318 #S * #i1 #b1 * #i2 #b2 #w %
319   [cases b1 cases b2 normalize /2/ * /3/ * /3/
320   |cases b1 cases b2 normalize /2/ * /3/ * /3/
321   ]
322 qed.
323
324 lemma odot_true : 
325   ∀S.∀i1,i2:pitem S.
326   〈i1,true〉 ▸ i2 = i1 ◂ (•i2).
327 // qed.
328
329 lemma odot_true_bis : 
330   ∀S.∀i1,i2:pitem S.
331   〈i1,true〉 ▸ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
332 #S #i1 #i2 normalize cases (•i2) // qed.
333
334 lemma odot_false: 
335   ∀S.∀i1,i2:pitem S.
336   〈i1,false〉 ▸ i2 = 〈i1 · i2, false〉.
337 // qed.
338
339 lemma LcatE : ∀S.∀e1,e2:pitem S.
340   \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}. 
341 // qed.
342
343 lemma erase_dot : ∀S.∀e1,e2:pitem S. |e1 · e2| = c ? (|e1|) (|e2|).
344 // qed.
345
346 lemma erase_plus : ∀S.∀i1,i2:pitem S.
347   |i1 + i2| = |i1| + |i2|.
348 // qed.
349
350 lemma erase_star : ∀S.∀i:pitem S.|i^*| = |i|^*. 
351 // qed.
352
353 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |i|.
354 #S #i elim i // 
355   [ #i1 #i2 #IH1 #IH2 >erase_dot <IH1 >eclose_dot
356     cases (•i1) #i11 #b1 cases b1 // <IH2 >odot_true_bis //
357   | #i1 #i2 #IH1 #IH2 >eclose_plus >(erase_plus … i1) <IH1 <IH2
358     cases (•i1) #i11 #b1 cases (•i2) #i21 #b2 //  
359   | #i #IH >eclose_star >(erase_star … i) <IH cases (•i) //
360   ]
361 qed.
362
363 lemma cat_ext_l: ∀S.∀A,B,C:word S →Prop. 
364   A =1 C  → A · B =1 C · B.
365 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
366 cases (H w1) /6/ 
367 qed.
368   
369 lemma cat_ext_r: ∀S.∀A,B,C:word S →Prop. 
370   B =1 C → A · B =1 A · C.
371 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
372 cases (H w2) /6/ 
373 qed.
374   
375 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
376   (A ∪ B) · C =1  A · C ∪ B · C. 
377 #S #A #B #C #w %
378   [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/] 
379 qed.
380
381 lemma espilon_in_star: ∀S.∀A:word S → Prop.
382   A^* [ ].
383 #S #A @(ex_intro … [ ]) normalize /2/
384 qed.
385
386 lemma cat_to_star:∀S.∀A:word S → Prop.
387   ∀w1,w2. A w1 → A^* w2 → A^* (w1@w2).
388 #S #A #w1 #w2 #Aw * #l * #H #H1 @(ex_intro … (w1::l)) 
389 % normalize /2/
390 qed.
391
392 lemma fix_star: ∀S.∀A:word S → Prop. 
393   A^* =1 A · A^* ∪ { [ ] }.
394 #S #A #w %
395   [* #l generalize in match w; -w cases l [normalize #w * /2/]
396    #w1 #tl #w * whd in ⊢ ((??%?)→?); #eqw whd in ⊢ (%→?); *
397    #w1A #cw1 %1 @(ex_intro … w1) @(ex_intro … (flatten S tl))
398    % /2/ whd @(ex_intro … tl) /2/
399   |* [2: whd in ⊢ (%→?); #eqw <eqw //]
400    * #w1 * #w2 * * #eqw <eqw @cat_to_star 
401   ]
402 qed.
403
404 lemma star_fix_eps : ∀S.∀A:word S → Prop.
405   A^* =1 (A - {[ ]}) · A^* ∪ {[ ]}.  
406 #S #A #w %
407   [* #l elim l 
408     [* whd in ⊢ ((??%?)→?); #eqw #_ %2 <eqw // 
409     |* [#tl #Hind * #H * #_ #H2 @Hind % [@H | //]
410        |#a #w1 #tl #Hind * whd in ⊢ ((??%?)→?); #H1 * #H2 #H3 %1 
411         @(ex_intro … (a::w1)) @(ex_intro … (flatten S tl)) %
412          [% [@H1 | normalize % /2/] |whd @(ex_intro … tl) /2/]
413        ]
414     ]
415   |* [* #w1 * #w2 * * #eqw * #H1 #_ <eqw @cat_to_star //
416      | whd in ⊢ (%→?); #H <H //
417      ]
418   ]
419 qed. 
420      
421 lemma star_epsilon: ∀S:DeqSet.∀A:word S → Prop.
422   A^* ∪ { [ ] } =1 A^*.
423 #S #A #w % /2/ * // 
424 qed.
425   
426 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
427   \sem{〈i^*,true〉} =1 \sem{〈i,false〉}·\sem{|i|}^* ∪ { [ ] }.
428 /2/ qed.
429
430 (* this kind of results are pretty bad for automation;
431    better not index them *)
432    
433 lemma epsilon_cat_r: ∀S.∀A:word S →Prop.
434    A · { [ ] } =1  A. 
435 #S #A #w %
436   [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
437   |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
438   ]
439 qed.
440
441 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
442    { [ ] } · A =1  A. 
443 #S #A #w %
444   [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
445   |#inA @(ex_intro … [ ]) @(ex_intro … w) /3/
446   ]
447 qed.
448
449 lemma distr_cat_r_eps: ∀S.∀A,C:word S →Prop.
450   (A ∪ { [ ] }) · C =1  A · C ∪ C. 
451 #S #A #C @eqP_trans [|@distr_cat_r |@eqP_union_l @epsilon_cat_l]
452 qed.
453
454 (* axiom eplison_cut_l: ∀S.∀A:word S →Prop. 
455    { [ ] } · A =1  A.
456    
457  axiom eplison_cut_r: ∀S.∀A:word S →Prop.
458    A · { [ ] } =1  A. *)
459
460 (*
461 lemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
462 #S p; ncases p; //; nqed.
463
464 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p. 
465 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
466 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
467 napply Hw2; nqed.*)
468
469 (* theorem 16: 1 → 3 *)
470 lemma odot_dot_aux : ∀S.∀e1:pre S.∀i2:pitem S.
471    \sem{•i2} =1  \sem{i2} ∪ \sem{|i2|} →
472    \sem{e1 ▸ i2} =1  \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
473 #S * #i1 #b1 #i2 cases b1
474   [2:#th >odot_false >sem_pre_false >sem_pre_false >sem_cat /2/
475   |#H >odot_true >sem_pre_true @(eqP_trans … (sem_pre_concat_r …))
476    >erase_bull @eqP_trans [|@(eqP_union_l … H)]
477     @eqP_trans [|@eqP_union_l[|@union_comm ]]
478     @eqP_trans [|@eqP_sym @union_assoc ] /3/ 
479   ]
480 qed.
481
482 lemma sem_fst: ∀S.∀e:pre S. \sem{\fst e} =1 \sem{e}-{[ ]}.
483 #S * #i * 
484   [>sem_pre_true normalize in ⊢ (??%?); #w % 
485     [/3/ | * * // #H1 #H2 @False_ind @(absurd …H1 H2)]
486   |>sem_pre_false normalize in ⊢ (??%?); #w % [ /3/ | * // ]
487   ]
488 qed.
489
490 lemma item_eps: ∀S.∀i:pitem S. \sem{i} =1 \sem{i}-{[ ]}.
491 #S #i #w % 
492   [#H whd % // normalize @(not_to_not … (not_epsilon_lp …i)) //
493   |* //
494   ]
495 qed.
496   
497 lemma sem_fst_aux: ∀S.∀e:pre S.∀i:pitem S.∀A. 
498  \sem{e} =1 \sem{i} ∪ A → \sem{\fst e} =1 \sem{i} ∪ (A - {[ ]}).
499 #S #e #i #A #seme
500 @eqP_trans [|@sem_fst]
501 @eqP_trans [||@eqP_union_r [|@eqP_sym @item_eps]]
502 @eqP_trans [||@distribute_substract] 
503 @eqP_substract_r //
504 qed.
505
506 (* theorem 16: 1 *)
507 theorem sem_bull: ∀S:DeqSet. ∀e:pitem S.  \sem{•e} =1 \sem{e} ∪ \sem{|e|}.
508 #S #e elim e 
509   [#w normalize % [/2/ | * //]
510   |/2/ 
511   |#x normalize #w % [ /2/ | * [@False_ind | //]]
512   |#x normalize #w % [ /2/ | * // ] 
513   |#i1 #i2 #IH1 #IH2 >eclose_dot
514    @eqP_trans [|@odot_dot_aux //] >sem_cat 
515    @eqP_trans
516      [|@eqP_union_r
517        [|@eqP_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
518    @eqP_trans [|@union_assoc]
519    @eqP_trans [||@eqP_sym @union_assoc]
520    @eqP_union_l //
521   |#i1 #i2 #IH1 #IH2 >eclose_plus
522    @eqP_trans [|@sem_oplus] >sem_plus >erase_plus 
523    @eqP_trans [|@(eqP_union_l … IH2)]
524    @eqP_trans [|@eqP_sym @union_assoc]
525    @eqP_trans [||@union_assoc] @eqP_union_r
526    @eqP_trans [||@eqP_sym @union_assoc]
527    @eqP_trans [||@eqP_union_l [|@union_comm]]
528    @eqP_trans [||@union_assoc] /2/
529   |#i #H >sem_pre_true >sem_star >erase_bull >sem_star
530    @eqP_trans [|@eqP_union_r [|@cat_ext_l [|@sem_fst_aux //]]]
531    @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
532    @eqP_trans [|@union_assoc] @eqP_union_l >erase_star 
533    @eqP_sym @star_fix_eps 
534   ]
535 qed.
536
537 definition lifted_cat ≝ λS:DeqSet.λe:pre S. 
538   lift S (lc S eclose e).
539
540 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
541
542 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
543
544 lemma odot_true_b : ∀S.∀i1,i2:pitem S.∀b. 
545   〈i1,true〉 ⊙ 〈i2,b〉 = 〈i1 · (\fst (•i2)),\snd (•i2) ∨ b〉.
546 #S #i1 #i2 #b normalize in ⊢ (??%?); cases (•i2) // 
547 qed.
548
549 lemma odot_false_b : ∀S.∀i1,i2:pitem S.∀b.
550   〈i1,false〉 ⊙ 〈i2,b〉 = 〈i1 · i2 ,b〉.
551 // 
552 qed.
553   
554 lemma erase_odot:∀S.∀e1,e2:pre S.
555   |\fst (e1 ⊙ e2)| = |\fst e1| · (|\fst e2|).
556 #S * #i1 * * #i2 #b2 // >odot_true_b // 
557 qed.
558
559 lemma ostar_true: ∀S.∀i:pitem S.
560   〈i,true〉^⊛ = 〈(\fst (•i))^*, true〉.
561 // qed.
562
563 lemma ostar_false: ∀S.∀i:pitem S.
564   〈i,false〉^⊛ = 〈i^*, false〉.
565 // qed.
566   
567 lemma erase_ostar: ∀S.∀e:pre S.
568   |\fst (e^⊛)| = |\fst e|^*.
569 #S * #i * // qed.
570
571 lemma sem_odot_true: ∀S:DeqSet.∀e1:pre S.∀i. 
572   \sem{e1 ⊙ 〈i,true〉} =1 \sem{e1 ▸ i} ∪ { [ ] }.
573 #S #e1 #i 
574 cut (e1 ⊙ 〈i,true〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) ∨ true〉) [//]
575 #H >H cases (e1 ▸ i) #i1 #b1 cases b1 
576   [>sem_pre_true @eqP_trans [||@eqP_sym @union_assoc]
577    @eqP_union_l /2/ 
578   |/2/
579   ]
580 qed.
581
582 lemma eq_odot_false: ∀S:DeqSet.∀e1:pre S.∀i. 
583   e1 ⊙ 〈i,false〉 = e1 ▸ i.
584 #S #e1 #i  
585 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) ∨ false〉) [//]
586 cases (e1 ▸ i) #i1 #b1 cases b1 #H @H
587 qed.
588
589 lemma sem_odot: 
590   ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
591 #S #e1 * #i2 * 
592   [>sem_pre_true 
593    @eqP_trans [|@sem_odot_true]
594    @eqP_trans [||@union_assoc] @eqP_union_r @odot_dot_aux //
595   |>sem_pre_false >eq_odot_false @odot_dot_aux //
596   ]
597 qed.
598
599 (* theorem 16: 4 *)      
600 theorem sem_ostar: ∀S.∀e:pre S. 
601   \sem{e^⊛} =1  \sem{e} · \sem{|\fst e|}^*.
602 #S * #i #b cases b
603   [>sem_pre_true >sem_pre_true >sem_star >erase_bull
604    @eqP_trans [|@eqP_union_r[|@cat_ext_l [|@sem_fst_aux //]]]
605    @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
606    @eqP_trans [||@eqP_sym @distr_cat_r]
607    @eqP_trans [|@union_assoc] @eqP_union_l
608    @eqP_trans [||@eqP_sym @epsilon_cat_l] @eqP_sym @star_fix_eps 
609   |>sem_pre_false >sem_pre_false >sem_star /2/
610   ]
611 qed.
612   
613 (*
614 nlet rec pre_of_re (S : DeqSet) (e : re S) on e : pitem S ≝ 
615   match e with 
616   [ z ⇒ pz ?
617   | e ⇒ pe ?
618   | s x ⇒ ps ? x
619   | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
620   | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
621   | k e1 ⇒ pk ? (pre_of_re ? e1)].
622
623 nlemma notFalse : ¬False. @; //; nqed.
624
625 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
626 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
627 *; #w1; *; #w2; *; *; //; nqed.
628
629 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
630 #S e; nelim e; ##[##1,2,3: //]
631 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
632     nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
633 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
634     nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
635 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
636     nrewrite > H1; napply dot0; ##]
637 nqed.
638
639 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
640 #S A; nelim A; //; 
641 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
642     nrewrite < H1; nrewrite < H2; //
643 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
644     nrewrite < H1; nrewrite < H2; //
645 ##| #e1 H1; nchange in match (𝐋  (e1^* )) with ((𝐋 e1)^* );
646     nrewrite < H1; //]
647 nqed.     
648
649 (* corollary 17 *)
650 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
651 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
652 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
653 nqed.
654
655 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
656 #S f g H; nrewrite > H; //; nqed.
657  
658 (* corollary 18 *)
659 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
660 #S e; @;
661 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
662     nrewrite > defsnde; #H; 
663     nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
664
665 *)
666
667