Consider $f(x)=x^2+1$ and $g(x)=\sqrt{x-1}$. Note that $(f\circ g)(x)=x$ and this checks in Mathematica.

Clear[f, g, x]
f[x_] = x^2 + 1;
g[x_] = Sqrt[x - 1];

The output is:


However, the domain of this function (using real numbers) is $D=[1,\infty)$, but Mathematica's FunctionDomain (probably working with complex numbers),




Which means all real numbers. Any way to get this command to focus on the reals?

I found one way:

Clear[f, g, x]
f[x_] = x^2 + 1
g[x_] = Surd[x - 1, 2]


FunctionDomain[f[g[x]], x]

returned $x\ge 1$.

Any other way?

Clear[f, g, x]
f[x_] := x^2 + 1;
g[x_] := Sqrt[x - 1];

Possible approach:

FunctionDomain[{f[g[x]], g[x] >= 0}, x]
(* x >= 1 *)

More general:

FunctionDomain[{f[g[x]], Element[g[x], Reals]}, x]
(* x >= 1 *)
  • $\begingroup$ Very helpful alternatives. Thanks. $\endgroup$
    – David
    Mar 18 '16 at 19:20
  • $\begingroup$ @David Glad it was useful. $\endgroup$
    – user31159
    Mar 18 '16 at 20:50
  • $\begingroup$ I'm thinking what happened with my original question is that Mathematica evaluates f(g(x)), looks at the final answer, then finds the domain of the result. So, I'm currently thinking that if I want my algebra students to use Mathematica to check the domain of the composition of two functions, the best approach would be to first check the domain of g, then the domain of $f\circ g$. $\endgroup$
    – David
    Mar 18 '16 at 21:34
  • $\begingroup$ @David Yes, FunctionDomain do not have an attribute of the form HoldXXX, so its internal definition will be used after the evaluation of f[g[x]] only. So in the end it fires as FunctionDomain[x, x]. The same thing happens in my propositions, but we kept the domain of definition of g in the process by adding a constraint in the input. I agree with your alternative, first FunctionDomain could be checked on g, and then the domain obtained could feed the FunctionDomain of f in the constraints part. $\endgroup$
    – user31159
    Mar 18 '16 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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