How would you describe the existence of a composite function $f(g(x))$in terms of range of $g$ and domain of $f$ . Does range of $g$ need to be subset of domain of $f$ or is it sufficient if the two sets have intersection only?
I used to define composite function if range of $g$ is a subset of domain of $f$ and in that case domain of the composite function is same as domain of the function $g$ but I have come across questions where only intersection exists. In that type of situation domain of composite function can not be the domain of $g$. I have this issue related to high school mathematics. Could you please help me to find the most appropriate way of describing the issue to the students relevant to their level of studies .
For further clarification here you have examples

  1. Let $f(x) = x^2$ and $g(x) = \sqrt{x-1}$.
    Here range of $g$ is a subset of domain of $f $, therefore $f(g(x)) = x -1$ exists. Now the issue is can you say $f(g(0))= - 1$ because 0 is not in the domain of $g$?

  2. Let $f(x)= x + 2$ and $g(x) = 1/(x - 1)$.
    Here range of $f$ is not a subset of domain of $g$ , now what about $g(f(x)) = 1/(x+1)$, how can you explain the way to obtain domain of this composite function because here that is not the same domain of $f$?

  3. Do we need to treat finding expression for $g(f(x))$ and finding composite function $g(f(x))$ in two different ways?
    By going through the suggested answers following are the conclusions I could able to make ,

  1. When the terms function or domain not mention in the question we can treat$ f(g(x))$ as an expression and substitute any real value to $x$ if output is real.
  2. When the domain of $f$ and $g$ are given $f(g(x))$ can be defined if range of $g$ is a subset of domain of $f$.
  3. When domain of $f$ and $g$ are not given we have to determine the domain of $g$ such that range of $g$ is a subset of domain of $f$ and range of $f(g(x))$ should be determined according to the selected domain of $g$.
    If you have any exceptions please mention it in your answers or comment about it so that we can make the final conclusion.
  • 3
    $\begingroup$ This is a question about mathematics, not about math education. $\endgroup$ Feb 18, 2023 at 21:42
  • 4
    $\begingroup$ This is definitely a teaching question: which convention is better to teach and how to explain it to students. $\endgroup$
    – TomKern
    Feb 18, 2023 at 21:52
  • $\begingroup$ @TomKern thanks for understanding the real meaning and the value of the issue. I too believe this is much better platform to clear doubts related to different approaches in teaching. $\endgroup$ Feb 19, 2023 at 0:01

3 Answers 3


Before addressing some of the issues directly, let me mention what I think is the standard approach in mathematics. A function is typically defined together with its domain and codomain, so saying "function $f$" is a shorthand for "function $f \colon A \to B$" (where $B$ is the codomain and potentially the range $f(A)$ is a proper subset of $B$). And then, the standard way of introducing composition is to require two functions $f \colon A \to B$, $g \colon B \to C$ to have matching (co)domains and let $g \circ f \colon A \to C$, $(g \circ f) (x) = g(f(x))$.

Of course, this is not the only option. If $f \colon A \to B$ and $g \colon B' \to C$ don't have matching (co)domains but $B' \subseteq B$ (typically $B = \mathbb{R}$), you can still define $g \circ f$ on the set $A' := f^{-1}(B')$ by $(g \circ f) \colon A' \to C$, $(g \circ f)(x) = g(f(x))$. It's mostly a pedagogical choice. If one wanted to be pedantic and stick to the previous definition, one would just have to use the composition $g \circ f|_{A'}$ (with $f$ replaced by its restriction).

It's probably best to stick with whatever your primary reference for the subject uses.

Now, there's a type of problems where a function is only given by an expression (say, $\frac{1}{x}$) and the student is required to find the set of all $x$'s for which the expression makes sense, the so called natural domain (here it would be $\mathbb{R} \setminus \{0\}$).

However, it's important to make a distinction between a function and an expression. Formally, in problems like the one above you are given an expression and asked to make it into a function. I'd suspect not all students are ready for such subtleties, but there are some advantages:

  • This is how it works in mathematics, but even more importantly, in programming. There, functions are usually statically typed, meaning that you specify the type of their input and output. If you try to compose two functions: $$ f \colon \mathbb{N} \to \mathbb{R}, \ f(n)=\sqrt{n} \quad \text{with} \quad g \colon \mathbb{N} \to \mathbb{N}, \ g(x)=x^2, $$ in a typical programming language, you should expect an error when trying to compute $g(f(4))$, even though the reason in somewhat artificial (at least from the mathematical perspective).
  • The distinction can clear up some confusion in your example 1. If $f(x) = x^2$ and $g(x) = \sqrt{x-1}$, then actually we deal with functions $g \colon [1,\infty) \to \mathbb{R}$ and $f \colon \mathbb{R} \to \mathbb{R}$, and their composition is by definition $f \circ g \colon [1,\infty) \to \mathbb{R}$, $(f \circ g)(x) = f(g(x)) = x-1$. Of course, given the expression $x-1$ out of context, we would ascribe $\mathbb{R}$ as its natural domain. Avoiding unnecessary subtleties, one could also summarize it as follows: the natural domain of the composition $f \circ g$ may be larger than the natural domain of $g$.

I hope it also sheds some light on how you could explain points 2 and 3.

  • $\begingroup$ Do you mean when f(x) and g(x) are given as expressions without mentioning domains, you can substitute any value for x in f(g(x)) ? $\endgroup$ Feb 19, 2023 at 10:15
  • 3
    $\begingroup$ @JanakaRodrigo I really cannot answer, as there are at least two ways to interpret the words "you can" (in principle, I can substitute anything anywhere, the problem is in interpreting the result). If $f(g(x))$ is your shortcut for the function composition $f \circ g$, then no, as explained in the answer. If $f(g(x))$ stand for the expression obtained by substituting one expression into another (which is basically a composition, but treated algebraically), then possibly yes (if only the resulting expression makes sense for such $x$). $\endgroup$ Feb 20, 2023 at 4:08
  • 1
    $\begingroup$ @StevenGubkin Can you elaborate? I don't know what monads are or what DNE means, but I'd be interested in knowing what you had in mind. Maybe you can write it as a separate answer? $\endgroup$ Feb 20, 2023 at 4:10
  • 1
    $\begingroup$ I don't feel like writing up an answer but I am using "DNE" for "Does not exist" (or "error"). You can basically adjoin a single element "DNE" to every set. Then functions which map DNE to DNE correspond to partial functions. Check out ncatlab.org/nlab/show/maybe+monad. $\endgroup$ Feb 20, 2023 at 13:33
  • 1
    $\begingroup$ It's also worth pointing out that in a lot of mathematics we pretend to be using one of the above definitions for function and function composition, but in reality we're just playing silly buggers and doing whatever we feel like, assuming the reader is smart enough to provide the necessary definitions themself. In such a way that the results match a sensible interpretation. $\endgroup$
    – DRF
    Feb 20, 2023 at 19:26

I initially found requiring the range of $g$ being a subset of the domain of $f$ to be the more appealing option, but having thought about it more, I now think that any two real functions should be composable. This is based on two principles:

  • The key takeaway skill from talking about domains is that students should be able to recognize when an expression exists or doesn't exist for various $x$. There shouldn't be extra rules for dealing with functions for students to memorize. As such:
  • Functions should not behave differently from ordinary algebra: students can write algebraic expressions that don't exist for any $x$, so they should also be able to write $f(g(x))$ when it doesn't make sense for any $x$.

Of course, the most important principle is to agree with whatever your textbook says, so that students don't get confused when they reference it.

  • $\begingroup$ I suggest just as to find expression for f(g(x)) you don't have to think about whether the range of g is a subset of domain of f or not but what about when you refer the function f(g(x) .I think here considering that condition may be important. $\endgroup$ Feb 19, 2023 at 2:09
  • $\begingroup$ Could you clarify what you mean by "but" in the first sentence? If you compose two functions $f,g:\mathbb{R} \to \mathbb{R}$, then you're in the situation described in the first part of the sentence: the range of $g$ is a subset of $\mathbb{R}$, which is in turn the domain of $f$. $\endgroup$ Feb 19, 2023 at 7:02
  • $\begingroup$ Whoops! I mean partial functions. I was specifically trying to avoid talking about functions that have inputs/outputs other than real numbers. $\endgroup$
    – TomKern
    Feb 19, 2023 at 8:10
  • $\begingroup$ @JochenGlueck as you agree function f(g(x) exists, what about the value of f(g(0)) because 0 is not in the domain of g but you can find f(g(0)) by substituting 0 for the expression f(g(x)) that is x -1. These kind of questions asked in high school grade 10 . $\endgroup$ Feb 19, 2023 at 10:10
  • 2
    $\begingroup$ This is pretty much the minimal understanding of functions I expect students to have in the US when enrolling in calculus in college. Whether it is the understanding I wish they had is another matter: you teach the students you get. For instance, in calculus, I usually have to explain $(\sqrt x)^2$ has a restricted domain. I don't know whether in other countries students usually obtain a more rigorous understanding of functions. Of course in the US, there is variation in level of rigor, level of proficiency, and with the holes in their backgrounds. $\endgroup$
    – user1815
    Feb 19, 2023 at 15:57

I think the answer by Michal Miśkiewicz does an excellent job addressing issues, and captures the formal mathematical perspective.

The distinction between the formality of "function with domain" and the more laissez-faire perspective of "expressions" is an important pedagogical issue. When I teach composition in precalculus and come to this issue, I like to refer to the "function with domain" as a rule typically given by an algebraic expression along with a demon who prevents evaluation at values not in the domain. This is akin to Maxwell's demon, the proverbial gatekeeper of the Second Law of Thermodynamics. enter image description here

Some of my more artistic students enjoy drawing their creative renditions of gatekeepers of functions domains. Often the characteristics of the demon reflect the name of the function--"square root" inspires some to draw a demon holding a mandrake with square roots. Having students draw domain demons so I can share them with the class seems to help students retain the idea that functions have domains. When I grade exams, I sometimes see more sketches that students draw in the margins.

When the demon goes to sleep, the function becomes an expression and that's when we can play fast and loose. When the demon for $(f(x)=x^2,\ x\in {\bf R})$ goes to sleep, we can square all sorts of things such as matrices, mandrake roots, etc.

  • $\begingroup$ When domains or the functions terms are not mentioned we can just treat $f(g(x)) $as expression, but what about when those terms are used in the question. How could you explain the following issue which I got from review exercise in high school grade 10. If $f(x)= x-2 $and $g(x) = 8/(x +1) $find $g(f(x)) $and state the domain ? In this question domain of$ f $and $g$ not given. $\endgroup$ Feb 20, 2023 at 4:10
  • 1
    $\begingroup$ @JanakaRodrigo We use the "implied" domain for each expression. We have $\left(f(x),{\bf R}\right)$, $\left(g(x),\{x\in{\bf R}, x\ne -1\}\right)$, $\left( h(x)=\frac{8}{x-1},\ x\in{\bf R}, x\ne1\}\right)$. The gremlin for $f$ has an easy job, and gets paid for doing nothing. The gremlin for $g$ gets paid to watch for $x=-1$ and shoot it out of the air whenever it tries to sneak into $g$. The gremlins for $g$ and $h$ are mirror twins. $\endgroup$
    – user52817
    Feb 20, 2023 at 14:32
  • $\begingroup$ As a conclusion can we say if domains given of the functions $f $and $g $such that range of $g $is not a subset of domain of $f$ , composite function$ fog(x) $can not be defined but if domains not given we can define those in order to exist the composite function. $\endgroup$ Feb 20, 2023 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.