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".
20 include "basics/deqsets.ma".
22 definition word ≝ λS:DeqSet.list S.
24 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
25 interpretation "epsilon" 'epsilon = (nil ?).
28 definition cat : ∀S,l1,l2,w.Prop ≝
29 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
30 notation "a · b" non associative with precedence 65 for @{ 'middot $a $b}.
31 interpretation "cat lang" 'middot a b = (cat ? a b).
33 let rec conjunct (S : DeqSet) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
34 match l with [ nil ⇒ True | cons w tl ⇒ r w ∧ conjunct ? tl r ].
37 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
38 notation "a ^ *" non associative with precedence 90 for @{ 'star $a}.
39 interpretation "star lang" 'star l = (star ? l).
41 lemma cat_ext_l: ∀S.∀A,B,C:word S →Prop.
42 A ≐ C → A · B ≐ C · B.
43 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
47 lemma cat_ext_r: ∀S.∀A,B,C:word S →Prop.
48 B ≐ C → A · B ≐ A · C.
49 #S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2
53 lemma cat_empty_l: ∀S.∀A:word S→Prop. ∅ · A ≐ ∅.
54 #S #A #w % [|*] * #w1 * #w2 * * #_ *
57 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
58 (A ∪ B) · C ≐ A · C ∪ B · C.
60 [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/]
65 definition deriv ≝ λS.λA:word S → Prop.λa,w. A (a::w).
67 lemma deriv_middot: ∀S,A,B,a. ¬ A ϵ →
68 deriv S (A·B) a ≐ (deriv S A a) · B.
69 #S #A #B #a #noteps #w normalize %
71 [* #w2 * * #_ #Aeps @False_ind /2/
72 |#b #w2 * #w3 * * whd in ⊢ ((??%?)→?); #H destruct
73 #H #H1 @(ex_intro … w2) @(ex_intro … w3) % // % //
75 |* #w1 * #w2 * * #H #H1 #H2 @(ex_intro … (a::w1))
76 @(ex_intro … w2) % // % normalize //
81 lemma espilon_in_star: ∀S.∀A:word S → Prop.
83 #S #A @(ex_intro … [ ]) normalize /2/
86 lemma cat_to_star:∀S.∀A:word S → Prop.
87 ∀w1,w2. A w1 → A^* w2 → A^* (w1@w2).
88 #S #A #w1 #w2 #Aw * #l * #H #H1 @(ex_intro … (w1::l))
89 % normalize destruct /2/
92 lemma fix_star: ∀S.∀A:word S → Prop.
95 [* #l generalize in match w; -w cases l [normalize #w * /2/]
96 #w1 #tl #w * whd in ⊢ ((??%?)→?); #eqw whd in ⊢ (%→?); *
97 #w1A #cw1 %1 @(ex_intro … w1) @(ex_intro … (flatten S tl))
98 % destruct /2/ whd @(ex_intro … tl) /2/
99 |* [2: whd in ⊢ (%→?); #eqw <eqw //]
100 * #w1 * #w2 * * #eqw <eqw @cat_to_star
104 lemma star_fix_eps : ∀S.∀A:word S → Prop.
105 A^* ≐ (A - {ϵ}) · A^* ∪ {ϵ}.
108 [* whd in ⊢ ((??%?)→?); #eqw #_ %2 <eqw //
109 |* [#tl #Hind * #H * #_ #H2 @Hind % [@H | //]
110 |#a #w1 #tl #Hind * whd in ⊢ ((??%?)→?); #H1 * #H2 #H3 %1
111 @(ex_intro … (a::w1)) @(ex_intro … (flatten S tl)) %
112 [% [@H1 | normalize % /2/] |whd @(ex_intro … tl) /2/]
115 |* [* #w1 * #w2 * * #eqw * #H1 #_ <eqw @cat_to_star //
116 | whd in ⊢ (%→?); #H <H //
121 lemma star_epsilon: ∀S:DeqSet.∀A:word S → Prop.
126 lemma epsilon_cat_r: ∀S.∀A:word S →Prop.
129 [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
130 |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
134 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
137 [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
138 |#inA @(ex_intro … ϵ) @(ex_intro … w) /3/
142 lemma distr_cat_r_eps: ∀S.∀A,C:word S →Prop.
143 (A ∪ {ϵ}) · C ≐ A · C ∪ C.
144 #S #A #C @eqP_trans [|@distr_cat_r |@eqP_union_l @epsilon_cat_l]