]> matita.cs.unibo.it Git - helm.git/blob - weblib/tutorial/chapter8.ma
7aac6fabca6a71b37ddc1e0dcf0112f5e6c0bd93
[helm.git] / weblib / tutorial / chapter8.ma
1 include "tutorial/chapter7.ma".
2
3 definition lo ≝ λS:DeqSet.λa,b:pre S.〈\fst a + \fst b,\snd a ∨ \snd b〉.
4 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
5 interpretation "oplus" 'oplus a b = (lo ? a b).
6
7 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1∨b2〉.
8 // qed.
9
10 definition pre_concat_r ≝ λS:DeqSet.λi:pitem S.λe:pre S.
11   match e with [ mk_Prod i1 b ⇒ 〈i · i1, b〉].
12  
13 notation "i ◃ e" left associative with precedence 60 for @{'lhd $i $e}.
14 interpretation "pre_concat_r" 'lhd i e = (pre_concat_r ? i e).
15
16 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop. 
17   A = B → A =1 B. 
18 #S #A #B #H >H /2/ qed.
19
20 lemma sem_pre_concat_r : ∀S,i.∀e:pre S.
21   \sem{i ◃ e} =1 \sem{i} · \sem{|\fst e|} ∪ \sem{e}.
22 #S #i * #i1 #b1 cases b1 [2: @eq_to_ex_eq //] 
23 >sem_pre_true >sem_cat >sem_pre_true /2/ 
24 qed.
25  
26 definition pre_concat_l ≝ λS:DeqSet.λbcast:∀S:DeqSet.pitem S → pre S.λe1:pre S.λi2:pitem S.
27   match e1 with 
28   [ mk_Prod i1 b1 ⇒ match b1 with 
29     [ true ⇒ (i1 ◃ (bcast ? i2)) 
30     | false ⇒ 〈i1 · i2,false〉
31     ]
32   ].
33
34 notation "a ▹ b" left associative with precedence 60 for @{'tril eclose $a $b}.
35 interpretation "item-pre concat" 'tril op a b = (pre_concat_l ? op a b).
36
37 notation "•" non associative with precedence 60 for @{eclose ?}.
38
39 let rec eclose (S: DeqSet) (i: pitem S) on i : pre S ≝
40  match i with
41   [ pz ⇒ 〈 `∅, false 〉
42   | pe ⇒ 〈 ϵ,  true 〉
43   | ps x ⇒ 〈 `.x, false〉
44   | pp x ⇒ 〈 `.x, false 〉
45   | po i1 i2 ⇒ •i1 ⊕ •i2
46   | pc i1 i2 ⇒ •i1 ▹ i2
47   | pk i ⇒ 〈(\fst (•i))^*,true〉].
48   
49 notation "• x" non associative with precedence 60 for @{'eclose $x}.
50 interpretation "eclose" 'eclose x = (eclose ? x).
51
52 lemma eclose_plus: ∀S:DeqSet.∀i1,i2:pitem S.
53   •(i1 + i2) = •i1 ⊕ •i2.
54 // qed.
55
56 lemma eclose_dot: ∀S:DeqSet.∀i1,i2:pitem S.
57   •(i1 · i2) = •i1 ▹ i2.
58 // qed.
59
60 lemma eclose_star: ∀S:DeqSet.∀i:pitem S.
61   •i^* = 〈(\fst(•i))^*,true〉.
62 // qed.
63
64 definition lift ≝ λS.λf:pitem S →pre S.λe:pre S. 
65   match e with 
66   [ mk_Prod i b ⇒ 〈\fst (f i), \snd (f i) ∨ b〉].
67   
68 definition preclose ≝ λS. lift S (eclose S). 
69 interpretation "preclose" 'eclose x = (preclose ? x).
70
71 (* theorem 16: 2 *)
72 lemma sem_oplus: ∀S:DeqSet.∀e1,e2:pre S.
73   \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}. 
74 #S * #i1 #b1 * #i2 #b2 #w %
75   [cases b1 cases b2 normalize /2/ * /3/ * /3/
76   |cases b1 cases b2 normalize /2/ * /3/ * /3/
77   ]
78 qed.
79
80 lemma odot_true : 
81   ∀S.∀i1,i2:pitem S.
82   〈i1,true〉 ▹ i2 = i1 ◃ (•i2).
83 // qed.
84
85 lemma odot_true_bis : 
86   ∀S.∀i1,i2:pitem S.
87   〈i1,true〉 ▹ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
88 #S #i1 #i2 normalize cases (•i2) // qed.
89
90 lemma odot_false: 
91   ∀S.∀i1,i2:pitem S.
92   〈i1,false〉 ▹ i2 = 〈i1 · i2, false〉.
93 // qed.
94
95 lemma LcatE : ∀S.∀e1,e2:pitem S.
96   \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}. 
97 // qed.
98
99 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |i|.
100 #S #i elim i // 
101   [ #i1 #i2 #IH1 #IH2 >erase_dot <IH1 >eclose_dot
102     cases (•i1) #i11 #b1 cases b1 // <IH2 >odot_true_bis //
103   | #i1 #i2 #IH1 #IH2 >eclose_plus >(erase_plus … i1) <IH1 <IH2
104     cases (•i1) #i11 #b1 cases (•i2) #i21 #b2 //  
105   | #i #IH >eclose_star >(erase_star … i) <IH cases (•i) //
106   ]
107 qed.
108
109 (*
110 lemma sem_eclose_star: ∀S:DeqSet.∀i:pitem S.
111   \sem{〈i^*,true〉} =1 \sem{〈i,false〉}·\sem{|i|}^* ∪ {ϵ}.
112 /2/ qed.
113 *)
114
115 (* theorem 16: 1 → 3 *)
116 lemma odot_dot_aux : ∀S.∀e1:pre S.∀i2:pitem S.
117    \sem{•i2} =1  \sem{i2} ∪ \sem{|i2|} →
118    \sem{e1 ▹ i2} =1  \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
119 #S * #i1 #b1 #i2 cases b1
120   [2:#th >odot_false >sem_pre_false >sem_pre_false >sem_cat /2/
121   |#H >odot_true >sem_pre_true @(eqP_trans … (sem_pre_concat_r …))
122    >erase_bull @eqP_trans [|@(eqP_union_l … H)]
123     @eqP_trans [|@eqP_union_l[|@union_comm ]]
124     @eqP_trans [|@eqP_sym @union_assoc ] /3/ 
125   ]
126 qed.
127   
128 lemma minus_eps_pre_aux: ∀S.∀e:pre S.∀i:pitem S.∀A. 
129  \sem{e} =1 \sem{i} ∪ A → \sem{\fst e} =1 \sem{i} ∪ (A - {[ ]}).
130 #S #e #i #A #seme
131 @eqP_trans [|@minus_eps_pre]
132 @eqP_trans [||@eqP_union_r [|@eqP_sym @minus_eps_item]]
133 @eqP_trans [||@distribute_substract] 
134 @eqP_substract_r //
135 qed.
136
137 (* theorem 16: 1 *)
138 theorem sem_bull: ∀S:DeqSet. ∀i:pitem S.  \sem{•i} =1 \sem{i} ∪ \sem{|i|}.
139 #S #e elim e 
140   [#w normalize % [/2/ | * //]
141   |/2/ 
142   |#x normalize #w % [ /2/ | * [@False_ind | //]]
143   |#x normalize #w % [ /2/ | * // ] 
144   |#i1 #i2 #IH1 #IH2 >eclose_dot
145    @eqP_trans [|@odot_dot_aux //] >sem_cat 
146    @eqP_trans
147      [|@eqP_union_r
148        [|@eqP_trans [|@(cat_ext_l … IH1)] @distr_cat_r]]
149    @eqP_trans [|@union_assoc]
150    @eqP_trans [||@eqP_sym @union_assoc]
151    @eqP_union_l //
152   |#i1 #i2 #IH1 #IH2 >eclose_plus
153    @eqP_trans [|@sem_oplus] >sem_plus >erase_plus 
154    @eqP_trans [|@(eqP_union_l … IH2)]
155    @eqP_trans [|@eqP_sym @union_assoc]
156    @eqP_trans [||@union_assoc] @eqP_union_r
157    @eqP_trans [||@eqP_sym @union_assoc]
158    @eqP_trans [||@eqP_union_l [|@union_comm]]
159    @eqP_trans [||@union_assoc] /2/
160   |#i #H >sem_pre_true >sem_star >erase_bull >sem_star
161    @eqP_trans [|@eqP_union_r [|@cat_ext_l [|@minus_eps_pre_aux //]]]
162    @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
163    @eqP_trans [|@union_assoc] @eqP_union_l >erase_star 
164    @eqP_sym @star_fix_eps 
165   ]
166 qed.
167
168 (* blank item *)
169 let rec blank (S: DeqSet) (i: re S) on i :pitem S ≝
170  match i with
171   [ z ⇒ `∅
172   | e ⇒ ϵ
173   | s y ⇒ `y
174   | o e1 e2 ⇒ (blank S e1) + (blank S e2) 
175   | c e1 e2 ⇒ (blank S e1) · (blank S e2)
176   | k e ⇒ (blank S e)^* ].
177   
178 lemma forget_blank: ∀S.∀e:re S.|blank S e| = e.
179 #S #e elim e normalize //
180 qed.
181
182 lemma sem_blank: ∀S.∀e:re S.\sem{blank S e} =1 ∅.
183 #S #e elim e 
184   [1,2:@eq_to_ex_eq // 
185   |#s @eq_to_ex_eq //
186   |#e1 #e2 #Hind1 #Hind2 >sem_cat 
187    @eqP_trans [||@(union_empty_r … ∅)] 
188    @eqP_trans [|@eqP_union_l[|@Hind2]] @eqP_union_r
189    @eqP_trans [||@(cat_empty_l … ?)] @cat_ext_l @Hind1
190   |#e1 #e2 #Hind1 #Hind2 >sem_plus 
191    @eqP_trans [||@(union_empty_r … ∅)] 
192    @eqP_trans [|@eqP_union_l[|@Hind2]] @eqP_union_r @Hind1
193   |#e #Hind >sem_star
194    @eqP_trans [||@(cat_empty_l … ?)] @cat_ext_l @Hind
195   ]
196 qed.
197    
198 theorem re_embedding: ∀S.∀e:re S. 
199   \sem{•(blank S e)} =1 \sem{e}.
200 #S #e @eqP_trans [|@sem_bull] >forget_blank 
201 @eqP_trans [|@eqP_union_r [|@sem_blank]]
202 @eqP_trans [|@union_comm] @union_empty_r.
203 qed.
204
205 (* lefted operations *)
206 definition lifted_cat ≝ λS:DeqSet.λe:pre S. 
207   lift S (pre_concat_l S eclose e).
208
209 notation "e1 ⊙ e2" left associative with precedence 70 for @{'odot $e1 $e2}.
210
211 interpretation "lifted cat" 'odot e1 e2 = (lifted_cat ? e1 e2).
212
213 lemma odot_true_b : ∀S.∀i1,i2:pitem S.∀b. 
214   〈i1,true〉 ⊙ 〈i2,b〉 = 〈i1 · (\fst (•i2)),\snd (•i2) ∨ b〉.
215 #S #i1 #i2 #b normalize in ⊢ (??%?); cases (•i2) // 
216 qed.
217
218 lemma odot_false_b : ∀S.∀i1,i2:pitem S.∀b.
219   〈i1,false〉 ⊙ 〈i2,b〉 = 〈i1 · i2 ,b〉.
220 // 
221 qed.
222   
223 lemma erase_odot:∀S.∀e1,e2:pre S.
224   |\fst (e1 ⊙ e2)| = |\fst e1| · (|\fst e2|).
225 #S * #i1 * * #i2 #b2 // >odot_true_b >erase_dot //  
226 qed.
227
228 definition lk ≝ λS:DeqSet.λe:pre S.
229   match e with 
230   [ mk_Prod i1 b1 ⇒
231     match b1 with 
232     [true ⇒ 〈(\fst (eclose ? i1))^*, true〉
233     |false ⇒ 〈i1^*,false〉
234     ]
235   ]. 
236
237 (* notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $a}.*)
238 interpretation "lk" 'lk a = (lk ? a).
239 notation "a^⊛" non associative with precedence 90 for @{'lk $a}.
240
241
242 lemma ostar_true: ∀S.∀i:pitem S.
243   〈i,true〉^⊛ = 〈(\fst (•i))^*, true〉.
244 // qed.
245
246 lemma ostar_false: ∀S.∀i:pitem S.
247   〈i,false〉^⊛ = 〈i^*, false〉.
248 // qed.
249   
250 lemma erase_ostar: ∀S.∀e:pre S.
251   |\fst (e^⊛)| = |\fst e|^*.
252 #S * #i * // qed.
253
254 lemma sem_odot_true: ∀S:DeqSet.∀e1:pre S.∀i. 
255   \sem{e1 ⊙ 〈i,true〉} =1 \sem{e1 ▹ i} ∪ { [ ] }.
256 #S #e1 #i 
257 cut (e1 ⊙ 〈i,true〉 = 〈\fst (e1 ▹ i), \snd(e1 ▹ i) ∨ true〉) [//]
258 #H >H cases (e1 ▹ i) #i1 #b1 cases b1 
259   [>sem_pre_true @eqP_trans [||@eqP_sym @union_assoc]
260    @eqP_union_l /2/ 
261   |/2/
262   ]
263 qed.
264
265 lemma eq_odot_false: ∀S:DeqSet.∀e1:pre S.∀i. 
266   e1 ⊙ 〈i,false〉 = e1 ▹ i.
267 #S #e1 #i  
268 cut (e1 ⊙ 〈i,false〉 = 〈\fst (e1 ▹ i), \snd(e1 ▹ i) ∨ false〉) [//]
269 cases (e1 ▹ i) #i1 #b1 cases b1 #H @H
270 qed.
271
272 lemma sem_odot: 
273   ∀S.∀e1,e2: pre S. \sem{e1 ⊙ e2} =1 \sem{e1}· \sem{|\fst e2|} ∪ \sem{e2}.
274 #S #e1 * #i2 * 
275   [>sem_pre_true 
276    @eqP_trans [|@sem_odot_true]
277    @eqP_trans [||@union_assoc] @eqP_union_r @odot_dot_aux //
278   |>sem_pre_false >eq_odot_false @odot_dot_aux //
279   ]
280 qed.
281
282 (* theorem 16: 4 *)      
283 theorem sem_ostar: ∀S.∀e:pre S. 
284   \sem{e^⊛} =1  \sem{e} · \sem{|\fst e|}^*.
285 #S * #i #b cases b
286   [>sem_pre_true >sem_pre_true >sem_star >erase_bull
287    @eqP_trans [|@eqP_union_r[|@cat_ext_l [|@minus_eps_pre_aux //]]]
288    @eqP_trans [|@eqP_union_r [|@distr_cat_r]]
289    @eqP_trans [||@eqP_sym @distr_cat_r]
290    @eqP_trans [|@union_assoc] @eqP_union_l
291    @eqP_trans [||@eqP_sym @epsilon_cat_l] @eqP_sym @star_fix_eps 
292   |>sem_pre_false >sem_pre_false >sem_star /2/
293   ]
294 qed.