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 "sets/sets.ma".
20 ninductive Admit : CProp[0] ≝ .
24 (* single = is for the abstract equality of setoids, == is for concrete
25 equalities (that may be lifted to the setoid level when needed *)
26 notation < "hvbox(a break mpadded width -50% (=)= b)" non associative with precedence 45 for @{ 'eq_low $a $b }.
27 notation > "a == b" non associative with precedence 45 for @{ 'eq_low $a $b }.
30 (* XXX move to lists.ma *)
31 ninductive list (A:Type[0]) : Type[0] ≝
33 | cons: A -> list A -> list A.
35 nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝
37 [ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ True | _ ⇒ False ]
38 | cons x xs ⇒ match l2 with [ nil ⇒ False | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
40 interpretation "eq_list" 'eq_low a b = (eq_list ? a b).
42 ndefinition LIST : setoid → setoid.
43 #S; @(list S); @(eq_list S);
44 ##[ #l; nelim l; //; #; @; //;
45 ##| #l1; nelim l1; ##[ #y; ncases y; //] #x xs H y; ncases y; ##[*] #y ys; *; #; @; /2/;
46 ##| #l1; nelim l1; ##[ #l2 l3; ncases l2; ncases l3; /3/; #z zs y ys; *]
47 #x xs H l2 l3; ncases l2; ncases l3; /2/; #z zs y yz; *; #H1 H2; *; #H3 H4; @; /3/;##]
50 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
51 unification hint 0 ≔ S : setoid;
53 P1 ≟ refl ? (eq0 (LIST S)),
54 P2 ≟ sym ? (eq0 (LIST S)),
55 P3 ≟ trans ? (eq0 (LIST S)),
56 X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list T) P1 P2 P3)
57 (*-----------------------------------------------------------------------*) ⊢
60 unification hint 0 ≔ SS : setoid;
62 TT ≟ setoid1_of_setoid (LIST SS)
63 (*-----------------------------------------------------------------*) ⊢
66 unification hint 0 ≔ S:setoid,a,b:list S;
69 (* -------------------------------------------- *) ⊢
70 eq_list S a b ≡ eq_rel L R a b.
72 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
73 unification hint 0 ≔ S : setoid, x,y;
75 TT ≟ setoid1_of_setoid SS
76 (*-----------------------------------------*) ⊢
77 eq_list S x y ≡ eq_rel1 ? (eq1 TT) x y.
79 notation "hvbox(hd break :: tl)"
80 right associative with precedence 47
83 notation "[ list0 x sep ; ]"
84 non associative with precedence 90
85 for ${fold right @'nil rec acc @{'cons $x $acc}}.
87 notation "hvbox(l1 break @ l2)"
88 right associative with precedence 47
89 for @{'append $l1 $l2 }.
91 interpretation "nil" 'nil = (nil ?).
92 interpretation "cons" 'cons hd tl = (cons ? hd tl).
94 nlet rec append A (l1: list A) l2 on l1 ≝
97 | cons hd tl ⇒ hd :: append A tl l2 ].
99 interpretation "append" 'append l1 l2 = (append ? l1 l2).
101 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
102 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
104 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
106 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
107 #A;#x;#y;#z;nelim x[ napply (refl ???) |#a;#x1;#H;nnormalize;/2/]nqed.
109 nlet rec flatten S (l : list (list S)) on l : list S ≝
110 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
112 (* end move to list *)
114 interpretation "iff" 'iff a b = (iff a b).
116 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ refl: eq A x x.
118 nlemma eq_rect_Type0_r':
119 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → P x p.
120 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
123 nlemma eq_rect_Type0_r:
124 ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
125 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
128 nlemma eq_rect_CProp0_r':
129 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
130 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
133 nlemma eq_rect_CProp0_r:
134 ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
135 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
138 (* XXX move to bool *)
139 interpretation "bool eq" 'eq_low a b = (eq bool a b).
141 ndefinition BOOL : setoid.
142 @bool; @(eq bool); nnormalize; //; #x y; ##[ #E; ncases E; ##| #y H; ncases H; ##] //; nqed.
144 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
145 alias id "refl" = "cic:/matita/ng/properties/relations/refl.fix(0,1,3)".
146 unification hint 0 ≔ ;
147 P1 ≟ refl ? (eq0 BOOL),
148 P2 ≟ sym ? (eq0 BOOL),
149 P3 ≟ trans ? (eq0 BOOL),
150 X ≟ mk_setoid bool (mk_equivalence_relation ? (eq bool) P1 P2 P3)
151 (*-----------------------------------------------------------------------*) ⊢
154 unification hint 0 ≔ a,b;
157 (* -------------------------------------------- *) ⊢
158 eq bool a b ≡ eq_rel L R a b.
160 nrecord Alpha : Type[1] ≝ {
162 eqb: acarr → acarr → bool;
163 eqb_true: ∀x,y. (eqb x y = true) = (x = y)
166 interpretation "eqb" 'eq_low a b = (eqb ? a b).
168 ninductive re (S: Type[0]) : Type[0] ≝
172 | c: re S → re S → re S
173 | o: re S → re S → re S
176 (* setoid support for re *)
178 nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝
180 [ z ⇒ match b with [ z ⇒ True | _ ⇒ False]
181 | e ⇒ match b with [ e ⇒ True | _ ⇒ False]
182 | s x ⇒ match b with [ s y ⇒ x = y | _ ⇒ False]
183 | c r1 r2 ⇒ match b with [ c s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
184 | o r1 r2 ⇒ match b with [ o s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
185 | k r1 ⇒ match b with [ k r2 ⇒ eq_re ? r1 r2 | _ ⇒ False]].
187 interpretation "eq_re" 'eq_low a b = (eq_re ? a b).
189 ndefinition RE : Alpha → setoid.
190 #A; @(re A); @(eq_re A);
191 ##[ #p; nelim p; /2/;
192 ##| #p1; nelim p1; ##[##1,2: #p2; ncases p2; /2/;
193 ##|##2,3: #x p2; ncases p2; /2/;
194 ##|##4,5: #e1 e2 H1 H2 p2; ncases p2; /3/; #e3 e4; *; #; @; /2/;
195 ##|#r H p2; ncases p2; /2/;##]
197 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
198 ##| ##3: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
199 ##| ##4,5: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
200 ##[##1,3,4,5,6,8: #; ncases (?:False); //;##]
201 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
202 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3: #; ncases (?:False); //]
206 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
207 alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
208 unification hint 0 ≔ A : Alpha;
211 P1 ≟ refl ? (eq0 (RE A)),
212 P2 ≟ sym ? (eq0 (RE A)),
213 P3 ≟ trans ? (eq0 (RE A)),
214 X ≟ mk_setoid (re T) (mk_equivalence_relation ? (eq_re A) P1 P2 P3)
215 (*-----------------------------------------------------------------------*) ⊢
218 unification hint 0 ≔ A:Alpha,a,b:re A;
221 (* -------------------------------------------- *) ⊢
222 eq_re A a b ≡ eq_rel L R a b.
224 nlemma c_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
225 #A; napply (mk_binary_morphism … (λs1,s2:re A. c A s1 s2));
227 ##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
228 ##|#x a' b b'; ncases a'; /2/ by conj;
229 ##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
230 ##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
233 (* XXX This is the good format for hints about morphisms, fix the others *)
234 unification hint 0 ≔ S:Alpha, A,B:re S;
235 MM ≟ mk_unary_morphism ??
236 (λA:re S.mk_unary_morphism ?? (λB.c ? A B) (prop1 ?? (c_is_morph S A)))
237 (prop1 ?? (c_is_morph S)),
239 (*--------------------------------------------------------------------------*) ⊢
240 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ c S A B.
242 nlemma o_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
243 #A; napply (mk_binary_morphism … (λs1,s2:re A. o A s1 s2));
245 ##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
246 ##|#x a' b b'; ncases a'; /2/ by conj;
247 ##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
248 ##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
251 unification hint 0 ≔ S:Alpha, A,B:re S;
252 MM ≟ mk_unary_morphism ??
253 (λA:re S.mk_unary_morphism ?? (λB.o ? A B) (prop1 ?? (o_is_morph S A)))
254 (prop1 ?? (o_is_morph S)),
256 (*--------------------------------------------------------------------------*) ⊢
257 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ o S A B.
260 (* end setoids support for re *)
262 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
263 notation > "a ^ *" non associative with precedence 75 for @{ 'pk $a}.
264 interpretation "star" 'pk a = (k ? a).
265 interpretation "or" 'plus a b = (o ? a b).
267 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
268 interpretation "cat" 'pc a b = (c ? a b).
270 (* to get rid of \middot *)
271 ncoercion c : ∀S.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
273 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
274 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
275 interpretation "atom" 'ps a = (s ? a).
277 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
278 interpretation "epsilon" 'epsilon = (e ?).
280 notation "0" non associative with precedence 90 for @{ 'empty_r }.
281 interpretation "empty" 'empty_r = (z ?).
283 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
284 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
286 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
287 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
290 ndefinition sing_lang : ∀A:setoid.∀x:A.Ω^A ≝ λS.λx.{ w | x = w }.
291 interpretation "sing lang" 'singl x = (sing_lang ? x).
294 interpretation "subset construction with type" 'comprehension t \eta.x =
297 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
298 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
299 interpretation "cat lang" 'pc a b = (cat ? a b).
301 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
302 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
303 interpretation "star lang" 'pk l = (star ? l).
305 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
306 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
311 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
312 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
314 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
315 interpretation "in_l" 'L_re E = (L_re ? E).
317 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
318 ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
319 interpretation "orb" 'orb a b = (orb a b).
321 ninductive pitem (S: Type[0]) : Type[0] ≝
326 | pc: pitem S → pitem S → pitem S
327 | po: pitem S → pitem S → pitem S
328 | pk: pitem S → pitem S.
330 nlet rec eq_pitem (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝
332 [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
333 | pe ⇒ match p2 with [ pe ⇒ True | _ ⇒ False]
334 | ps x ⇒ match p2 with [ ps y ⇒ x = y | _ ⇒ False]
335 | pp x ⇒ match p2 with [ pp y ⇒ x = y | _ ⇒ False]
336 | pc a1 a2 ⇒ match p2 with [ pc b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
337 | po a1 a2 ⇒ match p2 with [ po b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
338 | pk a ⇒ match p2 with [ pk b ⇒ eq_pitem ? a b | _ ⇒ False]].
340 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b).
342 nlemma PITEM : ∀S:Alpha.setoid.
343 #S; @(pitem S); @(eq_pitem …);
344 ##[ #p; nelim p; //; nnormalize; #; @; //;
345 ##| #p; nelim p; ##[##1,2: #y; ncases y; //; ##|##3,4: #x y; ncases y; //; #; napply (?^-1); nassumption;
346 ##|##5,6: #r1 r2 H1 H2 p2; ncases p2; //; #s1 s2; nnormalize; *; #; @; /2/;
347 ##| #r H y; ncases y; //; nnormalize; /2/;##]
349 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
350 ##| ##3,4: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
351 ##| ##5,6: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
352 ##[##1,2,5,6,7,8,4,10: #; ncases (?:False); //;##]
353 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
354 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3,4: #; ncases (?:False); //]
358 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
359 unification hint 0 ≔ SS:Alpha;
362 P1 ≟ refl ? (eq0 (PITEM SS)),
363 P2 ≟ sym ? (eq0 (PITEM SS)),
364 P3 ≟ trans ? (eq0 (PITEM SS)),
365 R ≟ mk_setoid (pitem S) (mk_equivalence_relation (pitem A) (eq_pitem SS) P1 P2 P3)
366 (*---------------------------*)⊢
369 unification hint 0 ≔ S:Alpha,a,b:pitem S;
372 (* -------------------------------------------- *) ⊢
373 eq_pitem S a b ≡ eq_rel L (eq0 R) a b.
375 (* XXX move to pair.ma *)
376 nlet rec eq_pair (A, B : setoid) (a : A × B) (b : A × B) on a : CProp[0] ≝
377 match a with [ mk_pair a1 a2 ⇒
378 match b with [ mk_pair b1 b2 ⇒ a1 = b1 ∧ a2 = b2 ]].
380 interpretation "eq_pair" 'eq_low a b = (eq_pair ?? a b).
382 nlemma PAIR : ∀A,B:setoid. setoid.
383 #A B; @(A × B); @(eq_pair …);
384 ##[ #ab; ncases ab; #a b; @; napply #;
385 ##| #ab cd; ncases ab; ncases cd; #a1 a2 b1 b2; *; #E1 E2;
386 @; napply (?^-1); //;
387 ##| #a b c; ncases a; ncases b; ncases c; #c1 c2 b1 b2 a1 a2;
388 *; #E1 E2; *; #E3 E4; @; ##[ napply (.= E1); //] napply (.= E2); //.##]
391 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
392 unification hint 0 ≔ AA, BB;
393 A ≟ carr AA, B ≟ carr BB,
394 P1 ≟ refl ? (eq0 (PAIR AA BB)),
395 P2 ≟ sym ? (eq0 (PAIR AA BB)),
396 P3 ≟ trans ? (eq0 (PAIR AA BB)),
397 R ≟ mk_setoid (A × B) (mk_equivalence_relation ? (eq_pair …) P1 P2 P3)
398 (*---------------------------------------------------------------------------*)⊢
401 unification hint 0 ≔ S1,S2,a,b;
404 (* -------------------------------------------- *) ⊢
405 eq_pair S1 S2 a b ≡ eq_rel L (eq0 R) a b.
407 (* end move to pair *)
409 ndefinition pre ≝ λS.pitem S × bool.
411 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
412 interpretation "fst" 'fst x = (fst ? ? x).
413 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
414 interpretation "snd" 'snd x = (snd ? ? x).
416 interpretation "pstar" 'pk a = (pk ? a).
417 interpretation "por" 'plus a b = (po ? a b).
418 interpretation "pcat" 'pc a b = (pc ? a b).
419 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
420 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
421 interpretation "ppatom" 'pp a = (pp ? a).
422 (* to get rid of \middot *)
423 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
424 interpretation "patom" 'ps a = (ps ? a).
425 interpretation "pepsilon" 'epsilon = (pe ?).
426 interpretation "pempty" 'empty_r = (pz ?).
428 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
429 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
435 | pc E1 E2 ⇒ (|E1| · |E2|)
436 | po E1 E2 ⇒ (|E1| + |E2|)
438 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
439 interpretation "forget" 'forget a = (forget ? a).
441 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
442 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
448 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
449 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
450 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
451 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
452 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
453 interpretation "in_pl" 'L_pi E = (L_pi ? E).
455 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
456 #S r; @(𝐋\p r); #w1 w2 E; nelim r;
459 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
460 napply ((.=_0 H) E^-1);
462 nchange in match (w1 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
463 nchange in match (w2 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?); good! *)
465 ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
466 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
467 napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #);
468 ##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
470 ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
471 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
472 (* nnormalize in ⊢ (???%%); good! (but a bit too hard) *)
473 napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#);
477 unification hint 0 ≔ S : Alpha,e : pitem S;
479 X ≟ (mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e)))
480 (*-----------------------------------------------------------------*)⊢
481 ext_carr SS X ≡ 𝐋\p e.
483 ndefinition epsilon ≝
484 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
486 interpretation "epsilon" 'epsilon = (epsilon ?).
487 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
488 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
490 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
492 interpretation "L_pr" 'L_pi E = (L_pr ? E).
494 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
495 #S w1; ncases w1; //. nqed.
498 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
499 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
500 *; ##[##2:*] nelim e;
501 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
502 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
503 ##| #r1 r2 H1 H2; *; /2/ by {}]
504 *; #w1; *; #w2; *; *;
505 ##[ #defw1 H1 foo; napply H;
506 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
508 ##| #defw1 H1 foo; napply H;
509 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
514 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
515 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
516 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
517 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
518 napply (. defw1^-1╪_1#);
520 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
521 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
522 nlapply (append_eq_nil ??? abs); # defw1; #;
523 napply (. defw1^-1╪_1#);
527 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
528 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
529 interpretation "oplus" 'oplus a b = (lo ? a b).
531 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
532 match a with [ mk_pair e1 b1 ⇒
534 [ false ⇒ 〈e1 · \fst b, \snd b〉
535 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
537 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
538 interpretation "lc" 'lc op a b = (lc ? op a b).
539 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
541 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
542 match a with [ mk_pair e1 b1 ⇒
544 [ false ⇒ 〈e1^*, false〉
545 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
547 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
548 interpretation "lk" 'lk op a = (lk ? op a).
549 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
551 notation > "•" non associative with precedence 60 for @{eclose ?}.
552 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
556 | ps x ⇒ 〈 `.x, false 〉
557 | pp x ⇒ 〈 `.x, false 〉
558 | po E1 E2 ⇒ •E1 ⊕ •E2
559 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
560 | pk E ⇒ 〈(\fst (•E))^*,true〉].
561 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
562 interpretation "eclose" 'eclose x = (eclose ? x).
563 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
565 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
566 interpretation "reclose" 'eclose x = (reclose ? x).
568 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
569 #S b1 b2; ncases b1; ncases b2;
570 nchange in match (true || true) with true;
571 nchange in match (true || false) with true;
572 nchange in match (ϵ true) with {[]};
573 nchange in match (ϵ false) with ∅;
574 ##[##1,4: napply ((cupID…)^-1);
575 ##| napply ((cup0 ? {[]})^-1);
576 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
579 (* XXX move somewere else *)
580 ndefinition if': ∀A,B:CPROP. A = B → A → B.
583 ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ???? to ∀_:?.?.
586 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
587 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2; (* oh my!
588 nwhd in ⊢ (???(??%)?);
589 nchange in ⊢(???%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
590 nchange in ⊢(???(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2)); *)
591 napply (.=_1 #╪_1 (epsilon_or ???));
592 napply (.=_1 (cupA…)^-1);
593 napply (.=_1 (cupA…)╪_1#);
594 napply (.=_1 (#╪_1(cupC…))╪_1#);
595 napply (.=_1 (cupA…)^-1╪_1#);
596 napply (.=_1 (cupA…));
601 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
602 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
603 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
604 #S e1 e2 b2; ncases b2; nnormalize; @; //; @; napply refl; nqed.
606 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
607 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
609 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
610 #S p q r; napply ext_set; #w; nnormalize; @;
611 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
612 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
616 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
617 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
620 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
621 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
623 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
625 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
626 #S a b; nnormalize; /2/; nqed.
628 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
629 #S A B x H; napply ext_set; #w; @;
630 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
631 *; #wb nwn; @; ##[@2;//] //;
632 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
635 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
636 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
638 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
639 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
641 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
642 #S a b w; nnormalize; *; //; nqed.
644 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
645 #S a; nelim a; // by {};
648 napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
649 nchange in match (•(e1 · ?)) with (?⊙?);
650 ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
651 napply (.=_0 #╪_0 (IH2)); //;
652 ##| #e1 e2 IH1 IH2; napply (?^-1);
653 napply (.=_0 (IH1^-1)╪_0(IH2^-1));
654 nchange in match (•(e1+?)) with (?⊕?);
655 ncases (•e1); ncases (•e2); //]
658 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
659 #S p; ncases p; //; nqed.
661 (* ext_carr non applica *)
662 nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p.
663 #S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
664 *; #w1; *; #w2; *; *; #defw defw1 Hw2;
666 napply (. (defw1^-1 ╪_0 #)╪_1#); (* manca @ morfismo *)
671 (* theorem 16: 1 → 3 *)
672 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
673 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| →
674 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
675 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
676 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
677 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
678 nchange in ⊢ (??%?) with (?∪?);
679 nchange in ⊢ (??(??%?)?) with (?∪?);
680 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
681 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
682 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
683 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
684 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 .|e2'|);
685 ngeneralize in match th1;
686 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
687 nrewrite > (eta_lp ? e2);
688 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
689 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
690 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
691 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
692 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
693 nchange in match (𝐋\p ?) with (?∪?);
694 nchange in match (𝐋\p (e1'·?)) with (?∪?);
695 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
697 nrewrite > (cupA…); //;##]
700 nlemma sub_dot_star :
701 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
702 #S X b; napply extP; #w; @;
703 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
704 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
705 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
706 @; //; napply (subW … sube);
707 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
708 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
709 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
710 @; ncases b in H1; #H1;
711 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
712 nrewrite > (associative_append ? w' w1 w2);
713 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
714 ##| ncases w' in Pw';
715 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
716 ##| #x xs Px; @(x::xs); @(w1@w2);
717 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
719 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
720 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
721 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
722 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
724 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
725 @; //; @; //; @; *;##]##]##]
729 alias symbol "pc" (instance 13) = "cat lang".
730 alias symbol "in_pl" (instance 23) = "in_pl".
731 alias symbol "in_pl" (instance 5) = "in_pl".
732 alias symbol "eclose" (instance 21) = "eclose".
733 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
735 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
736 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
738 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
739 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
740 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
741 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
742 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
743 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
745 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
746 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
747 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
748 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
749 nrewrite < (erase_plus …); //.
750 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
751 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
752 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
753 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
754 nrewrite > (erase_bull…e);
755 nrewrite > (erase_star …);
756 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
757 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
758 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
759 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
760 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
761 nrewrite > (cup_dotD…); nrewrite > (cupA…);
762 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
763 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
768 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
769 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
771 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
772 #S e; napply extP; #w; nnormalize; @;
773 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
774 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
775 nrewrite < defw; nrewrite < defw2; @; //; @;//;
776 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
777 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
781 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
782 #S e; @[]; /2/; nqed.
784 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
785 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
787 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
788 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
790 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
791 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
792 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
793 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
797 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
798 #S p; ncases p; #e b; ncases b;
799 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
800 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
801 nchange in ⊢ (??%?) with (?∪?);
802 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
803 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
804 nlapply (bull_cup ? e); #bc;
805 nchange in match (𝐋\p (•e)) in bc with (?∪?);
806 nchange in match b' in bc with b';
807 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
808 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
809 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
810 nrewrite > (sub_dot_star…);
811 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
812 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
813 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
815 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
816 nrewrite < (cup0 ? (𝐋\p e)); //;##]
819 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
824 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
825 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
826 | k e1 ⇒ pk ? (pre_of_re ? e1)].
828 nlemma notFalse : ¬False. @; //; nqed.
830 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
831 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
832 *; #w1; *; #w2; *; *; //; nqed.
834 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
835 #S e; nelim e; ##[##1,2,3: //]
836 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
837 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
838 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
839 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
840 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
841 nrewrite > H1; napply dot0; ##]
844 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
846 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
847 nrewrite < H1; nrewrite < H2; //
848 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
849 nrewrite < H1; nrewrite < H2; //
850 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
855 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
856 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
857 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
860 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
861 #S f g H; nrewrite > H; //; nqed.
864 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
866 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
867 nrewrite > defsnde; #H;
868 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
873 notation > "\move term 90 x term 90 E"
874 non associative with precedence 60 for @{move ? $x $E}.
875 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
879 | ps y ⇒ 〈 `y, false 〉
880 | pp y ⇒ 〈 `y, x == y 〉
881 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
882 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
883 | pk e ⇒ (\move x e)^⊛ ].
884 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
885 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
886 interpretation "move" 'move x E = (move ? x E).
888 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
889 interpretation "rmove" 'move x E = (rmove ? x E).
891 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
892 #S w abs; ninversion abs; #; ndestruct;
896 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
897 #S w abs; ninversion abs; #; ndestruct;
900 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
901 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
906 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
907 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
908 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
909 ncases e1 in H; ncases e2;
910 ##[##1: *; ##[*; nnormalize; #; ndestruct]
911 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
912 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
913 ##|##2: *; ##[*; nnormalize; #; ndestruct]
914 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
915 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
916 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
917 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
918 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
919 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
920 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
921 #H; ninversion H; nnormalize; #; ndestruct;
922 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
923 ##| #r1 r2; *; ##[ *; #defw]
928 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
929 #S E; ncases E; #r b; nelim r;
931 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
932 #H; ninversion H; #; ndestruct;
933 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
934 #H; ninversion H; #; ndestruct;##]
935 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
936 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
937 ##|#a c w; @; nnormalize;
938 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
939 #H; ninversion H; #; ndestruct;
940 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
941 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
942 ##|#r1 r2 H1 H2 a w; @;
943 ##[ #H; ncases (in_move_cat … H);
944 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
945 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
946 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
955 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
956 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
959 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
961 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
963 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
965 ∀E1,E2: bool × (pre S).
967 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
970 ndefinition NAT: decidable.
974 include "hints_declaration.ma".
976 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
977 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
979 ninductive unit: Type[0] ≝ I: unit.
981 nlet corec foo_nop (b: bool):
983 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
984 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
986 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
988 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
989 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
993 nlet corec foo (a: unit):
995 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
996 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1001 [ nnormalize in ⊢ (??%%);
1002 nnormalize in foo: (? → ??%%);
1004 [ nnormalize in ⊢ (??%%); napply foo_nop
1006 [ nnormalize in ⊢ (??%%);
1008 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1009 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1014 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1015 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1016 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1019 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1020 nnormalize in match test3;
1025 (**********************************************************)
1027 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1028 der_z: der S a (z S) (z S)
1029 | der_e: der S a (e S) (z S)
1030 | der_s1: der S a (s S a) (e ?)
1031 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1032 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1033 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1034 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1035 der S a (c ? e1 e2) (c ? e1' e2)
1036 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1037 der S a (o ? e1 e2) (o ? e1' e2').
1039 nlemma eq_rect_CProp0_r:
1040 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1041 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1044 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1046 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1047 (* #S; #r1; #r2; #w; nelim r1
1049 | #H1; #H2; napply (in_c ? []); //
1050 | (* tutti casi assurdi *) *)
1052 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1053 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1054 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1056 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1058 (in_l S [] E1 → in_l S [] E2) →
1059 (in_l S [] E2 → in_l S [] E1) →
1060 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1063 (* serve il lemma dopo? *)
1064 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1065 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1067 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1069 (* IL VICEVERSA NON VALE *)
1070 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1071 (* #S; #w; #E; #H; nelim H
1073 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1077 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1078 #S; #a; #E; #E'; #w; #H; nelim H
1079 [##1,2: #H1; ninversion H1
1080 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1081 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1082 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1083 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1084 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1085 |##6,13: #x; #y; #K; ncases (?:False); /2/
1086 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1087 ##| #H1; ninversion H1
1089 | #X; #Y; #K; ncases (?:False); /2/
1090 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1091 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1092 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1093 | #x; #y; #K; ncases (?:False); /2/
1094 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1095 ##| #H1; #H2; #H3; ninversion H3
1096 [ #_; #K; ncases (?:False); /2/
1097 | #X; #Y; #K; ncases (?:False); /2/
1098 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1099 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1100 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1101 | #x; #y; #K; ncases (?:False); /2/
1102 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1103 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;