MathGroup Archive 1999

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

Search the Archive

Re: How to construct all possible orderings

  • To: mathgroup at
  • Subject: [mg15648] Re: [mg15588] How to construct all possible orderings
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Sat, 30 Jan 1999 04:28:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at

There are lots of ways to do this using Outer and List. For example this


will list all arranements with repetitions of k objects our of the list



There is also an "illegal" (meaning strongly discouraged by wri) way of
solving many such problems, which personally I rather like. You first
clear the Orderless attribute in Times.

ClearAttributes[Times, Orderless]

Next, note that if you simply evaluate

                 2                      2        2      2 a b a + c b a
+ b  a + a c a + b c a + c  a + b a  + c a  + 
   3                    2                      2        2
  a  + b a b + c a b + a  b + a c b + b c b + c  b + a b  + 
     2    3                    2                      2
  c b  + b  + b a c + c a c + a  c + a b c + c b c + b  c + 
     2      2    3
  a c  + b c  + c

you have essentially got your answer. If you want to get it in the usual
form you can do something like

    Power[x_,n_]:>Apply[Sequence,Table[x,{n}]]} Out[30]=
{{a, b, a}, {c, b, a}, {b, b, a}, {a, c, a}, {b, c, a}, 
  {c, c, a}, {b, a, a}, {c, a, a}, a, a, a, {b, a, b}, 
  {c, a, b}, {a, a, b}, {a, c, b}, {b, c, b}, {c, c, b}, 
  {a, b, b}, {c, b, b}, b, b, b, {b, a, c}, {c, a, c}, 
  {a, a, c}, {a, b, c}, {c, b, c}, {b, b, c}, {a, c, c}, 
  {b, c, c}, c, c, c}

The reason why this is discouraged is that users ar enot supposed to
change attributes of basic functions like Times. One can, this sort of
thing quite legitimatley using the Non-commutative algebra package
available from MathSource, or define your own NonCommutativeExpand.

On Thu, Jan 28, 1999, Carlos Carreto <ccarreto at> wrote:

>I am trying to construct all possible orderings  of  for example 3
>elements, where each element can be A, B or C.
>The result will be something like this: AAA
>. . .
>How can I do this? 
>Thank you.
>-:- Carlos

Andrzej Kozlowski
Toyama International University

  • Prev by Date: Re: question
  • Next by Date: Re: D vs. Derivative
  • Previous by thread: RE: How to construct all possible orderings
  • Next by thread: BesselK