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 (* XXX This seems to be a pattern for equations in setoid(0) *)
166 unification hint 0 ≔ AA;
168 R ≟ setoid1_of_setoid (RE AA)
169 (*-----------------------------------------------*) ⊢
172 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
173 unification hint 0 ≔ S : Alpha, x,y: re (carr (acarr S));
175 TT ≟ setoid1_of_setoid SS,
177 (*-----------------------------------------*) ⊢
178 eq_re S x y ≡ eq_rel1 T (eq1 TT) x y.
180 (* contructors are morphisms *)
181 nlemma c_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
182 #A; napply (mk_binary_morphism … (λs1,s2:re A. s1 · s2)); #a; nelim a; /2/ by conj; nqed.
184 (* XXX This is the good format for hints about morphisms, fix the others *)
185 alias symbol "hint_decl" (instance 1) = "hint_decl_Type0".
186 unification hint 0 ≔ S:Alpha, A,B:re (carr (acarr S));
188 MM ≟ mk_unary_morphism ?? (λA.
190 (λB.A · B) (prop1 ?? (fun1 ?? (c_is_morph S) A)))
191 (prop1 ?? (c_is_morph S)),
193 (*--------------------------------------------------------------------------*) ⊢
194 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ c SS A B.
196 nlemma o_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
197 #A; napply (mk_binary_morphism … (λs1,s2:re A. s1 + s2)); #a; nelim a; /2/ by conj; nqed.
199 unification hint 0 ≔ S:Alpha, A,B:re (carr (acarr S));
201 MM ≟ mk_unary_morphism ?? (λA.
203 (λB.A + B) (prop1 ?? (fun1 ?? (o_is_morph S) A)))
204 (prop1 ?? (o_is_morph S)),
206 (*--------------------------------------------------------------------------*) ⊢
207 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ o SS A B.
209 nlemma k_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A).
210 #A; @(λs1:re A. s1^* ); #a; nelim a; /2/ by conj; nqed.
212 unification hint 0 ≔ S:Alpha, A:re (carr (acarr S));
214 MM ≟ mk_unary_morphism ?? (λB.B^* ) (prop1 ?? (k_is_morph S)),
216 (*--------------------------------------------------------------------------*) ⊢
217 fun1 T T MM A ≡ k SS A.
219 nlemma s_is_morph : ∀A:Alpha.A ⇒_0 (re A).
220 #A; @(λs1:A. s ? s1 ); #x y E; //; nqed.
222 unification hint 0 ≔ S:Alpha, a: carr (acarr S);
224 MM ≟ mk_unary_morphism ?? (λb.s ? b ) (prop1 ?? (s_is_morph S)),
225 T ≟ RE S, T1 ≟ acarr S
226 (*--------------------------------------------------------------------------*) ⊢
227 fun1 T1 T MM a ≡ s SS a.
229 (* end setoids support for re *)
231 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
232 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
234 interpretation "subset construction with type" 'comprehension t \eta.x =
237 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
238 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
239 interpretation "cat lang" 'pc a b = (cat ? a b).
242 nlemma cat_is_morph : ∀A:setoid. (lang A) ⇒_1 (lang A) ⇒_1 (lang A).
243 #X; napply (mk_binary_morphism1 … (λA,B:lang X.A · B));
244 #A1 A2 B1 B2 EA EB; napply ext_set; #x;
245 ncut (∀y,x:list X.(x ∈ B1) =_1 (x ∈ B2)); ##[
246 #_; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h1 | napply h2] ##] #YY;
247 ncut (∀x,y:list X.(x ∈ A1) =_1 (x ∈ A2)); ##[
248 #y; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h3 | napply h4] ##] #XX;
249 napply (.=_1 (∑w1, w2. XX w1 w2/ E ; (# ╪_1 E) ╪_1 #));
250 napply (.=_1 (∑w1, w2. YY w1 w2/ E ; # ╪_1 E)); //;
253 nlemma cat_is_ext: ∀A:setoid. (Elang A) → (Elang A) → (Elang A).
254 #S A B; @ (ext_carr … A · ext_carr … B); (* XXX coercion ext_carr che non funge *)
256 ncut (∀w1,w2.(x == w1@w2) = (y == w1@w2)); ##[
257 #w1 w2; @; #H; ##[ napply (.= Exy^-1) | napply (.= Exy)] // ]
259 ##[ napply (. (∑w1,w2. (E w1 w2)^-1 / E ; (E ╪_1 #) ╪_1 #)); napply H;
260 ##| napply (. (∑w1,w2. E w1 w2 / E ; (E ╪_1 #) ╪_1 #)); napply H ]
263 alias symbol "hint_decl" = "hint_decl_Type1".
264 unification hint 0 ≔ A : setoid, B,C : Elang A;
268 R ≟ mk_ext_powerclass AA
269 (cat A (ext_carr AA B) (ext_carr AA C))
270 (ext_prop AA (cat_is_ext A B C))
271 (*----------------------------------------------------------*) ⊢
272 ext_carr AA R ≡ cat A BB CC.
274 unification hint 0 ≔ S:setoid, A,B:lang (carr S);
275 T ≟ powerclass_setoid (list (carr S)),
276 MM ≟ mk_unary_morphism1 T (unary_morphism1_setoid1 T T)
278 mk_unary_morphism1 T T
279 (λB:lang (carr S).cat S A B)
280 (prop11 T T (fun11 ?? (cat_is_morph S) A)))
281 (prop11 T (unary_morphism1_setoid1 T T) (cat_is_morph S))
282 (*--------------------------------------------------------------------------*) ⊢
283 fun11 T T (fun11 T (unary_morphism1_setoid1 T T) MM A) B ≡ cat S A B.
285 nlemma cat_is_ext_morph:∀A:setoid.(Elang A) ⇒_1 (Elang A) ⇒_1 (Elang A).
286 #A; napply (mk_binary_morphism1 … (cat_is_ext …));
287 #x1 x2 y1 y2 Ex Ey; napply (prop11 … (cat_is_morph A)); nassumption.
290 unification hint 1 ≔ AA : setoid, B,C : Elang AA;
292 T ≟ ext_powerclass_setoid AAS,
293 R ≟ mk_unary_morphism1 T (unary_morphism1_setoid1 T T) (λX:Elang AA.
294 mk_unary_morphism1 T T (λY:Elang AA.
295 mk_ext_powerclass AAS
296 (cat AA (ext_carr ? X) (ext_carr ? Y))
297 (ext_prop AAS (cat_is_ext AA X Y)))
298 (prop11 T T (fun11 ?? (cat_is_ext_morph AA) X)))
299 (prop11 T (unary_morphism1_setoid1 T T) (cat_is_ext_morph AA)),
302 (*------------------------------------------------------*) ⊢
303 ext_carr AAS (fun11 T T (fun11 T (unary_morphism1_setoid1 T T) R B) C) ≡ cat AA BB CC.
305 (* end hints for cat *)
307 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
308 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
309 interpretation "star lang" 'pk l = (star ? l).
312 nlemma star_is_morph : ∀A:setoid. (lang A) ⇒_1 (lang A).
313 #X; @(λA:lang X.A^* ); #a1 a2 E; @; #x; *; #wl; *; #defx Px; @wl; @; //;
314 nelim wl in Px; //; #s tl IH; *; #a1s a1tl; /4/; nqed.
316 nlemma star_is_ext: ∀A:setoid. (Elang A) → (Elang A).
317 #S A; @ ((ext_carr … A) ^* ); #w1 w2 E; @; *; #wl; *; #defw1 Pwl;
318 @wl; @; //; napply (.=_0 defw1); /2/; nqed.
320 alias symbol "hint_decl" = "hint_decl_Type1".
321 unification hint 0 ≔ A : setoid, B : Elang A;
324 R ≟ mk_ext_powerclass ?
325 ((ext_carr ? B)^* ) (ext_prop ? (star_is_ext ? B))
326 (*--------------------------------------------------------------------*) ⊢
327 ext_carr AA R ≡ star A BB.
329 unification hint 0 ≔ S:setoid, A:lang (carr S);
330 T ≟ powerclass_setoid (list (carr S)),
331 MM ≟ mk_unary_morphism1 T T
332 (λB:lang (carr S).star S B) (prop11 T T (star_is_morph S))
333 (*--------------------------------------------------------------------------*) ⊢
334 fun11 T T MM A ≡ star S A.
336 nlemma star_is_ext_morph:∀A:setoid.(Elang A) ⇒_1 (Elang A).
337 #A; @(star_is_ext …);
338 #x1 x2 Ex; napply (prop11 … (star_is_morph A)); nassumption.
341 unification hint 1 ≔ AA : setoid, B : Elang AA;
343 T ≟ ext_powerclass_setoid AAS,
344 R ≟ mk_unary_morphism1 T T
346 mk_ext_powerclass AAS (star AA (ext_carr ? S))
347 (ext_prop AAS (star_is_ext AA S)))
348 (prop11 T T (star_is_ext_morph AA)),
350 (*------------------------------------------------------*) ⊢
351 ext_carr AAS (fun11 T T R B) ≡ star AA BB.
353 (* end hints for star *)
355 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
356 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
361 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
362 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
364 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
365 interpretation "in_l" 'L_re E = (L_re ? E).
367 (* support for 𝐋 as an extensional set *)
368 ndefinition L_re_is_ext : ∀S:Alpha.∀r:re S.Elang S.
369 #S r; @(𝐋 r); #w1 w2 E; nelim r;
370 ##[ ##1,2: /2/; @; #defw1; napply (.=_0 (defw1 : [ ] = ?)); //; napply (?^-1); //;
371 ##| #x; @; #defw1; napply (.=_0 (defw1 : [x] = ?)); //; napply (?^-1); //;
372 ##| #e1 e2 H1 H2; (* not shure I shoud Inline *)
373 @; *; #s1; *; #s2; *; *; #defw1 s1L1 s2L2;
374 ##[ nlapply (trans … E^-1 defw1); #defw2;
375 ##| nlapply (trans … E defw1); #defw2; ##] @s1; @s2; /3/;
376 ##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
377 ##| #e H; @; *; #l; *; #defw1 Pl; @l; @; //; napply (.=_1 defw1); /2/; ##]
380 unification hint 0 ≔ S : Alpha,e : re (carr (acarr S));
382 X ≟ mk_ext_powerclass SS (𝐋 e) (ext_prop SS (L_re_is_ext S e))
383 (*-----------------------------------------------------------------*)⊢
384 ext_carr SS X ≡ L_re S e.
386 nlemma L_re_is_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 Ω^(list A).
387 #A; @; ##[ napply (λr:re A.𝐋 r); ##] #r1; nelim r1;
388 ##[##1,2: #r2; ncases r2; //; ##[##1,6: *|##2,7,5,12,10: #a; *|##3,4,8,9: #a1 a2; *]
389 ##|#x r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##6: #a; *] #y E; @; #z defz;
390 ncases z in defz; ##[##1,3: *] #zh ztl; ncases ztl; ##[##2,4: #d dl; *; #_; *]
391 *; #defx; #_; @; //; napply (?^-1); napply (.= defx^-1); //; napply (?^-1); //;
392 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##5: #a1 a2; *|##3,6: #a1; *]
393 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
394 nchange in match (𝐋 (e1 · e2)) with (?·?);
395 napply (.=_1 (H1 ╪_1 H2)); //;
396 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##4: #a1 a2; *|##3,6: #a1; *]
397 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
398 napply (.=_1 H1╪_1H2); //;
399 ##|#r IH r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##3: #a1; *]
400 #e; #defe; nlapply (IH e defe); #H;
401 @; #x; *; #wl; *; #defx Px; @wl; @; //; nelim wl in Px; //; #l ls IH; *; #lr Pr;
402 ##[ nlapply (ifs' … H … lr) | nlapply (ifs' … H^-1 … lr) ] #le;
403 @; ##[##1,3: nassumption] /2/; ##]
406 unification hint 0 ≔ A:Alpha, a:re (carr (acarr A));
407 T ≟ setoid1_of_setoid (RE A),
408 T2 ≟ powerclass_setoid (list (carr (acarr A))),
409 MM ≟ mk_unary_morphism1 ??
410 (λa:carr1 (setoid1_of_setoid (RE A)).𝐋 a) (prop11 ?? (L_re_is_morph A))
411 (*--------------------------------------------------------------------------*) ⊢
412 fun11 T T2 MM a ≡ L_re A a.
414 nlemma L_re_is_ext_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 𝛀^(list A).
415 #A; @; ##[ #a; napply (L_re_is_ext ? a); ##] #a b E;
416 ncut (𝐋 b = 𝐋 a); ##[ napply (.=_1 (┼_1 E^-1)); // ] #EL;
417 @; #x H; nchange in H ⊢ % with (x ∈ 𝐋 ?);
418 ##[ napply (. (# ╪_1 ?)); ##[##3: napply H |##2: ##skip ] napply EL;
419 ##| napply (. (# ╪_1 ?)); ##[##3: napply H |##2: ##skip ] napply (EL^-1)]
422 unification hint 1 ≔ AA : Alpha, a: re (carr (acarr AA));
423 T ≟ RE AA, T1 ≟ LIST (acarr AA), T2 ≟ setoid1_of_setoid T,
424 TT ≟ ext_powerclass_setoid T1,
425 R ≟ mk_unary_morphism1 T2 TT
426 (λa:carr1 (setoid1_of_setoid T).
427 mk_ext_powerclass T1 (𝐋 a) (ext_prop T1 (L_re_is_ext AA a)))
428 (prop11 T2 TT (L_re_is_ext_morph AA))
429 (*------------------------------------------------------*) ⊢
430 ext_carr T1 (fun11 (setoid1_of_setoid T) TT R a) ≡ L_re AA a.
432 (* end support for 𝐋 as an extensional set *)
434 ninductive pitem (S: Type[0]) : Type[0] ≝
439 | pc: pitem S → pitem S → pitem S
440 | po: pitem S → pitem S → pitem S
441 | pk: pitem S → pitem S.
443 interpretation "pstar" 'pk a = (pk ? a).
444 interpretation "por" 'plus a b = (po ? a b).
445 interpretation "pcat" 'pc a b = (pc ? a b).
446 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
447 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
448 interpretation "ppatom" 'pp a = (pp ? a).
449 (* to get rid of \middot *)
450 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
451 interpretation "patom" 'ps a = (ps ? a).
452 interpretation "pepsilon" 'epsilon = (pe ?).
453 interpretation "pempty" 'empty_r = (pz ?).
455 (* setoids for pitem *)
456 nlet rec eq_pitem (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝
458 [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
459 | pe ⇒ match p2 with [ pe ⇒ True | _ ⇒ False]
460 | ps x ⇒ match p2 with [ ps y ⇒ x = y | _ ⇒ False]
461 | pp x ⇒ match p2 with [ pp y ⇒ x = y | _ ⇒ False]
462 | pc a1 a2 ⇒ match p2 with [ pc b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
463 | po a1 a2 ⇒ match p2 with [ po b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
464 | pk a ⇒ match p2 with [ pk b ⇒ eq_pitem ? a b | _ ⇒ False]].
466 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b).
468 nlemma PITEM : ∀S:Alpha.setoid.
469 #S; @(pitem S); @(eq_pitem …);
470 ##[ #p; nelim p; //; nnormalize; #; @; //;
471 ##| #p; nelim p; ##[##1,2: #y; ncases y; //; ##|##3,4: #x y; ncases y; //; #; napply (?^-1); nassumption;
472 ##|##5,6: #r1 r2 H1 H2 p2; ncases p2; //; #s1 s2; nnormalize; *; #; @; /2/;
473 ##| #r H y; ncases y; //; nnormalize; /2/;##]
475 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
476 ##| ##3,4: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
477 ##| ##5,6: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
478 ##[##1,2,5,6,7,8,4,10: #; ncases (?:False); //;##]
479 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
480 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3,4: #; ncases (?:False); //]
484 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
485 unification hint 0 ≔ SS:Alpha;
488 P1 ≟ refl ? (eq0 (PITEM SS)),
489 P2 ≟ sym ? (eq0 (PITEM SS)),
490 P3 ≟ trans ? (eq0 (PITEM SS)),
491 R ≟ mk_setoid (pitem (carr S))
492 (mk_equivalence_relation (pitem A) (eq_pitem SS) P1 P2 P3)
493 (*-----------------------------------------------------------------*)⊢
496 unification hint 0 ≔ S:Alpha,a,b:pitem (carr (acarr S));
497 R ≟ PITEM S, L ≟ pitem (carr (acarr S))
498 (* -------------------------------------------- *) ⊢
499 eq_pitem S a b ≡ eq_rel L (eq0 R) a b.
501 (* end setoids for pitem *)
503 ndefinition pre ≝ λS.pitem S × bool.
505 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
506 interpretation "fst" 'fst x = (fst ? ? x).
507 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
508 interpretation "snd" 'snd x = (snd ? ? x).
510 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
511 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
517 | pc E1 E2 ⇒ (|E1| · |E2|)
518 | po E1 E2 ⇒ (|E1| + |E2|)
521 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
522 interpretation "forget" 'forget a = (forget ? a).
524 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
525 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
531 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
532 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
533 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
534 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
535 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
536 interpretation "in_pl" 'L_pi E = (L_pi ? E).
538 (* set support for 𝐋\p *)
539 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
540 #S r; @(𝐋\p r); #w1 w2 E; nelim r;
543 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
544 napply ((.=_0 H) E^-1);
547 ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
548 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
549 napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #);
550 ##| #e1 e2 H1 H2; napply (H1‡H2);
552 ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
553 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
554 napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#);
558 unification hint 0 ≔ S : Alpha,e : pitem (carr (acarr S));
560 X ≟ mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e))
561 (*-----------------------------------------------------------------*)⊢
562 ext_carr SS X ≡ 𝐋\p e.
564 (* end set support for 𝐋\p *)
566 ndefinition epsilon ≝
567 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
569 interpretation "epsilon" 'epsilon = (epsilon ?).
570 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
571 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
573 (* hints for epsilon *)
574 nlemma epsilon_is_morph : ∀A:Alpha. (setoid1_of_setoid bool) ⇒_1 (lang A).
575 #X; @; ##[#b; napply(ϵ b)] #a1 a2; ncases a1; ncases a2; //; *; nqed.
577 nlemma epsilon_is_ext: ∀A:Alpha. (setoid1_of_setoid bool) → (Elang A).
578 #S b; @(ϵ b); #w1 w2 E; ncases b; @; ##[##3,4:*]
579 nchange in match (w1 ∈ ϵ true) with ([] =_0 w1);
580 nchange in match (w2 ∈ ϵ true) with ([] =_0 w2); #H; napply (.= H); /2/;
583 alias symbol "hint_decl" = "hint_decl_Type1".
584 unification hint 0 ≔ A : Alpha, B : bool;
586 R ≟ mk_ext_powerclass ?
587 (ϵ B) (ext_prop ? (epsilon_is_ext ? B))
588 (*--------------------------------------------------------------------*) ⊢
589 ext_carr AA R ≡ epsilon A B.
591 unification hint 0 ≔ S:Alpha, A:bool;
592 B ≟ setoid1_of_setoid BOOL,
593 T ≟ powerclass_setoid (list (carr (acarr S))),
594 MM ≟ mk_unary_morphism1 B T
595 (λB.ϵ B) (prop11 B T (epsilon_is_morph S))
596 (*--------------------------------------------------------------------------*) ⊢
597 fun11 B T MM A ≡ epsilon S A.
599 nlemma epsilon_is_ext_morph:∀A:Alpha. (setoid1_of_setoid bool) ⇒_1 (Elang A).
600 #A; @(epsilon_is_ext …);
601 #x1 x2 Ex; napply (prop11 … (epsilon_is_morph A)); nassumption.
604 unification hint 1 ≔ AA : Alpha, B : bool;
605 AAS ≟ LIST (acarr AA),
606 BB ≟ setoid1_of_setoid BOOL,
607 T ≟ ext_powerclass_setoid AAS,
608 R ≟ mk_unary_morphism1 BB T
610 mk_ext_powerclass AAS (epsilon AA S)
611 (ext_prop AAS (epsilon_is_ext AA S)))
612 (prop11 BB T (epsilon_is_ext_morph AA))
613 (*------------------------------------------------------*) ⊢
614 ext_carr AAS (fun11 BB T R B) ≡ epsilon AA B.
616 (* end hints for epsilon *)
618 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
620 interpretation "L_pr" 'L_pi E = (L_pr ? E).
622 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
623 #S w1; ncases w1; //. nqed.
625 (* lemma 12 *) (* XXX: a case where Leibnitz equality could be exploited for H *)
626 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
627 #S r; ncases r; #e b; @; ##[##2: #H; ncases b in H; ##[##2:*] #; @2; /2/; ##]
628 ncases b; //; *; ##[##2:*] nelim e;
629 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
630 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
631 ##| #r1 r2 H1 H2; *; /2/ by {}]
632 *; #w1; *; #w2; *; *;
633 ##[ #defw1 H1 foo; napply H;
634 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
636 ##| #defw1 H1 foo; napply H;
637 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
642 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
643 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
644 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
645 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
646 napply (. defw1^-1╪_1#);
648 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
649 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
650 nlapply (append_eq_nil ??? abs); # defw1; #;
651 napply (. defw1^-1╪_1#);
655 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
656 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
657 interpretation "oplus" 'oplus a b = (lo ? a b).
659 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
660 match a with [ mk_pair e1 b1 ⇒
662 [ false ⇒ 〈e1 · \fst b, \snd b〉
663 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
665 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
666 interpretation "lc" 'lc op a b = (lc ? op a b).
667 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
669 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
670 match a with [ mk_pair e1 b1 ⇒
672 [ false ⇒ 〈e1^*, false〉
673 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
675 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
676 interpretation "lk" 'lk op a = (lk ? op a).
677 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
679 notation > "•" non associative with precedence 60 for @{eclose ?}.
680 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
684 | ps x ⇒ 〈 `.x, false 〉
685 | pp x ⇒ 〈 `.x, false 〉
686 | po E1 E2 ⇒ •E1 ⊕ •E2
687 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
688 | pk E ⇒ 〈(\fst (•E))^*,true〉].
689 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
690 interpretation "eclose" 'eclose x = (eclose ? x).
691 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
693 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
694 interpretation "reclose" 'eclose x = (reclose ? x).
696 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
697 #S b1 b2; ncases b1; ncases b2;
698 nchange in match (true || true) with true;
699 nchange in match (true || false) with true;
700 nchange in match (ϵ true) with {[]};
701 nchange in match (ϵ false) with ∅;
702 ##[##1,4: napply ((cupID…)^-1);
703 ##| napply ((cup0 ? {[]})^-1);
704 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
708 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
709 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
710 napply (.=_1 #╪_1 (epsilon_or ???));
711 napply (.=_1 (cupA…)^-1);
712 napply (.=_1 (cupA…)╪_1#);
713 napply (.=_1 (#╪_1(cupC…))╪_1#);
714 napply (.=_1 (cupA…)^-1╪_1#);
715 napply (.=_1 (cupA…));
720 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
721 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
722 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
723 #S e1 e2 b2; ncases b2; @; /3/ by refl, conj, I; nqed.
726 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
727 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
730 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
731 #S p q r; napply ext_set; #w; nnormalize; @;
732 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
733 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
737 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
738 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
741 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
742 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
744 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
746 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
747 #S a b; nnormalize; /2/; nqed.
749 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
750 #S A B x H; napply ext_set; #w; @;
751 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
752 *; #wb nwn; @; ##[@2;//] //;
753 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
756 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
757 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
759 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
760 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
762 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
763 #S a b w; nnormalize; *; //; nqed.
765 alias symbol "eclose" (instance 3) = "eclose".
766 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
767 #S a; nelim a; // by {};
770 napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
771 nchange in match (•(e1 · ?)) with (?⊙?);
772 ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
773 napply (.=_0 #╪_0 (IH2)); //;
774 ##| #e1 e2 IH1 IH2; napply (?^-1);
775 napply (.=_0 (IH1^-1)╪_0(IH2^-1));
776 nchange in match (•(e1+?)) with (?⊕?);
777 ncases (•e1); ncases (•e2); //]
781 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
782 #S p; ncases p; //; nqed.
785 (* XXX coercion ext_carr non applica *)
786 nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p.
787 #S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
788 *; #w1; *; #w2; *; *; #defw defw1 Hw2;
790 napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
796 (* theorem 16: 1 → 3 *)
797 nlemma odot_dot_aux : ∀S:Alpha.∀e1,e2: pre S.
798 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
799 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
800 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
801 ##[ nchange in match (〈?,true〉⊙?) with 〈?,?〉;
802 nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
803 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
804 napply (.=_1 (# ╪_1 (epsilon_or …))); (* XXX … is too slow if combined with .= *)
805 nchange in match b2'' with b2''; (* XXX some unfoldings happened *)
806 nchange in match b2' with b2';
807 napply (.=_1 (# ╪_1 (cupC …))); napply (.=_1 (cupA …));
808 napply (.=_1 (# ╪_1 (cupA …)^-1)); (* XXX slow, but not because of disamb! *)
809 ncut (𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[
810 napply (?^-1); napply (.=_1 th1^-1); //;##] #E;
811 napply (.=_1 (# ╪_1 (E ╪_1 #)));
813 napply (.=_1 (cup_dotD …) ╪_1 #);
814 napply (.=_1 (# ╪_1 (epsilon_dot …)) ╪_1 #);
816 napply (.=_1 # ╪_1 ((cupC …) ╪_1 #));
817 napply (.=_1 (cupA …)^-1);
818 napply (.=_1 (cupA …)^-1 ╪_1 #);
819 napply (.=_1 (cupA …));
820 napply (.=_1 (((# ╪_1 (┼_1 (erase_bull S e2')) )╪_1 #)╪_1 #));
822 ##| ncases e2; #e2' b2'; nchange in match (𝐋\p ?) with (?∪?∪?);
823 napply (.=_1 (cupA…));
824 napply (?^-1); nchange in match (𝐋\p 〈?,false〉) with (?∪?);
825 napply (.=_1 ((cup0…)╪_1#)╪_1#);
831 nlemma sub_dot_star :
832 ∀S:Alpha.∀X:Elang S.∀b. (X - ϵ b) · (ext_carr … X)^* ∪ {[]} = (ext_carr … X)^*.
833 #S X b; napply ext_set; #w; @;
834 ##[ *; ##[##2: #defw; @[]; @; //]
835 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
836 @ (w1 :: lw); @; ##[ napply (.=_0 # ╪_0 flx); napply (?^-1); //]
837 @; //; napply (subW … sube);
838 ##| *; #wl; *; #defw Pwl; napply (. (defw^-1 ╪_1 #));
839 nelim wl in Pwl; /2/;
840 #s tl IH; *; #Xs Ptl; ncases s in Xs; ##[ #; napply IH; //] #x xs Xxxs;
841 @; @(x :: xs); @(flatten ? tl); @;
842 ##[ @; ##[ napply #] @; ##[nassumption] ncases b; *; ##]
843 nelim tl in Ptl; ##[ #; @[]; /2/] #w ws IH; *; #Xw Pws; @(w :: ws); @; ##[ napply #]
848 alias symbol "pc" (instance 13) = "cat lang".
849 alias symbol "in_pl" (instance 23) = "in_pl".
850 alias symbol "in_pl" (instance 5) = "in_pl".
851 alias symbol "eclose" (instance 21) = "eclose".
852 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
854 ##[ #a; napply ext_set; #w; @; *; /3/ by or_introl, or_intror;
855 ##| #a; napply ext_set; #w; @; *; /3/ by or_introl; *;
857 nchange in match (•(e1·e2)) with (•e1 ⊙ 〈e2,false〉);
858 napply (.=_1 (odot_dot_aux ?? 〈e2,false〉 IH2));
859 napply (.=_1 (IH1 ╪_1 #) ╪_1 #);
860 napply (.=_1 (cup_dotD …) ╪_1 #);
861 napply (.=_1 (cupA …));
862 napply (.=_1 # ╪_1 ((erase_dot ???)^-1 ╪_1 (cup0 ??)));
863 napply (.=_1 # ╪_1 (cupC…));
864 napply (.=_1 (cupA …)^-1); //;
866 nchange in match (•(?+?)) with (•e1 ⊕ •e2);
867 napply (.=_1 (oplus_cup …));
868 napply (.=_1 IH1 ╪_1 IH2);
869 napply (.=_1 (cupA …));
870 napply (.=_1 # ╪_1 (# ╪_1 (cupC…)));
871 napply (.=_1 # ╪_1 (cupA ????)^-1);
872 napply (.=_1 # ╪_1 (cupC…));
873 napply (.=_1 (cupA ????)^-1);
874 napply (.=_1 # ╪_1 (erase_plus ???)^-1); //;
875 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
876 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
877 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
878 (* nwhd in match (𝐋\p e'^* ); (* XXX bug uncertain *) *)
879 nchange in ⊢ (???(??%?)?) with (𝐋\p e' · ?);
880 napply (.=_1 (# ╪_1 (┼_1 (┼_0 (erase_bull S e)))) ╪_1 #);
881 napply (.=_1 (# ╪_1 (erase_star …)) ╪_1 #);
882 ncut ( 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[
883 nchange in IH : (???%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
884 ##[ #IH; napply (?^-1); napply (.=_1 (cup_sub … (not_epsilon_lp…)));
885 napply (.=_1 (IH^-1 ╪_1 #));
886 alias symbol "invert" = "setoid1 symmetry".
887 (* XXX too slow if ambiguous, since it tries with a ? (takes 12s) then
888 tries with sym0 and fails immediately, then with sym1 that is OK *)
889 napply (.=_1 (cup_sub …(not_epsilon_lp …))^-1);
890 napply (.=_1 # ╪_1 (subK…)); napply (.=_1 (cup0…)); //;
891 ##| #IH; napply (?^-1); napply (.=_1 # ╪_1 (sub0 …));
892 napply (.=_1 IH^-1); napply (.=_1 (cup0 …)); //; ##]##] #EE;
893 napply (.=_1 (EE ╪_1 #) ╪_1 #);
894 napply (.=_1 (cup_dotD…) ╪_1 #);
895 napply (.=_1 (cupA…));
896 napply (.=_1 # ╪_1 (sub_dot_star…)); //; ##]
903 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
904 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
906 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
907 #S e; napply extP; #w; nnormalize; @;
908 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
909 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
910 nrewrite < defw; nrewrite < defw2; @; //; @;//;
911 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
912 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
916 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
917 #S e; @[]; /2/; nqed.
919 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
920 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
922 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
923 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
925 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
926 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
927 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
928 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
932 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
933 #S p; ncases p; #e b; ncases b;
934 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
935 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
936 nchange in ⊢ (??%?) with (?∪?);
937 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
938 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
939 nlapply (bull_cup ? e); #bc;
940 nchange in match (𝐋\p (•e)) in bc with (?∪?);
941 nchange in match b' in bc with b';
942 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
943 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
944 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
945 nrewrite > (sub_dot_star…);
946 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
947 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
948 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
950 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
951 nrewrite < (cup0 ? (𝐋\p e)); //;##]
954 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
959 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
960 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
961 | k e1 ⇒ pk ? (pre_of_re ? e1)].
963 nlemma notFalse : ¬False. @; //; nqed.
965 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
966 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
967 *; #w1; *; #w2; *; *; //; nqed.
969 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
970 #S e; nelim e; ##[##1,2,3: //]
971 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
972 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
973 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
974 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
975 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
976 nrewrite > H1; napply dot0; ##]
979 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
981 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
982 nrewrite < H1; nrewrite < H2; //
983 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
984 nrewrite < H1; nrewrite < H2; //
985 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
990 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
991 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
992 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
995 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
996 #S f g H; nrewrite > H; //; nqed.
999 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
1001 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
1002 nrewrite > defsnde; #H;
1003 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
1008 notation > "\move term 90 x term 90 E"
1009 non associative with precedence 60 for @{move ? $x $E}.
1010 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
1014 | ps y ⇒ 〈 `y, false 〉
1015 | pp y ⇒ 〈 `y, x == y 〉
1016 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
1017 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
1018 | pk e ⇒ (\move x e)^⊛ ].
1019 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
1020 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
1021 interpretation "move" 'move x E = (move ? x E).
1023 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
1024 interpretation "rmove" 'move x E = (rmove ? x E).
1026 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
1027 #S w abs; ninversion abs; #; ndestruct;
1031 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
1032 #S w abs; ninversion abs; #; ndestruct;
1035 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
1036 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
1041 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
1042 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
1043 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
1044 ncases e1 in H; ncases e2;
1045 ##[##1: *; ##[*; nnormalize; #; ndestruct]
1046 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1047 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1048 ##|##2: *; ##[*; nnormalize; #; ndestruct]
1049 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1050 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1051 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
1052 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1053 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
1054 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
1055 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
1056 #H; ninversion H; nnormalize; #; ndestruct;
1057 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
1058 ##| #r1 r2; *; ##[ *; #defw]
1063 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
1064 #S E; ncases E; #r b; nelim r;
1066 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
1067 #H; ninversion H; #; ndestruct;
1068 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
1069 #H; ninversion H; #; ndestruct;##]
1070 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
1071 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
1072 ##|#a c w; @; nnormalize;
1073 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
1074 #H; ninversion H; #; ndestruct;
1075 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
1076 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
1077 ##|#r1 r2 H1 H2 a w; @;
1078 ##[ #H; ncases (in_move_cat … H);
1079 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
1080 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
1081 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
1090 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
1091 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
1094 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
1096 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
1098 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
1100 ∀E1,E2: bool × (pre S).
1102 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
1105 ndefinition NAT: decidable.
1109 include "hints_declaration.ma".
1111 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
1112 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1114 ninductive unit: Type[0] ≝ I: unit.
1116 nlet corec foo_nop (b: bool):
1118 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1119 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1121 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1123 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1124 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1128 nlet corec foo (a: unit):
1130 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1131 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1136 [ nnormalize in ⊢ (??%%);
1137 nnormalize in foo: (? → ??%%);
1139 [ nnormalize in ⊢ (??%%); napply foo_nop
1141 [ nnormalize in ⊢ (??%%);
1143 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1144 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1149 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1150 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1151 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1154 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1155 nnormalize in match test3;
1160 (**********************************************************)
1162 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1163 der_z: der S a (z S) (z S)
1164 | der_e: der S a (e S) (z S)
1165 | der_s1: der S a (s S a) (e ?)
1166 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1167 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1168 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1169 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1170 der S a (c ? e1 e2) (c ? e1' e2)
1171 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1172 der S a (o ? e1 e2) (o ? e1' e2').
1174 nlemma eq_rect_CProp0_r:
1175 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1176 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1179 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1181 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1182 (* #S; #r1; #r2; #w; nelim r1
1184 | #H1; #H2; napply (in_c ? []); //
1185 | (* tutti casi assurdi *) *)
1187 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1188 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1189 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1191 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1193 (in_l S [] E1 → in_l S [] E2) →
1194 (in_l S [] E2 → in_l S [] E1) →
1195 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1198 (* serve il lemma dopo? *)
1199 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1200 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1202 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1204 (* IL VICEVERSA NON VALE *)
1205 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1206 (* #S; #w; #E; #H; nelim H
1208 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1212 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1213 #S; #a; #E; #E'; #w; #H; nelim H
1214 [##1,2: #H1; ninversion H1
1215 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1216 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1217 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1218 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1219 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1220 |##6,13: #x; #y; #K; ncases (?:False); /2/
1221 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1222 ##| #H1; ninversion H1
1224 | #X; #Y; #K; ncases (?:False); /2/
1225 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1226 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1227 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1228 | #x; #y; #K; ncases (?:False); /2/
1229 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1230 ##| #H1; #H2; #H3; ninversion H3
1231 [ #_; #K; ncases (?:False); /2/
1232 | #X; #Y; #K; ncases (?:False); /2/
1233 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1234 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1235 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1236 | #x; #y; #K; ncases (?:False); /2/
1237 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1238 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;