sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.44k stars 481 forks source link

Implement ordered multiset partitions #25148

Closed alauve closed 6 years ago

alauve commented 6 years ago

An ordered multiset partition C of a multiset X is a list of subsets of X (not multisets), called the blocks of C, whose multi-union is X.

These objects appear in the work of

This module provides tools for manipulating ordered multiset partitions.

CC: @tscrim @darijgr @zabrocki @alauve @sagetrac-mshimo @anneschilling @saliola @amypang

Component: combinatorics

Keywords: IMA coding sprint, CHAs, sagedays@icerm

Author: Aaron Lauve, Anne Schilling

Branch: 085a93d

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/25148

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 4af474f to 830f5ae

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

89284befinished adding tests/examples for all functions; but found some errors to be corrected (see new TODO)
830f5aezapping bugs within `__init__` handling of constraints
alauve commented 6 years ago
comment:80

File in much better shape now (fingers crossed).

alauve commented 6 years ago
comment:82

Found some bugs in the __contains__ method

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

d18f780revamped tests for satisfying constraints
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 830f5ae to d18f780

alauve commented 6 years ago
comment:84

Bugs in __contains__ method zapped.

darijgr commented 6 years ago
comment:85

Branch is red (merge failed).

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from d18f780 to 659132f

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

659132ffix merge conflicts in references
alauve commented 6 years ago
comment:87

I think I should remove the user shorthand for OrderedMultisetPartition that uses OrderedMultisetPartitions.from_list().

While the shorthand is nice for OrderedMultisetPartition, I don't see how to make it play nicely with the __getitem__() method for combinatorial free modules over OrderedMultisetPartitions.

E.g., in the present state of ticket #25543, these come in correctly:

sage: from sage.combinat.chas.omp_hopf_algebras import HopfAlgebraOnOrderedMultisetPartitions
sage: H = HopfAlgebraOnOrderedMultisetPartitions(QQ).H()
sage: H[[1,2],[1,3]]
H[{1,2}, {1,3}]
sage: H[[[1,2],[1,3]]]
H[{1,2}, {1,3}]

But this one is problematic (there are two possible intended OMPs):

sage: H[[1,2]]

Should it be H(OrderedMultisetPartition([[1,2]])) or should it be H(OrderedMultisetPartition([1,2]))

NOTE: A similar shorthand confusion happens for WQSym (e.g., tickets #25133, #25151). There, I'd say the problem is even more serious due to the "words" option that we have allowed for that Hopf algebra. Indeed, perhaps this "bug" even merits a new ticket:

sage: M = WordQuasiSymmetricFunctions(QQ).M()
sage: x = M[[1,3],[2]]; x
M[{1, 3}, {2}]
sage: M.options.objects = "words"
sage: x
M[1, 2, 1]
sage: M[OrderedSetPartition([1,2,1])]
M[1, 2, 1]
sage: M[1,2,1]
M[1, 1]
sage: M[[1,2,1]]
M[1, 1]
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 659132f to 4598426

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4598426modified .split(), which was ignoring repeats
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

41f776cMerge branch 'public/combinat/implement_orbit_basis-25162' of trac.sagemath.org:sage into develop
5e92f49Merge branch 'develop' of trac.sagemath.org:sage into develop
357bf72Merge branch 'develop' into public/combinat/implement-ordered-multiset-partitions-25148
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 4598426 to 357bf72

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 357bf72 to df225ca

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

8bc94ebMerge branch 'develop' into public/combinat/implement-ordered-multiset-partitions-25148
a4fbebaMerge branch 'public/combinat/implement-ordered-multiset-partitions-25148' of trac.sagemath.org:sage into public/combinat/implement-ordered-multiset-partitions-25148
df225caremoved user shorthand for building an omp with the `OrderedMultisetPartition` class
alauve commented 6 years ago
comment:91

I removed the functionality

sage: OrderedMultisetPartition([1,2,0,1,2,3])
[{1,2}, {1,2,3}]

because it conflicts with the __getitem__ method when using OrderedMultisetPartitions as index set for combinatorial free modules.

It still exists as a method for the parent class. That is,

sage: OrderedMultisetPartitions().from_list([1,2,0,1,2,3])
[{1,2}, {1,2,3}]

still works.

anneschilling commented 6 years ago
comment:92

Hi Aaron,

Overall, the code looks pretty good. Here are some suggestions from the user point of view:

sage: p=OrderedMultisetPartition([[5, 3], [1, 3, 3]])
...
/Applications/sage/local/lib/python2.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2468)()
    387         dummy_error_message.cls = type(self)
    388         dummy_error_message.name = name
--> 389         raise AttributeError(dummy_error_message)
    390     cdef PyObject* attr = instance_getattr(cls, name)
    391     if attr is NULL:

AttributeError: 'OrderedMultisetPartitions_X_with_category.element_class' object has no attribute '_n'
sage: P=OrderedMultisetPartitions([0,0,1])
sage: P.from_list([1,0,0,0,0])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-128db23691d7> in <module>()
----> 1 P.from_list([Integer(1),Integer(0),Integer(0),Integer(0),Integer(0)])

/Applications/sage/local/lib/python2.7/site-packages/sage/combinat/multiset_partition_ordered.pyc in from_list(self, lst)
   1685             raise ValueError("Something is wrong: `from_list` does not expect to see negative integers; received {}.".format(str(lst)))
   1686         if 0 in list(lst) or '0' in list(lst):
-> 1687             return self._from_zero_list(lst)
   1688         else:
   1689             d = [frozenset([x]) for x in lst]

/Applications/sage/local/lib/python2.7/site-packages/sage/combinat/multiset_partition_ordered.pyc in _from_zero_list(self, lst_with_zeros)
   1732                 return c
   1733         else:
-> 1734             raise ValueError("ordered multiset partitions do not have repeated entries within blocks (%s received)"%str(co))
   1735 
   1736     def an_element(self):

ValueError: ordered multiset partitions do not have repeated entries within blocks ([[1]] received)
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

ef54c51Merge branch 'develop' into public/combinat/implement-ordered-multiset-partitions-25148
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from df225ca to ef54c51

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from ef54c51 to f84666b

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

f84666bfixed two references
anneschilling commented 6 years ago
comment:95

One more thing that I noticed is that the picture of the crystal is now not displayed using the ordered multisets (which I think it should!), but rather the tableau model, see

sage: B = crystals.Minimaj(2,3,2)
sage: view(B)
sage: B.list()
[((2, 1), (1,)), ((2,), (1, 2)), ((1,), (1, 2)), ((1, 2), (2,))]
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from f84666b to 10c8fd2

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

10c8fd2pyflakes mostly
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 10c8fd2 to 04ae9da

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

04ae9dacorrect a doctest
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

0f2e3bfoops
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 04ae9da to 0f2e3bf

alauve commented 6 years ago
comment:99

Replying to @anneschilling:

One more thing that I noticed is that the picture of the crystal is now not displayed using the ordered multisets (which I think it should!), but rather the tableau model, see

sage: B = crystals.Minimaj(2,3,2)
sage: view(B)
sage: B.list()
[((2, 1), (1,)), ((2,), (1, 2)), ((1,), (1, 2)), ((1, 2), (2,))]

This might take awhile to track down (though I agree with the sentiment), if anybody knows how, precisely, latex decides what to print for an element of a crystal, please chime in.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

ee5ece8removed from_list and changed deconcatenate and split examples
79aafdffixing doctests
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 0f2e3bf to 79aafdf

alauve commented 6 years ago
comment:101

I tracked down the latex problem. Try again:

age: B = crystals.Minimaj(2,3,2)
sage: view(B)
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 79aafdf to f87711a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

f87711aadded a `_latex_` method for elements of minimaj crystal
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

5a345efcorrect that doctest again
92bdad9Merge branch 'public/combinat/implement-ordered-multiset-partitions-25148' of git://trac.sagemath.org/sage into minimaj
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from f87711a to 92bdad9

anneschilling commented 6 years ago

Changed keywords from IMA coding sprint, CHAs to IMA coding sprint, CHAs, sage@icerm

anneschilling commented 6 years ago
comment:106

Now I get a doctest failure

sage -t multiset_partition_ordered.py
**********************************************************************
File "multiset_partition_ordered.py", line 2229, in sage.combinat.multiset_partition_ordered.OrderedMultisetPartitions_X.__iter__
Failed example:
    sorted([next(it) for _ in range(O.cardinality())], key=str)
Expected:
    [[{'a'}, {1}, {1}],
     [{1,'a'}, {1}],
     [{1}, {'a'}, {1}],
     [{1}, {1,'a'}],
     [{1}, {1}, {'a'}]]
Got:
    [[{1,'a'}, {1}],
     [{1}, {'a'}, {1}],
     [{1}, {1,'a'}],
     [{1}, {1}, {'a'}],
     [{1}, {1}, {'a'}]]
**********************************************************************
1 item had failures:
   1 of   7 in sage.combinat.multiset_partition_ordered.OrderedMultisetPartitions_X.__iter__
    [556 tests, 1 failure, 24.87 s]
----------------------------------------------------------------------
sage -t multiset_partition_ordered.py  # 1 doctest failed
----------------------------------------------------------------------
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

9854729fixed doc tests
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 92bdad9 to 9854729

anneschilling commented 6 years ago

Changed keywords from IMA coding sprint, CHAs, sage@icerm to IMA coding sprint, CHAs, sagedays@icerm

darijgr commented 6 years ago
comment:109

That doctest is still fucked up; there is a duplicate in the resulting list(O).

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from 9854729 to bdcc91b

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

8e51e49trivial doc correction
bdcc91bfix OrderedMultisetPartitions_X iterator
darijgr commented 6 years ago
comment:111

Replaced the iterator algorithm by one I was able to prove. That should fix the doctest. Note that I've changed lots of doctests since the new algorithm yields the partitions in a different order; I hope that the old order wasn't being tacitly relied upon!

alauve commented 6 years ago
comment:113

I figured out what was causing the repeats in iteration, and don't like the recursive algorithm Darij decided on. I'm reverting back to old iteration method (suitably modified). Please have another look.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from bdcc91b to 4ce9ff9

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4ce9ff9modified _iterator_weight to work with standardized multiset partitions