# 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$?

• When you write $h=f\circ g$, it is usually implicitly assumed that $g(A)\subset \text{dom}(f)$ – user160738 Jun 19 '17 at 2:40
• To composite the functions $f:X\to Y$ and $g:A\to B$, the sufficient condition for $f\circ g$ to be defined on $A$ is that $B\subseteq X$. – BAI Jun 19 '17 at 2:43
• @BAI But the function $h(x)=f(g(x))$ could still be well defined for values of $x$ even if this is not the case, I don't understand. Take $f:\mathbb{R}\to \mathbb{R}$ where $f(x)=x^2$ and $g:\mathbb{R}\to\mathbb{C}$ where $g(x)=x^3$ then $f(g(x))$ is still well defined for values of $x$ and yet $\mathbb{C}$ is not a subset of $\mathbb{R}$. – nomad66 Jun 19 '17 at 2:44
• @nomad66 it seems like $x\in g^{-1}(X\cap g[A])$ implies that $x\in A$ and $f\circ g$ is defined for which $(x\in A)\land(g(x)\in X)$. You could just see it like we choose another pair of domain and codomain $g:A'\toB'$ such that $B'\subseteq X$. – BAI Jun 19 '17 at 2:54
• @nomad66 and $B'\subseteq B$ – BAI Jun 19 '17 at 2:55

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.
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.