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 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 S;
177 MM ≟ mk_unary_morphism ??
178 (λA:re S.mk_unary_morphism ?? (λB.A · B) (prop1 ?? (c_is_morph S A)))
179 (prop1 ?? (c_is_morph S)),
181 (*--------------------------------------------------------------------------*) ⊢
182 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ A · B.
184 nlemma o_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
185 #A; napply (mk_binary_morphism … (λs1,s2:re A. s1 + s2));
187 ##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
188 ##|#x a' b b'; ncases a'; /2/ by conj;
189 ##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
190 ##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
193 unification hint 0 ≔ S:Alpha, A,B:re S;
194 MM ≟ mk_unary_morphism ??
195 (λA:re S.mk_unary_morphism ?? (λB.A + B) (prop1 ?? (o_is_morph S A)))
196 (prop1 ?? (o_is_morph S)),
198 (*--------------------------------------------------------------------------*) ⊢
199 fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ A + B.
201 (* end setoids support for re *)
203 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
204 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
206 interpretation "subset construction with type" 'comprehension t \eta.x =
209 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
210 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
211 interpretation "cat lang" 'pc a b = (cat ? a b).
214 nlemma cat_is_morph : ∀A:setoid. (lang A) ⇒_1 (lang A) ⇒_1 (lang A).
215 #X; napply (mk_binary_morphism1 … (λA,B:lang X.A · B));
216 #A1 A2 B1 B2 EA EB; napply ext_set; #x;
217 ncut (∀y,x:list X.(x ∈ B1) =_1 (x ∈ B2)); ##[
218 #_; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h1 | napply h2] ##] #YY;
219 ncut (∀x,y:list X.(x ∈ A1) =_1 (x ∈ A2)); ##[
220 #y; #y; ncases EA; ncases EB; #h1 h2 h3 h4; @; ##[ napply h3 | napply h4] ##] #XX;
221 napply (.=_1 (∑w1, w2. XX w1 w2/ E ; (# ╪_1 E) ╪_1 #));
222 napply (.=_1 (∑w1, w2. YY w1 w2/ E ; # ╪_1 E)); //;
225 nlemma cat_is_ext: ∀A:setoid. (Elang A) → (Elang A) → (Elang A).
226 #S A B; @ (ext_carr … A · ext_carr … B); (* XXX coercion ext_carr che non funge *)
228 ncut (∀w1,w2.(x == w1@w2) = (y == w1@w2)); ##[
229 #w1 w2; @; #H; ##[ napply (.= Exy^-1) | napply (.= Exy)] // ]
231 ##[ napply (. (∑w1,w2. (E w1 w2)^-1 / E ; (E ╪_1 #) ╪_1 #)); napply H;
232 ##| napply (. (∑w1,w2. E w1 w2 / E ; (E ╪_1 #) ╪_1 #)); napply H ]
235 alias symbol "hint_decl" = "hint_decl_Type1".
236 unification hint 0 ≔ A : setoid, B,C : Elang A;
238 R ≟ mk_ext_powerclass ?
239 (ext_carr ? B · ext_carr ? C) (ext_prop ? (cat_is_ext ? B C))
240 (*--------------------------------------------------------------------*) ⊢
241 ext_carr AA R ≡ cat A (ext_carr AA B) (ext_carr AA C).
243 unification hint 0 ≔ S:setoid, A,B:lang S;
244 T ≟ powerclass_setoid (list S),
245 TT ≟ unary_morphism1_setoid1 T T,
246 MM ≟ mk_unary_morphism1 T TT
248 mk_unary_morphism1 T T
249 (λB:lang S.A · B) (prop11 T T (cat_is_morph S A)))
250 (prop11 T TT (cat_is_morph S))
251 (*--------------------------------------------------------------------------*) ⊢
252 fun11 T T (fun11 T (unary_morphism1_setoid1 T T) MM A) B ≡ cat S A B.
254 nlemma cat_is_ext_morph:∀A:setoid.(Elang A) ⇒_1 (Elang A) ⇒_1 (Elang A).
255 #A; napply (mk_binary_morphism1 … (cat_is_ext …));
256 #x1 x2 y1 y2 Ex Ey; napply (prop11 … (cat_is_morph A)); nassumption.
259 unification hint 1 ≔ AA : setoid, B,C : Elang AA;
261 T ≟ ext_powerclass_setoid (list AA),
262 TT ≟ unary_morphism1_setoid1 T T,
263 R ≟ mk_unary_morphism1 ??
265 mk_unary_morphism1 ??
267 mk_ext_powerclass (list AA) (ext_carr ? S · ext_carr ? S')
268 (ext_prop (list AA) (cat_is_ext AA S S')))
269 (prop11 ?? (cat_is_ext_morph AA S)))
270 (prop11 ?? (cat_is_ext_morph AA)),
273 (*------------------------------------------------------*) ⊢
274 ext_carr AAS (fun11 T T (fun11 T TT R B) C) ≡ cat AA BB CC.
276 (* end hints for cat *)
278 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
279 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
280 interpretation "star lang" 'pk l = (star ? l).
282 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
283 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
288 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
289 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
291 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
292 interpretation "in_l" 'L_re E = (L_re ? E).
294 (* support for 𝐋 as an extensional set *)
295 ndefinition L_re_is_ext : ∀S:Alpha.∀r:re S.Elang S.
296 #S r; @(𝐋 r); #w1 w2 E; nelim r;
297 ##[ ##1,2: /2/; @; #defw1; napply (.=_0 (defw1 : [ ] = ?)); //; napply (?^-1); //;
298 ##| #x; @; #defw1; napply (.=_0 (defw1 : [x] = ?)); //; napply (?^-1); //;
299 ##| #e1 e2 H1 H2; (* not shure I shoud Inline *)
300 @; *; #s1; *; #s2; *; *; #defw1 s1L1 s2L2;
301 ##[ nlapply (trans … E^-1 defw1); #defw2;
302 ##| nlapply (trans … E defw1); #defw2; ##] @s1; @s2; /3/;
303 ##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
304 ##| #e H; @; *; #l; *; #defw1 Pl; @l; @; //; napply (.=_1 defw1); /2/; ##]
307 unification hint 0 ≔ S : Alpha,e : re S;
309 X ≟ mk_ext_powerclass SS (𝐋 e) (ext_prop SS (L_re_is_ext S e))
310 (*-----------------------------------------------------------------*)⊢
311 ext_carr SS X ≡ L_re S e.
313 nlemma L_re_is_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 Ω^(list A).
314 #A; @; ##[ napply (λr:re A.𝐋 r); ##] #r1; nelim r1;
315 ##[##1,2: #r2; ncases r2; //; ##[##1,6: *|##2,7,5,12,10: #a; *|##3,4,8,9: #a1 a2; *]
316 ##|#x r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##6: #a; *] #y E; @; #z defz;
317 ncases z in defz; ##[##1,3: *] #zh ztl; ncases ztl; ##[##2,4: #d dl; *; #_; *]
318 *; #defx; #_; @; //; napply (?^-1); napply (.= defx^-1); //; napply (?^-1); //;
319 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##5: #a1 a2; *|##3,6: #a1; *]
320 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
321 nchange in match (𝐋 (e1 · e2)) with (?·?);
322 napply (.=_1 (H1 ╪_1 H2)); //;
323 ##|#e1 e2 IH1 IH2 r2; ncases r2; ##[##1,2: *|##4: #a1 a2; *|##3,6: #a1; *]
324 #f1 f2; *; #E1 E2; nlapply (IH2 … E2); nlapply (IH1 … E1); #H1 H2;
325 napply (.=_1 H1╪_1H2); //;
326 ##|#r IH r2; ncases r2; ##[##1,2: *|##4,5: #a1 a2; *|##3: #a1; *]
327 #e; #defe; nlapply (IH e defe); #H;
328 @; #x; *; #wl; *; #defx Px; @wl; @; //; nelim wl in Px; //; #l ls IH; *; #lr Pr;
329 ##[ nlapply (ifs' … H … lr) | nlapply (ifs' … H^-1 … lr) ] #le;
330 @; ##[##1,3: nassumption] /2/; ##]
333 unification hint 0 ≔ A:Alpha, a:re A;
334 T ≟ setoid1_of_setoid (RE A),
336 T2 ≟ powerclass_setoid T1,
337 MM ≟ mk_unary_morphism1 ??
338 (λa:setoid1_of_setoid (RE A).𝐋 a) (prop11 ?? (L_re_is_morph A))
339 (*--------------------------------------------------------------------------*) ⊢
340 fun11 T T2 MM a ≡ 𝐋 a.
342 nlemma L_re_is_ext_morph:∀A:Alpha.(setoid1_of_setoid (re A)) ⇒_1 𝛀^(list A).
343 #A; @; ##[ #a; napply (L_re_is_ext ? a); ##] #a b E; @; #x H;
344 ##[ nchange with (x ∈ 𝐋 b); napply (. #╪_1?);
345 ##[ nchange with (𝐋 b = ?); napply (.= ┼_1 E^-1); napply #| ##skip]
347 ##| nchange with (x ∈ 𝐋 a); napply (. #╪_1?);
348 ##[ nchange with (𝐋 a = ?); napply (.= ┼_1 E); napply #| ##skip]
352 unification hint 1 ≔ AA : Alpha, a: re AA;
353 T ≟ RE AA, T1 ≟ LIST AA, TT ≟ ext_powerclass_setoid T1,
354 R ≟ mk_unary_morphism1 ??
355 (λa:setoid1_of_setoid T.
356 mk_ext_powerclass ? (𝐋 a) (ext_prop ? (L_re_is_ext AA a)))
357 (prop11 ?? (L_re_is_ext_morph AA))
358 (*------------------------------------------------------*) ⊢
359 ext_carr T1 (fun11 (setoid1_of_setoid T) TT R a) ≡ L_re AA a.
361 (* end support for 𝐋 as an extensional set *)
363 ninductive pitem (S: Type[0]) : Type[0] ≝
368 | pc: pitem S → pitem S → pitem S
369 | po: pitem S → pitem S → pitem S
370 | pk: pitem S → pitem S.
372 interpretation "pstar" 'pk a = (pk ? a).
373 interpretation "por" 'plus a b = (po ? a b).
374 interpretation "pcat" 'pc a b = (pc ? a b).
375 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
376 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
377 interpretation "ppatom" 'pp a = (pp ? a).
378 (* to get rid of \middot *)
379 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
380 interpretation "patom" 'ps a = (ps ? a).
381 interpretation "pepsilon" 'epsilon = (pe ?).
382 interpretation "pempty" 'empty_r = (pz ?).
384 (* setoids for pitem *)
385 nlet rec eq_pitem (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝
387 [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
388 | pe ⇒ match p2 with [ pe ⇒ True | _ ⇒ False]
389 | ps x ⇒ match p2 with [ ps y ⇒ x = y | _ ⇒ False]
390 | pp x ⇒ match p2 with [ pp y ⇒ x = y | _ ⇒ False]
391 | pc a1 a2 ⇒ match p2 with [ pc b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
392 | po a1 a2 ⇒ match p2 with [ po b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
393 | pk a ⇒ match p2 with [ pk b ⇒ eq_pitem ? a b | _ ⇒ False]].
395 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b).
397 nlemma PITEM : ∀S:Alpha.setoid.
398 #S; @(pitem S); @(eq_pitem …);
399 ##[ #p; nelim p; //; nnormalize; #; @; //;
400 ##| #p; nelim p; ##[##1,2: #y; ncases y; //; ##|##3,4: #x y; ncases y; //; #; napply (?^-1); nassumption;
401 ##|##5,6: #r1 r2 H1 H2 p2; ncases p2; //; #s1 s2; nnormalize; *; #; @; /2/;
402 ##| #r H y; ncases y; //; nnormalize; /2/;##]
404 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
405 ##| ##3,4: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
406 ##| ##5,6: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
407 ##[##1,2,5,6,7,8,4,10: #; ncases (?:False); //;##]
408 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
409 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3,4: #; ncases (?:False); //]
413 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
414 unification hint 0 ≔ SS:Alpha;
417 P1 ≟ refl ? (eq0 (PITEM SS)),
418 P2 ≟ sym ? (eq0 (PITEM SS)),
419 P3 ≟ trans ? (eq0 (PITEM SS)),
420 R ≟ mk_setoid (pitem S)
421 (mk_equivalence_relation (pitem A) (eq_pitem SS) P1 P2 P3)
422 (*-----------------------------------------------------------------*)⊢
425 unification hint 0 ≔ S:Alpha,a,b:pitem S;
426 R ≟ PITEM S, L ≟ (pitem S)
427 (* -------------------------------------------- *) ⊢
428 eq_pitem S a b ≡ eq_rel L (eq0 R) a b.
430 (* end setoids for pitem *)
432 ndefinition pre ≝ λS.pitem S × bool.
434 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
435 interpretation "fst" 'fst x = (fst ? ? x).
436 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
437 interpretation "snd" 'snd x = (snd ? ? x).
439 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
440 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
446 | pc E1 E2 ⇒ (|E1| · |E2|)
447 | po E1 E2 ⇒ (|E1| + |E2|)
450 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
451 interpretation "forget" 'forget a = (forget ? a).
453 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
454 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
460 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
461 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
462 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
463 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
464 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
465 interpretation "in_pl" 'L_pi E = (L_pi ? E).
467 (* set support for 𝐋\p *)
468 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
469 #S r; @(𝐋\p r); #w1 w2 E; nelim r;
472 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
473 napply ((.=_0 H) E^-1);
476 ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
477 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
478 napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #);
479 ##| #e1 e2 H1 H2; napply (H1‡H2);
481 ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
482 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
483 napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#);
487 unification hint 0 ≔ S : Alpha,e : pitem S;
489 X ≟ (mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e)))
490 (*-----------------------------------------------------------------*)⊢
491 ext_carr SS X ≡ 𝐋\p e.
493 (* end set support for 𝐋\p *)
495 ndefinition epsilon ≝
496 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
498 interpretation "epsilon" 'epsilon = (epsilon ?).
499 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
500 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
502 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
504 interpretation "L_pr" 'L_pi E = (L_pr ? E).
506 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
507 #S w1; ncases w1; //. nqed.
509 (* lemma 12 *) (* XXX: a case where Leibnitz equality could be exploited for H *)
510 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
511 #S r; ncases r; #e b; @; ##[##2: #H; ncases b in H; ##[##2:*] #; @2; /2/; ##]
512 ncases b; //; *; ##[##2:*] nelim e;
513 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
514 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
515 ##| #r1 r2 H1 H2; *; /2/ by {}]
516 *; #w1; *; #w2; *; *;
517 ##[ #defw1 H1 foo; napply H;
518 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
520 ##| #defw1 H1 foo; napply H;
521 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
526 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
527 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
528 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
529 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
530 napply (. defw1^-1╪_1#);
532 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
533 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
534 nlapply (append_eq_nil ??? abs); # defw1; #;
535 napply (. defw1^-1╪_1#);
539 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
540 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
541 interpretation "oplus" 'oplus a b = (lo ? a b).
543 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
544 match a with [ mk_pair e1 b1 ⇒
546 [ false ⇒ 〈e1 · \fst b, \snd b〉
547 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
549 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
550 interpretation "lc" 'lc op a b = (lc ? op a b).
551 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
553 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
554 match a with [ mk_pair e1 b1 ⇒
556 [ false ⇒ 〈e1^*, false〉
557 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
559 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
560 interpretation "lk" 'lk op a = (lk ? op a).
561 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
563 notation > "•" non associative with precedence 60 for @{eclose ?}.
564 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
568 | ps x ⇒ 〈 `.x, false 〉
569 | pp x ⇒ 〈 `.x, false 〉
570 | po E1 E2 ⇒ •E1 ⊕ •E2
571 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
572 | pk E ⇒ 〈(\fst (•E))^*,true〉].
573 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
574 interpretation "eclose" 'eclose x = (eclose ? x).
575 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
577 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
578 interpretation "reclose" 'eclose x = (reclose ? x).
580 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
581 #S b1 b2; ncases b1; ncases b2;
582 nchange in match (true || true) with true;
583 nchange in match (true || false) with true;
584 nchange in match (ϵ true) with {[]};
585 nchange in match (ϵ false) with ∅;
586 ##[##1,4: napply ((cupID…)^-1);
587 ##| napply ((cup0 ? {[]})^-1);
588 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
592 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
593 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
594 napply (.=_1 #╪_1 (epsilon_or ???));
595 napply (.=_1 (cupA…)^-1);
596 napply (.=_1 (cupA…)╪_1#);
597 napply (.=_1 (#╪_1(cupC…))╪_1#);
598 napply (.=_1 (cupA…)^-1╪_1#);
599 napply (.=_1 (cupA…));
604 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
605 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
606 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
607 #S e1 e2 b2; ncases b2; @; /3/ by refl, conj, I; nqed.
610 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
611 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
614 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
615 #S p q r; napply ext_set; #w; nnormalize; @;
616 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
617 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
621 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
622 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
625 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
626 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
628 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
630 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
631 #S a b; nnormalize; /2/; nqed.
633 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
634 #S A B x H; napply ext_set; #w; @;
635 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
636 *; #wb nwn; @; ##[@2;//] //;
637 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
640 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
641 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
643 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
644 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
646 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
647 #S a b w; nnormalize; *; //; nqed.
649 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
650 #S a; nelim a; // by {};
653 napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
654 nchange in match (•(e1 · ?)) with (?⊙?);
655 ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
656 napply (.=_0 #╪_0 (IH2)); //;
657 ##| #e1 e2 IH1 IH2; napply (?^-1);
658 napply (.=_0 (IH1^-1)╪_0(IH2^-1));
659 nchange in match (•(e1+?)) with (?⊕?);
660 ncases (•e1); ncases (•e2); //]
664 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
665 #S p; ncases p; //; nqed.
668 (* XXX coercion ext_carr non applica *)
669 nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p.
670 #S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
671 *; #w1; *; #w2; *; *; #defw defw1 Hw2;
673 napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
677 (* XXX This seems to be a pattern for equations *)
678 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
679 unification hint 0 ≔ S : Alpha, x,y: re S;
681 TT ≟ setoid1_of_setoid SS,
683 (*-----------------------------------------*) ⊢
684 eq_re S x y ≡ eq_rel1 T (eq1 TT) x y.
685 (* XXX the previous hint does not work *)
687 (* theorem 16: 1 → 3 *)
688 nlemma odot_dot_aux : ∀S:Alpha.∀e1,e2: pre S.
689 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
690 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
691 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
692 ##[ nchange in match (〈?,true〉⊙?) with 〈?,?〉;
693 nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
694 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
695 napply (.=_1 (# ╪_1 (epsilon_or …))); (* XXX … is too slow if combined with .= *)
696 nchange in match b2'' with b2''; (* XXX some unfoldings happened *)
697 nchange in match b2' with b2';
698 napply (.=_1 (# ╪_1 (cupC …))); napply (.=_1 (cupA …));
699 napply (.=_1 (# ╪_1 (cupA …)^-1)); (* XXX slow, but not because of disamb! *)
700 ncut (𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[
701 napply (?^-1); napply (.=_1 th1^-1); //;##] #E;
702 napply (.=_1 (# ╪_1 (E ╪_1 #)));
704 napply (.=_1 (cup_dotD …) ╪_1 #);
705 napply (.=_1 (# ╪_1 (epsilon_dot …)) ╪_1 #);
707 napply (.=_1 # ╪_1 ((cupC …) ╪_1 #));
708 napply (.=_1 (cupA …)^-1);
709 napply (.=_1 (cupA …)^-1 ╪_1 #);
710 napply (.=_1 (cupA …));
711 nlapply (erase_bull S e2'); #XX;
712 napply (.=_1 (((# ╪_1 (┼_1 ?) )╪_1 #)╪_1 #)); ##[##2: napply XX; ##| ##skip]
714 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
715 nchange in match (𝐋\p ?) with (?∪?);
716 nchange in match (𝐋\p (e1'·?)) with (?∪?);
717 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
719 nrewrite > (cupA…); //;##]
722 nlemma sub_dot_star :
723 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
724 #S X b; napply extP; #w; @;
725 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
726 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
727 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
728 @; //; napply (subW … sube);
729 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
730 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
731 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
732 @; ncases b in H1; #H1;
733 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
734 nrewrite > (associative_append ? w' w1 w2);
735 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
736 ##| ncases w' in Pw';
737 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
738 ##| #x xs Px; @(x::xs); @(w1@w2);
739 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
741 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
742 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
743 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
744 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
746 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
747 @; //; @; //; @; *;##]##]##]
751 alias symbol "pc" (instance 13) = "cat lang".
752 alias symbol "in_pl" (instance 23) = "in_pl".
753 alias symbol "in_pl" (instance 5) = "in_pl".
754 alias symbol "eclose" (instance 21) = "eclose".
755 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
757 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
758 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
760 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
761 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
762 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
763 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
764 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
765 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
767 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
768 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
769 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
770 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
771 nrewrite < (erase_plus …); //.
772 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
773 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
774 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
775 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
776 nrewrite > (erase_bull…e);
777 nrewrite > (erase_star …);
778 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
779 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
780 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
781 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
782 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
783 nrewrite > (cup_dotD…); nrewrite > (cupA…);
784 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
785 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
790 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
791 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
793 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
794 #S e; napply extP; #w; nnormalize; @;
795 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
796 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
797 nrewrite < defw; nrewrite < defw2; @; //; @;//;
798 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
799 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
803 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
804 #S e; @[]; /2/; nqed.
806 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
807 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
809 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
810 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
812 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
813 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
814 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
815 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
819 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
820 #S p; ncases p; #e b; ncases b;
821 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
822 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
823 nchange in ⊢ (??%?) with (?∪?);
824 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
825 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
826 nlapply (bull_cup ? e); #bc;
827 nchange in match (𝐋\p (•e)) in bc with (?∪?);
828 nchange in match b' in bc with b';
829 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
830 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
831 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
832 nrewrite > (sub_dot_star…);
833 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
834 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
835 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
837 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
838 nrewrite < (cup0 ? (𝐋\p e)); //;##]
841 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
846 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
847 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
848 | k e1 ⇒ pk ? (pre_of_re ? e1)].
850 nlemma notFalse : ¬False. @; //; nqed.
852 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
853 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
854 *; #w1; *; #w2; *; *; //; nqed.
856 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
857 #S e; nelim e; ##[##1,2,3: //]
858 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
859 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
860 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
861 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
862 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
863 nrewrite > H1; napply dot0; ##]
866 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
868 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
869 nrewrite < H1; nrewrite < H2; //
870 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
871 nrewrite < H1; nrewrite < H2; //
872 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
877 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
878 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
879 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
882 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
883 #S f g H; nrewrite > H; //; nqed.
886 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
888 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
889 nrewrite > defsnde; #H;
890 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
895 notation > "\move term 90 x term 90 E"
896 non associative with precedence 60 for @{move ? $x $E}.
897 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
901 | ps y ⇒ 〈 `y, false 〉
902 | pp y ⇒ 〈 `y, x == y 〉
903 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
904 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
905 | pk e ⇒ (\move x e)^⊛ ].
906 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
907 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
908 interpretation "move" 'move x E = (move ? x E).
910 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
911 interpretation "rmove" 'move x E = (rmove ? x E).
913 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
914 #S w abs; ninversion abs; #; ndestruct;
918 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
919 #S w abs; ninversion abs; #; ndestruct;
922 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
923 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
928 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
929 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
930 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
931 ncases e1 in H; ncases e2;
932 ##[##1: *; ##[*; nnormalize; #; ndestruct]
933 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
934 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
935 ##|##2: *; ##[*; nnormalize; #; ndestruct]
936 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
937 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
938 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
939 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
940 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
941 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
942 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
943 #H; ninversion H; nnormalize; #; ndestruct;
944 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
945 ##| #r1 r2; *; ##[ *; #defw]
950 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
951 #S E; ncases E; #r b; nelim r;
953 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
954 #H; ninversion H; #; ndestruct;
955 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
956 #H; ninversion H; #; ndestruct;##]
957 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
958 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
959 ##|#a c w; @; nnormalize;
960 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
961 #H; ninversion H; #; ndestruct;
962 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
963 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
964 ##|#r1 r2 H1 H2 a w; @;
965 ##[ #H; ncases (in_move_cat … H);
966 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
967 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
968 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
977 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
978 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
981 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
983 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
985 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
987 ∀E1,E2: bool × (pre S).
989 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
992 ndefinition NAT: decidable.
996 include "hints_declaration.ma".
998 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
999 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1001 ninductive unit: Type[0] ≝ I: unit.
1003 nlet corec foo_nop (b: bool):
1005 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1006 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1008 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1010 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1011 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1015 nlet corec foo (a: unit):
1017 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1018 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1023 [ nnormalize in ⊢ (??%%);
1024 nnormalize in foo: (? → ??%%);
1026 [ nnormalize in ⊢ (??%%); napply foo_nop
1028 [ nnormalize in ⊢ (??%%);
1030 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1031 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1036 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1037 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1038 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1041 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1042 nnormalize in match test3;
1047 (**********************************************************)
1049 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1050 der_z: der S a (z S) (z S)
1051 | der_e: der S a (e S) (z S)
1052 | der_s1: der S a (s S a) (e ?)
1053 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1054 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1055 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1056 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1057 der S a (c ? e1 e2) (c ? e1' e2)
1058 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1059 der S a (o ? e1 e2) (o ? e1' e2').
1061 nlemma eq_rect_CProp0_r:
1062 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1063 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1066 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1068 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1069 (* #S; #r1; #r2; #w; nelim r1
1071 | #H1; #H2; napply (in_c ? []); //
1072 | (* tutti casi assurdi *) *)
1074 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1075 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1076 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1078 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1080 (in_l S [] E1 → in_l S [] E2) →
1081 (in_l S [] E2 → in_l S [] E1) →
1082 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1085 (* serve il lemma dopo? *)
1086 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1087 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1089 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1091 (* IL VICEVERSA NON VALE *)
1092 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1093 (* #S; #w; #E; #H; nelim H
1095 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1099 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1100 #S; #a; #E; #E'; #w; #H; nelim H
1101 [##1,2: #H1; ninversion H1
1102 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1103 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1104 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1105 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1106 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1107 |##6,13: #x; #y; #K; ncases (?:False); /2/
1108 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1109 ##| #H1; ninversion H1
1111 | #X; #Y; #K; ncases (?:False); /2/
1112 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1113 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1114 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1115 | #x; #y; #K; ncases (?:False); /2/
1116 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1117 ##| #H1; #H2; #H3; ninversion H3
1118 [ #_; #K; ncases (?:False); /2/
1119 | #X; #Y; #K; ncases (?:False); /2/
1120 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1121 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1122 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1123 | #x; #y; #K; ncases (?:False); /2/
1124 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1125 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;