Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add class CombinatorialElement
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed May 8, 2015
1 parent 6a3cb27 commit 8f60acb
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 220 deletions.
117 changes: 105 additions & 12 deletions src/sage/combinat/combinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,14 @@
# 2007 Mike Hansen <mhansen@gmail.com>,
# 2006 William Stein <wstein@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# The full text of the GPL is available at:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************


from sage.interfaces.all import maxima
from sage.rings.all import ZZ, QQ, Integer, infinity
from sage.rings.arith import bernoulli, binomial
Expand All @@ -158,7 +155,10 @@
from sage.structure.parent import Parent
from sage.misc.lazy_attribute import lazy_attribute
from combinat_cython import _stirling_number2
######### combinatorial sequences
from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.categories.enumerated_sets import EnumeratedSets
from sage.structure.element import Element


def bell_number(n, algorithm='flint', **options):
r"""
Expand Down Expand Up @@ -817,6 +817,7 @@ def stirling_number2(n, k, algorithm=None):
else:
raise ValueError("unknown algorithm: %s" % algorithm)


class CombinatorialObject(SageObject):
def __init__(self, l, copy=True):
"""
Expand All @@ -830,6 +831,11 @@ def __init__(self, l, copy=True):
list and the hash of its parent's class. Thus, each
CombinatorialObject should have a unique string representation.
.. SEEALSO::
:class:`CombinatorialElement` if you want a combinatorial
object which is an element of a parent.
.. WARNING::
This class is slowly being deprecated. Use
Expand Down Expand Up @@ -1199,8 +1205,95 @@ def index(self, key):
return self._list.index(key)


from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.categories.enumerated_sets import EnumeratedSets
class CombinatorialElement(CombinatorialObject, Element):
"""
``CombinatorialElement`` is both a :class:`CombinatorialObject`
and an :class:`Element`. So it represents a list which is an
element of some parent.
A ``CombinatorialElement`` subclass also automatically supports
the ``__classcall__`` mechanism.
.. WARNING::
This class is slowly being deprecated. Use
:class:`~sage.structure.list_clone.ClonableList` instead.
INPUT:
- ``parent`` -- the :class:`Parent` class for this element.
- ``lst`` -- a list or any object that can be converted to a
list by calling ``list()``.
EXAMPLES::
sage: from sage.combinat.combinat import CombinatorialElement
sage: e = CombinatorialElement(Partitions(6), [3,2,1])
sage: e == loads(dumps(e))
True
sage: parent(e)
Partitions of the integer 6
sage: list(e)
[3, 2, 1]
Check classcalls::
sage: class Foo(CombinatorialElement):
....: @staticmethod
....: def __classcall__(cls, x):
....: return x
sage: Foo(17)
17
"""
__metaclass__ = ClasscallMetaclass

def __init__(self, parent, *args, **kwds):
"""
Initialize this ``CombinatorialElement`` with a parent and a
list.
EXAMPLES::
sage: from sage.combinat.combinat import CombinatorialElement
sage: e = CombinatorialElement(ZZ, list=(3,2,1))
sage: e._list
[3, 2, 1]
sage: e.parent()
Integer Ring
TESTS::
sage: CombinatorialElement(ZZ)
Traceback (most recent call last):
...
TypeError: __init__() takes exactly 2 arguments (1 given)
sage: CombinatorialElement(ZZ, 1, 2)
Traceback (most recent call last):
...
TypeError: __init__() takes exactly 2 arguments (3 given)
sage: CombinatorialElement(ZZ, 1, list=2)
Traceback (most recent call last):
...
TypeError: __init__() takes exactly 2 arguments (3 given)
sage: CombinatorialElement(ZZ, a=1, b=2)
Traceback (most recent call last):
...
TypeError: __init__() takes exactly 2 arguments (3 given)
"""
# There should be one "list" argument, which can be given as
# positional or keyword argument (in the latter case, the name
# doesn't matter).
if len(args) == 1 and not kwds:
L = args[0]
elif len(kwds) == 1 and not args:
L = kwds.values()[0]
else:
raise TypeError("__init__() takes exactly 2 arguments ({} given)".format(1+len(args)+len(kwds)))
super(CombinatorialElement, self).__init__(L)
super(CombinatorialObject, self).__init__(parent)


class CombinatorialClass(Parent):
"""
This class is deprecated, and will disappear as soon as all derived
Expand Down
25 changes: 7 additions & 18 deletions src/sage/combinat/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.structure.element import Element
from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.rings.all import ZZ
from combinat import CombinatorialObject
from combinat import CombinatorialElement
from cartesian_product import CartesianProduct
from integer_list import IntegerListsLex
import __builtin__
from sage.rings.integer import Integer
from sage.combinat.combinatorial_map import combinatorial_map


class Composition(CombinatorialObject, Element):
class Composition(CombinatorialElement):
r"""
Integer compositions
Expand Down Expand Up @@ -106,9 +104,12 @@ class Composition(CombinatorialObject, Element):
[1, 1, 2, 1]
sage: Composition(descents=({0,1,3},5))
[1, 1, 2, 1]
"""
__metaclass__ = ClasscallMetaclass
EXAMPLES::
sage: C = Composition([3,1,2])
sage: TestSuite(C).run()
"""
@staticmethod
def __classcall_private__(cls, co=None, descents=None, code=None, from_subset=None):
"""
Expand Down Expand Up @@ -143,18 +144,6 @@ def __classcall_private__(cls, co=None, descents=None, code=None, from_subset=No
else:
return Compositions()(list(co))

def __init__(self, parent, lst):
"""
Initialize ``self``.
EXAMPLES::
sage: C = Composition([3,1,2])
sage: TestSuite(C).run()
"""
CombinatorialObject.__init__(self, lst)
Element.__init__(self, parent)

def _ascii_art_(self):
"""
TESTS::
Expand Down
11 changes: 4 additions & 7 deletions src/sage/combinat/composition_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.functions.other import factorial
from sage.misc.cachefunc import cached_function
from sage.structure.element import Element
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.combinat.composition import Composition, Compositions
from sage.combinat.partition import Partition
from sage.combinat.combinat import CombinatorialObject
from sage.combinat.combinat import CombinatorialElement
from sage.rings.integer import Integer
from sage.combinat.backtrack import GenericBacktracker
import copy

class CompositionTableau(CombinatorialObject, Element):
class CompositionTableau(CombinatorialElement):
r"""
A composition tableau.
Expand Down Expand Up @@ -92,8 +91,7 @@ def __init__(self, parent, t):
Composition Tableaux
"""
if isinstance(t, CompositionTableau):
Element.__init__(self, parent)
CombinatorialObject.__init__(self, t._list)
CombinatorialElement.__init__(self, parent, t._list)
return

# CombinatorialObject verifies that t is a list
Expand Down Expand Up @@ -124,8 +122,7 @@ def __init__(self, parent, t):
if TT[j][k] != 0 and TT[j][k] >= TT[i][k] and TT[j][k] <= TT[i][k-1]:
raise ValueError("Triple condition must be satisfied.")

Element.__init__(self, parent)
CombinatorialObject.__init__(self, t)
CombinatorialElement.__init__(self, parent, t)

def _repr_diagram(self):
r"""
Expand Down
12 changes: 3 additions & 9 deletions src/sage/combinat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
# http://www.gnu.org/licenses/
#****************************************************************************

from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.structure.element import Element
from sage.combinat.partition import Partitions, Partition
from sage.combinat.combinat import CombinatorialObject
from sage.combinat.combinat import CombinatorialElement
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.functions.other import floor
from sage.combinat.combinatorial_map import combinatorial_map

class Core(CombinatorialObject, Element):
class Core(CombinatorialElement):
r"""
A `k`-core is an integer partition from which no rim hook of size `k`
can be removed.
Expand All @@ -51,9 +49,6 @@ class Core(CombinatorialObject, Element):
...
ValueError: [3, 1] is not a 4-core
"""

__metaclass__ = ClasscallMetaclass

@staticmethod
def __classcall_private__(cls, part, k):
r"""
Expand Down Expand Up @@ -105,8 +100,7 @@ def __init__(self, parent, core):
part = Partition(core)
if not part.is_core(k):
raise ValueError("%s is not a %s-core"%(part, k))
CombinatorialObject.__init__(self, core)
Element.__init__(self, parent)
CombinatorialElement.__init__(self, parent, core)

def __eq__(self, other):
"""
Expand Down
8 changes: 3 additions & 5 deletions src/sage/combinat/crystals/generalized_young_walls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@
import re
from copy import deepcopy
from sage.combinat.root_system.cartan_type import CartanType
from sage.structure.element import Element
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.combinat.combinat import CombinatorialObject
from sage.combinat.combinat import CombinatorialElement
from sage.categories.regular_crystals import RegularCrystals
from sage.categories.highest_weight_crystals import HighestWeightCrystals
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.combinat.root_system.root_system import RootSystem
from sage.rings.infinity import Infinity

class GeneralizedYoungWall(CombinatorialObject, Element):
class GeneralizedYoungWall(CombinatorialElement):
r"""
A generalized Young wall.
Expand Down Expand Up @@ -85,8 +84,7 @@ def __init__(self,parent,data):
else:
self.cols = max([len(r) for r in data])
self.data = data
CombinatorialObject.__init__(self, data)
Element.__init__(self, parent)
CombinatorialElement.__init__(self, parent, data)

def _repr_(self):
r"""
Expand Down
23 changes: 6 additions & 17 deletions src/sage/combinat/crystals/tensor_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
from sage.misc.latex import latex
from sage.misc.cachefunc import cached_method, cached_in_parent_method
from sage.structure.parent import Parent
from sage.structure.element import Element, parent
from sage.structure.element import parent
from sage.structure.global_options import GlobalOptions
from sage.categories.category import Category
from sage.categories.classical_crystals import ClassicalCrystals
from sage.categories.regular_crystals import RegularCrystals
from sage.categories.sets_cat import Sets
from sage.combinat.root_system.cartan_type import CartanType
from sage.combinat.cartesian_product import CartesianProduct
from sage.combinat.combinat import CombinatorialObject
from sage.combinat.combinat import CombinatorialElement
from sage.combinat.partition import Partition
from sage.combinat.tableau import Tableau
from letters import CrystalOfLetters
Expand Down Expand Up @@ -89,7 +89,7 @@ def _repr_(self):
"""
return "A parent for tests"

class ImmutableListWithParent(CombinatorialObject, Element):
class ImmutableListWithParent(CombinatorialElement):
r"""
A class for lists having a parent
Expand All @@ -112,22 +112,11 @@ class ImmutableListWithParent(CombinatorialObject, Element):
[3, 2, 1]
sage: l.set_index(1,4)
[1, 4, 3]
"""
def __init__(self, parent, list):
"""
EXAMPLES::
sage: from sage.combinat.crystals.tensor_product import ImmutableListWithParent, TestParent
sage: l = ImmutableListWithParent(TestParent(), [1,2,3])
sage: l.parent()
A parent for tests
sage: parent(l)
A parent for tests
sage: TestSuite(l).run(skip = "_test_category")
"""
Element.__init__(self, parent)
CombinatorialObject.__init__(self, list)
TESTS::
sage: TestSuite(l).run(skip = "_test_category")
"""
def _repr_(self):
"""
EXAMPLES::
Expand Down

0 comments on commit 8f60acb

Please sign in to comment.