[Next] [Prev] [_____] [Left] [Up] [Index] [Root]
Partitions

Partitions

Partitions(n) : RngIntElt -> [ [ RngIntElt ] ]
The unrestricted partitions of the positive integer n. This function returns a sequence of integer sequences, each of which is a different sequence of positive integers (in descending order) adding up to n. The integer n must be small.
NumberOfPartitions(n) : RngIntElt -> RngIntElt
The number of unrestricted partitions of the non-negative integer n. The integer n must be small.
RestrictedPartitions(n, Q) : RngIntElt, SetEnum -> [ [ RngIntElt ] ]
The partitions of the positive integer n, restricted to elements of the set Q, which must contain positive integers only. This function returns a sequence of integer sequences, each of which is a different sequence of positive integers (in descending order) adding up to n and each contained in Q (repetitions are allowed in the partition).

Example EnumComb_Partitions (H54E2)

The conjugacy classes of the symmetric group on n elements correspond to the partitions of n. The function PartnToElt below converts a partition to an element of the corresponding conjugacy class.

> PartitionToElt := function(G, p)
>     x := [];
>     s := 0;
>     for d in p do
>         x cat:= Rotate([s+1 .. s+d], -1);
>         s +:= d;
>     end for;
>     return G!x;
> end function;
>
> ConjClasses := function(n)
>     G := Sym(n);
>     return [ PartitionToElt(G, p) : p in Partitions(n) ];
> end function;
>
> ConjClasses(5);
[
    (1, 2, 3, 4, 5),
    (1, 2, 3, 4),
    (1, 2, 3)(4, 5),
    (1, 2, 3),
    (1, 2)(3, 4),
    (1, 2),
    Id($)
]
> Classes(Sym(5));
Conjugacy Classes
-----------------
[1]     Order 1       Length 1      
        Rep Id($)

[2] Order 2 Length 10 Rep (1, 2)

[3] Order 2 Length 15 Rep (1, 2)(3, 4)

[4] Order 3 Length 20 Rep (1, 2, 3)

[5] Order 4 Length 30 Rep (1, 2, 3, 4)

[6] Order 5 Length 24 Rep (1, 2, 3, 4, 5)

[7] Order 6 Length 20 Rep (1, 2, 3)(4, 5)


Example EnumComb_RestrictedPartitions (H54E3)

The number of ways of changing one dollar into five, ten, twenty and fifty cent coins can be calculated using RestrictedPartitions. There is also a well known solution from generating functions, which we use as a check.

> coins := {5, 10, 20, 50};
> T := [#RestrictedPartitions(n, coins) : n in [0 .. 100 by 5]];
> T;
[ 1, 1, 2, 2, 4, 4, 6, 6, 9, 9, 13, 13, 18, 18, 24, 24, 31, 31, 39, 39, 49 ]
> F<t> := PowerSeriesAlgebra(RationalField(), 101);
> &*[1/(1-t^i) : i in coins];
1 + t^5 + 2*t^10 + 2*t^15 + 4*t^20 + 4*t^25 + 6*t^30 + 6*t^35 + 9*t^40 + 9*t^45 
    + 13*t^50 + 13*t^55 + 18*t^60 + 18*t^65 + 24*t^70 + 24*t^75 + 31*t^80 + 
    31*t^85 + 39*t^90 + 39*t^95 + 49*t^100 + O(t^101)
[Next] [Prev] [_____] [Left] [Up] [Index] [Root]