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

r""" 

Quasisymmetric functions 

 

REFERENCES: 

 

.. [Ges] \I. Gessel, *Multipartite P-partitions and inner products of skew Schur 

functions*, Contemp. Math. **34** (1984), 289-301. 

http://people.brandeis.edu/~gessel/homepage/papers/multipartite.pdf 

 

.. [MR] \C. Malvenuto and C. Reutenauer, *Duality between quasi-symmetric 

functions and the Solomon descent algebra*, J. Algebra **177** (1995), 

no. 3, 967-982. http://www.mat.uniroma1.it/people/malvenuto/Duality.pdf 

 

.. [GriRei2014] Darij Grinberg, Victor Reiner, 

*Hopf algebras in combinatorics*, 

25 August 2015. :arxiv:`1409.8356v3`. 

 

.. [Mal1993] Claudia Malvenuto, *Produits et coproduits des fonctions 

quasi-symetriques et de l'algebre des descentes*, 

thesis, November 1993. 

http://www1.mat.uniroma1.it/people/malvenuto/Thesis.pdf 

 

.. [Haz2004] Michiel Hazewinkel, *Explicit polynomial generators for the 

ring of quasisymmetric functions over the integers*. 

:arxiv:`math/0410366v1` 

 

.. [Rad1979] David E. Radford, *A natural ring basis for the shuffle algebra 

and an application to group schemes*, J. Algebra **58** (1979), 432-454. 

 

.. [NCSF1] Israel Gelfand, D. Krob, Alain Lascoux, B. Leclerc, 

V. S. Retakh, J.-Y. Thibon, 

*Noncommutative symmetric functions*. 

:arxiv:`hep-th/9407124v1` 

 

.. [NCSF2] \D. Krob, B. Leclerc, J.-Y. Thibon, 

*Noncommutative symmetric functions II: Transformations of alphabets*. 

http://www-igm.univ-mlv.fr/~jyt/ARTICLES/NCSF2.ps 

 

.. [HLNT09] \F. Hivert, J.-G. Luque, J.-C. Novelli, J.-Y. Thibon, 

*The (1-E)-transform in combinatorial Hopf algebras*. 

:arxiv:`math/0912.0184v2` 

 

.. [LMvW13] Kurt Luoto, Stefan Mykytiuk and Stephanie van Willigenburg, 

*An introduction to quasisymmetric Schur functions -- Hopf algebras, 

quasisymmetric functions, and Young composition tableaux*, 

May 23, 2013, Springer. 

http://www.math.ubc.ca/%7Esteph/papers/QuasiSchurBook.pdf 

 

.. [BBSSZ2012] Chris Berg, Nantel Bergeron, Franco Saliola, 

Luis Serrano, Mike Zabrocki, 

*A lift of the Schur and Hall-Littlewood bases to 

non-commutative symmetric functions*, 

:arxiv:`1208.5191v3`. 

 

.. [Hoff2015] Michael Hoffman. 

*Quasi-symmetric functions and mod* `p` *multiple harmonic sums*. 

Kyushu J. Math. **69** (2015), pp. 345-366. 

:doi:`10.2206/kyushujm.69.345`, :arxiv:`math/0401319v3`. 

 

.. [BDHMN2017] Cristina Ballantine, Zajj Daugherty, Angela Hicks, Sarah Mason, 

Elizabeth Niese. *Quasisymmetric power sums*. :arxiv:`1710.11613`. 

 

AUTHOR: 

 

- Jason Bandlow 

- Franco Saliola 

- Chris Berg 

- Darij Grinberg 

""" 

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

# Copyright (C) 2010 Jason Bandlow <jbandlow@gmail.com>, 

# 2012 Franco Saliola <saliola@gmail.com>, 

# 2012 Chris Berg <chrisjamesberg@gmail.com> 

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

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

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

 

from sage.misc.bindable_class import BindableClass 

from sage.categories.graded_hopf_algebras import GradedHopfAlgebras 

from sage.categories.rings import Rings 

from sage.categories.fields import Fields 

from sage.categories.realizations import Category_realization_of_parent 

from sage.structure.parent import Parent 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.matrix.constructor import matrix 

from sage.matrix.matrix_space import MatrixSpace 

from sage.combinat.permutation import Permutations 

from sage.combinat.composition import Composition, Compositions 

from sage.combinat.composition_tableau import CompositionTableaux 

from sage.combinat.partition import Partitions, _Partitions 

from sage.combinat.free_module import CombinatorialFreeModule 

from sage.combinat.sf.sf import SymmetricFunctions 

from sage.combinat.ncsf_qsym.generic_basis_code import BasesOfQSymOrNCSF 

from sage.combinat.ncsf_qsym.combinatorics import (number_of_fCT, number_of_SSRCT, 

compositions_order, coeff_pi, coeff_lp, coeff_sp, coeff_ell) 

from sage.combinat.ncsf_qsym.ncsf import NonCommutativeSymmetricFunctions 

from sage.combinat.words.word import Word 

from sage.misc.cachefunc import cached_method 

from sage.categories.morphism import SetMorphism 

from sage.categories.homset import Hom 

 

import six 

 

 

class QuasiSymmetricFunctions(UniqueRepresentation, Parent): 

r""" 

.. rubric:: The Hopf algebra of quasisymmetric functions. 

 

Let `R` be a commutative ring with unity. 

The `R`-algebra of quasi-symmetric functions may be realized as an 

`R`-subalgebra of the ring of power series in countably many 

variables `R[[x_1, x_2, x_3, \ldots]]`. It consists of those 

formal power series `p` which are degree-bounded (i. e., the degrees 

of all monomials occuring with nonzero coefficient in `p` are bounded 

from above, although the bound can depend on `p`) and satisfy the 

following condition: For every tuple `(a_1, a_2, \ldots, a_m)` of 

positive integers, the coefficient of the monomial 

`x_{i_1}^{a_1} x_{i_2}^{a_2} \cdots x_{i_m}^{a_m}` in `p` is the same 

for all strictly increasing sequences `(i_1 < i_2 < \cdots < i_m)` of 

positive integers. (In other words, the coefficient of a monomial in `p` 

depends only on the sequence of nonzero exponents in the monomial. If 

"sequence" were to be replaced by "multiset" here, we would obtain 

the definition of a symmetric function.) 

 

The `R`-algebra of quasi-symmetric functions is commonly called 

`\mathrm{QSym}_R` or occasionally just `\mathrm{QSym}` (when 

`R` is clear from the context or `\ZZ` or `\QQ`). It is graded by 

the total degree of the power series. Its homogeneous elements of degree 

`k` form a free `R`-submodule of rank equal to the number of 

compositions of `k` (that is, `2^{k-1}` if `k \geq 1`, else `1`). 

 

The two classical bases of `\mathrm{QSym}`, the monomial basis 

`(M_I)_I` and the fundamental basis `(F_I)_I`, are indexed by 

compositions `I = (I_1, I_2, \cdots, I_\ell )` and defined by the 

formulas: 

 

.. MATH:: 

 

M_I = \sum_{1 \leq i_1 < i_2 < \cdots < i_\ell} x_{i_1}^{I_1} 

x_{i_2}^{I_2} \cdots x_{i_\ell}^{I_\ell} 

 

and 

 

.. MATH:: 

 

F_I = \sum_{(j_1, j_2, \ldots, j_n)} x_{j_1} x_{j_2} \cdots 

x_{j_n} 

 

where in the second equation the sum runs over all weakly increasing 

`n`-tuples `(j_1, j_2, \ldots, j_n)` of positive integers 

(where `n` is the size of `I`) which increase strictly from `j_r` 

to `j_{r+1}` if `r` is a descent of the composition `I`. 

 

These bases are related by the formula 

 

`F_I = \sum_{J \leq I} M_J` 

 

where the inequality `J \leq I` indicates that `J` is finer than `I`. 

 

The `R`-algebra of quasi-symmetric functions is a Hopf algebra, 

with the coproduct satisfying 

 

.. MATH:: 

 

\Delta M_I = \sum_{k=0}^{\ell} M_{(I_1, I_2, \cdots, I_k)} \otimes 

M_{(I_{k+1}, I_{k+2}, \cdots , I_{\ell})} 

 

for every composition `I = (I_1, I_2, \cdots , I_\ell )`. 

 

It is possible to define an `R`-algebra of quasi-symmetric 

functions in a finite number of variables as well (but it is not 

a bialgebra). These quasi-symmetric functions are actual polynomials 

then, not just power series. 

 

Chapter 5 of [GriRei2014]_ and Section 11 of [HazWitt1]_ are devoted 

to quasi-symmetric functions, as are Malvenuto's thesis [Mal1993]_ 

and part of Chapter 7 of [Sta-EC2]_. 

 

.. rubric:: The implementation of the quasi-symmetric function Hopf algebra 

 

We realize the `R`-algebra of quasi-symmetric functions in Sage as 

a graded Hopf algebra with basis elements indexed by compositions:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QSym.category() 

Join of Category of hopf algebras over Rational Field 

and Category of graded algebras over Rational Field 

and Category of monoids with realizations 

and Category of coalgebras over Rational Field with realizations 

 

The most standard two bases for this `R`-algebra are the monomial and 

fundamental bases, and are accessible by the ``M()`` and ``F()`` methods:: 

 

sage: M = QSym.M() 

sage: F = QSym.F() 

sage: M(F[2,1,2]) 

M[1, 1, 1, 1, 1] + M[1, 1, 1, 2] + M[2, 1, 1, 1] + M[2, 1, 2] 

sage: F(M[2,1,2]) 

F[1, 1, 1, 1, 1] - F[1, 1, 1, 2] - F[2, 1, 1, 1] + F[2, 1, 2] 

 

The product on this space is commutative and is inherited from the product 

on the realization within the ring of power series:: 

 

sage: M[3]*M[1,1] == M[1,1]*M[3] 

True 

sage: M[3]*M[1,1] 

M[1, 1, 3] + M[1, 3, 1] + M[1, 4] + M[3, 1, 1] + M[4, 1] 

sage: F[3]*F[1,1] 

F[1, 1, 3] + F[1, 2, 2] + F[1, 3, 1] + F[1, 4] + F[2, 1, 2] 

+ F[2, 2, 1] + F[2, 3] + F[3, 1, 1] + F[3, 2] + F[4, 1] 

sage: M[3]*F[2] 

M[1, 1, 3] + M[1, 3, 1] + M[1, 4] + M[2, 3] + M[3, 1, 1] + M[3, 2] 

+ M[4, 1] + M[5] 

sage: F[2]*M[3] 

F[1, 1, 1, 2] - F[1, 2, 2] + F[2, 1, 1, 1] - F[2, 1, 2] - F[2, 2, 1] 

+ F[5] 

 

There is a coproduct on `\mathrm{QSym}` as well, which in the Monomial 

basis acts by cutting the composition into a left half and a right 

half. The coproduct is not co-commutative:: 

 

sage: M[1,3,1].coproduct() 

M[] # M[1, 3, 1] + M[1] # M[3, 1] + M[1, 3] # M[1] + M[1, 3, 1] # M[] 

sage: F[1,3,1].coproduct() 

F[] # F[1, 3, 1] + F[1] # F[3, 1] + F[1, 1] # F[2, 1] 

+ F[1, 2] # F[1, 1] + F[1, 3] # F[1] + F[1, 3, 1] # F[] 

 

.. rubric:: The duality pairing with non-commutative symmetric functions 

 

These two operations endow the quasi-symmetric functions 

`\mathrm{QSym}` with the structure of a Hopf algebra. It is the graded 

dual Hopf algebra of the non-commutative symmetric functions `NCSF`. 

Under this duality, the Monomial basis of `\mathrm{QSym}` is dual to 

the Complete basis of `NCSF`, and the Fundamental basis of 

`\mathrm{QSym}` is dual to the Ribbon basis of `NCSF` (see [MR]_). 

 

:: 

 

sage: S = M.dual(); S 

Non-Commutative Symmetric Functions over the Rational Field in the Complete basis 

sage: M[1,3,1].duality_pairing( S[1,3,1] ) 

1 

sage: M.duality_pairing_matrix( S, degree=4 ) 

[1 0 0 0 0 0 0 0] 

[0 1 0 0 0 0 0 0] 

[0 0 1 0 0 0 0 0] 

[0 0 0 1 0 0 0 0] 

[0 0 0 0 1 0 0 0] 

[0 0 0 0 0 1 0 0] 

[0 0 0 0 0 0 1 0] 

[0 0 0 0 0 0 0 1] 

sage: F.duality_pairing_matrix( S, degree=4 ) 

[1 0 0 0 0 0 0 0] 

[1 1 0 0 0 0 0 0] 

[1 0 1 0 0 0 0 0] 

[1 1 1 1 0 0 0 0] 

[1 0 0 0 1 0 0 0] 

[1 1 0 0 1 1 0 0] 

[1 0 1 0 1 0 1 0] 

[1 1 1 1 1 1 1 1] 

sage: NCSF = M.realization_of().dual() 

sage: R = NCSF.Ribbon() 

sage: F.duality_pairing_matrix( R, degree=4 ) 

[1 0 0 0 0 0 0 0] 

[0 1 0 0 0 0 0 0] 

[0 0 1 0 0 0 0 0] 

[0 0 0 1 0 0 0 0] 

[0 0 0 0 1 0 0 0] 

[0 0 0 0 0 1 0 0] 

[0 0 0 0 0 0 1 0] 

[0 0 0 0 0 0 0 1] 

sage: M.duality_pairing_matrix( R, degree=4 ) 

[ 1 0 0 0 0 0 0 0] 

[-1 1 0 0 0 0 0 0] 

[-1 0 1 0 0 0 0 0] 

[ 1 -1 -1 1 0 0 0 0] 

[-1 0 0 0 1 0 0 0] 

[ 1 -1 0 0 -1 1 0 0] 

[ 1 0 -1 0 -1 0 1 0] 

[-1 1 1 -1 1 -1 -1 1] 

 

Let `H` and `G` be elements of `\mathrm{QSym}`, and `h` an element of 

`NCSF`. Then, if we represent the duality pairing with the 

mathematical notation `[ \cdot, \cdot ]`, 

 

`[H G, h] = [H \otimes G, \Delta(h)]~.` 

 

For example, the coefficient of ``M[2,1,4,1]`` in ``M[1,3]*M[2,1,1]`` may be 

computed with the duality pairing:: 

 

sage: I, J = Composition([1,3]), Composition([2,1,1]) 

sage: (M[I]*M[J]).duality_pairing(S[2,1,4,1]) 

1 

 

And the coefficient of ``S[1,3] # S[2,1,1]`` in ``S[2,1,4,1].coproduct()`` is 

equal to this result:: 

 

sage: S[2,1,4,1].coproduct() 

S[] # S[2, 1, 4, 1] + ... + S[1, 3] # S[2, 1, 1] + ... + S[4, 1] # S[2, 1] 

 

The duality pairing on the tensor space is another way of getting this 

coefficient, but currently the method ``duality_pairing`` is not defined on 

the tensor squared space. However, we can extend this functionality by 

applying a linear morphism to the terms in the coproduct, as follows:: 

 

sage: X = S[2,1,4,1].coproduct() 

sage: def linear_morphism(x, y): 

....: return x.duality_pairing(M[1,3]) * y.duality_pairing(M[2,1,1]) 

sage: X.apply_multilinear_morphism(linear_morphism, codomain=ZZ) 

1 

 

Similarly, if `H` is an element of `\mathrm{QSym}` and `g` and `h` are 

elements of `NCSF`, then 

 

.. MATH:: 

 

[ H, g h ] = [ \Delta(H), g \otimes h ]. 

 

For example, the coefficient of ``R[2,3,1]`` in ``R[2,1]*R[2,1]`` is 

computed with the duality pairing by the following command:: 

 

sage: (R[2,1]*R[2,1]).duality_pairing(F[2,3,1]) 

1 

sage: R[2,1]*R[2,1] 

R[2, 1, 2, 1] + R[2, 3, 1] 

 

This coefficient should then be equal to the coefficient of 

``F[2,1] # F[2,1]`` in ``F[2,3,1].coproduct()``:: 

 

sage: F[2,3,1].coproduct() 

F[] # F[2, 3, 1] + ... + F[2, 1] # F[2, 1] + ... + F[2, 3, 1] # F[] 

 

This can also be computed by the duality pairing on the tensor space, 

as above:: 

 

sage: X = F[2,3,1].coproduct() 

sage: def linear_morphism(x, y): 

....: return x.duality_pairing(R[2,1]) * y.duality_pairing(R[2,1]) 

sage: X.apply_multilinear_morphism(linear_morphism, codomain=ZZ) 

1 

 

.. rubric:: The operation dual to multiplication by a non-commutative symmetric function 

 

Let `g \in NCSF` and consider the linear endomorphism of `NCSF` defined by 

left (respectively, right) multiplication by `g`. Since there is a duality 

between `\mathrm{QSym}` and `NCSF`, this linear transformation induces an 

operator `g^{\perp}` on `\mathrm{QSym}` satisfying 

 

.. MATH:: 

 

[ g^{\perp}(H), h ] = [ H, gh ]. 

 

for any non-commutative symmetric function `h`. 

 

This is implemented by the method 

:meth:`~sage.combinat.ncsf_qsym.generic_basis_code.BasesOfQSymOrNCSF.ElementMethods.skew_by`. 

Explicitly, if ``H`` is a quasi-symmetric function and ``g`` 

a non-commutative symmetric function, then ``H.skew_by(g)`` and 

``H.skew_by(g, side='right')`` are expressions that satisfy, 

for any non-commutative symmetric function ``h``, the following 

equalities:: 

 

H.skew_by(g).duality_pairing(h) == H.duality_pairing(g*h) 

H.skew_by(g, side='right').duality_pairing(h) == H.duality_pairing(h*g) 

 

For example, ``M[J].skew_by(S[I])`` is `0` unless the composition ``J`` 

begins with ``I`` and ``M(J).skew_by(S(I), side='right')`` is `0` unless 

the composition ``J`` ends with ``I``. For example:: 

 

sage: M[3,2,2].skew_by(S[3]) 

M[2, 2] 

sage: M[3,2,2].skew_by(S[2]) 

0 

sage: M[3,2,2].coproduct().apply_multilinear_morphism( lambda x,y: x.duality_pairing(S[3])*y ) 

M[2, 2] 

sage: M[3,2,2].skew_by(S[3], side='right') 

0 

sage: M[3,2,2].skew_by(S[2], side='right') 

M[3, 2] 

 

.. rubric:: The counit 

 

The counit is defined by sending all elements of positive degree to zero:: 

 

sage: M[3].degree(), M[3,1,2].degree(), M.one().degree() 

(3, 6, 0) 

sage: M[3].counit() 

0 

sage: M[3,1,2].counit() 

0 

sage: M.one().counit() 

1 

sage: (M[3] - 2*M[3,1,2] + 7).counit() 

7 

sage: (F[3] - 2*F[3,1,2] + 7).counit() 

7 

 

.. rubric:: The antipode 

 

The antipode sends the Fundamental basis element indexed by the 

composition `I` to `(-1)^{|I|}` times the Fundamental 

basis element indexed by the conjugate composition to `I` 

(where `|I|` stands for the size of `I`, that is, the sum of all 

entries of `I`). 

:: 

 

sage: F[3,2,2].antipode() 

-F[1, 2, 2, 1, 1] 

sage: Composition([3,2,2]).conjugate() 

[1, 2, 2, 1, 1] 

 

The antipodes of the Monomial quasisymmetric functions can also be 

computed easily: Every composition `I` satisfies 

 

.. MATH:: 

 

\omega(M_I) = (-1)^{\ell(I)} \sum M_J, 

 

where the sum ranges over all compositions `J` of `|I|` 

which are coarser than the reversed composition `I^r` of 

`I`. Here, `\ell(I)` denotes the length of the composition `I` 

(that is, the number of its parts). :: 

 

sage: M[3,2,1].antipode() 

-M[1, 2, 3] - M[1, 5] - M[3, 3] - M[6] 

sage: M[3,2,2].antipode() 

-M[2, 2, 3] - M[2, 5] - M[4, 3] - M[7] 

 

We demonstrate here the defining relation of the antipode:: 

 

sage: X = F[3,2,2].coproduct() 

sage: X.apply_multilinear_morphism(lambda x,y: x*y.antipode()) 

0 

sage: X.apply_multilinear_morphism(lambda x,y: x.antipode()*y) 

0 

 

.. rubric:: The relation with symmetric functions 

 

The quasi-symmetric functions are a ring which contain the 

symmetric functions as a subring. The Monomial quasi-symmetric 

functions are related to the monomial symmetric functions by 

 

.. MATH:: 

 

m_\lambda = \sum_{\operatorname{sort}(I) = \lambda} M_I 

 

(where `\operatorname{sort}(I)` denotes the result of sorting 

the entries of `I` in decreasing order). 

 

There are methods to test if an expression in the quasi-symmetric 

functions is a symmetric function and, if it is, send it to an 

expression in the symmetric functions:: 

 

sage: f = M[1,1,2] + M[1,2,1] 

sage: f.is_symmetric() 

False 

sage: g = M[3,1] + M[1,3] 

sage: g.is_symmetric() 

True 

sage: g.to_symmetric_function() 

m[3, 1] 

 

The expansion of the Schur function in terms of the Fundamental quasi-symmetric 

functions is due to [Ges]_. There is one term in the expansion for each standard 

tableau of shape equal to the partition indexing the Schur function. 

:: 

 

sage: f = F[3,2] + F[2,2,1] + F[2,3] + F[1,3,1] + F[1,2,2] 

sage: f.is_symmetric() 

True 

sage: f.to_symmetric_function() 

5*m[1, 1, 1, 1, 1] + 3*m[2, 1, 1, 1] + 2*m[2, 2, 1] + m[3, 1, 1] + m[3, 2] 

sage: s = SymmetricFunctions(QQ).s() 

sage: s(f.to_symmetric_function()) 

s[3, 2] 

 

It is also possible to convert a symmetric function to a 

quasi-symmetric function:: 

 

sage: m = SymmetricFunctions(QQ).m() 

sage: M( m[3,1,1] ) 

M[1, 1, 3] + M[1, 3, 1] + M[3, 1, 1] 

sage: F( s[2,2,1] ) 

F[1, 1, 2, 1] + F[1, 2, 1, 1] + F[1, 2, 2] + F[2, 1, 2] + F[2, 2, 1] 

 

It is possible to experiment with the quasi-symmetric function expansion of other 

bases, but it is important that the base ring be the same for both algebras. 

:: 

 

sage: R = QQ['t'] 

sage: Qp = SymmetricFunctions(R).hall_littlewood().Qp() 

sage: QSymt = QuasiSymmetricFunctions(R) 

sage: Ft = QSymt.F() 

sage: Ft( Qp[2,2] ) 

F[1, 2, 1] + t*F[1, 3] + (t+1)*F[2, 2] + t*F[3, 1] + t^2*F[4] 

 

:: 

 

sage: K = QQ['q','t'].fraction_field() 

sage: Ht = SymmetricFunctions(K).macdonald().Ht() 

sage: Fqt = QuasiSymmetricFunctions(Ht.base_ring()).F() 

sage: Fqt(Ht[2,1]) 

q*t*F[1, 1, 1] + (q+t)*F[1, 2] + (q+t)*F[2, 1] + F[3] 

 

The following will raise an error because the base ring of ``F`` is not 

equal to the base ring of ``Ht``:: 

 

sage: F(Ht[2,1]) 

Traceback (most recent call last): 

... 

TypeError: do not know how to make x (= McdHt[2, 1]) an element of self (=Quasisymmetric functions over the Rational Field in the Fundamental basis) 

 

.. rubric:: The map to the ring of polynomials 

 

The quasi-symmetric functions can be seen as an inverse limit 

of a subring of a polynomial ring as the number of variables 

increases. Indeed, there exists a projection from the 

quasi-symmetric functions onto the polynomial ring 

`R[x_1, x_2, \ldots, x_n]`. This projection is defined by 

sending the variables `x_{n+1}, x_{n+2}, \cdots` to `0`, while 

the remaining `n` variables remain fixed. Note that this 

projection sends `M_I` to `0` if the length of the composition 

`I` is higher than `n`. :: 

 

sage: M[1,3,1].expand(4) 

x0*x1^3*x2 + x0*x1^3*x3 + x0*x2^3*x3 + x1*x2^3*x3 

sage: F[1,3,1].expand(4) 

x0*x1^3*x2 + x0*x1^3*x3 + x0*x1^2*x2*x3 + x0*x1*x2^2*x3 + x0*x2^3*x3 + x1*x2^3*x3 

sage: M[1,3,1].expand(2) 

0 

 

TESTS:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ); QSym 

Quasisymmetric functions over the Rational Field 

sage: QSym.base_ring() 

Rational Field 

""" 

def __init__(self, R): 

""" 

The Hopf algebra of quasi-symmetric functions. 

See ``QuasiSymmetricFunctions`` for full documentation. 

 

EXAMPLES:: 

 

sage: QuasiSymmetricFunctions(QQ) 

Quasisymmetric functions over the Rational Field 

sage: QSym1 = QuasiSymmetricFunctions(FiniteField(23)) 

sage: QSym2 = QuasiSymmetricFunctions(Integers(23)) 

sage: TestSuite(QuasiSymmetricFunctions(QQ)).run() 

""" 

# change the line below to assert(R in Rings()) once MRO issues from #15536, #15475 are resolved 

assert(R in Fields() or R in Rings()) # side effect of this statement assures MRO exists for R 

self._base = R # Won't be needed once CategoryObject won't override base_ring 

category = GradedHopfAlgebras(R) # TODO: .Commutative() 

self._category = category 

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

 

# Bases 

Monomial = self.Monomial() 

Fundamental = self.Fundamental() 

dualImmaculate = self.dualImmaculate() 

QS = self.Quasisymmetric_Schur() 

 

# Change of bases 

Fundamental.module_morphism(Monomial.sum_of_finer_compositions, 

codomain=Monomial, category=category 

).register_as_coercion() 

Monomial .module_morphism(Fundamental.alternating_sum_of_finer_compositions, 

codomain=Fundamental, category=category 

).register_as_coercion() 

#This changes dualImmaculate into Monomial 

dualImmaculate.module_morphism(dualImmaculate._to_Monomial_on_basis, 

codomain = Monomial, category = category 

).register_as_coercion() 

#This changes Monomial into dualImmaculate 

Monomial.module_morphism(dualImmaculate._from_Monomial_on_basis, 

codomain = dualImmaculate, category = category 

).register_as_coercion() 

#This changes Quasisymmetric Schur into Monomial 

QS .module_morphism(QS._to_monomial_on_basis, 

codomain=Monomial, category=category 

).register_as_coercion() 

#This changes Monomial into Quasisymmetric Schur 

Monomial.module_morphism(QS._from_monomial_on_basis, 

codomain=QS, category=category 

).register_as_coercion() 

 

# Embedding of Sym into QSym in the monomial bases 

Sym = SymmetricFunctions(self.base_ring()) 

Sym_m_to_M = Sym.m().module_morphism(Monomial.sum_of_partition_rearrangements, 

triangular='upper', inverse_on_support=Monomial._comp_to_par, 

codomain=Monomial, category=category) 

Sym_m_to_M.register_as_coercion() 

self.to_symmetric_function = Sym_m_to_M.section() 

 

def _repr_(self): 

r""" 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: M._repr_() 

'Quasisymmetric functions over the Integer Ring in the Monomial basis' 

""" 

return "Quasisymmetric functions over the %s"%self.base_ring() 

 

def a_realization(self): 

r""" 

Return the realization of the Monomial basis of the ring of quasi-symmetric functions. 

 

OUTPUT: 

 

- The Monomial basis of quasi-symmetric functions. 

 

EXAMPLES:: 

 

sage: QuasiSymmetricFunctions(QQ).a_realization() 

Quasisymmetric functions over the Rational Field in the Monomial basis 

""" 

return self.Monomial() 

 

_shorthands = tuple(['M', 'F', 'E', 'dI', 'QS', 'phi', 'psi']) 

 

def dual(self): 

r""" 

Return the dual Hopf algebra of the quasi-symmetric functions, which is the 

non-commutative symmetric functions. 

 

OUTPUT: 

 

- The non-commutative symmetric functions. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QSym.dual() 

Non-Commutative Symmetric Functions over the Rational Field 

""" 

return NonCommutativeSymmetricFunctions(self.base_ring()) 

 

def from_polynomial(self, f, check=True): 

""" 

Return the quasi-symmetric function in the Monomial basis 

corresponding to the quasi-symmetric polynomial ``f``. 

 

INPUT: 

 

- ``f`` -- a polynomial in finitely many variables over the same base 

ring as ``self``. It is assumed that this polynomial is 

quasi-symmetric. 

- ``check`` -- boolean (default: ``True``), checks whether the 

polynomial is indeed quasi-symmetric. 

 

OUTPUT: 

 

- quasi-symmetric function in the Monomial basis 

 

EXAMPLES:: 

 

sage: P = PolynomialRing(QQ, 'x', 3) 

sage: x = P.gens() 

sage: f = x[0] + x[1] + x[2] 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QSym.from_polynomial(f) 

M[1] 

 

Beware of setting ``check=False``:: 

 

sage: f = x[0] + 2*x[1] + x[2] 

sage: QSym.from_polynomial(f, check=True) 

Traceback (most recent call last): 

... 

ValueError: x0 + 2*x1 + x2 is not a quasi-symmetric polynomial 

sage: QSym.from_polynomial(f, check=False) 

M[1] 

 

To expand the quasi-symmetric function in a basis other than the 

Monomial basis, the following shorthands are provided:: 

 

sage: M = QSym.Monomial() 

sage: f = x[0]**2+x[1]**2+x[2]**2 

sage: g = M.from_polynomial(f); g 

M[2] 

sage: F = QSym.Fundamental() 

sage: F(g) 

-F[1, 1] + F[2] 

sage: F.from_polynomial(f) 

-F[1, 1] + F[2] 

""" 

assert self.base_ring() == f.base_ring() 

exponent_coefficient = f.dict() 

z = {} 

for (e, c) in six.iteritems(exponent_coefficient): 

I = Compositions()([ei for ei in e if ei > 0]) 

if I not in z: 

z[I] = c 

out = self.Monomial()._from_dict(z) 

if check and out.expand(f.parent().ngens(), f.parent().variable_names()) != f: 

raise ValueError("%s is not a quasi-symmetric polynomial" % f) 

return out 

 

class Bases(Category_realization_of_parent): 

r""" 

Category of bases of quasi-symmetric functions. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QSym.Bases() 

Category of bases of Quasisymmetric functions over the Rational Field 

""" 

def super_categories(self): 

r""" 

Return the super categories of bases of the Quasi-symmetric functions. 

 

OUTPUT: 

 

- a list of categories 

 

TESTS:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QSym.Bases().super_categories() 

[Category of commutative bases of Non-Commutative Symmetric Functions or Quasisymmetric functions over the Rational Field] 

""" 

return [BasesOfQSymOrNCSF(self.base()).Commutative()] 

 

class ParentMethods: 

r""" 

Methods common to all bases of ``QuasiSymmetricFunctions``. 

""" 

 

def from_polynomial(self, f, check=True): 

""" 

The quasi-symmetric function expanded in this basis 

corresponding to the quasi-symmetric polynomial ``f``. 

 

This is a default implementation that computes 

the expansion in the Monomial basis and converts 

to this basis. 

 

INPUT: 

 

- ``f`` -- a polynomial in finitely many variables over the same base 

ring as ``self``. It is assumed that this polynomial is 

quasi-symmetric. 

- ``check`` -- boolean (default: ``True``), checks whether the 

polynomial is indeed quasi-symmetric. 

 

OUTPUT: 

 

- quasi-symmetric function 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).Monomial() 

sage: F = QuasiSymmetricFunctions(QQ).Fundamental() 

sage: P = PolynomialRing(QQ, 'x', 3) 

sage: x = P.gens() 

sage: f = x[0] + x[1] + x[2] 

sage: M.from_polynomial(f) 

M[1] 

sage: F.from_polynomial(f) 

F[1] 

sage: f = x[0]**2+x[1]**2+x[2]**2 

sage: M.from_polynomial(f) 

M[2] 

sage: F.from_polynomial(f) 

-F[1, 1] + F[2] 

 

If the polynomial is not quasi-symmetric, an error 

is raised:: 

 

sage: f = x[0]^2+x[1] 

sage: M.from_polynomial(f) 

Traceback (most recent call last): 

... 

ValueError: x0^2 + x1 is not a quasi-symmetric polynomial 

sage: F.from_polynomial(f) 

Traceback (most recent call last): 

... 

ValueError: x0^2 + x1 is not a quasi-symmetric polynomial 

 

TESTS: 

 

We convert some quasi-symmetric functions to quasi-symmetric 

polynomials and back:: 

 

sage: f = (M[1,2] + M[1,1]).expand(3); f 

x0*x1^2 + x0*x2^2 + x1*x2^2 + x0*x1 + x0*x2 + x1*x2 

sage: M.from_polynomial(f) 

M[1, 1] + M[1, 2] 

sage: f = (2*M[2,1]+M[1,1]+3*M[3]).expand(3) 

sage: M.from_polynomial(f) 

M[1, 1] + 2*M[2, 1] + 3*M[3] 

sage: f = (F[1,2] + F[1,1]).expand(3); f 

x0*x1^2 + x0*x1*x2 + x0*x2^2 + x1*x2^2 + x0*x1 + x0*x2 + x1*x2 

sage: F.from_polynomial(f) 

F[1, 1] + F[1, 2] 

sage: f = (2*F[2,1]+F[1,1]+3*F[3]).expand(3) 

sage: F.from_polynomial(f) 

F[1, 1] + 2*F[2, 1] + 3*F[3] 

""" 

g = self.realization_of().from_polynomial(f, check=check) 

return self(g) 

 

def Eulerian(self, n, j, k=None): 

""" 

Return the Eulerian (quasi)symmetric function `Q_{n,j}` in 

terms of ``self``. 

 

INPUT: 

 

- ``n`` -- the value `n` or a partition 

- ``j`` -- the number of excedances 

- ``k`` -- (optional) if specified, determines the number of 

fixed points of the permutation 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.M() 

sage: M.Eulerian(3, 1) 

4*M[1, 1, 1] + 3*M[1, 2] + 3*M[2, 1] + 2*M[3] 

sage: M.Eulerian(4, 1, 2) 

6*M[1, 1, 1, 1] + 4*M[1, 1, 2] + 4*M[1, 2, 1] 

+ 2*M[1, 3] + 4*M[2, 1, 1] + 3*M[2, 2] + 2*M[3, 1] + M[4] 

sage: QS = QSym.QS() 

sage: QS.Eulerian(4, 2) 

2*QS[1, 3] + QS[2, 2] + 2*QS[3, 1] + 3*QS[4] 

sage: QS.Eulerian([2, 2, 1], 2) 

QS[1, 2, 2] + QS[1, 4] + QS[2, 1, 2] + QS[2, 2, 1] 

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

sage: dI = QSym.dI() 

sage: dI.Eulerian(5, 2) 

-dI[1, 3, 1] - 5*dI[1, 4] + dI[2, 2, 1] + dI[3, 1, 1] 

+ 5*dI[3, 2] + 6*dI[4, 1] + 6*dI[5] 

""" 

F = self.realization_of().F() 

if n in _Partitions: 

n = _Partitions(n) 

return self(F.Eulerian(n, j, k)) 

 

class ElementMethods: 

r""" 

Methods common to all elements of ``QuasiSymmetricFunctions``. 

""" 

 

def internal_coproduct(self): 

r""" 

Return the inner coproduct of ``self`` in the basis of ``self``. 

 

The inner coproduct (also known as the Kronecker coproduct, 

or as the second comultiplication on the `R`-algebra of 

quasi-symmetric functions) is an `R`-algebra homomorphism 

`\Delta^{\times}` from the `R`-algebra of quasi-symmetric 

functions to the tensor square (over `R`) of quasi-symmetric 

functions. It can be defined in the following two ways: 

 

#. If `I` is a composition, then a `(0, I)`-matrix will mean a 

matrix whose entries are nonnegative integers such that no 

row and no column of this matrix is zero, and such that if 

all the non-zero entries of the matrix are read (row by row, 

starting at the topmost row, reading every row from left to 

right), then the reading word obtained is `I`. If `A` is 

a `(0, I)`-matrix, then `\mathrm{row}(A)` will denote the 

vector of row sums of `A` (regarded as a composition), and 

`\mathrm{column}(A)` will denote the vector of column sums 

of `A` (regarded as a composition). 

 

For every composition `I`, the internal coproduct 

`\Delta^{\times}(M_I)` of the `I`-th monomial quasisymmetric 

function `M_I` is the sum 

 

.. MATH:: 

 

\sum_{A \hbox{ is a } (0, I) \text{-matrix}} 

M_{\mathrm{row}(A)} \otimes M_{\mathrm{column}(A)}. 

 

See Section 11.39 of [HazWitt1]_. 

 

#. For every permutation `w`, let `C(w)` denote the descent 

composition of `w`. Then, for any composition `I` of size 

`n`, the internal coproduct `\Delta^{\times}(F_I)` of the 

`I`-th fundamental quasisymmetric function `F_I` is the sum 

 

.. MATH:: 

 

\sum_{\substack{\sigma \in S_n,\\ \tau \in S_n,\\ 

\tau \sigma = \pi}} F_{C(\sigma)} \otimes F_{C(\tau)}, 

 

where `\pi` is any permutation in `S_n` having descent 

composition `I` and where permutations act from the left and 

multiply accordingly, so `\tau \sigma` means first applying 

`\sigma` and then `\tau`. See Theorem 4.23 in [Mal1993]_, 

but beware of the notations which are apparently different 

from those in [HazWitt1]_. 

 

The restriction of the internal coproduct to the 

`R`-algebra of symmetric functions is the well-known 

internal coproduct on the symmetric functions. 

 

The method :meth:`kronecker_coproduct` is a synonym of this one. 

 

EXAMPLES: 

 

Let us compute the internal coproduct of `M_{21}` (which is 

short for `M_{[2, 1]}`). The `(0, [2,1])`-matrices are 

 

.. MATH:: 

 

\begin{bmatrix} 2 & 1 \end{bmatrix}, 

\begin{bmatrix} 2 \\ 1 \end{bmatrix}, 

\begin{bmatrix} 2 & 0 \\ 0 & 1 \end{bmatrix}, \hbox{ and } 

\begin{bmatrix} 0 & 2 \\ 1 & 0 \end{bmatrix} 

 

so 

 

.. MATH:: 

 

\Delta^\times(M_{21}) = M_{3} \otimes M_{21} + 

M_{21} \otimes M_3 + M_{21} \otimes M_{21} + 

M_{21} \otimes M_{12}. 

 

This is confirmed by the following Sage computation 

(incidentally demonstrating the non-cocommutativity of 

the internal coproduct):: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: a = M([2,1]) 

sage: a.internal_coproduct() 

M[2, 1] # M[1, 2] + M[2, 1] # M[2, 1] + M[2, 1] # M[3] + M[3] # M[2, 1] 

 

Further examples:: 

 

sage: all( M([i]).internal_coproduct() == tensor([M([i]), M([i])]) 

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

True 

 

sage: M([1, 2]).internal_coproduct() 

M[1, 2] # M[1, 2] + M[1, 2] # M[2, 1] + M[1, 2] # M[3] + M[3] # M[1, 2] 

 

The definition of `\Delta^{\times}(M_I)` in terms of 

`(0, I)`-matrices is not suitable for computation in 

cases where the length of `I` is large, but we can use 

it as a doctest. Here is a naive implementation:: 

 

sage: def naive_internal_coproduct_on_M(I): 

....: # INPUT: composition I 

....: # (not quasi-symmetric function) 

....: # OUTPUT: interior coproduct of M_I 

....: M = QuasiSymmetricFunctions(ZZ).M() 

....: M2 = M.tensor(M) 

....: res = M2.zero() 

....: l = len(I) 

....: n = I.size() 

....: for S in Subsets(range(l**2), l): 

....: M_list = sorted(S) 

....: row_M = [sum([I[M_list.index(l * i + j)] 

....: for j in range(l) if 

....: l * i + j in S]) 

....: for i in range(l)] 

....: col_M = [sum([I[M_list.index(l * i + j)] 

....: for i in range(l) if 

....: l * i + j in S]) 

....: for j in range(l)] 

....: if 0 in row_M: 

....: first_zero = row_M.index(0) 

....: row_M = row_M[:first_zero] 

....: if sum(row_M) != n: 

....: continue 

....: if 0 in col_M: 

....: first_zero = col_M.index(0) 

....: col_M = col_M[:first_zero] 

....: if sum(col_M) != n: 

....: continue 

....: res += tensor([M(Compositions(n)(row_M)), 

....: M(Compositions(n)(col_M))]) 

....: return res 

sage: all( naive_internal_coproduct_on_M(I) 

....: == M(I).internal_coproduct() 

....: for I in Compositions(3) ) 

True 

 

TESTS: 

 

Border cases:: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: F = QuasiSymmetricFunctions(ZZ).F() 

sage: M([]).internal_coproduct() 

M[] # M[] 

sage: F([]).internal_coproduct() 

F[] # F[] 

 

The implementations on the ``F`` and ``M`` bases agree 

with each other:: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: F = QuasiSymmetricFunctions(ZZ).F() 

sage: def int_copr_on_F_via_M(I): 

....: result = tensor([F.zero(), F.zero()]) 

....: w = M(F(I)).internal_coproduct() 

....: for lam, a in w: 

....: (U, V) = lam 

....: result += a * tensor([F(M(U)), F(M(V))]) 

....: return result 

sage: all( int_copr_on_F_via_M(I) == F(I).internal_coproduct() 

....: for I in Compositions(3) ) 

True 

sage: all( int_copr_on_F_via_M(I) == F(I).internal_coproduct() 

....: for I in Compositions(4) ) 

True 

 

Restricting to the subring of symmetric functions gives the 

standard internal coproduct on the latter:: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: e = SymmetricFunctions(ZZ).e() 

sage: def int_copr_of_e_in_M(mu): 

....: result = tensor([M.zero(), M.zero()]) 

....: w = e(mu).internal_coproduct() 

....: for lam, a in w: 

....: (nu, kappa) = lam 

....: result += a * tensor([M(e(nu)), M(e(kappa))]) 

....: return result 

sage: all( int_copr_of_e_in_M(mu) == M(e(mu)).internal_coproduct() 

....: for mu in Partitions(3) ) 

True 

sage: all( int_copr_of_e_in_M(mu) == M(e(mu)).internal_coproduct() 

....: for mu in Partitions(4) ) 

True 

 

.. TODO:: 

 

Implement this directly on the monomial basis maybe? 

The `(0, I)`-matrices are a pain to generate from their 

definition, but maybe there is a good algorithm. 

If so, the above "further examples" should be moved 

to the M-method. 

""" 

# Coerce to F basis and back, doing the actual computation in that basis. 

parent = self.parent() 

F = parent.realization_of().F() 

from sage.categories.tensor import tensor 

result = tensor([parent.zero(), parent.zero()]) 

for lam, a in F(self).internal_coproduct(): 

(I, J) = lam 

result += a * tensor([parent(F(I)), parent(F(J))]) 

return result 

 

kronecker_coproduct = internal_coproduct 

 

def frobenius(self, n): 

r""" 

Return the image of the quasi-symmetric function ``self`` 

under the `n`-th Frobenius operator. 

 

The `n`-th Frobenius operator `\mathbf{f}_n` is defined to be 

the map from the `R`-algebra of quasi-symmetric functions 

to itself that sends every symmetric function 

`P(x_1, x_2, x_3, \ldots)` to 

`P(x_1^n, x_2^n, x_3^n, \ldots)`. This operator `\mathbf{f}_n` 

is a Hopf algebra endomorphism, and satisfies 

 

.. MATH:: 

 

f_n M_{(i_1, i_2, i_3, \ldots)} = 

M_{(ni_1, ni_2, ni_3, \ldots)} 

 

for every composition `(i_1, i_2, i_3, \ldots)` 

(where `M` means the monomial basis). 

 

The `n`-th Frobenius operator is also called the `n`-th 

Frobenius endomorphism. It is not related to the Frobenius map 

which connects the ring of symmetric functions with the 

representation theory of the symmetric group. 

 

The `n`-th Frobenius operator is also the `n`-th Adams operator 

of the `\Lambda`-ring of quasi-symmetric functions over the 

integers. 

 

The restriction of the `n`-th Frobenius operator to the 

subring formed by all symmetric functions is, not 

unexpectedly, the `n`-th Frobenius operator of the ring of 

symmetric functions. 

 

.. SEEALSO:: 

 

:meth:`Symmetric functions plethsym 

<sage.combinat.sf.sfa.SymmetricFunctionAlgebra_generic_Element.plethysm>` 

 

INPUT: 

 

- ``n`` -- a positive integer 

 

OUTPUT: 

 

The result of applying the `n`-th Frobenius operator (on the 

ring of quasi-symmetric functions) to ``self``. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: M = QSym.M() 

sage: F = QSym.F() 

sage: M[3,2].frobenius(2) 

M[6, 4] 

sage: (M[2,1] - 2*M[3]).frobenius(4) 

M[8, 4] - 2*M[12] 

sage: M([]).frobenius(3) 

M[] 

sage: F[1,1].frobenius(2) 

F[1, 1, 1, 1] - F[1, 1, 2] - F[2, 1, 1] + F[2, 2] 

 

The Frobenius endomorphisms are multiplicative:: 

 

sage: all( all( M(I).frobenius(3) * M(J).frobenius(3) 

....: == (M(I) * M(J)).frobenius(3) 

....: for I in Compositions(3) ) 

....: for J in Compositions(2) ) 

True 

 

Being Hopf algebra endomorphisms, the Frobenius operators 

commute with the antipode:: 

 

sage: all( M(I).frobenius(4).antipode() 

....: == M(I).antipode().frobenius(4) 

....: for I in Compositions(3) ) 

True 

 

The restriction of the Frobenius operators to the subring 

of symmetric functions are the Frobenius operators of 

the latter:: 

 

sage: e = SymmetricFunctions(ZZ).e() 

sage: all( M(e(lam)).frobenius(3) 

....: == M(e(lam).frobenius(3)) 

....: for lam in Partitions(3) ) 

True 

""" 

# Convert to the monomial basis, there apply Frobenius componentwise, 

# then convert back. 

parent = self.parent() 

M = parent.realization_of().M() 

C = parent._indices 

dct = {C([n * i for i in I]): coeff 

for (I, coeff) in M(self)} 

result_in_M_basis = M._from_dict(dct) 

return parent(result_in_M_basis) 

 

def adams_operation(self, *args, **opts): 

from sage.misc.superseded import deprecation 

deprecation(19255, "Do not use this method! Please use `frobenius` or `adams_operator` methods following what you expect.") 

 

def star_involution(self): 

r""" 

Return the image of the quasisymmetric function ``self`` under 

the star involution. 

 

The star involution is defined as the linear map 

`QSym \to QSym` which, for every composition `I`, sends the 

monomial quasisymmetric function `M_I` to `M_{I^r}`. Here, if 

`I` is a composition, we denote by `I^r` the reversed 

composition of `I`. Denoting by `f^{\ast}` the image of an 

element `f \in QSym` under the star involution, it can be shown 

that every composition `I` satisfies 

 

.. MATH:: 

 

(M_I)^{\ast} = M_{I^r}, \quad (F_I)^{\ast} = F_{I^r}, 

 

where `F_I` denotes the fundamental quasisymmetric function 

corresponding to the composition `I`. The star involution is an 

involution, an algebra automorphism and a coalgebra 

anti-automorphism of `QSym`. It also is an automorphism of the 

graded vector space `QSym`, and is the identity on the subspace 

`Sym` of `QSym`. It is adjoint to the star involution on `NCSF` 

by the standard adjunction between `NCSF` and `QSym`. 

 

The star involution has been denoted by `\rho` in [LMvW13]_, 

section 3.6. 

 

.. SEEALSO:: 

 

:meth:`star involution on NCSF 

<sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Bases.ElementMethods.star_involution>`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: M = QSym.M() 

sage: M[3,2].star_involution() 

M[2, 3] 

sage: M[6,3].star_involution() 

M[3, 6] 

sage: (M[9,1] - M[6,2] + 2*M[6,4] - 3*M[3] + 4*M[[]]).star_involution() 

4*M[] + M[1, 9] - M[2, 6] - 3*M[3] + 2*M[4, 6] 

sage: (M[3,3] - 2*M[2]).star_involution() 

-2*M[2] + M[3, 3] 

sage: M([4,2]).star_involution() 

M[2, 4] 

sage: dI = QSym.dI() 

sage: dI([1,2]).star_involution() 

-dI[1, 2] + dI[2, 1] 

sage: dI.zero().star_involution() 

0 

 

The star involution commutes with the antipode:: 

 

sage: all( M(I).star_involution().antipode() 

....: == M(I).antipode().star_involution() 

....: for I in Compositions(4) ) 

True 

 

The star involution is the identity on `Sym`:: 

 

sage: Sym = SymmetricFunctions(ZZ) 

sage: e = Sym.e() 

sage: all( M(e(lam)).star_involution() == M(e(lam)) 

....: for lam in Partitions(4) ) 

True 

""" 

# Convert to the homogeneous basis, there apply the star 

# involution componentwise, then convert back. 

parent = self.parent() 

M = parent.realization_of().M() 

dct = {I.reversed(): coeff for (I, coeff) in M(self)} 

return parent(M._from_dict(dct)) 

 

def omega_involution(self): 

r""" 

Return the image of the quasisymmetric function 

``self`` under the omega involution. 

 

The omega involution is defined as the linear map 

`QSym \to QSym` which, for every composition `I`, sends 

the fundamental quasisymmetric function `F_I` to 

`F_{I^t}`, where `I^t` denotes the conjugate 

(:meth:`~sage.combinat.composition.Composition.conjugate`) 

of the composition `I`. This map is commonly denoted by 

`\omega`. It is an algebra homomorphism and a coalgebra 

antihomomorphism; it also is an involution and an 

automorphism of the graded vector space `QSym`. Also, 

every composition `I` satisfies 

 

.. MATH:: 

 

\omega(M_I) = (-1)^{|I|-\ell(I)} \sum M_J, 

 

where the sum ranges over all compositions `J` of `|I|` 

which are coarser than the reversed composition `I^r` of 

`I`. Here, `\ell(I)` denotes the length of the composition 

`I` (that is, the number of parts of `I`). 

 

If `f` is a homogeneous element of `NCSF` of degree `n`, 

then 

 

.. MATH:: 

 

\omega(f) = (-1)^n S(f), 

 

where `S` denotes the antipode of `QSym`. 

 

The restriction of `\omega` to the ring of symmetric 

functions (which is a subring of `QSym`) is precisely the 

omega involution 

(:meth:`~sage.combinat.sf.sfa.SymmetricFunctionAlgebra_generic_Element.omega`) 

of said ring. 

 

The omega involution on `QSym` is adjoint to the omega 

involution on `NCSF` by the standard adjunction between `NCSF` 

and `QSym`. 

 

The omega involution has been denoted by `\omega` in [LMvW13]_, 

section 3.6. 

 

.. SEEALSO:: 

 

:meth:`omega involution on NCSF 

<sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Bases.ElementMethods.omega_involution>`, 

:meth:`psi involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.psi_involution>`, 

:meth:`star involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.star_involution>`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: F = QSym.F() 

sage: F[3,2].omega_involution() 

F[1, 2, 1, 1] 

sage: F[6,3].omega_involution() 

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

sage: (F[9,1] - F[8,2] + 2*F[2,4] - 3*F[3] + 4*F[[]]).omega_involution() 

4*F[] - 3*F[1, 1, 1] + 2*F[1, 1, 1, 2, 1] - F[1, 2, 1, 1, 1, 1, 1, 1, 1] + F[2, 1, 1, 1, 1, 1, 1, 1, 1] 

sage: (F[3,3] - 2*F[2]).omega_involution() 

-2*F[1, 1] + F[1, 1, 2, 1, 1] 

sage: F([2,1,1]).omega_involution() 

F[3, 1] 

sage: M = QSym.M() 

sage: M([2,1]).omega_involution() 

-M[1, 2] - M[3] 

sage: M.zero().omega_involution() 

0 

 

Testing the fact that the restriction of `\omega` to `Sym` 

is the omega automorphism of `Sym`:: 

 

sage: Sym = SymmetricFunctions(ZZ) 

sage: e = Sym.e() 

sage: all( F(e[lam]).omega_involution() == F(e[lam].omega()) 

....: for lam in Partitions(4) ) 

True 

""" 

# Use the `\omega(f) = (-1)^n S(f)` formula. 

return self.antipode().degree_negation() 

 

def psi_involution(self): 

r""" 

Return the image of the quasisymmetric function ``self`` 

under the involution `\psi`. 

 

The involution `\psi` is defined as the linear map 

`QSym \to QSym` which, for every composition `I`, sends the 

fundamental quasisymmetric function `F_I` to `F_{I^c}`, where 

`I^c` denotes the complement of the composition `I`. 

The map `\psi` is an involution and a graded Hopf algebra 

automorphism of `QSym`. Its restriction to the ring of 

symmetric functions coincides with the omega automorphism of 

the latter ring. 

 

The involution `\psi` of `QSym` is adjoint to the involution 

`\psi` of `NCSF` by the standard adjunction between `NCSF` and 

`QSym`. 

 

The involution `\psi` has been denoted by `\psi` in [LMvW13]_, 

section 3.6. 

 

.. SEEALSO:: 

 

:meth:`psi involution on NCSF 

<sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Bases.ElementMethods.psi_involution>`, 

:meth:`star involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.star_involution>`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: F = QSym.F() 

sage: F[3,2].psi_involution() 

F[1, 1, 2, 1] 

sage: F[6,3].psi_involution() 

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

sage: (F[9,1] - F[8,2] + 2*F[2,4] - 3*F[3] + 4*F[[]]).psi_involution() 

4*F[] - 3*F[1, 1, 1] + F[1, 1, 1, 1, 1, 1, 1, 1, 2] - F[1, 1, 1, 1, 1, 1, 1, 2, 1] + 2*F[1, 2, 1, 1, 1] 

sage: (F[3,3] - 2*F[2]).psi_involution() 

-2*F[1, 1] + F[1, 1, 2, 1, 1] 

sage: F([2,1,1]).psi_involution() 

F[1, 3] 

sage: M = QSym.M() 

sage: M([2,1]).psi_involution() 

-M[2, 1] - M[3] 

sage: M.zero().psi_involution() 

0 

 

The involution `\psi` commutes with the antipode:: 

 

sage: all( F(I).psi_involution().antipode() 

....: == F(I).antipode().psi_involution() 

....: for I in Compositions(4) ) 

True 

 

Testing the fact that the restriction of `\psi` to `Sym` 

is the omega automorphism of `Sym`:: 

 

sage: Sym = SymmetricFunctions(ZZ) 

sage: e = Sym.e() 

sage: all( F(e[lam]).psi_involution() == F(e[lam].omega()) 

....: for lam in Partitions(4) ) 

True 

""" 

# Convert to the fundamental basis, there apply the psi 

# involution componentwise, then convert back. 

parent = self.parent() 

F = parent.realization_of().F() 

dct = {I.complement(): coeff for (I, coeff) in F(self)} 

return parent(F._from_dict(dct)) 

 

def dendriform_less(self, other): 

r""" 

Return the result of applying the dendriform smaller 

operation to the two quasi-symmetric functions ``self`` 

and ``other``. 

 

The dendriform smaller operation is a binary operation, 

denoted by `\prec` and written infix, on the ring of 

quasi-symmetric functions. It can be defined as a 

restriction of a binary operation (denoted by `\prec` 

and written infix as well) on the ring of formal power 

series `R[[x_1, x_2, x_3, \ldots]]`, which is defined 

as follows: If `m` and `n` are two monomials in 

`x_1, x_2, x_3, \ldots`, then we let `m \prec n` be 

the product `mn` if the smallest positive integer `i` 

for which `x_i` occurs in `m` is smaller than the 

smallest positive integer `j` for which `x_j` occurs 

in `n` (this is understood to be false when `m = 1`, 

and true when `m \neq 1` and `n = 1`), and we let 

`m \prec n` be `0` otherwise. Having thus defined 

`\prec` on monomials, we extend `\prec` to a binary 

operation on `R[[x_1, x_2, x_3, \ldots]]` by requiring 

it to be continuous (in both inputs) and `R`-bilinear. 

It is easily seen that `QSym \prec QSym \subseteq 

QSym`, so that `\prec` restricts to a binary operation 

on `QSym`. 

 

.. SEEALSO:: 

 

:meth:`dendriform_leq` 

 

INPUT: 

 

- ``other`` -- a quasi-symmetric function over the 

same base ring as ``self`` 

 

OUTPUT: 

 

The quasi-symmetric function ``self`` `\prec` 

``other``, written in the basis of ``self``. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.M() 

sage: M[2, 1].dendriform_less(M[1, 2]) 

2*M[2, 1, 1, 2] + M[2, 1, 2, 1] + M[2, 1, 3] + M[2, 2, 2] 

sage: F = QSym.F() 

sage: F[2, 1].dendriform_less(F[1, 2]) 

F[1, 1, 2, 1, 1] + F[1, 1, 2, 2] + F[1, 1, 3, 1] 

+ F[1, 2, 1, 2] + F[1, 2, 2, 1] + F[1, 2, 3] 

+ F[2, 1, 1, 2] + F[2, 1, 2, 1] + F[2, 1, 3] + F[2, 2, 2] 

 

The operation `\prec` can be used to recursively 

construct the dual immaculate basis: For every positive 

integer `m` and every composition `I`, the dual 

immaculate function `\operatorname{dI}_{[m, I]}` of the 

composition `[m, I]` (this composition is `I` with `m` 

prepended to it) is `F_{[m]} \prec \operatorname{dI}_I`. :: 

 

sage: dI = QSym.dI() 

sage: dI(F[2]).dendriform_less(dI[1, 2]) 

dI[2, 1, 2] 

 

We check with the identity element:: 

 

sage: M.one().dendriform_less(M[1,2]) 

0 

sage: M[1,2].dendriform_less(M.one()) 

M[1, 2] 

 

The operation `\prec` is not symmetric, nor if 

`a \prec b \neq 0`, then `b \prec a = 0` (as it would be 

for a single monomial):: 

 

sage: M[1,2,1].dendriform_less(M[1,2]) 

M[1, 1, 2, 1, 2] + 2*M[1, 1, 2, 2, 1] + M[1, 1, 2, 3] 

+ M[1, 1, 4, 1] + 2*M[1, 2, 1, 1, 2] + M[1, 2, 1, 2, 1] 

+ M[1, 2, 1, 3] + M[1, 2, 2, 2] + M[1, 3, 1, 2] 

+ M[1, 3, 2, 1] + M[1, 3, 3] 

sage: M[1,2].dendriform_less(M[1,2,1]) 

M[1, 1, 2, 1, 2] + 2*M[1, 1, 2, 2, 1] + M[1, 1, 2, 3] 

+ M[1, 1, 4, 1] + M[1, 2, 1, 2, 1] + M[1, 3, 2, 1] 

""" 

# Convert to the monomial basis, there do restricted 

# shuffle product, then convert back to self.parent(). 

P = self.parent() 

M = P.realization_of().M() 

a = M(self) 

b = M(other) 

res = M.zero() 

for I, I_coeff in a: 

if not I: 

continue 

i_head = I[0] 

I_tail = Composition(I[1:]) 

for J, J_coeff in b: 

shufpro = I_tail.shuffle_product(J, overlap=True) 

res += J_coeff * M.sum_of_monomials(Composition([i_head] + list(K)) 

for K in shufpro) 

return P(res) 

 

def dendriform_leq(self, other): 

r""" 

Return the result of applying the dendriform 

smaller-or-equal operation to the two quasi-symmetric 

functions ``self`` and ``other``. 

 

The dendriform smaller-or-equal operation is a binary 

operation, denoted by `\preceq` and written infix, on 

the ring of quasi-symmetric functions. It can be 

defined as a restriction of a binary operation 

(denoted by `\preceq` and written infix as well) on 

the ring of formal power series 

`R[[x_1, x_2, x_3, \ldots]]`, which is defined as 

follows: If `m` and `n` are two monomials in 

`x_1, x_2, x_3, \ldots`, then we let `m \preceq n` be 

the product `mn` if the smallest positive integer `i` 

for which `x_i` occurs in `m` is smaller or equal to 

the smallest positive integer `j` for which `x_j` 

occurs in `n` (this is understood to be false when 

`m = 1` and `n \neq 1`, and true when `n = 1`), and we 

let `m \preceq n` be `0` otherwise. Having thus 

defined `\preceq` on monomials, we extend `\preceq` to 

a binary operation on `R[[x_1, x_2, x_3, \ldots]]` by 

requiring it to be continuous (in both inputs) and 

`R`-bilinear. It is easily seen that 

`QSym \preceq QSym \subseteq QSym`, so that `\preceq` 

restricts to a binary operation on `QSym`. 

 

This operation `\preceq` is related to the dendriform 

smaller relation `\prec` (:meth:`dendriform_less`). 

Namely, if we define a binary operation `\succ` on 

`QSym` by `a \succ b = b \prec a`, then 

`(QSym, \preceq, \succ)` is a dendriform `R`-algebra. 

Thus, any `a, b \in QSym` satisfy 

`a \preceq b = ab - b \prec a`. 

 

.. SEEALSO:: 

 

:meth:`dendriform_less` 

 

INPUT: 

 

- ``other`` -- a quasi-symmetric function over the 

same base ring as ``self`` 

 

OUTPUT: 

 

The quasi-symmetric function ``self`` `\preceq` 

``other``, written in the basis of ``self``. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.M() 

sage: M[2, 1].dendriform_leq(M[1, 2]) 

2*M[2, 1, 1, 2] + M[2, 1, 2, 1] + M[2, 1, 3] + M[2, 2, 2] 

+ M[3, 1, 2] + M[3, 2, 1] + M[3, 3] 

sage: F = QSym.F() 

sage: F[2, 1].dendriform_leq(F[1, 2]) 

F[2, 1, 1, 2] + F[2, 1, 2, 1] + F[2, 1, 3] + F[2, 2, 1, 1] 

+ 2*F[2, 2, 2] + F[2, 3, 1] + F[3, 1, 2] + F[3, 2, 1] + F[3, 3] 

""" 

# This might be somewhat slow... 

P = self.parent() 

return self * P(other) - P(other.dendriform_less(self)) 

 

def expand(self, n, alphabet='x'): 

r""" 

Expand the quasi-symmetric function into ``n`` variables in 

an alphabet, which by default is ``'x'``. 

 

INPUT: 

 

- ``n`` -- A nonnegative integer; the number of variables 

in the expansion 

- ``alphabet`` -- (default: ``'x'``); the alphabet in 

which ``self`` is to be expanded 

 

OUTPUT: 

 

- An expansion of ``self`` into the ``n`` variables specified 

by ``alphabet``. 

 

EXAMPLES:: 

 

sage: F=QuasiSymmetricFunctions(QQ).Fundamental() 

sage: F[3].expand(3) 

x0^3 + x0^2*x1 + x0*x1^2 + x1^3 + x0^2*x2 + x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2 + x2^3 

sage: F[2,1].expand(3) 

x0^2*x1 + x0^2*x2 + x0*x1*x2 + x1^2*x2 

 

One can use a different set of variable by adding an optional 

argument ``alphabet=...`` :: 

 

sage: F=QuasiSymmetricFunctions(QQ).Fundamental() 

sage: F[3].expand(2,alphabet='y') 

y0^3 + y0^2*y1 + y0*y1^2 + y1^3 

 

TESTS:: 

 

sage: (3*F([])).expand(2) 

3 

sage: F[4,2].expand(0) 

0 

sage: F([]).expand(0) 

1 

""" 

M = self.parent().realization_of().Monomial() 

return M(self).expand(n,alphabet) 

 

def is_symmetric(self): 

r""" 

Return ``True`` if ``self`` is an element of the symmetric 

functions. 

 

This is being tested by looking at the expansion in 

the Monomial basis and checking if the coefficients are 

the same if the indexing compositions are permutations 

of each other. 

 

OUTPUT: 

 

- ``True`` if ``self`` is symmetric. 

``False`` if ``self`` is not symmetric. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: F = QSym.Fundamental() 

sage: (F[3,2] + F[2,3]).is_symmetric() 

False 

sage: (F[1, 1, 1, 2] + F[1, 1, 3] + F[1, 3, 1] + F[2, 1, 1, 1] + F[3, 1, 1]).is_symmetric() 

True 

sage: F([]).is_symmetric() 

True 

""" 

M = self.parent().realization_of().Monomial() 

return M(self).is_symmetric() 

 

def to_symmetric_function(self): 

r""" 

Convert a quasi-symmetric function to a symmetric function. 

 

OUTPUT: 

 

- If ``self`` is a symmetric function, then return the expansion 

in the monomial basis. Otherwise raise an error. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: F = QSym.Fundamental() 

sage: (F[3,2] + F[2,3]).to_symmetric_function() 

Traceback (most recent call last): 

... 

ValueError: F[2, 3] + F[3, 2] is not a symmetric function 

sage: m = SymmetricFunctions(QQ).m() 

sage: s = SymmetricFunctions(QQ).s() 

sage: F(s[3,1,1]).to_symmetric_function() 

6*m[1, 1, 1, 1, 1] + 3*m[2, 1, 1, 1] + m[2, 2, 1] + m[3, 1, 1] 

sage: m(s[3,1,1]) 

6*m[1, 1, 1, 1, 1] + 3*m[2, 1, 1, 1] + m[2, 2, 1] + m[3, 1, 1] 

""" 

if self.is_symmetric(): 

M = self.parent().realization_of().Monomial() 

return M( self ).to_symmetric_function() 

else: 

raise ValueError("%s is not a symmetric function"%self) 

 

class Monomial(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric function in the Monomial basis. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.M() 

sage: F = QSym.F() 

sage: M(F[2,2]) 

M[1, 1, 1, 1] + M[1, 1, 2] + M[2, 1, 1] + M[2, 2] 

sage: m = SymmetricFunctions(QQ).m() 

sage: M(m[3,1,1]) 

M[1, 1, 3] + M[1, 3, 1] + M[3, 1, 1] 

sage: (1+M[1])^3 

M[] + 3*M[1] + 6*M[1, 1] + 6*M[1, 1, 1] + 3*M[1, 2] + 3*M[2] + 3*M[2, 1] + M[3] 

sage: M[1,2,1].coproduct() 

M[] # M[1, 2, 1] + M[1] # M[2, 1] + M[1, 2] # M[1] + M[1, 2, 1] # M[] 

 

The following is an alias for this basis:: 

 

sage: QSym.Monomial() 

Quasisymmetric functions over the Rational Field in the Monomial basis 

 

TESTS:: 

 

sage: M(F([])) 

M[] 

sage: M(F(0)) 

0 

sage: M(m([])) 

M[] 

""" 

def __init__(self, QSym): 

""" 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).Monomial(); M 

Quasisymmetric functions over the Rational Field in the Monomial basis 

sage: TestSuite(M).run() 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='M', bracket=False, 

category=QSym.Bases()) 

 

def dual(self): 

r""" 

Return the dual basis to the Monomial basis. This is the complete basis of the 

non-commutative symmetric functions. 

 

OUTPUT: 

 

- The complete basis of the non-commutative symmetric functions. 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: M.dual() 

Non-Commutative Symmetric Functions over the Rational Field in the Complete basis 

""" 

return self.realization_of().dual().Complete() 

 

def product_on_basis(self, I, J): 

""" 

The product on Monomial basis elements. 

 

The product of the basis elements indexed by two compositions 

`I` and `J` is the sum of the basis elements indexed by 

compositions in the stuffle product (also called the 

overlapping shuffle product) of `I` and `J`. 

 

INPUT: 

 

- ``I``, ``J`` -- compositions 

 

OUTPUT: 

 

- The product of the Monomial quasi-symmetric functions indexed by ``I`` and 

``J``, expressed in the Monomial basis. 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).Monomial() 

sage: c1 = Composition([2]) 

sage: c2 = Composition([1,3]) 

sage: M.product_on_basis(c1, c2) 

M[1, 2, 3] + M[1, 3, 2] + M[1, 5] + M[2, 1, 3] + M[3, 3] 

sage: M.product_on_basis(c1, Composition([])) 

M[2] 

""" 

return self.sum_of_monomials(I.shuffle_product(J, overlap=True)) 

 

def antipode_on_basis(self, compo): 

r""" 

Return the result of the antipode applied to a quasi-symmetric Monomial basis 

element. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The result of the antipode applied to the composition ``compo``, expressed 

in the Monomial basis. 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: M.antipode_on_basis(Composition([2,1])) 

M[1, 2] + M[3] 

sage: M.antipode_on_basis(Composition([])) 

M[] 

""" 

return (-1)**(len(compo)) * self.sum_of_fatter_compositions(compo.reversed()) 

 

def coproduct_on_basis(self, compo): 

r""" 

Return the coproduct of a Monomial basis element. 

 

Combinatorial rule: deconcatenation. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The coproduct applied to the Monomial quasi-symmetric function indexed by 

``compo``, expressed in the Monomial basis. 

 

EXAMPLES:: 

 

sage: M=QuasiSymmetricFunctions(QQ).Monomial() 

sage: M[4,2,3].coproduct() 

M[] # M[4, 2, 3] + M[4] # M[2, 3] + M[4, 2] # M[3] + M[4, 2, 3] # M[] 

sage: M.coproduct_on_basis(Composition([])) 

M[] # M[] 

""" 

return self.tensor_square().sum_of_monomials((self._indices(compo[:i]), 

self._indices(compo[i:])) 

for i in range(0,len(compo)+1)) 

 

def lambda_of_monomial(self, I, n): 

r""" 

Return the image of the monomial quasi-symmetric function 

`M_I` under the lambda-map `\lambda^n`, expanded in the 

monomial basis. 

 

The ring of quasi-symmetric functions over the integers, 

`\mathrm{QSym}_{\ZZ}` (and more generally, the ring of 

quasi-symmetric functions over any binomial ring) becomes 

a `\lambda`-ring (with the `\lambda`-structure inherited 

from the ring of formal power series, so that 

`\lambda^i(x_j)` is `x_j` if `i = 1` and `0` if `i > 1`). 

 

The Adams operations of this `\lambda`-ring are the 

Frobenius endomorphisms `\mathbf{f}_n` (see 

:meth:`~sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.frobenius` 

for their definition). Using these endomorphisms, the 

`\lambda`-operations can be explicitly computed via the formula 

 

.. MATH:: 

 

\exp \left(- \sum_{n=1}^{\infty} 

\frac{1}{n} \mathbf{f}_n(x) t^n \right) 

= \sum_{j=0}^{\infty} (-1)^j \lambda^j(x) t^j 

 

in the ring of formal power series in a variable `t` over 

the ring of quasi-symmetric functions. In particular, 

every composition `I = (I_1, I_2, \cdots, I_\ell )` satisfies 

 

.. MATH:: 

 

\exp \left(- \sum_{n=1}^{\infty} 

\frac{1}{n} M_{(nI_1, nI_2, \cdots, nI_\ell )} t^n \right) 

= \sum_{j=0}^{\infty} (-1)^j \lambda^j(M_I) t^j 

 

(corrected version of Remark 2.4 in [Haz2004]_). 

 

The quasi-symmetric functions `\lambda^i(M_I)` with `n` 

ranging over the positive integers and `I` ranging over 

the reduced Lyndon compositions (i. e., compositions 

which are Lyndon words and have the gcd of their entries 

equal to `1`) form a set of free polynomial generators 

for `\mathrm{QSym}`. See [GriRei2014]_, Chapter 6, for 

the proof, and [Haz2004]_ for a major part of it. 

 

INPUT: 

 

- ``I`` -- composition 

- ``n`` -- nonnegative integer 

 

OUTPUT: 

 

The quasi-symmetric function `\lambda^n(M_I)`, expanded in 

the monomial basis over the ground ring of ``self``. 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(CyclotomicField()).Monomial() 

sage: M.lambda_of_monomial([1, 2], 2) 

2*M[1, 1, 2, 2] + M[1, 1, 4] + M[1, 2, 1, 2] + M[1, 3, 2] + M[2, 2, 2] 

sage: M.lambda_of_monomial([1, 1], 2) 

3*M[1, 1, 1, 1] + M[1, 1, 2] + M[1, 2, 1] + M[2, 1, 1] 

sage: M = QuasiSymmetricFunctions(Integers(19)).Monomial() 

sage: M.lambda_of_monomial([1, 2], 3) 

6*M[1, 1, 1, 2, 2, 2] + 3*M[1, 1, 1, 2, 4] + 3*M[1, 1, 1, 4, 2] 

+ M[1, 1, 1, 6] + 4*M[1, 1, 2, 1, 2, 2] + 2*M[1, 1, 2, 1, 4] 

+ 2*M[1, 1, 2, 2, 1, 2] + 2*M[1, 1, 2, 3, 2] + 4*M[1, 1, 3, 2, 2] 

+ 2*M[1, 1, 3, 4] + M[1, 1, 4, 1, 2] + M[1, 1, 5, 2] 

+ 2*M[1, 2, 1, 1, 2, 2] + M[1, 2, 1, 1, 4] + M[1, 2, 1, 2, 1, 2] 

+ M[1, 2, 1, 3, 2] + 4*M[1, 2, 2, 2, 2] + M[1, 2, 2, 4] + M[1, 2, 4, 2] 

+ 2*M[1, 3, 1, 2, 2] + M[1, 3, 1, 4] + M[1, 3, 2, 1, 2] + M[1, 3, 3, 2] 

+ M[1, 4, 2, 2] + 3*M[2, 1, 2, 2, 2] + M[2, 1, 2, 4] + M[2, 1, 4, 2] 

+ 2*M[2, 2, 1, 2, 2] + M[2, 2, 1, 4] + M[2, 2, 2, 1, 2] + M[2, 2, 3, 2] 

+ 2*M[2, 3, 2, 2] + M[2, 3, 4] + M[3, 2, 2, 2] 

 

The map `\lambda^0` sends everything to `1`:: 

 

sage: M = QuasiSymmetricFunctions(ZZ).Monomial() 

sage: all( M.lambda_of_monomial(I, 0) == M.one() 

....: for I in Compositions(3) ) 

True 

 

The map `\lambda^1` is the identity map:: 

 

sage: M = QuasiSymmetricFunctions(QQ).Monomial() 

sage: all( M.lambda_of_monomial(I, 1) == M(I) 

....: for I in Compositions(3) ) 

True 

sage: M = QuasiSymmetricFunctions(Integers(5)).Monomial() 

sage: all( M.lambda_of_monomial(I, 1) == M(I) 

....: for I in Compositions(3) ) 

True 

sage: M = QuasiSymmetricFunctions(ZZ).Monomial() 

sage: all( M.lambda_of_monomial(I, 1) == M(I) 

....: for I in Compositions(3) ) 

True 

""" 

# The following algorithm is a rewriting of the formula in the docstring. 

# We are working over QQ because there are denominators which don't 

# immediately cancel. 

from sage.rings.all import ZZ, QQ 

QQM = QuasiSymmetricFunctions(QQ).M() 

QQ_result = QQM.zero() 

for lam in Partitions(n): 

coeff = QQ((-1) ** len(lam)) / lam.centralizer_size() 

QQ_result += coeff * QQM.prod([QQM(self._indices([k * i for i in I])) 

for k in lam]) 

QQ_result *= (-1) ** n 

# QQ_result is now \lambda^n(M_I) over QQ. 

result = self.sum_of_terms([(J, ZZ(coeff)) for (J, coeff) in QQ_result], 

distinct = True) 

return result 

 

class Element(CombinatorialFreeModule.Element): 

r""" 

Element methods of the ``Monomial`` basis of ``QuasiSymmetricFunctions``. 

""" 

 

def psi_involution(self): 

r""" 

Return the image of the quasisymmetric function ``self`` 

under the involution `\psi`. 

 

The involution `\psi` is defined as the linear map 

`QSym \to QSym` which, for every composition `I`, sends the 

fundamental quasisymmetric function `F_I` to `F_{I^c}`, where 

`I^c` denotes the complement of the composition `I`. 

The map `\psi` is an involution and a graded Hopf algebra 

automorphism of `QSym`. Its restriction to the ring of 

symmetric functions coincides with the omega automorphism of 

the latter ring. 

 

The involution `\psi` of `QSym` is adjoint to the involution 

`\psi` of `NCSF` by the standard adjunction between `NCSF` and 

`QSym`. 

 

The involution `\psi` has been denoted by `\psi` in [LMvW13]_, 

section 3.6. 

 

.. SEEALSO:: 

 

:meth:`psi involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.psi_involution>`, 

:meth:`psi involution on NCSF 

<sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Bases.ElementMethods.psi_involution>`, 

:meth:`star involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.star_involution>`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: M = QSym.M() 

sage: M[3,2].psi_involution() 

-M[3, 2] - M[5] 

sage: M[3,1].psi_involution() 

M[3, 1] + M[4] 

sage: M[3,1,1].psi_involution() 

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

sage: M[1,1,1].psi_involution() 

M[1, 1, 1] + M[1, 2] + M[2, 1] + M[3] 

sage: M[[]].psi_involution() 

M[] 

sage: M(0).psi_involution() 

0 

sage: (2*M[[]] - M[3,1] + 4*M[2]).psi_involution() 

2*M[] - 4*M[2] - M[3, 1] - M[4] 

 

This particular implementation is tailored to the monomial 

basis. It is semantically equivalent to the generic 

implementation it overshadows:: 

 

sage: F = QSym.F() 

sage: all( F(M[I].psi_involution()) == F(M[I]).psi_involution() 

....: for I in Compositions(3) ) 

True 

 

sage: F = QSym.F() 

sage: all( F(M[I].psi_involution()) == F(M[I]).psi_involution() 

....: for I in Compositions(4) ) 

True 

""" 

parent = self.parent() 

return parent.sum( (-1) ** (I.size() - len(I)) * coeff 

* parent.sum_of_fatter_compositions(I) 

for I, coeff in 

self._monomial_coefficients.items() ) 

 

def expand(self, n, alphabet='x'): 

r""" 

Expand the quasi-symmetric function written in the monomial basis in 

`n` variables. 

 

INPUT: 

 

- ``n`` -- an integer 

- ``alphabet`` -- (default: ``'x'``) a string 

 

OUTPUT: 

 

- The quasi-symmetric function ``self`` expressed in the ``n`` variables 

described by ``alphabet``. 

 

.. TODO:: accept an *alphabet* as input 

 

EXAMPLES:: 

 

sage: M = QuasiSymmetricFunctions(QQ).Monomial() 

sage: M[4,2].expand(3) 

x0^4*x1^2 + x0^4*x2^2 + x1^4*x2^2 

 

One can use a different set of variables by using the 

optional argument ``alphabet``:: 

 

sage: M=QuasiSymmetricFunctions(QQ).Monomial() 

sage: M[2,1,1].expand(4,alphabet='y') 

y0^2*y1*y2 + y0^2*y1*y3 + y0^2*y2*y3 + y1^2*y2*y3 

 

TESTS:: 

 

sage: (3*M([])).expand(2) 

3 

sage: M[4,2].expand(0) 

0 

sage: M([]).expand(0) 

1 

""" 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

M = self.parent() 

P = PolynomialRing(M.base_ring(), n, alphabet) 

x = P.gens() 

def on_basis(comp, i): 

if not comp: 

return P.one() 

elif len(comp) > i: 

return P.zero() 

else: 

return x[i-1]**comp[-1] * on_basis(comp[:-1], i-1) + \ 

on_basis(comp, i-1) 

return M._apply_module_morphism(self, lambda comp: on_basis(comp,n), 

codomain = P) 

 

def is_symmetric( self ): 

r""" 

Determine if a quasi-symmetric function, written in the Monomial basis, 

is symmetric. 

 

This is being tested by looking at the expansion in the Monomial 

basis and checking if the coefficients are the same if the indexing 

compositions are permutations of each other. 

 

OUTPUT: 

 

- ``True`` if ``self`` is an element of the symmetric 

functions and ``False`` otherwise. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.Monomial() 

sage: (M[3,2] + M[2,3] + M[4,1]).is_symmetric() 

False 

sage: (M[3,2] + M[2,3]).is_symmetric() 

True 

sage: (M[1,2,1] + M[1,1,2]).is_symmetric() 

False 

sage: (M[1,2,1] + M[1,1,2] + M[2,1,1]).is_symmetric() 

True 

""" 

# We must check that every rearrangement of a composition 

# that appears in self appears with the same coefficient. 

# We use a dictionary to keep track of the coefficient 

# and how many rearrangements of the composition we've seen. 

from sage.combinat.permutation import Permutations_mset 

d = {} 

for (I, coeff) in self: 

partition = I.to_partition() 

if partition not in d: 

d[partition] = [coeff, 1] 

else: 

if d[partition][0] != coeff: 

return False 

else: 

d[partition][1] += 1 

# make sure we've seen each rearrangement of the composition 

return all(d[partition][1] == Permutations_mset(partition).cardinality() 

for partition in d) 

 

def to_symmetric_function(self): 

r""" 

Take a quasi-symmetric function, expressed in the monomial basis, and 

return its symmetric realization, when possible, expressed in the 

monomial basis of symmetric functions. 

 

OUTPUT: 

 

- If ``self`` is a symmetric function, then the expansion 

in the monomial basis of the symmetric functions is returned. 

Otherwise an error is raised. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: M = QSym.Monomial() 

sage: (M[3,2] + M[2,3] + M[4,1]).to_symmetric_function() 

Traceback (most recent call last): 

... 

ValueError: M[2, 3] + M[3, 2] + M[4, 1] is not a symmetric function 

sage: (M[3,2] + M[2,3] + 2*M[4,1] + 2*M[1,4]).to_symmetric_function() 

m[3, 2] + 2*m[4, 1] 

sage: m = SymmetricFunctions(QQ).m() 

sage: M(m[3,1,1]).to_symmetric_function() 

m[3, 1, 1] 

sage: (M(m[2,1])*M(m[2,1])).to_symmetric_function()-m[2,1]*m[2,1] 

0 

 

TESTS:: 

 

sage: (M(0)).to_symmetric_function() 

0 

sage: (M([])).to_symmetric_function() 

m[] 

sage: (2*M([])).to_symmetric_function() 

2*m[] 

 

We check that the result is indexed by partitions:: 

 

sage: M([]).to_symmetric_function().leading_support().parent() 

Partitions 

""" 

m = SymmetricFunctions(self.parent().base_ring()).monomial() 

if self.is_symmetric(): 

return m._from_dict({_Partitions(list(I)): coeff 

for I, coeff in self 

if list(I) in _Partitions}, remove_zeros=False) 

else: 

raise ValueError("%s is not a symmetric function"%self) 

 

M = Monomial 

 

class Fundamental(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric functions in the Fundamental basis. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: F = QSym.F() 

sage: M = QSym.M() 

sage: F(M[2,2]) 

F[1, 1, 1, 1] - F[1, 1, 2] - F[2, 1, 1] + F[2, 2] 

sage: s = SymmetricFunctions(QQ).s() 

sage: F(s[3,2]) 

F[1, 2, 2] + F[1, 3, 1] + F[2, 2, 1] + F[2, 3] + F[3, 2] 

sage: (1+F[1])^3 

F[] + 3*F[1] + 3*F[1, 1] + F[1, 1, 1] + 2*F[1, 2] + 3*F[2] + 2*F[2, 1] + F[3] 

sage: F[1,2,1].coproduct() 

F[] # F[1, 2, 1] + F[1] # F[2, 1] + F[1, 1] # F[1, 1] + F[1, 2] # F[1] + F[1, 2, 1] # F[] 

 

The following is an alias for this basis:: 

 

sage: QSym.Fundamental() 

Quasisymmetric functions over the Rational Field in the Fundamental basis 

 

TESTS:: 

 

sage: F(M([])) 

F[] 

sage: F(M(0)) 

0 

sage: F(s([])) 

F[] 

sage: F(s(0)) 

0 

""" 

def __init__(self, QSym): 

""" 

EXAMPLES:: 

 

sage: F = QuasiSymmetricFunctions(QQ).Fundamental(); F 

Quasisymmetric functions over the Rational Field in the Fundamental basis 

sage: TestSuite(F).run() 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='F', bracket=False, 

category=QSym.Bases()) 

 

def dual(self): 

r""" 

Return the dual basis to the Fundamental basis. This is the ribbon 

basis of the non-commutative symmetric functions. 

 

OUTPUT: 

 

- The ribbon basis of the non-commutative symmetric functions. 

 

EXAMPLES:: 

 

sage: F = QuasiSymmetricFunctions(QQ).F() 

sage: F.dual() 

Non-Commutative Symmetric Functions over the Rational Field in the Ribbon basis 

""" 

return self.realization_of().dual().Ribbon() 

 

def antipode_on_basis(self, compo): 

r""" 

Return the antipode to a Fundamental quasi-symmetric basis element. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The result of the antipode applied to the quasi-symmetric 

Fundamental basis element indexed by ``compo``. 

 

EXAMPLES:: 

 

sage: F = QuasiSymmetricFunctions(QQ).F() 

sage: F.antipode_on_basis(Composition([2,1])) 

-F[2, 1] 

""" 

return (-1)**(compo.size()) * self.monomial(compo.conjugate()) 

 

def coproduct_on_basis(self, compo): 

r""" 

Return the coproduct to a Fundamental quasi-symmetric basis element. 

 

Combinatorial rule: quasi-deconcatenation. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The application of the coproduct to the Fundamental quasi-symmetric 

function indexed by the composition ``compo``. 

 

EXAMPLES:: 

 

sage: F = QuasiSymmetricFunctions(QQ).Fundamental() 

sage: F[4].coproduct() 

F[] # F[4] + F[1] # F[3] + F[2] # F[2] + F[3] # F[1] + F[4] # F[] 

sage: F[2,1,3].coproduct() 

F[] # F[2, 1, 3] + F[1] # F[1, 1, 3] + F[2] # F[1, 3] + F[2, 1] # F[3] + F[2, 1, 1] # F[2] + F[2, 1, 2] # F[1] + F[2, 1, 3] # F[] 

 

TESTS:: 

 

sage: F.coproduct_on_basis(Composition([2,1,3])) 

F[] # F[2, 1, 3] + F[1] # F[1, 1, 3] + F[2] # F[1, 3] + F[2, 1] # F[3] + F[2, 1, 1] # F[2] + F[2, 1, 2] # F[1] + F[2, 1, 3] # F[] 

sage: F.one().coproduct() # generic for graded / graded connected 

F[] # F[] 

""" 

T = self.tensor_square() 

C = Composition 

return T.sum_of_monomials( ( C(compo[:i]), C(compo[i:]) ) for i in range(len(compo)+1) ) + \ 

T.sum_of_monomials( ( C(compo[:i]+[j]), C([compo[i]-j]+compo[i+1:]) ) 

for i in range(len(compo)) 

for j in range(1, compo[i]) ) 

 

@cached_method 

def Eulerian(self, n, j, k=None): 

r""" 

Return the Eulerian (quasi)symmetric function `Q_{n,j}` (with 

`n` either an integer or a partition) defined in [SW2010]_ in 

terms of the fundamental quasisymmetric functions. 

Or, if the optional argument ``k`` is specified, return the 

function `Q_{n,j,k}` defined ibidem. 

 

If `n` and `j` are nonnegative integers, then the Eulerian 

quasisymmetric function `Q_{n,j}` is defined as 

 

.. MATH:: 

 

Q_{n,j} := \sum_{\sigma} F_{\mathrm{Dex}(\sigma)}, 

 

where we sum over all permutations `\sigma \in S_n` such that 

the number of excedances of `\sigma` is `j`, and where 

`\mathrm{Dex}(\sigma)` is a composition of `n` defined as follows: 

Let `S` be the set of all `i \in \{ 1, 2, \ldots, n-1 \}` such 

that either `\sigma_i > \sigma_{i+1} > i+1` or 

`i \geq \sigma_i > \sigma_{i+1}` or 

`\sigma_{i+1} > i + 1 > \sigma_i`. Then, 

`\mathrm{Dex}(\sigma)` is set to be the composition of `n` whose 

descent set is `S`. 

 

Here, an excedance of a permutation `\sigma \in S_n` means an 

element `i \in \{ 1, 2, \ldots, n-1 \}` satisfying `\sigma_i > i`. 

 

Similarly we can define a quasisymmetric function `Q_{\lambda, j}` 

for every partition `\lambda` and every nonnegative integer `j`. 

This differs from `Q_{n,j}` only in that the sum is restricted to 

all permutations `\sigma \in S_n` whose cycle type is `\lambda` 

(where `n = |\lambda|`, and where we still require the number of 

excedances to be `j`). The method at hand allows computing these 

functions by passing `\lambda` as the ``n`` parameter. 

 

Analogously we can define a quasisymmetric function `Q_{n,j,k}` for 

any nonnegative integers `n`, `j` and `k` by restricting the sum to 

all permutations `\sigma \in S_n` that have exactly `k` fixed 

points (and `j` excedances). This can be obtained by specifying the 

optional ``k`` argument in this method. 

 

All three versions of Eulerian quasisymmetric functions 

(`Q_{n,j}`, `Q_{\lambda,j}` and `Q_{n,j,k}`) are actually 

symmetric functions. See 

:meth:`~sage.combinat.sf.SymmetricFunctionsBases.ParentMethods.Eulerian`. 

 

INPUT: 

 

- ``n`` -- the nonnegative integer `n` or a partition 

- ``j`` -- the number of excedances 

- ``k`` -- (optional) if specified, determines the number of fixed 

points of the permutations which are being summed over 

 

REFERENCES: 

 

.. [SW2010] John Shareshian and Michelle Wachs. 

*Eulerian quasisymmetric functions*. (2010). 

:arxiv:`0812.0764v2` 

 

EXAMPLES:: 

 

sage: F = QuasiSymmetricFunctions(QQ).F() 

sage: F.Eulerian(3, 1) 

F[1, 2] + F[2, 1] + 2*F[3] 

sage: F.Eulerian(4, 2) 

F[1, 2, 1] + 2*F[1, 3] + 3*F[2, 2] + 2*F[3, 1] + 3*F[4] 

sage: F.Eulerian(5, 2) 

F[1, 1, 2, 1] + F[1, 1, 3] + F[1, 2, 1, 1] + 7*F[1, 2, 2] + 6*F[1, 3, 1] + 6*F[1, 4] + 2*F[2, 1, 2] + 7*F[2, 2, 1] + 11*F[2, 3] + F[3, 1, 1] + 11*F[3, 2] + 6*F[4, 1] + 6*F[5] 

sage: F.Eulerian(4, 0) 

F[4] 

sage: F.Eulerian(4, 3) 

F[4] 

sage: F.Eulerian(4, 1, 2) 

F[1, 2, 1] + F[1, 3] + 2*F[2, 2] + F[3, 1] + F[4] 

sage: F.Eulerian(Partition([2, 2, 1]), 2) 

F[1, 1, 2, 1] + F[1, 2, 1, 1] + 2*F[1, 2, 2] + F[1, 3, 1] 

+ F[1, 4] + F[2, 1, 2] + 2*F[2, 2, 1] + 2*F[2, 3] 

+ 2*F[3, 2] + F[4, 1] + F[5] 

sage: F.Eulerian(0, 0) 

F[] 

sage: F.Eulerian(0, 1) 

0 

sage: F.Eulerian(1, 0) 

F[1] 

sage: F.Eulerian(1, 1) 

0 

 

TESTS:: 

 

sage: F = QuasiSymmetricFunctions(QQ).F() 

sage: F.Eulerian(Partition([3, 1]), 1, 1) 

Traceback (most recent call last): 

... 

ValueError: invalid input, k cannot be specified 

""" 

from sage.combinat.partition import _Partitions 

if n in _Partitions: 

if k is not None: 

raise ValueError("invalid input, k cannot be specified") 

la = _Partitions(n) 

n = sum(la) 

else: 

la = None 

 

if n == 0: 

if k is not None and k != 0: 

return self.zero() 

if j != 0: 

return self.zero() 

return self.one() 

 

monomials = [] 

for p in Permutations(n): 

dex = [] 

exc = 0 

for i in range(n-1): 

if p[i] > i + 1: 

exc += 1 

if (p[i] > p[i+1] or (p[i] <= i+1 and p[i+1] > i+2)) \ 

and not (p[i] > i+1 and p[i+1] <= i+2): 

dex.append(i) 

 

if exc != j: 

continue 

if k is not None and p.number_of_fixed_points() != k: 

continue 

if la is not None and p.cycle_type() != la: 

continue 

 

# Converting to a composition 

d = [-1] + dex + [n-1] 

monomials.append(Compositions()( [d[i+1]-d[i] for i in range(len(d)-1)] )) 

 

return self.sum_of_monomials(monomials) 

 

class Element(CombinatorialFreeModule.Element): 

 

def internal_coproduct(self): 

r""" 

Return the inner coproduct of ``self`` in the Fundamental basis. 

 

The inner coproduct (also known as the Kronecker coproduct, 

or as the second comultiplication on the `R`-algebra of 

quasi-symmetric functions) is an `R`-algebra homomorphism 

`\Delta^{\times}` from the `R`-algebra of quasi-symmetric 

functions to the tensor square (over `R`) of quasi-symmetric 

functions. It can be defined in the following two ways: 

 

#. If `I` is a composition, then a `(0, I)`-matrix will mean a 

matrix whose entries are nonnegative integers such that no 

row and no column of this matrix is zero, and such that if 

all the non-zero entries of the matrix are read (row by row, 

starting at the topmost row, reading every row from left to 

right), then the reading word obtained is `I`. If `A` is 

a `(0, I)`-matrix, then `\mathrm{row}(A)` will denote the 

vector of row sums of `A` (regarded as a composition), and 

`\mathrm{column}(A)` will denote the vector of column sums 

of `A` (regarded as a composition). 

 

For every composition `I`, the internal coproduct 

`\Delta^{\times}(M_I)` of the `I`-th monomial quasisymmetric 

function `M_I` is the sum 

 

.. MATH:: 

 

\sum_{A \hbox{ is a } (0, I) \text{-matrix}} 

M_{\mathrm{row}(A)} \otimes M_{\mathrm{column}(A)}. 

 

See Section 11.39 of [HazWitt1]_. 

 

#. For every permutation `w`, let `C(w)` denote the descent 

composition of `w`. Then, for any composition `I` of size 

`n`, the internal coproduct `\Delta^{\times}(F_I)` of the 

`I`-th fundamental quasisymmetric function `F_I` is the sum 

 

.. MATH:: 

 

\sum_{\substack{\sigma \in S_n,\\ \tau \in S_n,\\ 

\tau \sigma = \pi}} F_{C(\sigma)} \otimes F_{C(\tau)}, 

 

where `\pi` is any permutation in `S_n` having descent 

composition `I` and where permutations act from the left and 

multiply accordingly, so `\tau \sigma` means first applying 

`\sigma` and then `\tau`. See Theorem 4.23 in [Mal1993]_, 

but beware of the notations which are apparently different 

from those in [HazWitt1]_. 

 

The restriction of the internal coproduct to the 

`R`-algebra of symmetric functions is the well-known 

internal coproduct on the symmetric functions. 

 

The method :meth:`kronecker_coproduct` is a synonym of this one. 

 

EXAMPLES: 

 

Let us compute the internal coproduct of `M_{21}` (which is 

short for `M_{[2, 1]}`). The `(0, [2,1])`-matrices are 

 

.. MATH:: 

 

\begin{bmatrix}2& 1\end{bmatrix}, 

\begin{bmatrix}2\\1\end{bmatrix}, 

\begin{bmatrix}2& 0\\0& 1\end{bmatrix}, \hbox{ and } 

\begin{bmatrix}0&2\\1&0\end{bmatrix} 

 

so 

 

.. MATH:: 

 

\Delta^\times(M_{21}) = M_{3} \otimes M_{21} + 

M_{21} \otimes M_3 + M_{21} \otimes M_{21} + 

M_{21} \otimes M_{12}. 

 

This is confirmed by the following Sage computation (incidentally 

demonstrating the non-cocommutativity of the internal 

coproduct):: 

 

sage: M = QuasiSymmetricFunctions(ZZ).M() 

sage: a = M([2,1]) 

sage: a.internal_coproduct() 

M[2, 1] # M[1, 2] + M[2, 1] # M[2, 1] + M[2, 1] # M[3] + M[3] # M[2, 1] 

 

Some examples on the Fundamental basis:: 

 

sage: F = QuasiSymmetricFunctions(ZZ).F() 

sage: F([1,1]).internal_coproduct() 

F[1, 1] # F[2] + F[2] # F[1, 1] 

sage: F([2]).internal_coproduct() 

F[1, 1] # F[1, 1] + F[2] # F[2] 

sage: F([3]).internal_coproduct() 

F[1, 1, 1] # F[1, 1, 1] + F[1, 2] # F[1, 2] + F[1, 2] # F[2, 1] 

+ F[2, 1] # F[1, 2] + F[2, 1] # F[2, 1] + F[3] # F[3] 

sage: F([1,2]).internal_coproduct() 

F[1, 1, 1] # F[1, 2] + F[1, 2] # F[2, 1] + F[1, 2] # F[3] 

+ F[2, 1] # F[1, 1, 1] + F[2, 1] # F[2, 1] + F[3] # F[1, 2] 

""" 

F = self.parent() 

F2 = F.tensor(F) 

result = F2.zero() 

from sage.categories.tensor import tensor 

from sage.combinat.permutation import Permutation 

for I, a in self: 

# We must add a * \Delta^\times(F_I) to result. 

from sage.combinat.permutation import descents_composition_last 

pi = descents_composition_last(I) 

n = I.size() 

for sigma in Permutations(n): 

sigma_inverse = sigma.inverse() 

# If the __mul__ of permutations wasn't such a mess, 

# the next line could be as simple as 

# tau = pi * sigma_inverse. 

tau = Permutation([pi(i) for i in sigma_inverse]) 

result += a * tensor([F(sigma.descents_composition()), 

F(tau.descents_composition())]) 

return result 

 

kronecker_coproduct = internal_coproduct 

 

def star_involution(self): 

r""" 

Return the image of the quasisymmetric function ``self`` under 

the star involution. 

 

The star involution is defined as the linear map 

`QSym \to QSym` which, for every composition `I`, sends the 

monomial quasisymmetric function `M_I` to `M_{I^r}`. Here, if 

`I` is a composition, we denote by `I^r` the reversed 

composition of `I`. Denoting by `f^{\ast}` the image of an 

element `f \in QSym` under the star involution, it can be shown 

that every composition `I` satisfies 

 

.. MATH:: 

 

(M_I)^{\ast} = M_{I^r}, \quad (F_I)^{\ast} = F_{I^r}, 

 

where `F_I` denotes the fundamental quasisymmetric function 

corresponding to the composition `I`. The star involution is an 

involution, an algebra automorphism and a coalgebra 

anti-automorphism of `QSym`. It also is an automorphism of the 

graded vector space `QSym`, and is the identity on the subspace 

`Sym` of `QSym`. It is adjoint to the star involution on `NCSF` 

by the standard adjunction between `NCSF` and `QSym`. 

 

The star involution has been denoted by `\rho` in [LMvW13]_, 

section 3.6. 

 

.. SEEALSO:: 

 

:meth:`star involution on QSym 

<sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Bases.ElementMethods.star_involution>`, 

:meth:`star involution on NCSF 

<sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Bases.ElementMethods.star_involution>`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: F = QSym.F() 

sage: F[3,1].star_involution() 

F[1, 3] 

sage: F[5,3].star_involution() 

F[3, 5] 

sage: (F[9,1] - F[6,2] + 2*F[6,4] - 3*F[3] + 4*F[[]]).star_involution() 

4*F[] + F[1, 9] - F[2, 6] - 3*F[3] + 2*F[4, 6] 

sage: (F[3,3] - 2*F[2]).star_involution() 

-2*F[2] + F[3, 3] 

sage: F([4,2]).star_involution() 

F[2, 4] 

sage: dI = QSym.dI() 

sage: dI([1,2]).star_involution() 

-dI[1, 2] + dI[2, 1] 

sage: dI.zero().star_involution() 

0 

""" 

parent = self.parent() 

dct = {I.reversed(): coeff for (I, coeff) in self} 

return parent._from_dict(dct) 

 

F = Fundamental 

 

class Essential(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric functions in the Essential basis. 

 

The Essential quasi-symmetric functions are defined by 

 

.. MATH:: 

 

E_I = \sum_{J \geq I} M_J = \sum_{i_1 \leq \cdots \leq i_k} 

x_{i_1}^{I_1} \cdots x_{i_k}^{I_k}, 

 

where `I = (I_1, \ldots, I_k)`. 

 

.. NOTE:: 

 

Our convention of `\leq` and `\geq` of compositions is 

opposite that of [Hoff2015]_. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: E = QSym.E() 

sage: M = QSym.M() 

sage: E(M[2,2]) 

E[2, 2] - E[4] 

sage: s = SymmetricFunctions(QQ).s() 

sage: E(s[3,2]) 

5*E[1, 1, 1, 1, 1] - 2*E[1, 1, 1, 2] - 2*E[1, 1, 2, 1] 

- 2*E[1, 2, 1, 1] + E[1, 2, 2] - 2*E[2, 1, 1, 1] 

+ E[2, 1, 2] + E[2, 2, 1] 

sage: (1 + E[1])^3 

E[] + 3*E[1] + 6*E[1, 1] + 6*E[1, 1, 1] - 3*E[1, 2] 

- 3*E[2] - 3*E[2, 1] + E[3] 

sage: E[1,2,1].coproduct() 

E[] # E[1, 2, 1] + E[1] # E[2, 1] + E[1, 2] # E[1] + E[1, 2, 1] # E[] 

 

The following is an alias for this basis:: 

 

sage: QSym.Essential() 

Quasisymmetric functions over the Rational Field in the Essential basis 

 

TESTS:: 

 

sage: E(M([])) 

E[] 

sage: E(M(0)) 

0 

sage: E(s([])) 

E[] 

sage: E(s(0)) 

0 

""" 

def __init__(self, QSym): 

""" 

EXAMPLES:: 

 

sage: E = QuasiSymmetricFunctions(QQ).Essential() 

sage: TestSuite(E).run() 

 

TESTS:: 

 

sage: E = QuasiSymmetricFunctions(QQ).E() 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all(E(M(E[c])) == E[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

sage: all(M(E(M[c])) == M[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='E', bracket=False, 

category=QSym.Bases()) 

 

M = QSym.M() 

category = self.realization_of()._category 

# This changes Monomial into Essential 

M.module_morphism(self.alternating_sum_of_fatter_compositions, 

codomain=self, category=category 

).register_as_coercion() 

# This changes Essential into Monomial 

self.module_morphism(M.sum_of_fatter_compositions, 

codomain=M, category=category 

).register_as_coercion() 

 

def antipode_on_basis(self, compo): 

r""" 

Return the result of the antipode applied to a quasi-symmetric 

Essential basis element. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The result of the antipode applied to the composition ``compo``, 

expressed in the Essential basis. 

 

EXAMPLES:: 

 

sage: E = QuasiSymmetricFunctions(QQ).E() 

sage: E.antipode_on_basis(Composition([2,1])) 

E[1, 2] - E[3] 

sage: E.antipode_on_basis(Composition([])) 

E[] 

 

TESTS:: 

 

sage: E = QuasiSymmetricFunctions(QQ).E() 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all(E(M(E[c]).antipode()) == E[c].antipode() 

....: for n in range(5) for c in Compositions(n)) 

True 

 

sage: all((-1)**len(I) * E[I] == M[I].star_involution().antipode() 

....: for k in [3,4] for I in Compositions(k)) 

True 

""" 

return (-1)**len(compo) * self.alternating_sum_of_fatter_compositions(compo.reversed()) 

 

def coproduct_on_basis(self, compo): 

r""" 

Return the coproduct of a Essential basis element. 

 

Combinatorial rule: deconcatenation. 

 

INPUT: 

 

- ``compo`` -- composition 

 

OUTPUT: 

 

- The coproduct applied to the Essential quasi-symmetric function 

indexed by ``compo``, expressed in the Essential basis. 

 

EXAMPLES:: 

 

sage: E = QuasiSymmetricFunctions(QQ).Essential() 

sage: E[4,2,3].coproduct() 

E[] # E[4, 2, 3] + E[4] # E[2, 3] + E[4, 2] # E[3] + E[4, 2, 3] # E[] 

sage: E.coproduct_on_basis(Composition([])) 

E[] # E[] 

""" 

return self.tensor_square().sum_of_monomials((self._indices(compo[:i]), 

self._indices(compo[i:])) 

for i in range(0,len(compo)+1)) 

 

def product_on_basis(self, I, J): 

""" 

The product on Essential basis elements. 

 

The product of the basis elements indexed by two compositions 

`I` and `J` is the sum of the basis elements indexed by 

compositions `K` in the stuffle product (also called the 

overlapping shuffle product) of `I` and `J` with a 

coefficient of `(-1)^{\ell(I) + \ell(J) - \ell(K)}`, 

where `\ell(C)` is the length of the composition `C`. 

 

INPUT: 

 

- ``I``, ``J`` -- compositions 

 

OUTPUT: 

 

- The product of the Essential quasi-symmetric functions indexed 

by ``I`` and ``J``, expressed in the Essential basis. 

 

EXAMPLES:: 

 

sage: E = QuasiSymmetricFunctions(QQ).E() 

sage: c1 = Composition([2]) 

sage: c2 = Composition([1,3]) 

sage: E.product_on_basis(c1, c2) 

E[1, 2, 3] + E[1, 3, 2] - E[1, 5] + E[2, 1, 3] - E[3, 3] 

sage: E.product_on_basis(c1, Composition([])) 

E[2] 

sage: E.product_on_basis(c1, Composition([3])) 

E[2, 3] + E[3, 2] - E[5] 

 

TESTS:: 

 

sage: E = QuasiSymmetricFunctions(QQ).E() 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all(E(M(E[cp])*M(E[c])) == E[cp]*E[c] # long time 

....: for c in Compositions(3) for cp in Compositions(5)) 

True 

""" 

n = len(I) + len(J) 

return self.sum_of_terms((K, (-1)**(n - len(K))) 

for K in I.shuffle_product(J, overlap=True)) 

 

E = Essential 

 

class Quasisymmetric_Schur(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric function in the Quasisymmetric 

Schur basis. 

 

The basis of Quasisymmetric Schur functions is defined in [QSCHUR]_ 

and in Definition 5.1.1 of [LMvW13]_. 

Don't mistake them for the completely unrelated quasi-Schur 

functions of [NCSF1]_! 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QS = QSym.QS() 

sage: F = QSym.F() 

sage: M = QSym.M() 

sage: F(QS[1,2]) 

F[1, 2] 

sage: M(QS[1,2]) 

M[1, 1, 1] + M[1, 2] 

sage: s = SymmetricFunctions(QQ).s() 

sage: QS(s[2,1,1]) 

QS[1, 1, 2] + QS[1, 2, 1] + QS[2, 1, 1] 

""" 

def __init__(self, QSym): 

r""" 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: F = QSym.Fundamental() 

sage: QS = QSym.Quasisymmetric_Schur() 

sage: QS(F(QS.an_element())) == QS.an_element() 

True 

sage: F(QS(F.an_element())) == F.an_element() 

True 

sage: M = QSym.Monomial() 

sage: QS(M(QS.an_element())) == QS.an_element() 

True 

sage: M(QS(M.an_element())) == M.an_element() 

True 

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

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='QS', bracket=False, 

category=QSym.Bases()) 

 

def _realization_name(self): 

r""" 

Return a nicer name for ``self`` than what is inherited 

from :mod:`sage.categories.sets_cat`. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QS = QSym.QS() 

sage: QS._realization_name() 

'Quasisymmetric Schur' 

""" 

return "Quasisymmetric Schur" 

 

@cached_method 

def _from_monomial_transition_matrix(self, n): 

r""" 

A matrix representing the transition coefficients to 

the complete basis and the ordering of compositions. 

 

INPUT: 

 

- ``n`` -- an integer 

 

OUTPUT: 

 

- a pair of a square matrix and the ordered list of compositions 

 

EXAMPLES:: 

 

sage: QS = QuasiSymmetricFunctions(QQ).QS() 

sage: QS._from_monomial_transition_matrix(4)[0] 

[ 1 -1 -1 0 1 1 1 -1] 

[ 0 1 0 0 -1 -1 0 1] 

[ 0 0 1 -1 0 0 -1 1] 

[ 0 0 0 1 -1 -1 -1 1] 

[ 0 0 0 0 1 0 0 -1] 

[ 0 0 0 0 0 1 0 -1] 

[ 0 0 0 0 0 0 1 -1] 

[ 0 0 0 0 0 0 0 1] 

""" 

if n == 0: 

return (matrix([[]]), []) 

CO = compositions_order(n) 

# ZZ is faster than over QQ for inverting a matrix 

from sage.rings.all import ZZ 

MS = MatrixSpace(ZZ, len(CO)) 

return (MS([[number_of_SSRCT(al,be) for al in CO] for be in CO]).inverse(), 

CO) 

 

@cached_method 

def _from_monomial_on_basis(self, comp): 

r""" 

Maps the Monomial quasi-symmetric function indexed by 

``comp`` to the Quasisymmetric Schur basis. 

 

INPUT: 

 

- ``comp`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the Quasisymmetric Schur basis 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QS = QSym.QS() 

sage: M = QSym.M() 

sage: QS._from_monomial_on_basis(Composition([1,3,1])) 

QS[1, 1, 1, 1, 1] - QS[1, 1, 2, 1] + QS[1, 3, 1] - QS[2, 2, 1] 

sage: QS._from_monomial_on_basis(Composition([2])) 

-QS[1, 1] + QS[2] 

""" 

comp = Composition(comp) 

if not comp._list: 

return self.one() 

T, comps = self._from_monomial_transition_matrix(comp.size()) 

i = comps.index(comp) 

return self._from_dict({c: T[i,j] for j,c in enumerate(comps) 

if T[i,j] != 0}, 

remove_zeros=False) 

 

@cached_method 

def _to_monomial_on_basis(self, comp_shape): 

r""" 

Expand the quasi-symmetric Schur function in the Monomial basis. 

 

The expansion of the quasi-symmetric Schur function indexed 

by ``comp_shape`` has coefficients which are given by the method 

:meth:`~sage.combinat.ncsf_qsym.combinatorics.number_of_SSRCT`. 

 

INPUT: 

 

- ``comp_shape`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the Monomial basis 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: QS = QSym.QS() 

sage: QS._to_monomial_on_basis(Composition([1,3,1])) 

2*M[1, 1, 1, 1, 1] + 2*M[1, 1, 2, 1] + M[1, 2, 1, 1] + M[1, 3, 1] + M[2, 1, 1, 1] + M[2, 2, 1] 

""" 

M = self.realization_of().Monomial() 

if not comp_shape: 

return M([]) 

return M.sum_of_terms(((comp_content, 

number_of_SSRCT(comp_content, comp_shape)) 

for comp_content in Compositions(sum(comp_shape))), 

distinct=True ) 

 

QS = Quasisymmetric_Schur 

 

class dualImmaculate(CombinatorialFreeModule, BindableClass): 

def __init__(self, QSym): 

r""" 

The dual immaculate basis of the quasi-symmetric functions. 

 

This basis first appears in [BBSSZ2012]_. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: dI = QSym.dI() 

sage: dI([1,3,2])*dI([1]) # long time (6s on sage.math, 2013) 

dI[1, 1, 3, 2] + dI[2, 3, 2] 

sage: dI([1,3])*dI([1,1]) 

dI[1, 1, 1, 3] + dI[1, 1, 4] + dI[1, 2, 3] - dI[1, 3, 2] - dI[1, 4, 1] - dI[1, 5] + dI[2, 3, 1] + dI[2, 4] 

sage: dI([3,1])*dI([2,1]) # long time (7s on sage.math, 2013) 

dI[1, 1, 5] - dI[1, 4, 1, 1] - dI[1, 4, 2] - 2*dI[1, 5, 1] - dI[1, 6] - dI[2, 4, 1] - dI[2, 5] - dI[3, 1, 3] + dI[3, 2, 1, 1] + dI[3, 2, 2] + dI[3, 3, 1] + dI[4, 1, 1, 1] + 2*dI[4, 2, 1] + dI[4, 3] + dI[5, 1, 1] + dI[5, 2] 

sage: F = QSym.F() 

sage: dI(F[1,3,1]) 

-dI[1, 1, 1, 2] + dI[1, 1, 2, 1] - dI[1, 2, 2] + dI[1, 3, 1] 

sage: F(dI(F([2,1,3]))) 

F[2, 1, 3] 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='dI', bracket=False, 

category=QSym.Bases()) 

 

def _to_Monomial_on_basis(self, J): 

r""" 

Expand the dual immaculate function labelled by a composition 

``J`` in the quasi-symmetric monomial basis. 

 

INPUT: 

 

- ``J`` -- a composition 

 

OUTPUT: 

 

- A quasi-symmetric function in the monomial basis. 

 

EXAMPLES:: 

 

sage: dI = QuasiSymmetricFunctions(QQ).dI() 

sage: dI._to_Monomial_on_basis(Composition([1,3])) 

M[1, 1, 1, 1] + M[1, 1, 2] + M[1, 2, 1] + M[1, 3] 

sage: dI._to_Monomial_on_basis(Composition([])) 

M[] 

sage: dI._to_Monomial_on_basis(Composition([2,1,2])) 

4*M[1, 1, 1, 1, 1] + 3*M[1, 1, 1, 2] + 2*M[1, 1, 2, 1] + M[1, 1, 3] + M[1, 2, 1, 1] + M[1, 2, 2] + M[2, 1, 1, 1] + M[2, 1, 2] 

""" 

M = self.realization_of().Monomial() 

if not J._list: 

return M([]) 

C = Compositions() 

C_size = Compositions(J.size()) 

return M.sum_of_terms( ( (C(I), number_of_fCT(C(I), J)) for I in C_size ), 

distinct=True ) 

 

@cached_method 

def _matrix_monomial_to_dual_immaculate(self, n): 

r""" 

This function caches the change of basis matrix from the 

quasisymmetric monomial basis to the dual immaculate basis. 

 

INPUT: 

 

- ``J`` -- a composition 

 

OUTPUT: 

 

- A list. Each entry in the list is a row in the 

change-of-basis matrix. 

 

EXAMPLES:: 

 

sage: dI = QuasiSymmetricFunctions(QQ).dI() 

sage: dI._matrix_monomial_to_dual_immaculate(3) 

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

sage: dI._matrix_monomial_to_dual_immaculate(0) 

[[1]] 

""" 

N = NonCommutativeSymmetricFunctions(self.base_ring()) 

I = N.I() 

S = N.S() 

mat = [] 

C = Compositions() 

C_n = Compositions(n) 

for alp in C_n: 

row = [] 

expansion = S(I(C(alp))) 

for bet in C_n: 

row.append(expansion.coefficient(C(bet))) 

mat.append(row) 

return mat 

 

def _from_Monomial_on_basis(self, J): 

r""" 

Expand the monomial quasi-symmetric function labelled by the 

composition ``J`` in the dual immaculate basis. 

 

INPUT: 

 

- ``J`` -- a composition 

 

OUTPUT: 

 

- A quasi-symmetric function in the dual immaculate basis. 

 

EXAMPLES:: 

 

sage: dI = QuasiSymmetricFunctions(QQ).dI() 

sage: dI._from_Monomial_on_basis(Composition([])) 

dI[] 

sage: dI._from_Monomial_on_basis(Composition([2,1])) 

-dI[1, 1, 1] - dI[1, 2] + dI[2, 1] 

sage: dI._from_Monomial_on_basis(Composition([3,1,2])) 

-dI[1, 1, 1, 1, 1, 1] + dI[1, 1, 1, 1, 2] + dI[1, 1, 1, 3] - dI[1, 1, 4] - dI[1, 2, 1, 1, 1] + dI[1, 2, 3] + dI[2, 1, 1, 1, 1] - dI[2, 1, 1, 2] + dI[2, 2, 1, 1] - dI[2, 2, 2] - dI[3, 1, 1, 1] + dI[3, 1, 2] 

""" 

n = J.size() 

C = Compositions() 

C_n = Compositions(n) 

mat = self._matrix_monomial_to_dual_immaculate(n) 

column = C_n.list().index(J) 

return self.sum_of_terms( ( (C(I), mat[C_n.list().index(I)][column]) 

for I in C_n ), 

distinct=True ) 

 

dI = dualImmaculate 

 

class HazewinkelLambda(CombinatorialFreeModule, BindableClass): 

r""" 

The Hazewinkel lambda basis of the quasi-symmetric functions. 

 

This basis goes back to [Haz2004]_, albeit it is indexed in a 

different way here. It is a multiplicative basis in a weak 

sense of this word (the product of any two basis elements is a 

basis element, but of course not the one obtained by 

concatenating the indexing compositions). 

 

In [Haz2004]_, Hazewinkel showed that the `\mathbf{k}`-algebra 

`\mathrm{QSym}` is a polynomial algebra. (The proof is correct 

but rests upon an unproven claim that the lexicographically 

largest term of the `n`-th shuffle power of a Lyndon word is 

the `n`-fold concatenation of this Lyndon word with 

itself, occurring `n!` times in that shuffle power. But this 

can be deduced from Section 2 of [Rad1979]_. See also 

Chapter 6 of [GriRei2014]_, specifically Theorem 6.107, for a 

complete proof.) More precisely, he showed that 

`\mathrm{QSym}` is generated, as a free commutative 

`\mathbf{k}`-algebra, by the elements `\lambda^n(M_I)`, where 

`n` ranges over the positive integers, and `I` ranges over 

all compositions which are Lyndon words and whose entries 

have gcd `1`. Here, `\lambda^n` denotes the `n`-th lambda 

operation as explained in 

:meth:`~sage.combinat.ncsf_qsym.qsym.QuasiSymmetricFunctions.Monomial.lambda_of_monomial`. 

 

Thus, products of these generators form a `\mathbf{k}`-module 

basis of `\mathrm{QSym}`. We index this basis by compositions 

here. More precisely, we define the Hazewinkel lambda basis 

`(\mathrm{HWL}_I)_I` (with `I` ranging over all compositions) 

as follows: 

 

Let `I` be a composition. Let `I = I_1 I_2 \ldots I_k` be the 

Chen-Fox-Lyndon factorization of `I` (see 

:meth:`~sage.combinat.words.finite_word.FiniteWord_class.lyndon_factorization`). 

For every `j \in \{1, 2, \ldots , k\}`, let `g_j` be the 

gcd of the entries of the Lyndon word `I_j`, and let `J_j` be 

the result of dividing the entries of `I_j` by this gcd. Then, 

`\mathrm{HWL}_I` is defined to be 

`\prod_{j=1}^{k} \lambda^{g_j} (M_{J_j})`. 

 

.. TODO:: 

 

The conversion from the M basis to the HWL basis is 

currently implemented in the naive way (inverting the 

base-change matrix in the other direction). This matrix 

is not triangular (not even after any permutations of 

the bases), and there could very well be a faster method 

(the one given by Hazewinkel?). 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ) 

sage: HWL = QSym.HazewinkelLambda() 

sage: M = QSym.M() 

sage: M(HWL([2])) 

M[1, 1] 

sage: M(HWL([1,1])) 

2*M[1, 1] + M[2] 

sage: M(HWL([1,2])) 

M[1, 2] 

sage: M(HWL([2,1])) 

3*M[1, 1, 1] + M[1, 2] + M[2, 1] 

sage: M(HWL(Composition([]))) 

M[] 

sage: HWL(M([1,1])) 

HWL[2] 

sage: HWL(M(Composition([2]))) 

HWL[1, 1] - 2*HWL[2] 

sage: HWL(M([1])) 

HWL[1] 

 

TESTS: 

 

Transforming from the M-basis into the HWL-basis and back 

returns us to where we started:: 

 

sage: all( M(HWL(M[I])) == M[I] for I in Compositions(3) ) 

True 

sage: all( HWL(M(HWL[I])) == HWL[I] for I in Compositions(4) ) 

True 

 

Checking the HWL basis elements corresponding to Lyndon 

words:: 

 

sage: all( M(HWL[Composition(I)]) 

....: == M.lambda_of_monomial([i // gcd(I) for i in I], gcd(I)) 

....: for I in LyndonWords(e=3, k=2) ) 

True 

""" 

 

def __init__(self, QSym): 

r""" 

TESTS:: 

 

sage: HWL = QuasiSymmetricFunctions(QQ).HazewinkelLambda() 

sage: TestSuite(HWL).run() 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='HWL', bracket=False, 

category=QSym.Bases()) 

 

def __init_extra__(self): 

""" 

Set up caches for the transition maps to and from the monomial 

basis, and register them as coercions. 

 

TESTS:: 

 

sage: HWL = QuasiSymmetricFunctions(QQ).HazewinkelLambda() 

sage: M = QuasiSymmetricFunctions(QQ).Monomial() 

sage: M2HWL = HWL.coerce_map_from(M); M2HWL 

Generic morphism: 

From: Quasisymmetric functions over the Rational Field in the Monomial basis 

To: Quasisymmetric functions over the Rational Field in the HazewinkelLambda basis 

sage: HWL2M = M.coerce_map_from(HWL); HWL2M 

Generic morphism: 

From: Quasisymmetric functions over the Rational Field in the HazewinkelLambda basis 

To: Quasisymmetric functions over the Rational Field in the Monomial basis 

sage: HWL2M(HWL[2]) 

M[1, 1] 

sage: M2HWL(M[2]) 

HWL[1, 1] - 2*HWL[2] 

""" 

M = self.realization_of().M() 

category = self.realization_of()._category 

# This changes Monomial into Hazewinkel Lambda 

M.module_morphism(self._from_Monomial_on_basis, 

codomain = self, category = category 

).register_as_coercion() 

# This changes Hazewinkel Lambda into Monomial 

self.module_morphism(self._to_Monomial_on_basis, 

codomain = M, category = category 

).register_as_coercion() 

 

# cache for the coordinates of the elements 

# of the monomial basis with respect to the HWL basis 

self._M_to_self_cache = {} 

# cache for the coordinates of the elements 

# of the HWL basis with respect to the monomial basis 

self._M_from_self_cache = {} 

# cache for transition matrices which contain the coordinates of 

# the elements of the monomial basis with respect to the HWL basis 

self._M_transition_matrices = {} 

# cache for transition matrices which contain the coordinates of 

# the elements of the HWL basis with respect to the monomial basis 

self._M_inverse_transition_matrices = {} 

 

def _precompute_cache(self, n, to_self_cache, from_self_cache, transition_matrices, inverse_transition_matrices, from_self_gen_function): 

""" 

Compute the transition matrices between ``self`` and the 

monomial basis in the homogeneous components of degree `n`. 

The results are not returned, but rather stored in the caches. 

 

This assumes that the transition matrices in all degrees smaller 

than `n` have already been computed and cached! 

 

INPUT: 

 

- ``n`` -- nonnegative integer 

- ``to_self_cache`` -- a cache which stores the coordinates of 

the elements of the monomial basis with respect to the 

basis ``self`` 

- ``from_self_cache`` -- a cache which stores the coordinates 

of the elements of ``self`` with respect to the monomial 

basis 

- ``transition_matrices`` -- a cache for transition matrices 

which contain the coordinates of the elements of the monomial 

basis with respect to ``self`` 

- ``inverse_transition_matrices`` -- a cache for transition 

matrices which contain the coordinates of the elements of 

``self`` with respect to the monomial basis 

- ``from_self_gen_function`` -- a function which takes a 

Lyndon word `I` and returns the Hazewinkel Lambda basis 

element indexed by `I` expanded with respect to the 

monomial basis (as an element of the monomial basis, not as 

a dictionary) 

 

EXAMPLES: 

 

The examples below demonstrate how the caches are built 

step by step using the ``_precompute_cache`` method. In order 

not to influence the outcome of other doctests, we make sure 

not to use the caches internally used by this class, but 

rather to create new caches. This allows us to compute the 

transition matrices for a slight variation of the Hazewinkel 

Lambda basis, namely the basis whose `I`-th element is given 

by the simple formula `\prod_{j=1}^{k} M_{I_j}` instead of 

`\prod_{j=1}^{k} \lambda^{g_j} (M_{J_j})`. We will see that 

this is only a `\QQ`-basis rather than a `\ZZ`-basis (a 

reason why the Ditters conjecture took so long to prove):: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: HWL = QSym.HazewinkelLambda() 

sage: M = QSym.M() 

sage: toy_to_self_cache = {} 

sage: toy_from_self_cache = {} 

sage: toy_transition_matrices = {} 

sage: toy_inverse_transition_matrices = {} 

sage: l = lambda c: [ (i[0],[j for j in sorted(i[1].items())]) for i in sorted(c.items())] 

sage: l(toy_to_self_cache) 

[] 

sage: def toy_gen_function(I): 

....: return M[I] 

sage: HWL._precompute_cache(0, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

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

sage: HWL._precompute_cache(1, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

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

sage: HWL._precompute_cache(2, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

[([], [([], 1)]), ([1], [([1], 1)]), ([1, 1], [([1, 1], 1/2), ([2], -1/2)]), ([2], [([2], 1)])] 

sage: toy_transition_matrices[2] 

[ 1/2 -1/2] 

[ 0 1] 

sage: toy_inverse_transition_matrices[2] 

[2 1] 

[0 1] 

sage: toy_transition_matrices.keys() 

[0, 1, 2] 

 

As we see from the fractions in the transition matrices, this 

is only a basis over `\QQ`, not over `\ZZ`. 

 

Let us try another variation on the definition of the basis: 

`\prod_{j=1}^{k} \lambda^{g_j} (M_{J_j})` will now be replaced 

by `\prod_{j=1}^{k} M_{J_j^{g_j}}`, where `J_g` means the 

`g`-fold concatenation of the composition `J` with itself:: 

 

sage: toy_to_self_cache = {} 

sage: toy_from_self_cache = {} 

sage: toy_transition_matrices = {} 

sage: toy_inverse_transition_matrices = {} 

sage: l = lambda c: [ (i[0],[j for j in sorted(i[1].items())]) for i in sorted(c.items())] 

sage: l(toy_to_self_cache) 

[] 

sage: def toy_gen_function(I): 

....: xs = [i // gcd(I) for i in I] * gcd(I) 

....: return M[xs] 

sage: HWL._precompute_cache(0, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

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

sage: HWL._precompute_cache(1, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

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

sage: HWL._precompute_cache(2, toy_to_self_cache, 

....: toy_from_self_cache, 

....: toy_transition_matrices, 

....: toy_inverse_transition_matrices, 

....: toy_gen_function) 

sage: l(toy_to_self_cache) 

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

 

This appears to form another `\ZZ`-basis of 

`\mathrm{QSym}`, but the appearance is deceiving: it 

fails to span the degree-`9` part of `\mathrm{QSym}`. 

(The corresponding computation is not tested as it takes 

a few minutes.) We have not checked if it spans 

`\mathrm{QSym}` over `\QQ`. 

""" 

# Much of this code is adapted from sage/combinat/sf/dual.py 

base_ring = self.base_ring() 

zero = base_ring.zero() 

 

# Handle the n == 0 case separately 

if n == 0: 

part = self._indices([]) 

one = base_ring.one() 

to_self_cache[ part ] = { part: one } 

from_self_cache[ part ] = { part: one } 

transition_matrices[n] = matrix(base_ring, [[one]]) 

inverse_transition_matrices[n] = matrix(base_ring, [[one]]) 

return 

 

compositions_n = Compositions(n).list() 

len_compositions_n = 2 ** (n-1) # since n > 0 by now. 

M = self.realization_of().M() 

 

# The monomial basis will be called M from now on. 

 

# This contains the data for the transition matrix from the 

# monomial basis M to the Hazewinkel lambda basis self. 

transition_matrix_n = matrix(base_ring, len_compositions_n, len_compositions_n) 

 

# This first section calculates how the basis elements of the 

# Hazewinkel lambda basis self decompose in the monomial 

# basis M. 

 

# For every composition I of size n, expand self[I] in terms 

# of the monomial basis M. 

i = 0 

for I in compositions_n: 

# M_coeffs will be M(self[I])._monomial_coefficients 

M_coeffs = {} 

 

self_I_in_M_basis = M.prod([from_self_gen_function(self._indices(list(J))) 

for J in Word(I).lyndon_factorization()]) 

 

j = 0 

 

for J in compositions_n: 

if J in self_I_in_M_basis._monomial_coefficients: 

sp = self_I_in_M_basis._monomial_coefficients[J] 

M_coeffs[J] = sp 

transition_matrix_n[i,j] = sp 

 

j += 1 

 

from_self_cache[I] = M_coeffs 

i += 1 

 

# Save the transition matrix 

inverse_transition_matrices[n] = transition_matrix_n 

 

# This second section calculates how the basis elements of the 

# monomial basis M expand in terms of the basis B. We do this 

# by inverting the above transition matrix. 

# 

# TODO: The way given in Hazewinkel's [Haz2004]_ paper might 

# be faster. 

inverse_transition = (~transition_matrix_n).change_ring(base_ring) 

# Note that we don't simply write 

# "inverse_transition = ~transition_matrix_n" because that 

# tends to cast the entries of the matrix into a quotient 

# field even if this is unnecessary. 

 

# TODO: This still looks fragile when the base ring is weird! 

# Possibly work over ZZ in this method? 

 

for i in range(len_compositions_n): 

self_coeffs = {} 

for j in range(len_compositions_n): 

if inverse_transition[i,j] != zero: 

self_coeffs[ compositions_n[j] ] = inverse_transition[i,j] 

 

to_self_cache[ compositions_n[i] ] = self_coeffs 

 

transition_matrices[n] = inverse_transition 

 

def _precompute_M(self, n): 

""" 

Compute the transition matrices between ``self`` and the 

monomial basis in the homogeneous components of degree `n` 

(and in those of smaller degree, if not already computed). 

The result is not returned, but rather stored in the cache. 

 

INPUT: 

 

- ``n`` -- nonnegative integer 

 

EXAMPLES: 

 

The examples below demonstrate how the caches of ``self`` are 

built step by step using the ``_precompute_M`` method. This 

demonstration relies on an untouched Hazewinkel Lambda basis 

(because any computations might have filled the cache already). 

We obtain such a basis by choosing a ground ring unlikely to 

appear elsewhere:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ['hell', 'yeah']) 

sage: HWL = QSym.HazewinkelLambda() 

sage: M = QSym.M() 

sage: l = lambda c: [ (i[0],[j for j in sorted(i[1].items())]) for i in sorted(c.items())] 

sage: l(HWL._M_to_self_cache) 

[] 

sage: HWL._precompute_M(0) 

sage: l(HWL._M_to_self_cache) 

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

sage: HWL._precompute_M(1) 

sage: l(HWL._M_to_self_cache) 

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

sage: HWL._precompute_M(2) 

sage: l(HWL._M_to_self_cache) 

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

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

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

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

sage: HWL._M_transition_matrices[2] 

[ 0 1] 

[ 1 -2] 

sage: HWL._M_inverse_transition_matrices[2] 

[2 1] 

[1 0] 

sage: HWL._M_transition_matrices.keys() 

[0, 1, 2] 

 

We did not have to call ``HWL._precompute_M(0)``, 

``HWL._precompute_M(1)`` and ``HWL._precompute_M(2)`` 

in this order; it would be enough to just call 

``HWL._precompute_M(2)``:: 

 

sage: QSym = QuasiSymmetricFunctions(ZZ['lol', 'wut']) 

sage: HWL = QSym.HazewinkelLambda() 

sage: M = QSym.M() 

sage: l = lambda c: [ (i[0],[j for j in sorted(i[1].items())]) for i in sorted(c.items())] 

sage: l(HWL._M_to_self_cache) 

[] 

sage: HWL._precompute_M(2) 

sage: l(HWL._M_to_self_cache) 

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

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

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

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

sage: HWL._precompute_M(1) 

sage: l(HWL._M_to_self_cache) 

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

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

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

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

""" 

l = len(self._M_transition_matrices) 

M = self.realization_of().M() 

if l <= n: 

from sage.misc.cachefunc import cached_function 

from sage.arith.all import gcd 

@cached_function 

def monolambda(I): 

# expansion of self[I] in monomial basis, 

# where I is a composition which is a Lyndon word 

g = gcd(I) 

I_reduced = [i // g for i in I] 

return M.lambda_of_monomial(I_reduced, g) 

for i in range(l, n + 1): 

self._precompute_cache(i, self._M_to_self_cache, 

self._M_from_self_cache, 

self._M_transition_matrices, 

self._M_inverse_transition_matrices, 

monolambda) 

 

def _to_Monomial_on_basis(self, J): 

r""" 

Expand the Hazewinkel Lambda basis element labelled by a 

composition ``J`` in the quasi-symmetric Monomial basis. 

 

INPUT: 

 

- ``J`` -- a composition 

 

OUTPUT: 

 

- A quasi-symmetric function in the Monomial basis. 

 

EXAMPLES:: 

 

sage: HWL = QuasiSymmetricFunctions(QQ).HazewinkelLambda() 

sage: J = Composition([1, 2, 1]) 

sage: HWL._to_Monomial_on_basis(J) 

2*M[1, 1, 2] + M[1, 2, 1] + M[1, 3] + M[2, 2] 

""" 

n = sum(J) 

self._precompute_M(n) 

return self.realization_of().M()._from_dict(self._M_from_self_cache[J]) 

 

def _from_Monomial_on_basis(self, J): 

r""" 

Expand the Monomial quasi-symmetric function labelled by the 

composition ``J`` in the Hazewinkel Lambda basis. 

 

INPUT: 

 

- ``J`` -- a composition 

 

OUTPUT: 

 

- A quasi-symmetric function in the Hazewinkel lambda basis. 

 

EXAMPLES:: 

 

sage: HWL = QuasiSymmetricFunctions(QQ).HazewinkelLambda() 

sage: J = Composition([1, 2, 1]) 

sage: HWL._from_Monomial_on_basis(J) 

-2*HWL[1, 1, 2] + HWL[1, 2, 1] - HWL[1, 3] - HWL[2, 2] + 2*HWL[3, 1] - 2*HWL[4] 

""" 

n = sum(J) 

self._precompute_M(n) 

return self._from_dict(self._M_to_self_cache[J]) 

 

def product_on_basis(self, I, J): 

""" 

The product on Hazewinkel Lambda basis elements. 

 

The product of the basis elements indexed by two compositions 

`I` and `J` is the basis element obtained by concatenating the 

Lyndon factorizations of the words `I` and `J`, then reordering 

the Lyndon factors in nonincreasing order, and finally 

concatenating them in this order (giving a new composition). 

 

INPUT: 

 

- ``I``, ``J`` -- compositions 

 

OUTPUT: 

 

- The product of the Hazewinkel Lambda quasi-symmetric 

functions indexed by ``I`` and ``J``, expressed in the 

Hazewinkel Lambda basis. 

 

EXAMPLES:: 

 

sage: HWL = QuasiSymmetricFunctions(QQ).HazewinkelLambda() 

sage: c1 = Composition([1, 2, 1]) 

sage: c2 = Composition([2, 1, 3, 2]) 

sage: HWL.product_on_basis(c1, c2) 

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

sage: HWL.product_on_basis(c1, Composition([])) 

HWL[1, 2, 1] 

sage: HWL.product_on_basis(Composition([]), Composition([])) 

HWL[] 

 

TESTS:: 

 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all( all( M(HWL[I] * HWL[J]) == M(HWL[I]) * M(HWL[J]) # long time 

....: for I in Compositions(3) ) 

....: for J in Compositions(3) ) 

True 

""" 

from sage.misc.flatten import flatten 

I_factors = [list(i) for i in Word(I).lyndon_factorization()] 

J_factors = [list(j) for j in Word(J).lyndon_factorization()] 

# This uses the convenient fact that comparison of lists in 

# Python works exactly as one wants in Lyndon word theory: 

# [a_1, a_2, ..., a_n] > [b_1, b_2, ..., b_m] if and only if 

# either some i satisfies a_i > b_i and (a_j == b_j for all 

# j < i), or we have n > m and all i <= m satisfy a_i == b_i. 

new_factors = sorted(I_factors + J_factors, reverse=True) 

return self.monomial(self._indices(flatten(new_factors))) 

 

class psi(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric functions in the `\psi` basis. 

 

The `\psi` basis is defined as a rescaled Hopf dual of the `\Psi` 

basis of the non-commutative symmetric functions (see Section 3.1 

of [BDHMN2017]_), where the pairing is 

 

.. MATH:: 

 

(\psi_I, \Psi_J) = z_I \delta_{I,J}, 

 

where `z_I = 1^{m_1} m_1! 2^{m_2} m_2! \cdots` with `m_i` being the 

multiplicity of `i` in the composition `I`. Therefore, we call these 

the *quasi-symmetric power sums of the first kind*. 

 

Using the duality, we can directly define the `\psi` basis by 

 

.. MATH:: 

 

\psi_I = \sum_{J \succ I} z_I / \pi_{I,J} M_J, 

 

where `\pi_{I,J}` is as defined in [NCSF]_. 

 

The `\psi`-basis is well-defined only when the base ring is a 

`\QQ`-algebra. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: psi = QSym.psi(); psi 

Quasisymmetric functions over the Rational Field in the psi basis 

sage: psi.an_element() 

2*psi[] + 2*psi[1] + 3*psi[1, 1] 

sage: p = SymmetricFunctions(QQ).p() 

sage: psi(p[2,2,1]) 

psi[1, 2, 2] + psi[2, 1, 2] + psi[2, 2, 1] 

sage: all(sum(psi(list(al)) for al in Permutations(la))==psi(p(la)) for la in Partitions(6)) 

True 

sage: p = SymmetricFunctions(QQ).p() 

sage: psi(p[3,2,2]) 

psi[2, 2, 3] + psi[2, 3, 2] + psi[3, 2, 2] 

 

Checking the equivalent definition of `\psi_n`:: 

 

sage: def test_psi(n): 

....: psi = QuasiSymmetricFunctions(QQ).psi() 

....: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() 

....: M = matrix([[psi[I].duality_pairing(Psi[J]) 

....: for I in Compositions(n)] 

....: for J in Compositions(n)]) 

....: def z(J): return J.to_partition().centralizer_size() 

....: return M == matrix.diagonal([z(I) for I in Compositions(n)]) 

sage: all(test_psi(k) for k in range(1,5)) 

True 

""" 

def __init__(self, QSym): 

r""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: psi = QuasiSymmetricFunctions(QQ).psi() 

sage: TestSuite(psi).run() 

 

TESTS:: 

 

sage: psi = QuasiSymmetricFunctions(QQ).psi() 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all(psi(M(psi[c])) == psi[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

sage: all(M(psi(M[c])) == M[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='psi', bracket=False, 

category=QSym.Bases()) 

 

category = self.realization_of()._category 

Monomial = self.realization_of().Monomial() 

self.module_morphism(self._to_Monomial_on_basis, 

codomain=Monomial, category=category 

).register_as_coercion() 

Monomial.module_morphism(self._from_Monomial_on_basis, 

codomain=self, category=category 

).register_as_coercion() 

 

def _from_Monomial_on_basis(self, I): 

r""" 

Expand a Monomial basis element indexed by ``I`` in the 

`\psi` basis. 

 

INPUT: 

 

- ``I`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the `\psi` basis 

 

TESTS:: 

 

sage: psi = QuasiSymmetricFunctions(QQ).psi() 

sage: I = Composition([2, 3, 2]) 

sage: psi._from_Monomial_on_basis(I) 

1/2*psi[2, 3, 2] - 2/5*psi[2, 5] - 3/5*psi[5, 2] + 2/7*psi[7] 

""" 

R = self.base_ring() 

minus_one = -R.one() 

def z(J): return R(J.to_partition().centralizer_size()) 

return self._from_dict({J: minus_one**(len(I)-len(J)) / z(J) * coeff_lp(I, J) 

for J in I.fatter()}) 

 

def _to_Monomial_on_basis(self, I): 

r""" 

Expand a `\psi` basis element indexed by ``I`` in the 

Monomial basis. 

 

INPUT: 

 

- ``I`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the Monomial basis 

 

TESTS:: 

 

sage: psi = QuasiSymmetricFunctions(QQ).psi() 

sage: I = Composition([2, 3, 2]) 

sage: psi._to_Monomial_on_basis(I) 

2*M[2, 3, 2] + 4/5*M[2, 5] + 6/5*M[5, 2] + 12/35*M[7] 

""" 

R = self.base_ring() 

z = R(I.to_partition().centralizer_size()) 

Monomial = self.realization_of().Monomial() 

return Monomial._from_dict({J: z / coeff_pi(I,J) for J in I.fatter()}) 

 

class phi(CombinatorialFreeModule, BindableClass): 

r""" 

The Hopf algebra of quasi-symmetric functions in the `\phi` basis. 

 

The `\phi` basis is defined as a rescaled Hopf dual of the `\Phi` 

basis of the non-commutative symmetric functions (see Section 3.1 

of [BDHMN2017]_), where the pairing is 

 

.. MATH:: 

 

(\phi_I, \Phi_J) = z_I \delta_{I,J}, 

 

where `z_I = 1^{m_1} m_1! 2^{m_2} m_2! \cdots` with `m_i` being the 

multiplicity of `i` in the composition `I`. Therefore, we call these 

the *quasi-symmetric power sums of the second kind*. 

 

Using the duality, we can directly define the `\phi` basis by 

 

.. MATH:: 

 

\phi_I = \sum_{J \succ I} z_I / sp_{I,J} M_J, 

 

where `sp_{I,J}` is as defined in [NCSF]_. 

 

The `\phi`-basis is well-defined only when the base ring is a 

`\QQ`-algebra. 

 

EXAMPLES:: 

 

sage: QSym = QuasiSymmetricFunctions(QQ) 

sage: phi = QSym.phi(); phi 

Quasisymmetric functions over the Rational Field in the phi basis 

sage: phi.an_element() 

2*phi[] + 2*phi[1] + 3*phi[1, 1] 

sage: p = SymmetricFunctions(QQ).p() 

sage: phi(p[2,2,1]) 

phi[1, 2, 2] + phi[2, 1, 2] + phi[2, 2, 1] 

sage: all(sum(phi(list(al)) for al in Permutations(la))==phi(p(la)) for la in Partitions(6)) 

True 

sage: p = SymmetricFunctions(QQ).p() 

sage: phi(p[3,2,2]) 

phi[2, 2, 3] + phi[2, 3, 2] + phi[3, 2, 2] 

 

Checking the equivalent definition of `\phi_n`:: 

 

sage: def test_phi(n): 

....: phi = QuasiSymmetricFunctions(QQ).phi() 

....: Phi = NonCommutativeSymmetricFunctions(QQ).Phi() 

....: M = matrix([[phi[I].duality_pairing(Phi[J]) 

....: for I in Compositions(n)] 

....: for J in Compositions(n)]) 

....: def z(J): return J.to_partition().centralizer_size() 

....: return M == matrix.diagonal([z(I) for I in Compositions(n)]) 

sage: all(test_phi(k) for k in range(1,5)) 

True 

""" 

def __init__(self, QSym): 

r""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: phi = QuasiSymmetricFunctions(QQ).phi() 

sage: TestSuite(phi).run() 

 

TESTS:: 

 

sage: phi = QuasiSymmetricFunctions(QQ).phi() 

sage: M = QuasiSymmetricFunctions(QQ).M() 

sage: all(phi(M(phi[c])) == phi[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

sage: all(M(phi(M[c])) == M[c] for n in range(5) 

....: for c in Compositions(n)) 

True 

""" 

CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(), 

prefix='phi', bracket=False, 

category=QSym.Bases()) 

 

category = self.realization_of()._category 

Monomial = self.realization_of().Monomial() 

self.module_morphism(self._to_Monomial_on_basis, 

codomain=Monomial, category=category 

).register_as_coercion() 

Monomial.module_morphism(self._from_Monomial_on_basis, 

codomain=self, category=category 

).register_as_coercion() 

 

def _from_Monomial_on_basis(self, I): 

r""" 

Expand a Monomial basis element indexed by ``I`` in the 

`\phi` basis. 

 

INPUT: 

 

- ``I`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the `\psi` basis 

 

TESTS:: 

 

sage: phi = QuasiSymmetricFunctions(QQ).phi() 

sage: I = Composition([3, 2, 2]) 

sage: phi._from_Monomial_on_basis(I) 

1/2*phi[3, 2, 2] - 1/2*phi[3, 4] - 1/2*phi[5, 2] + 1/3*phi[7] 

""" 

R = self.base_ring() 

minus_one = -R.one() 

def z(J): return R(J.to_partition().centralizer_size()) 

return self._from_dict({J: minus_one**(len(I)-len(J)) * R.prod(J) / (coeff_ell(I, J) * z(J)) 

for J in I.fatter()}) 

 

def _to_Monomial_on_basis(self, I): 

r""" 

Expand a `\phi` basis element indexed by ``I`` in the 

Monomial basis. 

 

INPUT: 

 

- ``I`` -- a composition 

 

OUTPUT: 

 

- a quasi-symmetric function in the Monomial basis 

 

TESTS:: 

 

sage: phi = QuasiSymmetricFunctions(QQ).phi() 

sage: I = Composition([3, 2, 2]) 

sage: phi._to_Monomial_on_basis(I) 

2*M[3, 2, 2] + M[3, 4] + M[5, 2] + 1/3*M[7] 

""" 

R = self.base_ring() 

z = R(I.to_partition().centralizer_size()) 

Monomial = self.realization_of().Monomial() 

return Monomial._from_dict({J: z / coeff_sp(I,J) for J in I.fatter()})