# Are epimorphisms in the category of magmas surjective?

The question says it all, but let me recall the definitions.

• A magma $$(X, \cdot)$$ is a set $$X$$ with a binary operation $$\cdot \colon X \times X \to X$$ (without any further assumptions like associativity).
• A morphism between two magmas $$X$$ and $$Y$$ is a map $$f \colon X \to Y$$ with $$f(a \cdot b) = f(a) \cdot f(b)$$ for all $$a, b\in X$$.
• A morphism $$f$$ is epi, respectively mono, if one can cancel it from the right, respectively left: $$g \circ f = h \circ f \implies g=h$$, respectively $$f \circ g = f \circ h \implies g = h$$.

Using free magmas with one generator shows that monomorphisms are injective. The question is whether epimorphisms are always surjective (in many other categories this fails, e.g., in the category of monoids).

Yes. Suppose $f:X\to Y$ is not surjective, and let $Z$ be the complement of $f(X)$ in $Y$. Then the disjoint union $f(X)\cup Z\cup Z'$ of $f(X)$ and two copies of $Z$ can be given a magma structure so that the two obvious embeddings of $Y$ (as $f(X)\cup Z$ and $f(X)\cup Z'$) are inclusions of submagmas, and have the same composition with $f$. Products of elements of $Z$ with elements of $Z'$ can be defined arbitrarily.
Given an algebraic category in which every monomorphism is regular, then every epimorphism is surjective. In fact, if $X \to Y$ is an epimorphism and $X \to Q \to Y$ is its image factorization, then $Q \to Y$ is a monomorphism, hence regular, but also an epimorphism, and hence an isomorphism. This result is usually used to show that epimorphisms of groups are surjective. But it can also be used to show that epimorphisms of magmas are surjective (and this is precisely what Jeremy Rickard's answer does): Let $(X,\cdot)$ be a submagma of $(Y,\cdot)$, let $Z$ be the complement of $X \subseteq Y$. Consider $Q = X \sqcup Z \sqcup Z$. Make it into a magma in such a way that the two inclusion maps $Y \to Q$ become magma morphisms $(Y,\cdot) \rightrightarrows (Q,\cdot)$ and the products between elements of the copies of $Z$ can be defined arbitrarily. Then $(X,\cdot) \to (Y,\cdot) \rightrightarrows (Q,\cdot)$ is an equalizer.