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