Bug introduced in 10.0.2 and fixed in 10.3.0
Simple examples with two points
nf1=Nearest[{{0, 0}, {Sqrt[2], Sqrt[2]}}]
nf1[{0, 0}, {All, 2.1}]
gives
{{0, 0}}
This is incorrect. If we test bigger radius, we can find that Mathematica takes 4 as critical radius. Because nf1[{0, 0}, {All, 3.999}]
gives {{0,0}}
and nf1[{0, 0}, {All, 4}]
gives {{0, 0}, {Sqrt[2], Sqrt[2]}}
. Why?
While if we use N
nf2 = Nearest[N@{{0, 0}, {Sqrt[2], Sqrt[2]}}]
nf2[{0, 0}, {All, 2.1}]
gives correct answer
{{0., 0.}, {1.41421, 1.41421}}
Why Nearest
gives wrong answer with irrational number? And If Nearest
doesn't support irrational number, is it possible to write another Nearest
function that has the same behavior and same efficiency while supporting irrational number directly.
nf=Nearest[{{0,0},(Sqrt[2],Sqrt[2]}}, DistanceFunction -> (Norm[#1 - #2] &)]
generates aNearestFunction
which returns the expected points fornf[{0, 0}, {All, 2.1}]
(at least in v10.2). $\endgroup$