How to approach questions that ask to prove a function exists? Consider the functions $r:S\rightarrow Q$ and $h:S\rightarrow T$ for arbitrary sets $S,T$ and $Q$. Prove that:
if
$$r(y)=r(x)\Rightarrow h(y)=h(x) $$
then we can find a function $g:Q\rightarrow T$ such that
$$ h(y)=g(r(y))$$
I am not sure how to approach this kind of proofs.
I am inclined to do the following:
Assume there exists a function $g:Q\rightarrow T$ . Then $$r(x)=r(y)\Rightarrow g(r(x))=g(r(y))$$
The above does not look helpful in proving the conclusion. In fact, I don't even think that the first step is correct, since it looks like I am assuming the conclusion is true. I thought of starting by assuming that that $h(y)=g(r(y))$ is true but this also looks like I am assuming the conclusion is true.
Please advise. I am aware that I need to show two things:


*

*$g$ is a function, which means for $q_1,q_2\in Q, q_1=q_2 \Rightarrow g(q_1)=g(q_2)$

*$h(y)=g(r(y))$

 A: You have to define a $g \colon Q \to T$ such that $h = g \circ r$ holds. So you have to tell what is $g(q)$ for each $q \in Q$. Fix an element $t_0 \in T$. Let $q \in Q$ be given, we consider two cases:


*

*$q \not\in r[S]$, that is, there is no $y \in S$ for which $r(y) = q$. Then let $g(q) = t_0$ (what you do here, does not really matter, as far as you do something well-defined, that makes $g$ a function).

*$q \in r[S]$. So there is some $y \in S$ with $r(y) = q$. We let $g(q) = h(y)$. We have to check that this does not depend on the choice of $y$ (as otherwise $g$ is no function): If $q = r(y_1)$ and $q = r(y_2)$ we have $r(y_1) = r(y_2)$, hence $h(y_1) = h(y_2)$ by assumption. 


We have by the above defined a function $g \colon Q \to T$, which by construction has $h = g \circ r$: Let $y \in Y$, write $q = r(y)$. Then (we are in the second case) $$g\bigl(r(y)\bigr) = g(q) = h(y).$$
A: The idea is this: we would like to define our function by
$$
g(r(y)) = h(y)
$$
There are two important things to note here: 
First, the above statement only defines $g$ over the image of $r$, which might not be all of $Q$.  For any other $q \in Q$, we just need to say something like "make $g(q)$ any value in $T$"; it doesn't matter which value you pick.
Second, this definition would not make $g$ a function for any $r$ and $h$; the information given is important in showing that this $g$, as defined, is really a function.  In particular, how do we know that $g$ has exactly one value at $r(y)$ for any $y \in S$?
