4 Intuitively, a regular expression e must be understood as a pointed expression with a single
5 point in front of it. Since however we only allow points before symbols, we must broadcast
6 this initial point inside e traversing all nullable subexpressions, that essentially corresponds
7 to the ϵ-closure operation on automata. We use the notation •(_) to denote such an operation;
8 its definition is the expected one: let us start discussing an example.
11 Let us broadcast a point inside (a + ϵ)(b*a + b)b. We start working in parallel on the
12 first occurrence of a (where the point stops), and on ϵ that gets traversed. We have hence
13 reached the end of a + ϵ and we must pursue broadcasting inside (b*a + b)b. Again, we work in
14 parallel on the two additive subterms b^*a and b; the first point is allowed to both enter the
15 star, and to traverse it, stopping in front of a; the second point just stops in front of b.
16 No point reached that end of b^*a + b hence no further propagation is possible. In conclusion:
17 •((a + ϵ)(b^*a + b)b) = 〈(•a + ϵ)((•b)^*•a + •b)b, false〉
20 include "tutorial/chapter7.ma".
22 (* Broadcasting a point inside an item generates a pre, since the point could possibly reach
23 the end of the expression.
24 Broadcasting inside a i1+i2 amounts to broadcast in parallel inside i1 and i2.
26 〈i1,b1〉 ⊕ 〈i2,b2〉 = 〈i1 + i2, b1∨ b2〉
27 then, we just have •(i1+i2) = •(i1)⊕ •(i2).
30 definition lo ≝ λS:DeqSet.λa,b:pre S.〈\fst a + \fst b,\snd a ∨ \snd b〉.
31 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
32 interpretation "oplus" 'oplus a b = (lo ? a b).
34 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1∨b2〉.
38 Concatenation is a bit more complex. In order to broadcast a point inside i1 · i2
39 we should start broadcasting it inside i1 and then proceed into i2 if and only if a
40 point reached the end of i1. This suggests to define •(i1 · i2) as •(i1) ▹ i2, where
41 e ▹ i is a general operation of concatenation between a pre and an item, defined by
42 cases on the boolean in e:
44 〈i1,true〉 ▹ i2 = i1 ◃ •(i_2)
45 〈i1,false〉 ▹ i2 = i1 · i2
46 In turn, ◃ says how to concatenate an item with a pre, that is however extremely simple:
47 i1 ◃ 〈i1,b〉 = 〈i_1 · i2, b〉
48 Let us come to the formalized definitions:
51 definition pre_concat_r ≝ λS:DeqSet.λi:pitem S.λe:pre S.
52 match e with [ mk_Prod i1 b ⇒ 〈i · i1, b〉].
54 notation "i ◃ e" left associative with precedence 60 for @{'lhd $i $e}.
55 interpretation "pre_concat_r" 'lhd i e = (pre_concat_r ? i e).
57 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop.
59 #S #A #B #H >H #x % // qed.
61 (* The behaviour of ◃ is summarized by the following, easy lemma: *)
63 lemma sem_pre_concat_r : ∀S,i.∀e:pre S.
64 \sem{i ◃ e} =1 \sem{i} · \sem{|\fst e|} ∪ \sem{e}.
65 #S #i * #i1 #b1 cases b1 [2: @eq_to_ex_eq //]
66 >sem_pre_true >sem_cat >sem_pre_true /2/
69 (* The definition of $•(-)$ (eclose) and ▹ (pre_concat_l) are mutually recursive.
70 In this situation, a viable alternative that is usually simpler to reason about,
71 is to abstract one of the two functions with respect to the other. In particular
72 we abstract pre_concat_l with respect to an input bcast function from items to
75 definition pre_concat_l ≝ λS:DeqSet.λbcast:∀S:DeqSet.pitem S → pre S.λe1:pre S.λi2:pitem S.
77 [ mk_Prod i1 b1 ⇒ match b1 with
78 [ true ⇒ (i1 ◃ (bcast ? i2))
79 | false ⇒ 〈i1 · i2,false〉
83 notation "a ▹ b" left associative with precedence 60 for @{'tril eclose $a $b}.
84 interpretation "item-pre concat" 'tril op a b = (pre_concat_l ? op a b).
86 (* We are ready to give the formal definition of the broadcasting operation. *)
88 notation "•" non associative with precedence 60 for @{eclose ?}.
90 let rec eclose (S: DeqSet) (i: pitem S) on i : pre S ≝
92 [ pz ⇒ 〈 pz ?, false 〉
94 | ps x ⇒ 〈 `.x, false 〉
95 | pp x ⇒ 〈 `.x, false 〉
96 | po i1 i2 ⇒ •i1 ⊕ •i2
98 | pk i ⇒ 〈(\fst (•i))^*,true〉].
100 notation "• x" non associative with precedence 60 for @{'eclose $x}.
101 interpretation "eclose" 'eclose x = (eclose ? x).
103 (* Here are a few simple properties of ▹ and •(-) *)
105 lemma pcl_true : ∀S.∀i1,i2:pitem S.
106 〈i1,true〉 ▹ i2 = i1 ◃ (•i2).
109 lemma pcl_true_bis : ∀S.∀i1,i2:pitem S.
110 〈i1,true〉 ▹ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
111 #S #i1 #i2 normalize cases (•i2) // qed.
113 lemma pcl_false: ∀S.∀i1,i2:pitem S.
114 〈i1,false〉 ▹ i2 = 〈i1 · i2, false〉.
117 lemma eclose_plus: ∀S:DeqSet.∀i1,i2:pitem S.
118 •(i1 + i2) = •i1 ⊕ •i2.
121 lemma eclose_dot: ∀S:DeqSet.∀i1,i2:pitem S.
122 •(i1 · i2) = •i1 ▹ i2.
125 lemma eclose_star: ∀S:DeqSet.∀i:pitem S.
126 •i^* = 〈(\fst(•i))^*,true〉.
129 (* The definition of •(-) (eclose) can then be lifted from items to pres
130 in the obvious way. *)
132 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S.
134 [ mk_Prod i b ⇒ 〈\fst (f i), \snd (f i) ∨ b〉].
136 definition preclose ≝ λS. lift S (eclose S).
137 interpretation "preclose" 'eclose x = (preclose ? x).
139 (* Obviously, broadcasting does not change the carrier of the item,
140 as it is easily proved by structural induction. *)
142 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |i|.
144 [ #i1 #i2 #IH1 #IH2 >erase_dot <IH1 >eclose_dot
145 cases (•i1) #i11 #b1 cases b1 // <IH2 >pcl_true_bis //
146 | #i1 #i2 #IH1 #IH2 >eclose_plus >(erase_plus … i1) <IH1 <IH2
147 cases (•i1) #i11 #b1 cases (•i2) #i21 #b2 //
148 | #i #IH >eclose_star >(erase_star … i) <IH cases (•i) //
152 (* We are now ready to state the main semantic properties of ⊕, ◃ and •(-):
154 sem_oplus: \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}
155 sem_pcl: \sem{e1 ▹ i2} =1 \sem{e1} · \sem{|i2|} ∪ \sem{i2}
156 sem_bullet \sem{•i} =1 \sem{i} ∪ \sem{|i|}
158 The proof of sem_oplus is straightforward. *)
160 lemma sem_oplus: ∀S:DeqSet.∀e1,e2:pre S.
161 \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}.
162 #S * #i1 #b1 * #i2 #b2 #w %
163 [cases b1 cases b2 normalize /2/ * /3/ * /3/
164 |cases b1 cases b2 normalize /2/ * /3/ * /3/
168 (* For the others, we proceed as follow: we first prove the following
169 auxiliary lemma, that assumes sem_bullet:
172 \sem{•i2} =1 \sem{i2} ∪ \sem{|i2|} →
173 \sem{e1 ▹ i2} =1 \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
175 Then, using the previous result, we prove sem_bullet by induction
176 on i. Finally, sem_pcl_aux and sem_bullet give sem_pcl. *)
178 lemma LcatE : ∀S.∀e1,e2:pitem S.
179 \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}.
182 lemma sem_pcl_aux : ∀S.∀e1:pre S.∀i2:pitem S.
183 \sem{•i2} =1 \sem{i2} ∪ \sem{|i2|} →
184 \sem{e1 ▹ i2} =1 \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
185 #S * #i1 #b1 #i2 cases b1
186 [2:#th >pcl_false >sem_pre_false >sem_pre_false >sem_cat /2/
187 |#H >pcl_true >sem_pre_true @(eqP_trans … (sem_pre_concat_r …))
188 >erase_bull @eqP_trans [|@(eqP_union_l … H)]
189 @eqP_trans [|@eqP_union_l[|@union_comm ]]
190 @eqP_trans [|@eqP_sym @union_assoc ] /3/
194 lemma minus_eps_pre_aux: ∀S.∀e:pre S.∀i:pitem S.∀A.
195 \sem{e} =1 \sem{i} ∪ A → \sem{\fst e} =1 \sem{i} ∪ (A - {[ ]}).
197 @eqP_trans [|@minus_eps_pre]
198 @eqP_trans [||@eqP_union_r [|@eqP_sym @minus_eps_item]]
199 @eqP_trans [||@distribute_substract]
203 theorem sem_bull: ∀S:DeqSet. ∀i:pitem S. \sem{•i} =1 \sem{i} ∪ \sem{|i|}.
205 [#w normalize % [/2/ | * //]
207 |#x normalize #w % [ /2/ | * [@False_ind | //]]
208 |#x normalize #w % [ /2/ | * // ]
209 |#i1 #i2 #IH1 #IH2 >eclose_dot
210 @eqP_trans [|@sem_pcl_aux //] >sem_cat
213 [|@eqP_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
214 @eqP_trans [|@union_assoc]
215 @eqP_trans [||@eqP_sym @union_assoc]
217 |#i1 #i2 #IH1 #IH2 >eclose_plus
218 @eqP_trans [|@sem_oplus] >sem_plus >erase_plus
219 @eqP_trans [|@(eqP_union_l … IH2)]
220 @eqP_trans [|@eqP_sym @union_assoc]
221 @eqP_trans [||@union_assoc] @eqP_union_r
222 @eqP_trans [||@eqP_sym @union_assoc]
223 @eqP_trans [||@eqP_union_l [|@union_comm]]
224 @eqP_trans [||@union_assoc] /2/
225 |#i #H >sem_pre_true >sem_star >erase_bull >sem_star
226 @eqP_trans [|@eqP_union_r [|@cat_ext_l [|@minus_eps_pre_aux //]]]
227 @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
228 @eqP_trans [|@union_assoc] @eqP_union_l >erase_star
229 @eqP_sym @star_fix_eps
237 As a corollary of theorem sem_bullet, given a regular expression e, we can easily
238 find an item with the same semantics of $e$: it is enough to get an item (blank e)
239 having e as carrier and no point, and then broadcast a point in it. The semantics of
240 (blank e) is obviously the empty language: from the point of view of the automaton,
241 it corresponds with the pit state. *)
243 let rec blank (S: DeqSet) (i: re S) on i :pitem S ≝
248 | o e1 e2 ⇒ (blank S e1) + (blank S e2)
249 | c e1 e2 ⇒ (blank S e1) · (blank S e2)
250 | k e ⇒ (blank S e)^* ].
252 lemma forget_blank: ∀S.∀e:re S.|blank S e| = e.
253 #S #e elim e normalize //
256 lemma sem_blank: ∀S.∀e:re S.\sem{blank S e} =1 ∅.
260 |#e1 #e2 #Hind1 #Hind2 >sem_cat
261 @eqP_trans [||@(union_empty_r … ∅)]
262 @eqP_trans [|@eqP_union_l[|@Hind2]] @eqP_union_r
263 @eqP_trans [||@(cat_empty_l … ?)] @cat_ext_l @Hind1
264 |#e1 #e2 #Hind1 #Hind2 >sem_plus
265 @eqP_trans [||@(union_empty_r … ∅)]
266 @eqP_trans [|@eqP_union_l[|@Hind2]] @eqP_union_r @Hind1
268 @eqP_trans [||@(cat_empty_l … ?)] @cat_ext_l @Hind
272 theorem re_embedding: ∀S.∀e:re S.
273 \sem{•(blank S e)} =1 \sem{e}.
274 #S #e @eqP_trans [|@sem_bull] >forget_blank
275 @eqP_trans [|@eqP_union_r [|@sem_blank]]
276 @eqP_trans [|@union_comm] @union_empty_r.
283 Plus and bullet have been already lifted from items to pres. We can now
284 do a similar job for concatenation ⊙ and Kleene's star ⊛.*)
286 definition lifted_cat ≝ λS:DeqSet.λe:pre S.
287 lift S (pre_concat_l S eclose e).
289 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
291 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
293 lemma odot_true_b : ∀S.∀i1,i2:pitem S.∀b.
294 〈i1,true〉 ⊙ 〈i2,b〉 = 〈i1 · (\fst (•i2)),\snd (•i2) ∨ b〉.
295 #S #i1 #i2 #b normalize in ⊢ (??%?); cases (•i2) //
298 lemma odot_false_b : ∀S.∀i1,i2:pitem S.∀b.
299 〈i1,false〉 ⊙ 〈i2,b〉 = 〈i1 · i2 ,b〉.
303 lemma erase_odot:∀S.∀e1,e2:pre S.
304 |\fst (e1 ⊙ e2)| = |\fst e1| · (|\fst e2|).
305 #S * #i1 * * #i2 #b2 // >odot_true_b >erase_dot //
308 (* Let us come to the star operation: *)
310 definition lk ≝ λS:DeqSet.λe:pre S.
314 [true ⇒ 〈(\fst (eclose ? i1))^*, true〉
315 |false ⇒ 〈i1^*,false〉
319 (* notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $a}.*)
320 interpretation "lk" 'lk a = (lk ? a).
321 notation "a^⊛" non associative with precedence 90 for @{'lk $a}.
323 lemma ostar_true: ∀S.∀i:pitem S.
324 〈i,true〉^⊛ = 〈(\fst (•i))^*, true〉.
327 lemma ostar_false: ∀S.∀i:pitem S.
328 〈i,false〉^⊛ = 〈i^*, false〉.
331 lemma erase_ostar: ∀S.∀e:pre S.
332 |\fst (e^⊛)| = |\fst e|^*.
335 lemma sem_odot_true: ∀S:DeqSet.∀e1:pre S.∀i.
336 \sem{e1 ⊙ 〈i,true〉} =1 \sem{e1 ▹ i} ∪ { [ ] }.
338 cut (e1 ⊙ 〈i,true〉 = 〈\fst (e1 ▹ i), \snd(e1 ▹ i) ∨ true〉) [//]
339 #H >H cases (e1 ▹ i) #i1 #b1 cases b1
340 [>sem_pre_true @eqP_trans [||@eqP_sym @union_assoc]
346 lemma eq_odot_false: ∀S:DeqSet.∀e1:pre S.∀i.
347 e1 ⊙ 〈i,false〉 = e1 ▹ i.
349 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▹ i), \snd(e1 ▹ i) ∨ false〉) [//]
350 cases (e1 ▹ i) #i1 #b1 cases b1 #H @H
353 (* We conclude this section with the proof of the main semantic properties
357 ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
360 @eqP_trans [|@sem_odot_true]
361 @eqP_trans [||@union_assoc] @eqP_union_r @sem_pcl_aux //
362 |>sem_pre_false >eq_odot_false @sem_pcl_aux //
366 theorem sem_ostar: ∀S.∀e:pre S.
367 \sem{e^⊛} =1 \sem{e} · \sem{|\fst e|}^*.
369 [>sem_pre_true >sem_pre_true >sem_star >erase_bull
370 @eqP_trans [|@eqP_union_r[|@cat_ext_l [|@minus_eps_pre_aux //]]]
371 @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
372 @eqP_trans [||@eqP_sym @distr_cat_r]
373 @eqP_trans [|@union_assoc] @eqP_union_l
374 @eqP_trans [||@eqP_sym @epsilon_cat_l] @eqP_sym @star_fix_eps
375 |>sem_pre_false >sem_pre_false >sem_star /2/