Thank you for the insightful replies and I shall report this behavior for RegionNearest[]
. Do I get a free waffle-maker from Wolfram for finding a bug? :)
I had wondered if RegionNearest[]
called ArgMin[]
or NArgMin[]
at a lower level. How does one determine which functions are used by other functions? Is that documented or proprietary?
It was also interesting (for me anyway) to see that using EuclideanDistance[]
reproduces the same problem that I found with RegionNearest[]
, i.e.
Minimize[{EuclideanDistance[{x, y}, {-1/2, 4}], y - x^2 == 0}, {x, y}] // N
gives the correct result, while
Minimize[{EuclideanDistance[{x, y}, {-0.5, 4}], y - x^2 == 0}, {x, y}]
gives the same wrong answer as before. (Note that in the second case, Minimize[]
calls NMinimize[]
to deal with the inexact value for x.) However, calling Minimize[]
or NMinimize[]
with my own squared-distance function, a quartic polynomial, works correctly for both (-1/2,4) and (-0.5/4). This is all shown in the original notebook that I attached.
For completeness, I shall mention that under "Possible Issues" for NMinimize[]
in the Help documentation, it states "For nonlinear functions, NMinimize[]
may sometimes find only a local minimum". Fair warning, although I hoped it would not matter whether my point was on the left or right of the y-axis when dealing with an even polynomial function like y=x^2.