Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I took a look to the code of the VectorPartitions and there was a line that i could not understand immediately...

@staticmethod
def __classcall_private__(cls, vec, min=None, parts=None, distinct=False, is_repeatable=None):
    r"""
    Create the class of vector partitions of ``vec`` where all parts
    are greater than or equal to the vector ``min``.

    EXAMPLES::

        sage: VP1 = VectorPartitions([2, 1])
        sage: VP2 = VectorPartitions((2, 1), min = [0, 1])
        sage: VP1 is VP2
        True
    """
    if min is None:
        min = find_min(vec)  # tuple([0 for v in vec[:-1]]+[1])
    if parts is None:
        parts = list(IntegerVectorsIterator(vec, min=min))
    if [0]*len(vec) in parts:
        parts.remove([0]*len(vec))
    if min in parts:
        min_index = parts.index(min)
        parts = parts[min_index:]
    parts = list(parts)
    for part_index in range(len(parts)):
        parts[part_index] = tuple(parts[part_index])
    return super().__classcall__(cls, tuple(vec), tuple(min), tuple(parts), distinct, is_repeatable)

The line that was somehow strange was the one where the code wants to work with the minimal vector [0, ... , 0, 1]... So i tried to use my min, to overwrite...

Let us compare:

sage: a, b, c = (0, 1), (1, 0), (1, 1)
sage: 
sage: for p in Permutations((a,b,c)):
....:     print(p, '--->', list(VectorPartitions([2, 2], parts=p)))
....: 
[(0, 1), (1, 0), (1, 1)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(0, 1), (1, 1), (1, 0)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(1, 0), (0, 1), (1, 1)] ---> [[[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(1, 0), (1, 1), (0, 1)] ---> []
[(1, 1), (0, 1), (1, 0)] ---> [[[0, 1], [1, 0], [1, 1]], [[0, 1], [0, 1], [1, 0], [1, 0]]]
[(1, 1), (1, 0), (0, 1)] ---> []
sage:

Yes, against my wish. We get a correct answer only when the parts are lexicographically sorted. Or we declare our min:

sage: for p in Permutations((a,b,c)):
....:     print(p, '--->', list(VectorPartitions([2, 2], parts=p, min=[0, 0])))
....: 
[(0, 1), (1, 0), (1, 1)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(0, 1), (1, 1), (1, 0)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(1, 0), (0, 1), (1, 1)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(1, 0), (1, 1), (0, 1)] ---> [[[0, 1], [0, 1], [1, 0], [1, 0]], [[0, 1], [1, 0], [1, 1]], [[1, 1], [1, 1]]]
[(1, 1), (0, 1), (1, 0)] ---> [[[1, 1], [1, 1]], [[0, 1], [1, 0], [1, 1]], [[0, 1], [0, 1], [1, 0], [1, 0]]]
[(1, 1), (1, 0), (0, 1)] ---> [[[1, 1], [1, 1]], [[0, 1], [1, 0], [1, 1]], [[0, 1], [0, 1], [1, 0], [1, 0]]]
sage:

(Tuples are used in order to have quickly the permutations.) (I did not try other cases... Hope it works, it is late in the night here...)