WolframLang: Detect Zero Vector

By Xah Lee. Date: . Last updated: .

What is the most efficient or elegant way to detect zero vector of n dimensions (list whose element are all 0)?

analysis:

Computing the Norm wins. Almost twice as fast.

isZeroVector1 = Function[Total[#^2] < 0.00000001];
isZeroVector2 = Function[Norm[#] < 0.00000001];

data = Table[{RandomReal[], RandomReal[], RandomReal[]}, {900000}];
x1 = Timing[Map[isZeroVector1, data]];
x2 = Timing[Map[isZeroVector2, data]];

{First@x1, First@x2}

(* {1.67188, 0.90625} *)

SameQ @@ {Last@x1, Last@x2}
(* True *)