# Why does Nearest not support Sqrt?

Bug introduced in 10.0.2 and fixed in 10.3.0

Simple examples with two points

nf1=Nearest[{{0, 0}, {Sqrt, Sqrt}}]

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, Sqrt}}. Why?

While if we use N

nf2 = Nearest[N@{{0, 0}, {Sqrt, Sqrt}}]
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.

• – IPoiler Oct 9 '15 at 14:35
• I also tested the workaround I gave in that question on your problem. nf=Nearest[{{0,0},(Sqrt,Sqrt}}, DistanceFunction -> (Norm[#1 - #2] &)] generates a NearestFunction which returns the expected points for nf[{0, 0}, {All, 2.1}] (at least in v10.2). – IPoiler Oct 9 '15 at 14:40
• This bug has been fixed in the development version. – ilian Oct 9 '15 at 14:53
• Development version is 10.2+a decimal to be named later – Daniel Lichtblau Oct 9 '15 at 15:09
• Yes, the fix should be available in the next release. – ilian Oct 9 '15 at 15:18

## 1 Answer

As mentioned in the comments, this bug has been fixed as of Mathematica 10.3.

\$Version

(* "10.3.0 for Microsoft Windows (64-bit) (October 9, 2015)" *)

nf1 = Nearest[{{0, 0}, {Sqrt, Sqrt}}];
nf1[{0, 0}, {All, 2.1}]

(* {{0, 0}, {Sqrt, Sqrt}} *)