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

Commit

Permalink
ticket 16465: fix some design of combinatorial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
elixyre committed Apr 23, 2015
1 parent 68a3da6 commit 7de9abc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 279 deletions.
270 changes: 38 additions & 232 deletions src/sage/categories/combinatorial_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,246 +22,49 @@

class CombinatorialStructures(Category):
"""
The category of classes of combinatorial structures
"In mathematics, a combinatorial class is a countable set of mathematical
objects." (Wikipedia)
A class of combinatorial structures is a graded set `C = \bigsqcup_{n \geqslant 0} C_n` such that each graded
component `C_n` is a finite set.
EXAMPLES::
sage: Partitions().category()
Category of combinatorial structures
The generating series of `C` is a *formal power series*
MATH::
C(t) = \sum_{n \geqslant 0} c_n t^n\,,
where `c_n` is the cardinality of the graded component `C_n`.
.. TODO waiting for TICKET species (u/elixyre/species)
"""

def super_categories(self):
return [SetsWithGrading(), InfiniteEnumeratedSets()]

class ParentMethods:

# def cycle(F, **options):
# """
# TESTS::
#
# sage: B = BinaryTrees()
# sage: BC = B.cycle(); BC
# Cycle of `Binary trees`
# sage: ascii_art(BC.graded_component(3,2).list())
# [ ( ) ( ) ( ) (
# [ ( , o ) ( , o ) ( , o ) ( ,
# [ ( ) ( ) ( \ ) ( \ ) ( ) ( / ) (
# [ ( o, o ) ( o, o ) ( o ) ( o ) ( , o ) ( o ) (
# [ ( \ ) ( / ) ( \ ) ( / ) ( / \ ) ( \ ) (
# [ ( o ), ( o ), ( o ), ( o ), ( o o ), ( o ), (
# <BLANKLINE>
# ) ]
# o ) ]
# / ) ]
# o ) ]
# / ) ]
# o ) ]
#
# sage: BC2 = B.restricted_structures(min=1).cycle(grading_set="sum"); BC2
# Cycle of `Binary trees with grading min=`1``
# sage: ascii_art(BC2.graded_component(3).list())
# [ ( o ) ( o ) ( o ) ( o )
# [ ( \ ) ( \ ) ( / ) ( / ) ( ) ( )
# [ ( o ) ( o ) ( o ) ( o ) ( o ) ( o, o ) ( o, o )
# [ ( \ ) ( / ) ( / \ ) ( \ ) ( / ) ( \ ) ( / ) (
# [ ( o ), ( o ), ( o o ), ( o ), ( o ), ( o ), ( o ), (
# <BLANKLINE>
# ]
# ]
# ]
# ) ]
# o, o, o ) ]
# """
# from sage.combinat.structures.operations.cycle import Cycle
# return Cycle(F, **options)
#
# def multiset(F, **options):
# """
# TESTS::
#
# sage: C = Compositions()
# sage: MC = C.multiset(); MC
# Multi-set of `Compositions of non-negative integers`
# sage: MC32 = MC.graded_component(3,2); MC32
# Multi-set of `Compositions of non-negative integers` of degree
# (3, 2)
# sage: MC32.list()
# [{[1], [1, 1]}, {[1], [2]}, {[], [1, 1, 1]}, {[], [1, 2]}, {[],
# [2, 1]}, {[], [3]}]
# """
# from sage.combinat.structures.operations.multi_sets import MultiSet
# return MultiSet(F, **options)
#
# def sequence(F, **options):
# """
# TESTS::
#
# sage: B = BinaryTrees()
# sage: BS = B.sequence(); BS
# Sequence of `Binary trees`
# sage: ascii_art(BS.graded_component(3,2).list())
# [
# [ [ o ] [ o ] [ o ] [ o ]
# [ [ \ ] [ \ ] [ / ] [ / ]
# [ [ o ] [ o ] [ o ] [ o ] [ o ] [ o o ] [
# [ [ \ ] [ / ] [ / \ ] [ \ ] [ / ] [ \ ] [
# [ [ o, ], [ o , ], [ o o, ], [ o, ], [ o , ], [ o, ], [
# <BLANKLINE>
# [ ] [ ] [
# [ , o ] [ , o ] [ , o
# [ ] [ ] [ \ ] [ \ ] [ ] [ /
# o o ] [ o, o ] [ o, o ] [ o ] [ o ] [ , o ] [ o
# / ] [ \ ] [ / ] [ \ ] [ / ] [ / \ ] [ \
# o , ], [ o ], [ o ], [ o ], [ o ], [ o o ], [ o
# <BLANKLINE>
# ] [ ] ]
# ] [ , o ] ]
# ] [ / ] ]
# ] [ o ] ]
# ] [ / ] ]
# ], [ o ] ]
# sage: BS2 = B.restricted_structures(min=1).sequence(grading_set="sum"); BS2
# Sequence of `Binary trees with grading min=`1``
# sage: ascii_art(BS2.graded_component(3).list())
# [ [ o ] [ o ] [ o ] [ o ]
# [ [ \ ] [ \ ] [ / ] [ / ] [
# [ [ o ] [ o ] [ o ] [ o ] [ o ] [ o o ] [ o o ] [
# [ [ \ ] [ / ] [ / \ ] [ \ ] [ / ] [ \ ] [ / ] [
# [ [ o ], [ o ], [ o o ], [ o ], [ o ], [ o, ], [ o , ], [
# <BLANKLINE>
# ]
# ] [ ] ]
# o, o ] [ o, o ] ]
# \ ] [ / ] [ ] ]
# o ], [ o ], [ o, o, o ] ]
#
# """
# from sage.combinat.structures.operations.sequences import Sequence
# return Sequence(F, **options)
#
# def product(F, G):
# """
# Return the Cauchy product of two structure.
#
# INPUT:
#
# -``F``, ``G`` -- two combinatorial structures.
#
# OUTPUT:
#
# The Cauchy product of ``F`` and ``G``.
#
# TESTS::
#
# sage: B = BinaryTrees()
# sage: C = Compositions()
# sage: CB = C*B; CB
# Product of structures : `Compositions of non-negative integers`,
# `Binary trees`
# sage: ascii_art(CB.graded_component(2).list())
# [ [ ] [ ] ]
# [ [ , o ] [ , o ] ]
# [ [ * ] [ ] [ ] [ \ ] [ / ] ]
# [ [ *, ], [ **, ], [ *, o ], [ o ], [ o ] ]
# """
# from sage.combinat.structures.operations.product import CauchyProduct
# return CauchyProduct(F, G)
# _mul_ = product
#
# def cartesian_product(F, G):
# """
# Return the cartesian products of two structures.
#
# INPUT:
#
# -``F``, ``G`` -- two combinatorial structures.
#
# OUTPUT:
#
# The cartesian product of ``F`` and ``G``.
#
# TESTS::
#
# sage: B = BinaryTrees()
# sage: C = Compositions()
# sage: BcC = B.cartesian_product(C); BcC
# Cartesian product of structures : 'Binary trees, Compositions of
# non-negative integers'
# sage: ascii_art(BcC.graded_component(2).list())
# [ [ * ] [ * ] ]
# [ [ o * ] [ o ** ] [ o * ] [ o ** ] ]
# [ [ \ ] [ \ ] [ / ] [ / ] ]
# [ [ o, ], [ o, ], [ o , ], [ o , ] ]
# """
# from sage.combinat.structures.operations.cartesian_product import CartesianProduct
# return CartesianProduct(F, G)
#
# def sum(F, G):
# """
# Return the sum of two structures.
#
# INPUT:
#
# -``F``, ``G`` -- two combinatorial structures.
#
# OUTPUT:
#
# The sum of ``F`` and ``G``.
#
# TESTS::
#
# sage: B = BinaryTrees()
# sage: C = Compositions()
# sage: BpC = B + C; BpC
# Sum of structures : `Binary trees`, `Compositions of
# non-negative integers`
# sage: ascii_art(BpC.graded_component(3).list())
# [ * ]
# [ * ** * ]
# [ o o o o o * * ** *** ]
# [ \ \ / \ / / ]
# [ o o o o o o ]
# [ \ / \ / ]
# [ o, o , , o, o , , , , ]
# """
# from sage.combinat.structures.operations.sum import Sum
# return Sum(F, G)
#
# __add__ = sum
#
# def restricted_structures(self, min=None, max=None):
# """
# Return the restriction of the combinatorial structure to the
# homogeneous component between ``min`` and ``max``.
#
# Return the sum of two structures.
#
# INPUT:
#
# -``min`` -- integer (default: None) lower bound of the interval.
# -``max`` -- integer (default: None) upper bound of the interval.
#
# OUTPUT:
#
# The restricted structure of ``self`` on the interval bounded by
# ``min`` and ``max``.
#
# TESTS::
#
# sage: B = BinaryTrees()
# sage: RB = B.restricted_structures(min=3, max=4); RB
# Binary trees with grading min=`3`, max=`4`
# sage: RB.graded_component(2).list()
# []
# sage: RB.graded_component(35).list()
# []
# sage: RB.graded_component(3).list()
# [[., [., [., .]]],
# [., [[., .], .]],
# [[., .], [., .]],
# [[., [., .]], .],
# [[[., .], .], .]]
# sage: _[2].parent()
# Binary trees with grading min=`3`, max=`4`
# """
# from sage.combinat.structures.operations import RestrictedStructures
# return RestrictedStructures(self, min=min, max=max)
@abstract_method(optional=True)
def generating_series(self):
"""
The generating series of the class of combinatorial structure.
MATH::
C(t) = \sum_{n \geqslant 0} c_n t^n\,.
"""
# TODO waiting for TICKET species (u/elixyre/species)

def gs(self): return self.generating_series()

def __iter__(self):
"""
Expand All @@ -283,8 +86,9 @@ def _repr_(self):
TESTS::
sage: from sage.categories.examples.combinatorial_structures_compositions import Compositions
sage: Compositions(4)
sage: Compositions().graded_component(4)
Compositions of integers of degree 4
"""
return repr(self.ambient()) + " of degree " + repr(self.grading())

Expand All @@ -297,6 +101,7 @@ def ambient(self):
sage: BinaryTrees(4).ambient()
Binary trees
"""

@abstract_method(optional=False)
Expand All @@ -308,4 +113,5 @@ def grading(self):
sage: BinaryTrees(4).grading()
4
"""
20 changes: 0 additions & 20 deletions src/sage/categories/examples/sets_with_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,4 @@ def grading(self, elt):
"""
return elt

def generating_series(self, var='z'):
r"""
Returns `1 / (1-z)`.
EXAMPLES::
sage: N = SetsWithGrading().example(); N
Non negative integers
sage: f = N.generating_series(); f
1/(-z + 1)
sage: LaurentSeriesRing(ZZ,'z')(f)
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + z^7 + z^8 + z^9 + z^10 + z^11 + z^12 + z^13 + z^14 + z^15 + z^16 + z^17 + z^18 + z^19 + O(z^20)
"""
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.integer import Integer
R = PolynomialRing(IntegerRing(), var)
z = R.gen()
return Integer(1) / (Integer(1)-z)

Example = NonNegativeIntegers
25 changes: 0 additions & 25 deletions src/sage/categories/sets_with_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,6 @@ def grading(self, elt):
4
"""

#@cached_method
@abstract_method(optional=True)
def generating_series(self):
"""
Default implementation for generating series.
OUTPUT:
A series, indexed by the grading set.
EXAMPLES::
sage: N = SetsWithGrading().example(); N
Non negative integers
sage: N.generating_series()
1/(-z + 1)
"""
#from sage.combinat.species.stream import _integers_from
#from sage.combinat.species.series import LazyPowerSeriesRing
#from sage.rings.integer_ring import ZZ
#R = LazyPowerSeriesRing(ZZ)
#return R(self.graded_component(grade).cardinality() for grade in _integers_from(0))

gs = generating_series

# TODO:
# * asymptotic behavior: we need an object for asymptotic behavior and
# a default name for the method that should be here. Such method will
Expand Down
Loading

0 comments on commit 7de9abc

Please sign in to comment.