Munkres Lemma 2.1 I'm trying to make sure that I have correctly proved Munkres' Lemma 2.1, which is left to the reader. The lemma states:

Let $f: A \to B$. If there are functions $g: B \to A$ and $h: B \to A$ such that $g(f(a)) = a$ for every $a$ in $A$ and $f(h(b)) = b$ for every $b$ in $B$, then $f$ is bijective and $g = h = f^{-1}$.

Here is my attempted proof.

We will show that $f$ is bijective by showing that it is both surjective and injective. Fix $b \in B$. Then $h(b) = a$ for some $a \in A$. Applying $f$, we obtain $f(a) = f(h(b)) = b$, so $f$ is surjective. Now, suppose $f(a) = f(a')$ for some $a,a' \in A$. Applying $g$, we obtain $g(f(a)) = g(f(a'))$ and hence $a = a'$, so $f$ is injective and hence bijective.
Now, it suffices to demonstrate that $g = h$. We have
$$g \circ \mathrm{id}_B = g \circ (f \circ h) = (g \circ f) \circ h = \mathrm{id}_A \circ h = h.$$
Therefore, we have $f \circ g =  f \circ h = \mathrm{id}_B$ and $g \circ f = h \circ f = \mathrm{id}_B$, so $g = h = f^{-1}$, as required.

The thing I'm most concerned about is whether I've shown that $g = h = f^{-1}$. This requires showing two things, I believe: (1) that $g$ and $h$ are equal and (2) that they both operate as both left and right inverses. By showing that $g$ is also a right inverse, I've shown it is a two-sided inverse, and similarly by showing that $h$ is also a left inverse. I haven't shown that any two-sided inverse is necessarily equal to both $g$ and $h$, so the equality to $f^{-1}$ is not immediately clear to me, which suggests I should also prove (3) any other inverse is necessarily equal to $g$ and $h$.
 A: The "function notation" $f^{-1} : B \to A$ is only used for bijections $f : A \to B$. But what is the precise definition of $f^{-1}$?
For $b \in B$ one defines $f^{-1}(b)$ as the unique element $a \in A$ such that $f(a) = b$. Note that the existence of such $a$ follows from the surjectivity of $f$ and the uniqueness of $a$ from the injectivity of $f$.
By definition of $f^{-1}$ one has $f^{-1}(f(a)) = a$  for all $a \in A$ and $f(f^{-1}(b)) = b$ for all $b \in B$, i.e.
$$f^{-1} \circ f = id_A \text{ and } f \circ f^{-1} = id_B \tag{*}.$$
You proved that $g \circ f = id_A$ and $f \circ h = id_B$ imply that $f$ is a bijection. Applying this (mutatis mutandis) to $(*)$, we see that $f^{-1}$ is a bijection. Of course you can also derive this directly from the definition of $f^{-1}$. That $f^{-1}$ is a bijection may seem to be obvious, but actually it requires a (simple) proof.
You also proved $g = h$, but $g = h = f^{-1}$ in fact requires a proof. So let us do it in one go.
$$g = g  \circ id_B = g \circ (f \circ f^{-1}) = (g \circ f) \circ f^{-1} = id_A \circ f^{-1} = f^{-1} \\
h = id_A  \circ h = (f^{-1} \circ f) \circ h = f^{-1} \circ (f \circ h) =  f^{-1}  \circ id_B = f^{-1}. $$
Let us finally observe that the follwing are equivalent:
(1) $f$ is a bijection.
(2) $f$ has a two-sided inverse $\phi : B \to A$ (i.e. $\phi \circ f = id_A$ and $f \circ \phi = id_B$).
(3) $f$ has a left inverse $g$ and a right inverse $h$.
(1) $\implies$ (2) is obvious (take $\phi = f^{-1})$, as is (2) $\implies$ (3) (take $g = h = \phi)$. (3) $\implies$ (1) has been proved by you. You also proved (3) $\implies$ (2) by showing that $g = h$.
The main ingredient in (1) $\implies$ (2) is our above explict description of $f^{-1}$ which led to (*).
Also note that if a function $\phi$ as in (2) exists, then it is uniquely determined. In fact, if $\psi$ is any two-sided inverse, then $\psi = id_A \circ \psi = (\phi \circ f) \circ \psi = \phi \circ (f \circ \psi) = \phi \circ id_B = \phi$. As you have proved, both $f$ and $\phi$ are bijections, and they are inverse to each other. By the way, this also shows that our $f^{-1}$ is the only two-sided inverse for $f$.
Similarly, if $g$ and $h$ as in (3) exist, then they are uniquely determined and equal.
A: This exercise does not require anything more than understanding definitions.
If $b\in B$ then there is some $h(b)=a\in A$ such that $f(a)=b$, so $f$ is surjective. If $p,q\in A$ and $f(p)=f(q)$ then $g(f(p))=p=g(f(q))=q$ so $p=q$, thus $f$ is injective.
Given $a\in A$, $f(a)=b\in B$ then $g(f(a))=a$ so $g(b)=a$, and $f(h(b))=f(a)$, hence from bijectivity $h(b)=a$, hence $g\equiv h\equiv f^{-1}$.
