# Set Theory: show that function h is injective

If $h$ belongs to the set of functions from $X$ to $X$, why is $h$ injective if and only if, for any functions $f$ and $g$ in that set, if $h \circ f = h \circ g$, then $f=g$?

I'm trying to understand this question about set theory. I'm studying Halmos's Naive Set Theory book. I'll post my progress later (if any :/)

So, h composite f means the domain of h equals the range of f. h composite g means the domain of h equals the range of g. then the range of f and g are the same.

$h$ is injective iff $h(x)=h(y)$ implies $x=y$.
Suppose $h$ is injective. Then if $(h \circ f)(x) = h(f(x))= (h \circ g)(x) = h(g(x))$, it follows that $f(x)=g(x)$. Since $x$ is arbitrary, we have $f=g$.
Now suppose that $(h \circ f) = (h \circ g)$ implies $f=g$. Now suppose $h(x)=h(y)$. Let $f(t) = x, g(t) = y$ for all $t$ in the domain. Then $h(x)=h(y)$ implies $(h \circ f)(t) = h(x)= (h \circ g)(t) = h(y)$ for all $t$, or in otherwords, $(h \circ f) = (h \circ g)$. Hence $f=g$, and so $f(t)=g(t)$, or in other words, $x=y$. Hence $h$ is injectve.