# Result is correct, but LinearProgramming spits out lpnn warning in RegionPlot

Sorry if this is a newbie question. I wrote a function to decide if a given vector is in the convex hull of another set of vectors using linear programming.

τ[dim_] := NMaximize[(dim - 2) Sin[s] + Sin[2 s], s][[1]]
τ[dim_, j_] := j NMaximize[(dim - 2 j) Sin[s] + j Sin[2 s], s][[1]]
BinaryCube[w_, bits_] := Table[(-1)^(BitAnd[w, 2^j]/2^j), {j, bits - 1, 0, -1}]
Proj[w_] := w - Sum[w[[i]], {i, 1, Dimensions[w][[1]]}]/Dimensions[w][[1]];
DB[dim_] := dim/2 Table[Proj[BinaryCube[w, dim]], {w, 1, 2^dim - 2}]
ConvexHull[M_, b_] :=
If[Table[1, {j, 1, Dimensions[M][[2]]}] .
LinearProgramming[Table[1, {j, 1, Dimensions[M][[2]]}], M, b] < 1,
1, 0]
DBMatrix = Transpose[DB[3]]
RegionPlot[
ConvexHull[DBMatrix, α {1, -1, 0}/Sqrt[2] + β {1, 1, -2}/Sqrt[6]] > 1/2,
{α, -3, 3}, {β, -3, 3},
PlotStyle -> Red]


When I call the function with a fixed matrix (representing the vectors defining the vertices of the convex polytope) and vector that we are checking for membership in the convex region it runs fine but when I call it from RegionPlot it generates a warning.

LinearProgramming::lpnn: Input data to linear programming algorithm {{1,1,1,1,1,1},{{1,1,2,-2,-1,-1},{1,-2,-1,1,2,-1},{-2,1,-1,1,-1,2}},{α/Sqrt[2]+β/Sqrt[6],-(α/Sqrt[2])+β/Sqrt[6],-Sqrt[(2/3)] β},{{}},{}} contains elements that are empty matrices, invalid vectors or matrices, or not real numbers.

Anyone know what is going on here? I am not sure where these empty vectors are coming from. For what it is worth it still generates what I know to be the correct plot in this case.

The problem doesn't seem to be the empty lists in the message, they're there probably because LinearProgamming has internally treated

LinearProgamming[c, m, b]


as

LinearProgramming[c, m, b, {{}}, {}]


The real problem is probably the α and β therein. This seems to be another story of evaluation order, which can be fixed with the frequently used NumericQ technique:

Clear@ConvexHull;
ConvexHull[M_, b : {__?NumericQ}] :=
If[Table[1, {j, 1, Dimensions[M][[2]]}] .
LinearProgramming[Table[1, {j, 1, Dimensions[M][[2]]}], M, b] < 1, 1, 0]


Tested in v9.0.1 and v12.2.

Finally it's worth mentioning that the warning doesn't pop up in v8.0.4 by default, and adding Evaluated -> True to RegionPlot in v8.0.4 reproduces the warning. Nevertheless, Evaluated -> False cannot fix the problem in v9.0.1 and v12.2. Bug or feature? I'm not sure.

• Thank you, this is very helpful. – Geardaddy Dec 21 '20 at 0:25