[Next][Prev] [Right] [Left] [Up] [Index] [Root]

Partitions

NumberOfPartitions(n) : RngIntElt -> RngIntElt
The number of unrestricted partitions of the non-negative integer n. The integer n must be small.
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.
Partitions(n, k) : RngIntElt, RngIntElt -> [ [ RngIntElt ] ]
The collection of all partitions of the positive integer n into k parts. This function returns a sequence of integer sequences, each of which is a distinct sequence of positive integers (in descending order) whose sum is n.
RestrictedPartitions(n, M) : RngIntElt, SetEnum -> [ [ RngIntElt ] ]
The partitions of the positive integer n, where the parts are restricted to being elements of the set M, 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) whose sum is n and each contained in M (repetitions are allowed in the partition).
RestrictedPartitions(n, k, M) : RngIntElt, SetEnum -> [ [ RngIntElt ] ]
The partitions of the positive integer n into k parts, where the parts are restricted to being elements of the set M, 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) whose sum is n and each contained in M (repetitions are allowed in the partition).
IsPartition(S) : SeqEnum -> BoolElt
A partition is considered to be a sequence of weakly decreasing positive integers. A sequence is allowed to have trailing zeros, and the empty sequence is accepted as a partition (of zero).
PartitionCovers(P1, P2) : SeqEnum, SeqEnum -> BoolElt
True if the young diagram of P1 covers the young diagram of P2. (see below for description of young diagram).
ConjugatePartition(P) : SeqEnum -> SeqEnum
For the young diagram corresponding to partition P, returned is the partition corresponding to its conjugate diagram. (see below for description of young diagram).
Weight(P) : SeqEnum -> RngIntElt
Will return the integer which the partition P is a partition of. Which is simply the sum of its entries.
IndexOfPartition(P) : SeqEnum -> RngIntElt
Lexicographical ordering of partitions is such that for partitions P1 and P2, P1 > P2 implies that P1 is greater in the first non-equal entry. The function returns the index of P with respect to lexicographical ordering of all the partitions of the same weight. The first index is zero.

Example EnumComb_Partitions (H92E2)

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 (H92E3)

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> := PowerSeriesRing(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] [Right] [Left] [Up] [Index] [Root]