[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] A combinatorial question
From: |
Bill Page |
Subject: |
Re: [Axiom-mail] A combinatorial question |
Date: |
Tue, 2 Oct 2007 20:36:44 -0400 |
On 10/2/07, Alasdair McAndrew wrote:
> To experiment with a little algorithm, I need to generate all subsets of a
> set S which have fixed cardinality; for example to generate all three
> element subsets of {1,2,3,4,5,6,7}. Is there an inbuilt command to do this
> in Axiom? Or has somebody written a package to do such a thing?
>
Here is one possible solution using the subSet operation:
(1) -> subsets(s,n) == set [set map(i+->parts(s).(i+1),j) for j in [subSet(#s,n,
k) for k in 0..binomial(#s,n)-1]]
Type: Void
(2) -> subsets(expand(1..7),3)
Compiling function subsets with type (List Integer,PositiveInteger)
-> Set Set Integer
(2)
{{1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}, {1,2,5}, {1,3,5}, {2,3,5}, {1,4,5},
{2,4,5}, {3,4,5}, {1,2,6}, {1,3,6}, {2,3,6}, {1,4,6}, {2,4,6}, {3,4,6},
{1,5,6}, {2,5,6}, {3,5,6}, {4,5,6}, {1,2,7}, {1,3,7}, {2,3,7}, {1,4,7},
{2,4,7}, {3,4,7}, {1,5,7}, {2,5,7}, {3,5,7}, {4,5,7}, {1,6,7}, {2,6,7},
{3,6,7}, {4,6,7}, {5,6,7}}
Type: Set Set Integer
Regards,
Bill Page.