+nlemma intersect_ok: ∀A. binary_morphism1 (ext_powerclass_setoid A) (ext_powerclass_setoid A) (ext_powerclass_setoid A).
+ #A; @
+ [ #S; #S'; @
+ [ napply (S ∩ S')
+ | #a; #a'; #Ha;
+ nwhd in ⊢ (? ? ? % %); @; *; #H1; #H2; @
+ [##1,2: napply (. Ha^-1‡#); nassumption;
+ ##|##3,4: napply (. Ha‡#); nassumption]##]
+ ##| #a; #a'; #b; #b'; #Ha; #Hb; nwhd; @; #x; nwhd in ⊢ (% → %); #H
+ [ alias symbol "invert" = "setoid1 symmetry".
+ alias symbol "refl" = "refl".
+alias symbol "prop2" = "prop21".
+napply (. ((#‡Ha^-1)‡(#‡Hb^-1))); nassumption
+ | napply (. ((#‡Ha)‡(#‡Hb))); nassumption ]##]
+nqed.
+
+(* unfold if intersect, exposing fun21 *)
+alias symbol "hint_decl" = "hint_decl_Type1".
+unification hint 0 ≔
+ A : setoid, B,C : ext_powerclass A ⊢
+ pc A (fun21 …
+ (mk_binary_morphism1 …
+ (λS,S':qpowerclass_setoid A.mk_qpowerclass ? (S ∩ S') (mem_ok' ? (intersect_ok ? S S')))
+ (prop21 … (intersect_ok A)))
+ B
+ C)
+ ≡ intersect ? (pc ? B) (pc ? C).
+
+nlemma test: ∀A:setoid. ∀U,V:qpowerclass A. ∀x,x':setoid1_of_setoid A. x=x' → x ∈ U ∩ V → x' ∈ U ∩ V.
+ #A; #U; #V; #x; #x'; #H; #p; napply (. (H^-1‡#)); nassumption.
+nqed.
+*)
+
+ndefinition image: ∀A,B. (carr A → carr B) → Ω^A → Ω^B ≝
+ λA,B:setoid.λf:carr A → carr B.λSa:Ω^A.
+ {y | ∃x. x ∈ Sa ∧ eq_rel (carr B) (eq0 B) (f x) y}.
+
+ndefinition counter_image: ∀A,B. (carr A → carr B) → Ω^B → Ω^A ≝
+ λA,B,f,Sb. {x | ∃y. y ∈ Sb ∧ f x = y}.
+
+(******************* compatible equivalence relations **********************)
+
+nrecord compatible_equivalence_relation (A: setoid) : Type[1] ≝
+ { rel:> equivalence_relation A;
+ compatibility: ∀x,x':A. x=x' → rel x x'
+ }.
+
+ndefinition quotient: ∀A. compatible_equivalence_relation A → setoid.
+ #A; #R; @ A R;
+nqed.
+
+(******************* first omomorphism theorem for sets **********************)
+
+ndefinition eqrel_of_morphism:
+ ∀A,B. unary_morphism A B → compatible_equivalence_relation A.
+ #A; #B; #f; @
+ [ @ [ napply (λx,y. f x = f y) ] /2/;
+##| #x; #x'; #H; nwhd; alias symbol "prop1" = "prop1".
+napply (.= (†H)); // ]
+nqed.
+
+ndefinition canonical_proj: ∀A,R. unary_morphism A (quotient A R).
+ #A; #R; @
+ [ napply (λx.x) | #a; #a'; #H; napply (compatibility … R … H) ]
+nqed.
+
+ndefinition quotiented_mor:
+ ∀A,B.∀f:unary_morphism A B.
+ unary_morphism (quotient … (eqrel_of_morphism … f)) B.
+ #A; #B; #f; @ [ napply f ] //.
+nqed.
+
+nlemma first_omomorphism_theorem_functions1:
+ ∀A,B.∀f: unary_morphism A B.
+ ∀x. f x = quotiented_mor … (canonical_proj … (eqrel_of_morphism … f) x).
+//. nqed.