Minor Mistake in Computability, Complexity, and Languages?
There's no contradiction, here.  The first case defines the partial function $g\colon \mathbb{N}\to\mathbb{N}$ given by
$$g(n) = \begin{cases}
 x &amp;\text{if $x\in\mathbb{N}$ and }x^2=n\\
 \text{undefined} &amp;\text{if no such $x$ exists.}
\end{cases}$$
As the text says, "the domain of $g$ is the  set of perfect squares."

The second case defines the total function $h\colon\mathbb{N}\to\mathbb{R}$ given by
$$h(n) = x \quad \text{if }x\in\mathbb{R}_{\geq 0} \text{ and } x^2=n\,.$$
The domain of $h$ is the set of all the natural numbers.

You say that these are the same function, but they are not. $g(2)$ is undefined but $h(2)$ is defined (and equal to $\sqrt{2}$). $h$&nbsp;associates a square root with every natural number but $g$&nbsp;only associates square roots with natural numbers that are perfect squares.

$\mathbb{N}$&nbsp;is closed under&nbsp;$g$ because, whenever $g$&nbsp;is defined, $g(n)\in\mathbb{N}$. $\mathbb{N}$&nbsp;is not closed under&nbsp;$h$ because, for example, $2\in\mathbb{N}$ but $h(2)\notin\mathbb{N}$.