Re: Select from Tuplet using logical expression

• To: mathgroup at smc.vnet.net
• Subject: [mg116861] Re: Select from Tuplet using logical expression
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Wed, 2 Mar 2011 04:37:26 -0500 (EST)

```m = 3;

n = Range[0, m];

sol = Select[Tuples[n, 3], FreeQ[Most[#], #[[-1]]] &];

Or you could use Cases or DeleteCases

sol ==
Cases[Tuples[n, 3], _?(FreeQ[Most[#], #[[-1]]] &)] ==

DeleteCases[Tuples[n, 3], _?(MemberQ[Most[#], #[[-1]]] &)]

True

For an indexed variable

f /@ # & /@ sol

{{f[0], f[0], f[1]}, {f[0], f[0], f[2]}, {f[0], f[0], f[3]}, {f[0], f[1],
f[2]}, {f[0], f[1], f[3]}, {f[0], f[2], f[1]}, {f[0], f[2], f[3]}, {f[0],
f[3], f[1]}, {f[0], f[3], f[2]}, {f[1], f[0], f[2]}, {f[1], f[0],
f[3]}, {f[1], f[1], f[0]}, {f[1], f[1], f[2]}, {f[1], f[1], f[3]}, {f[1],
f[2], f[0]}, {f[1], f[2], f[3]}, {f[1], f[3], f[0]}, {f[1], f[3],
f[2]}, {f[2], f[0], f[1]}, {f[2], f[0], f[3]}, {f[2], f[1], f[0]}, {f[2],
f[1], f[3]}, {f[2], f[2], f[0]}, {f[2], f[2], f[1]}, {f[2], f[2],
f[3]}, {f[2], f[3], f[0]}, {f[2], f[3], f[1]}, {f[3], f[0], f[1]}, {f[3],
f[0], f[2]}, {f[3], f[1], f[0]}, {f[3], f[1], f[2]}, {f[3], f[2],
f[0]}, {f[3], f[2], f[1]}, {f[3], f[3], f[0]}, {f[3], f[3], f[1]}, {f[3],
f[3], f[2]}}

For a subscripted variable

Subscript[f, #] & /@ # & /@ sol

{{Subscript[f, 0], Subscript[f, 0], Subscript[f, 1]}, {Subscript[f, 0],
Subscript[f, 0], Subscript[f, 2]},
{Subscript[f, 0], Subscript[f, 0], Subscript[f, 3]}, {Subscript[f, 0],
Subscript[f, 1], Subscript[f, 2]},
{Subscript[f, 0], Subscript[f, 1], Subscript[f, 3]}, {Subscript[f, 0],
Subscript[f, 2], Subscript[f, 1]},
{Subscript[f, 0], Subscript[f, 2], Subscript[f, 3]}, {Subscript[f, 0],
Subscript[f, 3], Subscript[f, 1]},
{Subscript[f, 0], Subscript[f, 3], Subscript[f, 2]}, {Subscript[f, 1],
Subscript[f, 0], Subscript[f, 2]},
{Subscript[f, 1], Subscript[f, 0], Subscript[f, 3]}, {Subscript[f, 1],
Subscript[f, 1], Subscript[f, 0]},
{Subscript[f, 1], Subscript[f, 1], Subscript[f, 2]}, {Subscript[f, 1],
Subscript[f, 1], Subscript[f, 3]},
{Subscript[f, 1], Subscript[f, 2], Subscript[f, 0]}, {Subscript[f, 1],
Subscript[f, 2], Subscript[f, 3]},
{Subscript[f, 1], Subscript[f, 3], Subscript[f, 0]}, {Subscript[f, 1],
Subscript[f, 3], Subscript[f, 2]},
{Subscript[f, 2], Subscript[f, 0], Subscript[f, 1]}, {Subscript[f, 2],
Subscript[f, 0], Subscript[f, 3]},
{Subscript[f, 2], Subscript[f, 1], Subscript[f, 0]}, {Subscript[f, 2],
Subscript[f, 1], Subscript[f, 3]},
{Subscript[f, 2], Subscript[f, 2], Subscript[f, 0]}, {Subscript[f, 2],
Subscript[f, 2], Subscript[f, 1]},
{Subscript[f, 2], Subscript[f, 2], Subscript[f, 3]}, {Subscript[f, 2],
Subscript[f, 3], Subscript[f, 0]},
{Subscript[f, 2], Subscript[f, 3], Subscript[f, 1]}, {Subscript[f, 3],
Subscript[f, 0], Subscript[f, 1]},
{Subscript[f, 3], Subscript[f, 0], Subscript[f, 2]}, {Subscript[f, 3],
Subscript[f, 1], Subscript[f, 0]},
{Subscript[f, 3], Subscript[f, 1], Subscript[f, 2]}, {Subscript[f, 3],
Subscript[f, 2], Subscript[f, 0]},
{Subscript[f, 3], Subscript[f, 2], Subscript[f, 1]}, {Subscript[f, 3],
Subscript[f, 3], Subscript[f, 0]},
{Subscript[f, 3], Subscript[f, 3], Subscript[f, 1]}, {Subscript[f, 3],
Subscript[f, 3], Subscript[f, 2]}}

Bob Hanlon

---- Lengyel Tamas <lt648 at hszk.bme.hu> wrote:

Hello.

Skip if needed:
///I am working on a part combinatorical problem with sets of 3
differently indexed values (e.g. F_i, F_j, F_k, F denoting frequency
channels) which are subsets of many values (e.g 16 different frequency
channels, denoted F_0, F_1 ... F_15).

Now, I need to select triplets from these channels, I used Tuplets. So far
so good. From these I need those combinations where indexes i!=k and/or
j!=k, and i=j is allowed (e.g {i,j,k} = {12, 12, 4} is a valid channel
combination, but {3, 12, 3} is not).///

So basically I need to generate triplets from a range of integer numbers,
where the first and second elements of these triplets do not match the
third. I thought Select would help, but I don't know if there exists an
option to control elements' values in a condition.

>From then on I must use these triplets' elements in a function.

But first I am asking your help in generating thos triplets of numbers.

Thanks.

Tam=C3=A1s Lengyel

```

• Prev by Date: Re: Problem exporting to LaTex
• Next by Date: Re: NIntegrate and speed
• Previous by thread: Re: Select from Tuplet using logical expression
• Next by thread: Re: Select from Tuplet using logical expression