+(**************************************************************************)
+(* ___ *)
+(* ||M|| *)
+(* ||A|| A project by Andrea Asperti *)
+(* ||T|| *)
+(* ||I|| Developers: *)
+(* ||T|| The HELM team. *)
+(* ||A|| http://helm.cs.unibo.it *)
+(* \ / *)
+(* \ / This file is distributed under the terms of the *)
+(* v GNU General Public License Version 2 *)
+(* *)
+(**************************************************************************)
+
+include "logic/connectives.ma".
+
+nrecord powerset (A: Type) : Type[1] ≝ { mem: A → CProp }.
+(* This is a projection! *)
+ndefinition mem ≝ λA.λr:powerset A.match r with [mk_powerset f ⇒ f].
+
+interpretation "powerset" 'powerset A = (powerset A).
+
+interpretation "subset construction" 'subset \eta.x = (mk_powerset ? x).
+
+interpretation "mem" 'mem a S = (mem ? S a).
+
+ndefinition subseteq ≝ λA.λU,V.∀a:A. a ∈ U → a ∈ V.
+
+interpretation "subseteq" 'subseteq U V = (subseteq ? U V).
+
+ntheorem subseteq_refl: ∀A.∀S:Ω \sup A.S ⊆ S.
+ #A; #S; #x; #H; nassumption;
+nqed.
+
+ntheorem subseteq_trans: ∀A.∀S1,S2,S3: Ω \sup A. S1 ⊆ S2 → S2 ⊆ S3 → S1 ⊆ S3.
+ #A; #S1; #S2; #S3; #H12; #H23; #x; #H;
+ napply (H23 ??); napply (H12 ??); nassumption;
+nqed.
+
+ndefinition overlaps ≝ λA.λU,V:Ω \sup A.∃x:A.x ∈ U ∧ x ∈ V.
+
+interpretation "overlaps" 'overlaps U V = (fun1 ??? (overlaps ?) U V).
+
+definition intersects:
+ ∀A. binary_morphism1 (powerset_setoid A) (powerset_setoid A) (powerset_setoid A).
+ intros;
+ constructor 1;
+ [ apply (λU,V. {x | x ∈ U ∧ x ∈ V });
+ intros; simplify; apply (.= (H‡#)‡(H‡#)); apply refl1;
+ | intros;
+ split; intros 2; simplify in f ⊢ %;
+ [ apply (. (#‡H)‡(#‡H1)); assumption
+ | apply (. (#‡(H \sup -1))‡(#‡(H1 \sup -1))); assumption]]
+qed.
+
+interpretation "intersects" 'intersects U V = (fun1 ??? (intersects ?) U V).
+
+definition union:
+ ∀A. binary_morphism1 (powerset_setoid A) (powerset_setoid A) (powerset_setoid A).
+ intros;
+ constructor 1;
+ [ apply (λU,V. {x | x ∈ U ∨ x ∈ V });
+ intros; simplify; apply (.= (H‡#)‡(H‡#)); apply refl1
+ | intros;
+ split; intros 2; simplify in f ⊢ %;
+ [ apply (. (#‡H)‡(#‡H1)); assumption
+ | apply (. (#‡(H \sup -1))‡(#‡(H1 \sup -1))); assumption]]
+qed.
+
+interpretation "union" 'union U V = (fun1 ??? (union ?) U V).
+
+definition singleton: ∀A:setoid. unary_morphism A (Ω \sup A).
+ intros; constructor 1;
+ [ apply (λA:setoid.λa:A.{b | a=b});
+ intros; simplify;
+ split; intro;
+ apply (.= H1);
+ [ apply H | apply (H \sup -1) ]
+ | intros; split; intros 2; simplify in f ⊢ %; apply trans;
+ [ apply a |4: apply a'] try assumption; apply sym; assumption]
+qed.
+
+interpretation "singleton" 'singl a = (fun_1 ?? (singleton ?) a).
\ No newline at end of file