# Domain of Sqrt[x]^2

I'm just starting to work with Mathematica and this is simplified version of the problem I have: seems that Sqrt[x]^2 simplifies to just x without any restrictions on domain:

In:= FunctionDomain[Sqrt[x]^2, x]
Out:= True


I can't restrict x>=0 globally because negative x is necessary in other parts of my calculation.

Is there a (preferably automatic) way to propagate domain during function composition?

So far I tried Sqrt, entering square root using Ctrl+2, and explicitly creating composition like this:

In:= f[x_] := Sqrt[x]
g[a_] := a^2
z[p_] := Composition[g, f]
FunctionDomain[z[x], x]
Out:= True • Sqrt's domain is at least the entire real line because Mathematica automatically uses complex numbers as relevant. If you would like to ensure that the real roots are used, consider looking at Surd. – eyorble Dec 27 '19 at 1:04
• For negative values: FullSimplify[ComplexExpand[Sqrt[x]], x < 0] gives I*(x^2)^(1/4), and FullSimplify[%^2, x < 0] is x, that corresponds to your plot. – Alx Dec 27 '19 at 2:29
• @eyorble when I run FunctionDomain[Sqrt[x]] it produces {x>=0} – fukanchik Dec 27 '19 at 3:17
• @Alx Sqrt is not the best example. Consider (x+2)*(x+1)/(x+2) – fukanchik Dec 27 '19 at 3:19

The problem is that Sqrt[x]^2 evaluates to x:

Sqrt[x]^2


x

Hence, your call to FunctionDomain checks the domain of x. You can use Unevaluated to prevent this:

FunctionDomain[Unevaluated[Sqrt[x]^2], x]


x >= 0

• Thanks Carl that is what I was looking for. – fukanchik Dec 27 '19 at 3:23