0
$\begingroup$

Here is a question difficult to explain (it's the reason of the weird title).

Say I have a set of elements

s = {a, b, c}

for wich I want to construct the set of all possible permutations of the form

s = {a ** b, a ** c, b ** c}

where ** stands for either >, or <. The desired output in this case is

{{a < b, a < c, b < c},{a < b, a > c, b < c},{a < b, a < c, b > c},{a < b, a > c, b > c}, {a > b, a < c, b < c},{a > b, a > c, b < c},{a > b, a < c, b > c},{a < b, a > c, b > c}}

$\endgroup$
  • $\begingroup$ Thanks corey979 but it is not exactly what I expect. I want b ** a transformed eventually in a ** b and ** should be Greater ... or -> $\endgroup$ – cyrille.piatecki Nov 10 '16 at 11:07
  • $\begingroup$ corey979 I dont understand what is unclear here is on a simpler set what I expect {a, b, c} Gives {{a < b, a < c, b < c}, {a < b, c < a, b < c},{a < b, a < c, c < b}, {a < b, c < a, b < c}, {b < a, a < c, b < c}, {b < a, c < a, b < c},{b < a, a < c, c < b}, {b < a, c < a, b < c}} or {{a -> b, a -> c, b -> c}, {a -> b, c -> a, b -> c},{a -> b, a -> c, c -> b}, {a -> b, c -> a, b -> c}, {b -> a, a -> c, b -> c}, {b -> a, c -> a, b -> c},{b -> a, a -> c, c -> b}, {b -> a, c -> a, b -> c}} $\endgroup$ – cyrille.piatecki Nov 10 '16 at 11:33
  • $\begingroup$ Dear Cyrille, I took the liberty to rephrase your question. See if it's really what you are after. $\endgroup$ – corey979 Nov 10 '16 at 11:39
1
$\begingroup$

With

s = {a, b, c}

make

sub = Subsets[s, {2}]

{{a, b}, {a, c}, {b, c}}

and

tup = Tuples[{Greater, Less}, {Length@sub}]

{{Greater, Greater, Greater}, {Greater, Greater, Less}, {Greater, Less, Greater}, {Greater, Less, Less}, {Less, Greater, Greater}, {Less, Greater, Less}, {Less, Less, Greater}, {Less, Less, Less}}

Then

Table[MapThread[Apply, {tup[[i]], sub}], {i, 1, Length@tup}]

{{a > b, a > c, b > c}, {a > b, a > c, b < c}, {a > b, a < c, b > c}, {a > b, a < c, b < c}, {a < b, a > c, b > c}, {a < b, a > c, b < c}, {a < b, a < c, b > c}, {a < b, a < c, b < c}}

$\endgroup$
  • $\begingroup$ Ok I was wrong but I want all the possible permutations. Not only {a > b, a > c, a > d, b > c, b > d, c > d} but also {b > a, a > c, a > d, b > c, b > d, c > d} , {b > a, c > a, a > d, b > c, b > d, c > d}... And how to replace > by -> ? $\endgroup$ – cyrille.piatecki Nov 10 '16 at 11:15
  • $\begingroup$ I have edited the question but I was precise I have writen a symbol like (<) or an arrow of substitution (->) $\endgroup$ – cyrille.piatecki Nov 10 '16 at 11:23

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.