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

Commit

Permalink
rebase Mike Hansen's code
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Jan 11, 2016
1 parent 8f93e71 commit aa8fd83
Show file tree
Hide file tree
Showing 18 changed files with 4,447 additions and 2,379 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
65 changes: 0 additions & 65 deletions src/sage/combinat/species/combinatorial_logarithm.py

This file was deleted.

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 @@ -180,30 +179,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 @@ -216,70 +191,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
Loading

0 comments on commit aa8fd83

Please sign in to comment.