Morphism epimorphism if and only if surjective In the category of sets, I want to prove that a morphism is an epimorphism if and only if it is surjective.
In both directions, I'm having a hard time approaching this problem.
This is how far I got.
$$\text{Morphism is epimorphism} \implies \text{Morphism is surjective}:$$
Let $\phi: A \to B$ be an epimorphism. 
For any morphisms $\beta,\beta': B \to Y$, we have 
$$ \beta \ \circ \ \phi = \beta' \ \circ \phi \implies \beta = \beta'.
$$
$$\vdots$$
$$\text{Morphism is surjective}\implies \text{Morphism is epimorphism} :$$
Pick an arbitrary $b \in B$.
Since $\phi$ is surjective there exists an $a\in A$ such that $b = \phi(a)$.
Set $y = \beta(\phi(a)) = \beta'(\phi(a))$.
$$\vdots$$ 
 A: Some hints:


*

*For epic $\Rightarrow$ surjective, let $Y=B \cup \{ \star \}$ (where $\star \not \in B$), let $\beta$ be the identity on $B$, and let $\beta'$ be the map which sends everything in the image of $\phi$ to itself, and everything not in the image of $\phi$ to $\star$. See what happens.

*For surjective $\Rightarrow$ epic, just show that if $\beta,\beta' : B \to Y$ and $\beta \circ \phi = \beta' \circ \phi$, then $\beta(b)=\beta'(b)$ for all $b \in B$. Use the fact that $\phi$ is surjective to write a given $b \in B$ in a more useful way.
A: If $f:X\to Y$ is an epimorphism, define $g_1:Y\to\{0,1\}$ with $g_1(y)=0$ for all $y\in Y$, and $$g_2(y)=\begin{cases}0&y\in\mathrm{im}(f)\\1&\text{otherwise}\end{cases}$$
Then for $x\in X$ we see that $g_1\circ f (x)=0= g_2\circ f(x)$. From the property of epimorphism, this means that $g_1=g_2$, which is only possible if $\mathrm{im}(f)$ is all of $Y$.
Now, if $f$ is surjective, then take $g_1,g_2:Y\to Z$ with $g_1\circ f = g_2\circ f$. Then for any $y\in Y$, we can find $x\in X$ such that $f(x)=y$. Then $$g_1(y)=g_1\circ f (x)=g_2\circ f(x)=g_2(y)$$
So $g_1=g_2$.
A: I will give a constructive (or, more precisely, intuitionistic) proof.
First, the easy direction: surjective maps are epimorphisms. Indeed, if $f : X \to Y$ is surjective and $g_0 \circ f = g_1 \circ f$, then $g_0 = g_1$, i.e. for every $y \in Y$, $g_0 (y) = g_1 (y)$, because there is $x \in X$ such that $y = f(x)$ and therefore $g_0 (y) = g_0 (f (x)) = g_1 (f (x)) = g_1 (y)$.
Now, the harder direction: epimorphisms are surjective. Suppose $f : X \to Y$ is an epimorphism. Let $\Omega$ be the set of subsets of $\{ 0 \}$, let $g_0 : Y \to \Omega$ be the constant map with value $\{ 0 \}$, and let $g_1 : Y \to \Omega$ be defined as follows:
$$0 \in g_1 (y) \iff \exists x \in X . f (x) = y$$
By construction, $g_0 \circ f = g_1 \circ f$; but then $g_0 = g_1$, so for every $y \in Y$, there is $x \in X$ such that $f (x) = y$, i.e. $f : X \to Y$ is surjective.
A: To show that a surjective function is epic, just check the equality pointwise. If $X \overset{f}{\to} Y$ is your surjection, and $g_1, g_2 : Y \to Z$ are two functions you want to test with $f$, see that $$g_1 \circ f = g_2 \circ f \iff \forall x \in X, g_1(f(x)) = g_2(f(x)) \overset{\text{surj.}}{\implies} g_1 = g_2,$$ since surjectivity tells us that $g_1$ and $g_2$ now agree everywhere on $Y$.
To show that an epimorphism is a surjection, show the contrapositive. If $X \overset{f}{\to} Y$ is not a surjection, i.e. the image $\operatorname{im}(f)$ is a proper subset of $Y$, then choose a surjection $\pi : Y \twoheadrightarrow \operatorname{im}(f)$. Consider the map $Y \overset{\pi}{\twoheadrightarrow} \operatorname{im}(f) \hookrightarrow Y.$ This is clearly not the identity on $Y$. Yet, if you precompose $\operatorname{id}_Y$ with $f$, you get the same thing as precomposing $Y \overset{\pi}{\twoheadrightarrow} \operatorname{im}(f) \hookrightarrow Y$ with $f$. So $f$ fails to be right-cancellative, which is the contrapositive.
A: Suppose $f\colon A\to B$ is any map, with $A\ne\emptyset$. Consider the relation $\sim$ on $B$ defined by $x\sim y$ if and only if $x\in f(A)$ and $y\in f(A)$ or $x\notin f(A)$ and $y\notin f(A)$.
It is clear that $\sim$ is an equivalence relation on $B$, so we can consider the canonical projection $p\colon B\to B/{\sim}$ and also the map $q\colon B\to B/{\sim}$ defined by $q(b)=[f(a)]_{\sim}$, where $a\in A$ and, for $b\in B$, $[b]_{\sim}$ is the equivalence class of $b$.
It is clear that $p\circ f=q\circ f$. However, if $b\notin f(A)$, we clearly have $p\ne q$, because $p(b)=[b]_{\sim}\ne[f(a)]_{\sim}=q(b)$. Therefore $f$ is not epic.
If $A=\emptyset$, then $f$ epic implies that, for each set $C$, there exists a unique map $B\to C$. Therefore $B$ is an initial object and so $B=\emptyset$. Therefore $f$ is surjective.
The converse, that is “surjective implies epic”, is easy to prove.
