1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ try BlockMap[Reduce[#,d]&@@#&, mylist,2,1]? $\endgroup$ – kglr Jun 13 '19 at 18:04
  • $\begingroup$ could you let us have the list of 37 inequalities? thanks $\endgroup$ – Manuel --Moe-- G Jun 13 '19 at 18:04
  • $\begingroup$ @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)} $\endgroup$ – Jay Schyler Raadt Jun 13 '19 at 18:10
6
$\begingroup$
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}

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Jay Schyler Raadt Jun 13 '19 at 18:16
  • $\begingroup$ @JaySchylerRaadt, please see the update. $\endgroup$ – kglr Jun 13 '19 at 18:19
  • 1
    $\begingroup$ 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. $\endgroup$ – Jay Schyler Raadt Jun 13 '19 at 18:29
  • $\begingroup$ @JaySchylerRaadt, my pleasure. Thank you for the accept and welcome to mma.se. $\endgroup$ – kglr Jun 13 '19 at 18:30
  • $\begingroup$ I think he wanted >= but the method of @kglr is great: Reduce[#[[1]]>=#[[2]],d]&/@Subsets[myList,{2}] $\endgroup$ – Mark R Jun 13 '19 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.