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).
91 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
92 interpretation "star lang" 'pk l = (star ? l).
94 let rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
99 | c r1 r2 ⇒ (in_l ? r1) · (in_l ? r2)
100 | o r1 r2 ⇒ (in_l ? r1) ∪ (in_l ? r2)
101 | k r1 ⇒ (in_l ? r1) ^*].
103 notation "\sem{E}" non associative with precedence 75 for @{'in_l $E}.
104 interpretation "in_l" 'in_l E = (in_l ? E).
105 interpretation "in_l mem" 'mem w l = (in_l ? l w).
107 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
108 interpretation "orb" 'orb a b = (orb a b).
110 definition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
111 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 }.
112 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 }.
113 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
115 inductive pitem (S: Alpha) : Type[0] ≝
120 | pc: pitem S → pitem S → pitem S
121 | po: pitem S → pitem S → pitem S
122 | pk: pitem S → pitem S.
124 definition pre ≝ λS.pitem S × bool.
126 interpretation "pstar" 'pk a = (pk ? a).
127 interpretation "por" 'plus a b = (po ? a b).
128 interpretation "pcat" 'pc a b = (pc ? a b).
129 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
130 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
131 interpretation "ppatom" 'pp a = (pp ? a).
132 (* to get rid of \middot
133 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
135 interpretation "patom" 'ps a = (ps ? a).
136 interpretation "pepsilon" 'epsilon = (pe ?).
137 interpretation "pempty" 'empty = (pz ?).
139 notation > "| e |" non associative with precedence 66 for @{forget ? $e}.
140 let rec forget (S: Alpha) (l : pitem S) on l: re S ≝
146 | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
147 | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
148 | pk E ⇒ (forget ? E)^* ].
150 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
151 interpretation "forget" 'forget a = (forget ? a).
154 let rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
160 | pc r1 r2 ⇒ (in_pl ? r1) · \sem{forget ? r2} ∪ (in_pl ? r2)
161 | po r1 r2 ⇒ (in_pl ? r1) ∪ (in_pl ? r2)
162 | pk r1 ⇒ (in_pl ? r1) · \sem{forget ? r1}^* ].
164 interpretation "in_pl" 'in_l E = (in_pl ? E).
165 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
167 definition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
169 interpretation "epsilon" 'epsilon = (epsilon ?).
170 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
171 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
173 definition in_prl ≝ λS : Alpha.λp:pre S. \sem{\fst p} ∪ ϵ (\snd p).
175 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
176 interpretation "in_prl" 'in_l E = (in_prl ? E).
178 lemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
179 #S #w1 #w2 cases w1 // #a #tl normalize #H destruct qed.
181 lemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ e).
182 #S #e elim e normalize /2/
183 [#r1 #r2 * #n1 #n2 % * /2/ * #w1 * #w2 * * #H
184 >(append_eq_nil …H…) /2/
185 |#r1 #r2 #n1 #n2 % * /2/
186 |#r #n % * #w1 * #w2 * * #H >(append_eq_nil …H…) /2/
191 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
192 #S #r * [#H apply False_ind /2/ | cases (\snd r) normalize // * ;
195 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
199 definition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
200 notation "a ⊕ b" left associative with precedence 65 for @{'oplus $a $b}.
201 interpretation "oplus" 'oplus a b = (lo ? a b).
203 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1||b2〉.
206 definition item_concat ≝ λS:Alpha.λi:pitem S.λe:pre S.
207 match e with [ pair i1 b ⇒ 〈i · i1, b〉].
209 definition lc ≝ λS:Alpha.λbcast:∀S:Alpha.pre S → pre S.λe1.λe2:pre S.
211 [ pair i1 b1 ⇒ match b1 with
212 [ true ⇒ item_concat ? i1 (bcast ? e2)
213 | false ⇒ item_concat ? i1 e2
217 definition lift ≝ λf:∀S.pitem S →pre S.λS.λe:pre S.
219 [ pair i b ⇒ 〈\fst (f S i), \snd (f S i) || b〉].
221 notation < "a ⊙ b" left associative with precedence 65 for @{'lc $op $a $b}.
222 interpretation "lc" 'lc op a b = (lc ? op a b).
223 notation > "a ⊙ b" left associative with precedence 65 for @{'lc (lift eclose) $a $b}.
225 definition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λe:pre S.
229 [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
234 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
235 interpretation "lk" 'lk op a = (lk ? op a).
236 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
239 notation > "•" non associative with precedence 65 for @{eclose ?}.
240 let rec eclose (S: Alpha) (i: pitem S) on i : pre S ≝
244 | ps x ⇒ 〈 `.x, false〉
245 | pp x ⇒ 〈 `.x, false 〉
246 | po E1 E2 ⇒ •E1 ⊕ •E2
247 | pc E1 E2 ⇒ •E1 ⊙ 〈E2,false〉
248 | pk E ⇒ 〈(\fst(•E))^*,true〉].
250 notation < "• x" non associative with precedence 65 for @{'eclose $x}.
251 interpretation "eclose" 'eclose x = (eclose ? x).
252 notation > "• x" non associative with precedence 65 for @{'eclose $x}.
254 definition reclose ≝ lift eclose.
255 interpretation "reclose" 'eclose x = (reclose ? x).
257 definition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
258 notation "A ≐ B" non associative with precedence 45 for @{'eq_f1 $A $B}.
259 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
262 lemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) ≐ ϵ b1 ∪ ϵ b2.
264 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
267 lemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
268 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
270 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
271 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
274 lemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.\sem{e1 ⊕ e2} ≐ \sem{e1} ∪ \sem{e2}.
275 #S * #i1 #b1 * #i2 #b2 >lo_def normalize in ⊢ (?%?);
277 #w cases b1 cases b2 normalize % #w r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
278 nwhd in ⊢ (??(??%)?);
279 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
280 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
281 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
282 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
283 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
287 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
288 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
290 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
292 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
293 #S p q r; napply extP; #w; nnormalize; @;
294 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
295 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
298 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
299 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
301 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
302 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
305 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
306 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
308 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
310 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
311 interpretation "substract" 'minus a b = (substract ? a b).
313 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
314 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
316 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
317 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
319 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
320 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
322 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
323 #S a b w; nnormalize; *; //; nqed.
325 nlemma erase_bull : ∀S.∀a:pitem S. |\fst (•a)| = |a|.
326 #S a; nelim a; // by {};
327 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
328 nrewrite < IH1; nrewrite < IH2;
329 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
330 ncases (•e1); #e3 b; ncases b; nnormalize;
331 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
332 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| + |e2|);
333 nrewrite < IH2; nrewrite < IH1;
334 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
335 ncases (•e1); ncases (•e2); //;
336 ##| #e IH; nchange in ⊢ (???%) with (|e|^* ); nrewrite < IH;
337 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
340 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
341 #S p; ncases p; //; nqed.
343 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
344 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
345 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
348 (* theorem 16: 1 → 3 *)
349 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
350 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
351 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
352 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
353 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
354 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
355 nchange in ⊢ (??%?) with (?∪?);
356 nchange in ⊢ (??(??%?)?) with (?∪?);
357 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
358 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
359 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
360 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[##2:
361 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 |e2'|);
362 ngeneralize in match th1;
363 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
364 nrewrite > (eta_lp ? e2);
365 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
366 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
367 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
368 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
369 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
370 nchange in match (𝐋\p ?) with (?∪?);
371 nchange in match (𝐋\p (e1'·?)) with (?∪?);
372 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
374 nrewrite > (cupA…); //;##]
377 nlemma sub_dot_star :
378 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
379 #S X b; napply extP; #w; @;
380 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
381 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
382 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
383 @; //; napply (subW … sube);
384 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
385 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
386 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
387 @; ncases b in H1; #H1;
388 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
389 nrewrite > (associative_append ? w' w1 w2);
390 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
391 ##| ncases w' in Pw';
392 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
393 ##| #x xs Px; @(x::xs); @(w1@w2);
394 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
396 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
397 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
398 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
399 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
401 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
402 @; //; @; //; @; *;##]##]##]
406 alias symbol "pc" (instance 13) = "cat lang".
407 alias symbol "in_pl" (instance 23) = "in_pl".
408 alias symbol "in_pl" (instance 5) = "in_pl".
409 alias symbol "eclose" (instance 21) = "eclose".
410 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
412 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
413 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
415 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
416 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
417 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
418 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
419 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
420 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
422 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
423 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
424 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
425 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
426 nrewrite < (erase_plus …); //.
427 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
428 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
429 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
430 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
431 nrewrite > (erase_bull…e);
432 nrewrite > (erase_star …);
433 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
434 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
435 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
436 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
437 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
438 nrewrite > (cup_dotD…); nrewrite > (cupA…);
439 nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
440 nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
445 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
446 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
448 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
449 #S e; napply extP; #w; nnormalize; @;
450 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
451 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
452 nrewrite < defw; nrewrite < defw2; @; //; @;//;
453 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
454 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
458 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
459 #S e; @[]; /2/; nqed.
461 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
462 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
464 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
465 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
467 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
468 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
469 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
470 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
474 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
475 #S p; ncases p; #e b; ncases b;
476 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
477 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
478 nchange in ⊢ (??%?) with (?∪?);
479 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
480 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
481 nlapply (bull_cup ? e); #bc;
482 nchange in match (𝐋\p (•e)) in bc with (?∪?);
483 nchange in match b' in bc with b';
484 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
485 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
486 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
487 nrewrite > (sub_dot_star…);
488 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
489 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
490 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
492 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
493 nrewrite < (cup0 ? (𝐋\p e)); //;##]
496 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
501 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
502 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
503 | k e1 ⇒ pk ? (pre_of_re ? e1)].
505 nlemma notFalse : ¬False. @; //; nqed.
507 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
508 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
509 *; #w1; *; #w2; *; *; //; nqed.
511 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
512 #S e; nelim e; ##[##1,2,3: //]
513 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
514 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
515 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
516 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
517 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
518 nrewrite > H1; napply dot0; ##]
521 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
523 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
524 nrewrite < H1; nrewrite < H2; //
525 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
526 nrewrite < H1; nrewrite < H2; //
527 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
532 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
533 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
534 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
537 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
538 #S f g H; nrewrite > H; //; nqed.
541 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
543 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
544 nrewrite > defsnde; #H;
545 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
549 notation > "\move term 90 x term 90 E"
550 non associative with precedence 65 for @{move ? $x $E}.
551 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
555 | ps y ⇒ 〈 `y, false 〉
556 | pp y ⇒ 〈 `y, x == y 〉
557 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
558 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
559 | pk e ⇒ (\move x e)^⊛ ].
560 notation < "\move\shy x\shy E" non associative with precedence 65 for @{'move $x $E}.
561 notation > "\move term 90 x term 90 E" non associative with precedence 65 for @{'move $x $E}.
562 interpretation "move" 'move x E = (move ? x E).
564 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
565 interpretation "rmove" 'move x E = (rmove ? x E).
567 nlemma XXz : ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
568 #S w abs; ninversion abs; #; ndestruct;
572 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
573 #S w abs; ninversion abs; #; ndestruct;
576 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
577 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
582 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
583 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
584 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
585 ncases e1 in H; ncases e2;
586 ##[##1: *; ##[*; nnormalize; #; ndestruct]
587 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
588 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
589 ##|##2: *; ##[*; nnormalize; #; ndestruct]
590 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
591 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
592 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
593 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
594 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
595 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
596 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
597 #H; ninversion H; nnormalize; #; ndestruct;
598 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
599 ##| #r1 r2; *; ##[ *; #defw]
604 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
605 #S E; ncases E; #r b; nelim r;
607 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
608 #H; ninversion H; #; ndestruct;
609 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
610 #H; ninversion H; #; ndestruct;##]
611 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
612 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
613 ##|#a c w; @; nnormalize;
614 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
615 #H; ninversion H; #; ndestruct;
616 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
617 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
618 ##|#r1 r2 H1 H2 a w; @;
619 ##[ #H; ncases (in_move_cat … H);
620 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
621 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
622 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
631 notation > "x ↦* E" non associative with precedence 65 for @{move_star ? $x $E}.
632 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
635 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
637 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
639 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
641 ∀E1,E2: bool × (pre S).
643 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
646 ndefinition NAT: decidable.
650 include "hints_declaration.ma".
652 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
653 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
655 ninductive unit: Type[0] ≝ I: unit.
657 nlet corec foo_nop (b: bool):
659 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
660 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
662 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
664 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
665 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
669 nlet corec foo (a: unit):
671 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
672 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
677 [ nnormalize in ⊢ (??%%);
678 nnormalize in foo: (? → ??%%);
680 [ nnormalize in ⊢ (??%%); napply foo_nop
682 [ nnormalize in ⊢ (??%%);
684 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
685 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
690 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
691 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
692 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
695 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
696 nnormalize in match test3;
701 (**********************************************************)
703 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
704 der_z: der S a (z S) (z S)
705 | der_e: der S a (e S) (z S)
706 | der_s1: der S a (s S a) (e ?)
707 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
708 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
709 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
710 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
711 der S a (c ? e1 e2) (c ? e1' e2)
712 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
713 der S a (o ? e1 e2) (o ? e1' e2').
715 nlemma eq_rect_CProp0_r:
716 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
717 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
720 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
722 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
723 (* #S; #r1; #r2; #w; nelim r1
725 | #H1; #H2; napply (in_c ? []); //
726 | (* tutti casi assurdi *) *)
728 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
729 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
730 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
732 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
734 (in_l S [] E1 → in_l S [] E2) →
735 (in_l S [] E2 → in_l S [] E1) →
736 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
739 (* serve il lemma dopo? *)
740 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
741 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
743 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
745 (* IL VICEVERSA NON VALE *)
746 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
747 (* #S; #w; #E; #H; nelim H
749 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
753 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
754 #S; #a; #E; #E'; #w; #H; nelim H
755 [##1,2: #H1; ninversion H1
756 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
757 |##2,9: #X; #Y; #K; ncases (?:False); /2/
758 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
759 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
760 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
761 |##6,13: #x; #y; #K; ncases (?:False); /2/
762 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
763 ##| #H1; ninversion H1
765 | #X; #Y; #K; ncases (?:False); /2/
766 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
767 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
768 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
769 | #x; #y; #K; ncases (?:False); /2/
770 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
771 ##| #H1; #H2; #H3; ninversion H3
772 [ #_; #K; ncases (?:False); /2/
773 | #X; #Y; #K; ncases (?:False); /2/
774 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
775 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
776 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
777 | #x; #y; #K; ncases (?:False); /2/
778 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
779 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;