3 (**************************************************************************)
6 (* ||A|| A project by Andrea Asperti *)
8 (* ||I|| Developers: *)
9 (* ||T|| The HELM team. *)
10 (* ||A|| http://helm.cs.unibo.it *)
12 (* \ / This file is distributed under the terms of the *)
13 (* v GNU General Public License Version 2 *)
15 (**************************************************************************)
17 include "arithmetics/nat.ma".
18 include "basics/lists/list.ma".
19 include "basics/sets.ma".
21 definition word ≝ λS:DeqSet.list S.
23 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
24 interpretation "epsilon" 'epsilon = (nil ?).
27 definition cat : ∀S,l1,l2,w.Prop ≝
28 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
29 notation "a · b" non associative with precedence 60 for @{ 'middot $a $b}.
30 interpretation "cat lang" 'middot a b = (cat ? a b).
32 let rec flatten (S : DeqSet) (l : list (word S)) on l : word S ≝
33 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
35 let rec conjunct (S : DeqSet) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
36 match l with [ nil ⇒ True | cons w tl ⇒ r w ∧ conjunct ? tl r ].
39 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
40 notation "a ^ *" non associative with precedence 90 for @{ 'star $a}.
41 interpretation "star lang" 'star l = (star ? l).
43 lemma cat_ext_l: ∀S.∀A,B,C:word S →Prop.
44 A =1 C → A · B =1 C · B.
45 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
49 lemma cat_ext_r: ∀S.∀A,B,C:word S →Prop.
50 B =1 C → A · B =1 A · C.
51 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
55 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
56 (A ∪ B) · C =1 A · C ∪ B · C.
58 [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/]
61 lemma espilon_in_star: ∀S.∀A:word S → Prop.
63 #S #A @(ex_intro … [ ]) normalize /2/
66 lemma cat_to_star:∀S.∀A:word S → Prop.
67 ∀w1,w2. A w1 → A^* w2 → A^* (w1@w2).
68 #S #A #w1 #w2 #Aw * #l * #H #H1 @(ex_intro … (w1::l))
72 lemma fix_star: ∀S.∀A:word S → Prop.
75 [* #l generalize in match w; -w cases l [normalize #w * /2/]
76 #w1 #tl #w * whd in ⊢ ((??%?)→?); #eqw whd in ⊢ (%→?); *
77 #w1A #cw1 %1 @(ex_intro … w1) @(ex_intro … (flatten S tl))
78 % /2/ whd @(ex_intro … tl) /2/
79 |* [2: whd in ⊢ (%→?); #eqw <eqw //]
80 * #w1 * #w2 * * #eqw <eqw @cat_to_star
84 lemma star_fix_eps : ∀S.∀A:word S → Prop.
85 A^* =1 (A - {ϵ}) · A^* ∪ {ϵ}.
88 [* whd in ⊢ ((??%?)→?); #eqw #_ %2 <eqw //
89 |* [#tl #Hind * #H * #_ #H2 @Hind % [@H | //]
90 |#a #w1 #tl #Hind * whd in ⊢ ((??%?)→?); #H1 * #H2 #H3 %1
91 @(ex_intro … (a::w1)) @(ex_intro … (flatten S tl)) %
92 [% [@H1 | normalize % /2/] |whd @(ex_intro … tl) /2/]
95 |* [* #w1 * #w2 * * #eqw * #H1 #_ <eqw @cat_to_star //
96 | whd in ⊢ (%→?); #H <H //
101 lemma star_epsilon: ∀S:DeqSet.∀A:word S → Prop.
106 lemma epsilon_cat_r: ∀S.∀A:word S →Prop.
109 [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
110 |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
114 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
117 [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
118 |#inA @(ex_intro … ϵ) @(ex_intro … w) /3/
122 lemma distr_cat_r_eps: ∀S.∀A,C:word S →Prop.
123 (A ∪ {ϵ}) · C =1 A · C ∪ C.
124 #S #A #C @eqP_trans [|@distr_cat_r |@eqP_union_l @epsilon_cat_l]