So why is it a function, even though for example $x = 8$; you'll have $y = +2$ and $y = -2$. It'll fail the vertical line test. But every textbook considers it as a function. Did I misunderstand something?

3 Answers
3

For the first question, there are two answers: $\pm 2$, since both of these numbers squared will give you $4$.

The second asks: "what nonnegative number, when squared, gives you $4$?" The answer to that is $2$ (and not $-2$). In general for a nonnegative real number $x$, its square root, $\sqrt{x}$ is defined to be the nonnegative solution $y$ to $y^2 = x$.

Thus, $\sqrt{8-4} \neq -2$, so the graph $y=\sqrt{x-4}$ contains the point $(x,y) = (8,2)$ but not $(x, y) = (8, -2)$. In general there is at most one answer to the question "evaluate $\sqrt{x-4}$," so the graph does indeed pass the vertical line test. (You can see a sketch of the graph on Wolfram Alpha.)

(Things get more interesting when we try to define a square root of a complex number!)

Edit (in response to follow up question about $y = \sqrt{4-x^2}$): Consider the graphs of $y^2 = x$ and $y = \sqrt{x}$. Based on the discussion above, they are not the same graph. The graph $y^2 = x$ "transforms" into $y = \pm \sqrt{x}$, which is not a function.

If $y = \sqrt{x}$ then $y^2 = x$ but not the other way around. Hence your equations $$y = \sqrt{4-x^2}$$ and $$x^2 + y^2 = 4$$ may very well have different sets of solutions, and they do. For the first of these equations, $y$ is automatically positive (because of the other discussions about the square root). The solutions of $y = \sqrt{4-x^2}$ form a semi-circle, the part of the circle $x^2 + y^2 = 4$ which correspond to points where $y \ge 0$.

It is a function because that square root sign in your expression denotes the principal square root. The principal square root of a positive number is defined as the positive square root of that number i.e. we discard the negative square root.

If that square root symbol instead denoted both the negative and positive square roots, then yes, it wouldn't be a function but a relation.