Integer Partition Refinement in Sage

961 Views Asked by At

A partition of an integer $n$ is a non-decreasing list of positive integers summing to $n$. For example, $3$ can be partitioned as $1 + 1 + 1$, $1 + 2$ or just $3$, but $2 + 1$ is indistinct from $1 + 2$ (e.g., order does not matter).

A refinement of a partition $P$ of $n$ is (I hope I'm using this term correctly) another partition of $n$ obtained by further partitioning the elements of $P$. That definition is a little loose, but I hope an example will clarify. The partitions $(1,1,1,3)$ and $(1,1,2,2)$ both refine $(3,3)$, since they are each obtained by partitioning the elements of $(3,3)$. By contrast, $(2,4)$ is also a partition of $6$, but it does not refine $(3,3)$. (Notice refinement induces a poset structure on the collection of partitions of an integer.)

Given a particular partition $P$ of $n$, is there a built-in function in Sage to iterate over all refinements of $P$? For example, iterating over the refinements of $(2,3)$ should produce something like the list $(2,3)$, $(1,2,2)$, $(1,1,3)$, $(1,1,1,2)$, $(1,1,1,1,1)$.

I see how one could build such a function "from scratch" (list all partitions for each entry and just stitch them together), but I wonder if there is something hidden in a number theory or lattice/poset theory package that I'm not aware of.

Alternate Goal: For my purposes, I would even be happy with the ability to efficiently check whether one integer partition refines another (as opposed to returning the list of all such refinements).

Update: Some evidence that this problem is hard in general and a suggested solution via integer linear programming.

2

There are 2 best solutions below

0
On BEST ANSWER

I don't currently have Sage installed but browsing the documentation seems to indicate that taking a closed interval (with one end of the interval being your partition in question and the other end being the finest, all-ones partition) of the IntegerPartitions poset should do the trick.

EDIT: I just tested it on SageMathCell, an online Sage interface, and it seems to work fine.

> P = Posets.IntegerPartitions(6);
> print(P.closed_interval((3,2,1), P.top()));
> P = Posets.IntegerPartitions(7);
> print(P.closed_interval((4,3), P.top()));

[(3, 2, 1), (3, 1, 1, 1), (2, 2, 1, 1), (2, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1)]
[(4, 3), (4, 2, 1), (4, 1, 1, 1), (3, 3, 1), (3, 2, 2), (3, 2, 1, 1), (3, 1, 1, 1, 1), (2, 2, 2, 1), (2, 2, 1, 1, 1), (2, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1)]

EDIT #2: You can also use is_gequal() to test if one partition is a refinement of another.

> P = Posets.IntegerPartitions(6);
> P.is_gequal((2,2,1,1), (3,3));

True

> P = Posets.IntegerPartitions(6);
> P.is_gequal((4,2), (3,3));

False
0
On

Good question. But the list of refinements of a composition is implemented. Thus you can do the following:

def finer(p):
    # Return the list of all partitions refining the given partition ``p``.
    # 
    # EXAMPLES::
    # 
    #     sage: finer(Partition([3,2,1]))
    #     [[1, 1, 1, 1, 1, 1], [2, 1, 1, 1, 1], [2, 2, 1, 1], [3, 1, 1, 1], [3, 2, 1]]
    P = Partitions() # just the constructor
    c = Compositions()(p) # make p into a composition
    return uniq([P(sorted(d, reverse=True)) for d in c.finer()])

This is probably not a very fast method, though... (The uniq is a blunt weapon.)