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

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

r""" 

"Named" Permutation groups (such as the symmetric group, S_n) 

 

You can construct the following permutation groups: 

 

-- SymmetricGroup, $S_n$ of order $n!$ (n can also be a list $X$ of distinct 

positive integers, in which case it returns $S_X$) 

 

-- AlternatingGroup, $A_n$ of order $n!/2$ (n can also be a list $X$ 

of distinct positive integers, in which case it returns 

$A_X$) 

 

-- DihedralGroup, $D_n$ of order $2n$ 

 

-- GeneralDihedralGroup, $Dih(G)$, where G is an abelian group 

 

-- CyclicPermutationGroup, $C_n$ of order $n$ 

 

-- DiCyclicGroup, nonabelian groups of order `4m` with a unique element of order 2 

 

-- TransitiveGroup, $n^{th}$ transitive group of degree $d$ 

from the GAP tables of transitive groups (requires 

the "optional" package database_gap) 

 

-- TransitiveGroups(d), TransitiveGroups(), set of all of the above 

 

-- PrimitiveGroup, $n^{th}$ primitive group of degree $d$ 

from the GAP tables of primitive groups (requires 

the "optional" package database_gap) 

 

-- PrimitiveGroups(d), PrimitiveGroups(), set of all of the above 

 

-- MathieuGroup(degree), Mathieu group of degree 9, 10, 11, 12, 21, 22, 23, or 24. 

 

-- KleinFourGroup, subgroup of $S_4$ of order $4$ which is not $C_2 \times C_2$ 

 

-- QuaternionGroup, non-abelian group of order `8`, `\{\pm 1, \pm I, \pm J, \pm K\}` 

 

-- SplitMetacyclicGroup, nonabelian groups of order `p^m` with cyclic 

subgroups of index p 

 

-- SemidihedralGroup, nonabelian 2-groups with cyclic subgroups of index 2 

 

-- PGL(n,q), projective general linear group of $n\times n$ matrices over 

the finite field GF(q) 

 

-- PSL(n,q), projective special linear group of $n\times n$ matrices over 

the finite field GF(q) 

 

-- PSp(2n,q), projective symplectic linear group of $2n\times 2n$ matrices 

over the finite field GF(q) 

 

-- PSU(n,q), projective special unitary group of $n \times n$ matrices having 

coefficients in the finite field $GF(q^2)$ that respect a 

fixed nondegenerate sesquilinear form, of determinant 1. 

 

-- PGU(n,q), projective general unitary group of $n\times n$ matrices having 

coefficients in the finite field $GF(q^2)$ that respect a 

fixed nondegenerate sesquilinear form, modulo the centre. 

 

-- SuzukiGroup(q), Suzuki group over GF(q), $^2 B_2(2^{2k+1}) = Sz(2^{2k+1})$. 

 

 

AUTHOR: 

- David Joyner (2007-06): split from permgp.py (suggested by Nick Alexander) 

 

REFERENCES: 

Cameron, P., Permutation Groups. New York: Cambridge University Press, 1999. 

Wielandt, H., Finite Permutation Groups. New York: Academic Press, 1964. 

Dixon, J. and Mortimer, B., Permutation Groups, Springer-Verlag, Berlin/New York, 1996. 

 

NOTE: 

Though Suzuki groups are okay, Ree groups should *not* be wrapped as 

permutation groups - the construction is too slow - unless (for 

small values or the parameter) they are made using explicit generators. 

""" 

 

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

# Copyright (C) 2006 William Stein <wstein@gmail.com> 

# David Joyner <wdjoyner@gmail.com> 

# 

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

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

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

from __future__ import print_function 

from six.moves import range 

 

from sage.rings.all import Integer 

from sage.interfaces.all import gap 

from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF 

from sage.arith.all import factor, valuation 

from sage.groups.abelian_gps.abelian_group import AbelianGroup 

from sage.misc.functional import is_even 

from sage.misc.cachefunc import cached_method, weak_cached_function 

from sage.groups.perm_gps.permgroup import PermutationGroup_generic 

from sage.groups.perm_gps.permgroup_element import SymmetricGroupElement 

from sage.structure.unique_representation import CachedRepresentation 

from sage.structure.parent import Parent 

from sage.structure.richcmp import richcmp 

from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 

from sage.sets.finite_enumerated_set import FiniteEnumeratedSet 

from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets 

from sage.sets.non_negative_integers import NonNegativeIntegers 

from sage.sets.family import Family 

from sage.sets.primes import Primes 

 

 

class PermutationGroup_unique(CachedRepresentation, PermutationGroup_generic): 

""" 

.. TODO:: 

 

Fix the broken hash. :: 

 

sage: G = SymmetricGroup(6) 

sage: G3 = G.subgroup([G((1,2,3,4,5,6)),G((1,2))]) 

sage: hash(G) == hash(G3) # todo: Should be True! 

False 

""" 

@weak_cached_function 

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

""" 

This makes sure that domain is a FiniteEnumeratedSet before it gets passed 

on to the __init__ method. 

 

EXAMPLES:: 

 

sage: SymmetricGroup(['a','b']).domain() #indirect doctest 

{'a', 'b'} 

""" 

domain = kwds.pop('domain', None) 

if domain is not None: 

if domain not in FiniteEnumeratedSets(): 

domain = FiniteEnumeratedSet(domain) 

kwds['domain'] = domain 

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

 

def __eq__(self, other): 

""" 

EXAMPLES:: 

 

sage: G = SymmetricGroup(6) 

sage: G3 = G.subgroup([G((1,2,3,4,5,6)),G((1,2))]) 

sage: G == G3 

True 

 

.. WARNING:: 

 

The hash currently is broken for this comparison. 

""" 

return super(CachedRepresentation, self).__eq__(other) 

 

 

class PermutationGroup_symalt(PermutationGroup_unique): 

""" 

This is a class used to factor out some of the commonality 

in the SymmetricGroup and AlternatingGroup classes. 

""" 

 

@staticmethod 

def __classcall__(cls, domain): 

""" 

Normalizes the input of the constructor into a set 

 

INPUT: 

 

- ``n`` -- an integer or list or tuple thereof 

 

Calls the constructor with a tuple representing the set. 

 

EXAMPLES:: 

 

sage: S1 = SymmetricGroup(4) 

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

sage: S3 = SymmetricGroup((1,2,3,4)) 

sage: S1 is S2 

True 

sage: S1 is S3 

True 

 

TESTS:: 

 

sage: SymmetricGroup(0) 

Symmetric group of order 0! as a permutation group 

sage: SymmetricGroup(1) 

Symmetric group of order 1! as a permutation group 

sage: SymmetricGroup(-1) 

Traceback (most recent call last): 

... 

ValueError: domain (=-1) must be an integer >= 0 or a list 

""" 

if domain not in FiniteEnumeratedSets(): 

if not isinstance(domain, (tuple, list, range)): 

try: 

domain = Integer(domain) 

except TypeError: 

raise TypeError("domain (={}) must be an integer >= 0 or a finite set (but domain has type {})".format(domain, type(domain))) 

 

if domain < 0: 

raise ValueError("domain (={}) must be an integer >= 0 or a list".format(domain)) 

domain = list(range(1, domain+1)) 

v = FiniteEnumeratedSet(domain) 

else: 

v = domain 

 

return super(PermutationGroup_symalt, cls).__classcall__(cls, domain=v) 

 

 

class SymmetricGroup(PermutationGroup_symalt): 

r""" 

The full symmetric group of order `n!`, as a permutation group. 

 

If `n` is a list or tuple of positive integers then it returns the 

symmetric group of the associated set. 

 

INPUT: 

 

- ``n`` -- a positive integer, or list or tuple thereof 

 

.. NOTE:: 

 

This group is also available via ``groups.permutation.Symmetric()``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(8) 

sage: G.order() 

40320 

sage: G 

Symmetric group of order 8! as a permutation group 

sage: G.degree() 

8 

sage: S8 = SymmetricGroup(8) 

sage: G = SymmetricGroup([1,2,4,5]) 

sage: G 

Symmetric group of order 4! as a permutation group 

sage: G.domain() 

{1, 2, 4, 5} 

sage: G = SymmetricGroup(4) 

sage: G 

Symmetric group of order 4! as a permutation group 

sage: G.domain() 

{1, 2, 3, 4} 

sage: G.category() 

Join of Category of finite enumerated permutation groups 

and Category of finite weyl groups 

 

TESTS:: 

 

sage: groups.permutation.Symmetric(4) 

Symmetric group of order 4! as a permutation group 

""" 

def __init__(self, domain=None): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: TestSuite(SymmetricGroup(0)).run() 

sage: TestSuite(SymmetricGroup(1)).run() 

sage: TestSuite(SymmetricGroup(3)).run() 

""" 

from sage.categories.finite_weyl_groups import FiniteWeylGroups 

from sage.categories.finite_permutation_groups import FinitePermutationGroups 

from sage.categories.category import Category 

 

#Note that we skip the call to the superclass initializer in order to 

#avoid infinite recursion since SymmetricGroup is called by 

#PermutationGroupElement 

cat = Category.join([FinitePermutationGroups(), FiniteWeylGroups()]) 

super(PermutationGroup_generic, self).__init__(category=cat) 

 

self._domain = domain 

self._deg = len(self._domain) 

self._domain_to_gap = {key: i+1 for i, key in enumerate(self._domain)} 

self._domain_from_gap = {i+1: key for i, key in enumerate(self._domain)} 

 

#Create the generators for the symmetric group 

gens = [tuple(self._domain)] 

if len(self._domain) > 2: 

gens.append(tuple(self._domain[:2])) 

self._gens = [self._element_class()(g, self, check=False) 

for g in gens] 

 

def _gap_init_(self, gap=None): 

""" 

Return the string used to create this group in GAP. 

 

EXAMPLES:: 

 

sage: S = SymmetricGroup(3) 

sage: S._gap_init_() 

'SymmetricGroup(3)' 

sage: S = SymmetricGroup(['a', 'b', 'c']) 

sage: S._gap_init_() 

'SymmetricGroup(3)' 

""" 

return 'SymmetricGroup({})'.format(self.degree()) 

 

@cached_method 

def index_set(self): 

""" 

Return the index set for the descents of the symmetric group ``self``. 

 

EXAMPLES:: 

 

sage: S8 = SymmetricGroup(8) 

sage: S8.index_set() 

(1, 2, 3, 4, 5, 6, 7) 

 

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

sage: S.index_set() 

(3, 1, 4) 

""" 

return tuple(self.domain()[:-1]) 

 

def __richcmp__(self, x, op): 

""" 

Fast comparison for SymmetricGroups. 

 

EXAMPLES:: 

 

sage: S8 = SymmetricGroup(8) 

sage: S3 = SymmetricGroup(3) 

sage: S8 > S3 

True 

""" 

if isinstance(x, SymmetricGroup): 

return richcmp((self._deg, self._domain), (x._deg, x._domain), op) 

return super(SymmetricGroup, self).__richcmp__(x, op) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: A = SymmetricGroup([2,3,7]); A 

Symmetric group of order 3! as a permutation group 

""" 

return "Symmetric group of order {}! as a permutation group".format(self.degree()) 

 

def cartan_type(self): 

r""" 

Return the Cartan type of ``self`` 

 

The symmetric group `S_n` is a Coxeter group of type `A_{n-1}`. 

 

EXAMPLES:: 

 

sage: A = SymmetricGroup([2,3,7]); A.cartan_type() 

['A', 2] 

 

sage: A = SymmetricGroup([]); A.cartan_type() 

['A', 0] 

""" 

from sage.combinat.root_system.cartan_type import CartanType 

return CartanType(['A', max(self.degree() - 1,0)]) 

 

def coxeter_matrix(self): 

r""" 

Return the Coxeter matrix of ``self``. 

 

EXAMPLES:: 

 

sage: A = SymmetricGroup([2,3,7,'a']); A.coxeter_matrix() 

[1 3 2] 

[3 1 3] 

[2 3 1] 

""" 

return self.cartan_type().coxeter_matrix() 

 

def simple_reflection(self, i): 

r""" 

For `i` in the index set of ``self``, this returns the 

elementary transposition `s_i = (i,i+1)`. 

 

EXAMPLES:: 

 

sage: A = SymmetricGroup(5) 

sage: A.simple_reflection(3) 

(3,4) 

 

sage: A = SymmetricGroup([2,3,7]) 

sage: A.simple_reflections() 

Finite family {2: (2,3), 3: (3,7)} 

""" 

return self([(i, self._domain[self._domain.index(i)+1])], check=False) 

 

def reflections(self): 

""" 

Return the list of all reflections in ``self``. 

 

EXAMPLES:: 

 

sage: A = SymmetricGroup(3) 

sage: A.reflections() 

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

""" 

from itertools import combinations 

dom = self._domain 

return [self([(i, j)], check=False) for i, j in combinations(dom, 2)] 

 

def young_subgroup(self, comp): 

""" 

Return the Young subgroup associated with the composition ``comp``. 

 

EXAMPLES:: 

 

sage: S = SymmetricGroup(8) 

sage: c = Composition([2,2,2,2]) 

sage: S.young_subgroup(c) 

Subgroup of (Symmetric group of order 8! as a permutation group) 

generated by [(7,8), (5,6), (3,4), (1,2)] 

 

sage: S = SymmetricGroup(['a','b','c']) 

sage: S.young_subgroup([2,1]) 

Subgroup of (Symmetric group of order 3! as a permutation group) 

generated by [('a','b')] 

 

sage: Y = S.young_subgroup([2,2,2,2,2]) 

Traceback (most recent call last): 

... 

ValueError: The composition is not of expected size 

""" 

if sum(comp) != self.degree(): 

raise ValueError('The composition is not of expected size') 

 

domain = self._domain 

gens = [] 

pos = 0 

for c in comp: 

for i in range(c - 1): 

gens.append(self((domain[pos + i], domain[pos + i + 1]))) 

pos += c 

 

return self.subgroup(gens) 

 

def major_index(self, parameter=None): 

r""" 

Return the *major index generating polynomial* of ``self``, 

which is a gadget counting the elements of ``self`` by major 

index. 

 

INPUT: 

 

- ``parameter`` -- an element of a ring; the result is 

more explicit with a formal variable (default: 

element ``q`` of Univariate Polynomial Ring in ``q`` over 

Integer Ring) 

 

.. MATH:: 

 

P(q) = \sum_{g\in S_n} q^{ \operatorname{major\ index}(g) } 

 

EXAMPLES:: 

 

sage: S4 = SymmetricGroup(4) 

sage: S4.major_index() 

q^6 + 3*q^5 + 5*q^4 + 6*q^3 + 5*q^2 + 3*q + 1 

sage: K.<t> = QQ[] 

sage: S4.major_index(t) 

t^6 + 3*t^5 + 5*t^4 + 6*t^3 + 5*t^2 + 3*t + 1 

""" 

from sage.combinat.q_analogues import q_factorial 

return q_factorial(self.degree(), parameter) 

 

def conjugacy_classes_representatives(self): 

""" 

Return a complete list of representatives of conjugacy classes in 

a permutation group `G`. 

 

Let `S_n` be the symmetric group on `n` letters. The conjugacy 

classes are indexed by partitions `\lambda` of `n`. The ordering 

of the conjugacy classes is reverse lexicographic order of 

the partitions. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(5) 

sage: G.conjugacy_classes_representatives() 

[(), (1,2), (1,2)(3,4), (1,2,3), (1,2,3)(4,5), 

(1,2,3,4), (1,2,3,4,5)] 

 

:: 

 

sage: S = SymmetricGroup(['a','b','c']) 

sage: S.conjugacy_classes_representatives() 

[(), ('a','b'), ('a','b','c')] 

 

TESTS: 

 

Check some border cases:: 

 

sage: S = SymmetricGroup(0) 

sage: S.conjugacy_classes_representatives() 

[()] 

sage: S = SymmetricGroup(1) 

sage: S.conjugacy_classes_representatives() 

[()] 

""" 

from sage.combinat.partition import Partitions_n 

from sage.groups.perm_gps.symgp_conjugacy_class import default_representative 

n = len(self.domain()) 

return [ default_representative(la, self) 

for la in reversed(Partitions_n(n)) ] 

 

def conjugacy_classes_iterator(self): 

""" 

Iterate over the conjugacy classes of ``self``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(5) 

sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() 

True 

""" 

from sage.combinat.partition import Partitions_n 

from sage.groups.perm_gps.symgp_conjugacy_class import SymmetricGroupConjugacyClass 

P = Partitions_n(len(self.domain())) 

for la in reversed(P): 

yield SymmetricGroupConjugacyClass(self, la) 

 

def conjugacy_classes(self): 

""" 

Return a list of the conjugacy classes of ``self``. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(5) 

sage: G.conjugacy_classes() 

[Conjugacy class of cycle type [1, 1, 1, 1, 1] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [2, 1, 1, 1] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [2, 2, 1] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [3, 1, 1] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [3, 2] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [4, 1] in 

Symmetric group of order 5! as a permutation group, 

Conjugacy class of cycle type [5] in 

Symmetric group of order 5! as a permutation group] 

""" 

return list(self.conjugacy_classes_iterator()) 

 

def conjugacy_class(self, g): 

r""" 

Return the conjugacy class of ``g`` inside the symmetric 

group ``self``. 

 

INPUT: 

 

- ``g`` -- a partition or an element of the symmetric group ``self`` 

 

OUTPUT: 

 

A conjugacy class of a symmetric group. 

 

EXAMPLES:: 

 

sage: G = SymmetricGroup(5) 

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

sage: G.conjugacy_class(g) 

Conjugacy class of cycle type [4, 1] in 

Symmetric group of order 5! as a permutation group 

""" 

from sage.groups.perm_gps.symgp_conjugacy_class import SymmetricGroupConjugacyClass 

return SymmetricGroupConjugacyClass(self, g) 

 

def algebra(self, base_ring, category=None): 

""" 

Return the symmetric group algebra associated to ``self``. 

 

INPUT: 

 

- ``base_ring`` -- a ring 

- ``category`` -- a category (default: the category of ``self``) 

 

If ``self`` is the symmetric group on `1,\ldots,n`, then this 

is special cased to take advantage of the features in 

:class:`SymmetricGroupAlgebra`. Otherwise the usual group 

algebra is returned. 

 

EXAMPLES:: 

 

sage: S4 = SymmetricGroup(4) 

sage: S4.algebra(QQ) 

Symmetric group algebra of order 4 over Rational Field 

 

sage: S3 = SymmetricGroup([1,2,3]) 

sage: A = S3.algebra(QQ); A 

Symmetric group algebra of order 3 over Rational Field 

sage: a = S3.an_element(); a 

(1,2,3) 

sage: A(a) 

(1,2,3) 

 

We illustrate the choice of the category:: 

 

sage: A.category() 

Join of Category of coxeter group algebras over Rational Field 

and Category of finite group algebras over Rational Field 

sage: A = S3.algebra(QQ, category=Semigroups()) 

sage: A.category() 

Category of finite dimensional semigroup algebras over Rational Field 

 

In the following case, a usual group algebra is returned: 

 

sage: S = SymmetricGroup([2,3,5]) 

sage: S.algebra(QQ) 

Algebra of Symmetric group of order 3! as a permutation group over Rational Field 

sage: a = S.an_element(); a 

(2,3,5) 

sage: S.algebra(QQ)(a) 

(2,3,5) 

""" 

from sage.combinat.symmetric_group_algebra import SymmetricGroupAlgebra 

domain = self.domain() 

if list(domain) == list(range(1, len(domain) + 1)): 

return SymmetricGroupAlgebra(base_ring, self, category=category) 

else: 

return super(SymmetricGroup, self).algebra(base_ring) 

 

def _element_class(self): 

r""" 

Return the class to be used for creating elements of this group. 

 

EXAMPLES:: 

 

sage: SymmetricGroup(17)._element_class() 

<type 'sage.groups.perm_gps.permgroup_element.SymmetricGroupElement'> 

""" 

return SymmetricGroupElement 

 

class AlternatingGroup(PermutationGroup_symalt): 

def __init__(self, domain=None): 

""" 

The alternating group of order $n!/2$, as a permutation group. 

 

INPUT: 

 

- ``n`` -- a positive integer, or list or tuple thereof 

 

.. note:: 

 

This group is also available via ``groups.permutation.Alternating()``. 

 

EXAMPLES:: 

 

sage: G = AlternatingGroup(6) 

sage: G.order() 

360 

sage: G 

Alternating group of order 6!/2 as a permutation group 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() # long time 

 

sage: G = AlternatingGroup([1,2,4,5]) 

sage: G 

Alternating group of order 4!/2 as a permutation group 

sage: G.domain() 

{1, 2, 4, 5} 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() 

 

TESTS:: 

 

sage: groups.permutation.Alternating(6) 

Alternating group of order 6!/2 as a permutation group 

""" 

PermutationGroup_symalt.__init__(self, gap_group='AlternatingGroup(%s)'%len(domain), domain=domain) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: A = AlternatingGroup([2,3,7]); A 

Alternating group of order 3!/2 as a permutation group 

""" 

return "Alternating group of order %s!/2 as a permutation group"%self.degree() 

 

def _gap_init_(self, gap=None): 

""" 

Returns the string used to create this group in GAP. 

 

EXAMPLES:: 

 

sage: A = AlternatingGroup(3) 

sage: A._gap_init_() 

'AlternatingGroup(3)' 

sage: A = AlternatingGroup(['a', 'b', 'c']) 

sage: A._gap_init_() 

'AlternatingGroup(3)' 

""" 

return 'AlternatingGroup(%s)'%(self.degree()) 

 

class CyclicPermutationGroup(PermutationGroup_unique): 

def __init__(self, n): 

""" 

A cyclic group of order n, as a permutation group. 

 

INPUT: 

 

n -- a positive integer 

 

.. note:: 

 

This group is also available via ``groups.permutation.Cyclic()``. 

 

EXAMPLES:: 

 

sage: G = CyclicPermutationGroup(8) 

sage: G.order() 

8 

sage: G 

Cyclic group of order 8 as a permutation group 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() 

sage: C = CyclicPermutationGroup(10) 

sage: C.is_abelian() 

True 

sage: C = CyclicPermutationGroup(10) 

sage: C.as_AbelianGroup() 

Multiplicative Abelian group isomorphic to C2 x C5 

 

TESTS:: 

 

sage: groups.permutation.Cyclic(6) 

Cyclic group of order 6 as a permutation group 

""" 

n = Integer(n) 

if n < 1: 

raise ValueError("n (=%s) must be >= 1" % n) 

gens = tuple(range(1, n+1)) 

PermutationGroup_generic.__init__(self, [gens], n) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: CyclicPermutationGroup(8) 

Cyclic group of order 8 as a permutation group 

""" 

return "Cyclic group of order %s as a permutation group"%self.order() 

 

def is_commutative(self): 

""" 

Return True if this group is commutative. 

 

EXAMPLES:: 

 

sage: C = CyclicPermutationGroup(8) 

sage: C.is_commutative() 

True 

""" 

return True 

 

def is_abelian(self): 

""" 

Return True if this group is abelian. 

 

EXAMPLES:: 

 

sage: C = CyclicPermutationGroup(8) 

sage: C.is_abelian() 

True 

""" 

return True 

 

def as_AbelianGroup(self): 

""" 

Returns the corresponding Abelian Group instance. 

 

EXAMPLES:: 

 

sage: C = CyclicPermutationGroup(8) 

sage: C.as_AbelianGroup() 

Multiplicative Abelian group isomorphic to C8 

""" 

n = self.order() 

a = list(factor(n)) 

invs = [x[0]**x[1] for x in a] 

G = AbelianGroup(len(a), invs) 

return G 

 

 

class DiCyclicGroup(PermutationGroup_unique): 

r""" 

The dicyclic group of order `4n`, for `n\geq 2`. 

 

INPUT: 

 

- n -- a positive integer, two or greater 

 

OUTPUT: 

 

This is a nonabelian group similar in some respects to the 

dihedral group of the same order, but with far fewer 

elements of order 2 (it has just one). The permutation 

representation constructed here is based on the presentation 

 

.. MATH:: 

 

\langle a, x\mid a^{2n}=1, x^{2}=a^{n}, x^{-1}ax=a^{-1}\rangle 

 

For `n=2` this is the group of quaternions 

(`{\pm 1, \pm I,\pm J, \pm K}`), which is the nonabelian 

group of order 8 that is not the dihedral group `D_4`, 

the symmetries of a square. For `n=3` this is the nonabelian 

group of order 12 that is not the dihedral group `D_6` 

nor the alternating group `A_4`. This group of order 12 is 

also the semi-direct product of `C_2` by `C_4`, 

`C_3\rtimes C_4`. [Con]_ 

 

 

When the order of the group is a 

power of 2 it is known as a "generalized quaternion group." 

 

IMPLEMENTATION: 

 

The presentation above means every element can be written as 

`a^{i}x^{j}` with `0\leq i<2n`, `j=0,1`. We code `a^i` as the symbol 

`i+1` and code `a^{i}x` as the symbol `2n+i+1`. The two generators 

are then represented using a left regular representation. 

 

.. note:: 

 

This group is also available via ``groups.permutation.DiCyclic()``. 

 

EXAMPLES: 

 

A dicyclic group of order 384, with a large power of 2 as a divisor:: 

 

sage: n = 3*2^5 

sage: G = DiCyclicGroup(n) 

sage: G.order() 

384 

sage: a = G.gen(0) 

sage: x = G.gen(1) 

sage: a^(2*n) 

() 

sage: a^n==x^2 

True 

sage: x^-1*a*x==a^-1 

True 

 

A large generalized quaternion group (order is a power of 2):: 

 

sage: n = 2^10 

sage: G=DiCyclicGroup(n) 

sage: G.order() 

4096 

sage: a = G.gen(0) 

sage: x = G.gen(1) 

sage: a^(2*n) 

() 

sage: a^n==x^2 

True 

sage: x^-1*a*x==a^-1 

True 

 

Just like the dihedral group, the dicyclic group has 

an element whose order is half the order of the group. 

Unlike the dihedral group, the dicyclic group has only 

one element of order 2. Like the dihedral groups of 

even order, the center of the dicyclic group is a 

subgroup of order 2 (thus has the unique element of 

order 2 as its non-identity element). :: 

 

sage: G=DiCyclicGroup(3*5*4) 

sage: G.order() 

240 

sage: two = [g for g in G if g.order()==2]; two 

[(1,5)(2,6)(3,7)(4,8)(9,13)(10,14)(11,15)(12,16)] 

sage: G.center().order() 

2 

 

For small orders, we check this is really a group 

we do not have in Sage otherwise. :: 

 

sage: G = DiCyclicGroup(2) 

sage: H = DihedralGroup(4) 

sage: G.is_isomorphic(H) 

False 

sage: G = DiCyclicGroup(3) 

sage: H = DihedralGroup(6) 

sage: K = AlternatingGroup(6) 

sage: G.is_isomorphic(H) or G.is_isomorphic(K) 

False 

 

TESTS:: 

 

sage: groups.permutation.DiCyclic(6) 

Diyclic group of order 24 as a permutation group 

 

AUTHOR: 

 

- Rob Beezer (2009-10-18) 

""" 

def __init__(self, n): 

r""" 

The dicyclic group of order `4*n`, as a permutation group. 

 

INPUT: 

 

n -- a positive integer, two or greater 

 

EXAMPLES:: 

 

sage: G = DiCyclicGroup(3*8) 

sage: G.order() 

96 

sage: TestSuite(G).run() 

""" 

n = Integer(n) 

if n < 2: 

raise ValueError("n (=%s) must be 2 or greater" % n) 

 

# Certainly 2^2 is part of the first factor of the order 

# r is maximum power of 2 in the order 

# m is the rest, the odd part 

order = 4*n 

factored = order.factor() 

r = factored[0][0]**factored[0][1] 

m = order//r 

halfr, fourthr = r//2, r//4 

 

# Representation of a 

# Two cycles of length halfr 

a = [tuple(range(1, halfr+1)), tuple(range(halfr+1, r+1))] 

# With an odd part, a cycle of length m will give the right order for a 

if m > 1: 

a.append( tuple(range(r+1, r+m+1)) ) 

 

# Representation of x 

# Four-cycles that will conjugate the generator a properly 

x = [(i+1, (-i)%halfr + halfr + 1, (fourthr+i)%halfr + 1, (-fourthr-i)%halfr + halfr + 1) 

for i in range(0, fourthr)] 

# With an odd part, transpositions will conjugate the m-cycle to create inverse 

if m > 1: 

x += [(r+i+1, r+m-i) for i in range(0, (m-1)//2)] 

 

PermutationGroup_generic.__init__(self, gens=[a, x]) 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: DiCyclicGroup(12) 

Diyclic group of order 48 as a permutation group 

""" 

return "Diyclic group of order %s as a permutation group"%self.order() 

 

def is_commutative(self): 

r""" 

Return True if this group is commutative. 

 

EXAMPLES:: 

 

sage: D = DiCyclicGroup(12) 

sage: D.is_commutative() 

False 

""" 

return False 

 

def is_abelian(self): 

r""" 

Return True if this group is abelian. 

 

EXAMPLES:: 

 

sage: D = DiCyclicGroup(12) 

sage: D.is_abelian() 

False 

""" 

return False 

 

class KleinFourGroup(PermutationGroup_unique): 

def __init__(self): 

r""" 

The Klein 4 Group, which has order $4$ and exponent $2$, viewed 

as a subgroup of $S_4$. 

 

OUTPUT: 

 

the Klein 4 group of order 4, as a permutation group of degree 4. 

 

.. note:: 

 

This group is also available via ``groups.permutation.KleinFour()``. 

 

EXAMPLES:: 

 

sage: G = KleinFourGroup(); G 

The Klein 4 group of order 4, as a permutation group 

sage: sorted(G) 

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

 

TESTS:: 

 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() 

 

sage: groups.permutation.KleinFour() 

The Klein 4 group of order 4, as a permutation group 

 

AUTHOR: 

-- Bobby Moretti (2006-10) 

""" 

gens = [(1,2),(3,4)] 

PermutationGroup_generic.__init__(self, gens) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = KleinFourGroup(); G 

The Klein 4 group of order 4, as a permutation group 

""" 

return 'The Klein 4 group of order 4, as a permutation group' 

 

class JankoGroup(PermutationGroup_unique): 

def __init__(self, n): 

r""" 

Janko Groups `J1, J2`, and `J3`. 

(Note that `J4` is too big to be treated here.) 

 

INPUT: 

 

- ``n`` -- an integer among `\{1,2,3\}`. 

 

EXAMPLES:: 

 

sage: G = groups.permutation.Janko(1); G # optional - gap_packages internet 

Janko group J1 of order 175560 as a permutation group 

 

TESTS:: 

 

sage: G.category() # optional - gap_packages internet 

Category of finite permutation groups 

sage: TestSuite(G).run(skip=["_test_enumerated_set_contains", "_test_enumerated_set_iter_list"]) # optional - gap_packages internet 

""" 

from sage.interfaces.gap import gap 

if n not in [1,2,3]: 

raise ValueError("n must belong to {1,2,3}.") 

self._n = n 

gap.load_package("atlasrep") 

id = 'AtlasGroup("J%s")'%n 

PermutationGroup_generic.__init__(self, gap_group=id) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = groups.permutation.Janko(1); G # optional - gap_packages internet 

Janko group J1 of order 175560 as a permutation group 

""" 

return "Janko group J%s of order %s as a permutation group"%(self._n,self.order()) 

 

class SuzukiSporadicGroup(PermutationGroup_unique): 

def __init__(self): 

r""" 

Suzuki Sporadic Group 

 

EXAMPLES:: 

 

sage: G = groups.permutation.SuzukiSporadic(); G # optional - gap_packages internet 

Sporadic Suzuki group acting on 1782 points 

 

TESTS:: 

 

sage: G.category() # optional - gap_packages internet 

Category of finite permutation groups 

sage: TestSuite(G).run(skip=["_test_enumerated_set_contains", "_test_enumerated_set_iter_list"]) # optional - gap_packages internet 

""" 

gap.load_package("atlasrep") 

PermutationGroup_generic.__init__(self, gap_group='AtlasGroup("Suz")') 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = groups.permutation.SuzukiSporadic(); G # optional - gap_packages internet 

Sporadic Suzuki group acting on 1782 points 

""" 

return "Sporadic Suzuki group acting on 1782 points" 

 

class QuaternionGroup(DiCyclicGroup): 

r""" 

The quaternion group of order 8. 

 

OUTPUT: 

 

The quaternion group of order 8, as a permutation group. 

See the ``DiCyclicGroup`` class for a generalization of this 

construction. 

 

.. note:: 

 

This group is also available via ``groups.permutation.Quaternion()``. 

 

EXAMPLES: 

 

The quaternion group is one of two non-abelian groups of order 8, 

the other being the dihedral group `D_4`. One way to describe this 

group is with three generators, `I, J, K`, so the whole group is 

then given as the set `\{\pm 1, \pm I, \pm J, \pm K\}` with relations 

such as `I^2=J^2=K^2=-1`, `IJ=K` and `JI=-K`. 

 

The examples below illustrate how to use this group in a similar 

manner, by testing some of these relations. The representation used 

here is the left-regular representation. :: 

 

sage: Q = QuaternionGroup() 

sage: I = Q.gen(0) 

sage: J = Q.gen(1) 

sage: K = I*J 

sage: [I,J,K] 

[(1,2,3,4)(5,6,7,8), (1,5,3,7)(2,8,4,6), (1,8,3,6)(2,7,4,5)] 

sage: neg_one = I^2; neg_one 

(1,3)(2,4)(5,7)(6,8) 

sage: J^2 == neg_one and K^2 == neg_one 

True 

sage: J*I == neg_one*K 

True 

sage: Q.center().order() == 2 

True 

sage: neg_one in Q.center() 

True 

 

TESTS:: 

 

sage: groups.permutation.Quaternion() 

Quaternion group of order 8 as a permutation group 

 

AUTHOR: 

 

- Rob Beezer (2009-10-09) 

""" 

def __init__(self): 

r""" 

TESTS:: 

 

sage: Q = QuaternionGroup() 

sage: TestSuite(Q).run() 

""" 

DiCyclicGroup.__init__(self, 2) 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: Q=QuaternionGroup(); Q 

Quaternion group of order 8 as a permutation group 

""" 

return "Quaternion group of order 8 as a permutation group" 

 

class GeneralDihedralGroup(PermutationGroup_generic): 

r""" 

The Generalized Dihedral Group generated by the abelian group with 

direct factors in the input list. 

 

INPUT: 

 

- ``factors`` - a list of the sizes of the cyclic factors of the 

abelian group being dihedralized (this will be sorted once 

entered) 

 

OUTPUT: 

 

For a given abelian group (noting that each finite abelian group 

can be represented as the direct product of cyclic groups), the 

General Dihedral Group it generates is simply the semi-direct 

product of the given group with `C_2`, where the nonidentity 

element of `C_2` acts on the abelian group by turning each element 

into its inverse. In this implementation, each input abelian group 

will be standardized so as to act on a minimal amount of letters. 

This will be done by breaking the direct factors into products of 

p-groups, before this new set of factors is ordered from smallest 

to largest for complete standardization. Note that the generalized 

dihedral group corresponding to a cyclic group, `C_n`, is simply 

the dihedral group `D_n`. 

 

EXAMPLES: 

 

As is noted in [TW1980]_, `Dih(C_3 \times C_3)` has the presentation 

 

.. MATH:: 

 

\langle a, b, c\mid a^{3}, b^{3}, c^{2}, ab = ba, ac = ca^{-1}, bc = cb^{-1} \rangle 

 

Note also the fact, verified by [TW1980]_, that the dihedralization of 

`C_3 \times C_3` is the only nonabelian group of order 18 

with no element of order 6. :: 

 

sage: G = GeneralDihedralGroup([3,3]) 

sage: G 

Generalized dihedral group generated by C3 x C3 

sage: G.order() 

18 

sage: G.gens() 

[(4,5,6), (2,3)(5,6), (1,2,3)] 

sage: a = G.gens()[2]; b = G.gens()[0]; c = G.gens()[1] 

sage: a.order() == 3, b.order() == 3, c.order() == 2 

(True, True, True) 

sage: a*b == b*a, a*c == c*a.inverse(), b*c == c*b.inverse() 

(True, True, True) 

sage: G.subgroup([a,b,c]) == G 

True 

sage: G.is_abelian() 

False 

sage: all([x.order() != 6 for x in G]) 

True 

 

If all of the direct factors are `C_2`, then the action turning 

each element into its inverse is trivial, and the semi-direct 

product becomes a direct product. :: 

 

sage: G = GeneralDihedralGroup([2,2,2]) 

sage: G.order() 

16 

sage: G.gens() 

[(7,8), (5,6), (3,4), (1,2)] 

sage: G.is_abelian() 

True 

sage: H = KleinFourGroup() 

sage: G.is_isomorphic(H.direct_product(H)[0]) 

True 

 

If two nonidentical input lists generate isomorphic abelian 

groups, then they will generate identical groups (with each direct 

factor broken up into its prime factors), but they will still have 

distinct descriptions. Note that If `gcd(n,m)=1`, then `C_n \times 

C_m \cong C_{nm}`, while the general dihedral groups 

generated by isomorphic abelian groups should be themselves 

isomorphic. :: 

 

sage: G = GeneralDihedralGroup([6,34,46,14]) 

sage: H = GeneralDihedralGroup([7,17,3,46,2,2,2]) 

sage: G == H, G.gens() == H.gens() 

(True, True) 

sage: [x.order() for x in G.gens()] 

[23, 17, 7, 2, 3, 2, 2, 2, 2] 

sage: G 

Generalized dihedral group generated by C6 x C34 x C46 x C14 

sage: H 

Generalized dihedral group generated by C7 x C17 x C3 x C46 x C2 x C2 x C2 

 

A cyclic input yields a Classical Dihedral Group. :: 

 

sage: G = GeneralDihedralGroup([6]) 

sage: D = DihedralGroup(6) 

sage: G.is_isomorphic(D) 

True 

 

A Generalized Dihedral Group will always have size twice the 

underlying group, be solvable (as it has an abelian subgroup with 

index 2), and, unless the underlying group is of the form 

`{C_2}^n`, be nonabelian (by the structure theorem of finite 

abelian groups and the fact that a semi-direct product is a 

direct product only when the underlying action is trivial). :: 

 

sage: G = GeneralDihedralGroup([6,18,33,60]) 

sage: (6*18*33*60)*2 

427680 

sage: G.order() 

427680 

sage: G.is_solvable() 

True 

sage: G.is_abelian() 

False 

 

TESTS:: 

 

sage: G = GeneralDihedralGroup("foobar") 

Traceback (most recent call last): 

... 

TypeError: factors of abelian group must be a list, not foobar 

 

sage: GeneralDihedralGroup([]) 

Traceback (most recent call last): 

... 

ValueError: there must be at least one direct factor in the abelian group being dihedralized 

 

sage: GeneralDihedralGroup([3, 1.5]) 

Traceback (most recent call last): 

... 

TypeError: the input list must consist of Integers 

 

sage: GeneralDihedralGroup([4, -8]) 

Traceback (most recent call last): 

... 

ValueError: all direct factors must be greater than 1 

 

AUTHOR: 

 

- Kevin Halasz (2012-7-12) 

 

""" 

def __init__(self, factors): 

r""" 

Init method of class <GeneralDihedralGroup>. See the docstring 

for :class:`<GeneralDihedralGroup>`. 

 

EXAMPLES:: 

 

sage: G = GeneralDihedralGroup([5,5,5]) 

sage: G.order() 

250 

sage: TestSuite(G).run() # long time 

""" 

 

 

if not isinstance(factors, list): 

msg = "factors of abelian group must be a list, not {}" 

raise TypeError(msg.format(factors)) 

 

if len(factors) < 1: 

raise ValueError('there must be at least one direct factor in the abelian group being dihedralized') 

 

if not all(isinstance(x, Integer) for x in factors): 

raise TypeError('the input list must consist of Integers') 

 

if not all(x >= 2 for x in factors): 

s = 'all direct factors must be greater than 1' 

raise ValueError(s) 

 

self.factors = factors 

# To get uniform outputs for isomorphic inputs, we break 

# each inputted cyclic group into a direct product of cyclic 

# p-groups 

simplified = sorted([term[0]**term[1] for a in factors for term in a.factor()]) 

 

gens = [] 

# genx is an element of order two that turns each of the 

# generators of the abelian group into its inverse via 

# conjugation 

genx = [] 

jumppoint = Integer(1) 

for a in simplified: 

# create one of the generators for the abelian group 

gens.append([tuple(range(jumppoint, jumppoint+a))]) 

# make contribution to the generator that dihedralizes the 

# abelian group 

for i in range(1, (a//2)+1): 

if i != a-i: 

genx.append(tuple((jumppoint+i, jumppoint+a-i))) 

jumppoint = jumppoint + a 

# If all of the direct factors are C2, then the action turning 

# each element into its inverse is trivial, and the 

# semi-direct product becomes a direct product, so we simply 

# tack on another disjoint transposition 

if all(x==2 for x in simplified): 

genx.append(tuple((jumppoint, jumppoint+1))) 

gens.append(genx) 

PermutationGroup_generic.__init__(self, gens=gens) 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: G = GeneralDihedralGroup([2,4,8]) 

sage: G 

Generalized dihedral group generated by C2 x C4 x C8 

""" 

grouplist = [] 

for n in self.factors: 

grouplist.append('C{}'.format(n)) 

return 'Generalized dihedral group generated by ' + ' x '.join(grouplist) 

 

class DihedralGroup(PermutationGroup_unique): 

def __init__(self, n): 

""" 

The Dihedral group of order `2n` for any integer `n\geq 1`. 

 

INPUT: 

 

- ``n`` -- a positive integer 

 

OUTPUT: 

 

The dihedral group of order `2n`, as a permutation group 

 

.. NOTE:: 

 

This group is also available via ``groups.permutation.Dihedral()``. 

 

EXAMPLES:: 

 

sage: DihedralGroup(1) 

Dihedral group of order 2 as a permutation group 

 

sage: DihedralGroup(2) 

Dihedral group of order 4 as a permutation group 

sage: DihedralGroup(2).gens() 

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

 

sage: DihedralGroup(5).gens() 

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

sage: sorted(DihedralGroup(5)) 

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

 

sage: G = DihedralGroup(6) 

sage: G.order() 

12 

sage: G = DihedralGroup(5) 

sage: G.order() 

10 

sage: G 

Dihedral group of order 10 as a permutation group 

sage: G.gens() 

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

 

sage: DihedralGroup(0) 

Traceback (most recent call last): 

... 

ValueError: n must be positive 

 

TESTS:: 

 

sage: TestSuite(G).run() 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() 

 

sage: groups.permutation.Dihedral(6) 

Dihedral group of order 12 as a permutation group 

""" 

n = Integer(n) 

if n <= 0: 

raise ValueError("n must be positive") 

 

# the first generator generates the cyclic subgroup of D_n, <(1...n)> in 

# cycle notation 

gen0 = range(1, n + 1) 

 

if n < 1: 

raise ValueError("n (=%s) must be >= 1" % n) 

 

# D_1 is a subgroup of S_2, we need the cyclic group of order 2 

if n == 1: 

gens = CyclicPermutationGroup(2).gens() 

elif n == 2: 

gens = ((1,2),(3,4)) 

else: 

gen1 = tuple((i, n-i+1) for i in range(1, n//2 +1)) 

gens = tuple([tuple(gen0), gen1]) 

 

PermutationGroup_generic.__init__(self, gens) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = DihedralGroup(5); G 

Dihedral group of order 10 as a permutation group 

""" 

return "Dihedral group of order %s as a permutation group"%self.order() 

 

 

 

class SplitMetacyclicGroup(PermutationGroup_unique): 

def __init__(self, p, m): 

r""" 

The split metacyclic group of order `p^m`. 

 

INPUT: 

 

- ``p`` -- a prime number that is the prime underlying this 

p-group 

 

- ``m`` -- a positive integer such that the order of this 

group is the `p^m`. Be aware that, for even `p`, `m` must be 

greater than 3, while for odd `p`, `m` must be greater than 

2. 

 

OUTPUT: 

 

The split metacyclic group of order `p^m`. This family of 

groups has presentation 

 

.. MATH:: 

 

\langle x, y\mid x^{p^{m-1}}, y^{p}, y^{-1}xy=x^{1+p^{m-2}} \rangle 

 

This family is notable because, for odd `p`, these are the 

only `p`-groups with a cyclic subgroup of index `p`, a 

result proven in [Gor1980]_. It is also shown in 

[Gor1980]_ that this is one of four families containing 

nonabelian 2-groups with a cyclic subgroup of index 2 

(with the others being the dicyclic groups, the dihedral 

groups, and the semidihedral groups). 

 

EXAMPLES: 

 

Using the last relation in the group's presentation, 

one can see that the elements of the form `y^{i}x`, 

`0 \leq i \leq p-1` all have order `p^{m-1}`, as it can be 

shown that their `p` th powers are all `x^{p^{m-2}+p}`, 

an element with order `p^{m-2}`. Manipulation of the same 

relation shows that none of these elements are powers of 

any other. Thus, there are `p` cyclic maximal subgroups in 

each split metacyclic group. It is also proven in 

[Gor1980]_ that this family has commutator subgroup 

of order `p`, and the Frattini subgroup is equal to the 

center, with this group being cyclic of order `p^{m-2}`. 

These characteristics are necessary to identify these 

groups in the case that `p=2`, although the possession of 

a cyclic maximal subgroup in a non-abelian `p`-group is 

enough for odd `p` given the group's order. :: 

 

sage: G = SplitMetacyclicGroup(2,8) 

sage: G.order() == 2**8 

True 

sage: G.is_abelian() 

False 

sage: len([H for H in G.subgroups() if H.order() == 2^7 and H.is_cyclic()]) 

2 

sage: G.commutator().order() 

2 

sage: G.frattini_subgroup() == G.center() 

True 

sage: G.center().order() == 2^6 

True 

sage: G.center().is_cyclic() 

True 

 

sage: G = SplitMetacyclicGroup(3,3) 

sage: len([H for H in G.subgroups() if H.order() == 3^2 and H.is_cyclic()]) 

3 

sage: G.commutator().order() 

3 

sage: G.frattini_subgroup() == G.center() 

True 

sage: G.center().order() 

3 

 

TESTS:: 

 

sage: G = SplitMetacyclicGroup(3,2.5) 

Traceback (most recent call last): 

... 

TypeError: both p and m must be integers 

 

sage: G = SplitMetacyclicGroup(4,3) 

Traceback (most recent call last): 

... 

ValueError: p must be prime, 4 is not prime 

 

sage: G = SplitMetacyclicGroup(2,2) 

Traceback (most recent call last): 

... 

ValueError: if prime is 2, the exponent must be greater than 3, not 2 

 

sage: G = SplitMetacyclicGroup(11,2) 

Traceback (most recent call last): 

... 

ValueError: if prime is odd, the exponent must be greater than 2, not 2 

 

AUTHOR: 

 

- Kevin Halasz (2012-8-7) 

 

""" 

 

if not isinstance(p, Integer) or not isinstance(m, Integer): 

raise TypeError('both p and m must be integers') 

 

if not p in Primes(): 

raise ValueError('p must be prime, %s is not prime' % p) 

 

if p == 2 and m <= 3: 

raise ValueError('if prime is 2, the exponent must be greater than 3, not %s' % m) 

 

if p%2 == 1 and m <= 2: 

raise ValueError('if prime is odd, the exponent must be greater than 2, not %s' % m) 

 

self.p = p 

self.m = m 

 

# x is created with list, rather than cycle, notation 

x = list(range(2, p ** (m - 1) + 1)) 

x.append(1) 

# y is also created with list notation, where the list 

# used is equivalent to the cycle notation representation of 

# x^(1+p^(m-2)). This technique is inspired by exercise 5.30 

# Judson's "Abstract Algebra" (abstract.pugetsound.edu). 

y = [1] 

point = 1 

for i in range(p**(m-1)-1): 

next = (point + 1 + p**(m-2))%(p**(m-1)) 

if next == 0: 

next = p**(m-1) 

y.append(next) 

point = next 

PermutationGroup_unique.__init__(self, gens = [x,y]) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = SplitMetacyclicGroup(7,4);G 

The split metacyclic group of order 7 ^ 4 

""" 

return 'The split metacyclic group of order %s ^ %s'%(self.p,self.m) 

 

class SemidihedralGroup(PermutationGroup_unique): 

def __init__(self,m): 

r""" 

The semidihedral group of order `2^m`. 

 

INPUT: 

 

- ``m`` - a positive integer; the power of 2 that is the 

group's order 

 

OUTPUT: 

 

The semidihedral group of order `2^m`. These groups can be 

thought of as a semidirect product of `C_{2^{m-1}}` with 

`C_2`, where the nontrivial element of `C_2` is sent to 

the element of the automorphism group of `C_{2^{m-1}}` that 

sends elements to their `-1+2^{m-2}` th power. Thus, the 

group has the presentation: 

 

.. MATH:: 

 

\langle x, y\mid x^{2^{m-1}}, y^{2}, y^{-1}xy=x^{-1+2^{m-2}} \rangle 

 

This family is notable because it is made up of non-abelian 

2-groups that all contain cyclic subgroups of index 2. It 

is one of only four such families. 

 

EXAMPLES: 

 

In [Gor1980]_ it is shown that the semidihedral groups 

have center of order 2. It is also shown that they have a 

Frattini subgroup equal to their commutator, which is a 

cyclic subgroup of order `2^{m-2}`. :: 

 

sage: G = SemidihedralGroup(12) 

sage: G.order() == 2^12 

True 

sage: G.commutator() == G.frattini_subgroup() 

True 

sage: G.commutator().order() == 2^10 

True 

sage: G.commutator().is_cyclic() 

True 

sage: G.center().order() 

2 

 

sage: G = SemidihedralGroup(4) 

sage: len([H for H in G.subgroups() if H.is_cyclic() and H.order() == 8]) 

1 

sage: G.gens() 

[(2,4)(3,7)(6,8), (1,2,3,4,5,6,7,8)] 

sage: x = G.gens()[1]; y = G.gens()[0] 

sage: x.order() == 2^3; y.order() == 2 

True 

True 

sage: y*x*y == x^(-1+2^2) 

True 

 

TESTS:: 

 

sage: G = SemidihedralGroup(4.4) 

Traceback (most recent call last): 

... 

TypeError: m must be an integer, not 4.40000000000000 

 

sage: G = SemidihedralGroup(-5) 

Traceback (most recent call last): 

... 

ValueError: the exponent must be greater than 3, not -5 

 

AUTHOR: 

 

- Kevin Halasz (2012-8-7) 

 

""" 

if not isinstance(m, Integer): 

raise TypeError('m must be an integer, not %s' % m) 

 

if m <= 3: 

raise ValueError('the exponent must be greater than 3, not %s' % m) 

 

self.m = m 

 

# x is created with list, rather than cycle, notation 

x = list(range(2, 2 ** (m - 1) + 1)) 

x.append(1) 

# y is also created with list notation, where the list 

# used is equivalent to the cycle notation representation of 

# x^(1+p^(m-2)). This technique is inspired by exercise 5.30 

# Judson's "Abstract Algebra" (abstract.pugetsound.edu). 

y = [1] 

k = 1 

for i in range(2**(m-1)-1): 

next = (k - 1 + 2**(m-2))%(2**(m-1)) 

if next == 0: 

next = 2**(m-1) 

y.append(next) 

k = next 

PermutationGroup_unique.__init__(self, gens = [x,y]) 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: G = SemidihedralGroup(6); G 

The semidiheral group of order 64 

""" 

return 'The semidiheral group of order %s'%(2**self.m) 

 

class MathieuGroup(PermutationGroup_unique): 

def __init__(self, n): 

""" 

The Mathieu group of degree $n$. 

 

INPUT: 

 

n -- a positive integer in {9, 10, 11, 12, 21, 22, 23, 24}. 

 

OUTPUT: 

 

the Mathieu group of degree n, as a permutation group 

 

.. note:: 

 

This group is also available via ``groups.permutation.Mathieu()``. 

 

EXAMPLES:: 

 

sage: G = MathieuGroup(12) 

sage: G 

Mathieu group of degree 12 and order 95040 as a permutation group 

 

TESTS:: 

 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run(skip=["_test_enumerated_set_contains", "_test_enumerated_set_iter_list"]) 

 

sage: groups.permutation.Mathieu(9) 

Mathieu group of degree 9 and order 72 as a permutation group 

 

Note: this is a fairly big group, so we skip some tests that 

currently require to list all the elements of the group, 

because there is no proper iterator yet. 

""" 

n = Integer(n) 

self._n = n 

if not(n in [9, 10, 11, 12, 21, 22, 23, 24]): 

raise ValueError("argument must belong to {9, 10, 11, 12, 21, 22, 23, 24}.") 

id = 'MathieuGroup(%s)'%n 

PermutationGroup_generic.__init__(self, gap_group=id) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = MathieuGroup(12); G 

Mathieu group of degree 12 and order 95040 as a permutation group 

""" 

return "Mathieu group of degree %s and order %s as a permutation group"%(self._n,self.order()) 

 

class TransitiveGroup(PermutationGroup_unique): 

def __init__(self, d, n): 

""" 

The transitive group from the GAP tables of transitive groups. 

 

INPUT: 

 

- d -- non-negative integer; the degree 

- n -- positive integer; the index of the group in the GAP database, 

starting at 1 

 

OUTPUT: 

 

the n-th transitive group of degree d 

 

.. note:: 

 

This group is also available via ``groups.permutation.Transitive()``. 

 

EXAMPLES:: 

 

sage: TransitiveGroup(0,1) 

Transitive group number 1 of degree 0 

sage: TransitiveGroup(1,1) 

Transitive group number 1 of degree 1 

sage: G = TransitiveGroup(5, 2); G # optional - database_gap 

Transitive group number 2 of degree 5 

sage: G.gens() # optional - database_gap 

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

 

sage: G.category() # optional - database_gap 

Category of finite enumerated permutation groups 

 

.. warning:: this follows GAP's naming convention of indexing 

the transitive groups starting from ``1``:: 

 

sage: TransitiveGroup(5,0) # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,5} 

 

.. warning:: only transitive groups of "small" degree are 

available in GAP's database:: 

 

sage: TransitiveGroup(31,1) # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the transitive groups of order less than 30 are available in GAP's database 

 

TESTS:: 

 

 

sage: groups.permutation.Transitive(1, 1) 

Transitive group number 1 of degree 1 

 

sage: TestSuite(TransitiveGroup(0,1)).run() 

sage: TestSuite(TransitiveGroup(1,1)).run() 

sage: TestSuite(TransitiveGroup(5,2)).run()# optional - database_gap 

 

sage: TransitiveGroup(1,5) # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,1} 

""" 

d = Integer(d) 

n = Integer(n) 

if d < 0: 

raise ValueError("Degree d must not be negative") 

max_n = TransitiveGroups(d).cardinality() 

if n > max_n or n <= 0: 

raise ValueError("Index n must be in {1,..,%s}" % max_n) 

gap_group = 'Group([()])' if d in [0,1] else 'TransitiveGroup(%s,%s)'%(d,n) 

try: 

PermutationGroup_generic.__init__(self, gap_group=gap_group) 

except RuntimeError: 

from sage.misc.misc import verbose 

verbose("Warning: Computing with TransitiveGroups requires the optional database_gap package. Please install it.", level=0) 

 

self._d = d 

self._n = n 

self._domain = list(range(1, d + 1)) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: G = TransitiveGroup(1,1); G 

Transitive group number 1 of degree 1 

""" 

return "Transitive group number %s of degree %s"%(self._n, self._d) 

 

def TransitiveGroups(d=None): 

""" 

INPUT: 

 

- ``d`` -- an integer (optional) 

 

Returns the set of all transitive groups of a given degree 

``d`` up to isomorphisms. If ``d`` is not specified, it returns the set of all 

transitive groups up to isomorphisms. 

 

Warning: TransitiveGroups requires the optional GAP database 

package. Please install it with ``sage -i database_gap``. 

 

EXAMPLES:: 

 

sage: TransitiveGroups(3) 

Transitive Groups of degree 3 

sage: TransitiveGroups(7) 

Transitive Groups of degree 7 

sage: TransitiveGroups(8) 

Transitive Groups of degree 8 

 

sage: TransitiveGroups() 

Transitive Groups 

 

.. warning:: in practice, the database currently only contains 

transitive groups up to degree 30:: 

 

sage: TransitiveGroups(31).cardinality() # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the transitive groups of order less than 30 are available in GAP's database 

 

""" 

if d is None: 

return TransitiveGroupsAll() 

else: 

d = Integer(d) 

if d < 0: 

raise ValueError("A transitive group acts on a non negative integer number of positions") 

return TransitiveGroupsOfDegree(d) 

 

class TransitiveGroupsAll(DisjointUnionEnumeratedSets): 

""" 

The infinite set of all transitive groups up to isomorphisms. 

 

EXAMPLES:: 

 

sage: L = TransitiveGroups(); L 

Transitive Groups 

sage: L.category() 

Category of facade infinite enumerated sets 

sage: L.cardinality() 

+Infinity 

 

sage: p = L.__iter__() # optional - database_gap 

sage: (next(p), next(p), next(p), next(p), next(p), next(p), next(p), next(p)) # optional - database_gap 

(Transitive group number 1 of degree 0, Transitive group number 1 of degree 1, Transitive group number 1 of degree 2, Transitive group number 1 of degree 3, Transitive group number 2 of degree 3, Transitive group number 1 of degree 4, Transitive group number 2 of degree 4, Transitive group number 3 of degree 4) 

 

TESTS: 

 

The following test is broken, see :trac:`22576`:: 

 

sage: TestSuite(TransitiveGroups()).run() # known bug # optional - database_gap # long time 

""" 

def __init__(self): 

""" 

TESTS:: 

 

sage: S = TransitiveGroups() # optional - database_gap 

sage: S.category() # optional - database_gap 

Category of facade infinite enumerated sets 

""" 

DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), lambda i: TransitiveGroups(i)) ) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: TransitiveGroups() # optional - database_gap # indirect doctest 

Transitive Groups 

""" 

return "Transitive Groups" 

 

def __contains__(self, G): 

r""" 

EXAMPLES:: 

 

sage: TransitiveGroup(5,2) in TransitiveGroups() # optional - database_gap 

True 

sage: TransitiveGroup(6,5) in TransitiveGroups() # optional - database_gap 

True 

sage: 1 in TransitiveGroups() # optional - database_gap 

False 

""" 

return isinstance(G,TransitiveGroup) 

 

class TransitiveGroupsOfDegree(CachedRepresentation, Parent): 

""" 

The set of all transitive groups of a given (small) degree up to isomorphisms. 

 

EXAMPLES:: 

 

sage: S = TransitiveGroups(4); S # optional - database_gap 

Transitive Groups of degree 4 

sage: list(S) # optional - database_gap 

[Transitive group number 1 of degree 4, Transitive group number 2 of degree 4, Transitive group number 3 of degree 4, Transitive group number 4 of degree 4, Transitive group number 5 of degree 4] 

 

sage: TransitiveGroups(5).an_element() # optional - database_gap 

Transitive group number 1 of degree 5 

 

We write the cardinality of all transitive groups of degree 5:: 

 

sage: for G in TransitiveGroups(5): # optional - database_gap 

....: print(G.cardinality()) 

5 

10 

20 

60 

120 

 

TESTS:: 

 

sage: TestSuite(TransitiveGroups(3)).run() # optional - database_gap 

 

 

""" 

def __init__(self, n): 

""" 

TESTS:: 

 

sage: S = TransitiveGroups(4) # optional - database_gap 

sage: S.category() # optional - database_gap 

Category of finite enumerated sets 

""" 

self._degree = n 

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

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: TransitiveGroups(6) # optional - database_gap 

Transitive Groups of degree 6 

""" 

return "Transitive Groups of degree %s"%(self._degree) 

 

def __contains__(self, G): 

r""" 

EXAMPLES:: 

 

sage: TransitiveGroup(6,5) in TransitiveGroups(4) # optional - database_gap 

False 

sage: TransitiveGroup(4,3) in TransitiveGroups(4) # optional - database_gap 

True 

sage: 1 in TransitiveGroups(4) # optional - database_gap 

False 

""" 

if isinstance(G,TransitiveGroup): 

return G._d == self._degree 

else: 

False 

 

def __getitem__(self, n): 

r""" 

INPUT: 

 

- ``n`` -- a positive integer 

 

Returns the `n`-th transitive group of a given degree. 

 

EXAMPLES:: 

 

sage: TransitiveGroups(5)[3] # optional - database_gap 

Transitive group number 3 of degree 5 

 

.. warning:: 

 

this follows GAP's naming convention of indexing 

the transitive groups starting from ``1``:: 

 

sage: TransitiveGroups(5)[0] # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,5} 

""" 

return TransitiveGroup(self._degree, n) 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: list(TransitiveGroups(5)) # indirect doctest # optional - database_gap 

[Transitive group number 1 of degree 5, Transitive group number 2 of degree 5, Transitive group number 3 of degree 5, Transitive group number 4 of degree 5, Transitive group number 5 of degree 5] 

""" 

for n in range(1, self.cardinality() + 1): 

yield self[n] 

 

@cached_method 

def cardinality(self): 

r""" 

Returns the cardinality of ``self``, that is the number of 

transitive groups of a given degree. 

 

EXAMPLES:: 

 

sage: TransitiveGroups(0).cardinality() # optional - database_gap 

1 

sage: TransitiveGroups(2).cardinality() # optional - database_gap 

1 

sage: TransitiveGroups(7).cardinality() # optional - database_gap 

7 

sage: TransitiveGroups(12).cardinality() # optional - database_gap 

301 

sage: [TransitiveGroups(i).cardinality() for i in range(11)] # optional - database_gap 

[1, 1, 1, 2, 5, 5, 16, 7, 50, 34, 45] 

 

.. warning:: 

 

The database_gap contains all transitive groups 

up to degree 30:: 

 

sage: TransitiveGroups(31).cardinality() # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the transitive groups of order less than 30 are available in GAP's database 

 

TESTS:: 

 

sage: type(TransitiveGroups(12).cardinality()) # optional - database_gap 

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

sage: type(TransitiveGroups(0).cardinality()) 

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

""" 

# gap.NrTransitiveGroups(0) fails, so Sage needs to handle this 

 

# While we are at it, and since Sage also handles the 

# transitive group of degree 1, we may as well handle 1 

if self._degree <= 1: 

return Integer(1) 

else: 

try: 

return Integer(gap.NrTransitiveGroups(gap(self._degree))) 

except RuntimeError: 

from sage.misc.misc import verbose 

verbose("Warning: TransitiveGroups requires the GAP database package. Please install it with ``sage -i database_gap``.", level=0) 

except TypeError: 

raise NotImplementedError("Only the transitive groups of order less than 30 are available in GAP's database") 

 

class PrimitiveGroup(PermutationGroup_unique): 

""" 

The primitive group from the GAP tables of primitive groups. 

 

INPUT: 

 

- ``d`` -- non-negative integer. the degree of the group. 

 

- ``n`` -- positive integer. the index of the group in the GAP 

database, starting at 1 

 

OUTPUT: 

 

The ``n``-th primitive group of degree ``d``. 

 

EXAMPLES:: 

 

sage: PrimitiveGroup(0,1) 

Trivial group 

sage: PrimitiveGroup(1,1) 

Trivial group 

sage: G = PrimitiveGroup(5, 2); G # optional - database_gap 

D(2*5) 

sage: G.gens() # optional - database_gap 

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

sage: G.category() # optional - database_gap 

Category of finite enumerated permutation groups 

 

.. warning:: 

 

this follows GAP's naming convention of indexing the primitive 

groups starting from ``1``:: 

 

sage: PrimitiveGroup(5,0) # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,5} 

 

Only primitive groups of "small" degree are available in GAP's 

database:: 

 

sage: PrimitiveGroup(2500,1) # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the primitive groups of degree less 

than 2500 are available in GAP's database 

""" 

 

def __init__(self, d, n): 

""" 

The Python constructor. 

 

INPUT/OUTPUT: 

 

See :class:`PrimitiveGroup`. 

 

TESTS:: 

 

sage: TestSuite(PrimitiveGroup(0,1)).run() 

sage: TestSuite(PrimitiveGroup(1,1)).run() 

sage: TestSuite(PrimitiveGroup(5,2)).run() # optional - database_gap 

sage: PrimitiveGroup(6,5) # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,4} 

""" 

d = Integer(d) 

n = Integer(n) 

if d < 0: 

raise ValueError("Degree d must not be negative") 

max_n = PrimitiveGroups(d).cardinality() 

if n > max_n or n <= 0: 

raise ValueError("Index n must be in {1,..,%s}" % max_n) 

if d in [0,1]: 

gap_group = gap.Group("[()]") 

self._pretty_name = "Trivial group" 

else: 

gap_group = gap.PrimitiveGroup(d, n) 

self._pretty_name = gap_group.str() 

try: 

PermutationGroup_generic.__init__(self, gap_group=gap_group) 

except RuntimeError: 

from sage.misc.misc import verbose 

verbose("Warning: Computing with PrimitiveGroups requires the optional database_gap package. Please install it.", level=0) 

 

self._d = d 

self._n = n 

self._domain = list(range(1, d + 1)) 

 

def _repr_(self): 

""" 

Return a string representation. 

 

OUTPUT: 

 

String. 

 

EXAMPLES:: 

 

sage: G = PrimitiveGroup(5,1); G # optional - database_gap 

C(5) 

""" 

return self._pretty_name 

 

def group_primitive_id(self): 

""" 

Return the index of this group in the GAP database of primitive groups. 

 

Requires "optional" database_gap package. 

 

OUTPUT: 

 

A positive integer, following GAP's conventions. 

 

EXAMPLES:: 

 

sage: G = PrimitiveGroup(5,2); G.group_primitive_id() # optional - database_gap 

2 

""" 

return self._n 

 

def PrimitiveGroups(d=None): 

""" 

Return the set of all primitive groups of a given degree ``d`` 

 

INPUT: 

 

- ``d`` -- an integer (optional) 

 

OUTPUT: 

 

The set of all primitive groups of a given degree ``d`` up to 

isomorphisms using GAP. If ``d`` is not specified, it returns the 

set of all primitive groups up to isomorphisms stored in GAP. 

 

.. WARNING:: 

 

PrimitiveGroups requires the optional GAP database package. 

Please install it by running ``sage -i database_gap``. 

 

EXAMPLES:: 

 

sage: PrimitiveGroups(3) 

Primitive Groups of degree 3 

sage: PrimitiveGroups(7) 

Primitive Groups of degree 7 

sage: PrimitiveGroups(8) 

Primitive Groups of degree 8 

sage: PrimitiveGroups() 

Primitive Groups 

 

The database currently only contains primitive groups up to degree 

2499:: 

 

sage: PrimitiveGroups(2500).cardinality() # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the primitive groups of degree less 

than 2500 are available in GAP's database 

 

.. TODO:: 

 

This enumeration helper could be extended based on 

``PrimitiveGroupsIterator`` in GAP. This method allows to 

enumerate groups with specified properties such as transitivity, 

solvability, ..., without creating all groups. 

""" 

if d is None: 

return PrimitiveGroupsAll() 

else: 

d = Integer(d) 

if d < 0: 

raise ValueError("A primitive group acts on a non negative integer number of positions") 

return PrimitiveGroupsOfDegree(d) 

 

 

class PrimitiveGroupsAll(DisjointUnionEnumeratedSets): 

""" 

The infinite set of all primitive groups up to isomorphisms. 

 

EXAMPLES:: 

 

sage: L = PrimitiveGroups(); L 

Primitive Groups 

sage: L.category() 

Category of facade infinite enumerated sets 

sage: L.cardinality() 

+Infinity 

 

sage: p = L.__iter__() # optional - database_gap 

sage: (next(p), next(p), next(p), next(p), # optional - database_gap 

....: next(p), next(p), next(p), next(p)) 

(Trivial group, Trivial group, S(2), A(3), S(3), A(4), S(4), C(5)) 

 

TESTS: 

 

The following test is broken, see :trac:`22576`:: 

 

sage: TestSuite(PrimitiveGroups()).run() # known bug # optional - database_gap # long time 

""" 

def __init__(self): 

""" 

TESTS:: 

 

sage: S = PrimitiveGroups() # optional - database_gap 

sage: S.category() # optional - database_gap 

Category of facade infinite enumerated sets 

""" 

DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), lambda i: PrimitiveGroups(i)) ) 

 

def _repr_(self): 

""" 

Return a string representation. 

 

OUTPUT: 

 

String. 

 

TESTS:: 

 

sage: PrimitiveGroups() # optional - database_gap # indirect doctest 

Primitive Groups 

""" 

return "Primitive Groups" 

 

def __contains__(self, G): 

r""" 

Test whether `G` is in ``self``. 

 

INPUT: 

 

- `G` -- anything. 

 

OUTPUT: 

 

Boolean. 

 

EXAMPLES:: 

 

sage: PrimitiveGroup(5,2) in PrimitiveGroups() # optional - database_gap 

True 

sage: PrimitiveGroup(6,4) in PrimitiveGroups() # optional - database_gap 

True 

sage: 1 in PrimitiveGroups() # optional - database_gap 

False 

""" 

return isinstance(G,PrimitiveGroup) 

 

class PrimitiveGroupsOfDegree(CachedRepresentation, Parent): 

""" 

The set of all primitive groups of a given degree up to isomorphisms. 

 

EXAMPLES:: 

 

sage: S = PrimitiveGroups(5); S # optional - database_gap 

Primitive Groups of degree 5 

sage: S.list() # optional - database_gap 

[C(5), D(2*5), AGL(1, 5), A(5), S(5)] 

sage: S.an_element() # optional - database_gap 

C(5) 

 

We write the cardinality of all primitive groups of degree 5:: 

 

sage: for G in PrimitiveGroups(5): # optional - database_gap 

....: print(G.cardinality()) 

5 

10 

20 

60 

120 

 

TESTS:: 

 

sage: TestSuite(PrimitiveGroups(3)).run() # optional - database_gap 

""" 

def __init__(self, n): 

""" 

TESTS:: 

 

sage: S = PrimitiveGroups(4) # optional - database_gap 

sage: S.category() # optional - database_gap 

Category of finite enumerated sets 

""" 

self._degree = n 

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

 

def _repr_(self): 

""" 

Return a string representation. 

 

OUTPUT: 

 

String. 

 

TESTS:: 

 

sage: PrimitiveGroups(6) # optional - database_gap 

Primitive Groups of degree 6 

""" 

return "Primitive Groups of degree %s"%(self._degree) 

 

def __contains__(self, G): 

r""" 

Test whether `G` is in ``self``. 

 

INPUT: 

 

- `G` -- anything. 

 

OUTPUT: 

 

Boolean. 

 

EXAMPLES:: 

 

sage: PrimitiveGroup(6,4) in PrimitiveGroups(4) # optional - database_gap 

False 

sage: PrimitiveGroup(4,2) in PrimitiveGroups(4) # optional - database_gap 

True 

sage: 1 in PrimitiveGroups(4) # optional - database_gap 

False 

""" 

if isinstance(G,PrimitiveGroup): 

return G._d == self._degree 

else: 

False 

 

def __getitem__(self, n): 

r""" 

Return the `n`-th primitive group of a given degree. 

 

INPUT: 

 

- ``n`` -- a positive integer 

 

EXAMPLES:: 

 

sage: PrimitiveGroups(5)[3] # optional - database_gap 

AGL(1, 5) 

 

.. warning:: 

 

this follows GAP's naming convention of indexing the 

primitive groups starting from ``1``:: 

 

sage: PrimitiveGroups(5)[0] # optional - database_gap 

Traceback (most recent call last): 

... 

ValueError: Index n must be in {1,..,5} 

""" 

return PrimitiveGroup(self._degree, n) 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: list(PrimitiveGroups(5)) # indirect doctest # optional - database_gap 

[C(5), D(2*5), AGL(1, 5), A(5), S(5)] 

""" 

for n in range(1, self.cardinality() + 1): 

yield self[n] 

 

@cached_method 

def cardinality(self): 

r""" 

Return the cardinality of ``self``. 

 

OUTPUT: 

 

An integer. The number of primitive groups of a given degree 

up to isomorphism. 

 

EXAMPLES:: 

 

sage: PrimitiveGroups(0).cardinality() # optional - database_gap 

1 

sage: PrimitiveGroups(2).cardinality() # optional - database_gap 

1 

sage: PrimitiveGroups(7).cardinality() # optional - database_gap 

7 

sage: PrimitiveGroups(12).cardinality() # optional - database_gap 

6 

sage: [PrimitiveGroups(i).cardinality() for i in range(11)] # optional - database_gap 

[1, 1, 1, 2, 2, 5, 4, 7, 7, 11, 9] 

 

The database_gap contains all primitive groups up to degree 

2499:: 

 

sage: PrimitiveGroups(2500).cardinality() # optional - database_gap 

Traceback (most recent call last): 

... 

NotImplementedError: Only the primitive groups of degree less than 

2500 are available in GAP's database 

 

TESTS:: 

 

sage: type(PrimitiveGroups(12).cardinality()) # optional - database_gap 

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

sage: type(PrimitiveGroups(0).cardinality()) 

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

""" 

# gap.NrPrimitiveGroups(0) fails, so Sage needs to handle this 

# While we are at it, and since Sage also handles the 

# primitive group of degree 1, we may as well handle 1 

if self._degree <= 1: 

return Integer(1) 

elif self._degree >= 2500: 

raise NotImplementedError("Only the primitive groups of degree less than 2500 are available in GAP's database") 

else: 

try: 

return Integer(gap.NrPrimitiveGroups(gap(self._degree))) 

except RuntimeError: 

from sage.misc.misc import verbose 

verbose("Warning: PrimitiveGroups requires the GAP database package. Please install it with ``sage -i database_gap``.", level=0) 

 

 

class PermutationGroup_plg(PermutationGroup_unique): 

def base_ring(self): 

""" 

EXAMPLES:: 

 

sage: G = PGL(2,3) 

sage: G.base_ring() 

Finite Field of size 3 

 

sage: G = PSL(2,3) 

sage: G.base_ring() 

Finite Field of size 3 

""" 

return self._base_ring 

 

def matrix_degree(self): 

""" 

EXAMPLES:: 

 

sage: G = PSL(2,3) 

sage: G.matrix_degree() 

2 

""" 

return self._n 

 

class PGL(PermutationGroup_plg): 

def __init__(self, n, q, name='a'): 

""" 

The projective general linear groups over GF(q). 

 

INPUT: 

 

- n -- positive integer; the degree 

- q -- prime power; the size of the ground field 

- name -- (default: 'a') variable name of indeterminate of finite field GF(q) 

 

OUTPUT: 

 

PGL(n,q) 

 

.. note:: 

 

This group is also available via ``groups.permutation.PGL()``. 

 

EXAMPLES:: 

 

sage: G = PGL(2,3); G 

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

sage: print(G) 

The projective general linear group of degree 2 over Finite Field of size 3 

sage: G.base_ring() 

Finite Field of size 3 

sage: G.order() 

24 

 

sage: G = PGL(2, 9, 'b'); G 

Permutation Group with generators [(3,10,9,8,4,7,6,5), (1,2,4)(5,6,8)(7,9,10)] 

sage: G.base_ring() 

Finite Field in b of size 3^2 

 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() # long time 

 

TESTS:: 

 

sage: groups.permutation.PGL(2, 3) 

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

""" 

id = 'Group([()])' if n == 1 else 'PGL(%s,%s)'%(n,q) 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

self._n = n 

 

def __str__(self): 

""" 

EXAMPLES:: 

 

sage: G = PGL(2,3); G 

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

sage: print(G) 

The projective general linear group of degree 2 over Finite Field of size 3 

""" 

return "The projective general linear group of degree %s over %s"%(self._n, self.base_ring()) 

 

class PSL(PermutationGroup_plg): 

def __init__(self, n, q, name='a'): 

""" 

The projective special linear groups over GF(q). 

 

INPUT: 

 

- n -- positive integer; the degree 

- q -- either a prime power (the size of the ground field) or a finite field 

- name -- (default: 'a') variable name of indeterminate of finite field GF(q) 

 

OUTPUT: 

 

the group PSL(n,q) 

 

.. note:: 

 

This group is also available via ``groups.permutation.PSL()``. 

 

EXAMPLES:: 

 

sage: G = PSL(2,3); G 

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

sage: G.order() 

12 

sage: G.base_ring() 

Finite Field of size 3 

sage: print(G) 

The projective special linear group of degree 2 over Finite Field of size 3 

 

We create two groups over nontrivial finite fields:: 

 

sage: G = PSL(2, 4, 'b'); G 

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

sage: G.base_ring() 

Finite Field in b of size 2^2 

sage: G = PSL(2, 8); G 

Permutation Group with generators [(3,8,6,4,9,7,5), (1,2,3)(4,7,5)(6,9,8)] 

sage: G.base_ring() 

Finite Field in a of size 2^3 

 

sage: G.category() 

Category of finite enumerated permutation groups 

sage: TestSuite(G).run() # long time 

 

TESTS:: 

 

sage: groups.permutation.PSL(2, 3) 

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

 

Check that :trac:`7424` is handled:: 

 

sage: PSL(2, GF(7,'x')) 

Permutation Group with generators [(3,7,5)(4,8,6), (1,2,6)(3,4,8)] 

sage: PSL(2, GF(3)) 

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

sage: PSL(2, QQ) 

Traceback (most recent call last): 

... 

ValueError: q must be a prime power or a finite field 

""" 

from sage.categories.finite_fields import FiniteFields 

if q in FiniteFields(): 

name = q.gen() 

q = q.cardinality() 

if not(q in NonNegativeIntegers()): 

raise ValueError('q must be a prime power or a finite field') 

if n == 1: 

id = 'Group([()])' 

else: 

id = 'PSL(%s,%s)' % (n, q) 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

self._n = n 

 

def __str__(self): 

""" 

EXAMPLES:: 

 

sage: G = PSL(2,3) 

sage: print(G) 

The projective special linear group of degree 2 over Finite Field of size 3 

""" 

return "The projective special linear group of degree %s over %s"%(self._n, self.base_ring()) 

 

def ramification_module_decomposition_hurwitz_curve(self): 

""" 

Helps compute the decomposition of the ramification module 

for the Hurwitz curves X (over CC say) with automorphism group 

G = PSL(2,q), q a "Hurwitz prime" (ie, p is $\pm 1 \pmod 7$). 

Using this computation and Borne's formula helps determine the 

G-module structure of the RR spaces of equivariant 

divisors can be determined explicitly. 

 

The output is a list of integer multiplicities: [m1,...,mn], 

where n is the number of conj classes of G=PSL(2,p) and mi is the 

multiplicity of pi_i in the ramification module of a 

Hurwitz curve with automorphism group G. 

Here IrrRepns(G) = [pi_1,...,pi_n] (in the order listed in the 

output of self.character_table()). 

 

REFERENCE: David Joyner, Amy Ksir, Roger Vogeler, 

"Group representations on Riemann-Roch spaces of some 

Hurwitz curves," preprint, 2006. 

 

EXAMPLES:: 

 

sage: G = PSL(2,13) 

sage: G.ramification_module_decomposition_hurwitz_curve() # random, optional - database_gap gap_packages 

[0, 7, 7, 12, 12, 12, 13, 15, 14] 

 

This means, for example, that the trivial representation does not 

occur in the ramification module of a Hurwitz curve with automorphism 

group PSL(2,13), since the trivial representation is listed first 

and that entry has multiplicity 0. The "randomness" is due to the 

fact that GAP randomly orders the conjugacy classes of the same order 

in the list of all conjugacy classes. Similarly, there is some 

randomness to the ordering of the characters. 

 

If you try to use this function on a group PSL(2,q) where q is 

not a (smallish) "Hurwitz prime", an error message will be printed. 

""" 

if self.matrix_degree()!=2: 

raise ValueError("Degree must be 2.") 

F = self.base_ring() 

q = F.order() 

from sage.env import SAGE_EXTCODE 

gapcode = SAGE_EXTCODE + '/gap/joyner/hurwitz_crv_rr_sp.gap' 

gap.eval('Read("'+gapcode+'")') 

mults = gap.eval("ram_module_hurwitz("+str(q)+")") 

return eval(mults) 

 

def ramification_module_decomposition_modular_curve(self): 

""" 

Helps compute the decomposition of the ramification module 

for the modular curve X(p) (over CC say) with automorphism group G = PSL(2,q), 

q a prime > 5. Using this computation and Borne's formula helps determine the 

G-module structure of the RR spaces of equivariant 

divisors can be determined explicitly. 

 

The output is a list of integer multiplicities: [m1,...,mn], 

where n is the number of conj classes of G=PSL(2,p) and mi is the 

multiplicity of pi_i in the ramification module of a 

modular curve with automorphism group G. 

Here IrrRepns(G) = [pi_1,...,pi_n] (in the order listed in the 

output of self.character_table()). 

 

REFERENCE: D. Joyner and A. Ksir, 'Modular representations 

on some Riemann-Roch spaces of modular curves 

$X(N)$', Computational Aspects of Algebraic Curves, 

(Editor: T. Shaska) Lecture Notes in Computing, WorldScientific, 

2005.) 

 

EXAMPLES:: 

 

sage: G = PSL(2,7) 

sage: G.ramification_module_decomposition_modular_curve() # random, optional - database_gap gap_packages 

[0, 4, 3, 6, 7, 8] 

 

This means, for example, that the trivial representation does not 

occur in the ramification module of X(7), since the trivial representation 

is listed first and that entry has multiplicity 0. The "randomness" is due to the 

fact that GAP randomly orders the conjugacy classes of the same order 

in the list of all conjugacy classes. Similarly, there is some 

randomness to the ordering of the characters. 

""" 

if self.matrix_degree()!=2: 

raise ValueError("Degree must be 2.") 

F = self.base_ring() 

q = F.order() 

from sage.env import SAGE_EXTCODE 

gapcode = SAGE_EXTCODE + '/gap/joyner/modular_crv_rr_sp.gap' 

gap.eval('Read("'+gapcode+'")') 

mults = gap.eval("ram_module_X("+str(q)+")") 

return eval(mults) 

 

class PSp(PermutationGroup_plg): 

def __init__(self, n, q, name='a'): 

""" 

The projective symplectic linear groups over GF(q). 

 

INPUT: 

 

- n -- positive integer; the degree 

- q -- prime power; the size of the ground field 

- name -- (default: 'a') variable name of indeterminate of finite field GF(q) 

 

OUTPUT: 

 

PSp(n,q) 

 

.. note:: 

 

This group is also available via ``groups.permutation.PSp()``. 

 

EXAMPLES:: 

 

sage: G = PSp(2,3); G 

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

sage: G.order() 

12 

sage: G = PSp(4,3); G 

Permutation Group with generators [(3,4)(6,7)(9,10)(12,13)(17,20)(18,21)(19,22)(23,32)(24,33)(25,34)(26,38)(27,39)(28,40)(29,35)(30,36)(31,37), (1,5,14,17,27,22,19,36,3)(2,6,32)(4,7,23,20,37,13,16,26,40)(8,24,29,30,39,10,33,11,34)(9,15,35)(12,25,38)(21,28,31)] 

sage: G.order() 

25920 

sage: print(G) 

The projective symplectic linear group of degree 4 over Finite Field of size 3 

sage: G.base_ring() 

Finite Field of size 3 

 

sage: G = PSp(2, 8, name='alpha'); G 

Permutation Group with generators [(3,8,6,4,9,7,5), (1,2,3)(4,7,5)(6,9,8)] 

sage: G.base_ring() 

Finite Field in alpha of size 2^3 

 

TESTS:: 

 

sage: groups.permutation.PSp(2, 3) 

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

""" 

if n%2 == 1: 

raise TypeError("The degree n must be even") 

else: 

id = 'PSp(%s,%s)'%(n,q) 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

self._n = n 

 

def __str__(self): 

""" 

EXAMPLES:: 

 

sage: G = PSp(4,3) 

sage: print(G) 

The projective symplectic linear group of degree 4 over Finite Field of size 3 

""" 

return "The projective symplectic linear group of degree %s over %s"%(self._n, self.base_ring()) 

 

PSP = PSp 

 

class PermutationGroup_pug(PermutationGroup_plg): 

def field_of_definition(self): 

""" 

EXAMPLES:: 

 

sage: PSU(2,3).field_of_definition() 

Finite Field in a of size 3^2 

""" 

return self._field_of_definition 

 

class PSU(PermutationGroup_pug): 

def __init__(self, n, q, name='a'): 

""" 

The projective special unitary groups over GF(q). 

 

INPUT: 

 

- n -- positive integer; the degree 

- q -- prime power; the size of the ground field 

- name -- (default: 'a') variable name of indeterminate of finite field GF(q) 

 

OUTPUT: 

 

PSU(n,q) 

 

.. note:: 

 

This group is also available via ``groups.permutation.PSU()``. 

 

EXAMPLES:: 

 

sage: PSU(2,3) 

The projective special unitary group of degree 2 over Finite Field of size 3 

 

sage: G = PSU(2, 8, name='alpha'); G 

The projective special unitary group of degree 2 over Finite Field in alpha of size 2^3 

sage: G.base_ring() 

Finite Field in alpha of size 2^3 

 

TESTS:: 

 

sage: groups.permutation.PSU(2, 3) 

The projective special unitary group of degree 2 over Finite Field of size 3 

""" 

id = 'PSU(%s,%s)'%(n,q) 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

self._field_of_definition = GF(q**2, name) 

self._n = n 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: PSU(2,3) 

The projective special unitary group of degree 2 over Finite Field of size 3 

 

""" 

return "The projective special unitary group of degree %s over %s"%(self._n, self.base_ring()) 

 

class PGU(PermutationGroup_pug): 

def __init__(self, n, q, name='a'): 

""" 

The projective general unitary groups over GF(q). 

 

INPUT: 

 

- n -- positive integer; the degree 

- q -- prime power; the size of the ground field 

- name -- (default: 'a') variable name of indeterminate of finite field GF(q) 

 

OUTPUT: 

 

PGU(n,q) 

 

.. note:: 

 

This group is also available via ``groups.permutation.PGU()``. 

 

EXAMPLES:: 

 

sage: PGU(2,3) 

The projective general unitary group of degree 2 over Finite Field of size 3 

 

sage: G = PGU(2, 8, name='alpha'); G 

The projective general unitary group of degree 2 over Finite Field in alpha of size 2^3 

sage: G.base_ring() 

Finite Field in alpha of size 2^3 

 

TESTS:: 

 

sage: groups.permutation.PGU(2, 3) 

The projective general unitary group of degree 2 over Finite Field of size 3 

""" 

id = 'PGU(%s,%s)'%(n,q) 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

self._field_of_definition = GF(q**2, name) 

self._n = n 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: PGU(2,3) 

The projective general unitary group of degree 2 over Finite Field of size 3 

 

""" 

return "The projective general unitary group of degree %s over %s"%(self._n, self.base_ring()) 

 

 

class SuzukiGroup(PermutationGroup_unique): 

def __init__(self, q, name='a'): 

r""" 

The Suzuki group over GF(q), 

$^2 B_2(2^{2k+1}) = Sz(2^{2k+1})$. 

 

A wrapper for the GAP function SuzukiGroup. 

 

INPUT: 

 

- q -- 2^n, an odd power of 2; the size of the ground 

field. (Strictly speaking, n should be greater than 1, or 

else this group os not simple.) 

- name -- (default: 'a') variable name of indeterminate of 

finite field GF(q) 

 

OUTPUT: 

 

- A Suzuki group. 

 

.. note:: 

 

This group is also available via ``groups.permutation.Suzuki()``. 

 

EXAMPLES:: 

 

sage: SuzukiGroup(8) 

Permutation Group with generators [(1,2)(3,10)(4,42)(5,18)(6,50)(7,26)(8,58)(9,34)(12,28)(13,45)(14,44)(15,23)(16,31)(17,21)(19,39)(20,38)(22,25)(24,61)(27,60)(29,65)(30,55)(32,33)(35,52)(36,49)(37,59)(40,54)(41,62)(43,53)(46,48)(47,56)(51,63)(57,64), 

(1,28,10,44)(3,50,11,42)(4,43,53,64)(5,9,39,52)(6,36,63,13)(7,51,60,57)(8,33,37,16)(12,24,55,29)(14,30,48,47)(15,19,61,54)(17,59,22,62)(18,23,34,31)(20,38,49,25)(21,26,45,58)(27,32,41,65)(35,46,40,56)] 

sage: print(SuzukiGroup(8)) 

The Suzuki group over Finite Field in a of size 2^3 

 

sage: G = SuzukiGroup(32, name='alpha') 

sage: G.order() 

32537600 

sage: G.order().factor() 

2^10 * 5^2 * 31 * 41 

sage: G.base_ring() 

Finite Field in alpha of size 2^5 

 

TESTS:: 

 

sage: groups.permutation.Suzuki(8) 

Permutation Group with generators [(1,2)(3,10)(4,42)(5,18)(6,50)(7,26)(8,58)(9,34)(12,28)(13,45)(14,44)(15,23)(16,31)(17,21)(19,39)(20,38)(22,25)(24,61)(27,60)(29,65)(30,55)(32,33)(35,52)(36,49)(37,59)(40,54)(41,62)(43,53)(46,48)(47,56)(51,63)(57,64), 

(1,28,10,44)(3,50,11,42)(4,43,53,64)(5,9,39,52)(6,36,63,13)(7,51,60,57)(8,33,37,16)(12,24,55,29)(14,30,48,47)(15,19,61,54)(17,59,22,62)(18,23,34,31)(20,38,49,25)(21,26,45,58)(27,32,41,65)(35,46,40,56)] 

 

REFERENCES: 

 

- :wikipedia:`Group_of_Lie_type\#Suzuki-Ree_groups` 

""" 

q = Integer(q) 

t = valuation(q, 2) 

if 2**t != q or is_even(t): 

raise ValueError("The ground field size %s must be an odd power of 2." % q) 

id = 'SuzukiGroup(IsPermGroup,%s)'%q 

PermutationGroup_generic.__init__(self, gap_group=id) 

self._q = q 

self._base_ring = GF(q, name=name) 

 

def base_ring(self): 

""" 

EXAMPLES:: 

 

sage: G = SuzukiGroup(32, name='alpha') 

sage: G.base_ring() 

Finite Field in alpha of size 2^5 

""" 

return self._base_ring 

 

def __str__(self): 

""" 

EXAMPLES:: 

 

sage: G = SuzukiGroup(32, name='alpha') 

sage: print(G) 

The Suzuki group over Finite Field in alpha of size 2^5 

 

""" 

return "The Suzuki group over %s" % self.base_ring()