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

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

r""" 

Tableaux 

 

AUTHORS: 

 

- Mike Hansen (2007): initial version 

 

- Jason Bandlow (2011): updated to use Parent/Element model, and many 

minor fixes 

 

- Andrew Mathas (2012-13): completed the transition to the parent/element model 

begun by Jason Bandlow 

 

- Travis Scrimshaw (11-22-2012): Added tuple options, changed ``*katabolism*`` 

to ``*catabolism*``. Cleaned up documentation. 

 

This file consists of the following major classes: 

 

Element classes: 

 

* :class:`Tableau` 

* :class:`SemistandardTableau` 

* :class:`StandardTableau` 

 

Factory classes: 

 

* :class:`Tableaux` 

* :class:`SemistandardTableaux` 

* :class:`StandardTableaux` 

 

Parent classes: 

 

* :class:`Tableaux_all` 

* :class:`Tableaux_size` 

* :class:`SemistandardTableaux_all` (facade class) 

* :class:`SemistandardTableaux_size` 

* :class:`SemistandardTableaux_size_inf` 

* :class:`SemistandardTableaux_size_weight` 

* :class:`SemistandardTableaux_shape` 

* :class:`SemistandardTableaux_shape_inf` 

* :class:`SemistandardTableaux_shape_weight` 

* :class:`StandardTableaux_all` (facade class) 

* :class:`StandardTableaux_size` 

* :class:`StandardTableaux_shape` 

 

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

 

.. TODO:: 

 

- Move methods that only apply to semistandard tableaux from tableau to 

semistandard tableau 

 

- Copy/move functionality to skew tableaux 

 

- Add a class for tableaux of a given shape (eg Tableaux_shape) 

""" 

 

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

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

# 2011 Jason Bandlow <jbandlow@gmail.com> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

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

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

from __future__ import print_function, absolute_import 

from six.moves import range, zip 

from six import add_metaclass, text_type 

 

from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets 

from sage.sets.family import Family 

from sage.sets.non_negative_integers import NonNegativeIntegers 

from sage.structure.global_options import GlobalOptions 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.structure.list_clone import ClonableList 

from sage.structure.parent import Parent 

from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass 

from sage.rings.finite_rings.integer_mod_ring import IntegerModRing 

from sage.rings.infinity import PlusInfinity 

from sage.arith.all import factorial, binomial 

from sage.rings.integer import Integer 

from sage.combinat.composition import Composition, Compositions 

from sage.combinat.integer_vector import IntegerVectors, integer_vectors_nk_fast_iter 

import sage.libs.symmetrica.all as symmetrica 

import sage.misc.prandom as random 

from . import permutation 

from sage.groups.perm_gps.permgroup import PermutationGroup 

from sage.misc.all import uniq, prod 

from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 

from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets 

from sage.categories.sets_cat import Sets 

from sage.combinat.combinatorial_map import combinatorial_map 

 

 

@add_metaclass(InheritComparisonClasscallMetaclass) 

class Tableau(ClonableList): 

""" 

A class to model a tableau. 

 

INPUT: 

 

- ``t`` -- a Tableau, a list of iterables, or an empty list 

 

OUTPUT: 

 

- A Tableau object constructed from ``t``. 

 

A tableau is abstractly a mapping from the cells in a partition to 

arbitrary objects (called entries). It is often represented as a 

finite list of nonempty lists (or, more generally an iterator of 

iterables) of weakly decreasing lengths. This list, 

in particular, can be empty, representing the empty tableau. 

 

Note that Sage uses the English convention for partitions and 

tableaux; the longer rows are displayed on top. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]); t 

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

sage: t.shape() 

[3, 2] 

sage: t.pp() # pretty print 

1 2 3 

4 5 

sage: t.is_standard() 

True 

 

sage: Tableau([['a','c','b'],[[],(2,1)]]) 

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

sage: Tableau([]) # The empty tableau 

[] 

 

When using code that will generate a lot of tableaux, it is slightly more 

efficient to construct a Tableau from the appropriate Parent object:: 

 

sage: T = Tableaux() 

sage: T([[1, 2, 3], [4, 5]]) 

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

 

.. SEEALSO:: 

 

- :class:`Tableaux` 

- :class:`SemistandardTableaux` 

- :class:`SemistandardTableau` 

- :class:`StandardTableaux` 

- :class:`StandardTableau` 

 

TESTS:: 

 

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

Traceback (most recent call last): 

... 

ValueError: A tableau must be a list of iterables of weakly decreasing length. 

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

Traceback (most recent call last): 

... 

ValueError: A tableau must be a list of iterables. 

 

""" 

@staticmethod 

def __classcall_private__(cls, t): 

r""" 

This ensures that a tableau is only ever constructed as an 

``element_class`` call of an appropriate parent. 

 

TESTS:: 

 

sage: t = Tableau([[1,1],[1]]) 

sage: TestSuite(t).run() 

 

sage: t.parent() 

Tableaux 

sage: t.category() 

Category of elements of Tableaux 

sage: type(t) 

<class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'> 

""" 

if isinstance(t, cls): 

return t 

 

# We must verify ``t`` is a list of iterables, and also 

# normalize it to be a list of tuples. 

try: 

t = [tuple(_) for _ in t] 

except TypeError: 

raise ValueError("A tableau must be a list of iterables.") 

 

return Tableaux_all().element_class(Tableaux_all(), t) 

 

def __init__(self, parent, t): 

r""" 

Initialize a tableau. 

 

TESTS:: 

 

sage: t = Tableaux()([[1,1],[1]]) 

sage: s = Tableaux(3)([[1,1],[1]]) 

sage: s==t 

True 

sage: t.parent() 

Tableaux 

sage: s.parent() 

Tableaux of size 3 

sage: r = Tableaux()(s); r.parent() 

Tableaux 

sage: s is t # identical tableaux are distinct objects 

False 

 

A tableau is shallowly immutable. See :trac:`15862`. The entries 

themselves may be mutable objects, though in that case the 

resulting Tableau should be unhashable. 

 

sage: T = Tableau([[1,2],[2]]) 

sage: t0 = T[0] 

sage: t0[1] = 3 

Traceback (most recent call last): 

... 

TypeError: 'tuple' object does not support item assignment 

sage: T[0][1] = 5 

Traceback (most recent call last): 

... 

TypeError: 'tuple' object does not support item assignment 

""" 

if isinstance(t, Tableau): 

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

ClonableList.__init__(self, parent, t) 

return 

 

# Normalize t to be a list of tuples. 

t = [tuple(_) for _ in t] 

 

ClonableList.__init__(self, parent, t) 

# This dispatches the input verification to the :meth:`check` 

# method. 

 

def __eq__(self, other): 

r""" 

Check whether ``self`` is equal to ``other``. 

 

.. TODO:: 

 

This overwrites the equality check of 

:class:`~sage.structure.list_clone.ClonableList` 

in order to circumvent the coercion framework. 

Eventually this should be solved more elegantly, 

for example along the lines of what was done for 

`k`-tableaux. 

 

For now, two elements are equal if their underlying 

defining lists compare equal. 

 

INPUT: 

 

``other`` -- the element that ``self`` is compared to 

 

OUTPUT: 

 

A Boolean. 

 

TESTS:: 

 

sage: t = Tableau([[1,2]]) 

sage: t == 0 

False 

sage: t == Tableaux(2)([[1,2]]) 

True 

""" 

if isinstance(other, Tableau): 

return list(self) == list(other) 

else: 

return list(self) == other 

 

def __ne__(self, other): 

r""" 

Check whether ``self`` is unequal to ``other``. 

 

See the documentation of :meth:`__eq__`. 

 

INPUT: 

 

``other`` -- the element that ``self`` is compared to 

 

OUTPUT: 

 

A Boolean. 

 

TESTS:: 

 

sage: t = Tableau([[2,3],[1]]) 

sage: t != [] 

True 

""" 

if isinstance(other, Tableau): 

return list(self) != list(other) 

else: 

return list(self) != other 

 

def __hash__(self): 

""" 

Return the hash of ``self``. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1],[2]]) 

sage: hash(tuple(t)) == hash(t) 

True 

""" 

return hash(tuple(self)) 

 

def check(self): 

r""" 

Check that ``self`` is a valid straight-shape tableau. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1],[2]]) 

sage: t.check() 

 

sage: t = Tableau([[None, None, 1], [2, 4], [3, 4, 5]]) 

Traceback (most recent call last): 

... 

ValueError: A tableau must be a list of iterables of weakly decreasing length. 

""" 

# Check that it has partition shape. That's all we require from a 

# general tableau. 

lens = [len(_) for _ in self] 

for (a, b) in zip(lens, lens[1:]): 

if a < b: 

raise ValueError("A tableau must be a list of iterables of weakly decreasing length.") 

if lens and lens[-1] == 0: 

raise ValueError("A tableau must not have empty rows.") 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: Tableaux.options.display="list" 

sage: t 

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

sage: Tableaux.options.display="array" 

sage: t 

1 2 3 

4 5 

sage: Tableaux.options.display="compact"; t 

1,2,3/4,5 

sage: Tableaux.options._reset() 

""" 

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

 

def _repr_list(self): 

""" 

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

 

EXAMPLES:: 

 

sage: T = Tableau([[1,2,3],[4,5]]) 

sage: T._repr_list() 

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

""" 

return repr([list(_) for _ in self]) 

 

# See #18024. CombinatorialObject provided __str__, though ClonableList 

# doesn't. Emulate the old functionality. Possibly remove when 

# CombinatorialObject is removed. 

__str__ = _repr_list 

 

def _repr_diagram(self): 

""" 

Return a string representation of ``self`` as an array. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: print(t._repr_diagram()) 

1 2 3 

4 5 

sage: Tableaux.options.convention="french" 

sage: print(t._repr_diagram()) 

4 5 

1 2 3 

sage: Tableaux.options._reset() 

 

TESTS: 

 

Check that :trac:`20768` is fixed:: 

 

sage: T = Tableau([[1523, 1, 2],[1,12341, -2]]) 

sage: T.pp() 

1523 1 2 

1 12341 -2 

""" 

if not self: 

return " -" 

 

# Get the widths of the columns 

str_tab = [[str(data) for data in row] for row in self] 

col_widths = [2]*len(str_tab[0]) 

for row in str_tab: 

for i,e in enumerate(row): 

col_widths[i] = max(col_widths[i], len(e)) 

 

if self.parent().options('convention') == "French": 

str_tab = reversed(str_tab) 

 

return "\n".join(" " 

+ " ".join("{:>{width}}".format(e,width=col_widths[i]) 

for i,e in enumerate(row)) 

for row in str_tab) 

 

def _repr_compact(self): 

""" 

Return a compact string representation of ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2,3],[4,5]])._repr_compact() 

'1,2,3/4,5' 

sage: Tableau([])._repr_compact() 

'-' 

""" 

if not self: 

return '-' 

return '/'.join(','.join('%s'%r for r in row) for row in self) 

 

def _ascii_art_(self): 

""" 

TESTS:: 

 

sage: ascii_art(list(StandardTableaux(3))) 

[ 1 ] 

[ 1 3 1 2 2 ] 

[ 1 2 3, 2 , 3 , 3 ] 

sage: Tableaux.options(ascii_art="compact") 

sage: ascii_art(list(StandardTableaux(3))) 

[ |1| ] 

[ |1|3| |1|2| |2| ] 

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

sage: Tableaux.options(convention="french", ascii_art="table") 

sage: ascii_art(list(StandardTableaux(3))) 

[ +---+ ] 

[ | 3 | ] 

[ +---+ +---+ +---+ ] 

[ | 2 | | 3 | | 2 | ] 

[ +---+---+---+ +---+---+ +---+---+ +---+ ] 

[ | 1 | 2 | 3 | | 1 | 3 | | 1 | 2 | | 1 | ] 

[ +---+---+---+, +---+---+, +---+---+, +---+ ] 

sage: Tableaux.options(ascii_art="repr") 

sage: ascii_art(list(StandardTableaux(3))) 

[ 3 ] 

[ 2 3 2 ] 

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

sage: Tableaux.options._reset() 

""" 

ascii = self.parent().options._dispatch(self,'_ascii_art_','ascii_art') 

from sage.typeset.ascii_art import AsciiArt 

return AsciiArt(ascii.splitlines()) 

 

def _unicode_art_(self): 

r""" 

TESTS:: 

 

sage: unicode_art(Tableau([[1,2,3],[4],[5]])) 

┌───┬───┬───┐ 

│ 1 │ 2 │ 3 │ 

├───┼───┴───┘ 

│ 4 │ 

├───┤ 

│ 5 │ 

└───┘ 

sage: unicode_art(Tableau([])) 

┌┐ 

└┘ 

""" 

from sage.typeset.unicode_art import UnicodeArt 

return UnicodeArt(self._ascii_art_table(use_unicode=True).splitlines()) 

 

_ascii_art_repr = _repr_diagram 

 

def _ascii_art_table(self, use_unicode=False): 

""" 

TESTS: 

 

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

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: print(t._ascii_art_table()) 

+---+---+---+ 

| 1 | 2 | 3 | 

+---+---+---+ 

| 4 | 5 | 

+---+---+ 

sage: Tableaux.options.convention="french" 

sage: print(t._ascii_art_table()) 

+---+---+ 

| 4 | 5 | 

+---+---+---+ 

| 1 | 2 | 3 | 

+---+---+---+ 

sage: t = Tableau([]); print(t._ascii_art_table()) 

++ 

++ 

sage: Tableaux.options._reset() 

 

sage: t = Tableau([[1,2,3,10,15],[12,15,17]]) 

sage: print(t._ascii_art_table()) 

+----+----+----+----+----+ 

| 1 | 2 | 3 | 10 | 15 | 

+----+----+----+----+----+ 

| 12 | 15 | 17 | 

+----+----+----+ 

 

sage: t = Tableau([[1,2,15,7],[12,5,6],[8,10],[9]]) 

sage: Tableaux.options(ascii_art='table') 

sage: ascii_art(t) 

+----+----+----+---+ 

| 1 | 2 | 15 | 7 | 

+----+----+----+---+ 

| 12 | 5 | 6 | 

+----+----+----+ 

| 8 | 10 | 

+----+----+ 

| 9 | 

+----+ 

sage: Tableaux.options.convention='french' 

sage: ascii_art(t) 

+----+ 

| 9 | 

+----+----+ 

| 8 | 10 | 

+----+----+----+ 

| 12 | 5 | 6 | 

+----+----+----+---+ 

| 1 | 2 | 15 | 7 | 

+----+----+----+---+ 

sage: Tableaux.options._reset() 

 

Unicode version:: 

 

sage: t = Tableau([[1,2,15,7],[12,5],[8,10],[9]]) 

sage: print(t._ascii_art_table(use_unicode=True)) 

┌────┬────┬────┬───┐ 

│ 1 │ 2 │ 15 │ 7 │ 

├────┼────┼────┴───┘ 

│ 12 │ 5 │ 

├────┼────┤ 

│ 8 │ 10 │ 

├────┼────┘ 

│ 9 │ 

└────┘ 

sage: Tableaux().options.convention='french' 

sage: t = Tableau([[1,2,15,7],[12,5],[8,10],[9]]) 

sage: print(t._ascii_art_table(use_unicode=True)) 

┌────┐ 

│ 9 │ 

├────┼────┐ 

│ 8 │ 10 │ 

├────┼────┤ 

│ 12 │ 5 │ 

├────┼────┼────┬───┐ 

│ 1 │ 2 │ 15 │ 7 │ 

└────┴────┴────┴───┘ 

sage: Tableaux.options._reset() 

""" 

if use_unicode: 

import unicodedata 

v = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL') 

h = unicodedata.lookup('BOX DRAWINGS LIGHT HORIZONTAL') 

dl = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND LEFT') 

dr = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND RIGHT') 

ul = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND LEFT') 

ur = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND RIGHT') 

vr = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND RIGHT') 

vl = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND LEFT') 

uh = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND HORIZONTAL') 

dh = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND HORIZONTAL') 

vh = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL') 

from sage.typeset.unicode_art import unicode_art as art 

else: 

v = '|' 

h = '-' 

dl = dr = ul = ur = vr = vl = uh = dh = vh = '+' 

from sage.typeset.ascii_art import ascii_art as art 

 

if not self: 

return dr + dl + '\n' + ur + ul 

 

# Get the widths of the columns 

str_tab = [[art(_) for _ in row] for row in self] 

col_widths = [1]*len(str_tab[0]) 

if use_unicode: 

# Special handling of overline not adding to printed length 

def get_len(e): 

return len(e) - list(text_type(e)).count(u"\u0304") 

else: 

get_len = len 

for row in str_tab: 

for i,e in enumerate(row): 

col_widths[i] = max(col_widths[i], get_len(e)) 

 

matr = [] # just the list of lines 

l1 = "" 

l1 += dr + h*(2+col_widths[0]) 

for w in col_widths[1:]: 

l1 += dh + h + h + h*w 

matr.append(l1 + dl) 

for nrow,row in enumerate(str_tab): 

l1 = ""; l2 = "" 

n = len(str_tab[nrow+1]) if nrow+1 < len(str_tab) else 0 

for i,(e,w) in enumerate(zip(row,col_widths)): 

if i == 0: 

if n: 

l1 += vr + h*(2+w) 

else: 

l1 += ur + h*(2+w) 

elif i <= n: 

l1 += vh + h*(2+w) 

else: 

l1 += uh + h*(2+w) 

if use_unicode: 

l2 += u"{} {:^{width}} ".format(v, e, width=w) 

else: 

l2 += "{} {:^{width}} ".format(v, e, width=w) 

if i+1 <= n: 

l1 += vl 

else: 

l1 += ul 

l2 += v 

matr.append(l2) 

matr.append(l1) 

 

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

return "\n".join(matr) 

else: 

output = "\n".join(reversed(matr)) 

if use_unicode: 

tr = { 

ord(dl): ul, ord(dr): ur, 

ord(ul): dl, ord(ur): dr, 

ord(dh): uh, ord(uh): dh} 

return output.translate(tr) 

else: 

return output 

 

def _ascii_art_compact(self): 

""" 

TESTS: 

 

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

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: print(t._ascii_art_compact()) 

|1|2|3| 

|4|5| 

sage: Tableaux.options.convention="french" 

sage: print(t._ascii_art_compact()) 

|4|5| 

|1|2|3| 

sage: Tableaux.options._reset() 

 

sage: t = Tableau([[1,2,3,10,15],[12,15,17]]) 

sage: print(t._ascii_art_compact()) 

|1 |2 |3 |10|15| 

|12|15|17| 

 

sage: t = Tableau([]) 

sage: print(t._ascii_art_compact()) 

. 

""" 

if not self: 

return "." 

 

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

T = self 

else: 

T = reversed(self) 

 

# Get the widths of the columns 

str_tab = [[str(_) for _ in row] for row in T] 

col_widths = [1]*len(self[0]) 

for row in str_tab: 

for i,e in enumerate(row): 

col_widths[i] = max(col_widths[i], len(e)) 

 

return "\n".join("|" 

+ "|".join("{:^{width}}".format(e, width=col_widths[i]) 

for i,e in enumerate(row)) 

+ "|" for row in str_tab) 

 

def _latex_(self): 

r""" 

Return a LaTeX version of ``self``. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,2],[2,3],[3]]) 

sage: latex(t) # indirect doctest 

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

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

\lr{1}&\lr{1}&\lr{2}\\\cline{1-3} 

\lr{2}&\lr{3}\\\cline{1-2} 

\lr{3}\\\cline{1-1} 

\end{array}$} 

} 

sage: Tableaux.options.convention="french" 

sage: latex(t) # indirect doctest 

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

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

\lr{3}\\\cline{1-2} 

\lr{2}&\lr{3}\\\cline{1-3} 

\lr{1}&\lr{1}&\lr{2}\\\cline{1-3} 

\end{array}$} 

} 

sage: Tableaux.options._reset() 

""" 

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

 

_latex_list=_repr_list 

 

def _latex_diagram(self): 

r""" 

Return a LaTeX representation of ``self`` as a Young diagram. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,2],[2,3],[3]]) 

sage: print(t._latex_diagram()) 

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

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

\lr{1}&\lr{1}&\lr{2}\\\cline{1-3} 

\lr{2}&\lr{3}\\\cline{1-2} 

\lr{3}\\\cline{1-1} 

\end{array}$} 

} 

""" 

if len(self) == 0: 

return "{\\emptyset}" 

from .output import tex_from_array 

return tex_from_array(self) 

 

def __truediv__(self, t): 

""" 

Return the skew tableau ``self``/``t``, where ``t`` is a partition 

contained in the shape of ``self``. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[3,4],[5]]) 

sage: t/[1,1] 

[[None, 2, 3], [None, 4], [5]] 

sage: t/[3,1] 

[[None, None, None], [None, 4], [5]] 

sage: t/[2,1,1,1] 

Traceback (most recent call last): 

... 

ValueError: the shape of the tableau must contain the partition 

""" 

from sage.combinat.partition import Partition 

#if t is a list, convert it to a partition first 

if isinstance(t, list): 

t = Partition(t) 

 

#Check to make sure that tableau shape contains t 

if not self.shape().contains(t): 

raise ValueError("the shape of the tableau must contain the partition") 

 

st = [list(row) for row in self] # create deep copy of t 

 

for i, t_i in enumerate(t): 

st_i = st[i] 

for j in range(t_i): 

st_i[j] = None 

 

from sage.combinat.skew_tableau import SkewTableau 

return SkewTableau(st) 

 

__div__ = __truediv__ 

 

def __call__(self, *cell): 

r""" 

 

INPUT: 

 

- ``cell`` -- a pair of integers, tuple, or list specifying a cell in 

the tableau 

 

OUTPUT: 

 

- The value in the corresponding cell. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: t(1,0) 

4 

sage: t((1,0)) 

4 

sage: t(3,3) 

Traceback (most recent call last): 

... 

IndexError: The cell (3,3) is not contained in [[1, 2, 3], [4, 5]] 

""" 

try: 

i,j = cell 

except ValueError: 

i,j = cell[0] 

 

try: 

return self[i][j] 

except IndexError: 

raise IndexError("The cell (%d,%d) is not contained in %s"%(i,j,repr(self))) 

 

def level(self): 

""" 

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

 

This function exists mainly for compatibility with :class:`TableauTuple`. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2,3],[4,5]]).level() 

1 

""" 

return 1 

 

def components(self): 

""" 

This function returns a list containing itself. It exists mainly for 

compatibility with :class:`TableauTuple` as it allows constructions like the 

example below. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]); 

sage: for s in t.components(): print(s.to_list()) 

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

""" 

return [self] 

 

@combinatorial_map(name='shape') 

def shape(self): 

r""" 

Return the shape of a tableau ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2,3],[4,5],[6]]).shape() 

[3, 2, 1] 

""" 

from sage.combinat.partition import Partition 

return Partition([len(row) for row in self]) 

 

def size(self): 

""" 

Return the size of the shape of the tableau ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 4, 6], [2, 5], [3]]).size() 

6 

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

4 

""" 

return sum([len(row) for row in self]) 

 

def corners(self): 

""" 

Return the corners of the tableau ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 4, 6], [2, 5], [3]]).corners() 

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

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

[(1, 1)] 

""" 

return self.shape().corners() 

 

 

@combinatorial_map(order=2,name='conjugate') 

def conjugate(self): 

""" 

Return the conjugate of ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).conjugate() 

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

sage: c = StandardTableau([[1,2],[3,4]]).conjugate() 

sage: c.parent() 

Standard tableaux 

""" 

if self: 

conj = [[] for i in range(len(self[0]))] 

for row in self: 

for j, x in enumerate(row): 

conj[j].append(x) 

else: 

conj = [] 

 

if isinstance(self, StandardTableau): 

return StandardTableau(conj) 

return Tableau(conj) 

 

def pp(self): 

""" 

Returns a pretty print string of the tableau. 

 

EXAMPLES:: 

 

sage: T = Tableau([[1,2,3],[3,4],[5]]) 

sage: T.pp() 

1 2 3 

3 4 

5 

sage: Tableaux.options.convention="french" 

sage: T.pp() 

5 

3 4 

1 2 3 

sage: Tableaux.options._reset() 

""" 

print(self._repr_diagram()) 

 

def to_word_by_row(self): 

""" 

Return the word obtained from a row reading of the tableau ``self`` 

(starting with the lowermost row, reading every row from left 

to right). 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).to_word_by_row() 

word: 3412 

sage: Tableau([[1, 4, 6], [2, 5], [3]]).to_word_by_row() 

word: 325146 

""" 

from sage.combinat.words.word import Word 

w = [] 

for row in reversed(self): 

w += row 

return Word(w) 

 

def to_word_by_column(self): 

""" 

Return the word obtained from a column reading of the tableau ``self`` 

(starting with the leftmost column, reading every column from bottom 

to top). 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).to_word_by_column() 

word: 3142 

sage: Tableau([[1, 4, 6], [2, 5], [3]]).to_word_by_column() 

word: 321546 

""" 

from sage.combinat.words.word import Word 

w = [] 

for row in self.conjugate(): 

w += row[::-1] 

return Word(w) 

 

def to_word(self): 

""" 

An alias for :meth:`to_word_by_row`. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).to_word() 

word: 3412 

sage: Tableau([[1, 4, 6], [2, 5], [3]]).to_word() 

word: 325146 

""" 

return self.to_word_by_row() 

 

def descents(self): 

""" 

Return a list of the cells ``(i,j)`` such that 

``self[i][j] > self[i-1][j]``. 

 

.. WARNING:: 

 

This is not to be confused with the descents of a standard tableau. 

 

EXAMPLES:: 

 

sage: Tableau( [[1,4],[2,3]] ).descents() 

[(1, 0)] 

sage: Tableau( [[1,2],[3,4]] ).descents() 

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

sage: Tableau( [[1,2,3],[4,5]] ).descents() 

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

""" 

descents = [] 

for i in range(1,len(self)): 

for j in range(len(self[i])): 

if self[i][j] > self[i-1][j]: 

descents.append((i,j)) 

return descents 

 

def major_index(self): 

""" 

Return the major index of ``self``. 

 

The major index of a tableau `T` is defined to be the sum of the number 

of descents of ``T`` (defined in :meth:`descents`) with the sum of 

their legs' lengths. 

 

.. WARNING:: 

 

This is not to be confused with the major index of a 

standard tableau. 

 

EXAMPLES:: 

 

sage: Tableau( [[1,4],[2,3]] ).major_index() 

1 

sage: Tableau( [[1,2],[3,4]] ).major_index() 

2 

 

If the major index would be defined in the sense of standard tableaux 

theory, then the following would give 3 for a result:: 

 

sage: Tableau( [[1,2,3],[4,5]] ).major_index() 

2 

""" 

descents = self.descents() 

p = self.shape() 

return len(descents) + sum([ p.leg_length(*d) for d in descents ]) 

 

def inversions(self): 

""" 

Return a list of the inversions of ``self``. 

 

Let `T` be a tableau. An inversion is an attacking pair `(c,d)` of 

the shape of `T` (see 

:meth:`~sage.combinat.partition.Partition.attacking_pairs` for 

a definition of this) such that the entry of `c` in `T` is 

greater than the entry of `d`. 

 

.. WARNING:: 

 

Do not mistake this for the inversions of a standard tableau. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[2,5]]) 

sage: t.inversions() 

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

sage: t = Tableau([[1,4,3],[5,2],[2,6],[3]]) 

sage: t.inversions() 

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

""" 

inversions = [] 

for i, row in enumerate(self): 

for j, entry in enumerate(row): 

#c is in position (i,j) 

#Find the d that satisfy condition 1 

for k in range(j+1, len(row)): 

if entry > row[k]: 

inversions.append( ((i,j),(i,k)) ) 

#Find the d that satisfy condition 2 

if i == 0: 

continue 

for k in range(j): 

if entry > previous_row[k]: 

inversions.append( ((i,j),(i-1,k)) ) 

previous_row = row 

return inversions 

 

def inversion_number(self): 

""" 

Return the inversion number of ``self``. 

 

The inversion number is defined to be the number of inversions of 

``self`` minus the sum of the arm lengths of the descents of ``self`` 

(see the :meth:`inversions` and :meth:`descents` methods for the 

relevant definitions). 

 

.. WARNING:: 

 

This has none of the meanings in which the word "inversion" 

is used in the theory of standard tableaux. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[2,5]]) 

sage: t.inversion_number() 

0 

sage: t = Tableau([[1,2,4],[3,5]]) 

sage: t.inversion_number() 

0 

""" 

p = self.shape() 

return len(self.inversions()) - sum([ p.arm_length(*cell) for cell in self.descents() ]) 

 

def to_sign_matrix(self, max_entry = None): 

r""" 

Return the sign matrix of ``self``. 

 

A sign matrix is an `m \times n` matrix of 0's, 1's and -1's such that the 

partial sums of each column is either 0 or 1 and the partial sums of 

each row is non-negative. [Aval2008]_ 

 

INPUT: 

 

- ``max_entry`` -- A non-negative integer, the maximum allowable number in 

the tableau. Defaults to the largest entry in the tableau if not specified. 

 

 

EXAMPLES:: 

 

sage: t = SemistandardTableau([[1,1,1,2,4],[3,3,4],[4,5],[6,6]]) 

sage: t.to_sign_matrix(6) 

[ 0 0 0 1 0 0] 

[ 0 1 0 -1 0 0] 

[ 1 -1 0 1 0 0] 

[ 0 0 1 -1 1 1] 

[ 0 0 0 1 -1 0] 

sage: t = Tableau([[1,2,4],[3,5]]) 

sage: t.to_sign_matrix(7) 

[ 0 0 0 1 0 0 0] 

[ 0 1 0 -1 1 0 0] 

[ 1 -1 1 0 -1 0 0] 

sage: t=Tableau([(4,5,4,3),(2,1,3)]) 

sage: t.to_sign_matrix(5) 

[ 0 0 1 0 0] 

[ 0 0 0 1 0] 

[ 1 0 -1 -1 1] 

[-1 1 0 1 -1] 

sage: s=Tableau([(1,0,-2,4),(3,4,5)]) 

sage: s.to_sign_matrix(6) 

Traceback (most recent call last): 

... 

ValueError: the entries must be non-negative integers 

 

 

REFERENCES: 

 

.. [Aval2008] Jean-Christope Aval. 

*Keys and Alternating Sign Matrices*, 

Seminaire Lotharingien de Combinatoire 59 (2008) B59f 

:arxiv:`0711.2150` 

""" 

from sage.rings.all import ZZ 

from sage.sets.positive_integers import PositiveIntegers 

PI = PositiveIntegers() 

for row in self: 

if any(c not in PI for c in row): 

raise ValueError("the entries must be non-negative integers") 

from sage.matrix.matrix_space import MatrixSpace 

if max_entry is None: 

max_entry=max([max(c) for c in self]) 

MS = MatrixSpace(ZZ, len(self[0]), max_entry) 

Tconj = self.conjugate() 

l = len(Tconj) 

d = {(l-i-1,elem-1): 1 for i, row in enumerate(Tconj) for elem in row} 

partial_sum_matrix = MS(d) 

from copy import copy 

sign_matrix = copy(MS.zero()) 

for j in range(max_entry): 

sign_matrix[0,j] = partial_sum_matrix[0,j] 

for i in range(1,l): 

for j in range(max_entry): 

sign_matrix[i,j] = partial_sum_matrix[i,j] - partial_sum_matrix[i-1,j] 

return sign_matrix 

 

def schuetzenberger_involution(self, n = None, check=True): 

r""" 

Return the Schuetzenberger involution of the tableau ``self``. 

 

This method relies on the analogous method on words, which reverts the 

word and then complements all letters within the underlying ordered 

alphabet. If `n` is specified, the underlying alphabet is assumed to 

be `[1, 2, \ldots, n]`. If no alphabet is specified, `n` is the maximal 

letter appearing in ``self``. 

 

INPUT: 

 

- ``n`` -- an integer specifying the maximal letter in the 

alphabet (optional) 

- ``check`` -- (Default: ``True``) Check to make sure ``self`` is 

semistandard. Set to ``False`` to avoid this check. (optional) 

 

OUTPUT: 

 

- a tableau, the Schuetzenberger involution of ``self`` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,1],[2,2]]) 

sage: t.schuetzenberger_involution(3) 

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

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: t.schuetzenberger_involution() 

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

 

sage: t = Tableau([[1,3,5,7],[2,4,6],[8,9]]) 

sage: t.schuetzenberger_involution() 

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

 

sage: t = Tableau([]) 

sage: t.schuetzenberger_involution() 

[] 

 

sage: t = StandardTableau([[1,2,3],[4,5]]) 

sage: s = t.schuetzenberger_involution() 

sage: s.parent() 

Standard tableaux 

""" 

if check and self not in SemistandardTableaux(): 

raise ValueError("the tableau must be semistandard") 

w = [i for row in self for i in reversed(row)] 

# ``w`` is now the Semitic reading word of ``self`` (that is, 

# the reverse of the reading word of ``self``). 

if not w: 

return self 

if n is None: 

n = max(w) 

N = n + 1 

wi = [N - i for i in w] 

t = Tableau([[wi[0]]]) 

for k in wi[1:]: 

t = t.bump(k) 

if isinstance(self, StandardTableau): 

return StandardTableau(list(t)) 

elif isinstance(self, SemistandardTableau): 

return SemistandardTableau(list(t)) 

return t 

 

@combinatorial_map(order=2,name='evacuation') 

def evacuation(self, n = None, check=True): 

r""" 

Return the evacuation of the tableau ``self``. 

 

This is an alias for :meth:`schuetzenberger_involution`. 

 

This method relies on the analogous method on words, which reverts the 

word and then complements all letters within the underlying ordered 

alphabet. If `n` is specified, the underlying alphabet is assumed to 

be `[1, 2, \ldots, n]`. If no alphabet is specified, `n` is the maximal 

letter appearing in ``self``. 

 

INPUT: 

 

- ``n`` -- an integer specifying the maximal letter in the 

alphabet (optional) 

- ``check`` -- (Default: ``True``) Check to make sure ``self`` is 

semistandard. Set to ``False`` to avoid this check. (optional) 

 

OUTPUT: 

 

- a tableau, the evacuation of ``self`` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,1],[2,2]]) 

sage: t.evacuation(3) 

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

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: t.evacuation() 

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

 

sage: t = Tableau([[1,3,5,7],[2,4,6],[8,9]]) 

sage: t.evacuation() 

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

 

sage: t = Tableau([]) 

sage: t.evacuation() 

[] 

 

sage: t = StandardTableau([[1,2,3],[4,5]]) 

sage: s = t.evacuation() 

sage: s.parent() 

Standard tableaux 

""" 

return self.schuetzenberger_involution(n,check) 

 

@combinatorial_map(name="standardization") 

def standardization(self, check=True): 

r""" 

Return the standardization of ``self``, assuming ``self`` is a 

semistandard tableau. 

 

The standardization of a semistandard tableau `T` is the standard 

tableau `\mathrm{st}(T)` of the same shape as `T` whose 

reversed reading word is the standardization of the reversed reading 

word of `T`. 

 

The standardization of a word `w` can be formed by replacing all `1`'s in 

`w` by `1, 2, \ldots, k_1` from left to right, all `2`'s in `w` by 

`k_1 + 1, k_1 + 2, \ldots, k_2`, and repeating for all letters which 

appear in `w`. 

See also :meth:`Word.standard_permutation()`. 

 

INPUT: 

 

- ``check`` -- (Default: ``True``) Check to make sure ``self`` is 

semistandard. Set to ``False`` to avoid this check. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,3,3,4],[2,4,4],[5,16]]) 

sage: t.standardization() 

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

 

Standard tableaux are fixed under standardization:: 

 

sage: all((t == t.standardization() for t in StandardTableaux(6))) 

True 

sage: t = Tableau([]) 

sage: t.standardization() 

[] 

 

The reading word of the standardization is the standardization of 

the reading word:: 

 

sage: T = SemistandardTableaux(shape=[6,3,3,1], max_entry=5) 

sage: all(t.to_word().standard_permutation() == t.standardization().reading_word_permutation() for t in T) # long time 

True 

""" 

if check and self not in SemistandardTableaux(): 

raise ValueError("the tableau must be semistandard") 

T = from_shape_and_word(self.shape(), self.to_word_by_row().standard_permutation()) 

return StandardTableaux()(T) 

 

def bender_knuth_involution(self, k, rows=None, check=True): 

r""" 

Return the image of ``self`` under the `k`-th Bender--Knuth 

involution, assuming ``self`` is a semistandard tableau. 

 

Let `T` be a tableau, then a *lower free `k` in `T`* means a cell of 

`T` which is filled with the integer `k` and whose direct lower 

neighbor is not filled with the integer `k + 1` (in particular, 

this lower neighbor might not exist at all). Let an *upper free `k + 1` 

in `T`* mean a cell of `T` which is filled with the integer `k + 1` 

and whose direct upper neighbor is not filled with the integer `k` 

(in particular, this neighbor might not exist at all). It is clear 

that for any row `r` of `T`, the lower free `k`'s and the upper 

free `k + 1`'s in `r` together form a contiguous interval or `r`. 

 

The *`k`-th Bender--Knuth switch at row `i`* changes the entries of 

the cells in this interval in such a way that if it used to have 

`a` entries of `k` and `b` entries of `k + 1`, it will now 

have `b` entries of `k` and `a` entries of `k + 1`. For fixed `k`, the 

`k`-th Bender--Knuth switches for different `i` commute. The 

composition of the `k`-th Bender--Knuth switches for all rows is 

called the *`k`-th Bender-Knuth involution*. This is used to show that 

the Schur functions defined by semistandard tableaux are symmetric 

functions. 

 

INPUT: 

 

- ``k`` -- an integer 

 

- ``rows`` -- (Default ``None``) When set to ``None``, the method 

computes the `k`-th Bender--Knuth involution as defined above. 

When an iterable, this computes the composition of the `k`-th 

Bender--Knuth switches at row `i` over all `i` in ``rows``. When set 

to an integer `i`, the method computes the `k`-th Bender--Knuth 

switch at row `i`. Note the indexing of the rows starts with `1`. 

 

- ``check`` -- (Default: ``True``) Check to make sure ``self`` is 

semistandard. Set to ``False`` to avoid this check. 

 

OUTPUT: 

 

The image of ``self`` under either the `k`-th Bender--Knuth 

involution, the `k`-th Bender--Knuth switch at a certain row, or 

the composition of such switches, as detailed in the INPUT section. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,3,4,4,5,6,7],[2,2,4,6,7,7,7],[3,4,5,8,8,9],[6,6,7,10],[7,8,8,11],[8]]) 

sage: t.bender_knuth_involution(1) == t 

True 

sage: t.bender_knuth_involution(2) 

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

sage: t.bender_knuth_involution(3) 

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

sage: t.bender_knuth_involution(4) 

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

sage: t.bender_knuth_involution(5) 

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

sage: t.bender_knuth_involution(666) == t 

True 

sage: t.bender_knuth_involution(4, 2) == t 

True 

sage: t.bender_knuth_involution(4, 3) 

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

 

The ``rows`` keyword can be an iterator:: 

 

sage: t.bender_knuth_involution(6, iter([1,2])) == t 

False 

sage: t.bender_knuth_involution(6, iter([3,4])) == t 

True 

 

The Bender--Knuth involution is an involution:: 

 

sage: T = SemistandardTableaux(shape=[3,1,1], max_entry=4) 

sage: all(all(t.bender_knuth_involution(k).bender_knuth_involution(k) == t for k in range(1,5)) for t in T) 

True 

 

The same holds for the single switches:: 

 

sage: all(all(t.bender_knuth_involution(k, j).bender_knuth_involution(k, j) == t for k in range(1,5) for j in range(1, 5)) for t in T) 

True 

 

Locality of the Bender--Knuth involutions:: 

 

sage: all(all(t.bender_knuth_involution(k).bender_knuth_involution(l) == t.bender_knuth_involution(l).bender_knuth_involution(k) for k in range(1,5) for l in range(1,5) if abs(k - l) > 1) for t in T) 

True 

 

Berenstein and Kirillov [BerKilGGI]_ have shown that 

`(s_1 s_2)^6 = id` (for tableaux of straight shape):: 

 

sage: p = lambda t, k: t.bender_knuth_involution(k).bender_knuth_involution(k + 1) 

sage: all(p(p(p(p(p(p(t,1),1),1),1),1),1) == t for t in T) 

True 

 

However, `(s_2 s_3)^6 = id` is false:: 

 

sage: p = lambda t, k: t.bender_knuth_involution(k).bender_knuth_involution(k + 1) 

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

sage: x = t 

sage: for i in range(6): x = p(x, 2) 

sage: x 

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

sage: x == t 

False 

 

TESTS:: 

 

sage: t = Tableau([]) 

sage: t.bender_knuth_involution(3) 

[] 

 

REFERENCES: 

 

.. [BerKilGGI] \A. N. Kirillov, A. D. Berenstein, 

*Groups generated by involutions, Gelfand--Tsetlin patterns, 

and combinatorics of Young tableaux*, 

Algebra i Analiz, 1995, Volume 7, Issue 1, pp. 92--152. 

http://math.uoregon.edu/~arkadiy/bk1.pdf 

""" 

if check and self not in SemistandardTableaux(): 

raise ValueError("the tableau must be semistandard") 

from sage.combinat.skew_tableau import SkewTableau 

sk = SkewTableau(self).bender_knuth_involution(k, rows, False) 

return SemistandardTableaux()(list(sk)) 

 

@combinatorial_map(name ='reading word permutation') 

def reading_word_permutation(self): 

""" 

Return the permutation obtained by reading the entries of the 

standardization of ``self`` row by row, starting with the 

bottommost row (in English notation). 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2],[3,4]]).reading_word_permutation() 

[3, 4, 1, 2] 

 

Check that :trac:`14724` is fixed:: 

 

sage: SemistandardTableau([[1,1]]).reading_word_permutation() 

[1, 2] 

""" 

return permutation.Permutation(self.standardization().to_word()) 

 

def entries(self): 

""" 

Return the tuple of all entries of ``self``, in the order obtained 

by reading across the rows from top to bottom (in English 

notation). 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,3], [2]]) 

sage: t.entries() 

(1, 3, 2) 

""" 

return sum(self, ()) 

 

def entry(self, cell): 

""" 

Returns the entry of cell ``cell`` in the tableau ``self``. Here, 

``cell`` should be given as a tuple `(i,j)` of zero-based 

coordinates (so the northwesternmost cell in English notation 

is `(0,0)`). 

 

EXAMPLES:: 

 

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

sage: t.entry( (0,0) ) 

1 

sage: t.entry( (1,1) ) 

4 

""" 

i,j = cell 

return self[i][j] 

 

def weight(self): 

r""" 

Return the weight of the tableau ``self``. Trailing zeroes are 

omitted when returning the weight. 

 

The weight of a tableau `T` is the sequence `(a_1, a_2, a_3, \ldots )`, 

where `a_k` is the number of entries of `T` equal to `k`. This 

sequence contains only finitely many nonzero entries. 

 

The weight of a tableau `T` is the same as the weight of the 

reading word of `T`, for any reading order. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).weight() 

[1, 1, 1, 1] 

 

sage: Tableau([]).weight() 

[] 

 

sage: Tableau([[1,3,3,7],[4,2],[2,3]]).weight() 

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

 

TESTS: 

 

We check that this agrees with going to the word:: 

 

sage: t = Tableau([[1,3,4,7],[6,2],[2,3]]) 

sage: def by_word(T): 

....: ed = T.to_word().evaluation_dict() 

....: m = max(ed) + 1 

....: return [ed.get(k, 0) for k in range(1, m)] 

sage: by_word(t) == t.weight() 

True 

sage: SST = SemistandardTableaux(shape=[3,1,1]) 

sage: all(by_word(t) == t.weight() for t in SST) 

True 

""" 

if len(self) == 0: 

return [] 

m = max(max(row) for row in self) 

res = [0] * m 

for row in self: 

for i in row: 

if i > 0: 

res[i - 1] += 1 

return res 

 

evaluation = weight 

 

def is_row_strict(self): 

""" 

Return ``True`` if ``self`` is a row strict tableau and ``False`` 

otherwise. 

 

A tableau is row strict if the entries in each row are in 

(strictly) increasing order. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 3], [2, 4]]).is_row_strict() 

True 

sage: Tableau([[1, 2], [2, 4]]).is_row_strict() 

True 

sage: Tableau([[2, 3], [2, 4]]).is_row_strict() 

True 

sage: Tableau([[5, 3], [2, 4]]).is_row_strict() 

False 

""" 

return all(row[i]<row[i+1] for row in self for i in range(len(row)-1)) 

 

def is_row_increasing(self, weak=False): 

r""" 

Return ``True`` if the entries in each row are in increasing order, 

and ``False`` otherwise. 

 

By default, this checks for strictly increasing rows. Set ``weak`` 

to ``True`` to test for weakly increasing rows. 

 

EXAMPLES:: 

 

sage: T = Tableau([[1, 1, 3], [1, 2]]) 

sage: T.is_row_increasing(weak=True) 

True 

sage: T.is_row_increasing() 

False 

sage: Tableau([[2, 1]]).is_row_increasing(weak=True) 

False 

""" 

if weak: 

def test(a, b): 

return a <= b 

else: 

def test(a, b): 

return a < b 

return all(test(a, b) for row in self for (a, b) in zip(row, row[1:])) 

 

def is_column_increasing(self, weak=False): 

r""" 

Return ``True`` if the entries in each column are in increasing order, 

and ``False`` otherwise. 

 

By default, this checks for strictly increasing columns. Set ``weak`` 

to ``True`` to test for weakly increasing columns. 

 

EXAMPLES:: 

 

sage: T = Tableau([[1, 1, 3], [1, 2]]) 

sage: T.is_column_increasing(weak=True) 

True 

sage: T.is_column_increasing() 

False 

sage: Tableau([[2], [1]]).is_column_increasing(weak=True) 

False 

""" 

if weak: 

def test(a, b): 

return a <= b 

else: 

def test(a, b): 

return a < b 

def tworow(a, b): 

return all(test(a[i], b_i) for i, b_i in enumerate(b)) 

return all(tworow(self[r], self[r+1]) for r in range(len(self) - 1)) 

 

def is_column_strict(self): 

""" 

Return ``True`` if ``self`` is a column strict tableau and ``False`` 

otherwise. 

 

A tableau is column strict if the entries in each column are in 

(strictly) increasing order. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 3], [2, 4]]).is_column_strict() 

True 

sage: Tableau([[1, 2], [2, 4]]).is_column_strict() 

True 

sage: Tableau([[2, 3], [2, 4]]).is_column_strict() 

False 

sage: Tableau([[5, 3], [2, 4]]).is_column_strict() 

False 

sage: Tableau([]).is_column_strict() 

True 

sage: Tableau([[1, 4, 2]]).is_column_strict() 

True 

sage: Tableau([[1, 4, 2], [2, 5]]).is_column_strict() 

True 

sage: Tableau([[1, 4, 2], [2, 3]]).is_column_strict() 

False 

""" 

def tworow(a, b): 

return all(a[i] < b_i for i, b_i in enumerate(b)) 

return all(tworow(self[r], self[r+1]) for r in range(len(self)-1)) 

 

def is_semistandard(self): 

r""" 

Return ``True`` if ``self`` is a semistandard tableau, and ``False`` 

otherwise. 

 

A tableau is semistandard if its rows weakly increase and its columns 

strictly increase. 

 

EXAMPLES:: 

 

sage: Tableau([[1,1],[1,2]]).is_semistandard() 

False 

sage: Tableau([[1,2],[1,2]]).is_semistandard() 

False 

sage: Tableau([[1,1],[2,2]]).is_semistandard() 

True 

sage: Tableau([[1,2],[2,3]]).is_semistandard() 

True 

sage: Tableau([[4,1],[3,2]]).is_semistandard() 

False 

""" 

return self.is_row_increasing(weak=True) and self.is_column_increasing() 

 

def is_standard(self): 

""" 

Return ``True`` if ``self`` is a standard tableau and ``False`` 

otherwise. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 3], [2, 4]]).is_standard() 

True 

sage: Tableau([[1, 2], [2, 4]]).is_standard() 

False 

sage: Tableau([[2, 3], [2, 4]]).is_standard() 

False 

sage: Tableau([[5, 3], [2, 4]]).is_standard() 

False 

""" 

entries = sorted(self.entries()) 

return entries == list(range(1, self.size() + 1)) and self.is_row_strict() and self.is_column_strict() 

 

def is_increasing(self): 

""" 

Return ``True`` if ``self`` is an increasing tableau and 

``False`` otherwise. 

 

A tableau is increasing if it is both row strict and column strict. 

 

EXAMPLES:: 

 

sage: Tableau([[1, 3], [2, 4]]).is_increasing() 

True 

sage: Tableau([[1, 2], [2, 4]]).is_increasing() 

True 

sage: Tableau([[2, 3], [2, 4]]).is_increasing() 

False 

sage: Tableau([[5, 3], [2, 4]]).is_increasing() 

False 

sage: Tableau([[1, 2, 3], [2, 3], [3]]).is_increasing() 

True 

""" 

return self.is_row_strict() and self.is_column_strict() 

 

def is_rectangular(self): 

""" 

Return ``True`` if the tableau ``self`` is rectangular and 

``False`` otherwise. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).is_rectangular() 

True 

sage: Tableau([[1,2,3],[4,5],[6]]).is_rectangular() 

False 

sage: Tableau([]).is_rectangular() 

True 

""" 

if len(self) == 0: 

return True 

return len(self[-1]) == len(self[0]) 

 

def vertical_flip(self): 

""" 

Return the tableau obtained by vertically flipping the tableau ``self``. 

 

This only works for rectangular tableaux. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).vertical_flip() 

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

""" 

if not self.is_rectangular(): 

raise TypeError("the tableau must be rectangular to use vertical_flip()") 

 

return Tableau([row for row in reversed(self)]) 

 

def rotate_180(self): 

""" 

Return the tableau obtained by rotating ``self`` by `180` degrees. 

 

This only works for rectangular tableaux. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).rotate_180() 

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

""" 

if not self.is_rectangular(): 

raise TypeError("the tableau must be rectangular to use rotate_180()") 

 

return Tableau([ [l for l in reversed(row)] for row in reversed(self) ]) 

 

def cells(self): 

""" 

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

 

Coordinates start at `0`, so the northwesternmost cell (in 

English notation) has coordinates `(0, 0)`. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).cells() 

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

""" 

s = [] 

for i, row in enumerate(self): 

s += [ (i,j) for j in range(len(row)) ] 

return s 

 

def cells_containing(self, i): 

r""" 

Return the list of cells in which the letter `i` appears in the 

tableau ``self``. The list is ordered with cells appearing from 

left to right. 

 

Cells are given as pairs of coordinates `(a, b)`, where both 

rows and columns are counted from `0` (so `a = 0` means the cell 

lies in the leftmost column of the tableau, etc.). 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,3],[2,3,5],[4,5]]) 

sage: t.cells_containing(5) 

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

sage: t.cells_containing(4) 

[(2, 0)] 

sage: t.cells_containing(6) 

[] 

 

sage: t = Tableau([[1,1,2,4],[2,4,4],[4]]) 

sage: t.cells_containing(4) 

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

 

sage: t = Tableau([[1,1,2,8,9],[2,5,6,11],[3,7,7,13],[4,8,9],[5],[13],[14]]) 

sage: t.cells_containing(8) 

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

 

sage: Tableau([]).cells_containing(3) 

[] 

""" 

cell_list = [] 

for r in range(len(self)-1, -1, -1): 

rth_row = self[r] 

for c,val in enumerate(rth_row): 

if val == i: 

cell_list.append((r,c)) 

return cell_list 

 

def leq(self, secondtab): 

""" 

Check whether each entry of ``self`` is less-or-equal to the 

corresponding entry of a further tableau ``secondtab``. 

 

INPUT: 

 

- ``secondtab`` -- a tableau of the same shape as ``self`` 

 

EXAMPLES: 

 

sage: T = Tableau([[1, 2], [3]]) 

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

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

sage: H = Tableau([[1, 2], [4]]) 

sage: T.leq(S) 

True 

sage: T.leq(T) 

True 

sage: T.leq(G) 

False 

sage: T.leq(H) 

True 

sage: S.leq(T) 

False 

sage: S.leq(G) 

False 

sage: S.leq(H) 

False 

sage: G.leq(H) 

False 

sage: H.leq(G) 

False 

 

TESTS:: 

 

sage: StandardTableau(T).leq(S) 

True 

sage: T.leq(SemistandardTableau(S)) 

True 

""" 

if not secondtab in Tableaux(): 

raise TypeError("{} must be a tableau".format(secondtab)) 

sh = self.shape() 

if sh != secondtab.shape(): 

raise TypeError("the tableaux must be the same shape") 

return all( self[a][b] <= secondtab[a][b] for a in range(len(self)) 

for b in range(len(self[a])) ) 

 

def k_weight(self, k): 

r""" 

Return the `k`-weight of ``self``. 

 

A tableau has `k`-weight `\alpha = (\alpha_1, ..., \alpha_n)` 

if there are exactly `\alpha_i` distinct residues for the 

cells occupied by the letter `i` for each `i`. The residue 

of a cell in position `(a,b)` is `a-b` modulo `k+1`. 

 

This definition is the one used in [Ive2012]_ (p. 12). 

 

REFERENCES: 

 

.. [Ive2012] \S. Iveson, 

*Tableaux on `k + 1`-cores, reduced words for affine 

permutations, and `k`-Schur expansions*, 

Operators on `k`-tableaux and the `k`-Littlewood-Richardson 

rule for a special case, 

UC Berkeley: Mathematics, Ph.D. Thesis, 

https://escholarship.org/uc/item/7pd1v1b5 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[2,3]]).k_weight(1) 

[1, 1, 1] 

sage: Tableau([[1,2],[2,3]]).k_weight(2) 

[1, 2, 1] 

sage: t = Tableau([[1,1,1,2,5],[2,3,6],[3],[4]]) 

sage: t.k_weight(1) 

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

sage: t.k_weight(2) 

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

sage: t.k_weight(3) 

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

sage: t.k_weight(4) 

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

sage: t.k_weight(5) 

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

""" 

res = [] 

w = self.weight() 

s = self.cells() 

 

for l in range(1,len(w)+1): 

new_s = [(i,j) for i,j in s if self[i][j] == l] 

 

#If there are no elements that meet the condition 

if new_s == []: 

res.append(0) 

continue 

x = uniq([ (i-j)%(k+1) for i,j in new_s ]) 

res.append(len(x)) 

 

return res 

 

def is_k_tableau(self, k): 

r""" 

Checks whether ``self`` is a valid weak `k`-tableau. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[2,3],[3]]) 

sage: t.is_k_tableau(3) 

True 

sage: t = Tableau([[1,1,3],[2,2],[3]]) 

sage: t.is_k_tableau(3) 

False 

""" 

shapes = self.to_chain() 

kshapes = [ la.k_conjugate(k) for la in shapes ] 

return all( kshapes[i+1].contains(kshapes[i]) for i in range(len(shapes)-1) ) 

 

def restrict(self, n): 

""" 

Return the restriction of the semistandard tableau ``self`` 

to ``n``. If possible, the restricted tableau will have the same 

parent as this tableau. 

 

If `T` is a semistandard tableau and `n` is a nonnegative integer, 

then the restriction of `T` to `n` is defined as the 

(semistandard) tableau obtained by removing all cells filled with 

entries greater than `n` from `T`. 

 

.. NOTE:: 

 

If only the shape of the restriction, rather than the whole 

restriction, is needed, then the faster method 

:meth:`restriction_shape` is preferred. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3],[4]]).restrict(3) 

[[1, 2], [3]] 

sage: StandardTableau([[1,2],[3],[4]]).restrict(2) 

[[1, 2]] 

sage: Tableau([[1,2,3],[2,4,4],[3]]).restrict(0) 

[] 

sage: Tableau([[1,2,3],[2,4,4],[3]]).restrict(2) 

[[1, 2], [2]] 

sage: Tableau([[1,2,3],[2,4,4],[3]]).restrict(3) 

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

sage: Tableau([[1,2,3],[2,4,4],[3]]).restrict(5) 

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

 

If possible the restricted tableau will belong to the same category as 

the original tableau:: 

 

sage: S=StandardTableau([[1,2,4,7],[3,5],[6]]); S.category() 

Category of elements of Standard tableaux 

sage: S.restrict(4).category() 

Category of elements of Standard tableaux 

sage: SS=StandardTableaux([4,2,1])([[1,2,4,7],[3,5],[6]]); SS.category() 

Category of elements of Standard tableaux of shape [4, 2, 1] 

sage: SS.restrict(4).category() 

Category of elements of Standard tableaux 

 

sage: Tableau([[1,2],[3],[4]]).restrict(3) 

[[1, 2], [3]] 

sage: Tableau([[1,2],[3],[4]]).restrict(2) 

[[1, 2]] 

sage: SemistandardTableau([[1,1],[2]]).restrict(1) 

[[1, 1]] 

sage: _.category() 

Category of elements of Semistandard tableaux 

""" 

res = [ [y for y in row if y <= n] for row in self ] 

res = [row for row in res if row] 

# attempt to return a tableau of the same type 

try: 

return self.parent()( res ) 

except Exception: 

try: 

return self.parent().Element( res ) 

except Exception: 

return Tableau(res) 

 

def restriction_shape(self, n): 

""" 

Return the shape of the restriction of the semistandard tableau 

``self`` to ``n``. 

 

If `T` is a semistandard tableau and `n` is a nonnegative integer, 

then the restriction of `T` to `n` is defined as the 

(semistandard) tableau obtained by removing all cells filled with 

entries greater than `n` from `T`. 

 

This method computes merely the shape of the restriction. For 

the restriction itself, use :meth:`restrict`. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[2,3],[3,4]]).restriction_shape(3) 

[2, 2, 1] 

sage: StandardTableau([[1,2],[3],[4],[5]]).restriction_shape(2) 

[2] 

sage: Tableau([[1,3,3,5],[2,4,4],[17]]).restriction_shape(0) 

[] 

sage: Tableau([[1,3,3,5],[2,4,4],[17]]).restriction_shape(2) 

[1, 1] 

sage: Tableau([[1,3,3,5],[2,4,4],[17]]).restriction_shape(3) 

[3, 1] 

sage: Tableau([[1,3,3,5],[2,4,4],[17]]).restriction_shape(5) 

[4, 3] 

 

sage: all( T.restriction_shape(i) == T.restrict(i).shape() 

....: for T in StandardTableaux(5) for i in range(1, 5) ) 

True 

""" 

from sage.combinat.partition import Partition 

res = [len([y for y in row if y <= n]) for row in self] 

return Partition(res) 

 

def to_chain(self, max_entry=None): 

""" 

Return the chain of partitions corresponding to the (semi)standard 

tableau ``self``. 

 

The optional keyword parameter ``max_entry`` can be used to 

customize the length of the chain. Specifically, if this parameter 

is set to a nonnegative integer ``n``, then the chain is 

constructed from the positions of the letters `1, 2, \ldots, n` 

in the tableau. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3],[4]]).to_chain() 

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

sage: Tableau([[1,1],[2]]).to_chain() 

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

sage: Tableau([[1,1],[3]]).to_chain() 

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

sage: Tableau([]).to_chain() 

[[]] 

sage: Tableau([[1,1],[2],[3]]).to_chain(max_entry=2) 

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

sage: Tableau([[1,1],[2],[3]]).to_chain(max_entry=3) 

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

sage: Tableau([[1,1],[2],[3]]).to_chain(max_entry=4) 

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

sage: Tableau([[1,1,2],[2,3],[4,5]]).to_chain(max_entry=6) 

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

""" 

if max_entry is None: 

if len(self) == 0: 

max_entry = 0 

else: 

max_entry = max(max(row) for row in self) 

return [self.restriction_shape(k) for k in range(max_entry+1)] 

 

@combinatorial_map(name='to Gelfand-Tsetlin pattern') 

def to_Gelfand_Tsetlin_pattern(self): 

""" 

Return the :class:`Gelfand-Tsetlin pattern <GelfandTsetlinPattern>` 

corresponding to ``self`` when semistandard. 

 

EXAMPLES:: 

 

sage: T = Tableau([[1,2,3],[2,3],[3]]) 

sage: G = T.to_Gelfand_Tsetlin_pattern(); G 

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

sage: G.to_tableau() == T 

True 

sage: T = Tableau([[1,3],[2]]) 

sage: T.to_Gelfand_Tsetlin_pattern() 

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

""" 

from sage.combinat.gelfand_tsetlin_patterns import GelfandTsetlinPatterns 

return GelfandTsetlinPatterns()(self) 

 

def anti_restrict(self, n): 

""" 

Return the skew tableau formed by removing all of the cells from 

``self`` that are filled with a number at most `n`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3],[4,5]]); t 

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

sage: t.anti_restrict(1) 

[[None, 2, 3], [4, 5]] 

sage: t.anti_restrict(2) 

[[None, None, 3], [4, 5]] 

sage: t.anti_restrict(3) 

[[None, None, None], [4, 5]] 

sage: t.anti_restrict(4) 

[[None, None, None], [None, 5]] 

sage: t.anti_restrict(5) 

[[None, None, None], [None, None]] 

""" 

t_new = [[None if g <= n else g for g in row] for row in self] 

from sage.combinat.skew_tableau import SkewTableau 

return SkewTableau(t_new) 

 

def to_list(self): 

""" 

Return ``self`` as a list of lists (not tuples!). 

 

EXAMPLES:: 

 

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

sage: l = t.to_list(); l 

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

sage: l[0][0] = 2 

sage: t 

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

""" 

return [list(row) for row in self] 

 

def bump(self, x): 

""" 

Insert ``x`` into ``self`` using Schensted's row-bumping (or 

row-insertion) algorithm. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[3]]) 

sage: t.bump(1) 

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

sage: t 

[[1, 2], [3]] 

sage: t.bump(2) 

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

sage: t.bump(3) 

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

sage: t 

[[1, 2], [3]] 

sage: t = Tableau([[1,2,2,3],[2,3,5,5],[4,4,6],[5,6]]) 

sage: t.bump(2) 

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

sage: t.bump(1) 

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

""" 

to_insert = x 

new_t = self.to_list() 

for row in new_t: 

i = 0 

#try to insert to_insert into row 

while i < len(row): 

if to_insert < row[i]: 

t = to_insert 

to_insert = row[i] 

row[i] = t 

break 

i += 1 

 

#if we haven't already inserted to_insert 

#append it to the end of row 

if i == len(row): 

row.append(to_insert) 

if isinstance(self, SemistandardTableau): 

return SemistandardTableau(new_t) 

return Tableau(new_t) 

#if we got here, we are at the end of the tableau 

#add to_insert as the last row 

new_t.append([to_insert]) 

if isinstance(self, SemistandardTableau): 

return SemistandardTableau(new_t) 

return Tableau(new_t) 

 

def schensted_insert(self, i, left=False): 

""" 

Insert ``i`` into ``self`` using Schensted's row-bumping (or 

row-insertion) algorithm. 

 

INPUT: 

 

- ``i`` -- a number to insert 

- ``left`` -- (default: ``False``) boolean; if set to 

``True``, the insertion will be done from the left. That 

is, if one thinks of the algorithm as appending a letter 

to the reading word of ``self``, we append the letter to 

the left instead of the right 

 

EXAMPLES:: 

 

sage: t = Tableau([[3,5],[7]]) 

sage: t.schensted_insert(8) 

[[3, 5, 8], [7]] 

sage: t.schensted_insert(8, left=True) 

[[3, 5], [7], [8]] 

""" 

if left: 

return self._left_schensted_insert(i) 

else: 

return self.bump(i) 

 

def _left_schensted_insert(self, letter): 

""" 

EXAMPLES:: 

 

sage: t = Tableau([[3,5],[7]]) 

sage: t._left_schensted_insert(8) 

[[3, 5], [7], [8]] 

sage: t._left_schensted_insert(6) 

[[3, 5], [6, 7]] 

sage: t._left_schensted_insert(2) 

[[2, 3, 5], [7]] 

""" 

h = len(self) 

if h == 0: 

return Tableau([[letter]]) 

h1 = h + 1 

rep = self.to_list() 

rep.reverse() 

 

width = len(rep[h-1]) 

heights = self._heights() + [h1] 

 

for j in range(1, width+2): 

i = heights[j-1] 

while i != h1 and rep[i-1][j-1] >= letter: 

i += 1 

if i == heights[j-1]: #add on top of column j 

if j == 1: 

rep = [[letter]] + rep 

else: 

rep[i-2].append(letter) 

break 

elif i == h1 and j == width: #add on right of line i 

if rep[i-2][j-1] < letter: 

rep[i-2].append(letter) 

else: 

new_letter = rep[i-2][j-1] 

rep[i-2][j-1] = letter 

rep[i-2].append(new_letter) 

break 

else: 

new_letter = rep[i-2][j-1] 

rep[i-2][j-1] = letter 

letter = new_letter 

 

rep.reverse() 

return Tableau(rep) 

 

def insert_word(self, w, left=False): 

""" 

Insert the word ``w`` into the tableau ``self`` letter by letter 

using Schensted insertion. By default, the word ``w`` is being 

processed from left to right, and the insertion used is row 

insertion. If the optional keyword ``left`` is set to ``True``, 

the word ``w`` is being processed from right to left, and column 

insertion is used instead. 

 

EXAMPLES:: 

 

sage: t0 = Tableau([]) 

sage: w = [1,1,2,3,3,3,3] 

sage: t0.insert_word(w) 

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

sage: t0.insert_word(w,left=True) 

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

sage: w.reverse() 

sage: t0.insert_word(w) 

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

sage: t0.insert_word(w,left=True) 

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

sage: t1 = Tableau([[1,3],[2]]) 

sage: t1.insert_word([4,5]) 

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

sage: t1.insert_word([4,5], left=True) 

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

""" 

if left: 

w = [i for i in reversed(w)] 

res = self 

for i in w: 

res = res.schensted_insert(i,left=left) 

return res 

 

def reverse_bump(self, loc): 

r""" 

Reverse row bump the entry of ``self`` at the specified 

location ``loc`` (given as a row index or a 

corner ``(r, c)`` of the tableau). 

 

This is the reverse of Schensted's row-insertion algorithm. 

See Section 1.1, page 8, of Fulton's [Ful1997]_. 

 

INPUT: 

 

- ``loc`` -- Can be either of the following: 

 

- The coordinates ``(r, c)`` of the square to reverse-bump 

(which must be a corner of the tableau); 

- The row index ``r`` of this square. 

 

Note that both ``r`` and ``c`` are `0`-based, i.e., the 

topmost row and the leftmost column are the `0`-th row 

and the `0`-th column. 

 

OUTPUT: 

 

An ordered pair consisting of: 

 

1. The resulting (smaller) tableau; 

2. The entry bumped out at the end of the process. 

 

.. SEEALSO:: 

 

:meth:`bump` 

 

EXAMPLES: 

 

This is the reverse of Schensted's bump:: 

 

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

sage: T.reverse_bump(2) 

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

sage: T == T.reverse_bump(2)[0].bump(2) 

True 

sage: T.reverse_bump((3, 0)) 

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

 

Some errors caused by wrong input:: 

 

sage: T.reverse_bump((3, 1)) 

Traceback (most recent call last): 

... 

ValueError: invalid corner 

sage: T.reverse_bump(4) 

Traceback (most recent call last): 

... 

IndexError: list index out of range 

sage: Tableau([[2, 2, 1], [3, 3]]).reverse_bump(0) 

Traceback (most recent call last): 

... 

ValueError: Reverse bumping is only defined for semistandard tableaux 

 

Some edge cases:: 

 

sage: Tableau([[1]]).reverse_bump(0) 

([], 1) 

sage: Tableau([[1,1]]).reverse_bump(0) 

([[1]], 1) 

sage: Tableau([]).reverse_bump(0) 

Traceback (most recent call last): 

... 

IndexError: list index out of range 

 

.. NOTE:: 

 

Reverse row bumping is only implemented for tableaux with weakly increasing 

and strictly increasing columns (though the tableau does not need to be an 

instance of class :class:`SemistandardTableau`). 

 

""" 

if not (self.is_semistandard()): 

raise ValueError("Reverse bumping is only defined for semistandard tableaux") 

try: 

(r, c) = loc 

if (r, c) not in self.corners(): 

raise ValueError("invalid corner") 

except TypeError: 

r = loc 

c = len(self[r]) - 1 

 

# make a copy of self 

new_t = self.to_list() 

 

# remove the last entry of row r from the tableau 

to_move = new_t[r].pop() 

 

# delete the row if it's now empty 

if not new_t[r]: 

new_t.pop() 

 

from bisect import bisect_left 

 

for row in reversed(new_t[:r]): 

# Decide where to insert: 

# the bisect_left command returns the greatest index such that 

# every entry to its left is strictly less than to_move 

c = bisect_left(row, to_move, lo=c) - 1 

 

# swap it with to_move 

row[c], to_move = to_move, row[c] 

 

if isinstance(self, SemistandardTableau): 

return SemistandardTableau(new_t), to_move 

return Tableau(new_t), to_move 

 

 

def bump_multiply(left, right): 

""" 

Multiply two tableaux using Schensted's bump. 

 

This product makes the set of semistandard tableaux into an 

associative monoid. The empty tableau is the unit in this monoid. 

See pp. 11-12 of [Ful1997]_. 

 

The same product operation is implemented in a different way in 

:meth:`slide_multiply`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,2,3],[2,3,5,5],[4,4,6],[5,6]]) 

sage: t2 = Tableau([[1,2],[3]]) 

sage: t.bump_multiply(t2) 

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

""" 

if not isinstance(right, Tableau): 

raise TypeError("right must be a Tableau") 

 

row = len(right) 

product = Tableau([list(a) for a in left]) # create deep copy of left 

while row > 0: 

row -= 1 

for i in right[row]: 

product = product.bump(i) 

return product 

 

def slide_multiply(left, right): 

""" 

Multiply two tableaux using jeu de taquin. 

 

This product makes the set of semistandard tableaux into an 

associative monoid. The empty tableau is the unit in this monoid. 

 

See pp. 15 of [Ful1997]_. 

 

The same product operation is implemented in a different way in 

:meth:`bump_multiply`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,2,3],[2,3,5,5],[4,4,6],[5,6]]) 

sage: t2 = Tableau([[1,2],[3]]) 

sage: t.slide_multiply(t2) 

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

""" 

st = [] 

if len(left) == 0: 

return right 

else: 

l = len(left[0]) 

 

for row in right: 

st.append((None,)*l + row) 

for row in left: 

st.append(row) 

 

from sage.combinat.skew_tableau import SkewTableau 

return SkewTableau(st).rectify() 

 

def _slide_up(self, c): 

r""" 

Auxiliary method used for promotion, which removes cell `c` from ``self``, 

slides the letters of ``self`` up using jeu de taquin slides, and 

then fills the empty cell at `(0,0)` with the value `0`. 

 

TESTS:: 

 

sage: t = Tableau([[1,1,2],[2,3,5],[4,5]]) 

sage: t._slide_up((2,1)) 

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

 

sage: t._slide_up((1,2)) 

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

 

sage: t = Tableau([[1,1,3],[2,3,5],[4,5]]) 

sage: t._slide_up((1,2)) 

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

""" 

new_st = self.to_list() 

spotl, spotc = c 

while [spotl, spotc] != [0,0]: 

#once moving box is in first column, just move letters up 

#(French notation!) 

if spotc == 0: 

new_st[spotl][spotc] = new_st[spotl-1][spotc] 

spotl -= 1 

continue 

#once moving box is in first row, just move letters up 

elif spotl == 0: 

new_st[spotl][spotc] = new_st[spotl][spotc-1] 

spotc -= 1 

continue 

else: 

#If we get to this stage, we need to compare 

below = new_st[spotl-1][spotc] 

left = new_st[spotl][spotc-1] 

if below >= left: 

#Swap with the cell below 

new_st[spotl][spotc] = new_st[spotl-1][spotc] 

spotl -= 1 

continue 

else: 

#Swap with the cell to the left 

new_st[spotl][spotc] = new_st[spotl][spotc-1] 

spotc -= 1 

continue 

#set box in position (0,0) to 0 

new_st[0][0] = 0 

return Tableau(new_st) 

 

def _slide_down(self, c, n): 

r""" 

Auxiliary method used for promotion, which removes cell `c` from ``self``, 

slides the letters of ``self`` down using jeu de taquin slides, and 

then fills the empty cell with the value `n + 2`. 

 

When the entries of ``self`` are positive integers, and cell `c` is 

filled with `1`, then the position of `c` is irrelevant. 

 

TESTS:: 

 

sage: t = Tableau([[1,1,2],[2,3,5],[4,5]]) 

sage: t._slide_down((0, 0), 8) 

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

 

sage: t._slide_down((0, 1), 8) 

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

 

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

sage: t._slide_down((0, 1), 9) 

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

""" 

new_st = self.to_list() 

#new_st is a deep copy of self, so as not to mess around with self. 

new_st_shape = [len(x) for x in self] 

spotl, spotc = c 

#spotl and spotc are the coordinates of the wandering hole. 

#All comments and variable names below refer to French notation. 

while True: 

#"right_neighbor" and "upper_neighbor" refer to neighbors of the 

#hole. 

go_right = None 

if len(new_st_shape) > spotl + 1 and new_st_shape[spotl + 1] >= spotc + 1: 

upper_neighbor = new_st[spotl + 1][spotc] 

go_right = False 

if new_st_shape[spotl] != spotc + 1: 

right_neighbor = new_st[spotl][spotc + 1] 

if go_right is None or upper_neighbor > right_neighbor: 

go_right = True 

if go_right is True: 

new_st[spotl][spotc] = right_neighbor 

spotc += 1 

elif go_right is False: 

new_st[spotl][spotc] = upper_neighbor 

spotl += 1 

else: 

break 

new_st[spotl][spotc] = n + 2 

return Tableau(new_st) 

 

def promotion_inverse(self, n): 

""" 

Return the image of ``self`` under the inverse promotion operator. 

 

.. WARNING:: 

 

You might know this operator as the promotion operator 

(without "inverse") -- literature does not agree on the 

name. 

 

The inverse promotion operator, applied to a tableau `t`, does the 

following: 

 

Iterate over all letters `1` in the tableau `t`, from right to left. 

For each of these letters, do the following: 

 

- Remove the letter from `t`, thus leaving a hole where it used to be. 

 

- Apply jeu de taquin to move this hole northeast (in French notation) 

until it reaches the outer boundary of `t`. 

 

- Fill `n+2` into the hole once jeu de taquin has completed. 

 

Once this all is done, subtract `1` from each letter in the tableau. 

This is not always well-defined. Restricted to the class of 

semistandard tableaux whose entries are all `\leq n + 1`, this is the 

usual inverse promotion operator defined on this class. 

 

When ``self`` is a standard tableau of size ``n + 1``, this definition of 

inverse promotion is the map called "promotion" in [Sg2011]_ (p. 23) and 

in [Stan2009]_, and is the inverse of the map called "promotion" in 

[Hai1992]_ (p. 90). 

 

.. WARNING:: 

 

To my (Darij's) knowledge, the fact that the above "inverse 

promotion operator" really is the inverse of the promotion 

operator :meth:`promotion` for semistandard tableaux has never 

been proven in literature. Corrections are welcome. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[3,3]]) 

sage: t.promotion_inverse(2) 

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

 

sage: t = Tableau([[1,2],[2,3]]) 

sage: t.promotion_inverse(2) 

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

 

sage: t = Tableau([[1,2,5],[3,3,6],[4,7]]) 

sage: t.promotion_inverse(8) 

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

 

sage: t = Tableau([]) 

sage: t.promotion_inverse(2) 

[] 

 

TESTS: 

 

We check the equivalence of two definitions of inverse promotion 

on semistandard tableaux:: 

 

sage: ST = SemistandardTableaux(shape=[4,2,1], max_entry=7) 

sage: def bk_promotion_inverse7(st): 

....: st2 = st 

....: for i in range(1, 7): 

....: st2 = st2.bender_knuth_involution(i, check=False) 

....: return st2 

sage: all( bk_promotion_inverse7(st) == st.promotion_inverse(6) for st in ST ) # long time 

True 

sage: ST = SemistandardTableaux(shape=[2,2,2], max_entry=7) 

sage: all( bk_promotion_inverse7(st) == st.promotion_inverse(6) for st in ST ) # long time 

True 

 

A test for :trac:`13203`:: 

 

sage: T = Tableau([[1]]) 

sage: type(T.promotion_inverse(2)[0][0]) 

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

""" 

if self.is_rectangular(): 

n = Integer(n) 

if self.size() == 0: 

return self 

s = self.shape()[0] 

l = self.weight()[0] 

word = [i-1 for row in reversed(self) for i in row if i>1] 

t = Tableau([]) 

t = t.insert_word(word) 

t = t.to_list() 

if l < s: 

for i in range(l): 

t[len(t)-1].append(n+1) 

else: 

t.append([n+1 for i in range(s)]) 

return Tableau(t) 

# Now, the non-rectangular case. 

p = self 

for c in reversed(self.cells_containing(1)): 

p = p._slide_down(c, n) 

return Tableau([[i-1 for i in row] for row in p]) 

 

def promotion(self, n): 

r""" 

Return the image of ``self`` under the promotion operator. 

 

.. WARNING:: 

 

You might know this operator as the inverse promotion 

operator -- literature does not agree on the name. You 

might also be looking for the Lapointe-Lascoux-Morse 

promotion operator (:meth:`promotion_operator`). 

 

The promotion operator, applied to a tableau `t`, does the following: 

 

Iterate over all letters `n+1` in the tableau `t`, from left to right. 

For each of these letters, do the following: 

 

- Remove the letter from `t`, thus leaving a hole where it used to be. 

 

- Apply jeu de taquin to move this hole southwest (in French notation) 

until it reaches the inner boundary of `t`. 

 

- Fill `0` into the hole once jeu de taquin has completed. 

 

Once this all is done, add `1` to each letter in the tableau. 

This is not always well-defined. Restricted to the class of 

semistandard tableaux whose entries are all `\leq n + 1`, this is the 

usual promotion operator defined on this class. 

 

When ``self`` is a standard tableau of size ``n + 1``, this definition of 

promotion is precisely the one given in [Hai1992]_ (p. 90). It is the 

inverse of the maps called "promotion" in [Sg2011]_ (p. 23) and in [Stan2009]_. 

 

.. WARNING:: 

 

To my (Darij's) knowledge, the fact that the above promotion 

operator really is the inverse of the "inverse promotion 

operator" :meth:`promotion_inverse` for semistandard tableaux 

has never been proven in literature. Corrections are welcome. 

 

REFERENCES: 

 

.. [Hai1992] Mark D. Haiman, 

*Dual equivalence with applications, including a conjecture of Proctor*, 

Discrete Mathematics 99 (1992), 79-113, 

http://www.sciencedirect.com/science/article/pii/0012365X9290368P 

 

.. [Sg2011] Bruce E. Sagan, 

*The cyclic sieving phenomenon: a survey*, 

:arXiv:`1008.0790v3` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[3,3]]) 

sage: t.promotion(2) 

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

 

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

sage: t.promotion(3) 

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

 

sage: t = Tableau([[1,2],[2]]) 

sage: t.promotion(3) 

[[2, 3], [3]] 

 

sage: t = Tableau([[1,1,3],[2,2]]) 

sage: t.promotion(2) 

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

 

sage: t = Tableau([[1,1,3],[2,3]]) 

sage: t.promotion(2) 

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

 

sage: t = Tableau([]) 

sage: t.promotion(2) 

[] 

 

TESTS: 

 

We check the equivalence of two definitions of promotion on 

semistandard tableaux:: 

 

sage: ST = SemistandardTableaux(shape=[3,2,2,1], max_entry=6) 

sage: def bk_promotion6(st): 

....: st2 = st 

....: for i in range(5, 0, -1): 

....: st2 = st2.bender_knuth_involution(i, check=False) 

....: return st2 

sage: all( bk_promotion6(st) == st.promotion(5) for st in ST ) # long time 

True 

sage: ST = SemistandardTableaux(shape=[4,4], max_entry=6) 

sage: all( bk_promotion6(st) == st.promotion(5) for st in ST ) # long time 

True 

 

We also check :meth:`promotion_inverse()` is the inverse 

of :meth:`promotion()`:: 

 

sage: ST = SemistandardTableaux(shape=[3,2,1], max_entry=7) 

sage: all( st.promotion(6).promotion_inverse(6) == st for st in ST ) # long time 

True 

""" 

if self.is_rectangular(): 

t = self.rotate_180() 

t = [tuple(n+2-i for i in row) for row in t] 

t = Tableau(t).promotion_inverse(n) 

t = [tuple(n+2-i for i in row) for row in t] 

return Tableau(t).rotate_180() 

p = self 

for c in self.cells_containing(n+1): 

p = p._slide_up(c) 

return Tableau([[i+1 for i in row] for row in p]) 

 

def row_stabilizer(self): 

""" 

Return the PermutationGroup corresponding to the row stabilizer of 

``self``. 

 

This assumes that every integer from `1` to the size of ``self`` 

appears exactly once in ``self``. 

 

EXAMPLES:: 

 

sage: rs = Tableau([[1,2,3],[4,5]]).row_stabilizer() 

sage: rs.order() == factorial(3)*factorial(2) 

True 

sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs 

True 

sage: PermutationGroupElement([(1,4)]) in rs 

False 

sage: rs = Tableau([[1, 2],[3]]).row_stabilizer() 

sage: PermutationGroupElement([(1,2),(3,)]) in rs 

True 

sage: rs.one().domain() 

[1, 2, 3] 

sage: rs = Tableau([[1],[2],[3]]).row_stabilizer() 

sage: rs.order() 

1 

sage: rs = Tableau([[2,4,5],[1,3]]).row_stabilizer() 

sage: rs.order() 

12 

sage: rs = Tableau([]).row_stabilizer() 

sage: rs.order() 

1 

""" 

# Ensure that the permutations involve all elements of the 

# tableau, by including the identity permutation on the set [1..k]. 

k = self.size() 

gens = [list(range(1, k + 1))] 

for row in self: 

for j in range(len(row) - 1): 

gens.append( (row[j], row[j + 1]) ) 

return PermutationGroup( gens ) 

 

def column_stabilizer(self): 

""" 

Return the PermutationGroup corresponding to the column stabilizer 

of ``self``. 

 

This assumes that every integer from `1` to the size of ``self`` 

appears exactly once in ``self``. 

 

EXAMPLES:: 

 

sage: cs = Tableau([[1,2,3],[4,5]]).column_stabilizer() 

sage: cs.order() == factorial(2)*factorial(2) 

True 

sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs 

False 

sage: PermutationGroupElement([(1,4)]) in cs 

True 

""" 

return self.conjugate().row_stabilizer() 

 

def height(self): 

""" 

Return the height of ``self``. 

 

EXAMPLES:: 

 

sage: Tableau([[1,2,3],[4,5]]).height() 

2 

sage: Tableau([[1,2,3]]).height() 

1 

sage: Tableau([]).height() 

0 

""" 

return len(self) 

 

def _heights(self): 

""" 

EXAMPLES:: 

 

sage: Tableau([[1,2,3,4],[5,6],[7],[8]])._heights() 

[1, 3, 4, 4] 

sage: Tableau([])._heights() 

[] 

sage: Tableau([[1]])._heights() 

[1] 

sage: Tableau([[1,2]])._heights() 

[1, 1] 

sage: Tableau([[1,2],[3],[4]])._heights() 

[1, 3] 

""" 

cor = self.corners() 

ncor = len(cor) 

if ncor == 0: 

return [] 

k = len(self) 

cor = [ [k-i,j+1] for i,j in reversed(cor)] 

 

heights = [1]*(cor[0][1]) 

for i in range(1, ncor): 

heights += [ cor[i][0] ]*(cor[i][1]-cor[i-1][1]) 

 

return heights 

 

def last_letter_lequal(self, tab2): 

""" 

Return ``True`` if ``self`` is less than or equal to ``tab2`` in the last 

letter ordering. 

 

EXAMPLES:: 

 

sage: st = StandardTableaux([3,2]) 

sage: f = lambda b: 1 if b else 0 

sage: matrix( [ [ f(t1.last_letter_lequal(t2)) for t2 in st] for t1 in st] ) 

[1 1 1 1 1] 

[0 1 1 1 1] 

[0 0 1 1 1] 

[0 0 0 1 1] 

[0 0 0 0 1] 

""" 

n = self.size() 

if not isinstance(tab2, Tableau): 

try: 

tab2 = Tableau(tab2) 

except Exception: 

raise TypeError("tab2 must be a standard tableau") 

 

if tab2.size() != n: 

raise ValueError("tab2 must be the same size as self") 

 

if self == tab2: 

return True 

 

for j in range(n, 1, -1): 

self_j_pos = None 

for i in range(len(self)): 

if j in self[i]: 

self_j_pos = i 

break 

 

tab2_j_pos = None 

for i in range(len(tab2)): 

if j in tab2[i]: 

tab2_j_pos = i 

break 

 

if self_j_pos < tab2_j_pos: 

return True 

if tab2_j_pos < self_j_pos: 

return False 

 

def charge(self): 

r""" 

Return the charge of the reading word of ``self``. See 

:meth:`~sage.combinat.words.finite_word.FiniteWord_class.charge` for more information. 

 

EXAMPLES:: 

 

sage: Tableau([[1,1],[2,2],[3]]).charge() 

0 

sage: Tableau([[1,1,3],[2,2]]).charge() 

1 

sage: Tableau([[1,1,2],[2],[3]]).charge() 

1 

sage: Tableau([[1,1,2],[2,3]]).charge() 

2 

sage: Tableau([[1,1,2,3],[2]]).charge() 

2 

sage: Tableau([[1,1,2,2],[3]]).charge() 

3 

sage: Tableau([[1,1,2,2,3]]).charge() 

4 

""" 

return self.to_word().charge() 

 

def cocharge(self): 

r""" 

Return the cocharge of the reading word of ``self``. See 

:meth:`~sage.combinat.words.finite_word.FiniteWord_class.cocharge` for more information. 

 

EXAMPLES:: 

 

sage: Tableau([[1,1],[2,2],[3]]).cocharge() 

4 

sage: Tableau([[1,1,3],[2,2]]).cocharge() 

3 

sage: Tableau([[1,1,2],[2],[3]]).cocharge() 

3 

sage: Tableau([[1,1,2],[2,3]]).cocharge() 

2 

sage: Tableau([[1,1,2,3],[2]]).cocharge() 

2 

sage: Tableau([[1,1,2,2],[3]]).cocharge() 

1 

sage: Tableau([[1,1,2,2,3]]).cocharge() 

0 

""" 

return self.to_word().cocharge() 

 

 

def add_entry(self, cell, m): 

""" 

Return the result of setting the entry in cell ``cell`` equal 

to ``m`` in the tableau ``self``. 

 

This tableau has larger size than ``self`` if ``cell`` does not 

belong to the shape of ``self``; otherwise, the tableau has the 

same shape as ``self`` and has the appropriate entry replaced. 

 

INPUT: 

 

- ``cell`` -- a pair of nonnegative integers 

 

OUTPUT: 

 

The tableau ``self`` with the entry in cell ``cell`` set to ``m``. This 

entry overwrites an existing entry if ``cell`` already belongs to 

``self``, or is added to the tableau if ``cell`` is a cocorner of the 

shape ``self``. (Either way, the input is not modified.) 

 

.. NOTE:: 

 

Both coordinates of ``cell`` are interpreted as starting at `0`. 

So, ``cell == (0, 0)`` corresponds to the northwesternmost cell. 

 

EXAMPLES:: 

 

sage: s = StandardTableau([[1,2,5],[3,4]]); s.pp() 

1 2 5 

3 4 

sage: t = s.add_entry( (1,2), 6); t.pp() 

1 2 5 

3 4 6 

sage: t.category() 

Category of elements of Standard tableaux 

sage: s.add_entry( (2,0), 6).pp() 

1 2 5 

3 4 

6 

sage: u = s.add_entry( (1,2), 3); u.pp() 

1 2 5 

3 4 3 

sage: u.category() 

Category of elements of Tableaux 

sage: s.add_entry( (2,2),3) 

Traceback (most recent call last): 

... 

IndexError: (2, 2) is not an addable cell of the tableau 

 

""" 

tab = self.to_list() 

(r, c) = cell 

try: 

tab[r][c] = m # will work if we are replacing an entry 

except IndexError: 

# Only add a new row if (r,c) is an addable cell (previous code 

# added m to the end of row r independently of the value of c) 

if r >= len(tab): 

if r == len(tab) and c == 0: 

tab.append([m]) 

else: 

raise IndexError('%s is not an addable cell of the tableau' % ((r,c),)) 

else: 

tab_r = tab[r] 

if c == len(tab_r): 

tab_r.append(m) 

else: 

raise IndexError('%s is not an addable cell of the tableau' % ((r,c),)) 

 

# attempt to return a tableau of the same type as self 

if tab in self.parent(): 

return self.parent()(tab) 

else: 

try: 

return self.parent().Element(tab) 

except Exception: 

return Tableau(tab) 

 

 

############## 

# catabolism # 

############## 

 

def catabolism(self): 

""" 

Remove the top row of ``self`` and insert it back in using 

column Schensted insertion (starting with the largest letter). 

 

EXAMPLES:: 

 

sage: Tableau([]).catabolism() 

[] 

sage: Tableau([[1,2,3,4,5]]).catabolism() 

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

sage: Tableau([[1,1,3,3],[2,3],[3]]).catabolism() 

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

sage: Tableau([[1, 1, 2, 3, 3, 3], [3]]).catabolism() 

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

""" 

h = self.height() 

if h == 0: 

return self 

else: 

#Remove the top row and insert it back in 

return Tableau(self[1:]).insert_word(self[0],left=True) 

 

def catabolism_sequence(self): 

""" 

Perform :meth:`catabolism` on ``self`` until it returns a 

tableau consisting of a single row. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2,3,4,5,6,8],[7,9]]) 

sage: t.catabolism_sequence() 

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

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

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

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

sage: Tableau([]).catabolism_sequence() 

[[]] 

""" 

h = self.height() 

res = [self] 

newterm = self 

while h > 1: 

newterm = newterm.catabolism() 

res.append(newterm) 

h = newterm.height() 

return res 

 

def lambda_catabolism(self, part): 

r""" 

Return the ``part``-catabolism of ``self``, where ``part`` is a 

partition (which can be just given as an array). 

 

For a partition `\lambda` and a tableau `T`, the 

`\lambda`-catabolism of `T` is defined by performing the following 

steps. 

 

1. Truncate the parts of `\lambda` so that `\lambda` is contained 

in the shape of `T`. Let `m` be the length of this partition. 

 

2. Let `T_a` be the first `m` rows of `T`, and `T_b` be the 

remaining rows. 

 

3. Let `S_a` be the skew tableau `T_a / \lambda`. 

 

4. Concatenate the reading words of `S_a` and `T_b`, and insert 

into a tableau. 

 

EXAMPLES:: 

 

sage: Tableau([[1,1,3],[2,4,5]]).lambda_catabolism([2,1]) 

[[3, 5], [4]] 

sage: t = Tableau([[1,1,3,3],[2,3],[3]]) 

sage: t.lambda_catabolism([]) 

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

sage: t.lambda_catabolism([1]) 

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

sage: t.lambda_catabolism([1,1]) 

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

sage: t.lambda_catabolism([2,1]) 

[[3, 3, 3, 3]] 

sage: t.lambda_catabolism([4,2,1]) 

[] 

sage: t.lambda_catabolism([5,1]) 

[[3, 3]] 

sage: t.lambda_catabolism([4,1]) 

[[3, 3]] 

""" 

#Reduce the partition if it is too big for the tableau 

part = [ min(part[i],len(self[i])) for i in range(min(len(self), len(part))) ] 

if self.shape() == part: 

return Tableau([]) 

 

m = len(part) 

 

w1 = list(sum((row for row in reversed(self[m:])), ())) 

 

w2 = [] 

for i,row in enumerate(reversed(self[:m])): 

w2 += row[ part[-1-i] : ] 

 

return Tableau([]).insert_word(w2+w1) 

 

 

def reduced_lambda_catabolism(self, part): 

""" 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,3,3],[2,3],[3]]) 

sage: t.reduced_lambda_catabolism([]) 

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

sage: t.reduced_lambda_catabolism([1]) 

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

sage: t.reduced_lambda_catabolism([1,1]) 

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

sage: t.reduced_lambda_catabolism([2,1]) 

[[3, 3, 3, 3]] 

sage: t.reduced_lambda_catabolism([4,2,1]) 

[] 

sage: t.reduced_lambda_catabolism([5,1]) 

0 

sage: t.reduced_lambda_catabolism([4,1]) 

0 

""" 

part1 = part 

 

if self == []: 

return self 

 

res = self.lambda_catabolism(part) 

 

if res == []: 

return res 

 

if res == 0: 

return 0 

 

a = self[0][0] 

 

part = [ min(part1[i], len(self[i])) for i in range(min(len(part1),len(self)))] 

tt_part = Tableau([ [a+i]*part[i] for i in range(len(part)) ]) 

t_part = Tableau([[self[i][j] for j in range(part[i])] for i in range(len(part))]) 

 

if t_part == tt_part: 

return res 

else: 

return 0 

 

def catabolism_projector(self, parts): 

""" 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,3,3],[2,3],[3]]) 

sage: t.catabolism_projector([[4,2,1]]) 

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

sage: t.catabolism_projector([[1]]) 

[] 

sage: t.catabolism_projector([[2,1],[1]]) 

[] 

sage: t.catabolism_projector([[1,1],[4,1]]) 

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

""" 

res = self 

for p in parts: 

res = res.reduced_lambda_catabolism(p) 

if res == 0: 

return 0 

 

if res == []: 

return self 

else: 

return Tableau([]) 

 

def promotion_operator(self, i): 

""" 

Return a list of semistandard tableaux obtained by the `i`-th 

Lapointe-Lascoux-Morse promotion operator from the 

semistandard tableau ``self``. 

 

.. WARNING:: 

 

This is not Schuetzenberger's jeu-de-taquin promotion! 

For the latter, see :meth:`promotion` and 

:meth:`promotion_inverse`. 

 

This operator is defined by taking the maximum entry `m` of 

`T`, then adding a horizontal `i`-strip to `T` in all possible 

ways, each time filling this strip with `m+1`'s, and finally 

letting the permutation 

`\sigma_1 \sigma_2 \cdots \sigma_m = (2, 3, \ldots, m+1, 1)` 

act on each of the resulting tableaux via the 

Lascoux-Schuetzenberger action 

(:meth:`symmetric_group_action_on_values`). This method 

returns the list of all resulting tableaux. See [LLM01]_ for 

the purpose of this operator. 

 

REFERENCES: 

 

.. [LLM01] \L. Lapointe, A. Lascoux, J. Morse. 

*Tableau atoms and a new Macdonald positivity conjecture*. 

:arxiv:`math/0008073v2`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[3]]) 

sage: t.promotion_operator(1) 

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

sage: t.promotion_operator(2) 

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

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

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

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

sage: Tableau([[1]]).promotion_operator(2) 

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

sage: Tableau([[1,1],[2]]).promotion_operator(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]]] 

 

The example from [LLM01]_ p. 12:: 

 

sage: Tableau([[1,1],[2,2]]).promotion_operator(3) 

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

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

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

 

TESTS:: 

 

sage: Tableau([]).promotion_operator(2) 

[[[1, 1]]] 

sage: Tableau([]).promotion_operator(1) 

[[[1]]] 

""" 

chain = self.to_chain() 

part = self.shape() 

weight = self.weight() 

perm = permutation.from_reduced_word(range(1, len(weight)+1)) 

l = part.add_horizontal_border_strip(i) 

ltab = [ from_chain( chain + [next] ) for next in l ] 

return [ x.symmetric_group_action_on_values(perm) for x in ltab ] 

 

 

################################## 

# actions on tableaux from words # 

################################## 

def raise_action_from_words(self, f, *args): 

""" 

EXAMPLES:: 

 

sage: from sage.combinat.tableau import symmetric_group_action_on_values 

sage: import functools 

sage: t = Tableau([[1,1,3,3],[2,3],[3]]) 

sage: f = functools.partial(t.raise_action_from_words, symmetric_group_action_on_values) 

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

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

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

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

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

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

""" 

w = self.to_word() 

w = f(w, *args) 

return from_shape_and_word(self.shape(), w) 

 

def symmetric_group_action_on_values(self, perm): 

r""" 

Return the image of the semistandard tableau ``self`` under the 

action of the permutation ``perm`` using the 

Lascoux-Schuetzenberger action of the symmetric group `S_n` on 

the semistandard tableaux with ceiling `n`. 

 

If `n` is a nonnegative integer, then the 

Lascoux-Schuetzenberger action is a group action of the 

symmetric group `S_n` on the set of semistandard Young tableaux 

with ceiling `n` (that is, with entries taken from the set 

`\{1, 2, \ldots, n\}`). It is defined as follows: 

 

Let `i \in \{1, 2, \ldots, n-1\}`, and let `T` be a 

semistandard tableau with ceiling `n`. Let `w` be the reading 

word (:meth:`to_word`) of `T`. Replace all letters `i` in `w` 

by closing parentheses, and all letters `i+1` in `w` by 

opening parentheses. Whenever an opening parenthesis stands 

left of a closing parenthesis without there being any 

parentheses in between (it is allowed to have letters 

in-between as long as they are not parentheses), consider these 

two parentheses as matched with each other, and replace them 

back by the letters `i+1` and `i`. Repeat this procedure until 

there are no more opening parentheses standing left of closing 

parentheses. Then, let `a` be the number of opening 

parentheses in the word, and `b` the number of closing 

parentheses (notice that all opening parentheses are left of 

all closing parentheses). Replace the first `a` parentheses 

by the letters `i`, and replace the remaining `b` parentheses 

by the letters `i+1`. Let `w'` be the resulting word. Let 

`T'` be the tableau with the same shape as `T` but with reading 

word `w'`. This tableau `T'` can be shown to be semistandard. 

We define the image of `T` under the action of the simple 

transposition `s_i = (i, i+1) \in S_n` to be this tableau `T'`. 

It can be shown that these actions `s_1, s_2, \ldots, s_{n-1}` 

satisfy the Moore-Coxeter relations of `S_n`, and thus this 

extends to a unique action of the symmetric group `S_n` on 

the set of semistandard tableaux with ceiling `n`. This is the 

Lascoux-Schuetzenberger action. 

 

This action of the symmetric group `S_n` on the set of all 

semistandard tableaux of given shape `\lambda` with entries 

in `\{ 1, 2, \ldots, n \}` is the one defined in 

[Loth02]_ Theorem 5.6.3. In particular, the action of `s_i` 

is denoted by `\sigma_i` in said source. (Beware of the typo 

in the definition of `\sigma_i`: it should say 

`\sigma_i ( a_i^r a_{i+1}^s ) = a_i^s a_{i+1}^r`, not 

`\sigma_i ( a_i^r a_{i+1}^s ) = a_i^s a_{i+1}^s`.) 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,3,3],[2,3],[3]]) 

sage: t.symmetric_group_action_on_values([1,2,3]) 

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

sage: t.symmetric_group_action_on_values([2,1,3]) 

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

sage: t.symmetric_group_action_on_values([3,1,2]) 

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

sage: t.symmetric_group_action_on_values([2,3,1]) 

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

sage: t.symmetric_group_action_on_values([3,2,1]) 

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

sage: t.symmetric_group_action_on_values([1,3,2]) 

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

 

TESTS:: 

 

sage: t = Tableau([]) 

sage: t.symmetric_group_action_on_values([]) 

[] 

""" 

return self.raise_action_from_words(symmetric_group_action_on_values, perm) 

 

######### 

# atoms # 

######### 

def socle(self): 

""" 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).socle() 

2 

sage: Tableau([[1,2,3,4]]).socle() 

4 

""" 

h = self.height() 

if h == 0: 

return 0 

w1row = self[0] 

i = 0 

while i < len(w1row)-1: 

if w1row[i+1] != w1row[i] + 1: 

break 

i += 1 

return i+1 

 

def atom(self): 

""" 

EXAMPLES:: 

 

sage: Tableau([[1,2],[3,4]]).atom() 

[2, 2] 

sage: Tableau([[1,2,3],[4,5],[6]]).atom() 

[3, 2, 1] 

""" 

ll = [ t.socle() for t in self.catabolism_sequence() ] 

lres = ll[:] 

for i in range(1,len(ll)): 

lres[i] = ll[i] - ll[i-1] 

return lres 

 

 

def symmetric_group_action_on_entries(self, w): 

r""" 

Return the tableau obtained form this tableau by acting by the 

permutation ``w``. 

 

Let `T` be a standard tableau of size `n`, then the action of 

`w \in S_n` is defined by permuting the entries of `T` (recall they 

are `1, 2, \ldots, n`). In particular, suppose the entry at cell 

`(i, j)` is `a`, then the entry becomes `w(a)`. In general, the 

resulting tableau `wT` may *not* be standard. 

 

.. NOTE:: 

 

This is different than :meth:`symmetric_group_action_on_values` 

which is defined on semistandard tableaux and is guaranteed to 

return a semistandard tableau. 

 

INPUT: 

 

- ``w`` -- a permutation 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2,4],[3,5]]).symmetric_group_action_on_entries( Permutation(((4,5))) ) 

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

sage: _.category() 

Category of elements of Standard tableaux 

sage: StandardTableau([[1,2,4],[3,5]]).symmetric_group_action_on_entries( Permutation(((1,2))) ) 

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

sage: _.category() 

Category of elements of Tableaux 

""" 

w = w + [i+1 for i in range(len(w), self.size())] #need to ensure that it belongs to Sym_size 

try: 

return self.parent()([[w[entry-1] for entry in row] for row in self]) 

except Exception: 

return Tableau([[w[entry-1] for entry in row] for row in self]) 

 

def is_key_tableau(self): 

""" 

Return ``True`` if ``self`` is a key tableau or ``False`` otherwise. 

 

A tableau is a *key tableau* if the set of entries in the `j`-th 

column is a subset of the set of entries in the `(j-1)`-st column. 

 

REFERENCES: 

 

.. [LS90] \A. Lascoux, M.-P. Schutzenberger. 

Keys and standard bases, invariant theory and tableaux. 

IMA Volumes in Math and its Applications (D. Stanton, ED.). 

Southend on Sea, UK, 19 (1990). 125-144. 

 

.. [Willis10] \M. Willis. A direct way to find the right key of 

a semistandard Young tableau. :arxiv:`1110.6184v1`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,1],[2,3],[3]]) 

sage: t.is_key_tableau() 

True 

 

sage: t = Tableau([[1,1,2],[2,3],[3]]) 

sage: t.is_key_tableau() 

False 

""" 

T_conj = self.conjugate() 

return all(x in T_conj[i-1] for i in range(1, len(T_conj)) for x in T_conj[i]) 

 

def right_key_tableau(self): 

""" 

Return the right key tableau of ``self``. 

 

The right key tableau of a tableau `T` is a key tableau whose entries 

are weakly greater than the corresponding entries in `T`, and whose column 

reading word is subject to certain conditions. See [LS90]_ for the full definition. 

 

ALGORITHM: 

 

The following algorithm follows [Willis10]_. Note that if `T` is a key tableau 

then the output of the algorithm is `T`. 

 

To compute the right key tableau `R` of a tableau `T` we iterate over the columns 

of `T`. Let `T_j` be the `j`-th column of `T` and iterate over the entries 

in `T_j` from bottom to top. Initialize the corresponding entry `k` in `R` to be 

the largest entry in `T_j`. Scan the bottom of each column of `T` to the right of 

`T_j`, updating `k` to be the scanned entry whenever the scanned entry is weakly 

greater than `k`. Update `T_j` and all columns to the right by removing all 

scanned entries. 

 

.. SEEALSO:: 

 

- :meth:`is_key_tableau()` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[2,3]]) 

sage: t.right_key_tableau() 

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

sage: t = Tableau([[1,1,2,4],[2,3,3],[4],[5]]) 

sage: t.right_key_tableau() 

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

 

TESTS: 

 

We check that if we have a key tableau, we return the same tableau:: 

 

sage: t = Tableau([[1,1,1,2], [2,2,2], [4], [5]]) 

sage: t.is_key_tableau() 

True 

sage: t.right_key_tableau() == t 

True 

""" 

cols_list = self.conjugate() 

key = [[] for row in cols_list] 

 

for i, col_a in enumerate(cols_list): 

right_cols = cols_list[i+1:] 

for elem in reversed(col_a): 

key_val = elem 

update = [] 

for col_b in right_cols: 

if col_b and key_val <= col_b[-1]: 

key_val = col_b[-1] 

update.append(col_b[:-1]) 

else: 

update.append(col_b) 

key[i].insert(0,key_val) 

right_cols = update 

return Tableau(key).conjugate() 

 

def left_key_tableau(self): 

""" 

Return the left key tableau of ``self``. 

 

The left key tableau of a tableau `T` is the key tableau whose entries 

are weakly lesser than the corresponding entries in `T`, and whose column 

reading word is subject to certain conditions. See [LS90]_ for the full definition. 

 

ALGORITHM: 

 

The following algorithm follows [Willis10]_. Note that if `T` is a key tableau 

then the output of the algorithm is `T`. 

 

To compute the left key tableau `L` of a tableau `T` we iterate over the columns 

of `T`. Let `T_j` be the `j`-th column of `T` and iterate over the entries 

in `T_j` from bottom to top. Initialize the corresponding entry `k` in `L` as the 

largest entry in `T_j`. Scan the columns to the left of `T_j` and with each column 

update `k` to be the lowest entry in that column which is weakly less than `k`. 

Update `T_j` and all columns to the left by removing all scanned entries. 

 

.. SEEALSO:: 

 

- :meth:`is_key_tableau()` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,2],[2,3]]) 

sage: t.left_key_tableau() 

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

sage: t = Tableau([[1,1,2,4],[2,3,3],[4],[5]]) 

sage: t.left_key_tableau() 

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

 

TESTS: 

 

We check that if we have a key tableau, we return the same tableau:: 

 

sage: t = Tableau([[1,1,1,2], [2,2,2], [4], [5]]) 

sage: t.is_key_tableau() 

True 

sage: t.left_key_tableau() == t 

True 

""" 

cols_list = self.conjugate() 

key = [[] for row in cols_list] 

key[0] = list(cols_list[0]) 

 

from bisect import bisect_right 

for i, col_a in enumerate(cols_list[1:],1): 

left_cols = cols_list[:i] 

for elem in reversed(col_a): 

key_val = elem 

update = [] 

for col_b in reversed(left_cols): 

j = bisect_right(col_b, key_val) - 1 

key_val = col_b[j] 

update.insert(0, col_b[:j]) 

left_cols = update 

key[i].insert(0,key_val) 

return Tableau(key).conjugate() 

 

################# 

# seg and flush # 

################# 

def _segments(self): 

r""" 

Internal function returning the set of segments of a tableau as 

a dictionary. 

 

OUTPUT: 

 

- A dictionary with items of the form ``{(r,k):c}``, where ``r`` is the 

row the ``k``-segment appears and ``c`` is the column the left-most 

box of the ``k``-segment appears. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,2,3,5],[2,3,5,5],[3,4]]) 

sage: sorted(t._segments().items()) 

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

 

sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) 

sage: t = B[31].to_tableau() 

sage: sorted(t._segments().items()) 

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

""" 

segments = {} 

for r, row in enumerate(self): 

for c in range(len(row)): 

for j in range(c + 1): 

if row[j] != r + 1 and (r, row[j]) not in segments: 

segments[(r, row[j])] = j 

return segments 

 

def seg(self): 

r""" 

Return the total number of segments in ``self``, as in [S14]_. 

 

Let `T` be a tableaux. We define a `k`-*segment* of `T` (in the `i`-th 

row) to be a maximal consecutive sequence of `k`-boxes in the `i`-th 

row for any `i+1 \le k \le r+1`. Denote the total number of 

`k`-segments in `T` by `\mathrm{seg}(T)`. 

 

REFERENCES: 

 

.. [S14] \B. Salisbury. 

The flush statistic on semistandard Young tableaux. 

:arXiv:`1401.1185` 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,2,3,5],[2,3,5,5],[3,4]]) 

sage: t.seg() 

6 

 

sage: B = crystals.Tableaux("A4",shape=[4,3,2,1]) 

sage: t = B[31].to_tableau() 

sage: t.seg() 

3 

""" 

return len(self._segments()) 

 

def flush(self): 

r""" 

Return the number of flush segments in ``self``, as in [S14]_. 

 

Let `1 \le i < k \le r+1` and suppose `\ell` is the smallest integer 

greater than `k` such that there exists an `\ell`-segment in the 

`(i+1)`-st row of `T`. A `k`-segment in the `i`-th row of `T` is 

called *flush* if the leftmost box in the `k`-segment and the leftmost 

box of the `\ell`-segment are in the same column of `T`. If, however, 

no such `\ell` exists, then this `k`-segment is said to be *flush* if 

the number of boxes in the `k`-segment is equal to `\theta_i`, where 

`\theta_i = \lambda_i - \lambda_{i+1}` and the shape of `T` is 

`\lambda = (\lambda_1 > \lambda_2 > \cdots > \lambda_r)`. Denote the 

number of flush `k`-segments in `T` by `\mathrm{flush}(T)`. 

 

EXAMPLES:: 

 

sage: t = Tableau([[1,1,2,3,5],[2,3,5,5],[3,4]]) 

sage: t.flush() 

3 

 

sage: B = crystals.Tableaux("A4",shape=[4,3,2,1]) 

sage: t = B[32].to_tableau() 

sage: t.flush() 

4 

""" 

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

if len(self[i]) <= len(self[i+1]): 

raise ValueError('only defined for tableaux with stricly decreasing parts') 

f = 0 

S = self._segments().items() 

for s in S: 

if (s[0][0] != len(self)-1 and s[1] == len(self[s[0][0]+1]) 

and self[s[0][0]+1][-1] <= s[0][1]) \ 

or (s[0][0] == len(self)-1 and s[1] == 0): 

f += 1 

else: 

for t in S: 

if s[0][0]+1 == t[0][0] and s[1] == t[1] and ( 

(s[1] >= 1 and self[s[0][0]+1][s[1]-1] <= self[s[0][0]][s[1]]) 

or (s[1] < 1 and self[s[0][0]+1][s[1]] != s[0][0]+2) ): 

f += 1 

return f 

 

################################## 

# contents, residues and degrees # 

################################## 

 

def content(self, k, multicharge=[0]): 

""" 

Return the content of ``k`` in the standard tableau ``self``. 

 

The content of `k` is `c - r` if `k` appears in row `r` and 

column `c` of the tableau. 

 

The ``multicharge`` is a list of length 1 which gives an offset for 

all of the contents. It is included mainly for compatibility with 

:meth:`sage.combinat.tableau_tuple.TableauTuple`. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2],[3,4]]).content(3) 

-1 

 

sage: StandardTableau([[1,2],[3,4]]).content(6) 

Traceback (most recent call last): 

... 

ValueError: 6 does not appear in tableau 

""" 

for r,row in enumerate(self): 

try: 

return row.index(k) - r + multicharge[0] 

except ValueError: 

pass 

raise ValueError("%d does not appear in tableau"%k) 

 

def residue(self, k, e, multicharge=(0,)): 

r""" 

Return the residue of the integer ``k`` in the tableau ``self``. 

 

The *residue* of `k` in a standard tableau is `c - r + m` 

in `\ZZ / e\ZZ`, where `k` appears in row `r` and column `c` 

of the tableau with multicharge `m`. 

 

INPUT: 

 

- ``k`` -- an integer in `\{1, 2, \ldots, n\}` 

- ``e`` -- an integer in `\{0, 2, 3, 4, 5, \ldots\}` 

- ``multicharge`` -- (default: ``[0]``) a list of length 1 

 

Here `n` is its size of ``self``. 

 

The ``multicharge`` is a list of length 1 which gives an offset for 

all of the contents. It is included mainly for compatibility with 

:meth:`~sage.combinat.tableau_tuples.TableauTuple.residue`. 

 

OUTPUT: 

 

The residue in `\ZZ / e\ZZ`. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2,5],[3,4]]).residue(1,3) 

0 

sage: StandardTableau([[1,2,5],[3,4]]).residue(2,3) 

1 

sage: StandardTableau([[1,2,5],[3,4]]).residue(3,3) 

2 

sage: StandardTableau([[1,2,5],[3,4]]).residue(4,3) 

0 

sage: StandardTableau([[1,2,5],[3,4]]).residue(5,3) 

2 

sage: StandardTableau([[1,2,5],[3,4]]).residue(6,3) 

Traceback (most recent call last): 

... 

ValueError: 6 does not appear in the tableau 

""" 

for r, row in enumerate(self): 

try: 

return IntegerModRing(e)(row.index(k) - r + multicharge[0]) 

except ValueError: 

pass 

raise ValueError('%d does not appear in the tableau'%k) 

 

def residue_sequence(self, e, multicharge=(0,)): 

r""" 

Return the :class:`sage.combinat.tableau_residues.ResidueSequence` 

of the tableau ``self``. 

 

INPUT: 

 

- ``e`` -- an integer in `\{0, 2, 3, 4, 5, \ldots\}` 

- ``multicharge`` -- (default: ``[0]``) a sequence of integers 

of length 1 

 

The `multicharge` is a list of length 1 which gives an offset for 

all of the contents. It is included mainly for compatibility with 

:meth:`~sage.combinat.tableau_tuples.StandardTableauTuple.residue`. 

 

OUTPUT: 

 

The corresponding residue sequence of the tableau; 

see :class:`ResidueSequence`. 

 

EXAMPLES:: 

 

sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(2) 

2-residue sequence (0,1,1,0) with multicharge (0) 

sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(3) 

3-residue sequence (0,1,2,0) with multicharge (0) 

sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(4) 

4-residue sequence (0,1,3,0) with multicharge (0) 

""" 

res = [0] * self.size() 

for r,row in enumerate(self): 

for c,entry in enumerate(row): 

res[entry-1] = multicharge[0] - r + c 

from sage.combinat.tableau_residues import ResidueSequence 

return ResidueSequence(e, multicharge, res, check=False) 

 

def degree(self, e, multicharge=(0,)): 

""" 

Return the Brundan-Kleshchev-Wang [BKW11]_ degree of ``self``. 

 

The *degree* is an integer that is defined recursively by successively 

stripping off the number `k`, for `k = n, n-1, \ldots, 1` and at stage 

adding the number of addable cell of the same residue minus the number 

of removable cells of the same residue as `k` and which are below `k` 

in the diagram. 

 

The degrees of the tableau `T` gives the degree of the homogeneous 

basis element of the graded Specht module that is indexed by `T`. 

 

INPUT: 

 

- ``e`` -- the *quantum characteristic* 

- ``multicharge`` -- (default: ``[0]``) the multicharge 

 

OUTPUT: 

 

The degree of the tableau ``self``, which is an integer. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2,5],[3,4]]).degree(3) 

0 

sage: StandardTableau([[1,2,5],[3,4]]).degree(4) 

1 

 

REFERENCES: 

 

.. [BKW11] \J. Brundan, A. Kleshchev, and W. Wang, 

*Graded Specht modules*, 

J. Reine Angew. Math., 655 (2011), 61-87. 

""" 

n = self.size() 

if n == 0: 

return 0 

 

deg = self.shape()._initial_degree(e,multicharge) 

res = self.shape().initial_tableau().residue_sequence(e, multicharge) 

for r in self.reduced_row_word(): 

if res[r] == res[r+1]: 

deg -= 2 

elif res[r] == res[r+1] + 1 or res[r] == res[r+1] - 1: 

deg += (e == 2 and 2 or 1) 

res = res.swap_residues(r, r+1) 

return deg 

 

def codegree(self, e, multicharge=(0,)): 

""" 

Return the Brundan-Kleshchev-Wang [BKW11]_ codegree of the 

standard tableau ``self``. 

 

The *coderee* of a tableau is an integer that is defined recursively by 

successively stripping off the number `k`, for `k = n, n-1, \ldots, 1` 

and at stage adding the number of addable cell of the same residue 

minus the number of removable cells of the same residue as `k` and 

are above `k` in the diagram. 

 

The codegree of the tableau `T` gives the degree of "dual" 

homogeneous basis element of the Graded Specht module that 

is indexed by `T`. 

 

INPUT: 

 

- ``e`` -- the *quantum characteristic* 

- ``multicharge`` -- (default: ``[0]``) the multicharge 

 

OUTPUT: 

 

The codegree of the tableau ``self``, which is an integer. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,3,5],[2,4]]).codegree(3) 

0 

sage: StandardTableau([[1,2,5],[3,4]]).codegree(3) 

1 

sage: StandardTableau([[1,2,5],[3,4]]).codegree(4) 

0 

 

REFERENCES: 

 

- [BKW11]_ \J. Brundan, A. Kleshchev, and W. Wang, 

*Graded Specht modules*, 

J. Reine Angew. Math., 655 (2011), 61-87. 

""" 

if not self: # the trivial case 

return 0 

 

conj_shape = self.shape().conjugate() 

codeg = conj_shape._initial_degree(e) 

res = conj_shape.initial_tableau().residue_sequence(e) 

for r in self.reduced_column_word(): 

if res[r] == res[r+1]: 

codeg -= 2 

elif res[r] == res[r+1] + 1 or res[r] == res[r+1] - 1: 

codeg += (e == 2 and 2 or 1) 

res = res.swap_residues(r, r+1) 

return codeg 

 

def first_row_descent(self): 

r""" 

Return the first cell where the tableau ``self`` is not row standard. 

 

Cells are ordered left to right along the rows and then top to bottom. 

That is, the cell `(r,c)` with `r` and `c` minimal such that the entry 

in position `(r,c)` is bigger than the entry in position `(r, c+1)`. 

If there is no such cell then ``None`` is returned - in this case the 

tableau is row strict. 

 

OUTPUT: 

 

The first cell which there is a descent or ``None`` if no such 

cell exists. 

 

EXAMPLES:: 

 

sage: t=Tableau([[1,3,2],[4]]); t.first_row_descent() 

(0, 1) 

sage: Tableau([[1,2,3],[4]]).first_row_descent() is None 

True 

""" 

for row in range(len(self)): 

for col in range(len(self[row])-1): 

if self[row][col]>self[row][col+1]: 

return (row,col) 

return None 

 

def first_column_descent(self): 

r""" 

Return the first cell where ``self`` is not column standard. 

 

Cells are ordered left to right along the rows and then top to bottom. 

That is, the cell `(r, c)` with `r` and `c` minimal such that 

the entry in position `(r, c)` is bigger than the entry in position 

`(r, c+1)`. If there is no such cell then ``None`` is returned - in 

this case the tableau is column strict. 

 

OUTPUT: 

 

The first cell which there is a descent or ``None`` if no such 

cell exists. 

 

EXAMPLES:: 

 

sage: Tableau([[1,4,5],[2,3]]).first_column_descent() 

(0, 1) 

sage: Tableau([[1,2,3],[4]]).first_column_descent() is None 

True 

""" 

for row in range(len(self)-1): 

col = 0 

while col < len(self[row+1]): 

if self[row][col] > self[row+1][col]: 

return (row, col) 

col += 1 

return None 

 

def reduced_row_word(self): 

r""" 

Return the lexicographically minimal reduced expression for the 

permutation that maps the :meth:`initial_tableau` to ``self``. 

 

Ths reduced expression is a minimal length coset representative for the 

corresponding Young subgroup. In one line notation, the permutation is 

obtained by concatenating the rows of the tableau in order from top to 

bottom. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,2,3],[4,5],[6]]).reduced_row_word() 

[] 

sage: StandardTableau([[1,2,3],[4,6],[5]]).reduced_row_word() 

[5] 

sage: StandardTableau([[1,2,4],[3,6],[5]]).reduced_row_word() 

[3, 5] 

sage: StandardTableau([[1,2,5],[3,6],[4]]).reduced_row_word() 

[3, 5, 4] 

sage: StandardTableau([[1,2,6],[3,5],[4]]).reduced_row_word() 

[3, 4, 5, 4] 

""" 

return permutation.Permutation(list(self.entries())).inverse().reduced_word_lexmin() 

 

def reduced_column_word(self): 

r""" 

Return the lexicographically minimal reduced expression for the 

permutation that maps the conjugate of the :meth:`initial_tableau` 

to ``self``. 

 

Ths reduced expression is a minimal length coset representative for 

the corresponding Young subgroup. In one line notation, the 

permutation is obtained by concatenating the columns of the 

tableau in order from top to bottom. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1,4,6],[2,5],[3]]).reduced_column_word() 

[] 

sage: StandardTableau([[1,4,5],[2,6],[3]]).reduced_column_word() 

[5] 

sage: StandardTableau([[1,3,6],[2,5],[4]]).reduced_column_word() 

[3] 

sage: StandardTableau([[1,3,5],[2,6],[4]]).reduced_column_word() 

[3, 5] 

sage: StandardTableau([[1,2,5],[3,6],[4]]).reduced_column_word() 

[3, 2, 5] 

""" 

data = list(self.conjugate().entries()) 

return permutation.Permutation(data).inverse().reduced_word_lexmin() 

 

class SemistandardTableau(Tableau): 

""" 

A class to model a semistandard tableau. 

 

INPUT: 

 

- ``t`` -- a tableau, a list of iterables, or an empty list 

 

OUTPUT: 

 

- A SemistandardTableau object constructed from ``t``. 

 

A semistandard tableau is a tableau whose entries are positive integers, 

which are weakly increasing in rows and strictly increasing down columns. 

 

EXAMPLES:: 

 

sage: t = SemistandardTableau([[1,2,3],[2,3]]); t 

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

sage: t.shape() 

[3, 2] 

sage: t.pp() # pretty print 

1 2 3 

2 3 

sage: t = Tableau([[1,2],[2]]) 

sage: s = SemistandardTableau(t); s 

[[1, 2], [2]] 

sage: SemistandardTableau([]) # The empty tableau 

[] 

 

When using code that will generate a lot of tableaux, it is slightly more 

efficient to construct a SemistandardTableau from the appropriate 

:class:`Parent` object:: 

 

sage: SST = SemistandardTableaux() 

sage: SST([[1, 2, 3], [4, 5]]) 

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

 

.. SEEALSO:: 

 

- :class:`Tableaux` 

- :class:`Tableau` 

- :class:`SemistandardTableaux` 

- :class:`StandardTableaux` 

- :class:`StandardTableau` 

 

TESTS:: 

 

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

Traceback (most recent call last): 

... 

ValueError: [[1, 2, 3], [1]] is not a column strict tableau 

 

sage: SemistandardTableau([[1,2,1]]) 

Traceback (most recent call last): 

... 

ValueError: The rows of [[1, 2, 1]] are not weakly increasing 

 

sage: SemistandardTableau([[0,1]]) 

Traceback (most recent call last): 

... 

ValueError: entries must be positive integers 

""" 

@staticmethod 

def __classcall_private__(self, t): 

r""" 

This ensures that a SemistandardTableau is only ever constructed as an 

element_class call of an appropriate parent. 

 

TESTS:: 

 

sage: t = SemistandardTableau([[1,1],[2]]) 

sage: TestSuite(t).run() 

 

sage: t.parent() 

Semistandard tableaux 

sage: t.category() 

Category of elements of Semistandard tableaux 

sage: type(t) 

<class 'sage.combinat.tableau.SemistandardTableaux_all_with_category.element_class'> 

""" 

if isinstance(t, SemistandardTableau): 

return t 

elif t in SemistandardTableaux(): 

return SemistandardTableaux_all().element_class(SemistandardTableaux_all(), t) 

 

# t is not a semistandard tableau so we give an appropriate error message 

if t not in Tableaux(): 

raise ValueError('%s is not a tableau' % t) 

 

if not all(isinstance(c,(int,Integer)) and c>0 for row in t for c in row): 

raise ValueError("entries must be positive integers"%t) 

 

if any(row[c]>row[c+1] for row in t for c in range(len(row)-1)): 

raise ValueError("The rows of %s are not weakly increasing"%t) 

 

# If we're still here ``t`` cannot be column strict 

raise ValueError('%s is not a column strict tableau' % t) 

 

 

def __init__(self, parent, t): 

r""" 

Initialize a semistandard tableau. 

 

TESTS:: 

 

sage: t = Tableaux()([[1,1],[2]]) 

sage: s = SemistandardTableaux(3)([[1,1],[2]]) 

sage: s==t 

True 

sage: s.parent() 

Semistandard tableaux of size 3 and maximum entry 3 

sage: r = SemistandardTableaux(3)(t); r.parent() 

Semistandard tableaux of size 3 and maximum entry 3 

sage: isinstance(r, Tableau) 

True 

sage: s2 = SemistandardTableaux(3)([(1,1),(2,)]) 

sage: s2 == s 

True 

sage: s2.parent() 

Semistandard tableaux of size 3 and maximum entry 3 

""" 

super(SemistandardTableau, self).__init__(parent, t) 

 

# Tableau() has checked that t is tableau, so it remains to check that 

# the entries of t are positive integers which are weakly increasing 

# along rows 

from sage.sets.positive_integers import PositiveIntegers 

PI = PositiveIntegers() 

 

for row in t: 

if any(c not in PI for c in row): 

raise ValueError("the entries of a semistandard tableau must be non-negative integers") 

if any(row[c] > row[c+1] for c in range(len(row)-1)): 

raise ValueError("the entries in each row of a semistandard tableau must be weakly increasing") 

 

# and strictly increasing down columns 

if t: 

for row, next in zip(t, t[1:]): 

if not all(row[c] < next[c] for c in range(len(next))): 

raise ValueError("the entries of each column of a semistandard tableau must be strictly increasing") 

 

class StandardTableau(SemistandardTableau): 

""" 

A class to model a standard tableau. 

 

INPUT: 

 

- ``t`` -- a Tableau, a list of iterables, or an empty list 

 

OUTPUT: 

 

- A StandardTableau object constructed from ``t``. 

 

A standard tableau is a semistandard tableau whose entries are exactly the 

positive integers from 1 to `n`, where `n` is the size of the tableau. 

 

EXAMPLES:: 

 

sage: t = StandardTableau([[1,2,3],[4,5]]); t 

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

sage: t.shape() 

[3, 2] 

sage: t.pp() # pretty print 

1 2 3 

4 5 

sage: t.is_standard() 

True 

sage: StandardTableau([]) # The empty tableau 

[] 

 

When using code that will generate a lot of tableaux, it is slightly more 

efficient to construct a StandardTableau from the appropriate 

:class:`Parent` object:: 

 

sage: ST = StandardTableaux() 

sage: ST([[1, 2, 3], [4, 5]]) 

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

 

.. SEEALSO:: 

 

- :class:`Tableaux` 

- :class:`Tableau` 

- :class:`SemistandardTableaux` 

- :class:`SemistandardTableau` 

- :class:`StandardTableaux` 

 

sage: StandardTableau([[1,2,3],[4,4]]) 

Traceback (most recent call last): 

... 

ValueError: the entries in a standard tableau must be in bijection with 1,2,...,n 

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

Traceback (most recent call last): 

... 

ValueError: the entries in each row of a semistandard tableau must be weakly increasing 

""" 

@staticmethod 

def __classcall_private__(self, t): 

r""" 

This ensures that a :class:`StandardTableau` is only ever constructed 

as an ``element_class`` call of an appropriate parent. 

 

TESTS:: 

 

sage: t = StandardTableau([[1,2],[3]]) 

sage: TestSuite(t).run() 

 

sage: t.parent() 

Standard tableaux 

sage: type(t) 

<class 'sage.combinat.tableau.StandardTableaux_all_with_category.element_class'> 

""" 

if isinstance(t, StandardTableau): 

return t 

 

return StandardTableaux_all().element_class(StandardTableaux_all(), t) 

 

def __init__(self, parent, t): 

r""" 

Initializes a standard tableau. 

 

TESTS:: 

 

sage: t = Tableaux()([[1,2],[3]]) 

sage: s = StandardTableaux(3)([[1,2],[3]]) 

sage: s==t 

True 

sage: s.parent() 

Standard tableaux of size 3 

sage: r = StandardTableaux(3)(t); r.parent() 

Standard tableaux of size 3 

sage: isinstance(r, Tableau) 

True 

""" 

super(StandardTableau, self).__init__(parent, t) 

 

# t is semistandard so we only need to check 

# that its entries are in bijection with {1, 2, ..., n} 

flattened_list = [i for row in self for i in row] 

if sorted(flattened_list) != list(range(1, len(flattened_list) + 1)): 

raise ValueError("the entries in a standard tableau must be in bijection with 1,2,...,n") 

 

def dominates(self, t): 

r""" 

Return ``True`` if ``self`` dominates the tableau ``t``. 

 

That is, if the shape of the tableau restricted to `k` 

dominates the shape of ``t`` restricted to `k`, for `k = 1, 2, 

\ldots, n`. 

 

When the two tableaux have the same shape, then this ordering 

coincides with the Bruhat ordering for the corresponding permutations. 

 

INPUT: 

 

- ``t`` -- a tableau 

 

EXAMPLES:: 

 

sage: s=StandardTableau([[1,2,3],[4,5]]) 

sage: t=StandardTableau([[1,2],[3,5],[4]]) 

sage: s.dominates(t) 

True 

sage: t.dominates(s) 

False 

sage: all(StandardTableau(s).dominates(t) for t in StandardTableaux([3,2])) 

True 

sage: s.dominates([[1,2,3,4,5]]) 

False 

 

""" 

t=StandardTableau(t) 

return all(self.restrict(m).shape().dominates(t.restrict(m).shape()) 

for m in range(1,1+self.size())) 

 

def is_standard(self): 

""" 

Return ``True`` since ``self`` is a standard tableau. 

 

EXAMPLES:: 

 

sage: StandardTableau([[1, 3], [2, 4]]).is_standard() 

True 

""" 

return True 

 

def up(self): 

""" 

An iterator for all the standard tableaux that can be 

obtained from ``self`` by adding a cell. 

 

EXAMPLES:: 

 

sage: t = StandardTableau([[1,2]]) 

sage: [x for x in t.up()] 

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

""" 

#Get a list of all places where we can add a cell 

#to the shape of self 

 

outside_corners = self.shape().outside_corners() 

 

n = self.size() 

 

#Go through and add n+1 to the end of each 

#of the rows 

for row, _ in outside_corners: 

new_t = [list(_) for _ in self] 

if row != len(self): 

new_t[row] += [n+1] 

else: 

new_t.append([n+1]) 

yield StandardTableau(new_t) 

 

def up_list(self): 

""" 

Return a list of all the standard tableaux that can be obtained 

from ``self`` by adding a cell. 

 

EXAMPLES:: 

 

sage: t = StandardTableau([[1,2]]) 

sage: t.up_list() 

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

""" 

return list(self.up()) 

 

def down(self): 

""" 

An iterator for all the standard tableaux that can be obtained 

from ``self`` by removing a cell. Note that this iterates just 

over a single tableau (or nothing if ``self`` is empty). 

 

EXAMPLES:: 

 

sage: t = StandardTableau([[1,2],[3]]) 

sage: [x for x in t.down()] 

[[[1, 2]]] 

sage: t = StandardTableau([]) 

sage: [x for x in t.down()] 

[] 

""" 

if self: 

yield self.restrict(self.size() - 1) 

 

def down_list(self): 

""" 

Return a list of all the standard tableaux that can be obtained 

from ``self`` by removing a cell. Note that this is just a singleton 

list if ``self`` is nonempty, and an empty list otherwise. 

 

EXAMPLES:: 

 

sage: t = StandardTableau([[1,2],[3]]) 

sage: t.down_list() 

[[[1, 2]]] 

sage: t = StandardTableau([]) 

sage: t.down_list() 

[] 

""" 

return list(self.down()) 

 

def standard_descents(self): 

""" 

Return a list of the integers `i` such that `i` appears 

strictly further north than `i + 1` in ``self`` (this is not 

to say that `i` and `i + 1` must be in the same column). The 

list is sorted in increasing order. 

 

EXAMPLES:: 

 

sage: StandardTableau( [[1,3,4],[2,5]] ).standard_descents() 

[1, 4] 

sage: StandardTableau( [[1,2],[3,4]] ).standard_descents() 

[2] 

sage: StandardTableau( [[1,2,5],[3,4],[6,7],[8],[9]] ).standard_descents() 

[2, 5, 7, 8] 

sage: StandardTableau( [] ).standard_descents() 

[] 

""" 

descents = [] 

#whatpart gives the number for which self is a partition 

whatpart = sum(i for i in self.shape()) 

#now find the descents 

for i in range(1, whatpart): 

#find out what row i and i+1 are in (we're using the 

#standardness of self here) 

for row in self: 

if row.count(i + 1): 

break 

if row.count(i): 

descents.append(i) 

break 

return descents 

 

def standard_number_of_descents(self): 

""" 

Return the number of all integers `i` such that `i` appears 

strictly further north than `i + 1` in ``self`` (this is not 

to say that `i` and `i + 1` must be in the same column). A 

list of these integers can be obtained using the 

:meth:`standard_descents` method. 

 

EXAMPLES:: 

 

sage: StandardTableau( [[1,2],[3,4],[5]] ).standard_number_of_descents() 

2 

sage: StandardTableau( [] ).standard_number_of_descents() 

0 

sage: tabs = StandardTableaux(5) 

sage: all( t.standard_number_of_descents() == t.schuetzenberger_involution().standard_number_of_descents() for t in tabs ) 

True 

""" 

return len(self.standard_descents()) 

 

def standard_major_index(self): 

""" 

Return the major index of the standard tableau ``self`` in the 

standard meaning of the word. The major index is defined to be 

the sum of the descents of ``self`` (see :meth:`standard_descents` 

for their definition). 

 

EXAMPLES:: 

 

sage: StandardTableau( [[1,4,5],[2,6],[3]] ).standard_major_index() 

8 

sage: StandardTableau( [[1,2],[3,4]] ).standard_major_index() 

2 

sage: StandardTableau( [[1,2,3],[4,5]] ).standard_major_index() 

3 

""" 

return sum(self.standard_descents()) 

 

def promotion_inverse(self, n=None): 

""" 

Return the image of ``self`` under the inverse promotion operator. 

The optional variable `m` should be set to the size of ``self`` minus 

`1` for a minimal speedup; otherwise, it defaults to this number. 

 

The inverse promotion operator, applied to a standard tableau `t`, 

does the following: 

 

Remove the letter `1` from `t`, thus leaving a hole where it used to be. 

Apply jeu de taquin to move this hole northeast (in French notation) 

until it reaches the outer boundary of `t`. Fill `n + 1` into this hole, 

where `n` is the size of `t`. Finally, subtract `1` from each letter in 

the tableau. This yields a new standard tableau. 

 

This definition of inverse promotion is the map called "promotion" in 

[Sg2011]_ (p. 23) and in [Stan2009]_, and is the inverse of the map 

called "promotion" in [Hai1992]_ (p. 90). 

 

See the :meth:`~sage.combinat.tableau.promotion_inverse` method for a 

more general operator. 

 

EXAMPLES:: 

 

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

sage: t.promotion_inverse() 

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

 

We check the equivalence of two definitions of inverse promotion on 

standard tableaux:: 

 

sage: ST = StandardTableaux(7) 

sage: def bk_promotion_inverse7(st): 

....: st2 = st 

....: for i in range(1, 7): 

....: st2 = st2.bender_knuth_involution(i, check=False) 

....: return st2 

sage: all( bk_promotion_inverse7(st) == st.promotion_inverse() for st in ST ) # long time 

True 

""" 

if n is None: 

n = self.size() - 1 

return StandardTableau(Tableau(self[:]).promotion_inverse(n)) 

 

def promotion(self, n=None): 

r""" 

Return the image of ``self`` under the promotion operator. 

 

The promotion operator, applied to a standard tableau `t`, does the 

following: 

 

Remove the letter `n` from `t`, thus leaving a hole where it used to be. 

Apply jeu de taquin to move this hole southwest (in French notation) 

until it reaches the inner boundary of `t`. Fill `0` into the hole once 

jeu de taquin has completed. Finally, add `1` to each letter in the 

tableau. The resulting standard tableau is the image of `t` under the 

promotion operator. 

 

This definition of promotion is precisely the one given in [Hai1992]_ 

(p. 90). It is the inverse of the maps called "promotion" in [Sg2011]_ 

(p. 23) and in [Stan2009]_. 

 

See the :meth:`~sage.combinat.tableau.promotion` method for a 

more general operator. 

 

EXAMPLES:: 

 

sage: ST = StandardTableaux(7) 

sage: all( st.promotion().promotion_inverse() == st for st in ST ) # long time 

True 

sage: all( st.promotion_inverse().promotion() == st for st in ST ) # long time 

True 

sage: st = StandardTableau([[1,2,5],[3,4]]) 

sage: parent(st.promotion()) 

Standard tableaux 

""" 

if n is None: 

n = self.size() - 1 

return StandardTableau(Tableau(self[:]).promotion(n)) 

 

def from_chain(chain): 

""" 

Returns a semistandard tableau from a chain of partitions. 

 

EXAMPLES:: 

 

sage: from sage.combinat.tableau import from_chain 

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

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

""" 

res = [[0]*chain[-1][i] for i in range(len(chain[-1]))] 

for i in reversed(range(2, len(chain)+1)): 

for j in range(len(chain[i-1])): 

for k in range(chain[i-1][j]): 

res[j][k] = i -1 

return Tableau(res) 

 

def from_shape_and_word(shape, w, convention="French"): 

r""" 

Returns a tableau from a shape and word. 

 

INPUT: 

 

- ``shape`` -- a partition 

 

- ``w`` -- a word whose length equals that of the partition 

 

- ``convention`` -- a string which can take values ``"French"`` or 

``"English"``; the default is ``"French"`` 

 

OUTPUT: 

 

A tableau, whose shape is ``shape`` and whose reading word is ``w``. 

If the ``convention`` is specified as ``"French"``, the reading word is to be read 

starting from the top row in French convention (= the bottom row in English 

convention). If the ``convention`` is specified as ``"English"``, the reading word 

is to be read starting with the top row in English convention. 

 

EXAMPLES:: 

 

sage: from sage.combinat.tableau import from_shape_and_word 

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

sage: shape = t.shape(); shape 

[2, 1, 1] 

sage: word = t.to_word(); word 

word: 4213 

sage: from_shape_and_word(shape, word) 

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

sage: word = Word(flatten(t)) 

sage: from_shape_and_word(shape, word, convention = "English") 

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

""" 

res = [] 

j = 0 

if convention == "French": 

shape = reversed(shape) 

for l in shape: 

res.append( list(w[j:j+l]) ) 

j += l 

if convention == "French": 

res.reverse() 

return Tableau(res) 

 

class Tableaux(UniqueRepresentation, Parent): 

""" 

A factory class for the various classes of tableaux. 

 

INPUT: 

 

- ``n`` (optional) -- a non-negative integer 

 

OUTPUT: 

 

- If ``n`` is specified, the class of tableaux of size ``n``. Otherwise, 

the class of all tableaux. 

 

A tableau in Sage is a finite list of lists, whose lengths are weakly 

decreasing, or an empty list, representing the empty tableau. The entries 

of a tableau can be any Sage objects. Because of this, no enumeration 

through the set of Tableaux is possible. 

 

EXAMPLES:: 

 

sage: T = Tableaux(); T 

Tableaux 

sage: T3 = Tableaux(3); T3 

Tableaux of size 3 

sage: [['a','b']] in T 

True 

sage: [['a','b']] in T3 

False 

sage: t = T3([[1,1,1]]); t 

[[1, 1, 1]] 

sage: t in T 

True 

sage: t.parent() 

Tableaux of size 3 

sage: T([]) # the empty tableau 

[] 

sage: T.category() 

Category of sets 

 

.. SEEALSO:: 

 

- :class:`Tableau` 

- :class:`SemistandardTableaux` 

- :class:`SemistandardTableau` 

- :class:`StandardTableaux` 

- :class:`StandardTableau` 

 

TESTS:: 

 

sage: TestSuite( Tableaux() ).run() 

sage: TestSuite( Tableaux(5) ).run() 

sage: t = Tableaux(3)([[1,2],[3]]) 

sage: t.parent() 

Tableaux of size 3 

sage: Tableaux(t) 

Traceback (most recent call last): 

... 

ValueError: The argument to Tableaux() must be a non-negative integer. 

sage: Tableaux(3)([[1, 1]]) 

Traceback (most recent call last): 

... 

ValueError: [[1, 1]] is not an element of Tableaux of size 3. 

 

sage: t0 = Tableau([[1]]) 

sage: t1 = Tableaux()([[1]]) 

sage: t2 = Tableaux()(t1) 

sage: t0 == t1 == t2 

True 

sage: t1 in Tableaux() 

True 

sage: t1 in Tableaux(1) 

True 

sage: t1 in Tableaux(2) 

False 

 

sage: [[1]] in Tableaux() 

True 

sage: [] in Tableaux(0) 

True 

 

Check that :trac:`14145` has been fixed:: 

 

sage: 1 in Tableaux() 

False 

""" 

@staticmethod 

def __classcall_private__(cls, *args, **kwargs): 

r""" 

This is a factory class which returns the appropriate parent based on 

arguments. See the documentation for :class:`Tableaux` for more 

information. 

 

TESTS:: 

 

sage: Tableaux() 

Tableaux 

sage: Tableaux(3) 

Tableaux of size 3 

""" 

if args: 

n = args[0] 

elif 'n' in kwargs: 

n = kwargs[n] 

else: 

n = None 

 

if n is None: 

return Tableaux_all() 

else: 

if not isinstance(n,(int, Integer)) or n < 0: 

raise ValueError( "The argument to Tableaux() must be a non-negative integer." ) 

return Tableaux_size(n) 

 

Element = Tableau 

 

# add options to class 

class options(GlobalOptions): 

r""" 

Sets the global options for elements of the tableau, skew_tableau, 

and tableau tuple classes. The defaults are for tableau to be 

displayed as a list, latexed as a Young diagram using the English 

convention. 

 

@OPTIONS@ 

 

.. NOTE:: 

 

Changing the ``convention`` for tableaux also changes the 

``convention`` for partitions. 

 

If no parameters are set, then the function returns a copy of the 

options dictionary. 

 

EXAMPLES:: 

 

sage: T = Tableau([[1,2,3],[4,5]]) 

sage: T 

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

sage: Tableaux.options.display="array" 

sage: T 

1 2 3 

4 5 

sage: Tableaux.options.convention="french" 

sage: T 

4 5 

1 2 3 

 

Changing the ``convention`` for tableaux also changes the ``convention`` 

for partitions and vice versa:: 

 

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

sage: print(P.ferrers_diagram()) 

* 

*** 

*** 

sage: Partitions.options.convention="english" 

sage: print(P.ferrers_diagram()) 

*** 

*** 

* 

sage: T 

1 2 3 

4 5 

 

The ASCII art can also be changed:: 

 

sage: t = Tableau([[1,2,3],[4,5]]) 

sage: ascii_art(t) 

1 2 3 

4 5 

sage: Tableaux.options.ascii_art = "table" 

sage: ascii_art(t) 

+---+---+---+ 

| 1 | 2 | 3 | 

+---+---+---+ 

| 4 | 5 | 

+---+---+ 

sage: Tableaux.options.ascii_art = "compact" 

sage: ascii_art(t) 

|1|2|3| 

|4|5| 

sage: Tableaux.options._reset() 

""" 

NAME = 'Tableaux' 

module = 'sage.combinat.tableau' 

display = dict(default="list", 

description='Controls the way in which tableaux are printed', 

values=dict(list='print tableaux as lists', 

diagram='display as Young diagram (similar to :meth:`~sage.combinat.tableau.Tableau.pp()`', 

compact='minimal length string representation'), 

alias=dict(array="diagram", ferrers_diagram="diagram", young_diagram="diagram"), 

case_sensitive=False) 

ascii_art = dict(default="repr", 

description='Controls the ascii art output for tableaux', 

values=dict(repr='display using the diagram string representation', 

table='display as a table', 

compact='minimal length ascii art'), 

case_sensitive=False) 

latex = dict(default="diagram", 

description='Controls the way in which tableaux are latexed', 

values=dict(list='as a list', diagram='as a Young diagram'), 

alias=dict(array="diagram", ferrers_diagram="diagram", young_diagram="diagram"), 

case_sensitive=False) 

convention = dict(default="English", 

description='Sets the convention used for displaying tableaux and partitions', 

values=dict(English='use the English convention',French='use the French convention'), 

case_sensitive=False) 

notation = dict(alt_name="convention") 

 

def _element_constructor_(self, t): 

r""" 

Constructs an object from ``t`` as an element of ``self``, if 

possible. This is inherited by all Tableaux, SemistandardTableaux, and 

StandardTableaux classes. 

 

INPUT: 

 

- ``t`` -- Data which can be interpreted as a tableau 

 

OUTPUT: 

 

- The corresponding tableau object 

 

TESTS:: 

 

sage: T = Tableaux(3) 

sage: T([[1,2,1]]).parent() is T # indirect doctest 

True 

sage: T( StandardTableaux(3)([[1, 2, 3]])).parent() is T 

True 

sage: T([[1,2]]) 

Traceback (most recent call last): 

... 

ValueError: [[1, 2]] is not an element of Tableaux of size 3. 

""" 

if not t in self: 

raise ValueError("%s is not an element of %s."%(t, self)) 

 

return self.element_class(self, t) 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: T = sage.combinat.tableau.Tableaux() 

sage: [[1,2],[3,4]] in T 

True 

sage: [[1,2],[3]] in T 

True 

sage: [] in T 

True 

sage: [['a','b']] in T 

True 

sage: Tableau([['a']]) in T 

True 

 

sage: [1,2,3] in T 

False 

sage: [[1],[1,2]] in T 

False 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in sage.combinat.tableau.Tableaux() 

False 

""" 

from sage.combinat.partition import _Partitions 

if isinstance(x, Tableau): 

return True 

elif isinstance(x, list): 

try: 

for row in x: 

iter(row) 

except TypeError: 

return False 

# any list of lists of partition shape is a tableau 

return [len(_) for _ in x] in _Partitions 

else: 

return False 

 

# def list(self): 

# """ 

# Raises a ``NotImplementedError`` since there is not a method to 

# enumerate all tableaux. 

# 

# TESTS:: 

# 

# sage: Tableaux().list() 

# Traceback (most recent call last): 

# ... 

# NotImplementedError 

# """ 

# raise NotImplementedError 

# 

# def __iter__(self): 

# """ 

# TESTS:: 

# 

# sage: iter(Tableaux()) 

# Traceback (most recent call last): 

# ... 

# NotImplementedError 

# """ 

# raise NotImplementedError 

 

class Tableaux_all(Tableaux): 

 

def __init__(self): 

r""" 

Initializes the class of all tableaux 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.Tableaux_all() 

sage: TestSuite(T).run() 

 

""" 

super(Tableaux_all, self).__init__(category=Sets()) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(Tableaux()) # indirect doctest 

'Tableaux' 

""" 

return "Tableaux" 

 

def an_element(self): 

r""" 

Returns a particular element of the class. 

 

TESTS:: 

 

sage: T = Tableaux() 

sage: T.an_element() 

[[1, 1], [1]] 

""" 

return self.element_class(self, [[1, 1], [1]]) 

 

 

class Tableaux_size(Tableaux): 

""" 

Tableaux of a fixed size `n`. 

""" 

 

def __init__(self, n): 

r""" 

Initializes the class of tableaux of size ``n``. 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.Tableaux_size(3) 

sage: TestSuite(T).run() 

 

sage: T = sage.combinat.tableau.Tableaux_size(0) 

sage: TestSuite(T).run() 

""" 

super(Tableaux_size, self).__init__(category=Sets()) 

self.size = n 

 

def __contains__(self,x): 

""" 

TESTS:: 

 

sage: T = sage.combinat.tableau.Tableaux_size(3) 

sage: [[2,4], [1]] in T 

True 

 

sage: [[2,4],[1,3]] in T 

False 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in sage.combinat.tableau.Tableaux_size(3) 

False 

""" 

return Tableaux.__contains__(self, x) and sum(len(row) for row in x) == self.size 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(Tableaux(4)) # indirect doctest 

'Tableaux of size 4' 

""" 

return "Tableaux of size %s"%self.size 

 

def an_element(self): 

r""" 

Returns a particular element of the class. 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.Tableaux_size(3) 

sage: T.an_element() 

[[1, 1], [1]] 

sage: T = sage.combinat.tableau.Tableaux_size(0) 

sage: T.an_element() 

[] 

""" 

if self.size==0: 

return self.element_class(self, []) 

 

if self.size==1: 

return self.element_class(self, [[1]]) 

 

return self.element_class(self, [[1]*(self.size-1),[1]]) 

 

 

########################## 

# Semi-standard tableaux # 

########################## 

class SemistandardTableaux(Tableaux): 

""" 

A factory class for the various classes of semistandard tableaux. 

 

INPUT: 

 

Keyword arguments: 

 

- ``size`` -- The size of the tableaux 

- ``shape`` -- The shape of the tableaux 

- ``eval`` -- The weight (also called content or evaluation) of 

the tableaux 

- ``max_entry`` -- A maximum entry for the tableaux. This can be a 

positive integer or infinity (``oo``). If ``size`` or ``shape`` are 

specified, ``max_entry`` defaults to be ``size`` or the size of 

``shape``. 

 

Positional arguments: 

 

- The first argument is interpreted as either ``size`` or ``shape`` 

according to whether it is an integer or a partition 

- The second keyword argument will always be interpreted as ``eval`` 

 

OUTPUT: 

 

- The appropriate class, after checking basic consistency tests. (For 

example, specifying ``eval`` implies a value for `max_entry`). 

 

A semistandard tableau is a tableau whose entries are positive integers, 

which are weakly increasing in rows and strictly increasing down columns. 

Note that Sage uses the English convention for partitions and tableaux; 

the longer rows are displayed on top. 

 

Classes of semistandard tableaux can be iterated over if and only if there 

is some restriction. 

 

EXAMPLES:: 

 

sage: SST = SemistandardTableaux([2,1]); SST 

Semistandard tableaux of shape [2, 1] and maximum entry 3 

sage: SST.list() 

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

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

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

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

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

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

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

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

 

sage: SST = SemistandardTableaux(3); SST 

Semistandard tableaux of size 3 and maximum entry 3 

sage: SST.list() 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 1, 3]], 

[[1, 2, 2]], 

[[1, 2, 3]], 

[[1, 3, 3]], 

[[2, 2, 2]], 

[[2, 2, 3]], 

[[2, 3, 3]], 

[[3, 3, 3]], 

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

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

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

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

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

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

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

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

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

 

sage: SST = SemistandardTableaux(3, max_entry=2); SST 

Semistandard tableaux of size 3 and maximum entry 2 

sage: SST.list() 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 2, 2]], 

[[2, 2, 2]], 

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

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

 

sage: SST = SemistandardTableaux(3, max_entry=oo); SST 

Semistandard tableaux of size 3 

sage: SST[123] 

[[3, 4], [6]] 

 

sage: SemistandardTableaux(max_entry=2)[11] 

[[1, 1], [2]] 

 

sage: SemistandardTableaux()[0] 

[] 

 

.. SEEALSO:: 

 

- :class:`Tableaux` 

- :class:`Tableau` 

- :class:`SemistandardTableau` 

- :class:`StandardTableaux` 

- :class:`StandardTableau` 

""" 

@staticmethod 

def __classcall_private__(cls, *args, **kwargs): 

r""" 

This is a factory class which returns the appropriate parent based on 

arguments. See the documentation for :class:`SemistandardTableaux` 

for more information. 

 

TESTS:: 

 

sage: SemistandardTableaux() 

Semistandard tableaux 

sage: SemistandardTableaux(3) 

Semistandard tableaux of size 3 and maximum entry 3 

sage: SemistandardTableaux(size=3) 

Semistandard tableaux of size 3 and maximum entry 3 

sage: SemistandardTableaux(0) 

Semistandard tableaux of size 0 and maximum entry 0 

sage: SemistandardTableaux([2,1]) 

Semistandard tableaux of shape [2, 1] and maximum entry 3 

sage: SemistandardTableaux(shape=[2,1]) 

Semistandard tableaux of shape [2, 1] and maximum entry 3 

sage: SemistandardTableaux([]) 

Semistandard tableaux of shape [] and maximum entry 0 

sage: SemistandardTableaux(eval=[2,1]) 

Semistandard tableaux of size 3 and weight [2, 1] 

sage: SemistandardTableaux(max_entry=3) 

Semistandard tableaux with maximum entry 3 

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

Semistandard tableaux of size 3 and weight [2, 1] 

sage: SemistandardTableaux(3, shape=[2,1]) 

Semistandard tableaux of shape [2, 1] and maximum entry 3 

sage: SemistandardTableaux(3, [2,1], shape=[2,1]) 

Semistandard tableaux of shape [2, 1] and weight [2, 1] 

sage: SemistandardTableaux(3, max_entry=4) 

Semistandard tableaux of size 3 and maximum entry 4 

sage: SemistandardTableaux(3, max_entry=oo) 

Semistandard tableaux of size 3 

sage: SemistandardTableaux([2, 1], max_entry=oo) 

Semistandard tableaux of shape [2, 1] 

sage: SemistandardTableaux([2, 1], [2, 1]) 

Semistandard tableaux of shape [2, 1] and weight [2, 1] 

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

Semistandard tableaux of shape [2, 1] and weight [2, 1] 

sage: SemistandardTableaux(3, [2, 1], max_entry=2) 

Semistandard tableaux of size 3 and weight [2, 1] 

 

sage: SemistandardTableaux(3, shape=[2]) 

Traceback (most recent call last): 

... 

ValueError: size and shape are different sizes 

 

sage: SemistandardTableaux(3, [2]) 

Traceback (most recent call last): 

... 

ValueError: size and eval are different sizes 

 

sage: SemistandardTableaux([2],[3]) 

Traceback (most recent call last): 

... 

ValueError: shape and eval are different sizes 

 

sage: SemistandardTableaux(2,[2], max_entry=4) 

Traceback (most recent call last): 

... 

ValueError: the maximum entry must match the weight 

 

sage: SemistandardTableaux(eval=[2], max_entry=oo) 

Traceback (most recent call last): 

... 

ValueError: the maximum entry must match the weight 

 

sage: SemistandardTableaux([[1]]) 

Traceback (most recent call last): 

... 

ValueError: shape must be a (skew) partition 

""" 

from sage.combinat.partition import Partition, _Partitions 

# Process the keyword arguments -- allow for original syntax where 

# n == size, p== shape and mu == eval 

n = kwargs.get('n', None) 

size = kwargs.get('size', n) 

 

p = kwargs.get('p', None) 

shape = kwargs.get('shape', p) 

 

mu = kwargs.get('eval', None) 

mu = kwargs.get("mu", mu) 

 

max_entry = kwargs.get('max_entry', None) 

 

# Process the positional arguments 

if args: 

# The first arg could be either a size or a shape 

if isinstance(args[0], (int, Integer)): 

if size is not None: 

raise ValueError( "size was specified more than once" ) 

else: 

size = args[0] 

else: 

if shape is not None: 

raise ValueError( "the shape was specified more than once" ) 

shape = args[0] # we check it's a partition later 

 

if len(args) == 2: 

# The second non-keyword argument is the weight 

if mu is not None: 

raise ValueError( "the weight was specified more than once" ) 

else: 

mu = args[1] 

 

# Consistency checks 

if size is not None: 

if not isinstance(size, (int, Integer)): 

raise ValueError( "size must be an integer" ) 

elif size < 0: 

raise ValueError( "size must be non-negative" ) 

 

if shape is not None: 

from sage.combinat.skew_partition import SkewPartitions 

# use in (and not isinstance) below so that lists can be used as 

# shorthand 

if shape in _Partitions: 

shape = Partition(shape) 

elif shape in SkewPartitions(): 

from sage.combinat.skew_tableau import SemistandardSkewTableaux 

return SemistandardSkewTableaux(shape, mu) 

else: 

raise ValueError( "shape must be a (skew) partition" ) 

 

if mu is not None: 

if (not mu in Compositions()) and\ 

(not mu in _Partitions): 

raise ValueError( "mu must be a composition" ) 

mu = Composition(mu) 

 

is_inf = max_entry is PlusInfinity() 

 

if max_entry is not None: 

if not is_inf and not isinstance(max_entry, (int, Integer)): 

raise ValueError( "max_entry must be an integer or PlusInfinity" ) 

elif max_entry <= 0: 

raise ValueError( "max_entry must be positive" ) 

 

if (mu is not None) and (max_entry is not None): 

if max_entry != len(mu): 

raise ValueError( "the maximum entry must match the weight" ) 

 

if (size is not None) and (shape is not None): 

if sum(shape) != size: 

# This could return an empty class instead of an error 

raise ValueError( "size and shape are different sizes" ) 

 

if (size is not None) and (mu is not None): 

if sum(mu) != size: 

# This could return an empty class instead of an error 

raise ValueError( "size and eval are different sizes" ) 

 

# Dispatch appropriately 

if (shape is not None) and (mu is not None): 

if sum(shape) != sum(mu): 

# This could return an empty class instead of an error 

raise ValueError( "shape and eval are different sizes" ) 

else: 

return SemistandardTableaux_shape_weight(shape, mu) 

 

if (shape is not None): 

if is_inf: 

return SemistandardTableaux_shape_inf(shape) 

return SemistandardTableaux_shape(shape, max_entry) 

 

if (mu is not None): 

return SemistandardTableaux_size_weight(sum(mu), mu) 

 

if (size is not None): 

if is_inf: 

return SemistandardTableaux_size_inf(size) 

return SemistandardTableaux_size(size, max_entry) 

 

return SemistandardTableaux_all(max_entry) 

 

Element = SemistandardTableau 

 

def __init__(self, **kwds): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: S = SemistandardTableaux() 

sage: TestSuite(S).run() 

""" 

if 'max_entry' in kwds: 

self.max_entry = kwds['max_entry'] 

kwds.pop('max_entry') 

else: 

self.max_entry = None 

Tableaux.__init__(self, **kwds) 

 

def __getitem__(self, r): 

r""" 

The default implementation of ``__getitem__`` for enumerated sets 

does not allow slices so we override it. 

 

EXAMPLES:: 

 

sage: StandardTableaux([4,3,3,2])[10:20] # indirect doctest 

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

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

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

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

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

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

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

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

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

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

 

sage: SemistandardTableaux(size=2, max_entry=oo)[5] 

[[2, 3]] 

 

sage: SemistandardTableaux([2,1], max_entry=oo)[3] 

[[1, 2], [3]] 

 

sage: SemistandardTableaux(3, max_entry=2)[0:5] # indirect doctest 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 2, 2]], 

[[2, 2, 2]], 

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

 

sage: SemistandardTableaux([2,2], [2, 1, 1])[0] # indirect doctest 

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

 

sage: SemistandardTableaux([1,1,1], max_entry=4)[0:4] 

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

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

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

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

 

sage: SemistandardTableaux(3, [2,1])[1] # indirect doctest 

[[1, 1], [2]] 

 

sage: StandardTableaux(3)[:] # indirect doctest 

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

 

sage: StandardTableaux([2,2])[1] # indirect doctest 

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

 

TESTS:: 

 

sage: SemistandardTableaux()[5] 

[[1], [2]] 

 

sage: SemistandardTableaux(max_entry=2)[5] 

[[2, 2]] 

 

sage: SemistandardTableaux()[:] 

Traceback (most recent call last): 

... 

ValueError: infinite set 

 

sage: SemistandardTableaux(size=2, max_entry=oo)[:] 

Traceback (most recent call last): 

... 

ValueError: infinite set 

""" 

if isinstance(r,(int,Integer)): 

return self.unrank(r) 

elif isinstance(r,slice): 

start=0 if r.start is None else r.start 

stop=r.stop 

if stop is None and not self.is_finite(): 

raise ValueError( 'infinite set' ) 

else: 

raise ValueError( 'r must be an integer or a slice' ) 

count=0 

tabs=[] 

for t in self: 

if count==stop: 

break 

if count>=start: 

tabs.append(t) 

count+=1 

 

# this is to cope with empty slices endpoints like [:6] or [:} 

if count==stop or stop is None: 

return tabs 

raise IndexError('value out of range') 

 

def __contains__(self, t): 

""" 

Return ``True`` if ``t`` can be interpreted as a 

:class:`SemistandardTableau`. 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.SemistandardTableaux_all() 

sage: [[1,2],[2]] in T 

True 

sage: [] in T 

True 

sage: Tableau([[1]]) in T 

True 

sage: StandardTableau([[1]]) in T 

True 

 

sage: [[1,2],[1]] in T 

False 

sage: [[1,1],[5]] in T 

True 

sage: [[1,3,2]] in T 

False 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in sage.combinat.tableau.SemistandardTableaux() 

False 

""" 

if isinstance(t, SemistandardTableau): 

return self.max_entry is None or \ 

len(t) == 0 or \ 

max(max(row) for row in t) <= self.max_entry 

elif not t: 

return True 

elif Tableaux.__contains__(self, t): 

for row in t: 

if not all(c > 0 for c in row): 

return False 

if not all(row[i] <= row[i+1] for i in range(len(row)-1)): 

return False 

for row, next in zip(t, t[1:]): 

if not all(row[c] < next[c] for c in range(len(next))): 

return False 

return self.max_entry is None or max(max(row) for row in t) <= self.max_entry 

else: 

return False 

 

class SemistandardTableaux_all(SemistandardTableaux, DisjointUnionEnumeratedSets): 

""" 

All semistandard tableaux. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, max_entry=None): 

r""" 

Initializes the class of all semistandard tableaux. 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.SemistandardTableaux_all() 

sage: TestSuite(T).run() 

 

sage: T=sage.combinat.tableau.SemistandardTableaux_all(max_entry=3) 

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

""" 

if max_entry is not PlusInfinity(): 

self.max_entry = max_entry 

SST_n = lambda n: SemistandardTableaux_size(n, max_entry) 

DisjointUnionEnumeratedSets.__init__( self, 

Family(NonNegativeIntegers(), SST_n), 

facade=True, keepkey = False) 

 

else: 

self.max_entry = None 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: SemistandardTableaux() # indirect doctest 

Semistandard tableaux 

 

sage: SemistandardTableaux(max_entry=3) 

Semistandard tableaux with maximum entry 3 

""" 

if self.max_entry is not None: 

return "Semistandard tableaux with maximum entry %s"%str(self.max_entry) 

return "Semistandard tableaux" 

 

 

def list(self): 

""" 

TESTS:: 

 

sage: SemistandardTableaux().list() 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

raise NotImplementedError 

 

 

class SemistandardTableaux_size_inf(SemistandardTableaux): 

""" 

Semistandard tableaux of fixed size `n` with no maximum entry. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, n): 

r""" 

Initializes the class of semistandard tableaux of size ``n`` with no 

maximum entry. 

 

TESTS:: 

 

sage: T = sage.combinat.tableau.SemistandardTableaux_size_inf(3) 

sage: TestSuite(T).run() 

""" 

super(SemistandardTableaux_size_inf, self).__init__( 

category = InfiniteEnumeratedSets()) 

self.size = n 

 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux(3, max_entry=oo)) # indirect doctest 

'Semistandard tableaux of size 3' 

""" 

return "Semistandard tableaux of size %s"%str(self.size) 

 

def __contains__(self, t): 

""" 

Return ``True`` if ``t`` can be interpreted as an element of this 

class. 

 

TESTS:: 

 

sage: T = SemistandardTableaux(3, max_entry=oo) 

sage: [[1,2],[5]] in T 

True 

sage: StandardTableau([[1, 2], [3]]) in T 

True 

 

sage: [] in T 

False 

sage: Tableau([[1]]) in T 

False 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in SemistandardTableaux(3, max_entry=oo) 

False 

""" 

return SemistandardTableaux.__contains__(self, t) and sum(map(len, t)) == self.size 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: sst = SemistandardTableaux(3, max_entry=oo) 

sage: [sst[t] for t in range(0,5)] 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 2, 2]], 

[[2, 2, 2]], 

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

sage: sst[1000] 

[[2, 12], [7]] 

sage: sst[0].parent() is sst 

True 

""" 

from sage.combinat.partition import Partitions 

# Iterates through with maximum entry as order 

i = 1 

while(True): 

for part in Partitions(self.size): 

if i != 1: 

for k in range(1, self.size+1): 

for c in integer_vectors_nk_fast_iter(self.size - k, i-1): 

c.append(k) 

for sst in SemistandardTableaux_shape_weight(part, Composition(c)): 

yield self.element_class(self, sst) 

else: 

for sst in SemistandardTableaux_shape_weight(part, Composition([self.size])): 

yield self.element_class(self, sst) 

i += 1 

 

 

def list(self): 

""" 

TESTS:: 

 

sage: SemistandardTableaux(3, max_entry=oo).list() 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

raise NotImplementedError 

 

 

class SemistandardTableaux_shape_inf(SemistandardTableaux): 

""" 

Semistandard tableaux of fixed shape `p` and no maximum entry. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, p): 

r""" 

Initializes the class of semistandard tableaux of shape ``p`` and no 

maximum entry. 

 

TESTS:: 

 

sage: SST = SemistandardTableaux([2,1], max_entry=oo) 

sage: type(SST) 

<class 'sage.combinat.tableau.SemistandardTableaux_shape_inf_with_category'> 

sage: TestSuite(SST).run() 

""" 

super(SemistandardTableaux_shape_inf, self).__init__( 

category = InfiniteEnumeratedSets()) 

self.shape = p 

 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: SST = SemistandardTableaux([2,1], max_entry=oo) 

sage: [[13, 67], [1467]] in SST 

True 

sage: SST = SemistandardTableaux([3,1], max_entry=oo) 

sage: [[13, 67], [1467]] in SST 

False 

 

Check that :trac:`14145` is fixed:: 

 

sage: SST = SemistandardTableaux([3,1], max_entry=oo) 

sage: 1 in SST 

False 

""" 

return SemistandardTableaux.__contains__(self, x) and [len(_) for _ in x]==self.shape 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux([2,1], max_entry=oo)) # indirect doctest 

'Semistandard tableaux of shape [2, 1]' 

""" 

return "Semistandard tableaux of shape %s" %str(self.shape) 

 

 

def __iter__(self): 

""" 

An iterator for the semistandard partitions of shape ``p`` and no 

maximum entry. Iterates through with maximum entry as order. 

 

EXAMPLES:: 

 

sage: SST = SemistandardTableaux([3, 1], max_entry=oo) 

sage: SST[1000] 

[[1, 1, 10], [6]] 

sage: [ SST[t] for t in range(0, 5) ] 

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

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

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

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

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

sage: SST[0].parent() is SST 

True 

""" 

# Iterates through with maximum entry as order 

i = 1 

n = sum(self.shape) 

while(True): 

if i != 1: 

for k in range(1, n+1): 

for c in integer_vectors_nk_fast_iter(n - k, i-1): 

c.append(k) 

for sst in SemistandardTableaux_shape_weight(self.shape, Composition(c)): 

yield self.element_class(self, sst) 

else: 

for sst in SemistandardTableaux_shape_weight(self.shape, Composition([n])): 

yield self.element_class(self, sst) 

i += 1 

 

 

class SemistandardTableaux_size(SemistandardTableaux): 

""" 

Semistandard tableaux of fixed size `n`. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` 

to ensure the options are properly parsed. 

""" 

def __init__(self, n, max_entry=None): 

r""" 

Initializes the class of semistandard tableaux of size ``n``. 

 

TESTS:: 

 

sage: SST = SemistandardTableaux(3); SST 

Semistandard tableaux of size 3 and maximum entry 3 

sage: type(SST) 

<class 'sage.combinat.tableau.SemistandardTableaux_size_with_category'> 

sage: TestSuite(SST).run() 

 

sage: SST = SemistandardTableaux(3, max_entry=6) 

sage: type(SST) 

<class 'sage.combinat.tableau.SemistandardTableaux_size_with_category'> 

sage: TestSuite(SST).run() 

""" 

 

if max_entry is None: 

max_entry = n 

super(SemistandardTableaux_size, self).__init__(max_entry = max_entry, 

category = FiniteEnumeratedSets()) 

self.size = n 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux(3)) # indirect doctest 

'Semistandard tableaux of size 3 and maximum entry 3' 

 

sage: repr(SemistandardTableaux(3, max_entry=6)) 

'Semistandard tableaux of size 3 and maximum entry 6' 

""" 

return "Semistandard tableaux of size %s and maximum entry %s"%(str(self.size), str(self.max_entry)) 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: [[1,2],[3,3]] in SemistandardTableaux(3) 

False 

sage: [[1,2],[3,3]] in SemistandardTableaux(4) 

True 

sage: [[1,2],[3,3]] in SemistandardTableaux(4, max_entry=2) 

False 

sage: SST = SemistandardTableaux(4) 

sage: all(sst in SST for sst in SST) 

True 

 

Check that :trac:`14145` is fixed:: 

 

sage: SST = SemistandardTableaux(4) 

sage: 1 in SST 

False 

""" 

if self.size==0: 

return x == [] 

 

return (SemistandardTableaux.__contains__(self, x) 

and sum(map(len,x)) == self.size 

and max(max(row) for row in x) <= self.max_entry) 

 

def random_element(self): 

r""" 

Generate a random :class:`SemistandardTableau` with uniform probability. 

 

The RSK algorithm gives a bijection between symmetric `k\times k` matrices 

of nonnegative integers that sum to `n` and semistandard tableaux with size `n` 

and maximum entry `k`. 

 

The number of `k\times k` symmetric matrices of nonnegative integers 

having sum of elements on the diagonal `i` and sum of elements above 

the diagonal `j` is `\binom{k + i - 1}{k - 1}\binom{\binom{k}{2} + j - 1}{\binom{k}{2} - 1}`. 

We first choose the sum of the elements on the diagonal randomly weighted by the 

number of matrices having that trace. We then create random integer vectors 

of length `k` having that sum and use them to generate a `k\times k` diagonal matrix. 

Then we take a random integer vector of length `\binom{k}{2}` summing to half the 

remainder and distribute it symmetrically to the remainder of the matrix. 

 

Applying RSK to the random symmetric matrix gives us a pair of identical 

:class:`SemistandardTableau` of which we choose the first. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux(6).random_element() # random 

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

sage: SemistandardTableaux(6, max_entry=7).random_element() # random 

[[2, 4, 4, 6, 6, 6]] 

""" 

from sage.rings.all import ZZ 

from sage.matrix.constructor import diagonal_matrix 

from sage.combinat.rsk import RSK 

kchoose2m1 = self.max_entry * (self.max_entry - 1) / 2 - 1 

km1 = self.max_entry - 1 

weights = [binomial(self.size - i + km1, km1) * binomial((i/2) + kchoose2m1, kchoose2m1) 

for i in range(0, self.size + 1, 2)] 

randpos = ZZ.random_element(sum(weights)) 

tot = weights[0] 

pos = 0 

while randpos >= tot: 

pos += 1 

tot += weights[pos] 

# we now have pos elements over the diagonal and n - 2 * pos on it 

m = diagonal_matrix( list(IntegerVectors(self.size - 2 * pos, 

self.max_entry).random_element()) ) 

above_diagonal = list(IntegerVectors(pos, kchoose2m1 + 1).random_element()) 

index = 0 

for i in range(self.max_entry - 1): 

for j in range(i + 1, self.max_entry): 

m[i,j] = above_diagonal[index] 

m[j,i] = above_diagonal[index] 

index += 1 

return RSK(m)[0] 

 

def cardinality(self): 

""" 

Return the cardinality of ``self``. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux(3).cardinality() 

19 

sage: SemistandardTableaux(4).cardinality() 

116 

sage: SemistandardTableaux(4, max_entry=2).cardinality() 

9 

sage: SemistandardTableaux(4, max_entry=10).cardinality() 

4225 

sage: ns = list(range(1, 6)) 

sage: ssts = [ SemistandardTableaux(n) for n in ns ] 

sage: all(sst.cardinality() == len(sst.list()) for sst in ssts) 

True 

""" 

from sage.combinat.partition import Partitions 

c = 0 

for part in Partitions(self.size): 

c += SemistandardTableaux_shape(part, self.max_entry).cardinality() 

return c 

 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: [ t for t in SemistandardTableaux(2) ] 

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

sage: [ t for t in SemistandardTableaux(3) ] 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 1, 3]], 

[[1, 2, 2]], 

[[1, 2, 3]], 

[[1, 3, 3]], 

[[2, 2, 2]], 

[[2, 2, 3]], 

[[2, 3, 3]], 

[[3, 3, 3]], 

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

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

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

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

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

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

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

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

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

 

sage: [ t for t in SemistandardTableaux(3, max_entry=2) ] 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 2, 2]], 

[[2, 2, 2]], 

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

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

 

sage: sst = SemistandardTableaux(3) 

sage: sst[0].parent() is sst 

True 

""" 

from sage.combinat.partition import Partitions 

for part in Partitions(self.size): 

for sst in SemistandardTableaux_shape(part, self.max_entry): 

yield self.element_class(self, sst) 

 

class SemistandardTableaux_shape(SemistandardTableaux): 

""" 

Semistandard tableaux of fixed shape `p` with a given max entry. 

 

A semistandard tableau with max entry `i` is required to have all 

its entries less or equal to `i`. It is not required to actually 

contain an entry `i`. 

 

INPUT: 

 

- ``p`` -- A partition 

 

- ``max_entry`` -- The max entry; defaults to the size of ``p``. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, p, max_entry=None): 

r""" 

Initializes the class of semistandard tableaux of shape ``p``, with a 

given ``max_entry``. 

 

TESTS:: 

 

sage: SST = SemistandardTableaux([2,1]) 

sage: TestSuite(SST).run() 

 

sage: SST = SemistandardTableaux([2,1], max_entry=5) 

sage: TestSuite(SST).run() 

""" 

if max_entry is None: 

max_entry = sum(p) 

super(SemistandardTableaux_shape, self).__init__(max_entry = max_entry, 

category = FiniteEnumeratedSets()) 

self.shape = p 

 

def __iter__(self): 

""" 

An iterator for the semistandard tableaux of the specified shape 

with the specified max entry. 

 

EXAMPLES:: 

 

sage: [ t for t in SemistandardTableaux([3]) ] 

[[[1, 1, 1]], 

[[1, 1, 2]], 

[[1, 1, 3]], 

[[1, 2, 2]], 

[[1, 2, 3]], 

[[1, 3, 3]], 

[[2, 2, 2]], 

[[2, 2, 3]], 

[[2, 3, 3]], 

[[3, 3, 3]]] 

sage: [ t for t in SemistandardTableaux([2,1]) ] 

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

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

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

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

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

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

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

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

sage: [ t for t in SemistandardTableaux([1,1,1]) ] 

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

 

sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ] 

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

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

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

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

 

sage: sst = SemistandardTableaux([3]) 

sage: sst[0].parent() is sst 

True 

""" 

for c in integer_vectors_nk_fast_iter(sum(self.shape), self.max_entry): 

for sst in SemistandardTableaux_shape_weight(self.shape, Composition(c)): 

yield self.element_class(self, sst) 

 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: SST = SemistandardTableaux([2,1]) 

sage: all(sst in SST for sst in SST) 

True 

sage: len(filter(lambda x: x in SST, SemistandardTableaux(3))) 

8 

sage: SST.cardinality() 

8 

 

sage: SST = SemistandardTableaux([2,1], max_entry=4) 

sage: all(sst in SST for sst in SST) 

True 

sage: SST.cardinality() 

20 

""" 

return SemistandardTableaux.__contains__(self, x) and [len(_) for _ in x] == self.shape 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux([2,1])) # indirect doctest 

'Semistandard tableaux of shape [2, 1] and maximum entry 3' 

 

sage: repr(SemistandardTableaux([2,1], max_entry=5)) 

'Semistandard tableaux of shape [2, 1] and maximum entry 5' 

""" 

return "Semistandard tableaux of shape %s and maximum entry %s" %(str(self.shape), str(self.max_entry)) 

 

def random_element(self): 

""" 

Return a uniformly distributed random tableau of the given ``shape`` and ``max_entry``. 

 

Uses the algorithm from [Krat99]_ based on the Novelli-Pak-Stoyanovskii bijection 

 

EXAMPLES:: 

 

sage: SemistandardTableaux([2, 2, 1, 1]).random_element() 

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

sage: SemistandardTableaux([2, 2, 1, 1], max_entry=7).random_element() 

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

 

 

REFERENCES: 

 

.. [Krat99] \C. Krattenthaler, 

*Another Involution Principle-Free Bijective Proof of Stanley's Hook Content Formula*, 

Journal of Combinatorial Theory, Series A vol 88 Issue 1 (1999), 66-92, 

http://www.sciencedirect.com/science/article/pii/0012365X9290368P 

""" 

from sage.misc.prandom import randint 

from sage.combinat.partition import Partition 

with_sentinels = [max(i,j) for i,j in zip([0]+list(self.shape), [k+1 for k in self.shape]+[0])] 

t = [[self.max_entry+1]*i for i in with_sentinels] 

for i,l in enumerate(self.shape): 

for j in range(l): 

content = j - i 

t[i][j] = randint(1 - content, self.max_entry) 

conj = Partition(self.shape).conjugate() 

for i in range(len(conj) - 1, -1, -1): 

for j in range(conj[i] - 1, -1, -1): 

row = j 

col = i 

s = t[row][col] 

x = t[row][col + 1] 

y = t[row + 1][col] 

while s > x or s >= y: 

if x + 1 < y: 

t[row][col] = x + 1 

t[row][col + 1] = s 

col += 1 

else: 

t[row][col] = y - 1 

t[row + 1][col] = s 

row += 1 

x = t[row][col + 1] 

y = t[row + 1][col] 

return SemistandardTableau([l[:c] for l,c in zip(t, self.shape)]) 

 

def cardinality(self, algorithm='hook'): 

r""" 

Return the cardinality of ``self``. 

 

INPUT: 

 

- ``algorithm`` -- (default: ``'hook'``) any one of the following: 

 

- ``'hook'`` -- use Stanley's hook length formula 

 

- ``'sum'`` -- sum over the compositions of ``max_entry`` the 

number of semistandard tableau with ``shape`` and given 

weight vector 

 

This is computed using *Stanley's hook length formula*: 

 

.. MATH:: 

 

f_{\lambda} = \prod_{u\in\lambda} \frac{n+c(u)}{h(u)}. 

 

where `n` is the ``max_entry``, `c(u)` is the content of `u`, 

and `h(u)` is the hook length of `u`. 

See [Sta-EC2]_ Corollary 7.21.4. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux([2,1]).cardinality() 

8 

sage: SemistandardTableaux([2,2,1]).cardinality() 

75 

sage: SymmetricFunctions(QQ).schur()([2,2,1]).expand(5)(1,1,1,1,1) # cross check 

75 

sage: SemistandardTableaux([5]).cardinality() 

126 

sage: SemistandardTableaux([3,2,1]).cardinality() 

896 

sage: SemistandardTableaux([3,2,1], max_entry=7).cardinality() 

2352 

sage: SemistandardTableaux([6,5,4,3,2,1], max_entry=30).cardinality() 

208361017592001331200 

sage: ssts = [SemistandardTableaux(p, max_entry=6) for p in Partitions(5)] 

sage: all(sst.cardinality() == sst.cardinality(algorithm='sum') 

....: for sst in ssts) 

True 

""" 

if algorithm == 'hook': 

conj = self.shape.conjugate() 

num = Integer(1) 

den = Integer(1) 

for i,l in enumerate(self.shape): 

for j in range(l): 

num *= self.max_entry + j - i 

den *= l + conj[j] - i - j - 1 

return Integer(num / den) 

elif algorithm == 'sum': 

c = 0 

for comp in integer_vectors_nk_fast_iter(sum(self.shape), self.max_entry): 

c += SemistandardTableaux_shape_weight(self.shape, Composition(comp)).cardinality() 

return c 

raise ValueError("unknown algorithm {}".format(algorithm)) 

 

class SemistandardTableaux_shape_weight(SemistandardTableaux_shape): 

r""" 

Semistandard tableaux of fixed shape `p` and weight `\mu`. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, p, mu): 

r""" 

Initializes the class of all semistandard tableaux of shape ``p`` and 

weight ``mu``. 

 

TESTS:: 

 

sage: SST = SemistandardTableaux([2,1], [2,1]) 

sage: TestSuite(SST).run() 

""" 

super(SemistandardTableaux_shape_weight, self).__init__(p, len(mu)) 

self.weight = mu 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux([2,1],[2,1])) # indirect doctest 

'Semistandard tableaux of shape [2, 1] and weight [2, 1]' 

""" 

return "Semistandard tableaux of shape %s and weight %s"%(self.shape, self.weight) 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: SST = SemistandardTableaux([2,1], [2,1]) 

sage: all(sst in SST for sst in SST) 

True 

sage: len(filter(lambda x: x in SST, SemistandardTableaux(3))) 

1 

sage: SST.cardinality() 

1 

""" 

if x not in SemistandardTableaux_shape(self.shape, self.max_entry): 

return False 

n = sum(self.shape) 

 

if n == 0 and len(x) == 0: 

return True 

 

content = {} 

for row in x: 

for i in row: 

content[i] = content.get(i, 0) + 1 

content_list = [0]*int(max(content)) 

 

for key in content: 

content_list[key-1] = content[key] 

 

if content_list != self.weight: 

return False 

 

return True 

 

 

def cardinality(self): 

""" 

Returns the number of semistandard tableaux of the given shape and 

weight, as computed by ``kostka_number`` function of symmetrica. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux([2,2], [2, 1, 1]).cardinality() 

1 

sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).cardinality() 

1 

sage: SemistandardTableaux([2,2,2], [2, 2, 2]).cardinality() 

1 

sage: SemistandardTableaux([3,2,1], [2, 2, 2]).cardinality() 

2 

""" 

return symmetrica.kostka_number(self.shape,self.weight) 

 

def __iter__(self): 

""" 

TESTS:: 

 

sage: sst = SemistandardTableaux([3,1],[2,1,1]) 

sage: [sst[i] for i in range(2)] 

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

sage: sst[0].parent() is sst 

True 

""" 

for t in symmetrica.kostka_tab(self.shape, self.weight): 

yield self.element_class(self, t) 

 

 

def list(self): 

""" 

Return a list of all semistandard tableaux in ``self`` generated 

by symmetrica. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux([2,2], [2, 1, 1]).list() 

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

sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).list() 

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

sage: SemistandardTableaux([2,2,2], [2, 2, 2]).list() 

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

sage: SemistandardTableaux([3,2,1], [2, 2, 2]).list() 

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

""" 

return symmetrica.kostka_tab(self.shape, self.weight) 

 

 

class SemistandardTableaux_size_weight(SemistandardTableaux): 

r""" 

Semistandard tableaux of fixed size `n` and weight `\mu`. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, n, mu): 

r""" 

Initializes the class of semistandard tableaux of size ``n`` and 

weight ``mu``. 

 

TESTS:: 

 

sage: SST = SemistandardTableaux(3, [2,1]) 

sage: TestSuite(SST).run() 

""" 

super(SemistandardTableaux_size_weight, self).__init__(max_entry=len(mu), 

category = FiniteEnumeratedSets()) 

self.size = n 

self.weight = mu 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(SemistandardTableaux(3, [2,1])) # indirect doctest 

'Semistandard tableaux of size 3 and weight [2, 1]' 

""" 

return "Semistandard tableaux of size %s and weight %s"%(self.size, self.weight) 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: [ t for t in SemistandardTableaux(3, [2,1]) ] 

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

sage: [ t for t in SemistandardTableaux(4, [2,2]) ] 

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

sage: sst = SemistandardTableaux(4, [2,2]) 

sage: sst[0].parent() is sst 

True 

""" 

from sage.combinat.partition import Partitions 

for p in Partitions(self.size): 

for sst in SemistandardTableaux_shape_weight(p, self.weight): 

yield self.element_class(self, sst) 

 

 

def cardinality(self): 

""" 

Return the cardinality of ``self``. 

 

EXAMPLES:: 

 

sage: SemistandardTableaux(3, [2,1]).cardinality() 

2 

sage: SemistandardTableaux(4, [2,2]).cardinality() 

3 

""" 

from sage.combinat.partition import Partitions 

c = 0 

for p in Partitions(self.size): 

c += SemistandardTableaux_shape_weight(p, self.weight).cardinality() 

return c 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: SST = SemistandardTableaux(6, [2,2,2]) 

sage: all(sst in SST for sst in SST) 

True 

sage: all(sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])) 

True 

""" 

from sage.combinat.partition import Partition 

return x in SemistandardTableaux_shape_weight(Partition( 

[len(_) for _ in x]), self.weight) 

 

######################## 

# Standard Tableaux # 

######################## 

 

class StandardTableaux(SemistandardTableaux): 

""" 

A factory for the various classes of standard tableaux. 

 

INPUT: 

 

- Either a non-negative integer (possibly specified with the keyword ``n``) 

or a partition. 

 

OUTPUT: 

 

- With no argument, the class of all standard tableaux 

 

- With a non-negative integer argument, ``n``, the class of all standard 

tableaux of size ``n`` 

 

- With a partition argument, the class of all standard tableaux of that 

shape. 

 

A standard tableau is a semistandard tableaux which contains each of the 

entries from 1 to ``n`` exactly once. 

 

All classes of standard tableaux are iterable. 

 

EXAMPLES:: 

 

sage: ST = StandardTableaux(3); ST 

Standard tableaux of size 3 

sage: ST.first() 

[[1, 2, 3]] 

sage: ST.last() 

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

sage: ST.cardinality() 

4 

sage: ST.list() 

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

 

.. SEEALSO:: 

 

- :class:`Tableaux` 

- :class:`Tableau` 

- :class:`SemistandardTableaux` 

- :class:`SemistandardTableau` 

- :class:`StandardTableau` 

- :class:`StandardSkewTableaux` 

 

TESTS:: 

 

sage: StandardTableaux()([]) 

[] 

sage: ST = StandardTableaux([2,2]); ST 

Standard tableaux of shape [2, 2] 

sage: ST.first() 

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

sage: ST.last() 

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

sage: ST.cardinality() 

2 

sage: ST.list() 

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

sage: StandardTableau([[1,2,3],[4,5]]).residue_sequence(3).standard_tableaux() 

Standard tableaux with 3-residue sequence (0,1,2,2,0) and multicharge (0) 

""" 

@staticmethod 

def __classcall_private__(cls, *args, **kwargs): 

r""" 

This is a factory class which returns the appropriate parent based on 

arguments. See the documentation for :class:`StandardTableaux` for 

more information. 

 

TESTS:: 

 

sage: StandardTableaux() 

Standard tableaux 

sage: StandardTableaux(3) 

Standard tableaux of size 3 

sage: StandardTableaux([2,1]) 

Standard tableaux of shape [2, 1] 

sage: StandardTableaux(0) 

Standard tableaux of size 0 

 

sage: StandardTableaux(-1) 

Traceback (most recent call last): 

... 

ValueError: The argument must be a non-negative integer or a partition. 

sage: StandardTableaux([[1]]) 

Traceback (most recent call last): 

... 

ValueError: The argument must be a non-negative integer or a partition. 

""" 

from sage.combinat.partition import _Partitions, Partition 

from sage.combinat.skew_partition import SkewPartitions 

 

if args: 

n = args[0] 

elif 'n' in kwargs: 

n = kwargs[n] 

else: 

n = None 

 

if n is None: 

return StandardTableaux_all() 

 

elif n in _Partitions: 

return StandardTableaux_shape(Partition(n)) 

 

elif n in SkewPartitions(): 

from sage.combinat.skew_tableau import StandardSkewTableaux 

return StandardSkewTableaux(n) 

 

if not isinstance(n, (int, Integer)) or n < 0: 

raise ValueError( "The argument must be a non-negative integer or a partition." ) 

 

return StandardTableaux_size(n) 

 

Element = StandardTableau 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: [[1,1],[2,3]] in StandardTableaux() 

False 

sage: [[1,2],[3,4]] in StandardTableaux() 

True 

sage: [[1,3],[2,4]] in StandardTableaux() 

True 

sage: [[1,3],[2,5]] in StandardTableaux() 

False 

sage: [] in StandardTableaux() 

True 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in StandardTableaux() 

False 

""" 

if isinstance(x, StandardTableau): 

return True 

elif Tableaux.__contains__(self, x): 

flatx = sorted(sum((list(row) for row in x),[])) 

return flatx == list(range(1,len(flatx)+1)) and (len(x)==0 or 

(all(row[i]<row[i+1] for row in x for i in range(len(row)-1)) and 

all(x[r][c]<x[r+1][c] for r in range(len(x)-1) 

for c in range(len(x[r+1])) ) 

)) 

return False 

 

class StandardTableaux_all(StandardTableaux, DisjointUnionEnumeratedSets): 

""" 

All standard tableaux. 

""" 

def __init__(self): 

r""" 

Initializes the class of all standard tableaux. 

 

TESTS:: 

 

sage: ST = StandardTableaux() 

sage: TestSuite(ST).run() 

""" 

DisjointUnionEnumeratedSets.__init__( self, 

Family(NonNegativeIntegers(), StandardTableaux_size), 

facade=True, keepkey = False) 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(StandardTableaux()) # indirect doctest 

'Standard tableaux' 

""" 

return "Standard tableaux" 

 

 

class StandardTableaux_size(StandardTableaux): 

""" 

Standard tableaux of fixed size `n`. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`StandardTableaux` to ensure 

the options are properly parsed. 

""" 

def __init__(self, n): 

r""" 

Initializes the class of all standard tableaux of size ``n``. 

 

TESTS:: 

 

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

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

""" 

super(StandardTableaux_size, self).__init__( 

category = FiniteEnumeratedSets()) 

self.size = Integer(n) 

 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(StandardTableaux(3)) # indirect doctest 

'Standard tableaux of size 3' 

""" 

return "Standard tableaux of size %s"%self.size 

 

def __contains__(self, x): 

""" 

TESTS:: 

 

sage: ST3 = StandardTableaux(3) 

sage: all(st in ST3 for st in ST3) 

True 

sage: ST4 = StandardTableaux(4) 

sage: filter(lambda x: x in ST3, ST4) 

[] 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in StandardTableaux(4) 

False 

""" 

return StandardTableaux.__contains__(self, x) and sum(map(len, x)) == self.size 

 

def __iter__(self): 

""" 

EXAMPLES:: 

 

sage: [ t for t in StandardTableaux(1) ] 

[[[1]]] 

sage: [ t for t in StandardTableaux(2) ] 

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

sage: [ t for t in StandardTableaux(3) ] 

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

sage: [ t for t in StandardTableaux(4) ] 

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

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

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

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

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

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

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

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

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

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

sage: ST4 = StandardTableaux(4) 

sage: ST4[0].parent() is ST4 

True 

""" 

from sage.combinat.partition import Partitions 

for p in Partitions(self.size): 

for st in StandardTableaux(p): 

yield self.element_class(self, st) 

 

def cardinality(self): 

r""" 

Return the number of all standard tableaux of size ``n``. 

 

The number of standard tableaux of size `n` is equal to the 

number of involutions in the symmetric group `S_n`. 

This is a consequence of the symmetry of the RSK 

correspondence, that if `\sigma \mapsto (P, Q)`, then 

`\sigma^{-1} \mapsto (Q, P)`. For more information, see 

:wikipedia:`Robinson-Schensted-Knuth_correspondence#Symmetry`. 

 

ALGORITHM: 

 

The algorithm uses the fact that standard tableaux of size 

``n`` are in bijection with the involutions of size ``n``, 

(see page 41 in section 4.1 of [Ful1997]_). For each number of 

fixed points, you count the number of ways to choose those 

fixed points multiplied by the number of perfect matchings on 

the remaining values. 

 

REFERENCES: 

 

.. [Ful1997] William Fulton, 

*Young Tableaux*. 

Cambridge University Press, 1997. 

 

EXAMPLES:: 

 

sage: StandardTableaux(3).cardinality() 

4 

sage: ns = [1,2,3,4,5,6] 

sage: sts = [StandardTableaux(n) for n in ns] 

sage: all(st.cardinality() == len(st.list()) for st in sts) 

True 

sage: StandardTableaux(50).cardinality() 

27886995605342342839104615869259776 

 

TESTS:: 

 

sage: def cardinality_using_hook_formula(n): 

....: c = 0 

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

....: c += StandardTableaux(p).cardinality() 

....: return c 

sage: all(cardinality_using_hook_formula(i) == StandardTableaux(i).cardinality() for i in range(10)) 

True 

""" 

tableaux_number = self.size % 2 # identity involution 

fixed_point_numbers = list(range(tableaux_number, self.size + 1 - tableaux_number, 2)) 

 

# number of involutions of size "size" (number of ways to 

# choose "fixed_point_number" out of "size" elements * 

# number of involutions without fixed point of size 

# "size" - "fixed_point_number") 

for fixed_point_number in fixed_point_numbers: 

tableaux_number += (self.size.binomial(fixed_point_number) * 

prod(range(1, self.size - fixed_point_number, 2))) 

 

return tableaux_number 

 

def random_element(self): 

r""" 

Return a random ``StandardTableau`` with uniform probability. 

 

This algorithm uses the fact that the Robinson-Schensted 

correspondence returns a pair of identical standard Young 

tableaux (SYTs) if and only if the permutation was an involution. 

Thus, generating a random SYT is equivalent to generating a 

random involution. 

 

To generate an involution, we first need to choose its number of 

fixed points `k` (if the size of the involution is even, the 

number of fixed points will be even, and if the size is odd, the 

number of fixed points will be odd). To do this, we choose a 

random integer `r` between 0 and the number `N` of all 

involutions of size `n`. We then decompose the interval 

`\{ 1, 2, \ldots, N \}` into subintervals whose lengths are the 

numbers of involutions of size `n` with respectively `0`, `1`, 

`\ldots`, `\left \lfloor N/2 \right \rfloor` fixed points. The 

interval in which our random integer `r` lies then decides how 

many fixed points our random involution will have. We then 

place those fixed points randomly and then compute a perfect 

matching (an involution without fixed points) on the remaining 

values. 

 

EXAMPLES:: 

 

sage: StandardTableaux(5).random_element() # random 

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

sage: StandardTableaux(0).random_element() 

[] 

sage: StandardTableaux(1).random_element() 

[[1]] 

 

TESTS:: 

 

sage: all(StandardTableaux(10).random_element() in StandardTableaux(10) for i in range(20)) 

True 

""" 

from sage.misc.prandom import randrange 

from sage.misc.prandom import sample 

from sage.combinat.perfect_matching import PerfectMatchings 

from sage.combinat.permutation import from_cycles 

# We compute the number of involutions of size ``size``. 

involution_index = randrange(0, StandardTableaux(self.size).cardinality()) 

# ``involution_index`` is our random integer `r`. 

partial_sum = 0 

fixed_point_number = self.size % 2 

# ``fixed_point_number`` will become `k`. 

while True: 

# We add the number of involutions with ``fixed_point_number`` 

# fixed points. 

partial_sum += binomial(self.size, fixed_point_number) * \ 

prod(range(1, self.size - fixed_point_number , 2)) 

# If the partial sum is greater than the involution index, 

# then the random involution that we want to generate has 

# ``fixed_point_number`` fixed points. 

if partial_sum > involution_index: 

break 

fixed_point_number += 2 

# We generate a subset of size "fixed_point_number" of the set {1, 

# ..., size}. 

fixed_point_positions = set(sample(range(1, self.size + 1), fixed_point_number)) 

# We generate a list of tuples which will form the cycle 

# decomposition of our random involution. This list contains 

# singletons (corresponding to the fixed points of the 

# involution) and pairs (forming a perfect matching on the 

# remaining values). 

permutation_cycle_rep = [(fixed_point,) for fixed_point in fixed_point_positions] + \ 

list(PerfectMatchings(set(range(1, self.size + 1)) - set(fixed_point_positions)).random_element()) 

return from_cycles(self.size, permutation_cycle_rep).robinson_schensted()[0] 

 

 

class StandardTableaux_shape(StandardTableaux): 

""" 

Semistandard tableaux of a fixed shape `p`. 

 

.. WARNING:: 

 

Input is not checked; please use :class:`SemistandardTableaux` to 

ensure the options are properly parsed. 

""" 

def __init__(self, p): 

r""" 

Initializes the class of all semistandard tableaux of a given shape. 

 

TESTS:: 

 

sage: TestSuite( StandardTableaux([2,1,1]) ).run() 

""" 

from sage.combinat.partition import Partition 

super(StandardTableaux_shape, self).__init__(category = FiniteEnumeratedSets()) 

self.shape = Partition(p) 

 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: ST = StandardTableaux([2,1,1]) 

sage: all(st in ST for st in ST) 

True 

sage: len(filter(lambda x: x in ST, StandardTableaux(4))) 

3 

sage: ST.cardinality() 

3 

 

Check that :trac:`14145` is fixed:: 

 

sage: 1 in StandardTableaux([2,1,1]) 

False 

""" 

return StandardTableaux.__contains__(self, x) and [len(_) for _ in x] == self.shape 

 

def _repr_(self): 

""" 

TESTS:: 

 

sage: repr(StandardTableaux([2,1,1])) # indirect doctest 

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

""" 

return "Standard tableaux of shape %s"%str(self.shape) 

 

def cardinality(self): 

r""" 

Return the number of standard Young tableaux of this shape. 

 

This method uses the so-called *hook length formula*, a formula 

for the number of Young tableaux associated with a given 

partition. The formula says the following: Let `\lambda` be a 

partition. For each cell `c` of the Young diagram of `\lambda`, 

let the *hook length* of `c` be defined as `1` plus the number of 

cells horizontally to the right of `c` plus the number of cells 

vertically below `c`. The number of standard Young tableaux of 

shape `\lambda` is then `n!` divided by the product of the hook 

lengths of the shape of `\lambda`, where `n = |\lambda|`. 

 

For example, consider the partition ``[3,2,1]`` of ``6`` with 

Ferrers diagram:: 

 

# # # 

# # 

# 

 

When we fill in the cells with their respective hook lengths, we 

obtain:: 

 

5 3 1 

3 1 

1 

 

The hook length formula returns 

 

.. MATH:: 

 

\frac{6!}{5 \cdot 3 \cdot 1 \cdot 3 \cdot 1 \cdot 1} = 16. 

 

EXAMPLES:: 

 

sage: StandardTableaux([3,2,1]).cardinality() 

16 

sage: StandardTableaux([2,2]).cardinality() 

2 

sage: StandardTableaux([5]).cardinality() 

1 

sage: StandardTableaux([6,5,5,3]).cardinality() 

6651216 

sage: StandardTableaux([]).cardinality() 

1 

 

REFERENCES: 

 

- http://mathworld.wolfram.com/HookLengthFormula.html 

""" 

pi = self.shape 

 

number = factorial(sum(pi)) 

hook = pi.hook_lengths() 

 

for row in hook: 

for col in row: 

#Divide the hook length by the entry 

number /= col 

 

return Integer(number) 

 

def __iter__(self): 

r""" 

An iterator for the standard Young tableaux associated to the 

shape `p` of ``self``. 

 

EXAMPLES:: 

 

sage: [t for t in StandardTableaux([2,2])] 

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

sage: [t for t in StandardTableaux([3,2])] 

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

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

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

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

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

sage: st = StandardTableaux([2,1]) 

sage: st[0].parent() is st 

True 

""" 

 

pi = self.shape 

#Set the initial tableau by filling it in going down the columns 

tableau = [[None]*n for n in pi] 

size = sum(pi) 

row = 0 

col = 0 

for i in range(size): 

tableau[row][col] = i+1 

 

#If we can move down, then do it; 

#otherwise, move to the next column over 

if ( row + 1 < len(pi) and col < pi[row+1]): 

row += 1 

else: 

row = 0 

col += 1 

 

yield self.element_class(self, tableau) 

 

# iterate until we reach the last tableau which is 

# filled with the row indices. 

last_tableau = sum([[row]*l for (row,l) in enumerate(pi)], []) 

 

#Convert the tableau to "vector format" 

#tableau_vector[i] is the row that number i 

#is in 

tableau_vector = [None]*size 

for row in range(len(pi)): 

for col in range(pi[row]): 

tableau_vector[tableau[row][col]-1] = row 

 

while tableau_vector!=last_tableau: 

#Locate the smallest integer j such that j is not 

#in the lowest corner of the subtableau T_j formed by 

#1,...,j. This happens to be first j such that 

#tableau_vector[j]<tableau_vector[j-1]. 

#l will correspond to the shape of T_j 

l = [0]*size 

l[0] = 1 

j = 0 

for i in range(1,size): 

l[tableau_vector[i]] += 1 

if ( tableau_vector[i] < tableau_vector[i-1] ): 

j = i 

break 

 

#Find the last nonzero row of l and store it in k 

i = size - 1 

while ( l[i] == 0 ): 

i -= 1 

k = i 

 

#Find a new row for the letter j (next lowest corner) 

t = l[ 1 + tableau_vector[j] ] 

i = k 

while ( l[i] != t ): 

i -= 1 

 

#Move the letter j to row i 

tableau_vector[j] = i 

l[i] -= 1 

 

#Fill in the columns of T_j using 1,...,j-1 in increasing order 

m = 0 

while ( m < j ): 

r = 0 

while ( l[r] != 0 ): 

tableau_vector[m] = r 

l[r] -= 1 

m += 1 

r += 1 

 

#Convert the tableau vector back to the regular tableau 

#format 

row_count= [0]*len(pi) 

tableau = [[None]*n for n in pi] 

 

for i in range(size): 

tableau[tableau_vector[i]][row_count[tableau_vector[i]]] = i+1 

row_count[tableau_vector[i]] += 1 

 

yield self.element_class(self, tableau) 

 

return 

 

 

def list(self): 

r""" 

Return a list of the standard Young tableaux of the specified shape. 

 

EXAMPLES:: 

 

sage: StandardTableaux([2,2]).list() 

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

sage: StandardTableaux([5]).list() 

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

sage: StandardTableaux([3,2,1]).list() 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

""" 

return [y for y in self] 

 

 

def random_element(self): 

""" 

Return a random standard tableau of the given shape using the 

Greene-Nijenhuis-Wilf Algorithm. 

 

EXAMPLES:: 

 

sage: StandardTableaux([2,2]).random_element() 

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

sage: StandardTableaux([]).random_element() 

[] 

""" 

 

p = self.shape 

 

t = [[None]*n for n in p] 

 

 

#Get the cells in the 

cells = [] 

for i in range(len(p)): 

for j in range(p[i]): 

cells.append((i,j)) 

 

m = sum(p) 

while m > 0: 

 

#Choose a cell at random 

cell = random.choice(cells) 

 

 

#Find a corner 

inner_corners = p.corners() 

while cell not in inner_corners: 

hooks = [] 

for k in range(cell[1], p[cell[0]]): 

hooks.append((cell[0], k)) 

for k in range(cell[0], len(p)): 

if p[k] > cell[1]: 

hooks.append((k, cell[1])) 

 

cell = random.choice(hooks) 

 

 

#Assign m to cell 

t[cell[0]][cell[1]] = m 

 

p = p.remove_cell(cell[0]) 

 

cells.remove(cell) 

 

m -= 1 

 

return self.element_class(self, t) 

 

 

########################## 

# Symmetric group action # 

########################## 

def unmatched_places(w, open, close): 

""" 

EXAMPLES:: 

 

sage: from sage.combinat.tableau import unmatched_places 

sage: unmatched_places([2,2,2,1,1,1],2,1) 

([], []) 

sage: unmatched_places([1,1,1,2,2,2],2,1) 

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

sage: unmatched_places([], 2, 1) 

([], []) 

sage: unmatched_places([1,2,4,6,2,1,5,3],2,1) 

([0], [1]) 

sage: unmatched_places([2,2,1,2,4,6,2,1,5,3], 2, 1) 

([], [0, 3]) 

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

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

""" 

lw = len(w) 

places_open = [] 

places_close = [] 

for i in range(lw): 

letter = w[i] 

if letter == open: 

places_open.append(i) 

elif letter == close: 

if places_open == []: 

places_close.append(i) 

else: 

places_open.pop() 

return places_close, places_open 

 

 

def symmetric_group_action_on_values(word, perm): 

""" 

EXAMPLES:: 

 

sage: from sage.combinat.tableau import symmetric_group_action_on_values 

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

[1, 1, 1] 

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

[2, 2, 2] 

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

[2, 2, 1] 

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

[1, 1, 1] 

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

[2, 1, 1] 

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

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

sage: symmetric_group_action_on_values([2,1,1],[2,1]) 

[2, 1, 2] 

sage: symmetric_group_action_on_values([2,2,1],[2,1]) 

[1, 2, 1] 

sage: symmetric_group_action_on_values([1,2,1],[2,1]) 

[2, 2, 1] 

""" 

w = list(word) 

ts = permutation.Permutations()(perm).reduced_word() 

for r in reversed(ts): 

l = r + 1 

places_r, places_l = unmatched_places(w, l, r) 

 

#Now change the number of l's and r's in the new word 

nbl = len(places_l) 

nbr = len(places_r) 

ma = max(nbl, nbr) 

dif = ma - min(nbl, nbr) 

if ma == nbl: 

for i in places_l[:dif]: 

w[i] = r 

else: 

for i in places_r[nbr-dif:ma]: 

w[i] = l 

return w 

 

 

 

class Tableau_class(Tableau): 

""" 

This exists solely for unpickling ``Tableau_class`` objects. 

""" 

def __setstate__(self, state): 

r""" 

Unpickle old ``Tableau_class`` objects. 

 

TESTS:: 

 

sage: loads(b'x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+IL\xcaIM,\xe5\n\x81\xd0\xf1\xc99\x89\xc5\xc5\\\x85\x8c\x9a\x8d\x85L\xb5\x85\xcc\x1a\xa1\xac\xf1\x19\x89\xc5\x19\x85,~@VNfqI!kl![l!;\xc4\x9c\xa2\xcc\xbc\xf4b\xbd\xcc\xbc\x92\xd4\xf4\xd4"\xae\xdc\xc4\xec\xd4x\x18\xa7\x90#\x94\xd1\xb05\xa8\x9031\xb14I\x0f\x00\xf6\xae)7') 

[[1]] 

sage: loads(dumps( Tableau([[1]]) )) 

[[1]] 

""" 

self.__class__ = Tableau 

self.__init__(Tableaux(), state['_list']) 

 

# October 2012: fixing outdated pickles which use classed being deprecated 

from sage.structure.sage_object import register_unpickle_override 

register_unpickle_override('sage.combinat.tableau', 'Tableau_class', Tableau_class) 

register_unpickle_override('sage.combinat.tableau', 'Tableaux_n', Tableaux_size) 

register_unpickle_override('sage.combinat.tableau', 'StandardTableaux_n', StandardTableaux_size) 

register_unpickle_override('sage.combinat.tableau', 'StandardTableaux_partition', StandardTableaux_shape) 

register_unpickle_override('sage.combinat.tableau', 'SemistandardTableaux_n', SemistandardTableaux_size) 

register_unpickle_override('sage.combinat.tableau', 'SemistandardTableaux_p', SemistandardTableaux_shape) 

register_unpickle_override('sage.combinat.tableau', 'SemistandardTableaux_nmu', SemistandardTableaux_size_weight) 

register_unpickle_override('sage.combinat.tableau', 'SemistandardTableaux_pmu', SemistandardTableaux_shape_weight) 

 

 

# Deprecations from trac:18555. July 2016 

from sage.misc.superseded import deprecated_function_alias 

Tableaux.global_options=deprecated_function_alias(18555, Tableaux.options)