Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

4302

4303

4304

4305

4306

4307

4308

4309

4310

4311

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324

4325

4326

4327

4328

4329

4330

4331

4332

4333

4334

4335

4336

4337

4338

4339

4340

4341

4342

4343

4344

4345

4346

4347

4348

4349

4350

4351

4352

4353

4354

4355

4356

4357

4358

4359

4360

4361

4362

4363

4364

4365

4366

4367

4368

4369

4370

4371

4372

4373

4374

4375

4376

4377

4378

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4429

4430

4431

4432

4433

4434

4435

4436

4437

4438

4439

4440

4441

4442

4443

4444

4445

4446

4447

4448

4449

4450

4451

4452

4453

4454

4455

4456

4457

4458

4459

4460

4461

4462

4463

4464

4465

4466

4467

4468

4469

4470

4471

4472

4473

4474

4475

4476

4477

4478

4479

4480

4481

4482

4483

4484

4485

4486

4487

4488

4489

4490

4491

4492

4493

4494

4495

4496

4497

4498

4499

4500

4501

4502

4503

4504

4505

4506

4507

4508

4509

4510

4511

4512

4513

4514

4515

4516

4517

4518

4519

4520

4521

4522

4523

4524

4525

4526

4527

4528

4529

4530

4531

4532

4533

4534

4535

4536

4537

4538

4539

4540

4541

4542

4543

4544

4545

4546

4547

4548

4549

4550

4551

4552

4553

4554

4555

4556

4557

4558

4559

4560

4561

4562

4563

4564

4565

4566

4567

4568

4569

4570

4571

4572

4573

4574

4575

4576

4577

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

r""" 

Finite lattices and semilattices 

 

This module implements finite (semi)lattices. It defines: 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`LatticePoset` | Construct a lattice. 

:meth:`MeetSemilattice` | Construct a meet semi-lattice. 

:meth:`JoinSemilattice` | Construct a join semi-lattice. 

:class:`FiniteLatticePoset` | A class for finite lattices. 

:class:`FiniteMeetSemilattice` | A class for finite meet semilattices. 

:class:`FiniteJoinSemilattice` | A class for finite join semilattices. 

 

List of (semi)lattice methods 

----------------------------- 

 

**Meet and join** 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`~FiniteMeetSemilattice.meet` | Return the meet of given elements. 

:meth:`~FiniteJoinSemilattice.join` | Return the join of given elements. 

:meth:`~FiniteMeetSemilattice.meet_matrix` | Return the matrix of meets of all elements of the meet semi-lattice. 

:meth:`~FiniteJoinSemilattice.join_matrix` | Return the matrix of joins of all elements of the join semi-lattice. 

 

**Properties of the lattice** 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`~FiniteLatticePoset.is_distributive` | Return ``True`` if the lattice is distributive. 

:meth:`~FiniteLatticePoset.is_modular` | Return ``True`` if the lattice is modular. 

:meth:`~FiniteLatticePoset.is_lower_semimodular` | Return ``True`` if all elements with common upper cover have a common lower cover. 

:meth:`~FiniteLatticePoset.is_upper_semimodular` | Return ``True`` if all elements with common lower cover have a common upper cover. 

:meth:`~FiniteLatticePoset.is_semidistributive` | Return ``True`` if the lattice is both join- and meet-semidistributive. 

:meth:`~FiniteLatticePoset.is_join_semidistributive` | Return ``True`` if the lattice is join-semidistributive. 

:meth:`~FiniteLatticePoset.is_meet_semidistributive` | Return ``True`` if the lattice is meet-semidistributive. 

:meth:`~FiniteLatticePoset.is_join_distributive` | Return ``True`` if the lattice is join-distributive. 

:meth:`~FiniteLatticePoset.is_meet_distributive` | Return ``True`` if the lattice is meet-distributive. 

:meth:`~FiniteLatticePoset.is_atomic` | Return ``True`` if every element of the lattice can be written as a join of atoms. 

:meth:`~FiniteLatticePoset.is_coatomic` | Return ``True`` if every element of the lattice can be written as a meet of coatoms. 

:meth:`~FiniteLatticePoset.is_geometric` | Return ``True`` if the lattice is atomic and upper semimodular. 

:meth:`~FiniteLatticePoset.is_complemented` | Return ``True`` if every element of the lattice has at least one complement. 

:meth:`~FiniteLatticePoset.is_sectionally_complemented` | Return ``True`` if every interval from the bottom is complemented. 

:meth:`~FiniteLatticePoset.is_cosectionally_complemented` | Return ``True`` if every interval to the top is complemented. 

:meth:`~FiniteLatticePoset.is_relatively_complemented` | Return ``True`` if every interval of the lattice is complemented. 

:meth:`~FiniteLatticePoset.is_pseudocomplemented` | Return ``True`` if every element of the lattice has a (meet-)pseudocomplement. 

:meth:`~FiniteLatticePoset.is_join_pseudocomplemented` | Return ``True`` if every element of the lattice has a join-pseudocomplement. 

:meth:`~FiniteLatticePoset.is_orthocomplemented` | Return ``True`` if the lattice has an orthocomplementation. 

:meth:`~FiniteLatticePoset.is_supersolvable` | Return ``True`` if the lattice is supersolvable. 

:meth:`~FiniteLatticePoset.is_planar` | Return ``True`` if the lattice has an upward planar drawing. 

:meth:`~FiniteLatticePoset.is_dismantlable` | Return ``True`` if the lattice is dismantlable. 

:meth:`~FiniteLatticePoset.is_stone` | Return ``True`` if the lattice is a Stone lattice. 

:meth:`~FiniteLatticePoset.is_vertically_decomposable` | Return ``True`` if the lattice is vertically decomposable. 

:meth:`~FiniteLatticePoset.is_simple` | Return ``True`` if the lattice has no nontrivial congruences. 

:meth:`~FiniteLatticePoset.is_isoform` | Return ``True`` if all congruences of the lattice consists of isoform blocks. 

:meth:`~FiniteLatticePoset.is_uniform` | Return ``True`` if all congruences of the lattice consists of equal-sized blocks. 

:meth:`~FiniteLatticePoset.is_regular` | Return ``True`` if all congruences of lattice are determined by any of the congruence blocks. 

:meth:`~FiniteLatticePoset.is_subdirectly_reducible` | Return ``True`` if the lattice is a sublattice of the product of smaller lattices. 

:meth:`~FiniteLatticePoset.is_constructible_by_doublings` | Return ``True`` if the lattice is constructible by doublings from the one-element lattice. 

:meth:`~FiniteLatticePoset.breadth` | Return the breadth of the lattice. 

 

**Specific elements** 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`~FiniteMeetSemilattice.atoms()` | Return elements covering the bottom element. 

:meth:`~FiniteJoinSemilattice.coatoms()` | Return elements covered by the top element. 

:meth:`~FiniteLatticePoset.double_irreducibles` | Return double irreducible elements. 

:meth:`~FiniteLatticePoset.join_primes` | Return the join prime elements. 

:meth:`~FiniteLatticePoset.meet_primes` | Return the meet prime elements. 

:meth:`~FiniteLatticePoset.complements` | Return the list of complements of an element, or the dictionary of complements for all elements. 

:meth:`~FiniteMeetSemilattice.pseudocomplement` | Return the pseudocomplement of an element. 

:meth:`~FiniteLatticePoset.is_modular_element` | Return ``True`` if given element is modular in the lattice. 

:meth:`~FiniteLatticePoset.neutral_elements` | Return neutral elements of the lattice. 

:meth:`~FiniteLatticePoset.canonical_joinands` | Return the canonical joinands of an element. 

:meth:`~FiniteLatticePoset.canonical_meetands` | Return the canonical meetands of an element. 

 

**Sublattices** 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`~FiniteLatticePoset.sublattice` | Return sublattice generated by list of elements. 

:meth:`~FiniteLatticePoset.is_sublattice` | Return ``True`` if the lattice is a sublattice of given lattice. 

:meth:`~FiniteLatticePoset.sublattices` | Return all sublattices of the lattice. 

:meth:`~FiniteLatticePoset.sublattices_lattice` | Return the lattice of sublattices. 

:meth:`~FiniteLatticePoset.isomorphic_sublattices_iterator` | Return an iterator over the sublattices isomorphic to given lattice. 

:meth:`~FiniteLatticePoset.maximal_sublattices` | Return maximal sublattices of the lattice. 

:meth:`~FiniteLatticePoset.frattini_sublattice` | Return the intersection of maximal sublattices of the lattice. 

:meth:`~FiniteLatticePoset.skeleton` | Return the skeleton of the lattice. 

:meth:`~FiniteLatticePoset.center` | Return the sublattice of complemented neutral elements. 

:meth:`~FiniteLatticePoset.vertical_decomposition` | Return the vertical decomposition of the lattice. 

 

**Miscellaneous** 

 

.. csv-table:: 

:class: contentstable 

:widths: 30, 70 

:delim: | 

 

:meth:`~FiniteLatticePoset.moebius_algebra` | Return the Möbius algebra of the lattice. 

:meth:`~FiniteLatticePoset.quantum_moebius_algebra` | Return the quantum Möbius algebra of the lattice. 

:meth:`~FiniteLatticePoset.vertical_composition` | Return ordinal sum of lattices with top/bottom element unified. 

:meth:`~FiniteLatticePoset.day_doubling` | Return the lattice with Alan Day's doubling construction of a subset. 

:meth:`~FiniteLatticePoset.adjunct` | Return the adjunct with other lattice. 

:meth:`~FiniteLatticePoset.subdirect_decomposition` | Return the subdirect decomposition of the lattice. 

:meth:`~FiniteLatticePoset.congruence` | Return the congruence generated by lists of elements. 

:meth:`~FiniteLatticePoset.quotient` | Return the quotient lattice by a congruence. 

:meth:`~FiniteLatticePoset.congruences_lattice` | Return the lattice of congruences. 

""" 

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

# Copyright (C) 2008 Peter Jipsen <jipsen@chapman.edu>, 

# Franco Saliola <saliola@gmail.com> 

# 

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

# 

# This code is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

# General Public License for more details. 

# 

# The full text of the GPL is available at: 

# 

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

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

from six.moves import range 

from six import iteritems 

 

from sage.categories.finite_lattice_posets import FiniteLatticePosets 

from sage.combinat.posets.posets import Poset, FinitePoset 

from sage.combinat.posets.elements import (LatticePosetElement, 

MeetSemilatticeElement, 

JoinSemilatticeElement) 

from sage.combinat.posets.hasse_diagram import LatticeError 

 

from sage.misc.decorators import rename_keyword 

 

 

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

 

def MeetSemilattice(data=None, *args, **options): 

r""" 

Construct a meet semi-lattice from various forms of input data. 

 

INPUT: 

 

- ``data``, ``*args``, ``**options`` -- data and options that will 

be passed down to :func:`Poset` to construct a poset that is 

also a meet semilattice. 

 

.. SEEALSO:: :func:`Poset`, :func:`JoinSemilattice`, :func:`LatticePoset` 

 

EXAMPLES: 

 

Using data that defines a poset:: 

 

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

Finite meet-semilattice containing 4 elements 

 

sage: MeetSemilattice([[1,2],[3],[3]], cover_relations = True) 

Finite meet-semilattice containing 4 elements 

 

Using a previously constructed poset:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: L = MeetSemilattice(P); L 

Finite meet-semilattice containing 4 elements 

sage: type(L) 

<class 'sage.combinat.posets.lattices.FiniteMeetSemilattice_with_category'> 

 

If the data is not a lattice, then an error is raised:: 

 

sage: MeetSemilattice({'a': ['b', 'c'], 'b': ['d', 'e'], 

....: 'c': ['d', 'e'], 'd': ['f'], 'e': ['f']}) 

Traceback (most recent call last): 

... 

LatticeError: no meet for e and d 

""" 

if isinstance(data, FiniteMeetSemilattice) and not args and not options: 

return data 

P = Poset(data, *args, **options) 

try: 

P._hasse_diagram.meet_matrix() 

except LatticeError as error: 

error.x = P._vertex_to_element(error.x) 

error.y = P._vertex_to_element(error.y) 

raise 

return FiniteMeetSemilattice(P) 

 

 

class FiniteMeetSemilattice(FinitePoset): 

""" 

.. note:: 

We assume that the argument passed to MeetSemilattice is the poset 

of a meet-semilattice (i.e. a poset with greatest lower bound for 

each pair of elements). 

 

TESTS:: 

 

sage: M = MeetSemilattice([[1,2],[3],[3]]) 

sage: TestSuite(M).run() 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: M = MeetSemilattice(P) 

sage: TestSuite(M).run() 

""" 

Element = MeetSemilatticeElement 

 

def _repr_(self): 

r""" 

TESTS:: 

 

sage: M = MeetSemilattice([[1,2],[3],[3]]) 

sage: M._repr_() 

'Finite meet-semilattice containing 4 elements' 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: M = MeetSemilattice(P) 

sage: M._repr_() 

'Finite meet-semilattice containing 4 elements' 

""" 

s = "Finite meet-semilattice containing %s elements" % self._hasse_diagram.order() 

if self._with_linear_extension: 

s += " with distinguished linear extension" 

return s 

 

def meet_matrix(self): 

""" 

Return a matrix whose ``(i,j)`` entry is ``k``, where 

``self.linear_extension()[k]`` is the meet (greatest lower bound) of 

``self.linear_extension()[i]`` and ``self.linear_extension()[j]``. 

 

EXAMPLES:: 

 

sage: P = LatticePoset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]], facade = False) 

sage: M = P.meet_matrix(); M 

[0 0 0 0 0 0 0 0] 

[0 1 0 1 0 0 0 1] 

[0 0 2 2 2 0 2 2] 

[0 1 2 3 2 0 2 3] 

[0 0 2 2 4 0 2 4] 

[0 0 0 0 0 5 5 5] 

[0 0 2 2 2 5 6 6] 

[0 1 2 3 4 5 6 7] 

sage: M[P(4).vertex,P(3).vertex] == P(0).vertex 

True 

sage: M[P(5).vertex,P(2).vertex] == P(2).vertex 

True 

sage: M[P(5).vertex,P(2).vertex] == P(5).vertex 

False 

""" 

return self._hasse_diagram.meet_matrix() 

 

def meet(self, x, y=None): 

r""" 

Return the meet of given elements in the lattice. 

 

INPUT: 

 

- ``x, y`` -- two elements of the (semi)lattice OR 

- ``x`` -- a list or tuple of elements 

 

EXAMPLES:: 

 

sage: D = posets.DiamondPoset(5) 

sage: D.meet(1, 2) 

0 

sage: D.meet(1, 1) 

1 

sage: D.meet(1, 0) 

0 

sage: D.meet(1, 4) 

1 

 

Using list of elements as an argument. Meet of empty list is 

the bottom element:: 

 

sage: B4=posets.BooleanLattice(4) 

sage: B4.meet([3,5,6]) 

0 

sage: B4.meet([]) 

15 

 

For non-facade lattices operator ``*`` works for meet:: 

 

sage: L = posets.PentagonPoset(facade=False) 

sage: L(1)*L(2) 

0 

 

.. SEEALSO:: 

 

- Dual function: :meth:`~sage.combinat.posets.lattices.FiniteJoinSemilattice.join` 

""" 

if y is not None: # Handle basic case fast 

i, j = map(self._element_to_vertex, (x, y)) 

return self._vertex_to_element(self._hasse_diagram._meet[i, j]) 

m = self.cardinality() - 1 # m = top element 

for i in (self._element_to_vertex(_) for _ in x): 

m = self._hasse_diagram._meet[i, m] 

return self._vertex_to_element(m) 

 

def atoms(self): 

""" 

Return the list atoms of this (semi)lattice. 

 

An *atom* of a lattice is an element covering the bottom element. 

 

EXAMPLES:: 

 

sage: L = posets.DivisorLattice(60) 

sage: sorted(L.atoms()) 

[2, 3, 5] 

 

.. SEEALSO:: 

 

- Dual function: :meth:`~FiniteJoinSemilattice.coatoms` 

 

TESTS:: 

 

sage: LatticePoset().atoms() 

[] 

sage: LatticePoset({0: []}).atoms() 

[] 

""" 

if self.cardinality() == 0: 

return [] 

return self.upper_covers(self.bottom()) 

 

def pseudocomplement(self, element): 

""" 

Return the pseudocomplement of ``element``, if it exists. 

 

The (meet-)pseudocomplement is the greatest element whose 

meet with given element is the bottom element. I.e. 

in a meet-semilattice with bottom element `\hat{0}` 

the pseudocomplement of an element `e` is the element 

`e^\star` such that `e \wedge e^\star = \hat{0}` and 

`e' \le e^\star` if `e \wedge e' = \hat{0}`. 

 

See :wikipedia:`Pseudocomplement`. 

 

INPUT: 

 

- ``element`` -- an element of the lattice. 

 

OUTPUT: 

 

An element of the lattice or ``None`` if the pseudocomplement does 

not exist. 

 

EXAMPLES: 

 

The pseudocomplement's pseudocomplement is not always the original 

element:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [5], 4: [6], 5: [6]}) 

sage: L.pseudocomplement(2) 

5 

sage: L.pseudocomplement(5) 

4 

 

An element can have complements but no pseudocomplement, or vice 

versa:: 

 

sage: L = LatticePoset({0: [1, 2], 1: [3, 4, 5], 2: [5], 3: [6], 

....: 4: [6], 5: [6]}) 

sage: L.complements(1), L.pseudocomplement(1) 

([], 2) 

sage: L.complements(2), L.pseudocomplement(2) 

([3, 4], None) 

 

.. SEEALSO:: :meth:`~sage.combinat.posets.lattices.FiniteLatticePoset.is_pseudocomplemented` 

 

TESTS:: 

 

sage: L = LatticePoset({'a': []}) 

sage: L.pseudocomplement('a') 

'a' 

sage: L = LatticePoset({'a': ['b'], 'b': ['c']}) 

sage: [L.pseudocomplement(e) for e in ['a', 'b', 'c']] 

['c', 'a', 'a'] 

""" 

v = self._element_to_vertex(element) 

e = self._hasse_diagram.pseudocomplement(v) 

if e is None: 

return None 

return self._vertex_to_element(e) 

 

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

 

 

def JoinSemilattice(data=None, *args, **options): 

r""" 

Construct a join semi-lattice from various forms of input data. 

 

INPUT: 

 

- ``data``, ``*args``, ``**options`` -- data and options that will 

be passed down to :func:`Poset` to construct a poset that is 

also a join semilattice 

 

.. SEEALSO:: :func:`Poset`, :func:`MeetSemilattice`, :func:`LatticePoset` 

 

EXAMPLES: 

 

Using data that defines a poset:: 

 

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

Finite join-semilattice containing 4 elements 

 

sage: JoinSemilattice([[1,2],[3],[3]], cover_relations = True) 

Finite join-semilattice containing 4 elements 

 

Using a previously constructed poset:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: J = JoinSemilattice(P); J 

Finite join-semilattice containing 4 elements 

sage: type(J) 

<class 'sage.combinat.posets.lattices.FiniteJoinSemilattice_with_category'> 

 

If the data is not a lattice, then an error is raised:: 

 

sage: JoinSemilattice({'a': ['b', 'c'], 'b': ['d', 'e'], 

....: 'c': ['d', 'e'], 'd': ['f'], 'e': ['f']}) 

Traceback (most recent call last): 

... 

LatticeError: no join for b and c 

""" 

if isinstance(data, FiniteJoinSemilattice) and not args and not options: 

return data 

P = Poset(data, *args, **options) 

try: 

P._hasse_diagram.join_matrix() 

except LatticeError as error: 

error.x = P._vertex_to_element(error.x) 

error.y = P._vertex_to_element(error.y) 

raise 

 

return FiniteJoinSemilattice(P) 

 

 

class FiniteJoinSemilattice(FinitePoset): 

""" 

We assume that the argument passed to FiniteJoinSemilattice is the 

poset of a join-semilattice (i.e. a poset with least upper bound 

for each pair of elements). 

 

TESTS:: 

 

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

sage: TestSuite(J).run() 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: J = JoinSemilattice(P) 

sage: TestSuite(J).run() 

 

""" 

Element = JoinSemilatticeElement 

 

def _repr_(self): 

r""" 

TESTS:: 

 

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

sage: J._repr_() 

'Finite join-semilattice containing 4 elements' 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: J = JoinSemilattice(P) 

sage: J._repr_() 

'Finite join-semilattice containing 4 elements' 

""" 

s = "Finite join-semilattice containing %s elements" % self._hasse_diagram.order() 

if self._with_linear_extension: 

s += " with distinguished linear extension" 

return s 

 

def join_matrix(self): 

""" 

Return a matrix whose ``(i,j)`` entry is ``k``, where 

``self.linear_extension()[k]`` is the join (least upper bound) of 

``self.linear_extension()[i]`` and ``self.linear_extension()[j]``. 

 

EXAMPLES:: 

 

sage: P = LatticePoset([[1,3,2],[4],[4,5,6],[6],[7],[7],[7],[]], facade = False) 

sage: J = P.join_matrix(); J 

[0 1 2 3 4 5 6 7] 

[1 1 3 3 7 7 7 7] 

[2 3 2 3 4 6 6 7] 

[3 3 3 3 7 7 7 7] 

[4 7 4 7 4 7 7 7] 

[5 7 6 7 7 5 6 7] 

[6 7 6 7 7 6 6 7] 

[7 7 7 7 7 7 7 7] 

sage: J[P(4).vertex,P(3).vertex] == P(7).vertex 

True 

sage: J[P(5).vertex,P(2).vertex] == P(5).vertex 

True 

sage: J[P(5).vertex,P(2).vertex] == P(2).vertex 

False 

""" 

return self._hasse_diagram.join_matrix() 

 

def join(self, x, y=None): 

r""" 

Return the join of given elements in the lattice. 

 

INPUT: 

 

- ``x, y`` -- two elements of the (semi)lattice OR 

- ``x`` -- a list or tuple of elements 

 

EXAMPLES:: 

 

sage: D = posets.DiamondPoset(5) 

sage: D.join(1, 2) 

4 

sage: D.join(1, 1) 

1 

sage: D.join(1, 4) 

4 

sage: D.join(1, 0) 

1 

 

Using list of elements as an argument. Join of empty list is 

the bottom element:: 

 

sage: B4=posets.BooleanLattice(4) 

sage: B4.join([2,4,8]) 

14 

sage: B4.join([]) 

0 

 

For non-facade lattices operator ``+`` works for join:: 

 

sage: L = posets.PentagonPoset(facade=False) 

sage: L(1)+L(2) 

4 

 

.. SEEALSO:: 

 

- Dual function: :meth:`~sage.combinat.posets.lattices.FiniteMeetSemilattice.meet` 

""" 

if y is not None: # Handle basic case fast 

i, j = map(self._element_to_vertex, (x, y)) 

return self._vertex_to_element(self._hasse_diagram._join[i, j]) 

j = 0 # j = bottom element 

for i in (self._element_to_vertex(_) for _ in x): 

j = self._hasse_diagram._join[i, j] 

return self._vertex_to_element(j) 

 

def coatoms(self): 

""" 

Return the list of co-atoms of this (semi)lattice. 

 

A *co-atom* of a lattice is an element covered by the top element. 

 

EXAMPLES:: 

 

sage: L = posets.DivisorLattice(60) 

sage: sorted(L.coatoms()) 

[12, 20, 30] 

 

.. SEEALSO:: 

 

- Dual function: :meth:`~FiniteMeetSemilattice.atoms` 

 

TESTS:: 

 

sage: LatticePoset().coatoms() 

[] 

sage: LatticePoset({0: []}).coatoms() 

[] 

""" 

if self.cardinality() == 0: 

return [] 

return self.lower_covers(self.top()) 

 

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

 

 

def LatticePoset(data=None, *args, **options): 

r""" 

Construct a lattice from various forms of input data. 

 

INPUT: 

 

- ``data``, ``*args``, ``**options`` -- data and options that will 

be passed down to :func:`Poset` to construct a poset that is 

also a lattice. 

 

OUTPUT: 

 

An instance of :class:`FiniteLatticePoset`. 

 

.. SEEALSO:: 

 

:class:`Posets`, :class:`FiniteLatticePosets`, 

:func:`JoinSemiLattice`, :func:`MeetSemiLattice` 

 

EXAMPLES: 

 

Using data that defines a poset:: 

 

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

Finite lattice containing 4 elements 

 

sage: LatticePoset([[1,2],[3],[3]], cover_relations = True) 

Finite lattice containing 4 elements 

 

Using a previously constructed poset:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: L = LatticePoset(P); L 

Finite lattice containing 4 elements 

sage: type(L) 

<class 'sage.combinat.posets.lattices.FiniteLatticePoset_with_category'> 

 

If the data is not a lattice, then an error is raised:: 

 

sage: elms = [1,2,3,4,5,6,7] 

sage: rels = [[1,2],[3,4],[4,5],[2,5]] 

sage: LatticePoset((elms, rels)) 

Traceback (most recent call last): 

... 

ValueError: not a meet-semilattice: no bottom element 

 

Creating a facade lattice:: 

 

sage: L = LatticePoset([[1,2],[3],[3]], facade = True) 

sage: L.category() 

Category of facade finite enumerated lattice posets 

sage: parent(L[0]) 

Integer Ring 

sage: TestSuite(L).run(skip = ['_test_an_element']) # is_parent_of is not yet implemented 

""" 

if isinstance(data, FiniteLatticePoset) and not args and not options: 

return data 

P = Poset(data, *args, **options) 

if P.cardinality() != 0: 

if not P.has_bottom(): 

raise ValueError("not a meet-semilattice: no bottom element") 

try: 

P._hasse_diagram.join_matrix() 

except LatticeError as error: 

error.x = P._vertex_to_element(error.x) 

error.y = P._vertex_to_element(error.y) 

raise 

return FiniteLatticePoset(P, category=FiniteLatticePosets(), facade=P._is_facade) 

 

 

class FiniteLatticePoset(FiniteMeetSemilattice, FiniteJoinSemilattice): 

""" 

We assume that the argument passed to FiniteLatticePoset is the 

poset of a lattice (i.e. a poset with greatest lower bound and 

least upper bound for each pair of elements). 

 

TESTS:: 

 

sage: L = LatticePoset([[1,2],[3],[3]]) 

sage: TestSuite(L).run() 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: L = LatticePoset(P) 

sage: TestSuite(L).run() 

 

""" 

Element = LatticePosetElement 

 

def _repr_(self): 

r""" 

TESTS:: 

 

sage: L = LatticePoset([[1,2],[3],[3]]) 

sage: L._repr_() 

'Finite lattice containing 4 elements' 

 

:: 

 

sage: P = Poset([[1,2],[3],[3]]) 

sage: L = LatticePoset(P) 

sage: L._repr_() 

'Finite lattice containing 4 elements' 

""" 

s = "Finite lattice containing %s elements" % self._hasse_diagram.order() 

if self._with_linear_extension: 

s += " with distinguished linear extension" 

return s 

 

def double_irreducibles(self): 

""" 

Return the list of double irreducible elements of this lattice. 

 

A *double irreducible* element of a lattice is an element 

covering and covered by exactly one element. In other words 

it is neither a meet nor a join of any elements. 

 

EXAMPLES:: 

 

sage: L = posets.DivisorLattice(12) 

sage: sorted(L.double_irreducibles()) 

[3, 4] 

 

sage: L = posets.BooleanLattice(3) 

sage: L.double_irreducibles() 

[] 

 

.. SEEALSO:: 

 

:meth:`~sage.categories.finite_lattice_posets.FiniteLatticePosets.ParentMethods.meet_irreducibles`, 

:meth:`~sage.categories.finite_lattice_posets.FiniteLatticePosets.ParentMethods.join_irreducibles` 

 

TESTS:: 

 

sage: LatticePoset().double_irreducibles() 

[] 

sage: posets.ChainPoset(2).double_irreducibles() 

[] 

""" 

H = self._hasse_diagram 

return [self._vertex_to_element(e) for e in H 

if H.in_degree(e) == 1 and H.out_degree(e) == 1] 

 

def join_primes(self): 

r""" 

Return the join-prime elements of the lattice. 

 

An element `x` of a lattice `L` is *join-prime* if `x \le a \vee b` 

implies `x \le a` or `x \le b` for every `a, b \in L`. 

 

These are also called *coprime* in some books. Every join-prime 

is join-irreducible; converse holds if and only if the lattise 

is distributive. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], 

....: 4: [6], 5: [7], 6: [7]}) 

sage: L.join_primes() 

[3, 4] 

 

sage: D12 = posets.DivisorLattice(12) # Distributive lattice 

sage: D12.join_irreducibles() == D12.join_primes() 

True 

 

.. SEEALSO:: 

 

- Dual function: :meth:`meet_primes` 

- Other: :meth:`~sage.categories.finite_lattice_posets.FiniteLatticePosets.ParentMethods.join_irreducibles` 

 

TESTS:: 

 

sage: LatticePoset().join_primes() 

[] 

sage: posets.DiamondPoset(5).join_primes() 

[] 

""" 

return [self._vertex_to_element(v) for 

v in self._hasse_diagram.prime_elements()[0]] 

 

def meet_primes(self): 

r""" 

Return the meet-prime elements of the lattice. 

 

An element `x` of a lattice `L` is *meet-prime* if `x \ge a \wedge b` 

implies `x \ge a` or `x \ge b` for every `a, b \in L`. 

 

These are also called just *prime* in some books. Every meet-prime 

is meet-irreducible; converse holds if and only if the lattise 

is distributive. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], 

....: 4: [6], 5: [7], 6: [7]}) 

sage: L.meet_primes() 

[6, 5] 

 

sage: D12 = posets.DivisorLattice(12) 

sage: sorted(D12.meet_primes()) 

[3, 4, 6] 

 

.. SEEALSO:: 

 

- Dual function: :meth:`join_primes` 

- Other: :meth:`~sage.categories.finite_lattice_posets.FiniteLatticePosets.ParentMethods.meet_irreducibles` 

 

TESTS:: 

 

sage: LatticePoset().meet_primes() 

[] 

sage: posets.DiamondPoset(5).meet_primes() 

[] 

""" 

return [self._vertex_to_element(v) for 

v in self._hasse_diagram.prime_elements()[1]] 

 

def neutral_elements(self): 

r""" 

Return the list of neutral elements of the lattice. 

 

An element `e` of the lattice `L` is *neutral* if the sublattice 

generated by `e`, `x` and `y` is distributive for all `x, y \in L`. 

It can also be characterized as an element of intersection of 

maximal distributive sublattices. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [6], 3: [4, 5, 6], 4: [8], 

....: 5: [7], 6: [7], 7: [8, 9], 8: [10], 9: [10]}) 

sage: L.neutral_elements() 

[1, 3, 8, 10] 

 

TESTS:: 

 

sage: all(posets.ChainPoset(i).neutral_elements() == list(range(i)) 

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

True 

 

sage: posets.BooleanLattice(3).neutral_elements() 

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

 

sage: L = LatticePoset(DiGraph('QQG?LA??__?OG@C??p???O??A?E??@??@g??Q??S??@??E??@??@???')) 

sage: L.neutral_elements() 

[0, 1, 4, 5, 15, 17] 

""" 

t = sorted(self._hasse_diagram.neutral_elements()) 

return [self._vertex_to_element(v) for v in t] 

 

def is_join_distributive(self, certificate=False): 

""" 

Return ``True`` if the lattice is join-distributive and ``False`` 

otherwise. 

 

A lattice is *join-distributive* if every interval from an element 

to the join of the element's upper covers is a distributive lattice. 

Actually this distributive sublattice is then a Boolean lattice. 

 

They are also called as *Dilworth's lattices* and *upper locally 

distributive lattices*. They can be characterized in many other 

ways, see [Dil1940]_. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where `e` is an element such that the interval 

from `e` to the meet of upper covers of `e` is not distributive. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5, 7], 

....: 4: [6, 7], 5: [8, 9], 6: [9], 7: [9, 10], 

....: 8: [11], 9: [11], 10: [11]}) 

sage: L.is_join_distributive() 

True 

 

sage: L = LatticePoset({1: [2], 2: [3, 4], 3: [5], 4: [6], 

....: 5: [7], 6: [7]}) 

sage: L.is_join_distributive() 

False 

sage: L.is_join_distributive(certificate=True) 

(False, 2) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_meet_distributive` 

- Weaker properties: :meth:`is_meet_semidistributive`, 

:meth:`is_upper_semimodular` 

- Stronger properties: :meth:`is_distributive` 

 

TESTS:: 

 

sage: E = LatticePoset() 

sage: E.is_join_distributive() 

True 

sage: E.is_join_distributive(certificate=True) 

(True, None) 

 

sage: L = LatticePoset({1: []}) 

sage: L.is_join_distributive() 

True 

sage: L.is_join_distributive(certificate=True) 

(True, None) 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3: [5, 6], 

....: 4: [6], 5: [7], 6:[7]}) 

sage: L.is_join_distributive() 

False 

sage: L.is_join_distributive(certificate=True) 

(False, 1) 

 

sage: L = LatticePoset({1: [2], 2: [3, 4, 5], 3: [6], 4: [6], 5: [6]}) 

sage: L.is_join_distributive(certificate=True) 

(False, 2) 

""" 

if ((self.is_ranked() and len(self.meet_irreducibles()) == self.rank()) or 

self.cardinality() == 0): 

return (True, None) if certificate else True 

if not certificate: 

return False 

 

# A lattice that is not join-distributive is either not upper 

# semimodular or contains a diamond as a covering sublattice. 

result = self.is_upper_semimodular(certificate=True) 

if not result[0]: 

return (False, self.meet(result[1])) 

 

from sage.graphs.digraph import DiGraph 

M3 = DiGraph({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) 

diamond = next(self._hasse_diagram.subgraph_search_iterator(M3)) 

return (False, self[diamond[0]]) 

 

def is_meet_distributive(self, certificate=False): 

""" 

Return ``True`` if the lattice is meet-distributive and ``False`` 

otherwise. 

 

A lattice is *meet-distributive* if every interval to an element 

from the meet of the element's lower covers is a distributive lattice. 

Actually this distributive sublattice is then a Boolean lattice. 

 

They are also called as *lower locally distributive lattices*. 

They can be characterized in many other ways, see [Dil1940]_. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where `e` is an element such that the interval 

to `e` from the meet of lower covers of `e` is not distributive. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3: [5, 6, 7], 

....: 4: [7], 5: [9, 8], 6: [10, 8], 7: 

....: [9, 10], 8: [11], 9: [11], 10: [11]}) 

sage: L.is_meet_distributive() 

True 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [5], 4: [6], 

....: 5: [6], 6: [7]}) 

sage: L.is_meet_distributive() 

False 

sage: L.is_meet_distributive(certificate=True) 

(False, 6) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_join_distributive` 

- Weaker properties: :meth:`is_join_semidistributive`, 

:meth:`is_lower_semimodular` 

- Stronger properties: :meth:`is_distributive` 

 

TESTS:: 

 

sage: E = LatticePoset() 

sage: E.is_meet_distributive() 

True 

sage: E.is_meet_distributive(certificate=True) 

(True, None) 

 

sage: L = LatticePoset({1: []}) 

sage: L.is_meet_distributive() 

True 

sage: L.is_meet_distributive(certificate=True) 

(True, None) 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [5, 6], 4: [7], 

....: 5: [7], 6: [7]}) 

sage: L.is_meet_distributive() 

False 

sage: L.is_meet_distributive(certificate=True) 

(False, 7) 

 

sage: L = LatticePoset({1: [2], 2: [3, 4, 5], 3: [6], 4: [6], 5: [6]}) 

sage: L.is_meet_distributive(certificate=True) 

(False, 6) 

""" 

if ((self.is_ranked() and len(self.join_irreducibles()) == self.rank()) or 

self.cardinality() == 0): 

return (True, None) if certificate else True 

if not certificate: 

return False 

 

# A lattice that is not meet-distributive is either not lower 

# semimodular or contains a diamond as a covering sublattice. 

result = self.is_lower_semimodular(certificate=True) 

if not result[0]: 

return (False, self.join(result[1])) 

 

from sage.graphs.digraph import DiGraph 

M3 = DiGraph({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) 

diamond = next(self._hasse_diagram.subgraph_search_iterator(M3)) 

return (False, self[diamond[4]]) 

 

def is_stone(self, certificate=False): 

r""" 

Return ``True`` if the lattice is a Stone lattice, and ``False`` 

otherwise. 

 

The lattice is expected to be distributive (and hence 

pseudocomplemented). 

 

A pseudocomplemented lattice is a Stone lattice if 

 

.. MATH:: 

 

e^* \vee e^{**} = \top 

 

for every element `e` of the lattice, where `^*` is the 

pseudocomplement and `\top` is the top element of the lattice. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)`` such that `e^* \vee e^{**} \neq \top`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES: 

 

Divisor lattices are canonical example:: 

 

sage: D72 = posets.DivisorLattice(72) 

sage: D72.is_stone() 

True 

 

A non-example:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [4], 4: [5]}) 

sage: L.is_stone() 

False 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_distributive` 

 

TESTS:: 

 

sage: LatticePoset().is_stone() # Empty lattice 

True 

 

sage: L = LatticePoset(DiGraph('GW?_W@?W@?O?')) 

sage: L.is_stone() # Pass the fast check, but not a Stone lattice 

False 

""" 

# TODO: For now we can factor only undirected graphs. When that 

# is extended to directed, use that; see comment below. 

 

if not self.is_distributive(): 

raise ValueError("the lattice is not distributive") 

 

from sage.arith.misc import factor 

ok = (True, None) if certificate else True 

 

# Needed for the empty lattice that has no bottom element. 

if self.cardinality() < 5: 

return ok 

 

# Quick check: 

# A Stone lattice is direct product of distributive lattices with 

# one atom. Return False if for example the lattice has two atoms 

# and odd number of elements. 

atoms_n = self._hasse_diagram.out_degree(0) 

if atoms_n == 1: 

return ok 

if not certificate: 

if sum([x[1] for x in factor(self.cardinality())]) < atoms_n: 

return False 

if self._hasse_diagram.in_degree(self.cardinality() - 1) < atoms_n: 

return False 

 

# Quick check failed 

one = self.top() 

tested = set() 

for e in self: 

e_ = self.pseudocomplement(e) 

if e_ not in tested: 

if self.join(e_, self.pseudocomplement(e_)) != one: 

if certificate: 

return (False, e) 

return False 

tested.add(e_) 

 

return ok 

 

def is_distributive(self, certificate=False): 

r""" 

Return ``True`` if the lattice is distributive, and ``False`` 

otherwise. 

 

A lattice `(L, \vee, \wedge)` is distributive if meet 

distributes over join: `x \wedge (y \vee z) = (x \wedge y) 

\vee (x \wedge z)` for every `x,y,z \in L` just like `x \cdot 

(y+z)=x \cdot y + x \cdot z` in normal arithmetic. For duality 

in lattices it follows that then also join distributes over 

meet. 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (x, y, z))``, where `x`, `y` and `z` are elements 

of the lattice such that 

`x \wedge (y \vee z) \neq (x \wedge y) \vee (x \wedge z)`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [4], 4: [5]}) 

sage: L.is_distributive() 

True 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3: [6], 4: [6], 5: [6]}) 

sage: L.is_distributive() 

False 

sage: L.is_distributive(certificate=True) 

(False, (5, 3, 2)) 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_modular`, 

:meth:`is_semidistributive`, :meth:`is_join_distributive`, 

:meth:`is_meet_distributive`, :meth:`is_subdirectly_reducible`, 

:meth:`is_constructible_by_doublings` (by interval doubling) 

- Stronger properties: :meth:`is_stone` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_distributive() for i in range(3)] 

[True, True, True] 

""" 

from sage.graphs.digraph import DiGraph 

 

ok = (True, None) if certificate else True 

 

if self.cardinality() == 0: 

return ok 

 

if (self.is_graded() and 

self.rank() == len(self.join_irreducibles()) == 

len(self.meet_irreducibles())): 

return ok 

 

if not certificate: 

return False 

 

result, cert = self.is_modular(certificate=True) 

if not result: 

return (False, (cert[2], cert[1], cert[0])) 

M3 = DiGraph({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) 

diamond = next(self._hasse_diagram.subgraph_search_iterator(M3)) 

return (False, (self._vertex_to_element(diamond[1]), 

self._vertex_to_element(diamond[2]), 

self._vertex_to_element(diamond[3]))) 

 

def is_semidistributive(self): 

""" 

Return ``True`` if the lattice is both join- and meet-semidistributive, 

and ``False`` otherwise. 

 

EXAMPLES: 

 

Tamari lattices are typical examples of semidistributive but not 

distributive (and hence not modular) lattices:: 

 

sage: T4 = posets.TamariLattice(4) 

sage: T4.is_semidistributive(), T4.is_distributive() 

(True, False) 

 

Smallest non-selfdual example:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [5], 4: [6], 5: [7], 6: [7]}) 

sage: L.is_semidistributive() 

True 

 

The diamond is not semidistributive:: 

 

sage: L = posets.DiamondPoset(5) 

sage: L.is_semidistributive() 

False 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_join_semidistributive`, 

:meth:`is_meet_semidistributive` 

- Stronger properties: :meth:`is_distributive` 

 

TESTS:: 

 

sage: LatticePoset().is_semidistributive() 

True 

sage: LatticePoset({1: []}).is_semidistributive() 

True 

""" 

H = self._hasse_diagram 

# See trac #21528 for explanation. 

return ( (H.in_degree_sequence().count(1) == 

H.out_degree_sequence().count(1)) and 

self.is_meet_semidistributive() ) 

 

def is_meet_semidistributive(self, certificate=False): 

r""" 

Return ``True`` if the lattice is meet-semidistributive, and ``False`` 

otherwise. 

 

A lattice is meet-semidistributive if for all elements 

`e, x, y` in the lattice we have 

 

.. MATH:: 

 

e \wedge x = e \wedge y \implies 

e \wedge x = e \wedge (x \vee y) 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (e, x, y))`` such that `e \wedge x = e \wedge y` 

but `e \wedge x \neq e \wedge (x \vee y)`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1:[2, 3, 4], 2:[4, 5], 3:[5, 6], 

....: 4:[7], 5:[7], 6:[7]}) 

sage: L.is_meet_semidistributive() 

True 

sage: L_ = L.dual() 

sage: L_.is_meet_semidistributive() 

False 

sage: L_.is_meet_semidistributive(certificate=True) 

(False, (5, 4, 6)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_join_semidistributive` 

- Weaker properties: :meth:`is_pseudocomplemented` 

- Stronger properties: :meth:`is_semidistributive`, 

:meth:`is_join_distributive`, 

:meth:`is_constructible_by_doublings` (by upper pseudo-intervals) 

 

TESTS:: 

 

sage: LatticePoset().is_meet_semidistributive() 

True 

 

Smallest lattice that fails the quick check:: 

 

sage: L = LatticePoset(DiGraph('IY_T@A?CC_@?W?O@??')) 

sage: L.is_meet_semidistributive() 

False 

 

Confirm that :trac:`21340` is fixed:: 

 

sage: posets.BooleanLattice(4).is_meet_semidistributive() 

True 

""" 

# See http://www.math.hawaii.edu/~ralph/Preprints/algorithms-survey.pdf 

# for explanation of this 

n = self.cardinality() 

if n == 0: 

if certificate: 

return (True, None) 

return True 

H = self._hasse_diagram 

if not certificate and H.size() * 2 > n * _log_2(n): 

return False 

 

for v in H: 

if H.in_degree(v) == 1 and H.kappa(v) is None: 

if not certificate: 

return False 

v_ = next(H.neighbor_in_iterator(v)) 

t1 = set(H.depth_first_search(v_)) 

t2 = set(H.depth_first_search(v)) 

tmp = sorted(t1.difference(t2), reverse=True) 

x = tmp[0] 

for y in tmp: 

if H.are_incomparable(x, y): 

return (False, 

(self._vertex_to_element(v), 

self._vertex_to_element(x), 

self._vertex_to_element(y))) 

if certificate: 

return (True, None) 

return True 

 

def is_join_semidistributive(self, certificate=False): 

r""" 

Return ``True`` if the lattice is join-semidistributive, and ``False`` 

otherwise. 

 

A lattice is join-semidistributive if for all elements `e, x, y` in 

the lattice we have 

 

.. MATH:: 

 

e \vee x = e \vee y \implies 

e \vee x = e \vee (x \wedge y) 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (e, x, y))`` such that `e \vee x = e \vee y` 

but `e \vee x \neq e \vee (x \wedge y)`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: T4 = posets.TamariLattice(4) 

sage: T4.is_join_semidistributive() 

True 

sage: L = LatticePoset({1:[2, 3], 2:[4, 5], 3:[5, 6], 

....: 4:[7], 5:[7], 6:[7]}) 

sage: L.is_join_semidistributive() 

False 

sage: L.is_join_semidistributive(certificate=True) 

(False, (5, 4, 6)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_meet_semidistributive` 

- Weaker properties: :meth:`is_join_pseudocomplemented` 

- Stronger properties: :meth:`is_semidistributive`, 

:meth:`is_meet_distributive`, 

:meth:`is_constructible_by_doublings` (by lower pseudo-intervals) 

 

TESTS:: 

 

sage: LatticePoset().is_join_semidistributive() 

True 

 

Smallest lattice that fails the quick check:: 

 

sage: L = LatticePoset(DiGraph('IY_T@A?CC_@?W?O@??')) 

sage: L.is_join_semidistributive() 

False 

 

Confirm that :trac:`21340` is fixed:: 

 

sage: posets.BooleanLattice(3).is_join_semidistributive() 

True 

""" 

# See http://www.math.hawaii.edu/~ralph/Preprints/algorithms-survey.pdf 

# for explanation of this 

n = self.cardinality() 

if n == 0: 

if certificate: 

return (True, None) 

return True 

H = self._hasse_diagram 

if not certificate and H.size() * 2 > n * _log_2(n): 

return False 

 

for v in H: 

if H.out_degree(v) == 1 and H.kappa_dual(v) is None: 

if not certificate: 

return False 

v_ = next(H.neighbor_out_iterator(v)) 

it = H.neighbor_in_iterator 

t1 = set(H.depth_first_search(v_, neighbors=it)) 

t2 = set(H.depth_first_search(v, neighbors=it)) 

tmp = sorted(t1.difference(t2)) 

x = tmp[0] 

for y in tmp: 

if H.are_incomparable(x, y): 

return (False, 

(self._vertex_to_element(v), 

self._vertex_to_element(x), 

self._vertex_to_element(y))) 

if certificate: 

return (True, None) 

return True 

 

return all(H.kappa_dual(v) is not None 

for v in H if H.out_degree(v) == 1) 

 

def is_complemented(self, certificate=False): 

r""" 

Return ``True`` if the lattice is complemented, and 

``False`` otherwise. 

 

A lattice is complemented if every element has at least one 

complement. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where ``e`` is an element without a complement. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) 

sage: L.is_complemented() 

True 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], 4: [6], 

....: 5: [7], 6: [7]}) 

sage: L.is_complemented() 

False 

sage: L.is_complemented(certificate=True) 

(False, 2) 

 

.. SEEALSO:: 

 

- Stronger properties: :meth:`is_sectionally_complemented`, 

:meth:`is_cosectionally_complemented`, 

:meth:`is_orthocomplemented` 

- Other: :meth:`complements` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_complemented() for i in range(5)] 

[True, True, True, False, False] 

""" 

e = self._hasse_diagram.is_complemented() 

if not certificate: 

return e is None 

if e is None: 

return (True, None) 

return (False, self._vertex_to_element(e)) 

 

def is_cosectionally_complemented(self, certificate=False): 

""" 

Return ``True`` if the lattice is cosectionally complemented, and 

``False`` otherwise. 

 

A lattice is *cosectionally complemented* if all intervals to 

the top element interpreted as sublattices are complemented 

lattices. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) Whether to return 

a certificate if the lattice is not cosectionally complemented. 

 

OUTPUT: 

 

- If ``certificate=False`` return ``True`` or ``False``. 

If ``certificate=True`` return either ``(True, None)`` 

or ``(False, (b, e))``, where `b` is an element so that in the 

sublattice from `b` to the top element has no complement 

for element `e`. 

 

EXAMPLES: 

 

The smallest sectionally but not cosectionally complemented lattice:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3: [5], 4: [6], 5: [6]}) 

sage: L.is_sectionally_complemented(), L.is_cosectionally_complemented() 

(True, False) 

 

A sectionally and cosectionally but not relatively complemented 

lattice:: 

 

sage: L = LatticePoset(DiGraph('MYi@O?P??D?OG?@?O_?C?Q??O?W?@??O??')) 

sage: L.is_sectionally_complemented() and L.is_cosectionally_complemented() 

True 

sage: L.is_relatively_complemented() 

False 

 

Getting a certificate:: 

 

sage: L = LatticePoset(DiGraph('HW?@D?Q?GE?G@??')) 

sage: L.is_cosectionally_complemented(certificate=True) 

(False, (2, 7)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_sectionally_complemented` 

- Weaker properties: :meth:`is_complemented`, :meth:`is_coatomic`, 

:meth:`is_regular` 

- Stronger properties: :meth:`is_relatively_complemented` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_cosectionally_complemented() for i in range(5)] 

[True, True, True, False, False] 

""" 

# Quick check: every sectionally complemented lattice is atomic. 

if not certificate and not self.is_coatomic(): 

return False 

 

n = self.cardinality() 

H = self._hasse_diagram 

mt = H._meet 

jn = H._join 

top = n - 1 

 

for bottom in range(n - 3, -1, -1): 

interval = H.principal_order_filter(bottom) 

for e in interval: 

for f in interval: 

if mt[e, f] == bottom and jn[e, f] == top: 

break 

else: 

if certificate: 

return (False, (self._vertex_to_element(bottom), 

self._vertex_to_element(e))) 

return False 

 

return (True, None) if certificate else True 

 

def is_relatively_complemented(self, certificate=False): 

""" 

Return ``True`` if the lattice is relatively complemented, and 

``False`` otherwise. 

 

A lattice is relatively complemented if every interval of it 

is a complemented lattice. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) Whether to return 

a certificate if the lattice is not relatively complemented. 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (a, b, c))``, where `b` is the only element that 

covers `a` and is covered by `c`. If ``certificate=False`` 

return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4, 8], 2: [5, 6], 3: [5, 7], 

....: 4: [6, 7], 5: [9], 6: [9], 7: [9], 8: [9]}) 

sage: L.is_relatively_complemented() 

True 

 

sage: L = posets.PentagonPoset() 

sage: L.is_relatively_complemented() 

False 

 

Relatively complemented lattice must be both atomic and coatomic. 

Implication to other direction does not hold:: 

 

sage: L = LatticePoset({0: [1, 2, 3, 4, 5], 1: [6, 7], 2: [6, 8], 

....: 3: [7, 8, 9], 4: [9, 11], 5: [9, 10], 

....: 6: [10, 11], 7: [12], 8: [12], 9: [12], 

....: 10: [12], 11: [12]}) 

sage: L.is_atomic() and L.is_coatomic() 

True 

sage: L.is_relatively_complemented() 

False 

 

We can also get a non-complemented 3-element interval:: 

 

sage: L.is_relatively_complemented(certificate=True) 

(False, (1, 6, 11)) 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_sectionally_complemented`, 

:meth:`is_cosectionally_complemented`, :meth:`is_isoform` 

- Stronger properties: :meth:`is_geometric` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_relatively_complemented() for 

....: i in range(5)] 

[True, True, True, False, False] 

 

Usually a lattice that is not relatively complemented contains elements 

`l`, `m`, and `u` such that `r(l) + 1 = r(m) = r(u) - 1`, where `r` is 

the rank function and `m` is the only element in the interval `[l, u]`. 

We construct an example where this does not hold:: 

 

sage: B3 = posets.BooleanLattice(3) 

sage: B5 = posets.BooleanLattice(5) 

sage: B3 = B3.subposet([e for e in B3 if e not in [0, 7]]) 

sage: B5 = B5.subposet([e for e in B5 if e not in [0, 31]]) 

sage: B3 = B3.hasse_diagram() 

sage: B5 = B5.relabel(lambda x: x+10).hasse_diagram() 

sage: G = B3.union(B5) 

sage: G.add_edge(B3.sources()[0], B5.neighbors_in(B5.sinks()[0])[0]) 

sage: L = LatticePoset(Poset(G).with_bounds()) 

sage: L.is_relatively_complemented() 

False 

 

Confirm that :trac:`22292` is fixed:: 

 

sage: L = LatticePoset(DiGraph('IYOS`G?CE?@?C?_@??')) 

sage: L.is_relatively_complemented(certificate=True) 

(False, (7, 8, 9)) 

""" 

from sage.misc.flatten import flatten 

from collections import Counter 

 

# Work directly with Hasse diagram 

H = self._hasse_diagram 

n = H.order() 

if n < 3: 

return (True, None) if certificate else True 

 

# Quick check: the lattice must be atomic and coatomic. 

if not certificate: 

if H.out_degree(0) != H.in_degree().count(1): 

return False 

if H.in_degree(n - 1) != H.out_degree().count(1): 

return False 

 

for e1 in range(n - 1): 

C = Counter(flatten([H.neighbors_out(e2) for e2 in H.neighbors_out(e1)])) 

for e3, c in iteritems(C): 

if c == 1 and len(H.closed_interval(e1, e3)) == 3: 

if not certificate: 

return False 

for e2 in H.neighbors_in(e3): 

if e2 in H.neighbors_out(e1): 

break 

return (False, (self._vertex_to_element(e1), 

self._vertex_to_element(e2), 

self._vertex_to_element(e3))) 

return (True, None) if certificate else True 

 

def is_sectionally_complemented(self, certificate=False): 

""" 

Return ``True`` if the lattice is sectionally complemented, and 

``False`` otherwise. 

 

A lattice is sectionally complemented if all intervals from 

the bottom element interpreted as sublattices are complemented 

lattices. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) Whether to return 

a certificate if the lattice is not sectionally complemented. 

 

OUTPUT: 

 

- If ``certificate=False`` return ``True`` or ``False``. 

If ``certificate=True`` return either ``(True, None)`` 

or ``(False, (t, e))``, where `t` is an element so that in the 

sublattice from the bottom element to `t` has no complement 

for element `e`. 

 

EXAMPLES: 

 

Smallest examples of a complemented but not sectionally complemented 

lattice and a sectionally complemented but not relatively complemented 

lattice:: 

 

sage: L = posets.PentagonPoset() 

sage: L.is_complemented() 

True 

sage: L.is_sectionally_complemented() 

False 

 

sage: L = LatticePoset({0: [1, 2, 3], 1: [4], 2: [4], 3: [5], 4: [5]}) 

sage: L.is_sectionally_complemented() 

True 

sage: L.is_relatively_complemented() 

False 

 

Getting a certificate:: 

 

sage: L = LatticePoset(DiGraph('HYOgC?C@?C?G@??')) 

sage: L.is_sectionally_complemented(certificate=True) 

(False, (6, 1)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_cosectionally_complemented` 

- Weaker properties: :meth:`is_complemented`, :meth:`is_atomic`, 

:meth:`is_regular` 

- Stronger properties: :meth:`is_relatively_complemented` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_sectionally_complemented() for i in range(5)] 

[True, True, True, False, False] 

""" 

# Quick check: every sectionally complemented lattice is atomic. 

if not certificate and not self.is_atomic(): 

return False 

 

n = self.cardinality() 

H = self._hasse_diagram 

mt = H._meet 

jn = H._join 

bottom = 0 

 

for top in range(n): 

interval = H.principal_order_ideal(top) 

for e in interval: 

for f in interval: 

if mt[e, f] == bottom and jn[e, f] == top: 

break 

else: 

if certificate: 

return (False, (self._vertex_to_element(top), 

self._vertex_to_element(e))) 

return False 

 

return (True, None) if certificate else True 

 

def breadth(self, certificate=False): 

r""" 

Return the breadth of the lattice. 

 

The breadth of a lattice is the largest integer `n` such that 

any join of elements `x_1, x_2, \ldots, x_{n+1}` is join of a 

proper subset of `x_i`. 

 

This can be also characterized by sublattices: a lattice 

of breadth at least `n` contains a sublattice isomorphic to the 

Boolean lattice of `2^n` elements. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return the pair `(b, a)` where `b` is 

the breadth and `a` is an antichain such that the join of `a` 

differs from the join of any proper subset of `a`. 

If ``certificate=False`` return just the breadth. 

 

EXAMPLES:: 

 

sage: D10 = posets.DiamondPoset(10) 

sage: D10.breadth() 

2 

 

sage: B3 = posets.BooleanLattice(3) 

sage: B3.breadth() 

3 

sage: B3.breadth(certificate=True) 

(3, [1, 2, 4]) 

 

ALGORITHM: 

 

For a lattice to have breadth at least `n`, it must have an 

`n`-element antichain `A` with join `j`. Element `j` must 

cover at least `n` elements. There must also be `n-2` levels 

of elements between `A` and `j`. So we start by searching 

elements that could be our `j` and then just check possible 

antichains `A`. 

 

.. NOTE:: 

 

Prior to version 8.1 this function returned just an 

antichain with ``certificate=True``. 

 

TESTS:: 

 

sage: posets.ChainPoset(0).breadth() 

0 

sage: posets.ChainPoset(1).breadth() 

1 

""" 

# A place for optimization: Adding a doubly irreducible element to 

# a lattice does not change the breadth, except from 1 to 2. 

# Hence we could start by removing double irreducibles. 

 

from sage.combinat.subsets_pairwise import PairwiseCompatibleSubsets 

 

# First check if breadth is zero (empty lattice) or one (a chain). 

n = self.cardinality() 

if n == 0: 

return (0, []) if certificate else 0 

if self.is_chain(): 

return (1, [self.bottom()]) if certificate else 1 

# Breadth is at least two. 

 

# Work directly with the Hasse diagram 

H = self._hasse_diagram 

 

# Helper function: Join of elements in the list L. 

jn = H._join 

 

def join(L): 

j = 0 

for i in L: 

j = jn[i, j] 

return j 

 

indegs = [H.in_degree(i) for i in range(n)] 

max_breadth = max(indegs) 

 

for B in range(max_breadth, 1, -1): 

for j in H: 

if indegs[j] < B: 

continue 

 

# Get elements more than B levels below it. 

too_close = set(H.breadth_first_search(j, 

neighbors=H.neighbors_in, 

distance=B - 2)) 

elems = [e for e in H.order_ideal([j]) if e not in too_close] 

 

achains = PairwiseCompatibleSubsets(elems, 

lambda x, y: H.are_incomparable(x, y)) 

achains_n = achains.elements_of_depth_iterator(B) 

 

for A in achains_n: 

if join(A) == j: 

if all(join(A[:i] + A[i + 1:]) != j for i in range(B)): 

if certificate: 

return (B, [self._vertex_to_element(e) for e in A]) 

else: 

return B 

assert False, "BUG: breadth() in lattices.py have an error." 

 

def complements(self, element=None): 

r""" 

Return the list of complements of an element in the lattice, 

or the dictionary of complements for all elements. 

 

Elements `x` and `y` are complements if their meet and join 

are respectively the bottom and the top element of the lattice. 

 

INPUT: 

 

- ``element`` -- an element of the lattice whose complement is 

returned. If ``None`` (default) then dictionary of 

complements for all elements having at least one 

complement is returned. 

 

EXAMPLES:: 

 

sage: L=LatticePoset({0:['a','b','c'], 'a':[1], 'b':[1], 'c':[1]}) 

sage: C = L.complements() 

 

Let us check that 'a' and 'b' are complements of each other:: 

 

sage: 'a' in C['b'] 

True 

sage: 'b' in C['a'] 

True 

 

Full list of complements:: 

 

sage: L.complements() # random order 

{0: [1], 1: [0], 'a': ['b', 'c'], 'b': ['c', 'a'], 'c': ['b', 'a']} 

 

sage: L=LatticePoset({0:[1,2],1:[3],2:[3],3:[4]}) 

sage: L.complements() # random order 

{0: [4], 4: [0]} 

sage: L.complements(1) 

[] 

 

.. SEEALSO:: :meth:`is_complemented` 

 

TESTS:: 

 

sage: L=LatticePoset({0:['a','b','c'], 'a':[1], 'b':[1], 'c':[1]}) 

sage: for v,v_complements in L.complements().items(): 

....: for v_c in v_complements: 

....: assert L.meet(v,v_c) == L.bottom() 

....: assert L.join(v,v_c) == L.top() 

 

sage: posets.ChainPoset(0).complements() 

{} 

sage: posets.ChainPoset(1).complements() 

{0: [0]} 

sage: posets.ChainPoset(2).complements() 

{0: [1], 1: [0]} 

""" 

if element is None: 

n = self.cardinality() 

if n == 1: 

return {self[0]: [self[0]]} 

jn = self.join_matrix() 

mt = self.meet_matrix() 

zero = 0 

one = n - 1 

c = [[] for x in range(n)] 

for x in range(n): 

for y in range(x, n): 

if jn[x][y] == one and mt[x][y] == zero: 

c[x].append(y) 

c[y].append(x) 

 

comps = {} 

for i in range(n): 

if c[i]: 

comps[self._vertex_to_element(i)] = ( 

[self._vertex_to_element(x) for x in c[i]]) 

return comps 

 

# Looking for complements of one element. 

if element not in self: 

raise ValueError("element (=%s) not in poset" % element) 

return [x for x in self 

if self.meet(x, element) == self.bottom() and 

self.join(x, element) == self.top()] 

 

def is_pseudocomplemented(self, certificate=False): 

""" 

Return ``True`` if the lattice is pseudocomplemented, and ``False`` 

otherwise. 

 

A lattice is (meet-)pseudocomplemented if every element `e` has a 

pseudocomplement `e^\star`, i.e. the greatest element such that 

the meet of `e` and `e^\star` is the bottom element. 

 

See :wikipedia:`Pseudocomplement`. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where ``e`` is an element without a 

pseudocomplement. If ``certificate=False`` return ``True`` 

or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 5], 2: [3, 6], 3: [4], 4: [7], 

....: 5: [6], 6: [7]}) 

sage: L.is_pseudocomplemented() 

True 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5, 6], 3: [6], 4: [7], 

....: 5: [7], 6: [7]}) 

sage: L.is_pseudocomplemented() 

False 

sage: L.is_pseudocomplemented(certificate=True) 

(False, 3) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_join_pseudocomplemented` 

- Stronger properties: :meth:`is_meet_semidistributive` 

- Other: :meth:`~sage.combinat.posets.lattices.FiniteMeetSemilattice.pseudocomplement()`. 

 

ALGORITHM: 

 

According to [Cha92]_ a lattice is pseudocomplemented if and 

only if every atom has a pseudocomplement. So we only check those. 

 

TESTS:: 

 

sage: LatticePoset({}).is_pseudocomplemented() 

True 

""" 

H = self._hasse_diagram 

if H.order() == 0: 

if certificate: 

return (True, None) 

return True 

for e in H.neighbor_out_iterator(0): 

if H.kappa(e) is None: 

if certificate: 

return (False, self._vertex_to_element(e)) 

return False 

if certificate: 

return (True, None) 

return True 

 

def is_join_pseudocomplemented(self, certificate=False): 

""" 

Return ``True`` if the lattice is join-pseudocomplemented, and 

``False`` otherwise. 

 

A lattice is join-pseudocomplemented if every element `e` has a 

join-pseudocomplement `e'`, i.e. the least element such that 

the join of `e` and `e'` is the top element. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where ``e`` is an element without a 

join-pseudocomplement. If ``certificate=False`` return ``True`` 

or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 5], 2: [3, 6], 3: [4], 4: [7], 

....: 5: [6], 6: [7]}) 

sage: L.is_join_pseudocomplemented() 

True 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5, 6], 3: [6], 4: [7], 

....: 5: [7], 6: [7]}) 

sage: L.is_join_pseudocomplemented() 

False 

sage: L.is_join_pseudocomplemented(certificate=True) 

(False, 4) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_pseudocomplemented` 

- Stronger properties: :meth:`is_join_semidistributive` 

 

TESTS:: 

 

sage: LatticePoset({}).is_pseudocomplemented() 

True 

""" 

H = self._hasse_diagram 

if H.order() == 0: 

if certificate: 

return (True, None) 

return True 

for e in H.neighbor_in_iterator(H.order() - 1): 

if H.kappa_dual(e) is None: 

if certificate: 

return (False, self._vertex_to_element(e)) 

return False 

if certificate: 

return (True, None) 

return True 

 

def skeleton(self): 

""" 

Return the skeleton of the lattice. 

 

The lattice is expected to be pseudocomplemented. 

 

The *skeleton* of a pseudocomplemented lattice `L`, where `^*` is 

the pseudocomplementation operation, is the subposet induced by 

`\{e^* \mid e \in L\}`. Actually this poset is a Boolean lattice. 

 

EXAMPLES:: 

 

sage: D12 = posets.DivisorLattice(12) 

sage: S = D12.skeleton(); S 

Finite lattice containing 4 elements 

sage: S.cover_relations() 

[[1, 3], [1, 4], [3, 12], [4, 12]] 

 

sage: T4 = posets.TamariLattice(4) 

sage: T4.skeleton().is_isomorphic(posets.BooleanLattice(3)) 

True 

 

.. SEEALSO:: :meth:`sage.combinat.posets.lattices.FiniteMeetSemilattice.pseudocomplement`. 

 

TESTS:: 

 

sage: posets.ChainPoset(0).skeleton() 

Finite lattice containing 0 elements 

sage: posets.ChainPoset(1).skeleton() 

Finite lattice containing 1 elements 

sage: posets.ChainPoset(2).skeleton() 

Finite lattice containing 2 elements 

sage: posets.ChainPoset(3).skeleton() 

Finite lattice containing 2 elements 

 

sage: L = posets.BooleanLattice(3) 

sage: L == L.skeleton() 

True 

 

sage: posets.DiamondPoset(5).skeleton() 

Traceback (most recent call last): 

... 

ValueError: lattice is not pseudocomplemented 

""" 

# TODO: What about non-facade lattices and lattices with 

# given linear extension? 

if self.cardinality() < 3: 

return self 

elms = [self._vertex_to_element(v) for v in 

self._hasse_diagram.skeleton()] 

return LatticePoset(self.subposet(elms)) 

 

def is_orthocomplemented(self, unique=False): 

""" 

Return ``True`` if the lattice admits an orthocomplementation, and 

``False`` otherwise. 

 

An orthocomplementation of a lattice is a function defined for 

every element `e` and marked as `e^{\\bot}` such that 

1) they are complements, i.e. `e \\vee e^{\\bot}` is the top element 

and `e \\wedge e^{\\bot}` is the bottom element, 2) it is involution, 

i.e. `{(e^{\\bot})}^{\\bot} = e`, and 3) it is order-reversing, i.e. 

if `a < b` then `b^{\\bot} < a^{\\bot}`. 

 

INPUT: 

 

- ``unique``, a Boolean -- If ``True``, return ``True`` only 

if the lattice has exactly one orthocomplementation. If 

``False`` (the default), return ``True`` when the lattice 

has at least one orthocomplementation. 

 

EXAMPLES:: 

 

sage: D5 = posets.DiamondPoset(5) 

sage: D5.is_orthocomplemented() 

False 

 

sage: D6 = posets.DiamondPoset(6) 

sage: D6.is_orthocomplemented() 

True 

sage: D6.is_orthocomplemented(unique=True) 

False 

 

sage: hexagon = LatticePoset({0:[1, 2], 1:[3], 2:[4], 3:[5], 4:[5]}) 

sage: hexagon.is_orthocomplemented(unique=True) 

True 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_complemented`, 

:meth:`~sage.categories.finite_posets.FinitePosets.ParentMethods.is_self_dual` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_orthocomplemented() for i in range(4)] 

[True, True, True, False] 

""" 

it = self._hasse_diagram.orthocomplementations_iterator() 

try: 

_ = next(it) 

if not unique: 

return True 

except StopIteration: 

return False 

try: 

_ = next(it) 

return False 

except StopIteration: 

return True 

raise AssertionError("bug in is_orthocomplemented()") 

 

def is_atomic(self, certificate=False): 

r""" 

Return ``True`` if the lattice is atomic, and ``False`` otherwise. 

 

A lattice is atomic if every element can be written as a join of atoms. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where `e` is a join-irreducible element 

that is not an atom. If ``certificate=False`` return 

``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3:[5], 4:[6], 5:[6]}) 

sage: L.is_atomic() 

True 

 

sage: L = LatticePoset({0: [1, 2], 1: [3], 2: [3], 3:[4]}) 

sage: L.is_atomic() 

False 

sage: L.is_atomic(certificate=True) 

(False, 4) 

 

TESTS:: 

 

sage: LatticePoset({}).is_atomic() 

True 

 

NOTES: 

 

See [EnumComb1]_, Section 3.3 for a discussion of atomic lattices. 

 

.. SEEALSO:: 

 

- Dual property: :meth:`~FiniteLatticePoset.is_coatomic` 

- Stronger properties: :meth:`is_sectionally_complemented` 

- Mutually exclusive properties: :meth:`is_vertically_decomposable` 

""" 

if not certificate: 

return (self.cardinality() == 0 or 

self._hasse_diagram.out_degree(0) == 

self._hasse_diagram.in_degree().count(1)) 

if self.cardinality() < 3: 

return (True, None) 

H = self._hasse_diagram 

atoms = set(H.neighbors_out(0)) 

for v in H: 

if H.in_degree(v) == 1 and v not in atoms: 

return (False, self._vertex_to_element(v)) 

return (True, None) 

 

def is_coatomic(self, certificate=False): 

r""" 

Return ``True`` if the lattice is coatomic, and ``False`` otherwise. 

 

A lattice is coatomic if every element can be written as a meet 

of coatoms; i.e. if the dual of the lattice is atomic. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, e)``, where `e` is a meet-irreducible element 

that is not a coatom. If ``certificate=False`` return 

``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = posets.BooleanLattice(3) 

sage: L.is_coatomic() 

True 

 

sage: L = LatticePoset({1: [2], 2: [3, 4], 3: [5], 4:[5]}) 

sage: L.is_coatomic() 

False 

sage: L.is_coatomic(certificate=True) 

(False, 1) 

 

TESTS:: 

 

sage: LatticePoset({}).is_coatomic() 

True 

 

.. SEEALSO:: 

 

- Dual property: :meth:`~FiniteLatticePoset.is_atomic` 

- Stronger properties: :meth:`is_cosectionally_complemented` 

- Mutually exclusive properties: :meth:`is_vertically_decomposable` 

""" 

n = self.cardinality() 

if not certificate: 

if n == 0: 

return True 

return (self._hasse_diagram.in_degree(n - 1) == 

self._hasse_diagram.out_degree().count(1)) 

 

if self.cardinality() < 3: 

return (True, None) 

H = self._hasse_diagram 

coatoms = set(H.neighbors_in(n - 1)) 

for v in H: 

if H.out_degree(v) == 1 and v not in coatoms: 

return (False, self._vertex_to_element(v)) 

return (True, None) 

 

def is_geometric(self): 

""" 

Return ``True`` if the lattice is geometric, and ``False`` otherwise. 

 

A lattice is geometric if it is both atomic and upper semimodular. 

 

EXAMPLES: 

 

Canonical example is the lattice of partitions of finite set 

ordered by refinement:: 

 

sage: S = SetPartitions(3) 

sage: L = LatticePoset( (S, lambda a, b: S.is_less_than(a, b)) ) 

sage: L.is_geometric() 

True 

 

Smallest example of geometric lattice that is not modular:: 

 

sage: L = LatticePoset(DiGraph('K]?@g@S?q?M?@?@?@?@?@?@??')) 

sage: L.is_geometric() 

True 

sage: L.is_modular() 

False 

 

Two non-examples:: 

 

sage: L = LatticePoset({1:[2, 3, 4], 2:[5, 6], 3:[5], 4:[6], 5:[7], 6:[7]}) 

sage: L.is_geometric() # Graded, but not upper semimodular 

False 

sage: L = posets.ChainPoset(3) 

sage: L.is_geometric() # Modular, but not atomic 

False 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_upper_semimodular`, :meth:`is_relatively_complemented` 

 

TESTS:: 

 

sage: LatticePoset({}).is_geometric() 

True 

sage: LatticePoset({1:[]}).is_geometric() 

True 

""" 

return self.is_atomic() and self.is_upper_semimodular() 

 

def is_planar(self): 

r""" 

Return ``True`` if the lattice is *upward* planar, and ``False`` 

otherwise. 

 

A lattice is upward planar if its Hasse diagram has a planar drawing in 

the `\mathbb{R}^2` plane, in such a way that `x` is strictly below `y` 

(on the vertical axis) whenever `x<y` in the lattice. 

 

Note that the scientific litterature on posets often omits "upward" and 

shortens it to "planar lattice" (e.g. [GW2014]_), which can cause 

confusion with the notion of graph planarity in graph theory. 

 

.. NOTE:: 

 

Not all lattices which are planar -- in the sense of graph planarity 

-- admit such a planar drawing (see example below). 

 

ALGORITHM: 

 

Using the result from [Platt1976]_, this method returns its result by 

testing that the Hasse diagram of the lattice is planar (in the sense of 

graph theory) when an edge is added between the top and bottom elements. 

 

EXAMPLES: 

 

The Boolean lattice of `2^3` elements is not upward planar, even if 

it's covering relations graph is planar:: 

 

sage: B3 = posets.BooleanLattice(3) 

sage: B3.is_planar() 

False 

sage: G = B3.cover_relations_graph() 

sage: G.is_planar() 

True 

 

Ordinal product of planar lattices is obviously planar. Same does 

not apply to Cartesian products:: 

 

sage: P = posets.PentagonPoset() 

sage: Pc = P.product(P) 

sage: Po = P.ordinal_product(P) 

sage: Pc.is_planar() 

False 

sage: Po.is_planar() 

True 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_dismantlable` 

 

TESTS:: 

 

sage: posets.ChainPoset(0).is_planar() 

True 

sage: posets.ChainPoset(1).is_planar() 

True 

""" 

# The 8-element Boolean lattice is the smallest non-planar lattice. 

if self.cardinality() < 8: 

return True 

g = self._hasse_diagram.copy(immutable=False) 

g.add_edge(0, self.cardinality() - 1) 

return g.is_planar() 

 

def is_modular(self, L=None, certificate=False): 

r""" 

Return ``True`` if the lattice is modular and ``False`` otherwise. 

 

An element `b` of a lattice is *modular* if 

 

.. MATH:: 

 

x \vee (a \wedge b) = (x \vee a) \wedge b 

 

for every element `x \leq b` and `a`. A lattice is modular if every 

element is modular. There are other equivalent definitions, see 

:wikipedia:`Modular_lattice`. 

 

With the parameter ``L`` this can be used to check that 

some subset of elements are all modular. 

 

INPUT: 

 

- ``L`` -- (default: ``None``) a list of elements to check being 

modular, if ``L`` is ``None``, then this checks the entire lattice 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (x, a, b))``, where `a`, `b` and `x` are elements 

of the lattice such that `x < b` but 

`x \vee (a \wedge b) \neq (x \vee a) \wedge b`. If also 

`L` is given then `b` in the certificate will be an element 

of `L`. If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = posets.DiamondPoset(5) 

sage: L.is_modular() 

True 

 

sage: L = posets.PentagonPoset() 

sage: L.is_modular() 

False 

 

sage: L = LatticePoset({1:[2,3],2:[4,5],3:[5,6],4:[7],5:[7],6:[7]}) 

sage: L.is_modular(certificate=True) 

(False, (2, 6, 4)) 

sage: [L.is_modular([x]) for x in L] 

[True, True, False, True, True, False, True] 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_upper_semimodular`, 

:meth:`is_lower_semimodular`, :meth:`is_supersolvable` 

- Stronger properties: :meth:`is_distributive` 

- Other: :meth:`is_modular_element` 

 

TESTS:: 

 

sage: all(posets.ChainPoset(i).is_modular() for i in range(4)) 

True 

 

sage: L = LatticePoset({1:[2,3],2:[4,5],3:[5,6],4:[7],5:[7],6:[7]}) 

sage: L.is_modular(L=[1, 4, 2], certificate=True) 

(False, (2, 6, 4)) 

sage: L.is_modular(L=[1, 6, 2], certificate=True) 

(False, (3, 4, 6)) 

""" 

if not certificate and L is None: 

return self.is_upper_semimodular() and self.is_lower_semimodular() 

 

if certificate and L is None: 

tmp = self.is_lower_semimodular(certificate=True) 

if not tmp[0]: 

a, b = tmp[1] 

t = self.meet(a, b) 

for x in self.upper_covers(t): 

if self.is_less_than(x, b): 

return (False, (x, a, b)) 

if self.is_less_than(x, a): 

return (False, (x, b, a)) 

tmp = self.is_upper_semimodular(certificate=True) 

if not tmp[0]: 

x, a = tmp[1] 

t = self.join(x, a) 

for b in self.lower_covers(t): 

if self.is_greater_than(b, x): 

return (False, (x, a, b)) 

if self.is_greater_than(b, a): 

return (False, (a, x, b)) 

return (True, None) 

 

# L is not None 

for b in L: 

for x in self.principal_lower_set(b): 

for a in self: 

if (self.join(x, self.meet(a, b)) != 

self.meet(self.join(x, a), b)): 

if certificate: 

return (False, (x, a, b)) 

return False 

if certificate: 

return (True, None) 

return True 

 

def is_modular_element(self, x): 

r""" 

Return ``True`` if ``x`` is a modular element and ``False`` otherwise. 

 

INPUT: 

 

- ``x`` -- an element of the lattice 

 

An element `x` in a lattice `L` is *modular* if `x \leq b` implies 

 

.. MATH:: 

 

x \vee (a \wedge b) = (x \vee a) \wedge b 

 

for every `a, b \in L`. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1:[2,3],2:[4,5],3:[5,6],4:[7],5:[7],6:[7]}) 

sage: L.is_modular() 

False 

sage: [L.is_modular_element(x) for x in L] 

[True, True, False, True, True, False, True] 

 

.. SEEALSO:: 

 

:meth:`is_modular` to check modularity for the full lattice or 

some set of elements 

""" 

return self.is_modular([x]) 

 

def is_upper_semimodular(self, certificate=False): 

r""" 

Return ``True`` if the lattice is upper semimodular and 

``False`` otherwise. 

 

A lattice is upper semimodular if any pair of elements with 

a common lower cover have also a common upper cover. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) Whether to return 

a certificate if the lattice is not upper semimodular. 

 

OUTPUT: 

 

- If ``certificate=False`` return ``True`` or ``False``. 

If ``certificate=True`` return either ``(True, None)`` or 

``(False, (a, b))``, where `a` and `b` covers their meet but 

are not covered by their join. 

 

See :wikipedia:`Semimodular_lattice` 

 

EXAMPLES:: 

 

sage: L = posets.DiamondPoset(5) 

sage: L.is_upper_semimodular() 

True 

 

sage: L = posets.PentagonPoset() 

sage: L.is_upper_semimodular() 

False 

 

sage: L = LatticePoset(posets.IntegerPartitions(4)) 

sage: L.is_upper_semimodular() 

True 

 

sage: L = LatticePoset({1:[2, 3, 4], 2: [5], 3:[5, 6], 4:[6], 5:[7], 6:[7]}) 

sage: L.is_upper_semimodular(certificate=True) 

(False, (4, 2)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_lower_semimodular` 

- Weaker properties: :meth:`~sage.combinat.posets.posets.FinitePoset.is_graded` 

- Stronger properties: :meth:`is_modular`, 

:meth:`is_join_distributive`, :meth:`is_geometric` 

 

TESTS:: 

 

sage: all(posets.ChainPoset(i).is_upper_semimodular() for i in range(5)) 

True 

""" 

nonmodular = self._hasse_diagram.find_nonsemimodular_pair(upper=True) 

if nonmodular is None: 

return (True, None) if certificate else True 

if certificate: 

return (False, (self._vertex_to_element(nonmodular[0]), 

self._vertex_to_element(nonmodular[1]))) 

return False 

 

def is_lower_semimodular(self, certificate=False): 

r""" 

Return ``True`` if the lattice is lower semimodular and 

``False`` otherwise. 

 

A lattice is lower semimodular if any pair of elements with 

a common upper cover have also a common lower cover. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) Whether to return 

a certificate if the lattice is not lower semimodular. 

 

OUTPUT: 

 

- If ``certificate=False`` return ``True`` or ``False``. 

If ``certificate=True`` return either ``(True, None)`` or 

``(False, (a, b))``, where `a` and `b` are covered by their 

join but do no cover their meet. 

 

See :wikipedia:`Semimodular_lattice` 

 

EXAMPLES:: 

 

sage: L = posets.DiamondPoset(5) 

sage: L.is_lower_semimodular() 

True 

 

sage: L = posets.PentagonPoset() 

sage: L.is_lower_semimodular() 

False 

 

sage: L = posets.ChainPoset(6) 

sage: L.is_lower_semimodular() 

True 

 

sage: L = LatticePoset(DiGraph('IS?`?AAOE_@?C?_@??')) 

sage: L.is_lower_semimodular(certificate=True) 

(False, (4, 2)) 

 

.. SEEALSO:: 

 

- Dual property: :meth:`is_upper_semimodular` 

- Weaker properties: :meth:`~sage.combinat.posets.posets.FinitePoset.is_graded` 

- Stronger properties: :meth:`is_modular`, 

:meth:`is_meet_distributive` 

""" 

nonmodular = self._hasse_diagram.find_nonsemimodular_pair(upper=False) 

if nonmodular is None: 

return (True, None) if certificate else True 

if certificate: 

return (False, (self._vertex_to_element(nonmodular[0]), 

self._vertex_to_element(nonmodular[1]))) 

return False 

 

def is_supersolvable(self, certificate=False): 

""" 

Return ``True`` if the lattice is supersolvable, and 

``False`` otherwise. 

 

A lattice `L` is *supersolvable* if there exists a maximal chain `C` 

such that every `x \in C` is a modular element in `L`. Equivalent 

definition is that the sublattice generated by `C` and any other chain 

is distributive. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(False, None)`` or 

``(True, C)``, where ``C`` is a maximal chain of modular elements. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = posets.DiamondPoset(5) 

sage: L.is_supersolvable() 

True 

 

sage: L = posets.PentagonPoset() 

sage: L.is_supersolvable() 

False 

 

sage: L = LatticePoset({1:[2,3],2:[4,5],3:[5,6],4:[7],5:[7],6:[7]}) 

sage: L.is_supersolvable() 

True 

sage: L.is_supersolvable(certificate=True) 

(True, [1, 2, 5, 7]) 

sage: L.is_modular() 

False 

 

sage: L = LatticePoset({0: [1, 2, 3, 4], 1: [5, 6, 7], 

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

....: 5: [11], 6: [11], 7: [11], 8: [11], 

....: 9: [11], 10: [11]}) 

sage: L.is_supersolvable() 

False 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`~sage.combinat.posets.posets.FinitePoset.is_graded` 

- Stronger properties: :meth:`is_modular` 

 

TESTS:: 

 

sage: LatticePoset().is_supersolvable() 

True 

""" 

from sage.misc.cachefunc import cached_function 

 

if not self.is_ranked(): 

if certificate: 

return (False, None) 

return False 

 

if self.cardinality() == 0: 

if certificate: 

return (True, []) 

return True 

 

H = self._hasse_diagram 

height = self.height() 

n = H.order() 

cur = H.maximal_elements()[0] 

cert = [cur] 

next_ = [H.neighbor_in_iterator(cur)] 

 

@cached_function 

def is_modular_elt(a): 

return all(H._rank[a] + H._rank[b] == 

H._rank[H._meet[a, b]] + H._rank[H._join[a, b]] 

for b in range(n)) 

 

if not is_modular_elt(cur): 

return False 

while len(next_) < height: 

try: 

cur = next(next_[-1]) 

except StopIteration: 

next_.pop() 

cert.pop() 

if not next_: 

return False 

continue 

if is_modular_elt(cur): 

next_.append(H.neighbor_in_iterator(cur)) 

cert.append(cur) 

if certificate: 

return (True, [self._vertex_to_element(e) for e in reversed(cert)]) 

return True 

 

def vertical_composition(self, other, labels='pairs'): 

r""" 

Return the vertical composition of the lattice with ``other``. 

 

Let `L` and `K` be lattices and `b_K` the bottom element 

of `K`. The vertical composition of `L` and `K` is the ordinal 

sum of `L` and `K \setminus \{b_K\}`. Informally said this is 

lattices "glued" together with a common element. 

 

Mathematically, it is only defined when `L` and `K` have no 

common element; here we force that by giving them different 

names in the resulting poset. 

 

INPUT: 

 

- ``other`` -- a lattice 

 

- ``labels`` -- a string (default ``'pairs'``); can be one of 

the following: 

 

* ``'pairs'`` - each element ``v`` in this poset will be 

named ``(0, v)`` and each element ``u`` in ``other`` will 

be named ``(1, u)`` in the result 

* ``'integers'`` - the elements of the result will be 

relabeled with consecutive integers 

 

EXAMPLES:: 

 

sage: L = LatticePoset({'a': ['b', 'c'], 'b': ['d'], 'c': ['d']}) 

sage: K = LatticePoset({'e': ['f', 'g'], 'f': ['h'], 'g': ['h']}) 

sage: M = L.vertical_composition(K) 

sage: M.list() 

[(0, 'a'), (0, 'b'), (0, 'c'), (0, 'd'), (1, 'f'), (1, 'g'), (1, 'h')] 

sage: M.upper_covers((0, 'd')) 

[(1, 'f'), (1, 'g')] 

 

sage: C2 = posets.ChainPoset(2) 

sage: M3 = posets.DiamondPoset(5) 

sage: L = C2.vertical_composition(M3, labels='integers') 

sage: L.cover_relations() 

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

 

.. SEEALSO:: 

 

:meth:`vertical_decomposition`, 

:meth:`sage.combinat.posets.posets.FinitePoset.ordinal_sum` 

 

TESTS:: 

 

sage: C0 = LatticePoset() 

sage: C1 = LatticePoset({'a': []}) 

sage: C2 = LatticePoset({'b': ['c']}) 

sage: C2.vertical_composition(C2) 

Finite lattice containing 3 elements 

sage: C0.vertical_composition(C0) 

Finite lattice containing 0 elements 

sage: C0.vertical_composition(C1).list() 

[(1, 'a')] 

sage: C1.vertical_composition(C0).list() 

[(0, 'a')] 

sage: C1.vertical_composition(C1).list() 

[(0, 'a')] 

sage: C1.vertical_composition(C2).list() 

[(0, 'a'), (1, 'c')] 

sage: C2.vertical_composition(C1).list() 

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

""" 

from copy import copy 

 

# Todo: This and ordinal_sum() of posets could keep 

# distinguished linear extension, if it is defined 

# for both posets/lattices. That can be done after 

# trac ticket #21607. 

 

if labels not in ['integers', 'pairs']: 

raise ValueError("labels must be either 'pairs' or 'integers'") 

if not isinstance(self, FiniteLatticePoset): 

raise ValueError("the input is not a finite lattice") 

if self._is_facade != other._is_facade: 

raise ValueError("mixing facade and non-facade lattices is not defined") 

 

if labels == 'integers': 

g_self = copy(self._hasse_diagram) 

g_other = other._hasse_diagram.copy(immutable=False) 

n = max(g_self.order(), 1) # max() takes care of empty 'self'. 

g_other.relabel(lambda v: v + n - 1) 

g_result = g_self.union(g_other) 

return FiniteLatticePoset(g_result, elements=range(g_result.order()), 

facade=self._is_facade, category=FiniteLatticePosets()) 

 

if self.cardinality() == 0: 

return other.relabel(lambda e: (1, e)) 

S = other.subposet([e for e in other if e != other.bottom()]) 

return LatticePoset(self.ordinal_sum(S), facade=self._is_facade) 

 

def vertical_decomposition(self, elements_only=False): 

r""" 

Return sublattices from the vertical decomposition of the lattice. 

 

Let `d_1, \ldots, d_n` be elements (excluding the top and bottom 

elements) comparable to every element of the lattice. Let `b` 

be the bottom element and `t` be the top element. This function 

returns either a list `d_1, \ldots, d_n`, or the list of 

intervals `[b, d_1], [d_1, d_2], \ldots, [d_{n-1}, d_n], [d_n, 

t]` as lattices. 

 

Informally said, this returns the lattice split into parts at 

every single-element "cutting point". 

 

INPUT: 

 

- ``elements_only`` - if ``True``, return the list of decomposing 

elements as defined above; if ``False`` (the default), 

return the list of sublattices so that the lattice is a 

vertical composition of them. 

 

EXAMPLES: 

 

Number 6 is divided by 1, 2, and 3, and it divides 12, 18 and 36:: 

 

sage: L = LatticePoset( ([1, 2, 3, 6, 12, 18, 36], 

....: attrcall("divides")) ) 

sage: parts = L.vertical_decomposition() 

sage: [lat.list() for lat in parts] 

[[1, 2, 3, 6], [6, 12, 18, 36]] 

sage: L.vertical_decomposition(elements_only=True) 

[6] 

 

.. SEEALSO:: 

 

:meth:`vertical_composition`, 

:meth:`is_vertically_decomposable` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).vertical_decomposition(elements_only=True) 

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

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

""" 

if self.cardinality() <= 2: 

if not elements_only: 

return [self] 

else: 

return [] 

if elements_only: 

return [self[e] for e in 

self._hasse_diagram.vertical_decomposition(return_list=True)] 

elms = ( [0] + 

self._hasse_diagram.vertical_decomposition(return_list=True) + 

[self.cardinality() - 1] ) 

n = len(elms) 

result = [] 

for i in range(n - 1): 

result.append(LatticePoset( 

self.subposet([self[e] for e in range(elms[i], elms[i + 1] + 1)]))) 

return result 

 

def is_vertically_decomposable(self, certificate=False): 

r""" 

Return ``True`` if the lattice is vertically decomposable, and 

``False`` otherwise. 

 

A lattice is vertically decomposable if it has an element that 

is comparable to all elements and is neither the bottom nor 

the top element. 

 

Informally said, a lattice is vertically decomposable if it 

can be seen as two lattices "glued" by unifying the top 

element of first lattice to the bottom element of second one. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(False, None)`` or 

``(True, e)``, where `e` is an element that is comparable to all 

other elements and is neither the bottom nor the top element. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: posets.TamariLattice(4).is_vertically_decomposable() 

False 

sage: L = LatticePoset( ([1, 2, 3, 6, 12, 18, 36], 

....: attrcall("divides")) ) 

sage: L.is_vertically_decomposable() 

True 

sage: L.is_vertically_decomposable(certificate=True) 

(True, 6) 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_subdirectly_reducible` 

- Mutually exclusive properties: :meth:`is_atomic`, :meth:`is_coatomic` 

- Other: :meth:`vertical_decomposition` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_vertically_decomposable() for i in 

....: range(5)] 

[False, False, False, True, True] 

""" 

e = self._hasse_diagram.vertical_decomposition() 

if e is None: 

if certificate: 

return (False, None) 

return False 

if certificate: 

return (True, self._vertex_to_element(e)) 

return True 

 

def sublattice(self, elms): 

r""" 

Return the smallest sublattice containing elements on the given list. 

 

INPUT: 

 

- ``elms`` -- a list of elements of the lattice. 

 

EXAMPLES:: 

 

sage: L=LatticePoset(( [], [[1,2],[1,17],[1,8],[2,3],[2,22],[2,5],[2,7],[17,22],[17,13],[8,7],[8,13],[3,16],[3,9],[22,16],[22,18],[22,10],[5,18],[5,14],[7,9],[7,14],[7,10],[13,10],[16,6],[16,19],[9,19],[18,6],[18,33],[14,33],[10,19],[10,33],[6,4],[19,4],[33,4]] )) 

sage: L.sublattice([14, 13, 22]).list() 

[1, 2, 8, 7, 14, 17, 13, 22, 10, 33] 

 

sage: L = posets.BooleanLattice(3) 

sage: L.sublattice([3,5,6,7]) 

Finite lattice containing 8 elements 

""" 

gens_remaining = set(elms) 

current_set = set() 

 

# We add elements one by one in 'current_set'. 

# 

# When adding a point g to 'current_set', we add to 'gens_remaning' all 

# meet/join obtained from g and another point of 'current_set' 

while gens_remaining: 

g = gens_remaining.pop() 

if g in current_set: 

continue 

for x in current_set: 

gens_remaining.add(self.join(x, g)) 

gens_remaining.add(self.meet(x, g)) 

current_set.add(g) 

 

return LatticePoset(self.subposet(current_set)) 

 

def is_sublattice(self, other): 

""" 

Return ``True`` if the lattice is a sublattice of ``other``, 

and ``False`` otherwise. 

 

Lattice `K` is a sublattice of `L` if `K` is an (induced) subposet 

of `L` and closed under meet and join of `L`. 

 

.. NOTE:: 

 

This method does not check whether the lattice is a 

*isomorphic* (i.e., up to relabeling) sublattice of ``other``, 

but only if ``other`` directly contains the lattice as an 

sublattice. 

 

EXAMPLES: 

 

A pentagon sublattice in a non-modular lattice:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [5, 6], 4: [7], 5: [7], 6: [7]}) 

sage: N5 = LatticePoset({1: [2, 6], 2: [4], 4: [7], 6: [7]}) 

sage: N5.is_sublattice(L) 

True 

 

This pentagon is a subposet but not closed under join, hence not a sublattice:: 

 

sage: N5_ = LatticePoset({1: [2, 3], 2: [4], 3: [7], 4: [7]}) 

sage: N5_.is_induced_subposet(L) 

True 

sage: N5_.is_sublattice(L) 

False 

 

.. SEEALSO:: 

 

:meth:`isomorphic_sublattices_iterator` 

 

TESTS:: 

 

sage: E = LatticePoset({}) 

sage: P = posets.PentagonPoset() 

sage: E.is_sublattice(P) 

True 

 

sage: P1 = LatticePoset({'a':['b']}) 

sage: P2 = P1.dual() 

sage: P1.is_sublattice(P2) 

False 

 

sage: P = MeetSemilattice({0: [1]}) 

sage: E.is_sublattice(P) 

Traceback (most recent call last): 

... 

TypeError: other is not a lattice 

sage: P = JoinSemilattice({0: [1]}) 

sage: E.is_sublattice(P) 

Traceback (most recent call last): 

... 

TypeError: other is not a lattice 

""" 

try: 

_ = other.meet 

_ = other.join 

except (AttributeError): 

raise TypeError('other is not a lattice') 

if not self.is_induced_subposet(other): 

return False 

 

n = self.cardinality() 

for i in range(n): 

for j in range(i): 

if (other.meet(self[i], self[j]) not in self or 

other.join(self[i], self[j]) not in self): 

return False 

return True 

 

def sublattices(self): 

""" 

Return all sublattices of the lattice. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2:[5], 3:[5, 6], 4:[6], 

....: 5:[7], 6:[7]}) 

sage: sublats = L.sublattices(); len(sublats) 

54 

sage: sublats[3] 

Finite lattice containing 4 elements 

sage: sublats[3].list() 

[1, 2, 3, 5] 

 

TESTS: 

 

A subposet that is a lattice but not a sublattice:: 

 

sage: L = LatticePoset({1: [2, 3], 2:[4], 3:[4], 4:[5]}) 

sage: sl = L.sublattices() 

sage: LatticePoset({1: [2, 3], 2:[5], 3:[5]}) in sl 

False 

 

`n`-element chain has `2^n` sublattices (also tests empty lattice):: 

 

sage: [len(posets.ChainPoset(n).sublattices()) for n in range(4)] 

[1, 2, 4, 8] 

""" 

return [LatticePoset(self.subposet(map(self._vertex_to_element, elms))) 

for elms in self._hasse_diagram.sublattices_iterator(set(), 0)] 

 

@rename_keyword(deprecation=22225, element_constructor='labels') 

def sublattices_lattice(self, labels='lattice'): 

""" 

Return the lattice of sublattices. 

 

Every element of the returned lattice is a sublattice and 

they are ordered by containment; that is, atoms are one-element 

lattices, coatoms are maximal sublattices of the original 

lattice and so on. 

 

INPUT: 

 

- ``labels`` -- string; can be one of the following: 

 

* ``'lattice'`` (default) elements of the lattice will be 

lattices that correspond to sublattices of the original lattice 

 

* ``'tuple'`` - elements are tuples of elements of the sublattices 

of the original lattice 

 

* ``'integer'`` - elements are plain integers 

 

EXAMPLES:: 

 

sage: D4 = posets.DiamondPoset(4) 

sage: sll = D4.sublattices_lattice(labels='tuple') 

sage: sll.coatoms() # = maximal sublattices of the original lattice 

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

 

sage: L = posets.DivisorLattice(12) 

sage: sll = L.sublattices_lattice() 

sage: L.is_dismantlable() == (len(sll.atoms()) == sll.rank()) 

True 

 

TESTS:: 

 

sage: E = posets.ChainPoset(0) 

sage: E.sublattices_lattice() 

Finite lattice containing 1 elements 

 

sage: C3 = posets.ChainPoset(3) 

sage: sll = C3.sublattices_lattice(labels='integer') 

sage: sll.is_isomorphic(posets.BooleanLattice(3)) 

True 

""" 

if labels not in ['lattice', 'tuple', 'integer']: 

raise ValueError("labels must be one of 'lattice', 'tuple' or 'integer'") 

sublats = [frozenset(x) for x in self._hasse_diagram.sublattices_iterator(set(), 0)] 

L = LatticePoset([sublats, lambda a, b: a != b and a.issubset(b)]) 

if labels == 'integer': 

return L.canonical_label() 

L = L.relabel(lambda x: tuple(self._vertex_to_element(y) for y in x)) 

if labels == 'lattice': 

return L.relabel(lambda x: self.sublattice(x)) 

return L 

 

def isomorphic_sublattices_iterator(self, other): 

""" 

Return an iterator over the sublattices of the lattice isomorphic to ``other``. 

 

INPUT: 

 

- other -- a finite lattice 

 

EXAMPLES: 

 

A non-modular lattice contains a pentagon sublattice:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [5, 6], 4: [7], 5: [7], 6: [7]}) 

sage: L.is_modular() 

False 

sage: N5 = posets.PentagonPoset() 

sage: N5_in_L = next(L.isomorphic_sublattices_iterator(N5)); N5_in_L 

Finite lattice containing 5 elements 

sage: N5_in_L.list() 

[1, 3, 6, 4, 7] 

 

A divisor lattice is modular, hence does not contain the 

pentagon as sublattice, even if it has the pentagon 

subposet:: 

 

sage: D12 = posets.DivisorLattice(12) 

sage: D12.has_isomorphic_subposet(N5) 

True 

sage: list(D12.isomorphic_sublattices_iterator(N5)) 

[] 

 

.. SEEALSO:: 

 

:meth:`sage.combinat.posets.posets.FinitePoset.isomorphic_subposets_iterator` 

 

.. WARNING:: 

 

This function will return same sublattice as many times as 

there are automorphism on it. This is due to 

:meth:`~sage.graphs.generic_graph.GenericGraph.subgraph_search_iterator` 

returning labelled subgraphs. 

 

TESTS:: 

 

sage: E = LatticePoset() 

sage: P = LatticePoset({1: []}) 

sage: list(N5.isomorphic_sublattices_iterator(E)) 

[Finite lattice containing 0 elements] 

sage: len(list(N5.isomorphic_sublattices_iterator(P))) 

5 

""" 

from itertools import combinations 

if not isinstance(other, FiniteLatticePoset): 

raise TypeError('the input is not a finite lattice') 

H = self._hasse_diagram 

self_closure = H.transitive_closure() 

other_closure = other._hasse_diagram.transitive_closure() 

for g in self_closure.subgraph_search_iterator(other_closure, induced=True): 

if all(H._meet[a, b] in g and H._join[a, b] in g for a, b in combinations(g, 2)): 

yield self.sublattice([self._vertex_to_element(v) for v in g]) 

 

def maximal_sublattices(self): 

r""" 

Return maximal (proper) sublattices of the lattice. 

 

EXAMPLES:: 

 

sage: L = LatticePoset(( [], [[1,2],[1,17],[1,8],[2,3],[2,22], 

....: [2,5],[2,7],[17,22],[17,13],[8,7], 

....: [8,13],[3,16],[3,9],[22,16],[22,18], 

....: [22,10],[5,18],[5,14],[7,9],[7,14], 

....: [7,10],[13,10],[16,6],[16,19],[9,19], 

....: [18,6],[18,33],[14,33],[10,19], 

....: [10,33],[6,4],[19,4],[33,4]] )) 

sage: maxs = L.maximal_sublattices() 

sage: len(maxs) 

7 

sage: sorted(maxs[0].list()) 

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 16, 18, 19, 22, 33] 

""" 

n = self.cardinality() 

if n < 2: 

return [] 

if n == 2: 

return [self.sublattice([self.bottom()]), self.sublattice([self.top()])] 

return [self.sublattice([self[x] for x in d]) for d in self._hasse_diagram.maximal_sublattices()] 

 

def frattini_sublattice(self): 

r""" 

Return the Frattini sublattice of the lattice. 

 

The Frattini sublattice `\Phi(L)` is the intersection of all 

proper maximal sublattices of `L`. It is also the set of 

"non-generators" - if the sublattice generated by set `S` of 

elements is whole lattice, then also `S \setminus \Phi(L)` 

generates whole lattice. 

 

EXAMPLES:: 

 

sage: L = LatticePoset(( [], [[1,2],[1,17],[1,8],[2,3],[2,22], 

....: [2,5],[2,7],[17,22],[17,13],[8,7], 

....: [8,13],[3,16],[3,9],[22,16],[22,18], 

....: [22,10],[5,18],[5,14],[7,9],[7,14], 

....: [7,10],[13,10],[16,6],[16,19],[9,19], 

....: [18,6],[18,33],[14,33],[10,19], 

....: [10,33],[6,4],[19,4],[33,4]] )) 

sage: sorted(L.frattini_sublattice().list()) 

[1, 2, 4, 10, 19, 22, 33] 

""" 

return LatticePoset(self.subposet([self[x] for x in 

self._hasse_diagram.frattini_sublattice()])) 

 

def moebius_algebra(self, R): 

""" 

Return the Möbius algebra of ``self`` over ``R``. 

 

OUTPUT: 

 

An instance of :class:`sage.combinat.posets.moebius_algebra.MoebiusAlgebra`. 

 

EXAMPLES:: 

 

sage: L = posets.BooleanLattice(4) 

sage: L.moebius_algebra(QQ) 

Moebius algebra of Finite lattice containing 16 elements over Rational Field 

""" 

from sage.combinat.posets.moebius_algebra import MoebiusAlgebra 

return MoebiusAlgebra(R, self) 

 

def quantum_moebius_algebra(self, q=None): 

""" 

Return the quantum Möbius algebra of ``self`` with parameter ``q``. 

 

INPUT: 

 

- ``q`` -- (optional) the deformation parameter `q` 

 

OUTPUT: 

 

An instance of :class:`sage.combinat.posets.moebius_algebra.QuantumMoebiusAlgebra`. 

 

EXAMPLES:: 

 

sage: L = posets.BooleanLattice(4) 

sage: L.quantum_moebius_algebra() 

Quantum Moebius algebra of Finite lattice containing 16 elements 

with q=q over Univariate Laurent Polynomial Ring in q over Integer Ring 

""" 

from sage.combinat.posets.moebius_algebra import QuantumMoebiusAlgebra 

return QuantumMoebiusAlgebra(self, q) 

 

def day_doubling(self, S): 

r""" 

Return the lattice with Alan Day's doubling construction of subset `S`. 

 

The subset `S` is assumed to be convex (i.e. if 

`a, c \in S` and `a < b < c` in the lattice, then `b \in S`) 

and connected (i.e. if `a, b \in S` then there is a chain 

`a=e_1, e_2, \ldots, e_n=b` such that `e_i` either covers or 

is covered by `e_{i+1}`). 

 

.. image:: ../../../media/day-doubling.png 

 

Alan Day's doubling construction is a specific extension of 

the lattice. Here we formulate it in a format more suitable 

for computation. 

 

Let `L` be a lattice and `S` a convex subset of it. The resulting 

lattice `L[S]` has elements `(e, 0)` for each `e \in L` and 

`(e, 1)` for each `e \in S`. If `x \le y` in `L`, then in the 

new lattice we have 

 

* `(x, 0), (x, 1) \le (y, 0), (y, 1)` 

* `(x, 0) \le (x, 1)` 

 

INPUT: 

 

- ``S`` -- a subset of the lattice 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: ['a', 'b', 2], 'a': ['c'], 'b': ['c', 'd'], 

....: 2: [3], 'c': [4], 'd': [4], 3: [4]}) 

sage: L2 = L.day_doubling(['a', 'b', 'c', 'd']); L2 

Finite lattice containing 12 elements 

sage: set(L2.upper_covers((1, 0))) == set([(2, 0), ('a', 0), ('b', 0)]) 

True 

sage: set(L2.upper_covers(('b', 0))) == set([('d', 0), ('b', 1), ('c', 0)]) 

True 

 

.. SEEALSO:: 

 

:meth:`is_constructible_by_doublings` 

 

TESTS:: 

 

sage: L2._hasse_diagram.is_isomorphic(DiGraph('KSCH??_BO?g?_?@?G?@?A?@??')) 

True 

 

sage: L = LatticePoset({'a': ['b']}) 

sage: set(L.day_doubling([]).list()) == set([('a', 0), ('b', 0)]) 

True 

sage: set(L.day_doubling(['a', 'b']).list()) == set([('a', 0), ('a', 1), ('b', 0), ('b', 1)]) 

True 

""" 

# Rationale for naming of elements: a lattice can have 

# elements 1, (1, 1), (1, (1, 1)) and so on. We can't just 

# make a copy of S with elements (s, 1). 

 

# The construction could be defined for any convex 

# subset S, but we assume that the user made an error 

# if S is not also connected. 

 

from sage.misc.misc import uniq 

S = uniq(S) 

S_ = [self._element_to_vertex(e) for e in S] 

if not self._hasse_diagram.is_convex_subset(S_): 

raise ValueError("subset S is not convex") 

if not self._hasse_diagram.subgraph(S_).is_connected(): 

raise ValueError("subset S is not connected") 

 

g = self.hasse_diagram() 

g.relabel(lambda e: (e, 0)) 

 

for e in S: 

g.add_edge((e, 0), (e, 1)) 

for e_up in self.upper_covers(e): 

if e_up in S: 

g.add_edge((e, 1), (e_up, 1)) 

else: 

g.delete_edge((e, 0), (e_up, 0)) 

g.add_edge((e, 1), (e_up, 0)) 

 

return LatticePoset(g) 

 

def adjunct(self, other, a, b): 

r""" 

Return the adjunct of the lattice by ``other`` on the pair `(a, b)`. 

 

It is assumed that `a < b` but `b` does not cover `a`. 

 

The adjunct of a lattice `K` to `L` with respect to pair 

`(a, b)` of `L` is defined such that `x < y` if 

 

- `x, y \in K` and `x < y` in `K`, 

- `x, y \in L` and `x < y` in `L`, 

- `x \in L`, `y \in K` and `x \le a` in `L`, or 

- `x \in K`, `y \in L` and `b \le y` in `L`. 

 

Informally this can be seen as attaching the lattice `K` to `L` 

as a new block between `a` and `b`. Dismantlable lattices are exactly 

those that can be created from chains with this function. 

 

Mathematically, it is only defined when `L` and `K` have no 

common element; here we force that by giving them different 

names in the resulting lattice. 

 

EXAMPLES:: 

 

sage: Pnum = posets.PentagonPoset() 

sage: Palp = Pnum.relabel(lambda x: chr(ord('a')+x)) 

sage: PP = Pnum.adjunct(Palp, 0, 3) 

sage: PP.atoms() 

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

sage: PP.coatoms() 

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

 

TESTS:: 

 

sage: P = posets.PentagonPoset() 

sage: E = LatticePoset() 

sage: PE = P.adjunct(E, 0, 3); PE.is_isomorphic(P) 

True 

sage: PE.bottom() 

(0, 0) 

sage: C4 = posets.ChainPoset(4) 

sage: C1 = posets.ChainPoset(1) 

sage: C4.adjunct(C1, 0, 3).is_isomorphic(P) 

True 

""" 

if not isinstance(other, FiniteLatticePoset): 

raise ValueError("other is not a finite lattice") 

if not self.is_greater_than(b, a): 

raise ValueError("element %s is not greater than %s in the lattice" % (b, a)) 

if self.covers(a, b): 

raise ValueError("element %s covers element %s in the lattice" % (b, a)) 

 

if other.cardinality() == 0: 

return self.relabel(lambda e: (0, e)) 

 

g_self = self.hasse_diagram() 

g_other = other.hasse_diagram() 

g = g_self.disjoint_union(g_other, labels='pairs') 

g.add_edge((0, a), (1, other.bottom())) 

g.add_edge((1, other.top()), (0, b)) 

return LatticePoset(g) 

 

def center(self): 

""" 

Return the center of the lattice. 

 

An element of a lattice is *central* if it is neutral and has a 

complement. The subposet induced by central elements is a *center* of 

the lattice. Actually it is a Boolean lattice. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [6, 7], 3: [8, 9, 7], 

....: 4: [5, 6], 5: [8, 10], 6: [10], 7: [13, 11], 

....: 8: [13, 12], 9: [11, 12], 10: [13], 

....: 11: [14], 12: [14], 13: [14]}) 

sage: C = L.center(); C 

Finite lattice containing 4 elements 

sage: C.cover_relations() 

[[1, 2], [1, 12], [2, 14], [12, 14]] 

 

sage: L = posets.DivisorLattice(60) 

sage: sorted(L.center().list()) 

[1, 3, 4, 5, 12, 15, 20, 60] 

 

.. SEEALSO:: 

 

:meth:`neutral_elements`, :meth:`complements` 

 

TESTS:: 

 

sage: LatticePoset().center() 

Finite lattice containing 0 elements 

 

sage: posets.ChainPoset(1).center() 

Finite lattice containing 1 elements 

 

sage: L = posets.BooleanLattice(3) 

sage: L.center() == L 

True 

""" 

neutrals = self.neutral_elements() 

comps = self.complements() 

return self.sublattice([e for e in neutrals if e in comps]) 

 

def is_dismantlable(self, certificate=False): 

r""" 

Return ``True`` if the lattice is dismantlable, and ``False`` 

otherwise. 

 

An `n`-element lattice `L_n` is dismantlable if there is a sublattice 

chain `L_{n-1} \supset L_{n-2}, \supset \cdots, \supset L_0` so that 

every `L_i` is a sublattice of `L_{i+1}` with one element less, and 

`L_0` is the empty lattice. In other words, a dismantlable lattice 

can be reduced to empty lattice removing doubly irreducible 

element one by one. 

 

INPUT: 

 

- ``certificate`` (boolean) -- Whether to return a certificate. 

 

* If ``certificate = False`` (default), returns ``True`` or 

``False`` accordingly. 

 

* If ``certificate = True``, returns: 

 

* ``(True, elms)`` when the lattice is dismantlable, where 

``elms`` is elements listed in a possible removing order. 

 

* ``(False, crown)`` when the lattice is not dismantlable, 

where ``crown`` is a subposet of `2k` elements 

`a_1, \ldots, a_k, b_1, \ldots, b_k` with covering 

relations `a_i \lessdot b_i` and `a_i \lessdot b_{i+1}` 

for `i \in [1, \ldots, k-1]`, and `a_k \lessdot b_1`. 

 

EXAMPLES:: 

 

sage: DL12 = LatticePoset((divisors(12), attrcall("divides"))) 

sage: DL12.is_dismantlable() 

True 

sage: DL12.is_dismantlable(certificate=True) 

(True, [4, 2, 1, 3, 6, 12]) 

 

sage: B3 = posets.BooleanLattice(3) 

sage: B3.is_dismantlable() 

False 

sage: B3.is_dismantlable(certificate=True) 

(False, Finite poset containing 6 elements) 

 

Every planar lattice is dismantlable. Converse is not true:: 

 

sage: L = LatticePoset( ([], [[0, 1], [0, 2], [0, 3], [0, 4], 

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

....: [4, 6], [4, 7], [5, 8], [6, 8], 

....: [7, 8]]) ) 

sage: L.is_dismantlable() 

True 

sage: L.is_planar() 

False 

 

.. SEEALSO:: 

 

- Stronger properties: :meth:`is_planar` 

 

TESTS:: 

 

sage: posets.ChainPoset(0).is_dismantlable() 

True 

sage: posets.ChainPoset(1).is_dismantlable() 

True 

 

sage: L = LatticePoset(DiGraph('L@_?W?E?@CCO?A?@??_?O?Jw????C?')) 

sage: L.is_dismantlable() 

False 

sage: c = L.is_dismantlable(certificate=True)[1] 

sage: (3 in c, 12 in c, 9 in c) 

(True, False, True) 

""" 

from sage.graphs.digraph import DiGraph 

from copy import copy 

 

H = copy(self._hasse_diagram) 

cert = [] 

# Smallest lattice that is not dismantlable is the 

# Boolean lattice with 2^3=8 elements. Hence the limit 7. 

limit = 0 if certificate else 7 

 

while H.order() > limit: 

for e in H: 

i = H.in_degree(e) 

o = H.out_degree(e) 

if i < 2 and o < 2: 

if certificate: 

cert.append(e) 

if i == 1 and o == 1: # Remove inside the lattice 

lower = H.neighbors_in(e)[0] 

upper = H.neighbors_out(e)[0] 

H.delete_vertex(e) 

if upper not in H.depth_first_search(lower): 

H.add_edge(lower, upper) 

else: # Remove the top or bottom element 

H.delete_vertex(e) 

break 

else: 

if not certificate: 

return False 

k = 3 

while True: 

crown = DiGraph({i: [k + i, k + (i + 1) % k] 

for i in range(k)}) 

sg = H.transitive_closure().subgraph_search(crown, True) 

if sg: 

elms = [self[e] for e in sg] 

return (False, self.subposet(elms)) 

k += 1 

if not certificate: 

return True 

return (True, [self[e] for e in cert]) 

 

def is_subdirectly_reducible(self, certificate=False): 

r""" 

Return ``True`` if the lattice is subdirectly reducible. 

 

A lattice `M` is a *subdirect product* of `K` and `L` if it 

is a sublattice of `K \times L`. Lattice `M` is *subdirectly 

reducible* if there exists such lattices `K` and `L` so that 

`M` is not a sublattice of either. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate 

 

OUTPUT: 

 

- if ``certificate=False``, return only ``True`` or ``False`` 

- if ``certificate=True``, return either 

 

* ``(True, (K, L))`` such that the lattice is isomorphic to 

a sublattice of `K \times L`. 

* ``(False, (a, b))``, where `a` and `b` are elements that are 

in the same congruence class for every nontrivial congruence 

of the lattice. Special case: If the lattice has zero or one element, 

return ``(False, None)``. 

 

EXAMPLES:: 

 

sage: N5 = posets.PentagonPoset() 

sage: N5.is_subdirectly_reducible() 

False 

 

sage: hex = LatticePoset({1: [2, 3], 2: [4], 3: [5], 4: [6], 5: [6]}) 

sage: hex.is_subdirectly_reducible() 

True 

 

sage: N5.is_subdirectly_reducible(certificate=True) 

(False, (2, 3)) 

sage: res, cert = hex.is_subdirectly_reducible(certificate=True) 

sage: cert[0].is_isomorphic(N5) 

True 

 

.. SEEALSO:: 

 

- Stronger properties: :meth:`is_distributive`, 

:meth:`is_vertically_decomposable` 

- Other: :meth:`subdirect_decomposition` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_subdirectly_reducible() for i in range(5)] 

[False, False, False, True, True] 

""" 

H = self._hasse_diagram 

A = H.atoms_of_congruence_lattice() 

 

if not certificate: 

return len(A) > 1 

 

# Kind of special cases. How should we define this for empty, 

# one-element and two-element lattices? 

if self.cardinality() < 2: 

return (False, None) 

 

if len(A) == 1: 

for a in A[0]: 

if len(a) > 1: 

return (False, (self._vertex_to_element(a[0]), 

self._vertex_to_element(a[1]))) 

 

H_closure = H.transitive_closure() 

a0 = [min(v) for v in A[0]] 

a1 = [min(v) for v in A[1]] 

K0 = LatticePoset(H_closure.subgraph(a0).transitive_reduction()) 

K1 = LatticePoset(H_closure.subgraph(a1).transitive_reduction()) 

return (False, (K0, K1)) 

 

def canonical_meetands(self, e): 

r""" 

Return the canonical meetands of `e`. 

 

The canonical meetands of an element `e` in the lattice `L` is the 

subset `S \subseteq L` such that 1) the meet of `S` is `e`, and 

2) if the meet of some other subset `S'` of is also `e`, then for 

every element `s \in S` there is an element `s' \in S'` such that 

`s \ge s'`. 

 

Informally said this is the set of greatest possible elements 

with given meet. It exists for every element if and only if 

the lattice is meet-semidistributive. Canonical meetands are 

always meet-irreducibles. 

 

INPUT: 

 

- ``e`` -- an element of the lattice 

 

OUTPUT: 

 

- canonical meetands as a list, if it exists; if not, ``None`` 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [5, 6], 4: [6], 

....: 5: [7], 6: [7]}) 

sage: L.canonical_meetands(1) 

[5, 4] 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [6], 4: [6], 

....: 5: [6]}) 

sage: L.canonical_meetands(1) is None 

True 

 

.. SEEALSO:: 

 

:meth:`canonical_joinands` 

 

TESTS:: 

 

LatticePoset({1: []}).canonical_meetands(1) 

[1] 

""" 

# Algorithm: Make interval from e to the top element. 

# Now compute kappa function for every atom of that lattice, i.e. 

# kind of "restricted" kappa for elements covering e. 

# This is done implicitly here. 

H = self._hasse_diagram 

e = self._element_to_vertex(e) 

meetands = [] 

for a in H.neighbors_out(e): 

above_a = list(H.depth_first_search(a)) 

go_up = lambda v: [v_ for v_ in H.neighbors_out(v) if v_ not in above_a] 

result = None 

for v in H.depth_first_search(e, neighbors=go_up): 

if H.out_degree(v) == 1 and next(H.neighbor_out_iterator(v)) in above_a: 

if result is not None: 

return None 

result = v 

meetands.append(result) 

return [self._vertex_to_element(v) for v in meetands] 

 

def canonical_joinands(self, e): 

r""" 

Return the canonical joinands of `e`. 

 

The canonical joinands of an element `e` in the lattice `L` is the 

subset `S \subseteq L` such that 1) the join of `S` is `e`, and 

2) if the join of some other subset `S'` of is also `e`, then for 

every element `s \in S` there is an element `s' \in S'` such that 

`s \le s'`. 

 

Informally said this is the set of lowest possible elements 

with given join. It exists for every element if and only if 

the lattice is join-semidistributive. Canonical joinands are 

always join-irreducibles. 

 

INPUT: 

 

- ``e`` -- an element of the lattice 

 

OUTPUT: 

 

- canonical joinands as a list, if it exists; if not, ``None`` 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [5], 4: [6], 

....: 5: [7], 6: [7]}) 

sage: L.canonical_joinands(7) 

[3, 4] 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [6], 4: [6], 

....: 5: [6]}) 

sage: L.canonical_joinands(6) is None 

True 

 

.. SEEALSO:: 

 

:meth:`canonical_meetands` 

 

TESTS:: 

 

LatticePoset({1: []}).canonical_joinands(1) 

[1] 

""" 

# Algorithm: Make dual of interval from the bottom element to e. 

# Now compute kappa function for every atom of that lattice, i.e. 

# kind of "restricted" dual kappa for elements covered by e. 

# This is done implicitly here. 

H = self._hasse_diagram 

e = self._element_to_vertex(e) 

joinands = [] 

for a in H.neighbors_in(e): 

below_a = list(H.depth_first_search(a, neighbors=H.neighbors_in)) 

go_down = lambda v: [v_ for v_ in H.neighbors_in(v) if v_ not in below_a] 

result = None 

for v in H.depth_first_search(e, neighbors=go_down): 

if H.in_degree(v) == 1 and next(H.neighbor_in_iterator(v)) in below_a: 

if result is not None: 

return None 

result = v 

joinands.append(result) 

return [self._vertex_to_element(v) for v in joinands] 

 

def is_constructible_by_doublings(self, type): 

r""" 

Return ``True`` if the lattice is constructible by doublings, and 

``False`` otherwise. 

 

We call a lattice doubling constructible if it can be constructed 

from the one element lattice by a sequence of Alan Day's doubling 

constructions. 

 

Lattices constructible by interval doubling are also called 

*bounded*. Lattices constructible by lower and upper pseudo-interval 

are called *lower bounded* and *upper bounded*. Lattices 

constructible by any convex set doubling are called *congruence 

normal*. 

 

INPUT: 

 

- ``type`` -- a string; can be one of the following: 

 

* ``'interval'`` - allow only doublings of an interval 

* ``'lower'`` - allow doublings of lower pseudo-interval; that is, a 

subset of the lattice with a unique minimal element 

* ``'upper'`` - allow doublings of upper pseudo-interval; that is, a 

subset of the lattice with a unique maximal element 

* ``'convex'`` - allow doubling of any convex set 

* ``'any'`` - allow doubling of any set 

 

EXAMPLES: 

 

The pentagon can be constructed by doubling intervals; the 5-element 

diamond can not be constructed by any doublings:: 

 

sage: posets.PentagonPoset().is_constructible_by_doublings('interval') 

True 

 

sage: posets.DiamondPoset(5).is_constructible_by_doublings('any') 

False 

 

After doubling both upper and lower pseudo-interval a lattice is 

constructible by convex subset doubling:: 

 

sage: L = posets.BooleanLattice(2) 

sage: L = L.day_doubling([0, 1, 2]) # A lower pseudo-interval 

sage: L.is_constructible_by_doublings('interval') 

False 

sage: L.is_constructible_by_doublings('lower') 

True 

sage: L = L.day_doubling([(3,0), (1,1), (2,1)]) # An upper pseudo-interval 

sage: L.is_constructible_by_doublings('upper') 

False 

sage: L.is_constructible_by_doublings('convex') 

True 

 

An example of a lattice that can be constructed by doublings 

of a non-convex subsets:: 

 

sage: L = LatticePoset(DiGraph('OQC?a?@CO?G_C@?GA?O??_??@?BO?A_?G??C??_?@???')) 

sage: L.is_constructible_by_doublings('convex') 

False 

sage: L.is_constructible_by_doublings('any') 

True 

 

.. SEEALSO:: 

 

- Stronger properties: :meth:`is_distributive` (doubling by interval), 

:meth:`is_join_semidistributive` (doubling by lower pseudo-intervals), 

:meth:`is_meet_semidistributive` (doubling by upper pseudo-intervals) 

- Mutually exclusive properties: :meth:`is_simple` (doubling by any set) 

- Other: :meth:`day_doubling` 

 

TESTS:: 

 

sage: LatticePoset().is_constructible_by_doublings('interval') 

True 

 

The congruence lattice of this lattice has maximal chains satisfying the needed 

property, but also maximal chains not satisfying that; this shows that the code 

can't be optimized to test just some maximal chain:: 

 

sage: L = LatticePoset(DiGraph('QSO?I?_?_GBG??_??a???@?K??A??B???C??s??G??I??@??A??@???')) 

sage: L.is_constructible_by_doublings('convex') 

False 

sage: L.is_constructible_by_doublings('any') 

True 

 

ALGORITHM: 

 

According to [HOLM2016]_ a lattice `L` is lower bounded if and only if 

`|\mathrm{Ji}(L)| = |\mathrm{Ji}(\mathrm{Con}\ L)|`, and so dually 

`|\mathrm{Mi}(L)| = |\mathrm{Mi}(\mathrm{Con}\ L)|` in upper bounded 

lattices. The same reference gives a test for being constructible by 

convex or by any subset. 

""" 

if type not in ['interval', 'lower', 'upper', 'convex', 'any']: 

raise ValueError("type must be one of 'interval', 'lower', 'upper', 'convex' or 'any'") 

 

if self.cardinality() < 5: 

return True 

 

if type == 'interval': 

return (len(self.join_irreducibles()) == 

len(self.meet_irreducibles()) == 

self._hasse_diagram.principal_congruences_poset()[0].cardinality()) 

if type == 'lower': 

return (len(self.join_irreducibles()) == 

self._hasse_diagram.principal_congruences_poset()[0].cardinality()) 

if type == 'upper': 

return (len(self.meet_irreducibles()) == 

self._hasse_diagram.principal_congruences_poset()[0].cardinality()) 

if type == 'convex': 

return self._hasse_diagram.is_congruence_normal() 

# type == 'any' 

 

def splitting_depth_2(a, b): 

""" 

Return ``True`` if every block of `b` is made from 

combining at most two blocks of `a`. 

""" 

return all(len([x for x in a if x.issubset(y)]) <= 2 for y in b) 

 

conL = self.congruences_lattice() 

todo = [conL[0]] 

reachable = [] 

 

while todo: 

e = todo.pop() 

for e_up in conL.upper_covers(e): 

if e_up not in reachable and splitting_depth_2(e, e_up): 

if len(e_up) == 1: # = the top of the cong. lattice 

return True 

reachable.append(e_up) 

todo.append(e_up) 

return False 

 

def is_isoform(self, certificate=False): 

""" 

Return ``True`` if the lattice is isoform and ``False`` otherwise. 

 

A congruence is *isoform* (or *isotype*) if all blocks are isomorphic 

sublattices. A lattice is isoform if it has only isoform 

congruences. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate if the lattice is not isoform 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, C)``, where `C` is a non-isoform congruence as a 

:class:`sage.combinat.set_partition.SetPartition`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1:[2, 3, 4], 2: [5, 6], 3: [6, 7], 4: [7], 5: [8], 6: [8], 7: [8]}) 

sage: L.is_isoform() 

True 

 

Every isoform lattice is (trivially) uniform, but the converse is 

not true:: 

 

sage: L = LatticePoset({1: [2, 3, 6], 2: [4, 5], 3: [5], 4: [9, 8], 5: [7, 8], 6: [9], 7: [10], 8: [10], 9: [10]}) 

sage: L.is_isoform(), L.is_uniform() 

(False, True) 

 

sage: L.is_isoform(certificate=True) 

(False, {{1, 2, 4, 6, 9}, {3, 5, 7, 8, 10}}) 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_uniform` 

- Stronger properties: :meth:`is_simple`, 

:meth:`is_relatively_complemented` 

- Other: :meth:`congruence` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_isoform() for i in range(5)] 

[True, True, True, False, False] 

 

sage: posets.DiamondPoset(5).is_isoform() # Simple, so trivially isoform 

True 

""" 

ok = (True, None) if certificate else True 

 

H = self._hasse_diagram 

if H.order() == 0: 

return ok 

for c in H.congruences_iterator(): 

cong = list(c) 

d = H.subgraph(cong[0]) 

for part in cong: 

if not H.subgraph(part).is_isomorphic(d): 

if certificate: 

from sage.combinat.set_partition import SetPartition 

return (False, 

SetPartition([[self._vertex_to_element(v) for v in p] for p in cong])) 

return False 

return ok 

 

def is_uniform(self, certificate=False): 

""" 

Return ``True`` if the lattice is uniform and ``False`` otherwise. 

 

A congruence is *uniform* if all blocks are have equal number 

of elements. A lattice is uniform if it has only uniform 

congruences. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate if the lattice is not regular 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, C)``, where `C` is a non-uniform congruence as a 

:class:`sage.combinat.set_partition.SetPartition`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [6, 7], 3: [5], 4: [5], 5: [9, 8], 6: [9], 7: [10], 8: [10], 9: [10]}) 

sage: L.is_uniform() 

True 

 

Every uniform lattice is regular, but the converse is not true:: 

 

sage: N6 = LatticePoset({1: [2, 3, 5], 2: [4], 3: [4], 5: [6], 4: [6]}) 

sage: N6.is_uniform(), N6.is_regular() 

(False, True) 

 

sage: N6.is_uniform(certificate=True) 

(False, {{1, 2, 3, 4}, {5, 6}}) 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_regular` 

- Stronger properties: :meth:`is_isoform` 

- Other: :meth:`congruence` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_uniform() for i in range(5)] 

[True, True, True, False, False] 

 

sage: posets.DiamondPoset(5).is_uniform() # Simple, so trivially uniform 

True 

""" 

ok = (True, None) if certificate else True 

 

H = self._hasse_diagram 

if H.order() == 0: 

return ok 

 

for c in H.congruences_iterator(): 

cong = list(c) 

n = len(cong[0]) 

for part in cong: 

if len(part) != n: 

if certificate: 

from sage.combinat.set_partition import SetPartition 

return (False, 

SetPartition([[self._vertex_to_element(v) for v in p] for p in c])) 

return False 

return ok 

 

def is_regular(self, certificate=False): 

""" 

Return ``True`` if the lattice is regular and ``False`` otherwise. 

 

A congruence of a lattice is *regular* if it is generated 

by any of it's part. A lattice is regular if it has only 

regular congruences. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate if the lattice is not regular 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, (C, p))``, where `C` is a non-regular congruence as a 

:class:`sage.combinat.set_partition.SetPartition` and `p` is a 

congruence class of `C` such that the congruence generated by `p` 

is not `C`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [8, 7], 4: [6, 7], 5: [8], 6: [9], 7: [9], 8: [9]}) 

sage: L.is_regular() 

True 

 

sage: N5 = posets.PentagonPoset() 

sage: N5.is_regular() 

False 

sage: N5.is_regular(certificate=True) 

(False, ({{0}, {1}, {2, 3}, {4}}, [0])) 

 

.. SEEALSO:: 

 

- Stronger properties: :meth:`is_uniform`, 

:meth:`is_sectionally_complemented`, 

:meth:`is_cosectionally_complemented` 

- Other: :meth:`congruence` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_regular() for i in range(5)] 

[True, True, True, False, False] 

""" 

H = self._hasse_diagram 

for cong in H.congruences_iterator(): 

for part in cong: 

if H.congruence([part]) != cong: 

if certificate: 

from sage.combinat.set_partition import SetPartition 

return (False, 

(SetPartition([[self._vertex_to_element(v) for v in p] for p in cong]), 

[self._vertex_to_element(v) for v in part])) 

return False 

if certificate: 

return (True, None) 

return True 

 

def is_simple(self, certificate=False): 

""" 

Return ``True`` if the lattice is simple and ``False`` otherwise. 

 

A lattice is *simple* if it has no nontrivial congruences; in 

other words, for every two distinct elements `a` and `b` the 

principal congruence generated by `(a, b)` has only one 

component, i.e. the whole lattice. 

 

INPUT: 

 

- ``certificate`` -- (default: ``False``) whether to return 

a certificate if the lattice is not simple 

 

OUTPUT: 

 

- If ``certificate=True`` return either ``(True, None)`` or 

``(False, c)``, where `c` is a nontrivial congruence as a 

:class:`sage.combinat.set_partition.SetPartition`. 

If ``certificate=False`` return ``True`` or ``False``. 

 

EXAMPLES:: 

 

sage: posets.DiamondPoset(5).is_simple() # Smallest nontrivial example 

True 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [6], 4: [6], 5: [6]}) 

sage: L.is_simple() 

False 

sage: L.is_simple(certificate=True) 

(False, {{1, 3}, {2, 4, 5, 6}}) 

 

Two more examples. First is a non-simple lattice without any 

2-element congruences:: 

 

sage: L = LatticePoset({1: [2, 3, 4], 2: [5], 3: [5], 4: [6, 7], 

....: 5: [8], 6: [8], 7: [8]}) 

sage: L.is_simple() 

False 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [8], 

....: 5: [8], 6: [8], 7: [8]}) 

sage: L.is_simple() 

True 

 

.. SEEALSO:: 

 

- Weaker properties: :meth:`is_isoform` 

- Mutually exclusive properties: :meth:`is_constructible_by_doublings` 

(by any set) 

- Other: :meth:`congruence` 

 

TESTS:: 

 

sage: [posets.ChainPoset(i).is_simple() for i in range(5)] 

[True, True, True, False, False] 

""" 

from sage.combinat.set_partition import SetPartition 

cong = self._hasse_diagram.find_nontrivial_congruence() 

if cong is None: 

return (True, None) if certificate else True 

if not certificate: 

return False 

return (False, SetPartition([[self._vertex_to_element(v) for v in s] 

for s in cong])) 

 

def subdirect_decomposition(self): 

r""" 

Return the subdirect decomposition of the lattice. 

 

The subdirect decomposition of a lattice `L` is the list 

of smaller lattices `L_1, \ldots, L_n` such that `L` is 

a sublattice of `L_1 \times \ldots \times L_n`, none 

of `L_i` can be decomposed further and `L` is not a sublattice 

of any `L_i`. (Except when the list has only one element, i.e. 

when the lattice is subdirectly irreducible.) 

 

EXAMPLES:: 

 

sage: posets.ChainPoset(3).subdirect_decomposition() 

[Finite lattice containing 2 elements, Finite lattice containing 2 elements] 

 

sage: L = LatticePoset({1: [2, 4], 2: [3], 3: [6, 7], 4: [5, 7], 

....: 5: [9, 8], 6: [9], 7: [9], 8: [10], 9: [10]}) 

sage: Ldecomp = L.subdirect_decomposition() 

sage: [fac.cardinality() for fac in Ldecomp] 

[2, 5, 7] 

sage: Ldecomp[1].is_isomorphic(posets.PentagonPoset()) 

True 

 

TESTS:: 

 

sage: posets.ChainPoset(0).subdirect_decomposition() 

[Finite lattice containing 0 elements] 

sage: posets.ChainPoset(1).subdirect_decomposition() 

[Finite lattice containing 1 elements] 

sage: posets.ChainPoset(2).subdirect_decomposition() 

[Finite lattice containing 2 elements] 

 

The pentagon is subdirectly irreducible, i.e. the decomposition 

has only one element:: 

 

sage: N5 = posets.PentagonPoset() 

sage: N5.subdirect_decomposition() 

[Finite lattice containing 5 elements] 

""" 

H = self._hasse_diagram 

cong_ji, congs = H.principal_congruences_poset() 

 

if self.cardinality() <= 2 or cong_ji.has_bottom(): 

return [self.relabel(self._element_to_vertex_dict)] 

 

L_ = cong_ji.order_ideals_lattice() 

c = L_.canonical_meetands(L_.bottom()) 

L = L_.subposet(L_.order_ideal(c)) 

 

C = {} 

for e in L: 

low = L.lower_covers(e) 

if len(low) == 1: # a join-irreducible element 

C[e] = congs[max(e, key=cong_ji._element_to_vertex)] 

elif low: # "extending" congruence to avoid re-computation 

low_0 = min(low, key=lambda x: C[x].number_of_subsets()) 

for new_pair in e: 

if new_pair not in low_0: 

break 

C[e] = self._hasse_diagram.congruence([new_pair], start=C[low_0]) 

 

decomposing_congruences = [C[m] for m in L.maximal_elements()] 

decomposing_congruences.sort(key=lambda x: x.number_of_subsets()) 

 

result = [] 

for congruence in decomposing_congruences: 

part_bottoms = [min(part) for part in congruence] 

F = H.transitive_closure().subgraph(part_bottoms) 

result.append(LatticePoset(F)) 

 

return result 

 

def congruence(self, S): 

""" 

Return the congruence generated by set of sets `S`. 

 

A congruence of a lattice is an equivalence relation `\cong` that is 

compatible with meet and join; i.e. if `a_1 \cong a_2` and 

`b_1 \cong b_2`, then `(a_1 \\vee b_1) \cong (a_2 \\vee b_2)` and 

`(a_1 \wedge b_1) \cong (a_2 \wedge b_2)`. 

 

By the congruence generated by set of sets `\{S_1, \ldots, S_n\}` we 

mean the least congruence `\cong` such that for every `x, y \in S_i` 

for some `i` we have `x \cong y`. 

 

INPUT: 

 

- ``S``, a list of lists -- list of element blocks that the congruence 

will contain. 

 

OUTPUT: 

 

Congruence of the lattice as a 

:class:`sage.combinat.set_partition.SetPartition`. 

 

EXAMPLES:: 

 

sage: L = posets.DivisorLattice(12) 

sage: cong = L.congruence([[1, 3]]) 

sage: sorted(sorted(c) for c in cong) 

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

sage: L.congruence([[1, 2], [6, 12]]) 

{{1, 2, 4}, {3, 6, 12}} 

 

sage: L = LatticePoset({1: [2, 3], 2: [4], 3: [4], 4: [5]}) 

sage: L.congruence([[1, 2]]) 

{{1, 2}, {3, 4}, {5}} 

 

sage: L = LatticePoset({1: [2, 3], 2: [4, 5, 6], 4: [5], 5: [7, 8], 

....: 6: [8], 3: [9], 7: [10], 8: [10], 9:[10]}) 

sage: cong = L.congruence([[1, 2]]) 

sage: cong[0] 

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 

 

.. SEEALSO:: :meth:`quotient` 

 

TESTS:: 

 

sage: P = posets.PentagonPoset() 

sage: P.congruence([]) 

{{0}, {1}, {2}, {3}, {4}} 

sage: P.congruence([[2]]) 

{{0}, {1}, {2}, {3}, {4}} 

sage: P.congruence([[2, 2]]) 

{{0}, {1}, {2}, {3}, {4}} 

sage: P.congruence([[0, 4]]) 

{{0, 1, 2, 3, 4}} 

sage: LatticePoset().congruence([]) 

{} 

 

"Double zigzag" to ensure that up-down propagation 

works:: 

 

sage: L = LatticePoset(DiGraph('P^??@_?@??B_?@??B??@_?@??B_?@??B??@??A??C??G??O???')) 

sage: sorted(sorted(p) for p in L.congruence([[1,6]])) 

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

 

Simple lattice, i.e. a lattice without any nontrivial congruence:: 

 

sage: L = LatticePoset(DiGraph('GPb_@?OC@?O?')) 

sage: L.congruence([[1,2]]) 

{{0, 1, 2, 3, 4, 5, 6, 7}} 

""" 

from sage.combinat.set_partition import SetPartition 

S = [[self._element_to_vertex(e) for e in s] for s in S] 

cong = self._hasse_diagram.congruence(S) 

return SetPartition([[self._vertex_to_element(v) for v in s] 

for s in cong]) 

 

def quotient(self, congruence, labels='tuple'): 

r""" 

Return the quotient lattice by ``congruence``. 

 

Let `L` be a lattice and `\Theta` be a congruence of `L` with 

congruence classes `\Theta_1, \Theta_2, \ldots`. The quotient 

lattice `L/\Theta` is the lattice with elements 

`\{\Theta_1, \Theta_2, \ldots\}` and meet and join given by the 

original lattice. Explicitly, if `e_1 \in \Theta_1` and 

`e_2 \in \Theta_2`, such that `e_1 \vee e_2 \in \Theta_3` then 

`\Theta_1 \vee \Theta_2 = \Theta_3` in `L/\Theta` and similarly 

for meets. 

 

INPUT: 

 

- ``congruence`` -- list of lists; a congruence 

 

- ``labels`` -- string; the elements of the resulting 

lattice and can be one of the following: 

 

* ``'tuple'`` - elements are tuples of elements of the original 

lattice 

* ``'lattice'`` - elements are sublattices of the original lattice 

* ``'integer'`` - elements are labeled by integers 

 

.. WARNING:: 

 

``congruence`` is expected to be a valid congruence of the 

lattice. This is *not* checked. 

 

EXAMPLES:: 

 

sage: L = posets.PentagonPoset() 

sage: c = L.congruence([[0, 1]]) 

sage: I = L.quotient(c); I 

Finite lattice containing 2 elements 

sage: I.top() 

(2, 3, 4) 

sage: I = L.quotient(c, labels='lattice') 

sage: I.top() 

Finite lattice containing 3 elements 

 

sage: B3 = posets.BooleanLattice(3) 

sage: c = B3.congruence([[0,1]]) 

sage: B2 = B3.quotient(c, labels='integer') 

sage: B2.is_isomorphic(posets.BooleanLattice(2)) 

True 

 

.. SEEALSO:: :meth:`congruence` 

 

TESTS:: 

 

sage: E = LatticePoset() 

sage: E.quotient([]) 

Finite lattice containing 0 elements 

 

sage: L = posets.PentagonPoset() 

sage: L.quotient(L.congruence([[1]])).is_isomorphic(L) 

True 

""" 

if labels not in ['lattice', 'tuple', 'integer']: 

raise ValueError("labels must be one of 'lattice', 'tuple' or 'integer'") 

 

parts_H = [sorted([self._element_to_vertex(e) for e in part]) for 

part in congruence] 

minimal_vertices = [part[0] for part in parts_H] 

H = self._hasse_diagram.transitive_closure().subgraph(minimal_vertices).transitive_reduction() 

if labels == 'integer': 

H.relabel(list(range(len(minimal_vertices)))) 

return LatticePoset(H) 

part_dict = {m[0]: [self._vertex_to_element(x) for x in m] for m 

in parts_H} 

if labels == 'tuple': 

H.relabel(lambda m: tuple(part_dict[m])) 

return LatticePoset(H) 

maximal_vertices = [max(part) for part in parts_H] 

H.relabel(lambda m: self.sublattice(part_dict[m])) 

return LatticePoset(H) 

 

def congruences_lattice(self, labels='congruence'): 

r""" 

Return the lattice of congruences. 

 

A congruence of a lattice is a partition of elements to classes 

compatible with both meet- and join-operation; see :meth:`congruence`. 

Elements of the *congruence lattice* are congruences ordered by 

refinement; i.e. if every class of a congruence `\Theta` is 

contained in some class of `\Phi`, then `\Theta \le \Phi` 

in the congruence lattice. 

 

INPUT: 

 

- ``labels`` -- a string; the type of elements in the resulting lattice 

 

OUTPUT: 

 

A distributive lattice. 

 

- If ``labels='congruence'``, then elements of the 

result will be congruences given as 

:class:`sage.combinat.set_partition.SetPartition`. 

- If ``labels='integers'``, result is a lattice on 

integers isomorphic to the congruence lattice. 

 

EXAMPLES:: 

 

sage: N5 = posets.PentagonPoset() 

sage: CL = N5.congruences_lattice(); CL 

Finite lattice containing 5 elements 

sage: CL.atoms() 

[{{0}, {1}, {2, 3}, {4}}] 

sage: CL.coatoms() 

[{{0, 1}, {2, 3, 4}}, {{0, 2, 3}, {1, 4}}] 

 

sage: C4 = posets.ChainPoset(4) 

sage: CL = C4.congruences_lattice(labels='integer') 

sage: CL.is_isomorphic(posets.BooleanLattice(3)) 

True 

 

TESTS:: 

 

sage: posets.ChainPoset(0).congruences_lattice() 

Finite lattice containing 1 elements 

sage: posets.ChainPoset(1).congruences_lattice() 

Finite lattice containing 1 elements 

sage: posets.ChainPoset(2).congruences_lattice() 

Finite lattice containing 2 elements 

sage: posets.ChainPoset(3).congruences_lattice() 

Finite lattice containing 4 elements 

""" 

from sage.sets.set import Set 

from sage.sets.disjoint_set import DisjointSet 

from sage.combinat.set_partition import SetPartition 

if labels not in ['integer', 'congruence']: 

raise ValueError("'labels' must be 'integer' or 'congruence'") 

 

cong_ji, congs = self._hasse_diagram.principal_congruences_poset() 

 

# Form of the lattice of congruences can be computed much faster than 

# all congruences. 

if labels == 'integer': 

tmp = Poset(cong_ji).order_ideals_lattice(as_ideals=False) 

return tmp.relabel(tmp._element_to_vertex_dict) 

 

# To compute full lattice of congruences we "extend" already computed 

# parts of a congruence. 

L = cong_ji.order_ideals_lattice() 

C = {} 

C[Set()] = DisjointSet(self.cardinality()) # the bottom element 

for e in L: 

low = L.lower_covers(e) 

if len(low) == 1: # a join-irreducible element 

C[e] = congs[max(e, key=lambda x: cong_ji._element_to_vertex(x))] 

if len(low) > 1: # "extending" congruence to avoid re-computation 

low_0 = min(low, key=lambda x: C[x].number_of_subsets()) 

for new_pair in e: 

if new_pair not in low_0: 

break 

C[e] = self._hasse_diagram.congruence([new_pair], start=C[low_0]) 

 

return L.relabel(lambda e: SetPartition([[self._vertex_to_element(v) 

for v in p] for p in C[e]])) 

 

 

def _log_2(n): 

""" 

Return the 2-based logarithm of `n` rounded up. 

 

`n` is assumed to be a positive integer. 

 

EXAMPLES:: 

 

sage: sage.combinat.posets.lattices._log_2(10) 

4 

 

TESTS:: 

 

sage: sage.combinat.posets.lattices._log_2(15) 

4 

sage: sage.combinat.posets.lattices._log_2(16) 

4 

sage: sage.combinat.posets.lattices._log_2(17) 

5 

""" 

bits = -1 

i = n 

while i: 

i = i >> 1 

bits += 1 

if 1 << bits == n: 

return bits 

return bits + 1 

 

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

 

FiniteMeetSemilattice._dual_class = FiniteJoinSemilattice 

FiniteJoinSemilattice._dual_class = FiniteMeetSemilattice 

FiniteLatticePoset ._dual_class = FiniteLatticePoset