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

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

""" 

Characteristic 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 six.moves import range 

 

from .species import GenericCombinatorialSpecies 

from .generating_series import factorial_stream 

from .structure import GenericSpeciesStructure 

from .set_species import SetSpecies 

from sage.structure.unique_representation import UniqueRepresentation 

 

class CharacteristicSpeciesStructure(GenericSpeciesStructure): 

def __repr__(self): 

""" 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(3) 

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

{1, 2, 3} 

sage: F = species.SingletonSpecies() 

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

[1] 

sage: F = species.EmptySetSpecies() 

sage: F.structures([]).list() 

[{}] 

""" 

s = GenericSpeciesStructure.__repr__(self) 

if self.parent()._n == 1: 

return s[1:-1] 

else: 

return "{" + s[1:-1] + "}" 

 

 

def canonical_label(self): 

""" 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(3) 

sage: a = F.structures(["a", "b", "c"]).random_element(); a 

{'a', 'b', 'c'} 

sage: a.canonical_label() 

{'a', 'b', 'c'} 

""" 

P = self.parent() 

rng = list(range(1, P._n + 1)) 

return CharacteristicSpeciesStructure(P, self._labels, rng) 

 

 

def transport(self, perm): 

""" 

Returns the transport of this structure along the permutation 

perm. 

 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(3) 

sage: a = F.structures(["a", "b", "c"]).random_element(); a 

{'a', 'b', 'c'} 

sage: p = PermutationGroupElement((1,2)) 

sage: a.transport(p) 

{'a', 'b', 'c'} 

""" 

return self 

 

def automorphism_group(self): 

""" 

Returns the group of permutations whose action on this structure 

leave it fixed. For the characteristic species, there is only one 

structure, so every permutation is in its automorphism group. 

 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(3) 

sage: a = F.structures(["a", "b", "c"]).random_element(); a 

{'a', 'b', 'c'} 

sage: a.automorphism_group() 

Symmetric group of order 3! as a permutation group 

""" 

from sage.groups.all import SymmetricGroup 

return SymmetricGroup(len(self._labels)) 

 

 

class CharacteristicSpecies(GenericCombinatorialSpecies, UniqueRepresentation): 

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

""" 

Return the characteristic species of order `n`. 

 

This species has exactly one structure on a set of size `n` 

and no structures on sets of any other size. 

 

EXAMPLES:: 

 

sage: X = species.CharacteristicSpecies(1) 

sage: X.structures([1]).list() 

[1] 

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

[] 

sage: X.generating_series().coefficients(4) 

[0, 1, 0, 0] 

sage: X.isotype_generating_series().coefficients(4) 

[0, 1, 0, 0] 

sage: X.cycle_index_series().coefficients(4) 

[0, p[1], 0, 0] 

 

sage: F = species.CharacteristicSpecies(3) 

sage: c = F.generating_series().coefficients(4) 

sage: F._check() 

True 

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

True 

 

TESTS:: 

 

sage: S1 = species.CharacteristicSpecies(1) 

sage: S2 = species.CharacteristicSpecies(1) 

sage: S3 = species.CharacteristicSpecies(2) 

sage: S4 = species.CharacteristicSpecies(2, weight=2) 

sage: S1 is S2 

True 

sage: S1 == S3 

False 

""" 

self._n = n 

self._name = "Characteristic species of order %s"%n 

self._state_info = [n] 

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

 

_default_structure_class = CharacteristicSpeciesStructure 

 

def _structures(self, structure_class, labels): 

""" 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(2) 

sage: l = [1, 2, 3] 

sage: F.structures(l).list() 

[] 

sage: F = species.CharacteristicSpecies(3) 

sage: F.structures(l).list() 

[{1, 2, 3}] 

""" 

if len(labels) == self._n: 

yield structure_class(self, labels, range(1,self._n+1)) 

 

_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. 

 

EXAMPLES:: 

 

sage: F = species.CharacteristicSpecies(2) 

sage: F._order() 

2 

""" 

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) 

 

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: C = species.CharacteristicSpecies(2) 

sage: Qz = QQ['z'] 

sage: R.<node0> = Qz[] 

sage: var_mapping = {'z':Qz.gen(), 'node0':R.gen()} 

sage: C._equation(var_mapping) 

z^2 

""" 

return var_mapping['z']**(self._n) 

 

#Backward compatibility 

CharacteristicSpecies_class = CharacteristicSpecies 

 

class EmptySetSpecies(CharacteristicSpecies): 

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

""" 

Returns the empty set species. 

 

This species has exactly one structure on the empty set. It is 

the same (and is implemented) as ``CharacteristicSpecies(0)``. 

 

EXAMPLES:: 

 

sage: X = species.EmptySetSpecies() 

sage: X.structures([]).list() 

[{}] 

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

[] 

sage: X.generating_series().coefficients(4) 

[1, 0, 0, 0] 

sage: X.isotype_generating_series().coefficients(4) 

[1, 0, 0, 0] 

sage: X.cycle_index_series().coefficients(4) 

[p[], 0, 0, 0] 

 

TESTS:: 

 

sage: E1 = species.EmptySetSpecies() 

sage: E2 = species.EmptySetSpecies() 

sage: E1 is E2 

True 

 

sage: E = species.EmptySetSpecies() 

sage: E._check() 

True 

sage: E == loads(dumps(E)) 

True 

""" 

CharacteristicSpecies_class.__init__(self, 0, min=min, max=max, weight=weight) 

self._name = "Empty set species" 

self._state_info = [] 

 

#Backward compatibility 

EmptySetSpecies_class = EmptySetSpecies._cached_constructor = EmptySetSpecies 

 

class SingletonSpecies(CharacteristicSpecies): 

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

""" 

Returns the species of singletons. 

 

This species has exactly one structure on a set of size `1`. It 

is the same (and is implemented) as ``CharacteristicSpecies(1)``. 

 

EXAMPLES:: 

 

sage: X = species.SingletonSpecies() 

sage: X.structures([1]).list() 

[1] 

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

[] 

sage: X.generating_series().coefficients(4) 

[0, 1, 0, 0] 

sage: X.isotype_generating_series().coefficients(4) 

[0, 1, 0, 0] 

sage: X.cycle_index_series().coefficients(4) 

[0, p[1], 0, 0] 

 

TESTS:: 

 

sage: S1 = species.SingletonSpecies() 

sage: S2 = species.SingletonSpecies() 

sage: S1 is S2 

True 

 

sage: S = species.SingletonSpecies() 

sage: S._check() 

True 

sage: S == loads(dumps(S)) 

True 

""" 

CharacteristicSpecies_class.__init__(self, 1, min=min, max=max, weight=weight) 

self._name = "Singleton species" 

self._state_info = [] 

 

#Backward compatibility 

SingletonSpecies_class = SingletonSpecies