# Is this function composition "legal"?

I have a question regarding the commutativity of function composition. Here are two examples:

First example: \begin{align} f_1&: \mathbb R^2 \to \mathbb R, &f_1(u,v)=u^2-v\sin u \tag 1 \\ g_1&: \mathbb R^2 \to \mathbb R^2, &g_1(x,y)=(x+y,xe^y) \tag 2 \end{align}

And the composition $$h_1 = f_1 \circ g_1 :\mathbb R^2 \to \mathbb R$$ is \begin{align} h_1(x,y)&=(f_1\circ g_1)(x,y) \\ &=f_1(g_1(x,y))\\ &= f_1(x+y,xe^y)\\ &=(x+y)^2-xe^y\sin (x+y) \tag 3 \end{align} Question: is it possible to compose $$g_1\circ f_1$$?

My first thought was "no", according to the definition:

\begin{align} f&: \mathbb R^n \to \mathbb R^p\\ g&:\mathbb R^m \to \mathbb R^n\\ h&=f\circ g: \mathbb R^m \to \mathbb R^p \end{align} I.e. $$h(x)=(f\circ g)(x)=f(g(x))$$

However, is it not possible to introduce a new function $$F_1$$ with the right co-domain and compose it with $$g_1$$, i.e. $$g_1 \circ F_1$$?

Attempt: Introduce \begin{align} F_1&:\mathbb R^2\to \mathbb R^2 \tag 4\\ F_1&(u,v)=(u,f_1(u,v))=(u,u^2-v\sin u) \tag 5 \end{align} And with $$g_1:\mathbb R^2\to \mathbb R^2$$ we have the composition $$h_2= g_1\circ F_1:\mathbb R^2 \to \mathbb R^2 \tag 6$$ According to the definition the composition is valid, however is this "legal"? \begin{align} h_2(u,v)&=(g_1\circ F_1)(u,v)=g(F_1(u,v))\\ &=g(u,u^2-v\sin u)\\ &=(u+u^2-v\sin u,ue^{u^2-v\sin u}) \tag 7 \end{align}

Second example: \begin{align} f_2&:\mathbb R^3 \to \mathbb R^2, &f_2(u,v, w)=(u^3-v\sin u, uvw) \tag 8\\ g_2&:\mathbb R^2 \to \mathbb R^2, &g_2(x,y)=ax^2+by \tag 9 \end{align} $$f_2\circ g_2$$ is not a valid composition. Now introduce $$G_2:\mathbb R^2 \to \mathbb R^3$$, $$G_2(x,y)=(x,y,g_2(x,y))=(x,y,ax^2+by) \tag{10}$$ So the composition $$h_3= f_2\circ G_2:\mathbb R^2\to \mathbb R^2$$ is \begin{align} h_3(x,y)&=(f_2\circ G_2) (x,y)=f(G_2(x,y))\\ &=f(x,y,ax^2+by)\\ &= (x-y\sin x, xy(ax^2+by)) \tag{11} \end{align}

Is this legal?

• It is not a matter of "legality", it is a matter of meaning and usefulness. What is the purpose of "forcing" such a composition ?
– user65203
Jun 24, 2020 at 8:44

There isn't a canonical embedding $$\mathbb R \subset \mathbb R^2$$. So it is not well-defined, without further annotations.
Let $$X$$, $$Y$$, and $$Z$$ be any non-empty sets, and let $$f \colon X \rightarrow Y$$ and $$g \colon Y \rightarrow Z$$ be any functions. Then the composite function $$g \circ f \colon X \rightarrow Z$$ is defined as follows: $$\big( g \circ f)(x) \colon= g\big( f(x) \big) \qquad \mbox{ for all } x \in X.$$
Note that in order for the composite function $$g \circ f$$ to be defined, we must have $$\mbox{Range } f \subset \mbox{Domain } g,$$ where $$\mbox{Range } f$$ is defined as follows: $$\mbox{Range } f \colon= \big\{ \, f(x) \, \colon \, x \in X \, \big\}.$$
So in order for the composite $$f \circ g$$ to be defined, we must also have $$\mbox{Range } g \subset \mbox{Domain } f,$$