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