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

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

# -*- coding: utf-8 -*- 

r""" 

Conjugacy classes of groups 

 

This module implements a wrapper of GAP's ``ConjugacyClass`` function. 

 

There are two main classes, :class:`ConjugacyClass` and 

:class:`ConjugacyClassGAP`. All generic methods should go into 

:class:`ConjugacyClass`, whereas :class:`ConjugacyClassGAP` should only 

contain wrappers for GAP functions. :class:`ConjugacyClass` contains some 

fallback methods in case some group cannot be defined as a GAP object. 

 

.. TODO:: 

 

- Implement a non-naive fallback method for computing all the elements of 

the conjugacy class when the group is not defined in GAP, as the one in 

Butler's paper. 

- Define a sage method for gap matrices so that groups of matrices can 

use the quicker GAP algorithm rather than the naive one. 

 

EXAMPLES: 

 

Conjugacy classes for groups of permutations:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: G.conjugacy_class(g) 

Conjugacy class of cycle type [4] in Symmetric group of order 4! as a permutation group 

 

Conjugacy classes for groups of matrices:: 

 

sage: F = GF(5) 

sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] 

sage: H = MatrixGroup(gens) 

sage: h = H(matrix(F,2,[1,2, -1, 1])) 

sage: H.conjugacy_class(h) 

Conjugacy class of [1 2] 

[4 1] in Matrix group over Finite Field of size 5 with 2 generators ( 

[1 2] [1 1] 

[4 1], [0 1] 

) 

 

TESTS:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2,3)) 

sage: C = ConjugacyClass(G,g) 

sage: TestSuite(C).run() 

""" 

 

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

# Copyright (C) 2011 Javier López Peña <jlopez@ende.cc> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

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

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

 

from sage.structure.parent import Parent 

from sage.misc.cachefunc import cached_method 

from sage.categories.enumerated_sets import EnumeratedSets 

from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 

 

 

class ConjugacyClass(Parent): 

r""" 

Generic conjugacy classes for elements in a group. 

 

This is the default fall-back implementation to be used whenever 

GAP cannot handle the group. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: ConjugacyClass(G,g) 

Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a 

permutation group 

""" 

def __init__(self, group, element): 

r""" 

Generic conjugacy classes for elements in a group. 

 

This is the default fall-back implementation to be used whenever 

GAP cannot handle the group. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: ConjugacyClass(G,g) 

Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a 

permutation group 

sage: TestSuite(G).run() 

""" 

self._parent = group 

self._representative = element 

try: 

finite = group.is_finite() 

except (AttributeError, NotImplementedError): 

finite = False 

if finite: 

Parent.__init__(self, category=FiniteEnumeratedSets()) 

else: # If the group is not finite, then we do not know if we are finite or not 

Parent.__init__(self, category=EnumeratedSets()) 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: C = ConjugacyClass(G,g) 

sage: C 

Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a 

permutation group 

""" 

return "Conjugacy class of %s in %s" % (self._representative, 

self._parent) 

 

def __eq__(self, other): 

r""" 

Equality of conjugacy classes is tested by comparing the 

underlying sets. 

 

EXAMPLES:: 

 

sage: F = GF(5) 

sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] 

sage: H = MatrixGroup(gens) 

sage: h = H(matrix(F,2,[1,2, -1, 1])) 

sage: h2 = H(matrix(F,2,[1,1, 0, 1])) 

sage: g = h2*h*h2^(-1) 

sage: C = ConjugacyClass(H,h) 

sage: D = ConjugacyClass(H,g) 

sage: C == D 

True 

""" 

if not isinstance(other, ConjugacyClass): 

return False 

return self.set() == other.set() 

 

def __ne__(self, other): 

""" 

Negation of equality. 

 

EXAMPLES:: 

 

sage: F = GF(5) 

sage: gens = [matrix(F,2, [1,2,-1,1]), matrix(F,2, [1,1,0,1])] 

sage: H = MatrixGroup(gens) 

sage: h = H(matrix(F,2, [1,2,-1,1])) 

sage: h2 = H(matrix(F,2, [1,1,0,1])) 

sage: g = h2 * h * h2^(-1) 

sage: C = ConjugacyClass(H, h) 

sage: D = ConjugacyClass(H, g) 

sage: C != D 

False 

sage: C != ConjugacyClass(H, H(identity_matrix(F, 2))) 

True 

""" 

return not (self == other) 

 

def __contains__(self, element): 

r""" 

Check if ``element`` belongs to the conjugacy class ``self``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: C = ConjugacyClass(G,g) 

sage: g in C 

True 

""" 

return element in self.set() 

 

def __iter__(self): 

r""" 

Naive algorithm to give the elements of the conjugacy class. 

 

.. TODO:: 

 

Implement a non-naive algorithm, cf. for instance 

G. Butler: "An Inductive Schema for Computing Conjugacy Classes 

in Permutation Groups", Math. of Comp. Vol. 62, No. 205 (1994) 

 

EXAMPLES: 

 

Groups of permutations:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2)) 

sage: C = ConjugacyClass(G,g) 

sage: sorted(C) 

[(2,3), (1,2), (1,3)] 

 

It works for infinite groups:: 

 

sage: a = matrix(ZZ,2,[1,1,0,1]) 

sage: b = matrix(ZZ,2,[1,0,1,1]) 

sage: G = MatrixGroup([a,b]) # takes 1s 

sage: a = G(a) 

sage: C = ConjugacyClass(G, a) 

sage: it = iter(C) 

sage: [next(it) for _ in range(5)] # random (nothing guarantees enumeration order) 

[ 

[1 1] [ 2 1] [ 0 1] [ 3 1] [ 3 4] 

[0 1], [-1 0], [-1 2], [-4 -1], [-1 -1] 

] 

 

We check that two matrices are in C:: 

 

sage: b = G(b) 

sage: m1 = b * a * ~b 

sage: m2 = ~b * a * b 

sage: any(x == m1 for x in C) 

True 

sage: any(x == m2 for x in C) 

True 

 

""" 

from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet 

g = self._representative 

gens = self._parent.monoid_generators() 

R = RecursivelyEnumeratedSet([g], 

lambda y: [c * y * c**-1 for c in gens], 

structure=None) 

return R.breadth_first_search_iterator() 

 

@cached_method 

def set(self): 

r""" 

Return the set of elements of the conjugacy class. 

 

EXAMPLES: 

 

Groups of permutations:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2)) 

sage: C = ConjugacyClass(G,g) 

sage: S = [(2,3), (1,2), (1,3)] 

sage: C.set() == Set(G(x) for x in S) 

True 

 

Groups of matrices over finite fields:: 

 

sage: F = GF(5) 

sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] 

sage: H = MatrixGroup(gens) 

sage: h = H(matrix(F,2,[1,2, -1, 1])) 

sage: C = ConjugacyClass(H,h) 

sage: S = [[[3, 2], [2, 4]], [[0, 1], [2, 2]], [[3, 4], [1, 4]],\ 

[[0, 3], [4, 2]], [[1, 2], [4, 1]], [[2, 1], [2, 0]],\ 

[[4, 1], [4, 3]], [[4, 4], [1, 3]], [[2, 4], [3, 0]],\ 

[[1, 4], [2, 1]], [[3, 3], [3, 4]], [[2, 3], [4, 0]],\ 

[[0, 2], [1, 2]], [[1, 3], [1, 1]], [[4, 3], [3, 3]],\ 

[[4, 2], [2, 3]], [[0, 4], [3, 2]], [[1, 1], [3, 1]],\ 

[[2, 2], [1, 0]], [[3, 1], [4, 4]]] 

sage: C.set() == Set(H(x) for x in S) 

True 

 

It is not implemented for infinite groups:: 

 

sage: a = matrix(ZZ,2,[1,1,0,1]) 

sage: b = matrix(ZZ,2,[1,0,1,1]) 

sage: G = MatrixGroup([a,b]) # takes 1s 

sage: g = G(a) 

sage: C = ConjugacyClass(G, g) 

sage: C.set() 

Traceback (most recent call last): 

... 

NotImplementedError: Listing the elements of conjugacy classes is not implemented for infinite groups! Use the iter function instead. 

""" 

if self._parent.is_finite(): 

from sage.sets.set import Set 

return Set(iter(self)) 

# return Set(self) creates an infinite loop in __contains__ 

else: 

raise NotImplementedError("Listing the elements of conjugacy " 

"classes is not implemented for infinite groups! Use the " 

"iter function instead.") 

 

def list(self): 

r""" 

Return a list with all the elements of ``self``. 

 

EXAMPLES: 

 

Groups of permutations:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2,3)) 

sage: c = ConjugacyClass(G,g) 

sage: L = c.list() 

sage: Set(L) == Set([G((1,3,2)), G((1,2,3))]) 

True 

""" 

if self._parent.is_finite(): 

return list(iter(self)) 

# return list(self) creates an infinite loop because list calls 

# __len__ which calls list... 

else: 

raise NotImplementedError("Listing the elements of conjugacy " 

"classes is not implemented for infinite groups! Use the " 

"iter function instead.") 

 

def is_real(self): 

""" 

Check if ``self`` is real (closed for inverses). 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: c = ConjugacyClass(G,g) 

sage: c.is_real() 

True 

""" 

return self._representative**(-1) in self 

 

def is_rational(self): 

""" 

Check if ``self`` is rational (closed for powers). 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: c = ConjugacyClass(G,g) 

sage: c.is_rational() 

False 

""" 

g = self._representative 

return all(g**k in self.set() for k in range(2, g.order())) 

 

def representative(self): 

""" 

Return a representative of ``self``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2,3)) 

sage: C = ConjugacyClass(G,g) 

sage: C.representative() 

(1,2,3) 

""" 

return self._representative 

 

an_element = representative 

 

 

class ConjugacyClassGAP(ConjugacyClass): 

r""" 

Class for a conjugacy class for groups defined over GAP. 

 

Intended for wrapping GAP methods on conjugacy classes. 

 

INPUT: 

 

- ``group`` -- the group in which the conjugacy class is taken 

 

- ``element`` -- the element generating the conjugacy class 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: ConjugacyClassGAP(G,g) 

Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a 

permutation group 

""" 

def __init__(self, group, element): 

r""" 

Constructor for the class. 

 

EXAMPLES: 

 

Conjugacy classes for groups of permutations:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: ConjugacyClassGAP(G,g) 

Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group 

 

Conjugacy classes for groups of matrices:: 

 

sage: F = GF(5) 

sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] 

sage: H = MatrixGroup(gens) 

sage: h = H(matrix(F,2,[1,2, -1, 1])) 

sage: ConjugacyClassGAP(H,h) 

Conjugacy class of [1 2] 

[4 1] in Matrix group over Finite Field of size 5 with 2 generators ( 

[1 2] [1 1] 

[4 1], [0 1] 

) 

""" 

try: 

# GAP interface 

self._gap_group = group._gap_() 

self._gap_representative = element._gap_() 

except (AttributeError, TypeError): 

try: 

# LibGAP 

self._gap_group = group.gap() 

self._gap_representative = element.gap() 

except (AttributeError, TypeError): 

raise TypeError("The group %s cannot be defined as a GAP group" % group) 

 

self._gap_conjugacy_class = self._gap_group.ConjugacyClass(self._gap_representative) 

ConjugacyClass.__init__(self, group, element) 

 

def _gap_(self): 

r""" 

Return the gap object corresponding to ``self``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(3) 

sage: g = G((1,2,3)) 

sage: C = ConjugacyClassGAP(G,g) 

sage: C._gap_() 

ConjugacyClass( SymmetricGroup( [ 1 .. 3 ] ), (1,2,3) ) 

""" 

return self._gap_conjugacy_class 

 

def cardinality(self): 

r""" 

Return the size of this conjugacy class. 

 

EXAMPLES:: 

 

sage: W = WeylGroup(['C',6]) 

sage: cc = W.conjugacy_class(W.an_element()) 

sage: cc.cardinality() 

3840 

sage: type(cc.cardinality()) 

<type 'sage.rings.integer.Integer'> 

""" 

return self._gap_().Size().sage() 

 

def __contains__(self, g): 

r""" 

Containment test. 

 

Wraps ``IsConjugate`` from GAP. 

 

TESTS:: 

 

sage: W = WeylGroup(['C',6]) 

sage: g0,g1,g2,g3,g4,g5 = W.gens() 

sage: cc = W.conjugacy_class(g0) 

sage: g0 in cc 

True 

sage: g1 in cc 

True 

sage: g2 in cc 

True 

sage: g3 in cc 

True 

sage: g4 in cc 

True 

sage: g5 in cc 

False 

 

Only trivial cases are implemented for infinite groups:: 

 

sage: G = SL(2,ZZ) 

sage: m1 = G([[1,1],[0,1]]) 

sage: m2 = G([[1,0],[1,1]]) 

sage: m1 in G.conjugacy_class(m1) and m2 in G.conjugacy_class(m2) 

True 

sage: m2 in G.conjugacy_class(m1) 

Traceback (most recent call last): 

... 

NotImplementedError: only implemented for finite groups 

""" 

g = self._parent(g) 

g0 = self._representative 

if g == g0: 

return True 

 

G = self._parent 

try: 

finite = G.is_finite() 

except (AttributeError, NotImplementedError): 

finite = False 

 

if not finite: 

raise NotImplementedError("only implemented for finite groups") 

 

return G._gap_().IsConjugate(g0._gap_(), g._gap_()).sage() 

 

@cached_method 

def set(self): 

r""" 

Return a Sage ``Set`` with all the elements of the conjugacy class. 

 

By default attempts to use GAP construction of the conjugacy class. 

If GAP method is not implemented for the given group, and the group 

is finite, falls back to a naive algorithm. 

 

.. WARNING:: 

 

The naive algorithm can be really slow and memory intensive. 

 

EXAMPLES: 

 

Groups of permutations:: 

 

sage: G = SymmetricGroup(4) 

sage: g = G((1,2,3,4)) 

sage: C = ConjugacyClassGAP(G,g) 

sage: S = [(1,3,2,4), (1,4,3,2), (1,3,4,2), (1,2,3,4), (1,4,2,3), (1,2,4,3)] 

sage: C.set() == Set(G(x) for x in S) 

True 

 

""" 

from sage.sets.set import Set 

try: 

cc = self._gap_conjugacy_class.AsList().sage() 

return Set([self._parent(x) for x in cc]) 

except NotImplementedError: # If GAP doesn't work, fall back to naive method 

return ConjugacyClass.set.f(self) # Need the f because the base-class method is also cached