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 "datatypes/list.ma".
16 include "datatypes/pairs.ma".
17 include "arithmetics/nat.ma".
19 interpretation "iff" 'iff a b = (iff a b).
21 nrecord Alpha : Type[1] ≝ { carr :> Type[0];
22 eqb: carr → carr → bool;
23 eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y)
26 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
27 interpretation "eqb" 'eqb a b = (eqb ? a b).
29 ndefinition word ≝ λS:Alpha.list S.
31 ninductive re (S: Alpha) : Type[0] ≝
35 | c: re S → re S → re S
36 | o: re S → re S → re S
39 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
40 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
41 interpretation "star" 'pk a = (k ? a).
42 interpretation "or" 'plus a b = (o ? a b).
44 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
45 interpretation "cat" 'pc a b = (c ? a b).
47 (* to get rid of \middot *)
48 ncoercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
50 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
51 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
52 interpretation "atom" 'ps a = (s ? a).
54 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
55 interpretation "epsilon" 'epsilon = (e ?).
57 notation "∅" non associative with precedence 90 for @{ 'empty }.
58 interpretation "empty" 'empty = (z ?).
60 nlet rec flatten (S : Alpha) (l : list (word S)) on l : word S ≝
61 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
63 nlet rec conjunct (S : Alpha) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
64 match l with [ nil ⇒ ? | cons w tl ⇒ r w ∧ conjunct ? tl r ]. napply True. nqed.
66 ndefinition empty_lang ≝ λS.λw:word S.False.
67 notation "{}" non associative with precedence 90 for @{'empty_lang}.
68 interpretation "empty lang" 'empty_lang = (empty_lang ?).
70 ndefinition sing_lang ≝ λS.λx,w:word S.x=w.
71 notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.
72 interpretation "sing lang" 'sing_lang x = (sing_lang ? x).
74 ndefinition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
75 interpretation "union lang" 'union a b = (union ? a b).
77 ndefinition cat : ∀S,l1,l2,w.Prop ≝
78 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
79 interpretation "cat lang" 'pc a b = (cat ? a b).
81 ndefinition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
82 interpretation "star lang" 'pk l = (star ? l).
84 notation > "𝐋 term 70 E" non associative with precedence 75 for @{in_l ? $E}.
85 nlet rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
90 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
91 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
93 notation "𝐋 term 70 E" non associative with precedence 75 for @{'in_l $E}.
94 interpretation "in_l" 'in_l E = (in_l ? E).
95 interpretation "in_l mem" 'mem w l = (in_l ? l w).
97 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
98 interpretation "orb" 'orb a b = (orb a b).
100 ndefinition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
101 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 }.
102 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 }.
103 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
105 ninductive pitem (S: Alpha) : Type[0] ≝
110 | pc: pitem S → pitem S → pitem S
111 | po: pitem S → pitem S → pitem S
112 | pk: pitem S → pitem S.
114 ndefinition pre ≝ λS.pitem S × bool.
116 interpretation "pstar" 'pk a = (pk ? a).
117 interpretation "por" 'plus a b = (po ? a b).
118 interpretation "pcat" 'pc a b = (pc ? a b).
119 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
120 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
121 interpretation "ppatom" 'pp a = (pp ? a).
122 (* to get rid of \middot *)
123 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
124 interpretation "patom" 'ps a = (ps ? a).
125 interpretation "pepsilon" 'epsilon = (pe ?).
126 interpretation "pempty" 'empty = (pz ?).
128 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
129 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
135 | pc E1 E2 ⇒ (|E1| · |E2|)
136 | po E1 E2 ⇒ (|E1| + |E2|)
138 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
139 interpretation "forget" 'forget a = (forget ? a).
141 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
142 interpretation "fst" 'fst x = (fst ? ? x).
143 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
144 interpretation "snd" 'snd x = (snd ? ? x).
146 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{in_pl ? $E}.
147 nlet rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
153 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
154 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
155 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
156 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'in_pl $E}.
157 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'in_pl $E}.
158 interpretation "in_pl" 'in_pl E = (in_pl ? E).
159 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
161 ndefinition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
163 interpretation "epsilon" 'epsilon = (epsilon ?).
164 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
165 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
167 ndefinition in_prl ≝ λS : Alpha.λp:pre S. 𝐋\p (\fst p) ∪ ϵ (\snd p).
169 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
170 interpretation "in_prl" 'in_pl E = (in_prl ? E).
172 nlemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
173 #S w1; nelim w1; //. #x tl IH w2; nnormalize; #abs; ndestruct; nqed.
176 nlemma epsilon_in_true : ∀S.∀e:pre S. [ ] ∈ e ↔ \snd e = true.
177 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
178 nnormalize; *; ##[##2:*] nelim e;
179 ##[ ##1,2: *; ##| #c; *; ##| #c; nnormalize; #; ndestruct; ##| ##7: #p H;
180 ##| #r1 r2 H G; *; ##[##2: /3/ by or_intror]
181 ##| #r1 r2 H1 H2; *; /3/ by or_intror, or_introl; ##]
182 *; #w1; *; #w2; *; *; #defw1; nrewrite > (append_eq_nil … w1 w2 …); /3/ by {};//;
185 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ((𝐋\p e) [ ]).
186 #S e; nelim e; nnormalize; /2/ by nmk;
187 ##[ #; @; #; ndestruct;
188 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
189 nrewrite > (append_eq_nil …H…); /2/;
190 ##| #r1 r2 n1 n2; @; *; /2/;
191 ##| #r n; @; *; #w1; *; #w2; *; *; #H;
192 nrewrite > (append_eq_nil …H…); /2/;##]
195 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
196 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
197 interpretation "oplus" 'oplus a b = (lo ? a b).
199 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
200 match a with [ mk_pair e1 b1 ⇒
202 [ false ⇒ 〈e1 · \fst b, \snd b〉
203 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
205 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
206 interpretation "lc" 'lc op a b = (lc ? op a b).
207 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
209 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
210 match a with [ mk_pair e1 b1 ⇒
212 [ false ⇒ 〈e1^*, false〉
213 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
215 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
216 interpretation "lk" 'lk op a = (lk ? op a).
217 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
219 notation > "•" non associative with precedence 60 for @{eclose ?}.
220 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
224 | ps x ⇒ 〈 `.x, false 〉
225 | pp x ⇒ 〈 `.x, false 〉
226 | po E1 E2 ⇒ •E1 ⊕ •E2
227 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
228 | pk E ⇒ 〈(\fst (•E))^*,true〉].
229 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
230 interpretation "eclose" 'eclose x = (eclose ? x).
231 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
233 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
234 interpretation "reclose" 'eclose x = (reclose ? x).
236 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
237 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
238 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
239 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
241 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
243 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
244 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
247 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
248 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
250 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
251 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
254 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
255 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
256 nwhd in ⊢ (??(??%)?);
257 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
258 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
259 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
260 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
261 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
265 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
266 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
268 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
270 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
271 #S p q r; napply extP; #w; nnormalize; @;
272 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
273 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
276 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
277 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
279 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
280 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
283 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
284 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
286 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
288 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
289 interpretation "substract" 'minus a b = (substract ? a b).
291 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
292 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
294 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
295 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
297 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
298 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
300 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
301 #S a b w; nnormalize; *; //; nqed.
303 nlemma erase_bull : ∀S.∀a:pitem S. |\fst (•a)| = |a|.
304 #S a; nelim a; // by {};
305 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
306 nrewrite < IH1; nrewrite < IH2;
307 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
308 ncases (•e1); #e3 b; ncases b; nnormalize;
309 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
310 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| + |e2|);
311 nrewrite < IH2; nrewrite < IH1;
312 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
313 ncases (•e1); ncases (•e2); //;
314 ##| #e IH; nchange in ⊢ (???%) with (|e|^* ); nrewrite < IH;
315 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
318 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
319 #S p; ncases p; //; nqed.
321 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
322 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
323 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
326 (* theorem 16: 1 → 3 *)
327 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
328 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
329 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
330 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
331 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
332 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
333 nchange in ⊢ (??%?) with (?∪?);
334 nchange in ⊢ (??(??%?)?) with (?∪?);
335 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
336 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
337 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
338 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[##2:
339 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 |e2'|);
340 ngeneralize in match th1;
341 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
342 nrewrite > (eta_lp ? e2);
343 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
344 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
345 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
346 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
347 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
348 nchange in match (𝐋\p ?) with (?∪?);
349 nchange in match (𝐋\p (e1'·?)) with (?∪?);
350 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
352 nrewrite > (cupA…); //;##]
355 nlemma sub_dot_star :
356 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
357 #S X b; napply extP; #w; @;
358 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
359 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
360 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
361 @; //; napply (subW … sube);
362 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
363 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
364 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
365 @; ncases b in H1; #H1;
366 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
367 nrewrite > (associative_append ? w' w1 w2);
368 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
369 ##| ncases w' in Pw';
370 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
371 ##| #x xs Px; @(x::xs); @(w1@w2);
372 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
374 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
375 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
376 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
377 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
379 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
380 @; //; @; //; @; *;##]##]##]
384 alias symbol "pc" (instance 13) = "cat lang".
385 alias symbol "in_pl" (instance 23) = "in_pl".
386 alias symbol "in_pl" (instance 5) = "in_pl".
387 alias symbol "eclose" (instance 21) = "eclose".
388 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
390 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
391 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
393 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
394 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
395 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
396 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
397 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
398 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
400 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
401 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
402 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
403 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
404 nrewrite < (erase_plus …); //.
405 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
406 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
407 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
408 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
409 nrewrite > (erase_bull…e);
410 nrewrite > (erase_star …);
411 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
412 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
413 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
414 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
415 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
416 nrewrite > (cup_dotD…); nrewrite > (cupA…);
417 nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
418 nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
423 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
424 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
426 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
427 #S e; napply extP; #w; nnormalize; @;
428 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
429 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
430 nrewrite < defw; nrewrite < defw2; @; //; @;//;
431 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
432 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
436 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
437 #S e; @[]; /2/; nqed.
439 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
440 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
442 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
443 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
445 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
446 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
447 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
448 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
452 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
453 #S p; ncases p; #e b; ncases b;
454 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
455 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
456 nchange in ⊢ (??%?) with (?∪?);
457 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
458 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
459 nlapply (bull_cup ? e); #bc;
460 nchange in match (𝐋\p (•e)) in bc with (?∪?);
461 nchange in match b' in bc with b';
462 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
463 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
464 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
465 nrewrite > (sub_dot_star…);
466 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
467 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
468 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
470 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
471 nrewrite < (cup0 ? (𝐋\p e)); //;##]
474 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
479 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
480 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
481 | k e1 ⇒ pk ? (pre_of_re ? e1)].
483 nlemma notFalse : ¬False. @; //; nqed.
485 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
486 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
487 *; #w1; *; #w2; *; *; //; nqed.
489 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
490 #S e; nelim e; ##[##1,2,3: //]
491 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
492 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
493 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
494 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
495 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
496 nrewrite > H1; napply dot0; ##]
499 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
501 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
502 nrewrite < H1; nrewrite < H2; //
503 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
504 nrewrite < H1; nrewrite < H2; //
505 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
510 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
511 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
512 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
515 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
516 #S f g H; nrewrite > H; //; nqed.
519 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
521 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
522 nrewrite > defsnde; #H;
523 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
527 notation > "\move term 90 x term 90 E"
528 non associative with precedence 60 for @{move ? $x $E}.
529 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
533 | ps y ⇒ 〈 `y, false 〉
534 | pp y ⇒ 〈 `y, x == y 〉
535 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
536 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
537 | pk e ⇒ (\move x e)^⊛ ].
538 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
539 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
540 interpretation "move" 'move x E = (move ? x E).
542 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
543 interpretation "rmove" 'move x E = (rmove ? x E).
545 nlemma XXz : ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
546 #S w abs; ninversion abs; #; ndestruct;
550 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
551 #S w abs; ninversion abs; #; ndestruct;
554 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
555 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
560 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
561 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
562 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
563 ncases e1 in H; ncases e2;
564 ##[##1: *; ##[*; nnormalize; #; ndestruct]
565 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
566 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
567 ##|##2: *; ##[*; nnormalize; #; ndestruct]
568 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
569 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
570 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
571 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
572 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
573 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
574 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
575 #H; ninversion H; nnormalize; #; ndestruct;
576 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
577 ##| #r1 r2; *; ##[ *; #defw]
582 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
583 #S E; ncases E; #r b; nelim r;
585 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
586 #H; ninversion H; #; ndestruct;
587 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
588 #H; ninversion H; #; ndestruct;##]
589 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
590 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
591 ##|#a c w; @; nnormalize;
592 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
593 #H; ninversion H; #; ndestruct;
594 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
595 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
596 ##|#r1 r2 H1 H2 a w; @;
597 ##[ #H; ncases (in_move_cat … H);
598 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
599 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
600 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
609 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
610 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
613 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
615 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
617 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
619 ∀E1,E2: bool × (pre S).
621 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
624 ndefinition NAT: decidable.
628 include "hints_declaration.ma".
630 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
631 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
633 ninductive unit: Type[0] ≝ I: unit.
635 nlet corec foo_nop (b: bool):
637 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
638 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
640 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
642 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
643 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
647 nlet corec foo (a: unit):
649 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
650 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
655 [ nnormalize in ⊢ (??%%);
656 nnormalize in foo: (? → ??%%);
658 [ nnormalize in ⊢ (??%%); napply foo_nop
660 [ nnormalize in ⊢ (??%%);
662 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
663 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
668 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
669 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
670 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
673 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
674 nnormalize in match test3;
679 (**********************************************************)
681 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
682 der_z: der S a (z S) (z S)
683 | der_e: der S a (e S) (z S)
684 | der_s1: der S a (s S a) (e ?)
685 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
686 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
687 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
688 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
689 der S a (c ? e1 e2) (c ? e1' e2)
690 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
691 der S a (o ? e1 e2) (o ? e1' e2').
693 nlemma eq_rect_CProp0_r:
694 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
695 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
698 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
700 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
701 (* #S; #r1; #r2; #w; nelim r1
703 | #H1; #H2; napply (in_c ? []); //
704 | (* tutti casi assurdi *) *)
706 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
707 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
708 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
710 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
712 (in_l S [] E1 → in_l S [] E2) →
713 (in_l S [] E2 → in_l S [] E1) →
714 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
717 (* serve il lemma dopo? *)
718 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
719 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
721 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
723 (* IL VICEVERSA NON VALE *)
724 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
725 (* #S; #w; #E; #H; nelim H
727 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
731 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
732 #S; #a; #E; #E'; #w; #H; nelim H
733 [##1,2: #H1; ninversion H1
734 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
735 |##2,9: #X; #Y; #K; ncases (?:False); /2/
736 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
737 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
738 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
739 |##6,13: #x; #y; #K; ncases (?:False); /2/
740 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
741 ##| #H1; ninversion H1
743 | #X; #Y; #K; ncases (?:False); /2/
744 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
745 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
746 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
747 | #x; #y; #K; ncases (?:False); /2/
748 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
749 ##| #H1; #H2; #H3; ninversion H3
750 [ #_; #K; ncases (?:False); /2/
751 | #X; #Y; #K; ncases (?:False); /2/
752 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
753 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
754 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
755 | #x; #y; #K; ncases (?:False); /2/
756 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
757 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;