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/lists/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 let rec eqbw S (x,y:word S) on x ≝
32 [ nil ⇒ match y with [nil ⇒ true | _ ⇒ false]
33 | cons a xtl ⇒ match y with
34 [nil ⇒ false | cons b ytl ⇒ a == b ∧ eqbw S xtl ytl ]
38 inductive re (S: Alpha) : Type[0] ≝
42 | c: re S → re S → re S
43 | o: re S → re S → re S
46 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
47 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
48 interpretation "star" 'pk a = (k ? a).
49 interpretation "or" 'plus a b = (o ? a b).
51 notation "a · b" non associative with precedence 65 for @{ 'pc $a $b}.
52 interpretation "cat" 'pc a b = (c ? a b).
54 (* to get rid of \middot
55 ncoercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
58 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
59 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
60 interpretation "atom" 'ps a = (s ? a).
62 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
63 interpretation "epsilon" 'epsilon = (e ?).
65 notation "∅" non associative with precedence 90 for @{ 'empty }.
66 interpretation "empty" 'empty = (z ?).
68 let rec flatten (S : Alpha) (l : list (word S)) on l : word S ≝
69 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
71 let rec conjunct (S : Alpha) (l : list (word S)) (r : word S → bool) on l: bool ≝
72 match l with [ nil ⇒ true | cons w tl ⇒ r w ∧ conjunct ? tl r ].
74 definition empty_lang ≝ λS.λw:word S.false.
75 notation "{}" non associative with precedence 90 for @{'empty_lang}.
76 interpretation "empty lang" 'empty_lang = (empty_lang ?).
78 definition sing_lang ≝ λS.λx,w:word S.eqbw S x w.
79 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.*)
80 interpretation "sing lang" 'singl x = (sing_lang ? x).
82 definition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
83 interpretation "union lang" 'union a b = (union ? a b).
85 definition cat : ∀S,l1,l2,w.Prop ≝
86 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
87 interpretation "cat lang" 'pc a b = (cat ? a b).
89 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
90 interpretation "star lang" 'pk l = (star ? l).
92 let rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
97 | c r1 r2 ⇒ (in_l ? r1) · (in_l ? r2)
98 | o r1 r2 ⇒ (in_l ? r1) ∪ (in_l ? r2)
99 | k r1 ⇒ (in_l ? r1) ^*].
101 notation "\sem{E}" non associative with precedence 75 for @{'in_l $E}.
102 interpretation "in_l" 'in_l E = (in_l ? E).
103 interpretation "in_l mem" 'mem w l = (in_l ? l w).
105 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
106 interpretation "orb" 'orb a b = (orb a b).
108 definition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
109 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 }.
110 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 }.
111 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
113 inductive pitem (S: Alpha) : Type[0] ≝
118 | pc: pitem S → pitem S → pitem S
119 | po: pitem S → pitem S → pitem S
120 | pk: pitem S → pitem S.
122 definition pre ≝ λS.pitem S × bool.
124 interpretation "pstar" 'pk a = (pk ? a).
125 interpretation "por" 'plus a b = (po ? a b).
126 interpretation "pcat" 'pc a b = (pc ? a b).
127 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
128 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
129 interpretation "ppatom" 'pp a = (pp ? a).
130 (* to get rid of \middot
131 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
133 interpretation "patom" 'ps a = (ps ? a).
134 interpretation "pepsilon" 'epsilon = (pe ?).
135 interpretation "pempty" 'empty = (pz ?).
137 notation > "| e |" non associative with precedence 66 for @{forget ? $e}.
138 let rec forget (S: Alpha) (l : pitem S) on l: re S ≝
144 | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
145 | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
146 | pk E ⇒ (forget ? E)^* ].
148 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
149 interpretation "forget" 'forget a = (forget ? a).
152 let rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
158 | pc r1 r2 ⇒ (in_pl ? r1) · \sem{forget ? r2} ∪ (in_pl ? r2)
159 | po r1 r2 ⇒ (in_pl ? r1) ∪ (in_pl ? r2)
160 | pk r1 ⇒ (in_pl ? r1) · \sem{forget ? r1}^* ].
162 interpretation "in_pl" 'in_l E = (in_pl ? E).
163 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
165 definition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
167 interpretation "epsilon" 'epsilon = (epsilon ?).
168 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
169 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
171 definition in_prl ≝ λS : Alpha.λp:pre S. \sem{\fst p} ∪ ϵ (\snd p).
173 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
174 interpretation "in_prl" 'in_l E = (in_prl ? E).
176 lemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
177 #S #w1 #w2 cases w1 // #a #tl normalize #H destruct qed.
179 lemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ e).
180 #S #e elim e normalize /2/
181 [#r1 #r2 * #n1 #n2 % * /2/ * #w1 * #w2 * * #H
182 >(append_eq_nil …H…) /2/
183 |#r1 #r2 #n1 #n2 % * /2/
184 |#r #n % * #w1 * #w2 * * #H >(append_eq_nil …H…) /2/
189 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
190 #S #r * [#H apply False_ind /2/ | cases (\snd r) normalize // * ;
193 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
197 definition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
198 notation "a ⊕ b" left associative with precedence 65 for @{'oplus $a $b}.
199 interpretation "oplus" 'oplus a b = (lo ? a b).
201 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1||b2〉.
204 definition item_concat ≝ λS:Alpha.λi:pitem S.λe:pre S.
205 match e with [ pair i1 b ⇒ 〈i · i1, b〉].
207 definition lc ≝ λS:Alpha.λbcast:∀S:Alpha.pre S → pre S.λe1.λe2:pre S.
209 [ pair i1 b1 ⇒ match b1 with
210 [ true ⇒ item_concat ? i1 (bcast ? e2)
211 | false ⇒ item_concat ? i1 e2
215 definition lift ≝ λf:∀S.pitem S →pre S.λS.λe:pre S.
217 [ pair i b ⇒ 〈\fst (f S i), \snd (f S i) || b〉].
219 notation < "a ⊙ b" left associative with precedence 65 for @{'lc $op $a $b}.
220 interpretation "lc" 'lc op a b = (lc ? op a b).
221 notation > "a ⊙ b" left associative with precedence 65 for @{'lc (lift eclose) $a $b}.
223 definition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λe:pre S.
227 [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
232 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
233 interpretation "lk" 'lk op a = (lk ? op a).
234 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
237 notation > "•" non associative with precedence 65 for @{eclose ?}.
238 let rec eclose (S: Alpha) (i: pitem S) on i : pre S ≝
242 | ps x ⇒ 〈 `.x, false〉
243 | pp x ⇒ 〈 `.x, false 〉
244 | po E1 E2 ⇒ •E1 ⊕ •E2
245 | pc E1 E2 ⇒ •E1 ⊙ 〈E2,false〉
246 | pk E ⇒ 〈(\fst(•E))^*,true〉].
248 notation < "• x" non associative with precedence 65 for @{'eclose $x}.
249 interpretation "eclose" 'eclose x = (eclose ? x).
250 notation > "• x" non associative with precedence 65 for @{'eclose $x}.
252 definition reclose ≝ lift eclose.
253 interpretation "reclose" 'eclose x = (reclose ? x).
255 definition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
256 notation "A ≐ B" non associative with precedence 45 for @{'eq_f1 $A $B}.
257 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
260 lemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) ≐ ϵ b1 ∪ ϵ b2.
262 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
265 lemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
266 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
268 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
269 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
272 lemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.\sem{e1 ⊕ e2} ≐ \sem{e1} ∪ \sem{e2}.
273 #S * #i1 #b1 * #i2 #b2 >lo_def normalize in ⊢ (?%?);
275 #w cases b1 cases b2 normalize % #w r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
276 nwhd in ⊢ (??(??%)?);
277 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
278 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
279 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
280 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
281 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
285 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
286 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
288 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
290 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
291 #S p q r; napply extP; #w; nnormalize; @;
292 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
293 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
296 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
297 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
299 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
300 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
303 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
304 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
306 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
308 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
309 interpretation "substract" 'minus a b = (substract ? a b).
311 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
312 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
314 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
315 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
317 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
318 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
320 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
321 #S a b w; nnormalize; *; //; nqed.
323 nlemma erase_bull : ∀S.∀a:pitem S. |\fst (•a)| = |a|.
324 #S a; nelim a; // by {};
325 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
326 nrewrite < IH1; nrewrite < IH2;
327 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
328 ncases (•e1); #e3 b; ncases b; nnormalize;
329 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
330 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| + |e2|);
331 nrewrite < IH2; nrewrite < IH1;
332 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
333 ncases (•e1); ncases (•e2); //;
334 ##| #e IH; nchange in ⊢ (???%) with (|e|^* ); nrewrite < IH;
335 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
338 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
339 #S p; ncases p; //; nqed.
341 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
342 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
343 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
346 (* theorem 16: 1 → 3 *)
347 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
348 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
349 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
350 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
351 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
352 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
353 nchange in ⊢ (??%?) with (?∪?);
354 nchange in ⊢ (??(??%?)?) with (?∪?);
355 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
356 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
357 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
358 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[##2:
359 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 |e2'|);
360 ngeneralize in match th1;
361 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
362 nrewrite > (eta_lp ? e2);
363 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
364 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
365 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
366 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
367 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
368 nchange in match (𝐋\p ?) with (?∪?);
369 nchange in match (𝐋\p (e1'·?)) with (?∪?);
370 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
372 nrewrite > (cupA…); //;##]
375 nlemma sub_dot_star :
376 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
377 #S X b; napply extP; #w; @;
378 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
379 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
380 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
381 @; //; napply (subW … sube);
382 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
383 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
384 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
385 @; ncases b in H1; #H1;
386 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
387 nrewrite > (associative_append ? w' w1 w2);
388 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
389 ##| ncases w' in Pw';
390 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
391 ##| #x xs Px; @(x::xs); @(w1@w2);
392 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
394 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
395 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
396 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
397 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
399 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
400 @; //; @; //; @; *;##]##]##]
404 alias symbol "pc" (instance 13) = "cat lang".
405 alias symbol "in_pl" (instance 23) = "in_pl".
406 alias symbol "in_pl" (instance 5) = "in_pl".
407 alias symbol "eclose" (instance 21) = "eclose".
408 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
410 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
411 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
413 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
414 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
415 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
416 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
417 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
418 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
420 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
421 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
422 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
423 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
424 nrewrite < (erase_plus …); //.
425 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
426 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
427 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
428 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
429 nrewrite > (erase_bull…e);
430 nrewrite > (erase_star …);
431 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
432 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
433 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
434 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
435 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
436 nrewrite > (cup_dotD…); nrewrite > (cupA…);
437 nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
438 nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
443 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
444 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
446 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
447 #S e; napply extP; #w; nnormalize; @;
448 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
449 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
450 nrewrite < defw; nrewrite < defw2; @; //; @;//;
451 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
452 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
456 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
457 #S e; @[]; /2/; nqed.
459 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
460 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
462 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
463 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
465 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
466 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
467 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
468 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
472 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
473 #S p; ncases p; #e b; ncases b;
474 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
475 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
476 nchange in ⊢ (??%?) with (?∪?);
477 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
478 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
479 nlapply (bull_cup ? e); #bc;
480 nchange in match (𝐋\p (•e)) in bc with (?∪?);
481 nchange in match b' in bc with b';
482 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
483 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
484 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
485 nrewrite > (sub_dot_star…);
486 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
487 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
488 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
490 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
491 nrewrite < (cup0 ? (𝐋\p e)); //;##]
494 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
499 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
500 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
501 | k e1 ⇒ pk ? (pre_of_re ? e1)].
503 nlemma notFalse : ¬False. @; //; nqed.
505 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
506 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
507 *; #w1; *; #w2; *; *; //; nqed.
509 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
510 #S e; nelim e; ##[##1,2,3: //]
511 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
512 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
513 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
514 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
515 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
516 nrewrite > H1; napply dot0; ##]
519 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
521 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
522 nrewrite < H1; nrewrite < H2; //
523 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
524 nrewrite < H1; nrewrite < H2; //
525 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
530 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
531 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
532 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
535 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
536 #S f g H; nrewrite > H; //; nqed.
539 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
541 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
542 nrewrite > defsnde; #H;
543 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
547 notation > "\move term 90 x term 90 E"
548 non associative with precedence 65 for @{move ? $x $E}.
549 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
553 | ps y ⇒ 〈 `y, false 〉
554 | pp y ⇒ 〈 `y, x == y 〉
555 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
556 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
557 | pk e ⇒ (\move x e)^⊛ ].
558 notation < "\move\shy x\shy E" non associative with precedence 65 for @{'move $x $E}.
559 notation > "\move term 90 x term 90 E" non associative with precedence 65 for @{'move $x $E}.
560 interpretation "move" 'move x E = (move ? x E).
562 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
563 interpretation "rmove" 'move x E = (rmove ? x E).
565 nlemma XXz : ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
566 #S w abs; ninversion abs; #; ndestruct;
570 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
571 #S w abs; ninversion abs; #; ndestruct;
574 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
575 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
580 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
581 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
582 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
583 ncases e1 in H; ncases e2;
584 ##[##1: *; ##[*; nnormalize; #; ndestruct]
585 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
586 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
587 ##|##2: *; ##[*; nnormalize; #; ndestruct]
588 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
589 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
590 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
591 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
592 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
593 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
594 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
595 #H; ninversion H; nnormalize; #; ndestruct;
596 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
597 ##| #r1 r2; *; ##[ *; #defw]
602 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
603 #S E; ncases E; #r b; nelim r;
605 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
606 #H; ninversion H; #; ndestruct;
607 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
608 #H; ninversion H; #; ndestruct;##]
609 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
610 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
611 ##|#a c w; @; nnormalize;
612 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
613 #H; ninversion H; #; ndestruct;
614 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
615 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
616 ##|#r1 r2 H1 H2 a w; @;
617 ##[ #H; ncases (in_move_cat … H);
618 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
619 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
620 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
629 notation > "x ↦* E" non associative with precedence 65 for @{move_star ? $x $E}.
630 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
633 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
635 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
637 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
639 ∀E1,E2: bool × (pre S).
641 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
644 ndefinition NAT: decidable.
648 include "hints_declaration.ma".
650 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
651 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
653 ninductive unit: Type[0] ≝ I: unit.
655 nlet corec foo_nop (b: bool):
657 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
658 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
660 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
662 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
663 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
667 nlet corec foo (a: unit):
669 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
670 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
675 [ nnormalize in ⊢ (??%%);
676 nnormalize in foo: (? → ??%%);
678 [ nnormalize in ⊢ (??%%); napply foo_nop
680 [ nnormalize in ⊢ (??%%);
682 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
683 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
688 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
689 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
690 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
693 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
694 nnormalize in match test3;
699 (**********************************************************)
701 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
702 der_z: der S a (z S) (z S)
703 | der_e: der S a (e S) (z S)
704 | der_s1: der S a (s S a) (e ?)
705 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
706 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
707 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
708 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
709 der S a (c ? e1 e2) (c ? e1' e2)
710 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
711 der S a (o ? e1 e2) (o ? e1' e2').
713 nlemma eq_rect_CProp0_r:
714 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
715 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
718 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
720 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
721 (* #S; #r1; #r2; #w; nelim r1
723 | #H1; #H2; napply (in_c ? []); //
724 | (* tutti casi assurdi *) *)
726 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
727 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
728 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
730 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
732 (in_l S [] E1 → in_l S [] E2) →
733 (in_l S [] E2 → in_l S [] E1) →
734 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
737 (* serve il lemma dopo? *)
738 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
739 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
741 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
743 (* IL VICEVERSA NON VALE *)
744 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
745 (* #S; #w; #E; #H; nelim H
747 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
751 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
752 #S; #a; #E; #E'; #w; #H; nelim H
753 [##1,2: #H1; ninversion H1
754 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
755 |##2,9: #X; #Y; #K; ncases (?:False); /2/
756 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
757 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
758 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
759 |##6,13: #x; #y; #K; ncases (?:False); /2/
760 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
761 ##| #H1; ninversion H1
763 | #X; #Y; #K; ncases (?:False); /2/
764 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
765 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
766 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
767 | #x; #y; #K; ncases (?:False); /2/
768 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
769 ##| #H1; #H2; #H3; ninversion H3
770 [ #_; #K; ncases (?:False); /2/
771 | #X; #Y; #K; ncases (?:False); /2/
772 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
773 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
774 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
775 | #x; #y; #K; ncases (?:False); /2/
776 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
777 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;