1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "arithmetics/nat.ma".
16 include "basics/lists/list.ma".
17 include "basics/sets.ma".
19 definition word ≝ λS:DeqSet.list S.
21 inductive re (S: DeqSet) : Type[0] ≝
25 | c: re S → re S → re S
26 | o: re S → re S → re S
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).
34 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
35 interpretation "cat" 'pc a b = (c ? a b).
37 (* to get rid of \middot
38 ncoercion c : ∀S:DeqSet.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
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).
45 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
46 interpretation "epsilon" 'epsilon = (e ?).
48 notation "`∅" non associative with precedence 90 for @{ 'empty }.
49 interpretation "empty" 'empty = (z ?).
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 ].
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 ].
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 ?).
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).
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). *)
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).
74 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
75 interpretation "star lang" 'pk l = (star ? l).
77 let rec in_l (S : DeqSet) (r : re S) on r : word S → Prop ≝
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) ^*].
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).
90 lemma rsem_star : ∀S.∀r: re S. \sem{r^*} = \sem{r}^*.
93 inductive pitem (S: DeqSet) : Type[0] ≝
98 | pc: pitem S → pitem S → pitem S
99 | po: pitem S → pitem S → pitem S
100 | pk: pitem S → pitem S.
102 definition pre ≝ λS.pitem S × bool.
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).
111 (* to get rid of \middot
112 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
115 interpretation "patom" 'ps a = (ps ? a).
116 interpretation "pepsilon" 'epsilon = (pe ?).
117 interpretation "pempty" 'empty = (pz ?).
119 let rec forget (S: DeqSet) (l : pitem S) on l: re S ≝
125 | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
126 | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
127 | pk E ⇒ (forget ? E)^* ].
129 (* notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.*)
130 interpretation "forget" 'norm a = (forget ? a).
132 let rec in_pl (S : DeqSet) (r : pitem S) on r : word S → Prop ≝
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}^* ].
142 interpretation "in_pl" 'in_l E = (in_pl ? E).
143 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
146 definition epsilon : ∀S:DeqSet.bool → word S → Prop
147 ≝ λS,b.if b then { ([ ] : word S) } else ∅.
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). *)
153 definition in_prl ≝ λS : DeqSet.λp:pre S.
154 if (\snd p) then \sem{\fst p} ∪ { ([ ] : word S) } else \sem{\fst p}.
156 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
157 interpretation "in_prl" 'in_l E = (in_prl ? E).
159 lemma sem_pre_true : ∀S.∀i:pitem S.
160 \sem{〈i,true〉} = \sem{i} ∪ { ([ ] : word S) }.
163 lemma sem_pre_false : ∀S.∀i:pitem S.
164 \sem{〈i,false〉} = \sem{i}.
167 lemma sem_cat: ∀S.∀i1,i2:pitem S.
168 \sem{i1 · i2} = \sem{i1} · \sem{|i2|} ∪ \sem{i2}.
171 lemma sem_cat_w: ∀S.∀i1,i2:pitem S.∀w.
172 \sem{i1 · i2} w = ((\sem{i1} · \sem{|i2|}) w ∨ \sem{i2} w).
175 lemma sem_plus: ∀S.∀i1,i2:pitem S.
176 \sem{i1 + i2} = \sem{i1} ∪ \sem{i2}.
179 lemma sem_plus_w: ∀S.∀i1,i2:pitem S.∀w.
180 \sem{i1 + i2} w = (\sem{i1} w ∨ \sem{i2} w).
183 lemma sem_star : ∀S.∀i:pitem S.
184 \sem{i^*} = \sem{i} · \sem{|i|}^*.
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).
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.
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/
204 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
205 #S * #i #b cases b // normalize #H @False_ind /2/
208 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
209 #S * #i #b #btrue normalize in btrue; >btrue %2 //
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).
216 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1∨b2〉.
219 definition pre_concat_r ≝ λS:DeqSet.λi:pitem S.λe:pre S.
220 match e with [ pair i1 b ⇒ 〈i · i1, b〉].
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).
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).
229 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop.
231 #S #A #B #H >H /2/ qed.
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/
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/]
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/
249 definition lc ≝ λS:DeqSet.λbcast:∀S:DeqSet.pitem S → pre S.λe1:pre S.λi2:pitem S.
251 [ pair i1 b1 ⇒ match b1 with
252 [ true ⇒ (i1 ◂ (bcast ? i2))
253 | false ⇒ 〈i1 · i2,false〉
257 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S.
259 [ pair i b ⇒ 〈\fst (f i), \snd (f i) ∨ b〉].
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).
264 definition lk ≝ λS:DeqSet.λbcast:∀S:DeqSet.∀E:pitem S.pre S.λe:pre S.
268 [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
269 |false ⇒ 〈i1^*,false〉
274 lemma oplus_tt : ∀S: DeqSet.∀i1,i2:pitem S.
275 〈i1,true〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
278 lemma oplus_tf : ∀S: DeqSet.∀i1,i2:pitem S.
279 〈i1,true〉 ⊕ 〈i2,false〉 = 〈i1 + i2,true〉.
282 lemma oplus_ft : ∀S: DeqSet.∀i1,i2:pitem S.
283 〈i1,false〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
286 lemma oplus_ff : ∀S: DeqSet.∀i1,i2:pitem S.
287 〈i1,false〉 ⊕ 〈i2,false〉 = 〈i1 + i2,false〉.
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}.
294 notation "•" non associative with precedence 60 for @{eclose ?}.
296 let rec eclose (S: DeqSet) (i: pitem S) on i : pre S ≝
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〉].
306 notation "• x" non associative with precedence 60 for @{'eclose $x}.
307 interpretation "eclose" 'eclose x = (eclose ? x).
309 lemma eclose_plus: ∀S:DeqSet.∀i1,i2:pitem S.
310 •(i1 + i2) = •i1 ⊕ •i2.
313 lemma eclose_dot: ∀S:DeqSet.∀i1,i2:pitem S.
314 •(i1 · i2) = •i1 ▸ i2.
317 lemma eclose_star: ∀S:DeqSet.∀i:pitem S.
318 •i^* = 〈(\fst(•i))^*,true〉.
321 definition reclose ≝ λS. lift S (eclose S).
322 interpretation "reclose" 'eclose x = (reclose ? x).
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/ * ;
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.
333 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
334 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
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/
347 〈i1,true〉 ▸ i2 = i1 ◂ (•i2).
350 lemma odot_true_bis :
352 〈i1,true〉 ▸ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
353 #S #i1 #i2 normalize cases (•i2) // qed.
357 〈i1,false〉 ▸ i2 = 〈i1 · i2, false〉.
360 lemma LcatE : ∀S.∀e1,e2:pitem S.
361 \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}.
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; ##]
371 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
372 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.*)
374 lemma erase_dot : ∀S.∀e1,e2:pitem S. |e1 · e2| = c ? (|e1|) (|e2|).
377 lemma erase_plus : ∀S.∀i1,i2:pitem S.
378 |i1 + i2| = |i1| + |i2|.
381 lemma erase_star : ∀S.∀i:pitem S.|i^*| = |i|^*.
384 definition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
385 interpretation "substract" 'minus a b = (substract ? a b).
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.
390 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
391 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
393 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
394 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
396 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
397 #S a b w; nnormalize; *; //; nqed. *)
399 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |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) //
409 axiom cat_ext_l: ∀S.∀A,B,C:word S →Prop.
410 A =1 C → A · B =1 C · B.
412 axiom cat_ext_r: ∀S.∀A,B,C:word S →Prop.
413 B =1 C → A · B =1 A · C.
415 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
416 (A ∪ B) · C =1 A · C ∪ B · C.
418 [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/]
421 axiom fix_star: ∀S.∀A:word S → Prop.
422 A^* =1 A · A^* ∪ { [ ] }.
424 axiom star_epsilon: ∀S:DeqSet.∀A:word S → Prop.
425 A^* ∪ { [ ] } =1 A^*.
427 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
428 \sem{〈i^*,true〉} =1 \sem{〈i,false〉}·\sem{|i|}^* ∪ { [ ] }.
432 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
433 \sem{〈i^*,true〉} =1 \sem{〈i,true〉}·\sem{|i|}^* ∪ { [ ] }.
437 [>sem_pre_true >sem_star
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.
446 [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
447 |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
451 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
454 [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
455 |#inA @(ex_intro … [ ]) @(ex_intro … w) /3/
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]
465 (* axiom eplison_cut_l: ∀S.∀A:word S →Prop.
468 axiom eplison_cut_r: ∀S.∀A:word S →Prop.
472 lemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
473 #S p; ncases p; //; nqed.
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;
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/
494 ∀S.∀X:word S → Prop.(X - {[ ]}) · X^* ∪ {[ ]} =1 X^*.
496 axiom sem_fst: ∀S.∀e:pre S. \sem{\fst e} =1 \sem{e}-{[ ]}.
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 - {[ ]}).
502 theorem sem_bull: ∀S:DeqSet. ∀e:pitem S. \sem{•e} =1 \sem{e} ∪ \sem{|e|}.
504 [#w normalize % [/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
512 [|@eqP_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
513 @eqP_trans [|@union_assoc]
514 @eqP_trans [||@eqP_sym @union_assoc]
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
531 definition lifted_cat ≝ λS:DeqSet.λe:pre S.
532 lift S (lc S eclose e).
534 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
536 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
538 lemma sem_odot_true: ∀S:DeqSet.∀e1:pre S.∀i.
539 \sem{e1 ⊙ 〈i,true〉} =1 \sem{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]
549 lemma eq_odot_false: ∀S:DeqSet.∀e1:pre S.∀i.
550 e1 ⊙ 〈i,false〉 = e1 ▸ i.
552 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) ∨ false〉) [//]
553 cases (e1 ▸ i) #i1 #b1 cases b1 #H @H
557 ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
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 //
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;
577 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
578 #S e; @[]; /2/; nqed.
580 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
581 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
583 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
584 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
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); *]
594 theorem sem_ostar: ∀S.∀e:pre S.
595 \sem{e^⊛} =1 \sem{e} · \sem{|\fst e|}^*.
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/
608 nlet rec pre_of_re (S : DeqSet) (e : re S) on e : pitem S ≝
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)].
617 nlemma notFalse : ¬False. @; //; nqed.
619 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
620 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
621 *; #w1; *; #w2; *; *; //; nqed.
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; ##]
633 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
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)^* );
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…); //;
649 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
650 #S f g H; nrewrite > H; //; nqed.
653 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
655 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
656 nrewrite > defsnde; #H;
657 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;