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/pairs.ma".
16 include "datatypes/bool.ma".
17 include "logic/cprop.ma".
19 ninductive Admit : CProp[0] ≝ .
22 ninductive list (A:Type[0]) : Type[0] ≝
24 | cons: A -> list A -> list A.
26 nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝
28 [ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ ? | _ ⇒ ? ]
29 | cons x xs ⇒ match l2 with [ nil ⇒ ? | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
30 ##[ napply True|napply False|napply False]nqed.
32 ndefinition LIST : setoid → setoid.
33 #S; @(list S); @(eq_list S); ncases admit; nqed.
35 unification hint 0 ≔ S : setoid;
37 P1 ≟ refl ? (eq (LIST S)),
38 P2 ≟ sym ? (eq (LIST S)),
39 P3 ≟ trans ? (eq (LIST S)),
40 X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list S) P1 P2 P3)
41 (*-----------------------------------------------------------------------*) ⊢
44 notation "hvbox(hd break :: tl)"
45 right associative with precedence 47
48 notation "[ list0 x sep ; ]"
49 non associative with precedence 90
50 for ${fold right @'nil rec acc @{'cons $x $acc}}.
52 notation "hvbox(l1 break @ l2)"
53 right associative with precedence 47
54 for @{'append $l1 $l2 }.
56 interpretation "nil" 'nil = (nil ?).
57 interpretation "cons" 'cons hd tl = (cons ? hd tl).
59 nlet rec append A (l1: list A) l2 on l1 ≝
62 | cons hd tl ⇒ hd :: append A tl l2 ].
64 interpretation "append" 'append l1 l2 = (append ? l1 l2).
66 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
67 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
69 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
71 ninductive one : Type[0] ≝ unit : one.
74 λS:Type[1].λs:S.λT:Type[1].λt:T.λlock:one.
75 match lock return λ_.Type[1] with [ unit ⇒ T].
77 nlet rec lift (S:Type[1]) (s:S) (T:Type[1]) (t:T) (lock:one) on lock : force S s T t lock ≝
78 match lock return λlock.force S s T t lock with [ unit ⇒ t ].
80 ncoercion lift : ∀S:Type[1].∀s:S.∀T:Type[1].∀t:T.∀lock:one. force S s T t lock ≝ lift
81 on s : ? to force ?????.
83 unification hint 0 ≔ R : setoid;
84 TR ≟ setoid, MR ≟ (carr R), lock ≟ unit
85 (* ---------------------------------------- *) ⊢
86 setoid ≡ force ?(*Type[0]*) MR TR R lock.
88 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
89 #A;#x;#y;#z;nelim x[//|#a;#x1;#H;nnormalize;/2/]nqed.
91 interpretation "iff" 'iff a b = (iff a b).
93 naxiom eq_bool : bool → bool → CProp[0].
94 ndefinition BOOL : setoid.
95 @bool; @eq_bool; ncases admit.nqed.
97 unification hint 0 ≔ ;
98 P1 ≟ refl ? (eq BOOL),
100 P3 ≟ trans ? (eq BOOL),
101 X ≟ mk_setoid bool (mk_equivalence_relation ? eq_bool P1 P2 P3)
102 (*-----------------------------------------------------------------------*) ⊢
105 nrecord Alpha : Type[1] ≝ {
107 eqb: acarr → acarr → bool (*;
108 eqb_true: ∀x,y. (eqb x y = true) = (x = y)*)
111 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
112 interpretation "eqb" 'eqb a b = (eqb ? a b).
114 ninductive re (S: Type[0]) : Type[0] ≝
118 | c: re S → re S → re S
119 | o: re S → re S → re S
122 naxiom eq_re : ∀S:Alpha.re S → re S → CProp[0].
123 ndefinition RE : Alpha → setoid.
124 #A; @(re A); @(eq_re A); ncases admit. nqed.
126 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
127 alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
128 unification hint 0 ≔ A : Alpha;
130 P1 ≟ refl ? (eq (RE A)),
131 P2 ≟ sym ? (eq (RE A)),
132 P3 ≟ trans ? (eq (RE A)),
133 X ≟ mk_setoid (re T) (mk_equivalence_relation ? (eq_re A) P1 P2 P3)
134 (*-----------------------------------------------------------------------*) ⊢
137 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
138 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
139 interpretation "star" 'pk a = (k ? a).
140 interpretation "or" 'plus a b = (o ? a b).
142 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
143 interpretation "cat" 'pc a b = (c ? a b).
145 (* to get rid of \middot *)
146 ncoercion c : ∀S.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
148 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
149 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
150 interpretation "atom" 'ps a = (s ? a).
152 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
153 interpretation "epsilon" 'epsilon = (e ?).
155 notation "∅" non associative with precedence 90 for @{ 'empty }.
156 interpretation "empty" 'empty = (z ?).
158 nrecord Setl (A : Type[0]) : Type[1] ≝ { in_set : A → CProp[0] }.
159 ndefinition Lang ≝ λA.Setl (list A).
161 interpretation "in Setl" 'mem x l = (in_set ? l x).
162 interpretation "compr Lang" 'comprehension t f = (mk_Setl t f).
164 nlet rec flatten S (l : list (list S)) on l : list S ≝
165 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
167 nlet rec conjunct S (l : list (list S)) (L : Lang S) on l: CProp[0] ≝
168 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
170 ndefinition empty_lang ≝ λS.{ w ∈ list S | False }.
171 notation "{}" non associative with precedence 90 for @{'empty_lang}.
172 interpretation "empty lang" 'empty_lang = (empty_lang ?).
174 ndefinition sing_lang ≝ λS:Alpha.λx.{ w ∈ list S | x = w }.
175 interpretation "sing lang" 'singl x = (sing_lang ? x).
177 ndefinition union ≝ λS.λl1,l2.{ w ∈ list S | w ∈ l1 ∨ w ∈ l2}.
178 interpretation "union lang" 'union a b = (union ? a b).
181 λS:Alpha.λl1,l2.{ w ∈ list S | ∃w1,w2.w1 @ w2 = w ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
182 interpretation "cat lang" 'pc a b = (cat ? a b).
185 λS:Alpha.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
186 interpretation "star lang" 'pk l = (star ? l).
188 notation > "𝐋 term 90 E" non associative with precedence 75 for @{L_re ? $E}.
189 nlet rec L_re (S : Alpha) (r : re S) on r : Lang S ≝
194 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
195 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
197 notation "𝐋 term 90 E" non associative with precedence 75 for @{'L_re $E}.
198 interpretation "in_l" 'L_re E = (L_re ? E).
200 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
201 ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
202 interpretation "orb" 'orb a b = (orb a b).
204 ninductive pitem (S: Type[0]) : Type[0] ≝
209 | pc: pitem S → pitem S → pitem S
210 | po: pitem S → pitem S → pitem S
211 | pk: pitem S → pitem S.
213 ndefinition pre ≝ λS.pitem S × bool.
215 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
216 interpretation "fst" 'fst x = (fst ? ? x).
217 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
218 interpretation "snd" 'snd x = (snd ? ? x).
220 interpretation "pstar" 'pk a = (pk ? a).
221 interpretation "por" 'plus a b = (po ? a b).
222 interpretation "pcat" 'pc a b = (pc ? a b).
223 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
224 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
225 interpretation "ppatom" 'pp a = (pp ? a).
226 (* to get rid of \middot *)
227 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
228 interpretation "patom" 'ps a = (ps ? a).
229 interpretation "pepsilon" 'epsilon = (pe ?).
230 interpretation "pempty" 'empty = (pz ?).
232 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
233 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
239 | pc E1 E2 ⇒ (|E1| · |E2|)
240 | po E1 E2 ⇒ (|E1| + |E2|)
242 notation < ".|term 19 e|" non associative with precedence 70 for @{'forget $e}.
243 interpretation "forget" 'forget a = (forget ? a).
245 notation > "𝐋\p\ term 90 E" non associative with precedence 90 for @{in_pl ? $E}.
246 nlet rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
252 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 .|r2| ∪ 𝐋\p\ r2
253 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
254 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (.|r1|^* ) ].
255 notation > "𝐋\p term 90 E" non associative with precedence 90 for @{'in_pl $E}.
256 notation "𝐋\sub(\p) term 90 E" non associative with precedence 90 for @{'in_pl $E}.
257 interpretation "in_pl" 'in_pl E = (in_pl ? E).
258 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
260 ndefinition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
262 interpretation "epsilon" 'epsilon = (epsilon ?).
263 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
264 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
266 ndefinition in_prl ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
268 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
269 interpretation "in_prl" 'in_pl E = (in_prl ? E).
271 nlemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
272 #S w1; nelim w1; //. #x tl IH w2; nnormalize; #abs; ndestruct; nqed.
275 nlemma epsilon_in_true : ∀S.∀e:pre S. [ ] ∈ e ↔ \snd e = true.
276 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
277 nnormalize; *; ##[##2:*] nelim e;
278 ##[ ##1,2: *; ##| #c; *; ##| #c; nnormalize; #; ndestruct; ##| ##7: #p H;
279 ##| #r1 r2 H G; *; ##[##2: /3/ by or_intror]
280 ##| #r1 r2 H1 H2; *; /3/ by or_intror, or_introl; ##]
281 *; #w1; *; #w2; *; *; #defw1; nrewrite > (append_eq_nil … w1 w2 …); /3/ by {};//;
284 nlemma not_epsilon_lp : ∀S.∀e:pitem S. ¬ (𝐋\p e [ ]).
285 #S e; nelim e; nnormalize; /2/ by nmk;
286 ##[ #; @; #; ndestruct;
287 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
288 nrewrite > (append_eq_nil …H…); /2/;
289 ##| #r1 r2 n1 n2; @; *; /2/;
290 ##| #r n; @; *; #w1; *; #w2; *; *; #H;
291 nrewrite > (append_eq_nil …H…); /2/;##]
294 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
295 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
296 interpretation "oplus" 'oplus a b = (lo ? a b).
298 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
299 match a with [ mk_pair e1 b1 ⇒
301 [ false ⇒ 〈e1 · \fst b, \snd b〉
302 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
304 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
305 interpretation "lc" 'lc op a b = (lc ? op a b).
306 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
308 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
309 match a with [ mk_pair e1 b1 ⇒
311 [ false ⇒ 〈e1^*, false〉
312 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
314 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
315 interpretation "lk" 'lk op a = (lk ? op a).
316 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
318 notation > "•" non associative with precedence 60 for @{eclose ?}.
319 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
323 | ps x ⇒ 〈 `.x, false 〉
324 | pp x ⇒ 〈 `.x, false 〉
325 | po E1 E2 ⇒ •E1 ⊕ •E2
326 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
327 | pk E ⇒ 〈(\fst (•E))^*,true〉].
328 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
329 interpretation "eclose" 'eclose x = (eclose ? x).
330 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
332 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
333 interpretation "reclose" 'eclose x = (reclose ? x).
335 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
336 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
337 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
338 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
340 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
342 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
343 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
346 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
347 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
349 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
350 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
353 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
354 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
355 nwhd in ⊢ (??(??%)?);
356 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
357 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
358 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
359 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
360 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
364 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
365 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
367 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 .|e2| ∪ 𝐋\p e2. //; nqed.
369 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
370 #S p q r; napply extP; #w; nnormalize; @;
371 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
372 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
375 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
376 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
378 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 .|e1 · e2| = 𝐋 .|e1| · 𝐋 .|e2|.
379 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
382 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 .|e1 + e2| = 𝐋 .|e1| ∪ 𝐋 .|e2|.
383 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
385 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 .|e1|^* = 𝐋 .|e1^*|. //; nqed.
387 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
388 interpretation "substract" 'minus a b = (substract ? a b).
390 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
391 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
393 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
394 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
396 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
397 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
399 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
400 #S a b w; nnormalize; *; //; nqed.
402 nlemma erase_bull : ∀S.∀a:pitem S. .|\fst (•a)| = .|a|.
403 #S a; nelim a; // by {};
404 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| · .|e2|);
405 nrewrite < IH1; nrewrite < IH2;
406 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
407 ncases (•e1); #e3 b; ncases b; nnormalize;
408 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
409 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
410 nrewrite < IH2; nrewrite < IH1;
411 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
412 ncases (•e1); ncases (•e2); //;
413 ##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
414 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
417 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
418 #S p; ncases p; //; nqed.
420 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
421 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
422 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
425 (* theorem 16: 1 → 3 *)
426 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
427 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| →
428 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
429 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
430 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
431 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
432 nchange in ⊢ (??%?) with (?∪?);
433 nchange in ⊢ (??(??%?)?) with (?∪?);
434 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
435 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
436 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
437 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
438 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 .|e2'|);
439 ngeneralize in match th1;
440 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
441 nrewrite > (eta_lp ? e2);
442 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
443 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
444 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
445 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
446 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
447 nchange in match (𝐋\p ?) with (?∪?);
448 nchange in match (𝐋\p (e1'·?)) with (?∪?);
449 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
451 nrewrite > (cupA…); //;##]
454 nlemma sub_dot_star :
455 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
456 #S X b; napply extP; #w; @;
457 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
458 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
459 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
460 @; //; napply (subW … sube);
461 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
462 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
463 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
464 @; ncases b in H1; #H1;
465 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
466 nrewrite > (associative_append ? w' w1 w2);
467 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
468 ##| ncases w' in Pw';
469 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
470 ##| #x xs Px; @(x::xs); @(w1@w2);
471 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
473 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
474 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
475 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
476 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
478 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
479 @; //; @; //; @; *;##]##]##]
483 alias symbol "pc" (instance 13) = "cat lang".
484 alias symbol "in_pl" (instance 23) = "in_pl".
485 alias symbol "in_pl" (instance 5) = "in_pl".
486 alias symbol "eclose" (instance 21) = "eclose".
487 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
489 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
490 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
492 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
493 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
494 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
495 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
496 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
497 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
499 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
500 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
501 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
502 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
503 nrewrite < (erase_plus …); //.
504 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
505 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
506 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
507 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
508 nrewrite > (erase_bull…e);
509 nrewrite > (erase_star …);
510 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
511 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
512 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
513 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
514 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
515 nrewrite > (cup_dotD…); nrewrite > (cupA…);
516 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
517 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
522 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
523 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
525 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
526 #S e; napply extP; #w; nnormalize; @;
527 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
528 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
529 nrewrite < defw; nrewrite < defw2; @; //; @;//;
530 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
531 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
535 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
536 #S e; @[]; /2/; nqed.
538 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
539 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
541 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
542 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
544 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
545 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
546 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
547 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
551 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
552 #S p; ncases p; #e b; ncases b;
553 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
554 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
555 nchange in ⊢ (??%?) with (?∪?);
556 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
557 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
558 nlapply (bull_cup ? e); #bc;
559 nchange in match (𝐋\p (•e)) in bc with (?∪?);
560 nchange in match b' in bc with b';
561 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
562 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
563 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
564 nrewrite > (sub_dot_star…);
565 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
566 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
567 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
569 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
570 nrewrite < (cup0 ? (𝐋\p e)); //;##]
573 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
578 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
579 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
580 | k e1 ⇒ pk ? (pre_of_re ? e1)].
582 nlemma notFalse : ¬False. @; //; nqed.
584 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
585 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
586 *; #w1; *; #w2; *; *; //; nqed.
588 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
589 #S e; nelim e; ##[##1,2,3: //]
590 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
591 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
592 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
593 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
594 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
595 nrewrite > H1; napply dot0; ##]
598 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
600 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
601 nrewrite < H1; nrewrite < H2; //
602 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
603 nrewrite < H1; nrewrite < H2; //
604 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
609 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
610 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
611 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
614 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
615 #S f g H; nrewrite > H; //; nqed.
618 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
620 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
621 nrewrite > defsnde; #H;
622 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
627 notation > "\move term 90 x term 90 E"
628 non associative with precedence 60 for @{move ? $x $E}.
629 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
633 | ps y ⇒ 〈 `y, false 〉
634 | pp y ⇒ 〈 `y, x == y 〉
635 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
636 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
637 | pk e ⇒ (\move x e)^⊛ ].
638 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
639 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
640 interpretation "move" 'move x E = (move ? x E).
642 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
643 interpretation "rmove" 'move x E = (rmove ? x E).
645 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
646 #S w abs; ninversion abs; #; ndestruct;
650 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
651 #S w abs; ninversion abs; #; ndestruct;
654 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
655 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
660 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
661 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
662 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
663 ncases e1 in H; ncases e2;
664 ##[##1: *; ##[*; nnormalize; #; ndestruct]
665 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
666 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
667 ##|##2: *; ##[*; nnormalize; #; ndestruct]
668 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
669 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
670 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
671 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
672 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
673 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
674 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
675 #H; ninversion H; nnormalize; #; ndestruct;
676 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
677 ##| #r1 r2; *; ##[ *; #defw]
682 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
683 #S E; ncases E; #r b; nelim r;
685 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
686 #H; ninversion H; #; ndestruct;
687 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
688 #H; ninversion H; #; ndestruct;##]
689 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
690 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
691 ##|#a c w; @; nnormalize;
692 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
693 #H; ninversion H; #; ndestruct;
694 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
695 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
696 ##|#r1 r2 H1 H2 a w; @;
697 ##[ #H; ncases (in_move_cat … H);
698 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
699 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
700 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
709 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
710 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
713 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
715 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
717 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
719 ∀E1,E2: bool × (pre S).
721 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
724 ndefinition NAT: decidable.
728 include "hints_declaration.ma".
730 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
731 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
733 ninductive unit: Type[0] ≝ I: unit.
735 nlet corec foo_nop (b: bool):
737 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
738 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
740 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
742 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
743 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
747 nlet corec foo (a: unit):
749 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
750 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
755 [ nnormalize in ⊢ (??%%);
756 nnormalize in foo: (? → ??%%);
758 [ nnormalize in ⊢ (??%%); napply foo_nop
760 [ nnormalize in ⊢ (??%%);
762 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
763 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
768 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
769 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
770 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
773 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
774 nnormalize in match test3;
779 (**********************************************************)
781 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
782 der_z: der S a (z S) (z S)
783 | der_e: der S a (e S) (z S)
784 | der_s1: der S a (s S a) (e ?)
785 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
786 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
787 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
788 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
789 der S a (c ? e1 e2) (c ? e1' e2)
790 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
791 der S a (o ? e1 e2) (o ? e1' e2').
793 nlemma eq_rect_CProp0_r:
794 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
795 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
798 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
800 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
801 (* #S; #r1; #r2; #w; nelim r1
803 | #H1; #H2; napply (in_c ? []); //
804 | (* tutti casi assurdi *) *)
806 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
807 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
808 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
810 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
812 (in_l S [] E1 → in_l S [] E2) →
813 (in_l S [] E2 → in_l S [] E1) →
814 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
817 (* serve il lemma dopo? *)
818 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
819 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
821 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
823 (* IL VICEVERSA NON VALE *)
824 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
825 (* #S; #w; #E; #H; nelim H
827 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
831 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
832 #S; #a; #E; #E'; #w; #H; nelim H
833 [##1,2: #H1; ninversion H1
834 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
835 |##2,9: #X; #Y; #K; ncases (?:False); /2/
836 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
837 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
838 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
839 |##6,13: #x; #y; #K; ncases (?:False); /2/
840 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
841 ##| #H1; ninversion H1
843 | #X; #Y; #K; ncases (?:False); /2/
844 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
845 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
846 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
847 | #x; #y; #K; ncases (?:False); /2/
848 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
849 ##| #H1; #H2; #H3; ninversion H3
850 [ #_; #K; ncases (?:False); /2/
851 | #X; #Y; #K; ncases (?:False); /2/
852 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
853 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
854 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
855 | #x; #y; #K; ncases (?:False); /2/
856 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
857 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;