]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/nlibrary/re/re-setoids.ma
fixed notation for \cup and \cap
[helm.git] / helm / software / matita / nlibrary / re / re-setoids.ma
index 41a43894d7a8ae8afb02355cf513f60a3c064b10..dcf1d85fe99fa8488b3e566c0b16d0dad7ed9e05 100644 (file)
 (*                                                                        *)
 (**************************************************************************)
 
-include "datatypes/pairs.ma".
-include "datatypes/bool.ma".
+include "datatypes/pairs-setoids.ma".
+include "datatypes/bool-setoids.ma".
+include "datatypes/list-setoids.ma".
 include "sets/sets.ma".
 
+(*
 ninductive Admit : CProp[0] ≝ .
 naxiom admit : Admit.
+*)
 
-(* single = is for the abstract equality of setoids, == is for concrete 
-   equalities (that may be lifted to the setoid level when needed *)
-notation < "hvbox(a break mpadded width -50% (=)= b)" non associative with precedence 45 for @{ 'eq_low $a $b }.
-notation > "a == b" non associative with precedence 45 for @{ 'eq_low $a $b }.
-
-
-(* XXX move to lists.ma *)
-ninductive list (A:Type[0]) : Type[0] ≝ 
-  | nil: list A
-  | cons: A -> list A -> list A.
-  
-nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝ 
-match l1 with
-[ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ True | _ ⇒ False ]
-| cons x xs ⇒ match l2 with [ nil ⇒ False | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
-   
-interpretation "eq_list" 'eq_low a b = (eq_list ? a b).
-   
-ndefinition LIST : setoid → setoid.
-#S; @(list S); @(eq_list S);
-##[ #l; nelim l; //; #; @; //;
-##| #l1; nelim l1; ##[ #y; ncases y; //] #x xs H y; ncases y; ##[*] #y ys; *; #; @; /2/;
-##| #l1; nelim l1; ##[ #l2 l3; ncases l2; ncases l3; /3/; #z zs y ys; *] 
-    #x xs H l2 l3; ncases l2; ncases l3; /2/; #z zs y yz; *; #H1 H2; *; #H3 H4; @; /3/;##]
-nqed.
-
-alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
-unification hint 0 ≔ S : setoid;
-  T ≟ carr S,
-  P1 ≟ refl ? (eq0 (LIST S)),
-  P2 ≟ sym ? (eq0 (LIST S)),
-  P3 ≟ trans ? (eq0 (LIST S)),
-  X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list T) P1 P2 P3)
-(*-----------------------------------------------------------------------*) ⊢
-     carr X ≡ list T.
-
-unification hint 0 ≔ S:setoid,a,b:list S;
-   R ≟ eq0 (LIST S),
-   L ≟ (list S)
-(* -------------------------------------------- *) ⊢
-   eq_list S a b ≡ eq_rel L R a b.
-
-notation "hvbox(hd break :: tl)"
-  right associative with precedence 47
-  for @{'cons $hd $tl}.
-
-notation "[ list0 x sep ; ]"
-  non associative with precedence 90
-  for ${fold right @'nil rec acc @{'cons $x $acc}}.
-
-notation "hvbox(l1 break @ l2)"
-  right associative with precedence 47
-  for @{'append $l1 $l2 }.
-
-interpretation "nil" 'nil = (nil ?).
-interpretation "cons" 'cons hd tl = (cons ? hd tl).
+(* XXX move somewere else *)
+ndefinition if': ∀A,B:CPROP. A = B → A → B.
+#A B; *; /2/. nqed.
 
-nlet rec append A (l1: list A) l2 on l1 ≝ 
-  match l1 with
-  [ nil ⇒ l2
-  | cons hd tl ⇒ hd :: append A tl l2 ].
+ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ???? to ∀_:?.?.
 
-interpretation "append" 'append l1 l2 = (append ? l1 l2).
+(* XXX move to list-setoids-theory.ma *)
 
 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
@@ -91,57 +38,37 @@ ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) =
 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
 #A;#x;#y;#z;nelim x[ napply (refl ???) |#a;#x1;#H;nnormalize;/2/]nqed.
 
-nlet rec flatten S (l : list (list S)) on l : list S ≝ 
-match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
-
 (* end move to list *)
 
+
+(* XXX to undestand what I want inside Alpha 
+   the eqb part should be split away, but when available it should be
+   possible to obtain a leibnitz equality on lemmas proved on setoids
+*)
 interpretation "iff" 'iff a b = (iff a b).  
 
-ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ refl: eq A x x.
+ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ erefl: eq A x x.
 
 nlemma eq_rect_Type0_r':
- ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → P x p.
+ ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (erefl A a) → P x p.
  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
 nqed.
 
 nlemma eq_rect_Type0_r:
- ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
+ ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (erefl A a) → ∀x.∀p:eq ? x a.P x p.
  #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
 nqed.
 
 nlemma eq_rect_CProp0_r':
- ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
+ ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (erefl A a) → P x p.
  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
 nqed.
 
 nlemma eq_rect_CProp0_r:
- ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
+ ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (erefl A a) → ∀x.∀p:eq ? x a.P x p.
  #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
 nqed.
 
-(* XXX move to bool *)
-interpretation "bool eq" 'eq_low a b = (eq bool a b). 
-
-ndefinition BOOL : setoid.
-@bool; @(eq bool); ncases admit.nqed.
-
-alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
-alias id "refl" = "cic:/matita/ng/properties/relations/refl.fix(0,1,3)".
-unification hint 0 ≔ ;
-  P1 ≟ refl ? (eq0 BOOL),
-  P2 ≟ sym ? (eq0 BOOL),
-  P3 ≟ trans ? (eq0 BOOL),
-  X ≟ mk_setoid bool (mk_equivalence_relation ? (eq bool) P1 P2 P3)
-(*-----------------------------------------------------------------------*) ⊢
-     carr X ≡ bool.
-
-unification hint 0 ≔ a,b;
-   R ≟ eq0 BOOL,
-   L ≟ bool
-(* -------------------------------------------- *) ⊢
-   eq bool a b ≡ eq_rel L R a b.
-
 nrecord Alpha : Type[1] ≝ { 
    acarr :> setoid;
    eqb: acarr → acarr → bool; 
@@ -149,7 +76,9 @@ nrecord Alpha : Type[1] ≝ {
 }.
  
 interpretation "eqb" 'eq_low a b = (eqb ? a b).
+(* end alpha *)
 
+(* re *)
 ninductive re (S: Type[0]) : Type[0] ≝
    z: re S
  | e: re S
@@ -158,6 +87,32 @@ ninductive re (S: Type[0]) : Type[0] ≝
  | o: re S → re S → re S
  | k: re S → re S.
  
+notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
+notation > "a ^ *" non associative with precedence 75 for @{ 'pk $a}.
+interpretation "star" 'pk a = (k ? a).
+interpretation "or" 'plus a b = (o ? a b).
+           
+notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
+interpretation "cat" 'pc a b = (c ? a b).
+
+(* to get rid of \middot *)
+ncoercion c  : ∀S.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
+
+notation < "a" non associative with precedence 90 for @{ 'ps $a}.
+notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
+interpretation "atom" 'ps a = (s ? a).
+
+notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
+interpretation "epsilon" 'epsilon = (e ?).
+
+notation "0" non associative with precedence 90 for @{ 'empty_r }.
+interpretation "empty" 'empty_r = (z ?).
+
+notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
+notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
+(* setoid support for re *)
 nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝ 
   match a with
   [ z ⇒ match b with [ z ⇒ True | _ ⇒ False]
@@ -166,6 +121,8 @@ nlet rec eq_re (S:Alpha) (a,b : re S) on a : CProp[0] ≝
   | c r1 r2 ⇒ match b with [ c s1 s2 ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False]
   | o r1 r2 ⇒ match b with [ o s1 s2  ⇒ eq_re ? r1 s1 ∧ eq_re ? r2 s2 | _ ⇒ False] 
   | k r1 ⇒ match b with [ k r2 ⇒ eq_re ? r1 r2 | _ ⇒ False]].
+  
+interpretation "eq_re" 'eq_low a b = (eq_re ? a b).
 
 ndefinition RE : Alpha → setoid.
 #A; @(re A); @(eq_re A);
@@ -184,8 +141,6 @@ ndefinition RE : Alpha → setoid.
         #r2 r3; /3/; ##]##]
 nqed.
 
-alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
-alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
 unification hint 0 ≔ A : Alpha;
   S ≟ acarr A,
   T ≟ carr S,
@@ -202,36 +157,47 @@ unification hint 0 ≔ A:Alpha,a,b:re A;
 (* -------------------------------------------- *) ⊢
    eq_re A a b ≡ eq_rel L R a b.
 
-notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
-notation > "a ^ *" non associative with precedence 75 for @{ 'pk $a}.
-interpretation "star" 'pk a = (k ? a).
-interpretation "or" 'plus a b = (o ? a b).
-           
-notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
-interpretation "cat" 'pc a b = (c ? a b).
-
-(* to get rid of \middot *)
-ncoercion c  : ∀S.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
-
-notation < "a" non associative with precedence 90 for @{ 'ps $a}.
-notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
-interpretation "atom" 'ps a = (s ? a).
-
-notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
-interpretation "epsilon" 'epsilon = (e ?).
-
-notation "0" non associative with precedence 90 for @{ 'empty_r }.
-interpretation "empty" 'empty_r = (z ?).
-
-notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
-notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
+nlemma c_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
+#A; napply (mk_binary_morphism … (λs1,s2:re A. s1 · s2));
+#a; nelim a; 
+##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
+##|#x a' b b'; ncases a'; /2/ by conj;
+##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
+##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
+nqed.
+
+(* XXX This is the good format for hints about morphisms, fix the others *)
+alias symbol "hint_decl" (instance 1) = "hint_decl_Type0".
+unification hint 0 ≔ S:Alpha, A,B:re S;
+    MM ≟ mk_unary_morphism ??
+          (λA:re S.mk_unary_morphism ?? (λB.A · B) (prop1 ?? (c_is_morph S A)))
+          (prop1 ?? (c_is_morph S)),
+    T ≟ RE S
+(*--------------------------------------------------------------------------*) ⊢
+   fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ A · B.
+
+nlemma o_is_morph : ∀A:Alpha.(re A) ⇒_0 (re A) ⇒_0 (re A).
+#A; napply (mk_binary_morphism … (λs1,s2:re A. s1 + s2));
+#a; nelim a; 
+##[##1,2: #a' b b'; ncases a'; nnormalize; /2/ by conj;
+##|#x a' b b'; ncases a'; /2/ by conj;
+##|##4,5: #r1 r2 IH1 IH2 a'; ncases a'; nnormalize; /2/ by conj;
+##|#r IH a'; ncases a'; nnormalize; /2/ by conj; ##]
+nqed.
+
+unification hint 0 ≔ S:Alpha, A,B:re S;
+    MM ≟ mk_unary_morphism ??
+          (λA:re S.mk_unary_morphism ?? (λB.A + B) (prop1 ?? (o_is_morph S A)))
+          (prop1 ?? (o_is_morph S)),
+    T ≟ RE S
+(*--------------------------------------------------------------------------*) ⊢
+   fun1 T T (fun1 T (unary_morph_setoid T T) MM A) B ≡ A + B.
+
+(* end setoids support for re *)
 
 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
 
-ndefinition sing_lang : ∀A:setoid.∀x:A.Ω^A ≝ λS.λx.{ w | x = w }.
-interpretation "sing lang" 'singl x = (sing_lang ? x).
-
 interpretation "subset construction with type" 'comprehension t \eta.x = 
   (mk_powerclass t x).
 
@@ -255,10 +221,6 @@ match r with
 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
 interpretation "in_l" 'L_re E = (L_re ? E).
 
-notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
-ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
-interpretation "orb" 'orb a b = (orb a b).
-
 ninductive pitem (S: Type[0]) : Type[0] ≝
    pz: pitem S
  | pe: pitem S
@@ -268,6 +230,19 @@ ninductive pitem (S: Type[0]) : Type[0] ≝
  | po: pitem S → pitem S → pitem S
  | pk: pitem S → pitem S.
  
+interpretation "pstar" 'pk a = (pk ? a).
+interpretation "por" 'plus a b = (po ? a b).
+interpretation "pcat" 'pc a b = (pc ? a b).
+notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
+notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
+interpretation "ppatom" 'pp a = (pp ? a).
+(* to get rid of \middot *)
+ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S  ≝ pc on _p : pitem ? to ∀_:?.?.
+interpretation "patom" 'ps a = (ps ? a).
+interpretation "pepsilon" 'epsilon = (pe ?).
+interpretation "pempty" 'empty_r = (pz ?). 
+(* setoids for pitem *)
 nlet rec eq_pitem  (S : Alpha) (p1, p2 : pitem S) on p1 : CProp[0] ≝ 
  match p1 with
  [ pz ⇒ match p2 with [ pz ⇒ True | _ ⇒ False]
@@ -313,40 +288,8 @@ unification hint 0 ≔ S:Alpha,a,b:pitem S;
 (* -------------------------------------------- *) ⊢
    eq_pitem S a b ≡ eq_rel L (eq0 R) a b.    
     
-(* XXX move to pair.ma *)   
-nlet rec eq_pair (A, B : setoid) (a : A × B) (b : A × B) on a : CProp[0] ≝ 
-  match a with [ mk_pair a1 a2 ⇒ 
-  match b with [ mk_pair b1 b2 ⇒ a1 = b1 ∧ a2 = b2 ]].
-
-interpretation "eq_pair" 'eq_low a b = (eq_pair ?? a b). 
-
-nlemma PAIR : ∀A,B:setoid. setoid.
-#A B; @(A × B); @(eq_pair …);
-##[ #ab; ncases ab; #a b; @; napply #;
-##| #ab cd; ncases ab; ncases cd; #a1 a2 b1 b2; *; #E1 E2;
-    @; napply (?^-1); //;
-##| #a b c; ncases a; ncases b; ncases c; #c1 c2 b1 b2 a1 a2;
-    *; #E1 E2; *; #E3 E4; @; ##[ napply (.= E1); //] napply (.= E2); //.##]
-nqed.
-
-alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
-unification hint 0 ≔ AA, BB;
-    A ≟ carr AA, B ≟ carr BB,
-    P1 ≟ refl ? (eq0 (PAIR AA BB)),
-    P2 ≟ sym ? (eq0 (PAIR AA BB)),
-    P3 ≟ trans ? (eq0 (PAIR AA BB)),
-    R ≟ mk_setoid (A × B) (mk_equivalence_relation ? (eq_pair …) P1 P2 P3)
-(*---------------------------------------------------------------------------*)⊢
-    carr R ≡ A × B.
-unification hint 0 ≔ S1,S2,a,b;
-   R ≟ PAIR S1 S2,
-   L ≟ (pair S1 S2)
-(* -------------------------------------------- *) ⊢
-   eq_pair S1 S2 a b ≡ eq_rel L (eq0 R) a b.    
+(* end setoids for pitem *)
 
-(* end move to pair *) 
 ndefinition pre ≝ λS.pitem S × bool.
 
 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
@@ -354,18 +297,6 @@ interpretation "fst" 'fst x = (fst ? ? x).
 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
 interpretation "snd" 'snd x = (snd ? ? x).
 
-interpretation "pstar" 'pk a = (pk ? a).
-interpretation "por" 'plus a b = (po ? a b).
-interpretation "pcat" 'pc a b = (pc ? a b).
-notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
-notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
-interpretation "ppatom" 'pp a = (pp ? a).
-(* to get rid of \middot *)
-ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S  ≝ pc on _p : pitem ? to ∀_:?.?.
-interpretation "patom" 'ps a = (ps ? a).
-interpretation "pepsilon" 'epsilon = (pe ?).
-interpretation "pempty" 'empty_r = (pz ?).
-
 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
  match l with
@@ -376,6 +307,7 @@ nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
   | pc E1 E2 ⇒ (|E1| · |E2|)
   | po E1 E2 ⇒ (|E1| + |E2|)
   | pk E ⇒ |E|^* ].
+  
 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
 interpretation "forget" 'forget a = (forget ? a).
 
@@ -393,85 +325,27 @@ notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}
 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
 interpretation "in_pl" 'L_pi E = (L_pi ? E).
 
-(* The caml, as some patches for it *)
-ncoercion setoid1_of_setoid : ∀s:setoid. setoid1 ≝ setoid1_of_setoid on _s: setoid to setoid1.   
-   
-alias symbol "hint_decl" (instance 1) = "hint_decl_CProp2".
-unification hint 0 ≔ S : setoid, x,y;
-  SS ≟ LIST S,
-  TT ≟ setoid1_of_setoid SS
-(*-----------------------------------------*) ⊢ 
-  eq_list S x y ≡ eq_rel1 ? (eq1 TT) x y.
-  
-unification hint 0 ≔ SS : setoid;
-  S ≟ carr SS,
-  TT ≟ setoid1_of_setoid (LIST SS)
-(*-----------------------------------------------------------------*) ⊢ 
-  list S ≡ carr1 TT.
-
-(* XXX Ex setoid support *)
-nlemma Sig: ∀S,T:setoid.∀P: S → (T → CPROP).
-  ∀y,z:T.y = z → (∀x.y=z → P x y = P x z)  → (Ex S (λx.P x y)) =_1 (Ex S (λx.P x z)).
-#S T P y z Q E; @; *; #x Px; @x; nlapply (E x Q); *; /2/; nqed.
-
-notation "∑" non associative with precedence 90 for @{Sig ?????}.
-
-nlemma test : ∀S:setoid. ∀ee: S ⇒_1 S ⇒_1 CPROP.
- ∀x,y:setoid1_of_setoid S.x =_1 y → (Ex S (λw.ee x w ∧ True)) =_1 (Ex S (λw.ee y w ∧ True)).
-#S m x y E;
-napply (.=_1 (∑ E (λw,H.(H ╪_1 #)╪_1 #))).
-napply #.
-nqed.
-
-nlemma test2 : ∀S:setoid. ∀ee: S ⇒_1 S ⇒_1 CPROP.
- ∀x,y:setoid1_of_setoid S.x =_1 y → 
-   (True ∧ (Ex S (λw.ee x w ∧ True))) =_1 (True ∧ (Ex S (λw.ee y w ∧ True))).
-#S m x y E;
-napply (.=_1 #╪_1(∑ E (λw,H.(H ╪_1 #) ╪_1 #))).
-napply #.
-nqed.
-
-nlemma ex_setoid : ∀S:setoid.(S ⇒_1 CPROP) → setoid.
-#T P; @ (Ex T (λx:T.P x)); @;
-##[ #H1 H2; napply True |##*: //; ##]
-nqed.
-
-unification hint 0 ≔ T,P ; S ≟ (ex_setoid T P) ⊢
- Ex T (λx:T.P x) ≡ carr S.
-
-nlemma test3 : ∀S:setoid. ∀ee: S ⇒_1 S ⇒_1 CPROP.
- ∀x,y:setoid1_of_setoid S.x =_1 y → 
-   ((Ex S (λw.ee x w ∧ True) ∨ True)) =_1 ((Ex S (λw.ee y w ∧ True) ∨ True)).
-#S m x y E;
-napply (.=_1 (∑ E (λw,H.(H ╪_1 #) ╪_1 #)) ╪_1 #).
-napply #.
-nqed.
-(* Ex setoid support end *)
-
+(* set support for 𝐋\p *)
 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
 #S r; @(𝐋\p r); #w1 w2 E; nelim r; 
 ##[ ##1,2: /2/;
 ##| #x; @; *;
 ##| #x; @; #H; nchange in H with ([?] =_0 ?); ##[ napply ((.=_0 H) E); ##]
     napply ((.=_0 H) E^-1);
-##| #e1 e2 H1 H2; 
+##| #e1 e2 H1 H2; (*
     nchange in match (w1 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
-    nchange in match (w2 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
+    nchange in match (w2 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?); good! *)
     napply (.= (#‡H2));
-    napply (.=_1 (∑ E (λx1,H1.∑ E (λx2,H2.?)))╪_1 #); ##[
-      ncut ((w1 = (x1@x2)) = (w2 = (x1@x2)));##[
-        @; #X; ##[ napply ((.= H1^-1) X) | napply ((.= H2) X) ] ##] #X;
-      napply ( (X‡#)‡#); ##]
-    napply #;
-##| #e1 e2 H1 H2;
-    nnormalize in ⊢ (???%%);
-    napply (H1‡H2);
-##| #e H; nnormalize in ⊢ (???%%);
-    napply (.=_1 (∑ E (λx1,H1.∑ E (λx2,H2.?)))); ##[
-      ncut ((w1 = (x1@x2)) = (w2 = (x1@x2)));##[
-        @; #X; ##[ napply ((.= H1^-1) X) | napply ((.= H2) X) ] ##] #X;
-      napply ((X‡#)‡#); ##]
-    napply #;##] 
+    ncut (∀x1,x2. (w1 = (x1@x2)) = (w2 = (x1@x2)));##[
+      #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
+    napply ((∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#) ╪_1 #); 
+##| #e1 e2 H1 H2; napply (H1‡H2); (* good! *)
+##| #e H; 
+    ncut (∀x1,x2.(w1 = (x1@x2)) = (w2 = (x1@x2)));##[
+      #x1 x2; @; #X; ##[ napply ((.= E^-1) X) | napply ((.= E) X) ] ##] #X;
+    (* nnormalize in ⊢ (???%%); good! (but a bit too hard) *)
+    napply (∑w1,w2. X w1 w2 / H ; (H╪_1#)╪_1#); 
+##]
 nqed.
 
 unification hint 0 ≔ S : Alpha,e : pitem S; 
@@ -479,6 +353,8 @@ unification hint 0 ≔ S : Alpha,e : pitem S;
   X ≟ (mk_ext_powerclass SS (𝐋\p e) (ext_prop SS (L_pi_ext S e)))
 (*-----------------------------------------------------------------*)⊢ 
   ext_carr SS X ≡ 𝐋\p e.
+
+(* end set support for 𝐋\p *)  
   
 ndefinition epsilon ≝ 
   λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
@@ -494,10 +370,10 @@ interpretation "L_pr" 'L_pi E = (L_pr ? E).
 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. [ ] = w1 @ w2 → w1 = [ ].
 #S w1; ncases w1; //. nqed.
   
-(* lemma 12 *)
+(* lemma 12 *) (* XXX: a case where Leibnitz equality could be exploited for H *)
 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
-#S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//; 
-*; ##[##2:*] nelim e;
+#S r; ncases r; #e b; @; ##[##2: #H; ncases b in H; ##[##2:*] #; @2; /2/; ##] 
+ncases b; //; *; ##[##2:*] nelim e;
 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
 ##| #r1 r2 H1 H2; *; /2/ by {}]
@@ -576,18 +452,12 @@ nchange in match (ϵ false) with ∅;
 ##| napply (.= (cup0 ? {[]})^-1); napply cupC; ##]
 nqed.
 
-(* XXX move somewere else *)
-ndefinition if': ∀A,B:CPROP. A = B → A → B.
-#A B; *; /2/. nqed.
-
-ncoercion if : ∀A,B:CPROP. ∀p:A = B. A → B ≝ if' on _p : eq_rel1 ???? to ∀_:?.?.
-
 (* theorem 16: 2 *)
 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
-#S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
+#S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2; (* oh my!
 nwhd in ⊢ (???(??%)?);
 nchange in ⊢(???%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
-nchange in ⊢(???(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
+nchange in ⊢(???(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2)); *)
 napply (.=_1 #╪_1 (epsilon_or ???));
 napply (.=_1 (cupA…)^-1);
 napply (.=_1 (cupA…)╪_1#);
@@ -601,10 +471,12 @@ nqed.
 (* XXX problem: auto does not find # (refl) when it has a concrete == *)
 nlemma odotEt : ∀S:Alpha.∀e1,e2:pitem S.∀b2:bool.
   〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
-#S e1 e2 b2; ncases b2; nnormalize; @; //; @; napply refl; nqed.
+#S e1 e2 b2; ncases b2; @; /3/ by refl, conj, I; nqed.
 
+(*
 nlemma LcatE : ∀S:Alpha.∀e1,e2:pitem S.
   𝐋\p (e1 · e2) =  𝐋\p e1 · 𝐋  |e2| ∪ 𝐋\p e2. //; nqed.
+*)
 
 nlemma cup_dotD : ∀S:Alpha.∀p,q,r:lang S.(p ∪ q) · r = (p · r) ∪ (q · r). 
 #S p q r; napply ext_set; #w; nnormalize; @; 
@@ -622,68 +494,72 @@ nlemma erase_plus : ∀S:Alpha.∀e1,e2:pitem S.𝐋 |e1 + e2| =  𝐋 |e1| ∪
 
 nlemma erase_star : ∀S:Alpha.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
 
-ndefinition substract := λS:Alpha.λp,q:lang S.{ w | w ∈ p ∧ ¬ w ∈ q }.
-interpretation "substract" 'minus a b = (substract ? a b).
-
-FINQUI: manca ext per substract
+nlemma mem_single : ∀S:setoid.∀a,b:S. a ∈ {(b)} → a = b.
+#S a b; nnormalize; /2/; nqed.
 
-nlemma memnil : ∀S:Alpha.∀a:list S. a ∈ {[]} → a = [ ].
-#S a; ncases a; //; nqed.
-
-nlemma cup_sub: ∀S:Alpha.∀a,b:Elang S. ¬ ([]∈ a) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
-#S a b c; napply ext_set; #w; @; 
-##[ *; ##[ #wa; @; ##[@;//] #H; napply c; napply (. ?╪_0?); 
-    napply (. (memnil ?? H)^-1‡#); 
-/4/; *; /4/; nqed.
+nlemma cup_sub: ∀S.∀A,B:𝛀^S.∀x. ¬ (x ∈ A) → A ∪ (B - {(x)}) = (A ∪ B) - {(x)}.
+#S A B x H; napply ext_set; #w; @; 
+##[ *; ##[ #wa; @; ##[@;//] #H2; napply H; napply (. (mem_single ??? H2)^-1╪_1#); //]
+    *; #wb nwn; @; ##[@2;//] //;
+##| *; *; ##[ #wa nwn; @; //] #wb nwn; @2; @; //;##]
+nqed.
 
-nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
-#S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
+nlemma sub0 : ∀S.∀a:Ω^S. a - ∅ = a.
+#S a; napply ext_set; #w; nnormalize; @; /3/; *; //; nqed.
 
-nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
-#S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
+nlemma subK : ∀S.∀a:Ω^S. a - a = ∅.
+#S a; napply ext_set; #w; nnormalize; @; *; /2/; nqed.
 
-nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
+nlemma subW : ∀S.∀a,b:Ω^S.∀w.w ∈ (a - b) → w ∈ a.
 #S a b w; nnormalize; *; //; nqed.
 
-nlemma erase_bull : ∀S.∀a:pitem S. .|\fst (•a)| = .|a|.
+nlemma erase_bull : ∀S:Alpha.∀a:pitem S. |\fst (•a)| = |a|.
 #S a; nelim a; // by {};
-##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| · .|e2|);
-    nrewrite < IH1; nrewrite < IH2;  
-    nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
-    ncases (•e1); #e3 b; ncases b; nnormalize;
-    ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
-##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
-    nrewrite < IH2; nrewrite < IH1;
-    nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
-    ncases (•e1); ncases (•e2); //;
-##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
-    nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
+##[ #e1 e2 IH1 IH2;
+    napply (?^-1);
+    napply (.=_0 (IH1^-1)╪_0 (IH2^-1));
+    nchange in match (•(e1 · ?)) with (?⊙?);
+    ncases (•e1); #e3 b; ncases b; ##[ nnormalize; ncases (•e2); /3/ by refl, conj]
+    napply (.=_0 #╪_0 (IH2)); //;
+##| #e1 e2 IH1 IH2; napply (?^-1);
+    napply (.=_0 (IH1^-1)╪_0(IH2^-1));
+    nchange in match (•(e1+?)) with (?⊕?);
+    ncases (•e1); ncases (•e2); //]
 nqed.
 
-nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
+(*
+nlemma eta_lp : ∀S:Alpha.∀p:pre S. 𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
 #S p; ncases p; //; nqed.
+*)
 
-nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p. 
-#S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
-*; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
-napply Hw2; nqed.
+(* XXX coercion ext_carr non applica *)
+nlemma epsilon_dot: ∀S:Alpha.∀p:Elang S. {[]} · (ext_carr ? p) = p. 
+#S e; napply ext_set; #w; @; ##[##2: #Hw; @[]; @w; @; //; @; //; napply #; (* XXX auto *) ##]
+*; #w1; *; #w2; *; *; #defw defw1 Hw2; 
+napply (. defw╪_1#); 
+napply (. ((defw1 : [ ] = ?)^-1 ╪_0 #)╪_1#);
+napply Hw2; 
+nqed.
 
 (* theorem 16: 1 → 3 *)
-nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
-      𝐋\p (•(\fst e2)) =  𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| → 
-         𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
+nlemma odot_dot_aux : ∀S:Alpha.∀e1,e2: pre S.
+      𝐋\p (•(\fst e2)) =  𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| → 
+         𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
-##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2); 
+##[ nchange in match (〈?,true〉⊙?) with 〈?,?〉; 
+    nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2); 
     nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
-    nchange in ⊢ (??%?) with (?∪?); 
-    nchange in ⊢ (??(??%?)?) with (?∪?);
-    nchange in match (𝐋\p 〈?,?〉) with (?∪?);
-    nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
-    nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
-    nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
-      nchange with (𝐋\p 〈e2'',b2''〉 =  𝐋\p e2' ∪ 𝐋 .|e2'|); 
-      ngeneralize in match th1;
-      nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
+    napply (.=_1 (# ╪_1 (epsilon_or …))); (* XXX … is too slow if combined with .= *)
+    nchange in match b2'' with b2''; (* XXX some unfoldings happened *)
+    nchange in match b2' with b2';
+    napply (.=_1 (# ╪_1 (cupC …))); napply (.=_1 (cupA …)); 
+    napply (.=_1 (# ╪_1 (cupA …)^-1)); (* XXX slow, but not because of disamb! *)
+    ncut (𝐋\p e2'' ∪ ϵ b2'' =  𝐋\p e2' ∪ 𝐋  |e2'|); ##[
+      nchange with (𝐋\p 〈e2'',b2''〉 =  𝐋\p e2' ∪ 𝐋 |e2'|);
+      napply (?^-1); napply (.=_1 th1^-1); //;##] #E;
+    napply (.=_1 (# ╪_1 (E ╪_1 #)));
+    STOP  
+      
     nrewrite > (eta_lp ? e2); 
     nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
     nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);