Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Combination/Permutation questions

  • To: mathgroup at
  • Subject: [mg37462] Re: [mg37436] Combination/Permutation questions
  • From: "Michael Chang" <michael_chang86 at>
  • Date: Thu, 31 Oct 2002 04:41:36 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Hi Andrzej,

Many thanks for your help and solutions!

Actually, for completeness, I believe that for In[3], the input should have 

In[3]:= Perms[{a,b,c,d,e},2]

but I think that this is probably clear from Out[3] anyways.

Also, after seeing what *expert* Mathematica programmers do ;), I've found 
that for In[6],


seems to produce the expected number of sets when using, for example,

In[7]:= f[{a,b,c,d},3]

(A slightly larger set tends to result otherwise, due to the inclusion of 
some sets with Lenth[#]!=k.)



>From: Andrzej Kozlowski <andrzej at>
To: mathgroup at
>To: Andrzej Kozlowski <andrzej at>
>CC: michael_chang86 at (Michael Chang), mathgroup at
>Subject: [mg37462] Re: [mg37436] Combination/Permutation questions
>Date: Tue, 29 Oct 2002 23:23:21 +0900
>I guess I did not exactly answer your last question. To select those  
>expressions that involve just one minus use:
>       d,c-d,-a+d,a+d,-b+d,b+d,-c+d,c+d};
>On Tuesday, October 29, 2002, at 05:20 PM, Andrzej Kozlowski wrote:
>>On Tuesday, October 29, 2002, at 02:09 PM, Michael Chang wrote:
>>>First, suppose that I have 4 objects, a, b, c, and d, respectively.
>>>How can I generate the permutation set when chosing, say, only *2*
>>>In[1]:=  Permutations[{a,b,c,d}]
>>>gives me the permutation set when choosing *all* 4 objects ... :(
>>   b,e},{e,b},{c,d},{d,c},{c,e},{e,c},{d,e},{e,d}}
>>>Second, for the same four objects (a,b,c,d), to generate the
>>>*combination* set (with 2 elements), I use:
>>>In[2]:=  Needs["DiscreteMath`Combinatorica`"];
>>>In[3]:=  cset=KSubsets[{a,b,c,d},2]
>>>and this generates the expected 6 combinatorial pairs
>>>What I'd like to do next is add each combinatorial set, and I am able
>>>to do this correctly via:
>>>In[4]:=  Plus@@Transpose[cset]
>>>to obtain {a+b,a+c,a+d,b+c,b+d,c+d}.
>>>My problem lies in the fact that now, I'd like to be able to allow
>>>*each* (a,b,c,d) element to be either plus, or minus (in reality, I'm
>>>trying to generate combinatorial adds/minuses for *functions*
>>>(a,b,c,d)), and to still generate the 'sum' of the cominatorial set.
>>>So for instance, in my current example, for the *first* {a,b}
>>>combinatorial pair, I'd like to be able to generate
>>>(which generates {a+b,a-b,-a+b,-a-b}) ... only I'd like this to be
>>>somehow done automatically for *each* combinatorial pair (and, for the
>>>more general case when I generate combinatorial sets involving only
>>>'k' elements).  I've struggled with this for a while, and am only able
>>>to generate such a list *manually* for each of my six original
>>>combinatorial pairs ... a tedious, and somewhat tiresome procedure! :(
>>>  Is there a way of 'easily' doing this?!?
>>For example:
>>   c-d,c-d,-a+d,a+d,-b+d,b+d,-c+d,c+d}
>>>With my newly generated list (having 4*6 'elements'), how can I also
>>>go about finding which expressions involve/use only, say, 1 Minus?  Is
>>>there an 'easy' way of doing this too?  (For instance, I'd like to
>>>then 'filter' for (a-b) and (b-a) ...)  (Perhaps the count of 1 Minus
>>>is a little contrived for this example here, but for the more general
>>>case I'll probably be considering, I might need to filter for, say,
>>>(longer) expressions involving 2 Minuses (say).)
>>In cases like the above the following will work:
>>Andrzej Kozlowski
>>Yokohama, Japan
>Andrzej Kozlowski
>Yokohama, Japan

| Déconfiture                   |              Et vivre est dur |
| Des pépins                    |             Toujours un choix |
| Mais je veux croire           |                  Mais je jure |
| En l'au-delà                  |        Que le monde est à moi |
Extrait de "Dessine-moi un mouton" par Mylène Farmer

Get faster connections -- switch to MSN Internet Access!

  • Prev by Date: Re: Not quite a Swell FLOOP?
  • Previous by thread: Re: Combination/Permutation questions
  • Next by thread: Ted Ersek's Tips and Tricks ... Updated