Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

""" 

Examples of Combinatorial Species 

""" 

#***************************************************************************** 

# Copyright (C) 2008 Mike Hansen <mhansen@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: 

# 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

from __future__ import absolute_import 

 

from .set_species import SetSpecies 

from .partition_species import PartitionSpecies 

from .subset_species import SubsetSpecies 

from .recursive_species import CombinatorialSpecies 

from .characteristic_species import CharacteristicSpecies, SingletonSpecies, EmptySetSpecies 

from .cycle_species import CycleSpecies 

from .linear_order_species import LinearOrderSpecies 

from .permutation_species import PermutationSpecies 

from .empty_species import EmptySpecies 

from .sum_species import SumSpecies 

from .product_species import ProductSpecies 

from .composition_species import CompositionSpecies 

from .functorial_composition_species import FunctorialCompositionSpecies 

 

from sage.misc.cachefunc import cached_function 

 

@cached_function 

def SimpleGraphSpecies(): 

""" 

Returns the species of simple graphs. 

 

EXAMPLES:: 

 

sage: S = species.SimpleGraphSpecies() 

sage: S.generating_series().counts(10) 

[1, 1, 2, 8, 64, 1024, 32768, 2097152, 268435456, 68719476736] 

sage: S.cycle_index_series().coefficients(5) 

[p[], 

p[1], 

p[1, 1] + p[2], 

4/3*p[1, 1, 1] + 2*p[2, 1] + 2/3*p[3], 

8/3*p[1, 1, 1, 1] + 4*p[2, 1, 1] + 2*p[2, 2] + 4/3*p[3, 1] + p[4]] 

sage: S.isotype_generating_series().coefficients(6) 

[1, 1, 2, 4, 11, 34] 

 

TESTS:: 

 

sage: seq = S.isotype_generating_series().counts(6)[1:] 

sage: oeis(seq)[0] # optional -- internet 

A000088: Number of graphs on n unlabeled nodes. 

 

:: 

 

sage: seq = S.generating_series().counts(10)[1:] 

sage: oeis(seq)[0] # optional -- internet 

A006125: a(n) = 2^(n(n-1)/2). 

""" 

E = SetSpecies() 

E2 = SetSpecies(size=2) 

WP = SubsetSpecies() 

P2 = E2*E 

return WP.functorial_composition(P2) 

 

 

@cached_function 

def BinaryTreeSpecies(): 

""" 

Returns the species of binary trees on n leaves. The species of 

binary trees B is defined by B = X + B\*B where X is the singleton 

species. 

 

EXAMPLES:: 

 

sage: B = species.BinaryTreeSpecies() 

sage: B.generating_series().counts(10) 

[0, 1, 2, 12, 120, 1680, 30240, 665280, 17297280, 518918400] 

sage: B.isotype_generating_series().counts(10) 

[0, 1, 1, 2, 5, 14, 42, 132, 429, 1430] 

sage: B._check() 

True 

 

:: 

 

sage: B = species.BinaryTreeSpecies() 

sage: a = B.structures([1,2,3,4,5]).random_element(); a 

2*((5*3)*(4*1)) 

sage: a.automorphism_group() 

Permutation Group with generators [()] 

 

TESTS:: 

 

sage: seq = B.isotype_generating_series().counts(10)[1:] 

sage: oeis(seq)[0] # optional -- internet 

A000108: Catalan numbers: C(n) = binomial(2n,n)/(n+1) = (2n)!/(n!(n+1)!). Also called Segner numbers. 

""" 

B = CombinatorialSpecies() 

X = SingletonSpecies() 

B.define(X+B*B) 

return B 

 

@cached_function 

def BinaryForestSpecies(): 

""" 

Returns the species of binary forests. Binary forests are defined 

as sets of binary trees. 

 

EXAMPLES:: 

 

sage: F = species.BinaryForestSpecies() 

sage: F.generating_series().counts(10) 

[1, 1, 3, 19, 193, 2721, 49171, 1084483, 28245729, 848456353] 

sage: F.isotype_generating_series().counts(10) 

[1, 1, 2, 4, 10, 26, 77, 235, 758, 2504] 

sage: F.cycle_index_series().coefficients(7) 

[p[], 

p[1], 

3/2*p[1, 1] + 1/2*p[2], 

19/6*p[1, 1, 1] + 1/2*p[2, 1] + 1/3*p[3], 

193/24*p[1, 1, 1, 1] + 3/4*p[2, 1, 1] + 5/8*p[2, 2] + 1/3*p[3, 1] + 1/4*p[4], 

907/40*p[1, 1, 1, 1, 1] + 19/12*p[2, 1, 1, 1] + 5/8*p[2, 2, 1] + 1/2*p[3, 1, 1] + 1/6*p[3, 2] + 1/4*p[4, 1] + 1/5*p[5], 

49171/720*p[1, 1, 1, 1, 1, 1] + 193/48*p[2, 1, 1, 1, 1] + 15/16*p[2, 2, 1, 1] + 61/48*p[2, 2, 2] + 19/18*p[3, 1, 1, 1] + 1/6*p[3, 2, 1] + 7/18*p[3, 3] + 3/8*p[4, 1, 1] + 1/8*p[4, 2] + 1/5*p[5, 1] + 1/6*p[6]] 

 

TESTS:: 

 

sage: seq = F.isotype_generating_series().counts(10)[1:] 

sage: oeis(seq)[0] # optional -- internet 

A052854: Number of forests of ordered trees on n total nodes. 

""" 

B = BinaryTreeSpecies() 

S = SetSpecies() 

F = S(B) 

return F