Show $f(x) = (h \circ g)(x) $ for these given conditions Let $f \in {}^AC,$ $g \in {}^{A}B$ (a function $f$ that has domain A, codomain C, and a function $g$ that has domain A and codomain B, respectively). And the following conditions are satisfied:
1) $\operatorname{img}(g) = B$
2) $g^{-1}\{g(x)\} \subseteq f^{-1}\{f(x)\}$  for every $x \in A. $
Prove that $$ h:= \{(g(a), f(a)) \mid  a \in A \} $$ is a function that makes the following diagram commutative:
$\require{AMScd}$
\begin{CD}
    A @>f>> C\\
    @V g  VV \\
    B 
\end{CD}
So tried proving that $f(x) = (h \circ  g)(x) ,$ but I did it wrong, because I first wrote $f(a) = (h \circ  g)(a) = (h \circ  g)(b) = f(b),  $ which uses the fact that $f $ is a function and that is what I want to prove. And then I mentioned: $\operatorname{img}(g) = B$, so $g$ has a right inverse function, for some $g^{-1}.$ I did this so that I could try using the second condition, but I didn't figure out how. 
I did show that $\operatorname{img}(h) \subseteq C,$ which was the problem hint.
 A: Step 0: $\operatorname{dom}(h) = B$.
Proof. This follows immediately from $\operatorname{img}(g) = B$. Q.E.D.
Step 1: $h$ is a function.
Proof. We have to show that, for all $a,b \in A$
$$
g(a) = g(b) \implies f(a) = f(b).
$$
Fix $a \in A$. Then for any $b \in A$ with $g(a) = g(b)$ we have $b \in g^{-1} \{g(a) \} \subseteq f^{-1} \{f(a) \}$, i.e. $f(b) = f(a)$, as desired. Q.E.D.
Step 2: $h \circ g = f$.
Proof. Let $a \in A$. Then
$$
\begin{align*}
h \circ g (a) &= h(g(a)) \\
&= f(a)
\end{align*}
$$
by definition of $h$. Q.E.D.
A: Here is a proof in a different style, which might be helpful.  See e.g. EWD1300 for more backgroud on designing and writing proofs in this style.$%
\newcommand{\calc}{\begin{align} \quad &}
\newcommand{\op}[1]{\\ #1 \quad & \quad \unicode{x201c}}
\newcommand{\hints}[1]{\mbox{#1} \\ \quad & \quad \phantom{\unicode{x201c}} }
\newcommand{\hint}[1]{\mbox{#1} \unicode{x201d} \\ \quad & }
\newcommand{\endcalc}{\end{align}}
\newcommand{\subcalch}[1]{\\ \quad & \quad #1 \\ \quad &}
\newcommand{\subcalc}{\quad \begin{aligned} \quad & \\ \bullet \quad & }
\newcommand{\endsubcalc}{\end{aligned} \\ \\ \cdot \quad &}
\newcommand{\Ref}[1]{\text{(#1)}}
\newcommand{\then}{\Rightarrow}
\newcommand{\when}{\Leftarrow}
%$
You are asked to prove $\;f = h \mathop\circ g\;$.  So let's try and calculate which pairs $\;(a,c)\;$ are in the most complex side, the right hand side, and expand definitions and simplify and work towards the other side: for any $\;a,c\;$ we have
$$\calc
    \tag{R}
    (a,c) \in h \mathop\circ g
\op=\hint{definition of $\;\mathop\circ\;$}
    \langle \exists b :: (a,b) \in g \;\land\; (b,c) \in h \rangle
\op=\hint{left part: $\;g\;$ is a function; right part: definition of $\;h\;$}
    \langle \exists b :: g(a)=b \;\land\; \langle \exists a' : a' \in A : g(a') = b \;\land\; f(a') = c \rangle \rangle
\op=\hint{logic: eliminate $\;b\;$ using one-point rule}
    \langle \exists a' : a' \in A : g(a') = g(a) \;\land\; f(a') = c \rangle
\endcalc$$
Now we cannot make any progress without using what we are given about the connection between $\;g\;$ and $\;f\;$, viz. condition $\Ref{2}$:
$$\calc
    \tag{2}
    \langle \forall a' : a' \in A: g^{-1}\{g(a')\} \subseteq f^{-1}\{f(a')\} \rangle
\op=\hint{definition of $\;\subseteq\;$}
    \langle \forall a',a'' : a' \in A : a'' \in g^{-1}\{g(a')\} \;\then\; a'' \in f^{-1}\{f(a')\} \rangle
\op=\hints{basic property of $\;\dots^{-1}\{\dots\}\;$, twice,}
    \hint{using the fact that $\;g\;$ and $\;f\;$ are functions}
    \langle \forall a',a'' : a' \in A : g(a'') = g(a') \;\then\; f(a'') = f(a') \rangle
    \tag{*}
\endcalc$$
So we can use this to continue the first calculation:
$$\calc
    \dots
\op=\hint{replace $\;f(a')\;$ by $\;f(a)\;$ using $\Ref{*}$ with $\;a'':=a\;$}
    \langle \exists a' : a' \in A : g(a') = g(a) \;\land\; f(a) = c \rangle
\op=\hint{logic: extract part not using $\;a'\;$ out of $\;\exists a'\;$}
    \langle \exists a' : a' \in A : g(a') = g(a) \rangle \;\land\; f(a) = c
\op=\hints{left part follows from condition $\Ref{1}$ which says that}
    \hints{for all $\;b\;$ in the codomain of $\;g\;$, $\;\langle \exists a' : a' \in A : g(a') = b \rangle\;$;}
    \hint{change notation in right part}
    (a,c) \in f
    \tag{L}
\endcalc$$
And by set extensionality, this proves that $\;h \mathop\circ g \;=\; f\;$.
