When is composition of functions defined? Given any functions $f:X\to Y$ and $g:A\to B$ the function $h(x)=f(g(x))$ is well defined for any elements $x\in g^{-1}(X\cap g[A])$ can one then write $h=f\circ g$? Or is composition of $f$ and $g$ only defined when the domain of $g$ equals the codomain of $f$? If the composition is still well defined for some values, then why limit the definition? I understand that this could give rise to cases where you have functions with empty domains, in the circumstance the composition isn't defined anywhere but is that really a problem? Would it still be okay to write $h=f\circ g$?
 A: We need to work with one of two definitions:
Definition 1: Given two functions $f\colon X \to Y$ and $g\colon A \to B$, their composite $h = f\circ g$ is the function $h\colon g^{-1}(X \cap g[A]) \to Y$ given by $h(x) = f(g(x))$.
Definition 2 Given two functions $f\colon X \to Y$ and $g\colon A \to B$ such as that $g[A] \subseteq X$, their composite is the function $h\colon A \to Y$ given by $h(x) = f(g(x))$.
With both definitions, $h$ is well defined. Using definition 1, we can have an empty composite, a function from the empty set, while using definition 2, given that our sets are non-empty, then the composite is non-empty.
Also, when they apply, both definitions agree. For the sake of simplicity (given that we don't want to mess around with empty functions), we usually work with the second, less general definition.
Now, we may find ourselves in the middle way of the two extremes: we don't have $g[A] \subseteq X$, but their intersection is non-empty either: $X \cap g[A] \neq \varnothing$. For instance, take $g\colon \mathbb{R} \to \mathbb{R}$ and $f\colon \mathbb{R} - \{0\} \to \mathbb{R}$ given by $g(x) = x^2 - 1$ and $f(x) = \dfrac{1}{x}$. To define their composite $h$, we usually restrict $g$ to the pre-image of the non-problematic points, so we would be considering as it's domain the set $\mathbb{R} - \{\pm 1\}$ instead of simply $\mathbb{R}$. That's usually implicit when talking about composite functions, because when this happens, this restriction can always be done.
