# Reduce all pairwise comparisons in a list

I have a list of 37 values, like $$2d^2$$ and $$2d(1-d^2)$$. I know I can use Reduce[] to solve an inequality of the values. For example,

Reduce[2 d^2 >= (2 d (1 + d^2)), d]


returns

d<=0


However, to retype this function for each pairwise comparison for all 37 elements in the list would be exhausting and redundant.

How can I use Reduce[] to solve inequalities of all pairwise comparisons of elemetns in a list?

I tried

For[j = 1, j = 37, j++,For[i = 1, i = 37, i++,Print[Reduce[{mylist[[i ;; i]] >= mylist[[j ;; j]]}, d]]]]


and

Do[Reduce[{mylist[[i ;; i]] >= mylist[[i + 1 ;; i + 1]]}, d], {i, 6}]


but there was no output.

I also tried

Do[Print[Reduce[mylist >= mylist, d]], {mylist}]


which returned a list of $$d\in \mathbb{R}$$, which is not at all what I'm expecting.

• try BlockMap[Reduce[#,d]&@@#&, mylist,2,1]?
– kglr
Commented Jun 13, 2019 at 18:04
• could you let us have the list of 37 inequalities? thanks Commented Jun 13, 2019 at 18:04
• @Manuel--Moe--G This should help with a reproducible example: mylist={0,2,4,2d,2d^2,2d(1+d),-(2(1+d)+((4d^3)/(1-d)))(d-1)} Commented Jun 13, 2019 at 18:10

mylist = {0, 2, 4, 2d, 2d^2, 2d(1+d), -(2(1+d)+((4d^3)/(1-d)))(d-1)} ;


For pairs of consecutive elements you can use BlockMap:

BlockMap[Reduce[#[[1]] >= #[[2]], d] &, mylist, 2, 1]


{False, False, d <= 2, 0 <= d <= 1, d <= 0, d <= -(1/Sqrt[2]) || 1/Sqrt[2] <= d <= 1}

Alternatively, you can use MapThread:

MapThread[Reduce[# >= #2, d] &, {Most@mylist, Rest@mylist}]


same result

For all possible pairs, use Tuples:

Reduce[#[[1]] >= #[[2]], d]& /@ Tuples[mylist, {2}]


{True, False, False, d <= 0, d == 0, -1 <= d <= 0, d <= Root[1 - #^2 + 2 #^3& , 1, 0], True, True, False, d <= 1, -1 <= d <= 1, 1/2 (-1 - Sqrt[5]) <= d <= 1/2 (-1 + Sqrt[5]), d <= 1/2, True, True, True, d <= 2, -Sqrt[2] <= d <= Sqrt[2], -2 <= d <= 1, d <= 1, d >= 0, d >= 1, d >= 2, d ∈ Reals, 0 <= d <= 1, d == 0, d <= Root[1 - # - #^2 + 2 #^3& , 1, 0], d ∈ Reals, d <= -1 || d >= 1, d <= -Sqrt[2] || d >= Sqrt[2], d <= 0 || d >= 1, d ∈ Reals, d <= 0, d <= Root[1 - 2 #^2 + 2 #^3& , 1, 0], d <= -1 || d >= 0, d <= 1/2 (-1 - Sqrt[5]) || d >= 1/2 (-1 + Sqrt[5]), d <= -2 || d >= 1, d ∈ Reals, d >= 0, d ∈ Reals, d <= -(1/Sqrt[2]) || 1/Sqrt[2] <= d <= 1, d >= Root[1 - #^2 + 2 #^3& , 1, 0], d == 0 || d >= 1/2, d >= 1, d >= Root[1 - # - #^2 + 2 #^3& , 1, 0], d >= Root[ 1 - 2 #^2 + 2 #^3& , 1, 0], -(1/Sqrt[2]) <= d <= 1/Sqrt[2] || d >= 1, d ∈ Reals}

Update: Form your example in the comments, it seems that you need Subsets:

Reduce[#[[1]] >= #[[2]], d]& /@ Subsets[mylist, {2}]


{False, False, d <= 0, d == 0, -1 <= d <= 0, d <= Root[1 - #^2 + 2 #^3& , 1, 0], False, d <= 1, -1 <= d <= 1, 1/2 (-1 - Sqrt[5]) <= d <= 1/2 (-1 + Sqrt[5]), d <= 1/2, d <= 2, -Sqrt[2] <= d <= Sqrt[2], -2 <= d <= 1, d <= 1, 0 <= d <= 1, d == 0, d <= Root[1 - # - #^2 + 2 #^3& , 1, 0], d <= 0, d <= Root[1 - 2 #^2 + 2 #^3& , 1, 0], d <= -(1/Sqrt[2]) || 1/Sqrt[2] <= d <= 1}

If needed, use ToRadicals to get transform Root expressions:

ToRadicals @ %


{False, False, d <= 0, d == 0, -1 <= d <= 0, d <= 1/6 (1 - 1/(53 - 6 Sqrt[78])^(1/3) - (53 - 6 Sqrt[78])^( 1/3)), False, d <= 1, -1 <= d <= 1, 1/2 (-1 - Sqrt[5]) <= d <= 1/2 (-1 + Sqrt[5]), d <= 1/2, d <= 2, -Sqrt[2] <= d <= Sqrt[2], -2 <= d <= 1, d <= 1, 0 <= d <= 1, d == 0, d <= 1/6 (1 - 7/(44 - 3 Sqrt[177])^(1/3) - (44 - 3 Sqrt[177])^(1/3)), d <= 0, d <= 1/3 (1 - 2^(2/3)/(23 - 3 Sqrt[57])^(1/3) - (23 - 3 Sqrt[57])^(1/3)/ 2^(2/3)), d <= -(1/Sqrt[2]) || 1/Sqrt[2] <= d <= 1}

• With mylist={0,2,4,2d,2d^2,2d(1+d),-(2(1+d)+((4d^3)/(1-d)))(d-1)}, BlockMap[Reduce[#[[1]] > #[[2]], d] &, mylist, 2, 1] returns a list of 6 elements, whereas I would expect a list of 21 elements, which is all unique pairwise comparisons. Commented Jun 13, 2019 at 18:16
• The Reduce[#[[1]]<=#[[2]],d]&/@Subsets[ mylist,{2}] is exactly what I needed. Thank you for your help. You've saved me a lot of labor and heartache. Commented Jun 13, 2019 at 18:29