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

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

4302

4303

4304

4305

4306

4307

4308

4309

4310

4311

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324

4325

4326

4327

4328

4329

4330

4331

4332

4333

4334

4335

4336

4337

4338

4339

4340

4341

4342

4343

4344

4345

4346

4347

4348

4349

4350

4351

4352

4353

4354

4355

4356

4357

4358

4359

4360

4361

4362

4363

4364

4365

4366

4367

4368

4369

4370

4371

4372

4373

4374

4375

4376

4377

4378

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4429

4430

4431

4432

4433

4434

4435

4436

4437

4438

4439

4440

4441

4442

4443

4444

4445

4446

4447

4448

4449

4450

4451

4452

4453

4454

4455

4456

4457

4458

4459

4460

4461

4462

4463

4464

4465

4466

4467

4468

4469

4470

4471

4472

4473

4474

4475

4476

4477

4478

4479

4480

4481

4482

4483

4484

4485

4486

4487

4488

4489

4490

4491

4492

4493

4494

4495

4496

4497

4498

4499

4500

4501

4502

4503

4504

4505

4506

4507

4508

4509

4510

4511

4512

4513

4514

4515

4516

4517

4518

4519

4520

4521

4522

4523

4524

4525

4526

4527

4528

4529

4530

4531

4532

4533

4534

4535

4536

4537

4538

4539

4540

4541

4542

4543

4544

4545

4546

4547

4548

4549

4550

4551

4552

4553

4554

4555

4556

4557

4558

4559

4560

4561

4562

4563

4564

4565

4566

4567

4568

4569

4570

4571

4572

4573

4574

4575

4576

4577

4578

4579

4580

4581

4582

4583

4584

4585

4586

4587

4588

4589

4590

4591

4592

4593

4594

4595

4596

4597

4598

4599

4600

4601

4602

4603

4604

4605

4606

4607

4608

4609

4610

4611

4612

4613

4614

4615

4616

4617

4618

4619

4620

4621

4622

4623

4624

4625

4626

4627

4628

4629

4630

4631

4632

4633

4634

4635

4636

4637

4638

4639

4640

4641

4642

4643

4644

4645

4646

4647

4648

4649

4650

4651

4652

4653

4654

4655

4656

4657

4658

4659

4660

4661

4662

4663

4664

4665

4666

4667

4668

4669

4670

4671

4672

4673

4674

4675

4676

4677

4678

4679

4680

4681

4682

4683

4684

4685

4686

4687

4688

4689

4690

4691

4692

4693

4694

4695

4696

4697

4698

4699

4700

4701

4702

4703

4704

4705

4706

4707

4708

4709

4710

4711

4712

4713

4714

4715

4716

4717

4718

4719

4720

4721

4722

4723

4724

4725

4726

4727

4728

4729

4730

4731

4732

4733

4734

4735

4736

4737

4738

4739

4740

4741

4742

4743

4744

4745

4746

4747

4748

4749

4750

4751

4752

4753

4754

4755

4756

4757

4758

4759

4760

4761

4762

4763

4764

4765

4766

4767

4768

4769

4770

4771

4772

4773

4774

4775

4776

4777

4778

4779

4780

4781

4782

4783

4784

4785

4786

4787

4788

4789

4790

4791

4792

4793

4794

4795

4796

4797

4798

4799

4800

4801

4802

4803

4804

4805

4806

4807

4808

4809

4810

4811

4812

4813

4814

4815

4816

4817

4818

4819

4820

4821

4822

4823

4824

4825

4826

4827

4828

4829

4830

4831

4832

4833

4834

4835

4836

4837

4838

4839

4840

4841

4842

4843

4844

4845

4846

4847

4848

4849

4850

4851

4852

4853

4854

4855

4856

4857

4858

4859

4860

4861

4862

4863

4864

4865

4866

4867

4868

4869

4870

4871

4872

4873

4874

4875

4876

4877

4878

4879

4880

4881

4882

4883

4884

4885

4886

4887

4888

4889

4890

4891

4892

4893

4894

4895

4896

4897

4898

4899

4900

4901

4902

4903

4904

4905

4906

4907

4908

4909

4910

4911

4912

4913

4914

4915

4916

4917

4918

4919

4920

4921

4922

4923

4924

4925

4926

4927

4928

4929

4930

4931

4932

4933

4934

4935

4936

4937

4938

4939

4940

4941

4942

4943

4944

4945

4946

4947

4948

4949

4950

4951

4952

4953

4954

4955

4956

4957

4958

4959

4960

4961

4962

4963

4964

4965

4966

4967

4968

4969

4970

4971

4972

4973

4974

4975

4976

4977

4978

4979

4980

4981

4982

4983

4984

4985

4986

4987

4988

4989

4990

4991

4992

4993

4994

4995

4996

4997

4998

4999

5000

5001

5002

5003

5004

5005

5006

5007

5008

5009

5010

5011

5012

5013

5014

5015

5016

5017

5018

5019

5020

5021

5022

5023

5024

5025

5026

5027

5028

5029

5030

5031

5032

5033

5034

5035

5036

5037

5038

5039

5040

5041

5042

5043

5044

5045

5046

5047

5048

5049

5050

5051

5052

5053

5054

5055

5056

5057

5058

5059

5060

5061

5062

5063

5064

5065

5066

5067

5068

5069

5070

5071

5072

5073

5074

5075

5076

5077

5078

5079

5080

5081

5082

5083

5084

5085

5086

5087

5088

5089

5090

5091

5092

5093

5094

5095

5096

5097

5098

5099

5100

5101

5102

5103

5104

5105

5106

5107

5108

5109

5110

5111

5112

5113

5114

5115

5116

5117

5118

5119

5120

5121

5122

5123

5124

5125

5126

5127

5128

5129

5130

5131

5132

5133

5134

5135

5136

5137

5138

5139

5140

5141

5142

5143

5144

5145

5146

5147

5148

5149

5150

5151

5152

5153

5154

5155

5156

5157

5158

5159

5160

5161

5162

5163

5164

5165

5166

5167

5168

5169

5170

5171

5172

5173

5174

5175

5176

5177

5178

5179

5180

5181

5182

5183

5184

5185

5186

5187

5188

5189

5190

5191

5192

5193

5194

5195

5196

5197

5198

5199

5200

5201

5202

5203

5204

5205

5206

5207

5208

5209

5210

5211

5212

5213

5214

5215

5216

5217

5218

5219

5220

5221

5222

5223

5224

5225

5226

5227

5228

5229

5230

5231

5232

5233

5234

5235

5236

5237

5238

5239

5240

5241

5242

5243

5244

5245

5246

5247

5248

5249

5250

5251

5252

5253

5254

5255

5256

5257

5258

5259

5260

5261

5262

5263

5264

5265

5266

5267

5268

5269

5270

5271

5272

5273

5274

5275

5276

5277

5278

5279

5280

5281

5282

5283

5284

5285

5286

5287

5288

5289

5290

5291

5292

5293

5294

5295

5296

5297

5298

5299

5300

5301

5302

5303

5304

5305

5306

5307

5308

5309

5310

5311

5312

5313

5314

5315

5316

5317

5318

5319

5320

5321

5322

5323

5324

5325

5326

5327

5328

5329

5330

5331

5332

5333

5334

5335

5336

5337

5338

5339

5340

5341

5342

5343

5344

5345

5346

5347

5348

5349

5350

5351

5352

5353

5354

5355

5356

5357

5358

5359

5360

5361

5362

5363

5364

5365

5366

5367

5368

5369

5370

5371

5372

5373

5374

5375

5376

5377

5378

5379

5380

5381

5382

5383

5384

5385

5386

5387

5388

5389

5390

5391

5392

5393

5394

5395

5396

5397

5398

5399

5400

5401

5402

5403

5404

5405

5406

5407

5408

5409

5410

5411

5412

5413

5414

5415

5416

5417

5418

5419

5420

5421

5422

5423

5424

5425

5426

5427

5428

5429

5430

5431

5432

5433

5434

5435

5436

5437

5438

5439

5440

5441

5442

5443

5444

5445

5446

5447

5448

5449

5450

5451

5452

5453

5454

5455

5456

5457

5458

5459

5460

5461

5462

5463

5464

5465

5466

5467

5468

5469

5470

5471

5472

5473

5474

5475

5476

5477

5478

5479

5480

5481

5482

5483

5484

5485

5486

5487

5488

5489

5490

5491

5492

5493

5494

5495

5496

5497

5498

5499

5500

5501

5502

5503

5504

5505

5506

5507

5508

5509

5510

5511

5512

5513

5514

5515

5516

5517

5518

5519

5520

5521

5522

5523

5524

5525

5526

5527

5528

5529

5530

5531

5532

5533

5534

5535

5536

5537

5538

5539

5540

5541

5542

5543

5544

5545

5546

5547

5548

5549

5550

5551

5552

5553

5554

5555

5556

5557

5558

5559

5560

5561

5562

5563

5564

5565

5566

5567

5568

5569

5570

5571

5572

5573

5574

5575

5576

5577

5578

5579

5580

5581

5582

5583

5584

5585

5586

5587

5588

5589

5590

5591

5592

5593

5594

5595

5596

5597

5598

5599

5600

5601

5602

5603

5604

5605

5606

5607

5608

5609

5610

5611

5612

5613

5614

5615

5616

5617

5618

5619

5620

5621

5622

5623

5624

5625

5626

5627

5628

5629

5630

5631

5632

5633

5634

5635

5636

5637

5638

5639

5640

5641

5642

5643

5644

5645

5646

5647

5648

5649

5650

5651

5652

5653

5654

5655

5656

5657

5658

5659

5660

5661

5662

5663

5664

5665

5666

5667

5668

5669

5670

5671

5672

5673

5674

5675

5676

5677

5678

5679

5680

5681

5682

5683

5684

5685

5686

5687

5688

5689

5690

5691

5692

5693

5694

5695

5696

5697

5698

5699

5700

5701

5702

5703

5704

5705

5706

5707

5708

5709

5710

5711

5712

5713

5714

5715

5716

5717

5718

5719

5720

5721

5722

5723

5724

5725

5726

5727

5728

5729

5730

5731

5732

5733

5734

5735

5736

5737

5738

5739

5740

5741

5742

5743

5744

5745

5746

5747

5748

5749

5750

5751

5752

5753

5754

5755

5756

5757

5758

5759

5760

5761

5762

5763

5764

5765

5766

5767

5768

5769

5770

5771

5772

5773

5774

5775

5776

5777

5778

5779

5780

5781

5782

5783

5784

5785

5786

5787

5788

5789

5790

5791

5792

5793

5794

5795

5796

5797

5798

5799

5800

5801

5802

5803

5804

5805

5806

5807

5808

5809

5810

5811

5812

5813

5814

5815

5816

5817

5818

5819

5820

5821

5822

5823

5824

5825

5826

5827

5828

5829

5830

5831

5832

5833

5834

5835

5836

5837

5838

5839

5840

5841

5842

5843

5844

5845

5846

5847

5848

5849

5850

5851

5852

5853

5854

5855

5856

5857

5858

5859

5860

5861

5862

5863

5864

5865

5866

5867

5868

5869

5870

5871

5872

5873

5874

5875

5876

5877

5878

5879

5880

5881

5882

5883

5884

5885

5886

5887

5888

5889

5890

5891

5892

5893

5894

5895

5896

5897

5898

5899

5900

5901

5902

5903

5904

5905

5906

5907

5908

5909

5910

5911

5912

5913

5914

5915

5916

5917

5918

5919

5920

5921

5922

5923

5924

5925

5926

5927

5928

5929

5930

5931

5932

5933

5934

5935

5936

5937

5938

5939

5940

5941

5942

5943

5944

5945

5946

5947

5948

5949

5950

5951

5952

5953

5954

5955

5956

5957

5958

5959

5960

5961

5962

5963

5964

5965

5966

5967

5968

5969

5970

5971

5972

5973

5974

5975

5976

5977

5978

5979

5980

5981

5982

5983

5984

5985

5986

5987

5988

5989

5990

5991

5992

5993

5994

5995

5996

5997

5998

5999

6000

6001

6002

6003

6004

6005

6006

6007

6008

6009

6010

6011

6012

6013

6014

6015

6016

6017

6018

6019

6020

6021

6022

6023

6024

6025

6026

6027

6028

6029

6030

6031

6032

6033

6034

6035

6036

6037

6038

6039

6040

6041

6042

6043

6044

6045

6046

6047

6048

6049

6050

6051

6052

6053

6054

6055

6056

6057

6058

6059

6060

6061

6062

6063

6064

6065

6066

6067

6068

6069

6070

6071

6072

6073

6074

6075

6076

6077

6078

6079

6080

6081

6082

6083

6084

6085

6086

6087

6088

6089

6090

6091

6092

6093

6094

6095

6096

6097

6098

6099

6100

6101

6102

6103

6104

6105

6106

6107

6108

6109

6110

6111

6112

6113

6114

6115

6116

6117

6118

6119

6120

6121

6122

6123

6124

6125

6126

6127

6128

6129

6130

6131

6132

6133

6134

6135

6136

6137

6138

6139

6140

6141

6142

6143

6144

6145

6146

6147

6148

6149

6150

6151

6152

6153

6154

6155

6156

6157

6158

6159

6160

6161

6162

6163

6164

6165

6166

6167

6168

6169

6170

6171

6172

6173

6174

6175

6176

6177

6178

6179

6180

6181

6182

6183

6184

6185

6186

6187

6188

6189

6190

6191

6192

6193

6194

6195

6196

6197

6198

6199

6200

6201

6202

6203

6204

6205

6206

6207

6208

6209

6210

6211

6212

6213

6214

6215

6216

6217

6218

6219

6220

6221

6222

6223

6224

6225

6226

6227

6228

6229

6230

6231

6232

6233

6234

6235

6236

6237

6238

6239

6240

6241

6242

6243

6244

6245

6246

6247

6248

6249

6250

6251

6252

6253

6254

6255

6256

6257

6258

6259

6260

6261

6262

6263

6264

6265

6266

6267

6268

6269

6270

6271

6272

6273

6274

6275

6276

6277

6278

6279

6280

6281

6282

6283

6284

6285

6286

6287

6288

6289

6290

6291

6292

6293

6294

6295

6296

6297

6298

6299

6300

6301

6302

6303

6304

6305

6306

6307

6308

6309

6310

6311

6312

6313

6314

6315

6316

6317

6318

6319

6320

6321

6322

6323

6324

6325

6326

6327

6328

6329

6330

6331

6332

6333

6334

6335

6336

6337

6338

6339

6340

6341

6342

6343

6344

6345

6346

6347

6348

6349

6350

6351

6352

6353

6354

6355

6356

6357

6358

6359

6360

6361

6362

6363

6364

6365

6366

6367

6368

6369

6370

6371

6372

6373

6374

6375

6376

6377

6378

6379

6380

6381

6382

6383

6384

6385

6386

6387

6388

6389

6390

6391

6392

6393

6394

6395

6396

6397

6398

6399

6400

6401

6402

6403

6404

6405

6406

6407

6408

6409

6410

6411

6412

6413

6414

6415

6416

6417

6418

6419

6420

6421

6422

6423

6424

6425

6426

6427

6428

6429

6430

6431

6432

6433

6434

6435

6436

6437

6438

6439

6440

6441

6442

6443

6444

6445

6446

6447

6448

6449

6450

6451

6452

6453

6454

6455

6456

6457

6458

6459

6460

6461

6462

6463

6464

6465

6466

6467

6468

6469

6470

6471

6472

6473

6474

6475

6476

6477

6478

6479

6480

6481

6482

6483

6484

6485

6486

6487

6488

6489

6490

6491

6492

6493

6494

6495

6496

6497

6498

6499

6500

6501

6502

6503

6504

6505

6506

6507

6508

6509

6510

6511

6512

6513

6514

6515

6516

6517

6518

6519

6520

6521

6522

6523

6524

6525

6526

6527

6528

6529

6530

6531

6532

6533

6534

6535

6536

6537

6538

6539

6540

6541

6542

6543

6544

6545

6546

6547

6548

6549

6550

6551

6552

6553

6554

6555

6556

6557

6558

6559

6560

6561

6562

6563

6564

6565

6566

6567

6568

6569

6570

6571

6572

6573

6574

6575

6576

6577

6578

6579

6580

6581

6582

6583

6584

6585

6586

6587

6588

6589

6590

6591

6592

6593

6594

6595

6596

6597

6598

6599

6600

6601

6602

6603

6604

6605

6606

6607

6608

6609

6610

6611

6612

6613

6614

6615

6616

6617

6618

6619

6620

6621

6622

6623

6624

6625

6626

6627

6628

6629

6630

6631

6632

6633

6634

6635

6636

6637

6638

6639

6640

6641

6642

6643

6644

6645

6646

6647

6648

6649

6650

6651

6652

6653

6654

6655

6656

6657

6658

6659

6660

6661

6662

6663

6664

6665

6666

6667

6668

6669

6670

6671

6672

6673

6674

6675

6676

6677

6678

6679

6680

6681

6682

6683

6684

6685

6686

6687

6688

6689

6690

6691

6692

6693

6694

6695

6696

6697

6698

6699

6700

6701

6702

6703

6704

6705

6706

6707

6708

6709

6710

6711

6712

6713

6714

6715

6716

6717

6718

6719

6720

6721

6722

6723

6724

6725

6726

6727

6728

6729

6730

6731

6732

6733

6734

6735

6736

6737

6738

6739

6740

6741

6742

6743

6744

6745

6746

6747

6748

6749

6750

6751

6752

6753

6754

6755

6756

6757

6758

6759

6760

6761

6762

6763

6764

6765

6766

6767

6768

6769

6770

6771

6772

6773

6774

6775

6776

6777

6778

6779

6780

6781

6782

6783

6784

6785

6786

6787

6788

6789

6790

6791

6792

6793

6794

6795

6796

6797

6798

6799

6800

6801

6802

6803

6804

6805

6806

6807

6808

6809

6810

6811

6812

6813

6814

6815

6816

6817

6818

6819

6820

6821

6822

6823

6824

6825

6826

6827

6828

6829

6830

6831

6832

6833

6834

6835

6836

6837

6838

6839

6840

6841

6842

6843

6844

6845

6846

6847

6848

6849

6850

6851

6852

6853

6854

6855

6856

6857

6858

6859

6860

6861

6862

6863

6864

6865

6866

6867

6868

6869

6870

6871

6872

6873

6874

6875

6876

6877

6878

6879

6880

6881

6882

6883

6884

6885

6886

6887

6888

6889

6890

6891

6892

6893

6894

6895

6896

6897

6898

6899

6900

6901

6902

6903

6904

6905

6906

6907

6908

6909

6910

6911

6912

6913

6914

6915

6916

6917

6918

6919

6920

6921

6922

6923

6924

6925

6926

6927

6928

6929

6930

6931

6932

6933

6934

6935

6936

6937

6938

6939

6940

6941

6942

6943

6944

6945

6946

6947

6948

6949

6950

6951

6952

6953

6954

6955

6956

6957

6958

6959

6960

6961

6962

6963

6964

6965

6966

6967

6968

6969

6970

6971

6972

6973

6974

6975

6976

6977

6978

6979

6980

6981

6982

6983

6984

6985

6986

6987

6988

6989

6990

6991

6992

6993

6994

6995

6996

6997

6998

6999

7000

7001

7002

7003

7004

7005

7006

7007

7008

7009

7010

7011

7012

7013

7014

7015

7016

7017

7018

7019

7020

7021

7022

7023

7024

7025

7026

7027

7028

7029

7030

7031

7032

7033

7034

7035

7036

7037

7038

7039

7040

7041

7042

7043

7044

7045

7046

7047

7048

7049

7050

7051

7052

7053

7054

7055

7056

7057

7058

7059

7060

7061

7062

7063

7064

7065

7066

7067

7068

7069

7070

7071

7072

7073

7074

7075

7076

7077

7078

7079

7080

7081

7082

7083

7084

7085

7086

7087

7088

7089

7090

7091

7092

7093

7094

7095

7096

7097

7098

7099

7100

7101

7102

7103

7104

7105

7106

7107

7108

7109

7110

7111

7112

7113

7114

7115

7116

7117

7118

7119

7120

7121

7122

7123

7124

7125

7126

7127

7128

7129

7130

7131

7132

7133

7134

7135

7136

7137

7138

7139

7140

7141

7142

7143

7144

7145

7146

7147

7148

7149

7150

7151

7152

7153

7154

7155

7156

7157

7158

7159

7160

7161

7162

7163

7164

7165

7166

7167

7168

7169

7170

7171

7172

7173

7174

7175

7176

7177

7178

7179

7180

7181

7182

7183

7184

7185

7186

7187

7188

7189

7190

7191

7192

7193

7194

7195

7196

7197

7198

7199

7200

7201

7202

7203

7204

7205

7206

7207

7208

7209

7210

7211

7212

7213

7214

7215

7216

7217

7218

7219

7220

7221

7222

7223

7224

7225

7226

7227

7228

7229

7230

7231

7232

7233

7234

7235

7236

7237

7238

7239

7240

7241

7242

7243

7244

7245

7246

7247

7248

7249

7250

7251

7252

7253

7254

7255

7256

7257

7258

7259

7260

7261

7262

7263

7264

7265

7266

7267

7268

7269

7270

7271

7272

7273

7274

7275

7276

7277

7278

7279

7280

7281

7282

7283

7284

7285

7286

7287

7288

7289

7290

7291

7292

7293

7294

7295

7296

7297

7298

7299

7300

7301

7302

7303

7304

7305

7306

7307

7308

7309

7310

7311

7312

7313

7314

7315

7316

7317

7318

7319

7320

7321

7322

7323

7324

7325

7326

7327

7328

7329

7330

7331

7332

7333

7334

7335

7336

7337

7338

7339

7340

7341

7342

7343

7344

7345

7346

7347

7348

7349

7350

7351

7352

7353

7354

7355

7356

7357

7358

7359

7360

7361

7362

7363

7364

7365

7366

7367

7368

7369

7370

7371

7372

7373

7374

7375

7376

7377

7378

7379

7380

7381

7382

7383

7384

7385

7386

7387

7388

7389

7390

7391

7392

7393

7394

7395

7396

7397

7398

7399

7400

7401

7402

7403

7404

7405

7406

7407

7408

7409

7410

7411

7412

7413

7414

7415

7416

7417

7418

7419

7420

7421

7422

7423

7424

7425

7426

7427

7428

7429

7430

7431

7432

7433

7434

7435

7436

7437

7438

7439

7440

7441

7442

7443

7444

7445

7446

7447

7448

7449

7450

7451

7452

7453

7454

7455

7456

7457

7458

7459

7460

7461

7462

7463

7464

7465

7466

7467

7468

7469

7470

7471

7472

7473

7474

7475

7476

7477

7478

7479

7480

7481

7482

7483

7484

7485

7486

7487

7488

7489

7490

7491

7492

7493

7494

7495

7496

7497

7498

7499

7500

7501

7502

7503

7504

7505

7506

7507

7508

7509

7510

7511

7512

7513

7514

7515

7516

7517

7518

7519

7520

7521

7522

7523

7524

7525

7526

7527

7528

7529

7530

7531

7532

7533

7534

7535

7536

7537

7538

7539

7540

7541

7542

7543

7544

7545

7546

7547

7548

7549

7550

7551

7552

7553

7554

7555

7556

7557

7558

7559

7560

7561

7562

7563

7564

7565

7566

7567

7568

7569

7570

7571

7572

7573

7574

7575

7576

7577

7578

7579

7580

7581

7582

7583

7584

7585

7586

7587

7588

7589

7590

7591

7592

7593

7594

7595

7596

7597

7598

7599

7600

7601

7602

7603

7604

7605

7606

7607

7608

7609

7610

7611

7612

7613

7614

7615

7616

7617

7618

7619

7620

7621

7622

7623

7624

7625

7626

7627

7628

7629

7630

7631

7632

7633

7634

7635

7636

7637

7638

7639

7640

7641

7642

7643

7644

7645

7646

7647

7648

7649

7650

7651

7652

7653

7654

7655

7656

7657

7658

7659

7660

7661

7662

7663

7664

7665

7666

7667

7668

7669

7670

7671

7672

7673

7674

7675

7676

7677

7678

7679

7680

7681

7682

7683

7684

7685

7686

7687

7688

7689

7690

7691

7692

7693

7694

7695

7696

7697

7698

7699

7700

7701

7702

7703

7704

7705

7706

7707

7708

7709

7710

7711

7712

7713

7714

7715

7716

7717

7718

7719

7720

7721

7722

7723

7724

7725

7726

7727

7728

7729

7730

7731

7732

7733

7734

7735

7736

7737

7738

7739

7740

7741

7742

7743

7744

7745

7746

7747

7748

7749

7750

7751

7752

7753

7754

7755

7756

7757

7758

7759

7760

7761

7762

7763

7764

7765

7766

7767

7768

7769

7770

7771

7772

7773

7774

7775

7776

7777

7778

7779

7780

7781

7782

7783

7784

7785

7786

7787

7788

7789

7790

7791

7792

7793

7794

7795

7796

7797

7798

7799

7800

7801

7802

7803

7804

7805

7806

7807

7808

7809

7810

7811

7812

7813

7814

7815

7816

7817

7818

7819

7820

7821

7822

7823

7824

7825

7826

7827

7828

7829

7830

7831

7832

7833

7834

7835

7836

7837

7838

7839

7840

7841

7842

7843

7844

7845

7846

7847

7848

7849

7850

7851

7852

7853

7854

7855

7856

7857

7858

7859

7860

7861

7862

7863

7864

7865

7866

7867

7868

7869

7870

7871

7872

7873

7874

7875

7876

7877

7878

7879

7880

7881

7882

7883

7884

7885

7886

7887

7888

7889

7890

7891

7892

7893

7894

7895

7896

7897

7898

7899

7900

7901

7902

7903

7904

7905

7906

7907

7908

7909

7910

7911

7912

7913

7914

7915

7916

7917

7918

7919

7920

7921

7922

7923

7924

7925

7926

7927

7928

7929

7930

7931

7932

7933

7934

7935

7936

7937

7938

7939

7940

7941

7942

7943

7944

7945

7946

7947

7948

7949

7950

7951

7952

7953

7954

7955

7956

7957

7958

7959

7960

7961

7962

7963

7964

7965

7966

7967

7968

7969

7970

7971

7972

7973

7974

7975

7976

7977

7978

7979

7980

7981

7982

7983

7984

7985

7986

7987

7988

7989

7990

7991

7992

7993

7994

7995

7996

7997

7998

7999

8000

8001

8002

8003

8004

8005

8006

8007

8008

8009

8010

8011

8012

8013

8014

8015

8016

8017

8018

8019

8020

8021

8022

8023

8024

8025

8026

8027

8028

8029

8030

8031

8032

8033

8034

8035

8036

8037

8038

8039

8040

8041

8042

8043

8044

8045

8046

8047

8048

8049

8050

8051

8052

8053

8054

8055

8056

8057

8058

8059

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

r""" 

Integer partitions 

 

A partition `p` of a nonnegative integer `n` is a 

non-increasing list of positive integers (the *parts* of the 

partition) with total sum `n`. 

 

A partition can be depicted by a diagram made of rows of cells, 

where the number of cells in the `i^{th}` row starting from 

the top is the `i^{th}` part of the partition. 

 

The coordinate system related to a partition applies from the top 

to the bottom and from left to right. So, the corners of the 

partition `[5, 3, 1]` are `[[0,4], [1,2], [2,0]]`. 

 

For display options, see :obj:`Partitions.options`. 

 

.. NOTE:: 

 

- Boxes is a synonym for cells. All methods will use 'cell' and 'cells' 

instead of 'box' and 'boxes'. 

 

- Partitions are 0 based with coordinates in the form of (row-index, 

column-index). 

 

- If given coordinates of the form ``(r, c)``, then use Python's 

\*-operator. 

 

 

- Throughout this documentation, for a partition `\lambda` we will denote 

its conjugate partition by `\lambda^{\prime}`. For more on conjugate 

partitions, see :meth:`Partition.conjugate()`. 

 

- The comparisons on partitions use lexicographic order. 

 

.. NOTE:: 

 

We use the convention that lexicographic ordering is read from 

left-to-right. That is to say `[1, 3, 7]` is smaller than `[2, 3, 4]`. 

 

AUTHORS: 

 

- Mike Hansen (2007): initial version 

 

- Dan Drake (2009-03-28): deprecate RestrictedPartitions and implement 

Partitions_parts_in 

 

- Travis Scrimshaw (2012-01-12): Implemented latex function to Partition_class 

 

- Travis Scrimshaw (2012-05-09): Fixed Partitions(-1).list() infinite recursion 

loop by saying Partitions_n is the empty set. 

 

- Travis Scrimshaw (2012-05-11): Fixed bug in inner where if the length was 

longer than the length of the inner partition, it would include 0's. 

 

- Andrew Mathas (2012-06-01): Removed depreciated functions and added 

compatibility with the PartitionTuple classes. See :trac:`13072` 

 

- Travis Scrimshaw (2012-10-12): Added options. Made 

``Partition_class`` to the element ``Partition``. ``Partitions*`` are now 

all in the category framework except ``PartitionsRestricted`` (which will 

eventually be removed). Cleaned up documentation. 

 

EXAMPLES: 

 

There are `5` partitions of the integer `4`:: 

 

sage: Partitions(4).cardinality() 

5 

sage: Partitions(4).list() 

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

 

We can use the method ``.first()`` to get the 'first' partition of a 

number:: 

 

sage: Partitions(4).first() 

[4] 

 

Using the method ``.next(p)``, we can calculate the 'next' partition 

after `p`. When we are at the last partition, ``None`` will be returned:: 

 

sage: Partitions(4).next([4]) 

[3, 1] 

sage: Partitions(4).next([1,1,1,1]) is None 

True 

 

We can use ``iter`` to get an object which iterates over the partitions 

one by one to save memory. Note that when we do something like 

``for part in Partitions(4)`` this iterator is used in the background:: 

 

sage: g = iter(Partitions(4)) 

sage: next(g) 

[4] 

sage: next(g) 

[3, 1] 

sage: next(g) 

[2, 2] 

sage: for p in Partitions(4): print(p) 

[4] 

[3, 1] 

[2, 2] 

[2, 1, 1] 

[1, 1, 1, 1] 

 

We can add constraints to the type of partitions we want. For 

example, to get all of the partitions of `4` of length `2`, we'd do the 

following:: 

 

sage: Partitions(4, length=2).list() 

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

 

Here is the list of partitions of length at least `2` and the list of 

ones with length at most `2`:: 

 

sage: Partitions(4, min_length=2).list() 

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

sage: Partitions(4, max_length=2).list() 

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

 

The options ``min_part`` and ``max_part`` can be used to set constraints 

on the sizes of all parts. Using ``max_part``, we can select 

partitions having only 'small' entries. The following is the list 

of the partitions of `4` with parts at most `2`:: 

 

sage: Partitions(4, max_part=2).list() 

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

 

The ``min_part`` options is complementary to ``max_part`` and selects 

partitions having only 'large' parts. Here is the list of all 

partitions of `4` with each part at least `2`:: 

 

sage: Partitions(4, min_part=2).list() 

[[4], [2, 2]] 

 

The options ``inner`` and ``outer`` can be used to set part-by-part 

constraints. This is the list of partitions of `4` with ``[3, 1, 1]`` as 

an outer bound (that is, partitions of `4` contained in the partition 

``[3, 1, 1]``):: 

 

sage: Partitions(4, outer=[3,1,1]).list() 

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

 

``outer`` sets ``max_length`` to the length of its argument. Moreover, the 

parts of ``outer`` may be infinite to clear constraints on specific 

parts. Here is the list of the partitions of `4` of length at most `3` 

such that the second and third part are `1` when they exist:: 

 

sage: Partitions(4, outer=[oo,1,1]).list() 

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

 

Finally, here are the partitions of `4` with ``[1,1,1]`` as an inner 

bound (i. e., the partitions of `4` containing the partition ``[1,1,1]``). 

Note that ``inner`` sets ``min_length`` to the length of its argument:: 

 

sage: Partitions(4, inner=[1,1,1]).list() 

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

 

The options ``min_slope`` and ``max_slope`` can be used to set 

constraints on the slope, that is on the difference ``p[i+1]-p[i]`` of 

two consecutive parts. Here is the list of the strictly decreasing 

partitions of `4`:: 

 

sage: Partitions(4, max_slope=-1).list() 

[[4], [3, 1]] 

 

The constraints can be combined together in all reasonable ways. 

Here are all the partitions of `11` of length between `2` and `4` such 

that the difference between two consecutive parts is between `-3` and 

`-1`:: 

 

sage: Partitions(11,min_slope=-3,max_slope=-1,min_length=2,max_length=4).list() 

[[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]] 

 

Partition objects can also be created individually with :class:`Partition`:: 

 

sage: Partition([2,1]) 

[2, 1] 

 

Once we have a partition object, then there are a variety of 

methods that we can use. For example, we can get the conjugate of a 

partition. Geometrically, the conjugate of a partition is the 

reflection of that partition through its main diagonal. Of course, 

this operation is an involution:: 

 

sage: Partition([4,1]).conjugate() 

[2, 1, 1, 1] 

sage: Partition([4,1]).conjugate().conjugate() 

[4, 1] 

 

If we create a partition with extra zeros at the end, they will be dropped:: 

 

sage: Partition([4,1,0,0]) 

[4, 1] 

sage: Partition([0]) 

[] 

sage: Partition([0,0]) 

[] 

 

The idea of a partition being followed by infinitely many parts of size 

`0` is consistent with the ``get_part`` method:: 

 

sage: p = Partition([5, 2]) 

sage: p.get_part(0) 

5 

sage: p.get_part(10) 

0 

 

We can go back and forth between the standard and the exponential 

notations of a partition. The exponential notation can be padded with 

extra zeros:: 

 

sage: Partition([6,4,4,2,1]).to_exp() 

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

sage: Partition(exp=[1,1,0,2,0,1]) 

[6, 4, 4, 2, 1] 

sage: Partition([6,4,4,2,1]).to_exp(5) 

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

sage: Partition([6,4,4,2,1]).to_exp(7) 

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

sage: Partition([6,4,4,2,1]).to_exp(10) 

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

 

We can get the (zero-based!) coordinates of the corners of a 

partition:: 

 

sage: Partition([4,3,1]).corners() 

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

 

We can compute the core and quotient of a partition and build 

the partition back up from them:: 

 

sage: Partition([6,3,2,2]).core(3) 

[2, 1, 1] 

sage: Partition([7,7,5,3,3,3,1]).quotient(3) 

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

sage: p = Partition([11,5,5,3,2,2,2]) 

sage: p.core(3) 

[] 

sage: p.quotient(3) 

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

sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1])) 

[11, 5, 5, 3, 2, 2, 2] 

 

We can compute the `0-1` sequence and go back and forth:: 

 

sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0]) 

[5, 4] 

sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) 

....: == mu for n in range(5) for mu in Partitions(n)) 

True 

 

We can compute the Frobenius coordinates and go back and forth:: 

 

sage: Partition([7,3,1]).frobenius_coordinates() 

([6, 1], [2, 0]) 

sage: Partition(frobenius_coordinates=([6,1],[2,0])) 

[7, 3, 1] 

sage: all(mu == Partition(frobenius_coordinates=mu.frobenius_coordinates()) 

....: for n in range(30) for mu in Partitions(n)) 

True 

 

We use the lexicographic ordering:: 

 

sage: pl = Partition([4,1,1]) 

sage: ql = Partitions()([3,3]) 

sage: pl > ql 

True 

sage: PL = Partitions() 

sage: pl = PL([4,1,1]) 

sage: ql = PL([3,3]) 

sage: pl > ql 

True 

""" 

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

# Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>, 

# 

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

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

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

from __future__ import print_function, absolute_import 

 

import six 

from six.moves import range 

 

from sage.interfaces.all import gap 

from sage.libs.all import pari 

from sage.libs.flint.arith import number_of_partitions as flint_number_of_partitions 

 

from sage.structure.global_options import GlobalOptions 

from sage.structure.parent import Parent 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.symbolic.ring import var 

 

from sage.misc.lazy_import import lazy_import 

lazy_import('sage.combinat.skew_partition', 'SkewPartition') 

lazy_import('sage.combinat.partition_tuple', 'PartitionTuple') 

 

from sage.misc.all import prod 

from sage.misc.prandom import randrange 

from sage.misc.cachefunc import cached_method, cached_function 

 

from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets 

from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 

 

from sage.sets.non_negative_integers import NonNegativeIntegers 

from sage.rings.all import QQ, ZZ, NN, IntegerModRing 

from sage.arith.all import factorial, gcd 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

from sage.rings.integer import Integer 

from sage.rings.infinity import infinity 

 

from .combinat import CombinatorialClass, CombinatorialElement 

from . import tableau 

from . import permutation 

from . import composition 

from sage.combinat.partitions import number_of_partitions as bober_number_of_partitions 

from sage.combinat.partitions import ZS1_iterator, ZS1_iterator_nk 

from sage.combinat.integer_vector import IntegerVectors 

from sage.combinat.integer_lists import IntegerListsLex 

from sage.combinat.root_system.weyl_group import WeylGroup 

from sage.combinat.combinatorial_map import combinatorial_map 

from sage.groups.perm_gps.permgroup import PermutationGroup 

from sage.graphs.dot2tex_utils import have_dot2tex 

 

class Partition(CombinatorialElement): 

r""" 

A partition `p` of a nonnegative integer `n` is a 

non-increasing list of positive integers (the *parts* of the 

partition) with total sum `n`. 

 

A partition is often represented as a diagram consisting of **cells**, 

or **boxes**, placed in rows on top of each other such that the number of 

cells in the `i^{th}` row, reading from top to bottom, is the `i^{th}` 

part of the partition. The rows are left-justified (and become shorter 

and shorter the farther down one goes). This diagram is called the 

**Young diagram** of the partition, or more precisely its Young diagram 

in English notation. (French and Russian notations are variations on this 

representation.) 

 

The coordinate system related to a partition applies from the top 

to the bottom and from left to right. So, the corners of the 

partition ``[5, 3, 1]`` are ``[[0,4], [1,2], [2,0]]``. 

 

For display options, see :meth:`Partitions.options`. 

 

.. NOTE:: 

 

Partitions are 0 based with coordinates in the form of (row-index, 

column-index). For example consider the partition 

``mu=Partition([4,3,2,2])``, the first part is ``mu[0]`` (which is 4), 

the second is ``mu[1]``, and so on, and the upper-left cell in English 

convention is ``(0, 0)``. 

 

A partition can be specified in one of the following ways: 

 

- a list (the default) 

- using exponential notation 

- by Frobenius coordinates 

- specifying its `0-1` sequence 

- specifying the core and the quotient 

 

See the examples below. 

 

EXAMPLES: 

 

Creating partitions though parents:: 

 

sage: mu = Partitions(8)([3,2,1,1,1]); mu 

[3, 2, 1, 1, 1] 

sage: nu = Partition([3,2,1,1,1]); nu 

[3, 2, 1, 1, 1] 

sage: mu == nu 

True 

sage: mu is nu 

False 

sage: mu in Partitions() 

True 

sage: mu.parent() 

Partitions of the integer 8 

sage: mu.size() 

8 

sage: mu.category() 

Category of elements of Partitions of the integer 8 

sage: nu.parent() 

Partitions 

sage: nu.category() 

Category of elements of Partitions 

sage: mu[0] 

3 

sage: mu[1] 

2 

sage: mu[2] 

1 

sage: mu.pp() 

*** 

** 

* 

* 

* 

sage: mu.removable_cells() 

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

sage: mu.down_list() 

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

sage: mu.addable_cells() 

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

sage: mu.up_list() 

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

sage: mu.conjugate() 

[5, 2, 1] 

sage: mu.dominates(nu) 

True 

sage: nu.dominates(mu) 

True 

 

Creating partitions using ``Partition``:: 

 

sage: Partition([3,2,1]) 

[3, 2, 1] 

sage: Partition(exp=[2,1,1]) 

[3, 2, 1, 1] 

sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 

[11, 5, 5, 3, 2, 2, 2] 

sage: Partition(frobenius_coordinates=([3,2],[4,0])) 

[4, 4, 1, 1, 1] 

sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0]) 

[5, 4] 

sage: [2,1] in Partitions() 

True 

sage: [2,1,0] in Partitions() 

True 

sage: Partition([1,2,3]) 

Traceback (most recent call last): 

... 

ValueError: [1, 2, 3] is not an element of Partitions 

 

Sage ignores trailing zeros at the end of partitions:: 

 

sage: Partition([3,2,1,0]) 

[3, 2, 1] 

sage: Partitions()([3,2,1,0]) 

[3, 2, 1] 

sage: Partitions(6)([3,2,1,0]) 

[3, 2, 1] 

 

TESTS: 

 

Check that only trailing zeros are stripped:: 

 

sage: TestSuite( Partition([]) ).run() 

sage: TestSuite( Partition([4,3,2,2,2,1]) ).run() 

sage: Partition([3,2,2,2,1,0,0,0]) 

[3, 2, 2, 2, 1] 

sage: Partition([3,0,2,2,2,1,0]) 

Traceback (most recent call last): 

... 

ValueError: [3, 0, 2, 2, 2, 1, 0] is not an element of Partitions 

sage: Partition([0,7,3]) 

Traceback (most recent call last): 

... 

ValueError: [0, 7, 3] is not an element of Partitions 

""" 

@staticmethod 

def __classcall_private__(cls, mu=None, **keyword): 

""" 

This constructs a list from optional arguments and delegates the 

construction of a :class:`Partition` to the ``element_class()`` call 

of the appropriate parent. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]) 

[3, 2, 1] 

sage: Partition(exp=[2,1,1]) 

[3, 2, 1, 1] 

sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 

[11, 5, 5, 3, 2, 2, 2] 

""" 

l = len(keyword) 

if l == 0: 

if mu is not None: 

if isinstance(mu, Partition): 

return mu 

return _Partitions(list(mu)) 

if l == 1: 

if 'beta_numbers' in keyword: 

return _Partitions.from_beta_numbers(keyword['beta_numbers']) 

elif 'exp' in keyword: 

return _Partitions.from_exp(keyword['exp']) 

elif 'frobenius_coordinates' in keyword: 

return _Partitions.from_frobenius_coordinates(keyword['frobenius_coordinates']) 

elif 'zero_one' in keyword: 

return _Partitions.from_zero_one(keyword['zero_one']) 

 

if l == 2 and 'core' in keyword and 'quotient' in keyword: 

return _Partitions.from_core_and_quotient(keyword['core'], keyword['quotient']) 

raise ValueError('incorrect syntax for Partition()') 

 

def __setstate__(self, state): 

r""" 

In order to maintain backwards compatibility and be able to unpickle a 

old pickle from ``Partition_class`` we have to override the default 

``__setstate__``. 

 

EXAMPLES:: 

 

sage: loads(b'x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+H,*\xc9,\xc9\xcc\xcf\xe3\n\x80\xb1\xe2\x93s\x12\x8b\x8b\xb9\n\x195\x1b\x0b\x99j\x0b\x995BY\xe33\x12\x8b3\nY\xfc\x80\xac\x9c\xcc\xe2\x92B\xd6\xd8B6\r\x88IE\x99y\xe9\xc5z\x99y%\xa9\xe9\xa9E\\\xb9\x89\xd9\xa9\xf10N!{(\xa3qkP!G\x06\x90a\x04dp\x82\x18\x86@\x06Wji\x92\x1e\x00x0.\xb5') 

[3, 2, 1] 

sage: loads(dumps( Partition([3,2,1]) )) # indirect doctest 

[3, 2, 1] 

""" 

if isinstance(state, dict): # for old pickles from Partition_class 

self._set_parent(_Partitions) 

self.__dict__ = state 

else: 

self._set_parent(state[0]) 

self.__dict__ = state[1] 

 

def __init__(self, parent, mu): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,1]) 

sage: TestSuite(p).run() 

 

TESTS: 

 

Fix that tuples raise the correct error:: 

 

sage: Partition((3,1,7)) 

Traceback (most recent call last): 

... 

ValueError: [3, 1, 7] is not an element of Partitions 

""" 

if isinstance(mu, Partition): 

# Since we are (suppose to be) immutable, we can share the underlying data 

CombinatorialElement.__init__(self, parent, mu._list) 

return 

 

elif not mu: 

CombinatorialElement.__init__(self, parent, mu) 

 

elif (all(mu[i] in NN and mu[i] >= mu[i+1] for i in range(len(mu)-1)) 

and mu[-1] in NN): 

if mu[-1] == 0: # From the above checks, the last value must be == 0 or > 0 

# strip all trailing zeros 

temp = len(mu) - 1 

while temp > 0 and mu[temp-1] == 0: 

temp -= 1 

CombinatorialElement.__init__(self, parent, mu[:temp]) 

else: 

CombinatorialElement.__init__(self, parent, mu) 

 

else: 

raise ValueError("%s is not a valid partition"%repr(mu)) 

 

@cached_method 

def __hash__(self): 

r""" 

Return the hash of ``self``. 

 

TESTS:: 

 

sage: P = Partition([4,2,2,1]) 

sage: hash(P) == hash(P) 

True 

""" 

return hash(tuple(self._list)) 

 

def _repr_(self): 

r""" 

Return a string representation of ``self`` depending on 

:meth:`Partitions.options`. 

 

EXAMPLES:: 

 

sage: mu=Partition([7,7,7,3,3,2,1,1,1,1,1,1,1]); mu # indirect doctest 

[7, 7, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1] 

sage: Partitions.options.display="diagram"; mu 

******* 

******* 

******* 

*** 

*** 

** 

* 

* 

* 

* 

* 

* 

* 

sage: Partitions.options.display="list"; mu 

[7, 7, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1] 

sage: Partitions.options.display="compact_low"; mu 

1^7,2,3^2,7^3 

sage: Partitions.options.display="compact_high"; mu 

7^3,3^2,2,1^7 

sage: Partitions.options.display="exp_low"; mu 

1^7, 2, 3^2, 7^3 

sage: Partitions.options.display="exp_high"; mu 

7^3, 3^2, 2, 1^7 

 

sage: Partitions.options.convention="French"; 

sage: mu=Partition([7,7,7,3,3,2,1,1,1,1,1,1,1]); mu # indirect doctest 

7^3, 3^2, 2, 1^7 

sage: Partitions.options.display="diagram"; mu 

* 

* 

* 

* 

* 

* 

* 

** 

*** 

*** 

******* 

******* 

******* 

sage: Partitions.options.display="list"; mu 

[7, 7, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1] 

sage: Partitions.options.display="compact_low"; mu 

1^7,2,3^2,7^3 

sage: Partitions.options.display="compact_high"; mu 

7^3,3^2,2,1^7 

sage: Partitions.options.display="exp_low"; mu 

1^7, 2, 3^2, 7^3 

sage: Partitions.options.display="exp_high"; mu 

7^3, 3^2, 2, 1^7 

 

sage: Partitions.options._reset() 

""" 

return self.parent().options._dispatch(self, '_repr_', 'display') 

 

def _ascii_art_(self): 

""" 

TESTS:: 

 

sage: ascii_art(Partitions(5).list()) 

[ * ] 

[ ** * ] 

[ *** ** * * ] 

[ **** *** * ** * * ] 

[ *****, * , ** , * , * , * , * ] 

""" 

from sage.typeset.ascii_art import AsciiArt 

return AsciiArt(self._repr_diagram().splitlines(), baseline=0) 

 

def _unicode_art_(self): 

""" 

TESTS:: 

 

sage: unicode_art(Partitions(5).list()) 

⎡ ┌┐ ⎤ 

⎢ ┌┬┐ ├┤ ⎥ 

⎢ ┌┬┬┐ ┌┬┐ ├┼┘ ├┤ ⎥ 

⎢ ┌┬┬┬┐ ┌┬┬┐ ├┼┴┘ ├┼┤ ├┤ ├┤ ⎥ 

⎢ ┌┬┬┬┬┐ ├┼┴┴┘ ├┼┼┘ ├┤ ├┼┘ ├┤ ├┤ ⎥ 

⎣ └┴┴┴┴┘, └┘ , └┴┘ , └┘ , └┘ , └┘ , └┘ ⎦ 

sage: Partitions.options.convention = "French" 

sage: unicode_art(Partitions(5).list()) 

⎡ ┌┐ ⎤ 

⎢ ┌┐ ├┤ ⎥ 

⎢ ┌┐ ┌┐ ├┤ ├┤ ⎥ 

⎢ ┌┐ ┌┬┐ ├┤ ├┼┐ ├┤ ├┤ ⎥ 

⎢ ┌┬┬┬┬┐ ├┼┬┬┐ ├┼┼┐ ├┼┬┐ ├┼┤ ├┼┐ ├┤ ⎥ 

⎣ └┴┴┴┴┘, └┴┴┴┘, └┴┴┘, └┴┴┘, └┴┘, └┴┘, └┘ ⎦ 

sage: Partitions.options._reset() 

""" 

if not self._list: 

return u'∅' 

if self.parent().options.convention == "English": 

data = list(self) 

else: 

data = list(reversed(self)) 

 

txt = [u'┌' + u'┬' * (data[0] - 1) + u'┐'] 

for i in range(len(data) - 1): 

p = data[i] 

q = data[i + 1] 

if p < q: 

txt += [u'├' + u'┼' * p + u'┬' * (q - p - 1) + u'┐'] 

elif p == q: 

txt += [u'├' + u'┼' * (p - 1) + u'┤'] 

else: 

txt += [u'├' + u'┼' * q + u'┴' * (p - q - 1) + u'┘'] 

txt += [u'└' + u'┴' * (data[-1] - 1) + u'┘'] 

 

from sage.typeset.unicode_art import UnicodeArt 

return UnicodeArt(txt, baseline=0) 

 

def _repr_list(self): 

""" 

Return a string representation of ``self`` as a list. 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_list()) 

[7, 7, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1] 

""" 

return '[%s]' % ', '.join('%s'%m for m in self) 

 

def _repr_exp_low(self): 

""" 

Return a string representation of ``self`` in exponential form (lowest 

first). 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_exp_low()) 

1^7, 2, 3^2, 7^3 

sage: print(Partition([])._repr_exp_low()) 

- 

""" 

if not self._list: 

return '-' 

exp = self.to_exp() 

return '%s' % ', '.join('%s%s' % (m+1, '' if e==1 else '^%s'%e) 

for (m,e) in enumerate(exp) if e > 0) 

 

def _repr_exp_high(self): 

""" 

Return a string representation of ``self`` in exponential form (highest 

first). 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_exp_high()) 

7^3, 3^2, 2, 1^7 

 

sage: print(Partition([])._repr_exp_high()) 

- 

""" 

if not self._list: 

return '-' 

exp = self.to_exp()[::-1] # reversed list of exponents 

M=max(self) 

return '%s' % ', '.join('%s%s' % (M-m, '' if e==1 else '^%s'%e) 

for (m,e) in enumerate(exp) if e>0) 

 

def _repr_compact_low(self): 

""" 

Return a string representation of ``self`` in compact form (exponential 

form with lowest first). 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_compact_low()) 

1^7,2,3^2,7^3 

sage: print(Partition([])._repr_compact_low()) 

- 

""" 

if not self._list: 

return '-' 

exp = self.to_exp() 

return '%s' % ','.join('%s%s' % (m+1, '' if e==1 else '^%s'%e) 

for (m,e) in enumerate(exp) if e > 0) 

 

def _repr_compact_high(self): 

""" 

Return a string representation of ``self`` in compact form (exponential 

form with highest first). 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_compact_high()) 

7^3,3^2,2,1^7 

sage: print(Partition([])._repr_compact_low()) 

- 

""" 

if not self._list: 

return '-' 

exp = self.to_exp()[::-1] # reversed list of exponents 

M=max(self) 

return '%s' % ','.join('%s%s' % (M-m, '' if e==1 else '^%s'%e) 

for (m,e) in enumerate(exp) if e>0) 

 

def _repr_diagram(self): 

r""" 

Return a representation of ``self`` as a Ferrers diagram. 

 

EXAMPLES:: 

 

sage: print(Partition([7,7,7,3,3,2,1,1,1,1,1,1,1])._repr_diagram()) 

******* 

******* 

******* 

*** 

*** 

** 

* 

* 

* 

* 

* 

* 

* 

""" 

return self.ferrers_diagram() 

 

def level(self): 

""" 

Return the level of ``self``, which is always 1. 

 

This method exists only for compatibility with 

:class:`PartitionTuples`. 

 

EXAMPLES:: 

 

sage: Partition([4,3,2]).level() 

1 

""" 

return 1 

 

def components(self): 

""" 

Return a list containing the shape of ``self``. 

 

This method exists only for compatibility with 

:class:`PartitionTuples`. 

 

EXAMPLES:: 

 

sage: Partition([3,2]).components() 

[[3, 2]] 

""" 

return [ self ] 

 

def _latex_(self): 

r""" 

Return a LaTeX version of ``self``. 

 

For more on the latex options, see :meth:`Partitions.options`. 

 

EXAMPLES:: 

 

sage: mu = Partition([2, 1]) 

sage: Partitions.options.latex='diagram'; latex(mu) # indirect doctest 

{\def\lr#1{\multicolumn{1}{@{\hspace{.6ex}}c@{\hspace{.6ex}}}{\raisebox{-.3ex}{$#1$}}} 

\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\\ 

\lr{\ast}&\lr{\ast}\\ 

\lr{\ast}\\ 

\end{array}$} 

} 

sage: Partitions.options.latex='exp_high'; latex(mu) # indirect doctest 

2,1 

sage: Partitions.options.latex='exp_low'; latex(mu) # indirect doctest 

1,2 

sage: Partitions.options.latex='list'; latex(mu) # indirect doctest 

[2, 1] 

sage: Partitions.options.latex='young_diagram'; latex(mu) # indirect doctest 

{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}} 

\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\cline{1-2} 

\lr{\phantom{x}}&\lr{\phantom{x}}\\\cline{1-2} 

\lr{\phantom{x}}\\\cline{1-1} 

\end{array}$} 

} 

 

sage: Partitions.options(latex="young_diagram", convention="french") 

sage: Partitions.options.latex='exp_high'; latex(mu) # indirect doctest 

2,1 

sage: Partitions.options.latex='exp_low'; latex(mu) # indirect doctest 

1,2 

sage: Partitions.options.latex='list'; latex(mu) # indirect doctest 

[2, 1] 

sage: Partitions.options.latex='young_diagram'; latex(mu) # indirect doctest 

{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}} 

\raisebox{-.6ex}{$\begin{array}[t]{*{2}c}\cline{1-1} 

\lr{\phantom{x}}\\\cline{1-2} 

\lr{\phantom{x}}&\lr{\phantom{x}}\\\cline{1-2} 

\end{array}$} 

} 

 

sage: Partitions.options._reset() 

""" 

return self.parent().options._dispatch(self, '_latex_', 'latex') 

 

def _latex_young_diagram(self): 

r""" 

LaTeX output as a Young diagram. 

 

EXAMPLES:: 

 

sage: print(Partition([2, 1])._latex_young_diagram()) 

{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}} 

\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\cline{1-2} 

\lr{\phantom{x}}&\lr{\phantom{x}}\\\cline{1-2} 

\lr{\phantom{x}}\\\cline{1-1} 

\end{array}$} 

} 

sage: print(Partition([])._latex_young_diagram()) 

{\emptyset} 

""" 

if not self._list: 

return "{\\emptyset}" 

 

from sage.combinat.output import tex_from_array 

return tex_from_array([ ["\\phantom{x}"]*row_size for row_size in self._list ]) 

 

def _latex_diagram(self): 

r""" 

LaTeX output as a Ferrers' diagram. 

 

EXAMPLES:: 

 

sage: print(Partition([2, 1])._latex_diagram()) 

{\def\lr#1{\multicolumn{1}{@{\hspace{.6ex}}c@{\hspace{.6ex}}}{\raisebox{-.3ex}{$#1$}}} 

\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\\ 

\lr{\ast}&\lr{\ast}\\ 

\lr{\ast}\\ 

\end{array}$} 

} 

sage: print(Partition([])._latex_diagram()) 

{\emptyset} 

""" 

if not self._list: 

return "{\\emptyset}" 

 

entry = self.parent().options("latex_diagram_str") 

from sage.combinat.output import tex_from_array 

return tex_from_array([ [entry]*row_size for row_size in self._list ], False) 

 

def _latex_list(self): 

r""" 

LaTeX output as a list. 

 

EXAMPLES:: 

 

sage: print(Partition([2, 1])._latex_list()) 

[2, 1] 

sage: print(Partition([])._latex_list()) 

[] 

""" 

return repr(self._list) 

 

def _latex_exp_low(self): 

r""" 

LaTeX output in exponential notation (lowest first). 

 

EXAMPLES:: 

 

sage: print(Partition([2,2,1])._latex_exp_low()) 

1,2^{2} 

sage: print(Partition([])._latex_exp_low()) 

{\emptyset} 

""" 

if not self._list: 

return "{\\emptyset}" 

exp = self.to_exp() 

return '%s' % ','.join('%s%s' % (m+1, '' if e==1 else '^{%s}'%e) 

for (m,e) in enumerate(exp) if e > 0) 

 

def _latex_exp_high(self): 

r""" 

LaTeX output in exponential notation (highest first). 

 

EXAMPLES:: 

 

sage: print(Partition([2,2,1])._latex_exp_high()) 

2^{2},1 

sage: print(Partition([])._latex_exp_high()) 

{\emptyset} 

""" 

if not self._list: 

return "{\\emptyset}" 

exp = self.to_exp()[::-1] # reversed list of exponents 

M = max(self) 

return '%s' % ','.join('%s%s' % (M-m, '' if e==1 else '^{%s}'%e) 

for (m,e) in enumerate(exp) if e>0) 

 

 

def ferrers_diagram(self): 

r""" 

Return the Ferrers diagram of ``self``. 

 

EXAMPLES:: 

 

sage: mu=Partition([5,5,2,1]) 

sage: Partitions.options(diagram_str='*', convention="english") 

sage: print(mu.ferrers_diagram()) 

***** 

***** 

** 

* 

sage: Partitions.options(diagram_str='#') 

sage: print(mu.ferrers_diagram()) 

##### 

##### 

## 

# 

sage: Partitions.options.convention="french" 

sage: print(mu.ferrers_diagram()) 

# 

## 

##### 

##### 

sage: print(Partition([]).ferrers_diagram()) 

- 

sage: Partitions.options(diagram_str='-') 

sage: print(Partition([]).ferrers_diagram()) 

(/) 

sage: Partitions.options._reset() 

""" 

diag_str = self.parent().options.diagram_str 

if not self._list: 

return '-' if diag_str != '-' else "(/)" 

if self.parent().options.convention == "English": 

return '\n'.join([diag_str * p for p in self]) 

else: 

return '\n'.join([diag_str * p for p in reversed(self)]) 

 

def pp(self): 

r""" 

Prints the Ferrers diagram. 

 

See :meth:`ferrers_diagram` for more on the Ferrers diagram. 

 

EXAMPLES:: 

 

sage: Partition([5,5,2,1]).pp() 

***** 

***** 

** 

* 

sage: Partitions.options.convention='French' 

sage: Partition([5,5,2,1]).pp() 

* 

** 

***** 

***** 

sage: Partitions.options._reset() 

""" 

print(self.ferrers_diagram()) 

 

def __truediv__(self, p): 

""" 

Returns the skew partition ``self / p``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2,1]) 

sage: p/[1,1] 

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

sage: p/[3,2,1] 

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

sage: p/Partition([1,1]) 

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

sage: p/[2,2,2] 

Traceback (most recent call last): 

... 

ValueError: To form a skew partition p/q, q must be contained in p. 

""" 

if not self.contains(p): 

raise ValueError("To form a skew partition p/q, q must be contained in p.") 

 

return SkewPartition([self[:], p]) 

 

__div__ = __truediv__ 

 

def power(self, k): 

r""" 

Return the cycle type of the `k`-th power of any permutation 

with cycle type ``self`` (thus describes the powermap of 

symmetric groups). 

 

Equivalent to GAP's ``PowerPartition``. 

 

EXAMPLES:: 

 

sage: p = Partition([5,3]) 

sage: p.power(1) 

[5, 3] 

sage: p.power(2) 

[5, 3] 

sage: p.power(3) 

[5, 1, 1, 1] 

sage: p.power(4) 

[5, 3] 

 

Now let us compare this to the power map on `S_8`:: 

 

sage: G = SymmetricGroup(8) 

sage: g = G([(1,2,3,4,5),(6,7,8)]) 

sage: g 

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

sage: g^2 

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

sage: g^3 

(1,4,2,5,3) 

sage: g^4 

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

 

:: 

 

sage: Partition([3,2,1]).power(3) 

[2, 1, 1, 1, 1] 

""" 

res = [] 

for i in self: 

g = gcd(i, k) 

res.extend( [ZZ(i//g)]*int(g) ) 

res.sort(reverse=True) 

return Partition(res) 

 

def __next__(self): 

""" 

Return the partition that lexicographically follows ``self``. If 

``self`` is the last partition, then return ``False``. 

 

EXAMPLES:: 

 

sage: next(Partition([4])) 

[3, 1] 

sage: next(Partition([1,1,1,1])) 

False 

""" 

p = self 

n = 0 

m = 0 

for i in p: 

n += i 

m += 1 

 

next_p = p[:] + [1]*(n - len(p)) 

 

#Check to see if we are at the last (all ones) partition 

if p == [1]*n: 

return False 

 

# 

#If we are not, then run the ZS1 algorithm. 

# 

 

#Let h be the number of non-one entries in the 

#partition 

h = 0 

for i in next_p: 

if i != 1: 

h += 1 

 

if next_p[h-1] == 2: 

m += 1 

next_p[h-1] = 1 

h -= 1 

else: 

r = next_p[h-1] - 1 

t = m - h + 1 

next_p[h-1] = r 

 

while t >= r : 

h += 1 

next_p[h-1] = r 

t -= r 

 

if t == 0: 

m = h 

else: 

m = h + 1 

if t > 1: 

h += 1 

next_p[h-1] = t 

 

return self.parent()(next_p[:m]) 

 

next = __next__ 

 

def size(self): 

""" 

Return the size of ``self``. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).size() 

4 

sage: Partition([3,2,1]).size() 

6 

""" 

return sum(self) 

 

def sign(self): 

r""" 

Return the sign of any permutation with cycle type ``self``. 

 

This function corresponds to a homomorphism from the symmetric 

group `S_n` into the cyclic group of order 2, whose kernel 

is exactly the alternating group `A_n`. Partitions of sign 

`1` are called even partitions while partitions of sign 

`-1` are called odd. 

 

EXAMPLES:: 

 

sage: Partition([5,3]).sign() 

1 

sage: Partition([5,2]).sign() 

-1 

 

Zolotarev's lemma states that the Legendre symbol 

`\left(\frac{a}{p}\right)` for an integer 

`a \pmod p` (`p` a prime number), can be computed 

as sign(p_a), where sign denotes the sign of a permutation and 

p_a the permutation of the residue classes `\pmod p` 

induced by modular multiplication by `a`, provided 

`p` does not divide `a`. 

 

We verify this in some examples. 

 

:: 

 

sage: F = GF(11) 

sage: a = F.multiplicative_generator();a 

2 

sage: plist = [int(a*F(x)) for x in range(1,11)]; plist 

[2, 4, 6, 8, 10, 1, 3, 5, 7, 9] 

 

This corresponds to the permutation (1, 2, 4, 8, 5, 10, 9, 7, 3, 6) 

(acting the set `\{1,2,...,10\}`) and to the partition 

[10]. 

 

:: 

 

sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') 

sage: p.sign() 

-1 

sage: Partition([10]).sign() 

-1 

sage: kronecker_symbol(11,2) 

-1 

 

Now replace `2` by `3`:: 

 

sage: plist = [int(F(3*x)) for x in range(1,11)]; plist 

[3, 6, 9, 1, 4, 7, 10, 2, 5, 8] 

sage: list(range(1, 11)) 

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 

sage: p = PermutationGroupElement('(3,4,8,7,9)') 

sage: p.sign() 

1 

sage: kronecker_symbol(3,11) 

1 

sage: Partition([5,1,1,1,1,1]).sign() 

1 

 

In both cases, Zolotarev holds. 

 

REFERENCES: 

 

:wikipedia:`Zolotarev's_lemma` 

""" 

return (-1)**(self.size()-self.length()) 

 

def standard_tableaux(self): 

""" 

Return the :class:`standard tableaux<StandardTableaux>` of this shape. 

 

EXAMPLES:: 

 

sage: Partition([3,2,2,1]).standard_tableaux() 

Standard tableaux of shape [3, 2, 2, 1] 

""" 

return tableau.StandardTableaux(self) 

 

def up(self): 

r""" 

Returns a generator for partitions that can be obtained from ``self`` 

by adding a cell. 

 

EXAMPLES:: 

 

sage: [p for p in Partition([2,1,1]).up()] 

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

sage: [p for p in Partition([3,2]).up()] 

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

sage: [p for p in Partition([]).up()] 

[[1]] 

""" 

p = self 

previous = p.get_part(0) + 1 

for i, current in enumerate(p): 

if current < previous: 

yield Partition(p[:i] + [ p[i] + 1 ] + p[i+1:]) 

previous = current 

else: 

yield Partition(p + [1]) 

 

def up_list(self): 

""" 

Return a list of the partitions that can be formed from ``self`` by 

adding a cell. 

 

EXAMPLES:: 

 

sage: Partition([2,1,1]).up_list() 

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

sage: Partition([3,2]).up_list() 

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

sage: Partition([]).up_list() 

[[1]] 

""" 

return [p for p in self.up()] 

 

def down(self): 

r""" 

Return a generator for partitions that can be obtained from ``self`` 

by removing a cell. 

 

EXAMPLES:: 

 

sage: [p for p in Partition([2,1,1]).down()] 

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

sage: [p for p in Partition([3,2]).down()] 

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

sage: [p for p in Partition([3,2,1]).down()] 

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

 

TESTS: 

 

We check that :trac:`11435` is fixed:: 

 

sage: Partition([]).down_list() #indirect doctest 

[] 

""" 

p = self 

l = len(p) 

for i in range(l-1): 

if p[i] > p[i+1]: 

yield Partition(p[:i] + [ p[i]-1 ] + p[i+1:]) 

if l >= 1: 

last = p[-1] 

if last == 1: 

yield Partition(p[:-1]) 

else: 

yield Partition(p[:-1] + [ p[-1] - 1 ]) 

 

def down_list(self): 

""" 

Return a list of the partitions that can be obtained from ``self`` 

by removing a cell. 

 

EXAMPLES:: 

 

sage: Partition([2,1,1]).down_list() 

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

sage: Partition([3,2]).down_list() 

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

sage: Partition([3,2,1]).down_list() 

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

sage: Partition([]).down_list() #checks :trac:`11435` 

[] 

""" 

return [p for p in self.down()] 

 

@combinatorial_map(name="cell poset") 

def cell_poset(self, orientation="SE"): 

""" 

Return the Young diagram of ``self`` as a poset. The optional 

keyword variable ``orientation`` determines the order relation 

of the poset. 

 

The poset always uses the set of cells of the Young diagram 

of ``self`` as its ground set. The order relation of the poset 

depends on the ``orientation`` variable (which defaults to 

``"SE"``). Concretely, ``orientation`` has to be specified to 

one of the strings ``"NW"``, ``"NE"``, ``"SW"``, and ``"SE"``, 

standing for "northwest", "northeast", "southwest" and 

"southeast", respectively. If ``orientation`` is ``"SE"``, then 

the order relation of the poset is such that a cell `u` is 

greater or equal to a cell `v` in the poset if and only if `u` 

lies weakly southeast of `v` (this means that `u` can be 

reached from `v` by a sequence of south and east steps; the 

sequence is allowed to consist of south steps only, or of east 

steps only, or even be empty). Similarly the order relation is 

defined for the other three orientations. The Young diagram is 

supposed to be drawn in English notation. 

 

The elements of the poset are the cells of the Young diagram 

of ``self``, written as tuples of zero-based coordinates (so 

that `(3, 7)` stands for the `8`-th cell of the `4`-th row, 

etc.). 

 

EXAMPLES:: 

 

sage: p = Partition([3,3,1]) 

sage: Q = p.cell_poset(); Q 

Finite poset containing 7 elements 

sage: sorted(Q) 

[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] 

sage: sorted(Q.maximal_elements()) 

[(1, 2), (2, 0)] 

sage: Q.minimal_elements() 

[(0, 0)] 

sage: sorted(Q.upper_covers((1, 0))) 

[(1, 1), (2, 0)] 

sage: Q.upper_covers((1, 1)) 

[(1, 2)] 

 

sage: P = p.cell_poset(orientation="NW"); P 

Finite poset containing 7 elements 

sage: sorted(P) 

[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] 

sage: sorted(P.minimal_elements()) 

[(1, 2), (2, 0)] 

sage: P.maximal_elements() 

[(0, 0)] 

sage: P.upper_covers((2, 0)) 

[(1, 0)] 

sage: sorted(P.upper_covers((1, 2))) 

[(0, 2), (1, 1)] 

sage: sorted(P.upper_covers((1, 1))) 

[(0, 1), (1, 0)] 

sage: sorted([len(P.upper_covers(v)) for v in P]) 

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

 

sage: R = p.cell_poset(orientation="NE"); R 

Finite poset containing 7 elements 

sage: sorted(R) 

[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] 

sage: R.maximal_elements() 

[(0, 2)] 

sage: R.minimal_elements() 

[(2, 0)] 

sage: sorted([len(R.upper_covers(v)) for v in R]) 

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

sage: R.is_isomorphic(P) 

False 

sage: R.is_isomorphic(P.dual()) 

False 

 

Linear extensions of ``p.cell_poset()`` are in 1-to-1 correspondence 

with standard Young tableaux of shape `p`:: 

 

sage: all( len(p.cell_poset().linear_extensions()) 

....: == len(p.standard_tableaux()) 

....: for n in range(8) for p in Partitions(n) ) 

True 

 

This is not the case for northeast orientation:: 

 

sage: q = Partition([3, 1]) 

sage: q.cell_poset(orientation="NE").is_chain() 

True 

 

TESTS: 

 

We check that the posets are really what they should be for size 

up to `7`:: 

 

sage: def check_NW(n): 

....: for p in Partitions(n): 

....: P = p.cell_poset(orientation="NW") 

....: for c in p.cells(): 

....: for d in p.cells(): 

....: if P.le(c, d) != (c[0] >= d[0] 

....: and c[1] >= d[1]): 

....: return False 

....: return True 

sage: all( check_NW(n) for n in range(8) ) 

True 

 

sage: def check_NE(n): 

....: for p in Partitions(n): 

....: P = p.cell_poset(orientation="NE") 

....: for c in p.cells(): 

....: for d in p.cells(): 

....: if P.le(c, d) != (c[0] >= d[0] 

....: and c[1] <= d[1]): 

....: return False 

....: return True 

sage: all( check_NE(n) for n in range(8) ) 

True 

 

sage: def test_duality(n, ori1, ori2): 

....: for p in Partitions(n): 

....: P = p.cell_poset(orientation=ori1) 

....: Q = p.cell_poset(orientation=ori2) 

....: for c in p.cells(): 

....: for d in p.cells(): 

....: if P.lt(c, d) != Q.lt(d, c): 

....: return False 

....: return True 

sage: all( test_duality(n, "NW", "SE") for n in range(8) ) 

True 

sage: all( test_duality(n, "NE", "SW") for n in range(8) ) 

True 

sage: all( test_duality(n, "NE", "SE") for n in range(4) ) 

False 

""" 

from sage.combinat.posets.posets import Poset 

covers = {} 

if orientation == "NW": 

for i, row in enumerate(self): 

if i == 0: 

covers[(0, 0)] = [] 

for j in range(1, row): 

covers[(0, j)] = [(0, j - 1)] 

else: 

covers[(i, 0)] = [(i - 1, 0)] 

for j in range(1, row): 

covers[(i, j)] = [(i - 1, j), (i, j - 1)] 

elif orientation == "NE": 

for i, row in enumerate(self): 

if i == 0: 

covers[(0, row - 1)] = [] 

for j in range(row - 1): 

covers[(0, j)] = [(0, j + 1)] 

else: 

covers[(i, row - 1)] = [(i - 1, row - 1)] 

for j in range(row - 1): 

covers[(i, j)] = [(i - 1, j), (i, j + 1)] 

elif orientation == "SE": 

l = len(self) - 1 

for i, row in enumerate(self): 

if i == l: 

covers[(i, row - 1)] = [] 

for j in range(row - 1): 

covers[(i, j)] = [(i, j + 1)] 

else: 

next_row = self[i + 1] 

if row == next_row: 

covers[(i, row - 1)] = [(i + 1, row - 1)] 

for j in range(row - 1): 

covers[(i, j)] = [(i + 1, j), (i, j + 1)] 

else: 

covers[(i, row - 1)] = [] 

for j in range(next_row): 

covers[(i, j)] = [(i + 1, j), (i, j + 1)] 

for j in range(next_row, row - 1): 

covers[(i, j)] = [(i, j + 1)] 

elif orientation == "SW": 

l = len(self) - 1 

for i, row in enumerate(self): 

if i == l: 

covers[(i, 0)] = [] 

for j in range(1, row): 

covers[(i, j)] = [(i, j - 1)] 

else: 

covers[(i, 0)] = [(i + 1, 0)] 

next_row = self[i + 1] 

for j in range(1, next_row): 

covers[(i, j)] = [(i + 1, j), (i, j - 1)] 

for j in range(next_row, row): 

covers[(i, j)] = [(i, j - 1)] 

return Poset(covers) 

 

def frobenius_coordinates(self): 

""" 

Return a pair of sequences of Frobenius coordinates aka beta numbers 

of the partition. 

 

These are two strictly decreasing sequences of nonnegative integers 

of the same length. 

 

EXAMPLES:: 

 

sage: Partition([]).frobenius_coordinates() 

([], []) 

sage: Partition([1]).frobenius_coordinates() 

([0], [0]) 

sage: Partition([3,3,3]).frobenius_coordinates() 

([2, 1, 0], [2, 1, 0]) 

sage: Partition([9,1,1,1,1,1,1]).frobenius_coordinates() 

([8], [6]) 

 

""" 

mu = self 

muconj = mu.conjugate() # Naive implementation 

if len(mu) <= len(muconj): 

a = [x for x in (val-i-1 for i, val in enumerate(mu)) if x>=0] 

b = [x for x in (muconj[i]-i-1 for i in range(len(a))) if x>=0] 

else: 

b = [x for x in (val-i-1 for i, val in enumerate(muconj)) if x>=0] 

a = [x for x in (mu[i]-i-1 for i in range(len(b))) if x>=0] 

return (a,b) 

 

def frobenius_rank(self): 

r""" 

Return the Frobenius rank of the partition ``self``. 

 

The Frobenius rank of a partition 

`\lambda = (\lambda_1, \lambda_2, \lambda_3, \cdots)` is 

defined to be the largest `i` such that `\lambda_i \geq i`. 

In other words, it is the number of cells on the main diagonal 

of `\lambda`. In yet other words, it is the size of the largest 

square fitting into the Young diagram of `\lambda`. 

 

EXAMPLES:: 

 

sage: Partition([]).frobenius_rank() 

0 

sage: Partition([1]).frobenius_rank() 

1 

sage: Partition([3,3,3]).frobenius_rank() 

3 

sage: Partition([9,1,1,1,1,1]).frobenius_rank() 

1 

sage: Partition([2,1,1,1,1,1]).frobenius_rank() 

1 

sage: Partition([2,2,1,1,1,1]).frobenius_rank() 

2 

sage: Partition([3,2]).frobenius_rank() 

2 

sage: Partition([3,2,2]).frobenius_rank() 

2 

sage: Partition([8,4,4,4,4]).frobenius_rank() 

4 

sage: Partition([8,4,1]).frobenius_rank() 

2 

sage: Partition([3,3,1]).frobenius_rank() 

2 

""" 

for i, x in enumerate(self): 

if x <= i: 

return i 

return len(self) 

 

def beta_numbers(self, length=None): 

""" 

Return the set of beta numbers corresponding to ``self``. 

 

The optional argument ``length`` specifies the length of the beta set 

(which must be at least the length of ``self``). 

 

For more on beta numbers, see :meth:`frobenius_coordinates`. 

 

EXAMPLES:: 

 

sage: Partition([4,3,2]).beta_numbers() 

[6, 4, 2] 

sage: Partition([4,3,2]).beta_numbers(5) 

[8, 6, 4, 1, 0] 

sage: Partition([]).beta_numbers() 

[] 

sage: Partition([]).beta_numbers(3) 

[2, 1, 0] 

sage: Partition([6,4,1,1]).beta_numbers() 

[9, 6, 2, 1] 

sage: Partition([6,4,1,1]).beta_numbers(6) 

[11, 8, 4, 3, 1, 0] 

sage: Partition([1,1,1]).beta_numbers() 

[3, 2, 1] 

sage: Partition([1,1,1]).beta_numbers(4) 

[4, 3, 2, 0] 

""" 

true_length = len(self) 

if length is None: 

length = true_length 

elif length < true_length: 

raise ValueError("length must be at least the length of the partition") 

beta = [l + length - i - 1 for (i, l) in enumerate(self)] 

if length > true_length: 

beta.extend(list(range(length-true_length-1,-1,-1))) 

return beta 

 

def crank(self): 

r""" 

Return the Dyson crank of ``self``. 

 

The Dyson crank of a partition `\lambda` is defined as follows: 

If `\lambda` contains at least one `1`, then the crank is 

`\mu(\lambda) - \omega(\lambda)`, where `\omega(\lambda)` is the 

number of `1`s in `\lambda`, and `\mu(\lambda)` is the number of 

parts of `\lambda` larger than `\omega(\lambda)`. If `\lambda` 

contains no `1`, then the crank is simply the largest part of 

`\lambda`. 

 

REFERENCES: 

 

.. [AG1988] George E. Andrews, F. G. Garvan, 

*Dyson's crank of a partition*. 

Bull. Amer. Math. Soc. (N.S.) Volume 18, Number 2 (1988), 

167-171. 

http://projecteuclid.org/euclid.bams/1183554533 

 

EXAMPLES:: 

 

sage: Partition([]).crank() 

0 

sage: Partition([3,2,2]).crank() 

3 

sage: Partition([5,4,2,1,1]).crank() 

0 

sage: Partition([1,1,1]).crank() 

-3 

sage: Partition([6,4,4,3]).crank() 

6 

sage: Partition([6,3,3,1,1]).crank() 

1 

sage: Partition([6]).crank() 

6 

sage: Partition([5,1]).crank() 

0 

sage: Partition([4,2]).crank() 

4 

sage: Partition([4,1,1]).crank() 

-1 

sage: Partition([3,3]).crank() 

3 

sage: Partition([3,2,1]).crank() 

1 

sage: Partition([3,1,1,1]).crank() 

-3 

sage: Partition([2,2,2]).crank() 

2 

sage: Partition([2,2,1,1]).crank() 

-2 

sage: Partition([2,1,1,1,1]).crank() 

-4 

sage: Partition([1,1,1,1,1,1]).crank() 

-6 

""" 

l = len(self) 

if l == 0: 

return 0 

if self[-1] > 1: 

return self[0] 

ind_1 = self.index(1) 

w = l - ind_1 # w is omega(self). 

m = len([x for x in self if x > w]) 

return m - w 

 

def t_completion(self, t): 

r""" 

Return the ``t``-completion of the partition ``self``. 

 

If `\lambda = (\lambda_1, \lambda_2, \lambda_3, \ldots)` is a 

partition and `t` is an integer greater or equal to 

`\left\lvert \lambda \right\rvert + \lambda_1`, then the 

`t`-*completion of* `\lambda` is defined as the partition 

`(t - \left\lvert \lambda \right\rvert, \lambda_1, \lambda_2, 

\lambda_3, \ldots)` of `t`. This partition is denoted by `\lambda[t]` 

in [BOR09]_, by `\lambda_{[t]}` in [BdVO12]_, and by `\lambda(t)` 

in [CO10]_. 

 

REFERENCES: 

 

.. [BOR09] Emmanuel Briand, Rosa Orellana, Mercedes Rosas. 

*The stability of the Kronecker products of Schur 

functions*. 

:arxiv:`0907.4652v2`. 

 

.. [CO10] Jonathan Comes, Viktor Ostrik. 

*On blocks of Deligne's category* 

`\underline{\mathrm{Rep}}(S_t)`. 

:arxiv:`0910.5695v2`, 

http://pages.uoregon.edu/jcomes/blocks.pdf 

 

.. [BdVO12] Christopher Bowman, Maud De Visscher, Rosa Orellana. 

*The partition algebra and the Kronecker coefficients*. 

:arXiv:`1210.5579v6`. 

 

EXAMPLES:: 

 

sage: Partition([]).t_completion(0) 

[] 

sage: Partition([]).t_completion(1) 

[1] 

sage: Partition([]).t_completion(2) 

[2] 

sage: Partition([]).t_completion(3) 

[3] 

sage: Partition([2, 1]).t_completion(5) 

[2, 2, 1] 

sage: Partition([2, 1]).t_completion(6) 

[3, 2, 1] 

sage: Partition([4, 2, 2, 1]).t_completion(13) 

[4, 4, 2, 2, 1] 

sage: Partition([4, 2, 2, 1]).t_completion(19) 

[10, 4, 2, 2, 1] 

sage: Partition([4, 2, 2, 1]).t_completion(10) 

Traceback (most recent call last): 

... 

ValueError: 10-completion is not defined 

sage: Partition([4, 2, 2, 1]).t_completion(5) 

Traceback (most recent call last): 

... 

ValueError: 5-completion is not defined 

""" 

if self._list and t < self.size() + self._list[0]: 

raise ValueError("{}-completion is not defined".format(t)) 

return Partition([t - self.size()] + self._list) 

 

def larger_lex(self, rhs): 

""" 

Return ``True`` if ``self`` is larger than ``rhs`` in lexicographic 

order. Otherwise return ``False``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2]) 

sage: p.larger_lex([3,1]) 

True 

sage: p.larger_lex([1,4]) 

True 

sage: p.larger_lex([3,2,1]) 

False 

sage: p.larger_lex([3]) 

True 

sage: p.larger_lex([5]) 

False 

sage: p.larger_lex([3,1,1,1,1,1,1,1]) 

True 

""" 

return CombinatorialElement.__gt__(self, rhs) 

 

def dominates(self, p2): 

r""" 

Return ``True`` if ``self`` dominates the partition ``p2``. Otherwise 

it returns ``False``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2]) 

sage: p.dominates([3,1]) 

True 

sage: p.dominates([2,2]) 

True 

sage: p.dominates([2,1,1]) 

True 

sage: p.dominates([3,3]) 

False 

sage: p.dominates([4]) 

False 

sage: Partition([4]).dominates(p) 

False 

sage: Partition([]).dominates([1]) 

False 

sage: Partition([]).dominates([]) 

True 

sage: Partition([1]).dominates([]) 

True 

""" 

p1 = self 

sum1 = 0 

sum2 = 0 

min_length = min(len(p1), len(p2)) 

if min_length == 0: 

return not p2 # equivalent to len(p1) >= len(p2) = 0 

 

for i in range(min_length): 

sum1 += p1[i] 

sum2 += p2[i] 

if sum2 > sum1: 

return False 

return sum(p1) >= sum(p2) 

 

def cells(self): 

""" 

Return the coordinates of the cells of ``self``. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).cells() 

[(0, 0), (0, 1), (1, 0), (1, 1)] 

sage: Partition([3,2]).cells() 

[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)] 

""" 

res = [] 

for i in range(len(self)): 

for j in range(self[i]): 

res.append( (i,j) ) 

return res 

 

def generalized_pochhammer_symbol(self, a, alpha): 

r""" 

Return the generalized Pochhammer symbol 

`(a)_{self}^{(\alpha)}`. This is the product over all 

cells `(i,j)` in ``self`` of `a - (i-1) / \alpha + j - 1`. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).generalized_pochhammer_symbol(2,1) 

12 

""" 

res = 1 

for (i,j) in self.cells(): 

res *= (a - (i-1)/alpha + j-1) 

return res 

 

def get_part(self, i, default=Integer(0)): 

r""" 

Return the `i^{th}` part of ``self``, or ``default`` if it does 

not exist. 

 

EXAMPLES:: 

 

sage: p = Partition([2,1]) 

sage: p.get_part(0), p.get_part(1), p.get_part(2) 

(2, 1, 0) 

sage: p.get_part(10,-1) 

-1 

sage: Partition([]).get_part(0) 

0 

""" 

if i < len(self._list): 

return self._list[i] 

else: 

return default 

 

@combinatorial_map(name="partition to minimal Dyck word") 

def to_dyck_word(self, n=None): 

r""" 

Return the ``n``-Dyck word whose corresponding partition is 

``self`` (or, if ``n`` is not specified, the `n`-Dyck word with 

smallest `n` to satisfy this property). 

 

If `w` is an `n`-Dyck word (that is, a Dyck word with `n` open 

symbols and `n` close symbols), then the Dyck path corresponding 

to `w` can be regarded as a lattice path in the northeastern 

half of an `n \times n`-square. The region to the northeast of 

this Dyck path can be regarded as a partition. It is called the 

partition corresponding to the Dyck word `w`. (See 

:meth:`~sage.combinat.dyck_word.DyckWord.to_partition`.) 

 

For every partition `\lambda` and every nonnegative integer `n`, 

there exists at most one `n`-Dyck word `w` such that the 

partition corresponding to `w` is `\lambda` (in fact, such `w` 

exists if and only if `\lambda_i + i \leq n` for every `i`, 

where `\lambda` is written in the form 

`(\lambda_1, \lambda_2, \ldots, \lambda_k)` with `\lambda_k > 0`). 

This method computes this `w` for a given `\lambda` and `n`. 

If `n` is not specified, this method computes the `w` for the 

smallest possible `n` for which such an `w` exists. 

(The minimality of `n` means that the partition demarcated by the 

Dyck path touches the diagonal.) 

 

EXAMPLES:: 

 

sage: Partition([2,2]).to_dyck_word() 

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

sage: Partition([2,2]).to_dyck_word(4) 

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

sage: Partition([2,2]).to_dyck_word(5) 

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

sage: Partition([6,3,1]).to_dyck_word() 

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

sage: Partition([]).to_dyck_word() 

[] 

sage: Partition([]).to_dyck_word(3) 

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

 

The partition corresponding to ``self.dyck_word()`` is ``self`` 

indeed:: 

 

sage: all( p.to_dyck_word().to_partition() == p 

....: for p in Partitions(5) ) 

True 

""" 

from sage.combinat.dyck_word import DyckWord 

if not self._list: 

if n is None: 

return DyckWord([]) 

return DyckWord([1]*n + [0]*n) 

list_of_word = [] 

if n is None: 

n = max(i + l + 1 for (i, l) in enumerate(self)) 

# This n is also max(i+j for (i,j) in self.cells()) + 2. 

list_of_word.extend([1]*(n-self.length())) 

copy_part = list(self) 

while copy_part: 

c = copy_part.pop() 

list_of_word.extend([0]*c) 

for i in range(len(copy_part)): 

copy_part[i] -= c 

list_of_word.append(1) 

list_of_word.extend([0]*(n-self[0])) 

return DyckWord(list_of_word) 

 

@combinatorial_map(order=2, name="conjugate partition") 

def conjugate(self): 

""" 

Return the conjugate partition of the partition ``self``. This 

is also called the associated partition or the transpose in the 

literature. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).conjugate() 

[2, 2] 

sage: Partition([6,3,1]).conjugate() 

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

 

The conjugate partition is obtained by transposing the Ferrers 

diagram of the partition (see :meth:`.ferrers_diagram`):: 

 

sage: print(Partition([6,3,1]).ferrers_diagram()) 

****** 

*** 

* 

sage: print(Partition([6,3,1]).conjugate().ferrers_diagram()) 

*** 

** 

** 

* 

* 

* 

""" 

p = list(self) 

if p == []: 

return self 

l = len(p) 

conj = [l] * p[-1] 

for i in range(l - 1, 0, -1): 

conj.extend([i] * (p[i - 1] - p[i])) 

return Partition(conj) 

 

def suter_diagonal_slide(self, n, exp=1): 

r""" 

Return the image of ``self`` in `Y_n` under Suter's diagonal slide 

`\sigma_n`, where the notations used are those defined in [Sut2002]_. 

 

The set `Y_n` is defined as the set of all partitions 

`\lambda` such that the hook length of the `(0, 0)`-cell (i.e. the 

northwestern most cell in English notation) of `\lambda` is less 

than `n`, including the empty partition. 

 

The map `\sigma_n` sends a partition (with non-zero entries) 

`(\lambda_1, \lambda_2, \ldots, \lambda_m) \in Y_n` to the partition 

`(\lambda_2 + 1, \lambda_3 + 1, \ldots, \lambda_m + 1, 

\underbrace{1, 1, \ldots, 1}_{n - m - \lambda_1\text{ ones}})`. 

In other words, it pads the partition with trailing zeroes 

until it has length `n - \lambda_1`, then removes its first 

part, and finally adds `1` to each part. 

 

By Theorem 2.1 of [Sut2002]_, the dihedral group `D_n` with 

`2n` elements acts on `Y_n` by letting the primitive rotation 

act as `\sigma_n` and the reflection act as conjugation of 

partitions (:meth:`conjugate()`). This action is faithful if 

`n \geq 3`. 

 

INPUT: 

 

- ``n`` -- nonnegative integer 

 

- ``exp`` -- (default: 1) how many times `\sigma_n` should be applied 

 

OUTPUT: 

 

The result of applying Suter's diagonal slide `\sigma_n` to 

``self``, assuming that ``self`` lies in `Y_n`. If the 

optional argument ``exp`` is set, then the slide 

`\sigma_n` is applied not just once, but ``exp`` times 

(note that ``exp`` is allowed to be negative, since 

the slide has finite order). 

 

EXAMPLES:: 

 

sage: Partition([5,4,1]).suter_diagonal_slide(8) 

[5, 2] 

sage: Partition([5,4,1]).suter_diagonal_slide(9) 

[5, 2, 1] 

sage: Partition([]).suter_diagonal_slide(7) 

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

sage: Partition([]).suter_diagonal_slide(1) 

[] 

sage: Partition([]).suter_diagonal_slide(7, exp=-1) 

[6] 

sage: Partition([]).suter_diagonal_slide(1, exp=-1) 

[] 

sage: P7 = Partitions(7) 

sage: all( p == p.suter_diagonal_slide(9, exp=-1).suter_diagonal_slide(9) 

....: for p in P7 ) 

True 

sage: all( p == p.suter_diagonal_slide(9, exp=3) 

....: .suter_diagonal_slide(9, exp=3) 

....: .suter_diagonal_slide(9, exp=3) 

....: for p in P7 ) 

True 

sage: all( p == p.suter_diagonal_slide(9, exp=6) 

....: .suter_diagonal_slide(9, exp=6) 

....: .suter_diagonal_slide(9, exp=6) 

....: for p in P7 ) 

True 

sage: all( p == p.suter_diagonal_slide(9, exp=-1) 

....: .suter_diagonal_slide(9, exp=1) 

....: for p in P7 ) 

True 

 

Check of the assertion in [Sut2002]_ that `\sigma_n\bigl( \sigma_n( 

\lambda^{\prime})^{\prime} \bigr) = \lambda`:: 

 

sage: all( p.suter_diagonal_slide(8).conjugate() 

....: == p.conjugate().suter_diagonal_slide(8, exp=-1) 

....: for p in P7 ) 

True 

 

Check of Claim 1 in [Sut2002]_:: 

 

sage: P5 = Partitions(5) 

sage: all( all( (p.suter_diagonal_slide(6) in q.suter_diagonal_slide(6).down()) 

....: or (q.suter_diagonal_slide(6) in p.suter_diagonal_slide(6).down()) 

....: for p in q.down() ) 

....: for q in P5 ) 

True 

 

TESTS: 

 

Check for ``exp = 0``:: 

 

sage: P = Partitions(4) 

sage: all(p == p.suter_diagonal_slide(7, 0) for p in P) 

True 

 

Check for invalid input:: 

 

sage: p = Partition([2,1]) 

sage: p.hook_length(0, 0) 

3 

sage: p.suter_diagonal_slide(2) 

Traceback (most recent call last): 

... 

ValueError: the hook length must be less than n 

 

REFERENCES: 

 

.. [Sut2002] Ruedi Suter. 

*Young's Lattice and Dihedral Symmetries*. 

Europ. J. Combinatorics (2002) 23, 233--238. 

http://www.sciencedirect.com/science/article/pii/S0195669801905414 

""" 

# Check for valid input 

if len(self) > 0 and len(self) + self._list[0] > n: # >, not >=, since we double count the (0,0) cell 

raise ValueError("the hook length must be less than n") 

ret = self 

# Arbitrary exp 

exp = exp % n # It is at most order n 

if exp > n / 2: 

exp -= n 

while exp != 0: 

leng = len(ret) 

if exp > 0: 

# Suter's map \sigma_n 

if leng == 0: # Taking extra care about the empty partition. 

ret = Partition([1] * (n - 1)) 

exp -= 1 

continue 

res = [i + 1 for i in ret._list[1:]] 

res += [1] * (n - leng - ret._list[0]) 

ret = Partition(res) 

exp -= 1 

else: # exp < 0 since if exp == 0, we would exit the while loop 

# inverse map \sigma_n^{-1} 

if leng == 0: # Taking extra care about the empty partition. 

ret = Partition([n - 1]) 

exp += 1 

continue 

res = [n - leng - 1] 

res.extend([i - 1 for i in ret._list if i > 1]) 

ret = Partition(res) 

exp += 1 

return ret 

 

@combinatorial_map(name="reading tableau") 

def reading_tableau(self): 

r""" 

Return the RSK recording tableau of the reading word of the 

(standard) tableau `T` labeled down (in English convention) 

each column to the shape of ``self``. 

 

For an example of the tableau `T`, consider the partition 

`\lambda = (3,2,1)`, then we have:: 

 

1 4 6 

2 5 

3 

 

For more, see :func:`~sage.combinat.rsk.RSK()`. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).reading_tableau() 

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

""" 

st = tableau.StandardTableaux(self).first() 

return st.reading_word_permutation().right_tableau() 

 

@combinatorial_map(name="initial tableau") 

def initial_tableau(self): 

r""" 

Return the :class:`standard tableau<StandardTableau>` which has the 

numbers `1, 2, \ldots, n` where `n` is the :meth:`size` of ``self`` 

entered in order from left to right along the rows of each component, 

where the components are ordered from left to right. 

 

EXAMPLES:: 

 

sage: Partition([3,2,2]).initial_tableau() 

[[1, 2, 3], [4, 5], [6, 7]] 

""" 

mu = self._list 

# In Python 3, improve this using itertools.accumulate 

tab = [list(range(1+sum(mu[:i]), 1+sum(mu[:(i+1)]))) 

for i in range(len(mu))] 

return tableau.StandardTableau(tab) 

 

def initial_column_tableau(self): 

r""" 

Return the initial column tableau of shape ``self``. 

 

The initial column taleau of shape self is the standard tableau  

that has the numbers `1` to `n`, where `n` is the :meth:`size` of ``self``, 

entered in order from top to bottom and then left to right down the 

columns of ``self``. 

 

EXAMPLES:: 

 

sage: Partition([3,2]).initial_column_tableau() 

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

""" 

return self.conjugate().initial_tableau().conjugate() 

 

def garnir_tableau(self,*cell): 

r""" 

Return the Garnir tableau of shape ``self`` corresponding to the cell 

``cell``. If ``cell`` `= (a,c)` then `(a+1,c)` must belong to the 

diagram of ``self``. 

 

The Garnir tableaux play an important role in integral and 

non-semisimple representation theory because they determine the 

"straightening" rules for the Specht modules over an arbitrary ring. 

 

The Garnir tableaux are the "first" non-standard tableaux which arise 

when you act by simple transpositions. If `(a,c)` is a cell in the 

Young diagram of a partition, which is not at the bottom of its 

column, then the corresponding Garnir tableau has the integers 

`1, 2, \ldots, n` entered in order from left to right along the rows 

of the diagram up to the cell `(a,c-1)`, then along the cells 

`(a+1,1)` to `(a+1,c)`, then `(a,c)` until the end of row `a` and 

then continuing from left to right in the remaining positions. The 

examples below probably make this clearer! 

 

.. NOTE:: 

 

The function also sets ``g._garnir_cell``, where ``g`` is the 

resulting Garnir tableau, equal to ``cell`` which is used by 

some other functions. 

 

EXAMPLES:: 

 

sage: g=Partition([5,3,3,2]).garnir_tableau((0,2)); g.pp() 

1 2 6 7 8 

3 4 5 

9 10 11 

12 13 

sage: g.is_row_strict(); g.is_column_strict() 

True 

False 

 

sage: Partition([5,3,3,2]).garnir_tableau(0,2).pp() 

1 2 6 7 8 

3 4 5 

9 10 11 

12 13 

sage: Partition([5,3,3,2]).garnir_tableau(2,1).pp() 

1 2 3 4 5 

6 7 8 

9 12 13 

10 11 

sage: Partition([5,3,3,2]).garnir_tableau(2,2).pp() 

Traceback (most recent call last): 

... 

ValueError: (row+1, col) must be inside the diagram 

 

.. SEEALSO:: 

 

- :meth:`top_garnir_tableau` 

""" 

try: 

(row,col)=cell 

except ValueError: 

(row,col)=cell[0] 

 

if row+1>=len(self) or col>=self[row+1]: 

raise ValueError('(row+1, col) must be inside the diagram') 

g=self.initial_tableau().to_list() 

a=g[row][col] 

g[row][col:] = list(range(a+col+1,g[row+1][col]+1)) 

g[row+1][:col+1] = list(range(a,a+col+1)) 

g=tableau.Tableau(g) 

g._garnir_cell=(row,col) 

return g 

 

def top_garnir_tableau(self,e,cell): 

r""" 

Return the most dominant *standard* tableau which dominates the 

corresponding Garnir tableau and has the same ``e``-residue. 

 

The Garnir tableau play an important role in integral and non-semisimple 

representation theory because they determine the "straightening" rules 

for the Specht modules. The *top Garnir tableaux* arise in the graded 

representation theory of the symmetric groups and higher level Hecke 

algebras. They were introduced in [KMR]_. 

 

If the Garnir node is ``cell=(r,c)`` and `m` and `M` are the entries 

in the cells ``(r,c)`` and ``(r+1,c)``, respectively, in the initial 

tableau then the top ``e``-Garnir tableau is obtained by inserting the 

numbers `m, m+1, \ldots, M` in order from left to right first in the 

cells in row ``r+1`` which are not in the ``e``-Garnir belt, then in 

the cell in rows ``r`` and ``r+1`` which are in the Garnir belt and 

then, finally, in the remaining cells in row ``r`` which are not in 

the Garnir belt. All other entries in the tableau remain unchanged. 

 

If ``e = 0``, or if there are no ``e``-bricks in either row ``r`` 

or ``r+1``, then the top Garnir tableau is the corresponding Garnir 

tableau. 

 

EXAMPLES:: 

 

sage: Partition([5,4,3,2]).top_garnir_tableau(2,(0,2)).pp() 

1 2 4 5 8 

3 6 7 9 

10 11 12 

13 14 

sage: Partition([5,4,3,2]).top_garnir_tableau(3,(0,2)).pp() 

1 2 3 4 5 

6 7 8 9 

10 11 12 

13 14 

sage: Partition([5,4,3,2]).top_garnir_tableau(4,(0,2)).pp() 

1 2 6 7 8 

3 4 5 9 

10 11 12 

13 14 

sage: Partition([5,4,3,2]).top_garnir_tableau(0,(0,2)).pp() 

1 2 6 7 8 

3 4 5 9 

10 11 12 

13 14 

 

TESTS:: 

 

sage: Partition([5,4,3,2]).top_garnir_tableau(0,(3,2)).pp() 

Traceback (most recent call last): 

... 

ValueError: (4,2)=(row+1,col) must be inside the diagram 

 

REFERENCE: 

 

- [KMR]_ 

""" 

(row,col)=cell 

if row+1>=len(self) or col>=self[row+1]: 

raise ValueError('(%s,%s)=(row+1,col) must be inside the diagram' %(row+1,col)) 

 

g=self.garnir_tableau(cell) # start with the Garnir tableau and modify 

 

if e==0: return g # no more dominant tableau of the same residue 

 

a=e*int((self[row]-col)/e) # number of cells in the e-bricks in row `row` 

b=e*int((col+1)/e) # number of cells in the e-bricks in row `row+1` 

 

if a==0 or b==0: return g 

 

t=g.to_list() 

m=g[row+1][0] # smallest number in 0-Garnir belt 

# now we will put the number m,m+1,...,t[row+1][col] in order into t 

t[row][col:a+col]=[m+col-b+1+i for i in range(a)] 

t[row+1][col-b+1:col+1]=[m+a+col-b+1+i for i in range(b)] 

return tableau.StandardTableau(t) 

 

@cached_method 

def young_subgroup(self): 

r""" 

Return the corresponding Young, or parabolic, subgroup of the symmetric 

group. 

 

The Young subgroup of a partition 

`\lambda = (\lambda_1, \lambda_2, \ldots, \lambda_{\ell})` of `n` is 

the group: 

 

.. MATH:: 

 

S_{\lambda_1} \times S_{\lambda_2} \times \cdots \times 

S_{\lambda_{\ell}} 

 

embedded into `S_n` in the standard way (i.e., 

the `S_{\lambda_i}` factor acts on the numbers from 

`\lambda_1 + \lambda_2 + \cdots + \lambda_{i-1} + 1` to 

`\lambda_1 + \lambda_2 + \cdots + \lambda_i`). 

 

EXAMPLES:: 

 

sage: Partition([4,2]).young_subgroup() 

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

""" 

gens=[] 

m=0 

for row in self: 

gens.extend([ (c,c+1) for c in range(m+1,m+row)]) 

m+=row 

gens.append(list(range(1,self.size() + 1))) # to ensure we get a subgroup of Sym_n 

return PermutationGroup( gens ) 

 

def young_subgroup_generators(self): 

""" 

Return an indexing set for the generators of the corresponding Young 

subgroup. Here the generators correspond to the simple adjacent 

transpositions `s_i = (i \; i+1)`. 

 

EXAMPLES:: 

 

sage: Partition([4,2]).young_subgroup_generators() 

[1, 2, 3, 5] 

sage: Partition([1,1,1]).young_subgroup_generators() 

[] 

sage: Partition([2,2]).young_subgroup_generators() 

[1, 3] 

 

.. SEEALSO:: 

 

:meth:`young_subgroup` 

""" 

gens = [] 

m = 0 

for row in self: 

gens.extend(list(range(m + 1, m + row))) 

m += row 

return gens 

 

@cached_method 

def _initial_degree(self, e, multicharge=(0,)): 

r""" 

Return the Brundan-Kleshchev-Wang degree of the initial row tableau 

of shape ``self``. 

 

This degree depends only the shape of the tableau and it is 

used as the base case for computing the degrees of all tableau 

of shape ``self``, which is why this method is cached. See 

:meth:`sage.combinat.tableau.Tableau.degree` for more information. 

 

EXAMPLES:: 

 

sage: Partition([5,3,2])._initial_degree(0) 

0 

sage: Partition([5,3,2])._initial_degree(2) 

4 

sage: Partition([5,3,2])._initial_degree(3) 

2 

sage: Partition([5,3,2])._initial_degree(4) 

1 

""" 

if e == 0: 

return ZZ.zero() 

else: 

return sum(m // e for m in self) 

 

def degree(self, e): 

r""" 

Return the ``e``-th degree of ``self``. 

 

The `e`-th degree of a partition `\lambda` is the sum of the `e`-th 

degrees of the standard tableaux of shape `\lambda`. The `e`-th degree 

is the exponent of `\Phi_e(q)` in the Gram determinant of the Specht 

module for a semisimple Iwahori-Hecke algebra of type `A` with 

parameter `q`. 

 

INPUT: 

 

- ``e`` -- an integer `e > 1` 

 

OUTPUT: 

 

A non-negative integer. 

 

EXAMPLES:: 

 

sage: Partition([4,3]).degree(2) 

28 

sage: Partition([4,3]).degree(3) 

15 

sage: Partition([4,3]).degree(4) 

8 

sage: Partition([4,3]).degree(5) 

13 

sage: Partition([4,3]).degree(6) 

0 

sage: Partition([4,3]).degree(7) 

0 

 

Therefore, the Gram determinant of `S(5,3)` when the Hecke parameter 

`q` is "generic" is 

 

.. MATH:: 

 

q^N \Phi_2(q)^{28} \Phi_3(q)^{15} \Phi_4(q)^8 \Phi_5(q)^{13} 

 

for some integer `N`. Compare with :meth:`prime_degree`. 

""" 

return sum(t.degree(e) for t in self.standard_tableaux()) 

 

def prime_degree(self, p): 

r""" 

Return the prime degree for the prime integer``p`` for ``self``. 

 

INPUT: 

 

- ``p`` -- a prime integer 

 

OUTPUT: 

 

A non-negative integer  

 

The degree of a partition `\lambda` is the sum of the 

`e`-:meth:`degree` of the standard tableaux of shape `\lambda`, for 

`e` a poer of the prime `p`. The prime degree gives the exponent of 

`p` in the Gram determinant of the integral Specht module of the 

symmetric group. 

 

EXAMPLES:: 

 

sage: Partition([4,3]).prime_degree(2) 

36 

sage: Partition([4,3]).prime_degree(3) 

15 

sage: Partition([4,3]).prime_degree(5) 

13 

sage: Partition([4,3]).prime_degree(7) 

0 

 

THerefore, the Gram determinant of `S(5,3)` when `q = 1` is  

`2^{36} 3^{15} 5^{13}`. Compare with :meth:`degree`. 

""" 

ps = [p] 

 

while ps[-1] * p < self.size(): 

ps.append(ps[-1] * p) 

return sum(t.degree(pk) for pk in ps for t in self.standard_tableaux()) 

 

def arm_length(self, i, j): 

r""" 

Return the length of the arm of cell `(i,j)` in ``self``. 

 

The arm of cell `(i,j)` is the cells that appear to the right of 

cell `(i,j)`. 

 

The cell coordinates are zero-based, i. e., the northwesternmost 

cell is `(0,0)`. 

 

INPUT: 

 

- ``i, j`` -- two integers 

 

OUTPUT: 

 

An integer or a ``ValueError`` 

 

EXAMPLES:: 

 

sage: p = Partition([2,2,1]) 

sage: p.arm_length(0, 0) 

1 

sage: p.arm_length(0, 1) 

0 

sage: p.arm_length(2, 0) 

0 

sage: Partition([3,3]).arm_length(0, 0) 

2 

sage: Partition([3,3]).arm_length(*[0,0]) 

2 

""" 

p = self 

if i < len(p) and j < p[i]: 

return p[i]-(j+1) 

else: 

raise ValueError("The cell is not in the diagram") 

 

def arm_lengths(self, flat=False): 

""" 

Return a tableau of shape ``self`` where each cell is filled with 

its arm length. The optional boolean parameter ``flat`` provides 

the option of returning a flat list. 

 

EXAMPLES:: 

 

sage: Partition([2,2,1]).arm_lengths() 

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

sage: Partition([2,2,1]).arm_lengths(flat=True) 

[1, 0, 1, 0, 0] 

sage: Partition([3,3]).arm_lengths() 

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

sage: Partition([3,3]).arm_lengths(flat=True) 

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

""" 

p = self 

res = [[p[i]-(j+1) for j in range(p[i])] for i in range(len(p))] 

if flat: 

return sum(res, []) 

else: 

return res 

 

def arm_cells(self, i, j): 

r""" 

Return the list of the cells of the arm of cell `(i,j)` in ``self``. 

 

The arm of cell `c = (i,j)` is the boxes that appear to the right of 

`c`. 

 

The cell coordinates are zero-based, i. e., the northwesternmost 

cell is `(0,0)`. 

 

INPUT: 

 

- ``i, j`` -- two integers 

 

OUTPUT: 

 

A list of pairs of integers 

 

EXAMPLES:: 

 

sage: Partition([4,4,3,1]).arm_cells(1,1) 

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

 

sage: Partition([]).arm_cells(0,0) 

Traceback (most recent call last): 

... 

ValueError: The cell is not in the diagram 

 

""" 

p = self 

if i < len(p) and j < p[i]: 

return [ (i, x) for x in range(j+1, p[i]) ] 

else: 

raise ValueError("The cell is not in the diagram") 

 

 

def leg_length(self, i, j): 

""" 

Return the length of the leg of cell `(i,j)` in ``self``. 

 

The leg of cell `c = (i,j)` is defined to be the cells below `c` 

(in English convention). 

 

The cell coordinates are zero-based, i. e., the northwesternmost 

cell is `(0,0)`. 

 

INPUT: 

 

- ``i, j`` -- two integers 

 

OUTPUT: 

 

An integer or a ``ValueError`` 

 

EXAMPLES:: 

 

sage: p = Partition([2,2,1]) 

sage: p.leg_length(0, 0) 

2 

sage: p.leg_length(0,1) 

1 

sage: p.leg_length(2,0) 

0 

sage: Partition([3,3]).leg_length(0, 0) 

1 

sage: cell = [0,0]; Partition([3,3]).leg_length(*cell) 

1 

""" 

 

conj = self.conjugate() 

if j < len(conj) and i < conj[j]: 

return conj[j]-(i+1) 

else: 

raise ValueError("The cell is not in the diagram") 

 

def leg_lengths(self, flat=False): 

""" 

Return a tableau of shape ``self`` with each cell filled in with 

its leg length. The optional boolean parameter ``flat`` provides 

the option of returning a flat list. 

 

EXAMPLES:: 

 

sage: Partition([2,2,1]).leg_lengths() 

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

sage: Partition([2,2,1]).leg_lengths(flat=True) 

[2, 1, 1, 0, 0] 

sage: Partition([3,3]).leg_lengths() 

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

sage: Partition([3,3]).leg_lengths(flat=True) 

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

""" 

p = self 

conj = p.conjugate() 

res = [[conj[j]-(i+1) for j in range(p[i])] for i in range(len(p))] 

if flat: 

return sum(res, []) 

else: 

return res 

 

def leg_cells(self, i, j): 

r""" 

Return the list of the cells of the leg of cell `(i,j)` in ``self``. 

 

The leg of cell `c = (i,j)` is defined to be the cells below `c` (in 

English convention). 

 

The cell coordinates are zero-based, i. e., the northwesternmost 

cell is `(0,0)`. 

 

INPUT: 

 

- ``i, j`` -- two integers 

 

OUTPUT: 

 

A list of pairs of integers 

 

EXAMPLES:: 

 

sage: Partition([4,4,3,1]).leg_cells(1,1) 

[(2, 1)] 

sage: Partition([4,4,3,1]).leg_cells(0,1) 

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

 

sage: Partition([]).leg_cells(0,0) 

Traceback (most recent call last): 

... 

ValueError: The cell is not in the diagram 

""" 

l = self.leg_length(i, j) 

return [(x, j) for x in range(i+1, i+l+1)] 

 

def attacking_pairs(self): 

""" 

Return a list of the attacking pairs of the Young diagram of 

``self``. 

 

A pair of cells `(c, d)` of a Young diagram (in English notation) is 

said to be attacking if one of the following conditions holds: 

 

1. `c` and `d` lie in the same row with `c` strictly to the west 

of `d`. 

 

2. `c` is in the row immediately to the south of `d`, and `c` 

lies strictly east of `d`. 

 

This particular method returns each pair `(c, d)` as a tuple, 

where each of `c` and `d` is given as a tuple `(i, j)` with 

`i` and `j` zero-based (so `i = 0` means that the cell lies 

in the topmost row). 

 

EXAMPLES:: 

 

sage: p = Partition([3, 2]) 

sage: p.attacking_pairs() 

[((0, 0), (0, 1)), 

((0, 0), (0, 2)), 

((0, 1), (0, 2)), 

((1, 0), (1, 1)), 

((1, 1), (0, 0))] 

sage: Partition([]).attacking_pairs() 

[] 

""" 

attacking_pairs = [] 

for i, r in enumerate(self): 

for j in range(r): 

#c is in position (i,j) 

#Find the d that satisfy condition 1 

for k in range(j+1, r): 

attacking_pairs.append( ((i,j),(i,k)) ) 

 

#Find the d that satisfy condition 2 

if i == 0: 

continue 

for k in range(j): 

attacking_pairs.append( ((i,j),(i-1,k)) ) 

 

return attacking_pairs 

 

def dominated_partitions(self, rows=None): 

""" 

Return a list of the partitions dominated by `n`. If ``rows`` is 

specified, then it only returns the ones whose number of rows 

is at most ``rows``. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).dominated_partitions() 

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

sage: Partition([3,2,1]).dominated_partitions(rows=3) 

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

""" 

#Naive implementation because iteration is so fast 

n = sum(self) 

P = Partitions_n(n) 

if rows: 

return [P(x) for x in ZS1_iterator_nk(n, rows) if self.dominates(x)] 

else: 

return [P(x) for x in ZS1_iterator(n) if self.dominates(x)] 

 

def contains(self, x): 

""" 

Return ``True`` if ``x`` is a partition whose Ferrers diagram is 

contained in the Ferrers diagram of ``self``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2,1]) 

sage: p.contains([2,1]) 

True 

sage: all(p.contains(mu) for mu in Partitions(3)) 

True 

sage: all(p.contains(mu) for mu in Partitions(4)) 

False 

""" 

return len(self) >= len(x) and all(self[i] >= x[i] for i in range(len(x))) 

 

def hook_product(self, a): 

""" 

Return the Jack hook-product. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).hook_product(x) 

(2*x + 3)*(x + 2)^2 

sage: Partition([2,2]).hook_product(x) 

2*(x + 2)*(x + 1) 

""" 

 

nu = self.conjugate() 

res = 1 

for i in range(len(self)): 

for j in range(self[i]): 

res *= a*(self[i]-j-1)+nu[j]-i 

return res 

 

def hook_polynomial(self, q, t): 

""" 

Return the two-variable hook polynomial. 

 

EXAMPLES:: 

 

sage: R.<q,t> = PolynomialRing(QQ) 

sage: a = Partition([2,2]).hook_polynomial(q,t) 

sage: a == (1 - t)*(1 - q*t)*(1 - t^2)*(1 - q*t^2) 

True 

sage: a = Partition([3,2,1]).hook_polynomial(q,t) 

sage: a == (1 - t)^3*(1 - q*t^2)^2*(1 - q^2*t^3) 

True 

""" 

nu = self.conjugate() 

res = 1 

for i in range(len(self)): 

for j in range(self[i]): 

res *= 1-q**(self[i]-j-1)*t**(nu[j]-i) 

return res 

 

 

def hook_length(self, i, j): 

r""" 

Return the length of the hook of cell `(i,j)` in ``self``. 

 

The (length of the) hook of cell `(i,j)` of a partition `\lambda` 

is 

 

.. MATH:: 

 

\lambda_i + \lambda^{\prime}_j - i - j + 1 

 

where `\lambda^{\prime}` is the conjugate partition. In English 

convention, the hook length is the number of cells horizontally 

to the right and vertically below the cell `(i,j)` (including 

that cell). 

 

EXAMPLES:: 

 

sage: p = Partition([2,2,1]) 

sage: p.hook_length(0, 0) 

4 

sage: p.hook_length(0, 1) 

2 

sage: p.hook_length(2, 0) 

1 

sage: Partition([3,3]).hook_length(0, 0) 

4 

sage: cell = [0,0]; Partition([3,3]).hook_length(*cell) 

4 

""" 

return self.leg_length(i,j)+self.arm_length(i,j)+1 

 

def hooks(self): 

""" 

Return a sorted list of the hook lengths in ``self``. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).hooks() 

[5, 3, 3, 1, 1, 1] 

""" 

res = [] 

for row in self.hook_lengths(): 

res += row 

res.sort(reverse=True) 

return res 

 

def hook_lengths(self): 

r""" 

Return a tableau of shape ``self`` with the cells filled in with the 

hook lengths. 

 

In each cell, put the sum of one plus the number of cells 

horizontally to the right and vertically below the cell (the 

hook length). 

 

For example, consider the partition ``[3,2,1]`` of 6 with Ferrers 

diagram:: 

 

# # # 

# # 

# 

 

When we fill in the cells with the hook lengths, we obtain:: 

 

5 3 1 

3 1 

1 

 

EXAMPLES:: 

 

sage: Partition([2,2,1]).hook_lengths() 

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

sage: Partition([3,3]).hook_lengths() 

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

sage: Partition([3,2,1]).hook_lengths() 

[[5, 3, 1], [3, 1], [1]] 

sage: Partition([2,2]).hook_lengths() 

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

sage: Partition([5]).hook_lengths() 

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

 

REFERENCES: 

 

- http://mathworld.wolfram.com/HookLengthFormula.html 

""" 

p = self 

conj = p.conjugate() 

return [[p[i]-(i+1)+conj[j]-(j+1)+1 for j in range(p[i])] for i in range(len(p))] 

 

def upper_hook(self, i, j, alpha): 

r""" 

Return the upper hook length of the cell `(i,j)` in ``self``. 

When ``alpha = 1``, this is just the normal hook length. 

 

The upper hook length of a cell `(i,j)` in a partition 

`\kappa` is defined by 

 

.. MATH:: 

 

h^*_\kappa(i,j) = \kappa^\prime_j - i + \alpha(\kappa_i - j + 1). 

 

EXAMPLES:: 

 

sage: p = Partition([2,1]) 

sage: p.upper_hook(0,0,1) 

3 

sage: p.hook_length(0,0) 

3 

sage: [ p.upper_hook(i,j,x) for i,j in p.cells() ] 

[2*x + 1, x, x] 

""" 

p = self 

conj = self.conjugate() 

return conj[j] - (i+1) + alpha*(p[i]-j) 

 

def upper_hook_lengths(self, alpha): 

r""" 

Return a tableau of shape ``self`` with the cells filled in with the 

upper hook lengths. When ``alpha = 1``, these are just the normal hook 

lengths. 

 

The upper hook length of a cell `(i,j)` in a partition 

`\kappa` is defined by 

 

.. MATH:: 

 

h^*_\kappa(i,j) = \kappa^\prime_j - i + \alpha(\kappa_i - j + 1). 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).upper_hook_lengths(x) 

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

sage: Partition([3,2,1]).upper_hook_lengths(1) 

[[5, 3, 1], [3, 1], [1]] 

sage: Partition([3,2,1]).hook_lengths() 

[[5, 3, 1], [3, 1], [1]] 

""" 

p = self 

conj = p.conjugate() 

return [[conj[j] - (i+1) + alpha*(p[i]-j) for j in range(p[i])] for i in range(len(p))] 

 

def lower_hook(self, i, j, alpha): 

r""" 

Return the lower hook length of the cell `(i,j)` in ``self``. 

When ``alpha = 1``, this is just the normal hook length. 

 

The lower hook length of a cell `(i,j)` in a partition 

`\kappa` is defined by 

 

.. MATH:: 

 

h_*^\kappa(i,j) = \kappa^\prime_j - i + 1 + \alpha(\kappa_i - j). 

 

EXAMPLES:: 

 

sage: p = Partition([2,1]) 

sage: p.lower_hook(0,0,1) 

3 

sage: p.hook_length(0,0) 

3 

sage: [ p.lower_hook(i,j,x) for i,j in p.cells() ] 

[x + 2, 1, 1] 

""" 

p = self 

conj = self.conjugate() 

return conj[j] - i + alpha*(p[i] - (j+1)) 

 

def lower_hook_lengths(self, alpha): 

r""" 

Return a tableau of shape ``self`` with the cells filled in with the 

lower hook lengths. When ``alpha = 1``, these are just the normal hook 

lengths. 

 

The lower hook length of a cell `(i,j)` in a partition 

`\kappa` is defined by 

 

.. MATH:: 

 

h_*^\kappa(i,j) = \kappa^\prime_j - i + 1 + \alpha(\kappa_i - j). 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).lower_hook_lengths(x) 

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

sage: Partition([3,2,1]).lower_hook_lengths(1) 

[[5, 3, 1], [3, 1], [1]] 

sage: Partition([3,2,1]).hook_lengths() 

[[5, 3, 1], [3, 1], [1]] 

""" 

p = self 

conj = p.conjugate() 

return [[conj[j] - i + alpha*(p[i]-(j+1)) for j in range(p[i])] for i in range(len(p))] 

 

 

def weighted_size(self): 

r""" 

Return the weighted size of ``self``. 

 

The weighted size of a partition `\lambda` is 

 

.. MATH:: 

 

\sum_i i \cdot \lambda_i, 

 

where `\lambda = (\lambda_0, \lambda_1, \lambda_2, \cdots )`. 

 

This also the sum of the leg length of every cell in `\lambda`, or 

 

.. MATH:: 

 

\sum_i \binom{\lambda^{\prime}_i}{2} 

 

where `\lambda^{\prime}` is the conjugate partition of `\lambda`. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).weighted_size() 

2 

sage: Partition([3,3,3]).weighted_size() 

9 

sage: Partition([5,2]).weighted_size() 

2 

sage: Partition([]).weighted_size() 

0 

""" 

p = self 

return sum([i*p[i] for i in range(len(p))]) 

 

def is_empty(self): 

""" 

Return ``True`` if ``self`` is the empty partition. 

 

EXAMPLES:: 

 

sage: Partition([]).is_empty() 

True 

sage: Partition([2,1,1]).is_empty() 

False 

""" 

return len(self) == 0 

 

def length(self): 

""" 

Return the number of parts in ``self``. 

 

EXAMPLES:: 

 

sage: Partition([3,2]).length() 

2 

sage: Partition([2,2,1]).length() 

3 

sage: Partition([]).length() 

0 

""" 

return len(self) 

 

def to_exp(self, k=0): 

""" 

Return a list of the multiplicities of the parts of a partition. 

Use the optional parameter ``k`` to get a return list of length at 

least ``k``. 

 

EXAMPLES:: 

 

sage: Partition([3,2,2,1]).to_exp() 

[1, 2, 1] 

sage: Partition([3,2,2,1]).to_exp(5) 

[1, 2, 1, 0, 0] 

 

TESTS:: 

 

sage: [parent(x) for x in Partition([3,2,2,1]).to_exp(5)] 

[Integer Ring, Integer Ring, Integer Ring, Integer Ring, Integer Ring] 

""" 

p = self 

if len(p) > 0: 

k = max(k, p[0]) 

a = [ZZ.zero()] * k 

for i in p: 

a[i-1] += 1 

return a 

 

def evaluation(self): 

r""" 

Return the evaluation of ``self``. 

 

The **commutative evaluation**, often shortened to **evaluation**, of 

a word (we think of a partition as a word in `\{1, 2, 3, \ldots\}`) 

is its image in the free commutative monoid. In other words, 

this counts how many occurrences there are of each letter. 

 

This is also is known as **Parikh vector** and **abelianization** and 

has the same output as :meth:`to_exp()`. 

 

EXAMPLES:: 

 

sage: Partition([4,3,1,1]).evaluation() 

[2, 0, 1, 1] 

""" 

return self.to_exp() 

 

def to_exp_dict(self): 

""" 

Return a dictionary containing the multiplicities of the parts of 

``self``. 

 

EXAMPLES:: 

 

sage: p = Partition([4,2,2,1]) 

sage: d = p.to_exp_dict() 

sage: d[4] 

1 

sage: d[2] 

2 

sage: d[1] 

1 

sage: 5 in d 

False 

""" 

d = {} 

for part in self: 

d[part] = d.get(part, 0) + 1 

return d 

 

def centralizer_size(self, t=0, q=0): 

r""" 

Return the size of the centralizer of any permutation of cycle type 

``self``. 

 

If `m_i` is the multiplicity of `i` as a part of `p`, this is given by 

 

.. MATH:: 

 

\prod_i m_i! i^{m_i}. 

 

Including the optional parameters `t` and `q` gives the `q,t` analog, 

which is the former product times 

 

.. MATH:: 

 

\prod_{i=1}^{\mathrm{length}(p)} \frac{1 - q^{p_i}}{1 - t^{p_i}}. 

 

See [Ker]_. 

 

EXAMPLES:: 

 

sage: Partition([2,2,1]).centralizer_size() 

8 

sage: Partition([2,2,2]).centralizer_size() 

48 

sage: Partition([2,2,1]).centralizer_size(q=2, t=3) 

9/16 

sage: Partition([]).centralizer_size() 

1 

sage: Partition([]).centralizer_size(q=2, t=4) 

1 

""" 

size = prod(i ** mi * factorial(mi) 

for i, mi in six.iteritems(self.to_exp_dict())) 

if t or q: 

size *= prod((ZZ.one() - q ** j) / (ZZ.one() - t ** j) 

for j in self) 

 

return size 

 

def aut(self): 

r""" 

Return a factor for the number of permutations with cycle type 

``self``. 

 

This method returns `1^{j_1}j_1! \cdots n^{j_n}j_n!` where 

`j_k` is the number of parts in ``self`` equal to `k`. 

 

The number of permutations having ``self`` as a cycle type is 

given by 

 

.. MATH:: 

 

\frac{n!}{1^{j_1}j_1! \cdots n^{j_n}j_n!} 

 

(where `n` is the size of ``self``). 

 

EXAMPLES:: 

 

sage: Partition([2,1]).aut() 

2 

""" 

m = self.to_exp() 

return prod([(i+1)**m[i]*factorial(m[i]) for i in range(len(m)) if m[i] > 0]) 

 

def content(self, r, c, multicharge=(0,)): 

r""" 

Return the content of the cell at row `r` and column `c`. 

 

The content of a cell is `c - r`. 

 

For consistency with partition tuples there is also an optional 

``multicharge`` argument which is an offset to the usual content. By 

setting the ``multicharge`` equal to the 0-element of the ring 

`\ZZ/e\ZZ`, the corresponding `e`-residue will be returned. This is 

the content modulo `e`. 

 

The content (and residue) do not strictly depend on the partition, 

however, this method is included because it is often useful in the 

context of partitions. 

 

EXAMPLES:: 

 

sage: Partition([2,1]).content(1,0) 

-1 

sage: p = Partition([3,2]) 

sage: sum([p.content(*c) for c in p.cells()]) 

2 

 

and now we return the 3-residue of a cell:: 

 

sage: Partition([2,1]).content(1,0, multicharge=[IntegerModRing(3)(0)]) 

2 

""" 

return c - r + multicharge[0] 

 

def residue(self, r, c, l): 

""" 

Return the ``l``-residue of the cell at row ``r`` and column ``c``. 

 

The `\ell`-residue of a cell is `c - r` modulo `\ell`. 

 

This does not strictly depend upon the partition, however, this method 

is included because it is often useful in the context of partitions. 

 

EXAMPLES:: 

 

sage: Partition([2,1]).residue(1, 0, 3) 

2 

""" 

return (c - r) % l 

 

def defect(self, e, multicharge=(0,)): 

r""" 

Return the ``e``-defect or the ``e``-weight of ``self``. 

 

The `e`-defect is the number of (connected) `e`-rim hooks that 

can be removed from the partition. 

 

The defect of a partition is given by  

 

.. MATH:: 

 

\text{defect}(\beta) = (\Lambda, \beta) - \tfrac12(\beta, \beta) 

 

where `\Lambda = \sum_r \Lambda_{\kappa_r}` for the multicharge 

`(\kappa_1, \ldots, \kappa_{\ell})` and  

`\beta = \sum_{(r,c)} \alpha_{(c-r) \pmod e}`, with the sum 

being over the cells in the partition. 

 

EXAMPLES:: 

 

sage: Partition([4,3,2]).defect(3) 

3 

sage: Partition([0]).defect(3) 

0 

sage: Partition([3]).defect(3) 

1 

sage: Partition([6]).defect(3) 

2 

sage: Partition([9]).defect(3) 

3 

sage: Partition([12]).defect(3) 

4 

 

TESTS:: 

 

sage: all(mu.core(e).size() + e * mu.defect(e) == 9 

....: for mu in Partitions(9) for e in [2,3,4]) 

True 

""" 

beta = [0]*e # element of positive root lattice corresponding to the block 

 

Ie = IntegerModRing(e) 

for (r,c) in self.cells(): 

beta[Ie(r-c)] += 1 

 

return beta[multicharge[0]] - sum(beta[i]**2 - beta[i] * beta[Ie(i+1)] 

for i in range(e)) 

 

def conjugacy_class_size(self): 

""" 

Return the size of the conjugacy class of the symmetric group 

indexed by ``self``. 

 

EXAMPLES:: 

 

sage: Partition([2,2,2]).conjugacy_class_size() 

15 

sage: Partition([2,2,1]).conjugacy_class_size() 

15 

sage: Partition([2,1,1]).conjugacy_class_size() 

6 

 

REFERENCES: 

 

.. [Ker] Kerber, A. 'Algebraic Combinatorics via Finite Group Actions' 

1.3 p24 

""" 

 

return factorial(sum(self))/self.centralizer_size() 

 

def corners(self): 

r""" 

Return a list of the corners of the partition ``self``. 

 

A corner of a partition `\lambda` is a cell of the Young diagram 

of `\lambda` which can be removed from the Young diagram while 

still leaving a straight shape behind. 

 

The entries of the list returned are pairs of the form `(i,j)`, 

where `i` and `j` are the coordinates of the respective corner. 

The coordinates are counted from `0`. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).corners() 

[(0, 2), (1, 1), (2, 0)] 

sage: Partition([3,3,1]).corners() 

[(1, 2), (2, 0)] 

sage: Partition([]).corners() 

[] 

""" 

p = self 

if p.is_empty(): 

return [] 

 

lcors = [[0,p[0]-1]] 

nn = len(p) 

if nn == 1: 

return [tuple(_) for _ in lcors] 

 

lcors_index = 0 

for i in range(1, nn): 

if p[i] == p[i-1]: 

lcors[lcors_index][0] += 1 

else: 

lcors.append([i,p[i]-1]) 

lcors_index += 1 

 

return [tuple(_) for _ in lcors] 

 

inside_corners = corners 

removable_cells = corners # for compatibility with partition tuples 

 

def corners_residue(self, i, l): 

r""" 

Return a list of the corners of the partition ``self`` having 

``l``-residue ``i``. 

 

A corner of a partition `\lambda` is a cell of the Young diagram 

of `\lambda` which can be removed from the Young diagram while 

still leaving a straight shape behind. See :meth:`residue` for 

the definition of the ``l``-residue. 

 

The entries of the list returned are pairs of the form `(i,j)`, 

where `i` and `j` are the coordinates of the respective corner. 

The coordinates are counted from `0`. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).corners_residue(0, 3) 

[(1, 1)] 

sage: Partition([3,2,1]).corners_residue(1, 3) 

[(2, 0)] 

sage: Partition([3,2,1]).corners_residue(2, 3) 

[(0, 2)] 

""" 

return [x for x in self.corners() if self.residue(*x, l=l) == i] 

 

inside_corners_residue = corners_residue 

removable_cells_residue = corners_residue 

 

def outside_corners(self): 

r""" 

Return a list of the outside corners of the partition ``self``. 

 

An outside corner (also called a cocorner) of a partition 

`\lambda` is a cell on `\ZZ^2` which does not belong to 

the Young diagram of `\lambda` but can be added to this Young 

diagram to still form a straight-shape Young diagram. 

 

The entries of the list returned are pairs of the form `(i,j)`, 

where `i` and `j` are the coordinates of the respective corner. 

The coordinates are counted from `0`. 

 

EXAMPLES:: 

 

sage: Partition([2,2,1]).outside_corners() 

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

sage: Partition([2,2]).outside_corners() 

[(0, 2), (2, 0)] 

sage: Partition([6,3,3,1,1,1]).outside_corners() 

[(0, 6), (1, 3), (3, 1), (6, 0)] 

sage: Partition([]).outside_corners() 

[(0, 0)] 

""" 

p = self 

if p.is_empty(): 

return [(0,0)] 

res = [ (0, p[0]) ] 

for i in range(1, len(p)): 

if p[i-1] != p[i]: 

res.append((i,p[i])) 

res.append((len(p), 0)) 

 

return res 

 

addable_cells = outside_corners # for compatibility with partition tuples 

 

def outside_corners_residue(self, i, l): 

r""" 

Return a list of the outside corners of the partition ``self`` 

having ``l``-residue ``i``. 

 

An outside corner (also called a cocorner) of a partition 

`\lambda` is a cell on `\ZZ^2` which does not belong to 

the Young diagram of `\lambda` but can be added to this Young 

diagram to still form a straight-shape Young diagram. See 

:meth:`residue` for the definition of the ``l``-residue. 

 

The entries of the list returned are pairs of the form `(i,j)`, 

where `i` and `j` are the coordinates of the respective corner. 

The coordinates are counted from `0`. 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).outside_corners_residue(0, 3) 

[(0, 3), (3, 0)] 

sage: Partition([3,2,1]).outside_corners_residue(1, 3) 

[(1, 2)] 

sage: Partition([3,2,1]).outside_corners_residue(2, 3) 

[(2, 1)] 

""" 

return [x for x in self.outside_corners() if self.residue(*x, l=l) == i] 

 

addable_cells_residue = outside_corners_residue 

 

def rim(self): 

r""" 

Return the rim of ``self``. 

 

The rim of a partition `\lambda` is defined as the cells which belong 

to `\lambda` and which are adjacent to cells not in `\lambda`. 

 

EXAMPLES: 

 

The rim of the partition `[5,5,2,1]` consists of the cells marked with 

``#`` below:: 

 

****# 

*#### 

## 

# 

 

sage: Partition([5,5,2,1]).rim() 

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

 

sage: Partition([2,2,1]).rim() 

[(2, 0), (1, 0), (1, 1), (0, 1)] 

sage: Partition([2,2]).rim() 

[(1, 0), (1, 1), (0, 1)] 

sage: Partition([6,3,3,1,1]).rim() 

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

sage: Partition([]).rim() 

[] 

""" 

p = self 

res = [] 

prevLen = 1 

for i in range(len(p)-1, -1, -1): 

for c in range(prevLen-1, p[i]): 

res.append((i,c)) 

prevLen = p[i] 

return res 

 

def outer_rim(self): 

r""" 

Return the outer rim of ``self``. 

 

The outer rim of a partition `\lambda` is defined as the cells which do 

not belong to `\lambda` and which are adjacent to cells in `\lambda`. 

 

EXAMPLES: 

 

The outer rim of the partition `[4,1]` consists of the cells marked 

with ``#`` below:: 

 

****# 

*#### 

## 

 

:: 

 

sage: Partition([4,1]).outer_rim() 

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

 

sage: Partition([2,2,1]).outer_rim() 

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

sage: Partition([2,2]).outer_rim() 

[(2, 0), (2, 1), (2, 2), (1, 2), (0, 2)] 

sage: Partition([6,3,3,1,1]).outer_rim() 

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

sage: Partition([]).outer_rim() 

[(0, 0)] 

""" 

p = self 

res = [] 

prevLen = 0 

for i in range(len(p)-1, -1, -1): 

for c in range(prevLen, p[i]+1): 

res.append((i+1,c)) 

prevLen = p[i] 

res.append((0, prevLen)) 

return res 

 

def zero_one_sequence(self): 

r""" 

Compute the finite `0-1` sequence of the partition. 

 

The full `0-1` sequence is the sequence (infinite in both 

directions) indicating the steps taken when following the 

outer rim of the diagram of the partition. We use the convention 

that in English convention, a 1 corresponds to an East step, and 

a 0 corresponds to a North step. 

 

Note that every full `0-1` sequence starts with infinitely many 0's and 

ends with infinitely many 1's. 

 

One place where these arise is in the affine symmetric group where 

one takes an affine permutation `w` and every `i` such that 

`w(i) \leq 0` corresponds to a 1 and `w(i) > 0` corresponds to a 0. 

See pages 24-25 of [LLMMSZ13]_ for connections to affine Grassmannian 

elements (note there they use the French convention for their 

partitions). 

 

These are also known as **path sequences**, **Maya diagrams**, 

**plus-minus diagrams**, **Comet code** [Sta-EC2]_, among others. 

 

OUTPUT: 

 

The finite `0-1` sequence is obtained from the full `0-1` 

sequence by omitting all heading 0's and trailing 1's. The 

output sequence is finite, starts with a 1 and ends with a 

0 (unless it is empty, for the empty partition). Its length 

is the sum of the first part of the partition with the 

length of the partition. 

 

REFERENCES: 

 

.. [LLMMSZ13] Thomas Lam, Luc Laponte, Jennifer Morse, Anne Schilling, 

Mark Shimozono, and Mike Zabrocki. `k`-Schur Functions and Affine 

Schubert Calculus. 2013. :arxiv:`1301.3569`. 

 

EXAMPLES:: 

 

sage: Partition([5,4]).zero_one_sequence() 

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

sage: Partition([]).zero_one_sequence() 

[] 

sage: Partition([2]).zero_one_sequence() 

[1, 1, 0] 

 

TESTS:: 

 

sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n)) 

True 

""" 

tmp = [self[i]-i for i in range(len(self))] 

return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)]) 

 

def core(self, length): 

r""" 

Return the ``length``-core of the partition -- in the literature 

the core is commonly referred to as the `k`-core, `p`-core, 

`r`-core, ... . 

 

The `r`-core of a partition `\lambda` can be obtained by 

repeatedly removing rim hooks of size `r` from (the Young diagram 

of) `\lambda` until this is no longer possible. The remaining 

partition is the core. 

 

EXAMPLES:: 

 

sage: Partition([6,3,2,2]).core(3) 

[2, 1, 1] 

sage: Partition([]).core(3) 

[] 

sage: Partition([8,7,7,4,1,1,1,1,1]).core(3) 

[2, 1, 1] 

 

TESTS:: 

 

sage: Partition([3,3,3,2,1]).core(3) 

[] 

sage: Partition([10,8,7,7]).core(4) 

[] 

sage: Partition([21,15,15,9,6,6,6,3,3]).core(3) 

[] 

""" 

p = self 

#Normalize the length 

remainder = len(p) % length 

part = p[:] + [0]*remainder 

 

#Add the canonical vector to the partition 

part = [part[i-1] + len(part)-i for i in range(1, len(part)+1)] 

 

for e in range(length): 

k = e 

for i in reversed(range(1,len(part)+1)): 

if part[i-1] % length == e: 

part[i-1] = k 

k += length 

part.sort() 

part.reverse() 

 

#Remove the canonical vector 

part = [part[i-1]-len(part)+i for i in range(1, len(part)+1)] 

#Select the r-core 

return Partition([x for x in part if x != 0]) 

 

def quotient(self, length): 

r""" 

Return the quotient of the partition -- in the literature the 

quotient is commonly referred to as the `k`-quotient, `p`-quotient, 

`r`-quotient, ... . 

 

The `r`-quotient of a partition `\lambda` is a list of `r` 

partitions (labelled from `0` to `r-1`), constructed in the following 

way. Label each cell in the Young diagram of `\lambda` with its 

content modulo `r`. Let `R_i` be the set of rows ending in a cell 

labelled `i`, and `C_i` be the set of columns ending in a cell 

labelled `i`. Then the `j`-th component of the quotient of 

`\lambda` is the partition defined by intersecting `R_j` with 

`C_{j+1}`. (See Theorem 2.7.37 in [JamesKerber]_.) 

 

REFERENCES: 

 

.. [JamesKerber] Gordon James, Adalbert Kerber, 

*The Representation Theory of the Symmetric Group*, 

Encyclopedia of Mathematics and its Applications, vol. 16, 

Addison-Wesley 1981. 

 

EXAMPLES:: 

 

sage: Partition([7,7,5,3,3,3,1]).quotient(3) 

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

 

TESTS:: 

 

sage: Partition([8,7,7,4,1,1,1,1,1]).quotient(3) 

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

sage: Partition([10,8,7,7]).quotient(4) 

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

sage: Partition([6,3,3]).quotient(3) 

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

sage: Partition([3,3,3,2,1]).quotient(3) 

([1], [1, 1], [1]) 

sage: Partition([6,6,6,3,3,3]).quotient(3) 

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

sage: Partition([21,15,15,9,6,6,6,3,3]).quotient(3) 

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

sage: Partition([21,15,15,9,6,6,3,3]).quotient(3) 

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

sage: Partition([14,12,11,10,10,10,10,9,6,4,3,3,2,1]).quotient(5) 

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

 

sage: all(p == Partition(core=p.core(k), quotient=p.quotient(k)) 

....: for i in range(10) for p in Partitions(i) 

....: for k in range(1,6)) 

True 

""" 

p = self 

#Normalize the length 

remainder = len(p) % length 

part = p[:] + [0]*(length-remainder) 

 

#Add the canonical vector to the partition 

part = [part[i-1] + len(part)-i for i in range(1, len(part)+1)] 

result = [None]*length 

 

#Reducing vector 

for e in range(length): 

k = e 

tmp = [] 

for i in reversed(range(len(part))): 

if part[i] % length == e: 

tmp.append(ZZ((part[i]-k)//length)) 

k += length 

 

a = [i for i in tmp if i != 0] 

a.reverse() 

result[e] = a 

 

from .partition_tuple import PartitionTuple 

return PartitionTuple(result) #tuple(map(Partition, result)) 

 

def is_core(self, k): 

r""" 

Tests whether the partition is a `k`-core or not. Visuallly, this can 

be checked by trying to remove border strips of size `k` from ``self``. 

If this is not possible, then ``self`` is a `k`-core. 

 

A partition is said to be a *`k`-core* if it has no hooks of length 

`k`. Equivalently, a partition is said to be a `k`-core if it is its 

own `k`-core (where the latter is defined as in :meth:`core`). 

 

EXAMPLES:: 

 

sage: p = Partition([12,8,5,5,2,2,1]) 

sage: p.is_core(4) 

False 

sage: p.is_core(5) 

True 

sage: p.is_core(0) 

True 

""" 

return not k in self.hooks() 

 

def k_interior(self, k): 

r""" 

Return the partition consisting of the cells of ``self`` whose hook 

lengths are greater than ``k``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2,1]) 

sage: p.hook_lengths() 

[[5, 3, 1], [3, 1], [1]] 

sage: p.k_interior(2) 

[2, 1] 

sage: p.k_interior(3) 

[1] 

 

sage: p = Partition([]) 

sage: p.k_interior(3) 

[] 

""" 

return Partition([len([i for i in row if i > k]) 

for row in self.hook_lengths()]) 

 

def k_boundary(self, k): 

r""" 

Return the skew partition formed by removing the cells of the 

``k``-interior, see :meth:`k_interior`. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2,1]) 

sage: p.k_boundary(2) 

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

sage: p.k_boundary(3) 

[3, 2, 1] / [1] 

 

sage: p = Partition([12,8,5,5,2,2,1]) 

sage: p.k_boundary(4) 

[12, 8, 5, 5, 2, 2, 1] / [8, 5, 2, 2] 

""" 

return SkewPartition([self, self.k_interior(k)]) 

 

def add_cell(self, i, j = None): 

r""" 

Return a partition corresponding to ``self`` with a cell added in 

row ``i``. (This does not change ``self``.) 

 

EXAMPLES:: 

 

sage: Partition([3, 2, 1, 1]).add_cell(0) 

[4, 2, 1, 1] 

sage: cell = [4, 0]; Partition([3, 2, 1, 1]).add_cell(*cell) 

[3, 2, 1, 1, 1] 

""" 

 

if j is None: 

if i >= len(self): 

j = 0 

else: 

j = self[i] 

 

if (i,j) in self.outside_corners(): 

pl = self.to_list() 

if i == len(pl): 

pl.append(1) 

else: 

pl[i] += 1 

return Partition(pl) 

 

raise ValueError("[%s, %s] is not an addable cell"%(i,j)) 

 

 

def remove_cell(self, i, j = None): 

""" 

Return the partition obtained by removing a cell at the end of row 

``i`` of ``self``. 

 

EXAMPLES:: 

 

sage: Partition([2,2]).remove_cell(1) 

[2, 1] 

sage: Partition([2,2,1]).remove_cell(2) 

[2, 2] 

sage: #Partition([2,2]).remove_cell(0) 

 

:: 

 

sage: Partition([2,2]).remove_cell(1,1) 

[2, 1] 

sage: #Partition([2,2]).remove_cell(1,0) 

""" 

 

if i >= len(self): 

raise ValueError("i must be less than the length of the partition") 

 

if j is None: 

j = self[i] - 1 

 

if (i,j) not in self.corners(): 

raise ValueError("[%d,%d] is not a corner of the partition" % (i,j)) 

 

if self[i] == 1: 

return Partition(self[:-1]) 

else: 

return Partition(self[:i] + [ self[i:i+1][0] - 1 ] + self[i+1:]) 

 

def k_irreducible(self, k): 

r""" 

Return the partition with all `r \times (k+1-r)` rectangles removed. 

 

If ``self`` is a `k`-bounded partition, then this method will return the partition 

where all rectangles of dimension `r \times (k+1-r)` for `1 \leq r \leq k` 

have been deleted. 

 

If ``self`` is not a `k`-bounded partition then the method will raise an error. 

 

INPUT: 

 

- ``k`` -- a non-negative integer 

 

OUTPUT: 

 

- a partition 

 

EXAMPLES:: 

 

sage: Partition([3,2,2,1,1,1]).k_irreducible(4) 

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

sage: Partition([3,2,2,1,1,1]).k_irreducible(3) 

[] 

sage: Partition([3,3,3,2,2,2,2,2,1,1,1,1]).k_irreducible(3) 

[2, 1] 

""" 

pexp = self.to_exp() 

return Partition(sum(([r+1] for r in range(len(pexp)-1,-1,-1) for m in range(pexp[r] % (k-r))),[])) 

 

def k_skew(self, k): 

r""" 

Return the `k`-skew partition. 

 

The `k`-skew diagram of a `k`-bounded partition is the skew diagram 

denoted `\lambda/^k` satisfying the conditions: 

 

1. row `i` of `\lambda/^k` has length `\lambda_i`, 

 

2. no cell in `\lambda/^k` has hook-length exceeding `k`, 

 

3. every square above the diagram of `\lambda/^k` has hook 

length exceeding `k`. 

 

REFERENCES: 

 

.. [LM2004] Lapointe, L. and Morse, J. 'Order Ideals in Weak Subposets 

of Young's Lattice and Associated Unimodality Conjectures'. Ann. 

Combin. (2004) 

 

EXAMPLES:: 

 

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

sage: p.k_skew(4) 

[9, 5, 3, 2, 1, 1] / [5, 2, 1] 

""" 

 

if len(self) == 0: 

return SkewPartition([[],[]]) 

 

if self[0] > k: 

raise ValueError("the partition must be %d-bounded" % k) 

 

#Find the k-skew diagram of the partition formed 

#by removing the first row 

s = Partition(self[1:]).k_skew(k) 

 

s_inner = list(s.inner()) 

s_outer = list(s.outer()) 

s_conj_rl = s.conjugate().row_lengths() 

 

#Find the leftmost column with less than 

# or equal to kdiff cells 

kdiff = k - self[0] 

 

if s_outer == []: 

spot = 0 

else: 

spot = s_outer[0] 

 

for i in range(len(s_conj_rl)): 

if s_conj_rl[i] <= kdiff: 

spot = i 

break 

 

outer = [ self[0] + spot ] + s_outer[:] 

if spot > 0: 

inner = [ spot ] + s_inner[:] 

else: 

inner = s_inner[:] 

 

return SkewPartition([outer, inner]) 

 

def to_core(self, k): 

r""" 

Maps the `k`-bounded partition ``self`` to its corresponding `k+1`-core. 

 

See also :meth:`k_skew`. 

 

EXAMPLES:: 

 

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

sage: c = p.to_core(4); c 

[9, 5, 3, 2, 1, 1] 

sage: type(c) 

<class 'sage.combinat.core.Cores_length_with_category.element_class'> 

sage: c.to_bounded_partition() == p 

True 

""" 

from sage.combinat.core import Core 

return Core(self.k_skew(k)[0],k+1) 

 

def from_kbounded_to_reduced_word(self, k): 

r""" 

Maps a `k`-bounded partition to a reduced word for an element in 

the affine permutation group. 

 

This uses the fact that there is a bijection between `k`-bounded 

partitions and `(k+1)`-cores and an action of the affine nilCoxeter 

algebra of type `A_k^{(1)}` on `(k+1)`-cores as described in [LM2006]_. 

 

REFERENCES: 

 

.. [LM2006] MR2167475 (2006j:05214) 

L. Lapointe, J. Morse. Tableaux on `k+1`-cores, reduced words for affine permutations, and `k`-Schur expansions. 

J. Combin. Theory Ser. A 112 (2005), no. 1, 44--81. 

 

EXAMPLES:: 

 

sage: p=Partition([2,1,1]) 

sage: p.from_kbounded_to_reduced_word(2) 

[2, 1, 2, 0] 

sage: p=Partition([3,1]) 

sage: p.from_kbounded_to_reduced_word(3) 

[3, 2, 1, 0] 

sage: p.from_kbounded_to_reduced_word(2) 

Traceback (most recent call last): 

... 

ValueError: the partition must be 2-bounded 

sage: p=Partition([]) 

sage: p.from_kbounded_to_reduced_word(2) 

[] 

""" 

p=self.k_skew(k)[0] 

result = [] 

while not p.is_empty(): 

corners = p.corners() 

c = p.content(corners[0][0],corners[0][1])%(k+1) 

result.append(Integer(c)) 

list = [x for x in corners if p.content(x[0],x[1])%(k+1) ==c] 

for x in list: 

p = p.remove_cell(x[0]) 

return result 

 

def from_kbounded_to_grassmannian(self, k): 

r""" 

Maps a `k`-bounded partition to a Grassmannian element in 

the affine Weyl group of type `A_k^{(1)}`. 

 

For details, see the documentation of the method 

:meth:`from_kbounded_to_reduced_word` . 

 

EXAMPLES:: 

 

sage: p=Partition([2,1,1]) 

sage: p.from_kbounded_to_grassmannian(2) 

[-1 1 1] 

[-2 2 1] 

[-2 1 2] 

sage: p=Partition([]) 

sage: p.from_kbounded_to_grassmannian(2) 

[1 0 0] 

[0 1 0] 

[0 0 1] 

""" 

return WeylGroup(['A',k,1]).from_reduced_word(self.from_kbounded_to_reduced_word(k)) 

 

def to_list(self): 

r""" 

Return ``self`` as a list. 

 

EXAMPLES:: 

 

sage: p = Partition([2,1]).to_list(); p 

[2, 1] 

sage: type(p) 

<... 'list'> 

 

TESTS:: 

 

sage: p = Partition([2,1]) 

sage: pl = p.to_list() 

sage: pl[0] = 0; p 

[2, 1] 

""" 

return self._list[:] 

 

def add_vertical_border_strip(self, k): 

""" 

Return a list of all the partitions that can be obtained by adding 

a vertical border strip of length ``k`` to ``self``. 

 

EXAMPLES:: 

 

sage: Partition([]).add_vertical_border_strip(0) 

[[]] 

sage: Partition([]).add_vertical_border_strip(2) 

[[1, 1]] 

sage: Partition([2,2]).add_vertical_border_strip(2) 

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

sage: Partition([3,2,2]).add_vertical_border_strip(2) 

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

""" 

return [p.conjugate() for p in self.conjugate().add_horizontal_border_strip(k)] 

 

def add_horizontal_border_strip(self, k): 

""" 

Return a list of all the partitions that can be obtained by adding 

a horizontal border strip of length ``k`` to ``self``. 

 

EXAMPLES:: 

 

sage: Partition([]).add_horizontal_border_strip(0) 

[[]] 

sage: Partition([]).add_horizontal_border_strip(2) 

[[2]] 

sage: Partition([2,2]).add_horizontal_border_strip(2) 

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

sage: Partition([3,2,2]).add_horizontal_border_strip(2) 

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

 

.. TODO:: 

 

Reimplement like ``remove_horizontal_border_strip`` using 

:class:`IntegerListsLex` 

""" 

conj = self.conjugate().to_list() 

shelf = [] 

res = [] 

i = 0 

while i < len(conj): 

tmp = 1 

while i+1 < len(conj) and conj[i] == conj[i+1]: 

tmp += 1 

i += 1 

if i == len(conj)-1 and i > 0 and conj[i] != conj[i-1]: 

tmp = 1 

shelf.append(tmp) 

i += 1 

 

#added the last shelf on the right side of 

#the first line 

shelf.append(k) 

 

#list all of the positions for cells 

#filling each self from the left to the right 

for iv in IntegerVectors(k, len(shelf), outer=shelf): 

iv = list(iv) # Make a mutable list 

tmp = conj + [0]*k 

j = 0 

for t in range(len(iv)): 

while iv[t] > 0: 

tmp[j] += 1 

iv[t] -= 1 

j += 1 

j = sum(shelf[:t+1]) 

res.append(Partition([u for u in tmp if u != 0]).conjugate()) 

return res 

 

def remove_horizontal_border_strip(self, k): 

""" 

Return the partitions obtained from ``self`` by removing an 

horizontal border strip of length ``k``. 

 

EXAMPLES:: 

 

sage: Partition([5,3,1]).remove_horizontal_border_strip(0).list() 

[[5, 3, 1]] 

sage: Partition([5,3,1]).remove_horizontal_border_strip(1).list() 

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

sage: Partition([5,3,1]).remove_horizontal_border_strip(2).list() 

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

sage: Partition([5,3,1]).remove_horizontal_border_strip(3).list() 

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

sage: Partition([5,3,1]).remove_horizontal_border_strip(4).list() 

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

sage: Partition([5,3,1]).remove_horizontal_border_strip(5).list() 

[[3, 1]] 

sage: Partition([5,3,1]).remove_horizontal_border_strip(6).list() 

[] 

 

The result is returned as an instance of 

:class:`Partitions_with_constraints`:: 

 

sage: Partition([5,3,1]).remove_horizontal_border_strip(5) 

The subpartitions of [5, 3, 1] obtained by removing an horizontal border strip of length 5 

 

TESTS:: 

 

sage: Partition([3,2,2]).remove_horizontal_border_strip(2).list() 

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

sage: Partition([3,2,2]).remove_horizontal_border_strip(2).first().parent() 

The subpartitions of [3, 2, 2] obtained by removing an horizontal border strip of length 2 

sage: Partition([]).remove_horizontal_border_strip(0).list() 

[[]] 

sage: Partition([]).remove_horizontal_border_strip(6).list() 

[] 

""" 

return Partitions_with_constraints(n = self.size()-k, 

min_length = len(self)-1, 

max_length = len(self), 

floor = self[1:]+[0], 

ceiling = self[:], 

max_slope = 0, 

name = "The subpartitions of {} obtained by removing an horizontal border strip of length {}".format(self,k)) 

 

def k_conjugate(self, k): 

r""" 

Return the ``k``-conjugate of ``self``. 

 

The `k`-conjugate is the partition that is given by the columns of 

the `k`-skew diagram of the partition. 

 

We can also define the `k`-conjugate in the following way. Let `P` 

denote the bijection from `(k+1)`-cores to `k`-bounded partitions. The 

`k`-conjugate of a `(k+1)`-core `\lambda` is 

 

.. MATH:: 

 

\lambda^{(k)} = P^{-1}\left( (P(\lambda))^{\prime} \right). 

 

EXAMPLES:: 

 

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

sage: p.k_conjugate(4) 

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

""" 

return Partition(self.k_skew(k).conjugate().row_lengths()) 

 

def arms_legs_coeff(self, i, j): 

r""" 

This is a statistic on a cell `c = (i,j)` in the diagram of partition 

`p` given by 

 

.. MATH:: 

 

\frac{ 1 - q^a \cdot t^{\ell + 1} }{ 1 - q^{a + 1} \cdot t^{\ell} } 

 

where `a` is the arm length of `c` and `\ell` is the leg length of `c`. 

 

The coordinates ``i`` and ``j`` of the cell are understood to be 

`0`-based, so that ``(0, 0)`` is the northwesternmost cell (in 

English notation). 

 

EXAMPLES:: 

 

sage: Partition([3,2,1]).arms_legs_coeff(1,1) 

(-t + 1)/(-q + 1) 

sage: Partition([3,2,1]).arms_legs_coeff(0,0) 

(-q^2*t^3 + 1)/(-q^3*t^2 + 1) 

sage: Partition([3,2,1]).arms_legs_coeff(*[0,0]) 

(-q^2*t^3 + 1)/(-q^3*t^2 + 1) 

""" 

QQqt = PolynomialRing(QQ, ['q', 't']) 

(q, t) = QQqt.gens() 

if i < len(self) and j < self[i]: 

res = (1-q**self.arm_length(i,j) * t**(self.leg_length(i,j)+1)) 

res /= (1-q**(self.arm_length(i,j)+1) * t**self.leg_length(i,j)) 

return res 

return ZZ.one() 

 

def atom(self): 

""" 

Return a list of the standard tableaux of size ``self.size()`` whose 

atom is equal to ``self``. 

 

EXAMPLES:: 

 

sage: Partition([2,1]).atom() 

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

sage: Partition([3,2,1]).atom() 

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

""" 

res = [] 

for tab in tableau.StandardTableaux_size(self.size()): 

if tab.atom() == self: 

res.append(tab) 

return res 

 

def k_atom(self, k): 

""" 

Return a list of the standard tableaux of size ``self.size()`` whose 

``k``-atom is equal to ``self``. 

 

EXAMPLES:: 

 

sage: p = Partition([3,2,1]) 

sage: p.k_atom(1) 

[] 

sage: p.k_atom(3) 

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

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

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

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

sage: Partition([3,2,1]).k_atom(4) 

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

 

TESTS:: 

 

sage: Partition([1]).k_atom(1) 

[[[1]]] 

sage: Partition([1]).k_atom(2) 

[[[1]]] 

sage: Partition([]).k_atom(1) 

[[]] 

""" 

res = [ tableau.Tableau([]) ] 

for i in range(len(self)): 

res = [ x.promotion_operator( self[-i-1] ) for x in res] 

res = sum(res, []) 

res = [ y.catabolism_projector(Partition(self[-i-1:]).k_split(k)) for y in res] 

res = [ i for i in res if i !=0 and i != [] ] 

return res 

 

def k_split(self, k): 

""" 

Return the ``k``-split of ``self``. 

 

EXAMPLES:: 

 

sage: Partition([4,3,2,1]).k_split(3) 

[] 

sage: Partition([4,3,2,1]).k_split(4) 

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

sage: Partition([4,3,2,1]).k_split(5) 

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

sage: Partition([4,3,2,1]).k_split(6) 

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

sage: Partition([4,3,2,1]).k_split(7) 

[[4, 3, 2, 1]] 

sage: Partition([4,3,2,1]).k_split(8) 

[[4, 3, 2, 1]] 

""" 

if self == []: 

return [] 

elif k < self[0]: 

return [] 

else: 

res = [] 

part = list(self) 

while part != [] and part[0]+len(part)-1 >= k: 

p = k - part[0] 

res.append( part[:p+1] ) 

part = part[p+1:] 

if part != []: 

res.append(part) 

return res 

 

def jacobi_trudi(self): 

""" 

Return the Jacobi-Trudi matrix of ``self`` thought of as a skew 

partition. See :meth:`SkewPartition.jacobi_trudi() 

<sage.combinat.skew_partition.SkewPartition.jacobi_trudi>`. 

 

EXAMPLES:: 

 

sage: part = Partition([3,2,1]) 

sage: jt = part.jacobi_trudi(); jt 

[h[3] h[1] 0] 

[h[4] h[2] h[]] 

[h[5] h[3] h[1]] 

sage: s = SymmetricFunctions(QQ).schur() 

sage: h = SymmetricFunctions(QQ).homogeneous() 

sage: h( s(part) ) 

h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] 

sage: jt.det() 

h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] 

""" 

return SkewPartition([ self, [] ]).jacobi_trudi() 

 

 

def character_polynomial(self): 

r""" 

Return the character polynomial associated to the partition 

``self``. 

 

The character polynomial `q_\mu` associated to a partition `\mu` 

is defined by 

 

.. MATH:: 

 

q_\mu(x_1, x_2, \ldots, x_k) = \downarrow \sum_{\alpha \vdash k} 

\frac{ \chi^\mu_\alpha }{1^{a_1}2^{a_2}\cdots k^{a_k}a_1!a_2!\cdots 

a_k!} \prod_{i=1}^{k} (ix_i-1)^{a_i} 

 

where `k` is the size of `\mu`, and `a_i` is the multiplicity of 

`i` in `\alpha`. 

 

It is computed in the following manner: 

 

1. Expand the Schur function `s_\mu` in the power-sum basis, 

 

2. Replace each `p_i` with `ix_i-1`, 

 

3. Apply the umbral operator `\downarrow` to the resulting polynomial. 

 

EXAMPLES:: 

 

sage: Partition([1]).character_polynomial() 

x - 1 

sage: Partition([1,1]).character_polynomial() 

1/2*x0^2 - 3/2*x0 - x1 + 1 

sage: Partition([2,1]).character_polynomial() 

1/3*x0^3 - 2*x0^2 + 8/3*x0 - x2 

""" 

 

#Create the polynomial ring we will use 

k = self.size() 

P = PolynomialRing(QQ, k, 'x') 

x = P.gens() 

 

#Expand s_mu in the power sum basis 

from sage.combinat.sf.sf import SymmetricFunctions 

Sym = SymmetricFunctions(QQ) 

s = Sym.schur() 

p = Sym.power() 

ps_mu = p(s(self)) 

 

#Replace each p_i by i*x_i-1 

items = ps_mu.monomial_coefficients().items() #items contains a list of (partition, coeff) pairs 

partition_to_monomial = lambda part: prod([ (i*x[i-1]-1) for i in part ]) 

res = [ [partition_to_monomial(mc[0]), mc[1]] for mc in items ] 

 

#Write things in the monomial basis 

res = [ prod(pair) for pair in res ] 

res = sum( res ) 

 

#Apply the umbral operator and return the result 

from sage.combinat.misc import umbral_operation 

return umbral_operation(res) 

 

def dimension(self, smaller = [], k = 1): 

r""" 

Return the number of paths from the ``smaller`` partition to 

the partition ``self``, where each step consists of adding a 

`k`-ribbon while keeping a partition. 

 

Note that a 1-ribbon is just a single cell, so this counts paths 

in the Young graph when `k = 1`. 

 

Note also that the default case (`k = 1` and ``smaller = []``) 

gives the dimension of the irreducible representation of the 

symmetric group corresponding to ``self``. 

 

INPUT: 

 

- ``smaller`` -- a partition (default: an empty list ``[]``) 

 

- `k` -- a positive integer (default: 1) 

 

OUTPUT: 

 

The number of such paths 

 

EXAMPLES: 

 

Looks at the number of ways of getting from ``[5,4]`` to the empty 

partition, removing one cell at a time:: 

 

sage: mu = Partition([5,4]) 

sage: mu.dimension() 

42 

 

Same, but removing one 3-ribbon at a time. Note that the 3-core of 

``mu`` is empty:: 

 

sage: mu.dimension(k=3) 

3 

 

The 2-core of ``mu`` is not the empty partition:: 

 

sage: mu.dimension(k=2) 

0 

 

Indeed, the 2-core of ``mu`` is ``[1]``:: 

 

sage: mu.dimension(Partition([1]),k=2) 

2 

 

TESTS: 

 

Checks that the sum of squares of dimensions of characters of the 

symmetric group is the order of the group:: 

 

sage: all(sum(mu.dimension()^2 for mu in Partitions(i))==factorial(i) for i in range(10)) 

True 

 

A check coming from the theory of `k`-differentiable posets:: 

 

sage: k=2; core = Partition([2,1]) 

sage: all(sum(mu.dimension(core,k=2)^2 

....: for mu in Partitions(3+i*2) if mu.core(2) == core) 

....: == 2^i*factorial(i) for i in range(10)) 

True 

 

Checks that the dimension satisfies the obvious recursion relation:: 

 

sage: test = lambda larger, smaller: larger.dimension(smaller) == sum(mu.dimension(smaller) for mu in larger.down()) 

sage: all(test(larger,smaller) for l in range(1,10) for s in range(0,10) 

....: for larger in Partitions(l) for smaller in Partitions(s) if smaller != larger) 

True 

 

ALGORITHM: 

 

Depending on the parameters given, different simplifications 

occur. When `k=1` and ``smaller`` is empty, this function uses 

the hook formula. When `k=1` and ``smaller`` is not empty, it 

uses a formula from [ORV]_. 

 

When `k \neq 1`, we first check that both ``self`` and 

``smaller`` have the same `k`-core, then use the `k`-quotients 

and the same algorithm on each of the `k`-quotients. 

 

REFERENCES: 

 

.. [ORV] Grigori Olshanski, Amitai Regev, Anatoly Vershik, 

*Frobenius-Schur functions*, 

:arxiv:`math/0110077v1`. 

Possibly newer version at 

http://www.wisdom.weizmann.ac.il/~regev/papers/FrobeniusSchurFunctions.ps 

 

AUTHORS: 

 

- Paul-Olivier Dehaye (2011-06-07) 

""" 

larger = self 

if smaller == []: 

smaller = Partition([]) 

if k == 1: 

if smaller == Partition([]): # In this case, use the hook dimension formula 

return factorial(larger.size())/prod(larger.hooks()) 

else: 

if not larger.contains(smaller): # easy case 

return 0 

else: 

# relative dimension 

# Uses a formula of Olshanski, Regev, Vershik (see reference) 

def inv_factorial(i): 

if i < 0: 

return 0 

else: 

return 1/factorial(i) 

len_range = list(range(larger.length())) 

from sage.matrix.constructor import matrix 

M = matrix(QQ,[[inv_factorial(larger.get_part(i)-smaller.get_part(j)-i+j) for i in len_range] for j in len_range]) 

return factorial(larger.size()-smaller.size())*M.determinant() 

else: 

larger_core = larger.core(k) 

smaller_core = smaller.core(k) 

if smaller_core != larger_core: # easy case 

return 0 

larger_quotients = larger.quotient(k) 

smaller_quotients = smaller.quotient(k) 

 

def multinomial_with_partitions(sizes,path_counts): 

# count the number of ways of performing the k paths in parallel, 

# if we know the total length alloted for each of the paths (sizes), and the number 

# of paths for each component. A multinomial picks the ordering of the components where 

# each step is taken. 

return prod(path_counts) * factorial(sum(sizes)) / prod([factorial(_) for _ in sizes]) 

 

sizes = [larger_quotients[i].size()-smaller_quotients[i].size() for i in range(k)] 

path_counts = [larger_quotients[i].dimension(smaller_quotients[i]) for i in range(k)] 

return multinomial_with_partitions(sizes,path_counts) 

 

def plancherel_measure(self): 

r""" 

Return the probability of ``self`` under the Plancherel probability 

measure on partitions of the same size. 

 

This probability distribution comes from the uniform distribution 

on permutations via the Robinson-Schensted correspondence. 

 

See :wikipedia:`Plancherel\_measure` 

and :meth:`Partitions_n.random_element_plancherel`. 

 

EXAMPLES:: 

 

sage: Partition([]).plancherel_measure() 

1 

sage: Partition([1]).plancherel_measure() 

1 

sage: Partition([2]).plancherel_measure() 

1/2 

sage: [mu.plancherel_measure() for mu in Partitions(3)] 

[1/6, 2/3, 1/6] 

sage: Partition([5,4]).plancherel_measure() 

7/1440 

 

TESTS:: 

 

sage: all(sum(mu.plancherel_measure() for mu in Partitions(n))==1 for n in range(10)) 

True 

""" 

return self.dimension()**2/factorial(self.size()) 

 

def outline(self, variable=None): 

r""" 

Return the outline of the partition ``self``. 

 

This is a piecewise linear function, normalized so that the area 

under the partition ``[1]`` is 2. 

 

INPUT: 

 

- variable -- a variable (default: ``'x'`` in the symbolic ring) 

 

EXAMPLES:: 

 

sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)] 

[10, 9, 8, 7, 6, 5, 6, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10] 

 

sage: Partition([]).outline() 

abs(x) 

 

sage: Partition([1]).outline() 

abs(x + 1) + abs(x - 1) - abs(x) 

 

sage: y=sage.symbolic.ring.var("y") 

sage: Partition([6,5,1]).outline(variable=y) 

abs(y + 6) - abs(y + 5) + abs(y + 4) - abs(y + 3) + abs(y - 1) - abs(y - 2) + abs(y - 3) 

 

TESTS:: 

 

sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10)) 

2 

""" 

if variable is None: 

variable = var('x') 

outside_contents = [self.content(*c) for c in self.outside_corners()] 

inside_contents = [self.content(*c) for c in self.corners()] 

return sum(abs(variable+c) for c in outside_contents)\ 

-sum(abs(variable+c) for c in inside_contents) 

 

def dual_equivalence_graph(self, directed=False, coloring=None): 

r""" 

Return the dual equivalence graph of ``self``. 

 

Two permutations `p` and `q` in the symmetric group `S_n` 

differ by an `i`-*elementary dual equivalence (or dual Knuth) 

relation* (where `i` is an integer with `1 < i < n`) when the 

following two conditions are satisfied: 

 

- In the one-line notation of the permutation `p`, the letter 

`i` does not appear inbetween `i-1` and `i+1`. 

 

- The permutation `q` is obtained from `p` by switching two 

of the three letters `i-1, i, i+1` (in its one-line 

notation) -- namely, the leftmost and the rightmost one 

in order of their appearance in `p`. 

 

Notice that this is equivalent to the statement that the 

permutations `p^{-1}` and `q^{-1}` differ by an elementary 

Knuth equivalence at positions `i-1, i, i+1`. 

 

Two standard Young tableaux of shape `\lambda` differ by an 

`i`-elementary dual equivalence relation (of color `i`), if 

their reading words differ by an `i`-elementary dual 

equivalence relation. 

 

The *dual equivalence graph* of the partition `\lambda` is the 

edge-colored graph whose vertices are the standard Young 

tableaux of shape `\lambda`, and whose edges colored by `i` are 

given by the `i`-elementary dual equivalences. 

 

INPUT: 

 

- ``directed`` -- (default: ``False``) whether to have the dual 

equivalence graph be directed (where we have a directed edge 

`S \to T` if `i` appears to the left of `i+1` in the 

reading word of `T`; otherwise we have the directed edge 

`T \to S`) 

 

- ``coloring`` -- (optional) a function which sends each 

integer `i > 1` to a color (as a string, e.g., ``'red'`` or 

``'black'``) to be used when visually representing the 

resulting graph using dot2tex; the default choice is 

``2 -> 'red', 3 -> 'blue', 4 -> 'green', 5 -> 'purple', 

6 -> 'brown', 7 -> 'orange', 8 -> 'yellow', anything greater 

than 8 -> 'black'``. 

 

REFERENCES: 

 

.. [AssafDEG] Sami Assaf. *Dual equivalence graphs and a 

combinatorial proof of LLT and Macdonald positivity*. 

(2008). :arxiv:`1005.3759v5`. 

 

EXAMPLES:: 

 

sage: P = Partition([3,1,1]) 

sage: G = P.dual_equivalence_graph() 

sage: sorted(G.edges()) 

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

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

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

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

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

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

sage: G = P.dual_equivalence_graph(directed=True) 

sage: sorted(G.edges()) 

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

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

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

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

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

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

 

TESTS:: 

 

sage: G = Partition([1]).dual_equivalence_graph() 

sage: G.vertices() 

[[[1]]] 

sage: G = Partition([]).dual_equivalence_graph() 

sage: G.vertices() 

[[]] 

 

sage: P = Partition([3,1,1]) 

sage: G = P.dual_equivalence_graph(coloring=lambda x: 'red') 

sage: G2 = P.dual_equivalence_graph(coloring={2: 'black', 3: 'blue', 4: 'cyan', 5: 'grey'}) 

sage: G is G2 

False 

sage: G == G2 

True 

""" 

# We do some custom caching to not recreate the graph, but to make 

# copies with the desired coloring (i.e., act like a factory). 

try: 

if directed: 

G = self._DDEG.copy(immutable=False) 

else: 

G = self._DEG.copy(immutable=False) 

if have_dot2tex(): 

if coloring is None: 

d = {2: 'red', 3: 'blue', 4: 'green', 5: 'purple', 

6: 'brown', 7: 'orange', 8: 'yellow'} 

def coloring(i): 

if i in d: 

return d[i] 

return 'black' 

elif isinstance(coloring, dict): 

d = coloring 

coloring = lambda x: d[x] 

G.set_latex_options(format="dot2tex", 

edge_labels=True, 

color_by_label=coloring) 

return G 

except AttributeError: 

pass 

 

T = list(tableau.StandardTableaux(self)) 

n = sum(self) 

edges = [] 

to_perms = {t: t.reading_word_permutation() for t in T} 

to_tab = {to_perms[k]: k for k in to_perms} 

Perm = permutation.Permutations() 

for t in T: 

pt = list(to_perms[t]) 

for i in range(2, n): 

ii = pt.index(i) 

iip = pt.index(i+1) 

iim = pt.index(i-1) 

l = sorted([iim, ii, iip]) 

if l[0] != ii: 

continue 

x = pt[:] 

x[l[0]], x[l[2]] = x[l[2]], x[l[0]] 

if ii < iip: 

e = [t, to_tab[Perm(x)], i] 

edges.append(e) 

else: 

e = [to_tab[Perm(x)], t, i] 

edges.append(e) 

 

if directed: 

from sage.graphs.digraph import DiGraph 

self._DDEG = DiGraph([T, edges], format="vertices_and_edges", 

immutable=True, multiedges=True) 

else: 

from sage.graphs.graph import Graph 

self._DEG = Graph([T, edges], format="vertices_and_edges", 

immutable=True, multiedges=True) 

return self.dual_equivalence_graph(directed, coloring) 

 

############## 

# Partitions # 

############## 

 

class Partitions(UniqueRepresentation, Parent): 

r""" 

``Partitions(n, **kwargs)`` returns the combinatorial class of 

integer partitions of `n` subject to the constraints given by the 

keywords. 

 

Valid keywords are: ``starting``, ``ending``, ``min_part``, 

``max_part``, ``max_length``, ``min_length``, ``length``, 

``max_slope``, ``min_slope``, ``inner``, ``outer``, ``parts_in`` 

and ``regular``. They have the following meanings: 

 

- ``starting=p`` specifies that the partitions should all be less 

than or equal to `p` in lex order. This argument cannot be combined 

with any other (see :trac:`15467`). 

 

- ``ending=p`` specifies that the partitions should all be greater than 

or equal to `p` in lex order. This argument cannot be combined with any 

other (see :trac:`15467`). 

 

- ``length=k`` specifies that the partitions have 

exactly `k` parts. 

 

- ``min_length=k`` specifies that the partitions have 

at least `k` parts. 

 

- ``min_part=k`` specifies that all parts of the 

partitions are at least `k`. 

 

- ``inner=p`` specifies that the partitions must contain the 

partition `p`. 

 

- ``outer=p`` specifies that the partitions 

be contained inside the partition `p`. 

 

- ``min_slope=k`` specifies that the partitions have slope at least 

`k`; the slope at position `i` is the difference between the 

`(i+1)`-th part and the `i`-th part. 

 

- ``parts_in=S`` specifies that the partitions have parts in the set 

`S`, which can be any sequence of pairwise distinct positive 

integers. This argument cannot be combined with any other 

(see :trac:`15467`). 

 

- ``regular=ell`` specifies that the partitions are `\ell`-regular, 

and can only be combined with the ``max_length`` or ``max_part``, but 

not both, keywords if `n` is not specified 

 

The ``max_*`` versions, along with ``inner`` and ``ending``, work 

analogously. 

 

Right now, the ``parts_in``, ``starting``, ``ending``, and ``regular`` 

keyword arguments are mutually exclusive, both of each other and of other 

keyword arguments. If you specify, say, ``parts_in``, all other 

keyword arguments will be ignored; ``starting``, ``ending``, and 

``regular`` work the same way. 

 

EXAMPLES: 

 

If no arguments are passed, then the combinatorial class 

of all integer partitions is returned:: 

 

sage: Partitions() 

Partitions 

sage: [2,1] in Partitions() 

True 

 

If an integer `n` is passed, then the combinatorial class of integer 

partitions of `n` is returned:: 

 

sage: Partitions(3) 

Partitions of the integer 3 

sage: Partitions(3).list() 

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

 

If ``starting=p`` is passed, then the combinatorial class of partitions 

greater than or equal to `p` in lexicographic order is returned:: 

 

sage: Partitions(3, starting=[2,1]) 

Partitions of the integer 3 starting with [2, 1] 

sage: Partitions(3, starting=[2,1]).list() 

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

 

If ``ending=p`` is passed, then the combinatorial class of 

partitions at most `p` in lexicographic order is returned:: 

 

sage: Partitions(3, ending=[2,1]) 

Partitions of the integer 3 ending with [2, 1] 

sage: Partitions(3, ending=[2,1]).list() 

[[3], [2, 1]] 

 

Using ``max_slope=-1`` yields partitions into distinct parts -- each 

part differs from the next by at least 1. Use a different 

``max_slope`` to get parts that differ by, say, 2:: 

 

sage: Partitions(7, max_slope=-1).list() 

[[7], [6, 1], [5, 2], [4, 3], [4, 2, 1]] 

sage: Partitions(15, max_slope=-1).cardinality() 

27 

 

The number of partitions of `n` into odd parts equals the number of 

partitions into distinct parts. Let's test that for `n` from 10 to 20:: 

 

sage: test = lambda n: Partitions(n, max_slope=-1).cardinality() == Partitions(n, parts_in=[1,3..n]).cardinality() 

sage: all(test(n) for n in [10..20]) 

True 

 

The number of partitions of `n` into distinct parts that differ by 

at least 2 equals the number of partitions into parts that equal 1 

or 4 modulo 5; this is one of the Rogers-Ramanujan identities:: 

 

sage: test = lambda n: Partitions(n, max_slope=-2).cardinality() == Partitions(n, parts_in=([1,6..n] + [4,9..n])).cardinality() 

sage: all(test(n) for n in [10..20]) 

True 

 

Here are some more examples illustrating ``min_part``, ``max_part``, 

and ``length``:: 

 

sage: Partitions(5,min_part=2) 

Partitions of the integer 5 satisfying constraints min_part=2 

sage: Partitions(5,min_part=2).list() 

[[5], [3, 2]] 

 

:: 

 

sage: Partitions(3,max_length=2).list() 

[[3], [2, 1]] 

 

:: 

 

sage: Partitions(10, min_part=2, length=3).list() 

[[6, 2, 2], [5, 3, 2], [4, 4, 2], [4, 3, 3]] 

 

Some examples using the ``regular`` keyword:: 

 

sage: Partitions(regular=4) 

4-Regular Partitions 

sage: Partitions(regular=4, max_length=3) 

4-Regular Partitions with max length 3 

sage: Partitions(regular=4, max_part=3) 

4-Regular 3-Bounded Partitions 

sage: Partitions(3, regular=4) 

4-Regular Partitions of the integer 3 

 

Here are some further examples using various constraints:: 

 

sage: [x for x in Partitions(4)] 

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

sage: [x for x in Partitions(4, length=2)] 

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

sage: [x for x in Partitions(4, min_length=2)] 

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

sage: [x for x in Partitions(4, max_length=2)] 

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

sage: [x for x in Partitions(4, min_length=2, max_length=2)] 

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

sage: [x for x in Partitions(4, max_part=2)] 

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

sage: [x for x in Partitions(4, min_part=2)] 

[[4], [2, 2]] 

sage: [x for x in Partitions(4, outer=[3,1,1])] 

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

sage: [x for x in Partitions(4, outer=[infinity, 1, 1])] 

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

sage: [x for x in Partitions(4, inner=[1,1,1])] 

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

sage: [x for x in Partitions(4, max_slope=-1)] 

[[4], [3, 1]] 

sage: [x for x in Partitions(4, min_slope=-1)] 

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

sage: [x for x in Partitions(11, max_slope=-1, min_slope=-3, min_length=2, max_length=4)] 

[[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]] 

sage: [x for x in Partitions(11, max_slope=-1, min_slope=-3, min_length=2, max_length=4, outer=[6,5,2])] 

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

 

Note that if you specify ``min_part=0``, then it will treat the minimum 

part as being 1 (see :trac:`13605`):: 

 

sage: [x for x in Partitions(4, length=3, min_part=0)] 

[[2, 1, 1]] 

sage: [x for x in Partitions(4, min_length=3, min_part=0)] 

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

 

Except for very special cases, counting is done by brute force iteration 

through all the partitions. However the iteration itself has a reasonable 

complexity (see :class:`IntegerListsLex`), which allows for 

manipulating large partitions:: 

 

sage: Partitions(1000, max_length=1).list() 

[[1000]] 

 

In particular, getting the first element is also constant time:: 

 

sage: Partitions(30, max_part=29).first() 

[29, 1] 

 

TESTS:: 

 

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

sage: TestSuite(Partitions(5)).run() 

sage: TestSuite(Partitions(5, min_part=2)).run() 

 

sage: repr( Partitions(5, min_part=2) ) 

'Partitions of the integer 5 satisfying constraints min_part=2' 

 

sage: P = Partitions(5, min_part=2) 

sage: P.first().parent() 

Partitions... 

sage: [2,1] in P 

False 

sage: [2,2,1] in P 

False 

sage: [3,2] in P 

True 

 

sage: Partitions(5, inner=[2,1], min_length=3).list() 

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

sage: Partitions(5, inner=Partition([2,2]), min_length=3).list() 

[[2, 2, 1]] 

sage: Partitions(7, inner=(2, 2), min_length=3).list() 

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

sage: Partitions(5, inner=[2,0,0,0,0,0]).list() 

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

sage: Partitions(6, length=2, max_slope=-1).list() 

[[5, 1], [4, 2]] 

 

sage: Partitions(length=2, max_slope=-1).list() 

Traceback (most recent call last): 

... 

ValueError: the size must be specified with any keyword argument 

 

sage: Partitions(max_part = 3) 

3-Bounded Partitions 

 

Check that :trac:`14145` has been fixed:: 

 

sage: 1 in Partitions() 

False 

 

Check :trac:`15467`:: 

 

sage: Partitions(5,parts_in=[1,2,3,4], length=4) 

Traceback (most recent call last): 

... 

ValueError: The parameters 'parts_in', 'starting' and 'ending' cannot be combined with anything else. 

sage: Partitions(5,starting=[3,2], length=2) 

Traceback (most recent call last): 

... 

ValueError: The parameters 'parts_in', 'starting' and 'ending' cannot be combined with anything else. 

sage: Partitions(5,ending=[3,2], length=2) 

Traceback (most recent call last): 

... 

ValueError: The parameters 'parts_in', 'starting' and 'ending' cannot be combined with anything else. 

sage: Partitions(NN, length=2) 

Traceback (most recent call last): 

... 

ValueError: the size must be specified with any keyword argument 

sage: Partitions(('la','la','laaaa'), max_part=8) 

Traceback (most recent call last): 

... 

ValueError: n must be an integer or be equal to one of None, NN, NonNegativeIntegers() 

 

Check that calling ``Partitions`` with ``outer=a`` no longer 

mutates ``a`` (:trac:`16234`):: 

 

sage: a = [4,3,2,1,1,1,1] 

sage: for p in Partitions(8, outer=a, min_slope=-1): 

....: print(p) 

[3, 3, 2] 

[3, 2, 2, 1] 

[3, 2, 1, 1, 1] 

[2, 2, 2, 1, 1] 

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

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

sage: a 

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

 

Check that ``inner`` and ``outer`` indeed accept a partition as 

argument (:trac:`18423`):: 

 

sage: P = Partitions(5, inner=Partition([2,1]), outer=Partition([3,2])); P 

Partitions of the integer 5 satisfying constraints inner=[2, 1], outer=[3, 2] 

sage: P.list() 

[[3, 2]] 

""" 

@staticmethod 

def __classcall_private__(cls, n=None, **kwargs): 

""" 

Return the correct parent based upon the input. 

 

TESTS:: 

 

sage: P = Partitions() 

sage: P2 = Partitions(NN) 

sage: P is P2 

True 

sage: P2 = Partitions(NonNegativeIntegers()) 

sage: P is P2 

True 

sage: P = Partitions(4) 

sage: P2 = Partitions(int(4)) 

sage: P is P2 

True 

 

Check that :trac:`17898` is fixed:: 

 

sage: P = Partitions(5, min_slope=0) 

sage: list(P) 

[[5], [1, 1, 1, 1, 1]] 

""" 

if n == infinity: 

raise ValueError("n cannot be infinite") 

if n is None or n is NN or n is NonNegativeIntegers(): 

if len(kwargs) > 0: 

if len(kwargs) == 1: 

if 'max_part' in kwargs: 

return Partitions_all_bounded(kwargs['max_part']) 

if 'regular' in kwargs: 

return RegularPartitions_all(kwargs['regular']) 

elif len(kwargs) == 2: 

if 'regular' in kwargs: 

if kwargs['regular'] < 1 or kwargs['regular'] not in ZZ: 

raise ValueError("the regularity must be a positive integer") 

if 'max_part' in kwargs: 

return RegularPartitions_bounded(kwargs['regular'], kwargs['max_part']) 

if 'max_length' in kwargs: 

return RegularPartitions_truncated(kwargs['regular'], kwargs['max_length']) 

raise ValueError("the size must be specified with any keyword argument") 

return Partitions_all() 

elif isinstance(n, (int,Integer)): 

if len(kwargs) == 0: 

return Partitions_n(n) 

 

if len(kwargs) == 1: 

if 'max_part' in kwargs: 

return PartitionsGreatestLE(n, kwargs['max_part']) 

if 'length' in kwargs: 

return Partitions_nk(n, kwargs['length']) 

 

if (len(kwargs) > 1 and 

('parts_in' in kwargs or 

'starting' in kwargs or 

'ending' in kwargs)): 

raise ValueError("The parameters 'parts_in', 'starting' and "+ 

"'ending' cannot be combined with anything else.") 

 

if 'parts_in' in kwargs: 

return Partitions_parts_in(n, kwargs['parts_in']) 

elif 'starting' in kwargs: 

return Partitions_starting(n, kwargs['starting']) 

elif 'ending' in kwargs: 

return Partitions_ending(n, kwargs['ending']) 

elif 'regular' in kwargs: 

return RegularPartitions_n(n, kwargs['regular']) 

 

# FIXME: should inherit from IntegerListLex, and implement repr, or _name as a lazy attribute 

kwargs['name'] = "Partitions of the integer %s satisfying constraints %s"%(n, ", ".join( ["%s=%s"%(key, kwargs[key]) for key in sorted(kwargs)] )) 

 

# min_part is at least 1, and it is 1 by default 

kwargs['min_part'] = max(1,kwargs.get('min_part',1)) 

 

# max_slope is at most 0, and it is 0 by default 

kwargs['max_slope'] = min(0,kwargs.get('max_slope',0)) 

 

if kwargs.get('min_slope', -float('inf')) > 0: 

raise ValueError("the minimum slope must be non-negative") 

 

if 'outer' in kwargs: 

kwargs['max_length'] = min(len(kwargs['outer']), 

kwargs.get('max_length', infinity)) 

 

kwargs['ceiling'] = tuple(kwargs['outer']) 

del kwargs['outer'] 

 

if 'inner' in kwargs: 

inner = [x for x in kwargs['inner'] if x > 0] 

kwargs['floor'] = inner 

kwargs['min_length'] = max(len(inner), 

kwargs.get('min_length',0)) 

del kwargs['inner'] 

return Partitions_with_constraints(n, **kwargs) 

 

raise ValueError("n must be an integer or be equal to one of " 

"None, NN, NonNegativeIntegers()") 

 

def __init__(self, is_infinite=False): 

""" 

Initialize ``self``. 

 

INPUT: 

 

- ``is_infinite`` -- (Default: ``False``) If ``True``, then the number 

of partitions in this set is infinite. 

 

EXAMPLES:: 

 

sage: Partitions() 

Partitions 

sage: Partitions(2) 

Partitions of the integer 2 

""" 

if is_infinite: 

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

else: 

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

 

Element = Partition 

 

# add options to class 

class options(GlobalOptions): 

r""" 

Sets and displays the global options for elements of the partition, 

skew partition, and partition tuple classes. If no parameters are 

set, then the function returns a copy of the options dictionary. 

 

The ``options`` to partitions can be accessed as the method 

:obj:`Partitions.options` of :class:`Partitions` and 

related parent classes. 

 

@OPTIONS@ 

 

EXAMPLES:: 

 

sage: P = Partition([4,2,2,1]) 

sage: P 

[4, 2, 2, 1] 

sage: Partitions.options.display="exp" 

sage: P 

1, 2^2, 4 

sage: Partitions.options.display="exp_high" 

sage: P 

4, 2^2, 1 

 

It is also possible to use user defined functions for the ``display`` and 

``latex`` options:: 

 

sage: Partitions.options(display=lambda mu: '<%s>' % ','.join('%s'%m for m in mu._list)); P 

<4,2,2,1> 

sage: Partitions.options(latex=lambda mu: '\\Diagram{%s}' % ','.join('%s'%m for m in mu._list)); latex(P) 

\Diagram{4,2,2,1} 

sage: Partitions.options(display="diagram", diagram_str="#") 

sage: P 

#### 

## 

## 

# 

sage: Partitions.options(diagram_str="*", convention="french") 

sage: print(P.ferrers_diagram()) 

* 

** 

** 

**** 

 

Changing the ``convention`` for partitions also changes the ``convention`` 

option for tableaux and vice versa:: 

 

sage: T = Tableau([[1,2,3],[4,5]]) 

sage: T.pp() 

4 5 

1 2 3 

sage: Tableaux.options.convention="english" 

sage: print(P.ferrers_diagram()) 

**** 

** 

** 

* 

sage: T.pp() 

1 2 3 

4 5 

sage: Partitions.options._reset() 

""" 

NAME = 'Partitions' 

module = 'sage.combinat.partition' 

display = dict(default="list", 

description='Specifies how partitions should be printed', 

values=dict(list='displayed as a list', 

exp_low='in exponential form (lowest first)', 

exp_high='in exponential form (highest first)', 

diagram='as a Ferrers diagram', 

compact_low='compact form of ``exp_low``', 

compact_high='compact form of ``exp_high``'), 

alias=dict(exp="exp_low", compact="compact_low", array="diagram", 

ferrers_diagram="diagram", young_diagram="diagram"), 

case_sensitive=False) 

latex = dict(default="young_diagram", 

description='Specifies how partitions should be latexed', 

values=dict(diagram='latex as a Ferrers diagram', 

young_diagram='latex as a Young diagram', 

list='latex as a list', 

exp_high='latex as a list in exponential notation (highest first)', 

exp_low='as a list latex in exponential notation (lowest first)'), 

alias=dict(exp="exp_low", array="diagram", ferrers_diagram="diagram"), 

case_sensitive=False) 

diagram_str = dict(default="*", 

description='The character used for the cells when printing Ferrers diagrams', 

checker=lambda char: isinstance(char,str)) 

latex_diagram_str = dict(default="\\ast", 

description='The character used for the cells when latexing Ferrers diagrams', 

checker=lambda char: isinstance(char,str)) 

convention = dict(link_to=(tableau.Tableaux.options,'convention')) 

notation = dict(alt_name='convention') 

 

def __reversed__(self): 

""" 

A reversed iterator. 

 

EXAMPLES:: 

 

sage: [x for x in reversed(Partitions(4))] 

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

""" 

if not self.is_finite(): 

raise NotImplementedError("The set is infinite. This needs a custom reverse iterator") 

 

for i in reversed(range(self.cardinality())): 

yield self[i] 

 

def _element_constructor_(self, lst): 

""" 

Construct an element with ``self`` as parent. 

 

EXAMPLES:: 

 

sage: P = Partitions() 

sage: p = P([3,3,1]); p 

[3, 3, 1] 

sage: P(p) is p 

True 

sage: P([3, 2, 1, 0]) 

[3, 2, 1] 

 

sage: PT = PartitionTuples() 

sage: elt = PT([[4,4,2,2,1]]); elt 

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

sage: P(elt) 

[4, 4, 2, 2, 1] 

""" 

if isinstance(lst, PartitionTuple): 

if lst.level() != 1: 

raise ValueError('%s is not an element of %s'%(lst, self)) 

lst = lst[0] 

if lst.parent() is self: 

return lst 

if lst in self: 

# Trailing zeros are removed in the element constructor 

return self.element_class(self, lst) 

 

raise ValueError('%s is not an element of %s'%(lst, self)) 

 

def __contains__(self, x): 

""" 

Check if ``x`` is contained in ``self``. 

 

TESTS:: 

 

sage: P = Partitions() 

sage: Partition([2,1]) in P 

True 

sage: [2,1] in P 

True 

sage: [3,2,1] in P 

True 

sage: [1,2] in P 

False 

sage: [] in P 

True 

sage: [0] in P 

True 

 

Check that types that represent integers are not excluded:: 

 

sage: P = Partitions() 

sage: [3/1, 2/2] in P 

True 

sage: Partition([3/1, 2]) in P 

True 

""" 

if isinstance(x, Partition): 

return True 

if isinstance(x, (list, tuple)): 

return len(x) == 0 or (x[-1] in NN and 

all(x[i] in NN and x[i] >= x[i+1] for i in range(len(x)-1))) 

 

def subset(self, *args, **kwargs): 

r""" 

Return ``self`` if no arguments are given, otherwise raises a 

``ValueError``. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, starting=[3,1]); P 

Partitions of the integer 5 starting with [3, 1] 

sage: P.subset() 

Partitions of the integer 5 starting with [3, 1] 

sage: P.subset(ending=[3,1]) 

Traceback (most recent call last): 

... 

ValueError: Invalid combination of arguments 

""" 

if len(args) != 0 or len(kwargs) != 0: 

raise ValueError("Invalid combination of arguments") 

return self 

 

class Partitions_all(Partitions): 

""" 

Class of all partitions. 

 

TESTS:: 

 

sage: TestSuite( sage.combinat.partition.Partitions_all() ).run() 

""" 

 

def __init__(self): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: P = Partitions() 

sage: P.category() 

Category of infinite enumerated sets 

sage: Partitions().cardinality() 

+Infinity 

sage: TestSuite(P).run() 

""" 

Partitions.__init__(self, is_infinite=True) 

 

def subset(self, size=None, **kwargs): 

""" 

Returns the subset of partitions of a given size and additional 

keyword arguments. 

 

EXAMPLES:: 

 

sage: P = Partitions() 

sage: P.subset(4) 

Partitions of the integer 4 

""" 

if size is None: 

return self 

return Partitions(size, **kwargs) 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: Partitions() # indirect doctest 

Partitions 

""" 

return "Partitions" 

 

def __iter__(self): 

""" 

An iterator for all partitions. 

 

EXAMPLES:: 

 

sage: p = Partitions() 

sage: it = p.__iter__() 

sage: [next(it) for i in range(10)] 

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

""" 

n = 0 

while True: 

for p in ZS1_iterator(n): 

yield self.element_class(self, p) 

n += 1 

 

def __reversed__(self): 

""" 

A reversed iterator for all partitions. 

 

This reverse iterates through partitions of fixed `n` and incrementing 

`n` after reaching the end. 

 

EXAMPLES:: 

 

sage: p = Partitions() 

sage: revit = p.__reversed__() 

sage: [next(revit) for i in range(10)] 

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

""" 

n = 0 

while True: 

for p in reversed(list(ZS1_iterator(n))): 

yield self.element_class(self, p) 

n += 1 

 

 

def from_frobenius_coordinates(self, frobenius_coordinates): 

""" 

Returns a partition from a pair of sequences of Frobenius coordinates. 

 

EXAMPLES:: 

 

sage: Partitions().from_frobenius_coordinates(([],[])) 

[] 

sage: Partitions().from_frobenius_coordinates(([0],[0])) 

[1] 

sage: Partitions().from_frobenius_coordinates(([1],[1])) 

[2, 1] 

sage: Partitions().from_frobenius_coordinates(([6,3,2],[4,1,0])) 

[7, 5, 5, 1, 1] 

""" 

if len(frobenius_coordinates) != 2: 

raise ValueError('%s is not a valid partition, two sequences of coordinates are needed'%str(frobenius_coordinates)) 

else: 

a = frobenius_coordinates[0] 

b = frobenius_coordinates[1] 

if len(a) != len(b): 

raise ValueError('%s is not a valid partition, the sequences of coordinates need to be the same length'%str(frobenius_coordinates)) 

# should add tests to see if a and b are sorted down, nonnegative and strictly decreasing 

r = len(a) 

if r == 0: 

return self.element_class(self, []) 

tmp = [a[i]+i+1 for i in range(r)] 

# should check that a is strictly decreasing 

if a[-1] < 0: 

raise ValueError('%s is not a partition, no coordinate can be negative'%str(frobenius_coordinates)) 

if b[-1] >= 0: 

tmp.extend([r]*b[r-1]) 

else: 

raise ValueError('%s is not a partition, no coordinate can be negative'%str(frobenius_coordinates)) 

for i in range(r-1,0,-1): 

if b[i-1]-b[i] > 0: 

tmp.extend([i]*(b[i-1]-b[i]-1)) 

else: 

raise ValueError('%s is not a partition, the coordinates need to be strictly decreasing'%str(frobenius_coordinates)) 

return self.element_class(self, tmp) 

 

def from_beta_numbers(self, beta): 

r""" 

Return a partition corresponding to a sequence of beta numbers. 

 

A sequence of beta numbers is a strictly increasing sequence 

`0 \leq b_1 < \cdots < b_k` of non-negative integers. The 

corresponding partition `\mu = (\mu_k, \ldots, \mu_1)` is 

given by `\mu_i = [1,i) \setminus \{ b_1, \ldots, b_i \}`. This gives 

a bijection from the set of partitions with at most `k` non-zero parts 

to the set of strictly increasing sequences of non-negative integers 

of length `k`. 

 

EXAMPLES:: 

 

sage: Partitions().from_beta_numbers([0,1,2,4,5,8]) 

[3, 1, 1] 

sage: Partitions().from_beta_numbers([0,2,3,6]) 

[3, 1, 1] 

""" 

beta.sort() # put them into increasing order just in case 

offset = 0 

while offset < len(beta)-1 and beta[offset] == offset: 

offset+=1 

beta = beta[offset:] 

mu = [beta[i]-offset-i for i in range(len(beta))] 

return self.element_class(self, list(reversed(mu))) 

 

def from_exp(self, exp): 

""" 

Returns a partition from its list of multiplicities. 

 

EXAMPLES:: 

 

sage: Partitions().from_exp([2,2,1]) 

[3, 2, 2, 1, 1] 

""" 

p = [] 

for i in reversed(range(len(exp))): 

p += [i+1]*exp[i] 

return self.element_class(self, p) 

 

def from_zero_one(self, seq): 

r""" 

Return a partition from its `0-1` sequence. 

 

The full `0-1` sequence is the sequence (infinite in both 

directions) indicating the steps taken when following the 

outer rim of the diagram of the partition. We use the convention 

that in English convention, a 1 corresponds to an East step, and 

a 0 corresponds to a North step. 

 

Note that every full `0-1` sequence starts with infinitely many 0's and 

ends with infinitely many 1's. 

 

.. SEEALSO:: 

 

:meth:`Partition.zero_one_sequence()` 

 

INPUT: 

 

The input should be a finite sequence of 0's and 1's. The 

heading 0's and trailing 1's will be discarded. 

 

EXAMPLES:: 

 

sage: Partitions().from_zero_one([]) 

[] 

sage: Partitions().from_zero_one([1,0]) 

[1] 

sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0]) 

[5, 4] 

 

Heading 0's and trailing 1's are correctly handled:: 

 

sage: Partitions().from_zero_one([0,0,1,1,1,1,0,1,0,1,1,1]) 

[5, 4] 

 

TESTS:: 

 

sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n)) 

True 

""" 

tmp = [i for i in range(len(seq)) if seq[i] == 0] 

return self.element_class(self,[tmp[i]-i for i in range(len(tmp)-1,-1,-1)]) 

 

def from_core_and_quotient(self, core, quotient): 

""" 

Returns a partition from its core and quotient. 

 

Algorithm from mupad-combinat. 

 

EXAMPLES:: 

 

sage: Partitions().from_core_and_quotient([2,1], [[2,1],[3],[1,1,1]]) 

[11, 5, 5, 3, 2, 2, 2] 

 

TESTS:: 

 

sage: Partitions().from_core_and_quotient([2,1], [[2,1],[2,3,1],[1,1,1]]) 

Traceback (most recent call last): 

... 

ValueError: the quotient [[2, 1], [2, 3, 1], [1, 1, 1]] must be a tuple of partitions 

 

We check that :trac:`11412` is actually fixed:: 

 

sage: test = lambda x, k: x == Partition(core=x.core(k), 

....: quotient=x.quotient(k)) 

sage: all(test(mu,k) for k in range(1,5) 

....: for n in range(10) for mu in Partitions(n)) 

True 

sage: test2 = lambda core, mus: ( 

....: Partition(core=core, quotient=mus).core(mus.level()) == core 

....: and 

....: Partition(core=core, quotient=mus).quotient(mus.level()) == mus) 

sage: all(test2(core,mus) # long time (5s on sage.math, 2011) 

....: for k in range(1,10) 

....: for n_core in range(10-k) 

....: for core in Partitions(n_core) 

....: if core.core(k) == core 

....: for n_mus in range(10-k) 

....: for mus in PartitionTuples(k,n_mus)) 

True 

""" 

from .partition_tuple import PartitionTuple, PartitionTuples 

if not quotient in PartitionTuples(): 

raise ValueError('the quotient %s must be a tuple of partitions'%quotient) 

components = PartitionTuple(quotient).components() 

length = len(components) 

k = length*max(len(q) for q in components) + len(core) 

# k needs to be large enough. this seems to me like the smallest it can be 

v = [core[i]-i for i in range(len(core))] + [ -i for i in range(len(core),k) ] 

w = [ [x for x in v if (x-i) % length == 0] for i in range(1, length+1) ] 

new_w = [] 

for i in range(length): 

lw = len(w[i]) 

lq = len(components[i]) 

# k needs to be chosen so lw >= lq 

new_w += [ w[i][j] + length*components[i][j] for j in range(lq)] 

new_w += [ w[i][j] for j in range(lq,lw)] 

new_w.sort(reverse=True) 

return self.element_class(self, [new_w[i]+i for i in range(len(new_w))]) 

 

class Partitions_all_bounded(Partitions): 

 

def __init__(self, k): 

""" 

TESTS:: 

 

sage: TestSuite( sage.combinat.partition.Partitions_all_bounded(3) ).run() # long time 

""" 

self.k = k 

Partitions.__init__(self, is_infinite=True) 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: P = Partitions(max_part=3) 

sage: Partition([2,1]) in P 

True 

sage: [2,1] in P 

True 

sage: [3,2,1] in P 

True 

sage: [1,2] in P 

False 

sage: [5,1] in P 

False 

sage: [0] in P 

True 

sage: [] in P 

True 

""" 

return len(x) == 0 or (x[0] <= self.k and Partitions.__contains__(self, x)) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: from sage.combinat.partition import Partitions_all_bounded 

sage: Partitions_all_bounded(3) 

3-Bounded Partitions 

""" 

return "%d-Bounded Partitions"%self.k 

 

def __iter__(self): 

""" 

An iterator for all `k`-bounded partitions. 

 

EXAMPLES:: 

 

sage: p = Partitions(max_part=3) 

sage: it = p.__iter__() 

sage: [next(it) for i in range(10)] 

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

""" 

n = 0 

while True: 

for p in Partitions(n, max_part=self.k): 

yield self.element_class(self, p) 

n += 1 

 

 

class Partitions_n(Partitions): 

""" 

Partitions of the integer `n`. 

 

TESTS:: 

 

sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() 

sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() 

""" 

 

def __init__(self, n): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: TestSuite( Partitions(5) ).run() 

""" 

Partitions.__init__(self) 

self.n = n 

 

def __contains__(self, x): 

""" 

Check if ``x`` is contained in ``self``. 

 

TESTS:: 

 

sage: p = Partitions(5) 

sage: [2,1] in p 

False 

sage: [2,2,1] in p 

True 

sage: [3,2] in p 

True 

sage: [2,3] in p 

False 

""" 

return x in _Partitions and sum(x) == self.n 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: Partitions(5) # indirect doctest 

Partitions of the integer 5 

""" 

return "Partitions of the integer %s"%self.n 

 

def _an_element_(self): 

""" 

Returns a partition in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4).an_element() # indirect doctest 

[3, 1] 

sage: Partitions(0).an_element() 

[] 

sage: Partitions(1).an_element() 

[1] 

""" 

if self.n == 0: 

lst = [] 

elif self.n == 1: 

lst = [1] 

else: 

lst = [self.n-1, 1] 

return self.element_class(self, lst) 

 

def cardinality(self, algorithm='flint'): 

r""" 

Return the number of partitions of the specified size. 

 

INPUT: 

 

- ``algorithm`` - (default: ``'flint'``) 

 

- ``'flint'`` -- use FLINT (currently the fastest) 

- ``'bober'`` -- Use Jonathan Bober's implementation (*very* fast) 

- ``'gap'`` -- use GAP (VERY *slow*) 

- ``'pari'`` -- use PARI. Speed seems the same as GAP until 

`n` is in the thousands, in which case PARI is faster. 

 

It is possible to associate with every partition of the integer `n` a 

conjugacy class of permutations in the symmetric group on `n` points 

and vice versa. Therefore the number of partitions `p_n` is the number 

of conjugacy classes of the symmetric group on `n` points. 

 

EXAMPLES:: 

 

sage: v = Partitions(5).list(); v 

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

sage: len(v) 

7 

sage: Partitions(5).cardinality(algorithm='gap') 

7 

sage: Partitions(5).cardinality(algorithm='pari') 

7 

sage: Partitions(5).cardinality(algorithm='bober') 

7 

sage: number_of_partitions(5, algorithm='flint') 

7 

 

The input must be a nonnegative integer or a ``ValueError`` is raised. 

 

:: 

 

sage: Partitions(10).cardinality() 

42 

sage: Partitions(3).cardinality() 

3 

sage: Partitions(10).cardinality() 

42 

sage: Partitions(3).cardinality(algorithm='pari') 

3 

sage: Partitions(10).cardinality(algorithm='pari') 

42 

sage: Partitions(40).cardinality() 

37338 

sage: Partitions(100).cardinality() 

190569292 

 

A generating function for `p_n` is given by the reciprocal of 

Euler's function: 

 

.. MATH:: 

 

\sum_{n=0}^{\infty} p_n x^n = \prod_{k=1}^{\infty} \frac{1}{1-x^k}. 

 

We use Sage to verify that the first several coefficients do 

indeed agree:: 

 

sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen() 

sage: prod([(1-q^k)^(-1) for k in range(1,9)]) ## partial product of 

1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9) 

sage: [Partitions(k).cardinality() for k in range(2,10)] 

[2, 3, 5, 7, 11, 15, 22, 30] 

 

Another consistency test for ``n`` up to 500:: 

 

sage: len([n for n in [1..500] if Partitions(n).cardinality() != Partitions(n).cardinality(algorithm='pari')]) 

0 

 

REFERENCES: 

 

- :wikipedia:`Partition\_(number\_theory)` 

""" 

if algorithm == 'flint': 

return cached_number_of_partitions(self.n) 

 

elif algorithm == 'bober': 

return bober_number_of_partitions(self.n) 

 

elif algorithm == 'gap': 

return ZZ(gap.eval("NrPartitions(%s)" % (ZZ(self.n)))) 

 

elif algorithm == 'pari': 

return ZZ(pari(ZZ(self.n)).numbpart()) 

 

raise ValueError("unknown algorithm '%s'" % algorithm) 

 

def random_element(self, measure = 'uniform'): 

""" 

Return a random partitions of `n` for the specified measure. 

 

INPUT: 

 

- ``measure`` -- ``'uniform'`` or ``'Plancherel'`` 

(default: ``'uniform'``) 

 

.. SEEALSO:: 

 

- :meth:`random_element_uniform` 

- :meth:`random_element_plancherel` 

 

EXAMPLES:: 

 

sage: Partitions(5).random_element() # random 

[2, 1, 1, 1] 

sage: Partitions(5).random_element(measure='Plancherel') # random 

[2, 1, 1, 1] 

""" 

if measure == 'uniform': 

return self.random_element_uniform() 

elif measure == 'Plancherel': 

return self.random_element_plancherel() 

else: 

raise ValueError("Unkown measure: %s" % (measure)) 

 

def random_element_uniform(self): 

""" 

Return a random partition of `n` with uniform probability. 

 

EXAMPLES:: 

 

sage: Partitions(5).random_element_uniform() # random 

[2, 1, 1, 1] 

sage: Partitions(20).random_element_uniform() # random 

[9, 3, 3, 2, 2, 1] 

 

TESTS:: 

 

sage: all(Part.random_element_uniform() in Part 

....: for Part in map(Partitions, range(10))) 

True 

 

Check that :trac:`18752` is fixed:: 

 

sage: P = Partitions(5) 

sage: la = P.random_element_uniform() 

sage: la.parent() is P 

True 

 

ALGORITHM: 

 

- It is a python Implementation of RANDPAR, see [nw]_. The 

complexity is unknown, there may be better algorithms. 

 

.. TODO:: 

 

Check in Knuth AOCP4. 

 

- There is also certainly a lot of room for optimizations, see 

comments in the code. 

 

REFERENCES: 

 

.. [nw] Nijenhuis, Wilf, Combinatorial Algorithms, Academic Press 

(1978). 

 

AUTHOR: 

 

- Florent Hivert (2009-11-23) 

""" 

n = self.n 

res = [] # A dictionary of multiplicities could be faster. 

while n > 0: 

# Choose a pair d,j = 1,2..., with d*j <= n with probability 

# d*numpart(n-d*j) / n / numpart(n) 

# and add d^j to the result partition. The resulting partitions is 

# equiprobable. 

 

# The following could be made faster by a clever use of floats 

rand = randrange(0, n*cached_number_of_partitions(n)) # cached number_of_partition 

 

# It is better to start by the j = 1 pairs because they are the 

# most probable. Maybe there is an even more clever order. 

for j in range(1, n+1): 

d = 1 

r = n-j # n - d*j 

while r >= 0: 

rand -= d * cached_number_of_partitions(r) 

if rand < 0: break 

d +=1 

r -= j 

else: 

continue 

break 

res.extend([d]*j) 

n = r 

res.sort(reverse=True) 

return self.element_class(self, res) 

 

def random_element_plancherel(self): 

r""" 

Return a random partition of `n` (for the Plancherel measure). 

 

This probability distribution comes from the uniform distribution 

on permutations via the Robinson-Schensted correspondence. 

 

See :wikipedia:`Plancherel\_measure` 

and :meth:`Partition.plancherel_measure`. 

 

EXAMPLES:: 

 

sage: Partitions(5).random_element_plancherel() # random 

[2, 1, 1, 1] 

sage: Partitions(20).random_element_plancherel() # random 

[9, 3, 3, 2, 2, 1] 

 

TESTS:: 

 

sage: all(Part.random_element_plancherel() in Part 

....: for Part in map(Partitions, range(10))) 

True 

 

Check that :trac:`18752` is fixed:: 

 

sage: P = Partitions(5) 

sage: la = P.random_element_plancherel() 

sage: la.parent() is P 

True 

 

ALGORITHM: 

 

- insert by Robinson-Schensted a uniform random permutations of n and 

returns the shape of the resulting tableau. The complexity is 

`O(n\ln(n))` which is likely optimal. However, the implementation 

could be optimized. 

 

AUTHOR: 

 

- Florent Hivert (2009-11-23) 

""" 

T = permutation.Permutations(self.n).random_element().left_tableau() 

return self.element_class(self, [len(row) for row in T]) 

 

def first(self): 

""" 

Returns the lexicographically first partition of a positive integer 

`n`. This is the partition ``[n]``. 

 

EXAMPLES:: 

 

sage: Partitions(4).first() 

[4] 

""" 

return self.element_class(self, [self.n]) 

 

def next(self, p): 

""" 

Return the lexicographically next partition after the partition ``p``. 

 

EXAMPLES:: 

 

sage: Partitions(4).next([4]) 

[3, 1] 

sage: Partitions(4).next([1,1,1,1]) is None 

True 

""" 

found = False 

for i in self: 

if found: 

return i 

if i == p: 

found = True 

return None 

 

def last(self): 

""" 

Return the lexicographically last partition of the positive 

integer `n`. This is the all-ones partition. 

 

EXAMPLES:: 

 

sage: Partitions(4).last() 

[1, 1, 1, 1] 

""" 

return self.element_class(self, [1]*self.n) 

 

def __iter__(self): 

""" 

An iterator for the partitions of `n`. 

 

EXAMPLES:: 

 

sage: [x for x in Partitions(4)] 

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

""" 

for p in ZS1_iterator(self.n): 

yield self.element_class(self, p) 

 

def subset(self, **kwargs): 

r""" 

Return a subset of ``self`` with the additional optional arguments. 

 

EXAMPLES:: 

 

sage: P = Partitions(5); P 

Partitions of the integer 5 

sage: P.subset(starting=[3,1]) 

Partitions of the integer 5 starting with [3, 1] 

""" 

return Partitions(self.n, **kwargs) 

 

class Partitions_nk(Partitions): 

""" 

Partitions of the integer `n` of length equal to `k`. 

 

TESTS:: 

 

sage: TestSuite( sage.combinat.partition.Partitions_nk(0,0) ).run() 

sage: TestSuite( sage.combinat.partition.Partitions_nk(0,0) ).run() 

""" 

 

def __init__(self, n, k): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: TestSuite( Partitions(5, length=2) ).run() 

""" 

Partitions.__init__(self) 

self.n = n 

self.k = k 

 

def __contains__(self, x): 

""" 

Check if ``x`` is contained in ``self``. 

 

TESTS:: 

 

sage: p = Partitions(5, length=2) 

sage: [2,1] in p 

False 

sage: [2,2,1] in p 

False 

sage: [3,2] in p 

True 

sage: [2,3] in p 

False 

sage: [4,1] in p 

True 

sage: [1,1,1,1,1] in p 

False 

sage: [5] in p 

False 

""" 

return x in _Partitions and sum(x) == self.n and len(x) == self.k 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: Partitions(5, length=2) # indirect doctest 

Partitions of the integer 5 of length 2 

""" 

return "Partitions of the integer {} of length {}".format(self.n, self.k) 

 

def _an_element_(self): 

""" 

Returns a partition in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4, length=1).an_element() # indirect doctest 

[4] 

sage: Partitions(4, length=2).an_element() 

[3, 1] 

sage: Partitions(4, length=3).an_element() 

[2, 1, 1] 

sage: Partitions(4, length=4).an_element() 

[1, 1, 1, 1] 

 

sage: Partitions(1, length=1).an_element() 

[1] 

 

sage: Partitions(0, length=0).an_element() 

[] 

""" 

if self.n == 0: 

if self.k == 0: 

lst = [] 

else: 

from sage.categories.sets_cat import EmptySetError 

raise EmptySetError 

elif self.n >= self.k > 0: 

lst = [self.n - self.k + 1] + [1] * (self.k-1) 

else: 

from sage.categories.sets_cat import EmptySetError 

raise EmptySetError 

return self.element_class(self, lst) 

 

def __iter__(self): 

""" 

An iterator for all partitions of `n` of length `k`. 

 

EXAMPLES:: 

 

sage: p = Partitions(9, length=3) 

sage: it = p.__iter__() 

sage: list(it) 

[[7, 1, 1], [6, 2, 1], [5, 3, 1], [5, 2, 2], [4, 4, 1], [4, 3, 2], [3, 3, 3]] 

 

sage: p = Partitions(9, length=10) 

sage: list(p.__iter__()) 

[] 

 

sage: p = Partitions(0, length=0) 

sage: list(p.__iter__()) 

[[]] 

 

sage: from sage.combinat.partition import number_of_partitions_length 

sage: all( len(Partitions(n, length=k).list()) 

....: == number_of_partitions_length(n, k) 

....: for n in range(9) for k in range(n+2) ) 

True 

""" 

for p in ZS1_iterator_nk(self.n - self.k, self.k): 

v = [i + 1 for i in p] 

adds = [1] * (self.k - len(v)) 

yield self.element_class(self, v + adds) 

 

def cardinality(self, algorithm='hybrid'): 

r""" 

Return the number of partitions of the specified size with the 

specified length. 

 

INPUT: 

 

- ``algorithm`` -- (default: ``'hybrid'``) the algorithm to compute 

the cardinality and can be one of the following: 

 

* ``'hybrid'`` - use a hybrid algorithm which uses heuristics to 

reduce the complexity 

* ``'gap'`` - use GAP 

 

EXAMPLES:: 

 

sage: v = Partitions(5, length=2).list(); v 

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

sage: len(v) 

2 

sage: Partitions(5, length=2).cardinality() 

2 

 

More generally, the number of partitions of `n` of length `2` 

is `\left\lfloor \frac{n}{2} \right\rfloor`:: 

 

sage: all( Partitions(n, length=2).cardinality() 

....: == n // 2 for n in range(10) ) 

True 

 

The number of partitions of `n` of length `1` is `1` for `n` 

positive:: 

 

sage: all( Partitions(n, length=1).cardinality() == 1 

....: for n in range(1, 10) ) 

True 

 

Further examples:: 

 

sage: Partitions(5, length=3).cardinality() 

2 

sage: Partitions(6, length=3).cardinality() 

3 

sage: Partitions(8, length=4).cardinality() 

5 

sage: Partitions(8, length=5).cardinality() 

3 

sage: Partitions(15, length=6).cardinality() 

26 

sage: Partitions(0, length=0).cardinality() 

1 

sage: Partitions(0, length=1).cardinality() 

0 

sage: Partitions(1, length=0).cardinality() 

0 

sage: Partitions(1, length=4).cardinality() 

0 

 

TESTS: 

 

We check the hybrid approach gives the same results as GAP:: 

 

sage: N = [0, 1, 2, 3, 5, 10, 20, 500, 850] 

sage: K = [0, 1, 2, 3, 5, 10, 11, 20, 21, 250, 499, 500] 

sage: all(Partitions(n,length=k).cardinality() == Partitions(n,length=k).cardinality('gap') 

....: for n in N for k in K) 

True 

sage: P = Partitions(4562, length=2800) 

sage: P.cardinality() == P.cardinality('gap') 

True 

""" 

return number_of_partitions_length(self.n, self.k, algorithm) 

 

def subset(self, **kwargs): 

r""" 

Return a subset of ``self`` with the additional optional arguments. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, length=2); P 

Partitions of the integer 5 of length 2 

sage: P.subset(max_part=3) 

Partitions of the integer 5 satisfying constraints length=2, max_part=3 

""" 

return Partitions(self.n, length=self.k, **kwargs) 

 

class Partitions_parts_in(Partitions): 

""" 

Partitions of `n` with parts in a given set `S`. 

 

This is invoked indirectly when calling 

``Partitions(n, parts_in=parts)``, where ``parts`` is a list of 

pairwise distinct integers. 

 

TESTS:: 

 

sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run() 

""" 

 

@staticmethod 

def __classcall_private__(cls, n, parts): 

""" 

Normalize the input to ensure a unique representation. 

 

TESTS:: 

 

sage: P = Partitions(4, parts_in=[2,1]) 

sage: P2 = Partitions(4, parts_in=(1,2)) 

sage: P is P2 

True 

""" 

parts = tuple(sorted(parts)) 

return super(Partitions_parts_in, cls).__classcall__(cls, Integer(n), parts) 

 

def __init__(self, n, parts): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: TestSuite(Partitions(5, parts_in=[1,2,3])).run() 

""" 

Partitions.__init__(self) 

self.n = n 

self.parts = list(parts) 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: p = Partitions(5, parts_in=[1,2]) 

sage: [2,1,1,1] in p 

True 

sage: [4,1] in p 

False 

""" 

return (x in _Partitions and sum(x) == self.n and 

all(p in self.parts for p in x)) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: Partitions(5, parts_in=[1,2,3]) # indirect doctest 

Partitions of the integer 5 with parts in [1, 2, 3] 

""" 

return "Partitions of the integer %s with parts in %s" % (self.n, self.parts) 

 

def cardinality(self): 

r""" 

Return the number of partitions with parts in ``self``. Wraps GAP's 

``NrRestrictedPartitions``. 

 

EXAMPLES:: 

 

sage: Partitions(15, parts_in=[2,3,7]).cardinality() 

5 

 

If you can use all parts 1 through `n`, we'd better get `p(n)`:: 

 

sage: Partitions(20, parts_in=[1..20]).cardinality() == Partitions(20).cardinality() 

True 

 

TESTS: 

 

Let's check the consistency of GAP's function and our own 

algorithm that actually generates the partitions:: 

 

sage: ps = Partitions(15, parts_in=[1,2,3]) 

sage: ps.cardinality() == len(ps.list()) 

True 

sage: ps = Partitions(15, parts_in=[]) 

sage: ps.cardinality() == len(ps.list()) 

True 

sage: ps = Partitions(3000, parts_in=[50,100,500,1000]) 

sage: ps.cardinality() == len(ps.list()) 

True 

sage: ps = Partitions(10, parts_in=[3,6,9]) 

sage: ps.cardinality() == len(ps.list()) 

True 

sage: ps = Partitions(0, parts_in=[1,2]) 

sage: ps.cardinality() == len(ps.list()) 

True 

""" 

# GAP complains if you give it an empty list 

if self.parts: 

return ZZ(gap.eval("NrRestrictedPartitions(%s,%s)" % (ZZ(self.n), self.parts))) 

else: 

return Integer(self.n == 0) 

 

def first(self): 

""" 

Return the lexicographically first partition of a positive 

integer `n` with the specified parts, or ``None`` if no such 

partition exists. 

 

EXAMPLES:: 

 

sage: Partitions(9, parts_in=[3,4]).first() 

[3, 3, 3] 

sage: Partitions(6, parts_in=[1..6]).first() 

[6] 

sage: Partitions(30, parts_in=[4,7,8,10,11]).first() 

[11, 11, 8] 

""" 

try: 

return self.element_class(self, self._findfirst(self.n, self.parts[:])) 

except TypeError: 

return None 

 

def _findfirst(self, n, parts): 

""" 

TESTS:: 

 

sage: p = Partitions(9, parts_in=[3,4]) 

sage: p._findfirst(p.n, p.parts[:]) 

[3, 3, 3] 

sage: p._findfirst(0, p.parts[:]) 

[] 

sage: p._findfirst(p.n, [10]) 

 

""" 

if n == 0: 

return [] 

else: 

while parts: 

p = parts.pop() 

for k in range(n.quo_rem(p)[0], 0, -1): 

try: 

return k * [p] + self._findfirst(n - k * p, parts[:]) 

except TypeError: 

pass 

 

def last(self): 

""" 

Return the lexicographically last partition of the positive 

integer `n` with the specified parts, or ``None`` if no such 

partition exists. 

 

EXAMPLES:: 

 

sage: Partitions(15, parts_in=[2,3]).last() 

[3, 2, 2, 2, 2, 2, 2] 

sage: Partitions(30, parts_in=[4,7,8,10,11]).last() 

[7, 7, 4, 4, 4, 4] 

sage: Partitions(10, parts_in=[3,6]).last() is None 

True 

sage: Partitions(50, parts_in=[11,12,13]).last() 

[13, 13, 12, 12] 

sage: Partitions(30, parts_in=[4,7,8,10,11]).last() 

[7, 7, 4, 4, 4, 4] 

 

TESTS:: 

 

sage: Partitions(6, parts_in=[1..6]).last() 

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

sage: Partitions(0, parts_in=[]).last() 

[] 

sage: Partitions(50, parts_in=[11,12]).last() is None 

True 

""" 

try: 

return self.element_class(self, self._findlast(self.n, self.parts)) 

except TypeError: 

return None 

 

def _findlast(self, n, parts): 

""" 

Return the lexicographically largest partition of `n` using the 

given parts, or ``None`` if no such partition exists. This function 

is not intended to be called directly. 

 

INPUT: 

 

- ``n`` -- nonnegative integer 

 

- ``parts`` -- a sorted list of positive integers. 

 

OUTPUT: 

 

A list of integers in weakly decreasing order, or ``None``. The 

output is just a list, not a partition object. 

 

EXAMPLES:: 

 

sage: ps = Partitions(1, parts_in=[1]) 

sage: ps._findlast(15, [2,3]) 

[3, 2, 2, 2, 2, 2, 2] 

sage: ps._findlast(9, [2,4]) is None 

True 

sage: ps._findlast(0, []) 

[] 

sage: ps._findlast(100, [9,17,31]) 

[31, 17, 17, 17, 9, 9] 

""" 

if n < 0: 

return None 

elif n == 0: 

return [] 

elif parts != []: 

p = parts[0] 

q, r = n.quo_rem(p) 

if r == 0: 

return [p] * q 

# If the smallest part doesn't divide n, try using the next 

# largest part 

else: 

for i, p in enumerate(parts[1:]): 

rest = self._findlast(n - p, parts[:i+2]) 

if rest is not None: 

return [p] + rest 

# If we get to here, nothing ever worked, so there's no such 

# partitions, and we return None. 

return None 

 

 

def __iter__(self): 

""" 

An iterator through the partitions of `n` with all parts belonging 

to a particular set. 

 

EXAMPLES:: 

 

sage: [x for x in Partitions(4)] 

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

""" 

for p in self._fast_iterator(self.n, self.parts[:]): 

yield self.element_class(self, p) 

 

def _fast_iterator(self, n, parts): 

""" 

A fast iterator for the partitions of ``n`` which returns lists and 

not partition types. This function is not intended to be called 

directly. 

 

INPUT: 

 

- ``n`` -- nonnegative integer. 

 

- ``parts`` -- a list of parts to use. This list will be 

destroyed, so pass things here with ``foo[:]`` (or something 

equivalent) if you want to preserve your list. In particular, 

the ``__iter__`` method needs to use ``self.parts[:]``, or else we 

forget which parts we're using! 

 

OUTPUT: 

 

A generator object for partitions of `n` with parts in 

``parts``. 

 

If the parts in ``parts`` are sorted in increasing order, this 

function returns weakly decreasing lists. If ``parts`` is not 

sorted, your lists won't be, either. 

 

EXAMPLES:: 

 

sage: P = Partitions(4, parts_in=[2,4]) 

sage: it = P._fast_iterator(4, [2,4]) 

sage: next(it) 

[4] 

sage: type(_) 

<... 'list'> 

""" 

if n == 0: 

yield [] 

else: 

while parts: 

p = parts.pop() 

for k in range(n.quo_rem(p)[0], 0, -1): 

for q in self._fast_iterator(n - k * p, parts[:]): 

yield k * [p] + q 

 

class Partitions_starting(Partitions): 

""" 

All partitions with a given start. 

""" 

 

@staticmethod 

def __classcall_private__(cls, n, starting_partition): 

""" 

Normalize the input to ensure a unique representation. 

 

TESTS:: 

 

sage: P = Partitions(4, starting=[2,1]) 

sage: P2 = Partitions(4, starting=[2,1]) 

sage: P is P2 

True 

""" 

starting_partition = Partition(starting_partition) 

return super(Partitions_starting, cls).__classcall__(cls, Integer(n), 

starting_partition) 

 

def __init__(self, n, starting_partition): 

""" 

Initilizes ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(3, starting=[2,1]) 

Partitions of the integer 3 starting with [2, 1] 

sage: Partitions(3, starting=[2,1]).list() 

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

 

TESTS:: 

 

sage: p = Partitions(3, starting=[2,1]) 

sage: TestSuite(p).run() 

""" 

Partitions.__init__(self) 

self.n = n 

self._starting = starting_partition 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(3, starting=[2,1]) # indirect doctest 

Partitions of the integer 3 starting with [2, 1] 

""" 

return "Partitions of the integer %s starting with %s"%(self.n, self._starting) 

 

def __contains__(self, x): 

""" 

Checks if ``x`` is contained in ``self``. 

 

EXAMPLES:: 

 

sage: p = Partitions(3, starting=[2,1]) 

sage: [1,1] in p 

False 

sage: [2,1] in p 

True 

sage: [1,1,1] in p 

True 

sage: [3] in p 

False 

""" 

return x in Partitions_n(self.n) and x <= self._starting 

 

def first(self): 

""" 

Return the first partition in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(3, starting=[2,1]).first() 

[2, 1] 

""" 

return self._starting 

 

def next(self, part): 

""" 

Return the next partition after ``part`` in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(3, starting=[2,1]).next(Partition([2,1])) 

[1, 1, 1] 

""" 

return next(part) 

 

class Partitions_ending(Partitions): 

""" 

All partitions with a given ending. 

""" 

 

@staticmethod 

def __classcall_private__(cls, n, ending_partition): 

""" 

Normalize the input to ensure a unique representation. 

 

TESTS:: 

 

sage: P = Partitions(4) 

sage: P2 = Partitions(4) 

sage: P is P2 

True 

""" 

ending_partition = Partition(ending_partition) 

return super(Partitions_ending, cls).__classcall__(cls, Integer(n), 

ending_partition) 

 

def __init__(self, n, ending_partition): 

""" 

Initializes ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4, ending=[1,1,1,1]).list() 

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

sage: Partitions(4, ending=[2,2]).list() 

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

sage: Partitions(4, ending=[4]).list() 

[[4]] 

 

TESTS:: 

 

sage: p = Partitions(4, ending=[1,1,1,1]) 

sage: TestSuite(p).run() 

""" 

Partitions.__init__(self) 

self.n = n 

self._ending = ending_partition 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4, ending=[1,1,1,1]) # indirect doctest 

Partitions of the integer 4 ending with [1, 1, 1, 1] 

""" 

return "Partitions of the integer %s ending with %s"%(self.n, self._ending) 

 

def __contains__(self, x): 

""" 

Checks if ``x`` is contained in ``self``. 

 

EXAMPLES:: 

 

sage: p = Partitions(4, ending=[2,2]) 

sage: [4] in p 

True 

sage: [2,1,1] in p 

False 

sage: [2,1] in p 

False 

""" 

return x in Partitions_n(self.n) and x >= self._ending 

 

def first(self): 

""" 

Return the first partition in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4, ending=[1,1,1,1]).first() 

[4] 

""" 

return self.element_class(self, [self.n]) 

 

def next(self, part): 

""" 

Return the next partition after ``part`` in ``self``. 

 

EXAMPLES:: 

 

sage: Partitions(4, ending=[1,1,1,1]).next(Partition([4])) 

[3, 1] 

sage: Partitions(4, ending=[1,1,1,1]).next(Partition([1,1,1,1])) is None 

True 

""" 

if part == self._ending: 

return None 

else: 

return next(part) 

 

class PartitionsInBox(Partitions): 

r""" 

All partitions which fit in an `h \times w` box. 

 

EXAMPLES:: 

 

sage: PartitionsInBox(2,2) 

Integer partitions which fit in a 2 x 2 box 

sage: PartitionsInBox(2,2).list() 

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

""" 

 

def __init__(self, h, w): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: p = PartitionsInBox(2,2) 

sage: TestSuite(p).run() 

""" 

Partitions.__init__(self) 

self.h = h 

self.w = w 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: PartitionsInBox(2,2) # indirect doctest 

Integer partitions which fit in a 2 x 2 box 

""" 

return "Integer partitions which fit in a %s x %s box" % (self.h, self.w) 

 

def __contains__(self, x): 

""" 

Checks if ``x`` is contained in ``self``. 

 

EXAMPLES:: 

 

sage: [] in PartitionsInBox(2,2) 

True 

sage: [2,1] in PartitionsInBox(2,2) 

True 

sage: [3,1] in PartitionsInBox(2,2) 

False 

sage: [2,1,1] in PartitionsInBox(2,2) 

False 

sage: [3,1] in PartitionsInBox(3, 2) 

False 

sage: [3,1] in PartitionsInBox(2, 3) 

True 

""" 

return x in _Partitions and len(x) <= self.h \ 

and (len(x) == 0 or x[0] <= self.w) 

 

def list(self): 

""" 

Return a list of all the partitions inside a box of height `h` and 

width `w`. 

 

EXAMPLES:: 

 

sage: PartitionsInBox(2,2).list() 

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

sage: PartitionsInBox(2,3).list() 

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

 

TESTS: 

 

Check :trac:`10890`:: 

 

sage: type(PartitionsInBox(0,0)[0]) 

<class 'sage.combinat.partition.PartitionsInBox_with_category.element_class'> 

""" 

h = self.h 

w = self.w 

if h == 0: 

return [self.element_class(self, [])] 

else: 

l = [[i] for i in range(0, w+1)] 

add = lambda x: [ x+[i] for i in range(0, x[-1]+1)] 

for i in range(h-1): 

new_list = [] 

for element in l: 

new_list += add(element) 

l = new_list 

 

return [self.element_class(self, [x for x in p if x!=0]) for p in l] 

 

class Partitions_constraints(IntegerListsLex): 

""" 

For unpickling old constrained ``Partitions_constraints`` objects created 

with sage <= 3.4.1. See :class:`Partitions`. 

""" 

def __setstate__(self, data): 

r""" 

TESTS:: 

 

sage: dmp = 'x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+H,*\xc9,\xc9\xcc\xcf\xe3\n\x80\xb1\x8a\xe3\x93\x81DIQbf^I1W!\xa3fc!Sm!\xb3F(7\x92x!Km!k(GnbE<\xc8\x88B6\x88\xb9E\x99y\xe9\xc5z@\x05\xa9\xe9\xa9E\\\xb9\x89\xd9\xa9\xf10N!{(\xa3QkP!Gq(c^\x06\x90c\x0c\xe4p\x96&\xe9\x01\x00\xc2\xe53\xfd' 

sage: sp = loads(dmp); sp 

Integer lists of sum 3 satisfying certain constraints 

sage: sp.list() 

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

""" 

n = data['n'] 

self.__class__ = Partitions_with_constraints 

constraints = {'max_slope' : 0, 

'min_part' : 1} 

constraints.update(data['constraints']) 

self.__init__(n, **constraints) 

 

class Partitions_with_constraints(IntegerListsLex): 

""" 

Partitions which satisfy a set of constraints. 

 

EXAMPLES:: 

 

sage: P = Partitions(6, inner=[1,1], max_slope=-1) 

sage: list(P) 

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

 

TESTS:: 

 

sage: P = Partitions(6, min_part=2, max_slope=-1) 

sage: TestSuite(P).run() 

 

Test that :trac:`15525` is fixed:: 

 

sage: loads(dumps(P)) == P 

True 

""" 

# def __init__(self, n, **kwargs): 

# """ 

# Initialize ``self``. 

# """ 

# IntegerListsLex.__init__(self, n, **kwargs) 

 

Element = Partition 

options = Partitions.options 

 

###################### 

# Regular Partitions # 

###################### 

 

class RegularPartitions(Partitions): 

r""" 

Base class for `\ell`-regular partitions. 

 

Let `\ell` be a positive integer. A partition `\lambda` is 

`\ell`-*regular* if `m_i < \ell` for all `i`, where `m_i` is the 

multiplicity of `i` in `\lambda`. 

 

.. NOTE:: 

 

This is conjugate to the notion of `\ell`-*restricted* partitions, 

where the difference between any two consecutive 

parts is `< \ell`. 

 

INPUT: 

 

- ``ell`` -- the positive integer `\ell` 

- ``is_infinite`` -- boolean; if the subset of `\ell`-regular 

partitions is infinite 

""" 

def __init__(self, ell, is_infinite=False): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=2) 

sage: TestSuite(P).run() 

""" 

self._ell = ell 

Partitions.__init__(self, is_infinite) 

 

def ell(self): 

r""" 

Return the value `\ell`. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=2) 

sage: P.ell() 

2 

""" 

return self._ell 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: P = Partitions(regular=3) 

sage: [5] in P 

True 

sage: [] in P 

True 

sage: [3, 3, 2, 2] in P 

True 

sage: [3, 3, 3, 1] in P 

False 

sage: [4, 0, 0, 0, 0, 0] in P 

True 

sage: Partition([4,2,2,1]) in P 

True 

sage: Partition([4,2,2,2]) in P 

False 

sage: Partition([10,1]) in P 

True 

""" 

if not Partitions.__contains__(self, x): 

return False 

if isinstance(x, Partition): 

return max(x.to_exp() + [0]) < self._ell 

return all(x.count(i) < self._ell for i in set(x) if i > 0) 

 

def _fast_iterator(self, n, max_part): 

""" 

A fast (recursive) iterator which returns a list. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=3) 

sage: list(P._fast_iterator(5, 5)) 

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

sage: list(P._fast_iterator(5, 3)) 

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

sage: list(P._fast_iterator(5, 6)) 

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

""" 

if n == 0: 

yield [] 

return 

 

if n < max_part: 

max_part = n 

bdry = self._ell - 1 

 

for i in reversed(range(1, max_part+1)): 

for p in self._fast_iterator(n-i, i): 

if p.count(i) < bdry: 

yield [i] + p 

 

class RegularPartitions_all(RegularPartitions): 

r""" 

The class of all `\ell`-regular partitions. 

 

INPUT: 

 

- ``ell`` -- the positive integer `\ell` 

 

.. SEEALSO:: 

 

:class:`~sage.combinat.partition.RegularPartitions` 

""" 

def __init__(self, ell): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=4) 

sage: TestSuite(P).run() 

 

1-regular partitions:: 

 

sage: P = Partitions(regular=1) 

sage: P in FiniteEnumeratedSets() 

True 

sage: TestSuite(P).run() 

""" 

RegularPartitions.__init__(self, ell, bool(ell > 1)) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: from sage.combinat.partition import RegularPartitions_all 

sage: RegularPartitions_all(3) 

3-Regular Partitions 

""" 

return "{}-Regular Partitions".format(self._ell) 

 

def __iter__(self): 

""" 

Iterate over ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=3) 

sage: it = P.__iter__() 

sage: [next(it) for x in range(10)] 

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

 

Check that 1-regular partitions works (:trac:`20584`):: 

 

sage: P = Partitions(regular=1) 

sage: list(P) 

[[]] 

""" 

if self._ell == 1: 

yield self.element_class(self, []) 

return 

 

n = 0 

while True: 

for p in self._fast_iterator(n, n): 

yield self.element_class(self, p) 

n += 1 

 

class RegularPartitions_truncated(RegularPartitions): 

r""" 

The class of `\ell`-regular partitions with max length `k`. 

 

INPUT: 

 

- ``ell`` -- the integer `\ell` 

- ``max_len`` -- integer; the maximum length 

 

.. SEEALSO:: 

 

:class:`~sage.combinat.partition.RegularPartitions` 

""" 

def __init__(self, ell, max_len): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=4, max_length=3) 

sage: TestSuite(P).run() 

""" 

self._max_len = max_len 

RegularPartitions.__init__(self, ell, bool(ell > 1)) 

 

def max_length(self): 

""" 

Return the maximum length of the partitions of ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=4, max_length=3) 

sage: P.max_length() 

3 

""" 

return self._max_len 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: P = Partitions(regular=4, max_length=3) 

sage: [3, 3, 3] in P 

True 

sage: [] in P 

True 

sage: [4, 2, 1, 1] in P 

False 

""" 

return len(x) <= self._max_len and RegularPartitions.__contains__(self, x) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: from sage.combinat.partition import RegularPartitions_truncated 

sage: RegularPartitions_truncated(4, 3) 

4-Regular Partitions with max length 3 

""" 

return "{}-Regular Partitions with max length {}".format(self._ell, self._max_len) 

 

def __iter__(self): 

""" 

Iterate over ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=3, max_length=2) 

sage: it = P.__iter__() 

sage: [next(it) for x in range(10)] 

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

 

Check that 1-regular partitions works (:trac:`20584`):: 

 

sage: P = Partitions(regular=1, max_length=2) 

sage: list(P) 

[[]] 

""" 

if self._ell == 1: 

yield self.element_class(self, []) 

return 

 

n = 0 

while True: 

for p in self._fast_iterator(n, n): 

yield self.element_class(self, p) 

n += 1 

 

def _fast_iterator(self, n, max_part, depth=0): 

""" 

A fast (recursive) iterator which returns a list. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=2, max_length=2) 

sage: list(P._fast_iterator(5, 5)) 

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

sage: list(P._fast_iterator(5, 3)) 

[[3, 2]] 

sage: list(P._fast_iterator(5, 6)) 

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

""" 

if n == 0 or depth >= self._max_len: 

yield [] 

return 

 

# Special case 

if depth + 1 == self._max_len: 

if max_part >= n: 

yield [n] 

return 

 

if n < max_part: 

max_part = n 

bdry = self._ell - 1 

 

for i in reversed(range(1, max_part+1)): 

for p in self._fast_iterator(n-i, i, depth+1): 

if p.count(i) < bdry: 

yield [i] + p 

 

class RegularPartitions_bounded(RegularPartitions): 

r""" 

The class of `\ell`-regular `k`-bounded partitions. 

 

INPUT: 

 

- ``ell`` -- the integer `\ell` 

- ``k`` -- integer; the value `k` 

 

.. SEEALSO:: 

 

:class:`~sage.combinat.partition.RegularPartitions` 

""" 

def __init__(self, ell, k): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=4, max_part=3) 

sage: TestSuite(P).run() 

 

1-regular partitions:: 

 

sage: P = Partitions(regular=1, max_part=3) 

sage: P in FiniteEnumeratedSets() 

True 

sage: TestSuite(P).run() 

""" 

self.k = k 

RegularPartitions.__init__(self, ell, False) 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: P = Partitions(regular=4, max_part=3) 

sage: [3, 3, 3] in P 

True 

sage: [] in P 

True 

sage: [4, 2, 1] in P 

False 

""" 

return len(x) == 0 or (x[0] <= self.k and RegularPartitions.__contains__(self, x)) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: from sage.combinat.partition import RegularPartitions_bounded 

sage: RegularPartitions_bounded(4, 3) 

4-Regular 3-Bounded Partitions 

""" 

return "{}-Regular {}-Bounded Partitions".format(self._ell, self.k) 

 

def __iter__(self): 

""" 

Iterate over ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(regular=2, max_part=3) 

sage: list(P) 

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

 

Check that 1-regular partitions works (:trac:`20584`):: 

 

sage: P = Partitions(regular=1, max_part=3) 

sage: list(P) 

[[]] 

""" 

k = self.k 

for n in reversed(range(k*(k+1)/2 * self._ell)): 

for p in self._fast_iterator(n, k): 

yield self.element_class(self, p) 

 

class RegularPartitions_n(RegularPartitions, Partitions_n): 

r""" 

The class of `\ell`-regular partitions of `n`. 

 

INPUT: 

 

- ``n`` -- the integer `n` to partition 

- ``ell`` -- the integer `\ell` 

 

.. SEEALSO:: 

 

:class:`~sage.combinat.partition.RegularPartitions` 

""" 

def __init__(self, n, ell): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, regular=3) 

sage: TestSuite(P).run() 

 

1-regular partitions:: 

 

sage: P = Partitions(5, regular=1) 

sage: TestSuite(P).run() 

""" 

RegularPartitions.__init__(self, ell) 

Partitions_n.__init__(self, n) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: from sage.combinat.partition import RegularPartitions_n 

sage: RegularPartitions_n(3, 5) 

5-Regular Partitions of the integer 3 

""" 

return "{}-Regular Partitions of the integer {}".format(self._ell, self.n) 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: P = Partitions(5, regular=3) 

sage: [3, 1, 1] in P 

True 

sage: [3, 2, 1] in P 

False 

""" 

return RegularPartitions.__contains__(self, x) and sum(x) == self.n 

 

def __iter__(self): 

""" 

Iterate over ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, regular=3) 

sage: list(P) 

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

""" 

for p in self._fast_iterator(self.n, self.n): 

yield self.element_class(self, p) 

 

def cardinality(self): 

""" 

Return the cardinality of ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, regular=3) 

sage: P.cardinality() 

5 

sage: P = Partitions(5, regular=6) 

sage: P.cardinality() 

7 

sage: P.cardinality() == Partitions(5).cardinality() 

True 

 

TESTS: 

 

Check the corner case:: 

 

sage: P = Partitions(0, regular=3) 

sage: P.cardinality() 

1 

 

Check for 1-regular partitions:: 

 

sage: P = Partitions(0, regular=1) 

sage: P.cardinality() 

1 

sage: P = Partitions(5, regular=1) 

sage: P.cardinality() 

0 

 

""" 

if self._ell > self.n: 

return Partitions_n.cardinality(self) 

return ZZ.sum(1 for x in self) 

 

def _an_element_(self): 

""" 

Returns a partition in ``self``. 

 

EXAMPLES:: 

 

sage: P = Partitions(5, regular=2) 

sage: P._an_element_() 

[4, 1] 

 

sage: P = Partitions(0, regular=1) 

sage: P._an_element_() 

[] 

 

sage: P = Partitions(5, regular=1) 

sage: P._an_element_() 

Traceback (most recent call last): 

... 

EmptySetError 

""" 

if self._ell == 1 and self.n > 0: 

from sage.categories.sets_cat import EmptySetError 

raise EmptySetError 

return Partitions_n._an_element_(self) 

 

###################### 

# Ordered Partitions # 

###################### 

 

class OrderedPartitions(Partitions): 

""" 

The class of ordered partitions of `n`. If `k` is specified, then this 

contains only the ordered partitions of length `k`. 

 

An *ordered partition* of a nonnegative integer `n` means a list of 

positive integers whose sum is `n`. This is the same as a composition 

of `n`. 

 

.. NOTE:: 

 

It is recommended that you use :meth:`Compositions` instead as 

:meth:`OrderedPartitions` wraps GAP. 

 

EXAMPLES:: 

 

sage: OrderedPartitions(3) 

Ordered partitions of 3 

sage: OrderedPartitions(3).list() 

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

sage: OrderedPartitions(3,2) 

Ordered partitions of 3 of length 2 

sage: OrderedPartitions(3,2).list() 

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

 

sage: OrderedPartitions(10,k=2).list() 

[[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]] 

sage: OrderedPartitions(4).list() 

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

 

""" 

 

@staticmethod 

def __classcall_private__(cls, n, k=None): 

""" 

Normalize the input to ensure a unique representation. 

 

TESTS:: 

 

sage: P = OrderedPartitions(3,2) 

sage: P2 = OrderedPartitions(3,2) 

sage: P is P2 

True 

""" 

if k is not None: 

k = Integer(k) 

return super(OrderedPartitions, cls).__classcall__(cls, Integer(n), k) 

 

def __init__(self, n, k): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: o = OrderedPartitions(4,2) 

 

TESTS:: 

 

sage: TestSuite( OrderedPartitions(5,3) ).run() 

""" 

Partitions.__init__(self) 

self.n = n 

self.k = k 

 

def __contains__(self, x): 

""" 

Check to see if ``x`` is an element of ``self``. 

 

EXAMPLES:: 

 

sage: o = OrderedPartitions(4,2) 

sage: [2,1] in o 

False 

sage: [2,2] in o 

True 

sage: [1,2,1] in o 

False 

""" 

C = composition.Compositions(self.n, length=self.k) 

return C(x) in composition.Compositions(self.n, length=self.k) 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: OrderedPartitions(3) # indirect doctest 

Ordered partitions of 3 

sage: OrderedPartitions(3,2) # indirect doctest 

Ordered partitions of 3 of length 2 

""" 

string = "Ordered partitions of %s"%self.n 

if self.k is not None: 

string += " of length %s"%self.k 

return string 

 

def list(self): 

""" 

Return a list of partitions in ``self``. 

 

EXAMPLES:: 

 

sage: OrderedPartitions(3).list() 

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

sage: OrderedPartitions(3,2).list() 

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

""" 

n = self.n 

k = self.k 

if self.k is None: 

ans=gap.eval("OrderedPartitions(%s)"%(ZZ(n))) 

else: 

ans=gap.eval("OrderedPartitions(%s,%s)"%(ZZ(n),ZZ(k))) 

result = eval(ans.replace('\n','')) 

result.reverse() 

return result 

 

def cardinality(self): 

""" 

Return the cardinality of ``self``. 

 

EXAMPLES:: 

 

sage: OrderedPartitions(3).cardinality() 

4 

sage: OrderedPartitions(3,2).cardinality() 

2 

sage: OrderedPartitions(10,2).cardinality() 

9 

sage: OrderedPartitions(15).cardinality() 

16384 

""" 

n = self.n 

k = self.k 

if k is None: 

ans=gap.eval("NrOrderedPartitions(%s)"%(n)) 

else: 

ans=gap.eval("NrOrderedPartitions(%s,%s)"%(n,k)) 

return ZZ(ans) 

 

########################## 

# Partitions Greatest LE # 

########################## 

 

class PartitionsGreatestLE(UniqueRepresentation, IntegerListsLex): 

""" 

The class of all (unordered) "restricted" partitions of the integer `n` 

having parts less than or equal to the integer `k`. 

 

EXAMPLES:: 

 

sage: PartitionsGreatestLE(10,2) 

Partitions of 10 having parts less than or equal to 2 

sage: PartitionsGreatestLE(10,2).list() 

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

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

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

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

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

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

 

sage: [4,3,2,1] in PartitionsGreatestLE(10,2) 

False 

sage: [2,2,2,2,2] in PartitionsGreatestLE(10,2) 

True 

sage: PartitionsGreatestLE(10,2).first().parent() 

Partitions... 

""" 

 

def __init__(self, n, k): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: p = PartitionsGreatestLE(10,2) 

sage: p.n, p.k 

(10, 2) 

sage: TestSuite(p).run() 

""" 

IntegerListsLex.__init__(self, n, max_slope = 0, min_part=1, max_part = k) 

self.n = n 

self.k = k 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: PartitionsGreatestLE(10, 2) # indirect doctest 

Partitions of 10 having parts less than or equal to 2 

""" 

return "Partitions of %s having parts less than or equal to %s"%(self.n, self.k) 

 

Element = Partition 

options = Partitions.options 

 

########################## 

# Partitions Greatest EQ # 

########################## 

 

class PartitionsGreatestEQ(UniqueRepresentation, IntegerListsLex): 

""" 

The class of all (unordered) "restricted" partitions of the integer `n` 

having its greatest part equal to the integer `k`. 

 

EXAMPLES:: 

 

sage: PartitionsGreatestEQ(10,2) 

Partitions of 10 having greatest part equal to 2 

sage: PartitionsGreatestEQ(10,2).list() 

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

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

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

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

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

 

sage: [4,3,2,1] in PartitionsGreatestEQ(10,2) 

False 

sage: [2,2,2,2,2] in PartitionsGreatestEQ(10,2) 

True 

sage: [1]*10 in PartitionsGreatestEQ(10,2) 

False 

 

sage: PartitionsGreatestEQ(10,2).first().parent() 

Partitions... 

""" 

 

def __init__(self, n, k): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: p = PartitionsGreatestEQ(10,2) 

sage: p.n, p.k 

(10, 2) 

sage: TestSuite(p).run() 

""" 

IntegerListsLex.__init__(self, n, max_slope = 0, max_part=k, floor = [k]) 

self.n = n 

self.k = k 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: PartitionsGreatestEQ(10,2) # indirect doctest 

Partitions of 10 having greatest part equal to 2 

""" 

return "Partitions of %s having greatest part equal to %s"%(self.n, self.k) 

 

Element = Partition 

options = Partitions.options 

 

######################### 

# Restricted Partitions # 

######################### 

 

def RestrictedPartitions(n, S, k=None): 

r""" 

This function has been deprecated and will be removed in a 

future version of Sage; use :class:`Partitions` with the ``parts_in`` 

keyword. Note, however, that the current implementation of 

:class:`Partitions` does not allow the ``parts_in`` keyword to be combined 

with keywords such as ``max_length``; see :trac:`13072` and :trac:`12278` 

for more details. This class should not be removed until this problem 

has been fixed. 

 

Original docstring follows. 

 

A restricted partition is, like an ordinary partition, an unordered 

sum `n = p_1+p_2+\ldots+p_k` of positive integers and is 

represented by the list `p = [p_1,p_2,\ldots,p_k]`, in 

nonincreasing order. The difference is that here the `p_i` 

must be elements from the set `S`, while for ordinary 

partitions they may be elements from `[1..n]`. 

 

Returns the list of all restricted partitions of the positive 

integer n into sums with `k` summands with the summands of the 

partition coming from the set `S`. If `k` is not given all restricted 

partitions for all `k` are returned. 

 

Wraps GAP's ``RestrictedPartitions``. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: RestrictedPartitions(5,[3,2,1]) 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

doctest:...: DeprecationWarning: RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

Partitions of 5 restricted to the values [1, 2, 3] 

sage: RestrictedPartitions(5,[3,2,1]).list() 

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

sage: RestrictedPartitions(5,[3,2,1],4) 

Partitions of 5 restricted to the values [1, 2, 3] of length 4 

sage: RestrictedPartitions(5,[3,2,1],4).list() 

[[2, 1, 1, 1]] 

""" 

from sage.misc.superseded import deprecation 

deprecation(13072, 'RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.') 

return RestrictedPartitions_nsk(n, S, k) 

 

class RestrictedPartitions_nsk(CombinatorialClass): 

r""" 

We are deprecating :meth:`RestrictedPartitions`, so this class should 

be deprecated too. See :trac:`13072`. 

""" 

def __init__(self, n, S, k=None): 

""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: r = RestrictedPartitions(5,[3,2,1]) 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

sage: r == loads(dumps(r)) 

True 

""" 

from sage.misc.superseded import deprecation 

deprecation(13072, 'RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.') 

self.n = n 

self.S = S 

self.S.sort() 

self.k = k 

 

Element = Partition 

options = Partitions.options 

 

def __contains__(self, x): 

""" 

Check to see if ``x`` is in ``self``. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: [4,1] in RestrictedPartitions(5,[3,2,1]) 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

False 

sage: [3,2] in RestrictedPartitions(5,[3,2,1]) 

True 

sage: [3,2] in RestrictedPartitions(5,[3,2,1],4) 

False 

sage: [2,1,1,1] in RestrictedPartitions(5,[3,2,1],4) 

True 

""" 

return x in Partitions_n(self.n) and all(i in self.S for i in x) \ 

and (self.k is None or len(x) == self.k) 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: RestrictedPartitions(5,[3,2,1]).__repr__() 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

'Partitions of 5 restricted to the values [1, 2, 3]' 

""" 

string = "Partitions of %s restricted to the values %s"%(self.n, self.S) 

if self.k is not None: 

string += " of length %s" % self.k 

return string 

 

def list(self): 

r""" 

Returns the list of all restricted partitions of the positive 

integer `n` into sums with `k` summands with the summands of the 

partition coming from the set `S`. If `k` is not given all 

restricted partitions for all `k` are returned. 

 

Wraps GAP's RestrictedPartitions. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: RestrictedPartitions(8,[1,3,5,7]).list() 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

[[7, 1], [5, 3], [5, 1, 1, 1], [3, 3, 1, 1], [3, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]] 

sage: RestrictedPartitions(8,[1,3,5,7],2).list() 

[[7, 1], [5, 3]] 

""" 

n = self.n 

k = self.k 

S = self.S 

if k is None: 

ans=gap.eval("RestrictedPartitions(%s,%s)"%(n,S)) 

else: 

ans=gap.eval("RestrictedPartitions(%s,%s,%s)"%(n,S,k)) 

result = eval(ans) 

result.reverse() 

return [Partition(p) for p in result] 

 

def cardinality(self): 

""" 

Returns the size of ``self``. 

 

Wraps GAP's NrRestrictedPartitions. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import RestrictedPartitions 

sage: RestrictedPartitions(8,[1,3,5,7]).cardinality() 

doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead. 

See http://trac.sagemath.org/13072 for details. 

6 

sage: RestrictedPartitions(8,[1,3,5,7],2).cardinality() 

2 

""" 

n = self.n 

k = self.k 

S = self.S 

if k is None: 

ans=gap.eval("NrRestrictedPartitions(%s,%s)"%(ZZ(n),S)) 

else: 

ans=gap.eval("NrRestrictedPartitions(%s,%s,%s)"%(ZZ(n),S,ZZ(k))) 

return ZZ(ans) 

 

 

######################################################################### 

 

#### partitions 

 

def number_of_partitions(n, algorithm='default'): 

r""" 

Returns the number of partitions of `n` with, optionally, at most `k` 

parts. 

 

The options of :meth:`number_of_partitions()` are being deprecated 

:trac:`13072` in favour of :meth:`Partitions_n.cardinality()` so that 

:meth:`number_of_partitions()` can become a stripped down version of 

the fastest algorithm available (currently this is using FLINT). 

 

INPUT: 

 

- ``n`` -- an integer 

 

- ``algorithm`` -- (default: 'default') 

[Will be deprecated except in Partition().cardinality() ] 

 

- ``'default'`` -- If ``k`` is not ``None``, then use Gap (very slow). 

If ``k`` is ``None``, use FLINT. 

 

- ``'flint'`` -- use FLINT 

 

- ``'bober'`` -- use Jonathan Bober's implementation 

 

EXAMPLES:: 

 

sage: v = Partitions(5).list(); v 

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

sage: len(v) 

7 

sage: number_of_partitions(5, algorithm='bober') 

7 

 

The input must be a nonnegative integer or a ``ValueError`` is raised. 

 

:: 

 

sage: number_of_partitions(-5) 

Traceback (most recent call last): 

... 

ValueError: n (=-5) must be a nonnegative integer 

 

:: 

 

sage: number_of_partitions(10) 

42 

sage: number_of_partitions(3) 

3 

sage: number_of_partitions(10) 

42 

sage: number_of_partitions(40) 

37338 

sage: number_of_partitions(100) 

190569292 

sage: number_of_partitions(100000) 

27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519 

 

A generating function for the number of partitions `p_n` is given by the 

reciprocal of Euler's function: 

 

.. MATH:: 

 

\sum_{n=0}^{\infty} p_n x^n = \prod_{k=1}^{\infty} \left( 

\frac{1}{1-x^k} \right). 

 

We use Sage to verify that the first several coefficients do 

instead agree:: 

 

sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen() 

sage: prod([(1-q^k)^(-1) for k in range(1,9)]) ## partial product of 

1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9) 

sage: [number_of_partitions(k) for k in range(2,10)] 

[2, 3, 5, 7, 11, 15, 22, 30] 

 

REFERENCES: 

 

- :wikipedia:`Partition\_(number\_theory)` 

 

TESTS:: 

 

sage: n = 500 + randint(0,500) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1500 + randint(0,1500) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 1000000 + randint(0,1000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 

True 

sage: n = 100000000 + randint(0,100000000) 

sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 # long time (4s on sage.math, 2011) 

True 

 

""" 

n = ZZ(n) 

if n < 0: 

raise ValueError("n (=%s) must be a nonnegative integer"%n) 

elif n == 0: 

return ZZ.one() 

 

if algorithm == 'default': 

algorithm = 'flint' 

 

if algorithm == 'flint': 

return cached_number_of_partitions(n) 

 

elif algorithm == 'bober': 

return bober_number_of_partitions(n) 

 

raise ValueError("unknown algorithm '%s'"%algorithm) 

 

def number_of_partitions_length(n, k, algorithm='hybrid'): 

r""" 

Return the number of partitions of `n` with length `k`. 

 

This is a wrapper for GAP's ``NrPartitions`` function. 

 

EXAMPLES:: 

 

sage: from sage.combinat.partition import number_of_partitions_length 

sage: number_of_partitions_length(5, 2) 

2 

sage: number_of_partitions_length(10, 2) 

5 

sage: number_of_partitions_length(10, 4) 

9 

sage: number_of_partitions_length(10, 0) 

0 

sage: number_of_partitions_length(10, 1) 

1 

sage: number_of_partitions_length(0, 0) 

1 

sage: number_of_partitions_length(0, 1) 

0 

""" 

if algorithm == 'hybrid': 

# Do the hybrid algorithm 

 

# Special relations between n and k 

if n < k: 

return ZZ.zero() 

if n == k and n >= 0: 

return ZZ.one() 

 

# Special case of n 

if n <= 0: 

# Note: we've already checked the case when n == k == 0 

return ZZ.zero() 

 

# Small values of k 

if k <= 0: 

return ZZ.zero() 

if k == 1: 

return ZZ.one() 

if k == 2: 

return n // 2 

 

# We have one column of length `k` and all (inner) partitions of 

# size `n-k` can't have length more than `k` 

if n <= k*2: 

return number_of_partitions(n - k) 

 

# Fall back to GAP 

 

return ZZ(gap.eval( "NrPartitions({},{})".format(ZZ(n), ZZ(k)) )) 

 

 

########## 

# trac 14225: Partitions() is frequently used, but only weakly cached. Hence, 

# establish a strong reference to it. 

 

_Partitions = Partitions() 

 

# Rather than caching an under-used function I have cached the default 

# number_of_partitions functions which is currently using FLINT. 

# AM trac #13072 

cached_number_of_partitions = cached_function( flint_number_of_partitions ) 

 

# October 2012: fixing outdated pickles which use classes being deprecated 

from sage.structure.sage_object import register_unpickle_override 

from sage.combinat.partition_tuple import PartitionTuples_level_size 

register_unpickle_override('sage.combinat.partition', 'PartitionTuples_nk', PartitionTuples_level_size) 

register_unpickle_override('sage.combinat.partition', 'Partition_class', Partition) 

register_unpickle_override('sage.combinat.partition', 'OrderedPartitions_nk', OrderedPartitions) 

register_unpickle_override('sage.combinat.partition', 'PartitionsInBox_hw', PartitionsInBox) 

register_unpickle_override('sage.combinat.partition', 'PartitionsGreatestLE_nk', PartitionsGreatestLE) 

register_unpickle_override('sage.combinat.partition', 'PartitionsGreatestEQ_nk', PartitionsGreatestEQ) 

 

# Deprecations from trac:18555. July 2016 

from sage.misc.superseded import deprecated_function_alias 

Partitions.global_options=deprecated_function_alias(18555, Partitions.options) 

PartitionOptions = deprecated_function_alias(18555, Partitions.options) 

Partitions_with_constraints.global_options = deprecated_function_alias(18555, Partitions_with_constraints.options) 

PartitionsGreatestLE.global_options = deprecated_function_alias(18555, PartitionsGreatestLE.options) 

PartitionsGreatestEQ.global_options = deprecated_function_alias(18555, PartitionsGreatestEQ.options) 

RestrictedPartitions_nsk.global_options = deprecated_function_alias(18555, RestrictedPartitions_nsk.options)