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

Commit

Permalink
Merge branch 'u/mhansen/species_stream' of trac.sagemath.org:sage int…
Browse files Browse the repository at this point in the history
…o 15673

Conflicts:
	src/sage/combinat/species/series.py
  • Loading branch information
Frédéric Chapoton committed Apr 8, 2014
2 parents 12bbca0 + 927ff83 commit 8ff4acc
Show file tree
Hide file tree
Showing 19 changed files with 3,678 additions and 1,501 deletions.
91 changes: 47 additions & 44 deletions src/sage/combinat/species/characteristic_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
#
# http://www.gnu.org/licenses/
#*****************************************************************************
from species import GenericCombinatorialSpecies
from species import GenericCombinatorialSpecies, SpeciesTermStream
from generating_series import factorial_stream
from structure import GenericSpeciesStructure
from set_species import SetSpecies
from sage.misc.cachefunc import cached_function
from sage.structure.unique_representation import UniqueRepresentation

class CharacteristicSpeciesStructure(GenericSpeciesStructure):
Expand Down Expand Up @@ -157,18 +156,6 @@ def _structures(self, structure_class, labels):

_isotypes = _structures

def _gs_term(self, base_ring):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: F.generating_series().coefficients(5)
[0, 0, 1/2, 0, 0]
sage: F.generating_series().count(2)
1
"""
return base_ring(self._weight)/base_ring(factorial_stream[self._n])

def _order(self):
"""
Returns the order of the generating series.
Expand All @@ -181,36 +168,52 @@ def _order(self):
"""
return self._n

def _itgs_term(self, base_ring):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: F.isotype_generating_series().coefficients(5)
[0, 0, 1, 0, 0]
Here we test out weighting each structure by q.
::
sage: R.<q> = ZZ[]
sage: Fq = species.CharacteristicSpecies(2, weight=q)
sage: Fq.isotype_generating_series().coefficients(5)
[0, 0, q, 0, 0]
"""
return base_ring(self._weight)

def _cis_term(self, base_ring):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: g = F.cycle_index_series()
sage: g.coefficients(5)
[0, 0, 1/2*p[1, 1] + 1/2*p[2], 0, 0]
"""
cis = SetSpecies(weight=self._weight).cycle_index_series(base_ring)
return cis.coefficient(self._n)
class GeneratingSeriesStream(SpeciesTermStream):
def value(self, base_ring, weight):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: F.generating_series().coefficients(5)
[0, 0, 1/2, 0, 0]
sage: F.generating_series().count(2)
1
"""

return base_ring(weight)/factorial_stream[self._n]

class IsotypeGeneratingSeriesStream(SpeciesTermStream):
def value(self, base_ring, weight):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: F.isotype_generating_series().coefficients(5)
[0, 0, 1, 0, 0]
Here we test out weighting each structure by q.
::
sage: R.<q> = ZZ[]
sage: Fq = species.CharacteristicSpecies(2, weight=q)
sage: Fq.isotype_generating_series().coefficients(5)
[0, 0, q, 0, 0]
"""
return base_ring(weight)

class CycleIndexSeriesStream(SpeciesTermStream):
def value(self, base_ring, weight):
"""
EXAMPLES::
sage: F = species.CharacteristicSpecies(2)
sage: g = F.cycle_index_series()
sage: g.coefficients(5)
[0, 0, 1/2*p[1, 1] + 1/2*p[2], 0, 0]
"""
cis = SetSpecies(weight=weight).cycle_index_series(base_ring.base_ring())
return cis.coefficient(self._n)

def _equation(self, var_mapping):
"""
Expand Down
5 changes: 2 additions & 3 deletions src/sage/combinat/species/combinatorial_logarithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
#*****************************************************************************

from sage.misc.cachefunc import cached_function
from sage.combinat.species.stream import _integers_from
from sage.combinat.sf.all import SymmetricFunctions
from sage.combinat.species.generating_series import CycleIndexSeriesRing
from sage.rings.all import RationalField, Integer, divisors
from sage.rings.all import RationalField, Integer, divisors, NN

@cached_function
def _cl_term(n, R = RationalField()):
Expand Down Expand Up @@ -75,7 +74,7 @@ def _cl_gen (R = RationalField()):
sage: [g.next() for i in range(4)]
[0, p[1], -1/2*p[1, 1] - 1/2*p[2], 1/3*p[1, 1, 1] - 1/3*p[3]]
"""
return (_cl_term(i, R) for i in _integers_from(0))
return (_cl_term(i, R) for i in NN)

@cached_function
def CombinatorialLogarithmSeries(R = RationalField()):
Expand Down
1 change: 0 additions & 1 deletion src/sage/combinat/species/composition_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from species import GenericCombinatorialSpecies
from structure import GenericSpeciesStructure
from partition_species import PartitionSpecies
from sage.misc.cachefunc import cached_function
from sage.structure.unique_representation import UniqueRepresentation

class CompositionSpeciesStructure(GenericSpeciesStructure):
Expand Down
147 changes: 72 additions & 75 deletions src/sage/combinat/species/cycle_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
#
# http://www.gnu.org/licenses/
#*****************************************************************************
from species import GenericCombinatorialSpecies
from species import GenericCombinatorialSpecies, SpeciesSeriesStream
from series import SeriesStreamFromList
from structure import GenericSpeciesStructure
from generating_series import _integers_from
from sage.structure.unique_representation import UniqueRepresentation
from sage.rings.all import ZZ, divisors, euler_phi
from sage.misc.cachefunc import cached_function
from sage.combinat.species.misc import accept_size

class CycleSpeciesStructure(GenericSpeciesStructure):
Expand Down Expand Up @@ -58,7 +57,7 @@ def permutation_group_element(self):
sage: a.permutation_group_element()
(1,2,3)
"""
from sage.groups.all import PermutationGroupElement, SymmetricGroup
from sage.groups.all import PermutationGroupElement
return PermutationGroupElement(tuple(self._list))

def transport(self, perm):
Expand Down Expand Up @@ -178,30 +177,6 @@ def _isotypes(self, structure_class, labels):
if len(labels) != 0:
yield structure_class(self, labels, range(1, len(labels)+1))

def _gs_iterator(self, base_ring):
r"""
The generating series for cyclic permutations is
`-\log(1-x) = \sum_{n=1}^\infty x^n/n`.
EXAMPLES::
sage: P = species.CycleSpecies()
sage: g = P.generating_series()
sage: g.coefficients(10)
[0, 1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9]
TESTS::
sage: P = species.CycleSpecies()
sage: g = P.generating_series(RR)
sage: g.coefficients(3)
[0.000000000000000, 1.00000000000000, 0.500000000000000]
"""
one = base_ring(1)
yield base_ring(0)
for n in _integers_from(ZZ(1)):
yield self._weight*one/n

def _order(self):
"""
Returns the order of the generating series.
Expand All @@ -214,70 +189,92 @@ def _order(self):
"""
return 1

def _itgs_list(self, base_ring):
"""
The isomorphism type generating series for cyclic permutations is
given by `x/(1-x)`.
class GeneratingSeriesStream(SpeciesSeriesStream):
def compute(self, n):
r"""
The generating series for cyclic permutations is
`-\log(1-x) = \sum_{n=1}^\infty x^n/n`.
EXAMPLES::
EXAMPLES::
sage: P = species.CycleSpecies()
sage: g = P.isotype_generating_series()
sage: g.coefficients(5)
[0, 1, 1, 1, 1]
sage: P = species.CycleSpecies()
sage: g = P.generating_series()
sage: g.coefficients(10)
[0, 1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9]
TESTS::
TESTS::
sage: P = species.CycleSpecies()
sage: g = P.isotype_generating_series(RR)
sage: g.coefficients(3)
[0.000000000000000, 1.00000000000000, 1.00000000000000]
"""
return [base_ring(0), self._weight*base_ring(1)]
sage: P = species.CycleSpecies()
sage: g = P.generating_series(RR)
sage: g.coefficients(3)
[0.000000000000000, 1.00000000000000, 0.500000000000000]
"""
if n == 0:
return self._zero
else:
return self._base_ring(self._weight) / n

def _cis_iterator(self, base_ring):
r"""
The cycle index series of the species of cyclic permutations is
given by
class IsotypeGeneratingSeriesStream(SeriesStreamFromList, SpeciesSeriesStream):
def list(self):
"""
The isomorphism type generating series for cyclic permutations is
given by `x/(1-x)`.
.. math::
EXAMPLES::
-\sum_{k=1}^\infty \phi(k)/k * log(1 - x_k)
sage: P = species.CycleSpecies()
sage: g = P.isotype_generating_series()
sage: g.coefficients(5)
[0, 1, 1, 1, 1]
TESTS::
which is equal to
sage: P = species.CycleSpecies()
sage: g = P.isotype_generating_series(RR)
sage: g.coefficients(3)
[0.000000000000000, 1.00000000000000, 1.00000000000000]
"""
return [self._zero, self._weight*self._base_ring(1)]

.. math::
class CycleIndexSeriesStream(SpeciesSeriesStream):
def compute(self, n):
r"""
The cycle index series of the species of cyclic permutations is
given by
\sum_{n=1}^\infty \frac{1}{n} * \sum_{k|n} \phi(k) * x_k^{n/k}
.. math::
.
-\sum_{k=1}^\infty \phi(k)/k * log(1 - x_k)
EXAMPLES::
sage: P = species.CycleSpecies()
sage: cis = P.cycle_index_series()
sage: cis.coefficients(7)
[0,
p[1],
1/2*p[1, 1] + 1/2*p[2],
1/3*p[1, 1, 1] + 2/3*p[3],
1/4*p[1, 1, 1, 1] + 1/4*p[2, 2] + 1/2*p[4],
1/5*p[1, 1, 1, 1, 1] + 4/5*p[5],
1/6*p[1, 1, 1, 1, 1, 1] + 1/6*p[2, 2, 2] + 1/3*p[3, 3] + 1/3*p[6]]
"""
from sage.combinat.sf.sf import SymmetricFunctions
p = SymmetricFunctions(base_ring).power()
which is equal to
.. math::
\sum_{n=1}^\infty \frac{1}{n} * \sum_{k|n} \phi(k) * x_k^{n/k}
.
EXAMPLES::
zero = base_ring(0)
sage: P = species.CycleSpecies()
sage: cis = P.cycle_index_series()
sage: cis.coefficients(7)
[0,
p[1],
1/2*p[1, 1] + 1/2*p[2],
1/3*p[1, 1, 1] + 2/3*p[3],
1/4*p[1, 1, 1, 1] + 1/4*p[2, 2] + 1/2*p[4],
1/5*p[1, 1, 1, 1, 1] + 4/5*p[5],
1/6*p[1, 1, 1, 1, 1, 1] + 1/6*p[2, 2, 2] + 1/3*p[3, 3] + 1/3*p[6]]
"""
if n == 0:
return self._zero

yield zero
for n in _integers_from(1):
res = zero
res = self._zero
for k in divisors(n):
res += euler_phi(k)*p([k])**(n//k)
res /= n
yield self._weight*res
res += euler_phi(k)*self._base_ring([k])**(n//k)
return self._weight * res / n

#Backward compatibility
CycleSpecies_class = CycleSpecies
1 change: 0 additions & 1 deletion src/sage/combinat/species/empty_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# http://www.gnu.org/licenses/
#*****************************************************************************
from species import GenericCombinatorialSpecies
from sage.misc.cachefunc import cached_function
from series_order import inf
from sage.structure.unique_representation import UniqueRepresentation

Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/species/functorial_composition_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#*****************************************************************************
from species import GenericCombinatorialSpecies
from structure import GenericSpeciesStructure
from sage.misc.cachefunc import cached_function
from sage.structure.unique_representation import UniqueRepresentation

class FunctorialCompositionStructure(GenericSpeciesStructure):
pass

class FunctorialCompositionSpecies(GenericCombinatorialSpecies):
class FunctorialCompositionSpecies(GenericCombinatorialSpecies, UniqueRepresentation):
def __init__(self, F, G, min=None, max=None, weight=None):
"""
Returns the functorial composition of two species.
Expand Down

0 comments on commit 8ff4acc

Please sign in to comment.