3636single internal node, three have two internal nodes, and one has
3737three internal nodes.
3838"""
39- from __future__ import absolute_import
40- #*****************************************************************************
39+ # ****************************************************************************
4140# Copyright (C) 2008 Mike Hansen <[email protected] >, 4241#
4342# Distributed under the terms of the GNU General Public License (GPL)
4948#
5049# The full text of the GPL is available at:
5150#
52- # http ://www.gnu.org/licenses/
53- #* ****************************************************************************
51+ # https ://www.gnu.org/licenses/
52+ # ****************************************************************************
5453from .generating_series import OrdinaryGeneratingSeriesRing , ExponentialGeneratingSeriesRing , CycleIndexSeriesRing
5554from sage .rings .all import QQ
5655from sage .structure .sage_object import SageObject
5958from sage .combinat .species .structure import StructuresWrapper , IsotypesWrapper
6059from functools import reduce
6160
61+
6262class GenericCombinatorialSpecies (SageObject ):
6363 def __init__ (self , min = None , max = None , weight = None ):
6464 """
@@ -78,7 +78,7 @@ def __init__(self, min=None, max=None, weight=None):
7878
7979 def __hash__ (self ):
8080 """
81- Returns a hash of the unique info tuple.
81+ Return a hash of the unique info tuple.
8282
8383 EXAMPLES::
8484
@@ -87,10 +87,9 @@ def __hash__(self):
8787 """
8888 return hash (self ._unique_info ())
8989
90-
9190 def _unique_info (self ):
9291 """
93- Returns a tuple which should uniquely identify the species.
92+ Return a tuple which should uniquely identify the species.
9493
9594 EXAMPLES::
9695
@@ -176,7 +175,7 @@ def __ne__(self, other):
176175 False
177176 """
178177 return not (self == other )
179-
178+
180179 def __getstate__ (self ):
181180 r"""
182181 This is used during the pickling process and returns a dictionary
@@ -204,7 +203,7 @@ def __getstate__(self):
204203 def __setstate__ (self , state ):
205204 """
206205 This is used during unpickling to recreate this object from the
207- data provided by the __getstate__ method.
206+ data provided by the `` __getstate__`` method.
208207
209208 TESTS::
210209
@@ -220,7 +219,7 @@ def __setstate__(self, state):
220219
221220 def weighted (self , weight ):
222221 """
223- Returns a version of this species with the specified weight.
222+ Return a version of this species with the specified weight.
224223
225224 EXAMPLES::
226225
@@ -236,7 +235,7 @@ def weighted(self, weight):
236235
237236 def __repr__ (self ):
238237 """
239- Returns a string representation of this species.
238+ Return a string representation of this species.
240239
241240 EXAMPLES::
242241
@@ -260,7 +259,7 @@ def __repr__(self):
260259 else :
261260 name = "Combinatorial species"
262261
263- options = []
262+ options = []
264263
265264 if self ._min is not None :
266265 options .append ('min=%s' % self ._min )
@@ -276,7 +275,7 @@ def __repr__(self):
276275
277276 def __add__ (self , g ):
278277 """
279- Returns the sum of self and g .
278+ Return the sum of `` self`` and ``g`` .
280279
281280 EXAMPLES::
282281
@@ -295,7 +294,7 @@ def __add__(self, g):
295294
296295 def __mul__ (self , g ):
297296 """
298- Returns the product of self and g .
297+ Return the product of `` self`` and ``g`` .
299298
300299 EXAMPLES::
301300
@@ -327,7 +326,7 @@ def __call__(self, g):
327326
328327 def functorial_composition (self , g ):
329328 """
330- Returns the functorial composition of self with g .
329+ Return the functorial composition of `` self`` with ``g`` .
331330
332331 EXAMPLES::
333332
@@ -344,10 +343,17 @@ def functorial_composition(self, g):
344343 raise TypeError ("g must be a combinatorial species" )
345344 return FunctorialCompositionSpecies (self , g )
346345
347-
348346 @accept_size
349347 def restricted (self , min = None , max = None ):
350348 """
349+ Return the restriction of the species.
350+
351+ INPUT:
352+
353+ - ``min`` -- optional integer
354+
355+ - ``max`` -- optional integer
356+
351357 EXAMPLES::
352358
353359 sage: S = species.SetSpecies().restricted(min=3); S
@@ -388,7 +394,7 @@ def isotypes(self, labels, structure_class=None):
388394
389395 def _check (self , n = 5 ):
390396 """
391- Returns True if the number of structures and isomorphism types
397+ Return `` True`` if the number of structures and isomorphism types
392398 generated is the same as the number found from the generating
393399 series.
394400
@@ -409,7 +415,7 @@ def _check(self, n=5):
409415
410416 def __pow__ (self , n ):
411417 r"""
412- Returns this species to the power `n`.
418+ Return this species to the power `n`.
413419
414420 This uses a binary exponentiation algorithm to perform the
415421 powering.
@@ -466,9 +472,9 @@ def __pow__(self, n):
466472
467473 def _get_series (self , series_ring_class , prefix , base_ring = None ):
468474 """
469- Returns the generating / isotype generating / cycle index series
475+ Return the generating / isotype generating / cycle index series
470476 ring. The purpose of this method is to restrict the result of
471- _series_helper to self._min and self._max.
477+ _series_helper to `` self._min`` and `` self._max`` .
472478
473479 EXAMPLES::
474480
@@ -478,10 +484,10 @@ def _get_series(self, series_ring_class, prefix, base_ring=None):
478484 """
479485 series = self ._series_helper (series_ring_class , prefix , base_ring = base_ring )
480486
481- #We need to restrict the series based on the min
482- #and max of this species. Note that if min and max
483- #are both None (as in the default case), then the restrict
484- #method will just return series.
487+ # We need to restrict the series based on the min
488+ # and max of this species. Note that if min and max
489+ # are both None (as in the default case), then the restrict
490+ # method will just return series.
485491 return series .restricted (min = self ._min , max = self ._max )
486492
487493 def _series_helper (self , series_ring_class , prefix , base_ring = None ):
@@ -493,7 +499,6 @@ def _series_helper(self, series_ring_class, prefix, base_ring=None):
493499
494500 INPUT:
495501
496-
497502 - ``series_ring_class`` - A class for the series
498503 ring such as ExponentialGeneratingSeriesRing, etc.
499504
@@ -506,7 +511,6 @@ def _series_helper(self, series_ring_class, prefix, base_ring=None):
506511 of the generating series live. If it is not specified, then it is
507512 determined by the weight of the species.
508513
509-
510514 EXAMPLES::
511515
512516 sage: from sage.combinat.species.generating_series import OrdinaryGeneratingSeriesRing
@@ -521,73 +525,73 @@ def _series_helper(self, series_ring_class, prefix, base_ring=None):
521525 sage: itgs.coefficients(3)
522526 [1.0, 1.0, 1.0]
523527 """
524- prefix = "_" + prefix
528+ prefix = "_" + prefix
525529
526- #Get the base ring
530+ # Get the base ring
527531 if base_ring is None :
528532 base_ring = self .weight_ring ()
529533 else :
530- #The specified base ring must have maps from both
531- #the rational numbers and the weight ring
534+ # The specified base ring must have maps from both
535+ # the rational numbers and the weight ring
532536 if not base_ring .has_coerce_map_from (QQ ):
533537 raise ValueError ("specified base ring does not contain the rationals" )
534538 if not base_ring .has_coerce_map_from (self .weight_ring ()):
535539 raise ValueError ("specified base ring is incompatible with the weight ring of self" )
536540
537541 series_ring = series_ring_class (base_ring )
538542
539- #Try to return things like self._gs(base_ring)
540- #This is used when the subclass wants to just
541- #handle creating the generating series itself;
542- #for example, returning the exponential of a
543- #generating series.
543+ # Try to return things like self._gs(base_ring)
544+ # This is used when the subclass wants to just
545+ # handle creating the generating series itself;
546+ # for example, returning the exponential of a
547+ # generating series.
544548 try :
545549 return getattr (self , prefix )(series_ring , base_ring )
546550 except AttributeError :
547551 pass
548552
549- #Try to return things like self._gs_iterator(base_ring).
550- #This is used when the subclass just provides an iterator
551- #for the coefficients of the generating series. Optionally,
552- #the subclass can specify the order of the series.
553+ # Try to return things like self._gs_iterator(base_ring).
554+ # This is used when the subclass just provides an iterator
555+ # for the coefficients of the generating series. Optionally,
556+ # the subclass can specify the order of the series.
553557 try :
554- iterator = getattr (self , prefix + "_iterator" )(base_ring )
558+ iterator = getattr (self , prefix + "_iterator" )(base_ring )
555559 try :
556560 return series_ring (iterator , order = self ._order ())
557561 except AttributeError :
558562 return series_ring (iterator )
559563 except AttributeError :
560564 pass
561565
562- #Try to use things like self._gs_term(base_ring).
563- #This is used when the generating series is just a single
564- #term.
566+ # Try to use things like self._gs_term(base_ring).
567+ # This is used when the generating series is just a single
568+ # term.
565569 try :
566- return series_ring .term ( getattr (self , prefix + "_term" )(base_ring ),
567- self ._order ())
570+ return series_ring .term (getattr (self , prefix + "_term" )(base_ring ),
571+ self ._order ())
568572 except AttributeError :
569573 pass
570574
571- #Try to use things like self._gs_list(base_ring).
572- #This is used when the coefficients of the generating series
573- #can be given by a finite list with the last coefficient repeating.
574- #The generating series with all ones coefficients is generated this
575- #way.
575+ # Try to use things like self._gs_list(base_ring).
576+ # This is used when the coefficients of the generating series
577+ # can be given by a finite list with the last coefficient repeating.
578+ # The generating series with all ones coefficients is generated this
579+ # way.
576580 try :
577- return series_ring (getattr (self , prefix + "_list" )(base_ring ))
581+ return series_ring (getattr (self , prefix + "_list" )(base_ring ))
578582 except AttributeError :
579583 pass
580584
581585 raise NotImplementedError
582586
583-
584587 @cached_method
585588 def generating_series (self , base_ring = None ):
586589 r"""
587- Returns the generating series for this species. This is an
588- exponential generating series so the nth coefficient of the series
589- corresponds to the number of labeled structures with n labels
590- divided by n!.
590+ Return the generating series for this species.
591+
592+ This is an exponential generating series so the `n`-th
593+ coefficient of the series corresponds to the number of labeled
594+ structures with `n` labels divided by `n!`.
591595
592596 EXAMPLES::
593597
@@ -607,9 +611,10 @@ def generating_series(self, base_ring=None):
607611 @cached_method
608612 def isotype_generating_series (self , base_ring = None ):
609613 r"""
610- Returns the isotype generating series for this species. The nth
611- coefficient of this series corresponds to the number of isomorphism
612- types for the structures on n labels.
614+ Return the isotype generating series for this species.
615+
616+ The `n`-th coefficient of this series corresponds to the number
617+ of isomorphism types for the structures on `n` labels.
613618
614619 EXAMPLES::
615620
@@ -626,11 +631,12 @@ def isotype_generating_series(self, base_ring=None):
626631 """
627632 return self ._get_series (OrdinaryGeneratingSeriesRing , "itgs" , base_ring )
628633
629-
630634 @cached_method
631635 def cycle_index_series (self , base_ring = None ):
632636 r"""
633- Returns the cycle index series for this species.
637+ Return the cycle index series for this species.
638+
639+ The cycle index series is a sequence of symmetric functions.
634640
635641 EXAMPLES::
636642
@@ -641,10 +647,9 @@ def cycle_index_series(self, base_ring=None):
641647 """
642648 return self ._get_series (CycleIndexSeriesRing , "cis" , base_ring )
643649
644-
645650 def is_weighted (self ):
646651 """
647- Returns True if this species has a nontrivial weighting associated
652+ Return `` True`` if this species has a nontrivial weighting associated
648653 with it.
649654
650655 EXAMPLES::
@@ -657,7 +662,7 @@ def is_weighted(self):
657662
658663 def weight_ring (self ):
659664 """
660- Returns the ring in which the weights of this species occur.
665+ Return the ring in which the weights of this species occur.
661666
662667 By default, this is just the field of rational numbers.
663668
@@ -673,16 +678,16 @@ def weight_ring(self):
673678
674679 def _common_parent (self , parents ):
675680 """
676- Returns a parent that all of the parents in the given list of
677- parents
681+ Return a parent that contains all the parents
682+ in the given list of parents.
678683
679684 EXAMPLES::
680685
681686 sage: C = species.CombinatorialSpecies()
682687 sage: C._common_parent([QQ, ZZ['t']])
683688 Univariate Polynomial Ring in t over Rational Field
684689 """
685- assert len ( parents ) > 0
690+ assert parents
686691 from sage .structure .element import get_coercion_model
687692 cm = get_coercion_model ()
688693
@@ -725,7 +730,7 @@ def digraph(self):
725730
726731 def _add_to_digraph (self , d ):
727732 """
728- Add this species as a vertex to the digraph d along with any
733+ Add this species as a vertex to the digraph ``d`` along with any
729734 'children' of this species. For example, sum species would add
730735 itself as a vertex and an edge between itself and each of its
731736 summands.
@@ -753,7 +758,6 @@ def _add_to_digraph(self, d):
753758 d .add_edge (self , child )
754759 child ._add_to_digraph (d )
755760
756-
757761 def algebraic_equation_system (self ):
758762 """
759763 Return a system of algebraic equations satisfied by this species.
0 commit comments