Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Why are permutations duplicated with LexicographicPermutations? How to avoid this?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54675] Re: [mg54628] Why are permutations duplicated with LexicographicPermutations? How to avoid this?
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 25 Feb 2005 01:19:56 -0500 (EST)
  • References: <200502240821.DAA13312@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

You get duplicates because the two zeroes are treated as distinct items, as if you'd entered:

Needs["DiscreteMath`Combinatorica`"]
LexicographicPermutations[{a, b, c, d}] /. {c -> 0, d -> 0}

Is this what you wanted, instead?

Union@LexicographicPermutations[{a,b,0,0}]

{{0,0,a,b},{0,0,b,a},{0,a,0,b},{0,a,b,0},{0,b,0,a},{0,b,a,0},{
   a,0,0,b},{a,0,b,0},{a,b,0,0},{b,0,0,a},{b,0,a,0},{b,a,0,0}}

or maybe...

LexicographicPermutations[{a,b,0}]/.(0\[RuleDelayed]Sequence[0,0])

{{a,b,0,0},{a,0,0,b},{b,a,0,0},{b,0,0,a},{0,0,a,b},{0,0,b,a}}

as for LexicographicPermutations[{0,C,D,0,G,H,J,0,0,P,0,0,T,V,0,X,Y,0,0,4,0,7,8,0}], you have GOT to be kidding. Even with the most conservative assumption, look how many permutations there'd be:

Length@Union@{0,C,D,0,G,H,J,0,0,P,0,0,T,V,0,X,Y,0,0,4,0,7,8,0}
%!

14

87178291200

Bobby

On Thu, 24 Feb 2005 03:21:32 -0500 (EST), Valentina Mikel <valentina.mikel at po.htnet.hr> wrote:

> When I enter
>
> LexicographicPermutations[{a, b, 0, 0}]
>
> the result is following:
> {{a, b, 0, 0}, {a, b, 0, 0}, {a, 0, b, 0}, {a, 0, 0, b}, {
>    a, 0, b, 0}, {a, 0, 0, b}, {b, a, 0, 0}, {b, a, 0, 0}, {
>    b, 0, a, 0}, {b, 0, 0, a}, {b, 0, a, 0}, {b, 0, 0, a}, {
>    0, a, b, 0}, {0, a, 0, b}, {0, b, a, 0}, {0, b, 0, a}, {
>    0, 0, a, b}, {0, 0, b, a}, {0, a, b, 0}, {0, a, 0, b}, {
>    0, b, a, 0}, {0, b, 0, a}, {0, 0, a, b}, {0, 0, b, a}}
>
>
> Why does the result repeat duplicate cases?
> In my case I must perform exact functionality of
> LexicographicPermutations[{0,C,D,0,G,H,J,0,0,P,0,0,T,V,0,X,Y,0,0,4,0,7,8,0}];
> since there are lots of duplicates I'm trying to implement this in C++
> for maximum speed.
>
> Can this be avoided in Mathematica itself, and how?
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: finding roots of 1 + 6*x - 8*x^3
  • Next by Date: Re: finding roots of 1 + 6*x - 8*x^3
  • Previous by thread: Re: Why are permutations duplicated with LexicographicPermutations? How to avoid this?
  • Next by thread: Re: Why are permutations duplicated with LexicographicPermutations? How to avoid this?