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 65 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 (* hints for epsilon *)
550 nlemma epsilon_is_morph : ∀A:Alpha. (setoid1_of_setoid bool) ⇒_1 (lang A).
551 #X; @; ##[#b; napply(ϵ b)] #a1 a2; ncases a1; ncases a2; //; *; nqed.
553 nlemma epsilon_is_ext: ∀A:Alpha. (setoid1_of_setoid bool) → (Elang A).
554 #S b; @(ϵ b); #w1 w2 E; ncases b; @; ##[##3,4:*]
555 nchange in match (w1 ∈ ϵ true) with ([] =_0 w1);
556 nchange in match (w2 ∈ ϵ true) with ([] =_0 w2); #H; napply (.= H); /2/;
559 alias symbol "hint_decl" = "hint_decl_Type1".
560 unification hint 0 ≔ A : Alpha, B : bool;
562 R ≟ mk_ext_powerclass ?
563 (ϵ B) (ext_prop ? (epsilon_is_ext ? B))
564 (*--------------------------------------------------------------------*) ⊢
565 ext_carr AA R ≡ epsilon A B.
567 unification hint 0 ≔ S:Alpha, A:bool;
568 B ≟ setoid1_of_setoid BOOL,
569 T ≟ powerclass_setoid (list (carr (acarr S))),
570 MM ≟ mk_unary_morphism1 B T
571 (λB.ϵ B) (prop11 B T (epsilon_is_morph S))
572 (*--------------------------------------------------------------------------*) ⊢
573 fun11 B T MM A ≡ epsilon S A.
575 nlemma epsilon_is_ext_morph:∀A:Alpha. (setoid1_of_setoid bool) ⇒_1 (Elang A).
576 #A; @(epsilon_is_ext …);
577 #x1 x2 Ex; napply (prop11 … (epsilon_is_morph A)); nassumption.
580 unification hint 1 ≔ AA : Alpha, B : bool;
581 AAS ≟ LIST (acarr AA),
582 BB ≟ setoid1_of_setoid BOOL,
583 T ≟ ext_powerclass_setoid AAS,
584 R ≟ mk_unary_morphism1 BB T
586 mk_ext_powerclass AAS (epsilon AA S)
587 (ext_prop AAS (epsilon_is_ext AA S)))
588 (prop11 BB T (epsilon_is_ext_morph AA))
589 (*------------------------------------------------------*) ⊢
590 ext_carr AAS (fun11 BB T R B) ≡ epsilon AA B.
592 (* end hints for epsilon *)
594 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
596 interpretation "L_pr" 'L_pi E = (L_pr ? E).
598 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
599 #S w1; ncases w1; //. nqed.
601 (* lemma 12 *) (* XXX: a case where Leibnitz equality could be exploited for H *)
602 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
603 #S r; ncases r; #e b; @; ##[##2: #H; ncases b in H; ##[##2:*] #; @2; /2/; ##]
604 ncases b; //; *; ##[##2:*] nelim e;
605 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
606 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
607 ##| #r1 r2 H1 H2; *; /2/ by {}]
608 *; #w1; *; #w2; *; *;
609 ##[ #defw1 H1 foo; napply H;
610 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
612 ##| #defw1 H1 foo; napply H;
613 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
618 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
619 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
620 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
621 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
622 napply (. defw1^-1╪_1#);
624 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
625 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
626 nlapply (append_eq_nil ??? abs); # defw1; #;
627 napply (. defw1^-1╪_1#);
631 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
632 notation "a ⊕ b" left associative with precedence 65 for @{'oplus $a $b}.
633 interpretation "oplus" 'oplus a b = (lo ? a b).
635 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
636 match a with [ mk_pair e1 b1 ⇒
638 [ false ⇒ 〈e1 · \fst b, \snd b〉
639 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
641 notation < "a ⊙ b" left associative with precedence 65 for @{'lc $op $a $b}.
642 interpretation "lc" 'lc op a b = (lc ? op a b).
643 notation > "a ⊙ b" left associative with precedence 65 for @{'lc eclose $a $b}.
645 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
646 match a with [ mk_pair e1 b1 ⇒
648 [ false ⇒ 〈e1^*, false〉
649 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
651 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
652 interpretation "lk" 'lk op a = (lk ? op a).
653 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
655 notation > "•" non associative with precedence 65 for @{eclose ?}.
656 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
660 | ps x ⇒ 〈 `.x, false 〉
661 | pp x ⇒ 〈 `.x, false 〉
662 | po E1 E2 ⇒ •E1 ⊕ •E2
663 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
664 | pk E ⇒ 〈(\fst (•E))^*,true〉].
665 notation < "• x" non associative with precedence 65 for @{'eclose $x}.
666 interpretation "eclose" 'eclose x = (eclose ? x).
667 notation > "• x" non associative with precedence 65 for @{'eclose $x}.
669 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
670 interpretation "reclose" 'eclose x = (reclose ? x).
672 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
673 #S b1 b2; ncases b1; ncases b2;
674 nchange in match (true || true) with true;
675 nchange in match (true || false) with true;
676 nchange in match (ϵ true) with {[]};
677 nchange in match (ϵ false) with ∅;
678 ##[##1,4: napply ((cupID…)^-1);
679 ##| napply ((cup0 ? {[]})^-1);
680 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
684 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
685 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
686 napply (.=_1 #╪_1 (epsilon_or ???));
687 napply (.=_1 (cupA…)^-1);
688 napply (.=_1 (cupA…)╪_1#);
689 napply (.=_1 (#╪_1(cupC…))╪_1#);
690 napply (.=_1 (cupA…)^-1╪_1#);
691 napply (.=_1 (cupA…));
696 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
697 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
698 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
699 #S e1 e2 b2; ncases b2; @; /3/ by refl, conj, I; nqed.
702 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
703 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
706 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
707 #S p q r; napply ext_set; #w; nnormalize; @;
708 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
709 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
713 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
714 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
717 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
718 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
720 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
722 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
723 #S a b; nnormalize; /2/; nqed.
725 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
726 #S A B x H; napply ext_set; #w; @;
727 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
728 *; #wb nwn; @; ##[@2;//] //;
729 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
732 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
733 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
735 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
736 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
738 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
739 #S a b w; nnormalize; *; //; nqed.
741 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
742 #S a; nelim a; // by {};
745 napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
746 nchange in match (•(e1 · ?)) with (?⊙?);
747 ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
748 napply (.=_0 #╪_0 (IH2)); //;
749 ##| #e1 e2 IH1 IH2; napply (?^-1);
750 napply (.=_0 (IH1^-1)╪_0(IH2^-1));
751 nchange in match (•(e1+?)) with (?⊕?);
752 ncases (•e1); ncases (•e2); //]
756 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
757 #S p; ncases p; //; nqed.
760 (* XXX coercion ext_carr non applica *)
761 nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p.
762 #S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
763 *; #w1; *; #w2; *; *; #defw defw1 Hw2;
765 napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
769 (* XXX This seems to be a pattern for equations *)
770 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
771 unification hint 0 ≔ S : Alpha, x,y: re (carr (acarr S));
773 TT ≟ setoid1_of_setoid SS,
775 (*-----------------------------------------*) ⊢
776 eq_re S x y ≡ eq_rel1 T (eq1 TT) x y.
777 (* XXX the previous hint does not work *)
779 (* theorem 16: 1 → 3 *)
780 nlemma odot_dot_aux : ∀S:Alpha.∀e1,e2: pre S.
781 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
782 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
783 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
784 ##[ nchange in match (〈?,true〉⊙?) with 〈?,?〉;
785 nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
786 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
787 napply (.=_1 (# ╪_1 (epsilon_or …))); (* XXX … is too slow if combined with .= *)
788 nchange in match b2'' with b2''; (* XXX some unfoldings happened *)
789 nchange in match b2' with b2';
790 napply (.=_1 (# ╪_1 (cupC …))); napply (.=_1 (cupA …));
791 napply (.=_1 (# ╪_1 (cupA …)^-1)); (* XXX slow, but not because of disamb! *)
792 ncut (𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[
793 napply (?^-1); napply (.=_1 th1^-1); //;##] #E;
794 napply (.=_1 (# ╪_1 (E ╪_1 #)));
796 napply (.=_1 (cup_dotD …) ╪_1 #);
797 napply (.=_1 (# ╪_1 (epsilon_dot …)) ╪_1 #);
799 napply (.=_1 # ╪_1 ((cupC …) ╪_1 #));
800 napply (.=_1 (cupA …)^-1);
801 napply (.=_1 (cupA …)^-1 ╪_1 #);
802 napply (.=_1 (cupA …));
803 nlapply (erase_bull S e2'); #XX;
804 napply (.=_1 (((# ╪_1 (┼_1 ?) )╪_1 #)╪_1 #)); ##[##2: napply XX; ##| ##skip]
806 ##| ncases e2; #e2' b2'; nchange in match (𝐋\p ?) with (?∪?∪?);
807 napply (.=_1 (cupA…));
808 napply (?^-1); nchange in match (𝐋\p 〈?,false〉) with (?∪?);
809 napply (.=_1 ((cup0…)╪_1#)╪_1#);
815 nlemma sub_dot_star :
816 ∀S:Alpha.∀X:Elang S.∀b. (X - ϵ b) · (ext_carr … X)^* ∪ {[]} = (ext_carr … X)^*.
817 #S X b; napply ext_set; #w; @;
818 ##[ *; ##[##2: #defw; @[]; @; //]
819 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
820 @ (w1 :: lw); @; ##[ napply (.=_0 # ╪_0 flx); napply (?^-1); //]
821 @; //; napply (subW … sube);
822 ##| *; #wl; *; #defw Pwl; napply (. (defw^-1 ╪_1 #));
823 nelim wl in Pwl; /2/;
824 #s tl IH; *; #Xs Ptl; ncases s in Xs; ##[ #; napply IH; //] #x xs Xxxs;
825 @; @(x :: xs); @(flatten ? tl); @;
826 ##[ @; ##[ napply #] @; ##[nassumption] ncases b; *; ##]
827 nelim tl in Ptl; ##[ #; @[]; /2/] #w ws IH; *; #Xw Pws; @(w :: ws); @; ##[ napply #]
832 alias symbol "pc" (instance 13) = "cat lang".
833 alias symbol "in_pl" (instance 23) = "in_pl".
834 alias symbol "in_pl" (instance 5) = "in_pl".
835 alias symbol "eclose" (instance 21) = "eclose".
836 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
838 ##[ #a; napply ext_set; #w; @; *; /3/ by or_introl, or_intror;
839 ##| #a; napply ext_set; #w; @; *; /3/ by or_introl; *;
841 nchange in match (•(e1·e2)) with (•e1 ⊙ 〈e2,false〉);
842 napply (.=_1 (odot_dot_aux ?? 〈e2,false〉 IH2));
843 napply (.=_1 (IH1 ╪_1 #) ╪_1 #);
844 napply (.=_1 (cup_dotD …) ╪_1 #);
845 napply (.=_1 (cupA …));
846 napply (.=_1 # ╪_1 ((erase_dot ???)^-1 ╪_1 (cup0 ??)));
847 napply (.=_1 # ╪_1 (cupC…));
848 napply (.=_1 (cupA …)^-1);
851 nchange in match (•(?+?)) with (•e1 ⊕ •e2);
852 napply (.=_1 (oplus_cup …));
853 napply (.=_1 IH1 ╪_1 IH2);
854 napply (.=_1 (cupA …));
855 napply (.=_1 # ╪_1 (# ╪_1 (cupC…)));
856 napply (.=_1 # ╪_1 (cupA ????)^-1);
857 napply (.=_1 # ╪_1 (cupC…));
858 napply (.=_1 (cupA ????)^-1);
859 napply (.=_1 # ╪_1 (erase_plus ???)^-1);
861 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
862 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
863 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
865 nchange in match (𝐋\p (pk ? e')) with (𝐋\p e' · 𝐋 |e'|^* );
866 nrewrite > (erase_bull…e);
867 nrewrite > (erase_star …);
868 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
869 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
870 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
871 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
872 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
873 nrewrite > (cup_dotD…); nrewrite > (cupA…);
874 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
875 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
880 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
881 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
883 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
884 #S e; napply extP; #w; nnormalize; @;
885 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
886 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
887 nrewrite < defw; nrewrite < defw2; @; //; @;//;
888 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
889 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
893 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
894 #S e; @[]; /2/; nqed.
896 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
897 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
899 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
900 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
902 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
903 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
904 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
905 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
909 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
910 #S p; ncases p; #e b; ncases b;
911 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
912 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
913 nchange in ⊢ (??%?) with (?∪?);
914 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
915 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
916 nlapply (bull_cup ? e); #bc;
917 nchange in match (𝐋\p (•e)) in bc with (?∪?);
918 nchange in match b' in bc with b';
919 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
920 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
921 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
922 nrewrite > (sub_dot_star…);
923 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
924 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
925 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
927 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
928 nrewrite < (cup0 ? (𝐋\p e)); //;##]
931 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
936 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
937 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
938 | k e1 ⇒ pk ? (pre_of_re ? e1)].
940 nlemma notFalse : ¬False. @; //; nqed.
942 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
943 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
944 *; #w1; *; #w2; *; *; //; nqed.
946 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
947 #S e; nelim e; ##[##1,2,3: //]
948 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
949 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
950 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
951 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
952 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
953 nrewrite > H1; napply dot0; ##]
956 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
958 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
959 nrewrite < H1; nrewrite < H2; //
960 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
961 nrewrite < H1; nrewrite < H2; //
962 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
967 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
968 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
969 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
972 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
973 #S f g H; nrewrite > H; //; nqed.
976 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
978 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
979 nrewrite > defsnde; #H;
980 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
985 notation > "\move term 90 x term 90 E"
986 non associative with precedence 65 for @{move ? $x $E}.
987 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
991 | ps y ⇒ 〈 `y, false 〉
992 | pp y ⇒ 〈 `y, x == y 〉
993 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
994 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
995 | pk e ⇒ (\move x e)^⊛ ].
996 notation < "\move\shy x\shy E" non associative with precedence 65 for @{'move $x $E}.
997 notation > "\move term 90 x term 90 E" non associative with precedence 65 for @{'move $x $E}.
998 interpretation "move" 'move x E = (move ? x E).
1000 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
1001 interpretation "rmove" 'move x E = (rmove ? x E).
1003 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
1004 #S w abs; ninversion abs; #; ndestruct;
1008 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
1009 #S w abs; ninversion abs; #; ndestruct;
1012 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
1013 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
1018 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
1019 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
1020 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
1021 ncases e1 in H; ncases e2;
1022 ##[##1: *; ##[*; nnormalize; #; ndestruct]
1023 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1024 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1025 ##|##2: *; ##[*; nnormalize; #; ndestruct]
1026 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1027 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1028 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
1029 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1030 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
1031 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
1032 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
1033 #H; ninversion H; nnormalize; #; ndestruct;
1034 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
1035 ##| #r1 r2; *; ##[ *; #defw]
1040 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
1041 #S E; ncases E; #r b; nelim r;
1043 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
1044 #H; ninversion H; #; ndestruct;
1045 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
1046 #H; ninversion H; #; ndestruct;##]
1047 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
1048 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
1049 ##|#a c w; @; nnormalize;
1050 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
1051 #H; ninversion H; #; ndestruct;
1052 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
1053 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
1054 ##|#r1 r2 H1 H2 a w; @;
1055 ##[ #H; ncases (in_move_cat … H);
1056 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
1057 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
1058 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
1067 notation > "x ↦* E" non associative with precedence 65 for @{move_star ? $x $E}.
1068 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
1071 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
1073 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
1075 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
1077 ∀E1,E2: bool × (pre S).
1079 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
1082 ndefinition NAT: decidable.
1086 include "hints_declaration.ma".
1088 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
1089 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1091 ninductive unit: Type[0] ≝ I: unit.
1093 nlet corec foo_nop (b: bool):
1095 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1096 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1098 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1100 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1101 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1105 nlet corec foo (a: unit):
1107 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1108 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1113 [ nnormalize in ⊢ (??%%);
1114 nnormalize in foo: (? → ??%%);
1116 [ nnormalize in ⊢ (??%%); napply foo_nop
1118 [ nnormalize in ⊢ (??%%);
1120 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1121 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1126 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1127 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1128 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1131 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1132 nnormalize in match test3;
1137 (**********************************************************)
1139 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1140 der_z: der S a (z S) (z S)
1141 | der_e: der S a (e S) (z S)
1142 | der_s1: der S a (s S a) (e ?)
1143 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1144 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1145 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1146 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1147 der S a (c ? e1 e2) (c ? e1' e2)
1148 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1149 der S a (o ? e1 e2) (o ? e1' e2').
1151 nlemma eq_rect_CProp0_r:
1152 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1153 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1156 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1158 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1159 (* #S; #r1; #r2; #w; nelim r1
1161 | #H1; #H2; napply (in_c ? []); //
1162 | (* tutti casi assurdi *) *)
1164 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1165 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1166 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1168 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1170 (in_l S [] E1 → in_l S [] E2) →
1171 (in_l S [] E2 → in_l S [] E1) →
1172 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1175 (* serve il lemma dopo? *)
1176 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1177 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1179 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1181 (* IL VICEVERSA NON VALE *)
1182 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1183 (* #S; #w; #E; #H; nelim H
1185 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1189 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1190 #S; #a; #E; #E'; #w; #H; nelim H
1191 [##1,2: #H1; ninversion H1
1192 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1193 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1194 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1195 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1196 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1197 |##6,13: #x; #y; #K; ncases (?:False); /2/
1198 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1199 ##| #H1; ninversion H1
1201 | #X; #Y; #K; ncases (?:False); /2/
1202 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1203 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1204 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1205 | #x; #y; #K; ncases (?:False); /2/
1206 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1207 ##| #H1; #H2; #H3; ninversion H3
1208 [ #_; #K; ncases (?:False); /2/
1209 | #X; #Y; #K; ncases (?:False); /2/
1210 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1211 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1212 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1213 | #x; #y; #K; ncases (?:False); /2/
1214 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1215 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;