This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients LambertDW, TFinley, mark.dickinson, rhettinger
Date 2009-01-07.21:10:11
SpamBayes Score 3.3207663e-05
Marked as misclassified No
Message-id <1231362616.43.0.645953276392.issue4816@psf.upfronthosting.co.za>
In-reply-to
Content
Results from Magma, Sage and Gap:

Magma provides functions "Subsets(S, k)" and "Permutations(S, k)".  From 
the documentation:

Subsets(S, k) : The set of subsets of the set S of size k. If k is 
larger than the cardinality of S then the result will be empty.

Permutations(S, k) : The set of permutations (stored as sequences) of 
each of the subsets of the set S of cardinality k.

GAP has the same behaviour: even if you've never encountered GAP before, 
it's fairly Pythonesque, so the following extract from a GAP 4 REPL
means exactly what you think it does:

gap> Combinations([1,2,3,4], 3);
[ [ 1, 2, 3 ], [ 1, 2, 4 ], [ 1, 3, 4 ], [ 2, 3, 4 ] ]
gap> Combinations([1,2,3,4], 5);
[  ]

Permutations work the same way (but the function is called 
Arrangements):

gap> Arrangements([1,2,3,4], 3);
[ [ 1, 2, 3 ], [ 1, 2, 4 ], [ 1, 3, 2 ], [ 1, 3, 4 ], [ 1, 4, 2 ], 
  [ 1, 4, 3 ], [ 2, 1, 3 ], [ 2, 1, 4 ], [ 2, 3, 1 ], [ 2, 3, 4 ], 
  [ 2, 4, 1 ], [ 2, 4, 3 ], [ 3, 1, 2 ], [ 3, 1, 4 ], [ 3, 2, 1 ], 
  [ 3, 2, 4 ], [ 3, 4, 1 ], [ 3, 4, 2 ], [ 4, 1, 2 ], [ 4, 1, 3 ], 
  [ 4, 2, 1 ], [ 4, 2, 3 ], [ 4, 3, 1 ], [ 4, 3, 2 ] ]
gap> Arrangements([1,2,3,4], 5);
[  ]

Combinations([1,2,3,4], -1) gives an error.  Interestingly, 
Arrangements([1,2,3,4], -1) returns the empty list.

GAP also has a NrCombinations function returning the number of 
combinations:

gap> NrCombinations([1,2,3,4], 5);
0
gap> NrCombinations([1,2,3,4], -1);
0

My Sage installation currently seems to be broken, but from the 
documentation it looks as though it just steals the functions from GAP.
History
Date User Action Args
2009-01-07 21:10:16mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, LambertDW, TFinley
2009-01-07 21:10:16mark.dickinsonsetmessageid: <1231362616.43.0.645953276392.issue4816@psf.upfronthosting.co.za>
2009-01-07 21:10:15mark.dickinsonlinkissue4816 messages
2009-01-07 21:10:13mark.dickinsoncreate