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

""" 

Subset 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 .set_species import SetSpecies 

from .generating_series import _integers_from, factorial_stream 

from .structure import GenericSpeciesStructure 

from sage.combinat.species.misc import accept_size 

from sage.structure.unique_representation import UniqueRepresentation 

 

class SubsetSpeciesStructure(GenericSpeciesStructure): 

def __repr__(self): 

""" 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

{} 

""" 

s = GenericSpeciesStructure.__repr__(self) 

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

 

def canonical_label(self): 

""" 

EXAMPLES:: 

 

sage: P = species.SubsetSpecies() 

sage: S = P.structures(["a", "b", "c"]) 

sage: [s.canonical_label() for s in S] 

[{}, {'a'}, {'a'}, {'a'}, {'a', 'b'}, {'a', 'b'}, {'a', 'b'}, {'a', 'b', 'c'}] 

""" 

rng = list(range(1, len(self._list) + 1)) 

return self.__class__(self.parent(), self._labels, rng) 

 

 

def label_subset(self): 

""" 

Returns a subset of the labels that "appear" in this 

structure. 

 

EXAMPLES:: 

 

sage: P = species.SubsetSpecies() 

sage: S = P.structures(["a", "b", "c"]) 

sage: [s.label_subset() for s in S] 

[[], ['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] 

""" 

return [self._relabel(i) for i in self._list] 

 

def transport(self, perm): 

""" 

Returns the transport of this subset along the permutation perm. 

 

EXAMPLES:: 

 

sage: F = species.SubsetSpecies() 

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

{'a', 'c'} 

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

sage: a.transport(p) 

{'b', 'c'} 

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

sage: a.transport(p) 

{'a', 'c'} 

""" 

l = sorted([perm(i) for i in self._list]) 

return SubsetSpeciesStructure(self.parent(), self._labels, l) 

 

def automorphism_group(self): 

""" 

Returns the group of permutations whose action on this subset leave 

it fixed. 

 

EXAMPLES:: 

 

sage: F = species.SubsetSpecies() 

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

{1, 3} 

sage: a.automorphism_group() 

Permutation Group with generators [(2,4), (1,3)] 

 

:: 

 

sage: [a.transport(g) for g in a.automorphism_group()] 

[{1, 3}, {1, 3}, {1, 3}, {1, 3}] 

""" 

from sage.groups.all import SymmetricGroup, PermutationGroup 

a = SymmetricGroup(self._list) 

b = SymmetricGroup(self.complement()._list) 

return PermutationGroup(a.gens() + b.gens()) 

 

def complement(self): 

""" 

EXAMPLES:: 

 

sage: F = species.SubsetSpecies() 

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

{'a', 'c'} 

sage: a.complement() 

{'b'} 

""" 

new_list = [i for i in range(1, len(self._labels)+1) if i not in self._list] 

return SubsetSpeciesStructure(self.parent(), self._labels, new_list) 

 

class SubsetSpecies(GenericCombinatorialSpecies, UniqueRepresentation): 

@staticmethod 

@accept_size 

def __classcall__(cls, *args, **kwds): 

""" 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies(); S 

Subset species 

""" 

return super(SubsetSpecies, cls).__classcall__(cls, *args, **kwds) 

 

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

""" 

Returns the species of subsets. 

 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[1, 2, 2, 4/3, 2/3] 

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

[1, 2, 3, 4, 5] 

 

sage: S = species.SubsetSpecies() 

sage: c = S.generating_series().coefficients(3) 

sage: S._check() 

True 

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

True 

""" 

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

self._name = "Subset species" 

 

_default_structure_class = SubsetSpeciesStructure 

 

def _structures(self, structure_class, labels): 

""" 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[{}, {1}, {2}, {1, 2}] 

sage: S.structures(['a','b']).list() 

[{}, {'a'}, {'b'}, {'a', 'b'}] 

""" 

from sage.combinat.combination import Combinations 

for c in Combinations(range(1, len(labels)+1)): 

yield structure_class(self, labels, c) 

 

def _isotypes(self, structure_class, labels): 

""" 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[{}, {1}, {1, 2}] 

sage: S.isotypes(['a','b']).list() 

[{}, {'a'}, {'a', 'b'}] 

""" 

for i in range(len(labels)+1): 

yield structure_class(self, labels, range(1, i+1)) 

 

def _gs_iterator(self, base_ring): 

""" 

The generating series for the species of subsets is 

`e^{2x}`. 

 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[1, 2, 2, 4/3, 2/3] 

""" 

for n in _integers_from(0): 

yield base_ring(2)**n/base_ring(factorial_stream[n]) 

 

def _itgs_iterator(self, base_ring): 

""" 

The generating series for the species of subsets is 

`e^{2x}`. 

 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[1, 2, 3, 4, 5] 

""" 

for n in _integers_from(1): 

yield base_ring(n) 

 

def _cis(self, series_ring, base_ring): 

r""" 

The cycle index series for the species of subsets satisfies 

 

.. MATH:: 

 

Z_{\mathfrak{p}} = Z_{\mathcal{E}} \cdot Z_{\mathcal{E}} 

 

 

EXAMPLES:: 

 

sage: S = species.SubsetSpecies() 

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

[p[], 

2*p[1], 

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

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

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

""" 

ciset = SetSpecies().cycle_index_series(base_ring) 

res = ciset**2 

if self.is_weighted(): 

res *= self._weight 

return res 

 

#Backward compatibility 

SubsetSpecies_class = SubsetSpecies