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

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

""" 

Sum species 

""" 

from __future__ import absolute_import 

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

# 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 .species import GenericCombinatorialSpecies 

from .structure import SpeciesStructureWrapper 

from sage.structure.unique_representation import UniqueRepresentation 

 

 

class SumSpeciesStructure(SpeciesStructureWrapper): 

pass 

 

class SumSpecies(GenericCombinatorialSpecies, UniqueRepresentation): 

def __init__(self, F, G, min=None, max=None, weight=None): 

""" 

Returns the sum of two species. 

 

EXAMPLES:: 

 

sage: S = species.PermutationSpecies() 

sage: A = S+S 

sage: A.generating_series().coefficients(5) 

[2, 2, 2, 2, 2] 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F._check() 

True 

sage: F == loads(dumps(F)) 

True 

 

TESTS:: 

 

sage: A = species.SingletonSpecies() + species.SingletonSpecies() 

sage: B = species.SingletonSpecies() + species.SingletonSpecies() 

sage: C = species.SingletonSpecies() + species.SingletonSpecies(min=2) 

sage: A is B 

True 

sage: (A is C) or (A == C) 

False 

""" 

self._F = F 

self._G = G 

 

self._state_info = [F, G] 

 

GenericCombinatorialSpecies.__init__(self, min=None, max=None, weight=None) 

 

_default_structure_class = SumSpeciesStructure 

 

def left_summand(self): 

""" 

Returns the left summand of this species. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P*P 

sage: F.left_summand() 

Permutation species 

""" 

return self._F 

 

def right_summand(self): 

""" 

Returns the right summand of this species. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P*P 

sage: F.right_summand() 

Product of (Permutation species) and (Permutation species) 

""" 

return self._G 

 

def _name(self): 

""" 

Note that we use a function to return the name of this species 

because we can't do it in the __init__ method due to it 

requiring that self.left_summand() and self.right_summand() 

already be unpickled. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F._name() 

'Sum of (Permutation species) and (Permutation species)' 

""" 

return "Sum of (%s) and (%s)"%(self.left_summand(), self.right_summand()) 

 

def _structures(self, structure_class, labels): 

""" 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F.structures([1,2]).list() 

[[1, 2], [2, 1], [1, 2], [2, 1]] 

""" 

for res in self.left_summand().structures(labels): 

yield structure_class(self, res, tag="left") 

 

for res in self.right_summand().structures(labels): 

yield structure_class(self, res, tag="right") 

 

def _isotypes(self, structure_class, labels): 

""" 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F.isotypes([1,2]).list() 

[[2, 1], [1, 2], [2, 1], [1, 2]] 

""" 

for res in self._F.isotypes(labels): 

yield structure_class(self, res, tag="left") 

 

for res in self._G.isotypes(labels): 

yield structure_class(self, res, tag="right") 

 

def _gs(self, series_ring, base_ring): 

""" 

Returns the cycle index series of this species. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F.generating_series().coefficients(5) 

[2, 2, 2, 2, 2] 

""" 

return (self.left_summand().generating_series(base_ring) + 

self.right_summand().generating_series(base_ring)) 

 

 

def _itgs(self, series_ring, base_ring): 

""" 

Returns the isomorphism type generating series of this species. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

sage: F.isotype_generating_series().coefficients(5) 

[2, 2, 4, 6, 10] 

""" 

return (self.left_summand().isotype_generating_series(base_ring) + 

self.right_summand().isotype_generating_series(base_ring)) 

 

def _cis(self, series_ring, base_ring): 

""" 

Returns the generating series of this species. 

 

EXAMPLES:: 

 

sage: P = species.PermutationSpecies() 

sage: F = P + P 

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

[2*p[], 

2*p[1], 

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

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

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

""" 

return (self.left_summand().cycle_index_series(base_ring) + 

self.right_summand().cycle_index_series(base_ring)) 

 

def weight_ring(self): 

""" 

Returns the weight ring for this species. This is determined by 

asking Sage's coercion model what the result is when you add 

elements of the weight rings for each of the operands. 

 

EXAMPLES:: 

 

sage: S = species.SetSpecies() 

sage: C = S+S 

sage: C.weight_ring() 

Rational Field 

 

:: 

 

sage: S = species.SetSpecies(weight=QQ['t'].gen()) 

sage: C = S + S 

sage: C.weight_ring() 

Univariate Polynomial Ring in t over Rational Field 

""" 

return self._common_parent([self.left_summand().weight_ring(), 

self.right_summand().weight_ring()]) 

 

def _equation(self, var_mapping): 

""" 

Returns the right hand side of an algebraic equation satisfied by 

this species. This is a utility function called by the 

algebraic_equation_system method. 

 

EXAMPLES:: 

 

sage: X = species.SingletonSpecies() 

sage: S = X + X 

sage: S.algebraic_equation_system() 

[node1 - 2*z] 

""" 

return sum(var_mapping[operand] for operand in self._state_info) 

 

#Backward compatibility 

SumSpecies_class = SumSpecies