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/list.ma".
18 interpretation "iff" 'iff a b = (iff a b).
20 record Alpha : Type[1] ≝ { carr :> Type[0];
21 eqb: carr → carr → bool;
22 eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y)
25 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
26 interpretation "eqb" 'eqb a b = (eqb ? a b).
28 definition word ≝ λS:Alpha.list S.
30 inductive re (S: Alpha) : Type[0] ≝
34 | c: re S → re S → re S
35 | o: re S → re S → re S
38 (* notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.*)
39 notation "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
40 interpretation "star" 'pk a = (k ? a).
41 interpretation "or" 'plus a b = (o ? a b).
43 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
44 interpretation "cat" 'pc a b = (c ? a b).
46 (* to get rid of \middot
47 ncoercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
50 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
51 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
52 interpretation "atom" 'ps a = (s ? a).
54 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
55 interpretation "epsilon" 'epsilon = (e ?).
57 notation "∅" non associative with precedence 90 for @{ 'empty }.
58 interpretation "empty" 'empty = (z ?).
60 let rec flatten (S : Alpha) (l : list (word S)) on l : word S ≝
61 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
63 let rec conjunct (S : Alpha) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
64 match l with [ nil ⇒ ? | cons w tl ⇒ r w ∧ conjunct ? tl r ].
67 definition empty_lang ≝ λS.λw:word S.False.
68 notation "{}" non associative with precedence 90 for @{'empty_lang}.
69 interpretation "empty lang" 'empty_lang = (empty_lang ?).
71 definition sing_lang ≝ λS.λx,w:word S.x=w.
72 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.*)
73 interpretation "sing lang" 'singl x = (sing_lang ? x).
75 definition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
76 interpretation "union lang" 'union a b = (union ? a b).
78 definition cat : ∀S,l1,l2,w.Prop ≝
79 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
80 interpretation "cat lang" 'pc a b = (cat ? a b).
82 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
83 interpretation "star lang" 'pk l = (star ? l).
85 let rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
90 | c r1 r2 ⇒ (in_l ? r1) · (in_l ? r2)
91 | o r1 r2 ⇒ (in_l ? r1) ∪ (in_l ? r2)
92 | k r1 ⇒ (in_l ? r1) ^*].
94 notation "\sem{term 19 E}" non associative with precedence 75 for @{'in_l $E}.
95 interpretation "in_l" 'in_l E = (in_l ? E).
96 interpretation "in_l mem" 'mem w l = (in_l ? l w).
98 lemma rsem_star : ∀S.∀r: re S. \sem{r^*} = \sem{r}^*.
101 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
102 interpretation "orb" 'orb a b = (orb a b).
104 definition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
105 notation > "'if' term 19 e 'then' term 19 t 'else' term 19 f" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
106 notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
107 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
109 inductive pitem (S: Alpha) : Type[0] ≝
114 | pc: pitem S → pitem S → pitem S
115 | po: pitem S → pitem S → pitem S
116 | pk: pitem S → pitem S.
118 definition pre ≝ λS.pitem S × bool.
120 interpretation "pstar" 'pk a = (pk ? a).
121 interpretation "por" 'plus a b = (po ? a b).
122 interpretation "pcat" 'pc a b = (pc ? a b).
123 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
124 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
125 interpretation "ppatom" 'pp a = (pp ? a).
127 (* to get rid of \middot
128 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
131 interpretation "patom" 'ps a = (ps ? a).
132 interpretation "pepsilon" 'epsilon = (pe ?).
133 interpretation "pempty" 'empty = (pz ?).
135 let rec forget (S: Alpha) (l : pitem S) on l: re S ≝
141 | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
142 | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
143 | pk E ⇒ (forget ? E)^* ].
145 (* notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.*)
146 interpretation "forget" 'norm a = (forget ? a).
148 let rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
154 | pc r1 r2 ⇒ (in_pl ? r1) · \sem{forget ? r2} ∪ (in_pl ? r2)
155 | po r1 r2 ⇒ (in_pl ? r1) ∪ (in_pl ? r2)
156 | pk r1 ⇒ (in_pl ? r1) · \sem{forget ? r1}^* ].
158 interpretation "in_pl" 'in_l E = (in_pl ? E).
159 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
161 definition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
163 interpretation "epsilon" 'epsilon = (epsilon ?).
164 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
165 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
167 definition in_prl ≝ λS : Alpha.λp:pre S.
168 if (\snd p) then \sem{\fst p} ∪ { ([ ] : word S) } else \sem{\fst p}.
170 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
171 interpretation "in_prl" 'in_l E = (in_prl ? E).
173 lemma sem_pre_true : ∀S.∀i:pitem S.
174 \sem{〈i,true〉} = \sem{i} ∪ { ([ ] : word S) }.
177 lemma sem_pre_false : ∀S.∀i:pitem S.
178 \sem{〈i,false〉} = \sem{i}.
181 lemma sem_cat: ∀S.∀i1,i2:pitem S.
182 \sem{i1 · i2} = \sem{i1} · \sem{|i2|} ∪ \sem{i2}.
185 lemma sem_cat_w: ∀S.∀i1,i2:pitem S.∀w.
186 \sem{i1 · i2} w = ((\sem{i1} · \sem{|i2|}) w ∨ \sem{i2} w).
189 lemma sem_plus: ∀S.∀i1,i2:pitem S.
190 \sem{i1 + i2} = \sem{i1} ∪ \sem{i2}.
193 lemma sem_plus_w: ∀S.∀i1,i2:pitem S.∀w.
194 \sem{i1 + i2} w = (\sem{i1} w ∨ \sem{i2} w).
197 lemma sem_star : ∀S.∀i:pitem S.
198 \sem{i^*} = \sem{i} · \sem{|i|}^*.
201 lemma sem_star_w : ∀S.∀i:pitem S.∀w.
202 \sem{i^*} w = (∃w1,w2.w1 @ w2 = w ∧ \sem{i} w1 ∧ \sem{|i|}^* w2).
205 lemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
206 #S #w1 #w2 cases w1 // #a #tl normalize #H destruct qed.
208 lemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ e).
209 #S #e elim e normalize /2/
210 [#r1 #r2 * #n1 #n2 % * /2/ * #w1 * #w2 * * #H
211 >(append_eq_nil …H…) /2/
212 |#r1 #r2 #n1 #n2 % * /2/
213 |#r #n % * #w1 * #w2 * * #H >(append_eq_nil …H…) /2/
218 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
219 #S * #i #b cases b // normalize #H @False_ind /2/
222 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
223 #S * #i #b #btrue normalize in btrue; >btrue %2 //
226 definition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
227 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
228 interpretation "oplus" 'oplus a b = (lo ? a b).
230 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1||b2〉.
233 definition pre_concat_r ≝ λS:Alpha.λi:pitem S.λe:pre S.
234 match e with [ pair i1 b ⇒ 〈i · i1, b〉].
236 notation "i ◂ e" left associative with precedence 60 for @{'ltrif $i $e}.
237 interpretation "pre_concat_r" 'ltrif i e = (pre_concat_r ? i e).
239 definition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
240 notation "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
241 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
243 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop.
245 #S #A #B #H >H /2/ qed.
247 lemma ext_eq_trans: ∀S.∀A,B,C:word S → Prop.
248 A =1 B → B =1 C → A =1 C.
249 #S #A #B #C #eqAB #eqBC #w cases (eqAB w) cases (eqBC w) /4/
252 lemma union_assoc: ∀S.∀A,B,C:word S → Prop.
253 A ∪ B ∪ C =1 A ∪ (B ∪ C).
254 #S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/]
257 lemma sem_pre_concat_r : ∀S,i.∀e:pre S.
258 \sem{i ◂ e} =1 \sem{i} · \sem{|\fst e|} ∪ \sem{e}.
259 #S #i * #i1 #b1 cases b1 /2/
260 >sem_pre_true >sem_cat >sem_pre_true /2/
263 definition lc ≝ λS:Alpha.λbcast:∀S:Alpha.pitem S → pre S.λe1:pre S.λi2:pitem S.
265 [ pair i1 b1 ⇒ match b1 with
266 [ true ⇒ (i1 ◂ (bcast ? i2))
267 | false ⇒ 〈i1 · i2,false〉
271 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S.
273 [ pair i b ⇒ 〈\fst (f i), \snd (f i) || b〉].
275 notation "a ▸ b" left associative with precedence 60 for @{'lc eclose $a $b}.
276 interpretation "lc" 'lc op a b = (lc ? op a b).
278 definition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λe:pre S.
282 [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
283 |false ⇒ 〈i1^*,false〉
288 lemma oplus_tt : ∀S: Alpha.∀i1,i2:pitem S.
289 〈i1,true〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
292 lemma oplus_tf : ∀S: Alpha.∀i1,i2:pitem S.
293 〈i1,true〉 ⊕ 〈i2,false〉 = 〈i1 + i2,true〉.
296 lemma oplus_ft : ∀S: Alpha.∀i1,i2:pitem S.
297 〈i1,false〉 ⊕ 〈i2,true〉 = 〈i1 + i2,true〉.
300 lemma oplus_ff : ∀S: Alpha.∀i1,i2:pitem S.
301 〈i1,false〉 ⊕ 〈i2,false〉 = 〈i1 + i2,false〉.
304 (* notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.*)
305 interpretation "lk" 'lk op a = (lk ? op a).
306 notation "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
308 notation "•" non associative with precedence 60 for @{eclose ?}.
310 let rec eclose (S: Alpha) (i: pitem S) on i : pre S ≝
314 | ps x ⇒ 〈 `.x, false〉
315 | pp x ⇒ 〈 `.x, false 〉
316 | po i1 i2 ⇒ •i1 ⊕ •i2
317 | pc i1 i2 ⇒ •i1 ▸ i2
318 | pk i ⇒ 〈(\fst (•i))^*,true〉].
320 notation "• x" non associative with precedence 60 for @{'eclose $x}.
321 interpretation "eclose" 'eclose x = (eclose ? x).
323 lemma eclose_plus: ∀S:Alpha.∀i1,i2:pitem S.
324 •(i1 + i2) = •i1 ⊕ •i2.
327 lemma eclose_dot: ∀S:Alpha.∀i1,i2:pitem S.
328 •(i1 · i2) = •i1 ▸ i2.
331 lemma eclose_star: ∀S:Alpha.∀i:pitem S.
332 •i^* = 〈(\fst(•i))^*,true〉.
335 definition reclose ≝ λS. lift S (eclose S).
336 interpretation "reclose" 'eclose x = (reclose ? x).
338 lemma epsilon_or : ∀S:Alpha.∀b1,b2. epsilon S (b1 || b2) =1 ϵ b1 ∪ ϵ b2.
339 #S #b1 #b2 #w % cases b1 cases b2 normalize /2/ * /2/ * ;
343 lemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
344 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
346 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
347 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
350 lemma sem_oplus: ∀S:Alpha.∀e1,e2:pre S.
351 \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}.
352 #S * #i1 #b1 * #i2 #b2 #w %
353 [cases b1 cases b2 normalize /2/ * /3/ * /3/
354 |cases b1 cases b2 normalize /2/ * /3/ * /3/
360 〈i1,true〉 ▸ i2 = i1 ◂ (•i2).
363 lemma odot_true_bis :
365 〈i1,true〉 ▸ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
366 #S #i1 #i2 normalize cases (•i2) // qed.
370 〈i1,false〉 ▸ i2 = 〈i1 · i2, false〉.
373 lemma LcatE : ∀S.∀e1,e2:pitem S.
374 \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}.
378 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
379 #S p q r; napply extP; #w; nnormalize; @;
380 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
381 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
384 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
385 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.*)
387 lemma erase_dot : ∀S.∀e1,e2:pitem S. |e1 · e2| = c ? (|e1|) (|e2|).
390 lemma erase_plus : ∀S.∀i1,i2:pitem S.
391 |i1 + i2| = |i1| + |i2|.
394 lemma erase_star : ∀S.∀i:pitem S.|i^*| = |i|^*.
397 definition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
398 interpretation "substract" 'minus a b = (substract ? a b).
400 (* nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
401 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
403 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
404 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
406 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
407 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
409 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
410 #S a b w; nnormalize; *; //; nqed. *)
412 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |i|.
414 [ #i1 #i2 #IH1 #IH2 >erase_dot <IH1 >eclose_dot
415 cases (•i1) #i11 #b1 cases b1 // <IH2 >odot_true_bis //
416 | #i1 #i2 #IH1 #IH2 >eclose_plus >(erase_plus … i1) <IH1 <IH2
417 cases (•i1) #i11 #b1 cases (•i2) #i21 #b2 //
418 | #i #IH >eclose_star >(erase_star … i) <IH cases (•i) //
422 axiom eq_ext_sym: ∀S.∀A,B:word S →Prop.
425 axiom union_ext_l: ∀S.∀A,B,C:word S →Prop.
426 A =1 C → A ∪ B =1 C ∪ B.
428 axiom union_ext_r: ∀S.∀A,B,C:word S →Prop.
429 B =1 C → A ∪ B =1 A ∪ C.
431 axiom union_comm : ∀S.∀A,B:word S →Prop.
434 axiom union_idemp: ∀S.∀A:word S →Prop.
437 axiom cat_ext_l: ∀S.∀A,B,C:word S →Prop.
438 A =1 C → A · B =1 C · B.
440 axiom cat_ext_r: ∀S.∀A,B,C:word S →Prop.
441 B =1 C → A · B =1 A · C.
443 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
444 (A ∪ B) · C =1 A · C ∪ B · C.
446 [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/]
449 axiom fix_star: ∀S.∀A:word S → Prop.
450 A^* =1 A · A^* ∪ { [ ] }.
452 axiom star_epsilon: ∀S:Alpha.∀A:word S → Prop.
453 A^* ∪ { [ ] } =1 A^*.
455 lemma sem_eclose_star: ∀S:Alpha.∀i:pitem S.
456 \sem{〈i^*,true〉} =1 \sem{〈i,false〉}·\sem{|i|}^* ∪ { [ ] }.
460 lemma sem_eclose_star: ∀S:Alpha.∀i:pitem S.
461 \sem{〈i^*,true〉} =1 \sem{〈i,true〉}·\sem{|i|}^* ∪ { [ ] }.
465 [>sem_pre_true >sem_star
469 (* this kind of results are pretty bad for automation;
470 better not index them *)
471 lemma epsilon_cat_r: ∀S.∀A:word S →Prop.
474 [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
475 |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
479 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
482 [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
483 |#inA @(ex_intro … [ ]) @(ex_intro … w) /3/
488 lemma distr_cat_r_eps: ∀S.∀A,C:word S →Prop.
489 (A ∪ { [ ] }) · C =1 A · C ∪ C.
490 #S #A #C @ext_eq_trans [|@distr_cat_r |@union_ext_r @epsilon_cat_l]
493 (* axiom eplison_cut_l: ∀S.∀A:word S →Prop.
496 axiom eplison_cut_r: ∀S.∀A:word S →Prop.
500 lemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
501 #S p; ncases p; //; nqed.
503 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
504 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
505 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
508 (* theorem 16: 1 → 3 *)
509 lemma odot_dot_aux : ∀S.∀e1:pre S.∀i2:pitem S.
510 \sem{•i2} =1 \sem{i2} ∪ \sem{|i2|} →
511 \sem{e1 ▸ i2} =1 \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
512 #S * #i1 #b1 #i2 cases b1
513 [2:#th >odot_false >sem_pre_false >sem_pre_false >sem_cat /2/
514 |#H >odot_true >sem_pre_true @(ext_eq_trans … (sem_pre_concat_r …))
515 >erase_bull @ext_eq_trans [|@(union_ext_r … H)]
516 @ext_eq_trans [|@union_ext_r [|@union_comm ]]
517 @ext_eq_trans [|@eq_ext_sym @union_assoc ] /3/
522 ∀S.∀X:word S → Prop.(X - {[ ]}) · X^* ∪ {[ ]} =1 X^*.
524 axiom sem_fst: ∀S.∀e:pre S. \sem{\fst e} =1 \sem{e}-{[ ]}.
526 axiom sem_fst_aux: ∀S.∀e:pre S.∀i:pitem S.∀A.
527 \sem{e} =1 \sem{i} ∪ A → \sem{\fst e} =1 \sem{i} ∪ (A - {[ ]}).
530 theorem sem_bull: ∀S:Alpha. ∀e:pitem S. \sem{•e} =1 \sem{e} ∪ \sem{|e|}.
532 [#w normalize % [/2/ | * //]
534 |#x normalize #w % [ /2/ | * [@False_ind | //]]
535 |#x normalize #w % [ /2/ | * // ]
536 |#i1 #i2 #IH1 #IH2 >eclose_dot
537 @ext_eq_trans [|@odot_dot_aux //] >sem_cat
540 [|@ext_eq_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
541 @ext_eq_trans [|@union_assoc]
542 @ext_eq_trans [||@eq_ext_sym @union_assoc]
544 |#i1 #i2 #IH1 #IH2 >eclose_plus
545 @ext_eq_trans [|@sem_oplus] >sem_plus >erase_plus
546 @ext_eq_trans [|@(union_ext_r … IH2)]
547 @ext_eq_trans [|@eq_ext_sym @union_assoc]
548 @ext_eq_trans [||@union_assoc] @union_ext_l
549 @ext_eq_trans [||@eq_ext_sym @union_assoc]
550 @ext_eq_trans [||@union_ext_r [|@union_comm]]
551 @ext_eq_trans [||@union_assoc] /3/
552 |#i #H >sem_pre_true >sem_star >erase_bull >sem_star
553 @ext_eq_trans [|@union_ext_l [|@cat_ext_l [|@sem_fst_aux //]]]
554 @ext_eq_trans [|@union_ext_l [|@distr_cat_r]]
555 @ext_eq_trans [|@union_assoc] @union_ext_r >erase_star @star_fix
559 definition lifted_cat ≝ λS:Alpha.λe:pre S.
560 lift S (lc S eclose e).
562 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
564 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
566 lemma sem_odot_true: ∀S:Alpha.∀e1:pre S.∀i.
567 \sem{e1 ⊙ 〈i,true〉} =1 \sem{e1 ▸ i} ∪ { [ ] }.
569 cut (e1 ⊙ 〈i,true〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) || true〉) [//]
570 #H >H cases (e1 ▸ i) #i1 #b1 cases b1
571 [>sem_pre_true @ext_eq_trans [||@eq_ext_sym @union_assoc]
577 lemma eq_odot_false: ∀S:Alpha.∀e1:pre S.∀i.
578 e1 ⊙ 〈i,false〉 = e1 ▸ i.
580 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▸ i), \snd(e1 ▸ i) || false〉) [//]
581 cases (e1 ▸ i) #i1 #b1 cases b1 #H @H
585 ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
588 @ext_eq_trans [|@sem_odot_true]
589 @ext_eq_trans [||@union_assoc] @union_ext_l @odot_dot_aux //
590 |>sem_pre_false >eq_odot_false @odot_dot_aux //
595 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
596 #S e; napply extP; #w; nnormalize; @;
597 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
598 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
599 nrewrite < defw; nrewrite < defw2; @; //; @;//;
600 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
601 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
605 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
606 #S e; @[]; /2/; nqed.
608 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
609 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
611 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
612 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
614 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
615 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
616 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
617 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
622 theorem sem_ostar: ∀S.∀e:pre S.
623 \sem{e^⊛} =1 \sem{e} · \sem{|\fst e|}^*.
625 [>sem_pre_true >sem_pre_true >sem_star >erase_bull
626 @ext_eq_trans [|@union_ext_l [|@cat_ext_l [|@sem_fst_aux //]]]
627 @ext_eq_trans [|@union_ext_l [|@distr_cat_r]]
628 @ext_eq_trans [||@eq_ext_sym @distr_cat_r]
629 @ext_eq_trans [|@union_assoc] @union_ext_r
630 @ext_eq_trans [||@eq_ext_sym @epsilon_cat_l] @star_fix
631 |>sem_pre_false >sem_pre_false >sem_star /2/
636 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
641 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
642 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
643 | k e1 ⇒ pk ? (pre_of_re ? e1)].
645 nlemma notFalse : ¬False. @; //; nqed.
647 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
648 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
649 *; #w1; *; #w2; *; *; //; nqed.
651 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
652 #S e; nelim e; ##[##1,2,3: //]
653 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
654 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
655 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
656 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
657 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
658 nrewrite > H1; napply dot0; ##]
661 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
663 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
664 nrewrite < H1; nrewrite < H2; //
665 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
666 nrewrite < H1; nrewrite < H2; //
667 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
672 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
673 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
674 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
677 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
678 #S f g H; nrewrite > H; //; nqed.
681 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
683 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
684 nrewrite > defsnde; #H;
685 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;