]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/re/re-setoids.ma
...
[helm.git] / helm / software / 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.ma".
16 include "datatypes/bool.ma".
17 include "sets/sets.ma".
18
19 ninductive Admit : CProp[0] ≝ .
20 naxiom admit : Admit.
21
22 ninductive list (A:Type[0]) : Type[0] ≝ 
23   | nil: list A
24   | cons: A -> list A -> list A.
25   
26 nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝ 
27 match l1 with
28 [ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ ? | _ ⇒ ? ]
29 | cons x xs ⇒ match l2 with [ nil ⇒ ? | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
30 ##[ napply True|napply False|napply False]nqed.
31    
32 ndefinition LIST : setoid → setoid.
33 #S; @(list S); @(eq_list S); ncases admit; nqed.  
34
35 unification hint 0 ≔ S : setoid;
36   P1 ≟ refl ? (eq0 (LIST S)),
37   P2 ≟ sym ? (eq0 (LIST S)),
38   P3 ≟ trans ? (eq0 (LIST S)),
39   X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list S) P1 P2 P3),
40   T ≟ carr S
41 (*-----------------------------------------------------------------------*) ⊢
42      carr X ≡ list T.
43
44 notation "hvbox(hd break :: tl)"
45   right associative with precedence 47
46   for @{'cons $hd $tl}.
47
48 notation "[ list0 x sep ; ]"
49   non associative with precedence 90
50   for ${fold right @'nil rec acc @{'cons $x $acc}}.
51
52 notation "hvbox(l1 break @ l2)"
53   right associative with precedence 47
54   for @{'append $l1 $l2 }.
55
56 interpretation "nil" 'nil = (nil ?).
57 interpretation "cons" 'cons hd tl = (cons ? hd tl).
58
59 nlet rec append A (l1: list A) l2 on l1 ≝ 
60   match l1 with
61   [ nil ⇒ l2
62   | cons hd tl ⇒ hd :: append A tl l2 ].
63
64 interpretation "append" 'append l1 l2 = (append ? l1 l2).
65
66 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
67 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
68
69 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z. 
70
71 ninductive one : Type[0] ≝ unit : one.
72
73 ndefinition force ≝ 
74   λS:Type[2].λs:S.λT:Type[2].λt:T.λlock:one.
75     match lock return λ_.Type[2] with [ unit ⇒ T].
76
77 nlet rec lift (S:Type[2]) (s:S) (T:Type[2]) (t:T) (lock:one) on lock : force S s T t lock ≝ 
78  match lock return λlock.force S s T t lock with [ unit ⇒ t ].
79
80 ncoercion lift1 : ∀S:Type[1].∀s:S.∀T:Type[1].∀t:T.∀lock:one. force S s T t lock ≝ lift
81  on s : ? to force ?????.
82
83 ncoercion lift2 : ∀S:Type[2].∀s:S.∀T:Type[2].∀t:T.∀lock:one. force S s T t lock ≝ lift
84  on s : ? to force ?????.
85
86 unification hint 0 ≔ R : setoid; 
87    TR ≟ setoid, MR ≟ (carr R), lock ≟ unit 
88 (* ---------------------------------------- *) ⊢ 
89    setoid ≡ force ?(*Type[0]*) MR TR R lock.
90
91 unification hint 0 ≔ R : setoid1; 
92    TR ≟ setoid1, MR ≟ (carr1 R), lock ≟ unit 
93 (* ---------------------------------------- *) ⊢ 
94    setoid1 ≡ force ? MR TR R lock.
95
96 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
97 #A;#x;#y;#z;nelim x[//|#a;#x1;#H;nnormalize;/2/]nqed.
98
99 interpretation "iff" 'iff a b = (iff a b).  
100
101 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ refl: eq A x x.
102
103 nlemma eq_rect_Type0_r':
104  ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → P x p.
105  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
106 nqed.
107
108 nlemma eq_rect_Type0_r:
109  ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
110  #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
111 nqed.
112
113 nlemma eq_rect_CProp0_r':
114  ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
115  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
116 nqed.
117
118 nlemma eq_rect_CProp0_r:
119  ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
120  #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
121 nqed.
122
123 notation < "a = b" non associative with precedence 45 for @{ 'eqpp $a $b}.
124 interpretation "bool eq" 'eqpp a b = (eq bool a b). 
125
126 ndefinition BOOL : setoid.
127 @bool; @(eq bool); ncases admit.nqed.
128
129 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
130 alias id "refl" = "cic:/matita/ng/properties/relations/refl.fix(0,1,3)".
131 unification hint 0 ≔ ;
132   P1 ≟ refl ? (eq0 BOOL),
133   P2 ≟ sym ? (eq0 BOOL),
134   P3 ≟ trans ? (eq0 BOOL),
135   X ≟ mk_setoid bool (mk_equivalence_relation ? (eq bool) P1 P2 P3)
136 (*-----------------------------------------------------------------------*) ⊢
137      carr X ≡ bool.
138
139 nrecord Alpha : Type[1] ≝ { 
140    acarr :> setoid;
141    eqb: acarr → acarr → bool; 
142    eqb_true: ∀x,y. (eqb x y = true) = (x = y)
143 }.
144  
145 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
146 interpretation "eqb" 'eqb a b = (eqb ? a b).
147
148 ninductive re (S: Type[0]) : Type[0] ≝
149    z: re S
150  | e: re S
151  | s: S → re S
152  | c: re S → re S → re S
153  | o: re S → re S → re S
154  | k: re S → re S.
155  
156 naxiom eq_re : ∀S:Alpha.re S → re S → CProp[0].
157 ndefinition RE : Alpha → setoid.
158 #A; @(re A); @(eq_re A); ncases admit. nqed.
159
160 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
161 alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
162 unification hint 0 ≔ A : Alpha;
163   P1 ≟ refl ? (eq0 (RE A)),
164   P2 ≟ sym ? (eq0 (RE A)),
165   P3 ≟ trans ? (eq0 (RE A)),
166   X ≟ mk_setoid (re A) (mk_equivalence_relation ? (eq_re A) P1 P2 P3),
167   T ≟ acarr A
168 (*-----------------------------------------------------------------------*) ⊢
169      carr X ≡ (re T).
170
171 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
172 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
173 interpretation "star" 'pk a = (k ? a).
174 interpretation "or" 'plus a b = (o ? a b).
175            
176 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
177 interpretation "cat" 'pc a b = (c ? a b).
178
179 (* to get rid of \middot *)
180 ncoercion c  : ∀S.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
181
182 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
183 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
184 interpretation "atom" 'ps a = (s ? a).
185
186 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
187 interpretation "epsilon" 'epsilon = (e ?).
188
189 notation "0" non associative with precedence 90 for @{ 'empty }.
190 interpretation "empty" 'empty = (z ?).
191
192 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
193 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
194
195 nlet rec flatten S (l : list (list S)) on l : list S ≝ 
196 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
197
198 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
199 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
200
201
202 ndefinition empty_set : ∀A.Ω^A ≝ λA.{ w | False }.
203 notation "∅" non associative with precedence 90 for @{'emptyset}.
204 interpretation "empty set" 'emptyset = (empty_set ?).
205
206 (*
207 notation "{}" non associative with precedence 90 for @{'empty_lang}.
208 interpretation "empty lang" 'empty_lang = (empty_lang ?).
209 *)
210
211 ndefinition sing_lang : ∀A:setoid.∀x:A.Ω^A ≝ λS.λx.{ w | x = w }.
212 interpretation "sing lang" 'singl x = (sing_lang ? x).
213
214 interpretation "subset construction with type" 'comprehension t \eta.x = 
215   (mk_powerclass t x).
216
217 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝ 
218   λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
219 interpretation "cat lang" 'pc a b = (cat ? a b).
220
221 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝ 
222   λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}. 
223 interpretation "star lang" 'pk l = (star ? l).
224
225 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
226 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝ 
227 match r with
228 [ z ⇒ ∅
229 | e ⇒ { [ ] }
230 | s x ⇒ { [x] }
231 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
232 | o r1 r2 ⇒  𝐋 r1 ∪ 𝐋 r2
233 | k r1 ⇒ (𝐋 r1) ^*].
234 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
235 interpretation "in_l" 'L_re E = (L_re ? E).
236
237 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
238 ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
239 interpretation "orb" 'orb a b = (orb a b).
240
241 ninductive pitem (S: Type[0]) : Type[0] ≝
242    pz: pitem S
243  | pe: pitem S
244  | ps: S → pitem S
245  | pp: S → pitem S
246  | pc: pitem S → pitem S → pitem S
247  | po: pitem S → pitem S → pitem S
248  | pk: pitem S → pitem S.
249  
250 ndefinition pre ≝ λS.pitem S × bool.
251
252 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
253 interpretation "fst" 'fst x = (fst ? ? x).
254 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
255 interpretation "snd" 'snd x = (snd ? ? x).
256
257 interpretation "pstar" 'pk a = (pk ? a).
258 interpretation "por" 'plus a b = (po ? a b).
259 interpretation "pcat" 'pc a b = (pc ? a b).
260 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
261 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
262 interpretation "ppatom" 'pp a = (pp ? a).
263 (* to get rid of \middot *)
264 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S  ≝ pc on _p : pitem ? to ∀_:?.?.
265 interpretation "patom" 'ps a = (ps ? a).
266 interpretation "pepsilon" 'epsilon = (pe ?).
267 interpretation "pempty" 'empty = (pz ?).
268
269 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
270 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
271  match l with
272   [ pz ⇒ 0
273   | pe ⇒ ϵ
274   | ps x ⇒ `x
275   | pp x ⇒ `x
276   | pc E1 E2 ⇒ (|E1| · |E2|)
277   | po E1 E2 ⇒ (|E1| + |E2|)
278   | pk E ⇒ |E|^* ].
279 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
280 interpretation "forget" 'forget a = (forget ? a).
281
282 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
283 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝ 
284 match r with
285 [ pz ⇒ ∅
286 | pe ⇒ ∅
287 | ps _ ⇒ ∅
288 | pp x ⇒ { [x] }
289 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
290 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
291 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
292 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
293 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
294 interpretation "in_pl" 'L_pi E = (L_pi ? E).
295
296 unification hint 0 ≔ S,a,b;
297    R ≟ LIST S
298 (* -------------------------------------------- *) ⊢
299    eq_list S a b ≡ eq_rel (list S) (eq0 R) a b.
300
301 notation > "B ⇒_0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
302 notation > "B ⇒_1 C" right associative with precedence 72 for @{'umorph1 $B $C}.
303 notation "B ⇒\sub 0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
304 notation "B ⇒\sub 1 C" right associative with precedence 72 for @{'umorph1 $B $C}.
305
306 interpretation "unary morphism 0" 'umorph0 A B = (unary_morphism A B).
307 interpretation "unary morphism 1" 'umorph1 A B = (unary_morphism1 A B).
308
309 ncoercion setoid1_of_setoid : ∀s:setoid. setoid1 ≝ setoid1_of_setoid on _s: setoid to setoid1.
310
311 nlemma exists_is_morph: (* BUG *) ∀S,T:setoid.∀P: S ⇒_1 (T ⇒_1 (CProp[0]:?)).
312   ∀y,z:S.y =_0 z → (Ex T (P y)) = (Ex T (P z)).
313 #S T P y z E; @;
314 ##[ *; #x Px; @x; alias symbol "refl" (instance 4) = "refl".
315     alias symbol "prop2" (instance 2) = "prop21".
316     napply (. E^-1‡#); napply Px;
317 ##| *; #x Px; @x; napply (. E‡#); napply Px;##]
318 nqed.
319
320 ndefinition ex_morph : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
321 #S; @; ##[ #P; napply (Ex ? P); ##| #P1 P2 E; @; 
322 *; #x; #H; @ x; nlapply (E x x ?); //; *; /2/;
323 nqed.
324  
325 nlemma d : ∀S:Alpha.
326  ∀ee: (setoid1_of_setoid (list S)) ⇒_1 (setoid1_of_setoid (list S)) ⇒_1 CPROP.
327  ∀x,y:list S.x = y →
328  let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
329   form x = form y.
330  #S ee x y E;
331  nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
332  
333  nnormalize;
334  nlapply (exists_is_morph (list S) (list S) ? ?? E);
335  
336  nchange with (F x = F y);
337  nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
338  napply (.= † E);
339  napply #.
340 nqed.
341
342
343 E : w = w2
344   
345   
346   Σ(λx.(#‡E)‡#) : ∃x.x = w ∧ m → ∃x.x = w2 ∧ m 
347   λx.(#‡E)‡#    : ∀x.x = w ∧ m → x = w2 ∧ m 
348
349
350 w;
351 F ≟ ex_moprh ∘ G
352 g ≟ fun11 G
353 ------------------------------
354 ex (λx.g w x) ==?== fun11 F w
355
356 x ⊢ fun11 ?h ≟ λw. ?g w x
357 ?G ≟ morphism_leibniz (T → S) ∘ ?h 
358 ------------------------------
359 (λw. (λx:T.?g w x)) ==?== fun11 ?G
360
361 ...
362 x ⊢ fun11 ?h ==?== λw. eq x w ∧ m [w] 
363 (λw,x.eq x w ∧ m[w]) ==?== fun11 ?G
364 ex (λx.?g w x) ==?== ex (λx.x = w ∧ m[w])
365
366 ndefinition ex_morph : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
367 #S; @; ##[ #P; napply (Ex ? P); ##| ncases admit. ##] nqed.
368
369 ndefinition ex_morph1 : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
370 #S; @; ##[ #P; napply (Ex ? (λx.P); ##| ncases admit. ##] nqed.
371
372
373 nlemma d : ∀S:Alpha.
374  ∀ee: (setoid1_of_setoid (list S)) ⇒_1 (setoid1_of_setoid (list S)) ⇒_1 CPROP.
375  ∀x,y:list S.x = y →
376  let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
377   form x = form y.
378  #S ee x y E;
379  nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
380  
381  nnormalize;
382  
383  nchange with (F x = F y);
384  nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
385  napply (.= † E);
386  napply #.
387 nqed.
388
389
390 nlemma d : ∀S:Alpha.∀ee: (setoid1_of_setoid (list S)) ⇒_1 (setoid1_of_setoid (list S)) ⇒_1 CPROP.∀x,y:list S.x = y →
391  let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
392   form x = form y.
393  #S ee x y E;
394  nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
395  
396  nnormalize;
397  
398  nchange with (F x = F y);
399  nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
400  napply (.= † E);
401  napply #.
402 nqed.
403  
404   
405 nlemma d : ∀S:Alpha.(setoid1_of_setoid (list S)) ⇒_1 CPROP.
406  #S; napply (comp1_unary_morphisms ??? (ex_morph (list S)) ?);
407  napply (eq1).
408   
409   
410   
411 (*
412 ndefinition comp_ex : ∀X,S,T,K.∀P:X ⇒_1 (S ⇒_1 T).∀Pc : (S ⇒_1 T) ⇒_1 K. X ⇒_1 K.
413  *)
414
415 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
416 #S r; @(𝐋\p r); #w1 w2 E; nelim r; /2/;
417 ##[ #x; @; #H; ##[ nchange in H ⊢ % with ([?]=?); napply ((.= H) E)]
418     nchange in H ⊢ % with ([?]=?); napply ((.= H) E^-1);
419 ##| #e1 e2 H1 H2; 
420     nchange in match (w1 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
421     napply (.= (#‡H2));
422     napply (.= (Eexists ?? ? w1 w2 E)‡#);
423     
424     
425     nchange in match (w2 ∈ 𝐋\p (?·?)) with (?∨?);
426     napply (.= 
427     
428
429  //; napply (trans ?? ??? H E);
430    napply (trans (list S) (eq0 (LIST S)) ? [?] ?(*w1 [x] w2*) H E); 
431   nlapply (trans (list S) (eq0 (LIST S))).
432
433 napply (.= H); nnormalize; nlapply (trans ? [x] w1 w2 E H); napply (.= ?) [napply (w1 = [x])] ##[##2: napply #; napply sym1; napply refl1 ]
434
435 ndefinition epsilon ≝ 
436   λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
437
438 interpretation "epsilon" 'epsilon = (epsilon ?).
439 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
440 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
441
442 ndefinition L_pr ≝ λS : Alpha.λp:pre S.  𝐋\p\ (\fst p) ∪ ϵ (\snd p).
443   
444 interpretation "L_pr" 'L_pi E = (L_pr ? E).
445
446 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. w1 @ w2 = [ ] → w1 = [ ].
447 #S w1; ncases w1; //. nqed.
448
449 (* lemma 12 *)
450 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
451 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//; 
452 *; ##[##2:*] nelim e;
453 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
454 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
455 ##| #r1 r2 H1 H2; *; /2/ by {}]
456 *; #w1; *; #w2; *; *; 
457 ##[ #defw1 H1 foo; napply H; napply (. #‡#); (append_eq_nil … defw1)^-1‡#);
458
459  nrewrite > (append_eq_nil ? … w1 w2 …); /3/ by {};//;
460 nqed.
461
462 nlemma not_epsilon_lp : ∀S.∀e:pitem S. ¬ (𝐋\p e [ ]).
463 #S e; nelim e; nnormalize; /2/ by nmk;
464 ##[ #; @; #; ndestruct;
465 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
466     nrewrite > (append_eq_nil …H…); /2/;
467 ##| #r1 r2 n1 n2; @; *; /2/;
468 ##| #r n; @; *; #w1; *; #w2; *; *; #H;     
469     nrewrite > (append_eq_nil …H…); /2/;##]
470 nqed.
471
472 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
473 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
474 interpretation "oplus" 'oplus a b = (lo ? a b).
475
476 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
477    match a with [ mk_pair e1 b1 ⇒
478    match b1 with 
479    [ false ⇒ 〈e1 · \fst b, \snd b〉 
480    | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
481    
482 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
483 interpretation "lc" 'lc op a b = (lc ? op a b).
484 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
485
486 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
487    match a with [ mk_pair e1 b1 ⇒
488    match b1 with 
489    [ false ⇒ 〈e1^*, false〉 
490    | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
491
492 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
493 interpretation "lk" 'lk op a = (lk ? op a).
494 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
495
496 notation > "•" non associative with precedence 60 for @{eclose ?}.
497 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
498  match E with
499   [ pz ⇒ 〈 ∅, false 〉
500   | pe ⇒ 〈 ϵ,  true 〉
501   | ps x ⇒ 〈 `.x, false 〉
502   | pp x ⇒ 〈 `.x, false 〉
503   | po E1 E2 ⇒ •E1 ⊕ •E2
504   | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉 
505   | pk E ⇒ 〈(\fst (•E))^*,true〉].
506 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
507 interpretation "eclose" 'eclose x = (eclose ? x).
508 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
509
510 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
511 interpretation "reclose" 'eclose x = (reclose ? x).
512
513 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
514 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
515 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
516 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
517
518 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
519
520 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
521 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
522 nqed.
523
524 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
525 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
526
527 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
528 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
529
530 (* theorem 16: 2 *)
531 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
532 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
533 nwhd in ⊢ (??(??%)?);
534 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
535 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
536 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
537 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
538 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
539 nqed.
540
541 nlemma odotEt : 
542   ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
543 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
544
545 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) =  𝐋\p e1 · 𝐋 .|e2| ∪ 𝐋\p e2. //; nqed.
546
547 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r). 
548 #S p q r; napply extP; #w; nnormalize; @; 
549 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
550 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
551 nqed.
552
553 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
554 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
555
556 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 .|e1 · e2| =  𝐋 .|e1| · 𝐋 .|e2|.
557 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
558 nqed.
559
560 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 .|e1 + e2| =  𝐋 .|e1| ∪ 𝐋 .|e2|.
561 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
562
563 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 .|e1|^* = 𝐋 .|e1^*|. //; nqed.
564
565 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
566 interpretation "substract" 'minus a b = (substract ? a b).
567
568 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
569 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
570
571 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
572 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
573
574 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
575 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
576
577 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
578 #S a b w; nnormalize; *; //; nqed.
579
580 nlemma erase_bull : ∀S.∀a:pitem S. .|\fst (•a)| = .|a|.
581 #S a; nelim a; // by {};
582 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| · .|e2|);
583     nrewrite < IH1; nrewrite < IH2;  
584     nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
585     ncases (•e1); #e3 b; ncases b; nnormalize;
586     ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
587 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
588     nrewrite < IH2; nrewrite < IH1;
589     nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
590     ncases (•e1); ncases (•e2); //;
591 ##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
592     nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
593 nqed.
594
595 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
596 #S p; ncases p; //; nqed.
597
598 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p. 
599 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
600 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
601 napply Hw2; nqed.
602
603 (* theorem 16: 1 → 3 *)
604 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
605       𝐋\p (•(\fst e2)) =  𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| → 
606          𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
607 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
608 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2); 
609     nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
610     nchange in ⊢ (??%?) with (?∪?); 
611     nchange in ⊢ (??(??%?)?) with (?∪?);
612     nchange in match (𝐋\p 〈?,?〉) with (?∪?);
613     nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
614     nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
615     nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
616       nchange with (𝐋\p 〈e2'',b2''〉 =  𝐋\p e2' ∪ 𝐋 .|e2'|); 
617       ngeneralize in match th1;
618       nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
619     nrewrite > (eta_lp ? e2); 
620     nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
621     nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);       
622     nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
623     nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
624 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
625     nchange in match (𝐋\p ?) with (?∪?);
626     nchange in match (𝐋\p (e1'·?)) with (?∪?);
627     nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
628     nrewrite > (cup0…); 
629     nrewrite > (cupA…); //;##]
630 nqed.
631
632 nlemma sub_dot_star : 
633   ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
634 #S X b; napply extP; #w; @;
635 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
636     *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
637     @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
638     @; //; napply (subW … sube);
639 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
640     #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
641     ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
642         @; ncases b in H1; #H1; 
643         ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
644                 nrewrite > (associative_append ? w' w1 w2);
645                 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
646            ##| ncases w' in Pw';
647                ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
648                ##| #x xs Px; @(x::xs); @(w1@w2); 
649                    nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
650                    @wl'; @; //; ##] ##]
651         ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
652             nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
653             ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
654                 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
655                 @[]; @; //;
656             ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //] 
657                 @; //; @; //; @; *;##]##]##] 
658 nqed.
659
660 (* theorem 16: 1 *)
661 alias symbol "pc" (instance 13) = "cat lang".
662 alias symbol "in_pl" (instance 23) = "in_pl".
663 alias symbol "in_pl" (instance 5) = "in_pl".
664 alias symbol "eclose" (instance 21) = "eclose".
665 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S.  𝐋\p (•e) =  𝐋\p e ∪ 𝐋 .|e|.
666 #S e; nelim e; //;
667   ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
668   ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
669   ##| #e1 e2 IH1 IH2;  
670       nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
671       nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
672       nrewrite > (IH1 …); nrewrite > (cup_dotD …);
673       nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
674       nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
675       nrewrite < (erase_dot …); nrewrite < (cupA …); //;
676   ##| #e1 e2 IH1 IH2;
677       nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
678       nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
679       nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
680       nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …); 
681       nrewrite < (erase_plus …); //.
682   ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
683       nchange in match (𝐋\p ?) with  (𝐋\p 〈e'^*,true〉);
684       nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
685       nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
686       nrewrite > (erase_bull…e);
687       nrewrite > (erase_star …);
688       nrewrite > (?: 𝐋\p e' =  𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
689         nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH; 
690         ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH; 
691             nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
692         ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
693       nrewrite > (cup_dotD…); nrewrite > (cupA…); 
694       nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
695       nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
696  nqed.
697
698 (* theorem 16: 3 *)      
699 nlemma odot_dot: 
700   ∀S.∀e1,e2: pre S.  𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
701 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
702
703 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} =  𝐋 e^*.
704 #S e; napply extP; #w; nnormalize; @;
705 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2; 
706     *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
707     nrewrite < defw; nrewrite < defw2; @; //; @;//;
708 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
709     #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
710     @; /2/; @xs; /2/;##]
711  nqed.
712
713 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
714 #S e; @[]; /2/; nqed.
715
716 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
717 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
718
719 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
720 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
721
722 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
723   ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
724 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
725 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
726 nqed.
727
728 (* theorem 16: 4 *)      
729 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
730 #S p; ncases p; #e b; ncases b;
731 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
732     nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
733     nchange in ⊢ (??%?) with (?∪?);
734     nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
735     nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
736       nlapply (bull_cup ? e); #bc;
737       nchange in match (𝐋\p (•e)) in bc with (?∪?);
738       nchange in match b' in bc with b';
739       ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
740       nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
741     nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
742     nrewrite > (sub_dot_star…);
743     nchange in match (𝐋\p 〈?,?〉) with (?∪?);
744     nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;    
745 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
746     nrewrite > (cup0…);
747     nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
748     nrewrite < (cup0 ? (𝐋\p e)); //;##]
749 nqed.
750
751 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝ 
752   match e with 
753   [ z ⇒ pz ?
754   | e ⇒ pe ?
755   | s x ⇒ ps ? x
756   | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
757   | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
758   | k e1 ⇒ pk ? (pre_of_re ? e1)].
759
760 nlemma notFalse : ¬False. @; //; nqed.
761
762 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
763 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
764 *; #w1; *; #w2; *; *; //; nqed.
765
766 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
767 #S e; nelim e; ##[##1,2,3: //]
768 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
769     nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
770 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
771     nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
772 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
773     nrewrite > H1; napply dot0; ##]
774 nqed.
775
776 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
777 #S A; nelim A; //; 
778 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
779     nrewrite < H1; nrewrite < H2; //
780 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
781     nrewrite < H1; nrewrite < H2; //
782 ##| #e1 H1; nchange in match (𝐋  (e1^* )) with ((𝐋 e1)^* );
783     nrewrite < H1; //]
784 nqed.     
785
786 (* corollary 17 *)
787 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
788 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
789 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
790 nqed.
791
792 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
793 #S f g H; nrewrite > H; //; nqed.
794  
795 (* corollary 18 *)
796 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
797 #S e; @;
798 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
799     nrewrite > defsnde; #H; 
800     nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
801     E MO?
802
803 STOP
804
805 notation > "\move term 90 x term 90 E" 
806 non associative with precedence 60 for @{move ? $x $E}.
807 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
808  match E with
809   [ pz ⇒ 〈 ∅, false 〉
810   | pe ⇒ 〈 ϵ, false 〉
811   | ps y ⇒ 〈 `y, false 〉
812   | pp y ⇒ 〈 `y, x == y 〉
813   | po e1 e2 ⇒ \move x e1 ⊕ \move x e2 
814   | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
815   | pk e ⇒ (\move x e)^⊛ ].
816 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
817 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
818 interpretation "move" 'move x E = (move ? x E).
819
820 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
821 interpretation "rmove" 'move x E = (rmove ? x E).
822
823 nlemma XXz :  ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
824 #S w abs; ninversion abs; #; ndestruct;
825 nqed.
826
827
828 nlemma XXe :  ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
829 #S w abs; ninversion abs; #; ndestruct;
830 nqed.
831
832 nlemma XXze :  ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ)  → False.
833 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
834 nqed.
835
836
837 naxiom in_move_cat:
838  ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) → 
839    (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
840 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
841 ncases e1 in H; ncases e2;
842 ##[##1: *; ##[*; nnormalize; #; ndestruct] 
843    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
844    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
845 ##|##2: *; ##[*; nnormalize; #; ndestruct] 
846    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
847    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
848 ##| #r; *; ##[ *; nnormalize; #; ndestruct] 
849    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
850    ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
851    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
852 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
853    #H; ninversion H; nnormalize; #; ndestruct; 
854    ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
855 ##| #r1 r2; *; ##[ *; #defw]
856     ...
857 nqed.
858
859 ntheorem move_ok:
860  ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E. 
861 #S E; ncases E; #r b; nelim r;
862 ##[##1,2: #a w; @; 
863    ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
864       #H; ninversion H; #; ndestruct;
865    ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
866        #H; ninversion H; #; ndestruct;##]
867 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
868    *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
869 ##|#a c w; @; nnormalize; 
870    ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2;  nrewrite > (eqb_t … ca); @; ##]
871        #H; ninversion H; #; ndestruct;
872    ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
873               #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
874 ##|#r1 r2 H1 H2 a w; @;
875    ##[ #H; ncases (in_move_cat … H);
876       ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
877           ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good; 
878           nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
879       ##|
880       ...
881 ##|
882 ##|
883 ##]
884 nqed.
885
886
887 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
888 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
889  match w with
890   [ nil ⇒ E
891   | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
892
893 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
894
895 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
896  mk_equiv:
897   ∀E1,E2: bool × (pre S).
898    \fst E1  = \fst E2 →
899     (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
900      equiv S E1 E2.
901
902 ndefinition NAT: decidable.
903  @ nat eqb; /2/.
904 nqed.
905
906 include "hints_declaration.ma".
907
908 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
909 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
910
911 ninductive unit: Type[0] ≝ I: unit.
912
913 nlet corec foo_nop (b: bool):
914  equiv ?
915   〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
916   〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
917  @; //; #x; ncases x
918   [ nnormalize in ⊢ (??%%); napply (foo_nop false)
919   | #y; ncases y
920      [ nnormalize in ⊢ (??%%); napply (foo_nop false)
921      | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
922 nqed.
923
924 (*
925 nlet corec foo (a: unit):
926  equiv NAT
927   (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
928   (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
929 ≝ ?.
930  @;
931   ##[ nnormalize; //
932   ##| #x; ncases x
933        [ nnormalize in ⊢ (??%%);
934          nnormalize in foo: (? → ??%%);
935          @; //; #y; ncases y
936            [ nnormalize in ⊢ (??%%); napply foo_nop
937            | #y; ncases y
938               [ nnormalize in ⊢ (??%%);
939                 
940             ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
941      ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
942   ##]
943 nqed.
944 *)
945
946 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
947 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
948 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
949
950
951 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
952  nnormalize in match test3;
953  nnormalize;
954 //;
955 nqed.
956
957 (**********************************************************)
958
959 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
960    der_z: der S a (z S) (z S)
961  | der_e: der S a (e S) (z S)
962  | der_s1: der S a (s S a) (e ?)
963  | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
964  | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
965             der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
966  | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
967             der S a (c ? e1 e2) (c ? e1' e2)
968  | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
969     der S a (o ? e1 e2) (o ? e1' e2').
970
971 nlemma eq_rect_CProp0_r:
972  ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
973  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
974 nqed.
975
976 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
977
978 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
979 (* #S; #r1; #r2; #w; nelim r1
980   [ #K; ninversion K
981   | #H1; #H2; napply (in_c ? []); //
982   | (* tutti casi assurdi *) *)
983
984 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
985    in_l_empty1: ∀E.in_l S [] E → in_l' S [] E 
986  | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
987
988 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
989    mk_eq_re: ∀E1,E2.
990     (in_l S [] E1 → in_l S [] E2) →
991     (in_l S [] E2 → in_l S [] E1) →
992     (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
993       eq_re S E1 E2.
994
995 (* serve il lemma dopo? *)
996 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
997  #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
998   [ #r; #K (* ok *)
999   | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1000
1001 (* IL VICEVERSA NON VALE *)
1002 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1003 (* #S; #w; #E; #H; nelim H
1004   [ //
1005   | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1006   ]
1007 nqed. *)
1008
1009 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1010  #S; #a; #E; #E'; #w; #H; nelim H
1011   [##1,2: #H1; ninversion H1
1012      [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1013      |##2,9: #X; #Y; #K; ncases (?:False); /2/
1014      |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1015      |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1016      |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1017      |##6,13: #x; #y; #K; ncases (?:False); /2/
1018      |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1019 ##| #H1; ninversion H1
1020      [ //
1021      | #X; #Y; #K; ncases (?:False); /2/
1022      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1023      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1024      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1025      | #x; #y; #K; ncases (?:False); /2/
1026      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1027 ##| #H1; #H2; #H3; ninversion H3
1028      [ #_; #K; ncases (?:False); /2/
1029      | #X; #Y; #K; ncases (?:False); /2/
1030      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1031      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1032      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1033      | #x; #y; #K; ncases (?:False); /2/
1034      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1035 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;
1036