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-setoids.ma".
16 include "datatypes/bool-setoids.ma".
17 include "datatypes/list-setoids.ma".
18 include "sets/sets.ma".
21 ninductive Admit : CProp[0] ≝ .
25 (* XXX move somewere else *)
26 ndefinition if': ∀A,B:CPROP. A = B → A → B.
29 ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ? (eq1 CPROP) ?? to ∀_:?.?.
31 ndefinition ifs': ∀S.∀A,B:Ω^S. A = B → ∀x. x ∈ A → x ∈ B.
34 ncoercion ifs : ∀S.∀A,B:Ω^S. ∀p:A = B.∀x. x ∈ A → x ∈ B ≝ ifs' on _p : eq_rel1 ? (eq1 (powerclass_setoid ?))?? to ∀_:?.?.
36 (* XXX move to list-setoids-theory.ma *)
38 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
39 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
41 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
43 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
44 #A;#x;#y;#z;nelim x[ napply (refl ???) |#a;#x1;#H;nnormalize;/2/]nqed.
46 (* end move to list *)
49 (* XXX to undestand what I want inside Alpha
50 the eqb part should be split away, but when available it should be
51 possible to obtain a leibnitz equality on lemmas proved on setoids
53 interpretation "iff" 'iff a b = (iff a b).
55 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ erefl: eq A x x.
57 nlemma eq_rect_Type0_r':
58 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (erefl A a) → P x p.
59 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
62 nlemma eq_rect_Type0_r:
63 ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (erefl A a) → ∀x.∀p:eq ? x a.P x p.
64 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
67 nlemma eq_rect_CProp0_r':
68 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (erefl A a) → P x p.
69 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
72 nlemma eq_rect_CProp0_r:
73 ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (erefl A a) → ∀x.∀p:eq ? x a.P x p.
74 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
77 nrecord Alpha : Type[1] ≝ {
79 eqb: acarr → acarr → bool;
80 eqb_true: ∀x,y. (eqb x y = true) = (x = y)
83 interpretation "eqb" 'eq_low a b = (eqb ? a b).
87 ninductive re (S: Type[0]) : Type[0] ≝
91 | c: re S → re S → re S
92 | o: re S → re S → re S
95 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
96 notation > "a ^ *" non associative with precedence 75 for @{ 'pk $a}.
97 interpretation "star" 'pk a = (k ? a).
98 interpretation "or" 'plus a b = (o ? a b).
100 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
101 interpretation "cat" 'pc a b = (c ? a b).
103 (* to get rid of \middot *)
104 ncoercion c : ∀S.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
106 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
107 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
108 interpretation "atom" 'ps a = (s ? a).
110 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
111 interpretation "epsilon" 'epsilon = (e ?).
113 notation "0" non associative with precedence 90 for @{ 'empty_r }.
114 interpretation "empty" 'empty_r = (z ?).
116 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
117 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(LIST $S) }.
119 (* setoid support for re *)
121 nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝
123 [ z ⇒ match b with [ z ⇒ True | _ ⇒ False]
124 | e ⇒ match b with [ e ⇒ True | _ ⇒ False]
125 | s x ⇒ match b with [ s y ⇒ x = y | _ ⇒ False]
126 | c r1 r2 ⇒ match b with [ c s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
127 | o r1 r2 ⇒ match b with [ o s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
128 | k r1 ⇒ match b with [ k r2 ⇒ eq_re ? r1 r2 | _ ⇒ False]].
130 interpretation "eq_re" 'eq_low a b = (eq_re ? a b).
132 ndefinition RE : Alpha → setoid.
133 #A; @(re A); @(eq_re A);
134 ##[ #p; nelim p; /2/;
135 ##| #p1; nelim p1; ##[##1,2: #p2; ncases p2; /2/;
136 ##|##2,3: #x p2; ncases p2; /2/;
137 ##|##4,5: #e1 e2 H1 H2 p2; ncases p2; /3/; #e3 e4; *; #; @; /2/;
138 ##|#r H p2; ncases p2; /2/;##]
140 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
141 ##| ##3: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
142 ##| ##4,5: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
143 ##[##1,3,4,5,6,8: #; ncases (?:False); //;##]
144 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
145 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3: #; ncases (?:False); //]
149 unification hint 0 ≔ A : Alpha;
152 P1 ≟ refl ? (eq0 (RE A)),
153 P2 ≟ sym ? (eq0 (RE A)),
154 P3 ≟ trans ? (eq0 (RE A)),
155 X ≟ mk_setoid (re T) (mk_equivalence_relation ? (eq_re A) P1 P2 P3)
156 (*-----------------------------------------------------------------------*) ⊢
159 unification hint 0 ≔ A:Alpha, a,b:re (carr (acarr A));
161 L ≟ re (carr (acarr A))
162 (* -------------------------------------------- *) ⊢
163 eq_re A a b ≡ eq_rel L R a b.
165 nlemma c_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
166 #A; napply (mk_binary_morphism … (λs1,s2:re A. s1 · s2));
168 ##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
169 ##|#x a' b b'; ncases a'; /2/ by conj;
170 ##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
171 ##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
174 (* XXX This is the good format for hints about morphisms, fix the others *)
175 alias symbol "hint_decl" (instance 1) = "hint_decl_Type0".
176 unification hint 0 ≔ S:Alpha, A,B:re (carr (acarr S));
178 MM ≟ mk_unary_morphism ?? (λA.
180 (λB.A · B) (prop1 ?? (fun1 ?? (c_is_morph S) A)))
181 (prop1 ?? (c_is_morph S)),
183 (*--------------------------------------------------------------------------*) ⊢
184 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ c SS A B.
186 nlemma o_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
187 #A; napply (mk_binary_morphism … (λs1,s2:re A. s1 + s2));
189 ##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
190 ##|#x a' b b'; ncases a'; /2/ by conj;
191 ##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
192 ##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
195 unification hint 0 ≔ S:Alpha, A,B:re (carr (acarr S));
197 MM ≟ mk_unary_morphism ?? (λA.
199 (λB.A + B) (prop1 ?? (fun1 ?? (o_is_morph S) A)))
200 (prop1 ?? (o_is_morph S)),
202 (*--------------------------------------------------------------------------*) ⊢
203 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ o SS A B.
205 (* end setoids support for re *)
207 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
208 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
210 interpretation "subset construction with type" 'comprehension t \eta.x =
213 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
214 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
215 interpretation "cat lang" 'pc a b = (cat ? a b).
218 nlemma cat_is_morph : ∀A:setoid. (lang A) ⇒_1 (lang A) ⇒_1 (lang A).
219 #X; napply (mk_binary_morphism1 … (λA,B:lang X.A · B));
220 #A1 A2 B1 B2 EA EB; napply ext_set; #x;
221 ncut (∀y,x:list X.(x ∈ B1) =_1 (x ∈ B2)); ##[
222 #_; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h1 | napply h2] ##] #YY;
223 ncut (∀x,y:list X.(x ∈ A1) =_1 (x ∈ A2)); ##[
224 #y; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h3 | napply h4] ##] #XX;
225 napply (.=_1 (∑w1, w2. XX w1 w2/ E ; (# ╪_1 E) ╪_1 #));
226 napply (.=_1 (∑w1, w2. YY w1 w2/ E ; # ╪_1 E)); //;
229 nlemma cat_is_ext: ∀A:setoid. (Elang A) → (Elang A) → (Elang A).
230 #S A B; @ (ext_carr … A · ext_carr … B); (* XXX coercion ext_carr che non funge *)
232 ncut (∀w1,w2.(x == w1@w2) = (y == w1@w2)); ##[
233 #w1 w2; @; #H; ##[ napply (.= Exy^-1) | napply (.= Exy)] // ]
235 ##[ napply (. (∑w1,w2. (E w1 w2)^-1 / E ; (E ╪_1 #) ╪_1 #)); napply H;
236 ##| napply (. (∑w1,w2. E w1 w2 / E ; (E ╪_1 #) ╪_1 #)); napply H ]
239 alias symbol "hint_decl" = "hint_decl_Type1".
240 unification hint 0 ≔ A : setoid, B,C : Elang A;
244 R ≟ mk_ext_powerclass AA
245 (cat A (ext_carr AA B) (ext_carr AA C))
246 (ext_prop AA (cat_is_ext A B C))
247 (*----------------------------------------------------------*) ⊢
248 ext_carr AA R ≡ cat A BB CC.
250 unification hint 0 ≔ S:setoid, A,B:lang (carr S);
251 T ≟ powerclass_setoid (list (carr S)),
252 MM ≟ mk_unary_morphism1 T (unary_morphism1_setoid1 T T)
254 mk_unary_morphism1 T T
255 (λB:lang (carr S).cat S A B)
256 (prop11 T T (fun11 ?? (cat_is_morph S) A)))
257 (prop11 T (unary_morphism1_setoid1 T T) (cat_is_morph S))
258 (*--------------------------------------------------------------------------*) ⊢
259 fun11 T T (fun11 T (unary_morphism1_setoid1 T T) MM A) B ≡ cat S A B.
261 nlemma cat_is_ext_morph:∀A:setoid.(Elang A) ⇒_1 (Elang A) ⇒_1 (Elang A).
262 #A; napply (mk_binary_morphism1 … (cat_is_ext …));
263 #x1 x2 y1 y2 Ex Ey; napply (prop11 … (cat_is_morph A)); nassumption.
266 unification hint 1 ≔ AA : setoid, B,C : Elang AA;
268 T ≟ ext_powerclass_setoid AAS,
269 R ≟ mk_unary_morphism1 T (unary_morphism1_setoid1 T T) (λX:Elang AA.
270 mk_unary_morphism1 T T (λY:Elang AA.
271 mk_ext_powerclass AAS
272 (cat AA (ext_carr ? X) (ext_carr ? Y))
273 (ext_prop AAS (cat_is_ext AA X Y)))
274 (prop11 T T (fun11 ?? (cat_is_ext_morph AA) X)))
275 (prop11 T (unary_morphism1_setoid1 T T) (cat_is_ext_morph AA)),
278 (*------------------------------------------------------*) ⊢
279 ext_carr AAS (fun11 T T (fun11 T (unary_morphism1_setoid1 T T) R B) C) ≡ cat AA BB CC.
281 (* end hints for cat *)
283 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
284 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
285 interpretation "star lang" 'pk l = (star ? l).
288 nlemma star_is_morph : ∀A:setoid. (lang A) ⇒_1 (lang A).
289 #X; @(λA:lang X.A^* ); #a1 a2 E; @; #x; *; #wl; *; #defx Px; @wl; @; //;
290 nelim wl in Px; //; #s tl IH; *; #a1s a1tl; /4/; nqed.
292 nlemma star_is_ext: ∀A:setoid. (Elang A) → (Elang A).
293 #S A; @ ((ext_carr … A) ^* ); #w1 w2 E; @; *; #wl; *; #defw1 Pwl;
294 @wl; @; //; napply (.=_0 defw1); /2/; nqed.
296 alias symbol "hint_decl" = "hint_decl_Type1".
297 unification hint 0 ≔ A : setoid, B : Elang A;
300 R ≟ mk_ext_powerclass ?
301 ((ext_carr ? B)^* ) (ext_prop ? (star_is_ext ? B))
302 (*--------------------------------------------------------------------*) ⊢
303 ext_carr AA R ≡ star A BB.
305 unification hint 0 ≔ S:setoid, A:lang (carr S);
306 T ≟ powerclass_setoid (list (carr S)),
307 MM ≟ mk_unary_morphism1 T T
308 (λB:lang (carr S).star S B) (prop11 T T (star_is_morph S))
309 (*--------------------------------------------------------------------------*) ⊢
310 fun11 T T MM A ≡ star S A.
312 nlemma star_is_ext_morph:∀A:setoid.(Elang A) ⇒_1 (Elang A).
313 #A; @(star_is_ext …);
314 #x1 x2 Ex; napply (prop11 … (star_is_morph A)); nassumption.
317 unification hint 1 ≔ AA : setoid, B : Elang AA;
319 T ≟ ext_powerclass_setoid AAS,
320 R ≟ mk_unary_morphism1 T T
322 mk_ext_powerclass AAS (star AA (ext_carr ? S))
323 (ext_prop AAS (star_is_ext AA S)))
324 (prop11 T T (star_is_ext_morph AA)),
326 (*------------------------------------------------------*) ⊢
327 ext_carr AAS (fun11 T T R B) ≡ star AA BB.
329 (* end hints for star *)
331 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
332 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
337 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
338 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
340 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
341 interpretation "in_l" 'L_re E = (L_re ? E).
343 (* support for 𝐋 as an extensional set *)
344 ndefinition L_re_is_ext : ∀S:Alpha.∀r:re S.Elang S.
345 #S r; @(𝐋 r); #w1 w2 E; nelim r;
346 ##[ ##1,2: /2/; @; #defw1; napply (.=_0 (defw1 : [ ] = ?)); //; napply (?^-1); //;
347 ##| #x; @; #defw1; napply (.=_0 (defw1 : [x] = ?)); //; napply (?^-1); //;
348 ##| #e1 e2 H1 H2; (* not shure I shoud Inline *)
349 @; *; #s1; *; #s2; *; *; #defw1 s1L1 s2L2;
350 ##[ nlapply (trans … E^-1 defw1); #defw2;
351 ##| nlapply (trans … E defw1); #defw2; ##] @s1; @s2; /3/;
352 ##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
353 ##| #e H; @; *; #l; *; #defw1 Pl; @l; @; //; napply (.=_1 defw1); /2/; ##]
356 unification hint 0 ≔ S : Alpha,e : re (carr (acarr S));
358 X ≟ mk_ext_powerclass SS (𝐋 e) (ext_prop SS (L_re_is_ext S e))
359 (*-----------------------------------------------------------------*)⊢
360 ext_carr SS X ≡ L_re S e.
362 nlemma L_re_is_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 Ω^(list A).
363 #A; @; ##[ napply (λr:re A.𝐋 r); ##] #r1; nelim r1;
364 ##[##1,2: #r2; ncases r2; //; ##[##1,6: *|##2,7,5,12,10: #a; *|##3,4,8,9: #a1 a2; *]
365 ##|#x r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##6: #a; *] #y E; @; #z defz;
366 ncases z in defz; ##[##1,3: *] #zh ztl; ncases ztl; ##[##2,4: #d dl; *; #_; *]
367 *; #defx; #_; @; //; napply (?^-1); napply (.= defx^-1); //; napply (?^-1); //;
368 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##5: #a1 a2; *|##3,6: #a1; *]
369 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
370 nchange in match (𝐋 (e1 · e2)) with (?·?);
371 napply (.=_1 (H1 ╪_1 H2)); //;
372 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##4: #a1 a2; *|##3,6: #a1; *]
373 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
374 napply (.=_1 H1╪_1H2); //;
375 ##|#r IH r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##3: #a1; *]
376 #e; #defe; nlapply (IH e defe); #H;
377 @; #x; *; #wl; *; #defx Px; @wl; @; //; nelim wl in Px; //; #l ls IH; *; #lr Pr;
378 ##[ nlapply (ifs' … H … lr) | nlapply (ifs' … H^-1 … lr) ] #le;
379 @; ##[##1,3: nassumption] /2/; ##]
382 unification hint 0 ≔ A:Alpha, a:re (carr (acarr A));
383 T ≟ setoid1_of_setoid (RE A),
384 T2 ≟ powerclass_setoid (list (carr (acarr A))),
385 MM ≟ mk_unary_morphism1 ??
386 (λa:carr1 (setoid1_of_setoid (RE A)).𝐋 a) (prop11 ?? (L_re_is_morph A))
387 (*--------------------------------------------------------------------------*) ⊢
388 fun11 T T2 MM a ≡ L_re A a.
390 nlemma L_re_is_ext_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 𝛀^(list A).
391 #A; @; ##[ #a; napply (L_re_is_ext ? a); ##] #a b E;
392 ncut (𝐋 b = 𝐋 a); ##[ napply (.=_1 (┼_1 E^-1)); // ] #EL;
393 @; #x H; nchange in H ⊢ % with (x ∈ 𝐋 ?);
394 ##[ napply (. (# ╪_1 ?)); ##[##3: napply H |##2: ##skip ] napply EL;
395 ##| napply (. (# ╪_1 ?)); ##[##3: napply H |##2: ##skip ] napply (EL^-1)]
398 unification hint 1 ≔ AA : Alpha, a: re (carr (acarr AA));
399 T ≟ RE AA, T1 ≟ LIST (acarr AA), T2 ≟ setoid1_of_setoid T,
400 TT ≟ ext_powerclass_setoid T1,
401 R ≟ mk_unary_morphism1 T2 TT
402 (λa:carr1 (setoid1_of_setoid T).
403 mk_ext_powerclass T1 (𝐋 a) (ext_prop T1 (L_re_is_ext AA a)))
404 (prop11 T2 TT (L_re_is_ext_morph AA))
405 (*------------------------------------------------------*) ⊢
406 ext_carr T1 (fun11 (setoid1_of_setoid T) TT R a) ≡ L_re AA a.
408 (* end support for 𝐋 as an extensional set *)
410 ninductive pitem (S: Type[0]) : Type[0] ≝
415 | pc: pitem S → pitem S → pitem S
416 | po: pitem S → pitem S → pitem S
417 | pk: pitem S → pitem S.
419 interpretation "pstar" 'pk a = (pk ? a).
420 interpretation "por" 'plus a b = (po ? a b).
421 interpretation "pcat" 'pc a b = (pc ? a b).
422 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
423 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
424 interpretation "ppatom" 'pp a = (pp ? a).
425 (* to get rid of \middot *)
426 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
427 interpretation "patom" 'ps a = (ps ? a).
428 interpretation "pepsilon" 'epsilon = (pe ?).
429 interpretation "pempty" 'empty_r = (pz ?).
431 (* setoids for pitem *)
432 nlet rec eq_pitem (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝
434 [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
435 | pe ⇒ match p2 with [ pe ⇒ True | _ ⇒ False]
436 | ps x ⇒ match p2 with [ ps y ⇒ x = y | _ ⇒ False]
437 | pp x ⇒ match p2 with [ pp y ⇒ x = y | _ ⇒ False]
438 | pc a1 a2 ⇒ match p2 with [ pc b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
439 | po a1 a2 ⇒ match p2 with [ po b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
440 | pk a ⇒ match p2 with [ pk b ⇒ eq_pitem ? a b | _ ⇒ False]].
442 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b).
444 nlemma PITEM : ∀S:Alpha.setoid.
445 #S; @(pitem S); @(eq_pitem …);
446 ##[ #p; nelim p; //; nnormalize; #; @; //;
447 ##| #p; nelim p; ##[##1,2: #y; ncases y; //; ##|##3,4: #x y; ncases y; //; #; napply (?^-1); nassumption;
448 ##|##5,6: #r1 r2 H1 H2 p2; ncases p2; //; #s1 s2; nnormalize; *; #; @; /2/;
449 ##| #r H y; ncases y; //; nnormalize; /2/;##]
451 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
452 ##| ##3,4: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
453 ##| ##5,6: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
454 ##[##1,2,5,6,7,8,4,10: #; ncases (?:False); //;##]
455 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
456 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3,4: #; ncases (?:False); //]
460 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
461 unification hint 0 ≔ SS:Alpha;
464 P1 ≟ refl ? (eq0 (PITEM SS)),
465 P2 ≟ sym ? (eq0 (PITEM SS)),
466 P3 ≟ trans ? (eq0 (PITEM SS)),
467 R ≟ mk_setoid (pitem (carr S))
468 (mk_equivalence_relation (pitem A) (eq_pitem SS) P1 P2 P3)
469 (*-----------------------------------------------------------------*)⊢
472 unification hint 0 ≔ S:Alpha,a,b:pitem (carr (acarr S));
473 R ≟ PITEM S, L ≟ pitem (carr (acarr S))
474 (* -------------------------------------------- *) ⊢
475 eq_pitem S a b ≡ eq_rel L (eq0 R) a b.
477 (* end setoids for pitem *)
479 ndefinition pre ≝ λS.pitem S × bool.
481 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
482 interpretation "fst" 'fst x = (fst ? ? x).
483 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
484 interpretation "snd" 'snd x = (snd ? ? x).
486 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
487 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
493 | pc E1 E2 ⇒ (|E1| · |E2|)
494 | po E1 E2 ⇒ (|E1| + |E2|)
497 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
498 interpretation "forget" 'forget a = (forget ? a).
500 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
501 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
507 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
508 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
509 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
510 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
511 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
512 interpretation "in_pl" 'L_pi E = (L_pi ? E).
514 (* set support for 𝐋\p *)
515 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
516 #S r; @(𝐋\p r); #w1 w2 E; nelim r;
519 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
520 napply ((.=_0 H) E^-1);
523 ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
524 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
525 napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #);
526 ##| #e1 e2 H1 H2; napply (H1‡H2);
528 ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
529 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
530 napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#);
534 unification hint 0 ≔ S : Alpha,e : pitem (carr (acarr S));
536 X ≟ mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e))
537 (*-----------------------------------------------------------------*)⊢
538 ext_carr SS X ≡ 𝐋\p e.
540 (* end set support for 𝐋\p *)
542 ndefinition epsilon ≝
543 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
545 interpretation "epsilon" 'epsilon = (epsilon ?).
546 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
547 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
549 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
551 interpretation "L_pr" 'L_pi E = (L_pr ? E).
553 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
554 #S w1; ncases w1; //. nqed.
556 (* lemma 12 *) (* XXX: a case where Leibnitz equality could be exploited for H *)
557 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
558 #S r; ncases r; #e b; @; ##[##2: #H; ncases b in H; ##[##2:*] #; @2; /2/; ##]
559 ncases b; //; *; ##[##2:*] nelim e;
560 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
561 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
562 ##| #r1 r2 H1 H2; *; /2/ by {}]
563 *; #w1; *; #w2; *; *;
564 ##[ #defw1 H1 foo; napply H;
565 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
567 ##| #defw1 H1 foo; napply H;
568 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
573 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
574 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
575 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
576 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
577 napply (. defw1^-1╪_1#);
579 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
580 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
581 nlapply (append_eq_nil ??? abs); # defw1; #;
582 napply (. defw1^-1╪_1#);
586 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
587 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
588 interpretation "oplus" 'oplus a b = (lo ? a b).
590 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
591 match a with [ mk_pair e1 b1 ⇒
593 [ false ⇒ 〈e1 · \fst b, \snd b〉
594 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
596 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
597 interpretation "lc" 'lc op a b = (lc ? op a b).
598 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
600 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
601 match a with [ mk_pair e1 b1 ⇒
603 [ false ⇒ 〈e1^*, false〉
604 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
606 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
607 interpretation "lk" 'lk op a = (lk ? op a).
608 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
610 notation > "•" non associative with precedence 60 for @{eclose ?}.
611 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
615 | ps x ⇒ 〈 `.x, false 〉
616 | pp x ⇒ 〈 `.x, false 〉
617 | po E1 E2 ⇒ •E1 ⊕ •E2
618 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
619 | pk E ⇒ 〈(\fst (•E))^*,true〉].
620 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
621 interpretation "eclose" 'eclose x = (eclose ? x).
622 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
624 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
625 interpretation "reclose" 'eclose x = (reclose ? x).
627 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
628 #S b1 b2; ncases b1; ncases b2;
629 nchange in match (true || true) with true;
630 nchange in match (true || false) with true;
631 nchange in match (ϵ true) with {[]};
632 nchange in match (ϵ false) with ∅;
633 ##[##1,4: napply ((cupID…)^-1);
634 ##| napply ((cup0 ? {[]})^-1);
635 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
639 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
640 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
641 napply (.=_1 #╪_1 (epsilon_or ???));
642 napply (.=_1 (cupA…)^-1);
643 napply (.=_1 (cupA…)╪_1#);
644 napply (.=_1 (#╪_1(cupC…))╪_1#);
645 napply (.=_1 (cupA…)^-1╪_1#);
646 napply (.=_1 (cupA…));
651 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
652 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
653 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
654 #S e1 e2 b2; ncases b2; @; /3/ by refl, conj, I; nqed.
657 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
658 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
661 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
662 #S p q r; napply ext_set; #w; nnormalize; @;
663 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
664 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
668 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
669 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
672 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
673 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
675 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
677 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
678 #S a b; nnormalize; /2/; nqed.
680 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
681 #S A B x H; napply ext_set; #w; @;
682 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
683 *; #wb nwn; @; ##[@2;//] //;
684 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
687 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
688 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
690 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
691 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
693 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
694 #S a b w; nnormalize; *; //; nqed.
696 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
697 #S a; nelim a; // by {};
700 napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
701 nchange in match (•(e1 · ?)) with (?⊙?);
702 ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
703 napply (.=_0 #╪_0 (IH2)); //;
704 ##| #e1 e2 IH1 IH2; napply (?^-1);
705 napply (.=_0 (IH1^-1)╪_0(IH2^-1));
706 nchange in match (•(e1+?)) with (?⊕?);
707 ncases (•e1); ncases (•e2); //]
711 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
712 #S p; ncases p; //; nqed.
715 (* XXX coercion ext_carr non applica *)
716 nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p.
717 #S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
718 *; #w1; *; #w2; *; *; #defw defw1 Hw2;
720 napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
724 (* XXX This seems to be a pattern for equations *)
725 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
726 unification hint 0 ≔ S : Alpha, x,y: re (carr (acarr S));
728 TT ≟ setoid1_of_setoid SS,
730 (*-----------------------------------------*) ⊢
731 eq_re S x y ≡ eq_rel1 T (eq1 TT) x y.
732 (* XXX the previous hint does not work *)
734 (* theorem 16: 1 → 3 *)
735 nlemma odot_dot_aux : ∀S:Alpha.∀e1,e2: pre S.
736 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
737 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
738 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
739 ##[ nchange in match (〈?,true〉⊙?) with 〈?,?〉;
740 nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
741 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
742 napply (.=_1 (# ╪_1 (epsilon_or …))); (* XXX … is too slow if combined with .= *)
743 nchange in match b2'' with b2''; (* XXX some unfoldings happened *)
744 nchange in match b2' with b2';
745 napply (.=_1 (# ╪_1 (cupC …))); napply (.=_1 (cupA …));
746 napply (.=_1 (# ╪_1 (cupA …)^-1)); (* XXX slow, but not because of disamb! *)
747 ncut (𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[
748 napply (?^-1); napply (.=_1 th1^-1); //;##] #E;
749 napply (.=_1 (# ╪_1 (E ╪_1 #)));
751 napply (.=_1 (cup_dotD …) ╪_1 #);
752 napply (.=_1 (# ╪_1 (epsilon_dot …)) ╪_1 #);
754 napply (.=_1 # ╪_1 ((cupC …) ╪_1 #));
755 napply (.=_1 (cupA …)^-1);
756 napply (.=_1 (cupA …)^-1 ╪_1 #);
757 napply (.=_1 (cupA …));
758 nlapply (erase_bull S e2'); #XX;
759 napply (.=_1 (((# ╪_1 (┼_1 ?) )╪_1 #)╪_1 #)); ##[##2: napply XX; ##| ##skip]
761 ##| ncases e2; #e2' b2'; nchange in match (𝐋\p ?) with (?∪?∪?);
762 napply (.=_1 (cupA…));
763 napply (?^-1); nchange in match (𝐋\p 〈?,false〉) with (?∪?);
764 napply (.=_1 ((cup0…)╪_1#)╪_1#);
770 nlemma sub_dot_star :
771 ∀S:Alpha.∀X:Elang S.∀b. (X - ϵ b) · (ext_carr … X)^* ∪ {[]} = (ext_carr … X)^*.
772 #S X b; napply ext_set; #w; @;
773 ##[ *; ##[##2: #defw; @[]; @; //]
774 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
775 @ (w1 :: lw); @; ##[ napply (.=_0 # ╪_0 flx); napply (?^-1); //]
776 @; //; napply (subW … sube);
777 ##| *; #wl; *; #defw Pwl; (* STOP manca ext_carr vs epsilon. *)
778 ncases b; ##[ nchange in match (ϵtrue) with {[]}.
779 napply (. (defw^-1 ╪_1 #)); nelim wl in Pwl; /2/;
780 #s tl IH; *; #Xs Ptl; ncases s in Xs; ##[ #; napply IH; //] #x xs Xxxs;
781 @; @(x :: xs); @(flatten ? tl); @; ##[ @; ##[ napply #] @; //; nassumption; ##]
782 nelim tl in Ptl; ##[ #; @[]; /2/] #w ws IH; *; #Xw Pws; @(w :: ws); @; ##[ napply #]
787 nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
788 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
789 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
790 @; ncases b in H1; #H1;
791 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
792 nrewrite > (associative_append ? w' w1 w2);
793 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
794 ##| ncases w' in Pw';
795 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
796 ##| #x xs Px; @(x::xs); @(w1@w2);
797 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
799 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
800 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
801 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
802 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
804 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
805 @; //; @; //; @; *;##]##]##]
809 alias symbol "pc" (instance 13) = "cat lang".
810 alias symbol "in_pl" (instance 23) = "in_pl".
811 alias symbol "in_pl" (instance 5) = "in_pl".
812 alias symbol "eclose" (instance 21) = "eclose".
813 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
815 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
816 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
818 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
819 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
820 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
821 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
822 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
823 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
825 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
826 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
827 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
828 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
829 nrewrite < (erase_plus …); //.
830 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
831 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
832 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
833 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
834 nrewrite > (erase_bull…e);
835 nrewrite > (erase_star …);
836 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
837 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
838 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
839 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
840 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
841 nrewrite > (cup_dotD…); nrewrite > (cupA…);
842 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
843 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
848 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
849 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
851 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
852 #S e; napply extP; #w; nnormalize; @;
853 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
854 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
855 nrewrite < defw; nrewrite < defw2; @; //; @;//;
856 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
857 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
861 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
862 #S e; @[]; /2/; nqed.
864 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
865 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
867 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
868 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
870 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
871 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
872 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
873 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
877 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
878 #S p; ncases p; #e b; ncases b;
879 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
880 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
881 nchange in ⊢ (??%?) with (?∪?);
882 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
883 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
884 nlapply (bull_cup ? e); #bc;
885 nchange in match (𝐋\p (•e)) in bc with (?∪?);
886 nchange in match b' in bc with b';
887 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
888 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
889 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
890 nrewrite > (sub_dot_star…);
891 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
892 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
893 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
895 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
896 nrewrite < (cup0 ? (𝐋\p e)); //;##]
899 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
904 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
905 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
906 | k e1 ⇒ pk ? (pre_of_re ? e1)].
908 nlemma notFalse : ¬False. @; //; nqed.
910 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
911 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
912 *; #w1; *; #w2; *; *; //; nqed.
914 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
915 #S e; nelim e; ##[##1,2,3: //]
916 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
917 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
918 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
919 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
920 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
921 nrewrite > H1; napply dot0; ##]
924 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
926 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
927 nrewrite < H1; nrewrite < H2; //
928 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
929 nrewrite < H1; nrewrite < H2; //
930 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
935 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
936 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
937 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
940 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
941 #S f g H; nrewrite > H; //; nqed.
944 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
946 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
947 nrewrite > defsnde; #H;
948 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
953 notation > "\move term 90 x term 90 E"
954 non associative with precedence 60 for @{move ? $x $E}.
955 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
959 | ps y ⇒ 〈 `y, false 〉
960 | pp y ⇒ 〈 `y, x == y 〉
961 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
962 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
963 | pk e ⇒ (\move x e)^⊛ ].
964 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
965 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
966 interpretation "move" 'move x E = (move ? x E).
968 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
969 interpretation "rmove" 'move x E = (rmove ? x E).
971 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
972 #S w abs; ninversion abs; #; ndestruct;
976 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
977 #S w abs; ninversion abs; #; ndestruct;
980 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
981 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
986 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
987 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
988 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
989 ncases e1 in H; ncases e2;
990 ##[##1: *; ##[*; nnormalize; #; ndestruct]
991 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
992 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
993 ##|##2: *; ##[*; nnormalize; #; ndestruct]
994 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
995 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
996 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
997 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
998 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
999 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
1000 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
1001 #H; ninversion H; nnormalize; #; ndestruct;
1002 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
1003 ##| #r1 r2; *; ##[ *; #defw]
1008 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
1009 #S E; ncases E; #r b; nelim r;
1011 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
1012 #H; ninversion H; #; ndestruct;
1013 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
1014 #H; ninversion H; #; ndestruct;##]
1015 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
1016 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
1017 ##|#a c w; @; nnormalize;
1018 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
1019 #H; ninversion H; #; ndestruct;
1020 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
1021 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
1022 ##|#r1 r2 H1 H2 a w; @;
1023 ##[ #H; ncases (in_move_cat … H);
1024 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
1025 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
1026 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
1035 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
1036 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
1039 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
1041 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
1043 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
1045 ∀E1,E2: bool × (pre S).
1047 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
1050 ndefinition NAT: decidable.
1054 include "hints_declaration.ma".
1056 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
1057 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1059 ninductive unit: Type[0] ≝ I: unit.
1061 nlet corec foo_nop (b: bool):
1063 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1064 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1066 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1068 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1069 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1073 nlet corec foo (a: unit):
1075 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1076 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1081 [ nnormalize in ⊢ (??%%);
1082 nnormalize in foo: (? → ??%%);
1084 [ nnormalize in ⊢ (??%%); napply foo_nop
1086 [ nnormalize in ⊢ (??%%);
1088 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1089 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1094 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1095 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1096 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1099 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1100 nnormalize in match test3;
1105 (**********************************************************)
1107 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1108 der_z: der S a (z S) (z S)
1109 | der_e: der S a (e S) (z S)
1110 | der_s1: der S a (s S a) (e ?)
1111 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1112 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1113 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1114 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1115 der S a (c ? e1 e2) (c ? e1' e2)
1116 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1117 der S a (o ? e1 e2) (o ? e1' e2').
1119 nlemma eq_rect_CProp0_r:
1120 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1121 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1124 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1126 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1127 (* #S; #r1; #r2; #w; nelim r1
1129 | #H1; #H2; napply (in_c ? []); //
1130 | (* tutti casi assurdi *) *)
1132 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1133 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1134 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1136 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1138 (in_l S [] E1 → in_l S [] E2) →
1139 (in_l S [] E2 → in_l S [] E1) →
1140 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1143 (* serve il lemma dopo? *)
1144 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1145 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1147 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1149 (* IL VICEVERSA NON VALE *)
1150 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1151 (* #S; #w; #E; #H; nelim H
1153 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1157 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1158 #S; #a; #E; #E'; #w; #H; nelim H
1159 [##1,2: #H1; ninversion H1
1160 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1161 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1162 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1163 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1164 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1165 |##6,13: #x; #y; #K; ncases (?:False); /2/
1166 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1167 ##| #H1; ninversion H1
1169 | #X; #Y; #K; ncases (?:False); /2/
1170 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1171 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1172 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1173 | #x; #y; #K; ncases (?:False); /2/
1174 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1175 ##| #H1; #H2; #H3; ninversion H3
1176 [ #_; #K; ncases (?:False); /2/
1177 | #X; #Y; #K; ncases (?:False); /2/
1178 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1179 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1180 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1181 | #x; #y; #K; ncases (?:False); /2/
1182 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1183 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;