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 ⇒ True | cons w tl ⇒ r w ∧ conjunct ? tl r ].
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 ?).
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).
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). *)
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).
73 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
74 interpretation "star lang" 'pk l = (star ? l).
76 let rec in_l (S : DeqSet) (r : re S) on r : word S → Prop ≝
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) ^*].
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).
89 lemma rsem_star : ∀S.∀r: re S. \sem{r^*} = \sem{r}^*.
92 inductive pitem (S: DeqSet) : Type[0] ≝
97 | pc: pitem S → pitem S → pitem S
98 | po: pitem S → pitem S → pitem S
99 | pk: pitem S → pitem S.
101 definition pre ≝ λS.pitem S × bool.
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).
110 (* to get rid of \middot
111 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
114 interpretation "patom" 'ps a = (ps ? a).
115 interpretation "pepsilon" 'epsilon = (pe ?).
116 interpretation "pempty" 'empty = (pz ?).
118 let rec forget (S: DeqSet) (l : pitem S) on l: re S ≝
124 | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
125 | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
126 | pk E ⇒ (forget ? E)^* ].
128 (* notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.*)
129 interpretation "forget" 'norm a = (forget ? a).
131 let rec in_pl (S : DeqSet) (r : pitem S) on r : word S → Prop ≝
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}^* ].
141 interpretation "in_pl" 'in_l E = (in_pl ? E).
142 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
145 definition epsilon : ∀S:DeqSet.bool → word S → Prop
146 ≝ λS,b.if b then { ([ ] : word S) } else ∅.
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). *)
152 definition in_prl ≝ λS : DeqSet.λp:pre S.
153 if (\snd p) then \sem{\fst p} ∪ { ([ ] : word S) } else \sem{\fst p}.
155 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
156 interpretation "in_prl" 'in_l E = (in_prl ? E).
158 lemma sem_pre_true : ∀S.∀i:pitem S.
159 \sem{〈i,true〉} = \sem{i} ∪ { ([ ] : word S) }.
162 lemma sem_pre_false : ∀S.∀i:pitem S.
163 \sem{〈i,false〉} = \sem{i}.
166 lemma sem_cat: ∀S.∀i1,i2:pitem S.
167 \sem{i1 · i2} = \sem{i1} · \sem{|i2|} ∪ \sem{i2}.
170 lemma sem_cat_w: ∀S.∀i1,i2:pitem S.∀w.
171 \sem{i1 · i2} w = ((\sem{i1} · \sem{|i2|}) w ∨ \sem{i2} w).
174 lemma sem_plus: ∀S.∀i1,i2:pitem S.
175 \sem{i1 + i2} = \sem{i1} ∪ \sem{i2}.
178 lemma sem_plus_w: ∀S.∀i1,i2:pitem S.∀w.
179 \sem{i1 + i2} w = (\sem{i1} w ∨ \sem{i2} w).
182 lemma sem_star : ∀S.∀i:pitem S.
183 \sem{i^*} = \sem{i} · \sem{|i|}^*.
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).
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.
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/
203 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
204 #S * #i #b cases b // normalize #H @False_ind /2/
207 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
208 #S * #i #b #btrue normalize in btrue; >btrue %2 //
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).
215 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1∨b2〉.
218 definition pre_concat_r ≝ λS:DeqSet.λi:pitem S.λe:pre S.
219 match e with [ pair i1 b ⇒ 〈i · i1, b〉].
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).
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).
228 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop.
230 #S #A #B #H >H /2/ qed.
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/
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/]
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/
248 definition lc ≝ λS:DeqSet.λbcast:∀S:DeqSet.pitem S → pre S.λe1:pre S.λi2:pitem S.
250 [ pair i1 b1 ⇒ match b1 with
251 [ true ⇒ (i1 ◂ (bcast ? i2))
252 | false ⇒ 〈i1 · i2,false〉
256 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S.
258 [ pair i b ⇒ 〈\fst (f i), \snd (f i) ∨ b〉].
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).
263 definition lk ≝ λS:DeqSet.λbcast:∀S:DeqSet.∀E:pitem S.pre S.λe:pre S.
267 [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
268 |false ⇒ 〈i1^*,false〉
273 lemma oplus_tt : ∀S: DeqSet.∀i1,i2:pitem S.
274 〈i1,true〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
277 lemma oplus_tf : ∀S: DeqSet.∀i1,i2:pitem S.
278 〈i1,true〉 ⊕ 〈i2,false〉 = 〈i1 + i2,true〉.
281 lemma oplus_ft : ∀S: DeqSet.∀i1,i2:pitem S.
282 〈i1,false〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
285 lemma oplus_ff : ∀S: DeqSet.∀i1,i2:pitem S.
286 〈i1,false〉 ⊕ 〈i2,false〉 = 〈i1 + i2,false〉.
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}.
293 notation "•" non associative with precedence 60 for @{eclose ?}.
295 let rec eclose (S: DeqSet) (i: pitem S) on i : pre S ≝
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〉].
305 notation "• x" non associative with precedence 60 for @{'eclose $x}.
306 interpretation "eclose" 'eclose x = (eclose ? x).
308 lemma eclose_plus: ∀S:DeqSet.∀i1,i2:pitem S.
309 •(i1 + i2) = •i1 ⊕ •i2.
312 lemma eclose_dot: ∀S:DeqSet.∀i1,i2:pitem S.
313 •(i1 · i2) = •i1 ▸ i2.
316 lemma eclose_star: ∀S:DeqSet.∀i:pitem S.
317 •i^* = 〈(\fst(•i))^*,true〉.
320 definition reclose ≝ λS. lift S (eclose S).
321 interpretation "reclose" 'eclose x = (reclose ? x).
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/ * ;
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.
332 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
333 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
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/
346 〈i1,true〉 ▸ i2 = i1 ◂ (•i2).
349 lemma odot_true_bis :
351 〈i1,true〉 ▸ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
352 #S #i1 #i2 normalize cases (•i2) // qed.
356 〈i1,false〉 ▸ i2 = 〈i1 · i2, false〉.
359 lemma LcatE : ∀S.∀e1,e2:pitem S.
360 \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}.
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; ##]
370 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
371 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.*)
373 lemma erase_dot : ∀S.∀e1,e2:pitem S. |e1 · e2| = c ? (|e1|) (|e2|).
376 lemma erase_plus : ∀S.∀i1,i2:pitem S.
377 |i1 + i2| = |i1| + |i2|.
380 lemma erase_star : ∀S.∀i:pitem S.|i^*| = |i|^*.
383 definition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
384 interpretation "substract" 'minus a b = (substract ? a b).
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.
389 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
390 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
392 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
393 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
395 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
396 #S a b w; nnormalize; *; //; nqed. *)
398 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |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) //
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
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
420 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
421 (A ∪ B) · C =1 A · C ∪ B · C.
423 [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/]
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
432 lemma fix_star: ∀S.∀A:word S → Prop.
433 A^* =1 A · A^* ∪ { [ ] }.
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 ?)) //]
444 [#w1 #w2 #H cases (nil_to_nil … (sym_eq … H)) #_ #H >H #_
445 @(ex_intro … (nil ?)) /2/
447 [#w2 whd in ⊢ ((???%)→?); #eqw2 <eqw2 *
449 [* * whd in ⊢ ((??%?)→?); #H <H //
450 |#b #w5 * * whd in ⊢ ((??%?)→?); #H destruct
451 #H1 * #l * #H2 #H3 @(ex_intro … ((a::w5)::l)) %
454 |#b #w2 #w3 whd in ⊢ ((???%)→?); #H destruct #H1
461 axiom star_epsilon: ∀S:DeqSet.∀A:word S → Prop.
462 A^* ∪ { [ ] } =1 A^*.
464 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
465 \sem{〈i^*,true〉} =1 \sem{〈i,false〉}·\sem{|i|}^* ∪ { [ ] }.
469 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
470 \sem{〈i^*,true〉} =1 \sem{〈i,true〉}·\sem{|i|}^* ∪ { [ ] }.
474 [>sem_pre_true >sem_star
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.
483 [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
484 |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
488 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
491 [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
492 |#inA @(ex_intro … [ ]) @(ex_intro … w) /3/
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]
502 (* axiom eplison_cut_l: ∀S.∀A:word S →Prop.
505 axiom eplison_cut_r: ∀S.∀A:word S →Prop.
509 lemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
510 #S p; ncases p; //; nqed.
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;
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/
531 ∀S.∀X:word S → Prop.(X - {[ ]}) · X^* ∪ {[ ]} =1 X^*.
533 axiom sem_fst: ∀S.∀e:pre S. \sem{\fst e} =1 \sem{e}-{[ ]}.
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 - {[ ]}).
539 theorem sem_bull: ∀S:DeqSet. ∀e:pitem S. \sem{•e} =1 \sem{e} ∪ \sem{|e|}.
541 [#w normalize % [/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
549 [|@eqP_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
550 @eqP_trans [|@union_assoc]
551 @eqP_trans [||@eqP_sym @union_assoc]
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
568 definition lifted_cat ≝ λS:DeqSet.λe:pre S.
569 lift S (lc S eclose e).
571 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
573 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
575 lemma sem_odot_true: ∀S:DeqSet.∀e1:pre S.∀i.
576 \sem{e1 ⊙ 〈i,true〉} =1 \sem{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]
586 lemma eq_odot_false: ∀S:DeqSet.∀e1:pre S.∀i.
587 e1 ⊙ 〈i,false〉 = e1 ▸ i.
589 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) ∨ false〉) [//]
590 cases (e1 ▸ i) #i1 #b1 cases b1 #H @H
594 ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
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 //
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;
614 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
615 #S e; @[]; /2/; nqed.
617 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
618 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
620 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
621 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
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); *]
631 theorem sem_ostar: ∀S.∀e:pre S.
632 \sem{e^⊛} =1 \sem{e} · \sem{|\fst e|}^*.
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/
645 nlet rec pre_of_re (S : DeqSet) (e : re S) on e : pitem S ≝
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)].
654 nlemma notFalse : ¬False. @; //; nqed.
656 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
657 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
658 *; #w1; *; #w2; *; *; //; nqed.
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; ##]
670 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
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)^* );
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…); //;
686 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
687 #S f g H; nrewrite > H; //; nqed.
690 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
692 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
693 nrewrite > defsnde; #H;
694 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;