]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/nlibrary/re/re-setoids.ma
Stuff moved from old Matita.
[helm.git] / matita / matita / nlibrary / re / re-setoids.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "datatypes/pairs-setoids.ma".
16 include "datatypes/bool-setoids.ma".
17 include "datatypes/list-setoids.ma".
18 include "sets/sets.ma".
19
20 (*
21 ninductive Admit : CProp[0] ≝ .
22 naxiom admit : Admit.
23 *)
24
25 (* XXX move somewere else *)
26 ndefinition if': ∀A,B:CPROP. A = B → A → B.
27 #A B; *; /2/. nqed.
28
29 ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ? (eq1 CPROP) ?? to ∀_:?.?.
30
31 ndefinition ifs': ∀S.∀A,B:Ω^S. A = B → ∀x. x ∈ A → x ∈ B.
32 #S A B; *; /2/. nqed.
33
34 ncoercion ifs : ∀S.∀A,B:Ω^S. ∀p:A = B.∀x. x ∈ A → x ∈ B ≝ ifs' on _p : eq_rel1 ? (eq1 (powerclass_setoid ?))?? to ∀_:?.?.
35
36 (* XXX move to list-setoids-theory.ma *)
37
38 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
39 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
40
41 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z. 
42
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.
45
46 (* end move to list *)
47
48
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
52 *)
53 interpretation "iff" 'iff a b = (iff a b).  
54
55 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ erefl: eq A x x.
56
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.
60 nqed.
61
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.
65 nqed.
66
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.
70 nqed.
71
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.
75 nqed.
76
77 nrecord Alpha : Type[1] ≝ { 
78    acarr :> setoid;
79    eqb: acarr → acarr → bool; 
80    eqb_true: ∀x,y. (eqb x y = true) = (x = y)
81 }.
82  
83 interpretation "eqb" 'eq_low a b = (eqb ? a b).
84 (* end alpha *)
85
86 (* re *)
87 ninductive re (S: Type[0]) : Type[0] ≝
88    z: re S
89  | e: re S
90  | s: S → re S
91  | c: re S → re S → re S
92  | o: re S → re S → re S
93  | k: re S → re S.
94  
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).
99            
100 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
101 interpretation "cat" 'pc a b = (c ? a b).
102
103 (* to get rid of \middot *)
104 ncoercion c  : ∀S.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
105
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).
109
110 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
111 interpretation "epsilon" 'epsilon = (e ?).
112
113 notation "0" non associative with precedence 90 for @{ 'empty_r }.
114 interpretation "empty" 'empty_r = (z ?).
115
116 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
117 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(LIST $S) }.
118  
119 (* setoid support for re *)
120  
121 nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝ 
122   match a with
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]].
129   
130 interpretation "eq_re" 'eq_low a b = (eq_re ? a b).
131
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/;##]
139 ##| #p1; nelim p1;
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); //]
146         #r2 r3; /3/; ##]##]
147 nqed.
148
149 unification hint 0 ≔ A : Alpha;
150   S ≟ acarr A,
151   T ≟ carr S,
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 (*-----------------------------------------------------------------------*) ⊢
157      carr X ≡ re T.
158
159 unification hint 0 ≔ A:Alpha, a,b:re (carr (acarr A));
160    R ≟ eq0 (RE A),
161    L ≟ re (carr (acarr A))
162 (* -------------------------------------------- *) ⊢
163    eq_re A a b ≡ eq_rel L R a b.
164
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));
167 #a; nelim a; 
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; ##]
172 nqed.
173
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));
177     SS ≟ carr (acarr S),
178     MM ≟ mk_unary_morphism ?? (λA.
179            mk_unary_morphism ?? 
180              (λB.A · B) (prop1 ?? (fun1 ?? (c_is_morph S) A)))
181            (prop1 ?? (c_is_morph S)),
182     T ≟ RE S
183 (*--------------------------------------------------------------------------*) ⊢
184    fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ c SS A B.
185
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));
188 #a; nelim a; 
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; ##]
193 nqed.
194
195 unification hint 0 ≔ S:Alpha, A,B:re (carr (acarr S));
196     SS ≟ carr (acarr S),
197     MM ≟ mk_unary_morphism ?? (λA.
198            mk_unary_morphism ?? 
199              (λB.A + B) (prop1 ?? (fun1 ?? (o_is_morph S) A)))
200            (prop1 ?? (o_is_morph S)),
201     T ≟ RE S
202 (*--------------------------------------------------------------------------*) ⊢
203    fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ o SS A B.
204
205 (* end setoids support for re *)
206
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 ].
209
210 interpretation "subset construction with type" 'comprehension t \eta.x = 
211   (mk_powerclass t x).
212
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).
216
217 (* hints for cat *)
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)); //;
227 nqed.
228
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 *)
231 #x y Exy;
232 ncut (∀w1,w2.(x == w1@w2) = (y == w1@w2)); ##[
233   #w1 w2; @; #H; ##[ napply (.= Exy^-1) | napply (.= Exy)] // ] 
234 #E; @; #H;
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 ]
237 nqed.
238
239 alias symbol "hint_decl" = "hint_decl_Type1".
240 unification hint 0 ≔ A : setoid, B,C : Elang A;
241    AA ≟ LIST A,
242    BB ≟ ext_carr AA B,
243    CC ≟ ext_carr AA C,
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.
249     
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)
253           (λA:lang (carr S).
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.
260    
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.
264 nqed.
265
266 unification hint 1 ≔ AA : setoid, B,C : Elang AA;
267   AAS ≟ LIST 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)),
276    BB ≟ ext_carr ? B,
277    CC ≟ ext_carr ? C
278 (*------------------------------------------------------*) ⊢
279    ext_carr AAS (fun11 T T (fun11 T (unary_morphism1_setoid1 T T) R B) C) ≡ cat AA BB CC.
280
281 (* end hints for cat *)
282
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).
286
287 (* hints for star *)
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.
291
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.
295
296 alias symbol "hint_decl" = "hint_decl_Type1".
297 unification hint 0 ≔ A : setoid, B :  Elang A;
298    AA ≟ LIST A,
299    BB ≟ ext_carr AA B,
300    R ≟ mk_ext_powerclass ? 
301          ((ext_carr ? B)^* ) (ext_prop ? (star_is_ext ? B))
302 (*--------------------------------------------------------------------*)  ⊢
303     ext_carr AA R ≡ star A BB.
304     
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.
311    
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.
315 nqed.
316
317 unification hint 1 ≔ AA : setoid, B : Elang AA;
318   AAS ≟ LIST AA,
319   T ≟ ext_powerclass_setoid AAS,
320   R ≟ mk_unary_morphism1 T T
321             (λS:Elang AA.
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)),
325    BB ≟ ext_carr ? B
326 (*------------------------------------------------------*) ⊢
327    ext_carr AAS (fun11 T T R B) ≡ star AA BB.
328
329 (* end hints for star *)
330
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 ≝ 
333 match r with
334 [ z ⇒ ∅
335 | e ⇒ { [ ] }
336 | s x ⇒ { [x] }
337 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
338 | o r1 r2 ⇒  𝐋 r1 ∪ 𝐋 r2
339 | k r1 ⇒ (𝐋 r1) ^*].
340 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
341 interpretation "in_l" 'L_re E = (L_re ? E).
342
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/; ##]
354 nqed.
355
356 unification hint 0 ≔ S : Alpha,e : re (carr (acarr S)); 
357   SS ≟ LIST (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.
361
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/; ##]
380 nqed.
381
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.
389    
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)]
396 nqed.
397             
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.
407
408 (* end support for 𝐋 as an extensional set *)
409
410 ninductive pitem (S: Type[0]) : Type[0] ≝
411    pz: pitem S
412  | pe: pitem S
413  | ps: S → pitem S
414  | pp: S → pitem S
415  | pc: pitem S → pitem S → pitem S
416  | po: pitem S → pitem S → pitem S
417  | pk: pitem S → pitem S.
418  
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 ?). 
430  
431 (* setoids for pitem *)
432 nlet rec eq_pitem  (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝ 
433  match p1 with
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]].
441  
442 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b). 
443  
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/;##]
450 ##| #x; nelim x; 
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); //]
457         #r2 r3; /3/; ##]##]
458 nqed.
459
460 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
461 unification hint 0 ≔ SS:Alpha;
462     S ≟ acarr SS,
463     A ≟ carr S,
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 (*-----------------------------------------------------------------*)⊢
470     carr R ≡ pitem A.
471     
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.    
476     
477 (* end setoids for pitem *)
478
479 ndefinition pre ≝ λS.pitem S × bool.
480
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).
485
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 ≝
488  match l with
489   [ pz ⇒ 0
490   | pe ⇒ ϵ
491   | ps x ⇒ `x
492   | pp x ⇒ `x
493   | pc E1 E2 ⇒ (|E1| · |E2|)
494   | po E1 E2 ⇒ (|E1| + |E2|)
495   | pk E ⇒ |E|^* ].
496   
497 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
498 interpretation "forget" 'forget a = (forget ? a).
499
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 ≝ 
502 match r with
503 [ pz ⇒ ∅
504 | pe ⇒ ∅
505 | ps _ ⇒ ∅
506 | pp x ⇒ { [x] }
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).
513
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; 
517 ##[ ##1,2: /2/;
518 ##| #x; @; *;
519 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
520     napply ((.=_0 H) E^-1);
521 ##| #e1 e2 H1 H2;
522     napply (.= (#‡H2));
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); 
527 ##| #e H; 
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#); 
531 ##]
532 nqed.
533
534 unification hint 0 ≔ S : Alpha,e : pitem (carr (acarr S)); 
535   SS ≟ LIST (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.
539
540 (* end set support for 𝐋\p *)  
541   
542 ndefinition epsilon ≝ 
543   λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
544
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).
548
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.
552
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/;
557 nqed.
558
559 alias symbol "hint_decl" = "hint_decl_Type1".
560 unification hint 0 ≔ A : Alpha, B :  bool;
561    AA ≟ LIST (acarr A),
562    R ≟ mk_ext_powerclass ? 
563          (ϵ B) (ext_prop ? (epsilon_is_ext ? B))
564 (*--------------------------------------------------------------------*)  ⊢
565     ext_carr AA R ≡ epsilon A B.
566     
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.
574    
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.
578 nqed.
579
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
585             (λS.
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.
591
592 (* end hints for epsilon *)
593
594 ndefinition L_pr ≝ λS : Alpha.λp:pre S.  𝐋\p\ (\fst p) ∪ ϵ (\snd p).
595   
596 interpretation "L_pr" 'L_pi E = (L_pr ? E).
597
598 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
599 #S w1; ncases w1; //. nqed.
600   
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#);
611     nassumption; 
612 ##| #defw1 H1 foo; napply H;
613     napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
614     nassumption; 
615 ##]
616 nqed.
617
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#);
623     nassumption;
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#);
628     nassumption;##]
629 nqed.
630
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 60 for @{'oplus $a $b}.
633 interpretation "oplus" 'oplus a b = (lo ? a b).
634
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 ⇒
637    match b1 with 
638    [ false ⇒ 〈e1 · \fst b, \snd b〉 
639    | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
640    
641 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
642 interpretation "lc" 'lc op a b = (lc ? op a b).
643 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
644
645 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
646    match a with [ mk_pair e1 b1 ⇒
647    match b1 with 
648    [ false ⇒ 〈e1^*, false〉 
649    | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
650
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}.
654
655 notation > "•" non associative with precedence 60 for @{eclose ?}.
656 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
657  match E with
658   [ pz ⇒ 〈 0, false 〉
659   | pe ⇒ 〈 ϵ,  true 〉
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 60 for @{'eclose $x}.
666 interpretation "eclose" 'eclose x = (eclose ? x).
667 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
668
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).
671
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; ##]
681 nqed.
682
683 (* theorem 16: 2 *)
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…));
692 //;
693 nqed.
694
695
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.
700
701 (*
702 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
703   𝐋\p (e1 · e2) =  𝐋\p e1 · 𝐋  |e2| ∪ 𝐋\p e2. //; nqed.
704 *)
705
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; ##]
710 nqed.
711
712
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;
715 nqed.
716
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.
719
720 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
721
722 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
723 #S a b; nnormalize; /2/; nqed.
724
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; @; //;##]
730 nqed.
731
732 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
733 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
734
735 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
736 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
737
738 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
739 #S a b w; nnormalize; *; //; nqed.
740
741 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
742 #S a; nelim a; // by {};
743 ##[ #e1 e2 IH1 IH2;
744     napply (?^-1); 
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); //]
753 nqed.
754
755 (*
756 nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
757 #S p; ncases p; //; nqed.
758 *)
759
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; 
764 napply (. defw╪_1#); 
765 napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
766 napply Hw2; 
767 nqed.
768
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));
772   SS ≟ RE S,
773   TT ≟ setoid1_of_setoid SS,
774   T ≟ carr1 TT
775 (*-----------------------------------------*) ⊢ 
776   eq_re S x y ≡ eq_rel1 T (eq1 TT) x y.    
777 (* XXX the previous hint does not work *)
778
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 #)));
795     napply (?^-1);
796     napply (.=_1 (cup_dotD …) ╪_1 #);
797     napply (.=_1 (# ╪_1 (epsilon_dot …)) ╪_1 #); 
798     napply (?^-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]
805     //;   
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#);
810     //]
811 nqed.
812
813
814
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 #]
828     @; //;##]
829 nqed.
830
831 STOP
832
833 (* theorem 16: 1 *)
834 alias symbol "pc" (instance 13) = "cat lang".
835 alias symbol "in_pl" (instance 23) = "in_pl".
836 alias symbol "in_pl" (instance 5) = "in_pl".
837 alias symbol "eclose" (instance 21) = "eclose".
838 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S.  𝐋\p (•e) =  𝐋\p e ∪ 𝐋 .|e|.
839 #S e; nelim e; //;
840   ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
841   ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
842   ##| #e1 e2 IH1 IH2;  
843       nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
844       nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
845       nrewrite > (IH1 …); nrewrite > (cup_dotD …);
846       nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
847       nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
848       nrewrite < (erase_dot …); nrewrite < (cupA …); //;
849   ##| #e1 e2 IH1 IH2;
850       nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
851       nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
852       nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
853       nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …); 
854       nrewrite < (erase_plus …); //.
855   ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
856       nchange in match (𝐋\p ?) with  (𝐋\p 〈e'^*,true〉);
857       nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
858       nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
859       nrewrite > (erase_bull…e);
860       nrewrite > (erase_star …);
861       nrewrite > (?: 𝐋\p e' =  𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
862         nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH; 
863         ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH; 
864             nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
865         ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
866       nrewrite > (cup_dotD…); nrewrite > (cupA…); 
867       nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
868       nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
869  nqed.
870
871 (* theorem 16: 3 *)      
872 nlemma odot_dot: 
873   ∀S.∀e1,e2: pre S.  𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
874 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
875
876 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} =  𝐋 e^*.
877 #S e; napply extP; #w; nnormalize; @;
878 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2; 
879     *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
880     nrewrite < defw; nrewrite < defw2; @; //; @;//;
881 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
882     #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
883     @; /2/; @xs; /2/;##]
884  nqed.
885
886 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
887 #S e; @[]; /2/; nqed.
888
889 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
890 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
891
892 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
893 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
894
895 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
896   ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
897 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
898 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
899 nqed.
900
901 (* theorem 16: 4 *)      
902 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
903 #S p; ncases p; #e b; ncases b;
904 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
905     nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
906     nchange in ⊢ (??%?) with (?∪?);
907     nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
908     nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
909       nlapply (bull_cup ? e); #bc;
910       nchange in match (𝐋\p (•e)) in bc with (?∪?);
911       nchange in match b' in bc with b';
912       ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
913       nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
914     nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
915     nrewrite > (sub_dot_star…);
916     nchange in match (𝐋\p 〈?,?〉) with (?∪?);
917     nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;    
918 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
919     nrewrite > (cup0…);
920     nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
921     nrewrite < (cup0 ? (𝐋\p e)); //;##]
922 nqed.
923
924 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝ 
925   match e with 
926   [ z ⇒ pz ?
927   | e ⇒ pe ?
928   | s x ⇒ ps ? x
929   | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
930   | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
931   | k e1 ⇒ pk ? (pre_of_re ? e1)].
932
933 nlemma notFalse : ¬False. @; //; nqed.
934
935 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
936 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
937 *; #w1; *; #w2; *; *; //; nqed.
938
939 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
940 #S e; nelim e; ##[##1,2,3: //]
941 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
942     nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
943 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
944     nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
945 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
946     nrewrite > H1; napply dot0; ##]
947 nqed.
948
949 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
950 #S A; nelim A; //; 
951 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
952     nrewrite < H1; nrewrite < H2; //
953 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
954     nrewrite < H1; nrewrite < H2; //
955 ##| #e1 H1; nchange in match (𝐋  (e1^* )) with ((𝐋 e1)^* );
956     nrewrite < H1; //]
957 nqed.     
958
959 (* corollary 17 *)
960 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
961 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
962 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
963 nqed.
964
965 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
966 #S f g H; nrewrite > H; //; nqed.
967  
968 (* corollary 18 *)
969 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
970 #S e; @;
971 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
972     nrewrite > defsnde; #H; 
973     nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
974     E MO?
975
976 STOP
977
978 notation > "\move term 90 x term 90 E" 
979 non associative with precedence 60 for @{move ? $x $E}.
980 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
981  match E with
982   [ pz ⇒ 〈 ∅, false 〉
983   | pe ⇒ 〈 ϵ, false 〉
984   | ps y ⇒ 〈 `y, false 〉
985   | pp y ⇒ 〈 `y, x == y 〉
986   | po e1 e2 ⇒ \move x e1 ⊕ \move x e2 
987   | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
988   | pk e ⇒ (\move x e)^⊛ ].
989 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
990 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
991 interpretation "move" 'move x E = (move ? x E).
992
993 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
994 interpretation "rmove" 'move x E = (rmove ? x E).
995
996 nlemma XXz :  ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
997 #S w abs; ninversion abs; #; ndestruct;
998 nqed.
999
1000
1001 nlemma XXe :  ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
1002 #S w abs; ninversion abs; #; ndestruct;
1003 nqed.
1004
1005 nlemma XXze :  ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ)  → False.
1006 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
1007 nqed.
1008
1009
1010 naxiom in_move_cat:
1011  ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) → 
1012    (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
1013 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
1014 ncases e1 in H; ncases e2;
1015 ##[##1: *; ##[*; nnormalize; #; ndestruct] 
1016    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1017    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1018 ##|##2: *; ##[*; nnormalize; #; ndestruct] 
1019    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1020    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1021 ##| #r; *; ##[ *; nnormalize; #; ndestruct] 
1022    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1023    ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
1024    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
1025 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
1026    #H; ninversion H; nnormalize; #; ndestruct; 
1027    ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
1028 ##| #r1 r2; *; ##[ *; #defw]
1029     ...
1030 nqed.
1031
1032 ntheorem move_ok:
1033  ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E. 
1034 #S E; ncases E; #r b; nelim r;
1035 ##[##1,2: #a w; @; 
1036    ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
1037       #H; ninversion H; #; ndestruct;
1038    ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
1039        #H; ninversion H; #; ndestruct;##]
1040 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
1041    *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
1042 ##|#a c w; @; nnormalize; 
1043    ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2;  nrewrite > (eqb_t … ca); @; ##]
1044        #H; ninversion H; #; ndestruct;
1045    ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
1046               #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
1047 ##|#r1 r2 H1 H2 a w; @;
1048    ##[ #H; ncases (in_move_cat … H);
1049       ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
1050           ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good; 
1051           nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
1052       ##|
1053       ...
1054 ##|
1055 ##|
1056 ##]
1057 nqed.
1058
1059
1060 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
1061 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
1062  match w with
1063   [ nil ⇒ E
1064   | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
1065
1066 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
1067
1068 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
1069  mk_equiv:
1070   ∀E1,E2: bool × (pre S).
1071    \fst E1  = \fst E2 →
1072     (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
1073      equiv S E1 E2.
1074
1075 ndefinition NAT: decidable.
1076  @ nat eqb; /2/.
1077 nqed.
1078
1079 include "hints_declaration.ma".
1080
1081 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
1082 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1083
1084 ninductive unit: Type[0] ≝ I: unit.
1085
1086 nlet corec foo_nop (b: bool):
1087  equiv ?
1088   〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1089   〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1090  @; //; #x; ncases x
1091   [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1092   | #y; ncases y
1093      [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1094      | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1095 nqed.
1096
1097 (*
1098 nlet corec foo (a: unit):
1099  equiv NAT
1100   (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1101   (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1102 ≝ ?.
1103  @;
1104   ##[ nnormalize; //
1105   ##| #x; ncases x
1106        [ nnormalize in ⊢ (??%%);
1107          nnormalize in foo: (? → ??%%);
1108          @; //; #y; ncases y
1109            [ nnormalize in ⊢ (??%%); napply foo_nop
1110            | #y; ncases y
1111               [ nnormalize in ⊢ (??%%);
1112                 
1113             ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1114      ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1115   ##]
1116 nqed.
1117 *)
1118
1119 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1120 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1121 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1122
1123
1124 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1125  nnormalize in match test3;
1126  nnormalize;
1127 //;
1128 nqed.
1129
1130 (**********************************************************)
1131
1132 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1133    der_z: der S a (z S) (z S)
1134  | der_e: der S a (e S) (z S)
1135  | der_s1: der S a (s S a) (e ?)
1136  | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1137  | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1138             der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1139  | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1140             der S a (c ? e1 e2) (c ? e1' e2)
1141  | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1142     der S a (o ? e1 e2) (o ? e1' e2').
1143
1144 nlemma eq_rect_CProp0_r:
1145  ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1146  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1147 nqed.
1148
1149 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1150
1151 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1152 (* #S; #r1; #r2; #w; nelim r1
1153   [ #K; ninversion K
1154   | #H1; #H2; napply (in_c ? []); //
1155   | (* tutti casi assurdi *) *)
1156
1157 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1158    in_l_empty1: ∀E.in_l S [] E → in_l' S [] E 
1159  | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1160
1161 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1162    mk_eq_re: ∀E1,E2.
1163     (in_l S [] E1 → in_l S [] E2) →
1164     (in_l S [] E2 → in_l S [] E1) →
1165     (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1166       eq_re S E1 E2.
1167
1168 (* serve il lemma dopo? *)
1169 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1170  #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1171   [ #r; #K (* ok *)
1172   | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1173
1174 (* IL VICEVERSA NON VALE *)
1175 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1176 (* #S; #w; #E; #H; nelim H
1177   [ //
1178   | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1179   ]
1180 nqed. *)
1181
1182 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1183  #S; #a; #E; #E'; #w; #H; nelim H
1184   [##1,2: #H1; ninversion H1
1185      [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1186      |##2,9: #X; #Y; #K; ncases (?:False); /2/
1187      |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1188      |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1189      |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1190      |##6,13: #x; #y; #K; ncases (?:False); /2/
1191      |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1192 ##| #H1; ninversion H1
1193      [ //
1194      | #X; #Y; #K; ncases (?:False); /2/
1195      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1196      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1197      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1198      | #x; #y; #K; ncases (?:False); /2/
1199      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1200 ##| #H1; #H2; #H3; ninversion H3
1201      [ #_; #K; ncases (?:False); /2/
1202      | #X; #Y; #K; ncases (?:False); /2/
1203      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1204      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1205      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1206      | #x; #y; #K; ncases (?:False); /2/
1207      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1208 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;
1209