# Apply greater than to a list

How can I apply greater than $>$ to a list?

Example 1

list={1,4,5,-2}


How can I apply $>$ to the list to find all elements of the list greater than 0?

Desired output

{True,True,True,False}


Example 2

list={-(r/(-d + k r)), -(r/(-d + k r)), 0}


How can I apply $>$ to the list to find all elements of the list greater than or equal to 0 in combination with Reduce?

Desired output

The same as

Reduce[{list[] >= 0, list[] >= 0, list[] >= 0}]


which has output

(k < 0 && ((d < 0 && (r <= 0 || r > d/k)) || (d ==
0 && (r < 0 || r > 0)) || (d >
0 && (r < d/k || r >= 0)))) || (k ==
0 && ((d < 0 && r <= 0) || (d > 0 && r >= 0))) || (k >
0 && ((d < 0 && d/k < r <= 0) || (d > 0 && 0 <= r < d/k)))


For the first question, you can map GreaterThan over the list of values. If they are numeric, it will evaluate to True or False.

GreaterThan /@ {1, 4, 5, -2}
(* {True, True, True, False} *)


If the list is not numeric, it does not evaluate,

GreaterThan /@ {-(r/(-d + k r)), -(r/(-d + k r)), 0}
(* {-(r/(-d + k r)) > 0, -(r/(-d + k r)) > 0, False} *)


and so you can feed the above directly to Reduce after removing the last element because Reduce[{anything, False}] returns False.

Reduce[GreaterThan /@ {-(r/(-d + k r)), -(r/(-d + k r))}]
(* (k <
0 && ((d <= 0 && (r < 0 || r > d/k)) || (d >
0 && (r < d/k || r > 0)))) || (k ==
0 && ((d < 0 && r < 0) || (d > 0 && r > 0))) || (k >
0 && ((d < 0 && d/k < r < 0) || (d > 0 && 0 < r < d/k))) *)


Note

Reduce[GreaterEqualThan /@ {-(r/(-d + k r)), -(r/(-d + k r)),0}]


solves the second example.

• Thanks. This is what I was working for.
– AzJ
May 1, 2018 at 17:06
Positive @ {1, 4, 5, -2} (* or *)


{True, True, True, False}

FullSimplify @ Reduce[NonNegative /@ {-(r/(-d + k r)), -(r/(-d + k r))}] (* or *)
FullSimplify @ Reduce[Thread[GreaterEqual[{-(r/(-d + k r)), -(r/(-d + k r))}, 0]]]


(k < 0 && ((d == 0 && r != 0) || (d < 0 && k r < d) || (d > 0 && d < k r))) || (d < 0 && r <= 0 && (d < k r || k <= 0)) || (d > 0 && r >= 0 && (d > k r || k <= 0))

Timings: Positive@lst is faster than Thread[Greater[lst, 0]] which, in turn, is faster than GreaterThan/@lst:

lst = RandomReal[{-1,1},1000000];
(r1 = Positive[lst];)//RepeatedTiming // First


0.017

(r2 = Thread[Greater[lst, 0]];)//RepeatedTiming // First


0.414

(r3 = GreaterThan/@lst;)//RepeatedTiming // First


0.538

r1==r2 ==r3


True

For numeric data, integer arithmetric is very fast:

list = RandomInteger[{-10, 10}, {1000000}];
threshold = 2;
a = Greater[#, threshold] & /@ list; // RepeatedTiming // First
b = Positive[Subtract[list, threshold]]; // RepeatedTiming // First
c = Subtract[1, UnitStep[Subtract[threshold, list]]]; // RepeatedTiming // First

a == b
a == (c /. {0 -> False, 1 -> True})


0.507

0.016

0.00370

True

True

You have to interpret 1 as True and 0 as False. For example, this works very well with the three argument version of Pick.

Most compact method:

SetAttributes[Greater, Listable];
{1, 4, 5, -2} > 0
(* {True, True, True, False} *)

SetAttributes[GreaterEqual, Listable]
{-(r/(-d + k r)), -(r/(-d + k r)), 0} >= 0 // Reduce