+coercion setoid1_of_REL.
+
+definition comprehension: ∀b:REL. (b ⇒ CPROP) → Ω \sup b.
+ apply (λb:REL. λP: b ⇒ CPROP. {x | x ∈ b ∧ P x});
+ intros; simplify; apply (.= (H‡#)‡(†H)); apply refl1.
+qed.
+
+interpretation "subset comprehension" 'comprehension s p =
+ (comprehension s (mk_unary_morphism __ p _)).
+
+definition ext: ∀X,S:REL. binary_morphism1 (arrows1 ? X S) S (Ω \sup X).
+ apply (λX,S.mk_binary_morphism1 ??? (λr:arrows1 ? X S.λf:S.{x ∈ X | x ♮r f}) ?);
+ [ intros; simplify; apply (.= (H‡#)); apply refl1
+ | intros; simplify; split; intros; simplify; intros; cases f; split; try assumption;
+ [ apply (. (#‡H1)); whd in H; apply (if ?? (H ??)); assumption
+ | apply (. (#‡H1\sup -1)); whd in H; apply (fi ?? (H ??));assumption]]
+qed.
+
+definition extS: ∀X,S:REL. ∀r: arrows1 ? X S. Ω \sup S ⇒ Ω \sup X.
+ (* ∃ is not yet a morphism apply (λX,S,r,F.{x ∈ X | ∃a. a ∈ F ∧ x ♮r a});*)
+ intros (X S r); constructor 1;
+ [ intro F; constructor 1; constructor 1;
+ [ apply (λx. x ∈ X ∧ ∃a:S. a ∈ F ∧ x ♮r a);
+ | intros; split; intro; cases f (H1 H2); clear f; split;
+ [ apply (. (H‡#)); assumption
+ |3: apply (. (H\sup -1‡#)); assumption
+ |2,4: cases H2 (w H3); exists; [1,3: apply w]
+ [ apply (. (#‡(H‡#))); assumption
+ | apply (. (#‡(H \sup -1‡#))); assumption]]]
+ | intros; split; simplify; intros; cases f; cases H1; split;
+ [1,3: assumption
+ |2,4: exists; [1,3: apply w]
+ [ apply (. (#‡H)‡#); assumption
+ | apply (. (#‡H\sup -1)‡#); assumption]]]
+qed.
+
+lemma equalset_extS_id_X_X: ∀o:REL.∀X.extS ?? (id1 ? o) X = X.
+ intros;
+ unfold extS; simplify;
+ split; simplify;
+ [ intros 2; change with (a ∈ X);
+ cases f; clear f;
+ cases H; clear H;
+ cases x; clear x;
+ change in f2 with (eq1 ? a w);
+ apply (. (f2\sup -1‡#));
+ assumption
+ | intros 2; change in f with (a ∈ X);
+ split;
+ [ whd; exact I
+ | exists; [ apply a ]
+ split;
+ [ assumption
+ | change with (a = a); apply refl]]]
+qed.
+
+lemma extS_com: ∀o1,o2,o3,c1,c2,S. extS o1 o3 (c2 ∘ c1) S = extS o1 o2 c1 (extS o2 o3 c2 S).
+ intros; unfold extS; simplify; split; intros; simplify; intros;
+ [ cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
+ cases H3 (H4 H5); cases H5 (w1 H6); clear H3 H5; cases H6 (H7 H8); clear H6;
+ exists; [apply w1] split [2: assumption] constructor 1; [assumption]
+ exists; [apply w] split; assumption
+ | cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
+ cases H3 (H4 H5); cases H4 (w1 H6); clear H3 H4; cases H6 (w2 H7); clear H6;
+ cases H7; clear H7; exists; [apply w2] split; [assumption] exists [apply w] split;
+ assumption]
+qed.
+
+(* the same as ⋄ for a basic pair *)
+definition image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V).
+ intros; constructor 1;
+ [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∃x:U. x ♮r y ∧ x ∈ S});
+ intros; simplify; split; intro; cases H1; exists [1,3: apply w]
+ [ apply (. (#‡H)‡#); assumption
+ | apply (. (#‡H \sup -1)‡#); assumption]
+ | intros; split; simplify; intros; cases H2; exists [1,3: apply w]
+ [ apply (. #‡(#‡H1)); cases x; split; try assumption;
+ apply (if ?? (H ??)); assumption
+ | apply (. #‡(#‡H1 \sup -1)); cases x; split; try assumption;
+ apply (if ?? (H \sup -1 ??)); assumption]]
+qed.
+
+(* the same as □ for a basic pair *)
+definition minus_star_image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V).
+ intros; constructor 1;
+ [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∀x:U. x ♮r y → x ∈ S});
+ intros; simplify; split; intros; apply H1;
+ [ apply (. #‡H \sup -1); assumption
+ | apply (. #‡H); assumption]
+ | intros; split; simplify; intros; [ apply (. #‡H1); | apply (. #‡H1 \sup -1)]
+ apply H2; [ apply (if ?? (H \sup -1 ??)); | apply (if ?? (H ??)) ] assumption]
+qed.
+
+(* minus_image is the same as ext *)
+
+theorem image_id: ∀o,U. image o o (id1 REL o) U = U.
+ intros; unfold image; simplify; split; simplify; intros;
+ [ change with (a ∈ U);
+ cases H; cases x; change in f with (eq1 ? w a); apply (. f‡#); assumption
+ | change in f with (a ∈ U);
+ exists; [apply a] split; [ change with (a = a); apply refl | assumption]]
+qed.
+
+theorem minus_star_image_id: ∀o,U. minus_star_image o o (id1 REL o) U = U.
+ intros; unfold minus_star_image; simplify; split; simplify; intros;
+ [ change with (a ∈ U); apply H; change with (a=a); apply refl
+ | change in f1 with (eq1 ? x a); apply (. f1 \sup -1‡#); apply f]
+qed.
+
+theorem image_comp: ∀A,B,C,r,s,X. image A C (r ∘ s) X = image B C r (image A B s X).
+ intros; unfold image; simplify; split; simplify; intros; cases H; clear H; cases x;
+ clear x; [ cases f; clear f; | cases f1; clear f1 ]
+ exists; try assumption; cases x; clear x; split; try assumption;
+ exists; try assumption; split; assumption.
+qed.
+
+theorem minus_star_image_comp:
+ ∀A,B,C,r,s,X.
+ minus_star_image A C (r ∘ s) X = minus_star_image B C r (minus_star_image A B s X).
+ intros; unfold minus_star_image; simplify; split; simplify; intros; whd; intros;
+ [ apply H; exists; try assumption; split; assumption
+ | change with (x ∈ X); cases f; cases x1; apply H; assumption]
+qed.
+
+(*CSC: unused! *)
+theorem ext_comp:
+ ∀o1,o2,o3: REL.
+ ∀a: arrows1 ? o1 o2.
+ ∀b: arrows1 ? o2 o3.
+ ∀x. ext ?? (b∘a) x = extS ?? a (ext ?? b x).
+ intros;
+ unfold ext; unfold extS; simplify; split; intro; simplify; intros;
+ cases f; clear f; split; try assumption;
+ [ cases f2; clear f2; cases x1; clear x1; exists; [apply w] split;
+ [1: split] assumption;
+ | cases H; clear H; cases x1; clear x1; exists [apply w]; split;
+ [2: cases f] assumption]
+qed.
+
+theorem extS_singleton:
+ ∀o1,o2.∀a:arrows1 ? o1 o2.∀x.extS o1 o2 a (singleton o2 x) = ext o1 o2 a x.
+ intros; unfold extS; unfold ext; unfold singleton; simplify;
+ split; intros 2; simplify; cases f; split; try assumption;
+ [ cases H; cases x1; change in f2 with (eq1 ? x w); apply (. #‡f2 \sup -1);
+ assumption
+ | exists; try assumption; split; try assumption; change with (x = x); apply refl]
+qed.
\ No newline at end of file