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

r""" 

Clifford Algebras 

 

AUTHORS: 

 

- Travis Scrimshaw (2013-09-06): Initial version 

""" 

 

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

# Copyright (C) 2013 Travis Scrimshaw <tscrim at ucdavis.edu> 

# 

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

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

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

# (at your option) any later version. 

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

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

from six import iteritems 

 

from sage.misc.six import with_metaclass 

from sage.misc.cachefunc import cached_method 

from sage.structure.unique_representation import UniqueRepresentation 

from copy import copy 

 

from sage.categories.algebras_with_basis import AlgebrasWithBasis 

from sage.categories.hopf_algebras_with_basis import HopfAlgebrasWithBasis 

from sage.modules.with_basis.morphism import ModuleMorphismByLinearity 

from sage.categories.poor_man_map import PoorManMap 

from sage.rings.all import ZZ 

from sage.modules.free_module import FreeModule, FreeModule_generic 

from sage.matrix.constructor import Matrix 

from sage.matrix.matrix_space import MatrixSpace 

from sage.sets.family import Family 

from sage.combinat.free_module import CombinatorialFreeModule 

from sage.combinat.subset import SubsetsSorted 

from sage.quadratic_forms.quadratic_form import QuadraticForm 

from sage.algebras.weyl_algebra import repr_from_monomials 

from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass 

 

 

class CliffordAlgebraElement(CombinatorialFreeModule.Element): 

""" 

An element in a Clifford algebra. 

 

TESTS:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1, 2, 3, 4, 5, 6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = ((x^3-z)*x + y)^2 

sage: TestSuite(elt).run() 

""" 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

TESTS:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: ((x^3-z)*x + y)^2 

-2*x*y*z - x*z + 5*x - 4*y + 2*z + 2 

sage: Cl.zero() 

0 

""" 

return repr_from_monomials(self.list(), self.parent()._repr_term) 

 

def _latex_(self): 

r""" 

Return a `\LaTeX` representation of ``self``. 

 

TESTS:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: latex( ((x^3-z)*x + y)^2 ) 

-2 x y z - x z + 5 x - 4 y + 2 z + 2 

sage: Cl.<x0,x1,x2> = CliffordAlgebra(Q) 

sage: latex( (x1 - x2)*x0 + 5*x0*x1*x2 ) 

5 x_{0} x_{1} x_{2} - x_{0} x_{1} + x_{0} x_{2} - 1 

""" 

return repr_from_monomials(self.list(), self.parent()._latex_term, True) 

 

def _mul_(self, other): 

""" 

Return ``self`` multiplied by ``other``. 

 

INPUT: 

 

- ``other`` -- element of the same Clifford algebra as ``self`` 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: (x^3 - z*y)*x*(y*z + x*y*z) 

x*y*z + y*z - 24*x + 12*y + 2*z - 24 

sage: y*x 

-x*y + 2 

sage: z*x 

-x*z + 3 

sage: z*z 

6 

sage: x*0 

0 

sage: 0*x 

0 

""" 

Q = self.parent()._quadratic_form 

zero = self.parent().base_ring().zero() 

d = {} 

 

for ml,cl in self: 

# Distribute the current term ``cl`` * ``ml`` over ``other``. 

cur = copy(other._monomial_coefficients) # The current distribution of the term 

for i in reversed(ml): 

# Distribute the current factor ``e[i]`` (the ``i``-th 

# element of the standard basis). 

next = {} 

# At the end of the following for-loop, ``next`` will be 

# the dictionary describing the element 

# ``e[i]`` * (the element described by the dictionary ``cur``) 

# (where ``e[i]`` is the ``i``-th standard basis vector). 

for mr,cr in iteritems(cur): 

# Commute the factor as necessary until we are in order 

pos = 0 

for j in mr: 

if i <= j: 

break 

# Add the additional term from the commutation 

t = list(mr) 

t.pop(pos) 

t = tuple(t) 

next[t] = next.get(t, zero) + cr * Q[i,j] 

# Note: ``Q[i,j] == Q(e[i]+e[j]) - Q(e[i]) - Q(e[j])`` for 

# ``i != j``, where ``e[k]`` is the ``k``-th standard 

# basis vector. 

cr = -cr 

if next[t] == zero: 

del next[t] 

pos += 1 

 

# Check to see if we have a squared term or not 

t = list(mr) 

if i in t: 

t.remove(i) 

cr *= Q[i,i] 

# Note: ``Q[i,i] == Q(e[i])`` where ``e[i]`` is the 

# ``i``-th standard basis vector. 

else: 

t.insert(pos, i) 

# Note that ``t`` is now sorted. 

t = tuple(t) 

next[t] = next.get(t, zero) + cr 

if next[t] == zero: 

del next[t] 

cur = next 

 

# Add the distributed terms to the total 

for index,coeff in iteritems(cur): 

d[index] = d.get(index, zero) + cl * coeff 

if d[index] == zero: 

del d[index] 

 

return self.__class__(self.parent(), d) 

 

def list(self): 

""" 

Return the list of monomials and their coefficients in ``self`` 

(as a list of `2`-tuples, each of which has the form 

``(monomial, coefficient)``). 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = 5*x + y 

sage: elt.list() 

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

""" 

return sorted(self._monomial_coefficients.items(), key=lambda m_c : (-len(m_c[0]), m_c[0])) 

 

def support(self): 

""" 

Return the support of ``self``. 

 

This is the list of all monomials which appear with nonzero 

coefficient in ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = 5*x + y 

sage: elt.support() 

[(0,), (1,)] 

""" 

return sorted(self._monomial_coefficients.keys(), key=lambda x: (-len(x), x)) 

 

def reflection(self): 

""" 

Return the image of the reflection automorphism on ``self``. 

 

The *reflection automorphism* of a Clifford algebra is defined 

as the linear endomorphism of this algebra which maps 

 

.. MATH:: 

 

x_1 \wedge x_2 \wedge \cdots \wedge x_m \mapsto 

(-1)^m x_1 \wedge x_2 \wedge \cdots \wedge x_m. 

 

It is an algebra automorphism of the Clifford algebra. 

 

:meth:`degree_negation` is an alias for :meth:`reflection`. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = 5*x + y + x*z 

sage: r = elt.reflection(); r 

x*z - 5*x - y 

sage: r.reflection() == elt 

True 

 

TESTS: 

 

We check that the reflection is an involution:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: all(x.reflection().reflection() == x for x in Cl.basis()) 

True 

""" 

return self.__class__(self.parent(), {m: (-1)**len(m) * c for m,c in self}) 

 

degree_negation = reflection 

 

def transpose(self): 

r""" 

Return the transpose of ``self``. 

 

The transpose is an anti-algebra involution of a Clifford algebra 

and is defined (using linearity) by 

 

.. MATH:: 

 

x_1 \wedge x_2 \wedge \cdots \wedge x_m \mapsto 

x_m \wedge \cdots \wedge x_2 \wedge x_1. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = 5*x + y + x*z 

sage: t = elt.transpose(); t 

-x*z + 5*x + y + 3 

sage: t.transpose() == elt 

True 

sage: Cl.one().transpose() 

1 

 

TESTS: 

 

We check that the transpose is an involution:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: all(x.transpose().transpose() == x for x in Cl.basis()) 

True 

 

Zero is sent to zero:: 

 

sage: Cl.zero().transpose() == Cl.zero() 

True 

""" 

P = self.parent() 

if not self._monomial_coefficients: 

return P.zero() 

g = P.gens() 

return P.sum(c * P.prod(g[i] for i in reversed(m)) for m,c in self) 

 

def conjugate(self): 

r""" 

Return the Clifford conjugate of ``self``. 

 

The Clifford conjugate of an element `x` of a Clifford algebra is 

defined as 

 

.. MATH:: 

 

\bar{x} := \alpha(x^t) = \alpha(x)^t 

 

where `\alpha` denotes the :meth:`reflection <reflection>` 

automorphism and `t` the :meth:`transposition <transpose>`. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: elt = 5*x + y + x*z 

sage: c = elt.conjugate(); c 

-x*z - 5*x - y + 3 

sage: c.conjugate() == elt 

True 

 

TESTS: 

 

We check that the conjugate is an involution:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: all(x.conjugate().conjugate() == x for x in Cl.basis()) 

True 

""" 

return self.reflection().transpose() 

 

clifford_conjugate = conjugate 

 

# TODO: This is a general function which should be moved to a 

# superalgebras category when one is implemented. 

def supercommutator(self, x): 

""" 

Return the supercommutator of ``self`` and ``x``. 

 

Let `A` be a superalgebra. The *supercommutator* of homogeneous 

elements `x, y \in A` is defined by 

 

.. MATH:: 

 

[x, y\} = x y - (-1)^{|x| |y|} y x 

 

and extended to all elements by linearity. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: a = x*y - z 

sage: b = x - y + y*z 

sage: a.supercommutator(b) 

-5*x*y + 8*x*z - 2*y*z - 6*x + 12*y - 5*z 

sage: a.supercommutator(Cl.one()) 

0 

sage: Cl.one().supercommutator(a) 

0 

sage: Cl.zero().supercommutator(a) 

0 

sage: a.supercommutator(Cl.zero()) 

0 

 

sage: Q = QuadraticForm(ZZ, 2, [-1,1,-3]) 

sage: Cl.<x,y> = CliffordAlgebra(Q) 

sage: [a.supercommutator(b) for a in Cl.basis() for b in Cl.basis()] 

[0, 0, 0, 0, 0, -2, 1, -x - 2*y, 0, 1, 

-6, 6*x + y, 0, x + 2*y, -6*x - y, 0] 

sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] 

[0, 0, 0, 0, 0, 0, 2*x*y - 1, -x - 2*y, 0, 

-2*x*y + 1, 0, 6*x + y, 0, x + 2*y, -6*x - y, 0] 

 

Exterior algebras inherit from Clifford algebras, so 

supercommutators work as well. We verify the exterior algebra 

is supercommutative:: 

 

sage: E.<x,y,z,w> = ExteriorAlgebra(QQ) 

sage: all(b1.supercommutator(b2) == 0 

....: for b1 in E.basis() for b2 in E.basis()) 

True 

""" 

P = self.parent() 

ret = P.zero() 

for ms,cs in self: 

for mx,cx in x: 

ret += P.term(ms, cs) * P.term(mx, cx) 

s = (-1)**(P.degree_on_basis(ms) * P.degree_on_basis(mx)) 

ret -= s * P.term(mx, cx) * P.term(ms, cs) 

return ret 

 

class CliffordAlgebra(CombinatorialFreeModule): 

r""" 

The Clifford algebra of a quadratic form. 

 

Let `Q : V \to \mathbf{k}` denote a quadratic form on a vector space `V` 

over a field `\mathbf{k}`. The Clifford algebra `Cl(V, Q)` is defined as 

`T(V) / I_Q` where `T(V)` is the tensor algebra of `V` and `I_Q` is the 

two-sided ideal generated by all elements of the form `v \otimes v - Q(v)` 

for all `v \in V`. 

 

We abuse notation to denote the projection of a pure tensor 

`x_1 \otimes x_2 \otimes \cdots \otimes x_m \in T(V)` onto 

`T(V) / I_Q = Cl(V, Q)` by `x_1 \wedge x_2 \wedge \cdots \wedge x_m`. 

This is motivated by the fact that `Cl(V, Q)` is the exterior algebra 

`\wedge V` when `Q = 0` (one can also think of a Clifford algebra as 

a quantization of the exterior algebra). See :class:`ExteriorAlgebra` 

for the concept of an exterior algebra. 

 

From the definition, a basis of `Cl(V, Q)` is given by monomials of 

the form 

 

.. MATH:: 

 

\{ e_{i_1} \wedge \cdots \wedge e_{i_k} \mid 1 \leq i_1 < \cdots < 

i_k \leq n \}, 

 

where `n = \dim(V)` and where `\{ e_1, e_2, \cdots, e_n \}` is any 

fixed basis of `V`. Hence 

 

.. MATH:: 

 

\dim(Cl(V, Q)) = \sum_{k=0}^n \binom{n}{k} = 2^n. 

 

.. NOTE:: 

 

The algebra `Cl(V, Q)` is a `\ZZ / 2\ZZ`-graded algebra, but not 

(in general) `\ZZ`-graded (in a reasonable way). 

 

This construction satisfies the following universal property. Let 

`i : V \to Cl(V, Q)` denote the natural inclusion (which is an 

embedding). Then for every associative `\mathbf{k}`-algebra `A` 

and any `\mathbf{k}`-linear map `j : V \to A` satisfying 

 

.. MATH:: 

 

j(v)^2 = Q(v) \cdot 1_A 

 

for all `v \in V`, there exists a unique `\mathbf{k}`-algebra 

homomorphism `f : Cl(V, Q) \to A` such that `f \circ i = j`. 

This property determines the Clifford algebra uniquely up to 

canonical isomorphism. The inclusion `i` is commonly used to 

identify `V` with a vector subspace of `Cl(V)`. 

 

The Clifford algebra `Cl(V, Q)` is a `\ZZ_2`-graded algebra 

(where `\ZZ_2 = \ZZ / 2 \ZZ`); this grading is determined by 

placing all elements of `V` in degree `1`. It is also an 

`\NN`-filtered algebra, with the filtration too being defined 

by placing all elements of `V` in degree `1`. The :meth:`degree` gives 

the `\NN`-*filtration* degree, and to get the super degree use instead 

:meth:`~sage.categories.super_modules.SuperModules.ElementMethods.is_even_odd`. 

 

The Clifford algebra also can be considered as a covariant functor 

from the category of vector spaces equipped with quadratic forms 

to the category of algebras. In fact, if `(V, Q)` and `(W, R)` 

are two vector spaces endowed with quadratic forms, and if 

`g : W \to V` is a linear map preserving the quadratic form, 

then we can define an algebra morphism 

`Cl(g) : Cl(W, R) \to Cl(V, Q)` by requiring that it send every 

`w \in W` to `g(w) \in V`. Since the quadratic form `R` on `W` 

is uniquely determined by the quadratic form `Q` on `V` (due to 

the assumption that `g` preserves the quadratic form), this fact 

can be rewritten as follows: If `(V, Q)` is a vector space with a 

quadratic form, and `W` is another vector space, and 

`\phi : W \to V` is any linear map, then we obtain an algebra 

morphism `Cl(\phi) : Cl(W, \phi(Q)) \to Cl(V, Q)` where 

`\phi(Q) = \phi^T \cdot Q \cdot \phi` (we consider `\phi` as a 

matrix) is the quadratic form `Q` pulled back to `W`. In fact, the 

map `\phi` preserves the quadratic form because of 

 

.. MATH:: 

 

\phi(Q)(x) = x^T \cdot \phi^T \cdot Q \cdot \phi \cdot x 

= (\phi \cdot x)^T \cdot Q \cdot (\phi \cdot x) = Q(\phi(x)). 

 

Hence we have `\phi(w)^2 = Q(\phi(w)) = \phi(Q)(w)` for all `w \in W`. 

 

REFERENCES: 

 

- :wikipedia:`Clifford_algebra` 

 

INPUT: 

 

- ``Q`` -- a quadratic form 

- ``names`` -- (default: ``'e'``) the generator names 

 

EXAMPLES: 

 

To create a Clifford algebra, all one needs to do is specify a 

quadratic form:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl = CliffordAlgebra(Q) 

sage: Cl 

The Clifford algebra of the Quadratic form in 3 variables 

over Integer Ring with coefficients: 

[ 1 2 3 ] 

[ * 4 5 ] 

[ * * 6 ] 

 

We can also explicitly name the generators. In this example, the 

Clifford algebra we construct is an exterior algebra (since we 

choose the quadratic form to be zero):: 

 

sage: Q = QuadraticForm(ZZ, 4, [0]*10) 

sage: Cl.<a,b,c,d> = CliffordAlgebra(Q) 

sage: a*d 

a*d 

sage: d*c*b*a + a + 4*b*c 

a*b*c*d + 4*b*c + a 

""" 

@staticmethod 

def __classcall_private__(cls, Q, names=None): 

""" 

Normalize arguments to ensure a unique representation. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl1.<e0,e1,e2> = CliffordAlgebra(Q) 

sage: Cl2 = CliffordAlgebra(Q) 

sage: Cl3 = CliffordAlgebra(Q, ['e0','e1','e2']) 

sage: Cl1 is Cl2 and Cl2 is Cl3 

True 

""" 

if not isinstance(Q, QuadraticForm): 

raise ValueError("{} is not a quadratic form".format(Q)) 

if names is None: 

names = 'e' 

names = tuple(names) 

if len(names) != Q.dim(): 

if len(names) == 1: 

names = tuple( '{}{}'.format(names[0], i) for i in range(Q.dim()) ) 

else: 

raise ValueError("the number of variables does not match the number of generators") 

return super(CliffordAlgebra, cls).__classcall__(cls, Q, names) 

 

def __init__(self, Q, names, category=None): 

r""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl = CliffordAlgebra(Q) 

sage: Cl.category() 

Category of finite dimensional super algebras with basis over 

(euclidean domains and infinite enumerated sets and metric spaces) 

sage: TestSuite(Cl).run() 

 

TESTS: 

 

We check that the basis elements are indeed indexed by 

*strictly increasing* tuples:: 

 

sage: Q = QuadraticForm(ZZ, 9) 

sage: Cl = CliffordAlgebra(Q) 

sage: ba = Cl.basis().keys() 

sage: all( tuple(sorted(S)) in ba 

....: for S in Subsets(range(9)) ) 

True 

""" 

self._quadratic_form = Q 

R = Q.base_ring() 

category = AlgebrasWithBasis(R.category()).Super().Filtered().or_subcategory(category) 

indices = SubsetsSorted(range(Q.dim())) 

CombinatorialFreeModule.__init__(self, R, indices, category=category) 

self._assign_names(names) 

 

def _repr_(self): 

r""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: CliffordAlgebra(Q) 

The Clifford algebra of the Quadratic form in 3 variables 

over Integer Ring with coefficients: 

[ 1 2 3 ] 

[ * 4 5 ] 

[ * * 6 ] 

""" 

return "The Clifford algebra of the {}".format(self._quadratic_form) 

 

def _repr_term(self, m): 

""" 

Return a string representation of the basis element indexed by ``m``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl._repr_term((0,2)) 

'x*z' 

sage: Cl._repr_term(()) 

'1' 

sage: Cl._repr_term((1,)) 

'y' 

""" 

if not m: 

return '1' 

term = '' 

for i in m: 

if term: 

term += '*' 

term += self.variable_names()[i] 

return term 

 

def _latex_term(self, m): 

r""" 

Return a `\LaTeX` representation of the basis element indexed 

by ``m``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl._latex_term((0,2)) 

' x z' 

""" 

if not m: 

return '1' 

term = '' 

for i in m: 

term += ' ' + self.latex_variable_names()[i] 

return term 

 

def _coerce_map_from_(self, V): 

""" 

Return if there is a coerce map from ``V`` into ``self``. 

 

The things which coerce into ``self`` are: 

 

- Clifford algebras with the same generator names and an equal 

quadratic form over a ring which coerces into the base 

ring of ``self``. 

- The underlying free module of ``self``. 

- The base ring of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Qp = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) 

sage: Cl = CliffordAlgebra(Q) 

sage: Clp = CliffordAlgebra(Qp) 

sage: Cl.has_coerce_map_from(Clp) 

False 

sage: Clp.has_coerce_map_from(Cl) 

True 

 

Check that we preserve the multiplicative structure:: 

 

sage: all(Clp(b)*Clp(b) == Clp(b*b) for b in Cl.basis()) 

True 

 

Check from the underlying free module:: 

 

sage: M = ZZ^3 

sage: Mp = QQ^3 

sage: Cl.has_coerce_map_from(M) 

True 

sage: Cl.has_coerce_map_from(Mp) 

False 

sage: Clp.has_coerce_map_from(M) 

True 

sage: Clp.has_coerce_map_from(Mp) 

True 

 

Names matter:: 

 

sage: Cln = CliffordAlgebra(Q, names=['x','y','z']) 

sage: Cln.has_coerce_map_from(Cl) 

False 

sage: Cl.has_coerce_map_from(Cln) 

False 

 

Non-injective homomorphisms of base rings don't cause zero 

values in the coordinate dictionary (this had to be manually 

ensured):: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Qp = QuadraticForm(Integers(3), 3, [1,2,3,4,5,6]) 

sage: Cl = CliffordAlgebra(Q) 

sage: Clp = CliffordAlgebra(Qp) 

sage: a = Cl.basis()[(1,2)] 

sage: a 

e1*e2 

sage: Clp(a) # so far so good 

e1*e2 

sage: Clp(3*a) # but now 

0 

sage: Clp(3*a) == 0 

True 

sage: b = Cl.basis()[(0,2)] 

sage: Clp(3*a-4*b) 

2*e0*e2 

""" 

if isinstance(V, CliffordAlgebra): 

Q = self._quadratic_form 

try: 

return (V.variable_names() == self.variable_names() and 

V._quadratic_form.base_change_to(self.base_ring()) == Q) 

except Exception: 

return False 

 

if self.free_module().has_coerce_map_from(V): 

return True 

 

return super(CliffordAlgebra, self)._coerce_map_from_(V) 

 

def _element_constructor_(self, x): 

""" 

Construct an element of ``self`` from ``x``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Qp = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Clp = CliffordAlgebra(Qp, names=['x','y','z']) 

sage: M = ZZ^3 

sage: Mp = QQ^3 

sage: Cl(2/3) 

Traceback (most recent call last): 

... 

TypeError: do not know how to make x (= 2/3) an element of self ...  

sage: Clp(2/3) 

2/3 

sage: Clp(x) 

x 

sage: M = ZZ^3 

sage: Clp( M((1,-3,2)) ) 

x - 3*y + 2*z 

 

Zero coordinates are handled appropriately:: 

 

sage: Q3 = QuadraticForm(Integers(3), 3, [1,2,3,4,5,6]) 

sage: Cl3 = CliffordAlgebra(Q3, names='xyz') # different syntax for a change 

sage: Cl3( M((1,-3,2)) ) 

x + 2*z 

""" 

# This is the natural lift morphism of the underlying free module 

if x in self.free_module(): 

R = self.base_ring() 

if x.parent().base_ring() is R: 

return self.element_class(self, {(i,): c for i,c in iteritems(x)}) 

return self.element_class(self, {(i,): R(c) for i,c in iteritems(x) if R(c) != R.zero()}) 

 

if isinstance(x, CliffordAlgebraElement): 

if x.parent() is self: 

return x 

if self.has_coerce_map_from(x.parent()): 

R = self.base_ring() 

return self.element_class(self, {i: R(c) for i,c in x if R(c) != R.zero()}) 

 

return super(CliffordAlgebra, self)._element_constructor_(x) 

 

def gen(self, i): 

""" 

Return the ``i``-th standard generator of the algebra ``self``. 

 

This is the ``i``-th basis vector of the vector space on which 

the quadratic form defining ``self`` is defined, regarded as an 

element of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: [Cl.gen(i) for i in range(3)] 

[x, y, z] 

""" 

return self._from_dict({(i,): self.base_ring().one()}, remove_zeros=False) 

 

def algebra_generators(self): 

""" 

Return the algebra generators of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.algebra_generators() 

Finite family {'y': y, 'x': x, 'z': z} 

""" 

d = {x: self.gen(i) for i,x in enumerate(self.variable_names())} 

return Family(self.variable_names(), lambda x: d[x]) 

 

def gens(self): 

r""" 

Return the generators of ``self`` (as an algebra). 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.gens() 

(x, y, z) 

""" 

return tuple(self.algebra_generators()) 

 

def ngens(self): 

""" 

Return the number of algebra generators of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.ngens() 

3 

""" 

return self._quadratic_form.dim() 

 

@cached_method 

def one_basis(self): 

""" 

Return the basis index of the element `1`. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.one_basis() 

() 

""" 

return () 

 

def is_commutative(self): 

""" 

Check if ``self`` is a commutative algebra. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.is_commutative() 

False 

""" 

return self._quadratic_form.dim() < 2 

 

def quadratic_form(self): 

""" 

Return the quadratic form of ``self``. 

 

This is the quadratic form used to define ``self``. The 

quadratic form on ``self`` is yet to be implemented. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.quadratic_form() 

Quadratic form in 3 variables over Integer Ring with coefficients: 

[ 1 2 3 ] 

[ * 4 5 ] 

[ * * 6 ] 

""" 

return self._quadratic_form 

 

def degree_on_basis(self, m): 

r""" 

Return the degree of the monomial indexed by ``m``. 

 

We are considering the Clifford algebra to be `\NN`-filtered, 

and the degree of the monomial ``m`` is the length of ``m``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.degree_on_basis((0,)) 

1 

sage: Cl.degree_on_basis((0,1)) 

2 

""" 

return ZZ(len(m)) 

 

def graded_algebra(self): 

""" 

Return the associated graded algebra of ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.graded_algebra() 

The exterior algebra of rank 3 over Integer Ring 

""" 

return ExteriorAlgebra(self.base_ring(), self.variable_names()) 

 

@cached_method 

def free_module(self): 

""" 

Return the underlying free module `V` of ``self``. 

 

This is the free module on which the quadratic form that was 

used to construct ``self`` is defined. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.free_module() 

Ambient free module of rank 3 over the principal ideal domain Integer Ring 

""" 

return FreeModule(self.base_ring(), self._quadratic_form.dim()) 

 

def dimension(self): 

""" 

Return the rank of ``self`` as a free module. 

 

Let `V` be a free `R`-module of rank `n`; then, `Cl(V, Q)` is a 

free `R`-module of rank `2^n`. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.dimension() 

8 

""" 

return ZZ(2)**self._quadratic_form.dim() 

 

def pseudoscalar(self): 

""" 

Return the unit pseudoscalar of ``self``. 

 

Given the basis `e_1, e_2, \ldots, e_n` of the underlying 

`R`-module, the unit pseudoscalar is defined as 

`e_1 \cdot e_2 \cdots e_n`. 

 

This depends on the choice of basis. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.pseudoscalar() 

x*y*z 

 

sage: Q = QuadraticForm(ZZ, 0, []) 

sage: Cl = CliffordAlgebra(Q) 

sage: Cl.pseudoscalar() 

1 

 

REFERENCES: 

 

- :wikipedia:`Classification_of_Clifford_algebras#Unit_pseudoscalar` 

""" 

d = self._quadratic_form.dim() 

return self.element_class(self, {tuple(range(d)): self.base_ring().one()}) 

 

def lift_module_morphism(self, m, names=None): 

r""" 

Lift the matrix ``m`` to an algebra morphism of Clifford algebras. 

 

Given a linear map `m : W \to V` (here represented by a matrix 

acting on column vectors), this method returns the algebra 

morphism `Cl(m) : Cl(W, m(Q)) \to Cl(V, Q)`, where `Cl(V, Q)` 

is the Clifford algebra ``self`` and where `m(Q)` is the pullback 

of the quadratic form `Q` to `W`. See the documentation 

of :class:`CliffordAlgebra` for how this pullback and the 

morphism `Cl(m)` are defined. 

 

.. NOTE:: 

 

This is a map into ``self``. 

 

INPUT: 

 

- ``m`` -- a matrix 

- ``names`` -- (default: ``'e'``) the names of the generators of the 

Clifford algebra of the domain of (the map represented by) ``m`` 

 

OUTPUT: 

 

The algebra morphism `Cl(m)` from `Cl(W, m(Q))` to ``self``. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: m = matrix([[1,-1,-1],[0,1,-1],[1,1,1]]) 

sage: phi = Cl.lift_module_morphism(m, 'abc') 

sage: phi 

Generic morphism: 

From: The Clifford algebra of the Quadratic form in 3 variables over Integer Ring with coefficients: 

[ 10 17 3 ] 

[ * 11 0 ] 

[ * * 5 ] 

To: The Clifford algebra of the Quadratic form in 3 variables over Integer Ring with coefficients: 

[ 1 2 3 ] 

[ * 4 5 ] 

[ * * 6 ] 

sage: a,b,c = phi.domain().gens() 

sage: phi(a) 

x + z 

sage: phi(b) 

-x + y + z 

sage: phi(c) 

-x - y + z 

sage: phi(a + 3*b) 

-2*x + 3*y + 4*z 

sage: phi(a) + 3*phi(b) 

-2*x + 3*y + 4*z 

sage: phi(a*b) 

x*y + 2*x*z - y*z + 7 

sage: phi(b*a) 

-x*y - 2*x*z + y*z + 10 

sage: phi(a*b + c) 

x*y + 2*x*z - y*z - x - y + z + 7 

sage: phi(a*b) + phi(c) 

x*y + 2*x*z - y*z - x - y + z + 7 

 

We check that the map is an algebra morphism:: 

 

sage: phi(a)*phi(b) 

x*y + 2*x*z - y*z + 7 

sage: phi(a*b) 

x*y + 2*x*z - y*z + 7 

sage: phi(a*a) 

10 

sage: phi(a)*phi(a) 

10 

sage: phi(b*a) 

-x*y - 2*x*z + y*z + 10 

sage: phi(b) * phi(a) 

-x*y - 2*x*z + y*z + 10 

sage: phi((a + b)*(a + c)) == phi(a + b) * phi(a + c) 

True 

 

We can also lift arbitrary linear maps:: 

 

sage: m = matrix([[1,1],[0,1],[1,1]]) 

sage: phi = Cl.lift_module_morphism(m, 'ab') 

sage: a,b = phi.domain().gens() 

sage: phi(a) 

x + z 

sage: phi(b) 

x + y + z 

sage: phi(a*b) 

x*y - y*z + 15 

sage: phi(a)*phi(b) 

x*y - y*z + 15 

sage: phi(b*a) 

-x*y + y*z + 12 

sage: phi(b)*phi(a) 

-x*y + y*z + 12 

 

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

sage: phi = Cl.lift_module_morphism(m, 'abcd') 

sage: a,b,c,d = phi.domain().gens() 

sage: phi(a) 

x 

sage: phi(b) 

x + y + z 

sage: phi(c) 

x + y + z 

sage: phi(d) 

2*x + y + z 

sage: phi(a*b*c + d*a) 

-x*y - x*z + 21*x + 7 

sage: phi(a*b*c*d) 

21*x*y + 21*x*z + 42 

""" 

Q = self._quadratic_form(m) 

# If R is a quadratic form and m is a matrix, then R(m) returns 

# the quadratic form m^t R m. 

 

if Q == self._quadratic_form and names is None: 

Cl = self 

else: 

Cl = CliffordAlgebra(Q, names) 

 

n = self._quadratic_form.dim() 

f = lambda x: self.prod(self._from_dict( {(j,): m[j,i] for j in range(n)}, 

remove_zeros=True ) 

for i in x) 

return Cl.module_morphism(on_basis=f, codomain=self, 

category=AlgebrasWithBasis(self.base_ring()).Super()) 

 

def lift_isometry(self, m, names=None): 

r""" 

Lift an invertible isometry ``m`` of the quadratric form of 

``self`` to a Clifford algebra morphism. 

 

Given an invertible linear map `m : V \to W` (here represented by 

a matrix acting on column vectors), this method returns the 

algebra morphism `Cl(m)` from `Cl(V, Q)` to `Cl(W, m^{-1}(Q))`, 

where `Cl(V, Q)` is the Clifford algebra ``self`` and where 

`m^{-1}(Q)` is the pullback of the quadratic form `Q` to `W` along 

the inverse map `m^{-1} : W \to V`. See the documentation of 

:class:`CliffordAlgebra` for how this pullback and the morphism 

`Cl(m)` are defined. 

 

INPUT: 

 

- ``m`` -- an isometry of the quadratic form of ``self`` 

- ``names`` -- (default: ``'e'``) the names of the generators of 

the Clifford algebra of the codomain of (the map represented by) 

``m`` 

 

OUTPUT: 

 

The algebra morphism `Cl(m)` from ``self`` to `Cl(W, m^{-1}(Q))`. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

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

sage: phi = Cl.lift_isometry(m, 'abc') 

sage: phi(x) 

a 

sage: phi(y) 

a + b 

sage: phi(x*y) 

a*b + 1 

sage: phi(x) * phi(y) 

a*b + 1 

sage: phi(z*y) 

a*b - a*c - b*c 

sage: phi(z) * phi(y) 

a*b - a*c - b*c 

sage: phi(x + z) * phi(y + z) == phi((x + z) * (y + z)) 

True 

""" 

MS = m.parent() 

if not m.is_invertible(): 

raise ValueError('{} is not invertible') 

Q = self._quadratic_form(MS(m.inverse())) 

 

if Q == self._quadratic_form and names is None: 

Cl = self 

else: 

if names is None: 

names = 'e' 

Cl = CliffordAlgebra(Q, names) 

 

n = Q.dim() 

f = lambda x: Cl.prod(Cl._from_dict( {(j,): m[j,i] for j in range(n)}, 

remove_zeros=True ) 

for i in x) 

return self.module_morphism(on_basis=f, codomain=Cl, 

category=AlgebrasWithBasis(self.base_ring()).Super()) 

 

# This is a general method for finite dimensional algebras with bases 

# and should be moved to the corresponding category once there is 

# a category level method for getting the indexing set of the basis; 

# similar to #15289 but on a category level. 

@cached_method 

def center_basis(self): 

""" 

Return a list of elements which correspond to a basis for the center 

of ``self``. 

 

This assumes that the ground ring can be used to compute the 

kernel of a matrix. 

 

.. SEEALSO:: 

 

:meth:`supercenter_basis`, 

http://math.stackexchange.com/questions/129183/center-of-clifford-algebra-depending-on-the-parity-of-dim-v 

 

.. TODO:: 

 

Deprecate this in favor of a method called `center()` once 

subalgebras are properly implemented in Sage. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Z = Cl.center_basis(); Z 

(1, -2/5*x*y*z + x - 3/5*y + 2/5*z) 

sage: all(z*b - b*z == 0 for z in Z for b in Cl.basis()) 

True 

 

sage: Q = QuadraticForm(QQ, 3, [1,-2,-3, 4, 2, 1]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Z = Cl.center_basis(); Z 

(1, -x*y*z + x + 3/2*y - z) 

sage: all(z*b - b*z == 0 for z in Z for b in Cl.basis()) 

True 

 

sage: Q = QuadraticForm(QQ, 2, [1,-2,-3]) 

sage: Cl.<x,y> = CliffordAlgebra(Q) 

sage: Cl.center_basis() 

(1,) 

 

sage: Q = QuadraticForm(QQ, 2, [-1,1,-3]) 

sage: Cl.<x,y> = CliffordAlgebra(Q) 

sage: Cl.center_basis() 

(1,) 

 

A degenerate case:: 

 

sage: Q = QuadraticForm(QQ, 3, [4,4,-4,1,-2,1]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.center_basis() 

(1, x*y*z + x - 2*y - 2*z, x*y + x*z - 2*y*z) 

 

The most degenerate case (the exterior algebra):: 

 

sage: Q = QuadraticForm(QQ, 3) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.center_basis() 

(1, x*y, x*z, y*z, x*y*z) 

""" 

R = self.base_ring() 

B = self.basis() 

K = list(B.keys()) 

k = len(K) 

d = {} 

for a,i in enumerate(K): 

Bi = B[i] 

for b,j in enumerate(K): 

Bj = B[j] 

for m,c in (Bi*Bj - Bj*Bi): 

d[(a, K.index(m)+k*b)] = c 

m = Matrix(R, d, nrows=k, ncols=k*k, sparse=True) 

from_vector = lambda x: self.sum_of_terms(((K[i], c) for i,c in iteritems(x)), 

distinct=True) 

return tuple(map( from_vector, m.kernel().basis() )) 

 

# Dense version 

# R = self.base_ring() 

# B = self.basis() 

# K = list(B.keys()) 

# eqns = [[] for dummy in range(k)] 

# for a,i in enumerate(K): 

# for b,j in enumerate(K): 

# v = B[i]*B[j] - B[j]*B[i] 

# eqns[a].extend([v[k] for k in K]) 

# m = Matrix(R, eqns) 

# from_vector = lambda x: self.sum_of_terms(((K[i], c) for i,c in iteritems(x)), 

# distinct=True) 

# return tuple(map( from_vector, m.kernel().basis() )) 

 

# Same as center except for superalgebras 

@cached_method 

def supercenter_basis(self): 

""" 

Return a list of elements which correspond to a basis for the 

supercenter of ``self``. 

 

This assumes that the ground ring can be used to compute the 

kernel of a matrix. 

 

.. SEEALSO:: 

 

:meth:`center_basis`, 

http://math.stackexchange.com/questions/129183/center-of-clifford-algebra-depending-on-the-parity-of-dim-v 

 

.. TODO:: 

 

Deprecate this in favor of a method called `supercenter()` once 

subalgebras are properly implemented in Sage. 

 

EXAMPLES:: 

 

sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: SZ = Cl.supercenter_basis(); SZ 

(1,) 

sage: all(z.supercommutator(b) == 0 for z in SZ for b in Cl.basis()) 

True 

 

sage: Q = QuadraticForm(QQ, 3, [1,-2,-3, 4, 2, 1]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1,) 

 

sage: Q = QuadraticForm(QQ, 2, [1,-2,-3]) 

sage: Cl.<x,y> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1,) 

 

sage: Q = QuadraticForm(QQ, 2, [-1,1,-3]) 

sage: Cl.<x,y> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1,) 

 

Singular vectors of a quadratic form generate in the supercenter:: 

 

sage: Q = QuadraticForm(QQ, 3, [1/2,-2,4,256/249,3,-185/8]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1, x + 249/322*y + 22/161*z) 

 

sage: Q = QuadraticForm(QQ, 3, [4,4,-4,1,-2,1]) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1, x + 2*z, y + z, x*y + x*z - 2*y*z) 

 

The most degenerate case:: 

 

sage: Q = QuadraticForm(QQ, 3) 

sage: Cl.<x,y,z> = CliffordAlgebra(Q) 

sage: Cl.supercenter_basis() 

(1, x, y, z, x*y, x*z, y*z, x*y*z) 

""" 

R = self.base_ring() 

B = self.basis() 

K = list(B.keys()) 

k = len(K) 

d = {} 

for a,i in enumerate(K): 

Bi = B[i] 

for b,j in enumerate(K): 

Bj = B[j] 

if len(i) % 2 and len(j) % 2: 

supercommutator = Bi * Bj + Bj * Bi 

else: 

supercommutator = Bi * Bj - Bj * Bi 

for m,c in supercommutator: 

d[(a, K.index(m)+k*b)] = c 

m = Matrix(R, d, nrows=k, ncols=k*k, sparse=True) 

from_vector = lambda x: self.sum_of_terms(((K[i], c) for i,c in iteritems(x)), 

distinct=True) 

return tuple(map( from_vector, m.kernel().basis() )) 

 

# Dense version 

# R = self.base_ring() 

# B = self.basis() 

# K = list(B.keys()) 

# eqns = [[] for dummy in range(k)] 

# for a,i in enumerate(K): 

# for b,j in enumerate(K): 

# v = B[i].supercommutator(B[j]) # or better an if-loop as above 

# eqns[a].extend([v[k] for k in K]) 

# m = Matrix(R, eqns) 

# from_vector = lambda x: self.sum_of_terms(((K[i], c) for i,c in iteritems(x)), 

# distinct=True) 

# return tuple(map( from_vector, m.kernel().basis() )) 

 

Element = CliffordAlgebraElement 

 

class ExteriorAlgebra(CliffordAlgebra): 

r""" 

An exterior algebra of a free module over a commutative ring. 

 

Let `V` be a module over a commutative ring `R`. The exterior algebra 

(or Grassmann algebra) `\Lambda(V)` of `V` is defined as the quotient 

of the tensor algebra `T(V)` of `V` modulo the two-sided ideal 

generated by all tensors of the form `x \otimes x` with `x \in V`. The 

multiplication on `\Lambda(V)` is denoted by `\wedge` (so 

`v_1 \wedge v_2 \wedge \cdots \wedge v_n` is the projection of 

`v_1 \otimes v_2 \otimes \cdots \otimes v_n` onto `\Lambda(V)`) and 

called the "exterior product" or "wedge product". 

 

If `V` is a rank-`n` free `R`-module with a basis 

`\{e_1, \ldots, e_n\}`, then `\Lambda(V)` is the `R`-algebra 

noncommutatively generated by the `n` generators `e_1, \ldots, e_n` 

subject to the relations `e_i^2 = 0` for all `i`, and 

`e_i e_j = - e_j e_i` for all `i < j`. As an `R`-module, 

`\Lambda(V)` then has a basis `(\bigwedge_{i \in I} e_i)` with `I` 

ranging over the subsets of `\{1, 2, \ldots, n\}` (where 

`\bigwedge_{i \in I} e_i` is the wedge product of `e_i` for `i` 

running through all elements of `I` from smallest to largest), and 

hence is free of rank `2^n`. 

 

The exterior algebra of an `R`-module `V` can also be realized 

as the Clifford algebra of `V` for the quadratic form `Q` given by 

`Q(v) = 0` for all vectors `v \in V`. See :class:`CliffordAlgebra` 

for the notion of a Clifford algebra. 

 

The exterior algebra of an `R`-module `V` is a connected `\ZZ`-graded 

Hopf superalgebra. It is commutative in the super sense (i.e., the 

odd elements anticommute and square to `0`). 

 

This class implements the exterior algebra `\Lambda(R^n)` for 

`n` a nonnegative integer. 

 

.. WARNING:: 

 

We initialize the exterior algebra as an object of the category 

of Hopf algebras, but this is not really correct, since it is a 

Hopf superalgebra with the odd-degree components forming the odd 

part. So use Hopf-algebraic methods with care! 

 

INPUT: 

 

- ``R`` -- the base ring, *or* the free module whose exterior algebra 

is to be computed 

 

- ``names`` -- a list of strings to name the generators of the 

exterior algebra; this list can either have one entry only (in which 

case the generators will be called ``e + '0'``, ``e + '1'``, ..., 

``e + 'n-1'``, with ``e`` being said entry), or have ``n`` entries 

(in which case these entries will be used directly as names for the 

generators) 

 

- ``n`` -- the number of generators, i.e., the rank of the free 

module whose exterior algebra is to be computed (this doesn't have 

to be provided if it can be inferred from the rest of the input) 

 

REFERENCES: 

 

- :wikipedia:`Exterior_algebra` 

""" 

@staticmethod 

def __classcall_private__(cls, R, names=None, n=None): 

""" 

Normalize arguments to ensure a unique representation. 

 

EXAMPLES:: 

 

sage: E1.<e0,e1,e2> = ExteriorAlgebra(QQ) 

sage: E2 = ExteriorAlgebra(QQ, 3) 

sage: E3 = ExteriorAlgebra(QQ, ['e0','e1','e2']) 

sage: E1 is E2 and E2 is E3 

True 

""" 

if names is None: 

names = 'e' 

elif names in ZZ: 

n = names 

names = 'e' 

 

if isinstance(R, FreeModule_generic): 

if n is not None and n != R.dimension(): 

raise ValueError("the number of variables does not match the dimension") 

n = R.dimension() 

R = R.base_ring() 

 

names = tuple(names) 

if n is not None and len(names) != n: 

if len(names) == 1: 

names = tuple( '{}{}'.format(names[0], i) for i in range(n) ) 

else: 

raise ValueError("the number of variables does not match the number of generators") 

return super(ExteriorAlgebra, cls).__classcall__(cls, R, names) 

 

def __init__(self, R, names): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.category() 

Category of finite dimensional super hopf algebras with basis 

over Rational Field 

sage: TestSuite(E).run() 

""" 

cat = HopfAlgebrasWithBasis(R).Super() 

CliffordAlgebra.__init__(self, QuadraticForm(R, len(names)), names, cat) 

# TestSuite will fail if the HopfAlgebra classes will ever have tests for 

# the coproduct being an algebra morphism -- since this is really a 

# Hopf superalgebra, not a Hopf algebra. 

 

def _repr_(self): 

r""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: ExteriorAlgebra(QQ, 3) 

The exterior algebra of rank 3 over Rational Field 

""" 

return "The exterior algebra of rank {} over {}".format(self.ngens(), self.base_ring()) 

 

def _repr_term(self, m): 

""" 

Return a string representation of the basis element indexed by 

``m``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E._repr_term((0,1,2)) 

'x^y^z' 

""" 

if len(m) == 0: 

return '1' 

term = '' 

for i in m: 

if len(term) != 0: 

term += '^' 

term += self.variable_names()[i] 

return term 

 

def _latex_term(self, m): 

r""" 

Return a `\LaTeX` representation of the basis element indexed 

by ``m``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E._latex_term((0,1,2)) 

' x \\wedge y \\wedge z' 

sage: E.<x0,x1,x2> = ExteriorAlgebra(QQ) 

sage: E._latex_term((0,1,2)) 

' x_{0} \\wedge x_{1} \\wedge x_{2}' 

sage: E._latex_term(()) 

'1' 

sage: E._latex_term((0,)) 

' x_{0}' 

""" 

if len(m) == 0: 

return '1' 

term = '' 

for i in m: 

if len(term) != 0: 

term += ' \\wedge' 

term += ' ' + self.latex_variable_names()[i] 

return term 

 

def lift_morphism(self, phi, names=None): 

r""" 

Lift the matrix ``m`` to an algebra morphism of exterior algebras. 

 

Given a linear map `\phi : V \to W` (here represented by a matrix 

acting on column vectors over the base ring of `V`), this method 

returns the algebra morphism 

`\Lambda(\phi) : \Lambda(V) \to \Lambda(W)`. This morphism is defined 

on generators `v_i \in \Lambda(V)` by `v_i \mapsto \phi(v_i)`. 

 

.. NOTE:: 

 

This is the map going out of ``self`` as opposed to 

:meth:`~sage.algebras.clifford_algebra.CliffordAlgebraElement.lift_module_morphism()` 

for general Clifford algebras. 

 

INPUT: 

 

- ``phi`` -- a linear map `\phi` from `V` to `W`, encoded as a 

matrix 

- ``names`` -- (default: ``'e'``) the names of the generators of 

the Clifford algebra of the domain of (the map represented by) 

``phi`` 

 

OUTPUT: 

 

The algebra morphism `\Lambda(\phi)` from ``self`` to `\Lambda(W)`. 

 

EXAMPLES:: 

 

sage: E.<x,y> = ExteriorAlgebra(QQ) 

sage: phi = matrix([[0,1],[1,1],[1,2]]); phi 

[0 1] 

[1 1] 

[1 2] 

sage: L = E.lift_morphism(phi, ['a','b','c']); L 

Generic morphism: 

From: The exterior algebra of rank 2 over Rational Field 

To: The exterior algebra of rank 3 over Rational Field 

sage: L(x) 

b + c 

sage: L(y) 

a + b + 2*c 

sage: L.on_basis()((1,)) 

a + b + 2*c 

sage: p = L(E.one()); p 

1 

sage: p.parent() 

The exterior algebra of rank 3 over Rational Field 

sage: L(x*y) 

-a^b - a^c + b^c 

sage: L(x)*L(y) 

-a^b - a^c + b^c 

sage: L(x + y) 

a + 2*b + 3*c 

sage: L(x) + L(y) 

a + 2*b + 3*c 

sage: L(1/2*x + 2) 

1/2*b + 1/2*c + 2 

sage: L(E(3)) 

3 

 

sage: psi = matrix([[1, -3/2]]); psi 

[ 1 -3/2] 

sage: Lp = E.lift_morphism(psi, ['a']); Lp 

Generic morphism: 

From: The exterior algebra of rank 2 over Rational Field 

To: The exterior algebra of rank 1 over Rational Field 

sage: Lp(x) 

a 

sage: Lp(y) 

-3/2*a 

sage: Lp(x + 2*y + 3) 

-2*a + 3 

""" 

n = phi.nrows() 

R = self.base_ring() 

E = ExteriorAlgebra(R, names, n) 

f = lambda x: E.prod(E._from_dict( {(j,): phi[j,i] for j in range(n)}, 

remove_zeros=True ) 

for i in x) 

return self.module_morphism(on_basis=f, codomain=E, category=AlgebrasWithBasis(R).Super()) 

 

def volume_form(self): 

""" 

Return the volume form of ``self``. 

 

Given the basis `e_1, e_2, \ldots, e_n` of the underlying 

`R`-module, the volume form is defined as `e_1 \wedge e_2 

\wedge \cdots \wedge e_n`. 

 

This depends on the choice of basis. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.volume_form() 

x^y^z 

""" 

d = self._quadratic_form.dim() 

return self.element_class(self, {tuple(range(d)): self.base_ring().one()}) 

 

def boundary(self, s_coeff): 

r""" 

Return the boundary operator `\partial` defined by the structure 

coefficients ``s_coeff`` of a Lie algebra. 

 

For more on the boundary operator, see 

:class:`ExteriorAlgebraBoundary`. 

 

INPUT: 

 

- ``s_coeff`` -- a dictionary whose keys are in `I \times I`, where 

`I` is the index set of the underlying vector space `V`, and whose 

values can be coerced into 1-forms (degree 1 elements) in ``E`` 

(usually, these values will just be elements of `V`) 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

Boundary endomorphism of The exterior algebra of rank 3 over Rational Field 

""" 

return ExteriorAlgebraBoundary(self, s_coeff) 

 

def coboundary(self, s_coeff): 

r""" 

Return the coboundary operator `d` defined by the structure 

coefficients ``s_coeff`` of a Lie algebra. 

 

For more on the coboundary operator, see 

:class:`ExteriorAlgebraCoboundary`. 

 

INPUT: 

 

- ``s_coeff`` -- a dictionary whose keys are in `I \times I`, where 

`I` is the index set of the underlying vector space `V`, and whose 

values can be coerced into 1-forms (degree 1 elements) in ``E`` 

(usually, these values will just be elements of `V`) 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

Coboundary endomorphism of The exterior algebra of rank 3 over Rational Field 

""" 

return ExteriorAlgebraCoboundary(self, s_coeff) 

 

def degree_on_basis(self, m): 

r""" 

Return the degree of the monomial indexed by ``m``. 

 

The degree of ``m`` in the `\ZZ`-grading of ``self`` is defined 

to be the length of ``m``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.degree_on_basis(()) 

0 

sage: E.degree_on_basis((0,)) 

1 

sage: E.degree_on_basis((0,1)) 

2 

""" 

return ZZ(len(m)) 

 

def coproduct_on_basis(self, a): 

r""" 

Return the coproduct on the basis element indexed by ``a``. 

 

The coproduct is defined by 

 

.. MATH:: 

 

\Delta(e_{i_1} \wedge \cdots \wedge e_{i_m}) = \sum_{k=0}^m 

\sum_{\sigma \in Ush_{k,m-k}} (-1)^{\sigma} 

(e_{i_{\sigma(1)}} \wedge \cdots \wedge e_{i_{\sigma(k)}}) \otimes 

(e_{i_{\sigma(k+1)}} \wedge \cdots \wedge e_{i_{\sigma(m)}}), 

 

where `Ush_{k,m-k}` denotes the set of all `(k,m-k)`-unshuffles 

(i.e., permutations in `S_m` which are increasing on the interval 

`\{1, 2, \ldots, k\}` and on the interval 

`\{k+1, k+2, \ldots, k+m\}`). 

 

.. WARNING:: 

 

This coproduct is a homomorphism of superalgebras, not a 

homomorphism of algebras! 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.coproduct_on_basis((0,)) 

1 # x + x # 1 

sage: E.coproduct_on_basis((0,1)) 

1 # x^y + x # y + x^y # 1 - y # x 

sage: E.coproduct_on_basis((0,1,2)) 

1 # x^y^z + x # y^z + x^y # z + x^y^z # 1 

- x^z # y - y # x^z + y^z # x + z # x^y 

""" 

from sage.combinat.combinat import unshuffle_iterator 

one = self.base_ring().one() 

return self.tensor_square().sum_of_terms(unshuffle_iterator(a, one), 

distinct=True) 

 

def antipode_on_basis(self, m): 

r""" 

Return the antipode on the basis element indexed by ``m``. 

 

Given a basis element `\omega`, the antipode is defined by 

`S(\omega) = (-1)^{\deg(\omega)} \omega`. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.antipode_on_basis(()) 

1 

sage: E.antipode_on_basis((1,)) 

-y 

sage: E.antipode_on_basis((1,2)) 

y^z 

""" 

return self.term(m, (-self.base_ring().one())**len(m)) 

 

def counit(self, x): 

""" 

Return the counit of ``x``. 

 

The counit of an element `\omega` of the exterior algebra 

is its constant coefficient. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: elt = x*y - 2*x + 3 

sage: E.counit(elt) 

3 

""" 

return x.constant_coefficient() 

 

def interior_product_on_basis(self, a, b): 

""" 

Return the interior product `\iota_b a` of ``a`` with respect to 

``b``. 

 

See :meth:`~sage.algebras.clifford_algebra.CliffordAlgebra.Element.interior_product` 

for more information. 

 

In this method, ``a`` and ``b`` are supposed to be 

basis elements (see 

:meth:`~sage.algebras.clifford_algebra.CliffordAlgebra.Element.interior_product` 

for a method that computes interior product of arbitrary 

elements), and to be input as their keys. 

 

This depends on the choice of basis of the vector space 

whose exterior algebra is ``self``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: E.interior_product_on_basis((0,), (0,)) 

1 

sage: E.interior_product_on_basis((0,2), (0,)) 

z 

sage: E.interior_product_on_basis((1,), (0,2)) 

0 

sage: E.interior_product_on_basis((0,2), (1,)) 

0 

sage: E.interior_product_on_basis((0,1,2), (0,2)) 

-y 

""" 

sgn = True 

t = list(a) 

for i in b: 

if i not in t: 

return self.zero() 

if t.index(i) % 2: 

sgn = not sgn 

t.remove(i) 

R = self.base_ring() 

return self.term(tuple(t), (R.one() if sgn else - R.one())) 

 

def lifted_bilinear_form(self, M): 

r""" 

Return the bilinear form on the exterior algebra ``self`` 

`= \Lambda(V)` which is obtained by lifting the bilinear 

form `f` on `V` given by the matrix ``M``. 

 

Let `V` be a module over a commutative ring `R`, and let 

`f : V \times V \to R` be a bilinear form on `V`. Then, 

a bilinear form `\Lambda(f) : \Lambda(V) \times 

\Lambda(V) \to R` on `\Lambda(V)` can be canonically 

defined as follows: For every `n \in \NN`, `m \in \NN`, 

`v_1, v_2, \ldots, v_n, w_1, w_2, \ldots, w_m \in V`, 

we define 

 

.. MATH:: 

 

\Lambda(f) 

( v_1 \wedge v_2 \wedge \cdots \wedge v_n , 

w_1 \wedge w_2 \wedge \cdots \wedge w_m ) 

:= \begin{cases} 

0, &\mbox{if } n \neq m ; \\ 

\det G, & \mbox{if } n = m \end{cases} , 

 

where `G` is the `n \times m`-matrix whose 

`(i, j)`-th entry is `f(v_i, w_j)`. This bilinear form 

`\Lambda(f)` is known as the bilinear form on 

`\Lambda(V)` obtained by lifting the bilinear form `f`. 

Its restriction to the `1`-st homogeneous component 

`V` of `\Lambda(V)` is `f`. 

 

The bilinear form `\Lambda(f)` is symmetric if `f` is. 

 

INPUT: 

 

- ``M`` -- a matrix over the same base ring as ``self``, 

whose `(i, j)`-th entry is `f(e_i, e_j)`, where 

`(e_1, e_2, \ldots, e_N)` is the standard basis of the 

module `V` for which ``self`` `= \Lambda(V)` (so that 

`N = \dim(V)`), and where `f` is the bilinear form 

which is to be lifted. 

 

OUTPUT: 

 

A bivariate function which takes two elements `p` and 

`q` of ``self`` to `\Lambda(f)(p, q)`. 

 

.. NOTE:: 

 

This takes a bilinear form on `V` as matrix, and 

returns a bilinear form on ``self`` as a function in 

two arguments. We do not return the bilinear form as 

a matrix since this matrix can be huge and one often 

needs just a particular value. 

 

.. TODO:: 

 

Implement a class for bilinear forms and rewrite this 

method to use that class. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: M = Matrix(QQ, [[1, 2, 3], [2, 3, 4], [3, 4, 5]]) 

sage: Eform = E.lifted_bilinear_form(M) 

sage: Eform 

Bilinear Form from The exterior algebra of rank 3 over Rational 

Field (+) The exterior algebra of rank 3 over Rational Field to 

Rational Field 

sage: Eform(x*y, y*z) 

-1 

sage: Eform(x*y, y) 

0 

sage: Eform(x*(y+z), y*z) 

-3 

sage: Eform(x*(y+z), y*(z+x)) 

0 

sage: N = Matrix(QQ, [[3, 1, 7], [2, 0, 4], [-1, -3, -1]]) 

sage: N.determinant() 

-8 

sage: Eform = E.lifted_bilinear_form(N) 

sage: Eform(x, E.one()) 

0 

sage: Eform(x, x*z*y) 

0 

sage: Eform(E.one(), E.one()) 

1 

sage: Eform(E.zero(), E.one()) 

0 

sage: Eform(x, y) 

1 

sage: Eform(z, y) 

-3 

sage: Eform(x*z, y*z) 

20 

sage: Eform(x+x*y+x*y*z, z+z*y+z*y*x) 

11 

 

TESTS: 

 

Exterior algebra over a zero space (a border case):: 

 

sage: E = ExteriorAlgebra(QQ, 0) 

sage: M = Matrix(QQ, []) 

sage: Eform = E.lifted_bilinear_form(M) 

sage: Eform(E.one(), E.one()) 

1 

sage: Eform(E.zero(), E.one()) 

0 

 

.. TODO:: 

 

Another way to compute this bilinear form seems to be to 

map `x` and `y` to the appropriate Clifford algebra and 

there compute `x^t y`, then send the result back to the 

exterior algebra and return its constant coefficient. Or 

something like this. Once the maps to the Clifford and 

back are implemented, check if this is faster. 

""" 

R = self.base_ring() 

def lifted_form(x, y): 

result = R.zero() 

for mx, cx in x: 

for my, cy in y: 

n = len(mx) 

m = len(my) 

if m != n: 

continue 

MS = MatrixSpace(R, n, n) 

MC = MS._matrix_class 

matrix_list = [M[mx[i], my[j]] 

for i in range(n) 

for j in range(n)] 

matr = MC(MS, matrix_list, copy=False, coerce=False) 

# Using low-level matrix constructor here 

# because Matrix(...) does too much duck 

# typing (trac #17124). 

result += cx * cy * matr.determinant() 

return result 

from sage.categories.cartesian_product import cartesian_product 

return PoorManMap(lifted_form, domain=cartesian_product([self, self]), 

codomain=self.base_ring(), 

name="Bilinear Form") 

 

class Element(CliffordAlgebraElement): 

""" 

An element of an exterior algebra. 

""" 

def _mul_(self, other): 

""" 

Return ``self`` multiplied by ``other``. 

 

INPUT: 

 

- ``other`` -- element of the same exterior algebra as ``self`` 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: x*y 

x^y 

sage: y*x 

-x^y 

sage: z*y*x 

-x^y^z 

sage: (x*z)*y 

-x^y^z 

sage: (3*x + y)^2 

0 

sage: (x - 3*y + z/3)^2 

0 

sage: (x+y) * (y+z) 

x^y + x^z + y^z 

""" 

zero = self.parent().base_ring().zero() 

d = {} 

 

for ml,cl in self: 

for mr,cr in other: 

# Create the next term 

t = list(mr) 

for i in reversed(ml): 

pos = 0 

for j in t: 

if i == j: 

pos = None 

break 

if i < j: 

break 

pos += 1 

cr = -cr 

if pos is None: 

t = None 

break 

t.insert(pos, i) 

 

if t is None: # The next term is 0, move along 

continue 

 

t = tuple(t) 

d[t] = d.get(t, zero) + cl * cr 

if d[t] == zero: 

del d[t] 

 

return self.__class__(self.parent(), d) 

 

def interior_product(self, x): 

r""" 

Return the interior product (also known as antiderivation) of 

``self`` with respect to ``x`` (that is, the element 

`\iota_{x}(\text{self})` of the exterior algebra). 

 

If `V` is an `R`-module, and if `\alpha` is a fixed element of 

`V^*`, then the *interior product* with respect to `\alpha` is 

an `R`-linear map 

`i_{\alpha} \colon \Lambda(V) \to \Lambda(V)`, determined by 

the following requirements: 

 

- `i_{\alpha}(v) = \alpha(v)` for all `v \in V = \Lambda^1(V)`, 

- it is a graded derivation of degree `-1`: all `x` and `y` 

in `\Lambda(V)` satisfy 

 

.. MATH:: 

 

i_{\alpha}(x \wedge y) = (i_{\alpha} x) \wedge y 

+ (-1)^{\deg x} x \wedge (i_{\alpha} y). 

 

It can be shown that this map `i_{\alpha}` is graded of 

degree `-1` (that is, sends `\Lambda^k(V)` into 

`\Lambda^{k-1}(V)` for every `k`). 

 

When `V` is a finite free `R`-module, the interior product can 

also be defined by 

 

.. MATH:: 

 

(i_{\alpha} \omega)(u_1, \ldots, u_k) 

= \omega(\alpha, u_1, \ldots, u_k), 

 

where `\omega \in \Lambda^k(V)` is thought of as an 

alternating multilinear mapping from 

`V^* \times \cdots \times V^*` to `R`. 

 

Since Sage is only dealing with exterior powers of modules 

of the form `R^d` for some nonnegative integer `d`, the 

element `\alpha \in V^*` can be thought of as an element of 

`V` (by identifying the standard basis of `V = R^d` with its 

dual basis). This is how `\alpha` should be passed to this 

method. 

 

We then extend the interior product to all 

`\alpha \in \Lambda (V^*)` by 

 

.. MATH:: 

 

i_{\beta \wedge \gamma} = i_{\gamma} \circ i_{\beta}. 

 

INPUT: 

 

- ``x`` -- element of (or coercing into) `\Lambda^1(V)` 

(for example, an element of `V`); this plays the role of 

`\alpha` in the above definition 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: x.interior_product(x) 

1 

sage: (x + x*y).interior_product(2*y) 

-2*x 

sage: (x*z + x*y*z).interior_product(2*y - x) 

-2*x^z - y^z - z 

sage: x.interior_product(E.one()) 

x 

sage: E.one().interior_product(x) 

0 

sage: x.interior_product(E.zero()) 

0 

sage: E.zero().interior_product(x) 

0 

 

REFERENCES: 

 

- :wikipedia:`Exterior_algebra#Interior_product` 

""" 

P = self.parent() 

return P.sum([c * cx * P.interior_product_on_basis(m, mx) 

for m,c in self for mx,cx in x]) 

 

antiderivation = interior_product 

 

def hodge_dual(self): 

r""" 

Return the Hodge dual of ``self``. 

 

The Hodge dual of an element `\alpha` of the exterior algebra is 

defined as `i_{\alpha} \sigma`, where `\sigma` is the volume 

form 

(:meth:`~sage.algebras.clifford_algebra.ExteriorAlgebra.volume_form`) 

and `i_{\alpha}` denotes the antiderivation function with 

respect to `\alpha` (see :meth:`interior_product` for the 

definition of this). 

 

.. NOTE:: 

 

The Hodge dual of the Hodge dual of a homogeneous element 

`p` of `\Lambda(V)` equals `(-1)^{k(n-k)} p`, where 

`n = \dim V` and `k = \deg(p) = |p|`. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: x.hodge_dual() 

y^z 

sage: (x*z).hodge_dual() 

-y 

sage: (x*y*z).hodge_dual() 

1 

sage: [a.hodge_dual().hodge_dual() for a in E.basis()] 

[1, x, y, z, x^y, x^z, y^z, x^y^z] 

sage: (x + x*y).hodge_dual() 

y^z + z 

sage: (x*z + x*y*z).hodge_dual() 

-y + 1 

sage: E = ExteriorAlgebra(QQ, 'wxyz') 

sage: [a.hodge_dual().hodge_dual() for a in E.basis()] 

[1, -w, -x, -y, -z, w^x, w^y, w^z, x^y, x^z, y^z, 

-w^x^y, -w^x^z, -w^y^z, -x^y^z, w^x^y^z] 

""" 

volume_form = self.parent().volume_form() 

return volume_form.interior_product(self) 

 

def constant_coefficient(self): 

""" 

Return the constant coefficient of ``self``. 

 

.. TODO:: 

 

Define a similar method for general Clifford algebras once 

the morphism to exterior algebras is implemented. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: elt = 5*x + y + x*z + 10 

sage: elt.constant_coefficient() 

10 

sage: x.constant_coefficient() 

0 

""" 

return self._monomial_coefficients.get(self.parent().one_basis(), 

self.base_ring().zero()) 

 

def scalar(self, other): 

r""" 

Return the standard scalar product of ``self`` with ``other``. 

 

The standard scalar product of `x, y \in \Lambda(V)` is 

defined by `\langle x, y \rangle = \langle x^t y \rangle`, where 

`\langle a \rangle` denotes the degree-0 term of `a`, and where 

`x^t` denotes the transpose 

(:meth:`~sage.algebras.clifford_algebra.CliffordAlgebraElement.transpose`) 

of `x`. 

 

.. TODO:: 

 

Define a similar method for general Clifford algebras once 

the morphism to exterior algebras is implemented. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: elt = 5*x + y + x*z 

sage: elt.scalar(z + 2*x) 

0 

sage: elt.transpose() * (z + 2*x) 

-2*x^y + 5*x^z + y^z 

""" 

return (self.transpose() * other).constant_coefficient() 

 

##################################################################### 

## Differentials 

 

class ExteriorAlgebraDifferential(with_metaclass( 

InheritComparisonClasscallMetaclass, 

ModuleMorphismByLinearity, UniqueRepresentation 

)): 

r""" 

Internal class to store the data of a boundary or coboundary of 

an exterior algebra `\Lambda(L)` defined by the structure 

coefficients of a Lie algebra `L`. 

 

See :class:`ExteriorAlgebraBoundary` and 

:class:`ExteriorAlgebraCoboundary` for the actual classes, which 

inherit from this. 

 

.. WARNING:: 

 

This is not a general class for differentials on the exterior 

algebra. 

""" 

@staticmethod 

def __classcall__(cls, E, s_coeff): 

""" 

Standardize the structure coefficients to ensure a unique 

representation. 

 

EXAMPLES:: 

 

sage: from sage.algebras.clifford_algebra import ExteriorAlgebraDifferential 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par1 = ExteriorAlgebraDifferential(E, {(0,1): z, (1,2): x, (2,0): y}) 

sage: par2 = ExteriorAlgebraDifferential(E, {(0,1): z, (1,2): x, (0,2): -y}) 

sage: par3 = ExteriorAlgebraDifferential(E, {(1,0): {2:-1}, (1,2): {0:1}, (2,0):{1:1}}) 

sage: par1 is par2 and par2 is par3 

True 

 

sage: par4 = ExteriorAlgebraDifferential(E, {}) 

sage: par5 = ExteriorAlgebraDifferential(E, {(1,0): 0, (1,2): {}, (0,2): E.zero()}) 

sage: par6 = ExteriorAlgebraDifferential(E, {(1,0): 0, (1,2): 0, (0,2): 0}) 

sage: par4 is par5 and par5 is par6 

True 

""" 

d = {} 

 

for k,v in iteritems(dict(s_coeff)): 

if not v: # Strip terms with 0 

continue 

 

if isinstance(v, dict): 

R = E.base_ring() 

v = E._from_dict({(i,): R(c) for i,c in iteritems(v)}) 

else: 

# Make sure v is in ``E`` 

v = E(v) 

# It's okay if v.degree results in an error 

# (we'd throw a similar error) unless v == 0 (which 

# is what v.list() is testing for) 

if v.list() and v.degree() != 1: 

raise ValueError("elements must be degree 1") 

 

if k[0] < k[1]: 

d[tuple(k)] = v 

else: 

d[(k[1], k[0])] = -v 

 

from sage.sets.family import Family 

return super(ExteriorAlgebraDifferential, cls).__classcall__(cls, E, Family(d)) 

 

def __init__(self, E, s_coeff): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2):x, (2,0):y}) 

sage: TestSuite(par).run() # known bug - morphisms are properly in a category 

""" 

self._s_coeff = s_coeff 

 

# Technically this preserves the grading but with a shift of -1 

cat = AlgebrasWithBasis(E.base_ring()) 

ModuleMorphismByLinearity.__init__(self, domain=E, codomain=E, category=cat) 

 

def homology(self, deg=None, **kwds): 

""" 

Return the homology determined by ``self``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: par.homology() 

{0: Vector space of dimension 1 over Rational Field, 

1: Vector space of dimension 0 over Rational Field, 

2: Vector space of dimension 0 over Rational Field, 

3: Vector space of dimension 1 over Rational Field} 

sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: d.homology() 

{0: Vector space of dimension 1 over Rational Field, 

1: Vector space of dimension 0 over Rational Field, 

2: Vector space of dimension 0 over Rational Field, 

3: Vector space of dimension 1 over Rational Field} 

""" 

return self.chain_complex().homology(deg, **kwds) 

 

class ExteriorAlgebraBoundary(ExteriorAlgebraDifferential): 

r""" 

The boundary `\partial` of an exterior algebra `\Lambda(L)` defined 

by the structure coefficients of `L`. 

 

Let `L` be a Lie algebra. We give the exterior algebra 

`E = \Lambda(L)` a chain complex structure by considering a 

differential `\partial : \Lambda^{k+1}(L) \to \Lambda^k(L)` defined by 

 

.. MATH:: 

 

\partial(x_1 \wedge x_2 \wedge \cdots \wedge x_{k+1}) 

= \sum_{i < j} (-1)^{i+j+1} 

[x_i, x_j] \wedge x_1 \wedge \cdots \wedge \hat{x}_i \wedge \cdots 

\wedge \hat{x}_j \wedge \cdots \wedge x_{k+1} 

 

where `\hat{x}_i` denotes a missing index. The corresponding homology is 

the Lie algebra homology. 

 

INPUT: 

 

- ``E`` -- an exterior algebra of a vector space `L` 

- ``s_coeff`` -- a dictionary whose keys are in `I \times I`, where 

`I` is the index set of the basis of the vector space `L`, and whose 

values can be coerced into 1-forms (degree 1 elements) in ``E``; 

this dictionary will be used to define the Lie algebra structure 

on `L` (indeed, the `i`-th coordinate of the Lie bracket of the 

`j`-th and `k`-th basis vectors of `L` for `j < k` is set to be 

the value at the key `(j, k)` if this key appears in ``s_coeff``, 

or otherwise the negated of the value at the key `(k, j)`) 

 

.. WARNING:: 

 

The values of ``s_coeff`` are supposed to be coercible into 

1-forms in ``E``; but they can also be dictionaries themselves 

(in which case they are interpreted as giving the coordinates of 

vectors in ``L``). In the interest of speed, these dictionaries 

are not sanitized or checked. 

 

.. WARNING:: 

 

For any two distinct elements `i` and `j` of `I`, the dictionary 

``s_coeff`` must have only one of the pairs `(i, j)` and 

`(j, i)` as a key. This is not checked. 

 

EXAMPLES: 

 

We consider the differential given by Lie algebra given by the cross 

product `\times` of `\RR^3`:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: par(x) 

0 

sage: par(x*y) 

z 

sage: par(x*y*z) 

0 

sage: par(x+y-y*z+x*y) 

-x + z 

sage: par(E.zero()) 

0 

 

We check that `\partial \circ \partial = 0`:: 

 

sage: p2 = par * par 

sage: all(p2(b) == 0 for b in E.basis()) 

True 

 

Another example: the Lie algebra `\mathfrak{sl}_2`, which has a 

basis `e,f,h` satisfying `[h,e] = 2e`, `[h,f] = -2f`, and `[e,f] = h`:: 

 

sage: E.<e,f,h> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): h, (2,1): -2*f, (2,0): 2*e}) 

sage: par(E.zero()) 

0 

sage: par(e) 

0 

sage: par(e*f) 

h 

sage: par(f*h) 

2*f 

sage: par(h*f) 

-2*f 

sage: C = par.chain_complex(); C 

Chain complex with at most 4 nonzero terms over Rational Field 

sage: ascii_art(C) 

[ 0 -2 0] [0] 

[ 0 0 2] [0] 

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

0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0 

sage: C.homology() 

{0: Vector space of dimension 1 over Rational Field, 

1: Vector space of dimension 0 over Rational Field, 

2: Vector space of dimension 0 over Rational Field, 

3: Vector space of dimension 1 over Rational Field} 

 

Over the integers:: 

 

sage: C = par.chain_complex(R=ZZ); C 

Chain complex with at most 4 nonzero terms over Integer Ring 

sage: ascii_art(C) 

[ 0 -2 0] [0] 

[ 0 0 2] [0] 

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

0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0 

sage: C.homology() 

{0: Z, 1: C2 x C2, 2: 0, 3: Z} 

 

REFERENCES: 

 

- :wikipedia:`Exterior_algebra#Lie_algebra_homology` 

""" 

def _repr_type(self): 

""" 

TESTS:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: par._repr_type() 

'Boundary' 

""" 

return "Boundary" 

 

def _on_basis(self, m): 

""" 

Return the differential on the basis element indexed by ``m``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: par._on_basis(()) 

0 

sage: par._on_basis((0,)) 

0 

sage: par._on_basis((0,1)) 

z 

sage: par._on_basis((0,2)) 

-y 

sage: par._on_basis((0,1,2)) 

0 

""" 

E = self.domain() 

sc = self._s_coeff 

keys = sc.keys() 

return E.sum((-1)**b * sc[(i,j)] 

* E.monomial(m[:a] + m[a+1:a+b+1] + m[a+b+2:]) 

for a,i in enumerate(m) for b,j in enumerate(m[a+1:]) if (i,j) in keys) 

 

@cached_method 

def chain_complex(self, R=None): 

""" 

Return the chain complex over ``R`` determined by ``self``. 

 

INPUT: 

 

- ``R`` -- the base ring; the default is the base ring of 

the exterior algebra 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: C = par.chain_complex(); C 

Chain complex with at most 4 nonzero terms over Rational Field 

sage: ascii_art(C) 

[ 0 0 1] [0] 

[ 0 -1 0] [0] 

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

0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0 

 

TESTS: 

 

This still works in degree `1`:: 

 

sage: E.<x> = ExteriorAlgebra(QQ) 

sage: par = E.boundary({}) 

sage: C = par.chain_complex(); C 

Chain complex with at most 2 nonzero terms over Rational Field 

sage: ascii_art(C) 

[0] 

0 <-- C_0 <---- C_1 <-- 0 

 

Also in degree `0`:: 

 

sage: E = ExteriorAlgebra(QQ, 0) 

sage: par = E.boundary({}) 

sage: C = par.chain_complex(); C 

Chain complex with at most 1 nonzero terms over Rational Field 

sage: ascii_art(C) 

0 <-- C_0 <-- 0 

""" 

from sage.homology.chain_complex import ChainComplex 

from sage.matrix.constructor import Matrix 

E = self.domain() 

n = E.ngens() 

if R is None: 

R = E.base_ring() 

 

if n == 0: 

# Special case because there are no matrices and thus the 

# ChainComplex constructor needs the dimension of the 

# 0th degree space explicitly given. 

return ChainComplex({1: Matrix(R, [[]])}, degree=-1) 

# If you are reading this because you changed something about 

# the ChainComplex constructor and the doctests are failing: 

# This should return a chain complex with degree -1 and 

# only one nontrivial module, namely a free module of rank 1, 

# situated in degree 0. 

 

# Group the basis into degrees 

basis_by_deg = {deg: [] for deg in range(n+1)} 

for b in E.basis().keys(): 

basis_by_deg[len(b)].append(b) 

 

# Construct the transition matrices 

data = {} 

prev_basis = basis_by_deg[0] 

for deg in range(1,n+1): 

# Make sure within each basis we're sorted by lex 

basis = sorted(basis_by_deg[deg]) 

mat = [] 

for b in basis: 

ret = self._on_basis(b) 

mat.append([ret[p] for p in prev_basis]) 

data[deg] = Matrix(mat).transpose().change_ring(R) 

prev_basis = basis 

 

return ChainComplex(data, degree=-1) 

 

class ExteriorAlgebraCoboundary(ExteriorAlgebraDifferential): 

r""" 

The coboundary `d` of an exterior algebra `\Lambda(L)` defined 

by the structure coefficients of a Lie algebra `L`. 

 

Let `L` be a Lie algebra. We endow its exterior algebra 

`E = \Lambda(L)` with a cochain complex structure by considering a 

differential `d : \Lambda^k(L) \to \Lambda^{k+1}(L)` defined by 

 

.. MATH:: 

 

d x_i = \sum_{j < k} s_{jk}^i x_j x_k, 

 

where `(x_1, x_2, \ldots, x_n)` is a basis of `L`, and where 

`s_{jk}^i` is the `x_i`-coordinate of the Lie bracket `[x_j, x_k]`. 

 

The corresponding cohomology is the Lie algebra cohomology of `L`. 

 

This can also be thought of as the exterior derivative, in which case 

the resulting cohomology is the de Rham cohomology of a manifold whose 

exterior algebra of differential forms is ``E``. 

 

INPUT: 

 

- ``E`` -- an exterior algebra of a vector space `L` 

- ``s_coeff`` -- a dictionary whose keys are in `I \times I`, where 

`I` is the index set of the basis of the vector space `L`, and whose 

values can be coerced into 1-forms (degree 1 elements) in ``E``; 

this dictionary will be used to define the Lie algebra structure 

on `L` (indeed, the `i`-th coordinate of the Lie bracket of the 

`j`-th and `k`-th basis vectors of `L` for `j < k` is set to be 

the value at the key `(j, k)` if this key appears in ``s_coeff``, 

or otherwise the negated of the value at the key `(k, j)`) 

 

.. WARNING:: 

 

For any two distinct elements `i` and `j` of `I`, the dictionary 

``s_coeff`` must have only one of the pairs `(i, j)` and 

`(j, i)` as a key. This is not checked. 

 

EXAMPLES: 

 

We consider the differential coming from the Lie algebra given by the 

cross product `\times` of `\RR^3`:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: d(x) 

y^z 

sage: d(y) 

-x^z 

sage: d(x+y-y*z) 

-x^z + y^z 

sage: d(x*y) 

0 

sage: d(E.one()) 

0 

sage: d(E.zero()) 

0 

 

We check that `d \circ d = 0`:: 

 

sage: d2 = d * d 

sage: all(d2(b) == 0 for b in E.basis()) 

True 

 

Another example: the Lie algebra `\mathfrak{sl}_2`, which has a 

basis `e,f,h` satisfying `[h,e] = 2e`, `[h,f] = -2f`, and `[e,f] = h`:: 

 

sage: E.<e,f,h> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): h, (2,1): -2*f, (2,0): 2*e}) 

sage: d(E.zero()) 

0 

sage: d(e) 

-2*e^h 

sage: d(f) 

2*f^h 

sage: d(h) 

e^f 

sage: d(e*f) 

0 

sage: d(f*h) 

0 

sage: d(e*h) 

0 

sage: C = d.chain_complex(); C 

Chain complex with at most 4 nonzero terms over Rational Field 

sage: ascii_art(C) 

[ 0 0 1] [0] 

[-2 0 0] [0] 

[0 0 0] [ 0 2 0] [0] 

0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0 

sage: C.homology() 

{0: Vector space of dimension 1 over Rational Field, 

1: Vector space of dimension 0 over Rational Field, 

2: Vector space of dimension 0 over Rational Field, 

3: Vector space of dimension 1 over Rational Field} 

 

Over the integers:: 

 

sage: C = d.chain_complex(R=ZZ); C 

Chain complex with at most 4 nonzero terms over Integer Ring 

sage: ascii_art(C) 

[ 0 0 1] [0] 

[-2 0 0] [0] 

[0 0 0] [ 0 2 0] [0] 

0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0 

sage: C.homology() 

{0: Z, 1: 0, 2: C2 x C2, 3: Z} 

 

REFERENCES: 

 

- :wikipedia:`Exterior_algebra#Differential_geometry` 

""" 

def __init__(self, E, s_coeff): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): z, (1,2):x, (2,0):y}) 

sage: TestSuite(d).run() # known bug - morphisms are properly in a category 

""" 

# Construct the dictionary of costructure coefficients, i.e. given 

# [x_j, x_k] = \sum_i s_{jk}^i x_i, we get x^i |-> \sum_{j<k} s_{jk}^i x^j x^k. 

# This dictionary might contain 0 values and might also be missing 

# some keys (both times meaning that the respective `s_{jk}^i` are 

# zero for all `j` and `k`). 

self._cos_coeff = {} 

zero = E.zero() 

B = E.basis() 

for k, v in iteritems(dict(s_coeff)): 

k = B[k] 

for m,c in v: 

self._cos_coeff[m] = self._cos_coeff.get(m, zero) + c * k 

ExteriorAlgebraDifferential.__init__(self, E, s_coeff) 

 

def _repr_type(self): 

""" 

TESTS:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: d._repr_type() 

'Coboundary' 

""" 

return "Coboundary" 

 

def _on_basis(self, m): 

""" 

Return the differential on the basis element indexed by ``m``. 

 

EXAMPLES: 

 

The vector space `\RR^3` made into a Lie algebra using the 

cross product:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: d._on_basis(()) 

0 

sage: d._on_basis((0,)) 

y^z 

sage: d._on_basis((1,)) 

-x^z 

sage: d._on_basis((2,)) 

x^y 

sage: d._on_basis((0,1)) 

0 

sage: d._on_basis((0,2)) 

0 

sage: d._on_basis((0,1,2)) 

0 

""" 

E = self.domain() 

cc = self._cos_coeff 

keys = cc.keys() 

return E.sum((-1)**a * E.monomial(m[:a]) * cc[(i,)] * E.monomial(m[a+1:]) 

for a,i in enumerate(m) if (i,) in keys) 

 

@cached_method 

def chain_complex(self, R=None): 

""" 

Return the chain complex over ``R`` determined by ``self``. 

 

INPUT: 

 

- ``R`` -- the base ring; the default is the base ring of 

the exterior algebra 

 

EXAMPLES:: 

 

sage: E.<x,y,z> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y}) 

sage: C = d.chain_complex(); C 

Chain complex with at most 4 nonzero terms over Rational Field 

sage: ascii_art(C) 

[ 0 0 1] [0] 

[ 0 -1 0] [0] 

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

0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0 

 

TESTS: 

 

This still works in degree `1`:: 

 

sage: E.<x> = ExteriorAlgebra(QQ) 

sage: d = E.coboundary({}) 

sage: C = d.chain_complex(); C 

Chain complex with at most 2 nonzero terms over Rational Field 

sage: ascii_art(C) 

[0] 

0 <-- C_1 <---- C_0 <-- 0 

 

Also in degree `0`:: 

 

sage: E = ExteriorAlgebra(QQ, 0) 

sage: d = E.coboundary({}) 

sage: C = d.chain_complex(); C 

Chain complex with at most 1 nonzero terms over Rational Field 

sage: ascii_art(C) 

0 <-- C_0 <-- 0 

""" 

from sage.homology.chain_complex import ChainComplex 

from sage.matrix.constructor import Matrix 

E = self.domain() 

n = E.ngens() 

if R is None: 

R = E.base_ring() 

 

if n == 0: 

# Special case because there are no matrices and thus the 

# ChainComplex constructor needs the dimension of the 

# 0th degree space explicitly given. 

return ChainComplex({-1: Matrix(R, [[]])}, degree=1) 

# If you are reading this because you changed something about 

# the ChainComplex constructor and the doctests are failing: 

# This should return a chain complex with degree 1 and 

# only one nontrivial module, namely a free module of rank 1, 

# situated in degree 0. 

 

# Group the basis into degrees 

basis_by_deg = {deg: [] for deg in range(n+1)} 

for b in E.basis().keys(): 

basis_by_deg[len(b)].append(b) 

 

# Construct the transition matrices 

data = {} 

basis = basis_by_deg[0] 

for deg in range(n): 

# Make sure within each basis we're sorted by lex 

next_basis = sorted(basis_by_deg[deg+1]) 

mat = [] 

for b in basis: 

ret = self._on_basis(b) 

mat.append([ret[p] for p in next_basis]) 

data[deg] = Matrix(mat).transpose().change_ring(R) 

basis = next_basis 

 

return ChainComplex(data, degree=1)