Problem: The point on the curve $x^2 + 2y = 0$ that is nearest the point $\left(0, -\frac{1}{2}\right)$ occurs at what value of y?
Using the distance formula, I get my primary equation: $L^2 = (x-0)^2 + \left(y-\left(-\frac{1}{2}\right)\right)^2$
However, when using the secondary equation $x^2 + 2y = 0$ to write $L^2$ as a function of a single variable and then minimizing $L^2$, thus minimizing $L$, I am getting conflicting answers.
Let $D = L^2 = (x-0)^2 + \left(y-\left(-\frac{1}{2}\right)\right)^2$
Approach 1: substituting $y = -\frac{x^2}{2}$ into our primary equation,
$$D = (x-0)^2 + \left(-\frac{x^2}{2}-\left(-\frac{1}{2}\right)\right)^2$$ $$\frac{dD}{dx} = 2x + 2\left(\frac{x^2}{2}-\frac{1}{2}\right)(x)$$ $$\frac{dD}{dx} = x(x^2+1)$$
Therefore, $D$ has a critical point at x = 0. Using the first derivative test, $\frac{dD}{dx} < 0$ for all $x<0$ and $\frac{dD}{dx}>0$ for all $x>0$, therefore a minimum exists at $x = 0$. At $x=0$, $y = 0$.
Approach 2: substituting $x^2 = -2y$ into our primary equation,
$$D = -2y + \left(y-\left(-\frac{1}{2}\right)\right)^2$$ $$\frac{dD}{dy} = -2 + 2\left(y+\frac{1}{2}\right)$$ $$\frac{dD}{dy} = 2y-1$$
Therefore, $D$ has a critical point at $y = \frac{1}{2}$. Using the first derivative test, $\frac{dD}{dy} < 0$ for all $y<\frac{1}{2}$ and $\frac{dD}{dy}>0$ for all $y>\frac{1}{2}$, therefore a minimum exists at $y = \frac{1}{2}$.
Why do the results differ? What faulty assumption(s) have I made? Thanks in advance.
Note that $x\in (-\infty,+\infty), \ y\in (-\infty, 0]$. Your approach $2$ has implicit constraint on $y\le 0$ and you must check the border too. Hence $y=0$ is an optimal point.
Also note for $y=\frac 12$, $x^2=-1$, which gives complex roots as in the approach $1$: $x^2+1=0$.