Condition for Composite Mapping on Left

Theorem
Let $A, B, C$ be sets.

Suppose that $C$ is non-empty.

Let $f: A \to B$ and $g: A \to C$ be mappings.

Let $\mathcal R: B \to C$ be a relation such that $g = \mathcal R \circ f$ is the composite of $f$ and $\mathcal R$.

Then $\mathcal R$ may be a mapping iff:
 * $\forall x, y \in A: f \left({x}\right) = f \left({y}\right) \implies g \left({x}\right) = g \left({y}\right)$

That is:
 * $\forall x, y \in A: f \left({x}\right) = f \left({y}\right) \implies g \left({x}\right) = g \left({y}\right)$

iff:
 * $\exists h: B \to C$ such that $h$ is a mapping and $h \circ f = g$

Sufficient Condition
Suppose $\forall x, y \in A: f \left({x}\right) = f \left({y}\right) \implies g \left({x}\right) = g \left({y}\right)$.

Consider the subset $G \subseteq \operatorname{Im} \left({f}\right) \times C$ defined by:
 * $G = \left\{{\left({y, z}\right): \exists x \in A: y = f \left({x}\right), z = g \left({x}\right)}\right\}$

Clearly $G \ne \varnothing$ because for any $x \in A$ we have $\left({f \left({x}\right), g \left({x}\right)}\right) \in G$.

What we need to show is that $G$ is the graph of a mapping $t: \operatorname{Im} \left({f}\right) \to C$.

To do that, we need to show that for every $y \in \operatorname{Im} \left({f}\right)$, there is a unique $z \in C$ such that $\left({y, z}\right) \in G$.

It is clear that there is at least one such $z$: choose any $x \in A$ such that $y = f \left({x}\right)$ and set $z = g \left({x}\right)$.

Now we need to show that such a $z$ is unique.

Suppose we have $\left({y, z}\right) \in G$ and $\left({y, z'}\right) \in G$.

Then by the definition of $G$:
 * $\exists x, x' \in A: y = f \left({x}\right) = f \left({x'}\right), z = g \left({x}\right), z' = g \left({x'}\right)$

We have taken as a hypothesis that:
 * $\forall x, y \in A: f \left({x}\right) = f \left({y}\right) \implies g \left({x}\right) = g \left({y}\right)$

So $g \left({x}\right) = g \left({x'}\right)$ and so $z = z'$.

So $G$ is the graph of a mapping which we can denote:
 * $t: \operatorname{Im} \left({f}\right) \to C$

Also, since:
 * $\forall x \in A: \left({f \left({x}\right), g \left({x}\right)}\right) \in G$

it follows that:
 * $\forall x \in A: f \left({x}\right) = t \left({f \left({x}\right)}\right)$

Since $C$ is non-empty, it has an element $c$.

By Law of Excluded Middle, we can now construct a mapping $h$ as follows:
 * $h \left({x}\right) = \begin{cases}

t \left({x}\right) & : x \in \operatorname{Im} \left({f}\right) \\ c                  & : x \in B \setminus \operatorname{Im} \left({f}\right) \end{cases}$

So:
 * $\forall x \in A: \left({h \circ f}\right) \left({x}\right) = h \left({f \left({x}\right)}\right) = t \left({f \left({x}\right)}\right) = g \left({x}\right)$

Thus we have constructed a mapping $h$ such that $h \circ f = g$, as required.

Necessary Condition
Suppose there exists some mapping $h: B \to C$ such that $h \circ f = g$.

Let $f \left({x}\right) = f \left({y}\right)$. Then:

Then we have:

Comment
Hence we have a necessary and sufficient condition for determining whether the composition of mappings actually exists as a mapping.

Note that this is different from being given two mappings and creating their composition.