# 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)$ Jun 19, 2017 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, 2017 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}$. Jun 19, 2017 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, 2017 at 2:54
• @nomad66 and $B'\subseteq B$
– BAI
Jun 19, 2017 at 2:55

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.

• g^-1 might not even exist isnt Sir ? Its inverse i mean so second defintion is more good in that sense isnt ? Apr 21 at 20:21
• @Orion_Pax here the notation $g^{-1}(X \cap g[A])$ means the pre-image of the set $X \cap g[A]$ through $g$, the set of elements $a \in A$ such that $g(a)$ belongs to $X \cap g[A]$. This coincides with it's image through the inverse function $g^{-1}$ when it exists, but it is defined for any function $g$. Apr 23 at 10:14