In proving the dimension of a manifold is well-defined, I have come across this lemma. Could you check if my proof is fine or if it contains subtle logical mistakes?
Let $A \subseteq \mathbb R^m$, $B \subseteq \mathbb R^n$, and $f:A \to B$ be a diffeomorphism. Then $m = n$.
Proof: Let $f^{-1}$ be the two-sided inverse of $f$. Then $f^{-1}:B \to A$ is also a diffeomorphism. Fix $a \in A$ and let $b := f(a) \in B$. Then $\mathrm d f (a) \in \mathcal L(\mathbb R^m, \mathbb R^n)$, i.e., $\mathrm d f (a)$ is a continuous linear map from $\mathbb R^m$ to $\mathbb R^n$. Similarly, $\mathrm d f^{-1} (b)$ is a continuous linear map from $\mathbb R^n$ to $\mathbb R^m$.
Clearly, $g:=f \circ f^{-1}$ is the identity map from $B$ to $B$. Hence $\mathrm d g (b)$ is the identity map on $\mathbb R^n$. On the other hand, $\mathrm d g (b) = \mathrm d f (f^{-1}(b)) \circ \mathrm d f^{-1} (b) = \mathrm d f (a) \circ \mathrm d f^{-1} (b)$ by chain rule. This means $\mathrm d f (a)$ is the left inverse of $\mathrm d f^{-1} (b)$.
A similar argument with $g:=f^{-1} \circ f$ implies $\mathrm d f (a)$ is the right inverse of $\mathrm d f^{-1} (b)$. Hence $\mathrm d f (a)$ is the two-sided inverse of $\mathrm d f^{-1} (b)$. It follows that $\mathrm d f (a)$ is bijective and thus $\mathrm d f (a)$ is an isomorphism. It follows that $m=n$.
Update: I was sloppy. I should have restricted that $A,B$ are open. IMHO, we can extend the definition of differentiability to arbitrary set like here, but diffeomorphism makes sense only for open domain.