Does the domain of the function depend on how you write it?

Strictly speaking, $f(x,y)=\sqrt{xy}$ is not a function at all. It becomes a function when you specify a domain and a codomain. Depending on your domain, you may have alternative ways to write the function; for example, if you choose the domain $\{(x,y)\in\mathbb R^2: xy=1\}$ you can equivalently write the function as $f(x,y)=1$; this form clearly is not equivalent to your expression if you chose as domain e.g $\{(x,y)\in\mathbb R^2: x>0\land y>0\}$. And of course you have to make sure that your expression is defined on the complete domain, or alternatively, use it only for the corresponding part of the domain and give another expression for other parts of the domain. For example, on the domain $(x,y)\in\mathbb R^2: xy\ge 0$, you could write your function equivalently as $$f(x,y) = \begin{cases} x^{1/2}y^{1/2} & x\ge 0 \\ (-x)^{1/2}(-y)^{1/2} & \text{otherwise}\end{cases}$$

Usually when not specifying a domain, the domain is implicitly given as “whereever that expression is defined”. In that sense, the two functions you give are then not the same, as they have different domains, although they agree in the intersection of their domains.

Note also that without codomain, your function is not completely defined. For example, if you chose $\mathbb R_{\ge 0}$ as your codomain, your function (with implicitly given domain) is surjective (it reaches every point of the codomain), while with the codomain $\mathbb R$ it isn't.

If not explicitly specified, usually the codomain of a function is assumed either to be its image (the minimal possible codomain, which makes the function surjective), or the largest “reasonable” set containing the image (like $\mathbb R$ for real-valued functions).

Since the exact codomain is less often relevant than the domain, it is more often left unspecified.


In strictly (set theoretical) mathematical terms, the domain is part of the definition of a function. However, it is fairly common to write down a function by giving an expression how to calculate it, and then the natural domain of the function is the set where that expression is well-defined. As you have discovered, there are sometimes different expressions that evaluate to the same thing for some input values, but there are different sets on which the expressions are defined.

For example, $f(x)=(\sqrt{x+2})^2$ has the natural domain $[-2,\infty)$. However, everywhere in that domain it is equal to $(x+2)$. The function $g(x)=x+2$ has the natural domain $\mathbb R$.


This is actually poorly explained (in US schools at least) until you get to proof-based writing.

Formally, a function is two thing: a domain, and a "rule" which assigns to each element of the domain an output. If the domain is $D$, then for each $x\in D$, we assign a value $f(x)$. This "rule" is what we usually think of as some sort of equation like $f(x)=x^2-\sqrt x$. The domain can be any set, and the outputs can also be in any set.

In practice, though, the domain is often implied by the context and the rule. For example, in calculus, when you see the function $f(x)=1/x$, it is assumed that the domain is the largest set of real numbers for which it makes sense to plug into $f$. In this case, any number but $0$ makes sense, so we can write $D=(-\infty,0)\cup (0,\infty)$.

As you noticed, it is not always entirely obvious what the domain should be. For $f(x,y)=\sqrt{xy}$, it makes sense to plug in any positive numbers for $x$ and $y$, but also certain negative numbers. For example, it makes sense to plug in $x=-1$ and $y=-4$. However, it does not make sense to plug in $x=-1$, $y=4$. In this case the domain is assumed to be $\{(x,y):xy\ge 0\}$, or $\{(x,y):x,y\ge 0 \text{ or }x,y\le 0\}$.