Why is $\sqrt{x}$ a function? [duplicate]

How $\sqrt{x}$ can be a function when $\sqrt{4}$ is equal to $-2$ and $2$?


The notation $\sqrt{x}$ refers to the principal square root of $x$. The principal square root is the non-negative square root. The notation $-\sqrt{x}$ refers to the negative square root of $x$.

Hence,

\begin{align*} \sqrt{4} & = 2\\ -\sqrt{4} & = -2 \end{align*}

The function $f(x) = \sqrt{x}$ has domain $[0, \infty)$ and range $[0, \infty)$. Its graph is the upper half of the parabola $x = y^2$.

The function $g(x) = -\sqrt{x}$ also has domain $[0, \infty)$, but its range is $(-\infty, 0]$. Its graph is the lower half of the parabola $x = y^2$.

See the diagram below.

square_root_function_and_its_reflection_in_the_x-axis


Let $f$ be a function from $[0,\infty]\to [0,\infty]$ by $f(x)=x^2$. You can see that $f$ is invertable as it is $1-1$ and onto.

$f^{-1}(x)=g(x)=\sqrt x$ defined from $[0,\infty]\to [0,\infty]$ as an invverse of it. Thus $\sqrt 4=2$.