1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "datatypes/pairs.ma".
16 include "datatypes/bool.ma".
17 include "sets/sets.ma".
20 ninductive Admit : CProp[0] ≝ .
24 (* single = is for the abstract equality of setoids, == is for concrete
25 equalities (that may be lifted to the setoid level when needed *)
26 notation < "hvbox(a break mpadded width -50% (=)= b)" non associative with precedence 45 for @{ 'eq_low $a $b }.
27 notation > "a == b" non associative with precedence 45 for @{ 'eq_low $a $b }.
30 (* XXX move to lists.ma *)
31 ninductive list (A:Type[0]) : Type[0] ≝
33 | cons: A -> list A -> list A.
35 nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝
37 [ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ True | _ ⇒ False ]
38 | cons x xs ⇒ match l2 with [ nil ⇒ False | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
40 interpretation "eq_list" 'eq_low a b = (eq_list ? a b).
42 ndefinition LIST : setoid → setoid.
43 #S; @(list S); @(eq_list S);
44 ##[ #l; nelim l; //; #; @; //;
45 ##| #l1; nelim l1; ##[ #y; ncases y; //] #x xs H y; ncases y; ##[*] #y ys; *; #; @; /2/;
46 ##| #l1; nelim l1; ##[ #l2 l3; ncases l2; ncases l3; /3/; #z zs y ys; *]
47 #x xs H l2 l3; ncases l2; ncases l3; /2/; #z zs y yz; *; #H1 H2; *; #H3 H4; @; /3/;##]
50 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
51 unification hint 0 ≔ S : setoid;
53 P1 ≟ refl ? (eq0 (LIST S)),
54 P2 ≟ sym ? (eq0 (LIST S)),
55 P3 ≟ trans ? (eq0 (LIST S)),
56 X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list T) P1 P2 P3)
57 (*-----------------------------------------------------------------------*) ⊢
60 unification hint 0 ≔ S:setoid,a,b:list S;
63 (* -------------------------------------------- *) ⊢
64 eq_list S a b ≡ eq_rel L R a b.
66 notation "hvbox(hd break :: tl)"
67 right associative with precedence 47
70 notation "[ list0 x sep ; ]"
71 non associative with precedence 90
72 for ${fold right @'nil rec acc @{'cons $x $acc}}.
74 notation "hvbox(l1 break @ l2)"
75 right associative with precedence 47
76 for @{'append $l1 $l2 }.
78 interpretation "nil" 'nil = (nil ?).
79 interpretation "cons" 'cons hd tl = (cons ? hd tl).
81 nlet rec append A (l1: list A) l2 on l1 ≝
84 | cons hd tl ⇒ hd :: append A tl l2 ].
86 interpretation "append" 'append l1 l2 = (append ? l1 l2).
88 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
89 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
91 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
93 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
94 #A;#x;#y;#z;nelim x[ napply (refl ???) |#a;#x1;#H;nnormalize;/2/]nqed.
96 nlet rec flatten S (l : list (list S)) on l : list S ≝
97 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
99 (* end move to list *)
101 interpretation "iff" 'iff a b = (iff a b).
103 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ refl: eq A x x.
105 nlemma eq_rect_Type0_r':
106 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → P x p.
107 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
110 nlemma eq_rect_Type0_r:
111 ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
112 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
115 nlemma eq_rect_CProp0_r':
116 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
117 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
120 nlemma eq_rect_CProp0_r:
121 ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
122 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
125 (* XXX move to bool *)
126 interpretation "bool eq" 'eq_low a b = (eq bool a b).
128 ndefinition BOOL : setoid.
129 @bool; @(eq bool); nnormalize; //; #x y; ##[ #E; ncases E; ##| #y H; ncases H; ##] //; nqed.
131 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
132 alias id "refl" = "cic:/matita/ng/properties/relations/refl.fix(0,1,3)".
133 unification hint 0 ≔ ;
134 P1 ≟ refl ? (eq0 BOOL),
135 P2 ≟ sym ? (eq0 BOOL),
136 P3 ≟ trans ? (eq0 BOOL),
137 X ≟ mk_setoid bool (mk_equivalence_relation ? (eq bool) P1 P2 P3)
138 (*-----------------------------------------------------------------------*) ⊢
141 unification hint 0 ≔ a,b;
144 (* -------------------------------------------- *) ⊢
145 eq bool a b ≡ eq_rel L R a b.
147 nrecord Alpha : Type[1] ≝ {
149 eqb: acarr → acarr → bool;
150 eqb_true: ∀x,y. (eqb x y = true) = (x = y)
153 interpretation "eqb" 'eq_low a b = (eqb ? a b).
155 ninductive re (S: Type[0]) : Type[0] ≝
159 | c: re S → re S → re S
160 | o: re S → re S → re S
163 nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝
165 [ z ⇒ match b with [ z ⇒ True | _ ⇒ False]
166 | e ⇒ match b with [ e ⇒ True | _ ⇒ False]
167 | s x ⇒ match b with [ s y ⇒ x = y | _ ⇒ False]
168 | c r1 r2 ⇒ match b with [ c s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
169 | o r1 r2 ⇒ match b with [ o s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
170 | k r1 ⇒ match b with [ k r2 ⇒ eq_re ? r1 r2 | _ ⇒ False]].
172 interpretation "eq_re" 'eq_low a b = (eq_re ? a b).
174 ndefinition RE : Alpha → setoid.
175 #A; @(re A); @(eq_re A);
176 ##[ #p; nelim p; /2/;
177 ##| #p1; nelim p1; ##[##1,2: #p2; ncases p2; /2/;
178 ##|##2,3: #x p2; ncases p2; /2/;
179 ##|##4,5: #e1 e2 H1 H2 p2; ncases p2; /3/; #e3 e4; *; #; @; /2/;
180 ##|#r H p2; ncases p2; /2/;##]
182 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
183 ##| ##3: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
184 ##| ##4,5: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
185 ##[##1,3,4,5,6,8: #; ncases (?:False); //;##]
186 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
187 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3: #; ncases (?:False); //]
191 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
192 alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
193 unification hint 0 ≔ A : Alpha;
196 P1 ≟ refl ? (eq0 (RE A)),
197 P2 ≟ sym ? (eq0 (RE A)),
198 P3 ≟ trans ? (eq0 (RE A)),
199 X ≟ mk_setoid (re T) (mk_equivalence_relation ? (eq_re A) P1 P2 P3)
200 (*-----------------------------------------------------------------------*) ⊢
203 unification hint 0 ≔ A:Alpha,a,b:re A;
206 (* -------------------------------------------- *) ⊢
207 eq_re A a b ≡ eq_rel L R a b.
209 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
210 notation > "a ^ *" non associative with precedence 75 for @{ 'pk $a}.
211 interpretation "star" 'pk a = (k ? a).
212 interpretation "or" 'plus a b = (o ? a b).
214 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
215 interpretation "cat" 'pc a b = (c ? a b).
217 (* to get rid of \middot *)
218 ncoercion c : ∀S.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
220 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
221 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
222 interpretation "atom" 'ps a = (s ? a).
224 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
225 interpretation "epsilon" 'epsilon = (e ?).
227 notation "0" non associative with precedence 90 for @{ 'empty_r }.
228 interpretation "empty" 'empty_r = (z ?).
230 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
231 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
233 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
234 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
237 ndefinition sing_lang : ∀A:setoid.∀x:A.Ω^A ≝ λS.λx.{ w | x = w }.
238 interpretation "sing lang" 'singl x = (sing_lang ? x).
241 interpretation "subset construction with type" 'comprehension t \eta.x =
244 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
245 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
246 interpretation "cat lang" 'pc a b = (cat ? a b).
248 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
249 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
250 interpretation "star lang" 'pk l = (star ? l).
252 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
253 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
258 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
259 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
261 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
262 interpretation "in_l" 'L_re E = (L_re ? E).
264 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
265 ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
266 interpretation "orb" 'orb a b = (orb a b).
268 ninductive pitem (S: Type[0]) : Type[0] ≝
273 | pc: pitem S → pitem S → pitem S
274 | po: pitem S → pitem S → pitem S
275 | pk: pitem S → pitem S.
277 nlet rec eq_pitem (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝
279 [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
280 | pe ⇒ match p2 with [ pe ⇒ True | _ ⇒ False]
281 | ps x ⇒ match p2 with [ ps y ⇒ x = y | _ ⇒ False]
282 | pp x ⇒ match p2 with [ pp y ⇒ x = y | _ ⇒ False]
283 | pc a1 a2 ⇒ match p2 with [ pc b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
284 | po a1 a2 ⇒ match p2 with [ po b1 b2 ⇒ eq_pitem ? a1 b1 ∧ eq_pitem ? a2 b2| _ ⇒ False]
285 | pk a ⇒ match p2 with [ pk b ⇒ eq_pitem ? a b | _ ⇒ False]].
287 interpretation "eq_pitem" 'eq_low a b = (eq_pitem ? a b).
289 nlemma PITEM : ∀S:Alpha.setoid.
290 #S; @(pitem S); @(eq_pitem …);
291 ##[ #p; nelim p; //; nnormalize; #; @; //;
292 ##| #p; nelim p; ##[##1,2: #y; ncases y; //; ##|##3,4: #x y; ncases y; //; #; napply (?^-1); nassumption;
293 ##|##5,6: #r1 r2 H1 H2 p2; ncases p2; //; #s1 s2; nnormalize; *; #; @; /2/;
294 ##| #r H y; ncases y; //; nnormalize; /2/;##]
296 ##[ ##1,2: #y z; ncases y; ncases z; //; nnormalize; #; ncases (?:False); //;
297 ##| ##3,4: #a; #y z; ncases y; ncases z; /2/; nnormalize; #; ncases (?:False); //;
298 ##| ##5,6: #r1 r2 H1 H2 y z; ncases y; ncases z; //; nnormalize;
299 ##[##1,2,5,6,7,8,4,10: #; ncases (?:False); //;##]
300 #r1 r2 r3 r4; nnormalize; *; #H1 H2; *; #H3 H4; /3/;
301 ##| #r H y z; ncases y; ncases z; //; nnormalize; ##[##1,2,3,4: #; ncases (?:False); //]
305 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
306 unification hint 0 ≔ SS:Alpha;
309 P1 ≟ refl ? (eq0 (PITEM SS)),
310 P2 ≟ sym ? (eq0 (PITEM SS)),
311 P3 ≟ trans ? (eq0 (PITEM SS)),
312 R ≟ mk_setoid (pitem S) (mk_equivalence_relation (pitem A) (eq_pitem SS) P1 P2 P3)
313 (*---------------------------*)⊢
316 unification hint 0 ≔ S:Alpha,a,b:pitem S;
319 (* -------------------------------------------- *) ⊢
320 eq_pitem S a b ≡ eq_rel L (eq0 R) a b.
322 (* XXX move to pair.ma *)
323 nlet rec eq_pair (A, B : setoid) (a : A × B) (b : A × B) on a : CProp[0] ≝
324 match a with [ mk_pair a1 a2 ⇒
325 match b with [ mk_pair b1 b2 ⇒ a1 = b1 ∧ a2 = b2 ]].
327 interpretation "eq_pair" 'eq_low a b = (eq_pair ?? a b).
329 nlemma PAIR : ∀A,B:setoid. setoid.
330 #A B; @(A × B); @(eq_pair …);
331 ##[ #ab; ncases ab; #a b; @; napply #;
332 ##| #ab cd; ncases ab; ncases cd; #a1 a2 b1 b2; *; #E1 E2;
333 @; napply (?^-1); //;
334 ##| #a b c; ncases a; ncases b; ncases c; #c1 c2 b1 b2 a1 a2;
335 *; #E1 E2; *; #E3 E4; @; ##[ napply (.= E1); //] napply (.= E2); //.##]
338 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
339 unification hint 0 ≔ AA, BB;
340 A ≟ carr AA, B ≟ carr BB,
341 P1 ≟ refl ? (eq0 (PAIR AA BB)),
342 P2 ≟ sym ? (eq0 (PAIR AA BB)),
343 P3 ≟ trans ? (eq0 (PAIR AA BB)),
344 R ≟ mk_setoid (A × B) (mk_equivalence_relation ? (eq_pair …) P1 P2 P3)
345 (*---------------------------------------------------------------------------*)⊢
348 unification hint 0 ≔ S1,S2,a,b;
351 (* -------------------------------------------- *) ⊢
352 eq_pair S1 S2 a b ≡ eq_rel L (eq0 R) a b.
354 (* end move to pair *)
356 ndefinition pre ≝ λS.pitem S × bool.
358 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
359 interpretation "fst" 'fst x = (fst ? ? x).
360 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
361 interpretation "snd" 'snd x = (snd ? ? x).
363 interpretation "pstar" 'pk a = (pk ? a).
364 interpretation "por" 'plus a b = (po ? a b).
365 interpretation "pcat" 'pc a b = (pc ? a b).
366 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
367 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
368 interpretation "ppatom" 'pp a = (pp ? a).
369 (* to get rid of \middot *)
370 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
371 interpretation "patom" 'ps a = (ps ? a).
372 interpretation "pepsilon" 'epsilon = (pe ?).
373 interpretation "pempty" 'empty_r = (pz ?).
375 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
376 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
382 | pc E1 E2 ⇒ (|E1| · |E2|)
383 | po E1 E2 ⇒ (|E1| + |E2|)
385 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
386 interpretation "forget" 'forget a = (forget ? a).
388 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
389 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
395 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
396 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
397 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
398 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
399 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
400 interpretation "in_pl" 'L_pi E = (L_pi ? E).
402 (* The caml, as some patches for it *)
403 ncoercion setoid1_of_setoid : ∀s:setoid. setoid1 ≝ setoid1_of_setoid on _s: setoid to setoid1.
405 alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
406 unification hint 0 ≔ S : setoid, x,y;
408 TT ≟ setoid1_of_setoid SS
409 (*-----------------------------------------*) ⊢
410 eq_list S x y ≡ eq_rel1 ? (eq1 TT) x y.
412 unification hint 0 ≔ SS : setoid;
414 TT ≟ setoid1_of_setoid (LIST SS)
415 (*-----------------------------------------------------------------*) ⊢
418 (* not as morphism *)
419 nlemma Not_morphism : CProp[0] ⇒_1 CProp[0].
420 @(λx:CProp[0].¬ x); #a b; *; #; @; /3/; nqed.
422 unification hint 0 ≔ P : CProp[0];
425 M ≟ mk_unary_morphism1 ?? (λP.¬ P) (prop11 ?? Not_morphism)
426 (*------------------------*)⊢
429 (* XXX Ex setoid support *)
430 nlemma Ex_morphism : ∀S:setoid.(S ⇒_1 CProp[0]) ⇒_1 CProp[0].
431 #S; @(λP: S ⇒_1 CProp[0].Ex S P); #P Q E; @; *; #x Px; @x; ncases (E x x #); /2/; nqed.
433 unification hint 0 ≔ S : setoid, P : S ⇒_1 CProp[0];
434 A ≟ unary_morphism1_setoid1 (setoid1_of_setoid S) CPROP,
436 M ≟ mk_unary_morphism1 ?? (λP: S ⇒_1 CProp[0].Ex S P)
437 (prop11 ?? (Ex_morphism S))
438 (*------------------------*)⊢
439 fun11 A B M P ≡ Ex S (fun11 S CPROP P).
441 nlemma Ex_morphism_eta : ∀S:setoid.(S ⇒_1 CProp[0]) ⇒_1 CProp[0].
442 #S; @(λP: S ⇒_1 CProp[0].Ex S (λx.P x)); #P Q E; @; *; #x Px; @x; ncases (E x x #); /2/; nqed.
444 unification hint 0 ≔ S : setoid, P : S ⇒_1 CProp[0];
445 A ≟ unary_morphism1_setoid1 (setoid1_of_setoid S) CPROP,
447 M ≟ mk_unary_morphism1 ?? (λP: S ⇒_1 CProp[0].Ex S (λx.P x))
448 (prop11 ?? (Ex_morphism_eta S))
449 (*------------------------*)⊢
450 fun11 A B M P ≡ Ex S (λx.fun11 S CPROP P x).
452 nlemma Ex_setoid : ∀S:setoid.(S ⇒_1 CPROP) → setoid.
453 #T P; @ (Ex T (λx:T.P x)); @; ##[ #H1 H2; napply True |##*: //; ##] nqed.
455 unification hint 0 ≔ T,P ;
457 (*---------------------------*) ⊢
458 Ex T (λx:T.P x) ≡ carr S.
460 (* couts how many Ex we are traversing *)
461 ninductive counter : Type[0] ≝
463 | Next : (bool → bool) → (* dummy arg please the notation mechanism *)
466 (* to rewrite terms (live in setoid) *)
467 nlet rec mk_P (S, T : setoid) (n : counter) on n ≝
468 match n with [ End ⇒ T → CProp[0] | Next _ m ⇒ S → (mk_P S T m) ].
470 nlet rec mk_F (S, T : setoid) (n : counter) on n ≝
471 match n with [ End ⇒ T | Next _ m ⇒ S → (mk_F S T m) ].
473 nlet rec mk_E (S, T : setoid) (n : counter) on n : ∀f,g : mk_F S T n. CProp[0] ≝
475 [ End ⇒ λf,g:T. f = g
476 | Next q m ⇒ λf,g: mk_F S T (Next q m). ∀x:S.mk_E S T m (f x) (g x) ].
478 nlet rec mk_H (S, T : setoid) (n : counter) on n :
479 ∀P1,P2: mk_P S T n.∀f,g : mk_F S T n. CProp[1] ≝
481 [ End ⇒ λP1,P2:mk_P S T End.λf,g:T. f = g → P1 f =_1 P2 g
482 | Next q m ⇒ λP1,P2: mk_P S T (Next q m).λf,g: mk_F S T (Next q m).
483 ∀x:S.mk_H S T m (P1 x) (P2 x) (f x) (g x) ].
485 nlet rec mk_Ex (S, T : setoid) (n : counter) on n :
486 ∀P: mk_P S T n.∀f : mk_F S T n. CProp[0] ≝
488 [ End ⇒ λP:mk_P S T End.λf:T. P f
489 | Next q m ⇒ λP: mk_P S T (Next q m).λf: mk_F S T (Next q m).
490 ∃x:S.mk_Ex S T m (P x) (f x) ].
492 nlemma Sig_generic : ∀S,T.∀n:counter.∀P,f,g.
493 mk_E S T n f g → mk_H S T n P P f g → mk_Ex S T n P f =_1 mk_Ex S T n P g.
494 #S T n; nelim n; nnormalize;
496 ##| #q m IH P f g E H; @; *; #x Px; @x; ncases (IH … (E x) (H x)); /3/; ##]
499 (* to rewrite propositions (live in setoid1) *)
500 nlet rec mk_P1 (S : setoid) (T : setoid1) (n : counter) on n ≝
501 match n with [ End ⇒ T → CProp[0] | Next _ m ⇒ S → (mk_P1 S T m) ].
503 nlet rec mk_F1 (S : setoid) (T : setoid1) (n : counter) on n ≝
504 match n with [ End ⇒ T | Next _ m ⇒ S → (mk_F1 S T m) ].
506 nlet rec mk_E1 (S : setoid) (T : setoid1) (n : counter) on n : ∀f,g : mk_F1 S T n. CProp[1] ≝
508 [ End ⇒ λf,g:T. f =_1 g
509 | Next q m ⇒ λf,g: mk_F1 S T (Next q m). ∀x:S.mk_E1 S T m (f x) (g x) ].
511 nlet rec mk_H1 (S : setoid) (T : setoid1) (n : counter) on n :
512 ∀P1,P2: mk_P1 S T n.∀f,g : mk_F1 S T n. CProp[1] ≝
514 [ End ⇒ λP1,P2:mk_P1 S T End.λf,g:T. f = g → P1 f =_1 P2 g
515 | Next q m ⇒ λP1,P2: mk_P1 S T (Next q m).λf,g: mk_F1 S T (Next q m).
516 ∀x:S.mk_H1 S T m (P1 x) (P2 x) (f x) (g x) ].
518 nlet rec mk_Ex1 (S : setoid) (T : setoid1) (n : counter) on n :
519 ∀P: mk_P1 S T n.∀f : mk_F1 S T n. CProp[0] ≝
521 [ End ⇒ λP:mk_P1 S T End.λf:T. P f
522 | Next q m ⇒ λP: mk_P1 S T (Next q m).λf: mk_F1 S T (Next q m).
523 ∃x:S.mk_Ex1 S T m (P x) (f x) ].
525 nlemma Sig_generic1 : ∀S,T.∀n:counter.∀P,f,g.
526 mk_E1 S T n f g → mk_H1 S T n P P f g → mk_Ex1 S T n P f =_1 mk_Ex1 S T n P g.
527 #S T n; nelim n; nnormalize;
529 ##| #q m IH P f g E H; @; *; #x Px; @x; ncases (IH … (E x) (H x)); /3/; ##]
532 (* notation "∑x1,...,xn. E / H ; P" were:
533 - x1...xn are bound in E and P, H is bound in P
534 - H is an identifier that will have the type of E in P
535 - P is the proof that the two existentially quantified predicates are equal*)
536 notation > "∑ list1 ident x sep , . term 56 E / ident nE ; term 19 H" with precedence 20
538 ${ fold right @{ 'End } rec acc @{ ('Next (λ${ident x}.${ident x}) $acc) } }
539 ${ fold right @{ $E } rec acc @{ λ${ident x}.$acc } }
540 ${ fold right @{ λ${ident nE}.$H } rec acc @{ λ${ident x}.$acc } }
543 interpretation "next" 'Next x y = (Next x y).
544 interpretation "end" 'End = End.
545 (*interpretation "sig_gen" 'Sig_gen n E H = (Sig_generic ?? n ??? E H).*)
546 interpretation "sig_gen1" 'Sig_gen n E H = (Sig_generic1 ?? n ??? E H).
548 nlemma test0 : ∀S:setoid. ∀P: S ⇒_1 CPROP.∀f,g:S → S.
549 (∀x:S.f x = g x) → (Ex S (λw.P (f w))) =_1 (Ex S (λw.P (g w))).
550 #S P f g E; napply (∑w. E w / H ; ┼_1H); nqed.
552 nlemma test : ∀S:setoid. ∀P: S ⇒_1 CPROP.∀f,g:S → S.
553 (∀x:S.f x = g x) → (Ex S (λw.P (f w)∧ True)) =_1 (Ex S (λw.P (g w)∧ True)).
554 #S P f g E; napply (∑w. E w / H ; (┼_1H)╪_1#); nqed.
556 nlemma test_bound : ∀S:setoid. ∀e,f: S ⇒_1 CPROP. e = f →
557 (Ex S (λw.e w ∧ True)) =_1 (Ex S (λw.f w ∧ True)).
558 #S f g E; napply (.=_1 ∑x. E x x # / H ; (H ╪_1 #)); //; nqed.
560 nlemma test2 : ∀S:setoid. ∀ee: S ⇒_1 S ⇒_1 CPROP.
561 ∀x,y:setoid1_of_setoid S.x =_1 y →
562 (True ∧ (Ex S (λw.ee x w ∧ True))) =_1 (True ∧ (Ex S (λw.ee y w ∧ True))).
563 #S m x y E; napply (.=_1 #╪_1(∑w. E / E ; ((E ╪_1 #) ╪_1 #))). //; nqed.
565 nlemma test3 : ∀S:setoid. ∀ee: S ⇒_1 S ⇒_1 CPROP.
566 ∀x,y:setoid1_of_setoid S.x =_1 y →
567 ((Ex S (λw.ee x w ∧ True) ∨ True)) =_1 ((Ex S (λw.ee y w ∧ True) ∨ True)).
568 #S m x y E; napply (.=_1 (∑w. E / E ; ((E ╪_1 #) ╪_1 #)) ╪_1 #). //; nqed.
570 (* Ex setoid support end *)
572 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
573 #S r; @(𝐋\p r); #w1 w2 E; nelim r;
576 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
577 napply ((.=_0 H) E^-1);
579 nchange in match (w1 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
580 nchange in match (w2 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?); good! *)
582 ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
583 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
584 napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #);
585 ##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
587 ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
588 #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
589 (* nnormalize in ⊢ (???%%); good! (but a bit too hard) *)
590 napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#);
594 unification hint 0 ≔ S : Alpha,e : pitem S;
596 X ≟ (mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e)))
597 (*-----------------------------------------------------------------*)⊢
598 ext_carr SS X ≡ 𝐋\p e.
600 ndefinition epsilon ≝
601 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
603 interpretation "epsilon" 'epsilon = (epsilon ?).
604 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
605 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
607 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
609 interpretation "L_pr" 'L_pi E = (L_pr ? E).
611 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
612 #S w1; ncases w1; //. nqed.
615 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
616 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
617 *; ##[##2:*] nelim e;
618 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
619 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
620 ##| #r1 r2 H1 H2; *; /2/ by {}]
621 *; #w1; *; #w2; *; *;
622 ##[ #defw1 H1 foo; napply H;
623 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
625 ##| #defw1 H1 foo; napply H;
626 napply (. (append_eq_nil ? ?? defw1)^-1╪_1#);
631 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ (𝐋\p e)).
632 #S e; nelim e; ##[##1,2,3,4: nnormalize;/2/]
633 ##[ #p1 p2 np1 np2; *; ##[##2: napply np2] *; #w1; *; #w2; *; *; #abs;
634 nlapply (append_eq_nil ??? abs); # defw1; #; napply np1;
635 napply (. defw1^-1╪_1#);
637 ##| #p1 p2 np1 np2; *; nchange with (¬?); //;
638 ##| #r n; *; #w1; *; #w2; *; *; #abs; #; napply n;
639 nlapply (append_eq_nil ??? abs); # defw1; #;
640 napply (. defw1^-1╪_1#);
644 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
645 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
646 interpretation "oplus" 'oplus a b = (lo ? a b).
648 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
649 match a with [ mk_pair e1 b1 ⇒
651 [ false ⇒ 〈e1 · \fst b, \snd b〉
652 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
654 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
655 interpretation "lc" 'lc op a b = (lc ? op a b).
656 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
658 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
659 match a with [ mk_pair e1 b1 ⇒
661 [ false ⇒ 〈e1^*, false〉
662 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
664 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
665 interpretation "lk" 'lk op a = (lk ? op a).
666 notation > "a ^ ⊛" non associative with precedence 75 for @{'lk eclose $a}.
668 notation > "•" non associative with precedence 60 for @{eclose ?}.
669 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
673 | ps x ⇒ 〈 `.x, false 〉
674 | pp x ⇒ 〈 `.x, false 〉
675 | po E1 E2 ⇒ •E1 ⊕ •E2
676 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
677 | pk E ⇒ 〈(\fst (•E))^*,true〉].
678 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
679 interpretation "eclose" 'eclose x = (eclose ? x).
680 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
682 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
683 interpretation "reclose" 'eclose x = (reclose ? x).
685 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
686 #S b1 b2; ncases b1; ncases b2;
687 nchange in match (true || true) with true;
688 nchange in match (true || false) with true;
689 nchange in match (ϵ true) with {[]};
690 nchange in match (ϵ false) with ∅;
691 ##[##1,4: napply ((cupID…)^-1);
692 ##| napply ((cup0 ? {[]})^-1);
693 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
696 (* XXX move somewere else *)
697 ndefinition if': ∀A,B:CPROP. A = B → A → B.
700 ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ???? to ∀_:?.?.
703 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
704 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2; (* oh my!
705 nwhd in ⊢ (???(??%)?);
706 nchange in ⊢(???%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
707 nchange in ⊢(???(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2)); *)
708 napply (.=_1 #╪_1 (epsilon_or ???));
709 napply (.=_1 (cupA…)^-1);
710 napply (.=_1 (cupA…)╪_1#);
711 napply (.=_1 (#╪_1(cupC…))╪_1#);
712 napply (.=_1 (cupA…)^-1╪_1#);
713 napply (.=_1 (cupA…));
718 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
719 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
720 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
721 #S e1 e2 b2; ncases b2; nnormalize; @; //; @; napply refl; nqed.
723 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
724 𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
726 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r).
727 #S p q r; napply ext_set; #w; nnormalize; @;
728 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
729 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
733 nlemma erase_dot : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
734 #S e1 e2; napply ext_set; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
737 nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
738 #S e1 e2; napply ext_set; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
740 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
742 nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
743 #S a b; nnormalize; /2/; nqed.
745 notation < "[\setoid\emsp\of\emsp term 19 x]" non associative with precedence 90 for @{'mk_setoid $x}.
746 interpretation "mk_setoid" 'mk_setoid x = (mk_setoid x ?).
748 nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
749 #S A B x H; napply ext_set; #w; @;
750 ##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
751 *; #wb nwn; @; ##[@2;//] //;
752 ##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
755 nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
756 #S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
758 nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
759 #S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
761 nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
762 #S a b w; nnormalize; *; //; nqed.
764 nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
765 #S a; nelim a; // by {};
766 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
768 finqui: manca · morfismo, oppure un lemma che dice che == è come Leibnitz.
770 nrewrite < IH1; nrewrite < IH2;
771 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
772 ncases (•e1); #e3 b; ncases b; nnormalize;
773 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
774 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
775 nrewrite < IH2; nrewrite < IH1;
776 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
777 ncases (•e1); ncases (•e2); //]
778 ##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
779 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
782 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
783 #S p; ncases p; //; nqed.
785 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
786 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
787 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
790 (* theorem 16: 1 → 3 *)
791 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
792 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| →
793 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
794 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
795 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
796 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
797 nchange in ⊢ (??%?) with (?∪?);
798 nchange in ⊢ (??(??%?)?) with (?∪?);
799 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
800 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
801 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
802 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
803 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 .|e2'|);
804 ngeneralize in match th1;
805 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
806 nrewrite > (eta_lp ? e2);
807 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
808 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
809 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
810 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
811 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
812 nchange in match (𝐋\p ?) with (?∪?);
813 nchange in match (𝐋\p (e1'·?)) with (?∪?);
814 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
816 nrewrite > (cupA…); //;##]
819 nlemma sub_dot_star :
820 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
821 #S X b; napply extP; #w; @;
822 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
823 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
824 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
825 @; //; napply (subW … sube);
826 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
827 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
828 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
829 @; ncases b in H1; #H1;
830 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
831 nrewrite > (associative_append ? w' w1 w2);
832 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
833 ##| ncases w' in Pw';
834 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
835 ##| #x xs Px; @(x::xs); @(w1@w2);
836 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
838 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
839 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
840 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
841 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
843 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
844 @; //; @; //; @; *;##]##]##]
848 alias symbol "pc" (instance 13) = "cat lang".
849 alias symbol "in_pl" (instance 23) = "in_pl".
850 alias symbol "in_pl" (instance 5) = "in_pl".
851 alias symbol "eclose" (instance 21) = "eclose".
852 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
854 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
855 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
857 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
858 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
859 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
860 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
861 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
862 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
864 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
865 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
866 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
867 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
868 nrewrite < (erase_plus …); //.
869 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
870 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
871 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
872 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
873 nrewrite > (erase_bull…e);
874 nrewrite > (erase_star …);
875 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
876 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
877 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
878 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
879 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
880 nrewrite > (cup_dotD…); nrewrite > (cupA…);
881 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
882 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
887 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
888 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
890 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
891 #S e; napply extP; #w; nnormalize; @;
892 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
893 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
894 nrewrite < defw; nrewrite < defw2; @; //; @;//;
895 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
896 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
900 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
901 #S e; @[]; /2/; nqed.
903 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
904 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
906 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
907 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
909 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
910 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
911 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
912 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
916 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
917 #S p; ncases p; #e b; ncases b;
918 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
919 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
920 nchange in ⊢ (??%?) with (?∪?);
921 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
922 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
923 nlapply (bull_cup ? e); #bc;
924 nchange in match (𝐋\p (•e)) in bc with (?∪?);
925 nchange in match b' in bc with b';
926 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
927 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
928 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
929 nrewrite > (sub_dot_star…);
930 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
931 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
932 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
934 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
935 nrewrite < (cup0 ? (𝐋\p e)); //;##]
938 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
943 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
944 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
945 | k e1 ⇒ pk ? (pre_of_re ? e1)].
947 nlemma notFalse : ¬False. @; //; nqed.
949 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
950 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
951 *; #w1; *; #w2; *; *; //; nqed.
953 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
954 #S e; nelim e; ##[##1,2,3: //]
955 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
956 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
957 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
958 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
959 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
960 nrewrite > H1; napply dot0; ##]
963 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
965 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
966 nrewrite < H1; nrewrite < H2; //
967 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
968 nrewrite < H1; nrewrite < H2; //
969 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
974 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
975 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
976 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
979 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
980 #S f g H; nrewrite > H; //; nqed.
983 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
985 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
986 nrewrite > defsnde; #H;
987 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
992 notation > "\move term 90 x term 90 E"
993 non associative with precedence 60 for @{move ? $x $E}.
994 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
998 | ps y ⇒ 〈 `y, false 〉
999 | pp y ⇒ 〈 `y, x == y 〉
1000 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
1001 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
1002 | pk e ⇒ (\move x e)^⊛ ].
1003 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
1004 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
1005 interpretation "move" 'move x E = (move ? x E).
1007 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
1008 interpretation "rmove" 'move x E = (rmove ? x E).
1010 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
1011 #S w abs; ninversion abs; #; ndestruct;
1015 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
1016 #S w abs; ninversion abs; #; ndestruct;
1019 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
1020 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
1025 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
1026 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
1027 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
1028 ncases e1 in H; ncases e2;
1029 ##[##1: *; ##[*; nnormalize; #; ndestruct]
1030 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1031 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1032 ##|##2: *; ##[*; nnormalize; #; ndestruct]
1033 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1034 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
1035 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
1036 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
1037 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
1038 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
1039 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
1040 #H; ninversion H; nnormalize; #; ndestruct;
1041 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
1042 ##| #r1 r2; *; ##[ *; #defw]
1047 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
1048 #S E; ncases E; #r b; nelim r;
1050 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
1051 #H; ninversion H; #; ndestruct;
1052 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
1053 #H; ninversion H; #; ndestruct;##]
1054 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
1055 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
1056 ##|#a c w; @; nnormalize;
1057 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
1058 #H; ninversion H; #; ndestruct;
1059 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
1060 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
1061 ##|#r1 r2 H1 H2 a w; @;
1062 ##[ #H; ncases (in_move_cat … H);
1063 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
1064 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
1065 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
1074 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
1075 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
1078 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
1080 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
1082 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
1084 ∀E1,E2: bool × (pre S).
1086 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
1089 ndefinition NAT: decidable.
1093 include "hints_declaration.ma".
1095 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
1096 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
1098 ninductive unit: Type[0] ≝ I: unit.
1100 nlet corec foo_nop (b: bool):
1102 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
1103 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
1105 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1107 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
1108 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
1112 nlet corec foo (a: unit):
1114 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
1115 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
1120 [ nnormalize in ⊢ (??%%);
1121 nnormalize in foo: (? → ??%%);
1123 [ nnormalize in ⊢ (??%%); napply foo_nop
1125 [ nnormalize in ⊢ (??%%);
1127 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
1128 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
1133 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
1134 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
1135 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
1138 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
1139 nnormalize in match test3;
1144 (**********************************************************)
1146 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
1147 der_z: der S a (z S) (z S)
1148 | der_e: der S a (e S) (z S)
1149 | der_s1: der S a (s S a) (e ?)
1150 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
1151 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
1152 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
1153 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
1154 der S a (c ? e1 e2) (c ? e1' e2)
1155 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
1156 der S a (o ? e1 e2) (o ? e1' e2').
1158 nlemma eq_rect_CProp0_r:
1159 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
1160 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
1163 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
1165 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
1166 (* #S; #r1; #r2; #w; nelim r1
1168 | #H1; #H2; napply (in_c ? []); //
1169 | (* tutti casi assurdi *) *)
1171 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
1172 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
1173 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
1175 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
1177 (in_l S [] E1 → in_l S [] E2) →
1178 (in_l S [] E2 → in_l S [] E1) →
1179 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
1182 (* serve il lemma dopo? *)
1183 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
1184 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1186 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1188 (* IL VICEVERSA NON VALE *)
1189 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1190 (* #S; #w; #E; #H; nelim H
1192 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1196 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1197 #S; #a; #E; #E'; #w; #H; nelim H
1198 [##1,2: #H1; ninversion H1
1199 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1200 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1201 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1202 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1203 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1204 |##6,13: #x; #y; #K; ncases (?:False); /2/
1205 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1206 ##| #H1; ninversion H1
1208 | #X; #Y; #K; ncases (?:False); /2/
1209 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1210 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1211 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1212 | #x; #y; #K; ncases (?:False); /2/
1213 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1214 ##| #H1; #H2; #H3; ninversion H3
1215 [ #_; #K; ncases (?:False); /2/
1216 | #X; #Y; #K; ncases (?:False); /2/
1217 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1218 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1219 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1220 | #x; #y; #K; ncases (?:False); /2/
1221 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1222 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;